/** 语句:delay 延迟(仅 value;单位 ms/s/m/h/d/w/mon/月/y,可组合,纯数字按秒) */ const { assertStrictKeys } = require('../action-schema.js') const types = ['delay'] function parse (action, parseContext) { const path = parseContext.actionPath || 'delay' assertStrictKeys(action, ['type', 'value'], path) if (action.value === undefined || action.value === null || String(action.value).trim() === '') { throw new Error(`${path}: delay 须使用字段 value 指定时长`) } return { type: 'delay', value: action.value } } async function execute(action, ctx) { const raw = action.value != null ? action.value : '0s' const resolved = ctx.replaceVariablesInString && ctx.variableContext ? ctx.replaceVariablesInString(String(raw), ctx.variableContext) : raw const delayMs = ctx.parseDelayString ? ctx.parseDelayString(resolved) : 0 const waitMs = typeof delayMs === 'number' && delayMs > 0 ? delayMs : 0 if (waitMs > 0) await new Promise(r => setTimeout(r, waitMs)) return { success: true } } module.exports = { types, parse, execute }