@ui-tars-test/agent-sdk 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -0
- package/dist/GUIAgent.d.ts +24 -0
- package/dist/GUIAgent.d.ts.map +1 -0
- package/dist/GUIAgent.js +207 -0
- package/dist/GUIAgent.js.map +1 -0
- package/dist/GUIAgent.mjs +173 -0
- package/dist/GUIAgent.mjs.map +1 -0
- package/dist/ToolCallEngine.d.ts +61 -0
- package/dist/ToolCallEngine.d.ts.map +1 -0
- package/dist/ToolCallEngine.js +190 -0
- package/dist/ToolCallEngine.js.map +1 -0
- package/dist/ToolCallEngine.mjs +156 -0
- package/dist/ToolCallEngine.mjs.map +1 -0
- package/dist/constants.d.ts +6 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +42 -0
- package/dist/constants.js.map +1 -0
- package/dist/constants.mjs +8 -0
- package/dist/constants.mjs.map +1 -0
- package/dist/defaultImpls.d.ts +15 -0
- package/dist/defaultImpls.d.ts.map +1 -0
- package/dist/defaultImpls.js +67 -0
- package/dist/defaultImpls.js.map +1 -0
- package/dist/defaultImpls.mjs +30 -0
- package/dist/defaultImpls.mjs.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +72 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +7 -0
- package/dist/prompts.d.ts +10 -0
- package/dist/prompts.d.ts.map +1 -0
- package/dist/prompts.js +311 -0
- package/dist/prompts.js.map +1 -0
- package/dist/prompts.mjs +256 -0
- package/dist/prompts.mjs.map +1 -0
- package/dist/utils.d.ts +10 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +65 -0
- package/dist/utils.js.map +1 -0
- package/dist/utils.mjs +28 -0
- package/dist/utils.mjs.map +1 -0
- package/package.json +63 -0
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance, Inc. and its affiliates.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
var __webpack_require__ = {};
|
|
7
|
+
(()=>{
|
|
8
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
9
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: definition[key]
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = (exports1)=>{
|
|
20
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
GUIAgentToolCallEngine: ()=>GUIAgentToolCallEngine
|
|
32
|
+
});
|
|
33
|
+
const agent_interface_namespaceObject = require("@tarko/agent-interface");
|
|
34
|
+
const action_parser_namespaceObject = require("@ui-tars-test/action-parser");
|
|
35
|
+
const external_constants_js_namespaceObject = require("./constants.js");
|
|
36
|
+
const logger_namespaceObject = require("@agent-infra/logger");
|
|
37
|
+
const utils_namespaceObject = require("@ui-tars-test/shared/utils");
|
|
38
|
+
function _define_property(obj, key, value) {
|
|
39
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
40
|
+
value: value,
|
|
41
|
+
enumerable: true,
|
|
42
|
+
configurable: true,
|
|
43
|
+
writable: true
|
|
44
|
+
});
|
|
45
|
+
else obj[key] = value;
|
|
46
|
+
return obj;
|
|
47
|
+
}
|
|
48
|
+
const defaultParser = new action_parser_namespaceObject.DefaultActionParser();
|
|
49
|
+
const defaultLogger = new logger_namespaceObject.ConsoleLogger('[GUIAgent:ToolCallEngine]', logger_namespaceObject.LogLevel.DEBUG);
|
|
50
|
+
class GUIAgentToolCallEngine extends agent_interface_namespaceObject.ToolCallEngine {
|
|
51
|
+
preparePrompt(instructions, tools) {
|
|
52
|
+
return instructions;
|
|
53
|
+
}
|
|
54
|
+
prepareRequest(context) {
|
|
55
|
+
var _context_messages_find;
|
|
56
|
+
defaultLogger.log("\u3010New Sys Prompt'\u3011 System Prompt:", JSON.stringify((null == (_context_messages_find = context.messages.find((m)=>'system' === m.role)) ? void 0 : _context_messages_find.content) || ''));
|
|
57
|
+
return {
|
|
58
|
+
model: context.model,
|
|
59
|
+
messages: context.messages,
|
|
60
|
+
temperature: context.temperature || 0.7,
|
|
61
|
+
stream: true
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
initStreamProcessingState() {
|
|
65
|
+
return {
|
|
66
|
+
contentBuffer: '',
|
|
67
|
+
toolCalls: [],
|
|
68
|
+
reasoningBuffer: '',
|
|
69
|
+
finishReason: null
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
processStreamingChunk(chunk, state) {
|
|
73
|
+
var _chunk_choices_, _chunk_choices_1;
|
|
74
|
+
const delta = null == (_chunk_choices_ = chunk.choices[0]) ? void 0 : _chunk_choices_.delta;
|
|
75
|
+
if (null == delta ? void 0 : delta.content) state.contentBuffer += delta.content;
|
|
76
|
+
if (null == (_chunk_choices_1 = chunk.choices[0]) ? void 0 : _chunk_choices_1.finish_reason) state.finishReason = chunk.choices[0].finish_reason;
|
|
77
|
+
return {
|
|
78
|
+
content: (null == delta ? void 0 : delta.content) || '',
|
|
79
|
+
reasoningContent: '',
|
|
80
|
+
hasToolCallUpdate: false,
|
|
81
|
+
toolCalls: []
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
generateToolCallId() {
|
|
85
|
+
return `call_${Date.now()}_${Math.random().toString(36).substring(2, 11)}`;
|
|
86
|
+
}
|
|
87
|
+
finalizeStreamProcessing(state) {
|
|
88
|
+
const fullContent = state.contentBuffer;
|
|
89
|
+
defaultLogger.log("\u3010New Sys Prompt'\u3011 Model Response:", fullContent);
|
|
90
|
+
defaultLogger.log('[finalizeStreamProcessing] fullContent', fullContent);
|
|
91
|
+
console.log('[CLI DEBUG] [ToolCallEngine] Full model response received:', fullContent);
|
|
92
|
+
let parsedGUIResponse = null;
|
|
93
|
+
if (this.customActionParser) {
|
|
94
|
+
parsedGUIResponse = this.customActionParser(fullContent);
|
|
95
|
+
defaultLogger.log('[finalizeStreamProcessing] Using custom action parser');
|
|
96
|
+
console.log('[CLI DEBUG] [ToolCallEngine] Using custom action parser');
|
|
97
|
+
}
|
|
98
|
+
if (!parsedGUIResponse) {
|
|
99
|
+
console.log('[CLI DEBUG] [ToolCallEngine] Using default action parser (XML parser)');
|
|
100
|
+
parsedGUIResponse = defaultParser.parsePrediction(fullContent);
|
|
101
|
+
defaultLogger.log('[finalizeStreamProcessing] Using default action parser');
|
|
102
|
+
}
|
|
103
|
+
if (parsedGUIResponse) console.log('[CLI DEBUG] [ToolCallEngine] Parsed response:', JSON.stringify(parsedGUIResponse, null, 2));
|
|
104
|
+
else console.log('[CLI DEBUG] [ToolCallEngine] Parsing failed or returned null');
|
|
105
|
+
if (!parsedGUIResponse || parsedGUIResponse.errorMessage) return {
|
|
106
|
+
content: '',
|
|
107
|
+
rawContent: fullContent,
|
|
108
|
+
toolCalls: [
|
|
109
|
+
{
|
|
110
|
+
id: this.generateToolCallId(),
|
|
111
|
+
type: 'function',
|
|
112
|
+
function: {
|
|
113
|
+
name: external_constants_js_namespaceObject.GUI_ADAPTED_TOOL_NAME,
|
|
114
|
+
arguments: JSON.stringify({
|
|
115
|
+
action: '',
|
|
116
|
+
step: '',
|
|
117
|
+
thought: '',
|
|
118
|
+
operator_action: null,
|
|
119
|
+
errorMessage: (null == parsedGUIResponse ? void 0 : parsedGUIResponse.errorMessage) ?? 'Failed to parse GUI Action from output'
|
|
120
|
+
})
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
],
|
|
124
|
+
finishReason: 'tool_calls'
|
|
125
|
+
};
|
|
126
|
+
const toolCalls = [];
|
|
127
|
+
let finished = false;
|
|
128
|
+
let finishMessage = null;
|
|
129
|
+
for (const action of parsedGUIResponse.actions){
|
|
130
|
+
if ('finished' === action.type) {
|
|
131
|
+
var _action_inputs;
|
|
132
|
+
finished = true;
|
|
133
|
+
finishMessage = (null == (_action_inputs = action.inputs) ? void 0 : _action_inputs.content) ?? null;
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
toolCalls.push({
|
|
137
|
+
id: this.generateToolCallId(),
|
|
138
|
+
type: 'function',
|
|
139
|
+
function: {
|
|
140
|
+
name: external_constants_js_namespaceObject.GUI_ADAPTED_TOOL_NAME,
|
|
141
|
+
arguments: JSON.stringify({
|
|
142
|
+
action: (0, utils_namespaceObject.serializeAction)(action),
|
|
143
|
+
step: '',
|
|
144
|
+
thought: parsedGUIResponse.reasoningContent ?? '',
|
|
145
|
+
operator_action: action
|
|
146
|
+
})
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
const content = finishMessage ?? '';
|
|
151
|
+
const reasoningContent = parsedGUIResponse.reasoningContent ?? '';
|
|
152
|
+
const contentForWebUI = content.replace(/\\n|\n/g, '<br>');
|
|
153
|
+
const reasoningContentForWebUI = reasoningContent.replace(/\\n|\n/g, '<br>');
|
|
154
|
+
return {
|
|
155
|
+
content: contentForWebUI,
|
|
156
|
+
rawContent: fullContent,
|
|
157
|
+
reasoningContent: reasoningContentForWebUI,
|
|
158
|
+
toolCalls,
|
|
159
|
+
finishReason: toolCalls.length > 0 && !finished ? 'tool_calls' : 'stop'
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
buildHistoricalAssistantMessage(currentLoopAssistantEvent) {
|
|
163
|
+
return {
|
|
164
|
+
role: 'assistant',
|
|
165
|
+
content: currentLoopAssistantEvent.rawContent || currentLoopAssistantEvent.content
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
buildHistoricalToolCallResultMessages(toolCallResults) {
|
|
169
|
+
return toolCallResults.map((result)=>{
|
|
170
|
+
const textContent = result.content.filter((part)=>'text' === part.type).map((part)=>part.text).join('');
|
|
171
|
+
return {
|
|
172
|
+
role: 'user',
|
|
173
|
+
content: `Tool "${result.toolName}" result:\n${textContent}`
|
|
174
|
+
};
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
constructor(customActionParser){
|
|
178
|
+
super(), _define_property(this, "customActionParser", void 0);
|
|
179
|
+
this.customActionParser = customActionParser;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
exports.GUIAgentToolCallEngine = __webpack_exports__.GUIAgentToolCallEngine;
|
|
183
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
184
|
+
"GUIAgentToolCallEngine"
|
|
185
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
186
|
+
Object.defineProperty(exports, '__esModule', {
|
|
187
|
+
value: true
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
//# sourceMappingURL=ToolCallEngine.js.map
|
|
@@ -0,0 +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;;;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C,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"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance, Inc. and its affiliates.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { ToolCallEngine } from "@tarko/agent-interface";
|
|
6
|
+
import { DefaultActionParser } from "@ui-tars-test/action-parser";
|
|
7
|
+
import { GUI_ADAPTED_TOOL_NAME } from "./constants.mjs";
|
|
8
|
+
import { ConsoleLogger, LogLevel } from "@agent-infra/logger";
|
|
9
|
+
import { serializeAction } from "@ui-tars-test/shared/utils";
|
|
10
|
+
function _define_property(obj, key, value) {
|
|
11
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
12
|
+
value: value,
|
|
13
|
+
enumerable: true,
|
|
14
|
+
configurable: true,
|
|
15
|
+
writable: true
|
|
16
|
+
});
|
|
17
|
+
else obj[key] = value;
|
|
18
|
+
return obj;
|
|
19
|
+
}
|
|
20
|
+
const defaultParser = new DefaultActionParser();
|
|
21
|
+
const defaultLogger = new ConsoleLogger('[GUIAgent:ToolCallEngine]', LogLevel.DEBUG);
|
|
22
|
+
class GUIAgentToolCallEngine extends ToolCallEngine {
|
|
23
|
+
preparePrompt(instructions, tools) {
|
|
24
|
+
return instructions;
|
|
25
|
+
}
|
|
26
|
+
prepareRequest(context) {
|
|
27
|
+
var _context_messages_find;
|
|
28
|
+
defaultLogger.log("\u3010New Sys Prompt'\u3011 System Prompt:", JSON.stringify((null == (_context_messages_find = context.messages.find((m)=>'system' === m.role)) ? void 0 : _context_messages_find.content) || ''));
|
|
29
|
+
return {
|
|
30
|
+
model: context.model,
|
|
31
|
+
messages: context.messages,
|
|
32
|
+
temperature: context.temperature || 0.7,
|
|
33
|
+
stream: true
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
initStreamProcessingState() {
|
|
37
|
+
return {
|
|
38
|
+
contentBuffer: '',
|
|
39
|
+
toolCalls: [],
|
|
40
|
+
reasoningBuffer: '',
|
|
41
|
+
finishReason: null
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
processStreamingChunk(chunk, state) {
|
|
45
|
+
var _chunk_choices_, _chunk_choices_1;
|
|
46
|
+
const delta = null == (_chunk_choices_ = chunk.choices[0]) ? void 0 : _chunk_choices_.delta;
|
|
47
|
+
if (null == delta ? void 0 : delta.content) state.contentBuffer += delta.content;
|
|
48
|
+
if (null == (_chunk_choices_1 = chunk.choices[0]) ? void 0 : _chunk_choices_1.finish_reason) state.finishReason = chunk.choices[0].finish_reason;
|
|
49
|
+
return {
|
|
50
|
+
content: (null == delta ? void 0 : delta.content) || '',
|
|
51
|
+
reasoningContent: '',
|
|
52
|
+
hasToolCallUpdate: false,
|
|
53
|
+
toolCalls: []
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
generateToolCallId() {
|
|
57
|
+
return `call_${Date.now()}_${Math.random().toString(36).substring(2, 11)}`;
|
|
58
|
+
}
|
|
59
|
+
finalizeStreamProcessing(state) {
|
|
60
|
+
const fullContent = state.contentBuffer;
|
|
61
|
+
defaultLogger.log("\u3010New Sys Prompt'\u3011 Model Response:", fullContent);
|
|
62
|
+
defaultLogger.log('[finalizeStreamProcessing] fullContent', fullContent);
|
|
63
|
+
console.log('[CLI DEBUG] [ToolCallEngine] Full model response received:', fullContent);
|
|
64
|
+
let parsedGUIResponse = null;
|
|
65
|
+
if (this.customActionParser) {
|
|
66
|
+
parsedGUIResponse = this.customActionParser(fullContent);
|
|
67
|
+
defaultLogger.log('[finalizeStreamProcessing] Using custom action parser');
|
|
68
|
+
console.log('[CLI DEBUG] [ToolCallEngine] Using custom action parser');
|
|
69
|
+
}
|
|
70
|
+
if (!parsedGUIResponse) {
|
|
71
|
+
console.log('[CLI DEBUG] [ToolCallEngine] Using default action parser (XML parser)');
|
|
72
|
+
parsedGUIResponse = defaultParser.parsePrediction(fullContent);
|
|
73
|
+
defaultLogger.log('[finalizeStreamProcessing] Using default action parser');
|
|
74
|
+
}
|
|
75
|
+
if (parsedGUIResponse) console.log('[CLI DEBUG] [ToolCallEngine] Parsed response:', JSON.stringify(parsedGUIResponse, null, 2));
|
|
76
|
+
else console.log('[CLI DEBUG] [ToolCallEngine] Parsing failed or returned null');
|
|
77
|
+
if (!parsedGUIResponse || parsedGUIResponse.errorMessage) return {
|
|
78
|
+
content: '',
|
|
79
|
+
rawContent: fullContent,
|
|
80
|
+
toolCalls: [
|
|
81
|
+
{
|
|
82
|
+
id: this.generateToolCallId(),
|
|
83
|
+
type: 'function',
|
|
84
|
+
function: {
|
|
85
|
+
name: GUI_ADAPTED_TOOL_NAME,
|
|
86
|
+
arguments: JSON.stringify({
|
|
87
|
+
action: '',
|
|
88
|
+
step: '',
|
|
89
|
+
thought: '',
|
|
90
|
+
operator_action: null,
|
|
91
|
+
errorMessage: (null == parsedGUIResponse ? void 0 : parsedGUIResponse.errorMessage) ?? 'Failed to parse GUI Action from output'
|
|
92
|
+
})
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
],
|
|
96
|
+
finishReason: 'tool_calls'
|
|
97
|
+
};
|
|
98
|
+
const toolCalls = [];
|
|
99
|
+
let finished = false;
|
|
100
|
+
let finishMessage = null;
|
|
101
|
+
for (const action of parsedGUIResponse.actions){
|
|
102
|
+
if ('finished' === action.type) {
|
|
103
|
+
var _action_inputs;
|
|
104
|
+
finished = true;
|
|
105
|
+
finishMessage = (null == (_action_inputs = action.inputs) ? void 0 : _action_inputs.content) ?? null;
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
toolCalls.push({
|
|
109
|
+
id: this.generateToolCallId(),
|
|
110
|
+
type: 'function',
|
|
111
|
+
function: {
|
|
112
|
+
name: GUI_ADAPTED_TOOL_NAME,
|
|
113
|
+
arguments: JSON.stringify({
|
|
114
|
+
action: serializeAction(action),
|
|
115
|
+
step: '',
|
|
116
|
+
thought: parsedGUIResponse.reasoningContent ?? '',
|
|
117
|
+
operator_action: action
|
|
118
|
+
})
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
const content = finishMessage ?? '';
|
|
123
|
+
const reasoningContent = parsedGUIResponse.reasoningContent ?? '';
|
|
124
|
+
const contentForWebUI = content.replace(/\\n|\n/g, '<br>');
|
|
125
|
+
const reasoningContentForWebUI = reasoningContent.replace(/\\n|\n/g, '<br>');
|
|
126
|
+
return {
|
|
127
|
+
content: contentForWebUI,
|
|
128
|
+
rawContent: fullContent,
|
|
129
|
+
reasoningContent: reasoningContentForWebUI,
|
|
130
|
+
toolCalls,
|
|
131
|
+
finishReason: toolCalls.length > 0 && !finished ? 'tool_calls' : 'stop'
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
buildHistoricalAssistantMessage(currentLoopAssistantEvent) {
|
|
135
|
+
return {
|
|
136
|
+
role: 'assistant',
|
|
137
|
+
content: currentLoopAssistantEvent.rawContent || currentLoopAssistantEvent.content
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
buildHistoricalToolCallResultMessages(toolCallResults) {
|
|
141
|
+
return toolCallResults.map((result)=>{
|
|
142
|
+
const textContent = result.content.filter((part)=>'text' === part.type).map((part)=>part.text).join('');
|
|
143
|
+
return {
|
|
144
|
+
role: 'user',
|
|
145
|
+
content: `Tool "${result.toolName}" result:\n${textContent}`
|
|
146
|
+
};
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
constructor(customActionParser){
|
|
150
|
+
super(), _define_property(this, "customActionParser", void 0);
|
|
151
|
+
this.customActionParser = customActionParser;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
export { GUIAgentToolCallEngine };
|
|
155
|
+
|
|
156
|
+
//# sourceMappingURL=ToolCallEngine.mjs.map
|
|
@@ -0,0 +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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gBF;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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,qBAAqB,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance, Inc. and its affiliates.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
var __webpack_require__ = {};
|
|
7
|
+
(()=>{
|
|
8
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
9
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: definition[key]
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = (exports1)=>{
|
|
20
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
GUI_ADAPTED_TOOL_NAME: ()=>GUI_ADAPTED_TOOL_NAME
|
|
32
|
+
});
|
|
33
|
+
const GUI_ADAPTED_TOOL_NAME = 'browser_vision_control';
|
|
34
|
+
exports.GUI_ADAPTED_TOOL_NAME = __webpack_exports__.GUI_ADAPTED_TOOL_NAME;
|
|
35
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
36
|
+
"GUI_ADAPTED_TOOL_NAME"
|
|
37
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
38
|
+
Object.defineProperty(exports, '__esModule', {
|
|
39
|
+
value: true
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.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/constants.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 */\nexport const GUI_ADAPTED_TOOL_NAME = 'browser_vision_control';\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","GUI_ADAPTED_TOOL_NAME"],"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;;;;;;;ACFO,MAAMI,wBAAwB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.mjs","sources":["webpack://@ui-tars-test/agent-sdk/./src/constants.ts"],"sourcesContent":["/**\n * Copyright (c) 2025 Bytedance, Inc. and its affiliates.\n * SPDX-License-Identifier: Apache-2.0\n */\nexport const GUI_ADAPTED_TOOL_NAME = 'browser_vision_control';\n"],"names":["GUI_ADAPTED_TOOL_NAME"],"mappings":";;;;AAIO,MAAMA,wBAAwB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ImageDetailCalculator, NormalizeCoordinates } from '@ui-tars-test/shared/types';
|
|
2
|
+
/**
|
|
3
|
+
* Default coordinate normalization function
|
|
4
|
+
* Normalizes raw coordinates by dividing by 1000 (simple scaling)
|
|
5
|
+
* @param rawCoords - The raw coordinates to normalize
|
|
6
|
+
* @returns Object containing normalized coordinates
|
|
7
|
+
*/
|
|
8
|
+
export declare const defaultNormalizeCoords: NormalizeCoordinates;
|
|
9
|
+
/**
|
|
10
|
+
* Default implementation for detail calculation based on pixel count
|
|
11
|
+
* detail:low mode: 1,048,576 px (1024×1024)
|
|
12
|
+
* detail:high mode: 4,014,080 px (2048×1960)
|
|
13
|
+
*/
|
|
14
|
+
export declare const defaultDetailCalculator: ImageDetailCalculator;
|
|
15
|
+
//# sourceMappingURL=defaultImpls.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultImpls.d.ts","sourceRoot":"","sources":["../src/defaultImpls.ts"],"names":[],"mappings":"AAIA,OAAO,EAAe,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAEtG;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,EAAE,oBAYpC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,EAAE,qBAgBrC,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance, Inc. and its affiliates.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
var __webpack_require__ = {};
|
|
7
|
+
(()=>{
|
|
8
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
9
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: definition[key]
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = (exports1)=>{
|
|
20
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
defaultDetailCalculator: ()=>defaultDetailCalculator,
|
|
32
|
+
defaultNormalizeCoords: ()=>defaultNormalizeCoords
|
|
33
|
+
});
|
|
34
|
+
const defaultNormalizeCoords = (rawCoords)=>{
|
|
35
|
+
if (!rawCoords.raw) return {
|
|
36
|
+
normalized: rawCoords
|
|
37
|
+
};
|
|
38
|
+
const normalizedCoords = {
|
|
39
|
+
...rawCoords,
|
|
40
|
+
normalized: {
|
|
41
|
+
x: rawCoords.raw.x / 1000,
|
|
42
|
+
y: rawCoords.raw.y / 1000
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
return {
|
|
46
|
+
normalized: normalizedCoords
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
const defaultDetailCalculator = (width, height)=>{
|
|
50
|
+
const LOW_DETAIL_THRESHOLD = 1048576;
|
|
51
|
+
const HIGH_DETAIL_THRESHOLD = 4014080;
|
|
52
|
+
const pixelCount = width * height;
|
|
53
|
+
if (pixelCount <= LOW_DETAIL_THRESHOLD) return 'low';
|
|
54
|
+
if (pixelCount <= HIGH_DETAIL_THRESHOLD) return 'high';
|
|
55
|
+
return 'auto';
|
|
56
|
+
};
|
|
57
|
+
exports.defaultDetailCalculator = __webpack_exports__.defaultDetailCalculator;
|
|
58
|
+
exports.defaultNormalizeCoords = __webpack_exports__.defaultNormalizeCoords;
|
|
59
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
60
|
+
"defaultDetailCalculator",
|
|
61
|
+
"defaultNormalizeCoords"
|
|
62
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
63
|
+
Object.defineProperty(exports, '__esModule', {
|
|
64
|
+
value: true
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
//# sourceMappingURL=defaultImpls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultImpls.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/defaultImpls.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 { Coordinates, ImageDetailCalculator, NormalizeCoordinates } from '@ui-tars-test/shared/types';\n\n/**\n * Default coordinate normalization function\n * Normalizes raw coordinates by dividing by 1000 (simple scaling)\n * @param rawCoords - The raw coordinates to normalize\n * @returns Object containing normalized coordinates\n */\nexport const defaultNormalizeCoords: NormalizeCoordinates = (rawCoords: Coordinates) => {\n if (!rawCoords.raw) {\n return { normalized: rawCoords };\n }\n const normalizedCoords = {\n ...rawCoords,\n normalized: {\n x: rawCoords.raw.x / 1000,\n y: rawCoords.raw.y / 1000,\n },\n };\n return { normalized: normalizedCoords };\n};\n\n/**\n * Default implementation for detail calculation based on pixel count\n * detail:low mode: 1,048,576 px (1024×1024)\n * detail:high mode: 4,014,080 px (2048×1960)\n */\nexport const defaultDetailCalculator: ImageDetailCalculator = (\n width: number,\n height: number,\n): 'low' | 'high' | 'auto' => {\n const LOW_DETAIL_THRESHOLD = 1024 * 1024; // 1,048,576 px\n const HIGH_DETAIL_THRESHOLD = 2048 * 1960; // 4,014,080 px\n\n const pixelCount = width * height;\n if (pixelCount <= LOW_DETAIL_THRESHOLD) {\n return 'low';\n } else if (pixelCount <= HIGH_DETAIL_THRESHOLD) {\n return 'high';\n } else {\n // For images larger than high detail threshold, use high detail\n return 'auto';\n }\n};\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","defaultNormalizeCoords","rawCoords","normalizedCoords","defaultDetailCalculator","width","height","LOW_DETAIL_THRESHOLD","HIGH_DETAIL_THRESHOLD","pixelCount"],"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;;;;;;;;ACMO,MAAMI,yBAA+C,CAACC;IAC3D,IAAI,CAACA,UAAU,GAAG,EAChB,OAAO;QAAE,YAAYA;IAAU;IAEjC,MAAMC,mBAAmB;QACvB,GAAGD,SAAS;QACZ,YAAY;YACV,GAAGA,UAAU,GAAG,CAAC,CAAC,GAAG;YACrB,GAAGA,UAAU,GAAG,CAAC,CAAC,GAAG;QACvB;IACF;IACA,OAAO;QAAE,YAAYC;IAAiB;AACxC;AAOO,MAAMC,0BAAiD,CAC5DC,OACAC;IAEA,MAAMC,uBAAuB;IAC7B,MAAMC,wBAAwB;IAE9B,MAAMC,aAAaJ,QAAQC;IAC3B,IAAIG,cAAcF,sBAChB,OAAO;IACF,IAAIE,cAAcD,uBACvB,OAAO;IAGP,OAAO;AAEX"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance, Inc. and its affiliates.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
const defaultNormalizeCoords = (rawCoords)=>{
|
|
6
|
+
if (!rawCoords.raw) return {
|
|
7
|
+
normalized: rawCoords
|
|
8
|
+
};
|
|
9
|
+
const normalizedCoords = {
|
|
10
|
+
...rawCoords,
|
|
11
|
+
normalized: {
|
|
12
|
+
x: rawCoords.raw.x / 1000,
|
|
13
|
+
y: rawCoords.raw.y / 1000
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
return {
|
|
17
|
+
normalized: normalizedCoords
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
const defaultDetailCalculator = (width, height)=>{
|
|
21
|
+
const LOW_DETAIL_THRESHOLD = 1048576;
|
|
22
|
+
const HIGH_DETAIL_THRESHOLD = 4014080;
|
|
23
|
+
const pixelCount = width * height;
|
|
24
|
+
if (pixelCount <= LOW_DETAIL_THRESHOLD) return 'low';
|
|
25
|
+
if (pixelCount <= HIGH_DETAIL_THRESHOLD) return 'high';
|
|
26
|
+
return 'auto';
|
|
27
|
+
};
|
|
28
|
+
export { defaultDetailCalculator, defaultNormalizeCoords };
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=defaultImpls.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultImpls.mjs","sources":["webpack://@ui-tars-test/agent-sdk/./src/defaultImpls.ts"],"sourcesContent":["/*\n * Copyright (c) 2025 Bytedance, Inc. and its affiliates.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport { Coordinates, ImageDetailCalculator, NormalizeCoordinates } from '@ui-tars-test/shared/types';\n\n/**\n * Default coordinate normalization function\n * Normalizes raw coordinates by dividing by 1000 (simple scaling)\n * @param rawCoords - The raw coordinates to normalize\n * @returns Object containing normalized coordinates\n */\nexport const defaultNormalizeCoords: NormalizeCoordinates = (rawCoords: Coordinates) => {\n if (!rawCoords.raw) {\n return { normalized: rawCoords };\n }\n const normalizedCoords = {\n ...rawCoords,\n normalized: {\n x: rawCoords.raw.x / 1000,\n y: rawCoords.raw.y / 1000,\n },\n };\n return { normalized: normalizedCoords };\n};\n\n/**\n * Default implementation for detail calculation based on pixel count\n * detail:low mode: 1,048,576 px (1024×1024)\n * detail:high mode: 4,014,080 px (2048×1960)\n */\nexport const defaultDetailCalculator: ImageDetailCalculator = (\n width: number,\n height: number,\n): 'low' | 'high' | 'auto' => {\n const LOW_DETAIL_THRESHOLD = 1024 * 1024; // 1,048,576 px\n const HIGH_DETAIL_THRESHOLD = 2048 * 1960; // 4,014,080 px\n\n const pixelCount = width * height;\n if (pixelCount <= LOW_DETAIL_THRESHOLD) {\n return 'low';\n } else if (pixelCount <= HIGH_DETAIL_THRESHOLD) {\n return 'high';\n } else {\n // For images larger than high detail threshold, use high detail\n return 'auto';\n }\n};\n"],"names":["defaultNormalizeCoords","rawCoords","normalizedCoords","defaultDetailCalculator","width","height","LOW_DETAIL_THRESHOLD","HIGH_DETAIL_THRESHOLD","pixelCount"],"mappings":";;;;AAYO,MAAMA,yBAA+C,CAACC;IAC3D,IAAI,CAACA,UAAU,GAAG,EAChB,OAAO;QAAE,YAAYA;IAAU;IAEjC,MAAMC,mBAAmB;QACvB,GAAGD,SAAS;QACZ,YAAY;YACV,GAAGA,UAAU,GAAG,CAAC,CAAC,GAAG;YACrB,GAAGA,UAAU,GAAG,CAAC,CAAC,GAAG;QACvB;IACF;IACA,OAAO;QAAE,YAAYC;IAAiB;AACxC;AAOO,MAAMC,0BAAiD,CAC5DC,OACAC;IAEA,MAAMC,uBAAuB;IAC7B,MAAMC,wBAAwB;IAE9B,MAAMC,aAAaJ,QAAQC;IAC3B,IAAIG,cAAcF,sBAChB,OAAO;IACF,IAAIE,cAAcD,uBACvB,OAAO;IAGP,OAAO;AAEX"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,QAAQ,IAAI,OAAO,EAAE,MAAM,YAAY,CAAC"}
|