@midscene/core 1.12.4-beta-20260904065253.0 → 1.12.4

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.
Files changed (65) hide show
  1. package/dist/es/agent/agent.mjs +72 -25
  2. package/dist/es/agent/agent.mjs.map +1 -1
  3. package/dist/es/agent/index.mjs +2 -1
  4. package/dist/es/agent/insight.mjs +26 -10
  5. package/dist/es/agent/insight.mjs.map +1 -1
  6. package/dist/es/agent/prompt-context.mjs +12 -7
  7. package/dist/es/agent/prompt-context.mjs.map +1 -1
  8. package/dist/es/agent/run-gherkin-scenario.mjs +1 -1
  9. package/dist/es/agent/run-gherkin-scenario.mjs.map +1 -1
  10. package/dist/es/agent/tasks.mjs +2 -1
  11. package/dist/es/agent/tasks.mjs.map +1 -1
  12. package/dist/es/agent/test-runner-nodes.mjs +274 -0
  13. package/dist/es/agent/test-runner-nodes.mjs.map +1 -0
  14. package/dist/es/agent/utils.mjs +1 -1
  15. package/dist/es/ai-model/prompt/insight/user-prompt.mjs +1 -1
  16. package/dist/es/ai-model/prompt/insight/user-prompt.mjs.map +1 -1
  17. package/dist/es/ai-model/workflows/insight/extraction.mjs +3 -1
  18. package/dist/es/ai-model/workflows/insight/extraction.mjs.map +1 -1
  19. package/dist/es/ai-model/workflows/planning/custom-planning.mjs +3 -3
  20. package/dist/es/ai-model/workflows/planning/custom-planning.mjs.map +1 -1
  21. package/dist/es/ai-model/workflows/planning/standard-planning.mjs +1 -1
  22. package/dist/es/ai-model/workflows/planning/standard-planning.mjs.map +1 -1
  23. package/dist/es/report-html-template.mjs +1 -1
  24. package/dist/es/types.mjs.map +1 -1
  25. package/dist/es/utils.mjs +1 -1
  26. package/dist/es/yaml/player.mjs +0 -5
  27. package/dist/es/yaml/player.mjs.map +1 -1
  28. package/dist/es/yaml.mjs.map +1 -1
  29. package/dist/lib/agent/agent.js +72 -25
  30. package/dist/lib/agent/agent.js.map +1 -1
  31. package/dist/lib/agent/index.js +57 -8
  32. package/dist/lib/agent/insight.js +26 -10
  33. package/dist/lib/agent/insight.js.map +1 -1
  34. package/dist/lib/agent/prompt-context.js +16 -8
  35. package/dist/lib/agent/prompt-context.js.map +1 -1
  36. package/dist/lib/agent/run-gherkin-scenario.js +1 -1
  37. package/dist/lib/agent/run-gherkin-scenario.js.map +1 -1
  38. package/dist/lib/agent/tasks.js +2 -1
  39. package/dist/lib/agent/tasks.js.map +1 -1
  40. package/dist/lib/agent/test-runner-nodes.js +353 -0
  41. package/dist/lib/agent/test-runner-nodes.js.map +1 -0
  42. package/dist/lib/agent/utils.js +1 -1
  43. package/dist/lib/ai-model/prompt/insight/user-prompt.js +1 -1
  44. package/dist/lib/ai-model/prompt/insight/user-prompt.js.map +1 -1
  45. package/dist/lib/ai-model/workflows/insight/extraction.js +3 -1
  46. package/dist/lib/ai-model/workflows/insight/extraction.js.map +1 -1
  47. package/dist/lib/ai-model/workflows/planning/custom-planning.js +3 -3
  48. package/dist/lib/ai-model/workflows/planning/custom-planning.js.map +1 -1
  49. package/dist/lib/ai-model/workflows/planning/standard-planning.js +1 -1
  50. package/dist/lib/ai-model/workflows/planning/standard-planning.js.map +1 -1
  51. package/dist/lib/report-html-template.js +1 -1
  52. package/dist/lib/types.js.map +1 -1
  53. package/dist/lib/utils.js +1 -1
  54. package/dist/lib/yaml/player.js +0 -5
  55. package/dist/lib/yaml/player.js.map +1 -1
  56. package/dist/lib/yaml.js.map +1 -1
  57. package/dist/types/agent/agent.d.ts +26 -3
  58. package/dist/types/agent/index.d.ts +3 -1
  59. package/dist/types/agent/insight.d.ts +5 -1
  60. package/dist/types/agent/prompt-context.d.ts +2 -0
  61. package/dist/types/agent/run-gherkin-scenario.d.ts +1 -0
  62. package/dist/types/agent/test-runner-nodes.d.ts +192 -0
  63. package/dist/types/types.d.ts +28 -0
  64. package/dist/types/yaml.d.ts +12 -4
  65. package/package.json +10 -2
@@ -43,6 +43,17 @@ const defaultQueryOptions = {
43
43
  screenshotIncluded: true
44
44
  };
