@midscene/core 1.12.3 → 1.12.4-beta-20260902093735.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/agent/agent.mjs +88 -25
- package/dist/es/agent/agent.mjs.map +1 -1
- package/dist/es/agent/index.mjs +2 -1
- package/dist/es/agent/insight.mjs +40 -10
- package/dist/es/agent/insight.mjs.map +1 -1
- package/dist/es/agent/prompt-context.mjs +42 -6
- package/dist/es/agent/prompt-context.mjs.map +1 -1
- package/dist/es/agent/run-gherkin-scenario.mjs.map +1 -1
- package/dist/es/agent/utils.mjs +1 -1
- package/dist/es/ai-model/prompt/insight/user-prompt.mjs +1 -1
- package/dist/es/ai-model/prompt/insight/user-prompt.mjs.map +1 -1
- package/dist/es/ai-model/workflows/insight/extraction.mjs +4 -1
- package/dist/es/ai-model/workflows/insight/extraction.mjs.map +1 -1
- package/dist/es/ai-model/workflows/planning/custom-planning.mjs +3 -3
- package/dist/es/ai-model/workflows/planning/custom-planning.mjs.map +1 -1
- package/dist/es/ai-model/workflows/planning/standard-planning.mjs +1 -1
- package/dist/es/ai-model/workflows/planning/standard-planning.mjs.map +1 -1
- package/dist/es/index.mjs +2 -2
- package/dist/es/index.mjs.map +1 -1
- package/dist/es/report-html-template.mjs +1 -1
- package/dist/es/types.mjs.map +1 -1
- package/dist/es/utils.mjs +1 -1
- package/dist/es/yaml/player.mjs +0 -5
- package/dist/es/yaml/player.mjs.map +1 -1
- package/dist/es/yaml/utils.mjs +4 -3
- package/dist/es/yaml/utils.mjs.map +1 -1
- package/dist/lib/agent/agent.js +87 -24
- package/dist/lib/agent/agent.js.map +1 -1
- package/dist/lib/agent/index.js +5 -1
- package/dist/lib/agent/insight.js +40 -10
- package/dist/lib/agent/insight.js.map +1 -1
- package/dist/lib/agent/prompt-context.js +55 -7
- package/dist/lib/agent/prompt-context.js.map +1 -1
- package/dist/lib/agent/run-gherkin-scenario.js.map +1 -1
- package/dist/lib/agent/utils.js +1 -1
- package/dist/lib/ai-model/prompt/insight/user-prompt.js +1 -1
- package/dist/lib/ai-model/prompt/insight/user-prompt.js.map +1 -1
- package/dist/lib/ai-model/workflows/insight/extraction.js +4 -1
- package/dist/lib/ai-model/workflows/insight/extraction.js.map +1 -1
- package/dist/lib/ai-model/workflows/planning/custom-planning.js +3 -3
- package/dist/lib/ai-model/workflows/planning/custom-planning.js.map +1 -1
- package/dist/lib/ai-model/workflows/planning/standard-planning.js +1 -1
- package/dist/lib/ai-model/workflows/planning/standard-planning.js.map +1 -1
- package/dist/lib/index.js +4 -1
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/report-html-template.js +1 -1
- package/dist/lib/types.js.map +1 -1
- package/dist/lib/utils.js +1 -1
- package/dist/lib/yaml/player.js +0 -5
- package/dist/lib/yaml/player.js.map +1 -1
- package/dist/lib/yaml/utils.js +3 -2
- package/dist/lib/yaml/utils.js.map +1 -1
- package/dist/types/agent/agent.d.ts +22 -3
- package/dist/types/agent/index.d.ts +2 -1
- package/dist/types/agent/insight.d.ts +6 -1
- package/dist/types/agent/prompt-context.d.ts +27 -1
- package/dist/types/agent/run-gherkin-scenario.d.ts +1 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/types.d.ts +26 -0
- package/dist/types/yaml.d.ts +12 -4
- package/package.json +2 -2
|
@@ -1,25 +1,61 @@
|
|
|
1
|
+
const INTERNAL_AI_CONTEXT_METADATA_KEY = '_internalAIContextMetadata';
|
|
2
|
+
const resolvedAIContextFromOptions = (options)=>{
|
|
3
|
+
if (options?.context === void 0) return;
|
|
4
|
+
return {
|
|
5
|
+
value: options.context,
|
|
6
|
+
metadata: options[INTERNAL_AI_CONTEXT_METADATA_KEY] ?? {
|
|
7
|
+
source: 'call'
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
const renderAIContext = (resolvedContext, workflowHistory)=>{
|
|
12
|
+
const blocks = [];
|
|
13
|
+
const context = resolvedContext?.value.trim();
|
|
14
|
+
if (context && resolvedContext) {
|
|
15
|
+
const metadata = resolvedContext.metadata;
|
|
16
|
+
if ('default' === metadata.source) blocks.push(`<GLOBAL_CONTEXT>\n${context}\n</GLOBAL_CONTEXT>`);
|
|
17
|
+
else {
|
|
18
|
+
const apiAttribute = 'api' === metadata.source ? ` api="${metadata.apiName}"` : '';
|
|
19
|
+
blocks.push(`<REQUEST_CONTEXT source="${metadata.source}"${apiAttribute}>\n${context}\n</REQUEST_CONTEXT>`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const history = workflowHistory?.trim();
|
|
23
|
+
if (history) blocks.push(`<WORKFLOW_HISTORY read_only="true">\n${history}\n</WORKFLOW_HISTORY>`);
|
|
24
|
+
if (blocks.length > 0) return blocks.join('\n\n');
|
|
25
|
+
return void 0 !== resolvedContext || void 0 !== workflowHistory ? '' : void 0;
|
|
26
|
+
};
|
|
27
|
+
const mergeAIContexts = (...contexts)=>{
|
|
28
|
+
const definedContexts = contexts.filter((context)=>void 0 !== context);
|
|
29
|
+
if (0 === definedContexts.length) return;
|
|
30
|
+
return definedContexts.filter(Boolean).join('\n\n');
|
|
31
|
+
};
|
|
1
32
|
const buildPromptWithContext = (prompt, context)=>{
|
|
2
33
|
const trimmedContext = context?.trim();
|
|
3
34
|
if (!trimmedContext) return prompt;
|
|
4
35
|
const promptText = 'string' == typeof prompt ? prompt : prompt.prompt;
|
|
5
|
-
const promptWithContext =
|
|
36
|
+
const promptWithContext = `${trimmedContext}\n\n${promptText}`;
|
|
6
37
|
if ('string' == typeof prompt) return promptWithContext;
|
|
7
38
|
return {
|
|
8
39
|
...prompt,
|
|
9
40
|
prompt: promptWithContext
|
|
10
41
|
};
|
|
11
42
|
};
|
|
12
|
-
const buildLocatePromptWithContext = (prompt, context)=>{
|
|
13
|
-
const
|
|
14
|
-
|
|
43
|
+
const buildLocatePromptWithContext = (prompt, context, metadata)=>{
|
|
44
|
+
const renderedContext = renderAIContext(void 0 === context ? void 0 : {
|
|
45
|
+
value: context,
|
|
46
|
+
metadata: metadata ?? {
|
|
47
|
+
source: 'call'
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
if (!renderedContext) return prompt;
|
|
15
51
|
const promptText = 'string' == typeof prompt ? prompt : prompt.prompt;
|
|
16
|
-
const promptWithContext =
|
|
52
|
+
const promptWithContext = `${renderedContext}\n\n<LOCATE_TARGET>\n${promptText}\n</LOCATE_TARGET>`;
|
|
17
53
|
if ('string' == typeof prompt) return promptWithContext;
|
|
18
54
|
return {
|
|
19
55
|
...prompt,
|
|
20
56
|
prompt: promptWithContext
|
|
21
57
|
};
|
|
22
58
|
};
|
|
23
|
-
export { buildLocatePromptWithContext, buildPromptWithContext };
|
|
59
|
+
export { INTERNAL_AI_CONTEXT_METADATA_KEY, buildLocatePromptWithContext, buildPromptWithContext, mergeAIContexts, renderAIContext, resolvedAIContextFromOptions };
|
|
24
60
|
|
|
25
61
|
//# sourceMappingURL=prompt-context.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent/prompt-context.mjs","sources":["../../../src/agent/prompt-context.ts"],"sourcesContent":["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 =
|
|
1
|
+
{"version":3,"file":"agent/prompt-context.mjs","sources":["../../../src/agent/prompt-context.ts"],"sourcesContent":["import type { TUserPrompt } from '@/ai-model';\nimport type { AiApiName } from '@midscene/shared/agent-tools/agent-context';\n\nexport type AIContextMetadata =\n | { source: 'default' }\n | { source: 'api'; apiName: AiApiName }\n | { source: 'call' };\n\nexport interface ResolvedAIContext {\n value: string;\n metadata: AIContextMetadata;\n}\n\nexport const INTERNAL_AI_CONTEXT_METADATA_KEY =\n '_internalAIContextMetadata' as const;\n\nexport interface InternalAIContextOptions {\n [INTERNAL_AI_CONTEXT_METADATA_KEY]?: AIContextMetadata;\n /** Framework-owned workflow history appended after the selected context. */\n _internalAdditionalContext?: string;\n}\n\nexport const resolvedAIContextFromOptions = (\n options:\n | ({ context?: string } & Partial<InternalAIContextOptions>)\n | undefined,\n): ResolvedAIContext | undefined => {\n if (options?.context === undefined) {\n return undefined;\n }\n\n return {\n value: options.context,\n metadata: options[INTERNAL_AI_CONTEXT_METADATA_KEY] ?? { source: 'call' },\n };\n};\n\n/** Render the selected user context and framework history as separate blocks. */\nexport const renderAIContext = (\n resolvedContext: ResolvedAIContext | undefined,\n workflowHistory?: string,\n): string | undefined => {\n const blocks: string[] = [];\n const context = resolvedContext?.value.trim();\n\n if (context && resolvedContext) {\n const metadata = resolvedContext.metadata;\n if (metadata.source === 'default') {\n blocks.push(`<GLOBAL_CONTEXT>\\n${context}\\n</GLOBAL_CONTEXT>`);\n } else {\n const apiAttribute =\n metadata.source === 'api' ? ` api=\"${metadata.apiName}\"` : '';\n blocks.push(\n `<REQUEST_CONTEXT source=\"${metadata.source}\"${apiAttribute}>\\n${context}\\n</REQUEST_CONTEXT>`,\n );\n }\n }\n\n const history = workflowHistory?.trim();\n if (history) {\n blocks.push(\n `<WORKFLOW_HISTORY read_only=\"true\">\\n${history}\\n</WORKFLOW_HISTORY>`,\n );\n }\n\n if (blocks.length > 0) {\n return blocks.join('\\n\\n');\n }\n\n return resolvedContext !== undefined || workflowHistory !== undefined\n ? ''\n : undefined;\n};\n\n/** Explicitly concatenate context fragments in the order provided. */\nexport const mergeAIContexts = (\n ...contexts: Array<string | undefined>\n): string | undefined => {\n const definedContexts = contexts.filter(\n (context): context is string => context !== undefined,\n );\n if (definedContexts.length === 0) {\n return undefined;\n }\n\n return definedContexts.filter(Boolean).join('\\n\\n');\n};\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 = `${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 metadata?: AIContextMetadata,\n): TUserPrompt => {\n const renderedContext = renderAIContext(\n context === undefined\n ? undefined\n : { value: context, metadata: metadata ?? { source: 'call' } },\n );\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":["INTERNAL_AI_CONTEXT_METADATA_KEY","resolvedAIContextFromOptions","options","undefined","renderAIContext","resolvedContext","workflowHistory","blocks","context","metadata","apiAttribute","history","mergeAIContexts","contexts","definedContexts","Boolean","buildPromptWithContext","prompt","trimmedContext","promptText","promptWithContext","buildLocatePromptWithContext","renderedContext"],"mappings":"AAaO,MAAMA,mCACX;AAQK,MAAMC,+BAA+B,CAC1CC;IAIA,IAAIA,SAAS,YAAYC,QACvB;IAGF,OAAO;QACL,OAAOD,QAAQ,OAAO;QACtB,UAAUA,OAAO,CAACF,iCAAiC,IAAI;YAAE,QAAQ;QAAO;IAC1E;AACF;AAGO,MAAMI,kBAAkB,CAC7BC,iBACAC;IAEA,MAAMC,SAAmB,EAAE;IAC3B,MAAMC,UAAUH,iBAAiB,MAAM;IAEvC,IAAIG,WAAWH,iBAAiB;QAC9B,MAAMI,WAAWJ,gBAAgB,QAAQ;QACzC,IAAII,AAAoB,cAApBA,SAAS,MAAM,EACjBF,OAAO,IAAI,CAAC,CAAC,kBAAkB,EAAEC,QAAQ,mBAAmB,CAAC;aACxD;YACL,MAAME,eACJD,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,SAASA,OAAO,MAAM;IACtE,MAAMG,oBAAoB,GAAGE,gBAAgB,qBAAqB,EAAEH,WAAW,kBAAkB,CAAC;IAElG,IAAI,AAAkB,YAAlB,OAAOF,QACT,OAAOG;IAGT,OAAO;QACL,GAAGH,MAAM;QACT,QAAQG;IACV;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent/run-gherkin-scenario.mjs","sources":["../../../src/agent/run-gherkin-scenario.ts"],"sourcesContent":["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":["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":"AAuCA,MAAMA,qBAAqB;AAC3B,MAAMC,gBAAgB;AACtB,MAAMC,2BACJ;AAEF,MAAMC,uBAAuB,CAACC;IAC5B,MAAMC,eAAeD,QAAQ,WAAW;IACxC,IAAIC,AAAiB,YAAjBA,cAA0B,OAAO;IACrC,IAAIA,AAAiB,WAAjBA,cAAyB,OAAO;IACpC,IAAIA,AAAiB,WAAjBA,cAAyB,OAAO;IACpC,IAAIA,AAAiB,UAAjBA,cAAwB,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I;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.mjs","sources":["../../../src/agent/run-gherkin-scenario.ts"],"sourcesContent":["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 || 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":["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":"AAwCA,MAAMA,qBAAqB;AAC3B,MAAMC,gBAAgB;AACtB,MAAMC,2BACJ;AAEF,MAAMC,uBAAuB,CAACC;IAC5B,MAAMC,eAAeD,QAAQ,WAAW;IACxC,IAAIC,AAAiB,YAAjBA,cAA0B,OAAO;IACrC,IAAIA,AAAiB,WAAjBA,cAAyB,OAAO;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,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"}
|
package/dist/es/agent/utils.mjs
CHANGED
|
@@ -154,7 +154,7 @@ async function matchElementFromCache(context, cacheEntry, cachePrompt, cacheable
|
|
|
154
154
|
return;
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
|
-
const getMidsceneVersion = ()=>"1.12.
|
|
157
|
+
const getMidsceneVersion = ()=>"1.12.4-beta-20260902093735.0";
|
|
158
158
|
const parsePrompt = (prompt)=>{
|
|
159
159
|
if ('string' == typeof prompt) return {
|
|
160
160
|
textPrompt: prompt,
|
|
@@ -7,7 +7,7 @@ function buildTypeQueryDemandValue(type, demand) {
|
|
|
7
7
|
const extractDataQueryPrompt = (pageDescription, dataQuery, context)=>{
|
|
8
8
|
const dataQueryText = 'string' == typeof dataQuery ? dataQuery : JSON.stringify(dataQuery, null, 2);
|
|
9
9
|
const trimmedContext = context?.trim();
|
|
10
|
-
const contextSection = trimmedContext ? `\n
|
|
10
|
+
const contextSection = trimmedContext ? `\n${trimmedContext}\n` : '';
|
|
11
11
|
return `
|
|
12
12
|
<PageDescription>
|
|
13
13
|
${pageDescription}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-model/prompt/insight/user-prompt.mjs","sources":["../../../../../src/ai-model/prompt/insight/user-prompt.ts"],"sourcesContent":["import type { ServiceExtractParam } from '@/types';\n\nexport function buildTypeQueryDemandValue(\n type: 'Boolean' | 'Number' | 'String' | 'Assert' | 'WaitFor',\n demand: ServiceExtractParam,\n) {\n const currentScreenshotConstraint =\n 'based on the current screenshot and its contents if provided, unless the user explicitly asks to compare with reference images';\n\n if (type === 'Assert') {\n return `Boolean, ${currentScreenshotConstraint}, whether the following statement is true: ${demand}`;\n }\n\n if (type === 'WaitFor') {\n return `Boolean, the user wants to do some 'wait for' operation. ${currentScreenshotConstraint}, please check whether the following statement is true: ${demand}`;\n }\n\n return `${type}, ${currentScreenshotConstraint}, ${demand}`;\n}\n\nexport const extractDataQueryPrompt = (\n pageDescription: string,\n dataQuery: string | Record<string, string>,\n context?: string,\n) => {\n const dataQueryText =\n typeof dataQuery === 'string'\n ? dataQuery\n : JSON.stringify(dataQuery, null, 2);\n\n const trimmedContext = context?.trim();\n const contextSection = trimmedContext
|
|
1
|
+
{"version":3,"file":"ai-model/prompt/insight/user-prompt.mjs","sources":["../../../../../src/ai-model/prompt/insight/user-prompt.ts"],"sourcesContent":["import type { ServiceExtractParam } from '@/types';\n\nexport function buildTypeQueryDemandValue(\n type: 'Boolean' | 'Number' | 'String' | 'Assert' | 'WaitFor',\n demand: ServiceExtractParam,\n) {\n const currentScreenshotConstraint =\n 'based on the current screenshot and its contents if provided, unless the user explicitly asks to compare with reference images';\n\n if (type === 'Assert') {\n return `Boolean, ${currentScreenshotConstraint}, whether the following statement is true: ${demand}`;\n }\n\n if (type === 'WaitFor') {\n return `Boolean, the user wants to do some 'wait for' operation. ${currentScreenshotConstraint}, please check whether the following statement is true: ${demand}`;\n }\n\n return `${type}, ${currentScreenshotConstraint}, ${demand}`;\n}\n\nexport const extractDataQueryPrompt = (\n pageDescription: string,\n dataQuery: string | Record<string, string>,\n context?: string,\n) => {\n const dataQueryText =\n typeof dataQuery === 'string'\n ? dataQuery\n : JSON.stringify(dataQuery, null, 2);\n\n const trimmedContext = context?.trim();\n const contextSection = trimmedContext ? `\\n${trimmedContext}\\n` : '';\n\n return `\n<PageDescription>\n${pageDescription}\n</PageDescription>\n${contextSection}\n<DATA_DEMAND>\n${dataQueryText}\n</DATA_DEMAND>\n `;\n};\n"],"names":["buildTypeQueryDemandValue","type","demand","currentScreenshotConstraint","extractDataQueryPrompt","pageDescription","dataQuery","context","dataQueryText","JSON","trimmedContext","contextSection"],"mappings":"AAEO,SAASA,0BACdC,IAA4D,EAC5DC,MAA2B;IAE3B,MAAMC,8BACJ;IAEF,IAAIF,AAAS,aAATA,MACF,OAAO,CAAC,SAAS,EAAEE,4BAA4B,2CAA2C,EAAED,QAAQ;IAGtG,IAAID,AAAS,cAATA,MACF,OAAO,CAAC,yDAAyD,EAAEE,4BAA4B,wDAAwD,EAAED,QAAQ;IAGnK,OAAO,GAAGD,KAAK,EAAE,EAAEE,4BAA4B,EAAE,EAAED,QAAQ;AAC7D;AAEO,MAAME,yBAAyB,CACpCC,iBACAC,WACAC;IAEA,MAAMC,gBACJ,AAAqB,YAArB,OAAOF,YACHA,YACAG,KAAK,SAAS,CAACH,WAAW,MAAM;IAEtC,MAAMI,iBAAiBH,SAAS;IAChC,MAAMI,iBAAiBD,iBAAiB,CAAC,EAAE,EAAEA,eAAe,EAAE,CAAC,GAAG;IAElE,OAAO,CAAC;;AAEV,EAAEL,gBAAgB;;AAElB,EAAEM,eAAe;;AAEjB,EAAEH,cAAc;;EAEd,CAAC;AACH"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getDebug } from "@midscene/shared/logger";
|
|
2
|
+
import { renderAIContext, resolvedAIContextFromOptions } from "../../../agent/prompt-context.mjs";
|
|
2
3
|
import { buildInsightSystemPrompt, extractDataQueryPrompt } from "../../prompt/insight/index.mjs";
|
|
3
4
|
import { AIResponseParseError, callAI } from "../../service-caller/index.mjs";
|
|
4
5
|
import { callAiAndParseWithRetry, withSemanticRetryFeedback } from "../../service-caller/semantic-retry.mjs";
|
|
@@ -14,7 +15,9 @@ async function AiExtractElementInfo(options) {
|
|
|
14
15
|
insightProtocol
|
|
15
16
|
});
|
|
16
17
|
const screenshotBase64 = context.screenshot.base64;
|
|
17
|
-
const
|
|
18
|
+
const internalContextOptions = extractOption;
|
|
19
|
+
const renderedContext = renderAIContext(resolvedAIContextFromOptions(internalContextOptions), internalContextOptions?._internalAdditionalContext);
|
|
20
|
+
const extractDataPromptText = extractDataQueryPrompt(options.pageDescription || '', dataQuery, renderedContext);
|
|
18
21
|
const userContent = [];
|
|
19
22
|
if (extractOption?.screenshotIncluded !== false) {
|
|
20
23
|
const screenshotSequence = context.screenshotSequence;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-model/workflows/insight/extraction.mjs","sources":["../../../../../src/ai-model/workflows/insight/extraction.ts"],"sourcesContent":["import type { ServiceExtractOption, UIContext } from '@/types';\nimport { getDebug } from '@midscene/shared/logger';\nimport type {\n ChatCompletionSystemMessageParam,\n ChatCompletionUserMessageParam,\n} from 'openai/resources/index';\nimport type { TMultimodalPrompt } from '../../../common';\nimport type { ModelRuntime } from '../../models';\nimport {\n buildInsightSystemPrompt,\n extractDataQueryPrompt,\n} from '../../prompt/insight';\nimport { AIResponseParseError, callAI } from '../../service-caller/index';\nimport {\n callAiAndParseWithRetry,\n withSemanticRetryFeedback,\n} from '../../service-caller/semantic-retry';\nimport { multimodalPromptToChatMessages } from '../../shared/multimodal-prompt';\nimport { parseInsightResponse } from './insight-response-parser';\n\ntype InsightAIArgs = [\n ChatCompletionSystemMessageParam,\n ...ChatCompletionUserMessageParam[],\n];\n\nconst debugInsight = getDebug('ai:insight');\n\nexport async function AiExtractElementInfo<T>(options: {\n dataQuery: string | Record<string, string>;\n multimodalPrompt?: TMultimodalPrompt;\n context: UIContext;\n pageDescription?: string;\n extractOption?: ServiceExtractOption;\n modelRuntime: ModelRuntime;\n abortSignal?: AbortSignal;\n}) {\n const { dataQuery, context, extractOption, multimodalPrompt, modelRuntime } =\n options;\n const insightProtocol = modelRuntime.adapter.insight.protocol;\n const systemPrompt = buildInsightSystemPrompt({\n screenshotIncluded: extractOption?.screenshotIncluded !== false,\n referenceImagesIncluded: !!multimodalPrompt?.images?.length,\n insightProtocol,\n });\n const screenshotBase64 = context.screenshot.base64;\n const extractDataPromptText = extractDataQueryPrompt(\n options.pageDescription || '',\n dataQuery,\n
|
|
1
|
+
{"version":3,"file":"ai-model/workflows/insight/extraction.mjs","sources":["../../../../../src/ai-model/workflows/insight/extraction.ts"],"sourcesContent":["import type { ServiceExtractOption, UIContext } from '@/types';\nimport { getDebug } from '@midscene/shared/logger';\nimport type {\n ChatCompletionSystemMessageParam,\n ChatCompletionUserMessageParam,\n} from 'openai/resources/index';\nimport {\n type InternalAIContextOptions,\n renderAIContext,\n resolvedAIContextFromOptions,\n} from '../../../agent/prompt-context';\nimport type { TMultimodalPrompt } from '../../../common';\nimport type { ModelRuntime } from '../../models';\nimport {\n buildInsightSystemPrompt,\n extractDataQueryPrompt,\n} from '../../prompt/insight';\nimport { AIResponseParseError, callAI } from '../../service-caller/index';\nimport {\n callAiAndParseWithRetry,\n withSemanticRetryFeedback,\n} from '../../service-caller/semantic-retry';\nimport { multimodalPromptToChatMessages } from '../../shared/multimodal-prompt';\nimport { parseInsightResponse } from './insight-response-parser';\n\ntype InsightAIArgs = [\n ChatCompletionSystemMessageParam,\n ...ChatCompletionUserMessageParam[],\n];\n\nconst debugInsight = getDebug('ai:insight');\n\nexport async function AiExtractElementInfo<T>(options: {\n dataQuery: string | Record<string, string>;\n multimodalPrompt?: TMultimodalPrompt;\n context: UIContext;\n pageDescription?: string;\n extractOption?: ServiceExtractOption;\n modelRuntime: ModelRuntime;\n abortSignal?: AbortSignal;\n}) {\n const { dataQuery, context, extractOption, multimodalPrompt, modelRuntime } =\n options;\n const insightProtocol = modelRuntime.adapter.insight.protocol;\n const systemPrompt = buildInsightSystemPrompt({\n screenshotIncluded: extractOption?.screenshotIncluded !== false,\n referenceImagesIncluded: !!multimodalPrompt?.images?.length,\n insightProtocol,\n });\n const screenshotBase64 = context.screenshot.base64;\n\n const internalContextOptions = extractOption as\n | (ServiceExtractOption & InternalAIContextOptions)\n | undefined;\n const renderedContext = renderAIContext(\n resolvedAIContextFromOptions(internalContextOptions),\n internalContextOptions?._internalAdditionalContext,\n );\n const extractDataPromptText = extractDataQueryPrompt(\n options.pageDescription || '',\n dataQuery,\n renderedContext,\n );\n\n const userContent: ChatCompletionUserMessageParam['content'] = [];\n\n if (extractOption?.screenshotIncluded !== false) {\n const screenshotSequence = context.screenshotSequence;\n if (screenshotSequence && screenshotSequence.length > 1) {\n userContent.push({\n type: 'text',\n text: `The following ${screenshotSequence.length} images are consecutive screenshots captured over a time window, ordered from earliest to latest (Frame 1 is first, Frame ${screenshotSequence.length} is last). They record what appeared on screen during that window. Some UI elements such as toasts, banners, or transitions may appear only in certain frames and be gone by later ones. Interpret the temporal scope from the statement or question itself: if it asks whether something appeared at any point, inspect the whole sequence; if it asks about the final or current state, use the relevant later frame; if it asks about a change or sequence, compare frames in order. Unless <DATA_DEMAND> explicitly asks for comparison or matching against reference images, base your answer on these screenshots and their contents.`,\n });\n\n screenshotSequence.forEach((frame, index) => {\n userContent.push({\n type: 'text',\n text: `Frame ${index + 1}/${screenshotSequence.length}`,\n });\n userContent.push({\n type: 'image_url',\n image_url: {\n url: frame.base64,\n detail: 'high',\n },\n });\n });\n } else {\n userContent.push({\n type: 'text',\n text: 'This is the current screenshot to evaluate. Unless <DATA_DEMAND> explicitly asks for comparison or matching against reference images, base your answer on this screenshot and its contents when provided.',\n });\n\n userContent.push({\n type: 'image_url',\n image_url: {\n url: screenshotBase64,\n detail: 'high',\n },\n });\n }\n }\n\n userContent.push({\n type: 'text',\n text: extractDataPromptText,\n });\n\n const msgs: InsightAIArgs = [\n { role: 'system', content: systemPrompt },\n {\n role: 'user',\n content: userContent,\n },\n ];\n\n if (multimodalPrompt) {\n const addOns = await multimodalPromptToChatMessages(multimodalPrompt);\n msgs.push(...addOns);\n }\n\n return callAiAndParseWithRetry({\n callAi: (retryAttempt, previousParseError) =>\n callAI(\n withSemanticRetryFeedback(msgs, previousParseError),\n modelRuntime,\n {\n abortSignal: options.abortSignal,\n semanticRetryAttempt: retryAttempt,\n },\n ),\n parseResponse: (response) => {\n const {\n content: rawResponse,\n usage,\n reasoning_content,\n rawChoiceMessage,\n } = response;\n const parseResult = parseInsightResponse<T>(\n rawResponse,\n insightProtocol.dataOutput,\n modelRuntime.adapter.jsonParser,\n );\n return {\n parseResult,\n rawResponse,\n rawChoiceMessage,\n usage,\n reasoning_content,\n };\n },\n toParseError: (parseError, response) => {\n const errorMessage =\n parseError instanceof Error ? parseError.message : String(parseError);\n return new AIResponseParseError(\n `XML parse error: ${errorMessage}`,\n response.content,\n response.usage,\n response.rawChoiceMessage,\n );\n },\n parseRetryTimes: modelRuntime.config.retryCount,\n parseRetryInterval: modelRuntime.config.retryInterval,\n abortSignal: options.abortSignal,\n onParseRetry: (error) => {\n debugInsight(\n 'retrying insight after XML parsing failed: %s',\n error instanceof Error ? error.message : String(error),\n );\n },\n });\n}\n"],"names":["debugInsight","getDebug","AiExtractElementInfo","options","dataQuery","context","extractOption","multimodalPrompt","modelRuntime","insightProtocol","systemPrompt","buildInsightSystemPrompt","screenshotBase64","internalContextOptions","renderedContext","renderAIContext","resolvedAIContextFromOptions","extractDataPromptText","extractDataQueryPrompt","userContent","screenshotSequence","frame","index","msgs","addOns","multimodalPromptToChatMessages","callAiAndParseWithRetry","retryAttempt","previousParseError","callAI","withSemanticRetryFeedback","response","rawResponse","usage","reasoning_content","rawChoiceMessage","parseResult","parseInsightResponse","parseError","errorMessage","Error","String","AIResponseParseError","error"],"mappings":";;;;;;;AA8BA,MAAMA,eAAeC,SAAS;AAEvB,eAAeC,qBAAwBC,OAQ7C;IACC,MAAM,EAAEC,SAAS,EAAEC,OAAO,EAAEC,aAAa,EAAEC,gBAAgB,EAAEC,YAAY,EAAE,GACzEL;IACF,MAAMM,kBAAkBD,aAAa,OAAO,CAAC,OAAO,CAAC,QAAQ;IAC7D,MAAME,eAAeC,yBAAyB;QAC5C,oBAAoBL,eAAe,uBAAuB;QAC1D,yBAAyB,CAAC,CAACC,kBAAk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ACC,cAAcC,qBACrBC,OACEC,0BAA0BP,MAAMK,qBAChCpB,cACA;gBACE,aAAaL,QAAQ,WAAW;gBAChC,sBAAsBwB;YACxB;QAEJ,eAAe,CAACI;YACd,MAAM,EACJ,SAASC,WAAW,EACpBC,KAAK,EACLC,iBAAiB,EACjBC,gBAAgB,EACjB,GAAGJ;YACJ,MAAMK,cAAcC,qBAClBL,aACAvB,gBAAgB,UAAU,EAC1BD,aAAa,OAAO,CAAC,UAAU;YAEjC,OAAO;gBACL4B;gBACAJ;gBACAG;gBACAF;gBACAC;YACF;QACF;QACA,cAAc,CAACI,YAAYP;YACzB,MAAMQ,eACJD,sBAAsBE,QAAQF,WAAW,OAAO,GAAGG,OAAOH;YAC5D,OAAO,IAAII,qBACT,CAAC,iBAAiB,EAAEH,cAAc,EAClCR,SAAS,OAAO,EAChBA,SAAS,KAAK,EACdA,SAAS,gBAAgB;QAE7B;QACA,iBAAiBvB,aAAa,MAAM,CAAC,UAAU;QAC/C,oBAAoBA,aAAa,MAAM,CAAC,aAAa;QACrD,aAAaL,QAAQ,WAAW;QAChC,cAAc,CAACwC;YACb3C,aACE,iDACA2C,iBAAiBH,QAAQG,MAAM,OAAO,GAAGF,OAAOE;QAEpD;IACF;AACF"}
|
|
@@ -3,13 +3,13 @@ import { prepareModelImage } from "../../model-adapter/image-preprocess.mjs";
|
|
|
3
3
|
import { AIResponseParseError, callAIWithStringResponse } from "../../service-caller/index.mjs";
|
|
4
4
|
import { preparedReferenceImagesToChatMessages } from "../../shared/multimodal-prompt.mjs";
|
|
5
5
|
import { normalizePlanningActionLocateFields } from "./locate-normalization.mjs";
|
|
6
|
-
function
|
|
7
|
-
return systemPrompt + (actionContext ?
|
|
6
|
+
function appendActionContext(systemPrompt, actionContext) {
|
|
7
|
+
return systemPrompt + (actionContext ? `${actionContext}\n` : '');
|
|
8
8
|
}
|
|
9
9
|
function buildCustomPlanningMessages(input, config) {
|
|
10
10
|
const { options } = input;
|
|
11
11
|
const { conversationHistory, context, actionContext } = options;
|
|
12
|
-
const systemPrompt =
|
|
12
|
+
const systemPrompt = appendActionContext(config.buildSystemPrompt(), actionContext);
|
|
13
13
|
const userInstructionText = input.userInstruction.text;
|
|
14
14
|
const userInstruction = config.buildUserInstruction ? config.buildUserInstruction(userInstructionText) : userInstructionText;
|
|
15
15
|
const referenceImageMessages = preparedReferenceImagesToChatMessages(input.userInstruction.referenceImages);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-model/workflows/planning/custom-planning.mjs","sources":["../../../../../src/ai-model/workflows/planning/custom-planning.ts"],"sourcesContent":["import type { PlanningAIResponse, PlanningAction } from '@/types';\nimport type { ChatCompletionMessageParam } from 'openai/resources/index';\nimport { ScreenshotItem } from '../../../screenshot-item';\nimport type {\n CustomPlanningInput,\n CustomPlanningMessageConfig,\n ResolvedCustomPlanningDefinition,\n} from '../../model-adapter/custom-planning-types';\nimport { prepareModelImage } from '../../model-adapter/image-preprocess';\nimport type { ParsedPlanningLocateParameter } from '../../model-adapter/planning-protocol';\nimport {\n AIResponseParseError,\n callAIWithStringResponse,\n} from '../../service-caller/index';\nimport {\n type PreparedUserPrompt,\n preparedReferenceImagesToChatMessages,\n} from '../../shared/multimodal-prompt';\nimport { normalizePlanningActionLocateFields } from './locate-normalization';\nimport type { PlanOptions } from './types';\n\nfunction
|
|
1
|
+
{"version":3,"file":"ai-model/workflows/planning/custom-planning.mjs","sources":["../../../../../src/ai-model/workflows/planning/custom-planning.ts"],"sourcesContent":["import type { PlanningAIResponse, PlanningAction } from '@/types';\nimport type { ChatCompletionMessageParam } from 'openai/resources/index';\nimport { ScreenshotItem } from '../../../screenshot-item';\nimport type {\n CustomPlanningInput,\n CustomPlanningMessageConfig,\n ResolvedCustomPlanningDefinition,\n} from '../../model-adapter/custom-planning-types';\nimport { prepareModelImage } from '../../model-adapter/image-preprocess';\nimport type { ParsedPlanningLocateParameter } from '../../model-adapter/planning-protocol';\nimport {\n AIResponseParseError,\n callAIWithStringResponse,\n} from '../../service-caller/index';\nimport {\n type PreparedUserPrompt,\n preparedReferenceImagesToChatMessages,\n} from '../../shared/multimodal-prompt';\nimport { normalizePlanningActionLocateFields } from './locate-normalization';\nimport type { PlanOptions } from './types';\n\nfunction appendActionContext(\n systemPrompt: string,\n actionContext?: string,\n): string {\n return systemPrompt + (actionContext ? `${actionContext}\\n` : '');\n}\n\nexport function buildCustomPlanningMessages<TParsed>(\n input: CustomPlanningInput,\n config: CustomPlanningMessageConfig<TParsed>,\n): ChatCompletionMessageParam[] {\n const { options } = input;\n const { conversationHistory, context, actionContext } = options;\n const systemPrompt = appendActionContext(\n config.buildSystemPrompt(),\n actionContext,\n );\n const userInstructionText = input.userInstruction.text;\n const userInstruction = config.buildUserInstruction\n ? config.buildUserInstruction(userInstructionText)\n : userInstructionText;\n const referenceImageMessages = preparedReferenceImagesToChatMessages(\n input.userInstruction.referenceImages,\n );\n\n if (conversationHistory.pendingFeedbackMessage) {\n conversationHistory.append({\n role: 'user',\n content: [\n {\n type: 'text',\n text: `${conversationHistory.pendingFeedbackMessage}. The previous action has been executed, here is the latest screenshot. Please continue according to the instruction.`,\n },\n ],\n });\n conversationHistory.resetPendingFeedbackMessageIfExists();\n }\n\n conversationHistory.append({\n role: 'user',\n content: [\n {\n type: 'image_url',\n image_url: { url: context.screenshot.base64 },\n },\n ],\n });\n\n if (config.systemPromptPlacement === 'system-message') {\n return [\n { role: 'system', content: systemPrompt },\n {\n role: 'user',\n content: [{ type: 'text', text: userInstruction }],\n },\n ...referenceImageMessages,\n ...conversationHistory.snapshot(config.historyImageLimit),\n ];\n }\n\n return [\n {\n role: 'user',\n content: `${systemPrompt}${userInstruction}`,\n },\n ...referenceImageMessages,\n ...conversationHistory.snapshot(config.historyImageLimit),\n ];\n}\n\nexport async function runCustomPlanning<TParsed>(\n userInstruction: PreparedUserPrompt,\n options: PlanOptions,\n config: ResolvedCustomPlanningDefinition<TParsed>,\n): Promise<PlanningAIResponse> {\n const { context } = options;\n const preparedImage = await prepareModelImage({\n imageBase64: context.screenshot.base64,\n width: context.shotSize.width,\n height: context.shotSize.height,\n policy: options.modelRuntime.adapter.imagePreprocess,\n });\n const preparedOptions: PlanOptions = {\n ...options,\n context: {\n ...context,\n screenshot: ScreenshotItem.create(\n preparedImage.imageBase64,\n context.screenshot.capturedAt,\n ),\n shotSize: preparedImage.preparedSize,\n },\n };\n const input: CustomPlanningInput = {\n userInstruction,\n options: preparedOptions,\n coordinateSystem: config.coordinateSystem,\n };\n\n const messages = buildCustomPlanningMessages(input, config.messages);\n const { content, usage, rawChoiceMessage } = await callAIWithStringResponse(\n messages,\n preparedOptions.modelRuntime,\n {\n abortSignal: preparedOptions.abortSignal,\n requiresOriginalImageDetail: preparedOptions.includeLocateInPlanning,\n },\n );\n\n let parsed: TParsed;\n let actions: PlanningAction[];\n let shouldContinuePlanning: boolean;\n\n try {\n parsed = config.parseResponse(content, input);\n actions = config.transformActions(parsed, input);\n normalizePlanningActionLocateFields(actions, {\n actionSpace: preparedOptions.actionSpace,\n includeLocateInPlanning: preparedOptions.includeLocateInPlanning,\n locateResultCodec: config.coordinateNormalizer,\n locateResultContext: {\n preparedSize: preparedImage.preparedSize,\n contentSize: preparedImage.contentSize,\n },\n acceptBbox2dAlias: preparedOptions.modelRuntime.adapter.acceptBbox2dAlias,\n parseRawLocateParameter: (value) =>\n value as ParsedPlanningLocateParameter,\n });\n shouldContinuePlanning = config.shouldContinuePlanning(parsed, actions);\n } catch (parseError) {\n const errorMessage = `Parse error: ${\n parseError instanceof Error ? parseError.message : String(parseError)\n }`;\n throw new AIResponseParseError(\n errorMessage,\n JSON.stringify(content, undefined, 2),\n usage,\n rawChoiceMessage,\n );\n }\n\n const assistantContent = config.messages.buildAssistantContent?.(\n parsed,\n content,\n input,\n );\n // UI-TARS and Auto-GLM define their own assistant history format.\n if (assistantContent) {\n options.conversationHistory.append({\n role: 'assistant',\n content: assistantContent,\n });\n }\n\n return {\n actions,\n log: config.buildResponseLog(parsed, content),\n usage,\n shouldContinuePlanning,\n rawResponse: JSON.stringify(content, undefined, 2),\n rawChoiceMessage,\n };\n}\n"],"names":["appendActionContext","systemPrompt","actionContext","buildCustomPlanningMessages","input","config","options","conversationHistory","context","userInstructionText","userInstruction","referenceImageMessages","preparedReferenceImagesToChatMessages","runCustomPlanning","preparedImage","prepareModelImage","preparedOptions","ScreenshotItem","messages","content","usage","rawChoiceMessage","callAIWithStringResponse","parsed","actions","shouldContinuePlanning","normalizePlanningActionLocateFields","value","parseError","errorMessage","Error","String","AIResponseParseError","JSON","undefined","assistantContent"],"mappings":";;;;;AAqBA,SAASA,oBACPC,YAAoB,EACpBC,aAAsB;IAEtB,OAAOD,eAAgBC,CAAAA,gBAAgB,GAAGA,cAAc,EAAE,CAAC,GAAG,EAAC;AACjE;AAEO,SAASC,4BACdC,KAA0B,EAC1BC,MAA4C;IAE5C,MAAM,EAAEC,OAAO,EAAE,GAAGF;IACpB,MAAM,EAAEG,mBAAmB,EAAEC,OAAO,EAAEN,aAAa,EAAE,GAAGI;IACxD,MAAML,eAAeD,oBACnBK,OAAO,iBAAiB,IACxBH;IAEF,MAAMO,sBAAsBL,MAAM,eAAe,CAAC,IAAI;IACtD,MAAMM,kBAAkBL,OAAO,oBAAoB,GAC/CA,OAAO,oBAAoB,CAACI,uBAC5BA;IACJ,MAAME,yBAAyBC,sCAC7BR,MAAM,eAAe,CAAC,eAAe;IAGvC,IAAIG,oBAAoB,sBAAsB,EAAE;QAC9CA,oBAAoB,MAAM,CAAC;YACzB,MAAM;YACN,SAAS;gBACP;oBACE,MAAM;oBACN,MAAM,GAAGA,oBAAoB,sBAAsB,CAAC,qHAAqH,CAAC;gBAC5K;aACD;QACH;QACAA,oBAAoB,mCAAmC;IACzD;IAEAA,oBAAoB,MAAM,CAAC;QACzB,MAAM;QACN,SAAS;YACP;gBACE,MAAM;gBACN,WAAW;oBAAE,KAAKC,QAAQ,UAAU,CAAC,MAAM;gBAAC;YAC9C;SACD;IACH;IAEA,I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,CAACc,SAASf;QACvCoB,UAAUnB,OAAO,gBAAgB,CAACkB,QAAQnB;QAC1CsB,oCAAoCF,SAAS;YAC3C,aAAaR,gBAAgB,WAAW;YACxC,yBAAyBA,gBAAgB,uBAAuB;YAChE,mBAAmBX,OAAO,oBAAoB;YAC9C,qBAAqB;gBACnB,cAAcS,cAAc,YAAY;gBACxC,aAAaA,cAAc,WAAW;YACxC;YACA,mBAAmBE,gBAAgB,YAAY,CAAC,OAAO,CAAC,iBAAiB;YACzE,yBAAyB,CAACW,QACxBA;QACJ;QACAF,yBAAyBpB,OAAO,sBAAsB,CAACkB,QAAQC;IACjE,EAAE,OAAOI,YAAY;QACnB,MAAMC,eAAe,CAAC,aAAa,EACjCD,sBAAsBE,QAAQF,WAAW,OAAO,GAAGG,OAAOH,aAC1D;QACF,MAAM,IAAII,qBACRH,cACAI,KAAK,SAAS,CAACd,SAASe,QAAW,IACnCd,OACAC;IAEJ;IAEA,MAAMc,mBAAmB9B,OAAO,QAAQ,CAAC,qBAAqB,GAC5DkB,QACAJ,SACAf;IAGF,IAAI+B,kBACF7B,QAAQ,mBAAmB,CAAC,MAAM,CAAC;QACjC,MAAM;QACN,SAAS6B;IACX;IAGF,OAAO;QACLX;QACA,KAAKnB,OAAO,gBAAgB,CAACkB,QAAQJ;QACrCC;QACAK;QACA,aAAaQ,KAAK,SAAS,CAACd,SAASe,QAAW;QAChDb;IACF;AACF"}
|
|
@@ -101,7 +101,7 @@ async function standardPlan(userInstruction, opts) {
|
|
|
101
101
|
policy: adapter.imagePreprocess
|
|
102
102
|
});
|
|
103
103
|
const imagePayload = preparedImage.imageBase64;
|
|
104
|
-
const actionContext = opts.actionContext ?
|
|
104
|
+
const actionContext = opts.actionContext ? `${opts.actionContext}\n` : '';
|
|
105
105
|
const referenceImageMessages = preparedReferenceImagesToChatMessages(userInstruction.referenceImages);
|
|
106
106
|
const instruction = [
|
|
107
107
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-model/workflows/planning/standard-planning.mjs","sources":["../../../../../src/ai-model/workflows/planning/standard-planning.ts"],"sourcesContent":["import type {\n PlanningAIResponse,\n PlanningAction,\n RawResponsePlanningAIResponse,\n} from '@/types';\nimport { getDebug } from '@midscene/shared/logger';\nimport { assert } from '@midscene/shared/utils';\nimport type { ChatCompletionMessageParam } from 'openai/resources/index';\nimport { buildYamlFlowFromPlans } from '../../../common';\nimport { prepareModelImage } from '../../model-adapter/image-preprocess';\nimport { buildStandardPlanningSystemPrompt } from '../../prompt/planning';\nimport { AIResponseParseError, callAI } from '../../service-caller/index';\nimport {\n callAiAndParseWithRetry,\n withSemanticRetryFeedback,\n} from '../../service-caller/semantic-retry';\nimport type {\n LocateResultCodec,\n LocateResultContext,\n} from '../../shared/model-locate-result';\nimport { planningModelFamilyRequiredForLocateMessage } from '../../shared/model-locate-result/errors';\nimport {\n type PreparedUserPrompt,\n preparedReferenceImagesToChatMessages,\n} from '../../shared/multimodal-prompt';\nimport { normalizePlanningActionLocateFields } from './locate-normalization';\nimport { parseStandardPlanningResponse } from './standard-planning-parser';\nimport type { PlanOptions } from './types';\n\nconst debug = getDebug('planning');\nconst warnLog = getDebug('planning', { console: true });\n\nconst noPreviousActionsText =\n 'No previous actions have been executed in this aiAct execution yet. If the instruction asks for actions, choose the first action to execute.';\ntype PlanningCallResponse = Awaited<ReturnType<typeof callAI>>;\n\ntype CallAndParsePlanningResponseOptions = {\n messages: ChatCompletionMessageParam[];\n modelRuntime: PlanOptions['modelRuntime'];\n abortSignal?: AbortSignal;\n includeLocateInPlanning: boolean;\n actionSpace: PlanOptions['actionSpace'];\n locateResultCodec?: LocateResultCodec;\n locateResultContext: LocateResultContext;\n includeThought: boolean;\n includeLog: boolean;\n};\n\nasync function callAndParsePlanningResponse(\n options: CallAndParsePlanningResponseOptions,\n): Promise<{\n response: PlanningCallResponse;\n planFromAI: RawResponsePlanningAIResponse;\n actions: PlanningAction[];\n yamlFlow: ReturnType<typeof buildYamlFlowFromPlans>;\n}> {\n const {\n messages,\n modelRuntime,\n abortSignal,\n includeLocateInPlanning,\n actionSpace,\n locateResultCodec,\n locateResultContext,\n includeThought,\n includeLog,\n } = options;\n assert(\n modelRuntime.adapter.planning.kind === 'standard',\n 'callAndParsePlanningResponse requires a standard planning adapter',\n );\n const actionOutputProtocol =\n modelRuntime.adapter.planning.protocol.actionOutputProtocol;\n\n return callAiAndParseWithRetry({\n callAi: (retryAttempt, previousParseError) =>\n callAI(\n withSemanticRetryFeedback(messages, previousParseError),\n modelRuntime,\n {\n abortSignal,\n requiresOriginalImageDetail: includeLocateInPlanning,\n semanticRetryAttempt: retryAttempt,\n },\n ),\n parseResponse: (response) => {\n const planFromAI = parseStandardPlanningResponse(response.content, {\n includeThought,\n actionOutputProtocol,\n actionSpace,\n logSource: includeLog ? 'model' : 'action',\n });\n if (planFromAI.action && planFromAI.finalizeSuccess !== undefined) {\n warnLog(\n 'Planning response included both an action and <complete>; ignoring <complete> output.',\n );\n planFromAI.finalizeMessage = undefined;\n planFromAI.finalizeSuccess = undefined;\n }\n\n const actions = planFromAI.action ? [planFromAI.action] : [];\n normalizePlanningActionLocateFields(actions, {\n actionSpace,\n includeLocateInPlanning,\n locateResultCodec,\n locateResultContext,\n acceptBbox2dAlias: modelRuntime.adapter.acceptBbox2dAlias,\n parseRawLocateParameter: actionOutputProtocol.parseRawLocateParameter,\n });\n // dumpActionParam keeps only the locator prompt, so runtime-only\n // locatedPixelBbox fields added during normalization are not serialized.\n const yamlFlow = buildYamlFlowFromPlans(actions, actionSpace);\n return { response, planFromAI, actions, yamlFlow };\n },\n toParseError: (parseError, response) => {\n const errorMessage =\n parseError instanceof Error ? parseError.message : String(parseError);\n return new AIResponseParseError(\n `XML parse error: ${errorMessage}`,\n response.content,\n response.usage,\n response.rawChoiceMessage,\n response.reasoning_content,\n );\n },\n parseRetryTimes: modelRuntime.config.retryCount,\n parseRetryInterval: modelRuntime.config.retryInterval,\n abortSignal,\n onParseRetry: (parseError) => {\n debug(\n 'retrying plan after response parsing failed: %s',\n parseError instanceof Error ? parseError.message : String(parseError),\n );\n },\n });\n}\n\nexport async function standardPlan(\n userInstruction: PreparedUserPrompt,\n opts: PlanOptions,\n): Promise<PlanningAIResponse> {\n const { context, conversationHistory } = opts;\n const modelRuntime = opts.modelRuntime;\n const { adapter } = modelRuntime;\n const { shotSize } = context;\n const screenshotBase64 = context.screenshot.base64;\n assert(\n adapter.planning.kind === 'standard',\n 'standardPlan requires a standard planning adapter',\n );\n const planningProtocol = adapter.planning.protocol;\n\n if (opts.includeLocateInPlanning && !modelRuntime.config.modelFamily) {\n throw new Error(\n planningModelFamilyRequiredForLocateMessage(modelRuntime.config.slot),\n );\n }\n\n const locateResultCodec = modelRuntime.config.modelFamily\n ? adapter.planning.locateResultCodec\n : undefined;\n\n // Only enable sub-goals when aiAct is in deep-thinking planning mode.\n const includeSubGoals = opts.effort === 'deepThink';\n const includeThought = opts.effort !== 'fast';\n const includeLog = opts.effort !== 'fast';\n\n if (opts.includeLocateInPlanning && !locateResultCodec) {\n throw new Error(\n planningModelFamilyRequiredForLocateMessage(modelRuntime.config.slot),\n );\n }\n\n const systemPrompt = await buildStandardPlanningSystemPrompt({\n actionSpace: opts.actionSpace,\n includeThought,\n includeLog,\n includeSubGoals,\n planningProtocol,\n ...(opts.includeLocateInPlanning && locateResultCodec\n ? {\n includeLocateInPlanning: true,\n locatePromptSpec: locateResultCodec.promptSpec,\n }\n : { includeLocateInPlanning: false }),\n });\n\n const preparedImage = await prepareModelImage({\n imageBase64: screenshotBase64,\n width: shotSize.width,\n height: shotSize.height,\n policy: adapter.imagePreprocess,\n });\n const imagePayload = preparedImage.imageBase64;\n\n const actionContext = opts.actionContext\n ? `<high_priority_knowledge>${opts.actionContext}</high_priority_knowledge>\\n`\n : '';\n\n const referenceImageMessages = preparedReferenceImagesToChatMessages(\n userInstruction.referenceImages,\n );\n const instruction: ChatCompletionMessageParam[] = [\n {\n role: 'user',\n content: [\n {\n type: 'text',\n text: `${actionContext}<user_instruction>${userInstruction.text}</user_instruction>`,\n },\n ],\n },\n ...referenceImageMessages,\n ];\n\n let latestFeedbackMessage: ChatCompletionMessageParam;\n\n // Build sub-goal status text to include in the message\n // In planning deep-think mode: show full sub-goals with logs\n // Otherwise: show historical execution logs\n const executionProgressText = includeSubGoals\n ? conversationHistory.subGoalsToText()\n : conversationHistory.historicalLogsToText();\n const executionProgressSection = executionProgressText\n ? `\\n\\n${executionProgressText}`\n : conversationHistory.pendingFeedbackMessage\n ? ''\n : `\\n\\n${noPreviousActionsText}`;\n\n // Build memories text to include in the message\n const memoriesText = conversationHistory.memoriesToText();\n const memoriesSection = memoriesText ? `\\n\\n${memoriesText}` : '';\n\n if (conversationHistory.pendingFeedbackMessage) {\n latestFeedbackMessage = {\n role: 'user',\n content: [\n {\n type: 'text',\n text: `${conversationHistory.pendingFeedbackMessage}. The previous action has been executed, here is the latest screenshot. Please continue according to the instruction.${memoriesSection}${executionProgressSection}`,\n },\n {\n type: 'image_url',\n image_url: {\n url: imagePayload,\n detail: 'high',\n },\n },\n ],\n };\n\n conversationHistory.resetPendingFeedbackMessageIfExists();\n } else {\n latestFeedbackMessage = {\n role: 'user',\n content: [\n {\n type: 'text',\n text: `This is the current screenshot.${memoriesSection}${executionProgressSection}`,\n },\n {\n type: 'image_url',\n image_url: {\n url: imagePayload,\n detail: 'high',\n },\n },\n ],\n };\n }\n conversationHistory.append(latestFeedbackMessage);\n\n // Compress history if it exceeds the threshold to avoid context overflow\n conversationHistory.compressHistory(50, 20);\n\n const historyLog = conversationHistory.snapshot(opts.imagesIncludeCount);\n\n const msgs: ChatCompletionMessageParam[] = [\n { role: 'system', content: systemPrompt },\n ...instruction,\n ...historyLog,\n ];\n\n const {\n response: {\n content: rawResponse,\n usage,\n reasoning_content,\n rawChoiceMessage,\n },\n planFromAI,\n actions,\n yamlFlow,\n } = await callAndParsePlanningResponse({\n messages: msgs,\n modelRuntime,\n abortSignal: opts.abortSignal,\n includeLocateInPlanning: opts.includeLocateInPlanning,\n actionSpace: opts.actionSpace,\n locateResultCodec,\n locateResultContext: {\n preparedSize: preparedImage.preparedSize,\n contentSize: preparedImage.contentSize,\n },\n includeThought,\n includeLog,\n });\n\n let shouldContinuePlanning = true;\n\n // Check if task is completed via <complete> tag\n if (planFromAI.finalizeSuccess !== undefined) {\n debug('task completed via <complete> tag, stop planning');\n shouldContinuePlanning = false;\n // Mark all sub-goals as finished when goal is completed in planning deep-think mode.\n if (includeSubGoals) {\n conversationHistory.markAllSubGoalsFinished();\n }\n }\n\n const returnValue: PlanningAIResponse = {\n ...planFromAI,\n actions,\n rawResponse,\n rawChoiceMessage,\n usage,\n reasoning_content,\n yamlFlow,\n shouldContinuePlanning,\n };\n\n assert(planFromAI, \"can't get plans from AI\");\n\n // TODO: The plan log is recorded before its action has executed, so a failed\n // action may still appear in the next round as an action already performed.\n // Move this write to the successful action execution path in TaskExecutor.action.\n // Update sub-goals in conversation history only in planning deep-think mode.\n if (includeSubGoals) {\n if (planFromAI.updateSubGoals?.length) {\n conversationHistory.mergeSubGoals(planFromAI.updateSubGoals);\n }\n if (planFromAI.markFinishedIndexes?.length) {\n for (const index of planFromAI.markFinishedIndexes) {\n conversationHistory.markSubGoalFinished(index);\n }\n }\n // Append the planning log to the currently running sub-goal\n if (planFromAI.log) {\n conversationHistory.appendSubGoalLog(planFromAI.log);\n }\n } else {\n // Without planning deep-think mode, accumulate logs as historical execution steps.\n if (planFromAI.log) {\n conversationHistory.appendHistoricalLog(planFromAI.log);\n }\n }\n\n // Append memory to conversation history if present\n if (planFromAI.memory) {\n conversationHistory.appendMemory(planFromAI.memory);\n }\n\n // Some model providers require opaque assistant fields to be replayed\n // verbatim in later turns. Keep this opt-in per model adapter so that an\n // unverified provider does not receive non-standard response fields.\n if (\n modelRuntime.adapter.chatCompletion.replayRawAssistantMessage &&\n rawChoiceMessage\n ) {\n conversationHistory.append(rawChoiceMessage as ChatCompletionMessageParam);\n } else {\n conversationHistory.append({\n role: 'assistant',\n content: [\n {\n type: 'text',\n text: rawResponse,\n },\n ],\n });\n }\n\n return returnValue;\n}\n"],"names":["debug","getDebug","warnLog","noPreviousActionsText","callAndParsePlanningResponse","options","messages","modelRuntime","abortSignal","includeLocateInPlanning","actionSpace","locateResultCodec","locateResultContext","includeThought","includeLog","assert","actionOutputProtocol","callAiAndParseWithRetry","retryAttempt","previousParseError","callAI","withSemanticRetryFeedback","response","planFromAI","parseStandardPlanningResponse","undefined","actions","normalizePlanningActionLocateFields","yamlFlow","buildYamlFlowFromPlans","parseError","errorMessage","Error","String","AIResponseParseError","standardPlan","userInstruction","opts","context","conversationHistory","adapter","shotSize","screenshotBase64","planningProtocol","planningModelFamilyRequiredForLocateMessage","includeSubGoals","systemPrompt","buildStandardPlanningSystemPrompt","preparedImage","prepareModelImage","imagePayload","actionContext","referenceImageMessages","preparedReferenceImagesToChatMessages","instruction","latestFeedbackMessage","executionProgressText","executionProgressSection","memoriesText","memoriesSection","historyLog","msgs","rawResponse","usage","reasoning_content","rawChoiceMessage","shouldContinuePlanning","returnValue","index"],"mappings":";;;;;;;;;;;AA6BA,MAAMA,QAAQC,SAAS;AACvB,MAAMC,UAAUD,SAAS,YAAY;IAAE,SAAS;AAAK;AAErD,MAAME,wBACJ;AAeF,eAAeC,6BACbC,OAA4C;IAO5C,MAAM,EACJC,QAAQ,EACRC,YAAY,EACZC,WAAW,EACXC,uBAAuB,EACvBC,WAAW,EACXC,iBAAiB,EACjBC,mBAAmB,EACnBC,cAAc,EACdC,UAAU,EACX,GAAGT;IACJU,OACER,AAAuC,eAAvCA,aAAa,OAAO,CAAC,QAAQ,CAAC,IAAI,EAClC;IAEF,MAAMS,uBACJT,aAAa,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,oBAAoB;IAE7D,OAAOU,wBAAwB;QAC7B,QAAQ,CAACC,cAAcC,qBACrBC,OACEC,0BAA0Bf,UAAUa,qBACpCZ,cACA;gBACEC;gBACA,6BAA6BC;gBAC7B,sBAAsB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G,MAAMxB,6BAA6B;QACrC,UAAUyD;QACVtD;QACA,aAAa8B,KAAK,WAAW;QAC7B,yBAAyBA,KAAK,uBAAuB;QACrD,aAAaA,KAAK,WAAW;QAC7B1B;QACA,qBAAqB;YACnB,cAAcqC,cAAc,YAAY;YACxC,aAAaA,cAAc,WAAW;QACxC;QACAnC;QACAC;IACF;IAEA,IAAIoD,yBAAyB;IAG7B,IAAI3C,AAA+BE,WAA/BF,WAAW,eAAe,EAAgB;QAC5CvB,MAAM;QACNkE,yBAAyB;QAEzB,IAAIrB,iBACFN,oBAAoB,uBAAuB;IAE/C;IAEA,MAAM4B,cAAkC;QACtC,GAAG5C,UAAU;QACbG;QACAoC;QACAG;QACAF;QACAC;QACApC;QACAsC;IACF;IAEAnD,OAAOQ,YAAY;IAMnB,IAAIsB,iBAAiB;QACnB,IAAItB,WAAW,cAAc,EAAE,QAC7BgB,oBAAoB,aAAa,CAAChB,WAAW,cAAc;QAE7D,IAAIA,WAAW,mBAAmB,EAAE,QAClC,KAAK,MAAM6C,SAAS7C,WAAW,mBAAmB,CAChDgB,oBAAoB,mBAAmB,CAAC6B;QAI5C,IAAI7C,WAAW,GAAG,EAChBgB,oBAAoB,gBAAgB,CAAChB,WAAW,GAAG;IAEvD,OAEE,IAAIA,WAAW,GAAG,EAChBgB,oBAAoB,mBAAmB,CAAChB,WAAW,GAAG;IAK1D,IAAIA,WAAW,MAAM,EACnBgB,oBAAoB,YAAY,CAAChB,WAAW,MAAM;IAMpD,IACEhB,aAAa,OAAO,CAAC,cAAc,CAAC,yBAAyB,IAC7D0D,kBAEA1B,oBAAoB,MAAM,CAAC0B;SAE3B1B,oBAAoB,MAAM,CAAC;QACzB,MAAM;QACN,SAAS;YACP;gBACE,MAAM;gBACN,MAAMuB;YACR;SACD;IACH;IAGF,OAAOK;AACT"}
|
|
1
|
+
{"version":3,"file":"ai-model/workflows/planning/standard-planning.mjs","sources":["../../../../../src/ai-model/workflows/planning/standard-planning.ts"],"sourcesContent":["import type {\n PlanningAIResponse,\n PlanningAction,\n RawResponsePlanningAIResponse,\n} from '@/types';\nimport { getDebug } from '@midscene/shared/logger';\nimport { assert } from '@midscene/shared/utils';\nimport type { ChatCompletionMessageParam } from 'openai/resources/index';\nimport { buildYamlFlowFromPlans } from '../../../common';\nimport { prepareModelImage } from '../../model-adapter/image-preprocess';\nimport { buildStandardPlanningSystemPrompt } from '../../prompt/planning';\nimport { AIResponseParseError, callAI } from '../../service-caller/index';\nimport {\n callAiAndParseWithRetry,\n withSemanticRetryFeedback,\n} from '../../service-caller/semantic-retry';\nimport type {\n LocateResultCodec,\n LocateResultContext,\n} from '../../shared/model-locate-result';\nimport { planningModelFamilyRequiredForLocateMessage } from '../../shared/model-locate-result/errors';\nimport {\n type PreparedUserPrompt,\n preparedReferenceImagesToChatMessages,\n} from '../../shared/multimodal-prompt';\nimport { normalizePlanningActionLocateFields } from './locate-normalization';\nimport { parseStandardPlanningResponse } from './standard-planning-parser';\nimport type { PlanOptions } from './types';\n\nconst debug = getDebug('planning');\nconst warnLog = getDebug('planning', { console: true });\n\nconst noPreviousActionsText =\n 'No previous actions have been executed in this aiAct execution yet. If the instruction asks for actions, choose the first action to execute.';\ntype PlanningCallResponse = Awaited<ReturnType<typeof callAI>>;\n\ntype CallAndParsePlanningResponseOptions = {\n messages: ChatCompletionMessageParam[];\n modelRuntime: PlanOptions['modelRuntime'];\n abortSignal?: AbortSignal;\n includeLocateInPlanning: boolean;\n actionSpace: PlanOptions['actionSpace'];\n locateResultCodec?: LocateResultCodec;\n locateResultContext: LocateResultContext;\n includeThought: boolean;\n includeLog: boolean;\n};\n\nasync function callAndParsePlanningResponse(\n options: CallAndParsePlanningResponseOptions,\n): Promise<{\n response: PlanningCallResponse;\n planFromAI: RawResponsePlanningAIResponse;\n actions: PlanningAction[];\n yamlFlow: ReturnType<typeof buildYamlFlowFromPlans>;\n}> {\n const {\n messages,\n modelRuntime,\n abortSignal,\n includeLocateInPlanning,\n actionSpace,\n locateResultCodec,\n locateResultContext,\n includeThought,\n includeLog,\n } = options;\n assert(\n modelRuntime.adapter.planning.kind === 'standard',\n 'callAndParsePlanningResponse requires a standard planning adapter',\n );\n const actionOutputProtocol =\n modelRuntime.adapter.planning.protocol.actionOutputProtocol;\n\n return callAiAndParseWithRetry({\n callAi: (retryAttempt, previousParseError) =>\n callAI(\n withSemanticRetryFeedback(messages, previousParseError),\n modelRuntime,\n {\n abortSignal,\n requiresOriginalImageDetail: includeLocateInPlanning,\n semanticRetryAttempt: retryAttempt,\n },\n ),\n parseResponse: (response) => {\n const planFromAI = parseStandardPlanningResponse(response.content, {\n includeThought,\n actionOutputProtocol,\n actionSpace,\n logSource: includeLog ? 'model' : 'action',\n });\n if (planFromAI.action && planFromAI.finalizeSuccess !== undefined) {\n warnLog(\n 'Planning response included both an action and <complete>; ignoring <complete> output.',\n );\n planFromAI.finalizeMessage = undefined;\n planFromAI.finalizeSuccess = undefined;\n }\n\n const actions = planFromAI.action ? [planFromAI.action] : [];\n normalizePlanningActionLocateFields(actions, {\n actionSpace,\n includeLocateInPlanning,\n locateResultCodec,\n locateResultContext,\n acceptBbox2dAlias: modelRuntime.adapter.acceptBbox2dAlias,\n parseRawLocateParameter: actionOutputProtocol.parseRawLocateParameter,\n });\n // dumpActionParam keeps only the locator prompt, so runtime-only\n // locatedPixelBbox fields added during normalization are not serialized.\n const yamlFlow = buildYamlFlowFromPlans(actions, actionSpace);\n return { response, planFromAI, actions, yamlFlow };\n },\n toParseError: (parseError, response) => {\n const errorMessage =\n parseError instanceof Error ? parseError.message : String(parseError);\n return new AIResponseParseError(\n `XML parse error: ${errorMessage}`,\n response.content,\n response.usage,\n response.rawChoiceMessage,\n response.reasoning_content,\n );\n },\n parseRetryTimes: modelRuntime.config.retryCount,\n parseRetryInterval: modelRuntime.config.retryInterval,\n abortSignal,\n onParseRetry: (parseError) => {\n debug(\n 'retrying plan after response parsing failed: %s',\n parseError instanceof Error ? parseError.message : String(parseError),\n );\n },\n });\n}\n\nexport async function standardPlan(\n userInstruction: PreparedUserPrompt,\n opts: PlanOptions,\n): Promise<PlanningAIResponse> {\n const { context, conversationHistory } = opts;\n const modelRuntime = opts.modelRuntime;\n const { adapter } = modelRuntime;\n const { shotSize } = context;\n const screenshotBase64 = context.screenshot.base64;\n assert(\n adapter.planning.kind === 'standard',\n 'standardPlan requires a standard planning adapter',\n );\n const planningProtocol = adapter.planning.protocol;\n\n if (opts.includeLocateInPlanning && !modelRuntime.config.modelFamily) {\n throw new Error(\n planningModelFamilyRequiredForLocateMessage(modelRuntime.config.slot),\n );\n }\n\n const locateResultCodec = modelRuntime.config.modelFamily\n ? adapter.planning.locateResultCodec\n : undefined;\n\n // Only enable sub-goals when aiAct is in deep-thinking planning mode.\n const includeSubGoals = opts.effort === 'deepThink';\n const includeThought = opts.effort !== 'fast';\n const includeLog = opts.effort !== 'fast';\n\n if (opts.includeLocateInPlanning && !locateResultCodec) {\n throw new Error(\n planningModelFamilyRequiredForLocateMessage(modelRuntime.config.slot),\n );\n }\n\n const systemPrompt = await buildStandardPlanningSystemPrompt({\n actionSpace: opts.actionSpace,\n includeThought,\n includeLog,\n includeSubGoals,\n planningProtocol,\n ...(opts.includeLocateInPlanning && locateResultCodec\n ? {\n includeLocateInPlanning: true,\n locatePromptSpec: locateResultCodec.promptSpec,\n }\n : { includeLocateInPlanning: false }),\n });\n\n const preparedImage = await prepareModelImage({\n imageBase64: screenshotBase64,\n width: shotSize.width,\n height: shotSize.height,\n policy: adapter.imagePreprocess,\n });\n const imagePayload = preparedImage.imageBase64;\n\n const actionContext = opts.actionContext ? `${opts.actionContext}\\n` : '';\n\n const referenceImageMessages = preparedReferenceImagesToChatMessages(\n userInstruction.referenceImages,\n );\n const instruction: ChatCompletionMessageParam[] = [\n {\n role: 'user',\n content: [\n {\n type: 'text',\n text: `${actionContext}<user_instruction>${userInstruction.text}</user_instruction>`,\n },\n ],\n },\n ...referenceImageMessages,\n ];\n\n let latestFeedbackMessage: ChatCompletionMessageParam;\n\n // Build sub-goal status text to include in the message\n // In planning deep-think mode: show full sub-goals with logs\n // Otherwise: show historical execution logs\n const executionProgressText = includeSubGoals\n ? conversationHistory.subGoalsToText()\n : conversationHistory.historicalLogsToText();\n const executionProgressSection = executionProgressText\n ? `\\n\\n${executionProgressText}`\n : conversationHistory.pendingFeedbackMessage\n ? ''\n : `\\n\\n${noPreviousActionsText}`;\n\n // Build memories text to include in the message\n const memoriesText = conversationHistory.memoriesToText();\n const memoriesSection = memoriesText ? `\\n\\n${memoriesText}` : '';\n\n if (conversationHistory.pendingFeedbackMessage) {\n latestFeedbackMessage = {\n role: 'user',\n content: [\n {\n type: 'text',\n text: `${conversationHistory.pendingFeedbackMessage}. The previous action has been executed, here is the latest screenshot. Please continue according to the instruction.${memoriesSection}${executionProgressSection}`,\n },\n {\n type: 'image_url',\n image_url: {\n url: imagePayload,\n detail: 'high',\n },\n },\n ],\n };\n\n conversationHistory.resetPendingFeedbackMessageIfExists();\n } else {\n latestFeedbackMessage = {\n role: 'user',\n content: [\n {\n type: 'text',\n text: `This is the current screenshot.${memoriesSection}${executionProgressSection}`,\n },\n {\n type: 'image_url',\n image_url: {\n url: imagePayload,\n detail: 'high',\n },\n },\n ],\n };\n }\n conversationHistory.append(latestFeedbackMessage);\n\n // Compress history if it exceeds the threshold to avoid context overflow\n conversationHistory.compressHistory(50, 20);\n\n const historyLog = conversationHistory.snapshot(opts.imagesIncludeCount);\n\n const msgs: ChatCompletionMessageParam[] = [\n { role: 'system', content: systemPrompt },\n ...instruction,\n ...historyLog,\n ];\n\n const {\n response: {\n content: rawResponse,\n usage,\n reasoning_content,\n rawChoiceMessage,\n },\n planFromAI,\n actions,\n yamlFlow,\n } = await callAndParsePlanningResponse({\n messages: msgs,\n modelRuntime,\n abortSignal: opts.abortSignal,\n includeLocateInPlanning: opts.includeLocateInPlanning,\n actionSpace: opts.actionSpace,\n locateResultCodec,\n locateResultContext: {\n preparedSize: preparedImage.preparedSize,\n contentSize: preparedImage.contentSize,\n },\n includeThought,\n includeLog,\n });\n\n let shouldContinuePlanning = true;\n\n // Check if task is completed via <complete> tag\n if (planFromAI.finalizeSuccess !== undefined) {\n debug('task completed via <complete> tag, stop planning');\n shouldContinuePlanning = false;\n // Mark all sub-goals as finished when goal is completed in planning deep-think mode.\n if (includeSubGoals) {\n conversationHistory.markAllSubGoalsFinished();\n }\n }\n\n const returnValue: PlanningAIResponse = {\n ...planFromAI,\n actions,\n rawResponse,\n rawChoiceMessage,\n usage,\n reasoning_content,\n yamlFlow,\n shouldContinuePlanning,\n };\n\n assert(planFromAI, \"can't get plans from AI\");\n\n // TODO: The plan log is recorded before its action has executed, so a failed\n // action may still appear in the next round as an action already performed.\n // Move this write to the successful action execution path in TaskExecutor.action.\n // Update sub-goals in conversation history only in planning deep-think mode.\n if (includeSubGoals) {\n if (planFromAI.updateSubGoals?.length) {\n conversationHistory.mergeSubGoals(planFromAI.updateSubGoals);\n }\n if (planFromAI.markFinishedIndexes?.length) {\n for (const index of planFromAI.markFinishedIndexes) {\n conversationHistory.markSubGoalFinished(index);\n }\n }\n // Append the planning log to the currently running sub-goal\n if (planFromAI.log) {\n conversationHistory.appendSubGoalLog(planFromAI.log);\n }\n } else {\n // Without planning deep-think mode, accumulate logs as historical execution steps.\n if (planFromAI.log) {\n conversationHistory.appendHistoricalLog(planFromAI.log);\n }\n }\n\n // Append memory to conversation history if present\n if (planFromAI.memory) {\n conversationHistory.appendMemory(planFromAI.memory);\n }\n\n // Some model providers require opaque assistant fields to be replayed\n // verbatim in later turns. Keep this opt-in per model adapter so that an\n // unverified provider does not receive non-standard response fields.\n if (\n modelRuntime.adapter.chatCompletion.replayRawAssistantMessage &&\n rawChoiceMessage\n ) {\n conversationHistory.append(rawChoiceMessage as ChatCompletionMessageParam);\n } else {\n conversationHistory.append({\n role: 'assistant',\n content: [\n {\n type: 'text',\n text: rawResponse,\n },\n ],\n });\n }\n\n return returnValue;\n}\n"],"names":["debug","getDebug","warnLog","noPreviousActionsText","callAndParsePlanningResponse","options","messages","modelRuntime","abortSignal","includeLocateInPlanning","actionSpace","locateResultCodec","locateResultContext","includeThought","includeLog","assert","actionOutputProtocol","callAiAndParseWithRetry","retryAttempt","previousParseError","callAI","withSemanticRetryFeedback","response","planFromAI","parseStandardPlanningResponse","undefined","actions","normalizePlanningActionLocateFields","yamlFlow","buildYamlFlowFromPlans","parseError","errorMessage","Error","String","AIResponseParseError","standardPlan","userInstruction","opts","context","conversationHistory","adapter","shotSize","screenshotBase64","planningProtocol","planningModelFamilyRequiredForLocateMessage","includeSubGoals","systemPrompt","buildStandardPlanningSystemPrompt","preparedImage","prepareModelImage","imagePayload","actionContext","referenceImageMessages","preparedReferenceImagesToChatMessages","instruction","latestFeedbackMessage","executionProgressText","executionProgressSection","memoriesText","memoriesSection","historyLog","msgs","rawResponse","usage","reasoning_content","rawChoiceMessage","shouldContinuePlanning","returnValue","index"],"mappings":";;;;;;;;;;;AA6BA,MAAMA,QAAQC,SAAS;AACvB,MAAMC,UAAUD,SAAS,YAAY;IAAE,SAAS;AAAK;AAErD,MAAME,wBACJ;AAeF,eAAeC,6BACbC,OAA4C;IAO5C,MAAM,EACJC,QAAQ,EACRC,YAAY,EACZC,WAAW,EACXC,uBAAuB,EACvBC,WAAW,EACXC,iBAAiB,EACjBC,mBAAmB,EACnBC,cAAc,EACdC,UAAU,EACX,GAAGT;IACJU,OACER,AAAuC,eAAvCA,aAAa,OAAO,CAAC,QAAQ,CAAC,IAAI,EAClC;IAEF,MAAMS,uBACJT,aAAa,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,oBAAoB;IAE7D,OAAOU,wBAAwB;QAC7B,QAAQ,CAACC,cAAcC,qBACrBC,OACEC,0BAA0Bf,UAAUa,qBACpCZ,cACA;gBACEC;gBACA,6BAA6BC;gBAC7B,sBAAsBS;YACxB;QAEJ,eAAe,CAACI;YACd,MAAMC,aAAaC,8BAA8BF,SAAS,OAAO,EAAE;gBACjET;gBACAG;gBACAN;gBACA,WAAWI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7B1B;QACA,qBAAqB;YACnB,cAAcqC,cAAc,YAAY;YACxC,aAAaA,cAAc,WAAW;QACxC;QACAnC;QACAC;IACF;IAEA,IAAIoD,yBAAyB;IAG7B,IAAI3C,AAA+BE,WAA/BF,WAAW,eAAe,EAAgB;QAC5CvB,MAAM;QACNkE,yBAAyB;QAEzB,IAAIrB,iBACFN,oBAAoB,uBAAuB;IAE/C;IAEA,MAAM4B,cAAkC;QACtC,GAAG5C,UAAU;QACbG;QACAoC;QACAG;QACAF;QACAC;QACApC;QACAsC;IACF;IAEAnD,OAAOQ,YAAY;IAMnB,IAAIsB,iBAAiB;QACnB,IAAItB,WAAW,cAAc,EAAE,QAC7BgB,oBAAoB,aAAa,CAAChB,WAAW,cAAc;QAE7D,IAAIA,WAAW,mBAAmB,EAAE,QAClC,KAAK,MAAM6C,SAAS7C,WAAW,mBAAmB,CAChDgB,oBAAoB,mBAAmB,CAAC6B;QAI5C,IAAI7C,WAAW,GAAG,EAChBgB,oBAAoB,gBAAgB,CAAChB,WAAW,GAAG;IAEvD,OAEE,IAAIA,WAAW,GAAG,EAChBgB,oBAAoB,mBAAmB,CAAChB,WAAW,GAAG;IAK1D,IAAIA,WAAW,MAAM,EACnBgB,oBAAoB,YAAY,CAAChB,WAAW,MAAM;IAMpD,IACEhB,aAAa,OAAO,CAAC,cAAc,CAAC,yBAAyB,IAC7D0D,kBAEA1B,oBAAoB,MAAM,CAAC0B;SAE3B1B,oBAAoB,MAAM,CAAC;QACzB,MAAM;QACN,SAAS;YACP;gBACE,MAAM;gBACN,MAAMuB;YACR;SACD;IACH;IAGF,OAAOK;AACT"}
|
package/dist/es/index.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { getVersion } from "./utils.mjs";
|
|
|
5
5
|
import { AiLocateElement, PointSchema, RectSchema, SizeSchema, TMultimodalPromptSchema, TUserPromptSchema, getMidsceneLocationSchema, runConnectivityTest, standardPlan } from "./ai-model/index.mjs";
|
|
6
6
|
import { MIDSCENE_MODEL_NAME } from "@midscene/shared/env";
|
|
7
7
|
import { ExecutionDump, GroupedActionDump, ReportActionDump, ServiceError } from "./types.mjs";
|
|
8
|
-
import { Agent, createAgent } from "./agent/index.mjs";
|
|
8
|
+
import { Agent, createAgent, mergeAIContexts } from "./agent/index.mjs";
|
|
9
9
|
import { describeElementAtPoint, verifyElementDescriptionAtPoint, verifyLocator } from "./element-describer.mjs";
|
|
10
10
|
import { createInlineImageResolver, deriveCaseStatus, deriveTaskStatus, escapeContent, generateDumpScriptTag, generateImageScriptTag, parseDumpScript, parseDumpScriptAttributes, parseImageScripts, restoreImageReferences, restoreReportImageReferences, unescapeContent } from "./dump/index.mjs";
|
|
11
11
|
import { getTaskSearchArea, getTaskServiceDump } from "./dump/task-service-dump.mjs";
|
|
@@ -16,6 +16,6 @@ import { ScreenshotItem } from "./screenshot-item.mjs";
|
|
|
16
16
|
import { ReportImageStore, ScreenshotStore } from "./dump/screenshot-store.mjs";
|
|
17
17
|
import { executionToMarkdown, reportToMarkdown } from "./report-markdown.mjs";
|
|
18
18
|
const src = service;
|
|
19
|
-
export { Agent, AiLocateElement, ExecutionDump, GroupedActionDump, MIDSCENE_MODEL_NAME, PointSchema, RectSchema, ReportActionDump, ReportGenerator, ReportImageStore, ReportMergingTool, ScreenshotItem, ScreenshotStore, service as Service, ServiceError, SizeSchema, TMultimodalPromptSchema, TUserPromptSchema, TaskRunner, collectDedupedExecutions, createAgent, createInlineImageResolver, createReportCliCommands, dedupeExecutionsKeepLatest, src as default, deriveCaseStatus, deriveTaskStatus, describeElementAtPoint, escapeContent, executionToMarkdown, generateDumpScriptTag, generateImageScriptTag, getMidsceneLocationSchema, getTaskSearchArea, getTaskServiceDump, getVersion, mergeReportFiles, nullReportGenerator, parseDumpScript, parseDumpScriptAttributes, parseImageScripts, reportFileToMarkdown, reportToMarkdown, restoreImageReferences, restoreReportImageReferences, runConnectivityTest, splitReportFile, splitReportHtmlByExecution, standardPlan, unescapeContent, verifyElementDescriptionAtPoint, verifyLocator, z };
|
|
19
|
+
export { Agent, AiLocateElement, ExecutionDump, GroupedActionDump, MIDSCENE_MODEL_NAME, PointSchema, RectSchema, ReportActionDump, ReportGenerator, ReportImageStore, ReportMergingTool, ScreenshotItem, ScreenshotStore, service as Service, ServiceError, SizeSchema, TMultimodalPromptSchema, TUserPromptSchema, TaskRunner, collectDedupedExecutions, createAgent, createInlineImageResolver, createReportCliCommands, dedupeExecutionsKeepLatest, src as default, deriveCaseStatus, deriveTaskStatus, describeElementAtPoint, escapeContent, executionToMarkdown, generateDumpScriptTag, generateImageScriptTag, getMidsceneLocationSchema, getTaskSearchArea, getTaskServiceDump, getVersion, mergeAIContexts, mergeReportFiles, nullReportGenerator, parseDumpScript, parseDumpScriptAttributes, parseImageScripts, reportFileToMarkdown, reportToMarkdown, restoreImageReferences, restoreReportImageReferences, runConnectivityTest, splitReportFile, splitReportHtmlByExecution, standardPlan, unescapeContent, verifyElementDescriptionAtPoint, verifyLocator, z };
|
|
20
20
|
|
|
21
21
|
//# sourceMappingURL=index.mjs.map
|
package/dist/es/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../src/index.ts"],"sourcesContent":["import { z } from 'zod';\nimport Service from './service/index';\nimport { TaskRunner } from './task-runner';\nimport { getVersion } from './utils';\n\nexport {\n standardPlan,\n AiLocateElement,\n runConnectivityTest,\n getMidsceneLocationSchema,\n PointSchema,\n SizeSchema,\n RectSchema,\n TMultimodalPromptSchema,\n TUserPromptSchema,\n type TMultimodalPrompt,\n type TUserPrompt,\n type ConnectivityTestConfig,\n type ConnectivityTestResult,\n} from './ai-model/index';\n\nexport {\n MIDSCENE_MODEL_NAME,\n type CreateOpenAIClientFn,\n} from '@midscene/shared/env';\n\nexport type * from './types';\nexport {\n ServiceError,\n ExecutionDump,\n ReportActionDump,\n GroupedActionDump,\n type IExecutionDump,\n type IReportActionDump,\n type IGroupedActionDump,\n type ReportMeta,\n type GroupMeta,\n} from './types';\n\nexport { z };\n\nexport default Service;\nexport { TaskRunner, Service, getVersion };\n\nexport type {\n MidsceneYamlScript,\n MidsceneYamlTask,\n MidsceneYamlFlowItem,\n MidsceneYamlConfigResult,\n MidsceneYamlConfig,\n MidsceneYamlScriptWebEnv,\n MidsceneYamlScriptAndroidEnv,\n MidsceneYamlScriptIOSEnv,\n MidsceneYamlScriptEnv,\n LocateOption,\n DetailedLocateParam,\n} from './yaml';\n\nexport {\n Agent,\n type AgentOpt,\n type AiActOptions,\n type GherkinStepKeyword,\n type MidsceneUsageMetrics,\n type RunGherkinScenarioOptions,\n type UsageBucket,\n createAgent,\n type UIObservation,\n type UIObserver,\n type UIObserverOption,\n} from './agent';\nexport {\n describeElementAtPoint,\n verifyElementDescriptionAtPoint,\n verifyLocator,\n type DescribeElementAtPointOptions,\n type DescribeElementCoordinateSpace,\n type ElementDescriberRuntime,\n type VerifyElementDescriptionAtPointOptions,\n} from './element-describer';\n\n// Dump utilities\nexport {\n createInlineImageResolver,\n restoreImageReferences,\n restoreReportImageReferences,\n escapeContent,\n unescapeContent,\n parseImageScripts,\n parseDumpScript,\n parseDumpScriptAttributes,\n generateImageScriptTag,\n generateDumpScriptTag,\n deriveTaskStatus,\n deriveCaseStatus,\n} from './dump';\nexport type {\n TaskStatusFields,\n DerivedTaskStatus,\n RestoredScreenshotReference,\n StoredImageReferenceResolver,\n} from './dump';\nexport {\n getTaskSearchArea,\n getTaskServiceDump,\n} from './dump/task-service-dump';\n\n// Report generator\nexport type { IReportGenerator } from './report-generator';\nexport { ReportGenerator, nullReportGenerator } from './report-generator';\nexport {\n collectDedupedExecutions,\n ReportMergingTool,\n dedupeExecutionsKeepLatest,\n splitReportHtmlByExecution,\n} from './report';\nexport {\n createReportCliCommands,\n reportFileToMarkdown,\n splitReportFile,\n mergeReportFiles,\n type ConsumeReportFileAction,\n type ReportFileToMarkdownOptions,\n type ReportCliCommandDefinition,\n type ReportCliCommandEntry,\n type SplitReportFileOptions,\n type MergeReportFilesOptions,\n type MergeReportFilesResult,\n} from './report-cli';\n\n// ScreenshotItem\nexport { ScreenshotItem } from './screenshot-item';\nexport type {\n ImageUrlRef,\n ScreenshotRef,\n StoredImageRef,\n} from './dump/image-reference';\nexport {\n ReportImageStore,\n ScreenshotStore,\n} from './dump/screenshot-store';\n\nexport {\n executionToMarkdown,\n reportToMarkdown,\n type ExecutionMarkdownOptions,\n type ExecutionMarkdownResult,\n type ReportMarkdownOptions,\n type ReportMarkdownResult,\n type MarkdownAttachment,\n} from './report-markdown';\n"],"names":["Service"],"mappings":";;;;;;;;;;;;;;;;;AAyCA,YAAeA"}
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../src/index.ts"],"sourcesContent":["import { z } from 'zod';\nimport Service from './service/index';\nimport { TaskRunner } from './task-runner';\nimport { getVersion } from './utils';\n\nexport {\n standardPlan,\n AiLocateElement,\n runConnectivityTest,\n getMidsceneLocationSchema,\n PointSchema,\n SizeSchema,\n RectSchema,\n TMultimodalPromptSchema,\n TUserPromptSchema,\n type TMultimodalPrompt,\n type TUserPrompt,\n type ConnectivityTestConfig,\n type ConnectivityTestResult,\n} from './ai-model/index';\n\nexport {\n MIDSCENE_MODEL_NAME,\n type CreateOpenAIClientFn,\n} from '@midscene/shared/env';\n\nexport type * from './types';\nexport {\n ServiceError,\n ExecutionDump,\n ReportActionDump,\n GroupedActionDump,\n type IExecutionDump,\n type IReportActionDump,\n type IGroupedActionDump,\n type ReportMeta,\n type GroupMeta,\n} from './types';\n\nexport { z };\n\nexport default Service;\nexport { TaskRunner, Service, getVersion };\n\nexport type {\n MidsceneYamlScript,\n MidsceneYamlTask,\n MidsceneYamlFlowItem,\n MidsceneYamlConfigResult,\n MidsceneYamlConfig,\n MidsceneYamlScriptWebEnv,\n MidsceneYamlScriptAndroidEnv,\n MidsceneYamlScriptIOSEnv,\n MidsceneYamlScriptEnv,\n LocateOption,\n DetailedLocateParam,\n} from './yaml';\n\nexport {\n Agent,\n mergeAIContexts,\n type AgentOpt,\n type AiActOptions,\n type GherkinStepKeyword,\n type MidsceneUsageMetrics,\n type RunGherkinScenarioOptions,\n type UsageBucket,\n createAgent,\n type UIObservation,\n type UIObserver,\n type UIObserverOption,\n} from './agent';\nexport {\n describeElementAtPoint,\n verifyElementDescriptionAtPoint,\n verifyLocator,\n type DescribeElementAtPointOptions,\n type DescribeElementCoordinateSpace,\n type ElementDescriberRuntime,\n type VerifyElementDescriptionAtPointOptions,\n} from './element-describer';\n\n// Dump utilities\nexport {\n createInlineImageResolver,\n restoreImageReferences,\n restoreReportImageReferences,\n escapeContent,\n unescapeContent,\n parseImageScripts,\n parseDumpScript,\n parseDumpScriptAttributes,\n generateImageScriptTag,\n generateDumpScriptTag,\n deriveTaskStatus,\n deriveCaseStatus,\n} from './dump';\nexport type {\n TaskStatusFields,\n DerivedTaskStatus,\n RestoredScreenshotReference,\n StoredImageReferenceResolver,\n} from './dump';\nexport {\n getTaskSearchArea,\n getTaskServiceDump,\n} from './dump/task-service-dump';\n\n// Report generator\nexport type { IReportGenerator } from './report-generator';\nexport { ReportGenerator, nullReportGenerator } from './report-generator';\nexport {\n collectDedupedExecutions,\n ReportMergingTool,\n dedupeExecutionsKeepLatest,\n splitReportHtmlByExecution,\n} from './report';\nexport {\n createReportCliCommands,\n reportFileToMarkdown,\n splitReportFile,\n mergeReportFiles,\n type ConsumeReportFileAction,\n type ReportFileToMarkdownOptions,\n type ReportCliCommandDefinition,\n type ReportCliCommandEntry,\n type SplitReportFileOptions,\n type MergeReportFilesOptions,\n type MergeReportFilesResult,\n} from './report-cli';\n\n// ScreenshotItem\nexport { ScreenshotItem } from './screenshot-item';\nexport type {\n ImageUrlRef,\n ScreenshotRef,\n StoredImageRef,\n} from './dump/image-reference';\nexport {\n ReportImageStore,\n ScreenshotStore,\n} from './dump/screenshot-store';\n\nexport {\n executionToMarkdown,\n reportToMarkdown,\n type ExecutionMarkdownOptions,\n type ExecutionMarkdownResult,\n type ReportMarkdownOptions,\n type ReportMarkdownResult,\n type MarkdownAttachment,\n} from './report-markdown';\n"],"names":["Service"],"mappings":";;;;;;;;;;;;;;;;;AAyCA,YAAeA"}
|