@ui-tars-test/agent-sdk 0.3.9 → 0.3.12
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/GUIAgent.d.ts +1 -1
- package/dist/GUIAgent.d.ts.map +1 -1
- package/dist/GUIAgent.js +4 -4
- package/dist/GUIAgent.js.map +1 -1
- package/dist/GUIAgent.mjs +1 -1
- package/dist/GUIAgent.mjs.map +1 -1
- package/dist/ToolCallEngine.d.ts +1 -1
- package/dist/ToolCallEngine.d.ts.map +1 -1
- package/dist/ToolCallEngine.js +2 -2
- package/dist/ToolCallEngine.js.map +1 -1
- package/dist/ToolCallEngine.mjs +1 -1
- package/dist/ToolCallEngine.mjs.map +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js.map +1 -1
- package/dist/utils.mjs.map +1 -1
- package/package.json +3 -2
package/dist/GUIAgent.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LLMRequestHookPayload } from '@tarko
|
|
1
|
+
import { LLMRequestHookPayload } from '@ui-tars-test/tarko-agent';
|
|
2
2
|
import { Operator, BaseGUIAgent } from '@ui-tars-test/shared/base';
|
|
3
3
|
import { GUIAgentConfig } from '@ui-tars-test/shared/types';
|
|
4
4
|
export declare class GUIAgent<T extends Operator> extends BaseGUIAgent {
|
package/dist/GUIAgent.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GUIAgent.d.ts","sourceRoot":"","sources":["../src/GUIAgent.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,qBAAqB,EAKtB,MAAM,
|
|
1
|
+
{"version":3,"file":"GUIAgent.d.ts","sourceRoot":"","sources":["../src/GUIAgent.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,qBAAqB,EAKtB,MAAM,2BAA2B,CAAC;AAInC,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,EACL,cAAc,EAGf,MAAM,4BAA4B,CAAC;AAapC,qBAAa,QAAQ,CAAC,CAAC,SAAS,QAAQ,CAAE,SAAQ,YAAY;IAC5D,MAAM,CAAC,KAAK,SAAe;IAE3B,OAAO,CAAC,QAAQ,CAAuB;IACvC,OAAO,CAAC,oBAAoB,CAAuB;IACnD,OAAO,CAAC,gBAAgB,CAAwB;IAChD,OAAO,CAAC,gBAAgB,CAAS;gBAErB,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC;IA+C/B,UAAU;IA0CV,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC;IAkDvE,oBAAoB,CAAC,SAAS,EAAE,MAAM;IAItC,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIzC,gBAAgB,CACpB,EAAE,EAAE,MAAM,EACV,QAAQ,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAC9C,IAAI,EAAE,OAAO;IAKT,eAAe,CACnB,EAAE,EAAE,MAAM,EACV,QAAQ,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAC9C,MAAM,EAAE,OAAO,GACd,OAAO,CAAC,OAAO,CAAC;CA4DpB"}
|
package/dist/GUIAgent.js
CHANGED
|
@@ -30,7 +30,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
30
30
|
__webpack_require__.d(__webpack_exports__, {
|
|
31
31
|
GUIAgent: ()=>GUIAgent
|
|
32
32
|
});
|
|
33
|
-
const
|
|
33
|
+
const tarko_agent_namespaceObject = require("@ui-tars-test/tarko-agent");
|
|
34
34
|
const external_ToolCallEngine_js_namespaceObject = require("./ToolCallEngine.js");
|
|
35
35
|
const external_prompts_js_namespaceObject = require("./prompts.js");
|
|
36
36
|
const media_utils_namespaceObject = require("@agent-infra/media-utils");
|
|
@@ -49,10 +49,10 @@ function _define_property(obj, key, value) {
|
|
|
49
49
|
else obj[key] = value;
|
|
50
50
|
return obj;
|
|
51
51
|
}
|
|
52
|
-
const defaultLogger = new
|
|
52
|
+
const defaultLogger = new tarko_agent_namespaceObject.ConsoleLogger('[GUIAgent]', tarko_agent_namespaceObject.LogLevel.DEBUG);
|
|
53
53
|
class GUIAgent extends base_namespaceObject.BaseGUIAgent {
|
|
54
54
|
async initialize() {
|
|
55
|
-
this.registerTool(new
|
|
55
|
+
this.registerTool(new tarko_agent_namespaceObject.Tool({
|
|
56
56
|
id: external_constants_js_namespaceObject.GUI_ADAPTED_TOOL_NAME,
|
|
57
57
|
description: 'operator tool',
|
|
58
58
|
parameters: {},
|
|
@@ -186,7 +186,7 @@ class GUIAgent extends base_namespaceObject.BaseGUIAgent {
|
|
|
186
186
|
...maxLoopCount && {
|
|
187
187
|
maxIterations: maxLoopCount
|
|
188
188
|
},
|
|
189
|
-
logLevel:
|
|
189
|
+
logLevel: tarko_agent_namespaceObject.LogLevel.DEBUG
|
|
190
190
|
}), _define_property(this, "operator", void 0), _define_property(this, "normalizeCoordinates", void 0), _define_property(this, "detailCalculator", void 0), _define_property(this, "loopIntervalInMs", void 0);
|
|
191
191
|
this.operator = operator;
|
|
192
192
|
this.normalizeCoordinates = normalizeCoordinates ?? external_defaultImpls_js_namespaceObject.defaultNormalizeCoords;
|
package/dist/GUIAgent.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GUIAgent.js","sources":["webpack://@ui-tars-test/agent-sdk/webpack/runtime/define_property_getters","webpack://@ui-tars-test/agent-sdk/webpack/runtime/has_own_property","webpack://@ui-tars-test/agent-sdk/webpack/runtime/make_namespace_object","webpack://@ui-tars-test/agent-sdk/./src/GUIAgent.ts"],"sourcesContent":["__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","/*\n * Copyright (c) 2025 Bytedance, Inc. and its affiliates.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n LLMRequestHookPayload,\n ChatCompletionContentPart,\n LogLevel,\n Tool,\n ConsoleLogger,\n} from '@tarko/agent';\nimport { GUIAgentToolCallEngine } from './ToolCallEngine';\nimport { SYSTEM_PROMPT } from './prompts';\nimport { Base64ImageParser } from '@agent-infra/media-utils';\nimport { Operator, BaseGUIAgent } from '@ui-tars-test/shared/base';\nimport {\n GUIAgentConfig,\n NormalizeCoordinates,\n ImageDetailCalculator,\n} from '@ui-tars-test/shared/types';\nimport {\n assembleSystemPrompt,\n isSystemPromptTemplate,\n normalizeActionCoords,\n sleep,\n} from '@ui-tars-test/shared/utils';\nimport { GUI_ADAPTED_TOOL_NAME } from './constants';\nimport { convertToAgentUIAction, createGUIErrorResponse } from './utils';\nimport { defaultNormalizeCoords, defaultDetailCalculator } from './defaultImpls';\n\nconst defaultLogger = new ConsoleLogger('[GUIAgent]', LogLevel.DEBUG);\n\nexport class GUIAgent<T extends Operator> extends BaseGUIAgent {\n static label = 'GUI Agent';\n\n private operator: Operator | undefined;\n private normalizeCoordinates: NormalizeCoordinates;\n private detailCalculator: ImageDetailCalculator;\n private loopIntervalInMs: number;\n\n constructor(config: GUIAgentConfig<T>) {\n const {\n operator,\n model,\n systemPrompt,\n customeActionParser,\n normalizeCoordinates,\n detailCalculator,\n maxLoopCount,\n loopIntervalInMs = 500,\n } = config;\n let finalSystemPrompt = SYSTEM_PROMPT;\n if (typeof systemPrompt === 'string') {\n finalSystemPrompt = systemPrompt;\n } else if (Array.isArray(systemPrompt)) {\n finalSystemPrompt = systemPrompt\n .map((p) => (typeof p === 'string' ? p : p.content))\n .join('\\n\\n');\n } else if (systemPrompt && isSystemPromptTemplate(systemPrompt)) {\n finalSystemPrompt = assembleSystemPrompt(systemPrompt, operator.getSupportedActions());\n }\n defaultLogger.debug('final instructions for sp:', finalSystemPrompt);\n\n // Create a adapted ToolCallEngine constructor that captures the customeActionParser\n const AdaptedToolCallEngine = class extends GUIAgentToolCallEngine {\n constructor() {\n super(customeActionParser);\n }\n };\n\n super({\n name: GUIAgent.label,\n instructions: finalSystemPrompt,\n tools: [],\n toolCallEngine: AdaptedToolCallEngine,\n model: model,\n ...(maxLoopCount && { maxIterations: maxLoopCount }),\n logLevel: LogLevel.DEBUG,\n });\n this.operator = operator;\n this.normalizeCoordinates = normalizeCoordinates ?? defaultNormalizeCoords;\n // Default detail calculator implementation\n this.detailCalculator = detailCalculator ?? defaultDetailCalculator;\n this.loopIntervalInMs = loopIntervalInMs;\n this.logger = this.logger.spawn('[GUIAgent]');\n }\n\n async initialize() {\n // Register the GUI tool\n this.registerTool(\n new Tool({\n id: GUI_ADAPTED_TOOL_NAME,\n description: 'operator tool',\n parameters: {}, // no need to pass parameters\n function: async (input) => {\n this.logger.log(`${GUI_ADAPTED_TOOL_NAME} input:`, input);\n if (!this.operator) {\n return createGUIErrorResponse(input.action, 'Operator not initialized');\n }\n if (input.errorMessage) {\n return createGUIErrorResponse(input.action, input.errorMessage);\n }\n // normalize coordinates\n if (input.operator_action) {\n input.operator_action = normalizeActionCoords(\n input.operator_action,\n this.normalizeCoordinates,\n );\n }\n this.logger.info('action to execute:', JSON.stringify(input.operator_action));\n const result = await this.operator!.doExecute({\n actions: [input.operator_action],\n });\n if (result.errorMessage) {\n return createGUIErrorResponse(input.action, result.errorMessage);\n }\n // return { action: input.action, status: 'success', result };\n return {\n success: true,\n action: input.action,\n normalizedAction: convertToAgentUIAction(input.operator_action),\n observation: undefined, // Reserved for future implementation\n };\n },\n }),\n );\n super.initialize();\n }\n\n async onLLMRequest(id: string, payload: LLMRequestHookPayload): Promise<void> {\n try {\n const safeStringify = (obj: unknown, max = 800): string => {\n try {\n const s = JSON.stringify(obj);\n return s.length > max ? s.slice(0, max) + '…(truncated)' : s;\n } catch {\n return '[unserializable]';\n }\n };\n\n const req = payload?.request;\n const messages = req && Array.isArray(req.messages) ? req.messages : [];\n const model = req && typeof req.model === 'string' ? req.model : 'unknown';\n\n const hasImages = (() => {\n try {\n let cnt = 0;\n for (const m of messages as Array<{ content?: unknown }>) {\n const content = m?.content;\n if (Array.isArray(content)) {\n for (const part of content as Array<{ type?: string }>) {\n if (part?.type === 'image_url') cnt++;\n }\n }\n }\n return cnt;\n } catch {\n return undefined as unknown as number | undefined;\n }\n })();\n\n const summary = {\n id,\n model,\n messagesCount: messages.length,\n hasImages,\n };\n\n this.logger.info('[GUIAgent] onLLMRequest summary:', safeStringify(summary));\n\n const firstMsg = messages[0];\n if (firstMsg) {\n this.logger.debug('[GUIAgent] onLLMRequest first message:', safeStringify(firstMsg, 1200));\n }\n } catch (e) {\n this.logger.error('[GUIAgent] onLLMRequest logging failed:', e);\n }\n }\n\n async onEachAgentLoopStart(sessionId: string) {\n this.logger.info('onEachAgentLoopStart', sessionId);\n }\n\n async onAgentLoopEnd(id: string): Promise<void> {\n // await this.browserOperator.cleanup();\n }\n\n async onBeforeToolCall(\n id: string,\n toolCall: { toolCallId: string; name: string },\n args: unknown,\n ) {\n return args;\n }\n\n async onAfterToolCall(\n id: string,\n toolCall: { toolCallId: string; name: string },\n result: unknown,\n ): Promise<unknown> {\n this.logger.info('onAfterToolCall toolCall', JSON.stringify(toolCall));\n\n if (toolCall.name !== GUI_ADAPTED_TOOL_NAME) {\n this.logger.info('onAfterToolCall: skipping screenshot');\n return;\n }\n\n await sleep(this.loopIntervalInMs);\n\n const output = await this.operator!.doScreenshot();\n if (!output) {\n this.logger.error('Failed to get screenshot');\n return;\n }\n\n const base64Tool = new Base64ImageParser(output.base64);\n const base64Uri = base64Tool.getDataUri();\n if (!base64Uri) {\n this.logger.error('Failed to get base64 image uri');\n return;\n }\n\n const { width: imageWidth, height: imageHeight } = base64Tool.getDimensions() || {\n width: -1,\n height: -1,\n };\n\n const content: ChatCompletionContentPart[] = [\n {\n type: 'image_url',\n image_url: {\n url: base64Uri,\n detail: this.detailCalculator(imageWidth, imageHeight),\n },\n },\n ];\n\n if (output?.url) {\n content.push({\n type: 'text',\n text: `The current page's url: ${output.url}`,\n });\n }\n\n const eventStream = this.getEventStream();\n const events = eventStream.getEvents();\n this.logger.info('onAfterToolCall events length:', events.length);\n\n const event = eventStream.createEvent('environment_input', {\n description: 'Browser Screenshot',\n content,\n metadata: {\n type: 'screenshot',\n url: output?.url,\n },\n });\n eventStream.sendEvent(event);\n return result;\n }\n}\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","defaultLogger","ConsoleLogger","LogLevel","GUIAgent","BaseGUIAgent","Tool","GUI_ADAPTED_TOOL_NAME","input","createGUIErrorResponse","normalizeActionCoords","JSON","result","convertToAgentUIAction","undefined","id","payload","safeStringify","max","s","req","messages","Array","model","hasImages","cnt","m","content","part","summary","firstMsg","e","sessionId","toolCall","args","sleep","output","base64Tool","Base64ImageParser","base64Uri","imageWidth","imageHeight","eventStream","events","event","config","operator","systemPrompt","customeActionParser","normalizeCoordinates","detailCalculator","maxLoopCount","loopIntervalInMs","finalSystemPrompt","SYSTEM_PROMPT","p","isSystemPromptTemplate","assembleSystemPrompt","AdaptedToolCallEngine","GUIAgentToolCallEngine","defaultNormalizeCoords","defaultDetailCalculator"],"mappings":";;;;;;;IAAAA,oBAAoB,CAAC,GAAG,CAAC,UAASC;QACjC,IAAI,IAAIC,OAAOD,WACR,IAAGD,oBAAoB,CAAC,CAACC,YAAYC,QAAQ,CAACF,oBAAoB,CAAC,CAAC,UAASE,MACzEC,OAAO,cAAc,CAAC,UAASD,KAAK;YAAE,YAAY;YAAM,KAAKD,UAA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A,AAAAA,EAAqBV,cAAcD,SAAS,mBAAmB;QAErF7C,cAAc,KAAK,CAAC,8BAA8BoD;QAGlD,MAAMK,wBAAwB,cAAcC,2CAAAA,sBAAsBA;YAChE,aAAc;gBACZ,KAAK,CAACX;YACR;QACF;QAEA,KAAK,CAAC;YACJ,MAAM5C,SAAS,KAAK;YACpB,cAAciD;YACd,OAAO,EAAE;YACT,gBAAgBK;YAChB,OAAOnC;YACP,GAAI4B,gBAAgB;gBAAE,eAAeA;YAAa,CAAC;YACnD,UAAUhD,sBAAAA,QAAAA,CAAAA,KAAc;QAC1B,IA3CF,uBAAQ,YAAR,SACA,uBAAQ,wBAAR,SACA,uBAAQ,oBAAR,SACA,uBAAQ,oBAAR;QAyCE,IAAI,CAAC,QAAQ,GAAG2C;QAChB,IAAI,CAAC,oBAAoB,GAAGG,wBAAwBW,yCAAAA,sBAAsBA;QAE1E,IAAI,CAAC,gBAAgB,GAAGV,oBAAoBW,yCAAAA,uBAAuBA;QACnE,IAAI,CAAC,gBAAgB,GAAGT;QACxB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;IAClC;AA8KF;AAlOE,iBADWhD,UACJ,SAAQ"}
|
|
1
|
+
{"version":3,"file":"GUIAgent.js","sources":["webpack://@ui-tars-test/agent-sdk/webpack/runtime/define_property_getters","webpack://@ui-tars-test/agent-sdk/webpack/runtime/has_own_property","webpack://@ui-tars-test/agent-sdk/webpack/runtime/make_namespace_object","webpack://@ui-tars-test/agent-sdk/./src/GUIAgent.ts"],"sourcesContent":["__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","/*\n * Copyright (c) 2025 Bytedance, Inc. and its affiliates.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n LLMRequestHookPayload,\n ChatCompletionContentPart,\n LogLevel,\n Tool,\n ConsoleLogger,\n} from '@ui-tars-test/tarko-agent';\nimport { GUIAgentToolCallEngine } from './ToolCallEngine';\nimport { SYSTEM_PROMPT } from './prompts';\nimport { Base64ImageParser } from '@agent-infra/media-utils';\nimport { Operator, BaseGUIAgent } from '@ui-tars-test/shared/base';\nimport {\n GUIAgentConfig,\n NormalizeCoordinates,\n ImageDetailCalculator,\n} from '@ui-tars-test/shared/types';\nimport {\n assembleSystemPrompt,\n isSystemPromptTemplate,\n normalizeActionCoords,\n sleep,\n} from '@ui-tars-test/shared/utils';\nimport { GUI_ADAPTED_TOOL_NAME } from './constants';\nimport { convertToAgentUIAction, createGUIErrorResponse } from './utils';\nimport { defaultNormalizeCoords, defaultDetailCalculator } from './defaultImpls';\n\nconst defaultLogger = new ConsoleLogger('[GUIAgent]', LogLevel.DEBUG);\n\nexport class GUIAgent<T extends Operator> extends BaseGUIAgent {\n static label = 'GUI Agent';\n\n private operator: Operator | undefined;\n private normalizeCoordinates: NormalizeCoordinates;\n private detailCalculator: ImageDetailCalculator;\n private loopIntervalInMs: number;\n\n constructor(config: GUIAgentConfig<T>) {\n const {\n operator,\n model,\n systemPrompt,\n customeActionParser,\n normalizeCoordinates,\n detailCalculator,\n maxLoopCount,\n loopIntervalInMs = 500,\n } = config;\n let finalSystemPrompt = SYSTEM_PROMPT;\n if (typeof systemPrompt === 'string') {\n finalSystemPrompt = systemPrompt;\n } else if (Array.isArray(systemPrompt)) {\n finalSystemPrompt = systemPrompt\n .map((p) => (typeof p === 'string' ? p : p.content))\n .join('\\n\\n');\n } else if (systemPrompt && isSystemPromptTemplate(systemPrompt)) {\n finalSystemPrompt = assembleSystemPrompt(systemPrompt, operator.getSupportedActions());\n }\n defaultLogger.debug('final instructions for sp:', finalSystemPrompt);\n\n // Create a adapted ToolCallEngine constructor that captures the customeActionParser\n const AdaptedToolCallEngine = class extends GUIAgentToolCallEngine {\n constructor() {\n super(customeActionParser);\n }\n };\n\n super({\n name: GUIAgent.label,\n instructions: finalSystemPrompt,\n tools: [],\n toolCallEngine: AdaptedToolCallEngine,\n model: model,\n ...(maxLoopCount && { maxIterations: maxLoopCount }),\n logLevel: LogLevel.DEBUG,\n });\n this.operator = operator;\n this.normalizeCoordinates = normalizeCoordinates ?? defaultNormalizeCoords;\n // Default detail calculator implementation\n this.detailCalculator = detailCalculator ?? defaultDetailCalculator;\n this.loopIntervalInMs = loopIntervalInMs;\n this.logger = this.logger.spawn('[GUIAgent]');\n }\n\n async initialize() {\n // Register the GUI tool\n this.registerTool(\n new Tool({\n id: GUI_ADAPTED_TOOL_NAME,\n description: 'operator tool',\n parameters: {}, // no need to pass parameters\n function: async (input) => {\n this.logger.log(`${GUI_ADAPTED_TOOL_NAME} input:`, input);\n if (!this.operator) {\n return createGUIErrorResponse(input.action, 'Operator not initialized');\n }\n if (input.errorMessage) {\n return createGUIErrorResponse(input.action, input.errorMessage);\n }\n // normalize coordinates\n if (input.operator_action) {\n input.operator_action = normalizeActionCoords(\n input.operator_action,\n this.normalizeCoordinates,\n );\n }\n this.logger.info('action to execute:', JSON.stringify(input.operator_action));\n const result = await this.operator!.doExecute({\n actions: [input.operator_action],\n });\n if (result.errorMessage) {\n return createGUIErrorResponse(input.action, result.errorMessage);\n }\n // return { action: input.action, status: 'success', result };\n return {\n success: true,\n action: input.action,\n normalizedAction: convertToAgentUIAction(input.operator_action),\n observation: undefined, // Reserved for future implementation\n };\n },\n }),\n );\n super.initialize();\n }\n\n async onLLMRequest(id: string, payload: LLMRequestHookPayload): Promise<void> {\n try {\n const safeStringify = (obj: unknown, max = 800): string => {\n try {\n const s = JSON.stringify(obj);\n return s.length > max ? s.slice(0, max) + '…(truncated)' : s;\n } catch {\n return '[unserializable]';\n }\n };\n\n const req = payload?.request;\n const messages = req && Array.isArray(req.messages) ? req.messages : [];\n const model = req && typeof req.model === 'string' ? req.model : 'unknown';\n\n const hasImages = (() => {\n try {\n let cnt = 0;\n for (const m of messages as Array<{ content?: unknown }>) {\n const content = m?.content;\n if (Array.isArray(content)) {\n for (const part of content as Array<{ type?: string }>) {\n if (part?.type === 'image_url') cnt++;\n }\n }\n }\n return cnt;\n } catch {\n return undefined as unknown as number | undefined;\n }\n })();\n\n const summary = {\n id,\n model,\n messagesCount: messages.length,\n hasImages,\n };\n\n this.logger.info('[GUIAgent] onLLMRequest summary:', safeStringify(summary));\n\n const firstMsg = messages[0];\n if (firstMsg) {\n this.logger.debug('[GUIAgent] onLLMRequest first message:', safeStringify(firstMsg, 1200));\n }\n } catch (e) {\n this.logger.error('[GUIAgent] onLLMRequest logging failed:', e);\n }\n }\n\n async onEachAgentLoopStart(sessionId: string) {\n this.logger.info('onEachAgentLoopStart', sessionId);\n }\n\n async onAgentLoopEnd(id: string): Promise<void> {\n // await this.browserOperator.cleanup();\n }\n\n async onBeforeToolCall(\n id: string,\n toolCall: { toolCallId: string; name: string },\n args: unknown,\n ) {\n return args;\n }\n\n async onAfterToolCall(\n id: string,\n toolCall: { toolCallId: string; name: string },\n result: unknown,\n ): Promise<unknown> {\n this.logger.info('onAfterToolCall toolCall', JSON.stringify(toolCall));\n\n if (toolCall.name !== GUI_ADAPTED_TOOL_NAME) {\n this.logger.info('onAfterToolCall: skipping screenshot');\n return;\n }\n\n await sleep(this.loopIntervalInMs);\n\n const output = await this.operator!.doScreenshot();\n if (!output) {\n this.logger.error('Failed to get screenshot');\n return;\n }\n\n const base64Tool = new Base64ImageParser(output.base64);\n const base64Uri = base64Tool.getDataUri();\n if (!base64Uri) {\n this.logger.error('Failed to get base64 image uri');\n return;\n }\n\n const { width: imageWidth, height: imageHeight } = base64Tool.getDimensions() || {\n width: -1,\n height: -1,\n };\n\n const content: ChatCompletionContentPart[] = [\n {\n type: 'image_url',\n image_url: {\n url: base64Uri,\n detail: this.detailCalculator(imageWidth, imageHeight),\n },\n },\n ];\n\n if (output?.url) {\n content.push({\n type: 'text',\n text: `The current page's url: ${output.url}`,\n });\n }\n\n const eventStream = this.getEventStream();\n const events = eventStream.getEvents();\n this.logger.info('onAfterToolCall events length:', events.length);\n\n const event = eventStream.createEvent('environment_input', {\n description: 'Browser Screenshot',\n content,\n metadata: {\n type: 'screenshot',\n url: output?.url,\n },\n });\n eventStream.sendEvent(event);\n return result;\n }\n}\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","defaultLogger","ConsoleLogger","LogLevel","GUIAgent","BaseGUIAgent","Tool","GUI_ADAPTED_TOOL_NAME","input","createGUIErrorResponse","normalizeActionCoords","JSON","result","convertToAgentUIAction","undefined","id","payload","safeStringify","max","s","req","messages","Array","model","hasImages","cnt","m","content","part","summary","firstMsg","e","sessionId","toolCall","args","sleep","output","base64Tool","Base64ImageParser","base64Uri","imageWidth","imageHeight","eventStream","events","event","config","operator","systemPrompt","customeActionParser","normalizeCoordinates","detailCalculator","maxLoopCount","loopIntervalInMs","finalSystemPrompt","SYSTEM_PROMPT","p","isSystemPromptTemplate","assembleSystemPrompt","AdaptedToolCallEngine","GUIAgentToolCallEngine","defaultNormalizeCoords","defaultDetailCalculator"],"mappings":";;;;;;;IAAAA,oBAAoB,CAAC,GAAG,CAAC,UAASC;QACjC,IAAI,IAAIC,OAAOD,WACR,IAAGD,oBAAoB,CAAC,CAACC,YAAYC,QAAQ,CAACF,oBAAoB,CAAC,CAAC,UAASE,MACzEC,OAAO,cAAc,CAAC,UAASD,KAAK;YAAE,YAAY;YAAM,KAAKD,UAAU,CAACC,IAAI;QAAC;IAGzF;;;ICNAF,oBAAoB,CAAC,GAAG,CAACI,KAAKC,OAAUF,OAAO,SAAS,CAAC,cAAc,CAAC,IAAI,CAACC,KAAKC;;;ICClFL,oBAAoB,CAAC,GAAG,CAAC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ACF;QAEA,KAAK,CAAC;YACJ,MAAM5C,SAAS,KAAK;YACpB,cAAciD;YACd,OAAO,EAAE;YACT,gBAAgBK;YAChB,OAAOnC;YACP,GAAI4B,gBAAgB;gBAAE,eAAeA;YAAa,CAAC;YACnD,UAAUhD,4BAAAA,QAAAA,CAAAA,KAAc;QAC1B,IA3CF,uBAAQ,YAAR,SACA,uBAAQ,wBAAR,SACA,uBAAQ,oBAAR,SACA,uBAAQ,oBAAR;QAyCE,IAAI,CAAC,QAAQ,GAAG2C;QAChB,IAAI,CAAC,oBAAoB,GAAGG,wBAAwBW,yCAAAA,sBAAsBA;QAE1E,IAAI,CAAC,gBAAgB,GAAGV,oBAAoBW,yCAAAA,uBAAuBA;QACnE,IAAI,CAAC,gBAAgB,GAAGT;QACxB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;IAClC;AA8KF;AAlOE,iBADWhD,UACJ,SAAQ"}
|
package/dist/GUIAgent.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright (c) 2025 Bytedance, Inc. and its affiliates.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
|
-
import { ConsoleLogger, LogLevel, Tool } from "@tarko
|
|
5
|
+
import { ConsoleLogger, LogLevel, Tool } from "@ui-tars-test/tarko-agent";
|
|
6
6
|
import { GUIAgentToolCallEngine } from "./ToolCallEngine.mjs";
|
|
7
7
|
import { SYSTEM_PROMPT } from "./prompts.mjs";
|
|
8
8
|
import { Base64ImageParser } from "@agent-infra/media-utils";
|
package/dist/GUIAgent.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GUIAgent.mjs","sources":["webpack://@ui-tars-test/agent-sdk/./src/GUIAgent.ts"],"sourcesContent":["/*\n * Copyright (c) 2025 Bytedance, Inc. and its affiliates.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n LLMRequestHookPayload,\n ChatCompletionContentPart,\n LogLevel,\n Tool,\n ConsoleLogger,\n} from '@tarko/agent';\nimport { GUIAgentToolCallEngine } from './ToolCallEngine';\nimport { SYSTEM_PROMPT } from './prompts';\nimport { Base64ImageParser } from '@agent-infra/media-utils';\nimport { Operator, BaseGUIAgent } from '@ui-tars-test/shared/base';\nimport {\n GUIAgentConfig,\n NormalizeCoordinates,\n ImageDetailCalculator,\n} from '@ui-tars-test/shared/types';\nimport {\n assembleSystemPrompt,\n isSystemPromptTemplate,\n normalizeActionCoords,\n sleep,\n} from '@ui-tars-test/shared/utils';\nimport { GUI_ADAPTED_TOOL_NAME } from './constants';\nimport { convertToAgentUIAction, createGUIErrorResponse } from './utils';\nimport { defaultNormalizeCoords, defaultDetailCalculator } from './defaultImpls';\n\nconst defaultLogger = new ConsoleLogger('[GUIAgent]', LogLevel.DEBUG);\n\nexport class GUIAgent<T extends Operator> extends BaseGUIAgent {\n static label = 'GUI Agent';\n\n private operator: Operator | undefined;\n private normalizeCoordinates: NormalizeCoordinates;\n private detailCalculator: ImageDetailCalculator;\n private loopIntervalInMs: number;\n\n constructor(config: GUIAgentConfig<T>) {\n const {\n operator,\n model,\n systemPrompt,\n customeActionParser,\n normalizeCoordinates,\n detailCalculator,\n maxLoopCount,\n loopIntervalInMs = 500,\n } = config;\n let finalSystemPrompt = SYSTEM_PROMPT;\n if (typeof systemPrompt === 'string') {\n finalSystemPrompt = systemPrompt;\n } else if (Array.isArray(systemPrompt)) {\n finalSystemPrompt = systemPrompt\n .map((p) => (typeof p === 'string' ? p : p.content))\n .join('\\n\\n');\n } else if (systemPrompt && isSystemPromptTemplate(systemPrompt)) {\n finalSystemPrompt = assembleSystemPrompt(systemPrompt, operator.getSupportedActions());\n }\n defaultLogger.debug('final instructions for sp:', finalSystemPrompt);\n\n // Create a adapted ToolCallEngine constructor that captures the customeActionParser\n const AdaptedToolCallEngine = class extends GUIAgentToolCallEngine {\n constructor() {\n super(customeActionParser);\n }\n };\n\n super({\n name: GUIAgent.label,\n instructions: finalSystemPrompt,\n tools: [],\n toolCallEngine: AdaptedToolCallEngine,\n model: model,\n ...(maxLoopCount && { maxIterations: maxLoopCount }),\n logLevel: LogLevel.DEBUG,\n });\n this.operator = operator;\n this.normalizeCoordinates = normalizeCoordinates ?? defaultNormalizeCoords;\n // Default detail calculator implementation\n this.detailCalculator = detailCalculator ?? defaultDetailCalculator;\n this.loopIntervalInMs = loopIntervalInMs;\n this.logger = this.logger.spawn('[GUIAgent]');\n }\n\n async initialize() {\n // Register the GUI tool\n this.registerTool(\n new Tool({\n id: GUI_ADAPTED_TOOL_NAME,\n description: 'operator tool',\n parameters: {}, // no need to pass parameters\n function: async (input) => {\n this.logger.log(`${GUI_ADAPTED_TOOL_NAME} input:`, input);\n if (!this.operator) {\n return createGUIErrorResponse(input.action, 'Operator not initialized');\n }\n if (input.errorMessage) {\n return createGUIErrorResponse(input.action, input.errorMessage);\n }\n // normalize coordinates\n if (input.operator_action) {\n input.operator_action = normalizeActionCoords(\n input.operator_action,\n this.normalizeCoordinates,\n );\n }\n this.logger.info('action to execute:', JSON.stringify(input.operator_action));\n const result = await this.operator!.doExecute({\n actions: [input.operator_action],\n });\n if (result.errorMessage) {\n return createGUIErrorResponse(input.action, result.errorMessage);\n }\n // return { action: input.action, status: 'success', result };\n return {\n success: true,\n action: input.action,\n normalizedAction: convertToAgentUIAction(input.operator_action),\n observation: undefined, // Reserved for future implementation\n };\n },\n }),\n );\n super.initialize();\n }\n\n async onLLMRequest(id: string, payload: LLMRequestHookPayload): Promise<void> {\n try {\n const safeStringify = (obj: unknown, max = 800): string => {\n try {\n const s = JSON.stringify(obj);\n return s.length > max ? s.slice(0, max) + '…(truncated)' : s;\n } catch {\n return '[unserializable]';\n }\n };\n\n const req = payload?.request;\n const messages = req && Array.isArray(req.messages) ? req.messages : [];\n const model = req && typeof req.model === 'string' ? req.model : 'unknown';\n\n const hasImages = (() => {\n try {\n let cnt = 0;\n for (const m of messages as Array<{ content?: unknown }>) {\n const content = m?.content;\n if (Array.isArray(content)) {\n for (const part of content as Array<{ type?: string }>) {\n if (part?.type === 'image_url') cnt++;\n }\n }\n }\n return cnt;\n } catch {\n return undefined as unknown as number | undefined;\n }\n })();\n\n const summary = {\n id,\n model,\n messagesCount: messages.length,\n hasImages,\n };\n\n this.logger.info('[GUIAgent] onLLMRequest summary:', safeStringify(summary));\n\n const firstMsg = messages[0];\n if (firstMsg) {\n this.logger.debug('[GUIAgent] onLLMRequest first message:', safeStringify(firstMsg, 1200));\n }\n } catch (e) {\n this.logger.error('[GUIAgent] onLLMRequest logging failed:', e);\n }\n }\n\n async onEachAgentLoopStart(sessionId: string) {\n this.logger.info('onEachAgentLoopStart', sessionId);\n }\n\n async onAgentLoopEnd(id: string): Promise<void> {\n // await this.browserOperator.cleanup();\n }\n\n async onBeforeToolCall(\n id: string,\n toolCall: { toolCallId: string; name: string },\n args: unknown,\n ) {\n return args;\n }\n\n async onAfterToolCall(\n id: string,\n toolCall: { toolCallId: string; name: string },\n result: unknown,\n ): Promise<unknown> {\n this.logger.info('onAfterToolCall toolCall', JSON.stringify(toolCall));\n\n if (toolCall.name !== GUI_ADAPTED_TOOL_NAME) {\n this.logger.info('onAfterToolCall: skipping screenshot');\n return;\n }\n\n await sleep(this.loopIntervalInMs);\n\n const output = await this.operator!.doScreenshot();\n if (!output) {\n this.logger.error('Failed to get screenshot');\n return;\n }\n\n const base64Tool = new Base64ImageParser(output.base64);\n const base64Uri = base64Tool.getDataUri();\n if (!base64Uri) {\n this.logger.error('Failed to get base64 image uri');\n return;\n }\n\n const { width: imageWidth, height: imageHeight } = base64Tool.getDimensions() || {\n width: -1,\n height: -1,\n };\n\n const content: ChatCompletionContentPart[] = [\n {\n type: 'image_url',\n image_url: {\n url: base64Uri,\n detail: this.detailCalculator(imageWidth, imageHeight),\n },\n },\n ];\n\n if (output?.url) {\n content.push({\n type: 'text',\n text: `The current page's url: ${output.url}`,\n });\n }\n\n const eventStream = this.getEventStream();\n const events = eventStream.getEvents();\n this.logger.info('onAfterToolCall events length:', events.length);\n\n const event = eventStream.createEvent('environment_input', {\n description: 'Browser Screenshot',\n content,\n metadata: {\n type: 'screenshot',\n url: output?.url,\n },\n });\n eventStream.sendEvent(event);\n return result;\n }\n}\n"],"names":["defaultLogger","ConsoleLogger","LogLevel","GUIAgent","BaseGUIAgent","Tool","GUI_ADAPTED_TOOL_NAME","input","createGUIErrorResponse","normalizeActionCoords","JSON","result","convertToAgentUIAction","undefined","id","payload","safeStringify","obj","max","s","req","messages","Array","model","hasImages","cnt","m","content","part","summary","firstMsg","e","sessionId","toolCall","args","sleep","output","base64Tool","Base64ImageParser","base64Uri","imageWidth","imageHeight","eventStream","events","event","config","operator","systemPrompt","customeActionParser","normalizeCoordinates","detailCalculator","maxLoopCount","loopIntervalInMs","finalSystemPrompt","SYSTEM_PROMPT","p","isSystemPromptTemplate","assembleSystemPrompt","AdaptedToolCallEngine","GUIAgentToolCallEngine","defaultNormalizeCoords","defaultDetailCalculator"],"mappings":";;;;;;;;;;;;;AAGC;;;;;;;;;;AA2BD,MAAMA,gBAAgB,IAAIC,cAAc,cAAcC,SAAS,KAAK;AAE7D,MAAMC,iBAAqCC;IAuDhD,MAAM,aAAa;QAEjB,IAAI,CAAC,YAAY,CACf,IAAIC,KAAK;YACP,IAAIC;YACJ,aAAa;YACb,YAAY,CAAC;YACb,UAAU,OAAOC;gBACf,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAGD,sBAAsB,OAAO,CAAC,EAAEC;gBACnD,IAAI,CAAC,IAAI,CAAC,QAAQ,EAChB,OAAOC,uBAAuBD,MAAM,MAAM,EAAE;gBAE9C,IAAIA,MAAM,YAAY,EACpB,OAAOC,uBAAuBD,MAAM,MAAM,EAAEA,MAAM,YAAY;gBAGhE,IAAIA,MAAM,eAAe,EACvBA,MAAM,eAAe,GAAGE,sBACtBF,MAAM,eAAe,EACrB,IAAI,CAAC,oBAAoB;gBAG7B,IAAI,CAAC,MAAM,CAAC,IA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M7C,SAAS,KAAK;YACpB,cAAckD;YACd,OAAO,EAAE;YACT,gBAAgBK;YAChB,OAAOnC;YACP,GAAI4B,gBAAgB;gBAAE,eAAeA;YAAa,CAAC;YACnD,UAAUjD,SAAS,KAAK;QAC1B,IA3CF,uBAAQ,YAAR,SACA,uBAAQ,wBAAR,SACA,uBAAQ,oBAAR,SACA,uBAAQ,oBAAR;QAyCE,IAAI,CAAC,QAAQ,GAAG4C;QAChB,IAAI,CAAC,oBAAoB,GAAGG,wBAAwBW;QAEpD,IAAI,CAAC,gBAAgB,GAAGV,oBAAoBW;QAC5C,IAAI,CAAC,gBAAgB,GAAGT;QACxB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;IAClC;AA8KF;AAlOE,iBADWjD,UACJ,SAAQ"}
|
|
1
|
+
{"version":3,"file":"GUIAgent.mjs","sources":["webpack://@ui-tars-test/agent-sdk/./src/GUIAgent.ts"],"sourcesContent":["/*\n * Copyright (c) 2025 Bytedance, Inc. and its affiliates.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n LLMRequestHookPayload,\n ChatCompletionContentPart,\n LogLevel,\n Tool,\n ConsoleLogger,\n} from '@ui-tars-test/tarko-agent';\nimport { GUIAgentToolCallEngine } from './ToolCallEngine';\nimport { SYSTEM_PROMPT } from './prompts';\nimport { Base64ImageParser } from '@agent-infra/media-utils';\nimport { Operator, BaseGUIAgent } from '@ui-tars-test/shared/base';\nimport {\n GUIAgentConfig,\n NormalizeCoordinates,\n ImageDetailCalculator,\n} from '@ui-tars-test/shared/types';\nimport {\n assembleSystemPrompt,\n isSystemPromptTemplate,\n normalizeActionCoords,\n sleep,\n} from '@ui-tars-test/shared/utils';\nimport { GUI_ADAPTED_TOOL_NAME } from './constants';\nimport { convertToAgentUIAction, createGUIErrorResponse } from './utils';\nimport { defaultNormalizeCoords, defaultDetailCalculator } from './defaultImpls';\n\nconst defaultLogger = new ConsoleLogger('[GUIAgent]', LogLevel.DEBUG);\n\nexport class GUIAgent<T extends Operator> extends BaseGUIAgent {\n static label = 'GUI Agent';\n\n private operator: Operator | undefined;\n private normalizeCoordinates: NormalizeCoordinates;\n private detailCalculator: ImageDetailCalculator;\n private loopIntervalInMs: number;\n\n constructor(config: GUIAgentConfig<T>) {\n const {\n operator,\n model,\n systemPrompt,\n customeActionParser,\n normalizeCoordinates,\n detailCalculator,\n maxLoopCount,\n loopIntervalInMs = 500,\n } = config;\n let finalSystemPrompt = SYSTEM_PROMPT;\n if (typeof systemPrompt === 'string') {\n finalSystemPrompt = systemPrompt;\n } else if (Array.isArray(systemPrompt)) {\n finalSystemPrompt = systemPrompt\n .map((p) => (typeof p === 'string' ? p : p.content))\n .join('\\n\\n');\n } else if (systemPrompt && isSystemPromptTemplate(systemPrompt)) {\n finalSystemPrompt = assembleSystemPrompt(systemPrompt, operator.getSupportedActions());\n }\n defaultLogger.debug('final instructions for sp:', finalSystemPrompt);\n\n // Create a adapted ToolCallEngine constructor that captures the customeActionParser\n const AdaptedToolCallEngine = class extends GUIAgentToolCallEngine {\n constructor() {\n super(customeActionParser);\n }\n };\n\n super({\n name: GUIAgent.label,\n instructions: finalSystemPrompt,\n tools: [],\n toolCallEngine: AdaptedToolCallEngine,\n model: model,\n ...(maxLoopCount && { maxIterations: maxLoopCount }),\n logLevel: LogLevel.DEBUG,\n });\n this.operator = operator;\n this.normalizeCoordinates = normalizeCoordinates ?? defaultNormalizeCoords;\n // Default detail calculator implementation\n this.detailCalculator = detailCalculator ?? defaultDetailCalculator;\n this.loopIntervalInMs = loopIntervalInMs;\n this.logger = this.logger.spawn('[GUIAgent]');\n }\n\n async initialize() {\n // Register the GUI tool\n this.registerTool(\n new Tool({\n id: GUI_ADAPTED_TOOL_NAME,\n description: 'operator tool',\n parameters: {}, // no need to pass parameters\n function: async (input) => {\n this.logger.log(`${GUI_ADAPTED_TOOL_NAME} input:`, input);\n if (!this.operator) {\n return createGUIErrorResponse(input.action, 'Operator not initialized');\n }\n if (input.errorMessage) {\n return createGUIErrorResponse(input.action, input.errorMessage);\n }\n // normalize coordinates\n if (input.operator_action) {\n input.operator_action = normalizeActionCoords(\n input.operator_action,\n this.normalizeCoordinates,\n );\n }\n this.logger.info('action to execute:', JSON.stringify(input.operator_action));\n const result = await this.operator!.doExecute({\n actions: [input.operator_action],\n });\n if (result.errorMessage) {\n return createGUIErrorResponse(input.action, result.errorMessage);\n }\n // return { action: input.action, status: 'success', result };\n return {\n success: true,\n action: input.action,\n normalizedAction: convertToAgentUIAction(input.operator_action),\n observation: undefined, // Reserved for future implementation\n };\n },\n }),\n );\n super.initialize();\n }\n\n async onLLMRequest(id: string, payload: LLMRequestHookPayload): Promise<void> {\n try {\n const safeStringify = (obj: unknown, max = 800): string => {\n try {\n const s = JSON.stringify(obj);\n return s.length > max ? s.slice(0, max) + '…(truncated)' : s;\n } catch {\n return '[unserializable]';\n }\n };\n\n const req = payload?.request;\n const messages = req && Array.isArray(req.messages) ? req.messages : [];\n const model = req && typeof req.model === 'string' ? req.model : 'unknown';\n\n const hasImages = (() => {\n try {\n let cnt = 0;\n for (const m of messages as Array<{ content?: unknown }>) {\n const content = m?.content;\n if (Array.isArray(content)) {\n for (const part of content as Array<{ type?: string }>) {\n if (part?.type === 'image_url') cnt++;\n }\n }\n }\n return cnt;\n } catch {\n return undefined as unknown as number | undefined;\n }\n })();\n\n const summary = {\n id,\n model,\n messagesCount: messages.length,\n hasImages,\n };\n\n this.logger.info('[GUIAgent] onLLMRequest summary:', safeStringify(summary));\n\n const firstMsg = messages[0];\n if (firstMsg) {\n this.logger.debug('[GUIAgent] onLLMRequest first message:', safeStringify(firstMsg, 1200));\n }\n } catch (e) {\n this.logger.error('[GUIAgent] onLLMRequest logging failed:', e);\n }\n }\n\n async onEachAgentLoopStart(sessionId: string) {\n this.logger.info('onEachAgentLoopStart', sessionId);\n }\n\n async onAgentLoopEnd(id: string): Promise<void> {\n // await this.browserOperator.cleanup();\n }\n\n async onBeforeToolCall(\n id: string,\n toolCall: { toolCallId: string; name: string },\n args: unknown,\n ) {\n return args;\n }\n\n async onAfterToolCall(\n id: string,\n toolCall: { toolCallId: string; name: string },\n result: unknown,\n ): Promise<unknown> {\n this.logger.info('onAfterToolCall toolCall', JSON.stringify(toolCall));\n\n if (toolCall.name !== GUI_ADAPTED_TOOL_NAME) {\n this.logger.info('onAfterToolCall: skipping screenshot');\n return;\n }\n\n await sleep(this.loopIntervalInMs);\n\n const output = await this.operator!.doScreenshot();\n if (!output) {\n this.logger.error('Failed to get screenshot');\n return;\n }\n\n const base64Tool = new Base64ImageParser(output.base64);\n const base64Uri = base64Tool.getDataUri();\n if (!base64Uri) {\n this.logger.error('Failed to get base64 image uri');\n return;\n }\n\n const { width: imageWidth, height: imageHeight } = base64Tool.getDimensions() || {\n width: -1,\n height: -1,\n };\n\n const content: ChatCompletionContentPart[] = [\n {\n type: 'image_url',\n image_url: {\n url: base64Uri,\n detail: this.detailCalculator(imageWidth, imageHeight),\n },\n },\n ];\n\n if (output?.url) {\n content.push({\n type: 'text',\n text: `The current page's url: ${output.url}`,\n });\n }\n\n const eventStream = this.getEventStream();\n const events = eventStream.getEvents();\n this.logger.info('onAfterToolCall events length:', events.length);\n\n const event = eventStream.createEvent('environment_input', {\n description: 'Browser Screenshot',\n content,\n metadata: {\n type: 'screenshot',\n url: output?.url,\n },\n });\n eventStream.sendEvent(event);\n return result;\n }\n}\n"],"names":["defaultLogger","ConsoleLogger","LogLevel","GUIAgent","BaseGUIAgent","Tool","GUI_ADAPTED_TOOL_NAME","input","createGUIErrorResponse","normalizeActionCoords","JSON","result","convertToAgentUIAction","undefined","id","payload","safeStringify","obj","max","s","req","messages","Array","model","hasImages","cnt","m","content","part","summary","firstMsg","e","sessionId","toolCall","args","sleep","output","base64Tool","Base64ImageParser","base64Uri","imageWidth","imageHeight","eventStream","events","event","config","operator","systemPrompt","customeActionParser","normalizeCoordinates","detailCalculator","maxLoopCount","loopIntervalInMs","finalSystemPrompt","SYSTEM_PROMPT","p","isSystemPromptTemplate","assembleSystemPrompt","AdaptedToolCallEngine","GUIAgentToolCallEngine","defaultNormalizeCoords","defaultDetailCalculator"],"mappings":";;;;;;;;;;;;;AAGC;;;;;;;;;;AA2BD,MAAMA,gBAAgB,IAAIC,cAAc,cAAcC,SAAS,KAAK;AAE7D,MAAMC,iBAAqCC;IAuDhD,MAAM,aAAa;QAEjB,IAAI,CAAC,YAAY,CACf,IAAIC,KAAK;YACP,IAAIC;YACJ,aAAa;YACb,YAAY,CAAC;YACb,UAAU,OAAOC;gBACf,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAGD,sBAAsB,OAAO,CAAC,EAAEC;gBACnD,IAAI,CAAC,IAAI,CAAC,QAAQ,EAChB,OAAOC,uBAAuBD,MAAM,MAAM,EAAE;gBAE9C,IAAIA,MAAM,YAAY,EACpB,OAAOC,uBAAuBD,MAAM,MAAM,EAAEA,MAAM,YAAY;gBAGhE,IAAIA,MAAM,eAAe,EACvBA,MAAM,eAAe,GAAGE,sBACtBF,MAAM,eAAe,EACrB,IAAI,CAAC,oBAAoB;gBAG7B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,sBAAsBG,KAAK,SAAS,CAACH,MAAM,eAAe;gBAC3E,MAAMI,SAAS,MAAM,IAAI,CAAC,QAAQ,CAAE,SAAS,CAAC;oBAC5C,SAAS;wBAACJ,MAAM,eAAe;qBAAC;gBAClC;gBACA,IAAII,OAAO,YAAY,EACrB,OAAOH,uBAAuBD,MAAM,MAAM,EAAEI,OAAO,YAAY;gBAGjE,OAAO;oBACL,SAAS;oBACT,QAAQJ,MAAM,MAAM;oBACpB,kBAAkBK,uBAAuBL,MAAM,eAAe;oBAC9D,aAAaM;gBACf;YACF;QACF;QAEF,KAAK,CAAC;IACR;IAEA,MAAM,aAAaC,EAAU,EAAEC,OAA8B,EAAiB;QAC5E,IAAI;YACF,MAAMC,gBAAgB,CAACC,KAAcC,MAAM,GAAG;gBAC5C,IAAI;oBACF,MAAMC,IA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Engine.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ToolCallEngine, Tool, ToolCallEnginePrepareRequestContext, ChatCompletionCreateParams, ChatCompletionAssistantMessageParam, ChatCompletionChunk, MultimodalToolCallResult, AgentEventStream, ChatCompletionMessageParam, ParsedModelResponse, StreamProcessingState, StreamChunkResult } from '@tarko
|
|
1
|
+
import { ToolCallEngine, Tool, ToolCallEnginePrepareRequestContext, ChatCompletionCreateParams, ChatCompletionAssistantMessageParam, ChatCompletionChunk, MultimodalToolCallResult, AgentEventStream, ChatCompletionMessageParam, ParsedModelResponse, StreamProcessingState, StreamChunkResult } from '@ui-tars-test/tarko-agent-interface';
|
|
2
2
|
import { CustomActionParser } from '@ui-tars-test/shared/types';
|
|
3
3
|
/**
|
|
4
4
|
* GUIAgentToolCallEngine - Minimal prompt engineering tool call engine
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ToolCallEngine.d.ts","sourceRoot":"","sources":["../src/ToolCallEngine.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,IAAI,EACJ,mCAAmC,EACnC,0BAA0B,EAC1B,mCAAmC,EACnC,mBAAmB,EACnB,wBAAwB,EACxB,gBAAgB,EAChB,0BAA0B,EAE1B,mBAAmB,EACnB,qBAAqB,EACrB,iBAAiB,EAClB,MAAM,
|
|
1
|
+
{"version":3,"file":"ToolCallEngine.d.ts","sourceRoot":"","sources":["../src/ToolCallEngine.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,IAAI,EACJ,mCAAmC,EACnC,0BAA0B,EAC1B,mCAAmC,EACnC,mBAAmB,EACnB,wBAAwB,EACxB,gBAAgB,EAChB,0BAA0B,EAE1B,mBAAmB,EACnB,qBAAqB,EACrB,iBAAiB,EAClB,MAAM,qCAAqC,CAAC;AAK7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAKhE;;;;;;;;;GASG;AACH,qBAAa,sBAAuB,SAAQ,cAAc;IACxD,OAAO,CAAC,kBAAkB,CAAC,CAAqB;gBAEpC,kBAAkB,CAAC,EAAE,kBAAkB;IAKnD;;OAEG;IACH,aAAa,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,MAAM;IAI1D;;;;OAIG;IACH,cAAc,CAAC,OAAO,EAAE,mCAAmC,GAAG,0BAA0B;IAaxF;;;;OAIG;IACH,yBAAyB,IAAI,qBAAqB;IASlD;;;;OAIG;IACH,qBAAqB,CACnB,KAAK,EAAE,mBAAmB,EAC1B,KAAK,EAAE,qBAAqB,GAC3B,iBAAiB;IAsBpB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAI1B;;OAEG;IACH,wBAAwB,CAAC,KAAK,EAAE,qBAAqB,GAAG,mBAAmB;IAiG3E;;;;;OAKG;IACH,+BAA+B,CAC7B,yBAAyB,EAAE,gBAAgB,CAAC,qBAAqB,GAChE,mCAAmC;IAOtC;;;;;OAKG;IACH,qCAAqC,CACnC,eAAe,EAAE,wBAAwB,EAAE,GAC1C,0BAA0B,EAAE;CAchC"}
|
package/dist/ToolCallEngine.js
CHANGED
|
@@ -30,7 +30,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
30
30
|
__webpack_require__.d(__webpack_exports__, {
|
|
31
31
|
GUIAgentToolCallEngine: ()=>GUIAgentToolCallEngine
|
|
32
32
|
});
|
|
33
|
-
const
|
|
33
|
+
const tarko_agent_interface_namespaceObject = require("@ui-tars-test/tarko-agent-interface");
|
|
34
34
|
const action_parser_namespaceObject = require("@ui-tars-test/action-parser");
|
|
35
35
|
const external_constants_js_namespaceObject = require("./constants.js");
|
|
36
36
|
const logger_namespaceObject = require("@agent-infra/logger");
|
|
@@ -47,7 +47,7 @@ function _define_property(obj, key, value) {
|
|
|
47
47
|
}
|
|
48
48
|
const defaultParser = new action_parser_namespaceObject.DefaultActionParser();
|
|
49
49
|
const defaultLogger = new logger_namespaceObject.ConsoleLogger('[GUIAgent:ToolCallEngine]', logger_namespaceObject.LogLevel.DEBUG);
|
|
50
|
-
class GUIAgentToolCallEngine extends
|
|
50
|
+
class GUIAgentToolCallEngine extends tarko_agent_interface_namespaceObject.ToolCallEngine {
|
|
51
51
|
preparePrompt(instructions, tools) {
|
|
52
52
|
return instructions;
|
|
53
53
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ToolCallEngine.js","sources":["webpack://@ui-tars-test/agent-sdk/webpack/runtime/define_property_getters","webpack://@ui-tars-test/agent-sdk/webpack/runtime/has_own_property","webpack://@ui-tars-test/agent-sdk/webpack/runtime/make_namespace_object","webpack://@ui-tars-test/agent-sdk/./src/ToolCallEngine.ts"],"sourcesContent":["__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import {\n ToolCallEngine,\n Tool,\n ToolCallEnginePrepareRequestContext,\n ChatCompletionCreateParams,\n ChatCompletionAssistantMessageParam,\n ChatCompletionChunk,\n MultimodalToolCallResult,\n AgentEventStream,\n ChatCompletionMessageParam,\n ChatCompletionMessageToolCall,\n ParsedModelResponse,\n StreamProcessingState,\n StreamChunkResult,\n} from '@tarko/agent-interface';\nimport { DefaultActionParser } from '@ui-tars-test/action-parser';\nimport { GUI_ADAPTED_TOOL_NAME } from './constants';\nimport { ConsoleLogger, LogLevel } from '@agent-infra/logger';\nimport { serializeAction } from '@ui-tars-test/shared/utils';\nimport { CustomActionParser } from '@ui-tars-test/shared/types';\n\nconst defaultParser = new DefaultActionParser();\nconst defaultLogger = new ConsoleLogger('[GUIAgent:ToolCallEngine]', LogLevel.DEBUG);\n\n/**\n * GUIAgentToolCallEngine - Minimal prompt engineering tool call engine\n *\n * This is the simplest possible implementation of a tool call engine that:\n * 1. Uses prompt engineering to instruct the LLM to output tool calls in a specific format\n * 2. Parses tool calls from LLM response text using simple regex matching\n * 3. Does not support streaming (focuses on core functionality only)\n *\n * Format used: <tool_call>{\"name\": \"tool_name\", \"arguments\": {...}}</tool_call>\n */\nexport class GUIAgentToolCallEngine extends ToolCallEngine {\n private customActionParser?: CustomActionParser;\n\n constructor(customActionParser?: CustomActionParser) {\n super();\n this.customActionParser = customActionParser;\n }\n\n /**\n * Prepare system prompt with tool information and instructions\n */\n preparePrompt(instructions: string, tools: Tool[]): string {\n return instructions;\n }\n\n /**\n * Prepare request parameters for the LLM\n *\n * FIXME: move to base tool call engine.\n */\n prepareRequest(context: ToolCallEnginePrepareRequestContext): ChatCompletionCreateParams {\n defaultLogger.log(\n \"【New Sys Prompt'】 System Prompt:\",\n JSON.stringify(context.messages.find((m) => m.role === 'system')?.content || ''),\n );\n return {\n model: context.model,\n messages: context.messages,\n temperature: context.temperature || 0.7,\n stream: true,\n };\n }\n\n /**\n * Initialize processing state (minimal implementation)\n *\n * FIXME: move to base tool call engine.\n */\n initStreamProcessingState(): StreamProcessingState {\n return {\n contentBuffer: '',\n toolCalls: [],\n reasoningBuffer: '',\n finishReason: null,\n };\n }\n\n /**\n * Process streaming chunks - simply accumulate content\n *\n * FIXME: make it optional\n */\n processStreamingChunk(\n chunk: ChatCompletionChunk,\n state: StreamProcessingState,\n ): StreamChunkResult {\n const delta = chunk.choices[0]?.delta;\n\n // Accumulate content\n if (delta?.content) {\n state.contentBuffer += delta.content;\n }\n\n // Record finish reason\n if (chunk.choices[0]?.finish_reason) {\n state.finishReason = chunk.choices[0].finish_reason;\n }\n\n // Return incremental content without tool call detection during streaming\n return {\n content: delta?.content || '',\n reasoningContent: '',\n hasToolCallUpdate: false,\n toolCalls: [],\n };\n }\n\n /**\n * Generate a tool call ID\n */\n private generateToolCallId(): string {\n return `call_${Date.now()}_${Math.random().toString(36).substring(2, 11)}`;\n }\n\n /**\n * Extract tool calls from complete response text\n */\n finalizeStreamProcessing(state: StreamProcessingState): ParsedModelResponse {\n const fullContent = state.contentBuffer;\n defaultLogger.log(\"【New Sys Prompt'】 Model Response:\", fullContent);\n defaultLogger.log('[finalizeStreamProcessing] fullContent', fullContent);\n\n // Add explicit log to confirm XML parsing intent\n console.log('[CLI DEBUG] [ToolCallEngine] Full model response received:', fullContent);\n\n // Try custom action parser first if available\n let parsedGUIResponse = null;\n if (this.customActionParser) {\n parsedGUIResponse = this.customActionParser(fullContent);\n defaultLogger.log('[finalizeStreamProcessing] Using custom action parser');\n console.log('[CLI DEBUG] [ToolCallEngine] Using custom action parser');\n }\n\n // Fall back to default parser if custom parser is not available or returns null\n if (!parsedGUIResponse) {\n console.log('[CLI DEBUG] [ToolCallEngine] Using default action parser (XML parser)');\n parsedGUIResponse = defaultParser.parsePrediction(fullContent);\n defaultLogger.log('[finalizeStreamProcessing] Using default action parser');\n }\n\n if (parsedGUIResponse) {\n console.log(\n '[CLI DEBUG] [ToolCallEngine] Parsed response:',\n JSON.stringify(parsedGUIResponse, null, 2),\n );\n } else {\n console.log('[CLI DEBUG] [ToolCallEngine] Parsing failed or returned null');\n }\n\n if (!parsedGUIResponse || parsedGUIResponse.errorMessage) {\n return {\n content: '',\n rawContent: fullContent,\n toolCalls: [\n {\n id: this.generateToolCallId(),\n type: 'function',\n function: {\n name: GUI_ADAPTED_TOOL_NAME,\n arguments: JSON.stringify({\n action: '',\n step: '',\n thought: '',\n operator_action: null,\n errorMessage:\n parsedGUIResponse?.errorMessage ?? 'Failed to parse GUI Action from output',\n }),\n },\n },\n ],\n finishReason: 'tool_calls',\n };\n }\n\n const toolCalls: ChatCompletionMessageToolCall[] = [];\n\n let finished = false;\n let finishMessage: string | null = null;\n for (const action of parsedGUIResponse.actions) {\n if (action.type === 'finished') {\n finished = true;\n finishMessage = action.inputs?.content ?? null;\n continue;\n }\n toolCalls.push({\n id: this.generateToolCallId(),\n type: 'function',\n function: {\n name: GUI_ADAPTED_TOOL_NAME,\n arguments: JSON.stringify({\n action: serializeAction(action),\n step: '',\n thought: parsedGUIResponse.reasoningContent ?? '',\n operator_action: action,\n }),\n },\n });\n }\n\n const content = finishMessage ?? '';\n const reasoningContent = parsedGUIResponse.reasoningContent ?? '';\n const contentForWebUI = content.replace(/\\\\n|\\n/g, '<br>');\n const reasoningContentForWebUI = reasoningContent.replace(/\\\\n|\\n/g, '<br>');\n\n // No tool calls found - return regular response\n return {\n content: contentForWebUI,\n rawContent: fullContent,\n reasoningContent: reasoningContentForWebUI,\n toolCalls,\n finishReason: toolCalls.length > 0 && !finished ? 'tool_calls' : 'stop',\n };\n }\n\n /**\n * Build assistant message for conversation history\n * For PE engines, we preserve the raw content including tool call markup\n *\n * FIXME: move to base tool call engine.\n */\n buildHistoricalAssistantMessage(\n currentLoopAssistantEvent: AgentEventStream.AssistantMessageEvent,\n ): ChatCompletionAssistantMessageParam {\n return {\n role: 'assistant',\n content: currentLoopAssistantEvent.rawContent || currentLoopAssistantEvent.content,\n };\n }\n\n /**\n * Build tool result messages as user messages\n * PE engines format tool results as user input for next iteration\n *\n * FIXME: move to base tool call engine.\n */\n buildHistoricalToolCallResultMessages(\n toolCallResults: MultimodalToolCallResult[],\n ): ChatCompletionMessageParam[] {\n return toolCallResults.map((result) => {\n // Extract text content from multimodal result\n const textContent = result.content\n .filter((part) => part.type === 'text')\n .map((part) => (part as { text: string }).text)\n .join('');\n\n return {\n role: 'user',\n content: `Tool \"${result.toolName}\" result:\\n${textContent}`,\n };\n });\n }\n}\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","defaultParser","DefaultActionParser","defaultLogger","ConsoleLogger","LogLevel","GUIAgentToolCallEngine","ToolCallEngine","instructions","tools","context","_context_messages_find","JSON","m","chunk","state","_chunk_choices_","_chunk_choices_1","delta","Date","Math","fullContent","console","parsedGUIResponse","GUI_ADAPTED_TOOL_NAME","toolCalls","finished","finishMessage","action","_action_inputs","serializeAction","content","reasoningContent","contentForWebUI","reasoningContentForWebUI","currentLoopAssistantEvent","toolCallResults","result","textContent","part","customActionParser"],"mappings":";;;;;;;IAAAA,oBAAoB,CAAC,GAAG,CAAC,UAASC;QACjC,IAAI,IAAIC,OAAOD,WACR,IAAGD,oBAAoB,CAAC,CAACC,YAAYC,QAAQ,CAACF,oBAAoB,CAAC,CAAC,UAASE,MACzEC,OAAO,cAAc,CAAC,UAASD,KAAK;YAAE,YAAY;YAAM,KAAKD,UAAU,CAACC,IAAI;QAAC;IAGzF;;;ICNAF,oBAAoB,CAAC,GAAG,CAACI,KAAKC,OAAUF,OAAO,SAAS,CAAC,cAAc,CAAC,IAAI,CAACC,KAAKC;;;ICClFL,oBAAoB,CAAC,GAAG,CAAC;QACxB,IAAG,AAAkB,eAAlB,OAAOM,UAA0BA,OAAO,WAAW,EACrDH,OAAO,cAAc,CAAC,UAASG,OAAO,WAAW,EAAE;YAAE,OAAO;QAAS;QAEtEH,OAAO,cAAc,CAAC,UAAS,cAAc;YAAE,OAAO;QAAK;IAC5D;;;;;;;;;;;;;;;;;;;;;;ACeA,MAAMI,gBAAgB,IAAIC,8BAAAA,mBAAmBA;AAC7C,MAAMC,gBAAgB,IAAIC,uBAAAA,aAAaA,CAAC,6BAA6BC,uBAAAA,QAAAA,CAAAA,KAAc;AAY5E,MAAMC,+BAA+BC,gCAAAA,cAAcA;IAWxD,cAAcC,YAAoB,EAAEC,KAAa,EAAU;QACzD,OAAOD;IACT;IAOA,eAAeE,OAA4C,EAA8B;YAGtEC;QAFjBR,cAAc,GAAG,CACf,8CACAS,KAAK,SAAS,CAACD,AAAAA,SAAAA,CAAAA,yBAAAA,QAAQ,QAAQ,CAAC,IAAI,CAAC,CAACE,IAAMA,AAAW,aAAXA,EAAE,IAAI,CAAa,IAAhDF,KAAAA,IAAAA,u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AASL,kBAAkB,gBAAgB,IAAI;wBAC/C,iBAAiBK;oBACnB;gBACF;YACF;QACF;QAEA,MAAMG,UAAUJ,iBAAiB;QACjC,MAAMK,mBAAmBT,kBAAkB,gBAAgB,IAAI;QAC/D,MAAMU,kBAAkBF,QAAQ,OAAO,CAAC,WAAW;QACnD,MAAMG,2BAA2BF,iBAAiB,OAAO,CAAC,WAAW;QAGrE,OAAO;YACL,SAASC;YACT,YAAYZ;YACZ,kBAAkBa;YAClBT;YACA,cAAcA,UAAU,MAAM,GAAG,KAAK,CAACC,WAAW,eAAe;QACnE;IACF;IAQA,gCACES,yBAAiE,EAC5B;QACrC,OAAO;YACL,MAAM;YACN,SAASA,0BAA0B,UAAU,IAAIA,0BAA0B,OAAO;QACpF;IACF;IAQA,sCACEC,eAA2C,EACb;QAC9B,OAAOA,gBAAgB,GAAG,CAAC,CAACC;YAE1B,MAAMC,cAAcD,OAAO,OAAO,CAC/B,MAAM,CAAC,CAACE,OAASA,AAAc,WAAdA,KAAK,IAAI,EAC1B,GAAG,CAAC,CAACA,OAAUA,KAA0B,IAAI,EAC7C,IAAI,CAAC;YAER,OAAO;gBACL,MAAM;gBACN,SAAS,CAAC,MAAM,EAAEF,OAAO,QAAQ,CAAC,WAAW,EAAEC,aAAa;YAC9D;QACF;IACF;IAzNA,YAAYE,kBAAuC,CAAE;QACnD,KAAK,IAHP,uBAAQ,sBAAR;QAIE,IAAI,CAAC,kBAAkB,GAAGA;IAC5B;AAuNF"}
|
|
1
|
+
{"version":3,"file":"ToolCallEngine.js","sources":["webpack://@ui-tars-test/agent-sdk/webpack/runtime/define_property_getters","webpack://@ui-tars-test/agent-sdk/webpack/runtime/has_own_property","webpack://@ui-tars-test/agent-sdk/webpack/runtime/make_namespace_object","webpack://@ui-tars-test/agent-sdk/./src/ToolCallEngine.ts"],"sourcesContent":["__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import {\n ToolCallEngine,\n Tool,\n ToolCallEnginePrepareRequestContext,\n ChatCompletionCreateParams,\n ChatCompletionAssistantMessageParam,\n ChatCompletionChunk,\n MultimodalToolCallResult,\n AgentEventStream,\n ChatCompletionMessageParam,\n ChatCompletionMessageToolCall,\n ParsedModelResponse,\n StreamProcessingState,\n StreamChunkResult,\n} from '@ui-tars-test/tarko-agent-interface';\nimport { DefaultActionParser } from '@ui-tars-test/action-parser';\nimport { GUI_ADAPTED_TOOL_NAME } from './constants';\nimport { ConsoleLogger, LogLevel } from '@agent-infra/logger';\nimport { serializeAction } from '@ui-tars-test/shared/utils';\nimport { CustomActionParser } from '@ui-tars-test/shared/types';\n\nconst defaultParser = new DefaultActionParser();\nconst defaultLogger = new ConsoleLogger('[GUIAgent:ToolCallEngine]', LogLevel.DEBUG);\n\n/**\n * GUIAgentToolCallEngine - Minimal prompt engineering tool call engine\n *\n * This is the simplest possible implementation of a tool call engine that:\n * 1. Uses prompt engineering to instruct the LLM to output tool calls in a specific format\n * 2. Parses tool calls from LLM response text using simple regex matching\n * 3. Does not support streaming (focuses on core functionality only)\n *\n * Format used: <tool_call>{\"name\": \"tool_name\", \"arguments\": {...}}</tool_call>\n */\nexport class GUIAgentToolCallEngine extends ToolCallEngine {\n private customActionParser?: CustomActionParser;\n\n constructor(customActionParser?: CustomActionParser) {\n super();\n this.customActionParser = customActionParser;\n }\n\n /**\n * Prepare system prompt with tool information and instructions\n */\n preparePrompt(instructions: string, tools: Tool[]): string {\n return instructions;\n }\n\n /**\n * Prepare request parameters for the LLM\n *\n * FIXME: move to base tool call engine.\n */\n prepareRequest(context: ToolCallEnginePrepareRequestContext): ChatCompletionCreateParams {\n defaultLogger.log(\n \"【New Sys Prompt'】 System Prompt:\",\n JSON.stringify(context.messages.find((m) => m.role === 'system')?.content || ''),\n );\n return {\n model: context.model,\n messages: context.messages,\n temperature: context.temperature || 0.7,\n stream: true,\n };\n }\n\n /**\n * Initialize processing state (minimal implementation)\n *\n * FIXME: move to base tool call engine.\n */\n initStreamProcessingState(): StreamProcessingState {\n return {\n contentBuffer: '',\n toolCalls: [],\n reasoningBuffer: '',\n finishReason: null,\n };\n }\n\n /**\n * Process streaming chunks - simply accumulate content\n *\n * FIXME: make it optional\n */\n processStreamingChunk(\n chunk: ChatCompletionChunk,\n state: StreamProcessingState,\n ): StreamChunkResult {\n const delta = chunk.choices[0]?.delta;\n\n // Accumulate content\n if (delta?.content) {\n state.contentBuffer += delta.content;\n }\n\n // Record finish reason\n if (chunk.choices[0]?.finish_reason) {\n state.finishReason = chunk.choices[0].finish_reason;\n }\n\n // Return incremental content without tool call detection during streaming\n return {\n content: delta?.content || '',\n reasoningContent: '',\n hasToolCallUpdate: false,\n toolCalls: [],\n };\n }\n\n /**\n * Generate a tool call ID\n */\n private generateToolCallId(): string {\n return `call_${Date.now()}_${Math.random().toString(36).substring(2, 11)}`;\n }\n\n /**\n * Extract tool calls from complete response text\n */\n finalizeStreamProcessing(state: StreamProcessingState): ParsedModelResponse {\n const fullContent = state.contentBuffer;\n defaultLogger.log(\"【New Sys Prompt'】 Model Response:\", fullContent);\n defaultLogger.log('[finalizeStreamProcessing] fullContent', fullContent);\n\n // Add explicit log to confirm XML parsing intent\n console.log('[CLI DEBUG] [ToolCallEngine] Full model response received:', fullContent);\n\n // Try custom action parser first if available\n let parsedGUIResponse = null;\n if (this.customActionParser) {\n parsedGUIResponse = this.customActionParser(fullContent);\n defaultLogger.log('[finalizeStreamProcessing] Using custom action parser');\n console.log('[CLI DEBUG] [ToolCallEngine] Using custom action parser');\n }\n\n // Fall back to default parser if custom parser is not available or returns null\n if (!parsedGUIResponse) {\n console.log('[CLI DEBUG] [ToolCallEngine] Using default action parser (XML parser)');\n parsedGUIResponse = defaultParser.parsePrediction(fullContent);\n defaultLogger.log('[finalizeStreamProcessing] Using default action parser');\n }\n\n if (parsedGUIResponse) {\n console.log(\n '[CLI DEBUG] [ToolCallEngine] Parsed response:',\n JSON.stringify(parsedGUIResponse, null, 2),\n );\n } else {\n console.log('[CLI DEBUG] [ToolCallEngine] Parsing failed or returned null');\n }\n\n if (!parsedGUIResponse || parsedGUIResponse.errorMessage) {\n return {\n content: '',\n rawContent: fullContent,\n toolCalls: [\n {\n id: this.generateToolCallId(),\n type: 'function',\n function: {\n name: GUI_ADAPTED_TOOL_NAME,\n arguments: JSON.stringify({\n action: '',\n step: '',\n thought: '',\n operator_action: null,\n errorMessage:\n parsedGUIResponse?.errorMessage ?? 'Failed to parse GUI Action from output',\n }),\n },\n },\n ],\n finishReason: 'tool_calls',\n };\n }\n\n const toolCalls: ChatCompletionMessageToolCall[] = [];\n\n let finished = false;\n let finishMessage: string | null = null;\n for (const action of parsedGUIResponse.actions) {\n if (action.type === 'finished') {\n finished = true;\n finishMessage = action.inputs?.content ?? null;\n continue;\n }\n toolCalls.push({\n id: this.generateToolCallId(),\n type: 'function',\n function: {\n name: GUI_ADAPTED_TOOL_NAME,\n arguments: JSON.stringify({\n action: serializeAction(action),\n step: '',\n thought: parsedGUIResponse.reasoningContent ?? '',\n operator_action: action,\n }),\n },\n });\n }\n\n const content = finishMessage ?? '';\n const reasoningContent = parsedGUIResponse.reasoningContent ?? '';\n const contentForWebUI = content.replace(/\\\\n|\\n/g, '<br>');\n const reasoningContentForWebUI = reasoningContent.replace(/\\\\n|\\n/g, '<br>');\n\n // No tool calls found - return regular response\n return {\n content: contentForWebUI,\n rawContent: fullContent,\n reasoningContent: reasoningContentForWebUI,\n toolCalls,\n finishReason: toolCalls.length > 0 && !finished ? 'tool_calls' : 'stop',\n };\n }\n\n /**\n * Build assistant message for conversation history\n * For PE engines, we preserve the raw content including tool call markup\n *\n * FIXME: move to base tool call engine.\n */\n buildHistoricalAssistantMessage(\n currentLoopAssistantEvent: AgentEventStream.AssistantMessageEvent,\n ): ChatCompletionAssistantMessageParam {\n return {\n role: 'assistant',\n content: currentLoopAssistantEvent.rawContent || currentLoopAssistantEvent.content,\n };\n }\n\n /**\n * Build tool result messages as user messages\n * PE engines format tool results as user input for next iteration\n *\n * FIXME: move to base tool call engine.\n */\n buildHistoricalToolCallResultMessages(\n toolCallResults: MultimodalToolCallResult[],\n ): ChatCompletionMessageParam[] {\n return toolCallResults.map((result) => {\n // Extract text content from multimodal result\n const textContent = result.content\n .filter((part) => part.type === 'text')\n .map((part) => (part as { text: string }).text)\n .join('');\n\n return {\n role: 'user',\n content: `Tool \"${result.toolName}\" result:\\n${textContent}`,\n };\n });\n }\n}\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","defaultParser","DefaultActionParser","defaultLogger","ConsoleLogger","LogLevel","GUIAgentToolCallEngine","ToolCallEngine","instructions","tools","context","_context_messages_find","JSON","m","chunk","state","_chunk_choices_","_chunk_choices_1","delta","Date","Math","fullContent","console","parsedGUIResponse","GUI_ADAPTED_TOOL_NAME","toolCalls","finished","finishMessage","action","_action_inputs","serializeAction","content","reasoningContent","contentForWebUI","reasoningContentForWebUI","currentLoopAssistantEvent","toolCallResults","result","textContent","part","customActionParser"],"mappings":";;;;;;;IAAAA,oBAAoB,CAAC,GAAG,CAAC,UAASC;QACjC,IAAI,IAAIC,OAAOD,WACR,IAAGD,oBAAoB,CAAC,CAACC,YAAYC,QAAQ,CAACF,oBAAoB,CAAC,CAAC,UAASE,MACzEC,OAAO,cAAc,CAAC,UAASD,KAAK;YAAE,YAAY;YAAM,KAAKD,UAAU,CAACC,IAAI;QAAC;IAGzF;;;ICNAF,oBAAoB,CAAC,GAAG,CAACI,KAAKC,OAAUF,OAAO,SAAS,CAAC,cAAc,CAAC,IAAI,CAACC,KA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AG,CAAC,CAACC;YAE1B,MAAMC,cAAcD,OAAO,OAAO,CAC/B,MAAM,CAAC,CAACE,OAASA,AAAc,WAAdA,KAAK,IAAI,EAC1B,GAAG,CAAC,CAACA,OAAUA,KAA0B,IAAI,EAC7C,IAAI,CAAC;YAER,OAAO;gBACL,MAAM;gBACN,SAAS,CAAC,MAAM,EAAEF,OAAO,QAAQ,CAAC,WAAW,EAAEC,aAAa;YAC9D;QACF;IACF;IAzNA,YAAYE,kBAAuC,CAAE;QACnD,KAAK,IAHP,uBAAQ,sBAAR;QAIE,IAAI,CAAC,kBAAkB,GAAGA;IAC5B;AAuNF"}
|
package/dist/ToolCallEngine.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright (c) 2025 Bytedance, Inc. and its affiliates.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
|
-
import { ToolCallEngine } from "@tarko
|
|
5
|
+
import { ToolCallEngine } from "@ui-tars-test/tarko-agent-interface";
|
|
6
6
|
import { DefaultActionParser } from "@ui-tars-test/action-parser";
|
|
7
7
|
import { GUI_ADAPTED_TOOL_NAME } from "./constants.mjs";
|
|
8
8
|
import { ConsoleLogger, LogLevel } from "@agent-infra/logger";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ToolCallEngine.mjs","sources":["webpack://@ui-tars-test/agent-sdk/./src/ToolCallEngine.ts"],"sourcesContent":["import {\n ToolCallEngine,\n Tool,\n ToolCallEnginePrepareRequestContext,\n ChatCompletionCreateParams,\n ChatCompletionAssistantMessageParam,\n ChatCompletionChunk,\n MultimodalToolCallResult,\n AgentEventStream,\n ChatCompletionMessageParam,\n ChatCompletionMessageToolCall,\n ParsedModelResponse,\n StreamProcessingState,\n StreamChunkResult,\n} from '@tarko/agent-interface';\nimport { DefaultActionParser } from '@ui-tars-test/action-parser';\nimport { GUI_ADAPTED_TOOL_NAME } from './constants';\nimport { ConsoleLogger, LogLevel } from '@agent-infra/logger';\nimport { serializeAction } from '@ui-tars-test/shared/utils';\nimport { CustomActionParser } from '@ui-tars-test/shared/types';\n\nconst defaultParser = new DefaultActionParser();\nconst defaultLogger = new ConsoleLogger('[GUIAgent:ToolCallEngine]', LogLevel.DEBUG);\n\n/**\n * GUIAgentToolCallEngine - Minimal prompt engineering tool call engine\n *\n * This is the simplest possible implementation of a tool call engine that:\n * 1. Uses prompt engineering to instruct the LLM to output tool calls in a specific format\n * 2. Parses tool calls from LLM response text using simple regex matching\n * 3. Does not support streaming (focuses on core functionality only)\n *\n * Format used: <tool_call>{\"name\": \"tool_name\", \"arguments\": {...}}</tool_call>\n */\nexport class GUIAgentToolCallEngine extends ToolCallEngine {\n private customActionParser?: CustomActionParser;\n\n constructor(customActionParser?: CustomActionParser) {\n super();\n this.customActionParser = customActionParser;\n }\n\n /**\n * Prepare system prompt with tool information and instructions\n */\n preparePrompt(instructions: string, tools: Tool[]): string {\n return instructions;\n }\n\n /**\n * Prepare request parameters for the LLM\n *\n * FIXME: move to base tool call engine.\n */\n prepareRequest(context: ToolCallEnginePrepareRequestContext): ChatCompletionCreateParams {\n defaultLogger.log(\n \"【New Sys Prompt'】 System Prompt:\",\n JSON.stringify(context.messages.find((m) => m.role === 'system')?.content || ''),\n );\n return {\n model: context.model,\n messages: context.messages,\n temperature: context.temperature || 0.7,\n stream: true,\n };\n }\n\n /**\n * Initialize processing state (minimal implementation)\n *\n * FIXME: move to base tool call engine.\n */\n initStreamProcessingState(): StreamProcessingState {\n return {\n contentBuffer: '',\n toolCalls: [],\n reasoningBuffer: '',\n finishReason: null,\n };\n }\n\n /**\n * Process streaming chunks - simply accumulate content\n *\n * FIXME: make it optional\n */\n processStreamingChunk(\n chunk: ChatCompletionChunk,\n state: StreamProcessingState,\n ): StreamChunkResult {\n const delta = chunk.choices[0]?.delta;\n\n // Accumulate content\n if (delta?.content) {\n state.contentBuffer += delta.content;\n }\n\n // Record finish reason\n if (chunk.choices[0]?.finish_reason) {\n state.finishReason = chunk.choices[0].finish_reason;\n }\n\n // Return incremental content without tool call detection during streaming\n return {\n content: delta?.content || '',\n reasoningContent: '',\n hasToolCallUpdate: false,\n toolCalls: [],\n };\n }\n\n /**\n * Generate a tool call ID\n */\n private generateToolCallId(): string {\n return `call_${Date.now()}_${Math.random().toString(36).substring(2, 11)}`;\n }\n\n /**\n * Extract tool calls from complete response text\n */\n finalizeStreamProcessing(state: StreamProcessingState): ParsedModelResponse {\n const fullContent = state.contentBuffer;\n defaultLogger.log(\"【New Sys Prompt'】 Model Response:\", fullContent);\n defaultLogger.log('[finalizeStreamProcessing] fullContent', fullContent);\n\n // Add explicit log to confirm XML parsing intent\n console.log('[CLI DEBUG] [ToolCallEngine] Full model response received:', fullContent);\n\n // Try custom action parser first if available\n let parsedGUIResponse = null;\n if (this.customActionParser) {\n parsedGUIResponse = this.customActionParser(fullContent);\n defaultLogger.log('[finalizeStreamProcessing] Using custom action parser');\n console.log('[CLI DEBUG] [ToolCallEngine] Using custom action parser');\n }\n\n // Fall back to default parser if custom parser is not available or returns null\n if (!parsedGUIResponse) {\n console.log('[CLI DEBUG] [ToolCallEngine] Using default action parser (XML parser)');\n parsedGUIResponse = defaultParser.parsePrediction(fullContent);\n defaultLogger.log('[finalizeStreamProcessing] Using default action parser');\n }\n\n if (parsedGUIResponse) {\n console.log(\n '[CLI DEBUG] [ToolCallEngine] Parsed response:',\n JSON.stringify(parsedGUIResponse, null, 2),\n );\n } else {\n console.log('[CLI DEBUG] [ToolCallEngine] Parsing failed or returned null');\n }\n\n if (!parsedGUIResponse || parsedGUIResponse.errorMessage) {\n return {\n content: '',\n rawContent: fullContent,\n toolCalls: [\n {\n id: this.generateToolCallId(),\n type: 'function',\n function: {\n name: GUI_ADAPTED_TOOL_NAME,\n arguments: JSON.stringify({\n action: '',\n step: '',\n thought: '',\n operator_action: null,\n errorMessage:\n parsedGUIResponse?.errorMessage ?? 'Failed to parse GUI Action from output',\n }),\n },\n },\n ],\n finishReason: 'tool_calls',\n };\n }\n\n const toolCalls: ChatCompletionMessageToolCall[] = [];\n\n let finished = false;\n let finishMessage: string | null = null;\n for (const action of parsedGUIResponse.actions) {\n if (action.type === 'finished') {\n finished = true;\n finishMessage = action.inputs?.content ?? null;\n continue;\n }\n toolCalls.push({\n id: this.generateToolCallId(),\n type: 'function',\n function: {\n name: GUI_ADAPTED_TOOL_NAME,\n arguments: JSON.stringify({\n action: serializeAction(action),\n step: '',\n thought: parsedGUIResponse.reasoningContent ?? '',\n operator_action: action,\n }),\n },\n });\n }\n\n const content = finishMessage ?? '';\n const reasoningContent = parsedGUIResponse.reasoningContent ?? '';\n const contentForWebUI = content.replace(/\\\\n|\\n/g, '<br>');\n const reasoningContentForWebUI = reasoningContent.replace(/\\\\n|\\n/g, '<br>');\n\n // No tool calls found - return regular response\n return {\n content: contentForWebUI,\n rawContent: fullContent,\n reasoningContent: reasoningContentForWebUI,\n toolCalls,\n finishReason: toolCalls.length > 0 && !finished ? 'tool_calls' : 'stop',\n };\n }\n\n /**\n * Build assistant message for conversation history\n * For PE engines, we preserve the raw content including tool call markup\n *\n * FIXME: move to base tool call engine.\n */\n buildHistoricalAssistantMessage(\n currentLoopAssistantEvent: AgentEventStream.AssistantMessageEvent,\n ): ChatCompletionAssistantMessageParam {\n return {\n role: 'assistant',\n content: currentLoopAssistantEvent.rawContent || currentLoopAssistantEvent.content,\n };\n }\n\n /**\n * Build tool result messages as user messages\n * PE engines format tool results as user input for next iteration\n *\n * FIXME: move to base tool call engine.\n */\n buildHistoricalToolCallResultMessages(\n toolCallResults: MultimodalToolCallResult[],\n ): ChatCompletionMessageParam[] {\n return toolCallResults.map((result) => {\n // Extract text content from multimodal result\n const textContent = result.content\n .filter((part) => part.type === 'text')\n .map((part) => (part as { text: string }).text)\n .join('');\n\n return {\n role: 'user',\n content: `Tool \"${result.toolName}\" result:\\n${textContent}`,\n };\n });\n }\n}\n"],"names":["defaultParser","DefaultActionParser","defaultLogger","ConsoleLogger","LogLevel","GUIAgentToolCallEngine","ToolCallEngine","instructions","tools","context","_context_messages_find","JSON","m","chunk","state","_chunk_choices_","_chunk_choices_1","delta","Date","Math","fullContent","console","parsedGUIResponse","GUI_ADAPTED_TOOL_NAME","toolCalls","finished","finishMessage","action","_action_inputs","serializeAction","content","reasoningContent","contentForWebUI","reasoningContentForWebUI","currentLoopAssistantEvent","toolCallResults","result","textContent","part","customActionParser"],"mappings":";;;;;;;;;;;;;;;;;;;AAqBA,MAAMA,gBAAgB,IAAIC;AAC1B,MAAMC,gBAAgB,IAAIC,cAAc,6BAA6BC,SAAS,KAAK;AAY5E,MAAMC,+BAA+BC;IAW1C,cAAcC,YAAoB,EAAEC,KAAa,EAAU;QACzD,OAAOD;IACT;IAOA,eAAeE,OAA4C,EAA8B;YAGtEC;QAFjBR,cAAc,GAAG,CACf,8CACAS,KAAK,SAAS,CAACD,AAAAA,SAAAA,CAAAA,yBAAAA,QAAQ,QAAQ,CAAC,IAAI,CAAC,CAACE,IAAMA,AAAW,aAAXA,EAAE,IAAI,CAAa,IAAhDF,KAAAA,IAAAA,uBAAmD,OAAO,AAAD,KAAK;QAE/E,OAAO;YACL,OAAOD,QAAQ,KAAK;YACpB,UAAUA,QAAQ,QAAQ;YAC1B,aAAaA,QAAQ,WAAW,IAAI;YACpC,QAAQ;QACV;IACF;IAOA,4BAAmD;QACjD,OAAO;YACL,eAAe;YACf,WAAW,EAAE;YACb,iBAAiB;YACjB,cAAc;QAChB;IACF;IAOA,sBACEI,KAA0B,EAC1BC,KAA4B,EACT;YACLC,iBAQVC;QARJ,MAAMC,QAAQ,QAAAF,CAAAA,kBAAAA,MAAM,OAAO,CAAC,EAAE,AAAD,IAAfA,KAAAA,IAAAA,gBAAkB,KAAK;QAGrC,IAAIE,QAAAA,QAAAA,KAAAA,IAAAA,MAAO,OAAO,EAChBH,MAAM,aAAa,IAAIG,MAAM,OAAO;QAItC,IAAI,QAAAD,CAAAA,mBAAAA,MAAM,OAAO,CAAC,EAAE,AAAD,IAAf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G,CAAC,CAACA,OAAUA,KAA0B,IAAI,EAC7C,IAAI,CAAC;YAER,OAAO;gBACL,MAAM;gBACN,SAAS,CAAC,MAAM,EAAEF,OAAO,QAAQ,CAAC,WAAW,EAAEC,aAAa;YAC9D;QACF;IACF;IAzNA,YAAYE,kBAAuC,CAAE;QACnD,KAAK,IAHP,uBAAQ,sBAAR;QAIE,IAAI,CAAC,kBAAkB,GAAGA;IAC5B;AAuNF"}
|
|
1
|
+
{"version":3,"file":"ToolCallEngine.mjs","sources":["webpack://@ui-tars-test/agent-sdk/./src/ToolCallEngine.ts"],"sourcesContent":["import {\n ToolCallEngine,\n Tool,\n ToolCallEnginePrepareRequestContext,\n ChatCompletionCreateParams,\n ChatCompletionAssistantMessageParam,\n ChatCompletionChunk,\n MultimodalToolCallResult,\n AgentEventStream,\n ChatCompletionMessageParam,\n ChatCompletionMessageToolCall,\n ParsedModelResponse,\n StreamProcessingState,\n StreamChunkResult,\n} from '@ui-tars-test/tarko-agent-interface';\nimport { DefaultActionParser } from '@ui-tars-test/action-parser';\nimport { GUI_ADAPTED_TOOL_NAME } from './constants';\nimport { ConsoleLogger, LogLevel } from '@agent-infra/logger';\nimport { serializeAction } from '@ui-tars-test/shared/utils';\nimport { CustomActionParser } from '@ui-tars-test/shared/types';\n\nconst defaultParser = new DefaultActionParser();\nconst defaultLogger = new ConsoleLogger('[GUIAgent:ToolCallEngine]', LogLevel.DEBUG);\n\n/**\n * GUIAgentToolCallEngine - Minimal prompt engineering tool call engine\n *\n * This is the simplest possible implementation of a tool call engine that:\n * 1. Uses prompt engineering to instruct the LLM to output tool calls in a specific format\n * 2. Parses tool calls from LLM response text using simple regex matching\n * 3. Does not support streaming (focuses on core functionality only)\n *\n * Format used: <tool_call>{\"name\": \"tool_name\", \"arguments\": {...}}</tool_call>\n */\nexport class GUIAgentToolCallEngine extends ToolCallEngine {\n private customActionParser?: CustomActionParser;\n\n constructor(customActionParser?: CustomActionParser) {\n super();\n this.customActionParser = customActionParser;\n }\n\n /**\n * Prepare system prompt with tool information and instructions\n */\n preparePrompt(instructions: string, tools: Tool[]): string {\n return instructions;\n }\n\n /**\n * Prepare request parameters for the LLM\n *\n * FIXME: move to base tool call engine.\n */\n prepareRequest(context: ToolCallEnginePrepareRequestContext): ChatCompletionCreateParams {\n defaultLogger.log(\n \"【New Sys Prompt'】 System Prompt:\",\n JSON.stringify(context.messages.find((m) => m.role === 'system')?.content || ''),\n );\n return {\n model: context.model,\n messages: context.messages,\n temperature: context.temperature || 0.7,\n stream: true,\n };\n }\n\n /**\n * Initialize processing state (minimal implementation)\n *\n * FIXME: move to base tool call engine.\n */\n initStreamProcessingState(): StreamProcessingState {\n return {\n contentBuffer: '',\n toolCalls: [],\n reasoningBuffer: '',\n finishReason: null,\n };\n }\n\n /**\n * Process streaming chunks - simply accumulate content\n *\n * FIXME: make it optional\n */\n processStreamingChunk(\n chunk: ChatCompletionChunk,\n state: StreamProcessingState,\n ): StreamChunkResult {\n const delta = chunk.choices[0]?.delta;\n\n // Accumulate content\n if (delta?.content) {\n state.contentBuffer += delta.content;\n }\n\n // Record finish reason\n if (chunk.choices[0]?.finish_reason) {\n state.finishReason = chunk.choices[0].finish_reason;\n }\n\n // Return incremental content without tool call detection during streaming\n return {\n content: delta?.content || '',\n reasoningContent: '',\n hasToolCallUpdate: false,\n toolCalls: [],\n };\n }\n\n /**\n * Generate a tool call ID\n */\n private generateToolCallId(): string {\n return `call_${Date.now()}_${Math.random().toString(36).substring(2, 11)}`;\n }\n\n /**\n * Extract tool calls from complete response text\n */\n finalizeStreamProcessing(state: StreamProcessingState): ParsedModelResponse {\n const fullContent = state.contentBuffer;\n defaultLogger.log(\"【New Sys Prompt'】 Model Response:\", fullContent);\n defaultLogger.log('[finalizeStreamProcessing] fullContent', fullContent);\n\n // Add explicit log to confirm XML parsing intent\n console.log('[CLI DEBUG] [ToolCallEngine] Full model response received:', fullContent);\n\n // Try custom action parser first if available\n let parsedGUIResponse = null;\n if (this.customActionParser) {\n parsedGUIResponse = this.customActionParser(fullContent);\n defaultLogger.log('[finalizeStreamProcessing] Using custom action parser');\n console.log('[CLI DEBUG] [ToolCallEngine] Using custom action parser');\n }\n\n // Fall back to default parser if custom parser is not available or returns null\n if (!parsedGUIResponse) {\n console.log('[CLI DEBUG] [ToolCallEngine] Using default action parser (XML parser)');\n parsedGUIResponse = defaultParser.parsePrediction(fullContent);\n defaultLogger.log('[finalizeStreamProcessing] Using default action parser');\n }\n\n if (parsedGUIResponse) {\n console.log(\n '[CLI DEBUG] [ToolCallEngine] Parsed response:',\n JSON.stringify(parsedGUIResponse, null, 2),\n );\n } else {\n console.log('[CLI DEBUG] [ToolCallEngine] Parsing failed or returned null');\n }\n\n if (!parsedGUIResponse || parsedGUIResponse.errorMessage) {\n return {\n content: '',\n rawContent: fullContent,\n toolCalls: [\n {\n id: this.generateToolCallId(),\n type: 'function',\n function: {\n name: GUI_ADAPTED_TOOL_NAME,\n arguments: JSON.stringify({\n action: '',\n step: '',\n thought: '',\n operator_action: null,\n errorMessage:\n parsedGUIResponse?.errorMessage ?? 'Failed to parse GUI Action from output',\n }),\n },\n },\n ],\n finishReason: 'tool_calls',\n };\n }\n\n const toolCalls: ChatCompletionMessageToolCall[] = [];\n\n let finished = false;\n let finishMessage: string | null = null;\n for (const action of parsedGUIResponse.actions) {\n if (action.type === 'finished') {\n finished = true;\n finishMessage = action.inputs?.content ?? null;\n continue;\n }\n toolCalls.push({\n id: this.generateToolCallId(),\n type: 'function',\n function: {\n name: GUI_ADAPTED_TOOL_NAME,\n arguments: JSON.stringify({\n action: serializeAction(action),\n step: '',\n thought: parsedGUIResponse.reasoningContent ?? '',\n operator_action: action,\n }),\n },\n });\n }\n\n const content = finishMessage ?? '';\n const reasoningContent = parsedGUIResponse.reasoningContent ?? '';\n const contentForWebUI = content.replace(/\\\\n|\\n/g, '<br>');\n const reasoningContentForWebUI = reasoningContent.replace(/\\\\n|\\n/g, '<br>');\n\n // No tool calls found - return regular response\n return {\n content: contentForWebUI,\n rawContent: fullContent,\n reasoningContent: reasoningContentForWebUI,\n toolCalls,\n finishReason: toolCalls.length > 0 && !finished ? 'tool_calls' : 'stop',\n };\n }\n\n /**\n * Build assistant message for conversation history\n * For PE engines, we preserve the raw content including tool call markup\n *\n * FIXME: move to base tool call engine.\n */\n buildHistoricalAssistantMessage(\n currentLoopAssistantEvent: AgentEventStream.AssistantMessageEvent,\n ): ChatCompletionAssistantMessageParam {\n return {\n role: 'assistant',\n content: currentLoopAssistantEvent.rawContent || currentLoopAssistantEvent.content,\n };\n }\n\n /**\n * Build tool result messages as user messages\n * PE engines format tool results as user input for next iteration\n *\n * FIXME: move to base tool call engine.\n */\n buildHistoricalToolCallResultMessages(\n toolCallResults: MultimodalToolCallResult[],\n ): ChatCompletionMessageParam[] {\n return toolCallResults.map((result) => {\n // Extract text content from multimodal result\n const textContent = result.content\n .filter((part) => part.type === 'text')\n .map((part) => (part as { text: string }).text)\n .join('');\n\n return {\n role: 'user',\n content: `Tool \"${result.toolName}\" result:\\n${textContent}`,\n };\n });\n }\n}\n"],"names":["defaultParser","DefaultActionParser","defaultLogger","ConsoleLogger","LogLevel","GUIAgentToolCallEngine","ToolCallEngine","instructions","tools","context","_context_messages_find","JSON","m","chunk","state","_chunk_choices_","_chunk_choices_1","delta","Date","Math","fullContent","console","parsedGUIResponse","GUI_ADAPTED_TOOL_NAME","toolCalls","finished","finishMessage","action","_action_inputs","serializeAction","content","reasoningContent","contentForWebUI","reasoningContentForWebUI","currentLoopAssistantEvent","toolCallResults","result","textContent","part","customActionParser"],"mappings":";;;;;;;;;;;;;;;;;;;AAqBA,MAAMA,gBAAgB,IAAIC;AAC1B,MAAMC,gBAAgB,IAAIC,cAAc,6BAA6BC,SAAS,KAAK;AAY5E,MAAMC,+BAA+BC;IAW1C,cAAcC,YAAoB,EAAEC,KAAa,EAAU;QACzD,OAAOD;IACT;IAOA,eAAeE,OAA4C,EAA8B;YAGtEC;QAFjBR,cAAc,GAAG,CACf,8CACAS,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WAAWZ,KAAK,SAAS,CAAC;wBACxB,QAAQkB,gBAAgBF;wBACxB,MAAM;wBACN,SAASL,kBAAkB,gBAAgB,IAAI;wBAC/C,iBAAiBK;oBACnB;gBACF;YACF;QACF;QAEA,MAAMG,UAAUJ,iBAAiB;QACjC,MAAMK,mBAAmBT,kBAAkB,gBAAgB,IAAI;QAC/D,MAAMU,kBAAkBF,QAAQ,OAAO,CAAC,WAAW;QACnD,MAAMG,2BAA2BF,iBAAiB,OAAO,CAAC,WAAW;QAGrE,OAAO;YACL,SAASC;YACT,YAAYZ;YACZ,kBAAkBa;YAClBT;YACA,cAAcA,UAAU,MAAM,GAAG,KAAK,CAACC,WAAW,eAAe;QACnE;IACF;IAQA,gCACES,yBAAiE,EAC5B;QACrC,OAAO;YACL,MAAM;YACN,SAASA,0BAA0B,UAAU,IAAIA,0BAA0B,OAAO;QACpF;IACF;IAQA,sCACEC,eAA2C,EACb;QAC9B,OAAOA,gBAAgB,GAAG,CAAC,CAACC;YAE1B,MAAMC,cAAcD,OAAO,OAAO,CAC/B,MAAM,CAAC,CAACE,OAASA,AAAc,WAAdA,KAAK,IAAI,EAC1B,GAAG,CAAC,CAACA,OAAUA,KAA0B,IAAI,EAC7C,IAAI,CAAC;YAER,OAAO;gBACL,MAAM;gBACN,SAAS,CAAC,MAAM,EAAEF,OAAO,QAAQ,CAAC,WAAW,EAAEC,aAAa;YAC9D;QACF;IACF;IAzNA,YAAYE,kBAAuC,CAAE;QACnD,KAAK,IAHP,uBAAQ,sBAAR;QAIE,IAAI,CAAC,kBAAkB,GAAGA;IAC5B;AAuNF"}
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseAction } from '@ui-tars-test/shared/types';
|
|
2
|
-
import { MultimodalToolCallResult } from '@tarko
|
|
2
|
+
import { MultimodalToolCallResult } from '@ui-tars-test/tarko-agent';
|
|
3
3
|
export declare const createGUIErrorResponse: (action: BaseAction, errorMessage: string) => MultimodalToolCallResult;
|
|
4
4
|
export declare const convertToAgentUIAction: (action: BaseAction) => {
|
|
5
5
|
action: any;
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,wBAAwB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AAErE,eAAO,MAAM,sBAAsB,GACjC,QAAQ,UAAU,EAClB,cAAc,MAAM,KACnB,wBAcF,CAAC;AAEF,eAAO,MAAM,sBAAsB,GAAI,QAAQ,UAAU;;;;;CAUxD,CAAC"}
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["webpack://@ui-tars-test/agent-sdk/webpack/runtime/define_property_getters","webpack://@ui-tars-test/agent-sdk/webpack/runtime/has_own_property","webpack://@ui-tars-test/agent-sdk/webpack/runtime/make_namespace_object","webpack://@ui-tars-test/agent-sdk/./src/utils.ts"],"sourcesContent":["__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","/* eslint-disable @typescript-eslint/no-explicit-any */\n/*\n * Copyright (c) 2025 Bytedance, Inc. and its affiliates.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { BaseAction } from '@ui-tars-test/shared/types';\nimport { MultimodalToolCallResult } from '@tarko
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["webpack://@ui-tars-test/agent-sdk/webpack/runtime/define_property_getters","webpack://@ui-tars-test/agent-sdk/webpack/runtime/has_own_property","webpack://@ui-tars-test/agent-sdk/webpack/runtime/make_namespace_object","webpack://@ui-tars-test/agent-sdk/./src/utils.ts"],"sourcesContent":["__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","/* eslint-disable @typescript-eslint/no-explicit-any */\n/*\n * Copyright (c) 2025 Bytedance, Inc. and its affiliates.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { BaseAction } from '@ui-tars-test/shared/types';\nimport { MultimodalToolCallResult } from '@ui-tars-test/tarko-agent';\n\nexport const createGUIErrorResponse = (\n action: BaseAction,\n errorMessage: string,\n): MultimodalToolCallResult => {\n return {\n content: [\n {\n type: 'text',\n text: JSON.stringify({\n action: action,\n error: errorMessage,\n }),\n },\n ],\n // @ts-ignore: isError is not in MultimodalToolCallResult type but might be used by internal logic\n isError: true,\n };\n};\n\nexport const convertToAgentUIAction = (action: BaseAction) => {\n // Use type assertion or access properties safely as BaseAction might be generic\n // or properties might be on specific action types\n const anyAction = action as any;\n return {\n action: anyAction.prediction,\n thought: anyAction.thought,\n action_type: anyAction.action_type,\n action_input: anyAction.action_input,\n };\n};\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","createGUIErrorResponse","action","errorMessage","JSON","convertToAgentUIAction","anyAction"],"mappings":";;;;;;;IAAAA,oBAAoB,CAAC,GAAG,CAAC,UAASC;QACjC,IAAI,IAAIC,OAAOD,WACR,IAAGD,oBAAoB,CAAC,CAACC,YAAYC,QAAQ,CAACF,oBAAoB,CAAC,CAAC,UAASE,MACzEC,OAAO,cAAc,CAAC,UAASD,KAAK;YAAE,YAAY;YAAM,KAAKD,UAAU,CAACC,IAAI;QAAC;IAGzF;;;ICNAF,oBAAoB,CAAC,GAAG,CAACI,KAAKC,OAAUF,OAAO,SAAS,CAAC,cAAc,CAAC,IAAI,CAACC,KAAKC;;;ICClFL,oBAAoB,CAAC,GAAG,CAAC;QACxB,IAAG,AAAkB,eAAlB,OAAOM,UAA0BA,OAAO,WAAW,EACrDH,OAAO,cAAc,CAAC,UAASG,OAAO,WAAW,EAAE;YAAE,OAAO;QAAS;QAEtEH,OAAO,cAAc,CAAC,UAAS,cAAc;YAAE,OAAO;QAAK;IAC5D;;;;;;;;ACGO,MAAMI,yBAAyB,CACpCC,QACAC,eAEO;QACL,SAAS;YACP;gBACE,MAAM;gBACN,MAAMC,KAAK,SAAS,CAAC;oBACnB,QAAQF;oBACR,OAAOC;gBACT;YACF;SACD;QAED,SAAS;IACX;AAGK,MAAME,yBAAyB,CAACH;IAGrC,MAAMI,YAAYJ;IAClB,OAAO;QACL,QAAQI,UAAU,UAAU;QAC5B,SAASA,UAAU,OAAO;QAC1B,aAAaA,UAAU,WAAW;QAClC,cAAcA,UAAU,YAAY;IACtC;AACF"}
|
package/dist/utils.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","sources":["webpack://@ui-tars-test/agent-sdk/./src/utils.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n/*\n * Copyright (c) 2025 Bytedance, Inc. and its affiliates.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { BaseAction } from '@ui-tars-test/shared/types';\nimport { MultimodalToolCallResult } from '@tarko
|
|
1
|
+
{"version":3,"file":"utils.mjs","sources":["webpack://@ui-tars-test/agent-sdk/./src/utils.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n/*\n * Copyright (c) 2025 Bytedance, Inc. and its affiliates.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { BaseAction } from '@ui-tars-test/shared/types';\nimport { MultimodalToolCallResult } from '@ui-tars-test/tarko-agent';\n\nexport const createGUIErrorResponse = (\n action: BaseAction,\n errorMessage: string,\n): MultimodalToolCallResult => {\n return {\n content: [\n {\n type: 'text',\n text: JSON.stringify({\n action: action,\n error: errorMessage,\n }),\n },\n ],\n // @ts-ignore: isError is not in MultimodalToolCallResult type but might be used by internal logic\n isError: true,\n };\n};\n\nexport const convertToAgentUIAction = (action: BaseAction) => {\n // Use type assertion or access properties safely as BaseAction might be generic\n // or properties might be on specific action types\n const anyAction = action as any;\n return {\n action: anyAction.prediction,\n thought: anyAction.thought,\n action_type: anyAction.action_type,\n action_input: anyAction.action_input,\n };\n};\n"],"names":["createGUIErrorResponse","action","errorMessage","JSON","convertToAgentUIAction","anyAction"],"mappings":";;;;AASO,MAAMA,yBAAyB,CACpCC,QACAC,eAEO;QACL,SAAS;YACP;gBACE,MAAM;gBACN,MAAMC,KAAK,SAAS,CAAC;oBACnB,QAAQF;oBACR,OAAOC;gBACT;YACF;SACD;QAED,SAAS;IACX;AAGK,MAAME,yBAAyB,CAACH;IAGrC,MAAMI,YAAYJ;IAClB,OAAO;QACL,QAAQI,UAAU,UAAU;QAC5B,SAASA,UAAU,OAAO;QAC1B,aAAaA,UAAU,WAAW;QAClC,cAAcA,UAAU,YAAY;IACtC;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ui-tars-test/agent-sdk",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.12",
|
|
4
4
|
"description": "GUI Agent",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -39,8 +39,9 @@
|
|
|
39
39
|
"@ui-tars-test/operator-adb": "^0.3.0",
|
|
40
40
|
"@ui-tars-test/operator-browser": "^0.3.0",
|
|
41
41
|
"@ui-tars-test/operator-nutjs": "^0.3.0",
|
|
42
|
-
"@ui-tars-test/shared": "^0.3.
|
|
42
|
+
"@ui-tars-test/shared": "^0.3.7",
|
|
43
43
|
"@ui-tars-test/tarko-agent": "^0.3.1",
|
|
44
|
+
"@ui-tars-test/tarko-agent-interface": "^0.3.1",
|
|
44
45
|
"big.js": "^6.2.2",
|
|
45
46
|
"commander": "^14.0.0",
|
|
46
47
|
"dotenv": "^17.2.2",
|