@midscene/core 1.15.5 → 1.16.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 +13 -12
- package/dist/es/agent/agent.mjs.map +1 -1
- package/dist/es/agent/insight.mjs +3 -3
- package/dist/es/agent/insight.mjs.map +1 -1
- package/dist/es/agent/task-builder.mjs +14 -8
- package/dist/es/agent/task-builder.mjs.map +1 -1
- package/dist/es/agent/tasks.mjs +18 -13
- package/dist/es/agent/tasks.mjs.map +1 -1
- package/dist/es/agent/utils.mjs +1 -1
- package/dist/es/ai-model/connectivity/run-connectivity-test.mjs +25 -4
- package/dist/es/ai-model/connectivity/run-connectivity-test.mjs.map +1 -1
- package/dist/es/ai-model/model-adapter/insight.mjs +1 -0
- package/dist/es/ai-model/model-adapter/insight.mjs.map +1 -1
- package/dist/es/ai-model/model-adapter/resolve.mjs +2 -0
- package/dist/es/ai-model/model-adapter/resolve.mjs.map +1 -1
- package/dist/es/ai-model/models/gpt.mjs +3 -3
- package/dist/es/ai-model/models/gpt.mjs.map +1 -1
- package/dist/es/ai-model/models/jev/adapter.mjs +135 -0
- package/dist/es/ai-model/models/jev/adapter.mjs.map +1 -0
- package/dist/es/ai-model/models/jev/image.mjs +48 -0
- package/dist/es/ai-model/models/jev/image.mjs.map +1 -0
- package/dist/es/ai-model/models/jev/planning.mjs +168 -0
- package/dist/es/ai-model/models/jev/planning.mjs.map +1 -0
- package/dist/es/ai-model/models/registry.mjs +2 -0
- package/dist/es/ai-model/models/registry.mjs.map +1 -1
- package/dist/es/ai-model/models/task-routing.mjs +28 -0
- package/dist/es/ai-model/models/task-routing.mjs.map +1 -0
- package/dist/es/ai-model/models/utils/intent.mjs +1 -1
- package/dist/es/ai-model/models/utils/intent.mjs.map +1 -1
- package/dist/es/ai-model/service-caller/call-ai.mjs +15 -2
- package/dist/es/ai-model/service-caller/call-ai.mjs.map +1 -1
- package/dist/es/ai-model/service-caller/openai/call-openai.mjs +1 -2
- package/dist/es/ai-model/service-caller/openai/call-openai.mjs.map +1 -1
- package/dist/es/ai-model/service-caller/system-one.mjs +163 -0
- package/dist/es/ai-model/service-caller/system-one.mjs.map +1 -0
- package/dist/es/ai-model/shared/model-locate-result/errors.mjs +6 -2
- package/dist/es/ai-model/shared/model-locate-result/errors.mjs.map +1 -1
- package/dist/es/ai-model/workflows/insight/boolean.mjs +20 -0
- package/dist/es/ai-model/workflows/insight/boolean.mjs.map +1 -0
- package/dist/es/ai-model/workflows/insight/extraction.mjs +2 -0
- package/dist/es/ai-model/workflows/insight/extraction.mjs.map +1 -1
- package/dist/es/report-html-template.mjs +1 -1
- package/dist/es/service/index.mjs +2 -2
- package/dist/es/service/index.mjs.map +1 -1
- package/dist/es/types.mjs.map +1 -1
- package/dist/es/utils.mjs +1 -1
- package/dist/lib/agent/agent.js +15 -14
- package/dist/lib/agent/agent.js.map +1 -1
- package/dist/lib/agent/insight.js +3 -3
- package/dist/lib/agent/insight.js.map +1 -1
- package/dist/lib/agent/task-builder.js +14 -8
- package/dist/lib/agent/task-builder.js.map +1 -1
- package/dist/lib/agent/tasks.js +18 -13
- package/dist/lib/agent/tasks.js.map +1 -1
- package/dist/lib/agent/utils.js +1 -1
- package/dist/lib/ai-model/connectivity/run-connectivity-test.js +25 -4
- package/dist/lib/ai-model/connectivity/run-connectivity-test.js.map +1 -1
- package/dist/lib/ai-model/model-adapter/insight.js +1 -0
- package/dist/lib/ai-model/model-adapter/insight.js.map +1 -1
- package/dist/lib/ai-model/model-adapter/resolve.js +2 -0
- package/dist/lib/ai-model/model-adapter/resolve.js.map +1 -1
- package/dist/lib/ai-model/models/gpt.js +3 -3
- package/dist/lib/ai-model/models/gpt.js.map +1 -1
- package/dist/lib/ai-model/models/jev/adapter.js +169 -0
- package/dist/lib/ai-model/models/jev/adapter.js.map +1 -0
- package/dist/lib/ai-model/models/jev/image.js +85 -0
- package/dist/lib/ai-model/models/jev/image.js.map +1 -0
- package/dist/lib/ai-model/models/jev/planning.js +202 -0
- package/dist/lib/ai-model/models/jev/planning.js.map +1 -0
- package/dist/lib/ai-model/models/registry.js +2 -0
- package/dist/lib/ai-model/models/registry.js.map +1 -1
- package/dist/lib/ai-model/models/task-routing.js +62 -0
- package/dist/lib/ai-model/models/task-routing.js.map +1 -0
- package/dist/lib/ai-model/models/utils/intent.js +1 -1
- package/dist/lib/ai-model/models/utils/intent.js.map +1 -1
- package/dist/lib/ai-model/service-caller/call-ai.js +15 -2
- package/dist/lib/ai-model/service-caller/call-ai.js.map +1 -1
- package/dist/lib/ai-model/service-caller/openai/call-openai.js +1 -2
- package/dist/lib/ai-model/service-caller/openai/call-openai.js.map +1 -1
- package/dist/lib/ai-model/service-caller/system-one.js +206 -0
- package/dist/lib/ai-model/service-caller/system-one.js.map +1 -0
- package/dist/lib/ai-model/shared/model-locate-result/errors.js +8 -4
- package/dist/lib/ai-model/shared/model-locate-result/errors.js.map +1 -1
- package/dist/lib/ai-model/workflows/insight/boolean.js +54 -0
- package/dist/lib/ai-model/workflows/insight/boolean.js.map +1 -0
- package/dist/lib/ai-model/workflows/insight/extraction.js +2 -0
- package/dist/lib/ai-model/workflows/insight/extraction.js.map +1 -1
- package/dist/lib/report-html-template.js +1 -1
- package/dist/lib/service/index.js +1 -1
- package/dist/lib/service/index.js.map +1 -1
- package/dist/lib/types.js.map +1 -1
- package/dist/lib/utils.js +1 -1
- package/dist/types/agent/agent.d.ts.map +1 -1
- package/dist/types/agent/insight.d.ts +2 -1
- package/dist/types/agent/insight.d.ts.map +1 -1
- package/dist/types/agent/task-builder.d.ts +4 -2
- package/dist/types/agent/task-builder.d.ts.map +1 -1
- package/dist/types/agent/tasks.d.ts +5 -3
- package/dist/types/agent/tasks.d.ts.map +1 -1
- package/dist/types/agent/test-runner-nodes.d.ts +1 -1
- package/dist/types/ai-model/connectivity/run-connectivity-test.d.ts +1 -0
- package/dist/types/ai-model/connectivity/run-connectivity-test.d.ts.map +1 -1
- package/dist/types/ai-model/model-adapter/insight-protocol.d.ts +3 -0
- package/dist/types/ai-model/model-adapter/insight-protocol.d.ts.map +1 -1
- package/dist/types/ai-model/model-adapter/insight.d.ts.map +1 -1
- package/dist/types/ai-model/model-adapter/resolve.d.ts +1 -0
- package/dist/types/ai-model/model-adapter/resolve.d.ts.map +1 -1
- package/dist/types/ai-model/model-adapter/types.d.ts +9 -0
- package/dist/types/ai-model/model-adapter/types.d.ts.map +1 -1
- package/dist/types/ai-model/models/jev/adapter.d.ts +23 -0
- package/dist/types/ai-model/models/jev/adapter.d.ts.map +1 -0
- package/dist/types/ai-model/models/jev/image.d.ts +24 -0
- package/dist/types/ai-model/models/jev/image.d.ts.map +1 -0
- package/dist/types/ai-model/models/jev/planning.d.ts +3 -0
- package/dist/types/ai-model/models/jev/planning.d.ts.map +1 -0
- package/dist/types/ai-model/models/registry.d.ts +18 -0
- package/dist/types/ai-model/models/registry.d.ts.map +1 -1
- package/dist/types/ai-model/models/task-routing.d.ts +6 -0
- package/dist/types/ai-model/models/task-routing.d.ts.map +1 -0
- package/dist/types/ai-model/service-caller/call-ai.d.ts.map +1 -1
- package/dist/types/ai-model/service-caller/openai/call-openai.d.ts.map +1 -1
- package/dist/types/ai-model/service-caller/system-one.d.ts +216 -0
- package/dist/types/ai-model/service-caller/system-one.d.ts.map +1 -0
- package/dist/types/ai-model/service-caller/types.d.ts +2 -0
- package/dist/types/ai-model/service-caller/types.d.ts.map +1 -1
- package/dist/types/ai-model/shared/model-locate-result/errors.d.ts +1 -1
- package/dist/types/ai-model/shared/model-locate-result/errors.d.ts.map +1 -1
- package/dist/types/ai-model/workflows/insight/boolean.d.ts +15 -0
- package/dist/types/ai-model/workflows/insight/boolean.d.ts.map +1 -0
- package/dist/types/ai-model/workflows/insight/extraction.d.ts +6 -5
- package/dist/types/ai-model/workflows/insight/extraction.d.ts.map +1 -1
- package/dist/types/ai-model/workflows/planning/types.d.ts +2 -0
- package/dist/types/ai-model/workflows/planning/types.d.ts.map +1 -1
- package/dist/types/device/index.d.ts +7 -7
- package/dist/types/types.d.ts +8 -1
- package/dist/types/types.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -39,7 +39,7 @@ class Insight {
|
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
async aiQuery(demand, options = defaultQueryOptions) {
|
|
42
|
-
const modelRuntime = this.resolveModelRuntime();
|
|
42
|
+
const modelRuntime = this.resolveModelRuntime('extract');
|
|
43
43
|
const executionOptions = this.executionOptions();
|
|
44
44
|
const serviceOptions = this.withContext('aiQuery', options);
|
|
45
45
|
const { output } = executionOptions ? await this.taskExecutor.createTypeQueryExecution('Query', demand, modelRuntime, serviceOptions, void 0, executionOptions) : await this.taskExecutor.createTypeQueryExecution('Query', demand, modelRuntime, serviceOptions);
|
|
@@ -60,7 +60,7 @@ class Insight {
|
|
|
60
60
|
async queryPrimitive(type, apiName, prompt, options) {
|
|
61
61
|
const { textPrompt, multimodalPrompt } = parsePrompt(prompt);
|
|
62
62
|
const serviceOptions = this.withContext(apiName, options);
|
|
63
|
-
const { output } = await this.taskExecutor.createTypeQueryExecution(type, textPrompt, this.resolveModelRuntime(), serviceOptions, multimodalPrompt, this.executionOptions());
|
|
63
|
+
const { output } = await this.taskExecutor.createTypeQueryExecution(type, textPrompt, this.resolveModelRuntime('Boolean' === type ? 'boolean' : 'extract'), serviceOptions, multimodalPrompt, this.executionOptions());
|
|
64
64
|
return output;
|
|
65
65
|
}
|
|
66
66
|
async aiAssert(assertion, message, options) {
|
|
@@ -75,7 +75,7 @@ class Insight {
|
|
|
75
75
|
const { textPrompt, multimodalPrompt } = parsePrompt(assertion);
|
|
76
76
|
const assertionText = 'string' == typeof assertion ? assertion : assertion.prompt;
|
|
77
77
|
try {
|
|
78
|
-
const { output, thought } = await this.taskExecutor.createTypeQueryExecution('Assert', textPrompt, this.resolveModelRuntime(), serviceOptions, multimodalPrompt, this.executionOptions(options, true));
|
|
78
|
+
const { output, thought } = await this.taskExecutor.createTypeQueryExecution('Assert', textPrompt, this.resolveModelRuntime('boolean'), serviceOptions, multimodalPrompt, this.executionOptions(options, true));
|
|
79
79
|
const pass = Boolean(output);
|
|
80
80
|
const failureMessage = pass ? void 0 : `Assertion failed: ${message || assertionText}\nReason: ${thought || '(no_reason)'}`;
|
|
81
81
|
if (options?.keepRawResponse) return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent/insight.mjs","sources":["../../../src/agent/insight.ts"],"sourcesContent":["import type { TUserPrompt } from '@/ai-model/index';\nimport type { ModelRuntime } from '@/ai-model/models';\nimport type {\n AgentAssertResult,\n AssertOptions,\n InsightAPI,\n QueryOptions,\n ServiceExtractParam,\n UIContext,\n} from '@/types';\nimport type { AiApiName } from '@midscene/shared/agent-tools/agent-context';\nimport { TaskExecutionError, type TaskExecutor } from './tasks';\nimport { parsePrompt } from './utils';\n\nconst defaultQueryOptions: QueryOptions = {\n domIncluded: false,\n screenshotIncluded: true,\n};\n\ntype InsightTaskExecutor = Pick<TaskExecutor, 'createTypeQueryExecution'>;\n\ntype InsightContextOptions = { context?: string };\n\n/** Execute read-only AI operations against either live or fixed UI context. */\nexport class Insight implements InsightAPI {\n constructor(\n private readonly taskExecutor: InsightTaskExecutor,\n private readonly resolveModelRuntime: () => ModelRuntime,\n private readonly resolveAgentContext: (\n apiName: AiApiName,\n callContext?: string,\n ) => string | undefined,\n private readonly getUIContext?: () => UIContext,\n ) {}\n\n private resolveContext(\n apiName: AiApiName,\n options?: InsightContextOptions,\n ): string | undefined {\n return this.resolveAgentContext(apiName, options?.context);\n }\n\n private withContext<T extends InsightContextOptions>(\n apiName: AiApiName,\n options: T,\n ): T {\n const resolvedContext = this.resolveContext(apiName, options);\n if (resolvedContext === undefined) {\n return options;\n }\n\n return {\n ...options,\n context: resolvedContext,\n };\n }\n\n private executionOptions(\n options?: AssertOptions,\n includeAbortSignal = false,\n ): { abortSignal?: AbortSignal; uiContext?: UIContext } | undefined {\n const uiContext = this.getUIContext?.();\n if (!uiContext && !includeAbortSignal && !options?.abortSignal) {\n return undefined;\n }\n return {\n ...(includeAbortSignal || options?.abortSignal\n ? { abortSignal: options?.abortSignal }\n : {}),\n ...(uiContext ? { uiContext } : {}),\n };\n }\n\n async aiQuery<ReturnType = any>(\n demand: ServiceExtractParam,\n options: QueryOptions = defaultQueryOptions,\n ): Promise<ReturnType> {\n const modelRuntime = this.resolveModelRuntime();\n const executionOptions = this.executionOptions();\n const serviceOptions = this.withContext('aiQuery', options);\n const { output } = executionOptions\n ? await this.taskExecutor.createTypeQueryExecution(\n 'Query',\n demand,\n modelRuntime,\n serviceOptions,\n undefined,\n executionOptions,\n )\n : await this.taskExecutor.createTypeQueryExecution(\n 'Query',\n demand,\n modelRuntime,\n serviceOptions,\n );\n return output as ReturnType;\n }\n\n async aiBoolean(\n prompt: TUserPrompt,\n options: QueryOptions = defaultQueryOptions,\n ): Promise<boolean> {\n return this.queryPrimitive('Boolean', 'aiBoolean', prompt, options);\n }\n\n async aiNumber(\n prompt: TUserPrompt,\n options: QueryOptions = defaultQueryOptions,\n ): Promise<number> {\n return this.queryPrimitive('Number', 'aiNumber', prompt, options);\n }\n\n async aiString(\n prompt: TUserPrompt,\n options: QueryOptions = defaultQueryOptions,\n ): Promise<string> {\n return this.queryPrimitive('String', 'aiString', prompt, options);\n }\n\n async aiAsk(\n prompt: TUserPrompt,\n options: QueryOptions = defaultQueryOptions,\n ): Promise<string> {\n return this.queryPrimitive('String', 'aiAsk', prompt, options);\n }\n\n private async queryPrimitive<ReturnType>(\n type: 'Boolean' | 'Number' | 'String',\n apiName: 'aiBoolean' | 'aiNumber' | 'aiString' | 'aiAsk',\n prompt: TUserPrompt,\n options: QueryOptions,\n ): Promise<ReturnType> {\n const { textPrompt, multimodalPrompt } = parsePrompt(prompt);\n const serviceOptions = this.withContext(apiName, options);\n const { output } = await this.taskExecutor.createTypeQueryExecution(\n type,\n textPrompt,\n this.resolveModelRuntime(),\n serviceOptions,\n multimodalPrompt,\n this.executionOptions(),\n );\n return output as ReturnType;\n }\n\n async aiAssert(\n assertion: TUserPrompt,\n message?: string,\n options?: AssertOptions,\n ): Promise<AgentAssertResult | undefined> {\n const contextOptions = this.withContext('aiAssert', options ?? {});\n const serviceOptions: QueryOptions = {\n domIncluded: options?.domIncluded ?? defaultQueryOptions.domIncluded,\n screenshotIncluded:\n options?.screenshotIncluded ?? defaultQueryOptions.screenshotIncluded,\n ...(contextOptions.context !== undefined\n ? { context: contextOptions.context }\n : {}),\n };\n const { textPrompt, multimodalPrompt } = parsePrompt(assertion);\n const assertionText =\n typeof assertion === 'string' ? assertion : assertion.prompt;\n\n try {\n const { output, thought } =\n await this.taskExecutor.createTypeQueryExecution<boolean>(\n 'Assert',\n textPrompt,\n this.resolveModelRuntime(),\n serviceOptions,\n multimodalPrompt,\n this.executionOptions(options, true),\n );\n\n const pass = Boolean(output);\n const failureMessage = pass\n ? undefined\n : `Assertion failed: ${message || assertionText}\\nReason: ${thought || '(no_reason)'}`;\n\n if (options?.keepRawResponse) {\n return { pass, thought, message: failureMessage };\n }\n if (!pass) {\n throw new Error(failureMessage);\n }\n } catch (error) {\n if (error instanceof TaskExecutionError) {\n const thought = error.task?.thought;\n const diagnosticMessage =\n error.task?.errorMessage || error.cause.message;\n const reason = thought || diagnosticMessage || '(no_reason)';\n const failureMessage = `Assertion failed: ${message || assertionText}\\nReason: ${reason}`;\n\n if (options?.keepRawResponse) {\n return { pass: false, thought, message: failureMessage };\n }\n throw new Error(failureMessage, { cause: error.cause });\n }\n throw error;\n }\n }\n}\n"],"names":["defaultQueryOptions","Insight","apiName","options","resolvedContext","undefined","includeAbortSignal","uiContext","demand","modelRuntime","executionOptions","serviceOptions","output","prompt","type","textPrompt","multimodalPrompt","parsePrompt","assertion","message","contextOptions","assertionText","thought","pass","Boolean","failureMessage","Error","error","TaskExecutionError","diagnosticMessage","reason","taskExecutor","resolveModelRuntime","resolveAgentContext","getUIContext"],"mappings":";;;;;;;;;;;;AAcA,MAAMA,sBAAoC;IAC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mB,IACxBJ,gBACAK,kBACA,IAAI,CAAC,gBAAgB,CAACb,SAAS;YAGnC,MAAMoB,OAAOC,QAAQZ;YACrB,MAAMa,iBAAiBF,OACnBlB,SACA,CAAC,kBAAkB,EAAEc,WAAWE,cAAc,UAAU,EAAEC,WAAW,eAAe;YAExF,IAAInB,SAAS,iBACX,OAAO;gBAAEoB;gBAAMD;gBAAS,SAASG;YAAe;YAElD,IAAI,CAACF,MACH,MAAM,IAAIG,MAAMD;QAEpB,EAAE,OAAOE,OAAO;YACd,IAAIA,iBAAiBC,oBAAoB;gBACvC,MAAMN,UAAUK,MAAM,IAAI,EAAE;gBAC5B,MAAME,oBACJF,MAAM,IAAI,EAAE,gBAAgBA,MAAM,KAAK,CAAC,OAAO;gBACjD,MAAMG,SAASR,WAAWO,qBAAqB;gBAC/C,MAAMJ,iBAAiB,CAAC,kBAAkB,EAAEN,WAAWE,cAAc,UAAU,EAAES,QAAQ;gBAEzF,IAAI3B,SAAS,iBACX,OAAO;oBAAE,MAAM;oBAAOmB;oBAAS,SAASG;gBAAe;gBAEzD,MAAM,IAAIC,MAAMD,gBAAgB;oBAAE,OAAOE,MAAM,KAAK;gBAAC;YACvD;YACA,MAAMA;QACR;IACF;IA/KA,YACmBI,YAAiC,EACjCC,mBAAuC,EACvCC,mBAGM,EACNC,YAA8B,CAC/C;;;;;aAPiBH,YAAY,GAAZA;aACAC,mBAAmB,GAAnBA;aACAC,mBAAmB,GAAnBA;aAIAC,YAAY,GAAZA;IAChB;AAwKL"}
|
|
1
|
+
{"version":3,"file":"agent/insight.mjs","sources":["../../../src/agent/insight.ts"],"sourcesContent":["import type { TUserPrompt } from '@/ai-model/index';\nimport type { ModelTask } from '@/ai-model/model-adapter/types';\nimport type { ModelRuntime } from '@/ai-model/models';\nimport type {\n AgentAssertResult,\n AssertOptions,\n InsightAPI,\n QueryOptions,\n ServiceExtractParam,\n UIContext,\n} from '@/types';\nimport type { AiApiName } from '@midscene/shared/agent-tools/agent-context';\nimport { TaskExecutionError, type TaskExecutor } from './tasks';\nimport { parsePrompt } from './utils';\n\nconst defaultQueryOptions: QueryOptions = {\n domIncluded: false,\n screenshotIncluded: true,\n};\n\ntype InsightTaskExecutor = Pick<TaskExecutor, 'createTypeQueryExecution'>;\n\ntype InsightContextOptions = { context?: string };\n\n/** Execute read-only AI operations against either live or fixed UI context. */\nexport class Insight implements InsightAPI {\n constructor(\n private readonly taskExecutor: InsightTaskExecutor,\n private readonly resolveModelRuntime: (task?: ModelTask) => ModelRuntime,\n private readonly resolveAgentContext: (\n apiName: AiApiName,\n callContext?: string,\n ) => string | undefined,\n private readonly getUIContext?: () => UIContext,\n ) {}\n\n private resolveContext(\n apiName: AiApiName,\n options?: InsightContextOptions,\n ): string | undefined {\n return this.resolveAgentContext(apiName, options?.context);\n }\n\n private withContext<T extends InsightContextOptions>(\n apiName: AiApiName,\n options: T,\n ): T {\n const resolvedContext = this.resolveContext(apiName, options);\n if (resolvedContext === undefined) {\n return options;\n }\n\n return {\n ...options,\n context: resolvedContext,\n };\n }\n\n private executionOptions(\n options?: AssertOptions,\n includeAbortSignal = false,\n ): { abortSignal?: AbortSignal; uiContext?: UIContext } | undefined {\n const uiContext = this.getUIContext?.();\n if (!uiContext && !includeAbortSignal && !options?.abortSignal) {\n return undefined;\n }\n return {\n ...(includeAbortSignal || options?.abortSignal\n ? { abortSignal: options?.abortSignal }\n : {}),\n ...(uiContext ? { uiContext } : {}),\n };\n }\n\n async aiQuery<ReturnType = any>(\n demand: ServiceExtractParam,\n options: QueryOptions = defaultQueryOptions,\n ): Promise<ReturnType> {\n const modelRuntime = this.resolveModelRuntime('extract');\n const executionOptions = this.executionOptions();\n const serviceOptions = this.withContext('aiQuery', options);\n const { output } = executionOptions\n ? await this.taskExecutor.createTypeQueryExecution(\n 'Query',\n demand,\n modelRuntime,\n serviceOptions,\n undefined,\n executionOptions,\n )\n : await this.taskExecutor.createTypeQueryExecution(\n 'Query',\n demand,\n modelRuntime,\n serviceOptions,\n );\n return output as ReturnType;\n }\n\n async aiBoolean(\n prompt: TUserPrompt,\n options: QueryOptions = defaultQueryOptions,\n ): Promise<boolean> {\n return this.queryPrimitive('Boolean', 'aiBoolean', prompt, options);\n }\n\n async aiNumber(\n prompt: TUserPrompt,\n options: QueryOptions = defaultQueryOptions,\n ): Promise<number> {\n return this.queryPrimitive('Number', 'aiNumber', prompt, options);\n }\n\n async aiString(\n prompt: TUserPrompt,\n options: QueryOptions = defaultQueryOptions,\n ): Promise<string> {\n return this.queryPrimitive('String', 'aiString', prompt, options);\n }\n\n async aiAsk(\n prompt: TUserPrompt,\n options: QueryOptions = defaultQueryOptions,\n ): Promise<string> {\n return this.queryPrimitive('String', 'aiAsk', prompt, options);\n }\n\n private async queryPrimitive<ReturnType>(\n type: 'Boolean' | 'Number' | 'String',\n apiName: 'aiBoolean' | 'aiNumber' | 'aiString' | 'aiAsk',\n prompt: TUserPrompt,\n options: QueryOptions,\n ): Promise<ReturnType> {\n const { textPrompt, multimodalPrompt } = parsePrompt(prompt);\n const serviceOptions = this.withContext(apiName, options);\n const { output } = await this.taskExecutor.createTypeQueryExecution(\n type,\n textPrompt,\n this.resolveModelRuntime(type === 'Boolean' ? 'boolean' : 'extract'),\n serviceOptions,\n multimodalPrompt,\n this.executionOptions(),\n );\n return output as ReturnType;\n }\n\n async aiAssert(\n assertion: TUserPrompt,\n message?: string,\n options?: AssertOptions,\n ): Promise<AgentAssertResult | undefined> {\n const contextOptions = this.withContext('aiAssert', options ?? {});\n const serviceOptions: QueryOptions = {\n domIncluded: options?.domIncluded ?? defaultQueryOptions.domIncluded,\n screenshotIncluded:\n options?.screenshotIncluded ?? defaultQueryOptions.screenshotIncluded,\n ...(contextOptions.context !== undefined\n ? { context: contextOptions.context }\n : {}),\n };\n const { textPrompt, multimodalPrompt } = parsePrompt(assertion);\n const assertionText =\n typeof assertion === 'string' ? assertion : assertion.prompt;\n\n try {\n const { output, thought } =\n await this.taskExecutor.createTypeQueryExecution<boolean>(\n 'Assert',\n textPrompt,\n this.resolveModelRuntime('boolean'),\n serviceOptions,\n multimodalPrompt,\n this.executionOptions(options, true),\n );\n\n const pass = Boolean(output);\n const failureMessage = pass\n ? undefined\n : `Assertion failed: ${message || assertionText}\\nReason: ${thought || '(no_reason)'}`;\n\n if (options?.keepRawResponse) {\n return { pass, thought, message: failureMessage };\n }\n if (!pass) {\n throw new Error(failureMessage);\n }\n } catch (error) {\n if (error instanceof TaskExecutionError) {\n const thought = error.task?.thought;\n const diagnosticMessage =\n error.task?.errorMessage || error.cause.message;\n const reason = thought || diagnosticMessage || '(no_reason)';\n const failureMessage = `Assertion failed: ${message || assertionText}\\nReason: ${reason}`;\n\n if (options?.keepRawResponse) {\n return { pass: false, thought, message: failureMessage };\n }\n throw new Error(failureMessage, { cause: error.cause });\n }\n throw error;\n }\n }\n}\n"],"names":["defaultQueryOptions","Insight","apiName","options","resolvedContext","undefined","includeAbortSignal","uiContext","demand","modelRuntime","executionOptions","serviceOptions","output","prompt","type","textPrompt","multimodalPrompt","parsePrompt","assertion","message","contextOptions","assertionText","thought","pass","Boolean","failureMessage","Error","error","TaskExecutionError","diagnosticMessage","reason","taskExecutor","resolveModelRuntime","resolveAgentContext","getUIContext"],"mappings":";;;;;;;;;;;;AAeA,MAAMA,sBAAoC;IACxC,aAAa;IACb,oBAAoB;AACtB;AAOO,MAAMC;IAWH,eACNC,OAAkB,EAClBC,OAA+B,EACX;QACpB,OAAO,IAAI,CAAC,mBAAmB,CAACD,SAASC,SAAS;IACpD;IAEQ,YACND,OAAkB,EAClBC,OAAU,EACP;QACH,MAAMC,kBAAkB,IAAI,CAAC,cAAc,CAACF,SAASC;QACrD,IAAIC,AAAoBC,WAApBD,iBACF,OAAOD;QAGT,OAAO;YACL,GAAGA,OAAO;YACV,SAASC;QACX;IACF;IAEQ,iBACND,OAAuB,EACvBG,qBAAqB,KAAK,EACwC;QAClE,MAAMC,YAAY,IAAI,CAAC,YAAY;QACnC,IAAI,CAACA,aAAa,CAACD,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AE;gBAC5B,MAAME,oBACJF,MAAM,IAAI,EAAE,gBAAgBA,MAAM,KAAK,CAAC,OAAO;gBACjD,MAAMG,SAASR,WAAWO,qBAAqB;gBAC/C,MAAMJ,iBAAiB,CAAC,kBAAkB,EAAEN,WAAWE,cAAc,UAAU,EAAES,QAAQ;gBAEzF,IAAI3B,SAAS,iBACX,OAAO;oBAAE,MAAM;oBAAOmB;oBAAS,SAASG;gBAAe;gBAEzD,MAAM,IAAIC,MAAMD,gBAAgB;oBAAE,OAAOE,MAAM,KAAK;gBAAC;YACvD;YACA,MAAMA;QACR;IACF;IA/KA,YACmBI,YAAiC,EACjCC,mBAAuD,EACvDC,mBAGM,EACNC,YAA8B,CAC/C;;;;;aAPiBH,YAAY,GAAZA;aACAC,mBAAmB,GAAnBA;aACAC,mBAAmB,GAAnBA;aAIAC,YAAY,GAAZA;IAChB;AAwKL"}
|
|
@@ -49,13 +49,13 @@ function locatePlanForLocate(param) {
|
|
|
49
49
|
return locatePlan;
|
|
50
50
|
}
|
|
51
51
|
class TaskBuilder {
|
|
52
|
-
async build(plans, planningModel,
|
|
52
|
+
async build(plans, planningModel, locateModel, options) {
|
|
53
53
|
const tasks = [];
|
|
54
54
|
const cacheable = options?.cacheable;
|
|
55
55
|
const context = {
|
|
56
56
|
tasks,
|
|
57
57
|
planningModel,
|
|
58
|
-
|
|
58
|
+
locateModel,
|
|
59
59
|
cacheable,
|
|
60
60
|
multimodalPrompt: options?.multimodalPrompt,
|
|
61
61
|
deepLocate: options?.deepLocate,
|
|
@@ -209,7 +209,7 @@ class TaskBuilder {
|
|
|
209
209
|
context.tasks.push(task);
|
|
210
210
|
}
|
|
211
211
|
createLocateTask(plan, detailedLocateParam, context, onResult) {
|
|
212
|
-
const { cacheable,
|
|
212
|
+
const { cacheable, locateModel, deepLocate } = context;
|
|
213
213
|
let locateParam = normalizeLocateParam(detailedLocateParam);
|
|
214
214
|
if (context.multimodalPrompt?.images?.length && locateParam.prompt && !userPromptToMultimodalPrompt(locateParam.prompt)?.images?.length) locateParam = {
|
|
215
215
|
...locateParam,
|
|
@@ -256,9 +256,9 @@ class TaskBuilder {
|
|
|
256
256
|
rawAssistantOutput: dump.taskInfo?.rawAssistantOutput,
|
|
257
257
|
searchAreaRawChoiceMessage: dump.taskInfo?.searchAreaRawChoiceMessage
|
|
258
258
|
};
|
|
259
|
-
task.usage = withUsageIntent(dump.taskInfo?.usage, '
|
|
259
|
+
task.usage = withUsageIntent(dump.taskInfo?.usage, 'locate');
|
|
260
260
|
task.searchArea = dump.taskInfo?.searchArea;
|
|
261
|
-
if (dump.taskInfo?.searchAreaUsage) task.searchAreaUsage = withUsageIntent(dump.taskInfo.searchAreaUsage, '
|
|
261
|
+
if (dump.taskInfo?.searchAreaUsage) task.searchAreaUsage = withUsageIntent(dump.taskInfo.searchAreaUsage, 'locate');
|
|
262
262
|
if (dump.taskInfo?.reasoning_content) task.reasoning_content = dump.taskInfo.reasoning_content;
|
|
263
263
|
};
|
|
264
264
|
const planLocatedElement = paramWithLocatedPixelResult ? matchElementFromPlan(paramWithLocatedPixelResult) : void 0;
|
|
@@ -297,7 +297,7 @@ class TaskBuilder {
|
|
|
297
297
|
locateResult = await this.service.locate(locateParam, {
|
|
298
298
|
context: uiContext,
|
|
299
299
|
planLocatedElement
|
|
300
|
-
},
|
|
300
|
+
}, locateModel, abortSignal);
|
|
301
301
|
applyDump(locateResult.dump);
|
|
302
302
|
elementFromAiLocate = locateResult.element;
|
|
303
303
|
} catch (error) {
|
|
@@ -321,9 +321,13 @@ class TaskBuilder {
|
|
|
321
321
|
Math.round(element.center[0] / shrunkShotToLogicalRatio),
|
|
322
322
|
Math.round(element.center[1] / shrunkShotToLogicalRatio)
|
|
323
323
|
];
|
|
324
|
+
const defaultModel = this.getDefaultModelRuntime();
|
|
324
325
|
const feature = await this.interface.cacheFeatureForPoint(pointForCache, {
|
|
325
326
|
targetDescription: 'string' == typeof locateParam.prompt ? locateParam.prompt : locateParam.prompt?.prompt,
|
|
326
|
-
modelRuntime:
|
|
327
|
+
modelRuntime: {
|
|
328
|
+
...defaultModel,
|
|
329
|
+
executionId: locateModel.executionId
|
|
330
|
+
}
|
|
327
331
|
});
|
|
328
332
|
if (hasNonEmptyCache(feature)) {
|
|
329
333
|
debug('update cache, prompt: %s, cache: %o', cachePrompt, feature);
|
|
@@ -385,14 +389,16 @@ class TaskBuilder {
|
|
|
385
389
|
};
|
|
386
390
|
return taskLocator;
|
|
387
391
|
}
|
|
388
|
-
constructor({ interfaceInstance, service, taskCache, actionSpace, waitAfterAction, actionReadiness, operationResource }){
|
|
392
|
+
constructor({ getDefaultModelRuntime, interfaceInstance, service, taskCache, actionSpace, waitAfterAction, actionReadiness, operationResource }){
|
|
389
393
|
_define_property(this, "interface", void 0);
|
|
390
394
|
_define_property(this, "service", void 0);
|
|
395
|
+
_define_property(this, "getDefaultModelRuntime", void 0);
|
|
391
396
|
_define_property(this, "taskCache", void 0);
|
|
392
397
|
_define_property(this, "actionSpace", void 0);
|
|
393
398
|
_define_property(this, "waitAfterAction", void 0);
|
|
394
399
|
_define_property(this, "actionReadiness", void 0);
|
|
395
400
|
_define_property(this, "operationResource", void 0);
|
|
401
|
+
this.getDefaultModelRuntime = getDefaultModelRuntime;
|
|
396
402
|
this.interface = interfaceInstance;
|
|
397
403
|
this.service = service;
|
|
398
404
|
this.taskCache = taskCache;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent/task-builder.mjs","sources":["../../../src/agent/task-builder.ts"],"sourcesContent":["import { findAllMidsceneLocatorField, parseActionParam } from '@/ai-model';\nimport type { ModelRuntime } from '@/ai-model/models';\nimport {\n type TMultimodalPrompt,\n findActionInActionSpaceOrThrow,\n userPromptToMultimodalPrompt,\n userPromptToString,\n validateRequiredLocateFields,\n} from '@/common';\nimport { type AbstractInterface, defineActionSleep } from '@/device';\nimport type Service from '@/service';\nimport { setTimingFieldOnce } from '@/task-timing';\nimport type {\n AIUsageInfo,\n DetailedLocateParam,\n DeviceAction,\n ElementCacheFeature,\n ExecutionTaskActionApply,\n ExecutionTaskApply,\n ExecutionTaskHitBy,\n ExecutionTaskPlanningLocateApply,\n LocateResultElement,\n LocateResultWithDump,\n PlanningAction,\n Rect,\n ServiceDump,\n} from '@/types';\nimport { ServiceError } from '@/types';\nimport { getDebug } from '@midscene/shared/logger';\nimport { assert } from '@midscene/shared/utils';\nimport type { ActionReadiness } from './action-readiness';\nimport type { TaskCache } from './task-cache';\nimport { withUsageIntent } from './usage-intent';\nimport {\n ifLocateParamHasLocatedPixelResult,\n matchElementFromCache,\n matchElementFromPlan,\n transformLogicalElementToScreenshot,\n} from './utils';\n\nconst debug = getDebug('agent:task-builder');\n\n/**\n * Check if a cache object is non-empty\n */\nfunction hasNonEmptyCache(cache: unknown): boolean {\n return (\n cache !== null &&\n cache !== undefined &&\n typeof cache === 'object' &&\n Object.keys(cache).length > 0\n );\n}\n\nfunction invalidLocateElementReason(\n element: LocateResultElement,\n): string | undefined {\n const values = [element.center?.[0], element.center?.[1]];\n if (\n element.center?.length !== 2 ||\n values.some((value) => typeof value !== 'number' || !Number.isFinite(value))\n ) {\n return `Invalid locate result coordinates: ${JSON.stringify(element)}`;\n }\n return undefined;\n}\n\ntype LocateParamWithDeprecatedAlias = DetailedLocateParam & {\n deepThink?: boolean;\n};\n\nfunction normalizeLocateParam(\n param: string | DetailedLocateParam,\n): DetailedLocateParam {\n if (typeof param === 'string') {\n return { prompt: param };\n }\n\n const { deepThink, ...rest } = param as LocateParamWithDeprecatedAlias;\n const deepLocate = rest.deepLocate ?? deepThink;\n\n return deepLocate === undefined ? rest : { ...rest, deepLocate };\n}\n\nexport function locatePlanForLocate(param: string | DetailedLocateParam) {\n const locate = normalizeLocateParam(param);\n const locatePlan: PlanningAction<DetailedLocateParam> = {\n type: 'Locate',\n param: locate,\n thought: '',\n };\n return locatePlan;\n}\n\ninterface TaskBuilderDeps {\n interfaceInstance: AbstractInterface;\n service: Service;\n taskCache?: TaskCache;\n actionSpace: DeviceAction[];\n waitAfterAction?: number;\n actionReadiness?: ActionReadiness;\n operationResource?: object;\n}\n\ninterface BuildOptions {\n cacheable?: boolean;\n multimodalPrompt?: TMultimodalPrompt;\n deepLocate?: boolean;\n abortSignal?: AbortSignal;\n}\n\ninterface PlanBuildContext {\n tasks: ExecutionTaskApply[];\n planningModel: ModelRuntime;\n defaultModel: ModelRuntime;\n cacheable?: boolean;\n multimodalPrompt?: TMultimodalPrompt;\n deepLocate?: boolean;\n abortSignal?: AbortSignal;\n}\n\nexport class TaskBuilder {\n private readonly interface: AbstractInterface;\n\n private readonly service: Service;\n\n private readonly taskCache?: TaskCache;\n\n private readonly actionSpace: DeviceAction[];\n\n private readonly waitAfterAction?: number;\n private readonly actionReadiness?: ActionReadiness;\n private readonly operationResource: object;\n\n constructor({\n interfaceInstance,\n service,\n taskCache,\n actionSpace,\n waitAfterAction,\n actionReadiness,\n operationResource,\n }: TaskBuilderDeps) {\n this.interface = interfaceInstance;\n this.service = service;\n this.taskCache = taskCache;\n this.actionSpace = actionSpace;\n this.waitAfterAction = waitAfterAction;\n this.actionReadiness = actionReadiness;\n this.operationResource = operationResource ?? interfaceInstance;\n }\n\n public async build(\n plans: PlanningAction[],\n planningModel: ModelRuntime,\n defaultModel: ModelRuntime,\n options?: BuildOptions,\n ): Promise<{ tasks: ExecutionTaskApply[] }> {\n const tasks: ExecutionTaskApply[] = [];\n const cacheable = options?.cacheable;\n\n const context: PlanBuildContext = {\n tasks,\n planningModel,\n defaultModel,\n cacheable,\n multimodalPrompt: options?.multimodalPrompt,\n deepLocate: options?.deepLocate,\n abortSignal: options?.abortSignal,\n };\n\n type PlanHandler = (plan: PlanningAction) => Promise<void> | void;\n\n const planHandlers = new Map<string, PlanHandler>([\n [\n 'Locate',\n (plan) =>\n this.handleLocatePlan(\n plan as PlanningAction<DetailedLocateParam>,\n context,\n ),\n ],\n ['Finished', (plan) => this.handleFinishedPlan(plan, context)],\n ]);\n\n const defaultHandler: PlanHandler = (plan) =>\n this.handleActionPlan(plan, context);\n\n for (const plan of plans) {\n context.abortSignal?.throwIfAborted();\n const handler = planHandlers.get(plan.type) ?? defaultHandler;\n await handler(plan);\n }\n\n return {\n tasks,\n };\n }\n\n private handleFinishedPlan(\n plan: PlanningAction,\n context: PlanBuildContext,\n ): void {\n const taskActionFinished: ExecutionTaskActionApply<null> = {\n type: 'Action Space',\n subType: 'Finished',\n param: null,\n thought: plan.thought,\n executor: async () => {},\n };\n context.tasks.push(taskActionFinished);\n }\n\n private async handleLocatePlan(\n plan: PlanningAction<DetailedLocateParam>,\n context: PlanBuildContext,\n ): Promise<void> {\n const taskLocate = this.createLocateTask(plan, plan.param, context);\n context.tasks.push(taskLocate);\n }\n\n private async handleActionPlan(\n plan: PlanningAction,\n context: PlanBuildContext,\n ): Promise<void> {\n const planType = plan.type;\n const actionSpace = this.actionSpace;\n const action = findActionInActionSpaceOrThrow(planType, actionSpace);\n const param = plan.param;\n\n const locateFields = findAllMidsceneLocatorField(action.paramSchema);\n\n validateRequiredLocateFields(param, action.paramSchema);\n\n locateFields.forEach((field) => {\n if (param?.[field]) {\n // Always use createLocateTask for all locate params.\n // This ensures cache writing happens even when locatedPixelResult is available\n const locatePlan = locatePlanForLocate(param[field]);\n debug(\n 'will prepend locate param for field',\n `action.type=${planType}`,\n `param=${JSON.stringify(param[field])}`,\n `locatePlan=${JSON.stringify(locatePlan)}`,\n `hasLocatedPixelResult=${ifLocateParamHasLocatedPixelResult(param[field])}`,\n );\n const locateTask = this.createLocateTask(\n locatePlan,\n param[field],\n context,\n (result) => {\n param[field] = result;\n },\n );\n context.tasks.push(locateTask);\n } else {\n debug(`field '${field}' is not provided for action ${planType}`);\n }\n });\n\n const task: ExecutionTaskApply<\n 'Action Space',\n any,\n { success: boolean; action: string; param: any },\n void\n > = {\n type: 'Action Space',\n subType: planType,\n thought: plan.thought,\n param: plan.param,\n planningFeedbackMaxLength: action.planningFeedbackMaxLength,\n executor: async (taskContext) => {\n const abortSignal = context.abortSignal ?? taskContext.signal;\n const timing = taskContext.task.timing;\n\n debug(\n 'executing action',\n planType,\n param,\n `taskContext.element.center: ${taskContext.element?.center}`,\n );\n\n const uiContext = taskContext.uiContext;\n assert(uiContext, 'uiContext is required for Action task');\n\n validateRequiredLocateFields(param, action.paramSchema);\n\n const { shrunkShotToLogicalRatio } = uiContext;\n if (shrunkShotToLogicalRatio === undefined) {\n throw new Error(\n 'shrunkShotToLogicalRatio is not defined in Action task',\n );\n }\n const parsedParam = (() => {\n if (!action.paramSchema) return param;\n try {\n return parseActionParam(param, action.paramSchema, {\n shrunkShotToLogicalRatio,\n });\n } catch (error: any) {\n throw new Error(\n `Invalid parameters for action ${action.name}: ${error.message}\\nParameters: ${JSON.stringify(param)}`,\n { cause: error },\n );\n }\n })();\n\n const useDefaultWait = !this.actionReadiness;\n taskContext.task.actionReadiness = useDefaultWait\n ? 'default'\n : 'custom';\n abortSignal?.throwIfAborted();\n\n setTimingFieldOnce(timing, 'beforeInvokeActionHookStart');\n const delayBeforeRunner = useDefaultWait\n ? (action.delayBeforeRunner ?? 200)\n : 0;\n try {\n const preparation = await Promise.allSettled([\n this.interface.beforeInvokeAction?.(\n action.name,\n param,\n abortSignal,\n ),\n delayBeforeRunner > 0\n ? defineActionSleep(abortSignal).call({\n timeMs: delayBeforeRunner,\n })\n : Promise.resolve(),\n ]);\n const rejected = preparation.find(\n (item) => item.status === 'rejected',\n );\n if (rejected?.status === 'rejected') throw rejected.reason;\n } catch (originalError: any) {\n throw new Error(\n `error in running beforeInvokeAction for ${action.name}: ${originalError?.message || String(originalError)}`,\n { cause: originalError },\n );\n } finally {\n setTimingFieldOnce(timing, 'beforeInvokeActionHookEnd');\n }\n\n abortSignal?.throwIfAborted();\n setTimingFieldOnce(timing, 'callActionStart');\n debug('calling action', action.name);\n const actionResult = await action.call.call(\n this.interface,\n parsedParam,\n useDefaultWait\n ? { ...taskContext, signal: abortSignal }\n : { ...taskContext, signal: abortSignal, skipDefaultWait: true },\n );\n setTimingFieldOnce(timing, 'callActionEnd');\n debug('called action', action.name, 'result:', actionResult);\n abortSignal?.throwIfAborted();\n\n setTimingFieldOnce(timing, 'afterInvokeActionHookStart');\n setTimingFieldOnce(timing, 'waitForActionReadyStart');\n try {\n if (useDefaultWait) {\n const delayAfterRunner =\n action.delayAfterRunner ?? this.waitAfterAction ?? 300;\n if (delayAfterRunner > 0)\n await defineActionSleep(abortSignal).call({\n timeMs: delayAfterRunner,\n });\n await this.interface.defaultActionWait?.(\n action.name,\n parsedParam,\n abortSignal,\n );\n } else {\n await this.actionReadiness!.wait(\n {\n id: taskContext.task.taskId,\n name: action.name,\n param: parsedParam,\n },\n abortSignal,\n this.operationResource,\n );\n }\n } finally {\n setTimingFieldOnce(timing, 'waitForActionReadyEnd');\n }\n abortSignal?.throwIfAborted();\n try {\n await this.interface.afterInvokeAction?.(\n action.name,\n parsedParam,\n abortSignal,\n );\n } catch (originalError: any) {\n throw new Error(\n `error in running afterInvokeAction for ${action.name}: ${originalError?.message || String(originalError)}`,\n { cause: originalError },\n );\n } finally {\n setTimingFieldOnce(timing, 'afterInvokeActionHookEnd');\n }\n return { output: actionResult };\n },\n };\n\n context.tasks.push(task);\n }\n\n private createLocateTask(\n plan: PlanningAction<DetailedLocateParam>,\n detailedLocateParam: DetailedLocateParam | string,\n context: PlanBuildContext,\n onResult?: (result: LocateResultElement) => void,\n ): ExecutionTaskPlanningLocateApply {\n const { cacheable, defaultModel, deepLocate } = context;\n\n let locateParam = normalizeLocateParam(detailedLocateParam);\n\n // Planning produces text locators; carry the user's reference images into\n // independent grounding calls while preserving explicit locator images.\n if (\n context.multimodalPrompt?.images?.length &&\n locateParam.prompt &&\n !userPromptToMultimodalPrompt(locateParam.prompt)?.images?.length\n ) {\n locateParam = {\n ...locateParam,\n prompt: {\n ...context.multimodalPrompt,\n prompt: userPromptToString(locateParam.prompt),\n },\n };\n }\n\n if (cacheable !== undefined) {\n locateParam = {\n ...locateParam,\n cacheable,\n };\n }\n\n if (deepLocate && !locateParam.deepLocate) {\n locateParam = {\n ...locateParam,\n deepLocate: true,\n };\n }\n\n const taskLocator: ExecutionTaskPlanningLocateApply = {\n type: 'Planning',\n subType: 'Locate',\n param: locateParam,\n thought: plan.thought,\n executor: async (taskContext) => {\n const abortSignal = context.abortSignal ?? taskContext.signal;\n abortSignal?.throwIfAborted();\n const { task } = taskContext;\n let { uiContext } = taskContext;\n const paramWithLocatedPixelResult = ifLocateParamHasLocatedPixelResult(\n locateParam,\n )\n ? locateParam\n : undefined;\n\n assert(\n locateParam?.prompt || paramWithLocatedPixelResult,\n `No prompt or id or position or locatedPixelResult to locate, param=${JSON.stringify(\n locateParam,\n )}`,\n );\n\n if (!uiContext) {\n uiContext = await this.service.contextRetrieverFn(abortSignal);\n abortSignal?.throwIfAborted();\n }\n\n assert(uiContext, 'uiContext is required for Service task');\n\n const { shrunkShotToLogicalRatio } = uiContext;\n\n if (shrunkShotToLogicalRatio === undefined) {\n throw new Error(\n 'shrunkShotToLogicalRatio is not defined in locate task',\n );\n }\n\n let locateDump: ServiceDump | undefined;\n let locateResult: LocateResultWithDump | undefined;\n\n const applyDump = (dump?: ServiceDump) => {\n if (!dump) {\n return;\n }\n locateDump = dump;\n task.log = {\n dump,\n rawResponse: dump.taskInfo?.rawResponse,\n rawAssistantOutput: dump.taskInfo?.rawAssistantOutput,\n searchAreaRawChoiceMessage:\n dump.taskInfo?.searchAreaRawChoiceMessage,\n };\n task.usage = withUsageIntent(dump.taskInfo?.usage, 'default');\n task.searchArea = dump.taskInfo?.searchArea;\n if (dump.taskInfo?.searchAreaUsage) {\n // The deepLocate search-area call belongs to the same locate task,\n // so it shares the companion usage intent.\n task.searchAreaUsage = withUsageIntent(\n dump.taskInfo.searchAreaUsage,\n 'default',\n );\n }\n if (dump.taskInfo?.reasoning_content) {\n task.reasoning_content = dump.taskInfo.reasoning_content;\n }\n };\n\n const planLocatedElement = paramWithLocatedPixelResult\n ? matchElementFromPlan(paramWithLocatedPixelResult)\n : undefined;\n\n // from locatedPixelResult (direct plan hit)\n // when deepLocate is enabled, locatedPixelResult should be used as search\n // area hint, not as a final direct hit\n const elementFromPlan = locateParam.deepLocate\n ? undefined\n : planLocatedElement;\n const isPlanDirectHit = !!elementFromPlan;\n\n // from xpath\n let rectFromXpath: Rect | undefined;\n if (\n !isPlanDirectHit &&\n locateParam.xpath &&\n this.interface.rectMatchesCacheFeature\n ) {\n try {\n rectFromXpath = await this.interface.rectMatchesCacheFeature({\n xpaths: [locateParam.xpath],\n });\n } catch {\n // xpath locate failed, allow fallback to cache or AI locate\n }\n }\n\n const elementFromXpath = rectFromXpath\n ? transformLogicalElementToScreenshot(\n {\n center: [\n rectFromXpath.left + rectFromXpath.width / 2,\n rectFromXpath.top + rectFromXpath.height / 2,\n ],\n description:\n typeof locateParam.prompt === 'string'\n ? locateParam.prompt\n : locateParam.prompt?.prompt || '',\n rect: rectFromXpath,\n },\n shrunkShotToLogicalRatio,\n )\n : undefined;\n\n const isXpathHit = !!elementFromXpath;\n\n const cachePrompt = locateParam.prompt;\n const locateCacheRecord = this.taskCache?.matchLocateCache(cachePrompt);\n const cacheEntry = locateCacheRecord?.cacheContent?.cache;\n\n const elementFromCacheResult =\n isPlanDirectHit || isXpathHit\n ? null\n : await matchElementFromCache(\n {\n taskCache: this.taskCache,\n interfaceInstance: this.interface,\n },\n cacheEntry,\n cachePrompt,\n locateParam.cacheable,\n );\n\n // elementFromCacheResult is in logical coordinates, which should be transformed to screenshot coordinates;\n const elementFromCache = elementFromCacheResult\n ? transformLogicalElementToScreenshot(\n elementFromCacheResult,\n shrunkShotToLogicalRatio,\n )\n : undefined;\n\n const isCacheHit = !!elementFromCache;\n\n let elementFromAiLocate: LocateResultElement | null | undefined;\n const timing = taskContext.task.timing;\n if (!isXpathHit && !isCacheHit && !isPlanDirectHit) {\n try {\n setTimingFieldOnce(timing, 'callAiStart');\n locateResult = await this.service.locate(\n locateParam,\n {\n context: uiContext,\n planLocatedElement,\n },\n defaultModel,\n abortSignal,\n );\n applyDump(locateResult.dump);\n elementFromAiLocate = locateResult.element;\n } catch (error) {\n if (error instanceof ServiceError) {\n applyDump(error.dump);\n }\n throw error;\n } finally {\n setTimingFieldOnce(timing, 'callAiEnd');\n }\n }\n\n const element =\n elementFromPlan ||\n elementFromXpath ||\n elementFromCache ||\n elementFromAiLocate;\n\n if (element) {\n const invalidElementReason = invalidLocateElementReason(element);\n if (invalidElementReason) {\n if (locateDump) {\n throw new ServiceError(invalidElementReason, locateDump);\n }\n throw new Error(invalidElementReason);\n }\n }\n\n // Check if locate cache already exists (for planHitFlag case)\n const locateCacheAlreadyExists = hasNonEmptyCache(\n locateCacheRecord?.cacheContent?.cache,\n );\n\n let currentCacheEntry: ElementCacheFeature | undefined;\n // Write cache if:\n // 1. element found\n // 2. taskCache enabled\n // 3. not a cache hit (otherwise we'd be writing what we just read)\n // 4. not already cached for plan hit case (avoid redundant writes), OR allow update if cache validation failed\n // 5. cacheable is not explicitly false\n if (\n element &&\n this.taskCache &&\n !isCacheHit &&\n (!isPlanDirectHit || !locateCacheAlreadyExists) &&\n locateParam.cacheable !== false\n ) {\n if (this.interface.cacheFeatureForPoint) {\n try {\n // Transform coordinates to logical space for cacheFeatureForPoint\n // cacheFeatureForPoint needs logical coordinates to locate elements in DOM\n const pointForCache: [number, number] = [\n Math.round(element.center[0] / shrunkShotToLogicalRatio),\n Math.round(element.center[1] / shrunkShotToLogicalRatio),\n ];\n\n const feature = await this.interface.cacheFeatureForPoint(\n pointForCache,\n {\n targetDescription:\n typeof locateParam.prompt === 'string'\n ? locateParam.prompt\n : locateParam.prompt?.prompt,\n modelRuntime: defaultModel,\n },\n );\n if (hasNonEmptyCache(feature)) {\n debug(\n 'update cache, prompt: %s, cache: %o',\n cachePrompt,\n feature,\n );\n currentCacheEntry = feature;\n this.taskCache.updateOrAppendCacheRecord(\n {\n type: 'locate',\n prompt: cachePrompt,\n cache: feature,\n },\n locateCacheRecord,\n );\n } else {\n debug(\n 'no cache data returned, skip cache update, prompt: %s',\n cachePrompt,\n );\n }\n } catch (error) {\n debug('cacheFeatureForPoint failed: %s', error);\n }\n } else {\n debug('cacheFeatureForPoint is not supported, skip cache update');\n }\n }\n\n if (!element) {\n if (locateDump) {\n throw new ServiceError(\n `Element not found : ${locateParam.prompt}`,\n locateDump,\n );\n }\n throw new Error(`Element not found: ${locateParam.prompt}`);\n }\n\n let hitBy: ExecutionTaskHitBy | undefined;\n\n if (isPlanDirectHit && paramWithLocatedPixelResult) {\n hitBy = {\n from: 'Plan',\n context: {\n locatedPixelResult:\n paramWithLocatedPixelResult.locatedPixelResult,\n },\n };\n } else if (isXpathHit) {\n hitBy = {\n from: 'User expected path',\n context: {\n xpath: locateParam.xpath,\n },\n };\n } else if (isCacheHit) {\n hitBy = {\n from: 'Cache',\n context: {\n cacheEntry,\n cacheToSave: currentCacheEntry,\n },\n };\n }\n\n const promptDisplay = locateParam.promptDisplay;\n const elementForAction = promptDisplay\n ? {\n ...element,\n description: promptDisplay,\n }\n : element;\n\n if (promptDisplay && locateDump?.matchedElement) {\n locateDump.matchedElement = locateDump.matchedElement.map(\n (matchedElement) => ({\n ...matchedElement,\n description: promptDisplay,\n }),\n );\n }\n\n onResult?.(elementForAction);\n\n return {\n output: {\n element: {\n ...elementForAction,\n // backward compatibility for aiLocate, which return value needs a dpr field\n dpr: uiContext.deprecatedDpr,\n },\n },\n hitBy,\n };\n },\n };\n\n return taskLocator;\n }\n}\n"],"names":["debug","getDebug","hasNonEmptyCache","cache","Object","invalidLocateElementReason","element","values","value","Number","JSON","normalizeLocateParam","param","deepThink","rest","deepLocate","undefined","locatePlanForLocate","locate","locatePlan","TaskBuilder","plans","planningModel","defaultModel","options","tasks","cacheable","context","planHandlers","Map","plan","defaultHandler","handler","taskActionFinished","taskLocate","planType","actionSpace","action","findActionInActionSpaceOrThrow","locateFields","findAllMidsceneLocatorField","validateRequiredLocateFields","field","ifLocateParamHasLocatedPixelResult","locateTask","result","task","taskContext","abortSignal","timing","uiContext","assert","shrunkShotToLogicalRatio","Error","parsedParam","parseActionParam","error","useDefaultWait","setTimingFieldOnce","delayBeforeRunner","preparation","Promise","defineActionSleep","rejected","item","originalError","String","actionResult","delayAfterRunner","detailedLocateParam","onResult","locateParam","userPromptToMultimodalPrompt","userPromptToString","taskLocator","paramWithLocatedPixelResult","locateDump","locateResult","applyDump","dump","withUsageIntent","planLocatedElement","matchElementFromPlan","elementFromPlan","isPlanDirectHit","rectFromXpath","elementFromXpath","transformLogicalElementToScreenshot","isXpathHit","cachePrompt","locateCacheRecord","cacheEntry","elementFromCacheResult","matchElementFromCache","elementFromCache","isCacheHit","elementFromAiLocate","ServiceError","invalidElementReason","locateCacheAlreadyExists","currentCacheEntry","pointForCache","Math","feature","hitBy","promptDisplay","elementForAction","matchedElement","interfaceInstance","service","taskCache","waitAfterAction","actionReadiness","operationResource"],"mappings":";;;;;;;;;;;;;;;;;;;AAwCA,MAAMA,QAAQC,SAAS;AAKvB,SAASC,iBAAiBC,KAAc;IACtC,OACEA,QAAAA,SAEA,AAAiB,YAAjB,OAAOA,SACPC,OAAO,IAAI,CAACD,OAAO,MAAM,GAAG;AAEhC;AAEA,SAASE,2BACPC,OAA4B;IAE5B,MAAMC,SAAS;QAACD,QAAQ,MAAM,EAAE,CAAC,EAAE;QAAEA,QAAQ,MAAM,EAAE,CAAC,EAAE;KAAC;IACzD,IACEA,QAAQ,MAAM,EAAE,WAAW,KAC3BC,OAAO,IAAI,CAAC,CAACC,QAAU,AAAiB,YAAjB,OAAOA,SAAsB,CAACC,OAAO,QAAQ,CAACD,SAErE,OAAO,CAAC,mCAAmC,EAAEE,KAAK,SAAS,CAACJ,UAAU;AAG1E;AAMA,SAASK,qBACPC,KAAmC;IAEnC,IAAI,AAAiB,YAAjB,OAAOA,OACT,OAAO;QAAE,QAAQA;IAAM;IAGzB,MAAM,EAAEC,SAAS,EAAE,GAAGC,MAAM,GAAGF;IAC/B,MAAMG,aAAaD,KAAK,UAAU,IAAID;IAEtC,O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N,MAAM;oBACN,SAAS;wBACP,OAAOjC,YAAY,KAAK;oBAC1B;gBACF;qBACK,IAAIwB,YACTS,QAAQ;oBACN,MAAM;oBACN,SAAS;wBACPb;wBACA,aAAaS;oBACf;gBACF;gBAGF,MAAMK,gBAAgBlC,YAAY,aAAa;gBAC/C,MAAMmC,mBAAmBD,gBACrB;oBACE,GAAGnG,OAAO;oBACV,aAAamG;gBACf,IACAnG;gBAEJ,IAAImG,iBAAiB7B,YAAY,gBAC/BA,WAAW,cAAc,GAAGA,WAAW,cAAc,CAAC,GAAG,CACvD,CAAC+B,iBAAoB;wBACnB,GAAGA,cAAc;wBACjB,aAAaF;oBACf;gBAIJnC,WAAWoC;gBAEX,OAAO;oBACL,QAAQ;wBACN,SAAS;4BACP,GAAGA,gBAAgB;4BAEnB,KAAKxD,UAAU,aAAa;wBAC9B;oBACF;oBACAsD;gBACF;YACF;QACF;QAEA,OAAO9B;IACT;IA3nBA,YAAY,EACVkC,iBAAiB,EACjBC,OAAO,EACPC,SAAS,EACT1E,WAAW,EACX2E,eAAe,EACfC,eAAe,EACfC,iBAAiB,EACD,CAAE;QApBpB,uBAAiB,aAAjB;QAEA,uBAAiB,WAAjB;QAEA,uBAAiB,aAAjB;QAEA,uBAAiB,eAAjB;QAEA,uBAAiB,mBAAjB;QACA,uBAAiB,mBAAjB;QACA,uBAAiB,qBAAjB;QAWE,IAAI,CAAC,SAAS,GAAGL;QACjB,IAAI,CAAC,OAAO,GAAGC;QACf,IAAI,CAAC,SAAS,GAAGC;QACjB,IAAI,CAAC,WAAW,GAAG1E;QACnB,IAAI,CAAC,eAAe,GAAG2E;QACvB,IAAI,CAAC,eAAe,GAAGC;QACvB,IAAI,CAAC,iBAAiB,GAAGC,qBAAqBL;IAChD;AA4mBF"}
|
|
1
|
+
{"version":3,"file":"agent/task-builder.mjs","sources":["../../../src/agent/task-builder.ts"],"sourcesContent":["import { findAllMidsceneLocatorField, parseActionParam } from '@/ai-model';\nimport type { ModelRuntime } from '@/ai-model/models';\nimport {\n type TMultimodalPrompt,\n findActionInActionSpaceOrThrow,\n userPromptToMultimodalPrompt,\n userPromptToString,\n validateRequiredLocateFields,\n} from '@/common';\nimport { type AbstractInterface, defineActionSleep } from '@/device';\nimport type Service from '@/service';\nimport { setTimingFieldOnce } from '@/task-timing';\nimport type {\n AIUsageInfo,\n DetailedLocateParam,\n DeviceAction,\n ElementCacheFeature,\n ExecutionTaskActionApply,\n ExecutionTaskApply,\n ExecutionTaskHitBy,\n ExecutionTaskPlanningLocateApply,\n LocateResultElement,\n LocateResultWithDump,\n PlanningAction,\n Rect,\n ServiceDump,\n} from '@/types';\nimport { ServiceError } from '@/types';\nimport { getDebug } from '@midscene/shared/logger';\nimport { assert } from '@midscene/shared/utils';\nimport type { ActionReadiness } from './action-readiness';\nimport type { TaskCache } from './task-cache';\nimport { withUsageIntent } from './usage-intent';\nimport {\n ifLocateParamHasLocatedPixelResult,\n matchElementFromCache,\n matchElementFromPlan,\n transformLogicalElementToScreenshot,\n} from './utils';\n\nconst debug = getDebug('agent:task-builder');\n\n/**\n * Check if a cache object is non-empty\n */\nfunction hasNonEmptyCache(cache: unknown): boolean {\n return (\n cache !== null &&\n cache !== undefined &&\n typeof cache === 'object' &&\n Object.keys(cache).length > 0\n );\n}\n\nfunction invalidLocateElementReason(\n element: LocateResultElement,\n): string | undefined {\n const values = [element.center?.[0], element.center?.[1]];\n if (\n element.center?.length !== 2 ||\n values.some((value) => typeof value !== 'number' || !Number.isFinite(value))\n ) {\n return `Invalid locate result coordinates: ${JSON.stringify(element)}`;\n }\n return undefined;\n}\n\ntype LocateParamWithDeprecatedAlias = DetailedLocateParam & {\n deepThink?: boolean;\n};\n\nfunction normalizeLocateParam(\n param: string | DetailedLocateParam,\n): DetailedLocateParam {\n if (typeof param === 'string') {\n return { prompt: param };\n }\n\n const { deepThink, ...rest } = param as LocateParamWithDeprecatedAlias;\n const deepLocate = rest.deepLocate ?? deepThink;\n\n return deepLocate === undefined ? rest : { ...rest, deepLocate };\n}\n\nexport function locatePlanForLocate(param: string | DetailedLocateParam) {\n const locate = normalizeLocateParam(param);\n const locatePlan: PlanningAction<DetailedLocateParam> = {\n type: 'Locate',\n param: locate,\n thought: '',\n };\n return locatePlan;\n}\n\ninterface TaskBuilderDeps {\n getDefaultModelRuntime: () => ModelRuntime;\n interfaceInstance: AbstractInterface;\n service: Service;\n taskCache?: TaskCache;\n actionSpace: DeviceAction[];\n waitAfterAction?: number;\n actionReadiness?: ActionReadiness;\n operationResource?: object;\n}\n\ninterface BuildOptions {\n cacheable?: boolean;\n multimodalPrompt?: TMultimodalPrompt;\n deepLocate?: boolean;\n abortSignal?: AbortSignal;\n}\n\ninterface PlanBuildContext {\n tasks: ExecutionTaskApply[];\n planningModel: ModelRuntime;\n locateModel: ModelRuntime;\n cacheable?: boolean;\n multimodalPrompt?: TMultimodalPrompt;\n deepLocate?: boolean;\n abortSignal?: AbortSignal;\n}\n\nexport class TaskBuilder {\n private readonly interface: AbstractInterface;\n\n private readonly service: Service;\n private readonly getDefaultModelRuntime: () => ModelRuntime;\n\n private readonly taskCache?: TaskCache;\n\n private readonly actionSpace: DeviceAction[];\n\n private readonly waitAfterAction?: number;\n private readonly actionReadiness?: ActionReadiness;\n private readonly operationResource: object;\n\n constructor({\n getDefaultModelRuntime,\n interfaceInstance,\n service,\n taskCache,\n actionSpace,\n waitAfterAction,\n actionReadiness,\n operationResource,\n }: TaskBuilderDeps) {\n this.getDefaultModelRuntime = getDefaultModelRuntime;\n this.interface = interfaceInstance;\n this.service = service;\n this.taskCache = taskCache;\n this.actionSpace = actionSpace;\n this.waitAfterAction = waitAfterAction;\n this.actionReadiness = actionReadiness;\n this.operationResource = operationResource ?? interfaceInstance;\n }\n\n public async build(\n plans: PlanningAction[],\n planningModel: ModelRuntime,\n locateModel: ModelRuntime,\n options?: BuildOptions,\n ): Promise<{ tasks: ExecutionTaskApply[] }> {\n const tasks: ExecutionTaskApply[] = [];\n const cacheable = options?.cacheable;\n\n const context: PlanBuildContext = {\n tasks,\n planningModel,\n locateModel,\n cacheable,\n multimodalPrompt: options?.multimodalPrompt,\n deepLocate: options?.deepLocate,\n abortSignal: options?.abortSignal,\n };\n\n type PlanHandler = (plan: PlanningAction) => Promise<void> | void;\n\n const planHandlers = new Map<string, PlanHandler>([\n [\n 'Locate',\n (plan) =>\n this.handleLocatePlan(\n plan as PlanningAction<DetailedLocateParam>,\n context,\n ),\n ],\n ['Finished', (plan) => this.handleFinishedPlan(plan, context)],\n ]);\n\n const defaultHandler: PlanHandler = (plan) =>\n this.handleActionPlan(plan, context);\n\n for (const plan of plans) {\n context.abortSignal?.throwIfAborted();\n const handler = planHandlers.get(plan.type) ?? defaultHandler;\n await handler(plan);\n }\n\n return {\n tasks,\n };\n }\n\n private handleFinishedPlan(\n plan: PlanningAction,\n context: PlanBuildContext,\n ): void {\n const taskActionFinished: ExecutionTaskActionApply<null> = {\n type: 'Action Space',\n subType: 'Finished',\n param: null,\n thought: plan.thought,\n executor: async () => {},\n };\n context.tasks.push(taskActionFinished);\n }\n\n private async handleLocatePlan(\n plan: PlanningAction<DetailedLocateParam>,\n context: PlanBuildContext,\n ): Promise<void> {\n const taskLocate = this.createLocateTask(plan, plan.param, context);\n context.tasks.push(taskLocate);\n }\n\n private async handleActionPlan(\n plan: PlanningAction,\n context: PlanBuildContext,\n ): Promise<void> {\n const planType = plan.type;\n const actionSpace = this.actionSpace;\n const action = findActionInActionSpaceOrThrow(planType, actionSpace);\n const param = plan.param;\n\n const locateFields = findAllMidsceneLocatorField(action.paramSchema);\n\n validateRequiredLocateFields(param, action.paramSchema);\n\n locateFields.forEach((field) => {\n if (param?.[field]) {\n // Always use createLocateTask for all locate params.\n // This ensures cache writing happens even when locatedPixelResult is available\n const locatePlan = locatePlanForLocate(param[field]);\n debug(\n 'will prepend locate param for field',\n `action.type=${planType}`,\n `param=${JSON.stringify(param[field])}`,\n `locatePlan=${JSON.stringify(locatePlan)}`,\n `hasLocatedPixelResult=${ifLocateParamHasLocatedPixelResult(param[field])}`,\n );\n const locateTask = this.createLocateTask(\n locatePlan,\n param[field],\n context,\n (result) => {\n param[field] = result;\n },\n );\n context.tasks.push(locateTask);\n } else {\n debug(`field '${field}' is not provided for action ${planType}`);\n }\n });\n\n const task: ExecutionTaskApply<\n 'Action Space',\n any,\n { success: boolean; action: string; param: any },\n void\n > = {\n type: 'Action Space',\n subType: planType,\n thought: plan.thought,\n param: plan.param,\n planningFeedbackMaxLength: action.planningFeedbackMaxLength,\n executor: async (taskContext) => {\n const abortSignal = context.abortSignal ?? taskContext.signal;\n const timing = taskContext.task.timing;\n\n debug(\n 'executing action',\n planType,\n param,\n `taskContext.element.center: ${taskContext.element?.center}`,\n );\n\n const uiContext = taskContext.uiContext;\n assert(uiContext, 'uiContext is required for Action task');\n\n validateRequiredLocateFields(param, action.paramSchema);\n\n const { shrunkShotToLogicalRatio } = uiContext;\n if (shrunkShotToLogicalRatio === undefined) {\n throw new Error(\n 'shrunkShotToLogicalRatio is not defined in Action task',\n );\n }\n const parsedParam = (() => {\n if (!action.paramSchema) return param;\n try {\n return parseActionParam(param, action.paramSchema, {\n shrunkShotToLogicalRatio,\n });\n } catch (error: any) {\n throw new Error(\n `Invalid parameters for action ${action.name}: ${error.message}\\nParameters: ${JSON.stringify(param)}`,\n { cause: error },\n );\n }\n })();\n\n const useDefaultWait = !this.actionReadiness;\n taskContext.task.actionReadiness = useDefaultWait\n ? 'default'\n : 'custom';\n abortSignal?.throwIfAborted();\n\n setTimingFieldOnce(timing, 'beforeInvokeActionHookStart');\n const delayBeforeRunner = useDefaultWait\n ? (action.delayBeforeRunner ?? 200)\n : 0;\n try {\n const preparation = await Promise.allSettled([\n this.interface.beforeInvokeAction?.(\n action.name,\n param,\n abortSignal,\n ),\n delayBeforeRunner > 0\n ? defineActionSleep(abortSignal).call({\n timeMs: delayBeforeRunner,\n })\n : Promise.resolve(),\n ]);\n const rejected = preparation.find(\n (item) => item.status === 'rejected',\n );\n if (rejected?.status === 'rejected') throw rejected.reason;\n } catch (originalError: any) {\n throw new Error(\n `error in running beforeInvokeAction for ${action.name}: ${originalError?.message || String(originalError)}`,\n { cause: originalError },\n );\n } finally {\n setTimingFieldOnce(timing, 'beforeInvokeActionHookEnd');\n }\n\n abortSignal?.throwIfAborted();\n setTimingFieldOnce(timing, 'callActionStart');\n debug('calling action', action.name);\n const actionResult = await action.call.call(\n this.interface,\n parsedParam,\n useDefaultWait\n ? { ...taskContext, signal: abortSignal }\n : { ...taskContext, signal: abortSignal, skipDefaultWait: true },\n );\n setTimingFieldOnce(timing, 'callActionEnd');\n debug('called action', action.name, 'result:', actionResult);\n abortSignal?.throwIfAborted();\n\n setTimingFieldOnce(timing, 'afterInvokeActionHookStart');\n setTimingFieldOnce(timing, 'waitForActionReadyStart');\n try {\n if (useDefaultWait) {\n const delayAfterRunner =\n action.delayAfterRunner ?? this.waitAfterAction ?? 300;\n if (delayAfterRunner > 0)\n await defineActionSleep(abortSignal).call({\n timeMs: delayAfterRunner,\n });\n await this.interface.defaultActionWait?.(\n action.name,\n parsedParam,\n abortSignal,\n );\n } else {\n await this.actionReadiness!.wait(\n {\n id: taskContext.task.taskId,\n name: action.name,\n param: parsedParam,\n },\n abortSignal,\n this.operationResource,\n );\n }\n } finally {\n setTimingFieldOnce(timing, 'waitForActionReadyEnd');\n }\n abortSignal?.throwIfAborted();\n try {\n await this.interface.afterInvokeAction?.(\n action.name,\n parsedParam,\n abortSignal,\n );\n } catch (originalError: any) {\n throw new Error(\n `error in running afterInvokeAction for ${action.name}: ${originalError?.message || String(originalError)}`,\n { cause: originalError },\n );\n } finally {\n setTimingFieldOnce(timing, 'afterInvokeActionHookEnd');\n }\n return { output: actionResult };\n },\n };\n\n context.tasks.push(task);\n }\n\n private createLocateTask(\n plan: PlanningAction<DetailedLocateParam>,\n detailedLocateParam: DetailedLocateParam | string,\n context: PlanBuildContext,\n onResult?: (result: LocateResultElement) => void,\n ): ExecutionTaskPlanningLocateApply {\n const { cacheable, locateModel, deepLocate } = context;\n\n let locateParam = normalizeLocateParam(detailedLocateParam);\n\n // Planning produces text locators; carry the user's reference images into\n // independent grounding calls while preserving explicit locator images.\n if (\n context.multimodalPrompt?.images?.length &&\n locateParam.prompt &&\n !userPromptToMultimodalPrompt(locateParam.prompt)?.images?.length\n ) {\n locateParam = {\n ...locateParam,\n prompt: {\n ...context.multimodalPrompt,\n prompt: userPromptToString(locateParam.prompt),\n },\n };\n }\n\n if (cacheable !== undefined) {\n locateParam = {\n ...locateParam,\n cacheable,\n };\n }\n\n if (deepLocate && !locateParam.deepLocate) {\n locateParam = {\n ...locateParam,\n deepLocate: true,\n };\n }\n\n const taskLocator: ExecutionTaskPlanningLocateApply = {\n type: 'Planning',\n subType: 'Locate',\n param: locateParam,\n thought: plan.thought,\n executor: async (taskContext) => {\n const abortSignal = context.abortSignal ?? taskContext.signal;\n abortSignal?.throwIfAborted();\n const { task } = taskContext;\n let { uiContext } = taskContext;\n const paramWithLocatedPixelResult = ifLocateParamHasLocatedPixelResult(\n locateParam,\n )\n ? locateParam\n : undefined;\n\n assert(\n locateParam?.prompt || paramWithLocatedPixelResult,\n `No prompt or id or position or locatedPixelResult to locate, param=${JSON.stringify(\n locateParam,\n )}`,\n );\n\n if (!uiContext) {\n uiContext = await this.service.contextRetrieverFn(abortSignal);\n abortSignal?.throwIfAborted();\n }\n\n assert(uiContext, 'uiContext is required for Service task');\n\n const { shrunkShotToLogicalRatio } = uiContext;\n\n if (shrunkShotToLogicalRatio === undefined) {\n throw new Error(\n 'shrunkShotToLogicalRatio is not defined in locate task',\n );\n }\n\n let locateDump: ServiceDump | undefined;\n let locateResult: LocateResultWithDump | undefined;\n\n const applyDump = (dump?: ServiceDump) => {\n if (!dump) {\n return;\n }\n locateDump = dump;\n task.log = {\n dump,\n rawResponse: dump.taskInfo?.rawResponse,\n rawAssistantOutput: dump.taskInfo?.rawAssistantOutput,\n searchAreaRawChoiceMessage:\n dump.taskInfo?.searchAreaRawChoiceMessage,\n };\n task.usage = withUsageIntent(dump.taskInfo?.usage, 'locate');\n task.searchArea = dump.taskInfo?.searchArea;\n if (dump.taskInfo?.searchAreaUsage) {\n // The deepLocate search-area call belongs to the same locate task,\n // so it shares the companion usage intent.\n task.searchAreaUsage = withUsageIntent(\n dump.taskInfo.searchAreaUsage,\n 'locate',\n );\n }\n if (dump.taskInfo?.reasoning_content) {\n task.reasoning_content = dump.taskInfo.reasoning_content;\n }\n };\n\n const planLocatedElement = paramWithLocatedPixelResult\n ? matchElementFromPlan(paramWithLocatedPixelResult)\n : undefined;\n\n // Separate planning normally returns target descriptions, but may still\n // return coordinates. Reuse them even with a dedicated Locate model,\n // preserving the existing direct-plan-hit behavior.\n // when deepLocate is enabled, locatedPixelResult should be used as search\n // area hint, not as a final direct hit\n const elementFromPlan = locateParam.deepLocate\n ? undefined\n : planLocatedElement;\n const isPlanDirectHit = !!elementFromPlan;\n\n // from xpath\n let rectFromXpath: Rect | undefined;\n if (\n !isPlanDirectHit &&\n locateParam.xpath &&\n this.interface.rectMatchesCacheFeature\n ) {\n try {\n rectFromXpath = await this.interface.rectMatchesCacheFeature({\n xpaths: [locateParam.xpath],\n });\n } catch {\n // xpath locate failed, allow fallback to cache or AI locate\n }\n }\n\n const elementFromXpath = rectFromXpath\n ? transformLogicalElementToScreenshot(\n {\n center: [\n rectFromXpath.left + rectFromXpath.width / 2,\n rectFromXpath.top + rectFromXpath.height / 2,\n ],\n description:\n typeof locateParam.prompt === 'string'\n ? locateParam.prompt\n : locateParam.prompt?.prompt || '',\n rect: rectFromXpath,\n },\n shrunkShotToLogicalRatio,\n )\n : undefined;\n\n const isXpathHit = !!elementFromXpath;\n\n const cachePrompt = locateParam.prompt;\n const locateCacheRecord = this.taskCache?.matchLocateCache(cachePrompt);\n const cacheEntry = locateCacheRecord?.cacheContent?.cache;\n\n const elementFromCacheResult =\n isPlanDirectHit || isXpathHit\n ? null\n : await matchElementFromCache(\n {\n taskCache: this.taskCache,\n interfaceInstance: this.interface,\n },\n cacheEntry,\n cachePrompt,\n locateParam.cacheable,\n );\n\n // elementFromCacheResult is in logical coordinates, which should be transformed to screenshot coordinates;\n const elementFromCache = elementFromCacheResult\n ? transformLogicalElementToScreenshot(\n elementFromCacheResult,\n shrunkShotToLogicalRatio,\n )\n : undefined;\n\n const isCacheHit = !!elementFromCache;\n\n let elementFromAiLocate: LocateResultElement | null | undefined;\n const timing = taskContext.task.timing;\n if (!isXpathHit && !isCacheHit && !isPlanDirectHit) {\n try {\n setTimingFieldOnce(timing, 'callAiStart');\n locateResult = await this.service.locate(\n locateParam,\n {\n context: uiContext,\n planLocatedElement,\n },\n locateModel,\n abortSignal,\n );\n applyDump(locateResult.dump);\n elementFromAiLocate = locateResult.element;\n } catch (error) {\n if (error instanceof ServiceError) {\n applyDump(error.dump);\n }\n throw error;\n } finally {\n setTimingFieldOnce(timing, 'callAiEnd');\n }\n }\n\n const element =\n elementFromPlan ||\n elementFromXpath ||\n elementFromCache ||\n elementFromAiLocate;\n\n if (element) {\n const invalidElementReason = invalidLocateElementReason(element);\n if (invalidElementReason) {\n if (locateDump) {\n throw new ServiceError(invalidElementReason, locateDump);\n }\n throw new Error(invalidElementReason);\n }\n }\n\n // Check if locate cache already exists (for planHitFlag case)\n const locateCacheAlreadyExists = hasNonEmptyCache(\n locateCacheRecord?.cacheContent?.cache,\n );\n\n let currentCacheEntry: ElementCacheFeature | undefined;\n // Write cache if:\n // 1. element found\n // 2. taskCache enabled\n // 3. not a cache hit (otherwise we'd be writing what we just read)\n // 4. not already cached for plan hit case (avoid redundant writes), OR allow update if cache validation failed\n // 5. cacheable is not explicitly false\n if (\n element &&\n this.taskCache &&\n !isCacheHit &&\n (!isPlanDirectHit || !locateCacheAlreadyExists) &&\n locateParam.cacheable !== false\n ) {\n if (this.interface.cacheFeatureForPoint) {\n try {\n // Transform coordinates to logical space for cacheFeatureForPoint\n // cacheFeatureForPoint needs logical coordinates to locate elements in DOM\n const pointForCache: [number, number] = [\n Math.round(element.center[0] / shrunkShotToLogicalRatio),\n Math.round(element.center[1] / shrunkShotToLogicalRatio),\n ];\n\n const defaultModel = this.getDefaultModelRuntime();\n const feature = await this.interface.cacheFeatureForPoint(\n pointForCache,\n {\n targetDescription:\n typeof locateParam.prompt === 'string'\n ? locateParam.prompt\n : locateParam.prompt?.prompt,\n modelRuntime: {\n ...defaultModel,\n executionId: locateModel.executionId,\n },\n },\n );\n if (hasNonEmptyCache(feature)) {\n debug(\n 'update cache, prompt: %s, cache: %o',\n cachePrompt,\n feature,\n );\n currentCacheEntry = feature;\n this.taskCache.updateOrAppendCacheRecord(\n {\n type: 'locate',\n prompt: cachePrompt,\n cache: feature,\n },\n locateCacheRecord,\n );\n } else {\n debug(\n 'no cache data returned, skip cache update, prompt: %s',\n cachePrompt,\n );\n }\n } catch (error) {\n debug('cacheFeatureForPoint failed: %s', error);\n }\n } else {\n debug('cacheFeatureForPoint is not supported, skip cache update');\n }\n }\n\n if (!element) {\n if (locateDump) {\n throw new ServiceError(\n `Element not found : ${locateParam.prompt}`,\n locateDump,\n );\n }\n throw new Error(`Element not found: ${locateParam.prompt}`);\n }\n\n let hitBy: ExecutionTaskHitBy | undefined;\n\n if (isPlanDirectHit && paramWithLocatedPixelResult) {\n hitBy = {\n from: 'Plan',\n context: {\n locatedPixelResult:\n paramWithLocatedPixelResult.locatedPixelResult,\n },\n };\n } else if (isXpathHit) {\n hitBy = {\n from: 'User expected path',\n context: {\n xpath: locateParam.xpath,\n },\n };\n } else if (isCacheHit) {\n hitBy = {\n from: 'Cache',\n context: {\n cacheEntry,\n cacheToSave: currentCacheEntry,\n },\n };\n }\n\n const promptDisplay = locateParam.promptDisplay;\n const elementForAction = promptDisplay\n ? {\n ...element,\n description: promptDisplay,\n }\n : element;\n\n if (promptDisplay && locateDump?.matchedElement) {\n locateDump.matchedElement = locateDump.matchedElement.map(\n (matchedElement) => ({\n ...matchedElement,\n description: promptDisplay,\n }),\n );\n }\n\n onResult?.(elementForAction);\n\n return {\n output: {\n element: {\n ...elementForAction,\n // backward compatibility for aiLocate, which return value needs a dpr field\n dpr: uiContext.deprecatedDpr,\n },\n },\n hitBy,\n };\n },\n };\n\n return taskLocator;\n }\n}\n"],"names":["debug","getDebug","hasNonEmptyCache","cache","Object","invalidLocateElementReason","element","values","value","Number","JSON","normalizeLocateParam","param","deepThink","rest","deepLocate","undefined","locatePlanForLocate","locate","locatePlan","TaskBuilder","plans","planningModel","locateModel","options","tasks","cacheable","context","planHandlers","Map","plan","defaultHandler","handler","taskActionFinished","taskLocate","planType","actionSpace","action","findActionInActionSpaceOrThrow","locateFields","findAllMidsceneLocatorField","validateRequiredLocateFields","field","ifLocateParamHasLocatedPixelResult","locateTask","result","task","taskContext","abortSignal","timing","uiContext","assert","shrunkShotToLogicalRatio","Error","parsedParam","parseActionParam","error","useDefaultWait","setTimingFieldOnce","delayBeforeRunner","preparation","Promise","defineActionSleep","rejected","item","originalError","String","actionResult","delayAfterRunner","detailedLocateParam","onResult","locateParam","userPromptToMultimodalPrompt","userPromptToString","taskLocator","paramWithLocatedPixelResult","locateDump","locateResult","applyDump","dump","withUsageIntent","planLocatedElement","matchElementFromPlan","elementFromPlan","isPlanDirectHit","rectFromXpath","elementFromXpath","transformLogicalElementToScreenshot","isXpathHit","cachePrompt","locateCacheRecord","cacheEntry","elementFromCacheResult","matchElementFromCache","elementFromCache","isCacheHit","elementFromAiLocate","ServiceError","invalidElementReason","locateCacheAlreadyExists","currentCacheEntry","pointForCache","Math","defaultModel","feature","hitBy","promptDisplay","elementForAction","matchedElement","getDefaultModelRuntime","interfaceInstance","service","taskCache","waitAfterAction","actionReadiness","operationResource"],"mappings":";;;;;;;;;;;;;;;;;;;AAwCA,MAAMA,QAAQC,SAAS;AAKvB,SAASC,iBAAiBC,KAAc;IACtC,OACEA,QAAAA,SAEA,AAAiB,YAAjB,OAAOA,SACPC,OAAO,IAAI,CAACD,OAAO,MAAM,GAAG;AAEhC;AAEA,SAASE,2BACPC,OAA4B;IAE5B,MAAMC,S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X6E,eAAe,EACfC,eAAe,EACfC,iBAAiB,EACD,CAAE;QAtBpB,uBAAiB,aAAjB;QAEA,uBAAiB,WAAjB;QACA,uBAAiB,0BAAjB;QAEA,uBAAiB,aAAjB;QAEA,uBAAiB,eAAjB;QAEA,uBAAiB,mBAAjB;QACA,uBAAiB,mBAAjB;QACA,uBAAiB,qBAAjB;QAYE,IAAI,CAAC,sBAAsB,GAAGN;QAC9B,IAAI,CAAC,SAAS,GAAGC;QACjB,IAAI,CAAC,OAAO,GAAGC;QACf,IAAI,CAAC,SAAS,GAAGC;QACjB,IAAI,CAAC,WAAW,GAAG5E;QACnB,IAAI,CAAC,eAAe,GAAG6E;QACvB,IAAI,CAAC,eAAe,GAAGC;QACvB,IAAI,CAAC,iBAAiB,GAAGC,qBAAqBL;IAChD;AAknBF"}
|
package/dist/es/agent/tasks.mjs
CHANGED
|
@@ -88,8 +88,8 @@ class TaskExecutor {
|
|
|
88
88
|
else warnLog('useDeviceTime is enabled but getDeviceLocalTimeString is not implemented, falling back to runtime time.');
|
|
89
89
|
return getReadableTimeString(format);
|
|
90
90
|
}
|
|
91
|
-
async convertPlanToExecutable(plans, planningModel,
|
|
92
|
-
return this.taskBuilder.build(plans, planningModel,
|
|
91
|
+
async convertPlanToExecutable(plans, planningModel, locateModel, options) {
|
|
92
|
+
return this.taskBuilder.build(plans, planningModel, locateModel, options);
|
|
93
93
|
}
|
|
94
94
|
async loadYamlFlowAsPlanning(userInstruction, yamlString, reportOptions) {
|
|
95
95
|
const session = this.createExecutionSession(taskTitleStr(reportOptions?.type || 'Act', reportOptions?.prompt || userPromptToString(userInstruction)), {
|
|
@@ -157,7 +157,7 @@ class TaskExecutor {
|
|
|
157
157
|
}
|
|
158
158
|
});
|
|
159
159
|
}
|
|
160
|
-
async runPlans(title, plans, planningModel,
|
|
160
|
+
async runPlans(title, plans, planningModel, locateModel, options) {
|
|
161
161
|
const abortSignal = options?.abortSignal ?? this.getAbortSignal?.();
|
|
162
162
|
const session = this.createExecutionSession(title, {
|
|
163
163
|
...options,
|
|
@@ -168,11 +168,11 @@ class TaskExecutor {
|
|
|
168
168
|
...planningModel,
|
|
169
169
|
executionId: runner.id
|
|
170
170
|
};
|
|
171
|
-
const
|
|
172
|
-
...
|
|
171
|
+
const executionLocateModel = {
|
|
172
|
+
...locateModel,
|
|
173
173
|
executionId: runner.id
|
|
174
174
|
};
|
|
175
|
-
const { tasks } = await this.convertPlanToExecutable(plans, executionPlanningModel,
|
|
175
|
+
const { tasks } = await this.convertPlanToExecutable(plans, executionPlanningModel, executionLocateModel, {
|
|
176
176
|
abortSignal
|
|
177
177
|
});
|
|
178
178
|
const result = await session.appendAndRun(tasks);
|
|
@@ -182,9 +182,9 @@ class TaskExecutor {
|
|
|
182
182
|
runner
|
|
183
183
|
};
|
|
184
184
|
}
|
|
185
|
-
async action(userPrompt, planningModel,
|
|
185
|
+
async action(userPrompt, planningModel, locateModel, aiActContext, cacheable, replanningCycleLimitOverride, effort = 'balance', fileChooserAccept, deepLocate, abortSignal, reportOptions) {
|
|
186
186
|
abortSignal?.throwIfAborted();
|
|
187
|
-
return withFileChooser(this.interface, fileChooserAccept, async ()=>this.runAction(userPrompt, planningModel,
|
|
187
|
+
return withFileChooser(this.interface, fileChooserAccept, async ()=>this.runAction(userPrompt, planningModel, locateModel, aiActContext, cacheable, replanningCycleLimitOverride, effort, deepLocate, abortSignal, reportOptions));
|
|
188
188
|
}
|
|
189
189
|
invalidateFailedCacheHitLocates(runner, fromIndex) {
|
|
190
190
|
if (!this.taskCache) return;
|
|
@@ -196,7 +196,7 @@ class TaskExecutor {
|
|
|
196
196
|
}
|
|
197
197
|
}
|
|
198
198
|
}
|
|
199
|
-
async runAction(userPrompt, planningModel,
|
|
199
|
+
async runAction(userPrompt, planningModel, locateModel, aiActContext, cacheable, replanningCycleLimitOverride, effort = 'balance', deepLocate, abortSignal, reportOptions) {
|
|
200
200
|
abortSignal ??= this.getAbortSignal?.();
|
|
201
201
|
const conversationHistory = new ConversationHistory();
|
|
202
202
|
const promptDisplay = reportOptions?.prompt || userPromptToString(userPrompt);
|
|
@@ -213,11 +213,11 @@ class TaskExecutor {
|
|
|
213
213
|
...planningModel,
|
|
214
214
|
executionId: runner.id
|
|
215
215
|
};
|
|
216
|
-
|
|
217
|
-
...
|
|
216
|
+
locateModel = {
|
|
217
|
+
...locateModel,
|
|
218
218
|
executionId: runner.id
|
|
219
219
|
};
|
|
220
|
-
const noIndividualLocateModel = 'default' === planningModel.config.slot;
|
|
220
|
+
const noIndividualLocateModel = 'default' === planningModel.config.slot && 'default' === locateModel.config.slot;
|
|
221
221
|
const includeLocateInPlanning = 'deepThink' !== effort && noIndividualLocateModel;
|
|
222
222
|
const imagesIncludeCount = 'deepThink' === effort ? 2 : 1;
|
|
223
223
|
debug('setting includeLocateInPlanning to', includeLocateInPlanning, {
|
|
@@ -303,6 +303,8 @@ class TaskExecutor {
|
|
|
303
303
|
actionContext: renderAIContext(aiActContext),
|
|
304
304
|
actionSpace,
|
|
305
305
|
modelRuntime: planningModel,
|
|
306
|
+
locateModelRuntime: locateModel,
|
|
307
|
+
getDefaultModelRuntime: this.getDefaultModelRuntime,
|
|
306
308
|
conversationHistory,
|
|
307
309
|
includeLocateInPlanning,
|
|
308
310
|
imagesIncludeCount,
|
|
@@ -392,7 +394,7 @@ class TaskExecutor {
|
|
|
392
394
|
yamlFlow.push(...planResult?.yamlFlow || []);
|
|
393
395
|
let executables;
|
|
394
396
|
try {
|
|
395
|
-
executables = await this.convertPlanToExecutable(plans, planningModel,
|
|
397
|
+
executables = await this.convertPlanToExecutable(plans, planningModel, locateModel, {
|
|
396
398
|
cacheable,
|
|
397
399
|
multimodalPrompt: userPromptToMultimodalPrompt(userPrompt),
|
|
398
400
|
deepLocate,
|
|
@@ -625,6 +627,7 @@ class TaskExecutor {
|
|
|
625
627
|
_define_property(this, "interface", void 0);
|
|
626
628
|
_define_property(this, "service", void 0);
|
|
627
629
|
_define_property(this, "taskCache", void 0);
|
|
630
|
+
_define_property(this, "getDefaultModelRuntime", void 0);
|
|
628
631
|
_define_property(this, "providedActionSpace", void 0);
|
|
629
632
|
_define_property(this, "taskBuilder", void 0);
|
|
630
633
|
_define_property(this, "onTaskStartCallback", void 0);
|
|
@@ -633,6 +636,7 @@ class TaskExecutor {
|
|
|
633
636
|
_define_property(this, "replanningCycleLimit", void 0);
|
|
634
637
|
_define_property(this, "waitAfterAction", void 0);
|
|
635
638
|
_define_property(this, "useDeviceTime", void 0);
|
|
639
|
+
this.getDefaultModelRuntime = opts.getDefaultModelRuntime;
|
|
636
640
|
this.interface = interfaceInstance;
|
|
637
641
|
this.service = service;
|
|
638
642
|
this.taskCache = opts.taskCache;
|
|
@@ -644,6 +648,7 @@ class TaskExecutor {
|
|
|
644
648
|
this.getAbortSignal = opts.getAbortSignal;
|
|
645
649
|
this.providedActionSpace = opts.actionSpace;
|
|
646
650
|
this.taskBuilder = new TaskBuilder({
|
|
651
|
+
getDefaultModelRuntime: opts.getDefaultModelRuntime,
|
|
647
652
|
interfaceInstance,
|
|
648
653
|
service,
|
|
649
654
|
taskCache: opts.taskCache,
|