45
45
  class Insight {
46
+ resolveContext(apiName, options) {
47
+ return this.resolveAgentContext(apiName, options?.context);
48
+ }
49
+ withContext(apiName, options) {
50
+ const resolvedContext = this.resolveContext(apiName, options);
51
+ if (void 0 === resolvedContext) return options;
52
+ return {
53
+ ...options,
54
+ context: resolvedContext
55
+ };
56
+ }
46
57
  executionOptions(options, includeAbortSignal = false) {
47
58
  const uiContext = this.getUIContext?.();
48
59
  if (!uiContext && !includeAbortSignal && !options?.abortSignal) return;
@@ -58,32 +69,35 @@ class Insight {
58
69
  async aiQuery(demand, options = defaultQueryOptions) {
59
70
  const modelRuntime = this.resolveModelRuntime();
60
71
  const executionOptions = this.executionOptions();
61
- const { output } = executionOptions ? await this.taskExecutor.createTypeQueryExecution('Query', demand, modelRuntime, options, void 0, executionOptions) : await this.taskExecutor.createTypeQueryExecution('Query', demand, modelRuntime, options);
72
+ const serviceOptions = this.withContext('aiQuery', options);
73
+ const { output } = executionOptions ? await this.taskExecutor.createTypeQueryExecution('Query', demand, modelRuntime, serviceOptions, void 0, executionOptions) : await this.taskExecutor.createTypeQueryExecution('Query', demand, modelRuntime, serviceOptions);
62
74
  return output;
63
75
  }
64
76
  async aiBoolean(prompt, options = defaultQueryOptions) {
65
- return this.queryPrimitive('Boolean', prompt, options);
77
+ return this.queryPrimitive('Boolean', 'aiBoolean', prompt, options);
66
78
  }
67
79
  async aiNumber(prompt, options = defaultQueryOptions) {
68
- return this.queryPrimitive('Number', prompt, options);
80
+ return this.queryPrimitive('Number', 'aiNumber', prompt, options);
69
81
  }
70
82
  async aiString(prompt, options = defaultQueryOptions) {
71
- return this.queryPrimitive('String', prompt, options);
83
+ return this.queryPrimitive('String', 'aiString', prompt, options);
72
84
  }
73
85
  async aiAsk(prompt, options = defaultQueryOptions) {
74
- return this.aiString(prompt, options);
86
+ return this.queryPrimitive('String', 'aiAsk', prompt, options);
75
87
  }
76
- async queryPrimitive(type, prompt, options) {
88
+ async queryPrimitive(type, apiName, prompt, options) {
77
89
  const { textPrompt, multimodalPrompt } = (0, external_utils_js_namespaceObject.parsePrompt)(prompt);
78
- const { output } = await this.taskExecutor.createTypeQueryExecution(type, textPrompt, this.resolveModelRuntime(), options, multimodalPrompt, this.executionOptions());
90
+ const serviceOptions = this.withContext(apiName, options);
91
+ const { output } = await this.taskExecutor.createTypeQueryExecution(type, textPrompt, this.resolveModelRuntime(), serviceOptions, multimodalPrompt, this.executionOptions());
79
92
  return output;
80
93
  }
81
94
  async aiAssert(assertion, message, options) {
95
+ const contextOptions = this.withContext('aiAssert', options ?? {});
82
96
  const serviceOptions = {
83
97
  domIncluded: options?.domIncluded ?? defaultQueryOptions.domIncluded,
84
98
  screenshotIncluded: options?.screenshotIncluded ?? defaultQueryOptions.screenshotIncluded,
85
- ...options?.context !== void 0 ? {
86
- context: options.context
99
+ ...void 0 !== contextOptions.context ? {
100
+ context: contextOptions.context
87
101
  } : {}
88
102
  };
89
103
  const { textPrompt, multimodalPrompt } = (0, external_utils_js_namespaceObject.parsePrompt)(assertion);
@@ -116,12 +130,14 @@ class Insight {
116
130
  throw error;
117
131
  }
118
132
  }
119
- constructor(taskExecutor, resolveModelRuntime, getUIContext){
133
+ constructor(taskExecutor, resolveModelRuntime, resolveAgentContext, getUIContext){
120
134
  _define_property(this, "taskExecutor", void 0);
121
135
  _define_property(this, "resolveModelRuntime", void 0);
136
+ _define_property(this, "resolveAgentContext", void 0);
122
137
  _define_property(this, "getUIContext", void 0);
123
138
  this.taskExecutor = taskExecutor;
124
139
  this.resolveModelRuntime = resolveModelRuntime;
140
+ this.resolveAgentContext = resolveAgentContext;
125
141
  this.getUIContext = getUIContext;
126
142
  }
127
143
  }
@@ -1 +1 @@
1
- {"version":3,"file":"agent/insight.js","sources":["webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../../../src/agent/insight.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 { TUserPrompt } from '@/ai-model/index';\nimport type { ModelRuntime } from '@/ai-model/models';\nimport type {\n AgentAssertResult,\n AssertOptions,\n InsightAPI,\n QueryOptions,\n ServiceExtractParam,\n UIContext,\n} from '@/types';\nimport { TaskExecutionError, type TaskExecutor } from './tasks';\nimport { parsePrompt } from './utils';\n\nconst defaultQueryOptions: QueryOptions = {\n domIncluded: false,\n screenshotIncluded: true,\n};\n\ntype InsightTaskExecutor = Pick<TaskExecutor, 'createTypeQueryExecution'>;\n\n/** Execute read-only AI operations against either live or fixed UI context. */\nexport class Insight implements InsightAPI {\n constructor(\n private readonly taskExecutor: InsightTaskExecutor,\n private readonly resolveModelRuntime: () => ModelRuntime,\n private readonly getUIContext?: () => UIContext,\n ) {}\n\n private executionOptions(\n options?: AssertOptions,\n includeAbortSignal = false,\n ): { abortSignal?: AbortSignal; uiContext?: UIContext } | undefined {\n const uiContext = this.getUIContext?.();\n if (!uiContext && !includeAbortSignal && !options?.abortSignal) {\n return undefined;\n }\n return {\n ...(includeAbortSignal || options?.abortSignal\n ? { abortSignal: options?.abortSignal }\n : {}),\n ...(uiContext ? { uiContext } : {}),\n };\n }\n\n async aiQuery<ReturnType = any>(\n demand: ServiceExtractParam,\n options: QueryOptions = defaultQueryOptions,\n ): Promise<ReturnType> {\n const modelRuntime = this.resolveModelRuntime();\n const executionOptions = this.executionOptions();\n const { output } = executionOptions\n ? await this.taskExecutor.createTypeQueryExecution(\n 'Query',\n demand,\n modelRuntime,\n options,\n undefined,\n executionOptions,\n )\n : await this.taskExecutor.createTypeQueryExecution(\n 'Query',\n demand,\n modelRuntime,\n options,\n );\n return output as ReturnType;\n }\n\n async aiBoolean(\n prompt: TUserPrompt,\n options: QueryOptions = defaultQueryOptions,\n ): Promise<boolean> {\n return this.queryPrimitive('Boolean', prompt, options);\n }\n\n async aiNumber(\n prompt: TUserPrompt,\n options: QueryOptions = defaultQueryOptions,\n ): Promise<number> {\n return this.queryPrimitive('Number', prompt, options);\n }\n\n async aiString(\n prompt: TUserPrompt,\n options: QueryOptions = defaultQueryOptions,\n ): Promise<string> {\n return this.queryPrimitive('String', prompt, options);\n }\n\n async aiAsk(\n prompt: TUserPrompt,\n options: QueryOptions = defaultQueryOptions,\n ): Promise<string> {\n return this.aiString(prompt, options);\n }\n\n private async queryPrimitive<ReturnType>(\n type: 'Boolean' | 'Number' | 'String',\n prompt: TUserPrompt,\n options: QueryOptions,\n ): Promise<ReturnType> {\n const { textPrompt, multimodalPrompt } = parsePrompt(prompt);\n const { output } = await this.taskExecutor.createTypeQueryExecution(\n type,\n textPrompt,\n this.resolveModelRuntime(),\n options,\n multimodalPrompt,\n this.executionOptions(),\n );\n return output as ReturnType;\n }\n\n async aiAssert(\n assertion: TUserPrompt,\n message?: string,\n options?: AssertOptions,\n ): Promise<AgentAssertResult | undefined> {\n const serviceOptions: QueryOptions = {\n domIncluded: options?.domIncluded ?? defaultQueryOptions.domIncluded,\n screenshotIncluded:\n options?.screenshotIncluded ?? defaultQueryOptions.screenshotIncluded,\n ...(options?.context !== undefined ? { context: options.context } : {}),\n };\n const { textPrompt, multimodalPrompt } = parsePrompt(assertion);\n const assertionText =\n typeof assertion === 'string' ? assertion : assertion.prompt;\n\n try {\n const { output, thought } =\n await this.taskExecutor.createTypeQueryExecution<boolean>(\n 'Assert',\n textPrompt,\n this.resolveModelRuntime(),\n serviceOptions,\n multimodalPrompt,\n this.executionOptions(options, true),\n );\n\n const pass = Boolean(output);\n const failureMessage = pass\n ? undefined\n : `Assertion failed: ${message || assertionText}\\nReason: ${thought || '(no_reason)'}`;\n\n if (options?.keepRawResponse) {\n return { pass, thought, message: failureMessage };\n }\n if (!pass) {\n throw new Error(failureMessage);\n }\n } catch (error) {\n if (error instanceof TaskExecutionError) {\n const thought = error.task?.thought;\n const diagnosticMessage =\n error.task?.errorMessage || error.cause.message;\n const reason = thought || diagnosticMessage || '(no_reason)';\n const failureMessage = `Assertion failed: ${message || assertionText}\\nReason: ${reason}`;\n\n if (options?.keepRawResponse) {\n return { pass: false, thought, message: failureMessage };\n }\n throw new Error(failureMessage, { cause: error.cause });\n }\n throw error;\n }\n }\n}\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","defaultQueryOptions","Insight","options","includeAbortSignal","uiContext","demand","modelRuntime","executionOptions","output","undefined","prompt","type","textPrompt","multimodalPrompt","parsePrompt","assertion","message","serviceOptions","assertionText","thought","pass","Boolean","failureMessage","Error","error","TaskExecutionError","diagnosticMessage","reason","taskExecutor","resolveModelRuntime","getUIContext"],"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;;;;;;;;;;;;;;;;;;;ACOA,MAAMI,sBAAoC;IACxC,aAA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AI,EAAE,gBAAgBA,MAAM,KAAK,CAAC,OAAO;gBACjD,MAAMG,SAASR,WAAWO,qBAAqB;gBAC/C,MAAMJ,iBAAiB,CAAC,kBAAkB,EAAEN,WAAWE,cAAc,UAAU,EAAES,QAAQ;gBAEzF,IAAIzB,SAAS,iBACX,OAAO;oBAAE,MAAM;oBAAOiB;oBAAS,SAASG;gBAAe;gBAEzD,MAAM,IAAIC,MAAMD,gBAAgB;oBAAE,OAAOE,MAAM,KAAK;gBAAC;YACvD;YACA,MAAMA;QACR;IACF;IA/IA,YACmBI,YAAiC,EACjCC,mBAAuC,EACvCC,YAA8B,CAC/C;;;;aAHiBF,YAAY,GAAZA;aACAC,mBAAmB,GAAnBA;aACAC,YAAY,GAAZA;IAChB;AA4IL"}
1
+ {"version":3,"file":"agent/insight.js","sources":["webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../../../src/agent/insight.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 { TUserPrompt } from '@/ai-model/index';\nimport type { ModelRuntime } from '@/ai-model/models';\nimport type {\n AgentAssertResult,\n AssertOptions,\n InsightAPI,\n QueryOptions,\n ServiceExtractParam,\n UIContext,\n} from '@/types';\nimport type { AiApiName } from '@midscene/shared/agent-tools/agent-context';\nimport { TaskExecutionError, type TaskExecutor } from './tasks';\nimport { parsePrompt } from './utils';\n\nconst defaultQueryOptions: QueryOptions = {\n domIncluded: false,\n screenshotIncluded: true,\n};\n\ntype InsightTaskExecutor = Pick<TaskExecutor, 'createTypeQueryExecution'>;\n\ntype InsightContextOptions = { context?: string };\n\n/** Execute read-only AI operations against either live or fixed UI context. */\nexport class Insight implements InsightAPI {\n constructor(\n private readonly taskExecutor: InsightTaskExecutor,\n private readonly resolveModelRuntime: () => ModelRuntime,\n private readonly resolveAgentContext: (\n apiName: AiApiName,\n callContext?: string,\n ) => string | undefined,\n private readonly getUIContext?: () => UIContext,\n ) {}\n\n private resolveContext(\n apiName: AiApiName,\n options?: InsightContextOptions,\n ): string | undefined {\n return this.resolveAgentContext(apiName, options?.context);\n }\n\n private withContext<T extends InsightContextOptions>(\n apiName: AiApiName,\n options: T,\n ): T {\n const resolvedContext = this.resolveContext(apiName, options);\n if (resolvedContext === undefined) {\n return options;\n }\n\n return {\n ...options,\n context: resolvedContext,\n };\n }\n\n private executionOptions(\n options?: AssertOptions,\n includeAbortSignal = false,\n ): { abortSignal?: AbortSignal; uiContext?: UIContext } | undefined {\n const uiContext = this.getUIContext?.();\n if (!uiContext && !includeAbortSignal && !options?.abortSignal) {\n return undefined;\n }\n return {\n ...(includeAbortSignal || options?.abortSignal\n ? { abortSignal: options?.abortSignal }\n : {}),\n ...(uiContext ? { uiContext } : {}),\n };\n }\n\n async aiQuery<ReturnType = any>(\n demand: ServiceExtractParam,\n options: QueryOptions = defaultQueryOptions,\n ): Promise<ReturnType> {\n const modelRuntime = this.resolveModelRuntime();\n const executionOptions = this.executionOptions();\n const serviceOptions = this.withContext('aiQuery', options);\n const { output } = executionOptions\n ? await this.taskExecutor.createTypeQueryExecution(\n 'Query',\n demand,\n modelRuntime,\n serviceOptions,\n undefined,\n executionOptions,\n )\n : await this.taskExecutor.createTypeQueryExecution(\n 'Query',\n demand,\n modelRuntime,\n serviceOptions,\n );\n return output as ReturnType;\n }\n\n async aiBoolean(\n prompt: TUserPrompt,\n options: QueryOptions = defaultQueryOptions,\n ): Promise<boolean> {\n return this.queryPrimitive('Boolean', 'aiBoolean', prompt, options);\n }\n\n async aiNumber(\n prompt: TUserPrompt,\n options: QueryOptions = defaultQueryOptions,\n ): Promise<number> {\n return this.queryPrimitive('Number', 'aiNumber', prompt, options);\n }\n\n async aiString(\n prompt: TUserPrompt,\n options: QueryOptions = defaultQueryOptions,\n ): Promise<string> {\n return this.queryPrimitive('String', 'aiString', prompt, options);\n }\n\n async aiAsk(\n prompt: TUserPrompt,\n options: QueryOptions = defaultQueryOptions,\n ): Promise<string> {\n return this.queryPrimitive('String', 'aiAsk', prompt, options);\n }\n\n private async queryPrimitive<ReturnType>(\n type: 'Boolean' | 'Number' | 'String',\n apiName: 'aiBoolean' | 'aiNumber' | 'aiString' | 'aiAsk',\n prompt: TUserPrompt,\n options: QueryOptions,\n ): Promise<ReturnType> {\n const { textPrompt, multimodalPrompt } = parsePrompt(prompt);\n const serviceOptions = this.withContext(apiName, options);\n const { output } = await this.taskExecutor.createTypeQueryExecution(\n type,\n textPrompt,\n this.resolveModelRuntime(),\n serviceOptions,\n multimodalPrompt,\n this.executionOptions(),\n );\n return output as ReturnType;\n }\n\n async aiAssert(\n assertion: TUserPrompt,\n message?: string,\n options?: AssertOptions,\n ): Promise<AgentAssertResult | undefined> {\n const contextOptions = this.withContext('aiAssert', options ?? {});\n const serviceOptions: QueryOptions = {\n domIncluded: options?.domIncluded ?? defaultQueryOptions.domIncluded,\n screenshotIncluded:\n options?.screenshotIncluded ?? defaultQueryOptions.screenshotIncluded,\n ...(contextOptions.context !== undefined\n ? { context: contextOptions.context }\n : {}),\n };\n const { textPrompt, multimodalPrompt } = parsePrompt(assertion);\n const assertionText =\n typeof assertion === 'string' ? assertion : assertion.prompt;\n\n try {\n const { output, thought } =\n await this.taskExecutor.createTypeQueryExecution<boolean>(\n 'Assert',\n textPrompt,\n this.resolveModelRuntime(),\n serviceOptions,\n multimodalPrompt,\n this.executionOptions(options, true),\n );\n\n const pass = Boolean(output);\n const failureMessage = pass\n ? undefined\n : `Assertion failed: ${message || assertionText}\\nReason: ${thought || '(no_reason)'}`;\n\n if (options?.keepRawResponse) {\n return { pass, thought, message: failureMessage };\n }\n if (!pass) {\n throw new Error(failureMessage);\n }\n } catch (error) {\n if (error instanceof TaskExecutionError) {\n const thought = error.task?.thought;\n const diagnosticMessage =\n error.task?.errorMessage || error.cause.message;\n const reason = thought || diagnosticMessage || '(no_reason)';\n const failureMessage = `Assertion failed: ${message || assertionText}\\nReason: ${reason}`;\n\n if (options?.keepRawResponse) {\n return { pass: false, thought, message: failureMessage };\n }\n throw new Error(failureMessage, { cause: error.cause });\n }\n throw error;\n }\n }\n}\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","defaultQueryOptions","Insight","apiName","options","resolvedContext","undefined","includeAbortSignal","uiContext","demand","modelRuntime","executionOptions","serviceOptions","output","prompt","type","textPrompt","multimodalPrompt","parsePrompt","assertion","message","contextOptions","assertionText","thought","pass","Boolean","failureMessage","Error","error","TaskExecutionError","diagnosticMessage","reason","taskExecutor","resolveModelRuntime","resolveAgentContext","getUIContext"],"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;;;;;;;;;;;;;;;;;;;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AAEU,OAAO,EAAE,GACvB,MAAM,IAAI,CAAC,YAAY,CAAC,wBAAwB,CAC9C,UACAP,YACA,IAAI,CAAC,mBAAmB,IACxBJ,gBACAK,kBACA,IAAI,CAAC,gBAAgB,CAACb,SAAS;YAGnC,MAAMoB,OAAOC,QAAQZ;YACrB,MAAMa,iBAAiBF,OACnBlB,SACA,CAAC,kBAAkB,EAAEc,WAAWE,cAAc,UAAU,EAAEC,WAAW,eAAe;YAExF,IAAInB,SAAS,iBACX,OAAO;gBAAEoB;gBAAMD;gBAAS,SAASG;YAAe;YAElD,IAAI,CAACF,MACH,MAAM,IAAIG,MAAMD;QAEpB,EAAE,OAAOE,OAAO;YACd,IAAIA,iBAAiBC,kCAAAA,kBAAkBA,EAAE;gBACvC,MAAMN,UAAUK,MAAM,IAAI,EAAE;gBAC5B,MAAME,oBACJF,MAAM,IAAI,EAAE,gBAAgBA,MAAM,KAAK,CAAC,OAAO;gBACjD,MAAMG,SAASR,WAAWO,qBAAqB;gBAC/C,MAAMJ,iBAAiB,CAAC,kBAAkB,EAAEN,WAAWE,cAAc,UAAU,EAAES,QAAQ;gBAEzF,IAAI3B,SAAS,iBACX,OAAO;oBAAE,MAAM;oBAAOmB;oBAAS,SAASG;gBAAe;gBAEzD,MAAM,IAAIC,MAAMD,gBAAgB;oBAAE,OAAOE,MAAM,KAAK;gBAAC;YACvD;YACA,MAAMA;QACR;IACF;IA/KA,YACmBI,YAAiC,EACjCC,mBAAuC,EACvCC,mBAGM,EACNC,YAA8B,CAC/C;;;;;aAPiBH,YAAY,GAAZA;aACAC,mBAAmB,GAAnBA;aACAC,mBAAmB,GAAnBA;aAIAC,YAAY,GAAZA;IAChB;AAwKL"}
@@ -25,13 +25,19 @@ var __webpack_exports__ = {};
25
25
  __webpack_require__.r(__webpack_exports__);
26
26
  __webpack_require__.d(__webpack_exports__, {
27
27
  buildLocatePromptWithContext: ()=>buildLocatePromptWithContext,
28
- buildPromptWithContext: ()=>buildPromptWithContext
28
+ buildPromptWithContext: ()=>buildPromptWithContext,
29
+ renderAIContext: ()=>renderAIContext
29
30
  });
30
- const buildPromptWithContext = (prompt, context)=>{
31
+ const renderAIContext = (context)=>{
31
32
  const trimmedContext = context?.trim();
32
- if (!trimmedContext) return prompt;
33
+ if (trimmedContext) return `<CONTEXT>\n${trimmedContext}\n</CONTEXT>`;
34
+ return void 0 === context ? void 0 : '';
35
+ };
36
+ const buildPromptWithContext = (prompt, context)=>{
37
+ const renderedContext = renderAIContext(context);
38
+ if (!renderedContext) return prompt;
33
39
  const promptText = 'string' == typeof prompt ? prompt : prompt.prompt;
34
- const promptWithContext = `Context for this request:\n${trimmedContext}\n\n${promptText}`;
40
+ const promptWithContext = `${renderedContext}\n\n${promptText}`;
35
41
  if ('string' == typeof prompt) return promptWithContext;
36
42
  return {
37
43
  ...prompt,
@@ -39,10 +45,10 @@ const buildPromptWithContext = (prompt, context)=>{
39
45
  };
40
46
  };
41
47
  const buildLocatePromptWithContext = (prompt, context)=>{
42
- const trimmedContext = context?.trim();
43
- if (!trimmedContext) return prompt;
48
+ const renderedContext = renderAIContext(context);
49
+ if (!renderedContext) return prompt;
44
50
  const promptText = 'string' == typeof prompt ? prompt : prompt.prompt;
45
- const promptWithContext = `<CONTEXT>\n${trimmedContext}\n</CONTEXT>\n\n<LOCATE_TARGET>\n${promptText}\n</LOCATE_TARGET>`;
51
+ const promptWithContext = `${renderedContext}\n\n<LOCATE_TARGET>\n${promptText}\n</LOCATE_TARGET>`;
46
52
  if ('string' == typeof prompt) return promptWithContext;
47
53
  return {
48
54
  ...prompt,
@@ -51,9 +57,11 @@ const buildLocatePromptWithContext = (prompt, context)=>{
51
57
  };
52
58
  exports.buildLocatePromptWithContext = __webpack_exports__.buildLocatePromptWithContext;
53
59
  exports.buildPromptWithContext = __webpack_exports__.buildPromptWithContext;
60
+ exports.renderAIContext = __webpack_exports__.renderAIContext;
54
61
  for(var __rspack_i in __webpack_exports__)if (-1 === [
55
62
  "buildLocatePromptWithContext",
56
- "buildPromptWithContext"
63
+ "buildPromptWithContext",
64
+ "renderAIContext"
57
65
  ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
58
66
  Object.defineProperty(exports, '__esModule', {
59
67
  value: true
@@ -1 +1 @@
1
- {"version":3,"file":"agent/prompt-context.js","sources":["webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../../../src/agent/prompt-context.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 { TUserPrompt } from '@/ai-model';\n\nexport const buildPromptWithContext = (\n prompt: TUserPrompt,\n context: string | undefined,\n): TUserPrompt => {\n const trimmedContext = context?.trim();\n if (!trimmedContext) {\n return prompt;\n }\n\n const promptText = typeof prompt === 'string' ? prompt : prompt.prompt;\n const promptWithContext = `Context for this request:\\n${trimmedContext}\\n\\n${promptText}`;\n\n if (typeof prompt === 'string') {\n return promptWithContext;\n }\n\n return {\n ...prompt,\n prompt: promptWithContext,\n };\n};\n\nexport const buildLocatePromptWithContext = (\n prompt: TUserPrompt,\n context: string | undefined,\n): TUserPrompt => {\n const trimmedContext = context?.trim();\n if (!trimmedContext) {\n return prompt;\n }\n\n const promptText = typeof prompt === 'string' ? prompt : prompt.prompt;\n const promptWithContext = `<CONTEXT>\\n${trimmedContext}\\n</CONTEXT>\\n\\n<LOCATE_TARGET>\\n${promptText}\\n</LOCATE_TARGET>`;\n\n if (typeof prompt === 'string') {\n return promptWithContext;\n }\n\n return {\n ...prompt,\n prompt: promptWithContext,\n };\n};\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","buildPromptWithContext","prompt","context","trimmedContext","promptText","promptWithContext","buildLocatePromptWithContext"],"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;;;;;;;;ACJO,MAAMI,yBAAyB,CACpCC,QACAC;IAEA,MAAMC,iBAAiBD,SAAS;IAChC,IAAI,CAACC,gBACH,OAAOF;IAGT,MAAMG,aAAa,AAAkB,YAAlB,OAAOH,SAAsBA,SAASA,OAAO,MAAM;IACtE,MAAMI,oBAAoB,CAAC,2BAA2B,EAAEF,eAAe,IAAI,EAAEC,YAAY;IAEzF,IAAI,AAAkB,YAAlB,OAAOH,QACT,OAAOI;IAGT,OAAO;QACL,GAAGJ,MAAM;QACT,QAAQI;IACV;AACF;AAEO,MAAMC,+BAA+B,CAC1CL,QACAC;IAEA,MAAMC,iBAAiBD,SAAS;IAChC,IAAI,CAACC,gBACH,OAAOF;IAGT,MAAMG,aAAa,AAAkB,YAAlB,OAAOH,SAAsBA,SAASA,OAAO,MAAM;IACtE,MAAMI,oBAAoB,CAAC,WAAW,EAAEF,eAAe,iCAAiC,EAAEC,WAAW,kBAAkB,CAAC;IAExH,IAAI,AAAkB,YAAlB,OAAOH,QACT,OAAOI;IAGT,OAAO;QACL,GAAGJ,MAAM;QACT,QAAQI;IACV;AACF"}
1
+ {"version":3,"file":"agent/prompt-context.js","sources":["webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../../../src/agent/prompt-context.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 { TUserPrompt } from '@/ai-model';\n\n/** Render user-provided AI guidance at the model prompt boundary. */\nexport const renderAIContext = (\n context: string | undefined,\n): string | undefined => {\n const trimmedContext = context?.trim();\n if (trimmedContext) {\n return `<CONTEXT>\\n${trimmedContext}\\n</CONTEXT>`;\n }\n\n return context === undefined ? undefined : '';\n};\n\nexport const buildPromptWithContext = (\n prompt: TUserPrompt,\n context: string | undefined,\n): TUserPrompt => {\n const renderedContext = renderAIContext(context);\n if (!renderedContext) {\n return prompt;\n }\n\n const promptText = typeof prompt === 'string' ? prompt : prompt.prompt;\n const promptWithContext = `${renderedContext}\\n\\n${promptText}`;\n\n if (typeof prompt === 'string') {\n return promptWithContext;\n }\n\n return {\n ...prompt,\n prompt: promptWithContext,\n };\n};\n\nexport const buildLocatePromptWithContext = (\n prompt: TUserPrompt,\n context: string | undefined,\n): TUserPrompt => {\n const renderedContext = renderAIContext(context);\n if (!renderedContext) {\n return prompt;\n }\n\n const promptText = typeof prompt === 'string' ? prompt : prompt.prompt;\n const promptWithContext = `${renderedContext}\\n\\n<LOCATE_TARGET>\\n${promptText}\\n</LOCATE_TARGET>`;\n\n if (typeof prompt === 'string') {\n return promptWithContext;\n }\n\n return {\n ...prompt,\n prompt: promptWithContext,\n };\n};\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","renderAIContext","context","trimmedContext","undefined","buildPromptWithContext","prompt","renderedContext","promptText","promptWithContext","buildLocatePromptWithContext"],"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;;;;;;;;;ACHO,MAAMI,kBAAkB,CAC7BC;IAEA,MAAMC,iBAAiBD,SAAS;IAChC,IAAIC,gBACF,OAAO,CAAC,WAAW,EAAEA,eAAe,YAAY,CAAC;IAGnD,OAAOD,AAAYE,WAAZF,UAAwBE,SAAY;AAC7C;AAEO,MAAMC,yBAAyB,CACpCC,QACAJ;IAEA,MAAMK,kBAAkBN,gBAAgBC;IACxC,IAAI,CAACK,iBACH,OAAOD;IAGT,MAAME,aAAa,AAAkB,YAAlB,OAAOF,SAAsBA,SAASA,OAAO,MAAM;IACtE,MAAMG,oBAAoB,GAAGF,gBAAgB,IAAI,EAAEC,YAAY;IAE/D,IAAI,AAAkB,YAAlB,OAAOF,QACT,OAAOG;IAGT,OAAO;QACL,GAAGH,MAAM;QACT,QAAQG;IACV;AACF;AAEO,MAAMC,+BAA+B,CAC1CJ,QACAJ;IAEA,MAAMK,kBAAkBN,gBAAgBC;IACxC,IAAI,CAACK,iBACH,OAAOD;IAGT,MAAME,aAAa,AAAkB,YAAlB,OAAOF,SAAsBA,SAASA,OAAO,MAAM;IACtE,MAAMG,oBAAoB,GAAGF,gBAAgB,qBAAqB,EAAEC,WAAW,kBAAkB,CAAC;IAElG,IAAI,AAAkB,YAAlB,OAAOF,QACT,OAAOG;IAGT,OAAO;QACL,GAAGH,MAAM;QACT,QAAQG;IACV;AACF"}
@@ -126,7 +126,7 @@ const runGherkinScenario = async (agent, scenarioText, opt)=>{
126
126
  const prompt = buildStepPrompt(step);
127
127
  try {
128
128
  if ('aiAct' === action) await agent.aiAct(prompt, aiActOptions);
129
- else if (opt?.context || opt?.abortSignal) await agent.aiAssert(prompt, void 0, {
129
+ else if (opt?.context !== void 0 || opt?.abortSignal) await agent.aiAssert(prompt, void 0, {
130
130
  context: opt.context,
131
131
  abortSignal: opt.abortSignal
132
132
  });
@@ -1 +1 @@
1
- {"version":3,"file":"agent/run-gherkin-scenario.js","sources":["webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../../../src/agent/run-gherkin-scenario.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 { AiActOptions } from './agent';\n\nexport type GherkinStepKeyword = 'Given' | 'When' | 'Then' | 'And' | 'But';\n\ntype RunGherkinScenarioStepAction = 'aiAct' | 'aiAssert';\n\nexport type RunGherkinScenarioOptions = AiActOptions & {\n context?: string;\n};\n\ntype GherkinPrimaryKeyword = 'Given' | 'When' | 'Then';\n\ntype ParsedGherkinStep = {\n keyword: GherkinStepKeyword;\n effectiveKeyword: GherkinPrimaryKeyword;\n text: string;\n lineNumber: number;\n};\n\ntype RawGherkinStep = {\n keyword: GherkinStepKeyword;\n text: string;\n lineNumber: number;\n};\n\ntype ParsedGherkinScenario = {\n scenario?: string;\n steps: ParsedGherkinStep[];\n};\n\ntype GherkinScenarioAgent = {\n aiAct: (taskPrompt: string, opt?: AiActOptions) => Promise<unknown>;\n aiAssert: (\n assertion: string,\n msg?: string,\n opt?: { context?: string; abortSignal?: AbortSignal },\n ) => Promise<unknown>;\n};\n\nconst stepKeywordPattern = /^(Given|When|Then|And|But)\\s+(.+)$/i;\nconst headerPattern = /^(Scenario):\\s*(.*)$/i;\nconst unsupportedHeaderPattern =\n /^(Feature|Background|Scenario Outline|Scenario Template|Examples|Rule):/i;\n\nconst normalizeStepKeyword = (keyword: string): GherkinStepKeyword => {\n const lowerKeyword = keyword.toLowerCase();\n if (lowerKeyword === 'given') return 'Given';\n if (lowerKeyword === 'when') return 'When';\n if (lowerKeyword === 'then') return 'Then';\n if (lowerKeyword === 'and') return 'And';\n return 'But';\n};\n\nconst isPrimaryKeyword = (\n keyword: GherkinStepKeyword,\n): keyword is GherkinPrimaryKeyword => {\n return keyword === 'Given' || keyword === 'When' || keyword === 'Then';\n};\n\nconst resolveSteps = (steps: RawGherkinStep[]): ParsedGherkinStep[] => {\n let previousPrimaryKeyword: GherkinPrimaryKeyword | undefined;\n\n return steps.map((step) => {\n const effectiveKeyword = isPrimaryKeyword(step.keyword)\n ? step.keyword\n : previousPrimaryKeyword;\n\n if (!effectiveKeyword) {\n throw new Error(\n `runGherkinScenario cannot resolve \"${step.keyword}\" at line ${step.lineNumber}; use Given, When, or Then before ${step.keyword}.`,\n );\n }\n\n previousPrimaryKeyword = effectiveKeyword;\n\n return {\n ...step,\n effectiveKeyword,\n };\n });\n};\n\nconst throwIfAborted = (abortSignal: AbortSignal | undefined) => {\n if (!abortSignal?.aborted) {\n return;\n }\n\n if (typeof abortSignal.throwIfAborted === 'function') {\n abortSignal.throwIfAborted();\n }\n\n throw new Error(\n `runGherkinScenario aborted: ${abortSignal.reason || 'signal already aborted'}`,\n );\n};\n\nexport const parseGherkinScenario = (\n scenarioText: string,\n): ParsedGherkinScenario => {\n const lines = scenarioText.split(/\\r?\\n/);\n const scenarioSteps: RawGherkinStep[] = [];\n const anonymousSteps: RawGherkinStep[] = [];\n let scenario: string | undefined;\n let scenarioCount = 0;\n let section: 'prelude' | 'scenario' = 'prelude';\n\n for (const [lineIndex, rawLine] of lines.entries()) {\n const lineNumber = lineIndex + 1;\n const line = rawLine.trim();\n\n if (!line || line.startsWith('#') || line.startsWith('@')) {\n continue;\n }\n\n if (line === '\"\"\"' || line === \"'''\") {\n throw new Error(\n `runGherkinScenario does not support doc strings; found one at line ${lineNumber}.`,\n );\n }\n\n if (line.startsWith('|')) {\n throw new Error(\n `runGherkinScenario does not support data tables; found one at line ${lineNumber}.`,\n );\n }\n\n if (unsupportedHeaderPattern.test(line)) {\n throw new Error(\n `runGherkinScenario does not support \"${line}\" at line ${lineNumber}.`,\n );\n }\n\n const headerMatch = line.match(headerPattern);\n if (headerMatch) {\n scenarioCount += 1;\n scenario = headerMatch[2].trim() || undefined;\n section = 'scenario';\n continue;\n }\n\n const stepMatch = line.match(stepKeywordPattern);\n if (stepMatch) {\n const step = {\n keyword: normalizeStepKeyword(stepMatch[1]),\n text: stepMatch[2].trim(),\n lineNumber,\n };\n\n if (section === 'scenario') {\n scenarioSteps.push(step);\n } else {\n anonymousSteps.push(step);\n }\n\n continue;\n }\n\n throw new Error(\n `runGherkinScenario does not support content at line ${lineNumber}: ${line}`,\n );\n }\n\n if (scenarioCount > 1) {\n throw new Error(\n `runGherkinScenario expects exactly one Scenario, but found ${scenarioCount}.`,\n );\n }\n\n if (scenarioCount === 1 && anonymousSteps.length > 0) {\n throw new Error(\n 'runGherkinScenario cannot mix anonymous steps with a Scenario block.',\n );\n }\n\n const rawSteps = scenarioCount === 1 ? scenarioSteps : anonymousSteps;\n\n if (rawSteps.length === 0) {\n throw new Error('runGherkinScenario requires at least one Gherkin step.');\n }\n\n return {\n scenario,\n steps: resolveSteps(rawSteps),\n };\n};\n\nconst buildStepPrompt = (step: ParsedGherkinStep) => {\n if (step.effectiveKeyword === 'Given') {\n return `Set up this precondition: ${step.text}`;\n }\n\n if (step.effectiveKeyword === 'When') {\n return `Perform this user action: ${step.text}`;\n }\n\n return `Verify that ${step.text}`;\n};\n\nconst describeStepExecution = (\n step: ParsedGherkinStep,\n action: RunGherkinScenarioStepAction,\n) => {\n const keywordMapping =\n step.keyword === step.effectiveKeyword\n ? step.keyword\n : `${step.keyword} as ${step.effectiveKeyword}`;\n\n if (step.effectiveKeyword === 'Given') {\n return `setting up the precondition (${keywordMapping} -> ${action})`;\n }\n\n if (step.effectiveKeyword === 'When') {\n return `performing the user action (${keywordMapping} -> ${action})`;\n }\n\n return `verifying the expected result (${keywordMapping} -> ${action})`;\n};\n\nconst describeErrorCause = (error: unknown) => {\n if (error instanceof Error && error.message) {\n return ` Original error: ${error.message}`;\n }\n\n return '';\n};\n\nexport const runGherkinScenario = async (\n agent: GherkinScenarioAgent,\n scenarioText: string,\n opt?: RunGherkinScenarioOptions,\n): Promise<void> => {\n const parsedScenario = parseGherkinScenario(scenarioText);\n const aiActOptions: AiActOptions = {\n ...opt,\n cacheable: false,\n };\n\n for (const step of parsedScenario.steps) {\n throwIfAborted(opt?.abortSignal);\n\n const action: RunGherkinScenarioStepAction =\n step.effectiveKeyword === 'Then' ? 'aiAssert' : 'aiAct';\n const prompt = buildStepPrompt(step);\n\n try {\n if (action === 'aiAct') {\n await agent.aiAct(prompt, aiActOptions);\n } else if (opt?.context || opt?.abortSignal) {\n await agent.aiAssert(prompt, undefined, {\n context: opt.context,\n abortSignal: opt.abortSignal,\n });\n } else {\n await agent.aiAssert(prompt);\n }\n } catch (error) {\n throw new Error(\n `runGherkinScenario failed while ${describeStepExecution(\n step,\n action,\n )} at line ${step.lineNumber}: ${step.keyword} ${step.text}.${describeErrorCause(\n error,\n )}`,\n {\n cause: error,\n },\n );\n }\n }\n};\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","stepKeywordPattern","headerPattern","unsupportedHeaderPattern","normalizeStepKeyword","keyword","lowerKeyword","isPrimaryKeyword","resolveSteps","steps","previousPrimaryKeyword","step","effectiveKeyword","Error","throwIfAborted","abortSignal","parseGherkinScenario","scenarioText","lines","scenarioSteps","anonymousSteps","scenario","scenarioCount","section","lineIndex","rawLine","lineNumber","line","headerMatch","undefined","stepMatch","rawSteps","buildStepPrompt","describeStepExecution","action","keywordMapping","describeErrorCause","error","runGherkinScenario","agent","opt","parsedScenario","aiActOptions","prompt"],"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,OAA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B,KAAK;QAEpB,MAAMN,SACJvB,AAA0B,WAA1BA,KAAK,gBAAgB,GAAc,aAAa;QAClD,MAAMgC,SAASX,gBAAgBrB;QAE/B,IAAI;YACF,IAAIuB,AAAW,YAAXA,QACF,MAAMK,MAAM,KAAK,CAACI,QAAQD;iBACrB,IAAIF,KAAK,WAAWA,KAAK,aAC9B,MAAMD,MAAM,QAAQ,CAACI,QAAQd,QAAW;gBACtC,SAASW,IAAI,OAAO;gBACpB,aAAaA,IAAI,WAAW;YAC9B;iBAEA,MAAMD,MAAM,QAAQ,CAACI;QAEzB,EAAE,OAAON,OAAO;YACd,MAAM,IAAIxB,MACR,CAAC,gCAAgC,EAAEoB,sBACjCtB,MACAuB,QACA,SAAS,EAAEvB,KAAK,UAAU,CAAC,EAAE,EAAEA,KAAK,OAAO,CAAC,CAAC,EAAEA,KAAK,IAAI,CAAC,CAAC,EAAEyB,mBAC5DC,QACC,EACH;gBACE,OAAOA;YACT;QAEJ;IACF;AACF"}
1
+ {"version":3,"file":"agent/run-gherkin-scenario.js","sources":["webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../../../src/agent/run-gherkin-scenario.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 { AiActOptions } from './agent';\n\nexport type GherkinStepKeyword = 'Given' | 'When' | 'Then' | 'And' | 'But';\n\ntype RunGherkinScenarioStepAction = 'aiAct' | 'aiAssert';\n\nexport type RunGherkinScenarioOptions = AiActOptions & {\n /** Additional AI guidance applied to every step in this scenario run. */\n context?: string;\n};\n\ntype GherkinPrimaryKeyword = 'Given' | 'When' | 'Then';\n\ntype ParsedGherkinStep = {\n keyword: GherkinStepKeyword;\n effectiveKeyword: GherkinPrimaryKeyword;\n text: string;\n lineNumber: number;\n};\n\ntype RawGherkinStep = {\n keyword: GherkinStepKeyword;\n text: string;\n lineNumber: number;\n};\n\ntype ParsedGherkinScenario = {\n scenario?: string;\n steps: ParsedGherkinStep[];\n};\n\ntype GherkinScenarioAgent = {\n aiAct: (taskPrompt: string, opt?: AiActOptions) => Promise<unknown>;\n aiAssert: (\n assertion: string,\n msg?: string,\n opt?: { context?: string; abortSignal?: AbortSignal },\n ) => Promise<unknown>;\n};\n\nconst stepKeywordPattern = /^(Given|When|Then|And|But)\\s+(.+)$/i;\nconst headerPattern = /^(Scenario):\\s*(.*)$/i;\nconst unsupportedHeaderPattern =\n /^(Feature|Background|Scenario Outline|Scenario Template|Examples|Rule):/i;\n\nconst normalizeStepKeyword = (keyword: string): GherkinStepKeyword => {\n const lowerKeyword = keyword.toLowerCase();\n if (lowerKeyword === 'given') return 'Given';\n if (lowerKeyword === 'when') return 'When';\n if (lowerKeyword === 'then') return 'Then';\n if (lowerKeyword === 'and') return 'And';\n return 'But';\n};\n\nconst isPrimaryKeyword = (\n keyword: GherkinStepKeyword,\n): keyword is GherkinPrimaryKeyword => {\n return keyword === 'Given' || keyword === 'When' || keyword === 'Then';\n};\n\nconst resolveSteps = (steps: RawGherkinStep[]): ParsedGherkinStep[] => {\n let previousPrimaryKeyword: GherkinPrimaryKeyword | undefined;\n\n return steps.map((step) => {\n const effectiveKeyword = isPrimaryKeyword(step.keyword)\n ? step.keyword\n : previousPrimaryKeyword;\n\n if (!effectiveKeyword) {\n throw new Error(\n `runGherkinScenario cannot resolve \"${step.keyword}\" at line ${step.lineNumber}; use Given, When, or Then before ${step.keyword}.`,\n );\n }\n\n previousPrimaryKeyword = effectiveKeyword;\n\n return {\n ...step,\n effectiveKeyword,\n };\n });\n};\n\nconst throwIfAborted = (abortSignal: AbortSignal | undefined) => {\n if (!abortSignal?.aborted) {\n return;\n }\n\n if (typeof abortSignal.throwIfAborted === 'function') {\n abortSignal.throwIfAborted();\n }\n\n throw new Error(\n `runGherkinScenario aborted: ${abortSignal.reason || 'signal already aborted'}`,\n );\n};\n\nexport const parseGherkinScenario = (\n scenarioText: string,\n): ParsedGherkinScenario => {\n const lines = scenarioText.split(/\\r?\\n/);\n const scenarioSteps: RawGherkinStep[] = [];\n const anonymousSteps: RawGherkinStep[] = [];\n let scenario: string | undefined;\n let scenarioCount = 0;\n let section: 'prelude' | 'scenario' = 'prelude';\n\n for (const [lineIndex, rawLine] of lines.entries()) {\n const lineNumber = lineIndex + 1;\n const line = rawLine.trim();\n\n if (!line || line.startsWith('#') || line.startsWith('@')) {\n continue;\n }\n\n if (line === '\"\"\"' || line === \"'''\") {\n throw new Error(\n `runGherkinScenario does not support doc strings; found one at line ${lineNumber}.`,\n );\n }\n\n if (line.startsWith('|')) {\n throw new Error(\n `runGherkinScenario does not support data tables; found one at line ${lineNumber}.`,\n );\n }\n\n if (unsupportedHeaderPattern.test(line)) {\n throw new Error(\n `runGherkinScenario does not support \"${line}\" at line ${lineNumber}.`,\n );\n }\n\n const headerMatch = line.match(headerPattern);\n if (headerMatch) {\n scenarioCount += 1;\n scenario = headerMatch[2].trim() || undefined;\n section = 'scenario';\n continue;\n }\n\n const stepMatch = line.match(stepKeywordPattern);\n if (stepMatch) {\n const step = {\n keyword: normalizeStepKeyword(stepMatch[1]),\n text: stepMatch[2].trim(),\n lineNumber,\n };\n\n if (section === 'scenario') {\n scenarioSteps.push(step);\n } else {\n anonymousSteps.push(step);\n }\n\n continue;\n }\n\n throw new Error(\n `runGherkinScenario does not support content at line ${lineNumber}: ${line}`,\n );\n }\n\n if (scenarioCount > 1) {\n throw new Error(\n `runGherkinScenario expects exactly one Scenario, but found ${scenarioCount}.`,\n );\n }\n\n if (scenarioCount === 1 && anonymousSteps.length > 0) {\n throw new Error(\n 'runGherkinScenario cannot mix anonymous steps with a Scenario block.',\n );\n }\n\n const rawSteps = scenarioCount === 1 ? scenarioSteps : anonymousSteps;\n\n if (rawSteps.length === 0) {\n throw new Error('runGherkinScenario requires at least one Gherkin step.');\n }\n\n return {\n scenario,\n steps: resolveSteps(rawSteps),\n };\n};\n\nconst buildStepPrompt = (step: ParsedGherkinStep) => {\n if (step.effectiveKeyword === 'Given') {\n return `Set up this precondition: ${step.text}`;\n }\n\n if (step.effectiveKeyword === 'When') {\n return `Perform this user action: ${step.text}`;\n }\n\n return `Verify that ${step.text}`;\n};\n\nconst describeStepExecution = (\n step: ParsedGherkinStep,\n action: RunGherkinScenarioStepAction,\n) => {\n const keywordMapping =\n step.keyword === step.effectiveKeyword\n ? step.keyword\n : `${step.keyword} as ${step.effectiveKeyword}`;\n\n if (step.effectiveKeyword === 'Given') {\n return `setting up the precondition (${keywordMapping} -> ${action})`;\n }\n\n if (step.effectiveKeyword === 'When') {\n return `performing the user action (${keywordMapping} -> ${action})`;\n }\n\n return `verifying the expected result (${keywordMapping} -> ${action})`;\n};\n\nconst describeErrorCause = (error: unknown) => {\n if (error instanceof Error && error.message) {\n return ` Original error: ${error.message}`;\n }\n\n return '';\n};\n\nexport const runGherkinScenario = async (\n agent: GherkinScenarioAgent,\n scenarioText: string,\n opt?: RunGherkinScenarioOptions,\n): Promise<void> => {\n const parsedScenario = parseGherkinScenario(scenarioText);\n const aiActOptions: AiActOptions = {\n ...opt,\n cacheable: false,\n };\n\n for (const step of parsedScenario.steps) {\n throwIfAborted(opt?.abortSignal);\n\n const action: RunGherkinScenarioStepAction =\n step.effectiveKeyword === 'Then' ? 'aiAssert' : 'aiAct';\n const prompt = buildStepPrompt(step);\n\n try {\n if (action === 'aiAct') {\n await agent.aiAct(prompt, aiActOptions);\n } else if (opt?.context !== undefined || opt?.abortSignal) {\n await agent.aiAssert(prompt, undefined, {\n context: opt.context,\n abortSignal: opt.abortSignal,\n });\n } else {\n await agent.aiAssert(prompt);\n }\n } catch (error) {\n throw new Error(\n `runGherkinScenario failed while ${describeStepExecution(\n step,\n action,\n )} at line ${step.lineNumber}: ${step.keyword} ${step.text}.${describeErrorCause(\n error,\n )}`,\n {\n cause: error,\n },\n );\n }\n }\n};\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","stepKeywordPattern","headerPattern","unsupportedHeaderPattern","normalizeStepKeyword","keyword","lowerKeyword","isPrimaryKeyword","resolveSteps","steps","previousPrimaryKeyword","step","effectiveKeyword","Error","throwIfAborted","abortSignal","parseGherkinScenario","scenarioText","lines","scenarioSteps","anonymousSteps","scenario","scenarioCount","section","lineIndex","rawLine","lineNumber","line","headerMatch","undefined","stepMatch","rawSteps","buildStepPrompt","describeStepExecution","action","keywordMapping","describeErrorCause","error","runGherkinScenario","agent","opt","parsedScenario","aiActOptions","prompt"],"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;;;;;;;;ACkCA,MAAMI,qBAAqB;AAC3B,MAAMC,gBAAgB;AACtB,MAAMC,2BACJ;AAEF,MAAMC,uBAAuB,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MAAMK,MAAM,KAAK,CAACI,QAAQD;iBACrB,IAAIF,KAAK,YAAYX,UAAaW,KAAK,aAC5C,MAAMD,MAAM,QAAQ,CAACI,QAAQd,QAAW;gBACtC,SAASW,IAAI,OAAO;gBACpB,aAAaA,IAAI,WAAW;YAC9B;iBAEA,MAAMD,MAAM,QAAQ,CAACI;QAEzB,EAAE,OAAON,OAAO;YACd,MAAM,IAAIxB,MACR,CAAC,gCAAgC,EAAEoB,sBACjCtB,MACAuB,QACA,SAAS,EAAEvB,KAAK,UAAU,CAAC,EAAE,EAAEA,KAAK,OAAO,CAAC,CAAC,EAAEA,KAAK,IAAI,CAAC,CAAC,EAAEyB,mBAC5DC,QACC,EACH;gBACE,OAAOA;YACT;QAEJ;IACF;AACF"}
@@ -42,6 +42,7 @@ const utils_namespaceObject = require("@midscene/shared/utils");
42
42
  const external_execution_session_js_namespaceObject = require("./execution-session.js");
43
43
  const external_file_chooser_js_namespaceObject = require("./file-chooser.js");
44
44
  const external_progress_index_js_namespaceObject = require("./progress/index.js");
45
+ const external_prompt_context_js_namespaceObject = require("./prompt-context.js");
45
46
  const external_task_builder_js_namespaceObject = require("./task-builder.js");
46
47
  const external_task_timing_js_namespaceObject = require("../task-timing.js");
47
48
  const extractor_namespaceObject = require("@midscene/shared/extractor");
@@ -292,7 +293,7 @@ class TaskExecutor {
292
293
  (0, external_task_timing_js_namespaceObject.setTimingFieldOnce)(timing, 'callAiStart');
293
294
  planResult = await planImpl(preparedUserPrompt, {
294
295
  context: planningUiContext,
295
- actionContext: aiActContext,
296
+ actionContext: (0, external_prompt_context_js_namespaceObject.renderAIContext)(aiActContext),
296
297
  actionSpace,
297
298
  modelRuntime: planningModel,
298
299
  conversationHistory,