@midscene/test 1.12.2-beta-20260828074555.0 → 1.12.2

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.
@@ -310,13 +310,11 @@ function createMidsceneNodes(options) {
310
310
  async execute (ctx) {
311
311
  const agent = await getAgent(ctx);
312
312
  const aiAct = requireAgentMethod(agent, 'aiAct', 'aiAct');
313
- const aiActOptions = {
313
+ const output = await aiAct.call(agent, toAgentPrompt(ctx.input), {
314
314
  ...ctx.input.options,
315
315
  context: mergeContext(ctx.input.options?.context, ctx.history),
316
- abortSignal: ctx.signal,
317
- _internalContextMode: 'append'
318
- };
319
- const output = await aiAct.call(agent, toAgentPrompt(ctx.input), aiActOptions);
316
+ abortSignal: ctx.signal
317
+ });
320
318
  return void 0 === output ? void 0 : {
321
319
  summary: output
322
320
  };
@@ -1 +1 @@
1
- {"version":3,"file":"midscene/index.mjs","sources":["../../../src/errors.ts","../../../src/node/define-node.ts","../../../src/device/lifecycle.ts","../../../src/midscene/index.ts"],"sourcesContent":["import type { z } from 'zod/v4';\n\nexport 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 static fromZod(node: string, error: z.ZodError): NodeInputValidationError {\n const issues = error.issues.map((issue) => ({\n code: issue.code,\n path: issue.path.map(String).join('.'),\n message: issue.message,\n }));\n const firstIssue = issues[0];\n const path = firstIssue?.path || '<root>';\n const message = firstIssue?.message ?? 'invalid input';\n return new NodeInputValidationError(\n `Node \"${node}\" input validation failed at \"${path}\": ${message}`,\n { node, issues },\n );\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 WorkflowLifecycleError extends WorkflowError {\n constructor(message: string, details?: unknown) {\n super(message, { code: 'WORKFLOW_LIFECYCLE_ERROR', details });\n }\n}\n\nexport class ProjectSetupError extends WorkflowError {\n constructor(cause: unknown, details: { projectName: string }) {\n const causeMessage =\n cause instanceof Error ? cause.message : String(cause ?? 'Unknown error');\n super(`Project \"${details.projectName}\" setup failed: ${causeMessage}`, {\n code: 'PROJECT_SETUP_ERROR',\n details,\n cause,\n });\n }\n}\n\nexport class ProjectTeardownError extends WorkflowError {\n constructor(\n cause: unknown,\n details: { projectName: string; registrationIndex: number },\n ) {\n const causeMessage =\n cause instanceof Error ? cause.message : String(cause ?? 'Unknown error');\n super(`Project \"${details.projectName}\" teardown failed: ${causeMessage}`, {\n code: 'PROJECT_TEARDOWN_ERROR',\n details,\n cause,\n });\n }\n}\n\nexport class NodeScopeTeardownError extends WorkflowError {\n constructor(\n cause: unknown,\n details: {\n scope: 'case' | 'document';\n scopeId: string;\n node: string;\n registrationIndex: number;\n },\n ) {\n const causeMessage =\n cause instanceof Error ? cause.message : String(cause ?? 'Unknown error');\n super(\n `${details.scope === 'case' ? 'Case attempt' : 'Workflow document'} node teardown failed for \"${details.node}\": ${causeMessage}`,\n { code: 'NODE_SCOPE_TEARDOWN_ERROR', details, cause },\n );\n }\n}\n\nexport class FatalDeviceError extends WorkflowError {\n constructor(message: string, cause?: unknown) {\n super(message, { code: 'FATAL_DEVICE_ERROR', cause });\n }\n}\n\nexport const isFatalDeviceError = (error: unknown): boolean => {\n if (error instanceof FatalDeviceError) return true;\n if (error instanceof WorkflowError && error.code === 'FATAL_DEVICE_ERROR') {\n return true;\n }\n if (\n error instanceof Error &&\n /device offline|device not found|(?:adb|bdc|device) connection (?:was )?closed/i.test(\n error.message,\n )\n ) {\n return true;\n }\n return error instanceof Error && error.cause !== undefined\n ? isFatalDeviceError(error.cause)\n : false;\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 { z } from 'zod/v4';\nimport { NodeDefinitionError } from '../errors';\nimport type {\n DefineNodeOptions,\n DefineNodeWithSchemaOptions,\n NodeDefinition,\n NodeDefinitionWithSchema,\n NodeInputSchema,\n} from './types';\n\nconst validateOptionalText = (\n value: unknown,\n field: 'title' | 'description',\n node: string,\n): void => {\n if (\n value !== undefined &&\n (typeof value !== 'string' || value.trim().length === 0)\n ) {\n throw new NodeDefinitionError(\n `Node \"${node}\" ${field} must be a non-empty string.`,\n { node, field },\n );\n }\n};\n\nconst validateInputSchema = (schema: unknown, node: string): void => {\n if (schema === undefined) return;\n if (!(schema instanceof z.ZodObject)) {\n throw new NodeDefinitionError(\n `Node \"${node}\" inputSchema must be a Zod object schema.`,\n { node, field: 'inputSchema' },\n );\n }\n if ('$' in schema.shape) {\n throw new NodeDefinitionError(\n `Node \"${node}\" inputSchema must not declare \"$\" as an input property.`,\n { node, field: 'inputSchema.$' },\n );\n }\n};\n\nconst validateDefinition = (options: {\n name: string;\n title?: unknown;\n description?: unknown;\n inputSchema?: unknown;\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 validateOptionalText(options.title, 'title', options.name);\n validateOptionalText(options.description, 'description', options.name);\n validateInputSchema(options.inputSchema, options.name);\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 TSchema extends NodeInputSchema,\n TData = unknown,\n TContext = unknown,\n>(\n options: DefineNodeWithSchemaOptions<TSchema, TData, TContext>,\n): NodeDefinitionWithSchema<TSchema, TData, TContext>;\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\nexport function defineNode(\n options: DefineNodeOptions<any, any, any>,\n): NodeDefinition<any, any, any> {\n validateDefinition(options);\n return options;\n}\n","import { z } from 'zod/v4';\nimport type { Awaitable } from '../engine/types';\nimport { NodeExecutionError } from '../errors';\nimport { defineNode } from '../node/define-node';\nimport type { NodeDefinition, NodeExecutionContext } from '../node/types';\n\ntype NodeContext<TContext> = NodeExecutionContext<unknown, TContext>;\ntype AgentGetter<TContext> = (ctx: NodeContext<TContext>) => Awaitable<unknown>;\ntype LifecycleMethod = 'launch' | 'terminate';\n\n/** Device capabilities required by Android and iOS lifecycle Nodes. */\nexport interface DeviceLifecycleAgent {\n launch(uri: string): Promise<void>;\n terminate(uri: string): Promise<void>;\n}\n\nconst lifecycleInputSchema = (\n operation: LifecycleMethod,\n description: string,\n) =>\n z\n .strictObject({\n prompt: z\n .string()\n .regex(/\\S/, 'prompt must contain a non-whitespace character')\n .optional()\n .describe(`String shorthand for the app to ${operation}.`),\n uri: z\n .string()\n .regex(/\\S/, 'uri must contain a non-whitespace character')\n .optional()\n .describe(description),\n })\n .superRefine((input, ctx) => {\n if ((input.prompt === undefined) === (input.uri === undefined)) {\n ctx.addIssue({\n code: 'custom',\n message: 'exactly one of prompt and uri is required',\n });\n }\n });\n\n/** Input schema for the device launch Node. */\nexport const launchInputSchema = lifecycleInputSchema(\n 'launch',\n 'The app, URL, URI, package name, or bundle identifier to launch.',\n);\n\n/** Input schema for the device terminate Node. */\nexport const terminateInputSchema = lifecycleInputSchema(\n 'terminate',\n 'The package name, bundle identifier, or app name to terminate.',\n);\n\nexport type LaunchNodeInput = z.infer<typeof launchInputSchema>;\nexport type TerminateNodeInput = z.infer<typeof terminateInputSchema>;\n\nconst requireLifecycleMethod = (\n agent: unknown,\n method: LifecycleMethod,\n agentName: string,\n): DeviceLifecycleAgent[LifecycleMethod] => {\n if (\n typeof agent !== 'object' ||\n agent === null ||\n typeof (agent as Record<LifecycleMethod, unknown>)[method] !== 'function'\n ) {\n throw new NodeExecutionError(\n method,\n new TypeError(`getAgent() must return ${agentName} with ${method}().`),\n );\n }\n return (agent as DeviceLifecycleAgent)[method];\n};\n\nexport const createLaunchNode = <TContext>(\n getAgent: AgentGetter<TContext>,\n agentName = 'an Agent',\n): NodeDefinition<any, any, TContext> =>\n defineNode<typeof launchInputSchema, unknown, TContext>({\n name: 'launch',\n description:\n 'Launch an app, URL, or URI through the current Midscene Agent. This Node does not install or manage applications.',\n inputSchema: launchInputSchema,\n async execute(ctx) {\n const uri = ctx.input.uri ?? ctx.input.prompt!;\n const agent = await getAgent(ctx);\n const launch = requireLifecycleMethod(agent, 'launch', agentName);\n await launch.call(agent, uri);\n return { summary: `Launched ${uri}` };\n },\n });\n\nconst createTerminateNode = <TContext>(\n getAgent: AgentGetter<TContext>,\n agentName: string,\n): NodeDefinition<any, any, TContext> =>\n defineNode<typeof terminateInputSchema, unknown, TContext>({\n name: 'terminate',\n description:\n 'Terminate an application through the current Midscene Agent. This Node does not uninstall the application or clear its data.',\n inputSchema: terminateInputSchema,\n async execute(ctx) {\n const uri = ctx.input.uri ?? ctx.input.prompt!;\n const agent = await getAgent(ctx);\n const terminate = requireLifecycleMethod(agent, 'terminate', agentName);\n await terminate.call(agent, uri);\n return { summary: `Terminated ${uri}` };\n },\n });\n\nexport const createDeviceLifecycleNodes = <TContext>(\n getAgent: (ctx: NodeContext<TContext>) => Awaitable<DeviceLifecycleAgent>,\n agentName: string,\n): readonly NodeDefinition<any, any, TContext>[] => [\n createLaunchNode(getAgent, agentName),\n createTerminateNode(getAgent, agentName),\n];\n","import { z } from 'zod/v4';\nimport { createLaunchNode } from '../device/lifecycle';\nexport type { LaunchNodeInput } from '../device/lifecycle';\nexport { launchInputSchema } from '../device/lifecycle';\nimport type { Awaitable, NodeHistoryEntry } from '../engine/types';\nimport { NodeDefinitionError, NodeExecutionError } from '../errors';\nimport { defineNode } from '../node/define-node';\nimport type {\n NodeDefinition,\n NodeExecutionContext,\n NodeResult,\n} 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\ntype MidsceneAiActInternalOptions = MidsceneAiActOptions & {\n /** Ask a Core Agent to append Test Runner context to its Agent-level context. */\n _internalContextMode: 'append';\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 MidscenePromptImage {\n name: string;\n url: string;\n}\n\nexport type MidsceneUserPrompt =\n | string\n | {\n prompt: string;\n images?: MidscenePromptImage[];\n convertHttpImage2Base64?: 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: MidsceneUserPrompt,\n options?: MidsceneAiActOptions,\n ): Promise<string | undefined>;\n aiAssert(\n prompt: MidsceneUserPrompt,\n message?: string,\n options?: MidsceneAiAssertOptions,\n ): Promise<unknown>;\n recordToReport(\n title?: string,\n options?: MidsceneRecordToReportOptions,\n ): Promise<unknown>;\n /** Available on device Agents that support launching an app, URL, or URI. */\n launch?(uri: string): Promise<void>;\n}\n\nexport interface AgentProvider<TContext> {\n getAgent(\n runId: string,\n ctx: NodeExecutionContext<unknown, TContext>,\n ): Awaitable<MidsceneUIAgent>;\n // biome-ignore lint/suspicious/noConfusingVoidType: providers without a report intentionally return void.\n releaseAgent?(runId: string): Awaitable<AgentReleaseResult | void>;\n dispose?(): Awaitable<void>;\n}\n\nexport interface AgentReleaseResult {\n /** Absolute path to the finalized report for this Agent scope. */\n reportPath?: string;\n}\n\nexport interface AgentExecutorInput<TContext> {\n prompt: string;\n history: readonly NodeHistoryEntry[];\n context: TContext;\n signal: AbortSignal;\n execution:\n | { scope: 'case'; runId: string }\n | { scope: 'document'; runId: string };\n}\n\nexport interface AgentExecutor<TContext> {\n // biome-ignore lint/suspicious/noConfusingVoidType: executors may perform side effects without returning a summary.\n execute(input: AgentExecutorInput<TContext>): Awaitable<NodeResult | void>;\n}\n\nconst nonBlankPrompt = (description: string) =>\n z\n .string()\n .regex(/\\S/, 'prompt must contain a non-whitespace character')\n .describe(description);\n\nconst promptImagesInputSchema = z\n .array(\n z.strictObject({\n name: nonBlankPrompt('The name used to identify this reference image.'),\n url: nonBlankPrompt(\n 'The URL, data URL, or file path of this reference image.',\n ),\n }),\n )\n .min(1)\n .optional();\n\nconst promptImageConversionInputSchema = z\n .boolean()\n .optional()\n .describe('Whether HTTP reference images are converted to base64 first.');\n\nconst aiActOptionsInputSchema = z.strictObject({\n cacheable: z\n .boolean()\n .optional()\n .describe('Whether this action may use the Midscene cache.'),\n fileChooserAccept: z\n .union([z.string(), z.array(z.string())])\n .optional()\n .describe('Accepted file types for a file chooser.'),\n deepThink: z\n .union([z.literal('unset'), z.boolean()])\n .optional()\n .describe('Whether to enable deep thinking for this action.'),\n deepLocate: z\n .boolean()\n .optional()\n .describe('Whether to use deep element location.'),\n context: z\n .string()\n .optional()\n .describe('Additional context supplied to the UI Agent.'),\n});\n\nexport const aiActInputSchema = z.strictObject({\n prompt: nonBlankPrompt('The natural-language UI task to perform.'),\n images: promptImagesInputSchema,\n convertHttpImage2Base64: promptImageConversionInputSchema,\n options: aiActOptionsInputSchema.optional(),\n});\n\nconst aiAssertOptionsInputSchema = z.strictObject({\n domIncluded: z\n .union([z.boolean(), z.literal('visible-only')])\n .optional()\n .describe('How DOM information is included in the assertion.'),\n screenshotIncluded: z\n .boolean()\n .optional()\n .describe('Whether the assertion includes a screenshot.'),\n context: z\n .string()\n .optional()\n .describe('Additional context supplied to the UI Agent.'),\n});\n\nexport const aiAssertInputSchema = z.strictObject({\n prompt: nonBlankPrompt('The natural-language condition that must be true.'),\n images: promptImagesInputSchema,\n convertHttpImage2Base64: promptImageConversionInputSchema,\n message: z.string().optional().describe('The assertion failure message.'),\n options: aiAssertOptionsInputSchema.optional(),\n});\n\nconst reportScreenshotInputSchema = z.strictObject({\n base64: z.string().min(1).describe('A base64-encoded screenshot.'),\n description: z.string().optional().describe('What the screenshot shows.'),\n});\n\nexport const recordToReportInputSchema = z\n .strictObject({\n prompt: z.string().optional().describe('String shorthand for the title.'),\n title: z.string().optional().describe('The report section title.'),\n content: z.string().optional().describe('The report text content.'),\n screenshotBase64: z\n .string()\n .optional()\n .describe('One base64-encoded screenshot.'),\n screenshots: z\n .array(reportScreenshotInputSchema)\n .min(1)\n .optional()\n .describe('Screenshots attached to the report section.'),\n })\n .superRefine((input, ctx) => {\n if (input.prompt !== undefined && input.title !== undefined) {\n ctx.addIssue({\n code: 'custom',\n message: 'prompt and title are mutually exclusive',\n });\n }\n if (\n input.screenshotBase64 !== undefined &&\n input.screenshots !== undefined\n ) {\n ctx.addIssue({\n code: 'custom',\n message: 'screenshotBase64 and screenshots are mutually exclusive',\n });\n }\n });\n\nexport const waitInputSchema = z.strictObject({\n duration: z.number().positive().describe('How long to wait.'),\n unit: z\n .enum(['ms', 's', 'min'])\n .default('ms')\n .describe('Duration unit: milliseconds, seconds, or minutes.'),\n});\n\nexport const agentInputSchema = z.strictObject({\n prompt: nonBlankPrompt(\n 'A self-contained task, including allowed tools and success conditions.',\n ),\n});\n\nexport type AiActNodeInput = z.infer<typeof aiActInputSchema>;\nexport type AiAssertNodeInput = z.infer<typeof aiAssertInputSchema>;\nexport type RecordToReportNodeInput = z.infer<typeof recordToReportInputSchema>;\nexport type WaitNodeInput = z.infer<typeof waitInputSchema>;\nexport type AgentNodeInput = z.infer<typeof agentInputSchema>;\n\nexport interface CreateMidsceneNodesOptions<TContext> {\n getAgent?(\n ctx: NodeExecutionContext<unknown, TContext>,\n ): Awaitable<MidsceneUIAgent>;\n agentProvider?: AgentProvider<TContext>;\n /** Disable when a project registers its own platform-specific launch Node. */\n includeLaunch?: boolean;\n agentExecutor?: AgentExecutor<TContext>;\n}\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\nconst requireAgentMethod = <TMethod extends keyof MidsceneUIAgent>(\n agent: MidsceneUIAgent,\n method: TMethod,\n node: string,\n): NonNullable<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] as NonNullable<MidsceneUIAgent[TMethod]>;\n};\n\nconst maxHistoryContextCharacters = 64_000;\nconst maxHistoryValuePreviewCharacters = 8_000;\nconst maxHistoryEntryCharacters = 24_000;\nconst historyOmissionNoticeReserve = 256;\n\nconst compactHistoryContextValue = (value: unknown): unknown => {\n const serialized = JSON.stringify(value);\n if (\n serialized === undefined ||\n serialized.length <= maxHistoryValuePreviewCharacters\n ) {\n return value;\n }\n return {\n omittedFromContext: true,\n originalCharacters: serialized.length,\n preview:\n typeof value === 'string'\n ? value.slice(0, maxHistoryValuePreviewCharacters)\n : serialized.slice(0, maxHistoryValuePreviewCharacters),\n };\n};\n\nconst serializeHistoryEntryForContext = (\n entry: NodeHistoryEntry,\n index: number,\n): string => {\n const compacted = Object.fromEntries(\n Object.entries({ index, ...entry }).map(([key, value]) => [\n key,\n compactHistoryContextValue(value),\n ]),\n );\n const serialized = JSON.stringify(compacted);\n if (serialized.length <= maxHistoryEntryCharacters) return serialized;\n\n return JSON.stringify({\n index,\n scope: entry.scope,\n phase: entry.phase,\n stepIndex: entry.stepIndex,\n node: entry.node,\n status: entry.status,\n ...(entry.summary === undefined\n ? {}\n : { summary: compactHistoryContextValue(entry.summary) }),\n omittedFromContext: true,\n compactedCharacters: serialized.length,\n });\n};\n\nexport const renderNodeHistory = (\n history: readonly NodeHistoryEntry[],\n): string | undefined => {\n if (history.length === 0) return undefined;\n\n const heading = 'Previous workflow results (read-only):';\n const availableCharacters =\n maxHistoryContextCharacters - heading.length - historyOmissionNoticeReserve;\n const renderedEntries: string[] = [];\n let renderedCharacters = 0;\n\n for (let index = history.length - 1; index >= 0; index -= 1) {\n const rendered = serializeHistoryEntryForContext(history[index], index + 1);\n const separatorCharacters = renderedEntries.length === 0 ? 0 : 1;\n if (\n renderedCharacters + separatorCharacters + rendered.length >\n availableCharacters\n ) {\n break;\n }\n renderedEntries.unshift(rendered);\n renderedCharacters += separatorCharacters + rendered.length;\n }\n\n const omittedEntries = history.length - renderedEntries.length;\n return [\n heading,\n ...(omittedEntries === 0\n ? []\n : [\n `${omittedEntries} earlier history entr${omittedEntries === 1 ? 'y was' : 'ies were'} omitted from Agent context to stay within the size limit. Complete results remain available in the Test Runner output.`,\n ]),\n ...renderedEntries,\n ].join('\\n');\n};\n\nconst mergeContext = (\n explicit: string | undefined,\n history: readonly NodeHistoryEntry[],\n): string | undefined =>\n [explicit, renderNodeHistory(history)].filter(Boolean).join('\\n\\n') ||\n undefined;\n\nconst toAgentPrompt = (input: {\n prompt: string;\n images?: MidscenePromptImage[];\n convertHttpImage2Base64?: boolean;\n}): MidsceneUserPrompt => {\n if (\n input.images === undefined &&\n input.convertHttpImage2Base64 === undefined\n ) {\n return input.prompt;\n }\n return {\n prompt: input.prompt,\n ...(input.images === undefined ? {} : { images: input.images }),\n ...(input.convertHttpImage2Base64 === undefined\n ? {}\n : { convertHttpImage2Base64: input.convertHttpImage2Base64 }),\n };\n};\n\nconst waitFor = async (durationMs: number, signal: AbortSignal) => {\n if (signal.aborted) {\n throw signal.reason ?? new Error('Wait aborted.');\n }\n await new Promise<void>((resolve, reject) => {\n const timeout = setTimeout(() => {\n signal.removeEventListener('abort', abort);\n resolve();\n }, durationMs);\n const abort = () => {\n clearTimeout(timeout);\n reject(signal.reason ?? new Error('Wait aborted.'));\n };\n signal.addEventListener('abort', abort, { once: true });\n });\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 (\n typeof options.agentProvider?.getAgent !== 'function' &&\n typeof options.getAgent !== 'function'\n ) {\n throw new NodeDefinitionError(\n 'createMidsceneNodes() requires getAgent or agentProvider.getAgent.',\n );\n }\n\n const registeredAgentScopes = new Set<string>();\n const getExecutionId = (ctx: NodeExecutionContext<unknown, TContext>) =>\n ctx.scope === 'case' ? ctx.case.runId : ctx.document.documentRunId;\n const getAgent = async (\n ctx: NodeExecutionContext<unknown, TContext>,\n ): Promise<MidsceneUIAgent> => {\n if (!options.agentProvider) return options.getAgent!(ctx);\n const runId = getExecutionId(ctx);\n if (\n options.agentProvider.releaseAgent &&\n !registeredAgentScopes.has(runId)\n ) {\n registeredAgentScopes.add(runId);\n ctx.onTeardown(async () => {\n try {\n const released = await options.agentProvider!.releaseAgent!(runId);\n return released?.reportPath\n ? { reportPaths: [released.reportPath] }\n : undefined;\n } finally {\n registeredAgentScopes.delete(runId);\n }\n });\n }\n return options.agentProvider.getAgent(runId, ctx);\n };\n\n return [\n defineNode<typeof aiActInputSchema, unknown, TContext>({\n name: 'aiAct',\n description: 'Perform a natural-language task with a Midscene UI Agent.',\n inputSchema: aiActInputSchema,\n async execute(ctx) {\n const agent = await getAgent(ctx);\n const aiAct = requireAgentMethod(agent, 'aiAct', 'aiAct');\n const aiActOptions: MidsceneAiActInternalOptions = {\n ...ctx.input.options,\n context: mergeContext(ctx.input.options?.context, ctx.history),\n abortSignal: ctx.signal,\n _internalContextMode: 'append',\n };\n const output = await aiAct.call(\n agent,\n toAgentPrompt(ctx.input),\n aiActOptions,\n );\n return output === undefined ? undefined : { summary: output };\n },\n }),\n defineNode<typeof aiAssertInputSchema, unknown, TContext>({\n name: 'aiAssert',\n description:\n 'Assert a natural-language condition with a Midscene UI Agent.',\n inputSchema: aiAssertInputSchema,\n async execute(ctx) {\n const agent = await getAgent(ctx);\n const aiAssert = requireAgentMethod(agent, 'aiAssert', 'aiAssert');\n await aiAssert.call(\n agent,\n toAgentPrompt(ctx.input),\n ctx.input.message,\n {\n ...ctx.input.options,\n context: mergeContext(ctx.input.options?.context, ctx.history),\n abortSignal: ctx.signal,\n },\n );\n return { summary: `Assertion passed: ${ctx.input.prompt}` };\n },\n }),\n defineNode<typeof recordToReportInputSchema, unknown, TContext>({\n name: 'recordToReport',\n description: 'Add text or screenshots to the current Midscene report.',\n inputSchema: recordToReportInputSchema,\n async execute(ctx) {\n const title = ctx.input.title ?? ctx.input.prompt;\n const reportOptions: MidsceneRecordToReportOptions = {\n ...(ctx.input.content === undefined\n ? {}\n : { content: ctx.input.content }),\n ...(ctx.input.screenshotBase64 === undefined\n ? {}\n : { screenshotBase64: ctx.input.screenshotBase64 }),\n ...(ctx.input.screenshots === undefined\n ? {}\n : { screenshots: ctx.input.screenshots }),\n };\n const agent = await 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 ...(options.includeLaunch === false ? [] : [createLaunchNode(getAgent)]),\n defineNode<typeof waitInputSchema, unknown, TContext>({\n name: 'wait',\n description: 'Wait for a fixed duration while honoring cancellation.',\n inputSchema: waitInputSchema,\n async execute(ctx) {\n const multiplier =\n ctx.input.unit === 'min'\n ? 60_000\n : ctx.input.unit === 's'\n ? 1_000\n : 1;\n const durationMs = ctx.input.duration * multiplier;\n await waitFor(durationMs, ctx.signal);\n return { summary: `Waited ${durationMs}ms` };\n },\n }),\n defineNode<typeof agentInputSchema, unknown, TContext>({\n name: 'agent',\n description:\n 'Execute one self-contained natural-language task with an injected Agent executor.',\n inputSchema: agentInputSchema,\n async execute(ctx) {\n if (!options.agentExecutor) {\n throw new NodeExecutionError(\n 'agent',\n new TypeError('createMidsceneNodes() requires an agentExecutor.'),\n );\n }\n const execution =\n ctx.scope === 'case'\n ? { scope: 'case' as const, runId: ctx.case.runId }\n : {\n scope: 'document' as const,\n runId: ctx.document.documentRunId,\n };\n const result = await options.agentExecutor.execute({\n prompt: ctx.input.prompt,\n history: ctx.history,\n context: ctx.context,\n signal: ctx.signal,\n execution,\n });\n return result ?? { summary: 'Agent task completed.' };\n },\n }),\n ];\n}\n"],"names":["WorkflowError","Error","undefined","message","options","NodeDefinitionError","details","NodeExecutionError","node","cause","causeMessage","String","validateOptionalText","value","field","validateInputSchema","schema","z","validateDefinition","defineNode","lifecycleInputSchema","operation","description","input","ctx","launchInputSchema","requireLifecycleMethod","agent","method","agentName","TypeError","createLaunchNode","getAgent","uri","launch","nonBlankPrompt","promptImagesInputSchema","promptImageConversionInputSchema","aiActOptionsInputSchema","aiActInputSchema","aiAssertOptionsInputSchema","aiAssertInputSchema","reportScreenshotInputSchema","recordToReportInputSchema","waitInputSchema","agentInputSchema","isRecord","Array","requireAgentMethod","maxHistoryContextCharacters","maxHistoryValuePreviewCharacters","maxHistoryEntryCharacters","historyOmissionNoticeReserve","compactHistoryContextValue","serialized","JSON","serializeHistoryEntryForContext","entry","index","compacted","Object","key","renderNodeHistory","history","heading","availableCharacters","renderedEntries","renderedCharacters","rendered","separatorCharacters","omittedEntries","mergeContext","explicit","Boolean","toAgentPrompt","waitFor","durationMs","signal","Promise","resolve","reject","timeout","setTimeout","abort","clearTimeout","createMidsceneNodes","registeredAgentScopes","Set","getExecutionId","runId","released","aiAct","aiActOptions","output","aiAssert","title","re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BAGlB,MAAMqE,YACJ3E,AAAc,WAAdA,IAAI,KAAK,GACL;oBAAE,OAAO;oBAAiB,OAAOA,IAAI,IAAI,CAAC,KAAK;gBAAC,IAChD;oBACE,OAAO;oBACP,OAAOA,IAAI,QAAQ,CAAC,aAAa;gBACnC;gBACN,MAAM4E,SAAS,MAAMhG,QAAQ,aAAa,CAAC,OAAO,CAAC;oBACjD,QAAQoB,IAAI,KAAK,CAAC,MAAM;oBACxB,SAASA,IAAI,OAAO;oBACpB,SAASA,IAAI,OAAO;oBACpB,QAAQA,IAAI,MAAM;oBAClB2E;gBACF;gBACA,OAAOC,UAAU;oBAAE,SAAS;gBAAwB;YACtD;QACF;KACD;AACH"}
1
+ {"version":3,"file":"midscene/index.mjs","sources":["../../../src/errors.ts","../../../src/node/define-node.ts","../../../src/device/lifecycle.ts","../../../src/midscene/index.ts"],"sourcesContent":["import type { z } from 'zod/v4';\n\nexport 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 static fromZod(node: string, error: z.ZodError): NodeInputValidationError {\n const issues = error.issues.map((issue) => ({\n code: issue.code,\n path: issue.path.map(String).join('.'),\n message: issue.message,\n }));\n const firstIssue = issues[0];\n const path = firstIssue?.path || '<root>';\n const message = firstIssue?.message ?? 'invalid input';\n return new NodeInputValidationError(\n `Node \"${node}\" input validation failed at \"${path}\": ${message}`,\n { node, issues },\n );\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 WorkflowLifecycleError extends WorkflowError {\n constructor(message: string, details?: unknown) {\n super(message, { code: 'WORKFLOW_LIFECYCLE_ERROR', details });\n }\n}\n\nexport class ProjectSetupError extends WorkflowError {\n constructor(cause: unknown, details: { projectName: string }) {\n const causeMessage =\n cause instanceof Error ? cause.message : String(cause ?? 'Unknown error');\n super(`Project \"${details.projectName}\" setup failed: ${causeMessage}`, {\n code: 'PROJECT_SETUP_ERROR',\n details,\n cause,\n });\n }\n}\n\nexport class ProjectTeardownError extends WorkflowError {\n constructor(\n cause: unknown,\n details: { projectName: string; registrationIndex: number },\n ) {\n const causeMessage =\n cause instanceof Error ? cause.message : String(cause ?? 'Unknown error');\n super(`Project \"${details.projectName}\" teardown failed: ${causeMessage}`, {\n code: 'PROJECT_TEARDOWN_ERROR',\n details,\n cause,\n });\n }\n}\n\nexport class NodeScopeTeardownError extends WorkflowError {\n constructor(\n cause: unknown,\n details: {\n scope: 'case' | 'document';\n scopeId: string;\n node: string;\n registrationIndex: number;\n },\n ) {\n const causeMessage =\n cause instanceof Error ? cause.message : String(cause ?? 'Unknown error');\n super(\n `${details.scope === 'case' ? 'Case attempt' : 'Workflow document'} node teardown failed for \"${details.node}\": ${causeMessage}`,\n { code: 'NODE_SCOPE_TEARDOWN_ERROR', details, cause },\n );\n }\n}\n\nexport class FatalDeviceError extends WorkflowError {\n constructor(message: string, cause?: unknown) {\n super(message, { code: 'FATAL_DEVICE_ERROR', cause });\n }\n}\n\nexport const isFatalDeviceError = (error: unknown): boolean => {\n if (error instanceof FatalDeviceError) return true;\n if (error instanceof WorkflowError && error.code === 'FATAL_DEVICE_ERROR') {\n return true;\n }\n if (\n error instanceof Error &&\n /device offline|device not found|(?:adb|bdc|device) connection (?:was )?closed/i.test(\n error.message,\n )\n ) {\n return true;\n }\n return error instanceof Error && error.cause !== undefined\n ? isFatalDeviceError(error.cause)\n : false;\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 { z } from 'zod/v4';\nimport { NodeDefinitionError } from '../errors';\nimport type {\n DefineNodeOptions,\n DefineNodeWithSchemaOptions,\n NodeDefinition,\n NodeDefinitionWithSchema,\n NodeInputSchema,\n} from './types';\n\nconst validateOptionalText = (\n value: unknown,\n field: 'title' | 'description',\n node: string,\n): void => {\n if (\n value !== undefined &&\n (typeof value !== 'string' || value.trim().length === 0)\n ) {\n throw new NodeDefinitionError(\n `Node \"${node}\" ${field} must be a non-empty string.`,\n { node, field },\n );\n }\n};\n\nconst validateInputSchema = (schema: unknown, node: string): void => {\n if (schema === undefined) return;\n if (!(schema instanceof z.ZodObject)) {\n throw new NodeDefinitionError(\n `Node \"${node}\" inputSchema must be a Zod object schema.`,\n { node, field: 'inputSchema' },\n );\n }\n if ('$' in schema.shape) {\n throw new NodeDefinitionError(\n `Node \"${node}\" inputSchema must not declare \"$\" as an input property.`,\n { node, field: 'inputSchema.$' },\n );\n }\n};\n\nconst validateDefinition = (options: {\n name: string;\n title?: unknown;\n description?: unknown;\n inputSchema?: unknown;\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 validateOptionalText(options.title, 'title', options.name);\n validateOptionalText(options.description, 'description', options.name);\n validateInputSchema(options.inputSchema, options.name);\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 TSchema extends NodeInputSchema,\n TData = unknown,\n TContext = unknown,\n>(\n options: DefineNodeWithSchemaOptions<TSchema, TData, TContext>,\n): NodeDefinitionWithSchema<TSchema, TData, TContext>;\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\nexport function defineNode(\n options: DefineNodeOptions<any, any, any>,\n): NodeDefinition<any, any, any> {\n validateDefinition(options);\n return options;\n}\n","import { z } from 'zod/v4';\nimport type { Awaitable } from '../engine/types';\nimport { NodeExecutionError } from '../errors';\nimport { defineNode } from '../node/define-node';\nimport type { NodeDefinition, NodeExecutionContext } from '../node/types';\n\ntype NodeContext<TContext> = NodeExecutionContext<unknown, TContext>;\ntype AgentGetter<TContext> = (ctx: NodeContext<TContext>) => Awaitable<unknown>;\ntype LifecycleMethod = 'launch' | 'terminate';\n\n/** Device capabilities required by Android and iOS lifecycle Nodes. */\nexport interface DeviceLifecycleAgent {\n launch(uri: string): Promise<void>;\n terminate(uri: string): Promise<void>;\n}\n\nconst lifecycleInputSchema = (\n operation: LifecycleMethod,\n description: string,\n) =>\n z\n .strictObject({\n prompt: z\n .string()\n .regex(/\\S/, 'prompt must contain a non-whitespace character')\n .optional()\n .describe(`String shorthand for the app to ${operation}.`),\n uri: z\n .string()\n .regex(/\\S/, 'uri must contain a non-whitespace character')\n .optional()\n .describe(description),\n })\n .superRefine((input, ctx) => {\n if ((input.prompt === undefined) === (input.uri === undefined)) {\n ctx.addIssue({\n code: 'custom',\n message: 'exactly one of prompt and uri is required',\n });\n }\n });\n\n/** Input schema for the device launch Node. */\nexport const launchInputSchema = lifecycleInputSchema(\n 'launch',\n 'The app, URL, URI, package name, or bundle identifier to launch.',\n);\n\n/** Input schema for the device terminate Node. */\nexport const terminateInputSchema = lifecycleInputSchema(\n 'terminate',\n 'The package name, bundle identifier, or app name to terminate.',\n);\n\nexport type LaunchNodeInput = z.infer<typeof launchInputSchema>;\nexport type TerminateNodeInput = z.infer<typeof terminateInputSchema>;\n\nconst requireLifecycleMethod = (\n agent: unknown,\n method: LifecycleMethod,\n agentName: string,\n): DeviceLifecycleAgent[LifecycleMethod] => {\n if (\n typeof agent !== 'object' ||\n agent === null ||\n typeof (agent as Record<LifecycleMethod, unknown>)[method] !== 'function'\n ) {\n throw new NodeExecutionError(\n method,\n new TypeError(`getAgent() must return ${agentName} with ${method}().`),\n );\n }\n return (agent as DeviceLifecycleAgent)[method];\n};\n\nexport const createLaunchNode = <TContext>(\n getAgent: AgentGetter<TContext>,\n agentName = 'an Agent',\n): NodeDefinition<any, any, TContext> =>\n defineNode<typeof launchInputSchema, unknown, TContext>({\n name: 'launch',\n description:\n 'Launch an app, URL, or URI through the current Midscene Agent. This Node does not install or manage applications.',\n inputSchema: launchInputSchema,\n async execute(ctx) {\n const uri = ctx.input.uri ?? ctx.input.prompt!;\n const agent = await getAgent(ctx);\n const launch = requireLifecycleMethod(agent, 'launch', agentName);\n await launch.call(agent, uri);\n return { summary: `Launched ${uri}` };\n },\n });\n\nconst createTerminateNode = <TContext>(\n getAgent: AgentGetter<TContext>,\n agentName: string,\n): NodeDefinition<any, any, TContext> =>\n defineNode<typeof terminateInputSchema, unknown, TContext>({\n name: 'terminate',\n description:\n 'Terminate an application through the current Midscene Agent. This Node does not uninstall the application or clear its data.',\n inputSchema: terminateInputSchema,\n async execute(ctx) {\n const uri = ctx.input.uri ?? ctx.input.prompt!;\n const agent = await getAgent(ctx);\n const terminate = requireLifecycleMethod(agent, 'terminate', agentName);\n await terminate.call(agent, uri);\n return { summary: `Terminated ${uri}` };\n },\n });\n\nexport const createDeviceLifecycleNodes = <TContext>(\n getAgent: (ctx: NodeContext<TContext>) => Awaitable<DeviceLifecycleAgent>,\n agentName: string,\n): readonly NodeDefinition<any, any, TContext>[] => [\n createLaunchNode(getAgent, agentName),\n createTerminateNode(getAgent, agentName),\n];\n","import { z } from 'zod/v4';\nimport { createLaunchNode } from '../device/lifecycle';\nexport type { LaunchNodeInput } from '../device/lifecycle';\nexport { launchInputSchema } from '../device/lifecycle';\nimport type { Awaitable, NodeHistoryEntry } from '../engine/types';\nimport { NodeDefinitionError, NodeExecutionError } from '../errors';\nimport { defineNode } from '../node/define-node';\nimport type {\n NodeDefinition,\n NodeExecutionContext,\n NodeResult,\n} 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 MidscenePromptImage {\n name: string;\n url: string;\n}\n\nexport type MidsceneUserPrompt =\n | string\n | {\n prompt: string;\n images?: MidscenePromptImage[];\n convertHttpImage2Base64?: 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: MidsceneUserPrompt,\n options?: MidsceneAiActOptions,\n ): Promise<string | undefined>;\n aiAssert(\n prompt: MidsceneUserPrompt,\n message?: string,\n options?: MidsceneAiAssertOptions,\n ): Promise<unknown>;\n recordToReport(\n title?: string,\n options?: MidsceneRecordToReportOptions,\n ): Promise<unknown>;\n /** Available on device Agents that support launching an app, URL, or URI. */\n launch?(uri: string): Promise<void>;\n}\n\nexport interface AgentProvider<TContext> {\n getAgent(\n runId: string,\n ctx: NodeExecutionContext<unknown, TContext>,\n ): Awaitable<MidsceneUIAgent>;\n // biome-ignore lint/suspicious/noConfusingVoidType: providers without a report intentionally return void.\n releaseAgent?(runId: string): Awaitable<AgentReleaseResult | void>;\n dispose?(): Awaitable<void>;\n}\n\nexport interface AgentReleaseResult {\n /** Absolute path to the finalized report for this Agent scope. */\n reportPath?: string;\n}\n\nexport interface AgentExecutorInput<TContext> {\n prompt: string;\n history: readonly NodeHistoryEntry[];\n context: TContext;\n signal: AbortSignal;\n execution:\n | { scope: 'case'; runId: string }\n | { scope: 'document'; runId: string };\n}\n\nexport interface AgentExecutor<TContext> {\n // biome-ignore lint/suspicious/noConfusingVoidType: executors may perform side effects without returning a summary.\n execute(input: AgentExecutorInput<TContext>): Awaitable<NodeResult | void>;\n}\n\nconst nonBlankPrompt = (description: string) =>\n z\n .string()\n .regex(/\\S/, 'prompt must contain a non-whitespace character')\n .describe(description);\n\nconst promptImagesInputSchema = z\n .array(\n z.strictObject({\n name: nonBlankPrompt('The name used to identify this reference image.'),\n url: nonBlankPrompt(\n 'The URL, data URL, or file path of this reference image.',\n ),\n }),\n )\n .min(1)\n .optional();\n\nconst promptImageConversionInputSchema = z\n .boolean()\n .optional()\n .describe('Whether HTTP reference images are converted to base64 first.');\n\nconst aiActOptionsInputSchema = z.strictObject({\n cacheable: z\n .boolean()\n .optional()\n .describe('Whether this action may use the Midscene cache.'),\n fileChooserAccept: z\n .union([z.string(), z.array(z.string())])\n .optional()\n .describe('Accepted file types for a file chooser.'),\n deepThink: z\n .union([z.literal('unset'), z.boolean()])\n .optional()\n .describe('Whether to enable deep thinking for this action.'),\n deepLocate: z\n .boolean()\n .optional()\n .describe('Whether to use deep element location.'),\n context: z\n .string()\n .optional()\n .describe('Additional context supplied to the UI Agent.'),\n});\n\nexport const aiActInputSchema = z.strictObject({\n prompt: nonBlankPrompt('The natural-language UI task to perform.'),\n images: promptImagesInputSchema,\n convertHttpImage2Base64: promptImageConversionInputSchema,\n options: aiActOptionsInputSchema.optional(),\n});\n\nconst aiAssertOptionsInputSchema = z.strictObject({\n domIncluded: z\n .union([z.boolean(), z.literal('visible-only')])\n .optional()\n .describe('How DOM information is included in the assertion.'),\n screenshotIncluded: z\n .boolean()\n .optional()\n .describe('Whether the assertion includes a screenshot.'),\n context: z\n .string()\n .optional()\n .describe('Additional context supplied to the UI Agent.'),\n});\n\nexport const aiAssertInputSchema = z.strictObject({\n prompt: nonBlankPrompt('The natural-language condition that must be true.'),\n images: promptImagesInputSchema,\n convertHttpImage2Base64: promptImageConversionInputSchema,\n message: z.string().optional().describe('The assertion failure message.'),\n options: aiAssertOptionsInputSchema.optional(),\n});\n\nconst reportScreenshotInputSchema = z.strictObject({\n base64: z.string().min(1).describe('A base64-encoded screenshot.'),\n description: z.string().optional().describe('What the screenshot shows.'),\n});\n\nexport const recordToReportInputSchema = z\n .strictObject({\n prompt: z.string().optional().describe('String shorthand for the title.'),\n title: z.string().optional().describe('The report section title.'),\n content: z.string().optional().describe('The report text content.'),\n screenshotBase64: z\n .string()\n .optional()\n .describe('One base64-encoded screenshot.'),\n screenshots: z\n .array(reportScreenshotInputSchema)\n .min(1)\n .optional()\n .describe('Screenshots attached to the report section.'),\n })\n .superRefine((input, ctx) => {\n if (input.prompt !== undefined && input.title !== undefined) {\n ctx.addIssue({\n code: 'custom',\n message: 'prompt and title are mutually exclusive',\n });\n }\n if (\n input.screenshotBase64 !== undefined &&\n input.screenshots !== undefined\n ) {\n ctx.addIssue({\n code: 'custom',\n message: 'screenshotBase64 and screenshots are mutually exclusive',\n });\n }\n });\n\nexport const waitInputSchema = z.strictObject({\n duration: z.number().positive().describe('How long to wait.'),\n unit: z\n .enum(['ms', 's', 'min'])\n .default('ms')\n .describe('Duration unit: milliseconds, seconds, or minutes.'),\n});\n\nexport const agentInputSchema = z.strictObject({\n prompt: nonBlankPrompt(\n 'A self-contained task, including allowed tools and success conditions.',\n ),\n});\n\nexport type AiActNodeInput = z.infer<typeof aiActInputSchema>;\nexport type AiAssertNodeInput = z.infer<typeof aiAssertInputSchema>;\nexport type RecordToReportNodeInput = z.infer<typeof recordToReportInputSchema>;\nexport type WaitNodeInput = z.infer<typeof waitInputSchema>;\nexport type AgentNodeInput = z.infer<typeof agentInputSchema>;\n\nexport interface CreateMidsceneNodesOptions<TContext> {\n getAgent?(\n ctx: NodeExecutionContext<unknown, TContext>,\n ): Awaitable<MidsceneUIAgent>;\n agentProvider?: AgentProvider<TContext>;\n /** Disable when a project registers its own platform-specific launch Node. */\n includeLaunch?: boolean;\n agentExecutor?: AgentExecutor<TContext>;\n}\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\nconst requireAgentMethod = <TMethod extends keyof MidsceneUIAgent>(\n agent: MidsceneUIAgent,\n method: TMethod,\n node: string,\n): NonNullable<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] as NonNullable<MidsceneUIAgent[TMethod]>;\n};\n\nconst maxHistoryContextCharacters = 64_000;\nconst maxHistoryValuePreviewCharacters = 8_000;\nconst maxHistoryEntryCharacters = 24_000;\nconst historyOmissionNoticeReserve = 256;\n\nconst compactHistoryContextValue = (value: unknown): unknown => {\n const serialized = JSON.stringify(value);\n if (\n serialized === undefined ||\n serialized.length <= maxHistoryValuePreviewCharacters\n ) {\n return value;\n }\n return {\n omittedFromContext: true,\n originalCharacters: serialized.length,\n preview:\n typeof value === 'string'\n ? value.slice(0, maxHistoryValuePreviewCharacters)\n : serialized.slice(0, maxHistoryValuePreviewCharacters),\n };\n};\n\nconst serializeHistoryEntryForContext = (\n entry: NodeHistoryEntry,\n index: number,\n): string => {\n const compacted = Object.fromEntries(\n Object.entries({ index, ...entry }).map(([key, value]) => [\n key,\n compactHistoryContextValue(value),\n ]),\n );\n const serialized = JSON.stringify(compacted);\n if (serialized.length <= maxHistoryEntryCharacters) return serialized;\n\n return JSON.stringify({\n index,\n scope: entry.scope,\n phase: entry.phase,\n stepIndex: entry.stepIndex,\n node: entry.node,\n status: entry.status,\n ...(entry.summary === undefined\n ? {}\n : { summary: compactHistoryContextValue(entry.summary) }),\n omittedFromContext: true,\n compactedCharacters: serialized.length,\n });\n};\n\nexport const renderNodeHistory = (\n history: readonly NodeHistoryEntry[],\n): string | undefined => {\n if (history.length === 0) return undefined;\n\n const heading = 'Previous workflow results (read-only):';\n const availableCharacters =\n maxHistoryContextCharacters - heading.length - historyOmissionNoticeReserve;\n const renderedEntries: string[] = [];\n let renderedCharacters = 0;\n\n for (let index = history.length - 1; index >= 0; index -= 1) {\n const rendered = serializeHistoryEntryForContext(history[index], index + 1);\n const separatorCharacters = renderedEntries.length === 0 ? 0 : 1;\n if (\n renderedCharacters + separatorCharacters + rendered.length >\n availableCharacters\n ) {\n break;\n }\n renderedEntries.unshift(rendered);\n renderedCharacters += separatorCharacters + rendered.length;\n }\n\n const omittedEntries = history.length - renderedEntries.length;\n return [\n heading,\n ...(omittedEntries === 0\n ? []\n : [\n `${omittedEntries} earlier history entr${omittedEntries === 1 ? 'y was' : 'ies were'} omitted from Agent context to stay within the size limit. Complete results remain available in the Test Runner output.`,\n ]),\n ...renderedEntries,\n ].join('\\n');\n};\n\nconst mergeContext = (\n explicit: string | undefined,\n history: readonly NodeHistoryEntry[],\n): string | undefined =>\n [explicit, renderNodeHistory(history)].filter(Boolean).join('\\n\\n') ||\n undefined;\n\nconst toAgentPrompt = (input: {\n prompt: string;\n images?: MidscenePromptImage[];\n convertHttpImage2Base64?: boolean;\n}): MidsceneUserPrompt => {\n if (\n input.images === undefined &&\n input.convertHttpImage2Base64 === undefined\n ) {\n return input.prompt;\n }\n return {\n prompt: input.prompt,\n ...(input.images === undefined ? {} : { images: input.images }),\n ...(input.convertHttpImage2Base64 === undefined\n ? {}\n : { convertHttpImage2Base64: input.convertHttpImage2Base64 }),\n };\n};\n\nconst waitFor = async (durationMs: number, signal: AbortSignal) => {\n if (signal.aborted) {\n throw signal.reason ?? new Error('Wait aborted.');\n }\n await new Promise<void>((resolve, reject) => {\n const timeout = setTimeout(() => {\n signal.removeEventListener('abort', abort);\n resolve();\n }, durationMs);\n const abort = () => {\n clearTimeout(timeout);\n reject(signal.reason ?? new Error('Wait aborted.'));\n };\n signal.addEventListener('abort', abort, { once: true });\n });\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 (\n typeof options.agentProvider?.getAgent !== 'function' &&\n typeof options.getAgent !== 'function'\n ) {\n throw new NodeDefinitionError(\n 'createMidsceneNodes() requires getAgent or agentProvider.getAgent.',\n );\n }\n\n const registeredAgentScopes = new Set<string>();\n const getExecutionId = (ctx: NodeExecutionContext<unknown, TContext>) =>\n ctx.scope === 'case' ? ctx.case.runId : ctx.document.documentRunId;\n const getAgent = async (\n ctx: NodeExecutionContext<unknown, TContext>,\n ): Promise<MidsceneUIAgent> => {\n if (!options.agentProvider) return options.getAgent!(ctx);\n const runId = getExecutionId(ctx);\n if (\n options.agentProvider.releaseAgent &&\n !registeredAgentScopes.has(runId)\n ) {\n registeredAgentScopes.add(runId);\n ctx.onTeardown(async () => {\n try {\n const released = await options.agentProvider!.releaseAgent!(runId);\n return released?.reportPath\n ? { reportPaths: [released.reportPath] }\n : undefined;\n } finally {\n registeredAgentScopes.delete(runId);\n }\n });\n }\n return options.agentProvider.getAgent(runId, ctx);\n };\n\n return [\n defineNode<typeof aiActInputSchema, unknown, TContext>({\n name: 'aiAct',\n description: 'Perform a natural-language task with a Midscene UI Agent.',\n inputSchema: aiActInputSchema,\n async execute(ctx) {\n const agent = await getAgent(ctx);\n const aiAct = requireAgentMethod(agent, 'aiAct', 'aiAct');\n const output = await aiAct.call(agent, toAgentPrompt(ctx.input), {\n ...ctx.input.options,\n context: mergeContext(ctx.input.options?.context, ctx.history),\n abortSignal: ctx.signal,\n });\n return output === undefined ? undefined : { summary: output };\n },\n }),\n defineNode<typeof aiAssertInputSchema, unknown, TContext>({\n name: 'aiAssert',\n description:\n 'Assert a natural-language condition with a Midscene UI Agent.',\n inputSchema: aiAssertInputSchema,\n async execute(ctx) {\n const agent = await getAgent(ctx);\n const aiAssert = requireAgentMethod(agent, 'aiAssert', 'aiAssert');\n await aiAssert.call(\n agent,\n toAgentPrompt(ctx.input),\n ctx.input.message,\n {\n ...ctx.input.options,\n context: mergeContext(ctx.input.options?.context, ctx.history),\n abortSignal: ctx.signal,\n },\n );\n return { summary: `Assertion passed: ${ctx.input.prompt}` };\n },\n }),\n defineNode<typeof recordToReportInputSchema, unknown, TContext>({\n name: 'recordToReport',\n description: 'Add text or screenshots to the current Midscene report.',\n inputSchema: recordToReportInputSchema,\n async execute(ctx) {\n const title = ctx.input.title ?? ctx.input.prompt;\n const reportOptions: MidsceneRecordToReportOptions = {\n ...(ctx.input.content === undefined\n ? {}\n : { content: ctx.input.content }),\n ...(ctx.input.screenshotBase64 === undefined\n ? {}\n : { screenshotBase64: ctx.input.screenshotBase64 }),\n ...(ctx.input.screenshots === undefined\n ? {}\n : { screenshots: ctx.input.screenshots }),\n };\n const agent = await 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 ...(options.includeLaunch === false ? [] : [createLaunchNode(getAgent)]),\n defineNode<typeof waitInputSchema, unknown, TContext>({\n name: 'wait',\n description: 'Wait for a fixed duration while honoring cancellation.',\n inputSchema: waitInputSchema,\n async execute(ctx) {\n const multiplier =\n ctx.input.unit === 'min'\n ? 60_000\n : ctx.input.unit === 's'\n ? 1_000\n : 1;\n const durationMs = ctx.input.duration * multiplier;\n await waitFor(durationMs, ctx.signal);\n return { summary: `Waited ${durationMs}ms` };\n },\n }),\n defineNode<typeof agentInputSchema, unknown, TContext>({\n name: 'agent',\n description:\n 'Execute one self-contained natural-language task with an injected Agent executor.',\n inputSchema: agentInputSchema,\n async execute(ctx) {\n if (!options.agentExecutor) {\n throw new NodeExecutionError(\n 'agent',\n new TypeError('createMidsceneNodes() requires an agentExecutor.'),\n );\n }\n const execution =\n ctx.scope === 'case'\n ? { scope: 'case' as const, runId: ctx.case.runId }\n : {\n scope: 'document' as const,\n runId: ctx.document.documentRunId,\n };\n const result = await options.agentExecutor.execute({\n prompt: ctx.input.prompt,\n history: ctx.history,\n context: ctx.context,\n signal: ctx.signal,\n execution,\n });\n return result ?? { summary: 'Agent task completed.' };\n },\n }),\n ];\n}\n"],"names":["WorkflowError","Error","undefined","message","options","NodeDefinitionError","details","NodeExecutionError","node","cause","causeMessage","String","validateOptionalText","value","field","validateInputSchema","schema","z","validateDefinition","defineNode","lifecycleInputSchema","operation","description","input","ctx","launchInputSchema","requireLifecycleMethod","agent","method","agentName","TypeError","createLaunchNode","getAgent","uri","launch","nonBlankPrompt","promptImagesInputSchema","promptImageConversionInputSchema","aiActOptionsInputSchema","aiActInputSchema","aiAssertOptionsInputSchema","aiAssertInputSchema","reportScreenshotInputSchema","recordToReportInputSchema","waitInputSchema","agentInputSchema","isRecord","Array","requireAgentMethod","maxHistoryContextCharacters","maxHistoryValuePreviewCharacters","maxHistoryEntryCharacters","historyOmissionNoticeReserve","compactHistoryContextValue","serialized","JSON","serializeHistoryEntryForContext","entry","index","compacted","Object","key","renderNodeHistory","history","heading","availableCharacters","renderedEntries","renderedCharacters","rendered","separatorCharacters","omittedEntries","mergeContext","explicit","Boolean","toAgentPrompt","waitFor","durationMs","signal","Promise","resolve","reject","timeout","setTimeout","abort","clearTimeout","createMidsceneNodes","registeredAgentScopes","Set","getExecutionId","runId","released","aiAct","output","aiAssert","title","reportOptions","recordToReport","multiplier","execution","result"],"mappings":";;;;;;;;;;;AAQO,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;YA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AAO;oBACpB,QAAQA,IAAI,MAAM;oBAClB0E;gBACF;gBACA,OAAOC,UAAU;oBAAE,SAAS;gBAAwB;YACtD;QACF;KACD;AACH"}
@@ -345,13 +345,11 @@ function createMidsceneNodes(options) {
345
345
  async execute (ctx) {
346
346
  const agent = await getAgent(ctx);
347
347
  const aiAct = requireAgentMethod(agent, 'aiAct', 'aiAct');
348
- const aiActOptions = {
348
+ const output = await aiAct.call(agent, toAgentPrompt(ctx.input), {
349
349
  ...ctx.input.options,
350
350
  context: mergeContext(ctx.input.options?.context, ctx.history),
351
- abortSignal: ctx.signal,
352
- _internalContextMode: 'append'
353
- };
354
- const output = await aiAct.call(agent, toAgentPrompt(ctx.input), aiActOptions);
351
+ abortSignal: ctx.signal
352
+ });
355
353
  return void 0 === output ? void 0 : {
356
354
  summary: output
357
355
  };
@@ -1 +1 @@
1
- {"version":3,"file":"midscene/index.js","sources":["webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../../../src/errors.ts","../../../src/node/define-node.ts","../../../src/device/lifecycle.ts","../../../src/midscene/index.ts"],"sourcesContent":["__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import type { z } from 'zod/v4';\n\nexport 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 static fromZod(node: string, error: z.ZodError): NodeInputValidationError {\n const issues = error.issues.map((issue) => ({\n code: issue.code,\n path: issue.path.map(String).join('.'),\n message: issue.message,\n }));\n const firstIssue = issues[0];\n const path = firstIssue?.path || '<root>';\n const message = firstIssue?.message ?? 'invalid input';\n return new NodeInputValidationError(\n `Node \"${node}\" input validation failed at \"${path}\": ${message}`,\n { node, issues },\n );\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 WorkflowLifecycleError extends WorkflowError {\n constructor(message: string, details?: unknown) {\n super(message, { code: 'WORKFLOW_LIFECYCLE_ERROR', details });\n }\n}\n\nexport class ProjectSetupError extends WorkflowError {\n constructor(cause: unknown, details: { projectName: string }) {\n const causeMessage =\n cause instanceof Error ? cause.message : String(cause ?? 'Unknown error');\n super(`Project \"${details.projectName}\" setup failed: ${causeMessage}`, {\n code: 'PROJECT_SETUP_ERROR',\n details,\n cause,\n });\n }\n}\n\nexport class ProjectTeardownError extends WorkflowError {\n constructor(\n cause: unknown,\n details: { projectName: string; registrationIndex: number },\n ) {\n const causeMessage =\n cause instanceof Error ? cause.message : String(cause ?? 'Unknown error');\n super(`Project \"${details.projectName}\" teardown failed: ${causeMessage}`, {\n code: 'PROJECT_TEARDOWN_ERROR',\n details,\n cause,\n });\n }\n}\n\nexport class NodeScopeTeardownError extends WorkflowError {\n constructor(\n cause: unknown,\n details: {\n scope: 'case' | 'document';\n scopeId: string;\n node: string;\n registrationIndex: number;\n },\n ) {\n const causeMessage =\n cause instanceof Error ? cause.message : String(cause ?? 'Unknown error');\n super(\n `${details.scope === 'case' ? 'Case attempt' : 'Workflow document'} node teardown failed for \"${details.node}\": ${causeMessage}`,\n { code: 'NODE_SCOPE_TEARDOWN_ERROR', details, cause },\n );\n }\n}\n\nexport class FatalDeviceError extends WorkflowError {\n constructor(message: string, cause?: unknown) {\n super(message, { code: 'FATAL_DEVICE_ERROR', cause });\n }\n}\n\nexport const isFatalDeviceError = (error: unknown): boolean => {\n if (error instanceof FatalDeviceError) return true;\n if (error instanceof WorkflowError && error.code === 'FATAL_DEVICE_ERROR') {\n return true;\n }\n if (\n error instanceof Error &&\n /device offline|device not found|(?:adb|bdc|device) connection (?:was )?closed/i.test(\n error.message,\n )\n ) {\n return true;\n }\n return error instanceof Error && error.cause !== undefined\n ? isFatalDeviceError(error.cause)\n : false;\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 { z } from 'zod/v4';\nimport { NodeDefinitionError } from '../errors';\nimport type {\n DefineNodeOptions,\n DefineNodeWithSchemaOptions,\n NodeDefinition,\n NodeDefinitionWithSchema,\n NodeInputSchema,\n} from './types';\n\nconst validateOptionalText = (\n value: unknown,\n field: 'title' | 'description',\n node: string,\n): void => {\n if (\n value !== undefined &&\n (typeof value !== 'string' || value.trim().length === 0)\n ) {\n throw new NodeDefinitionError(\n `Node \"${node}\" ${field} must be a non-empty string.`,\n { node, field },\n );\n }\n};\n\nconst validateInputSchema = (schema: unknown, node: string): void => {\n if (schema === undefined) return;\n if (!(schema instanceof z.ZodObject)) {\n throw new NodeDefinitionError(\n `Node \"${node}\" inputSchema must be a Zod object schema.`,\n { node, field: 'inputSchema' },\n );\n }\n if ('$' in schema.shape) {\n throw new NodeDefinitionError(\n `Node \"${node}\" inputSchema must not declare \"$\" as an input property.`,\n { node, field: 'inputSchema.$' },\n );\n }\n};\n\nconst validateDefinition = (options: {\n name: string;\n title?: unknown;\n description?: unknown;\n inputSchema?: unknown;\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 validateOptionalText(options.title, 'title', options.name);\n validateOptionalText(options.description, 'description', options.name);\n validateInputSchema(options.inputSchema, options.name);\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 TSchema extends NodeInputSchema,\n TData = unknown,\n TContext = unknown,\n>(\n options: DefineNodeWithSchemaOptions<TSchema, TData, TContext>,\n): NodeDefinitionWithSchema<TSchema, TData, TContext>;\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\nexport function defineNode(\n options: DefineNodeOptions<any, any, any>,\n): NodeDefinition<any, any, any> {\n validateDefinition(options);\n return options;\n}\n","import { z } from 'zod/v4';\nimport type { Awaitable } from '../engine/types';\nimport { NodeExecutionError } from '../errors';\nimport { defineNode } from '../node/define-node';\nimport type { NodeDefinition, NodeExecutionContext } from '../node/types';\n\ntype NodeContext<TContext> = NodeExecutionContext<unknown, TContext>;\ntype AgentGetter<TContext> = (ctx: NodeContext<TContext>) => Awaitable<unknown>;\ntype LifecycleMethod = 'launch' | 'terminate';\n\n/** Device capabilities required by Android and iOS lifecycle Nodes. */\nexport interface DeviceLifecycleAgent {\n launch(uri: string): Promise<void>;\n terminate(uri: string): Promise<void>;\n}\n\nconst lifecycleInputSchema = (\n operation: LifecycleMethod,\n description: string,\n) =>\n z\n .strictObject({\n prompt: z\n .string()\n .regex(/\\S/, 'prompt must contain a non-whitespace character')\n .optional()\n .describe(`String shorthand for the app to ${operation}.`),\n uri: z\n .string()\n .regex(/\\S/, 'uri must contain a non-whitespace character')\n .optional()\n .describe(description),\n })\n .superRefine((input, ctx) => {\n if ((input.prompt === undefined) === (input.uri === undefined)) {\n ctx.addIssue({\n code: 'custom',\n message: 'exactly one of prompt and uri is required',\n });\n }\n });\n\n/** Input schema for the device launch Node. */\nexport const launchInputSchema = lifecycleInputSchema(\n 'launch',\n 'The app, URL, URI, package name, or bundle identifier to launch.',\n);\n\n/** Input schema for the device terminate Node. */\nexport const terminateInputSchema = lifecycleInputSchema(\n 'terminate',\n 'The package name, bundle identifier, or app name to terminate.',\n);\n\nexport type LaunchNodeInput = z.infer<typeof launchInputSchema>;\nexport type TerminateNodeInput = z.infer<typeof terminateInputSchema>;\n\nconst requireLifecycleMethod = (\n agent: unknown,\n method: LifecycleMethod,\n agentName: string,\n): DeviceLifecycleAgent[LifecycleMethod] => {\n if (\n typeof agent !== 'object' ||\n agent === null ||\n typeof (agent as Record<LifecycleMethod, unknown>)[method] !== 'function'\n ) {\n throw new NodeExecutionError(\n method,\n new TypeError(`getAgent() must return ${agentName} with ${method}().`),\n );\n }\n return (agent as DeviceLifecycleAgent)[method];\n};\n\nexport const createLaunchNode = <TContext>(\n getAgent: AgentGetter<TContext>,\n agentName = 'an Agent',\n): NodeDefinition<any, any, TContext> =>\n defineNode<typeof launchInputSchema, unknown, TContext>({\n name: 'launch',\n description:\n 'Launch an app, URL, or URI through the current Midscene Agent. This Node does not install or manage applications.',\n inputSchema: launchInputSchema,\n async execute(ctx) {\n const uri = ctx.input.uri ?? ctx.input.prompt!;\n const agent = await getAgent(ctx);\n const launch = requireLifecycleMethod(agent, 'launch', agentName);\n await launch.call(agent, uri);\n return { summary: `Launched ${uri}` };\n },\n });\n\nconst createTerminateNode = <TContext>(\n getAgent: AgentGetter<TContext>,\n agentName: string,\n): NodeDefinition<any, any, TContext> =>\n defineNode<typeof terminateInputSchema, unknown, TContext>({\n name: 'terminate',\n description:\n 'Terminate an application through the current Midscene Agent. This Node does not uninstall the application or clear its data.',\n inputSchema: terminateInputSchema,\n async execute(ctx) {\n const uri = ctx.input.uri ?? ctx.input.prompt!;\n const agent = await getAgent(ctx);\n const terminate = requireLifecycleMethod(agent, 'terminate', agentName);\n await terminate.call(agent, uri);\n return { summary: `Terminated ${uri}` };\n },\n });\n\nexport const createDeviceLifecycleNodes = <TContext>(\n getAgent: (ctx: NodeContext<TContext>) => Awaitable<DeviceLifecycleAgent>,\n agentName: string,\n): readonly NodeDefinition<any, any, TContext>[] => [\n createLaunchNode(getAgent, agentName),\n createTerminateNode(getAgent, agentName),\n];\n","import { z } from 'zod/v4';\nimport { createLaunchNode } from '../device/lifecycle';\nexport type { LaunchNodeInput } from '../device/lifecycle';\nexport { launchInputSchema } from '../device/lifecycle';\nimport type { Awaitable, NodeHistoryEntry } from '../engine/types';\nimport { NodeDefinitionError, NodeExecutionError } from '../errors';\nimport { defineNode } from '../node/define-node';\nimport type {\n NodeDefinition,\n NodeExecutionContext,\n NodeResult,\n} 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\ntype MidsceneAiActInternalOptions = MidsceneAiActOptions & {\n /** Ask a Core Agent to append Test Runner context to its Agent-level context. */\n _internalContextMode: 'append';\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 MidscenePromptImage {\n name: string;\n url: string;\n}\n\nexport type MidsceneUserPrompt =\n | string\n | {\n prompt: string;\n images?: MidscenePromptImage[];\n convertHttpImage2Base64?: 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: MidsceneUserPrompt,\n options?: MidsceneAiActOptions,\n ): Promise<string | undefined>;\n aiAssert(\n prompt: MidsceneUserPrompt,\n message?: string,\n options?: MidsceneAiAssertOptions,\n ): Promise<unknown>;\n recordToReport(\n title?: string,\n options?: MidsceneRecordToReportOptions,\n ): Promise<unknown>;\n /** Available on device Agents that support launching an app, URL, or URI. */\n launch?(uri: string): Promise<void>;\n}\n\nexport interface AgentProvider<TContext> {\n getAgent(\n runId: string,\n ctx: NodeExecutionContext<unknown, TContext>,\n ): Awaitable<MidsceneUIAgent>;\n // biome-ignore lint/suspicious/noConfusingVoidType: providers without a report intentionally return void.\n releaseAgent?(runId: string): Awaitable<AgentReleaseResult | void>;\n dispose?(): Awaitable<void>;\n}\n\nexport interface AgentReleaseResult {\n /** Absolute path to the finalized report for this Agent scope. */\n reportPath?: string;\n}\n\nexport interface AgentExecutorInput<TContext> {\n prompt: string;\n history: readonly NodeHistoryEntry[];\n context: TContext;\n signal: AbortSignal;\n execution:\n | { scope: 'case'; runId: string }\n | { scope: 'document'; runId: string };\n}\n\nexport interface AgentExecutor<TContext> {\n // biome-ignore lint/suspicious/noConfusingVoidType: executors may perform side effects without returning a summary.\n execute(input: AgentExecutorInput<TContext>): Awaitable<NodeResult | void>;\n}\n\nconst nonBlankPrompt = (description: string) =>\n z\n .string()\n .regex(/\\S/, 'prompt must contain a non-whitespace character')\n .describe(description);\n\nconst promptImagesInputSchema = z\n .array(\n z.strictObject({\n name: nonBlankPrompt('The name used to identify this reference image.'),\n url: nonBlankPrompt(\n 'The URL, data URL, or file path of this reference image.',\n ),\n }),\n )\n .min(1)\n .optional();\n\nconst promptImageConversionInputSchema = z\n .boolean()\n .optional()\n .describe('Whether HTTP reference images are converted to base64 first.');\n\nconst aiActOptionsInputSchema = z.strictObject({\n cacheable: z\n .boolean()\n .optional()\n .describe('Whether this action may use the Midscene cache.'),\n fileChooserAccept: z\n .union([z.string(), z.array(z.string())])\n .optional()\n .describe('Accepted file types for a file chooser.'),\n deepThink: z\n .union([z.literal('unset'), z.boolean()])\n .optional()\n .describe('Whether to enable deep thinking for this action.'),\n deepLocate: z\n .boolean()\n .optional()\n .describe('Whether to use deep element location.'),\n context: z\n .string()\n .optional()\n .describe('Additional context supplied to the UI Agent.'),\n});\n\nexport const aiActInputSchema = z.strictObject({\n prompt: nonBlankPrompt('The natural-language UI task to perform.'),\n images: promptImagesInputSchema,\n convertHttpImage2Base64: promptImageConversionInputSchema,\n options: aiActOptionsInputSchema.optional(),\n});\n\nconst aiAssertOptionsInputSchema = z.strictObject({\n domIncluded: z\n .union([z.boolean(), z.literal('visible-only')])\n .optional()\n .describe('How DOM information is included in the assertion.'),\n screenshotIncluded: z\n .boolean()\n .optional()\n .describe('Whether the assertion includes a screenshot.'),\n context: z\n .string()\n .optional()\n .describe('Additional context supplied to the UI Agent.'),\n});\n\nexport const aiAssertInputSchema = z.strictObject({\n prompt: nonBlankPrompt('The natural-language condition that must be true.'),\n images: promptImagesInputSchema,\n convertHttpImage2Base64: promptImageConversionInputSchema,\n message: z.string().optional().describe('The assertion failure message.'),\n options: aiAssertOptionsInputSchema.optional(),\n});\n\nconst reportScreenshotInputSchema = z.strictObject({\n base64: z.string().min(1).describe('A base64-encoded screenshot.'),\n description: z.string().optional().describe('What the screenshot shows.'),\n});\n\nexport const recordToReportInputSchema = z\n .strictObject({\n prompt: z.string().optional().describe('String shorthand for the title.'),\n title: z.string().optional().describe('The report section title.'),\n content: z.string().optional().describe('The report text content.'),\n screenshotBase64: z\n .string()\n .optional()\n .describe('One base64-encoded screenshot.'),\n screenshots: z\n .array(reportScreenshotInputSchema)\n .min(1)\n .optional()\n .describe('Screenshots attached to the report section.'),\n })\n .superRefine((input, ctx) => {\n if (input.prompt !== undefined && input.title !== undefined) {\n ctx.addIssue({\n code: 'custom',\n message: 'prompt and title are mutually exclusive',\n });\n }\n if (\n input.screenshotBase64 !== undefined &&\n input.screenshots !== undefined\n ) {\n ctx.addIssue({\n code: 'custom',\n message: 'screenshotBase64 and screenshots are mutually exclusive',\n });\n }\n });\n\nexport const waitInputSchema = z.strictObject({\n duration: z.number().positive().describe('How long to wait.'),\n unit: z\n .enum(['ms', 's', 'min'])\n .default('ms')\n .describe('Duration unit: milliseconds, seconds, or minutes.'),\n});\n\nexport const agentInputSchema = z.strictObject({\n prompt: nonBlankPrompt(\n 'A self-contained task, including allowed tools and success conditions.',\n ),\n});\n\nexport type AiActNodeInput = z.infer<typeof aiActInputSchema>;\nexport type AiAssertNodeInput = z.infer<typeof aiAssertInputSchema>;\nexport type RecordToReportNodeInput = z.infer<typeof recordToReportInputSchema>;\nexport type WaitNodeInput = z.infer<typeof waitInputSchema>;\nexport type AgentNodeInput = z.infer<typeof agentInputSchema>;\n\nexport interface CreateMidsceneNodesOptions<TContext> {\n getAgent?(\n ctx: NodeExecutionContext<unknown, TContext>,\n ): Awaitable<MidsceneUIAgent>;\n agentProvider?: AgentProvider<TContext>;\n /** Disable when a project registers its own platform-specific launch Node. */\n includeLaunch?: boolean;\n agentExecutor?: AgentExecutor<TContext>;\n}\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\nconst requireAgentMethod = <TMethod extends keyof MidsceneUIAgent>(\n agent: MidsceneUIAgent,\n method: TMethod,\n node: string,\n): NonNullable<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] as NonNullable<MidsceneUIAgent[TMethod]>;\n};\n\nconst maxHistoryContextCharacters = 64_000;\nconst maxHistoryValuePreviewCharacters = 8_000;\nconst maxHistoryEntryCharacters = 24_000;\nconst historyOmissionNoticeReserve = 256;\n\nconst compactHistoryContextValue = (value: unknown): unknown => {\n const serialized = JSON.stringify(value);\n if (\n serialized === undefined ||\n serialized.length <= maxHistoryValuePreviewCharacters\n ) {\n return value;\n }\n return {\n omittedFromContext: true,\n originalCharacters: serialized.length,\n preview:\n typeof value === 'string'\n ? value.slice(0, maxHistoryValuePreviewCharacters)\n : serialized.slice(0, maxHistoryValuePreviewCharacters),\n };\n};\n\nconst serializeHistoryEntryForContext = (\n entry: NodeHistoryEntry,\n index: number,\n): string => {\n const compacted = Object.fromEntries(\n Object.entries({ index, ...entry }).map(([key, value]) => [\n key,\n compactHistoryContextValue(value),\n ]),\n );\n const serialized = JSON.stringify(compacted);\n if (serialized.length <= maxHistoryEntryCharacters) return serialized;\n\n return JSON.stringify({\n index,\n scope: entry.scope,\n phase: entry.phase,\n stepIndex: entry.stepIndex,\n node: entry.node,\n status: entry.status,\n ...(entry.summary === undefined\n ? {}\n : { summary: compactHistoryContextValue(entry.summary) }),\n omittedFromContext: true,\n compactedCharacters: serialized.length,\n });\n};\n\nexport const renderNodeHistory = (\n history: readonly NodeHistoryEntry[],\n): string | undefined => {\n if (history.length === 0) return undefined;\n\n const heading = 'Previous workflow results (read-only):';\n const availableCharacters =\n maxHistoryContextCharacters - heading.length - historyOmissionNoticeReserve;\n const renderedEntries: string[] = [];\n let renderedCharacters = 0;\n\n for (let index = history.length - 1; index >= 0; index -= 1) {\n const rendered = serializeHistoryEntryForContext(history[index], index + 1);\n const separatorCharacters = renderedEntries.length === 0 ? 0 : 1;\n if (\n renderedCharacters + separatorCharacters + rendered.length >\n availableCharacters\n ) {\n break;\n }\n renderedEntries.unshift(rendered);\n renderedCharacters += separatorCharacters + rendered.length;\n }\n\n const omittedEntries = history.length - renderedEntries.length;\n return [\n heading,\n ...(omittedEntries === 0\n ? []\n : [\n `${omittedEntries} earlier history entr${omittedEntries === 1 ? 'y was' : 'ies were'} omitted from Agent context to stay within the size limit. Complete results remain available in the Test Runner output.`,\n ]),\n ...renderedEntries,\n ].join('\\n');\n};\n\nconst mergeContext = (\n explicit: string | undefined,\n history: readonly NodeHistoryEntry[],\n): string | undefined =>\n [explicit, renderNodeHistory(history)].filter(Boolean).join('\\n\\n') ||\n undefined;\n\nconst toAgentPrompt = (input: {\n prompt: string;\n images?: MidscenePromptImage[];\n convertHttpImage2Base64?: boolean;\n}): MidsceneUserPrompt => {\n if (\n input.images === undefined &&\n input.convertHttpImage2Base64 === undefined\n ) {\n return input.prompt;\n }\n return {\n prompt: input.prompt,\n ...(input.images === undefined ? {} : { images: input.images }),\n ...(input.convertHttpImage2Base64 === undefined\n ? {}\n : { convertHttpImage2Base64: input.convertHttpImage2Base64 }),\n };\n};\n\nconst waitFor = async (durationMs: number, signal: AbortSignal) => {\n if (signal.aborted) {\n throw signal.reason ?? new Error('Wait aborted.');\n }\n await new Promise<void>((resolve, reject) => {\n const timeout = setTimeout(() => {\n signal.removeEventListener('abort', abort);\n resolve();\n }, durationMs);\n const abort = () => {\n clearTimeout(timeout);\n reject(signal.reason ?? new Error('Wait aborted.'));\n };\n signal.addEventListener('abort', abort, { once: true });\n });\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 (\n typeof options.agentProvider?.getAgent !== 'function' &&\n typeof options.getAgent !== 'function'\n ) {\n throw new NodeDefinitionError(\n 'createMidsceneNodes() requires getAgent or agentProvider.getAgent.',\n );\n }\n\n const registeredAgentScopes = new Set<string>();\n const getExecutionId = (ctx: NodeExecutionContext<unknown, TContext>) =>\n ctx.scope === 'case' ? ctx.case.runId : ctx.document.documentRunId;\n const getAgent = async (\n ctx: NodeExecutionContext<unknown, TContext>,\n ): Promise<MidsceneUIAgent> => {\n if (!options.agentProvider) return options.getAgent!(ctx);\n const runId = getExecutionId(ctx);\n if (\n options.agentProvider.releaseAgent &&\n !registeredAgentScopes.has(runId)\n ) {\n registeredAgentScopes.add(runId);\n ctx.onTeardown(async () => {\n try {\n const released = await options.agentProvider!.releaseAgent!(runId);\n return released?.reportPath\n ? { reportPaths: [released.reportPath] }\n : undefined;\n } finally {\n registeredAgentScopes.delete(runId);\n }\n });\n }\n return options.agentProvider.getAgent(runId, ctx);\n };\n\n return [\n defineNode<typeof aiActInputSchema, unknown, TContext>({\n name: 'aiAct',\n description: 'Perform a natural-language task with a Midscene UI Agent.',\n inputSchema: aiActInputSchema,\n async execute(ctx) {\n const agent = await getAgent(ctx);\n const aiAct = requireAgentMethod(agent, 'aiAct', 'aiAct');\n const aiActOptions: MidsceneAiActInternalOptions = {\n ...ctx.input.options,\n context: mergeContext(ctx.input.options?.context, ctx.history),\n abortSignal: ctx.signal,\n _internalContextMode: 'append',\n };\n const output = await aiAct.call(\n agent,\n toAgentPrompt(ctx.input),\n aiActOptions,\n );\n return output === undefined ? undefined : { summary: output };\n },\n }),\n defineNode<typeof aiAssertInputSchema, unknown, TContext>({\n name: 'aiAssert',\n description:\n 'Assert a natural-language condition with a Midscene UI Agent.',\n inputSchema: aiAssertInputSchema,\n async execute(ctx) {\n const agent = await getAgent(ctx);\n const aiAssert = requireAgentMethod(agent, 'aiAssert', 'aiAssert');\n await aiAssert.call(\n agent,\n toAgentPrompt(ctx.input),\n ctx.input.message,\n {\n ...ctx.input.options,\n context: mergeContext(ctx.input.options?.context, ctx.history),\n abortSignal: ctx.signal,\n },\n );\n return { summary: `Assertion passed: ${ctx.input.prompt}` };\n },\n }),\n defineNode<typeof recordToReportInputSchema, unknown, TContext>({\n name: 'recordToReport',\n description: 'Add text or screenshots to the current Midscene report.',\n inputSchema: recordToReportInputSchema,\n async execute(ctx) {\n const title = ctx.input.title ?? ctx.input.prompt;\n const reportOptions: MidsceneRecordToReportOptions = {\n ...(ctx.input.content === undefined\n ? {}\n : { content: ctx.input.content }),\n ...(ctx.input.screenshotBase64 === undefined\n ? {}\n : { screenshotBase64: ctx.input.screenshotBase64 }),\n ...(ctx.input.screenshots === undefined\n ? {}\n : { screenshots: ctx.input.screenshots }),\n };\n const agent = await 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 ...(options.includeLaunch === false ? [] : [createLaunchNode(getAgent)]),\n defineNode<typeof waitInputSchema, unknown, TContext>({\n name: 'wait',\n description: 'Wait for a fixed duration while honoring cancellation.',\n inputSchema: waitInputSchema,\n async execute(ctx) {\n const multiplier =\n ctx.input.unit === 'min'\n ? 60_000\n : ctx.input.unit === 's'\n ? 1_000\n : 1;\n const durationMs = ctx.input.duration * multiplier;\n await waitFor(durationMs, ctx.signal);\n return { summary: `Waited ${durationMs}ms` };\n },\n }),\n defineNode<typeof agentInputSchema, unknown, TContext>({\n name: 'agent',\n description:\n 'Execute one self-contained natural-language task with an injected Agent executor.',\n inputSchema: agentInputSchema,\n async execute(ctx) {\n if (!options.agentExecutor) {\n throw new NodeExecutionError(\n 'agent',\n new TypeError('createMidsceneNodes() requires an agentExecutor.'),\n );\n }\n const execution =\n ctx.scope === 'case'\n ? { scope: 'case' as const, runId: ctx.case.runId }\n : {\n scope: 'document' as const,\n runId: ctx.document.documentRunId,\n };\n const result = await options.agentExecutor.execute({\n prompt: ctx.input.prompt,\n history: ctx.history,\n context: ctx.context,\n signal: ctx.signal,\n execution,\n });\n return result ?? { summary: 'Agent task completed.' };\n },\n }),\n ];\n}\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","WorkflowError","Error","undefined","message","options","NodeDefinitionError","details","NodeExecutionError","node","cause","causeMessage","String","validateOptionalText","value","field","validateInputSchema","schema","z","validateDefinition","defineNode","lifecycleInputSchema","operation","description","input","ctx","launchInputSchema","requireLifecycleMethod","agent","method","agentName","TypeError","createLaunchNode","getAgent","uri","launch","nonBlankPrompt","promptImagesInputSchema","promptImageConversionInputSchema","aiActOptionsInputSchema","aiActInputSchema","aiAssertOptionsInputSchema","aiAssertInputSchema","reportScreenshotInputSchema","recordToReportInputSchema","waitInputSchema","agentInputSchema","isRecord","Array","requireAgentMethod","maxHistoryContextCharacters","maxHistoryValuePreviewCharacters","maxHistoryEntryCharacters","historyOmissionNoticeReserve","compactHistoryContextValue","serialized","JSON","serializeHistoryEntryForContext","entry","index","compacted","renderNodeHistory","history","heading","availableCharacters","renderedEntries","renderedCharacters","rendered","separatorCharacters","omittedEntries","mergeContext","explicit","Boolean","toAgentPrompt","waitFor","durationMs","signal","Promise","resolve","reject","timeout","setTimeout","abort","clearTimeout","createMidsceneNodes","registeredAgentScopes","Set","getExecutionId","runId","released","aiAct","aiActOptions","output","aiAssert","title","reportOptions","recordToReport","multiplier","execution","result"],"mappings":";;;IAAAA,oBAAoB,CAAC,GAAG,CAAC,UAASC;QACjC,IAAI,IAAIC,OAAOD,WACR,IAAGD,oBAAoB,CAAC,CAACC,YAAYC,QAAQ,CAACF,oBAAoB,CAAC,CAAC,UAASE,MACzEC,OAAO,cAAc,CAAC,UAASD,KAAK;YAAE,YAAY;YAAM,KAAKD,UAAU,CAACC,IAAI;QAAC;IAGzF;;;ICNAF,oBAAoB,CAAC,GAAG,CAACI,KAAKC,OAAUF,OAAO,SAAS,CAAC,cAAc,CAAC,IAAI,CAACC,KAAKC;;;ICClFL,oBAAoB,CAAC,GAAG,CAAC;QACxB,IAAG,AAAkB,eAAlB,OAAOM,UAA0BA,OAAO,WAAW,EACrDH,OAAO,cAAc,CAAC,UAASG,OAAO,WAAW,EAAE;YAAE,OAAO;QAAS;QAEtEH,OAAO,cAAc,CAAC,UAAS,cAAc;YAAE,OAAO;QAAK;IAC5D;;;;;;;;;;;;;;;;;;;;;;;;;ACEO,MAAMI,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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wE,aACJxE,AAAmB,UAAnBA,IAAI,KAAK,CAAC,IAAI,GACV,QACAA,AAAmB,QAAnBA,IAAI,KAAK,CAAC,IAAI,GACZ,OACA;gBACR,MAAMkD,aAAalD,IAAI,KAAK,CAAC,QAAQ,GAAGwE;gBACxC,MAAMvB,QAAQC,YAAYlD,IAAI,MAAM;gBACpC,OAAO;oBAAE,SAAS,CAAC,OAAO,EAAEkD,WAAW,EAAE,CAAC;gBAAC;YAC7C;QACF;QACAvD,uBAAuD;YACrD,MAAM;YACN,aACE;YACF,aAAa0B;YACb,MAAM,SAAQrB,GAAG;gBACf,IAAI,CAACpB,QAAQ,aAAa,EACxB,MAAM,IAAIG,mBACR,SACA,IAAIuB,UAAU;gBAGlB,MAAMmE,YACJzE,AAAc,WAAdA,IAAI,KAAK,GACL;oBAAE,OAAO;oBAAiB,OAAOA,IAAI,IAAI,CAAC,KAAK;gBAAC,IAChD;oBACE,OAAO;oBACP,OAAOA,IAAI,QAAQ,CAAC,aAAa;gBACnC;gBACN,MAAM0E,SAAS,MAAM9F,QAAQ,aAAa,CAAC,OAAO,CAAC;oBACjD,QAAQoB,IAAI,KAAK,CAAC,MAAM;oBACxB,SAASA,IAAI,OAAO;oBACpB,SAASA,IAAI,OAAO;oBACpB,QAAQA,IAAI,MAAM;oBAClByE;gBACF;gBACA,OAAOC,UAAU;oBAAE,SAAS;gBAAwB;YACtD;QACF;KACD;AACH"}
1
+ {"version":3,"file":"midscene/index.js","sources":["webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../../../src/errors.ts","../../../src/node/define-node.ts","../../../src/device/lifecycle.ts","../../../src/midscene/index.ts"],"sourcesContent":["__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import type { z } from 'zod/v4';\n\nexport 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 static fromZod(node: string, error: z.ZodError): NodeInputValidationError {\n const issues = error.issues.map((issue) => ({\n code: issue.code,\n path: issue.path.map(String).join('.'),\n message: issue.message,\n }));\n const firstIssue = issues[0];\n const path = firstIssue?.path || '<root>';\n const message = firstIssue?.message ?? 'invalid input';\n return new NodeInputValidationError(\n `Node \"${node}\" input validation failed at \"${path}\": ${message}`,\n { node, issues },\n );\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 WorkflowLifecycleError extends WorkflowError {\n constructor(message: string, details?: unknown) {\n super(message, { code: 'WORKFLOW_LIFECYCLE_ERROR', details });\n }\n}\n\nexport class ProjectSetupError extends WorkflowError {\n constructor(cause: unknown, details: { projectName: string }) {\n const causeMessage =\n cause instanceof Error ? cause.message : String(cause ?? 'Unknown error');\n super(`Project \"${details.projectName}\" setup failed: ${causeMessage}`, {\n code: 'PROJECT_SETUP_ERROR',\n details,\n cause,\n });\n }\n}\n\nexport class ProjectTeardownError extends WorkflowError {\n constructor(\n cause: unknown,\n details: { projectName: string; registrationIndex: number },\n ) {\n const causeMessage =\n cause instanceof Error ? cause.message : String(cause ?? 'Unknown error');\n super(`Project \"${details.projectName}\" teardown failed: ${causeMessage}`, {\n code: 'PROJECT_TEARDOWN_ERROR',\n details,\n cause,\n });\n }\n}\n\nexport class NodeScopeTeardownError extends WorkflowError {\n constructor(\n cause: unknown,\n details: {\n scope: 'case' | 'document';\n scopeId: string;\n node: string;\n registrationIndex: number;\n },\n ) {\n const causeMessage =\n cause instanceof Error ? cause.message : String(cause ?? 'Unknown error');\n super(\n `${details.scope === 'case' ? 'Case attempt' : 'Workflow document'} node teardown failed for \"${details.node}\": ${causeMessage}`,\n { code: 'NODE_SCOPE_TEARDOWN_ERROR', details, cause },\n );\n }\n}\n\nexport class FatalDeviceError extends WorkflowError {\n constructor(message: string, cause?: unknown) {\n super(message, { code: 'FATAL_DEVICE_ERROR', cause });\n }\n}\n\nexport const isFatalDeviceError = (error: unknown): boolean => {\n if (error instanceof FatalDeviceError) return true;\n if (error instanceof WorkflowError && error.code === 'FATAL_DEVICE_ERROR') {\n return true;\n }\n if (\n error instanceof Error &&\n /device offline|device not found|(?:adb|bdc|device) connection (?:was )?closed/i.test(\n error.message,\n )\n ) {\n return true;\n }\n return error instanceof Error && error.cause !== undefined\n ? isFatalDeviceError(error.cause)\n : false;\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 { z } from 'zod/v4';\nimport { NodeDefinitionError } from '../errors';\nimport type {\n DefineNodeOptions,\n DefineNodeWithSchemaOptions,\n NodeDefinition,\n NodeDefinitionWithSchema,\n NodeInputSchema,\n} from './types';\n\nconst validateOptionalText = (\n value: unknown,\n field: 'title' | 'description',\n node: string,\n): void => {\n if (\n value !== undefined &&\n (typeof value !== 'string' || value.trim().length === 0)\n ) {\n throw new NodeDefinitionError(\n `Node \"${node}\" ${field} must be a non-empty string.`,\n { node, field },\n );\n }\n};\n\nconst validateInputSchema = (schema: unknown, node: string): void => {\n if (schema === undefined) return;\n if (!(schema instanceof z.ZodObject)) {\n throw new NodeDefinitionError(\n `Node \"${node}\" inputSchema must be a Zod object schema.`,\n { node, field: 'inputSchema' },\n );\n }\n if ('$' in schema.shape) {\n throw new NodeDefinitionError(\n `Node \"${node}\" inputSchema must not declare \"$\" as an input property.`,\n { node, field: 'inputSchema.$' },\n );\n }\n};\n\nconst validateDefinition = (options: {\n name: string;\n title?: unknown;\n description?: unknown;\n inputSchema?: unknown;\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 validateOptionalText(options.title, 'title', options.name);\n validateOptionalText(options.description, 'description', options.name);\n validateInputSchema(options.inputSchema, options.name);\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 TSchema extends NodeInputSchema,\n TData = unknown,\n TContext = unknown,\n>(\n options: DefineNodeWithSchemaOptions<TSchema, TData, TContext>,\n): NodeDefinitionWithSchema<TSchema, TData, TContext>;\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\nexport function defineNode(\n options: DefineNodeOptions<any, any, any>,\n): NodeDefinition<any, any, any> {\n validateDefinition(options);\n return options;\n}\n","import { z } from 'zod/v4';\nimport type { Awaitable } from '../engine/types';\nimport { NodeExecutionError } from '../errors';\nimport { defineNode } from '../node/define-node';\nimport type { NodeDefinition, NodeExecutionContext } from '../node/types';\n\ntype NodeContext<TContext> = NodeExecutionContext<unknown, TContext>;\ntype AgentGetter<TContext> = (ctx: NodeContext<TContext>) => Awaitable<unknown>;\ntype LifecycleMethod = 'launch' | 'terminate';\n\n/** Device capabilities required by Android and iOS lifecycle Nodes. */\nexport interface DeviceLifecycleAgent {\n launch(uri: string): Promise<void>;\n terminate(uri: string): Promise<void>;\n}\n\nconst lifecycleInputSchema = (\n operation: LifecycleMethod,\n description: string,\n) =>\n z\n .strictObject({\n prompt: z\n .string()\n .regex(/\\S/, 'prompt must contain a non-whitespace character')\n .optional()\n .describe(`String shorthand for the app to ${operation}.`),\n uri: z\n .string()\n .regex(/\\S/, 'uri must contain a non-whitespace character')\n .optional()\n .describe(description),\n })\n .superRefine((input, ctx) => {\n if ((input.prompt === undefined) === (input.uri === undefined)) {\n ctx.addIssue({\n code: 'custom',\n message: 'exactly one of prompt and uri is required',\n });\n }\n });\n\n/** Input schema for the device launch Node. */\nexport const launchInputSchema = lifecycleInputSchema(\n 'launch',\n 'The app, URL, URI, package name, or bundle identifier to launch.',\n);\n\n/** Input schema for the device terminate Node. */\nexport const terminateInputSchema = lifecycleInputSchema(\n 'terminate',\n 'The package name, bundle identifier, or app name to terminate.',\n);\n\nexport type LaunchNodeInput = z.infer<typeof launchInputSchema>;\nexport type TerminateNodeInput = z.infer<typeof terminateInputSchema>;\n\nconst requireLifecycleMethod = (\n agent: unknown,\n method: LifecycleMethod,\n agentName: string,\n): DeviceLifecycleAgent[LifecycleMethod] => {\n if (\n typeof agent !== 'object' ||\n agent === null ||\n typeof (agent as Record<LifecycleMethod, unknown>)[method] !== 'function'\n ) {\n throw new NodeExecutionError(\n method,\n new TypeError(`getAgent() must return ${agentName} with ${method}().`),\n );\n }\n return (agent as DeviceLifecycleAgent)[method];\n};\n\nexport const createLaunchNode = <TContext>(\n getAgent: AgentGetter<TContext>,\n agentName = 'an Agent',\n): NodeDefinition<any, any, TContext> =>\n defineNode<typeof launchInputSchema, unknown, TContext>({\n name: 'launch',\n description:\n 'Launch an app, URL, or URI through the current Midscene Agent. This Node does not install or manage applications.',\n inputSchema: launchInputSchema,\n async execute(ctx) {\n const uri = ctx.input.uri ?? ctx.input.prompt!;\n const agent = await getAgent(ctx);\n const launch = requireLifecycleMethod(agent, 'launch', agentName);\n await launch.call(agent, uri);\n return { summary: `Launched ${uri}` };\n },\n });\n\nconst createTerminateNode = <TContext>(\n getAgent: AgentGetter<TContext>,\n agentName: string,\n): NodeDefinition<any, any, TContext> =>\n defineNode<typeof terminateInputSchema, unknown, TContext>({\n name: 'terminate',\n description:\n 'Terminate an application through the current Midscene Agent. This Node does not uninstall the application or clear its data.',\n inputSchema: terminateInputSchema,\n async execute(ctx) {\n const uri = ctx.input.uri ?? ctx.input.prompt!;\n const agent = await getAgent(ctx);\n const terminate = requireLifecycleMethod(agent, 'terminate', agentName);\n await terminate.call(agent, uri);\n return { summary: `Terminated ${uri}` };\n },\n });\n\nexport const createDeviceLifecycleNodes = <TContext>(\n getAgent: (ctx: NodeContext<TContext>) => Awaitable<DeviceLifecycleAgent>,\n agentName: string,\n): readonly NodeDefinition<any, any, TContext>[] => [\n createLaunchNode(getAgent, agentName),\n createTerminateNode(getAgent, agentName),\n];\n","import { z } from 'zod/v4';\nimport { createLaunchNode } from '../device/lifecycle';\nexport type { LaunchNodeInput } from '../device/lifecycle';\nexport { launchInputSchema } from '../device/lifecycle';\nimport type { Awaitable, NodeHistoryEntry } from '../engine/types';\nimport { NodeDefinitionError, NodeExecutionError } from '../errors';\nimport { defineNode } from '../node/define-node';\nimport type {\n NodeDefinition,\n NodeExecutionContext,\n NodeResult,\n} 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 MidscenePromptImage {\n name: string;\n url: string;\n}\n\nexport type MidsceneUserPrompt =\n | string\n | {\n prompt: string;\n images?: MidscenePromptImage[];\n convertHttpImage2Base64?: 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: MidsceneUserPrompt,\n options?: MidsceneAiActOptions,\n ): Promise<string | undefined>;\n aiAssert(\n prompt: MidsceneUserPrompt,\n message?: string,\n options?: MidsceneAiAssertOptions,\n ): Promise<unknown>;\n recordToReport(\n title?: string,\n options?: MidsceneRecordToReportOptions,\n ): Promise<unknown>;\n /** Available on device Agents that support launching an app, URL, or URI. */\n launch?(uri: string): Promise<void>;\n}\n\nexport interface AgentProvider<TContext> {\n getAgent(\n runId: string,\n ctx: NodeExecutionContext<unknown, TContext>,\n ): Awaitable<MidsceneUIAgent>;\n // biome-ignore lint/suspicious/noConfusingVoidType: providers without a report intentionally return void.\n releaseAgent?(runId: string): Awaitable<AgentReleaseResult | void>;\n dispose?(): Awaitable<void>;\n}\n\nexport interface AgentReleaseResult {\n /** Absolute path to the finalized report for this Agent scope. */\n reportPath?: string;\n}\n\nexport interface AgentExecutorInput<TContext> {\n prompt: string;\n history: readonly NodeHistoryEntry[];\n context: TContext;\n signal: AbortSignal;\n execution:\n | { scope: 'case'; runId: string }\n | { scope: 'document'; runId: string };\n}\n\nexport interface AgentExecutor<TContext> {\n // biome-ignore lint/suspicious/noConfusingVoidType: executors may perform side effects without returning a summary.\n execute(input: AgentExecutorInput<TContext>): Awaitable<NodeResult | void>;\n}\n\nconst nonBlankPrompt = (description: string) =>\n z\n .string()\n .regex(/\\S/, 'prompt must contain a non-whitespace character')\n .describe(description);\n\nconst promptImagesInputSchema = z\n .array(\n z.strictObject({\n name: nonBlankPrompt('The name used to identify this reference image.'),\n url: nonBlankPrompt(\n 'The URL, data URL, or file path of this reference image.',\n ),\n }),\n )\n .min(1)\n .optional();\n\nconst promptImageConversionInputSchema = z\n .boolean()\n .optional()\n .describe('Whether HTTP reference images are converted to base64 first.');\n\nconst aiActOptionsInputSchema = z.strictObject({\n cacheable: z\n .boolean()\n .optional()\n .describe('Whether this action may use the Midscene cache.'),\n fileChooserAccept: z\n .union([z.string(), z.array(z.string())])\n .optional()\n .describe('Accepted file types for a file chooser.'),\n deepThink: z\n .union([z.literal('unset'), z.boolean()])\n .optional()\n .describe('Whether to enable deep thinking for this action.'),\n deepLocate: z\n .boolean()\n .optional()\n .describe('Whether to use deep element location.'),\n context: z\n .string()\n .optional()\n .describe('Additional context supplied to the UI Agent.'),\n});\n\nexport const aiActInputSchema = z.strictObject({\n prompt: nonBlankPrompt('The natural-language UI task to perform.'),\n images: promptImagesInputSchema,\n convertHttpImage2Base64: promptImageConversionInputSchema,\n options: aiActOptionsInputSchema.optional(),\n});\n\nconst aiAssertOptionsInputSchema = z.strictObject({\n domIncluded: z\n .union([z.boolean(), z.literal('visible-only')])\n .optional()\n .describe('How DOM information is included in the assertion.'),\n screenshotIncluded: z\n .boolean()\n .optional()\n .describe('Whether the assertion includes a screenshot.'),\n context: z\n .string()\n .optional()\n .describe('Additional context supplied to the UI Agent.'),\n});\n\nexport const aiAssertInputSchema = z.strictObject({\n prompt: nonBlankPrompt('The natural-language condition that must be true.'),\n images: promptImagesInputSchema,\n convertHttpImage2Base64: promptImageConversionInputSchema,\n message: z.string().optional().describe('The assertion failure message.'),\n options: aiAssertOptionsInputSchema.optional(),\n});\n\nconst reportScreenshotInputSchema = z.strictObject({\n base64: z.string().min(1).describe('A base64-encoded screenshot.'),\n description: z.string().optional().describe('What the screenshot shows.'),\n});\n\nexport const recordToReportInputSchema = z\n .strictObject({\n prompt: z.string().optional().describe('String shorthand for the title.'),\n title: z.string().optional().describe('The report section title.'),\n content: z.string().optional().describe('The report text content.'),\n screenshotBase64: z\n .string()\n .optional()\n .describe('One base64-encoded screenshot.'),\n screenshots: z\n .array(reportScreenshotInputSchema)\n .min(1)\n .optional()\n .describe('Screenshots attached to the report section.'),\n })\n .superRefine((input, ctx) => {\n if (input.prompt !== undefined && input.title !== undefined) {\n ctx.addIssue({\n code: 'custom',\n message: 'prompt and title are mutually exclusive',\n });\n }\n if (\n input.screenshotBase64 !== undefined &&\n input.screenshots !== undefined\n ) {\n ctx.addIssue({\n code: 'custom',\n message: 'screenshotBase64 and screenshots are mutually exclusive',\n });\n }\n });\n\nexport const waitInputSchema = z.strictObject({\n duration: z.number().positive().describe('How long to wait.'),\n unit: z\n .enum(['ms', 's', 'min'])\n .default('ms')\n .describe('Duration unit: milliseconds, seconds, or minutes.'),\n});\n\nexport const agentInputSchema = z.strictObject({\n prompt: nonBlankPrompt(\n 'A self-contained task, including allowed tools and success conditions.',\n ),\n});\n\nexport type AiActNodeInput = z.infer<typeof aiActInputSchema>;\nexport type AiAssertNodeInput = z.infer<typeof aiAssertInputSchema>;\nexport type RecordToReportNodeInput = z.infer<typeof recordToReportInputSchema>;\nexport type WaitNodeInput = z.infer<typeof waitInputSchema>;\nexport type AgentNodeInput = z.infer<typeof agentInputSchema>;\n\nexport interface CreateMidsceneNodesOptions<TContext> {\n getAgent?(\n ctx: NodeExecutionContext<unknown, TContext>,\n ): Awaitable<MidsceneUIAgent>;\n agentProvider?: AgentProvider<TContext>;\n /** Disable when a project registers its own platform-specific launch Node. */\n includeLaunch?: boolean;\n agentExecutor?: AgentExecutor<TContext>;\n}\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\nconst requireAgentMethod = <TMethod extends keyof MidsceneUIAgent>(\n agent: MidsceneUIAgent,\n method: TMethod,\n node: string,\n): NonNullable<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] as NonNullable<MidsceneUIAgent[TMethod]>;\n};\n\nconst maxHistoryContextCharacters = 64_000;\nconst maxHistoryValuePreviewCharacters = 8_000;\nconst maxHistoryEntryCharacters = 24_000;\nconst historyOmissionNoticeReserve = 256;\n\nconst compactHistoryContextValue = (value: unknown): unknown => {\n const serialized = JSON.stringify(value);\n if (\n serialized === undefined ||\n serialized.length <= maxHistoryValuePreviewCharacters\n ) {\n return value;\n }\n return {\n omittedFromContext: true,\n originalCharacters: serialized.length,\n preview:\n typeof value === 'string'\n ? value.slice(0, maxHistoryValuePreviewCharacters)\n : serialized.slice(0, maxHistoryValuePreviewCharacters),\n };\n};\n\nconst serializeHistoryEntryForContext = (\n entry: NodeHistoryEntry,\n index: number,\n): string => {\n const compacted = Object.fromEntries(\n Object.entries({ index, ...entry }).map(([key, value]) => [\n key,\n compactHistoryContextValue(value),\n ]),\n );\n const serialized = JSON.stringify(compacted);\n if (serialized.length <= maxHistoryEntryCharacters) return serialized;\n\n return JSON.stringify({\n index,\n scope: entry.scope,\n phase: entry.phase,\n stepIndex: entry.stepIndex,\n node: entry.node,\n status: entry.status,\n ...(entry.summary === undefined\n ? {}\n : { summary: compactHistoryContextValue(entry.summary) }),\n omittedFromContext: true,\n compactedCharacters: serialized.length,\n });\n};\n\nexport const renderNodeHistory = (\n history: readonly NodeHistoryEntry[],\n): string | undefined => {\n if (history.length === 0) return undefined;\n\n const heading = 'Previous workflow results (read-only):';\n const availableCharacters =\n maxHistoryContextCharacters - heading.length - historyOmissionNoticeReserve;\n const renderedEntries: string[] = [];\n let renderedCharacters = 0;\n\n for (let index = history.length - 1; index >= 0; index -= 1) {\n const rendered = serializeHistoryEntryForContext(history[index], index + 1);\n const separatorCharacters = renderedEntries.length === 0 ? 0 : 1;\n if (\n renderedCharacters + separatorCharacters + rendered.length >\n availableCharacters\n ) {\n break;\n }\n renderedEntries.unshift(rendered);\n renderedCharacters += separatorCharacters + rendered.length;\n }\n\n const omittedEntries = history.length - renderedEntries.length;\n return [\n heading,\n ...(omittedEntries === 0\n ? []\n : [\n `${omittedEntries} earlier history entr${omittedEntries === 1 ? 'y was' : 'ies were'} omitted from Agent context to stay within the size limit. Complete results remain available in the Test Runner output.`,\n ]),\n ...renderedEntries,\n ].join('\\n');\n};\n\nconst mergeContext = (\n explicit: string | undefined,\n history: readonly NodeHistoryEntry[],\n): string | undefined =>\n [explicit, renderNodeHistory(history)].filter(Boolean).join('\\n\\n') ||\n undefined;\n\nconst toAgentPrompt = (input: {\n prompt: string;\n images?: MidscenePromptImage[];\n convertHttpImage2Base64?: boolean;\n}): MidsceneUserPrompt => {\n if (\n input.images === undefined &&\n input.convertHttpImage2Base64 === undefined\n ) {\n return input.prompt;\n }\n return {\n prompt: input.prompt,\n ...(input.images === undefined ? {} : { images: input.images }),\n ...(input.convertHttpImage2Base64 === undefined\n ? {}\n : { convertHttpImage2Base64: input.convertHttpImage2Base64 }),\n };\n};\n\nconst waitFor = async (durationMs: number, signal: AbortSignal) => {\n if (signal.aborted) {\n throw signal.reason ?? new Error('Wait aborted.');\n }\n await new Promise<void>((resolve, reject) => {\n const timeout = setTimeout(() => {\n signal.removeEventListener('abort', abort);\n resolve();\n }, durationMs);\n const abort = () => {\n clearTimeout(timeout);\n reject(signal.reason ?? new Error('Wait aborted.'));\n };\n signal.addEventListener('abort', abort, { once: true });\n });\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 (\n typeof options.agentProvider?.getAgent !== 'function' &&\n typeof options.getAgent !== 'function'\n ) {\n throw new NodeDefinitionError(\n 'createMidsceneNodes() requires getAgent or agentProvider.getAgent.',\n );\n }\n\n const registeredAgentScopes = new Set<string>();\n const getExecutionId = (ctx: NodeExecutionContext<unknown, TContext>) =>\n ctx.scope === 'case' ? ctx.case.runId : ctx.document.documentRunId;\n const getAgent = async (\n ctx: NodeExecutionContext<unknown, TContext>,\n ): Promise<MidsceneUIAgent> => {\n if (!options.agentProvider) return options.getAgent!(ctx);\n const runId = getExecutionId(ctx);\n if (\n options.agentProvider.releaseAgent &&\n !registeredAgentScopes.has(runId)\n ) {\n registeredAgentScopes.add(runId);\n ctx.onTeardown(async () => {\n try {\n const released = await options.agentProvider!.releaseAgent!(runId);\n return released?.reportPath\n ? { reportPaths: [released.reportPath] }\n : undefined;\n } finally {\n registeredAgentScopes.delete(runId);\n }\n });\n }\n return options.agentProvider.getAgent(runId, ctx);\n };\n\n return [\n defineNode<typeof aiActInputSchema, unknown, TContext>({\n name: 'aiAct',\n description: 'Perform a natural-language task with a Midscene UI Agent.',\n inputSchema: aiActInputSchema,\n async execute(ctx) {\n const agent = await getAgent(ctx);\n const aiAct = requireAgentMethod(agent, 'aiAct', 'aiAct');\n const output = await aiAct.call(agent, toAgentPrompt(ctx.input), {\n ...ctx.input.options,\n context: mergeContext(ctx.input.options?.context, ctx.history),\n abortSignal: ctx.signal,\n });\n return output === undefined ? undefined : { summary: output };\n },\n }),\n defineNode<typeof aiAssertInputSchema, unknown, TContext>({\n name: 'aiAssert',\n description:\n 'Assert a natural-language condition with a Midscene UI Agent.',\n inputSchema: aiAssertInputSchema,\n async execute(ctx) {\n const agent = await getAgent(ctx);\n const aiAssert = requireAgentMethod(agent, 'aiAssert', 'aiAssert');\n await aiAssert.call(\n agent,\n toAgentPrompt(ctx.input),\n ctx.input.message,\n {\n ...ctx.input.options,\n context: mergeContext(ctx.input.options?.context, ctx.history),\n abortSignal: ctx.signal,\n },\n );\n return { summary: `Assertion passed: ${ctx.input.prompt}` };\n },\n }),\n defineNode<typeof recordToReportInputSchema, unknown, TContext>({\n name: 'recordToReport',\n description: 'Add text or screenshots to the current Midscene report.',\n inputSchema: recordToReportInputSchema,\n async execute(ctx) {\n const title = ctx.input.title ?? ctx.input.prompt;\n const reportOptions: MidsceneRecordToReportOptions = {\n ...(ctx.input.content === undefined\n ? {}\n : { content: ctx.input.content }),\n ...(ctx.input.screenshotBase64 === undefined\n ? {}\n : { screenshotBase64: ctx.input.screenshotBase64 }),\n ...(ctx.input.screenshots === undefined\n ? {}\n : { screenshots: ctx.input.screenshots }),\n };\n const agent = await 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 ...(options.includeLaunch === false ? [] : [createLaunchNode(getAgent)]),\n defineNode<typeof waitInputSchema, unknown, TContext>({\n name: 'wait',\n description: 'Wait for a fixed duration while honoring cancellation.',\n inputSchema: waitInputSchema,\n async execute(ctx) {\n const multiplier =\n ctx.input.unit === 'min'\n ? 60_000\n : ctx.input.unit === 's'\n ? 1_000\n : 1;\n const durationMs = ctx.input.duration * multiplier;\n await waitFor(durationMs, ctx.signal);\n return { summary: `Waited ${durationMs}ms` };\n },\n }),\n defineNode<typeof agentInputSchema, unknown, TContext>({\n name: 'agent',\n description:\n 'Execute one self-contained natural-language task with an injected Agent executor.',\n inputSchema: agentInputSchema,\n async execute(ctx) {\n if (!options.agentExecutor) {\n throw new NodeExecutionError(\n 'agent',\n new TypeError('createMidsceneNodes() requires an agentExecutor.'),\n );\n }\n const execution =\n ctx.scope === 'case'\n ? { scope: 'case' as const, runId: ctx.case.runId }\n : {\n scope: 'document' as const,\n runId: ctx.document.documentRunId,\n };\n const result = await options.agentExecutor.execute({\n prompt: ctx.input.prompt,\n history: ctx.history,\n context: ctx.context,\n signal: ctx.signal,\n execution,\n });\n return result ?? { summary: 'Agent task completed.' };\n },\n }),\n ];\n}\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","WorkflowError","Error","undefined","message","options","NodeDefinitionError","details","NodeExecutionError","node","cause","causeMessage","String","validateOptionalText","value","field","validateInputSchema","schema","z","validateDefinition","defineNode","lifecycleInputSchema","operation","description","input","ctx","launchInputSchema","requireLifecycleMethod","agent","method","agentName","TypeError","createLaunchNode","getAgent","uri","launch","nonBlankPrompt","promptImagesInputSchema","promptImageConversionInputSchema","aiActOptionsInputSchema","aiActInputSchema","aiAssertOptionsInputSchema","aiAssertInputSchema","reportScreenshotInputSchema","recordToReportInputSchema","waitInputSchema","agentInputSchema","isRecord","Array","requireAgentMethod","maxHistoryContextCharacters","maxHistoryValuePreviewCharacters","maxHistoryEntryCharacters","historyOmissionNoticeReserve","compactHistoryContextValue","serialized","JSON","serializeHistoryEntryForContext","entry","index","compacted","renderNodeHistory","history","heading","availableCharacters","renderedEntries","renderedCharacters","rendered","separatorCharacters","omittedEntries","mergeContext","explicit","Boolean","toAgentPrompt","waitFor","durationMs","signal","Promise","resolve","reject","timeout","setTimeout","abort","clearTimeout","createMidsceneNodes","registeredAgentScopes","Set","getExecutionId","runId","released","aiAct","output","aiAssert","title","reportOptions","recordToReport","multiplier","execution","result"],"mappings":";;;IAAAA,oBAAoB,CAAC,GAAG,CAAC,UAASC;QACjC,IAAI,IAAIC,OAAOD,WACR,IAAGD,oBAAoB,CAAC,CAACC,YAAYC,QAAQ,CAACF,oBAAoB,CAAC,CAAC,UAASE,MACzEC,OAAO,cAAc,CAAC,UAASD,KAAK;YAAE,YAAY;YAAM,KAAKD,UAAU,CAACC,IAAI;QAAC;IAGzF;;;ICNAF,oBAAoB,CAAC,GAAG,CAACI,KAAKC,OAAUF,OAAO,SAAS,CAAC,cAAc,CAAC,IAAI,CAACC,KAAKC;;;ICClFL,oBAAoB,CAAC,GAAG,CAAC;QACxB,IAAG,AAAkB,eAAlB,OAAOM,UAA0BA,OAAO,WAAW,EACrDH,OAAO,cAAc,CAAC,UAASG,OAAO,WAAW,EAAE;YAAE,OAAO;QAAS;QAEtEH,OAAO,cAAc,CAAC,UAAS,cAAc;YAAE,OAAO;QAAK;IAC5D;;;;;;;;;;;;;;;;;;;;;;;;;ACEO,MAAM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,aAAa,GAAa,EAAE,GAAG;YAAC2B,iBAAiBC;SAAU;QACvEb,uBAAsD;YACpD,MAAM;YACN,aAAa;YACb,aAAayB;YACb,MAAM,SAAQpB,GAAG;gBACf,MAAMuE,aACJvE,AAAmB,UAAnBA,IAAI,KAAK,CAAC,IAAI,GACV,QACAA,AAAmB,QAAnBA,IAAI,KAAK,CAAC,IAAI,GACZ,OACA;gBACR,MAAMkD,aAAalD,IAAI,KAAK,CAAC,QAAQ,GAAGuE;gBACxC,MAAMtB,QAAQC,YAAYlD,IAAI,MAAM;gBACpC,OAAO;oBAAE,SAAS,CAAC,OAAO,EAAEkD,WAAW,EAAE,CAAC;gBAAC;YAC7C;QACF;QACAvD,uBAAuD;YACrD,MAAM;YACN,aACE;YACF,aAAa0B;YACb,MAAM,SAAQrB,GAAG;gBACf,IAAI,CAACpB,QAAQ,aAAa,EACxB,MAAM,IAAIG,mBACR,SACA,IAAIuB,UAAU;gBAGlB,MAAMkE,YACJxE,AAAc,WAAdA,IAAI,KAAK,GACL;oBAAE,OAAO;oBAAiB,OAAOA,IAAI,IAAI,CAAC,KAAK;gBAAC,IAChD;oBACE,OAAO;oBACP,OAAOA,IAAI,QAAQ,CAAC,aAAa;gBACnC;gBACN,MAAMyE,SAAS,MAAM7F,QAAQ,aAAa,CAAC,OAAO,CAAC;oBACjD,QAAQoB,IAAI,KAAK,CAAC,MAAM;oBACxB,SAASA,IAAI,OAAO;oBACpB,SAASA,IAAI,OAAO;oBACpB,QAAQA,IAAI,MAAM;oBAClBwE;gBACF;gBACA,OAAOC,UAAU;oBAAE,SAAS;gBAAwB;YACtD;QACF;KACD;AACH"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@midscene/test",
3
3
  "description": "Extensible YAML test runner and node SDK for Midscene.",
4
- "version": "1.12.2-beta-20260828074555.0",
4
+ "version": "1.12.2",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/web-infra-dev/midscene.git",
@@ -63,9 +63,9 @@
63
63
  "playwright": "^1.45.0",
64
64
  "typescript": "^5.8.3",
65
65
  "vitest": "3.0.5",
66
- "@midscene/android": "1.12.2-beta-20260828074555.0",
67
- "@midscene/ios": "1.12.2-beta-20260828074555.0",
68
- "@midscene/web": "1.12.2-beta-20260828074555.0"
66
+ "@midscene/android": "1.12.2",
67
+ "@midscene/ios": "1.12.2",
68
+ "@midscene/web": "1.12.2"
69
69
  },
70
70
  "peerDependencies": {
71
71
  "playwright": "^1.45.0"