@midscene/test 0.0.0 → 1.10.4-beta-20260715034325.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/bin/midscene-workflow +3 -0
- package/dist/es/cli/index.mjs +1118 -0
- package/dist/es/cli/index.mjs.map +1 -0
- package/dist/es/index.mjs +843 -0
- package/dist/es/index.mjs.map +1 -0
- package/dist/es/midscene/index.mjs +198 -0
- package/dist/es/midscene/index.mjs.map +1 -0
- package/dist/es/workflow-cli.mjs +1160 -0
- package/dist/es/workflow-cli.mjs.map +1 -0
- package/dist/lib/cli/index.js +1170 -0
- package/dist/lib/cli/index.js.map +1 -0
- package/dist/lib/index.js +952 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/midscene/index.js +232 -0
- package/dist/lib/midscene/index.js.map +1 -0
- package/dist/lib/workflow-cli.js +1166 -0
- package/dist/lib/workflow-cli.js.map +1 -0
- package/dist/types/cli/index.d.ts +282 -0
- package/dist/types/index.d.ts +425 -0
- package/dist/types/midscene/index.d.ts +175 -0
- package/dist/types/workflow-cli.d.ts +1 -0
- package/package.json +60 -8
- package/README.md +0 -3
- package/index.js +0 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../src/errors.ts","../../src/parser/normalize.ts","../../src/node/define-node.ts","../../src/engine/registry.ts","../../src/engine/execute-step.ts","../../src/engine/run-collected-case.ts","../../src/engine/case-runner.ts","../../src/engine/document-runtime.ts","../../src/engine/run-workflow-document.ts","../../src/parser/collect.ts"],"sourcesContent":["export interface WorkflowErrorOptions {\n code?: string;\n details?: unknown;\n cause?: unknown;\n}\n\nexport class WorkflowError extends Error {\n readonly code: string;\n readonly details?: unknown;\n\n constructor(message: string, options: WorkflowErrorOptions = {}) {\n super(message, { cause: options.cause });\n this.name = new.target.name;\n this.code = options.code ?? 'WORKFLOW_ERROR';\n this.details = options.details;\n }\n\n toJSON(): Record<string, unknown> {\n return {\n name: this.name,\n message: this.message,\n code: this.code,\n ...(this.details === undefined ? {} : { details: this.details }),\n };\n }\n}\n\nexport class WorkflowParseError extends WorkflowError {\n constructor(message: string, details?: unknown, cause?: unknown) {\n super(message, { code: 'WORKFLOW_PARSE_ERROR', details, cause });\n }\n}\n\nexport class NodeDefinitionError extends WorkflowError {\n constructor(message: string, details?: unknown) {\n super(message, { code: 'NODE_DEFINITION_ERROR', details });\n }\n}\n\nexport class DuplicateNodeError extends WorkflowError {\n readonly node: string;\n\n constructor(node: string) {\n super(`Node \"${node}\" is already registered.`, {\n code: 'DUPLICATE_NODE',\n details: { node },\n });\n this.node = node;\n }\n}\n\nexport class NodeNotFoundError extends WorkflowError {\n readonly node: string;\n\n constructor(node: string) {\n super(`Node \"${node}\" is not registered.`, {\n code: 'NODE_NOT_FOUND',\n details: { node },\n });\n this.node = node;\n }\n}\n\nexport class NodeInputValidationError extends WorkflowError {\n constructor(message: string, details?: unknown) {\n super(message, { code: 'NODE_INPUT_VALIDATION_ERROR', details });\n }\n}\n\nexport class StepTimeoutError extends WorkflowError {\n readonly timeoutMs: number;\n readonly node?: string;\n\n constructor(timeoutMs: number, node?: string) {\n super(\n node\n ? `Node \"${node}\" timed out after ${timeoutMs}ms.`\n : `Step timed out after ${timeoutMs}ms.`,\n {\n code: 'STEP_TIMEOUT',\n details: { timeoutMs, ...(node === undefined ? {} : { node }) },\n },\n );\n this.timeoutMs = timeoutMs;\n this.node = node;\n }\n}\n\nexport class NodeExecutionError extends WorkflowError {\n readonly node: string;\n\n constructor(node: string, cause: unknown) {\n const causeMessage =\n cause instanceof Error ? cause.message : String(cause ?? 'Unknown error');\n super(`Node \"${node}\" failed: ${causeMessage}`, {\n code: 'NODE_EXECUTION_ERROR',\n details: { node },\n cause,\n });\n this.node = node;\n }\n}\n\nexport class WorkflowDocumentSetupError extends WorkflowError {\n constructor(\n cause: unknown,\n details: { documentId: string; documentRunId: string },\n ) {\n const causeMessage =\n cause instanceof Error ? cause.message : String(cause ?? 'Unknown error');\n super(`Workflow document setup failed: ${causeMessage}`, {\n code: 'WORKFLOW_DOCUMENT_SETUP_ERROR',\n details,\n cause,\n });\n }\n}\n\nexport class WorkflowDocumentTeardownError extends WorkflowError {\n constructor(\n cause: unknown,\n details: {\n documentId: string;\n documentRunId: string;\n registrationIndex: number;\n },\n ) {\n const causeMessage =\n cause instanceof Error ? cause.message : String(cause ?? 'Unknown error');\n super(`Workflow document teardown failed: ${causeMessage}`, {\n code: 'WORKFLOW_DOCUMENT_TEARDOWN_ERROR',\n details,\n cause,\n });\n }\n}\n\nexport class WorkflowLifecycleError extends WorkflowError {\n constructor(message: string, details?: unknown) {\n super(message, { code: 'WORKFLOW_LIFECYCLE_ERROR', details });\n }\n}\n\nexport class CaseExecutionError extends WorkflowError {\n readonly result: import('./engine/types').CaseRunResult;\n\n constructor(result: import('./engine/types').CaseRunResult) {\n super(`Case \"${result.name}\" failed.`, {\n code: 'CASE_EXECUTION_FAILED',\n details: { caseId: result.caseId, runId: result.runId },\n });\n this.result = result;\n }\n}\n\nexport class WorkflowDocumentExecutionError extends WorkflowError {\n readonly result: import('./engine/types').WorkflowDocumentRunResult;\n\n constructor(result: import('./engine/types').WorkflowDocumentRunResult) {\n super(`Workflow document \"${result.sourcePath}\" failed.`, {\n code: 'WORKFLOW_DOCUMENT_EXECUTION_FAILED',\n details: {\n documentId: result.documentId,\n documentRunId: result.documentRunId,\n },\n });\n this.result = result;\n }\n}\n\nexport function normalizeNodeExecutionError(\n error: unknown,\n node: string,\n): WorkflowError {\n return error instanceof WorkflowError\n ? error\n : new NodeExecutionError(node, error);\n}\n","import { WorkflowParseError } from '../errors';\nimport type {\n CommonNodeInput,\n NormalizedStep,\n NormalizedStepMeta,\n} from './types';\n\nconst supportedMetaKeys = new Set(['timeout', 'continue-on-error']);\n\nfunction isMapping(value: unknown): value is Record<string, unknown> {\n return (\n typeof value === 'object' &&\n value !== null &&\n !Array.isArray(value) &&\n (Object.getPrototypeOf(value) === Object.prototype ||\n Object.getPrototypeOf(value) === null)\n );\n}\n\nfunction formatStep(index: number): string {\n return `step ${index + 1}`;\n}\n\nfunction normalizeMeta(value: unknown, index: number): NormalizedStepMeta {\n if (value === undefined) {\n return { continueOnError: false };\n }\n\n if (!isMapping(value)) {\n throw new WorkflowParseError(\n `${formatStep(index)} \"$\" must be a mapping.`,\n { index },\n );\n }\n\n for (const key of Object.keys(value)) {\n if (!supportedMetaKeys.has(key)) {\n throw new WorkflowParseError(\n `${formatStep(index)} has unsupported engine metadata \"${key}\".`,\n { index, key },\n );\n }\n }\n\n const timeout = value.timeout;\n if (\n timeout !== undefined &&\n (typeof timeout !== 'number' || !Number.isFinite(timeout) || timeout <= 0)\n ) {\n throw new WorkflowParseError(\n `${formatStep(index)} \"$.timeout\" must be a positive number of milliseconds.`,\n { index, timeout },\n );\n }\n\n const continueOnError = value['continue-on-error'];\n if (continueOnError !== undefined && typeof continueOnError !== 'boolean') {\n throw new WorkflowParseError(\n `${formatStep(index)} \"$.continue-on-error\" must be a boolean.`,\n { index, continueOnError },\n );\n }\n\n return {\n ...(timeout === undefined ? {} : { timeoutMs: timeout }),\n continueOnError: continueOnError ?? false,\n };\n}\n\nexport function validateCommonNodeInput(\n input: Record<string, unknown>,\n index: number,\n): asserts input is Record<string, unknown> & CommonNodeInput {\n if (input.prompt !== undefined && typeof input.prompt !== 'string') {\n throw new WorkflowParseError(\n `${formatStep(index)} \"prompt\" must be a string.`,\n { index, prompt: input.prompt },\n );\n }\n}\n\nexport function normalizeStep(value: unknown, index = 0): NormalizedStep {\n if (!isMapping(value)) {\n throw new WorkflowParseError(`${formatStep(index)} must be a mapping.`, {\n index,\n });\n }\n\n const entries = Object.entries(value);\n if (entries.length !== 1) {\n throw new WorkflowParseError(\n `${formatStep(index)} must contain exactly one node.`,\n { index, nodes: Object.keys(value) },\n );\n }\n\n const [node, rawValue] = entries[0];\n if (node.trim().length === 0) {\n throw new WorkflowParseError(\n `${formatStep(index)} node name must not be empty.`,\n { index },\n );\n }\n\n if (typeof rawValue === 'string') {\n return {\n node,\n input: { prompt: rawValue },\n meta: { continueOnError: false },\n };\n }\n\n if (!isMapping(rawValue)) {\n throw new WorkflowParseError(\n `${formatStep(index)} value must be a string shorthand or a mapping.`,\n { index, node },\n );\n }\n\n const { $: rawMeta, ...input } = rawValue;\n validateCommonNodeInput(input, index);\n\n return {\n node,\n input,\n meta: normalizeMeta(rawMeta, index),\n };\n}\n\nexport function normalizeSteps(steps: unknown): NormalizedStep[] {\n if (!Array.isArray(steps)) {\n throw new WorkflowParseError('Steps must be an array.');\n }\n return steps.map((step, index) => normalizeStep(step, index));\n}\n","import { NodeDefinitionError } from '../errors';\nimport type { DefineNodeOptions, NodeDefinition } from './types';\n\nconst validateDefinition = (options: {\n name: string;\n execute: unknown;\n}): void => {\n if (!options || typeof options !== 'object') {\n throw new NodeDefinitionError('Node definition must be an object.');\n }\n\n if (typeof options.name !== 'string' || options.name.trim().length === 0) {\n throw new NodeDefinitionError('Node name must be a non-empty string.');\n }\n\n if (typeof options.execute !== 'function') {\n throw new NodeDefinitionError(\n `Node \"${options.name}\" must provide an execute function.`,\n { node: options.name },\n );\n }\n};\n\nexport function defineNode<\n TInput = unknown,\n TData = unknown,\n TContext = unknown,\n>(\n options: DefineNodeOptions<TInput, TData, TContext>,\n): NodeDefinition<TInput, TData, TContext> {\n validateDefinition(options);\n return options;\n}\n","import { DuplicateNodeError, NodeNotFoundError } from '../errors';\nimport { defineNode } from '../node/define-node';\nimport type { NodeDefinition } from '../node/types';\n\nexport class NodeRegistry {\n readonly #nodes = new Map<string, NodeDefinition<any, any>>();\n\n constructor(nodes: readonly NodeDefinition<any, any>[] = []) {\n for (const node of nodes) {\n this.register(node);\n }\n }\n\n register<TInput, TData>(node: NodeDefinition<TInput, TData>): this {\n defineNode(node);\n\n if (this.#nodes.has(node.name)) {\n throw new DuplicateNodeError(node.name);\n }\n\n this.#nodes.set(node.name, node);\n return this;\n }\n\n get(name: string): NodeDefinition<any, any> | undefined {\n return this.#nodes.get(name);\n }\n\n require(name: string): NodeDefinition<any, any> {\n const node = this.get(name);\n if (!node) {\n throw new NodeNotFoundError(name);\n }\n return node;\n }\n\n has(name: string): boolean {\n return this.#nodes.has(name);\n }\n\n names(): string[] {\n return [...this.#nodes.keys()];\n }\n}\n","import {\n NodeExecutionError,\n StepTimeoutError,\n normalizeNodeExecutionError,\n} from '../errors';\nimport type { NodeDefinition, NodeResult } from '../node/types';\nimport { validateCommonNodeInput } from '../parser/normalize';\nimport type { CommonNodeInput, NormalizedStep } from '../parser/types';\nimport type {\n NodeCaseContext,\n NodeDocumentContext,\n NodeExecutionPhase,\n StepRunResult,\n} from './types';\n\nfunction validateNodeOutput<TData>(\n output: unknown,\n node: string,\n): NodeResult<TData> | undefined {\n if (output === undefined) {\n return undefined;\n }\n\n if (typeof output !== 'object' || output === null || Array.isArray(output)) {\n throw new NodeExecutionError(\n node,\n new TypeError('Node output must be an object or undefined.'),\n );\n }\n\n if (\n 'summary' in output &&\n output.summary !== undefined &&\n typeof output.summary !== 'string'\n ) {\n throw new NodeExecutionError(\n node,\n new TypeError('Node output summary must be a string.'),\n );\n }\n\n return output as NodeResult<TData>;\n}\n\nfunction createStepResultBase(\n step: NormalizedStep,\n startedAt: Date,\n phase: NodeExecutionPhase,\n stepIndex: number,\n) {\n const endedAt = new Date();\n return {\n node: step.node,\n phase,\n stepIndex,\n input: step.input,\n meta: step.meta,\n startedAt: startedAt.toISOString(),\n endedAt: endedAt.toISOString(),\n durationMs: Math.max(0, endedAt.getTime() - startedAt.getTime()),\n };\n}\n\nasync function executeNode<TOutputData>(\n step: NormalizedStep,\n execute: (signal: AbortSignal) => unknown,\n phase: NodeExecutionPhase,\n stepIndex: number,\n): Promise<StepRunResult<TOutputData>> {\n validateCommonNodeInput(step.input, stepIndex);\n\n const startedAt = new Date();\n const abortController = new AbortController();\n const timeoutMs = step.meta.timeoutMs;\n let timeout: ReturnType<typeof setTimeout> | undefined;\n let timeoutError: StepTimeoutError | undefined;\n const execution = Promise.resolve().then(() =>\n execute(abortController.signal),\n );\n const timedExecution =\n timeoutMs === undefined\n ? execution\n : Promise.race([\n execution,\n new Promise<never>((_, reject) => {\n timeout = setTimeout(() => {\n timeoutError = new StepTimeoutError(timeoutMs, step.node);\n abortController.abort(timeoutError);\n reject(timeoutError);\n }, timeoutMs);\n }),\n ]);\n\n try {\n const output = validateNodeOutput<TOutputData>(\n await timedExecution,\n step.node,\n );\n return {\n ...createStepResultBase(step, startedAt, phase, stepIndex),\n status: 'success',\n continuedAfterError: false,\n ...(output === undefined ? {} : { output }),\n };\n } catch (error) {\n return {\n ...createStepResultBase(step, startedAt, phase, stepIndex),\n status: 'failed',\n continuedAfterError: step.meta.continueOnError,\n error: normalizeNodeExecutionError(timeoutError ?? error, step.node),\n };\n } finally {\n if (timeout !== undefined) clearTimeout(timeout);\n }\n}\n\ntype StepExecutionTarget =\n | { scope: 'case'; case: NodeCaseContext }\n | { scope: 'document'; document: NodeDocumentContext };\n\nexport async function executeStep<\n TInput = unknown,\n TOutputData = unknown,\n TContext = unknown,\n>(\n step: NormalizedStep,\n node: NodeDefinition<TInput, TOutputData, TContext>,\n target: StepExecutionTarget,\n context: TContext,\n): Promise<StepRunResult<TOutputData>> {\n const phase =\n target.scope === 'case' ? target.case.phase : target.document.phase;\n const stepIndex =\n target.scope === 'case' ? target.case.stepIndex : target.document.stepIndex;\n\n return executeNode<TOutputData>(\n step,\n (signal) => {\n const common = {\n input: step.input as TInput & CommonNodeInput,\n $: step.meta,\n signal,\n context,\n };\n return target.scope === 'case'\n ? node.execute({ ...common, scope: 'case', case: target.case })\n : node.execute({\n ...common,\n scope: 'document',\n document: target.document,\n });\n },\n phase,\n stepIndex,\n );\n}\n","import { randomUUID } from 'node:crypto';\nimport type { CollectedCase, NormalizedStep } from '../parser/types';\nimport { executeStep } from './execute-step';\nimport type {\n CaseNodePhase,\n CaseRunResult,\n NodeCaseContext,\n RunCollectedCaseOptions,\n StepRunResult,\n} from './types';\n\nexport async function runCollectedCase<TContext = undefined>(\n collectedCase: CollectedCase,\n options: RunCollectedCaseOptions<TContext>,\n): Promise<CaseRunResult> {\n const phases: Record<CaseNodePhase, readonly NormalizedStep[]> = {\n beforeEach: options.beforeEach ?? [],\n steps: collectedCase.definition.steps,\n afterEach: options.afterEach ?? [],\n };\n const nodes = {\n beforeEach: phases.beforeEach.map((step) => options.resolveNode(step.node)),\n steps: phases.steps.map((step) => options.resolveNode(step.node)),\n afterEach: phases.afterEach.map((step) => options.resolveNode(step.node)),\n };\n const runId = options.createRunId?.() ?? randomUUID();\n const startedAt = new Date();\n const beforeEach: StepRunResult[] = [];\n const steps: StepRunResult[] = [];\n const afterEach: StepRunResult[] = [];\n const completedNodes: StepRunResult[] = [];\n\n const runPhase = async (\n phase: CaseNodePhase,\n results: StepRunResult[],\n ): Promise<void> => {\n for (const [stepIndex, step] of phases[phase].entries()) {\n const caseContext: NodeCaseContext = {\n caseId: collectedCase.caseId,\n runId,\n name: collectedCase.definition.name,\n sourcePath: collectedCase.sourcePath,\n caseIndex: collectedCase.caseIndex,\n phase,\n stepIndex,\n completedSteps: Object.freeze([...steps]),\n completedNodes: Object.freeze([...completedNodes]),\n };\n const stepInfo = {\n scope: 'case' as const,\n node: step.node,\n stepCount: phases[phase].length,\n case: caseContext,\n };\n await options.onStepStart?.(stepInfo);\n const result = await executeStep(\n step,\n nodes[phase][stepIndex],\n { scope: 'case', case: caseContext },\n options.context as TContext,\n );\n await options.onStepResult?.(stepInfo, result);\n results.push(result);\n completedNodes.push(result);\n if (result.status === 'failed' && !result.continuedAfterError) break;\n }\n };\n\n await runPhase('beforeEach', beforeEach);\n if (!beforeEach.some((step) => step.status === 'failed')) {\n await runPhase('steps', steps);\n }\n await runPhase('afterEach', afterEach);\n\n const endedAt = new Date();\n const result: CaseRunResult = {\n caseId: collectedCase.caseId,\n runId,\n name: collectedCase.definition.name,\n sourcePath: collectedCase.sourcePath,\n caseIndex: collectedCase.caseIndex,\n status: completedNodes.some((step) => step.status === 'failed')\n ? 'failed'\n : 'success',\n beforeEach,\n steps,\n afterEach,\n startedAt: startedAt.toISOString(),\n endedAt: endedAt.toISOString(),\n durationMs: Math.max(0, endedAt.getTime() - startedAt.getTime()),\n };\n\n await options.onResult?.(result);\n return result;\n}\n","import type { NodeDefinition } from '../node/types';\nimport { normalizeSteps } from '../parser/normalize';\nimport type { CaseInput, CollectedCase } from '../parser/types';\nimport { NodeRegistry } from './registry';\nimport { runCollectedCase } from './run-collected-case';\nimport type { CaseRunResult, CaseRunnerOptions } from './types';\n\nexport class CaseRunner<TContext = undefined> {\n readonly registry: NodeRegistry;\n readonly context: TContext;\n\n constructor(options: CaseRunnerOptions<TContext> = {}) {\n this.registry = new NodeRegistry(options.nodes);\n this.context = options.context as TContext;\n }\n\n register<TInput, TData>(node: NodeDefinition<TInput, TData, TContext>): this {\n this.registry.register(node);\n return this;\n }\n\n async run(input: CaseInput): Promise<CaseRunResult> {\n const collectedCase: CollectedCase = {\n caseId: 'standalone-case',\n projectId: 'standalone-project',\n sourcePath: '',\n caseIndex: 0,\n definition: {\n name: input.name ?? 'case',\n steps: normalizeSteps(input.steps),\n },\n };\n const result = await runCollectedCase(collectedCase, {\n resolveNode: (name) =>\n this.registry.require(name) as NodeDefinition<any, any, TContext>,\n context: this.context,\n createRunId: () => 'standalone-case',\n });\n\n const fatalStepError = result.steps.find(\n (step) => step.status === 'failed' && !step.continuedAfterError,\n )?.error;\n if (fatalStepError) throw fatalStepError;\n return result;\n }\n}\n\nexport function createCaseRunner<TContext = undefined>(\n options: CaseRunnerOptions<TContext> = {},\n): CaseRunner<TContext> {\n return new CaseRunner(options);\n}\n","import { randomUUID } from 'node:crypto';\nimport {\n WorkflowDocumentSetupError,\n WorkflowDocumentTeardownError,\n WorkflowLifecycleError,\n} from '../errors';\nimport type { CollectedWorkflowDocument } from '../parser/types';\nimport { executeStep } from './execute-step';\nimport type {\n CreateDocumentRuntimeOptions,\n DocumentNodePhase,\n NodeDocumentContext,\n StepRunResult,\n WorkflowDocumentInfo,\n WorkflowDocumentRunResult,\n WorkflowDocumentRuntime,\n WorkflowDocumentTeardown,\n} from './types';\n\nexport function createDocumentRuntime<TContext = undefined>(\n document: CollectedWorkflowDocument,\n options: CreateDocumentRuntimeOptions<TContext>,\n): WorkflowDocumentRuntime<TContext> {\n const documentRunId = options.createDocumentRunId?.() ?? randomUUID();\n const startedAt = new Date();\n const beforeAll: StepRunResult[] = [];\n const afterAll: StepRunResult[] = [];\n const completedNodes: StepRunResult[] = [];\n const nodes = {\n beforeAll: document.lifecycle.beforeAll.map((step) =>\n options.resolveNode(step.node),\n ),\n afterAll: document.lifecycle.afterAll.map((step) =>\n options.resolveNode(step.node),\n ),\n };\n const info: WorkflowDocumentInfo = {\n documentId: document.documentId,\n documentRunId,\n projectId: document.projectId,\n sourcePath: document.sourcePath,\n cases: document.cases.map((caseDefinition) => caseDefinition.definition),\n lifecycle: document.lifecycle,\n env: Object.freeze({ ...process.env }),\n };\n const teardownStack: Array<{\n registrationIndex: number;\n teardown: WorkflowDocumentTeardown;\n }> = [];\n let acceptingTeardowns = options.setupDocument !== undefined;\n let context = undefined as TContext;\n let setupError: WorkflowDocumentSetupError | undefined;\n let started = false;\n let finishedResult: WorkflowDocumentRunResult | undefined;\n\n const createResult = (\n teardownErrors: WorkflowDocumentTeardownError[] = [],\n ): WorkflowDocumentRunResult => {\n const endedAt = new Date();\n return {\n documentId: document.documentId,\n documentRunId,\n projectId: document.projectId,\n sourcePath: document.sourcePath,\n status:\n setupError ||\n completedNodes.some((step) => step.status === 'failed') ||\n teardownErrors.length > 0\n ? 'failed'\n : 'success',\n startedAt: startedAt.toISOString(),\n endedAt: endedAt.toISOString(),\n durationMs: Math.max(0, endedAt.getTime() - startedAt.getTime()),\n beforeAll: [...beforeAll],\n afterAll: [...afterAll],\n ...(setupError ? { setupError } : {}),\n ...(teardownErrors.length > 0 ? { teardownErrors } : {}),\n };\n };\n\n const runPhase = async (\n phase: DocumentNodePhase,\n results: StepRunResult[],\n ): Promise<void> => {\n for (const [stepIndex, step] of document.lifecycle[phase].entries()) {\n const documentContext: NodeDocumentContext = {\n documentId: document.documentId,\n documentRunId,\n projectId: document.projectId,\n sourcePath: document.sourcePath,\n phase,\n stepIndex,\n completedNodes: Object.freeze([...completedNodes]),\n };\n const stepInfo = {\n scope: 'document' as const,\n node: step.node,\n stepCount: document.lifecycle[phase].length,\n document: documentContext,\n };\n await options.onStepStart?.(stepInfo);\n const result = await executeStep(\n step,\n nodes[phase][stepIndex],\n { scope: 'document', document: documentContext },\n context,\n );\n await options.onStepResult?.(stepInfo, result);\n results.push(result);\n completedNodes.push(result);\n if (result.status === 'failed' && !result.continuedAfterError) break;\n }\n };\n\n const onTeardown = (teardown: WorkflowDocumentTeardown): void => {\n if (!acceptingTeardowns) {\n throw new WorkflowLifecycleError(\n 'onTeardown() can only be called while setupDocument is running.',\n { documentId: document.documentId, documentRunId },\n );\n }\n if (typeof teardown !== 'function') {\n throw new WorkflowLifecycleError(\n 'onTeardown() requires a teardown function.',\n { documentId: document.documentId, documentRunId },\n );\n }\n teardownStack.push({\n registrationIndex: teardownStack.length,\n teardown,\n });\n };\n\n return {\n get context() {\n return context;\n },\n get canRunCases() {\n return (\n started &&\n !setupError &&\n !beforeAll.some((step) => step.status === 'failed')\n );\n },\n async start() {\n if (started) {\n throw new WorkflowLifecycleError(\n 'Workflow document runtime has already started.',\n { documentId: document.documentId, documentRunId },\n );\n }\n started = true;\n if (options.setupDocument) {\n try {\n context = await options.setupDocument({ ...info, onTeardown });\n } catch (error) {\n setupError = new WorkflowDocumentSetupError(error, {\n documentId: document.documentId,\n documentRunId,\n });\n } finally {\n acceptingTeardowns = false;\n }\n }\n if (!setupError) await runPhase('beforeAll', beforeAll);\n return createResult();\n },\n async finish() {\n if (finishedResult) return finishedResult;\n if (!started) {\n throw new WorkflowLifecycleError(\n 'Workflow document runtime must start before it can finish.',\n { documentId: document.documentId, documentRunId },\n );\n }\n if (!setupError) await runPhase('afterAll', afterAll);\n\n const statusBeforeTeardown = createResult().status;\n const teardownErrors: WorkflowDocumentTeardownError[] = [];\n for (const { registrationIndex, teardown } of teardownStack.reverse()) {\n try {\n await teardown({\n ...info,\n beforeAll: Object.freeze([...beforeAll]),\n afterAll: Object.freeze([...afterAll]),\n status: statusBeforeTeardown,\n ...(setupError ? { setupError } : {}),\n });\n } catch (error) {\n teardownErrors.push(\n new WorkflowDocumentTeardownError(error, {\n documentId: document.documentId,\n documentRunId,\n registrationIndex,\n }),\n );\n }\n }\n finishedResult = createResult(teardownErrors);\n await options.onResult?.(finishedResult);\n return finishedResult;\n },\n };\n}\n","import type { CollectedCase, CollectedWorkflowDocument } from '../parser/types';\nimport { createDocumentRuntime } from './document-runtime';\nimport { runCollectedCase } from './run-collected-case';\nimport type {\n CaseRunOutcome,\n RunWorkflowDocumentOptions,\n WorkflowDocumentExecutionResult,\n WorkflowDocumentRunResult,\n} from './types';\n\nconst asNotRun = (\n collectedCase: CollectedCase,\n reason: NonNullable<CaseRunOutcome['notRunReason']>,\n): CaseRunOutcome => ({\n caseId: collectedCase.caseId,\n name: collectedCase.definition.name,\n sourcePath: collectedCase.sourcePath,\n caseIndex: collectedCase.caseIndex,\n status: 'not-run',\n notRunReason: reason,\n});\n\nexport async function runWorkflowDocument<TContext = undefined>(\n document: CollectedWorkflowDocument,\n options: RunWorkflowDocumentOptions<TContext>,\n): Promise<WorkflowDocumentExecutionResult> {\n const createDocumentRunId = options.createDocumentRunId;\n const createCaseRunId = options.createCaseRunId;\n const runtime = createDocumentRuntime(document, {\n resolveNode: options.resolveNode,\n setupDocument: options.setupDocument,\n onStepStart: options.onStepStart,\n onStepResult: options.onStepResult,\n onResult: options.onDocumentResult,\n createDocumentRunId: createDocumentRunId\n ? () => createDocumentRunId(document)\n : undefined,\n });\n const cases: CaseRunOutcome[] = [];\n let runtimeStarted = false;\n let documentResult: WorkflowDocumentRunResult | undefined;\n let executionError: unknown;\n\n try {\n runtimeStarted = true;\n await runtime.start();\n\n if (!runtime.canRunCases) {\n cases.push(\n ...document.cases.map((collectedCase) =>\n asNotRun(collectedCase, 'document-start-failed'),\n ),\n );\n } else {\n for (const collectedCase of document.cases) {\n if (options.shouldStop?.()) {\n cases.push(asNotRun(collectedCase, 'interrupted'));\n continue;\n }\n await options.onCaseStart?.(collectedCase);\n const run = await runCollectedCase(collectedCase, {\n resolveNode: options.resolveNode,\n beforeEach: document.lifecycle.beforeEach,\n afterEach: document.lifecycle.afterEach,\n context: runtime.context,\n onStepStart: options.onStepStart,\n onStepResult: options.onStepResult,\n onResult: options.onCaseResult,\n createRunId: createCaseRunId\n ? () => createCaseRunId(collectedCase)\n : undefined,\n });\n cases.push({\n caseId: collectedCase.caseId,\n name: collectedCase.definition.name,\n sourcePath: collectedCase.sourcePath,\n caseIndex: collectedCase.caseIndex,\n status: run.status,\n run,\n });\n }\n }\n } catch (error) {\n executionError = error;\n } finally {\n if (runtimeStarted) {\n try {\n documentResult = await runtime.finish();\n } catch (error) {\n executionError ??= error;\n }\n }\n }\n\n if (executionError) throw executionError;\n if (!documentResult) {\n throw new Error(\n `Workflow document \"${document.sourcePath}\" did not produce a result.`,\n );\n }\n return { document: documentResult, cases };\n}\n","import { createHash } from 'node:crypto';\nimport { readFileSync } from 'node:fs';\nimport { sep } from 'node:path';\nimport { JSON_SCHEMA, load as loadYaml } from 'js-yaml';\nimport { WorkflowParseError } from '../errors';\nimport type { NodeDefinition } from '../node/types';\nimport { normalizeSteps } from './normalize';\nimport type {\n CollectedCase,\n CollectedWorkflowDocument,\n WorkflowDocumentSource,\n} from './types';\n\nexport interface CollectWorkflowDocumentOptions {\n resolveNode(name: string): NodeDefinition<any, any> | undefined;\n}\n\nconst isMapping = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\nconst rejectUnknownKeys = (\n value: Record<string, unknown>,\n allowed: readonly string[],\n label: string,\n) => {\n const allowedSet = new Set(allowed);\n const unknown = Object.keys(value).filter((key) => !allowedSet.has(key));\n if (unknown.length) {\n throw new WorkflowParseError(\n `${label} has unsupported field \"${unknown[0]}\".`,\n { field: unknown[0] },\n );\n }\n};\n\nexport const createCaseId = (\n projectId: string,\n sourcePath: string,\n caseIndex: number,\n): string =>\n createHash('sha256')\n .update(JSON.stringify([projectId, sourcePath, caseIndex]))\n .digest('hex');\n\nexport const createWorkflowDocumentId = (\n projectId: string,\n sourcePath: string,\n): string =>\n createHash('sha256')\n .update(JSON.stringify([projectId, sourcePath]))\n .digest('hex');\n\nexport function collectWorkflowDocument(\n source: WorkflowDocumentSource,\n options: CollectWorkflowDocumentOptions,\n): CollectedWorkflowDocument {\n let parsed: unknown;\n try {\n parsed = loadYaml(readFileSync(source.absolutePath, 'utf8'), {\n schema: JSON_SCHEMA,\n });\n } catch (error) {\n throw new WorkflowParseError(\n `Failed to parse workflow document \"${source.sourcePath}\".`,\n { sourcePath: source.sourcePath },\n error,\n );\n }\n\n if (!isMapping(parsed)) {\n throw new WorkflowParseError('Workflow document must be a mapping.');\n }\n rejectUnknownKeys(\n parsed,\n ['beforeAll', 'beforeEach', 'cases', 'afterEach', 'afterAll'],\n 'Workflow document',\n );\n if (!Array.isArray(parsed.cases) || parsed.cases.length === 0) {\n throw new WorkflowParseError(\n 'Workflow document must contain a non-empty cases array.',\n );\n }\n\n const sourcePath = source.sourcePath.split(sep).join('/');\n const normalizeLifecycle = (\n phase: 'beforeAll' | 'beforeEach' | 'afterEach' | 'afterAll',\n ) => {\n const value = parsed[phase];\n if (value === undefined) return [];\n if (!Array.isArray(value)) {\n throw new WorkflowParseError(\n `Workflow document ${phase} must be an array.`,\n { phase },\n );\n }\n return normalizeSteps(value).map((normalized, stepIndex) => {\n const resolved = options.resolveNode(normalized.node);\n if (!resolved) {\n throw new WorkflowParseError(\n `Workflow document ${phase} step ${stepIndex + 1} references unknown node \"${normalized.node}\".`,\n { phase, stepIndex, node: normalized.node },\n );\n }\n return normalized;\n });\n };\n const lifecycle = {\n beforeAll: normalizeLifecycle('beforeAll'),\n beforeEach: normalizeLifecycle('beforeEach'),\n afterEach: normalizeLifecycle('afterEach'),\n afterAll: normalizeLifecycle('afterAll'),\n };\n const ids = new Set<string>();\n const cases: CollectedCase[] = parsed.cases.map((definition, caseIndex) => {\n if (!isMapping(definition)) {\n throw new WorkflowParseError(`Case ${caseIndex + 1} must be a mapping.`, {\n caseIndex,\n });\n }\n rejectUnknownKeys(definition, ['name', 'steps'], `Case ${caseIndex + 1}`);\n if (\n typeof definition.name !== 'string' ||\n definition.name.trim().length === 0\n ) {\n throw new WorkflowParseError(\n `Case ${caseIndex + 1} name must be a non-empty string.`,\n { caseIndex },\n );\n }\n if (!Array.isArray(definition.steps) || definition.steps.length === 0) {\n throw new WorkflowParseError(\n `Case ${caseIndex + 1} steps must be a non-empty array.`,\n { caseIndex },\n );\n }\n\n const steps = normalizeSteps(definition.steps).map(\n (normalized, stepIndex) => {\n if (!options.resolveNode(normalized.node)) {\n throw new WorkflowParseError(\n `Case ${caseIndex + 1} step ${stepIndex + 1} references unknown node \"${normalized.node}\".`,\n { caseIndex, stepIndex, node: normalized.node },\n );\n }\n return normalized;\n },\n );\n const caseId = createCaseId(source.projectId, sourcePath, caseIndex);\n if (ids.has(caseId)) {\n throw new WorkflowParseError(`Case id collision: ${caseId}.`, {\n caseId,\n });\n }\n ids.add(caseId);\n\n return {\n caseId,\n projectId: source.projectId,\n sourcePath,\n caseIndex,\n definition: { name: definition.name, steps },\n };\n });\n\n return {\n documentId: createWorkflowDocumentId(source.projectId, sourcePath),\n projectId: source.projectId,\n sourcePath,\n lifecycle,\n cases,\n } satisfies CollectedWorkflowDocument;\n}\n"],"names":["WorkflowError","Error","undefined","message","options","WorkflowParseError","details","cause","NodeDefinitionError","DuplicateNodeError","node","NodeNotFoundError","NodeInputValidationError","StepTimeoutError","timeoutMs","NodeExecutionError","causeMessage","String","WorkflowDocumentSetupError","WorkflowDocumentTeardownError","WorkflowLifecycleError","CaseExecutionError","result","WorkflowDocumentExecutionError","normalizeNodeExecutionError","error","supportedMetaKeys","Set","isMapping","value","Array","Object","formatStep","index","normalizeMeta","key","timeout","Number","continueOnError","validateCommonNodeInput","input","normalizeStep","entries","rawValue","rawMeta","normalizeSteps","steps","step","validateDefinition","defineNode","_nodes","NodeRegistry","name","nodes","Map","validateNodeOutput","output","TypeError","createStepResultBase","startedAt","phase","stepIndex","endedAt","Date","Math","executeNode","execute","abortController","AbortController","timeoutError","execution","Promise","timedExecution","_","reject","setTimeout","clearTimeout","executeStep","target","context","signal","common","runCollectedCase","collectedCase","phases","runId","randomUUID","beforeEach","afterEach","completedNodes","runPhase","results","caseContext","stepInfo","CaseRunner","fatalStepError","createCaseRunner","createDocumentRuntime","document","documentRunId","beforeAll","afterAll","info","caseDefinition","process","teardownStack","acceptingTeardowns","setupError","started","finishedResult","createResult","teardownErrors","documentContext","onTeardown","teardown","statusBeforeTeardown","registrationIndex","asNotRun","reason","runWorkflowDocument","createDocumentRunId","createCaseRunId","runtime","cases","runtimeStarted","documentResult","executionError","run","rejectUnknownKeys","allowed","label","allowedSet","unknown","createCaseId","projectId","sourcePath","caseIndex","createHash","JSON","createWorkflowDocumentId","collectWorkflowDocument","source","parsed","loadYaml","readFileSync","JSON_SCHEMA","sep","normalizeLifecycle","normalized","resolved","lifecycle","ids","definition","caseId"],"mappings":";;;;;;;;;;;;;;AAMO,MAAMA,sBAAsBC;IAWjC,SAAkC;QAChC,OAAO;YACL,MAAM,IAAI,CAAC,IAAI;YACf,SAAS,IAAI,CAAC,OAAO;YACrB,MAAM,IAAI,CAAC,IAAI;YACf,GAAI,AAAiBC,WAAjB,IAAI,CAAC,OAAO,GAAiB,CAAC,IAAI;gBAAE,SAAS,IAAI,CAAC,OAAO;YAAC,CAAC;QACjE;IACF;IAdA,YAAYC,OAAe,EAAEC,UAAgC,CAAC,CAAC,CAAE;QAC/D,KAAK,CAACD,SAAS;YAAE,OAAOC,QAAQ,KAAK;QAAC,IAJxC,u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,CAAC,EACxD;YAAEA;QAAU;QAIhB,MAAM1F,QAAQD,eAAe2G,WAAW,KAAK,EAAE,GAAG,CAChD,CAACJ,YAAYvF;YACX,IAAI,CAACzD,QAAQ,WAAW,CAACgJ,WAAW,IAAI,GACtC,MAAM,IAAI/I,mBACR,CAAC,KAAK,EAAEmI,YAAY,EAAE,MAAM,EAAE3E,YAAY,EAAE,0BAA0B,EAAEuF,WAAW,IAAI,CAAC,EAAE,CAAC,EAC3F;gBAAEZ;gBAAW3E;gBAAW,MAAMuF,WAAW,IAAI;YAAC;YAGlD,OAAOA;QACT;QAEF,MAAMK,SAASpB,aAAaQ,OAAO,SAAS,EAAEN,YAAYC;QAC1D,IAAIe,IAAI,GAAG,CAACE,SACV,MAAM,IAAIpJ,mBAAmB,CAAC,mBAAmB,EAAEoJ,OAAO,CAAC,CAAC,EAAE;YAC5DA;QACF;QAEFF,IAAI,GAAG,CAACE;QAER,OAAO;YACLA;YACA,WAAWZ,OAAO,SAAS;YAC3BN;YACAC;YACA,YAAY;gBAAE,MAAMgB,WAAW,IAAI;gBAAE1G;YAAM;QAC7C;IACF;IAEA,OAAO;QACL,YAAY6F,yBAAyBE,OAAO,SAAS,EAAEN;QACvD,WAAWM,OAAO,SAAS;QAC3BN;QACAe;QACA3B;IACF;AACF"}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
3
|
+
value: value,
|
|
4
|
+
enumerable: true,
|
|
5
|
+
configurable: true,
|
|
6
|
+
writable: true
|
|
7
|
+
});
|
|
8
|
+
else obj[key] = value;
|
|
9
|
+
return obj;
|
|
10
|
+
}
|
|
11
|
+
class WorkflowError extends Error {
|
|
12
|
+
toJSON() {
|
|
13
|
+
return {
|
|
14
|
+
name: this.name,
|
|
15
|
+
message: this.message,
|
|
16
|
+
code: this.code,
|
|
17
|
+
...void 0 === this.details ? {} : {
|
|
18
|
+
details: this.details
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
constructor(message, options = {}){
|
|
23
|
+
super(message, {
|
|
24
|
+
cause: options.cause
|
|
25
|
+
}), _define_property(this, "code", void 0), _define_property(this, "details", void 0);
|
|
26
|
+
this.name = new.target.name;
|
|
27
|
+
this.code = options.code ?? 'WORKFLOW_ERROR';
|
|
28
|
+
this.details = options.details;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
class NodeDefinitionError extends WorkflowError {
|
|
32
|
+
constructor(message, details){
|
|
33
|
+
super(message, {
|
|
34
|
+
code: 'NODE_DEFINITION_ERROR',
|
|
35
|
+
details
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
class NodeExecutionError extends WorkflowError {
|
|
40
|
+
constructor(node, cause){
|
|
41
|
+
const causeMessage = cause instanceof Error ? cause.message : String(cause ?? 'Unknown error');
|
|
42
|
+
super(`Node "${node}" failed: ${causeMessage}`, {
|
|
43
|
+
code: 'NODE_EXECUTION_ERROR',
|
|
44
|
+
details: {
|
|
45
|
+
node
|
|
46
|
+
},
|
|
47
|
+
cause
|
|
48
|
+
}), _define_property(this, "node", void 0);
|
|
49
|
+
this.node = node;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const validateDefinition = (options)=>{
|
|
53
|
+
if (!options || 'object' != typeof options) throw new NodeDefinitionError('Node definition must be an object.');
|
|
54
|
+
if ('string' != typeof options.name || 0 === options.name.trim().length) throw new NodeDefinitionError('Node name must be a non-empty string.');
|
|
55
|
+
if ('function' != typeof options.execute) throw new NodeDefinitionError(`Node "${options.name}" must provide an execute function.`, {
|
|
56
|
+
node: options.name
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
function defineNode(options) {
|
|
60
|
+
validateDefinition(options);
|
|
61
|
+
return options;
|
|
62
|
+
}
|
|
63
|
+
const isRecord = (value)=>'object' == typeof value && null !== value && !Array.isArray(value);
|
|
64
|
+
const validateAllowedKeys = (value, allowedKeys, label)=>{
|
|
65
|
+
const allowed = new Set(allowedKeys);
|
|
66
|
+
const unsupported = Object.keys(value).find((key)=>!allowed.has(key));
|
|
67
|
+
if (unsupported) throw new TypeError(`${label} has unsupported option "${unsupported}".`);
|
|
68
|
+
};
|
|
69
|
+
const requirePrompt = (input, node)=>{
|
|
70
|
+
if ('string' != typeof input.prompt || 0 === input.prompt.trim().length) throw new TypeError(`Node "${node}" requires a non-empty prompt.`);
|
|
71
|
+
return input.prompt;
|
|
72
|
+
};
|
|
73
|
+
function validateOptionalString(value, label) {
|
|
74
|
+
if (void 0 !== value && 'string' != typeof value) throw new TypeError(`${label} must be a string.`);
|
|
75
|
+
}
|
|
76
|
+
const validateAiActOptions = (value)=>{
|
|
77
|
+
if (void 0 === value) return;
|
|
78
|
+
if (!isRecord(value)) throw new TypeError('aiAct options must be a mapping.');
|
|
79
|
+
validateAllowedKeys(value, [
|
|
80
|
+
'cacheable',
|
|
81
|
+
'fileChooserAccept',
|
|
82
|
+
'deepThink',
|
|
83
|
+
'deepLocate',
|
|
84
|
+
'context'
|
|
85
|
+
], 'aiAct options');
|
|
86
|
+
if (void 0 !== value.cacheable && 'boolean' != typeof value.cacheable) throw new TypeError('aiAct options.cacheable must be a boolean.');
|
|
87
|
+
if (void 0 !== value.fileChooserAccept && 'string' != typeof value.fileChooserAccept && !(Array.isArray(value.fileChooserAccept) && value.fileChooserAccept.every((item)=>'string' == typeof item))) throw new TypeError('aiAct options.fileChooserAccept must be a string or string array.');
|
|
88
|
+
if (void 0 !== value.deepThink && 'unset' !== value.deepThink && 'boolean' != typeof value.deepThink) throw new TypeError('aiAct options.deepThink must be a boolean or "unset".');
|
|
89
|
+
if (void 0 !== value.deepLocate && 'boolean' != typeof value.deepLocate) throw new TypeError('aiAct options.deepLocate must be a boolean.');
|
|
90
|
+
validateOptionalString(value.context, 'aiAct options.context');
|
|
91
|
+
return value;
|
|
92
|
+
};
|
|
93
|
+
const validateAiAssertOptions = (value)=>{
|
|
94
|
+
if (void 0 === value) return;
|
|
95
|
+
if (!isRecord(value)) throw new TypeError('aiAssert options must be a mapping.');
|
|
96
|
+
validateAllowedKeys(value, [
|
|
97
|
+
'domIncluded',
|
|
98
|
+
'screenshotIncluded',
|
|
99
|
+
'context'
|
|
100
|
+
], 'aiAssert options');
|
|
101
|
+
if (void 0 !== value.domIncluded && 'visible-only' !== value.domIncluded && 'boolean' != typeof value.domIncluded) throw new TypeError('aiAssert options.domIncluded must be a boolean or "visible-only".');
|
|
102
|
+
if (void 0 !== value.screenshotIncluded && 'boolean' != typeof value.screenshotIncluded) throw new TypeError('aiAssert options.screenshotIncluded must be a boolean.');
|
|
103
|
+
validateOptionalString(value.context, 'aiAssert options.context');
|
|
104
|
+
return value;
|
|
105
|
+
};
|
|
106
|
+
const validateReportInput = (input)=>{
|
|
107
|
+
validateOptionalString(input.prompt, 'recordToReport prompt');
|
|
108
|
+
validateOptionalString(input.title, 'recordToReport title');
|
|
109
|
+
validateOptionalString(input.content, 'recordToReport content');
|
|
110
|
+
validateOptionalString(input.screenshotBase64, 'recordToReport screenshotBase64');
|
|
111
|
+
if (void 0 !== input.prompt && void 0 !== input.title) throw new TypeError('recordToReport accepts either string shorthand or title, not both.');
|
|
112
|
+
if (void 0 !== input.screenshots) {
|
|
113
|
+
if (!Array.isArray(input.screenshots) || 0 === input.screenshots.length) throw new TypeError('recordToReport screenshots must be a non-empty array.');
|
|
114
|
+
for (const [index, screenshot] of input.screenshots.entries()){
|
|
115
|
+
if (!isRecord(screenshot) || 'string' != typeof screenshot.base64 || 0 === screenshot.base64.length) throw new TypeError(`recordToReport screenshot ${index + 1} requires base64.`);
|
|
116
|
+
validateAllowedKeys(screenshot, [
|
|
117
|
+
'base64',
|
|
118
|
+
"description"
|
|
119
|
+
], `recordToReport screenshot ${index + 1}`);
|
|
120
|
+
validateOptionalString(screenshot.description, `recordToReport screenshot ${index + 1} description`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (void 0 !== input.screenshotBase64 && void 0 !== input.screenshots) throw new TypeError('recordToReport accepts either screenshotBase64 or screenshots, not both.');
|
|
124
|
+
return {
|
|
125
|
+
...input.title ?? input.prompt ? {
|
|
126
|
+
title: input.title ?? input.prompt
|
|
127
|
+
} : {},
|
|
128
|
+
options: {
|
|
129
|
+
...void 0 === input.content ? {} : {
|
|
130
|
+
content: input.content
|
|
131
|
+
},
|
|
132
|
+
...void 0 === input.screenshotBase64 ? {} : {
|
|
133
|
+
screenshotBase64: input.screenshotBase64
|
|
134
|
+
},
|
|
135
|
+
...void 0 === input.screenshots ? {} : {
|
|
136
|
+
screenshots: input.screenshots
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
};
|
|
141
|
+
const requireAgentMethod = (agent, method, node)=>{
|
|
142
|
+
if (!isRecord(agent) || 'function' != typeof agent[method]) throw new NodeExecutionError(node, new TypeError(`getAgent() must return an Agent with ${method}().`));
|
|
143
|
+
return agent[method];
|
|
144
|
+
};
|
|
145
|
+
function createMidsceneNodes(options) {
|
|
146
|
+
if (!options || 'object' != typeof options) throw new NodeDefinitionError('createMidsceneNodes() options must be an object.');
|
|
147
|
+
if ('function' != typeof options.getAgent) throw new NodeDefinitionError('createMidsceneNodes() requires a getAgent function.');
|
|
148
|
+
return [
|
|
149
|
+
defineNode({
|
|
150
|
+
name: 'aiAct',
|
|
151
|
+
async execute (ctx) {
|
|
152
|
+
const prompt = requirePrompt(ctx.input, 'aiAct');
|
|
153
|
+
const nodeOptions = validateAiActOptions(ctx.input.options);
|
|
154
|
+
const agent = await options.getAgent(ctx);
|
|
155
|
+
const aiAct = requireAgentMethod(agent, 'aiAct', 'aiAct');
|
|
156
|
+
const output = await aiAct.call(agent, prompt, {
|
|
157
|
+
...nodeOptions,
|
|
158
|
+
abortSignal: ctx.signal
|
|
159
|
+
});
|
|
160
|
+
return void 0 === output ? void 0 : {
|
|
161
|
+
summary: output
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
}),
|
|
165
|
+
defineNode({
|
|
166
|
+
name: 'aiAssert',
|
|
167
|
+
async execute (ctx) {
|
|
168
|
+
const prompt = requirePrompt(ctx.input, 'aiAssert');
|
|
169
|
+
validateOptionalString(ctx.input.message, 'aiAssert message');
|
|
170
|
+
const nodeOptions = validateAiAssertOptions(ctx.input.options);
|
|
171
|
+
const agent = await options.getAgent(ctx);
|
|
172
|
+
const aiAssert = requireAgentMethod(agent, 'aiAssert', 'aiAssert');
|
|
173
|
+
await aiAssert.call(agent, prompt, ctx.input.message, {
|
|
174
|
+
...nodeOptions,
|
|
175
|
+
abortSignal: ctx.signal
|
|
176
|
+
});
|
|
177
|
+
return {
|
|
178
|
+
summary: `Assertion passed: ${prompt}`
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
}),
|
|
182
|
+
defineNode({
|
|
183
|
+
name: 'recordToReport',
|
|
184
|
+
async execute (ctx) {
|
|
185
|
+
const { title, options: reportOptions } = validateReportInput(ctx.input);
|
|
186
|
+
const agent = await options.getAgent(ctx);
|
|
187
|
+
const recordToReport = requireAgentMethod(agent, 'recordToReport', 'recordToReport');
|
|
188
|
+
await recordToReport.call(agent, title, reportOptions);
|
|
189
|
+
return {
|
|
190
|
+
summary: `Recorded to report: ${title ?? 'untitled'}`
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
})
|
|
194
|
+
];
|
|
195
|
+
}
|
|
196
|
+
export { createMidsceneNodes };
|
|
197
|
+
|
|
198
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"midscene/index.mjs","sources":["../../../src/errors.ts","../../../src/node/define-node.ts","../../../src/midscene/index.ts"],"sourcesContent":["export interface WorkflowErrorOptions {\n code?: string;\n details?: unknown;\n cause?: unknown;\n}\n\nexport class WorkflowError extends Error {\n readonly code: string;\n readonly details?: unknown;\n\n constructor(message: string, options: WorkflowErrorOptions = {}) {\n super(message, { cause: options.cause });\n this.name = new.target.name;\n this.code = options.code ?? 'WORKFLOW_ERROR';\n this.details = options.details;\n }\n\n toJSON(): Record<string, unknown> {\n return {\n name: this.name,\n message: this.message,\n code: this.code,\n ...(this.details === undefined ? {} : { details: this.details }),\n };\n }\n}\n\nexport class WorkflowParseError extends WorkflowError {\n constructor(message: string, details?: unknown, cause?: unknown) {\n super(message, { code: 'WORKFLOW_PARSE_ERROR', details, cause });\n }\n}\n\nexport class NodeDefinitionError extends WorkflowError {\n constructor(message: string, details?: unknown) {\n super(message, { code: 'NODE_DEFINITION_ERROR', details });\n }\n}\n\nexport class DuplicateNodeError extends WorkflowError {\n readonly node: string;\n\n constructor(node: string) {\n super(`Node \"${node}\" is already registered.`, {\n code: 'DUPLICATE_NODE',\n details: { node },\n });\n this.node = node;\n }\n}\n\nexport class NodeNotFoundError extends WorkflowError {\n readonly node: string;\n\n constructor(node: string) {\n super(`Node \"${node}\" is not registered.`, {\n code: 'NODE_NOT_FOUND',\n details: { node },\n });\n this.node = node;\n }\n}\n\nexport class NodeInputValidationError extends WorkflowError {\n constructor(message: string, details?: unknown) {\n super(message, { code: 'NODE_INPUT_VALIDATION_ERROR', details });\n }\n}\n\nexport class StepTimeoutError extends WorkflowError {\n readonly timeoutMs: number;\n readonly node?: string;\n\n constructor(timeoutMs: number, node?: string) {\n super(\n node\n ? `Node \"${node}\" timed out after ${timeoutMs}ms.`\n : `Step timed out after ${timeoutMs}ms.`,\n {\n code: 'STEP_TIMEOUT',\n details: { timeoutMs, ...(node === undefined ? {} : { node }) },\n },\n );\n this.timeoutMs = timeoutMs;\n this.node = node;\n }\n}\n\nexport class NodeExecutionError extends WorkflowError {\n readonly node: string;\n\n constructor(node: string, cause: unknown) {\n const causeMessage =\n cause instanceof Error ? cause.message : String(cause ?? 'Unknown error');\n super(`Node \"${node}\" failed: ${causeMessage}`, {\n code: 'NODE_EXECUTION_ERROR',\n details: { node },\n cause,\n });\n this.node = node;\n }\n}\n\nexport class WorkflowDocumentSetupError extends WorkflowError {\n constructor(\n cause: unknown,\n details: { documentId: string; documentRunId: string },\n ) {\n const causeMessage =\n cause instanceof Error ? cause.message : String(cause ?? 'Unknown error');\n super(`Workflow document setup failed: ${causeMessage}`, {\n code: 'WORKFLOW_DOCUMENT_SETUP_ERROR',\n details,\n cause,\n });\n }\n}\n\nexport class WorkflowDocumentTeardownError extends WorkflowError {\n constructor(\n cause: unknown,\n details: {\n documentId: string;\n documentRunId: string;\n registrationIndex: number;\n },\n ) {\n const causeMessage =\n cause instanceof Error ? cause.message : String(cause ?? 'Unknown error');\n super(`Workflow document teardown failed: ${causeMessage}`, {\n code: 'WORKFLOW_DOCUMENT_TEARDOWN_ERROR',\n details,\n cause,\n });\n }\n}\n\nexport class WorkflowLifecycleError extends WorkflowError {\n constructor(message: string, details?: unknown) {\n super(message, { code: 'WORKFLOW_LIFECYCLE_ERROR', details });\n }\n}\n\nexport class CaseExecutionError extends WorkflowError {\n readonly result: import('./engine/types').CaseRunResult;\n\n constructor(result: import('./engine/types').CaseRunResult) {\n super(`Case \"${result.name}\" failed.`, {\n code: 'CASE_EXECUTION_FAILED',\n details: { caseId: result.caseId, runId: result.runId },\n });\n this.result = result;\n }\n}\n\nexport class WorkflowDocumentExecutionError extends WorkflowError {\n readonly result: import('./engine/types').WorkflowDocumentRunResult;\n\n constructor(result: import('./engine/types').WorkflowDocumentRunResult) {\n super(`Workflow document \"${result.sourcePath}\" failed.`, {\n code: 'WORKFLOW_DOCUMENT_EXECUTION_FAILED',\n details: {\n documentId: result.documentId,\n documentRunId: result.documentRunId,\n },\n });\n this.result = result;\n }\n}\n\nexport function normalizeNodeExecutionError(\n error: unknown,\n node: string,\n): WorkflowError {\n return error instanceof WorkflowError\n ? error\n : new NodeExecutionError(node, error);\n}\n","import { NodeDefinitionError } from '../errors';\nimport type { DefineNodeOptions, NodeDefinition } from './types';\n\nconst validateDefinition = (options: {\n name: string;\n execute: unknown;\n}): void => {\n if (!options || typeof options !== 'object') {\n throw new NodeDefinitionError('Node definition must be an object.');\n }\n\n if (typeof options.name !== 'string' || options.name.trim().length === 0) {\n throw new NodeDefinitionError('Node name must be a non-empty string.');\n }\n\n if (typeof options.execute !== 'function') {\n throw new NodeDefinitionError(\n `Node \"${options.name}\" must provide an execute function.`,\n { node: options.name },\n );\n }\n};\n\nexport function defineNode<\n TInput = unknown,\n TData = unknown,\n TContext = unknown,\n>(\n options: DefineNodeOptions<TInput, TData, TContext>,\n): NodeDefinition<TInput, TData, TContext> {\n validateDefinition(options);\n return options;\n}\n","import type { Awaitable } from '../engine/types';\nimport { NodeDefinitionError, NodeExecutionError } from '../errors';\nimport { defineNode } from '../node/define-node';\nimport type { NodeDefinition, NodeExecutionContext } from '../node/types';\n\nexport interface MidsceneAiActOptions {\n cacheable?: boolean;\n fileChooserAccept?: string | string[];\n deepThink?: 'unset' | boolean;\n deepLocate?: boolean;\n context?: string;\n abortSignal?: AbortSignal;\n}\n\nexport interface MidsceneAiAssertOptions {\n domIncluded?: boolean | 'visible-only';\n screenshotIncluded?: boolean;\n context?: string;\n abortSignal?: AbortSignal;\n keepRawResponse?: boolean;\n}\n\nexport interface MidsceneReportScreenshot {\n base64: string;\n description?: string;\n}\n\nexport interface MidsceneRecordToReportOptions {\n content?: string;\n screenshotBase64?: string;\n screenshots?: MidsceneReportScreenshot[];\n}\n\nexport interface MidsceneUIAgent {\n aiAct(\n prompt: string,\n options?: MidsceneAiActOptions,\n ): Promise<string | undefined>;\n aiAssert(\n prompt: string,\n message?: string,\n options?: MidsceneAiAssertOptions,\n ): Promise<unknown>;\n recordToReport(\n title?: string,\n options?: MidsceneRecordToReportOptions,\n ): Promise<unknown>;\n}\n\nexport interface AiActNodeInput {\n prompt?: string;\n options?: Omit<MidsceneAiActOptions, 'abortSignal'>;\n}\n\nexport interface AiAssertNodeInput {\n prompt?: string;\n message?: string;\n options?: Omit<MidsceneAiAssertOptions, 'abortSignal' | 'keepRawResponse'>;\n}\n\nexport interface RecordToReportNodeInput {\n /** String shorthand is normalized into prompt and used as the title. */\n prompt?: string;\n title?: string;\n content?: string;\n screenshotBase64?: string;\n screenshots?: MidsceneReportScreenshot[];\n}\n\nexport interface CreateMidsceneNodesOptions<TContext> {\n getAgent(\n ctx: NodeExecutionContext<unknown, TContext>,\n ): Awaitable<MidsceneUIAgent>;\n}\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\nconst validateAllowedKeys = (\n value: Record<string, unknown>,\n allowedKeys: readonly string[],\n label: string,\n) => {\n const allowed = new Set(allowedKeys);\n const unsupported = Object.keys(value).find((key) => !allowed.has(key));\n if (unsupported) {\n throw new TypeError(`${label} has unsupported option \"${unsupported}\".`);\n }\n};\n\nconst requirePrompt = (input: { prompt?: string }, node: string): string => {\n if (typeof input.prompt !== 'string' || input.prompt.trim().length === 0) {\n throw new TypeError(`Node \"${node}\" requires a non-empty prompt.`);\n }\n return input.prompt;\n};\n\nfunction validateOptionalString(\n value: unknown,\n label: string,\n): asserts value is string | undefined {\n if (value !== undefined && typeof value !== 'string') {\n throw new TypeError(`${label} must be a string.`);\n }\n}\n\nconst validateAiActOptions = (\n value: unknown,\n): Omit<MidsceneAiActOptions, 'abortSignal'> | undefined => {\n if (value === undefined) return undefined;\n if (!isRecord(value)) throw new TypeError('aiAct options must be a mapping.');\n validateAllowedKeys(\n value,\n ['cacheable', 'fileChooserAccept', 'deepThink', 'deepLocate', 'context'],\n 'aiAct options',\n );\n if (value.cacheable !== undefined && typeof value.cacheable !== 'boolean') {\n throw new TypeError('aiAct options.cacheable must be a boolean.');\n }\n if (\n value.fileChooserAccept !== undefined &&\n typeof value.fileChooserAccept !== 'string' &&\n !(\n Array.isArray(value.fileChooserAccept) &&\n value.fileChooserAccept.every((item) => typeof item === 'string')\n )\n ) {\n throw new TypeError(\n 'aiAct options.fileChooserAccept must be a string or string array.',\n );\n }\n if (\n value.deepThink !== undefined &&\n value.deepThink !== 'unset' &&\n typeof value.deepThink !== 'boolean'\n ) {\n throw new TypeError(\n 'aiAct options.deepThink must be a boolean or \"unset\".',\n );\n }\n if (value.deepLocate !== undefined && typeof value.deepLocate !== 'boolean') {\n throw new TypeError('aiAct options.deepLocate must be a boolean.');\n }\n validateOptionalString(value.context, 'aiAct options.context');\n return value as Omit<MidsceneAiActOptions, 'abortSignal'>;\n};\n\nconst validateAiAssertOptions = (\n value: unknown,\n):\n | Omit<MidsceneAiAssertOptions, 'abortSignal' | 'keepRawResponse'>\n | undefined => {\n if (value === undefined) return undefined;\n if (!isRecord(value)) {\n throw new TypeError('aiAssert options must be a mapping.');\n }\n validateAllowedKeys(\n value,\n ['domIncluded', 'screenshotIncluded', 'context'],\n 'aiAssert options',\n );\n if (\n value.domIncluded !== undefined &&\n value.domIncluded !== 'visible-only' &&\n typeof value.domIncluded !== 'boolean'\n ) {\n throw new TypeError(\n 'aiAssert options.domIncluded must be a boolean or \"visible-only\".',\n );\n }\n if (\n value.screenshotIncluded !== undefined &&\n typeof value.screenshotIncluded !== 'boolean'\n ) {\n throw new TypeError(\n 'aiAssert options.screenshotIncluded must be a boolean.',\n );\n }\n validateOptionalString(value.context, 'aiAssert options.context');\n return value as Omit<\n MidsceneAiAssertOptions,\n 'abortSignal' | 'keepRawResponse'\n >;\n};\n\nconst validateReportInput = (\n input: RecordToReportNodeInput,\n): {\n title?: string;\n options: MidsceneRecordToReportOptions;\n} => {\n validateOptionalString(input.prompt, 'recordToReport prompt');\n validateOptionalString(input.title, 'recordToReport title');\n validateOptionalString(input.content, 'recordToReport content');\n validateOptionalString(\n input.screenshotBase64,\n 'recordToReport screenshotBase64',\n );\n if (input.prompt !== undefined && input.title !== undefined) {\n throw new TypeError(\n 'recordToReport accepts either string shorthand or title, not both.',\n );\n }\n if (input.screenshots !== undefined) {\n if (!Array.isArray(input.screenshots) || input.screenshots.length === 0) {\n throw new TypeError(\n 'recordToReport screenshots must be a non-empty array.',\n );\n }\n for (const [index, screenshot] of input.screenshots.entries()) {\n if (\n !isRecord(screenshot) ||\n typeof screenshot.base64 !== 'string' ||\n screenshot.base64.length === 0\n ) {\n throw new TypeError(\n `recordToReport screenshot ${index + 1} requires base64.`,\n );\n }\n validateAllowedKeys(\n screenshot,\n ['base64', 'description'],\n `recordToReport screenshot ${index + 1}`,\n );\n validateOptionalString(\n screenshot.description,\n `recordToReport screenshot ${index + 1} description`,\n );\n }\n }\n if (input.screenshotBase64 !== undefined && input.screenshots !== undefined) {\n throw new TypeError(\n 'recordToReport accepts either screenshotBase64 or screenshots, not both.',\n );\n }\n\n return {\n ...((input.title ?? input.prompt)\n ? { title: input.title ?? input.prompt }\n : {}),\n options: {\n ...(input.content === undefined ? {} : { content: input.content }),\n ...(input.screenshotBase64 === undefined\n ? {}\n : { screenshotBase64: input.screenshotBase64 }),\n ...(input.screenshots === undefined\n ? {}\n : { screenshots: input.screenshots }),\n },\n };\n};\n\nconst requireAgentMethod = <TMethod extends keyof MidsceneUIAgent>(\n agent: MidsceneUIAgent,\n method: TMethod,\n node: string,\n): MidsceneUIAgent[TMethod] => {\n if (!isRecord(agent) || typeof agent[method] !== 'function') {\n throw new NodeExecutionError(\n node,\n new TypeError(`getAgent() must return an Agent with ${method}().`),\n );\n }\n return agent[method];\n};\n\nexport function createMidsceneNodes<TContext>(\n options: CreateMidsceneNodesOptions<TContext>,\n): readonly NodeDefinition<any, any, TContext>[] {\n if (!options || typeof options !== 'object') {\n throw new NodeDefinitionError(\n 'createMidsceneNodes() options must be an object.',\n );\n }\n if (typeof options.getAgent !== 'function') {\n throw new NodeDefinitionError(\n 'createMidsceneNodes() requires a getAgent function.',\n );\n }\n\n return [\n defineNode<AiActNodeInput, unknown, TContext>({\n name: 'aiAct',\n async execute(ctx) {\n const prompt = requirePrompt(ctx.input, 'aiAct');\n const nodeOptions = validateAiActOptions(ctx.input.options);\n const agent = await options.getAgent(ctx);\n const aiAct = requireAgentMethod(agent, 'aiAct', 'aiAct');\n const output = await aiAct.call(agent, prompt, {\n ...nodeOptions,\n abortSignal: ctx.signal,\n });\n return output === undefined ? undefined : { summary: output };\n },\n }),\n defineNode<AiAssertNodeInput, unknown, TContext>({\n name: 'aiAssert',\n async execute(ctx) {\n const prompt = requirePrompt(ctx.input, 'aiAssert');\n validateOptionalString(ctx.input.message, 'aiAssert message');\n const nodeOptions = validateAiAssertOptions(ctx.input.options);\n const agent = await options.getAgent(ctx);\n const aiAssert = requireAgentMethod(agent, 'aiAssert', 'aiAssert');\n await aiAssert.call(agent, prompt, ctx.input.message, {\n ...nodeOptions,\n abortSignal: ctx.signal,\n });\n return { summary: `Assertion passed: ${prompt}` };\n },\n }),\n defineNode<RecordToReportNodeInput, unknown, TContext>({\n name: 'recordToReport',\n async execute(ctx) {\n const { title, options: reportOptions } = validateReportInput(\n ctx.input,\n );\n const agent = await options.getAgent(ctx);\n const recordToReport = requireAgentMethod(\n agent,\n 'recordToReport',\n 'recordToReport',\n );\n await recordToReport.call(agent, title, reportOptions);\n return { summary: `Recorded to report: ${title ?? 'untitled'}` };\n },\n }),\n ];\n}\n"],"names":["WorkflowError","Error","undefined","message","options","NodeDefinitionError","details","NodeExecutionError","node","cause","causeMessage","String","validateDefinition","defineNode","isRecord","value","Array","validateAllowedKeys","allowedKeys","label","allowed","Set","unsupported","Object","key","TypeError","requirePrompt","input","validateOptionalString","validateAiActOptions","item","validateAiAssertOptions","validateReportInput","index","screenshot","requireAgentMethod","agent","method","createMidsceneNodes","ctx","prompt","nodeOptions","aiAct","output","aiAssert","title","reportOptions","recordToReport"],"mappings":";;;;;;;;;;AAMO,MAAMA,sBAAsBC;IAWjC,SAAkC;QAChC,OAAO;YACL,MAAM,IAAI,CAAC,IAAI;YACf,SAAS,IAAI,CAAC,OAAO;YACrB,MAAM,IAAI,CAAC,IAAI;YACf,GAAI,AAAiBC,WAAjB,IAAI,CAAC,OAAO,GAAiB,CAAC,IAAI;gBAAE,SAAS,IAAI,CAAC,OAAO;YAAC,CAAC;QACjE;IACF;IAdA,YAAYC,OAAe,EAAEC,UAAgC,CAAC,CA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