@autotest/agent 0.0.6 → 0.0.7
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 +7 -0
- package/dist/api/agent_api.d.ts +2 -2
- package/dist/autotest-cli.js +1 -397
- package/dist/common/config/config.yaml +4 -0
- package/dist/common/config/manager.d.ts +4 -4
- package/dist/common/config/types.d.ts +5 -0
- package/dist/common/dfx/index.d.ts +1 -1
- package/dist/core/agent/single_agent/agent.d.ts +1 -0
- package/dist/core/device/device_protocol.d.ts +1 -1
- package/dist/core/knowledge/knowledge_manager.d.ts +3 -3
- package/dist/core/knowledge/vectordb.d.ts +5 -5
- package/dist/core/mcp/harmony_hdc_adapter.d.ts +1 -0
- package/dist/core/mcp/mcp_tools.d.ts +1 -0
- package/dist/core/mcp/verify_tool.d.ts +12 -0
- package/dist/core/prompt/templates/single/single_v2.0.md +15 -0
- package/dist/data_types/device.d.ts +1 -1
- package/dist/data_types/index.d.ts +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1 -163
- package/dist/tools/batch_runner.js +1 -745
- package/dist/tools/case_runner/runner.js +1 -410
- package/dist/tools/config/config_tool.js +1 -339
- package/dist/tools/prompt_compare/compare_runner.js +1 -360
- package/package.json +2 -2
- package/dist/api/agent_api.js +0 -550
- package/dist/api/autotest_agent.js +0 -205
- package/dist/api/types.js +0 -11
- package/dist/common/case_manager.js +0 -91
- package/dist/common/collect_case.js +0 -128
- package/dist/common/common_errors.js +0 -66
- package/dist/common/config/config_validator.js +0 -28
- package/dist/common/config/manager.js +0 -257
- package/dist/common/config/output.js +0 -59
- package/dist/common/config/types.js +0 -185
- package/dist/common/dfx/client_factory.js +0 -62
- package/dist/common/dfx/context.js +0 -23
- package/dist/common/dfx/index.js +0 -15
- package/dist/common/dfx/recorder.js +0 -191
- package/dist/common/dfx/recording_fetch.js +0 -228
- package/dist/common/dfx/source.js +0 -13
- package/dist/common/image_cacher.js +0 -36
- package/dist/common/image_helper.js +0 -128
- package/dist/common/image_similarity.js +0 -171
- package/dist/common/llm_cache/cache_transport.js +0 -102
- package/dist/common/llm_cache/prompt_cache.js +0 -113
- package/dist/common/logger.js +0 -158
- package/dist/common/model/custom_model.js +0 -487
- package/dist/common/model/index.js +0 -5
- package/dist/common/path_utils.js +0 -88
- package/dist/common/result_parser.js +0 -49
- package/dist/common/usage/token_usage.js +0 -117
- package/dist/common/utils.js +0 -125
- package/dist/core/agent/layered_agent/ability_helper.js +0 -125
- package/dist/core/agent/layered_agent/agent.js +0 -37
- package/dist/core/agent/layered_agent/agent_registry.js +0 -82
- package/dist/core/agent/layered_agent/decision.js +0 -518
- package/dist/core/agent/layered_agent/execute_agent/action_handler.js +0 -155
- package/dist/core/agent/layered_agent/execute_agent/agent_factory.js +0 -41
- package/dist/core/agent/layered_agent/execute_agent/base_agent.js +0 -112
- package/dist/core/agent/layered_agent/execute_agent/general_agent.js +0 -207
- package/dist/core/agent/layered_agent/execute_agent/glm_agent.js +0 -241
- package/dist/core/agent/layered_agent/execute_agent/i18n.js +0 -34
- package/dist/core/agent/layered_agent/execute_agent/index.js +0 -67
- package/dist/core/agent/layered_agent/execute_agent/mai_ui_agent.js +0 -316
- package/dist/core/agent/layered_agent/execute_agent/mcp_prompts.js +0 -154
- package/dist/core/agent/layered_agent/execute_agent/parser/general_parser.js +0 -243
- package/dist/core/agent/layered_agent/execute_agent/parser/glm_parser.js +0 -139
- package/dist/core/agent/layered_agent/execute_agent/parser/index.js +0 -9
- package/dist/core/agent/layered_agent/execute_agent/parser/mai_ui_parser.js +0 -94
- package/dist/core/agent/layered_agent/execute_agent/prompts.js +0 -109
- package/dist/core/agent/layered_agent/execute_agent/simple_reporter.js +0 -33
- package/dist/core/agent/layered_agent/execute_agent/utils.js +0 -52
- package/dist/core/agent/report_analyzer_agent/agent.js +0 -565
- package/dist/core/agent/report_analyzer_agent/config.js +0 -22
- package/dist/core/agent/report_analyzer_agent/data_loader.js +0 -255
- package/dist/core/agent/report_analyzer_agent/guardrails.js +0 -99
- package/dist/core/agent/report_analyzer_agent/hooks.js +0 -31
- package/dist/core/agent/report_analyzer_agent/index.js +0 -52
- package/dist/core/agent/report_analyzer_agent/key_steps_builder.js +0 -42
- package/dist/core/agent/report_analyzer_agent/mapping.js +0 -133
- package/dist/core/agent/report_analyzer_agent/parse.js +0 -375
- package/dist/core/agent/report_analyzer_agent/prompt.js +0 -300
- package/dist/core/agent/report_analyzer_agent/report_writer.js +0 -558
- package/dist/core/agent/report_analyzer_agent/tools.js +0 -150
- package/dist/core/agent/report_analyzer_agent/types.js +0 -274
- package/dist/core/agent/rewrite_agent/agent.js +0 -209
- package/dist/core/agent/rewrite_agent/guardrails.js +0 -95
- package/dist/core/agent/rewrite_agent/mapping.js +0 -56
- package/dist/core/agent/rewrite_agent/parse.js +0 -121
- package/dist/core/agent/rewrite_agent/types.js +0 -37
- package/dist/core/agent/single_agent/agent.js +0 -801
- package/dist/core/agent/single_agent/hook_manager.js +0 -59
- package/dist/core/agent/single_agent/hooks.js +0 -288
- package/dist/core/agent/single_agent/image_utils.js +0 -158
- package/dist/core/agent/single_agent/scroll_search_agent.js +0 -405
- package/dist/core/agent/single_agent/subagent_manager.js +0 -72
- package/dist/core/agent/single_agent/tool_recorder_hook.js +0 -42
- package/dist/core/agent/types.js +0 -2
- package/dist/core/agent/utils/message_builder.js +0 -138
- package/dist/core/device/device_protocol.js +0 -2
- package/dist/core/device/hdc/apps.js +0 -437
- package/dist/core/device/hdc/device.js +0 -219
- package/dist/core/device/hdc/index.js +0 -31
- package/dist/core/device/hdc/input.js +0 -74
- package/dist/core/device/hdc/screenshot.js +0 -171
- package/dist/core/device/index.js +0 -70
- package/dist/core/device/types.js +0 -2
- package/dist/core/knowledge/knowledge_manager.js +0 -70
- package/dist/core/knowledge/vectordb.js +0 -283
- package/dist/core/mcp/adapter_factory.js +0 -99
- package/dist/core/mcp/android_adapter.js +0 -286
- package/dist/core/mcp/base_adapter.js +0 -86
- package/dist/core/mcp/harmony_hdc_adapter.js +0 -798
- package/dist/core/mcp/ios_adapter.js +0 -286
- package/dist/core/mcp/local_tools.js +0 -41
- package/dist/core/mcp/mcp_tools.js +0 -473
- package/dist/core/mcp/types.js +0 -6
- package/dist/core/memory/_utils.js +0 -140
- package/dist/core/memory/compressed_session.js +0 -182
- package/dist/core/memory/context_compressor.js +0 -176
- package/dist/core/memory/index.js +0 -22
- package/dist/core/memory/memory_manager.js +0 -28
- package/dist/core/memory/reflector.js +0 -95
- package/dist/core/memory/replan_manager.js +0 -12
- package/dist/core/memory/session_factory.js +0 -29
- package/dist/core/memory/tool_player.js +0 -225
- package/dist/core/memory/tool_player_popup.js +0 -276
- package/dist/core/memory/tool_player_replan.js +0 -226
- package/dist/core/memory/tool_player_xpath.js +0 -139
- package/dist/core/memory/tool_recorder.js +0 -126
- package/dist/core/preprocessor/task_splitter.js +0 -112
- package/dist/core/prompt/prompt_loader.js +0 -315
- package/dist/core/skill/skill_manager.js +0 -302
- package/dist/data_types/action.js +0 -2
- package/dist/data_types/agent.js +0 -2
- package/dist/data_types/case.js +0 -57
- package/dist/data_types/device.js +0 -2
- package/dist/data_types/index.js +0 -11
- package/dist/data_types/report.js +0 -6
- package/dist/data_types/screen.js +0 -23
- package/dist/data_types/task.js +0 -2
- package/dist/loop/cli.js +0 -127
- package/dist/loop/orchestrator.js +0 -314
- package/dist/loop/result_writer.js +0 -260
- package/dist/loop/types.js +0 -82
- package/dist/mcp-server/server.js +0 -341
- package/dist/mcp-server/types.js +0 -224
- package/dist/reporter/batch_summary.js +0 -197
- package/dist/reporter/generator.js +0 -286
- package/dist/reporter/html_template/index.js +0 -529
- package/dist/reporter/json_report.js +0 -6
- package/dist/reporter/types.js +0 -45
- package/dist/tools/case_runner/report.js +0 -264
|
@@ -1,487 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.LLMCaller = void 0;
|
|
37
|
-
const crypto = __importStar(require("crypto"));
|
|
38
|
-
const ai_1 = require("ai");
|
|
39
|
-
const openai_1 = require("@ai-sdk/openai");
|
|
40
|
-
const token_usage_1 = require("../../common/usage/token_usage");
|
|
41
|
-
const cache_transport_1 = require("../llm_cache/cache_transport");
|
|
42
|
-
const prompt_cache_1 = require("../llm_cache/prompt_cache");
|
|
43
|
-
const logger_1 = require("../../common/logger");
|
|
44
|
-
const common_errors_1 = require("../../common/common_errors");
|
|
45
|
-
const MAX_SUMMARY_LEN = 300;
|
|
46
|
-
function truncate(s, max = MAX_SUMMARY_LEN) {
|
|
47
|
-
const one = s.replace(/\s+/g, ' ').trim();
|
|
48
|
-
return one.length > max ? `${one.slice(0, max)}…(${one.length} chars)` : one;
|
|
49
|
-
}
|
|
50
|
-
function safeJson(v) {
|
|
51
|
-
try {
|
|
52
|
-
return truncate(typeof v === 'string' ? v : JSON.stringify(v));
|
|
53
|
-
}
|
|
54
|
-
catch {
|
|
55
|
-
return '[unserializable]';
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
/** Build a compact, human-readable summary of a message's content for debug logs. */
|
|
59
|
-
function summarizeMessageContent(content) {
|
|
60
|
-
if (typeof content === 'string') {
|
|
61
|
-
return truncate(content);
|
|
62
|
-
}
|
|
63
|
-
if (!Array.isArray(content)) {
|
|
64
|
-
return '[object]';
|
|
65
|
-
}
|
|
66
|
-
const parts = content;
|
|
67
|
-
const summaries = parts.map((p) => {
|
|
68
|
-
switch (p.type) {
|
|
69
|
-
case 'text':
|
|
70
|
-
return `text:${truncate(String(p.text ?? ''))}`;
|
|
71
|
-
case 'file': {
|
|
72
|
-
const data = p.data;
|
|
73
|
-
const size = data ? data.length : 0;
|
|
74
|
-
return `file(${p.mediaType ?? '?'}, ${size} chars)`;
|
|
75
|
-
}
|
|
76
|
-
case 'image': {
|
|
77
|
-
const img = p.image;
|
|
78
|
-
const size = img ? img.length : 0;
|
|
79
|
-
return `image(${size} chars)`;
|
|
80
|
-
}
|
|
81
|
-
case 'tool-call':
|
|
82
|
-
return `tool-call(${p.toolName ?? '?'})→${safeJson(p.input ?? p.args)}`;
|
|
83
|
-
case 'tool-result':
|
|
84
|
-
return `tool-result(${p.toolName ?? '?'})→${safeJson(p.output ?? p.result)}`;
|
|
85
|
-
default:
|
|
86
|
-
return `${p.type ?? 'unknown'}:${safeJson(p)}`;
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
return `[${summaries.join(' | ')}]`;
|
|
90
|
-
}
|
|
91
|
-
class LLMCaller {
|
|
92
|
-
cacheTransport;
|
|
93
|
-
recordingFetch;
|
|
94
|
-
constructor(cacheTransport, recordingFetch) {
|
|
95
|
-
this.cacheTransport = cacheTransport ?? new cache_transport_1.CacheTransport();
|
|
96
|
-
this.recordingFetch = recordingFetch;
|
|
97
|
-
}
|
|
98
|
-
createProvider(modelConfig, onResponse) {
|
|
99
|
-
const extraBody = { ...(modelConfig.extraBody ?? {}) };
|
|
100
|
-
if (modelConfig.baseUrl.includes('dashscope') && !('enable_thinking' in extraBody)) {
|
|
101
|
-
extraBody.enable_thinking = modelConfig.enableThinking ?? true;
|
|
102
|
-
}
|
|
103
|
-
const baseFetch = this.recordingFetch ?? globalThis.fetch;
|
|
104
|
-
const needsWrapper = Object.keys(extraBody).length > 0 || !!onResponse;
|
|
105
|
-
const opts = {
|
|
106
|
-
baseURL: modelConfig.baseUrl,
|
|
107
|
-
apiKey: modelConfig.apiKey,
|
|
108
|
-
};
|
|
109
|
-
const extraHeaders = modelConfig.extraHeaders;
|
|
110
|
-
if (extraHeaders && Object.keys(extraHeaders).length > 0) {
|
|
111
|
-
opts.headers = extraHeaders;
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
opts.headers = { 'Chat-Id': 'autotest' };
|
|
115
|
-
}
|
|
116
|
-
if (needsWrapper || true) {
|
|
117
|
-
opts.fetch = async (input, init) => {
|
|
118
|
-
if (init?.body && typeof init.body === 'string') {
|
|
119
|
-
try {
|
|
120
|
-
const body = JSON.parse(init.body);
|
|
121
|
-
Object.assign(body, extraBody);
|
|
122
|
-
// DashScope 服务端 prompt cache:在 system message 上注入 cache_control,
|
|
123
|
-
// 跨步骤复用稳定前缀(
|
|
124
|
-
try {
|
|
125
|
-
if ((0, prompt_cache_1.injectPromptCache)(body, modelConfig.baseUrl, modelConfig.name, this.cacheTransport.isEnabled())) {
|
|
126
|
-
logger_1.logger.debug(`LLMCaller: injected cache_control (model=${modelConfig.name})`);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
catch (e) {
|
|
130
|
-
logger_1.logger.warn(`LLMCaller: inject cache_control failed, pass-through: ${e instanceof Error ? e.message : String(e)}`);
|
|
131
|
-
}
|
|
132
|
-
init = { ...init, body: JSON.stringify(body) };
|
|
133
|
-
}
|
|
134
|
-
catch {
|
|
135
|
-
// body is not JSON, skip
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
const response = await baseFetch(input, init);
|
|
139
|
-
// Check for API-level errors (HTTP 200 but error body)
|
|
140
|
-
if (response.ok) {
|
|
141
|
-
try {
|
|
142
|
-
const cloned = response.clone();
|
|
143
|
-
const text = await cloned.text();
|
|
144
|
-
if (text) {
|
|
145
|
-
const json = JSON.parse(text);
|
|
146
|
-
if (json.errorCode || json.error || json.error_msg) {
|
|
147
|
-
const msg = json.errorMsg || json.error?.message || json.error_msg || JSON.stringify(json).slice(0, 300);
|
|
148
|
-
logger_1.logger.error(`LLMCaller: API error (code=${json.errorCode || json.error?.code || '?'}): ${msg}`);
|
|
149
|
-
throw new Error(`LLM API error: ${msg}`);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
catch (e) {
|
|
154
|
-
if (e instanceof Error && e.message.startsWith('LLM API error'))
|
|
155
|
-
throw e;
|
|
156
|
-
// not JSON or already consumed — ignore
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
if (onResponse) {
|
|
160
|
-
try {
|
|
161
|
-
await onResponse(response);
|
|
162
|
-
}
|
|
163
|
-
catch {
|
|
164
|
-
// response interception failure is non-blocking
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
return response;
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
return (0, openai_1.createOpenAI)(opts);
|
|
171
|
-
}
|
|
172
|
-
buildMessages(opts) {
|
|
173
|
-
const messages = [];
|
|
174
|
-
if (opts.images && opts.images.length > 0) {
|
|
175
|
-
messages.push({
|
|
176
|
-
role: 'user',
|
|
177
|
-
content: [
|
|
178
|
-
{ type: 'text', text: opts.userPrompt },
|
|
179
|
-
...opts.images.map((img) => ({
|
|
180
|
-
type: 'file',
|
|
181
|
-
data: `data:${img.mimeType ?? 'image/jpeg'};base64,${img.base64Data}`,
|
|
182
|
-
mediaType: img.mimeType ?? 'image/jpeg',
|
|
183
|
-
})),
|
|
184
|
-
],
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
else {
|
|
188
|
-
messages.push({ role: 'user', content: opts.userPrompt });
|
|
189
|
-
}
|
|
190
|
-
return messages;
|
|
191
|
-
}
|
|
192
|
-
computeCacheKey(opts) {
|
|
193
|
-
const parts = [
|
|
194
|
-
opts.modelConfig.name,
|
|
195
|
-
opts.modelConfig.baseUrl,
|
|
196
|
-
opts.systemPrompt ?? '',
|
|
197
|
-
opts.userPrompt,
|
|
198
|
-
];
|
|
199
|
-
if (opts.images) {
|
|
200
|
-
for (const img of opts.images) {
|
|
201
|
-
parts.push(img.base64Data);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
const raw = parts.join('|');
|
|
205
|
-
return crypto.createHash('sha256').update(raw).digest('hex');
|
|
206
|
-
}
|
|
207
|
-
async call(opts) {
|
|
208
|
-
const cacheKey = this.computeCacheKey(opts);
|
|
209
|
-
const cached = await this.cacheTransport.getCachedResponse(cacheKey);
|
|
210
|
-
if (cached) {
|
|
211
|
-
try {
|
|
212
|
-
const parsed = JSON.parse(cached);
|
|
213
|
-
logger_1.logger.info(`LLMCaller: cache hit for key=${cacheKey}`);
|
|
214
|
-
return parsed;
|
|
215
|
-
}
|
|
216
|
-
catch {
|
|
217
|
-
logger_1.logger.warn(`LLMCaller: cache parse error, proceeding with live call`);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
let capturedReasoning;
|
|
221
|
-
let capturedCacheDetails;
|
|
222
|
-
const provider = this.createProvider(opts.modelConfig, async (response) => {
|
|
223
|
-
const cloned = response.clone();
|
|
224
|
-
try {
|
|
225
|
-
const json = await cloned.json();
|
|
226
|
-
const rc = json?.choices?.[0]?.message?.reasoning_content;
|
|
227
|
-
if (rc)
|
|
228
|
-
capturedReasoning = rc;
|
|
229
|
-
const ptd = json?.usage?.prompt_tokens_details;
|
|
230
|
-
if (ptd && (ptd.cached_tokens || ptd.cache_creation_input_tokens)) {
|
|
231
|
-
capturedCacheDetails = {
|
|
232
|
-
cached_tokens: ptd.cached_tokens ?? 0,
|
|
233
|
-
cache_creation_input_tokens: ptd.cache_creation_input_tokens ?? 0,
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
catch {
|
|
238
|
-
// response not JSON or already consumed
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
const model = provider.chat(opts.modelConfig.name);
|
|
242
|
-
const messages = this.buildMessages(opts);
|
|
243
|
-
const tokenType = (0, token_usage_1.resolveTokenType)(opts.modelConfig.baseUrl);
|
|
244
|
-
logger_1.logger.debug(`LLM call() input → model=${opts.modelConfig.name} messages=${messages.length}`);
|
|
245
|
-
for (const m of messages) {
|
|
246
|
-
const content = typeof m.content === 'string'
|
|
247
|
-
? m.content
|
|
248
|
-
: Array.isArray(m.content)
|
|
249
|
-
? m.content.filter((p) => p.type === 'text').map((p) => p.text ?? '').join('\n') || '[multimodal]'
|
|
250
|
-
: '[multimodal]';
|
|
251
|
-
if (m.role === 'user') {
|
|
252
|
-
logger_1.logger.info(`LLM call() message [user]: ${content}`);
|
|
253
|
-
}
|
|
254
|
-
else {
|
|
255
|
-
logger_1.logger.debug(`LLM call() message [${m.role}]: ${content}`);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
if (opts.tools)
|
|
259
|
-
logger_1.logger.debug(`LLM call() tools: ${Object.keys(opts.tools).join(', ')}`);
|
|
260
|
-
try {
|
|
261
|
-
const generateOpts = {
|
|
262
|
-
model,
|
|
263
|
-
system: opts.systemPrompt,
|
|
264
|
-
messages,
|
|
265
|
-
maxOutputTokens: opts.modelConfig.maxTokens,
|
|
266
|
-
temperature: opts.modelConfig.temperature,
|
|
267
|
-
topP: opts.modelConfig.topP,
|
|
268
|
-
frequencyPenalty: opts.modelConfig.frequencyPenalty,
|
|
269
|
-
};
|
|
270
|
-
if (opts.tools) {
|
|
271
|
-
generateOpts.tools = opts.tools;
|
|
272
|
-
}
|
|
273
|
-
const result = await (0, ai_1.generateText)(generateOpts);
|
|
274
|
-
logger_1.logger.info(`LLM call() output → finishReason=${result.finishReason} text=${result.text}`);
|
|
275
|
-
if (result.toolCalls && result.toolCalls.length > 0) {
|
|
276
|
-
logger_1.logger.debug(`LLM call() toolCalls: ${result.toolCalls.map(tc => tc.toolName).join(', ')}`);
|
|
277
|
-
}
|
|
278
|
-
let reasoning;
|
|
279
|
-
if (result.reasoningText) {
|
|
280
|
-
reasoning = result.reasoningText;
|
|
281
|
-
}
|
|
282
|
-
else if (result.reasoning && result.reasoning.length > 0) {
|
|
283
|
-
reasoning = result.reasoning
|
|
284
|
-
.map((r) => (typeof r === 'object' && 'text' in r ? r.text : String(r)))
|
|
285
|
-
.join('\n');
|
|
286
|
-
}
|
|
287
|
-
else if (capturedReasoning) {
|
|
288
|
-
reasoning = capturedReasoning;
|
|
289
|
-
}
|
|
290
|
-
const toolCalls = [];
|
|
291
|
-
for (const tc of result.toolCalls) {
|
|
292
|
-
if ('input' in tc) {
|
|
293
|
-
toolCalls.push({
|
|
294
|
-
toolName: tc.toolName,
|
|
295
|
-
args: (typeof tc.input === 'object' && tc.input !== null)
|
|
296
|
-
? tc.input
|
|
297
|
-
: {},
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
const usage = result.usage;
|
|
302
|
-
const usageObj = {
|
|
303
|
-
input_tokens: usage.inputTokens ?? 0,
|
|
304
|
-
output_tokens: usage.outputTokens ?? 0,
|
|
305
|
-
total_tokens: usage.totalTokens ?? 0,
|
|
306
|
-
};
|
|
307
|
-
if (capturedCacheDetails) {
|
|
308
|
-
usageObj.input_tokens_details = capturedCacheDetails;
|
|
309
|
-
}
|
|
310
|
-
const tokenUsage = tokenType.fromUsageObj(usageObj);
|
|
311
|
-
const llmResult = {
|
|
312
|
-
text: result.text,
|
|
313
|
-
reasoning,
|
|
314
|
-
toolCalls: toolCalls.length > 0 ? toolCalls : undefined,
|
|
315
|
-
tokenUsage,
|
|
316
|
-
finishReason: result.finishReason ?? 'stop',
|
|
317
|
-
rawResponse: result.providerMetadata,
|
|
318
|
-
};
|
|
319
|
-
await this.cacheTransport.setCachedResponse(cacheKey, JSON.stringify(llmResult));
|
|
320
|
-
logger_1.logger.info(`LLMCaller: call succeeded, tokens=${tokenUsage?.toString() ?? 'N/A'}`);
|
|
321
|
-
return llmResult;
|
|
322
|
-
}
|
|
323
|
-
catch (e) {
|
|
324
|
-
const errMsg = e instanceof Error ? e.message : String(e);
|
|
325
|
-
const errDetails = e instanceof Error && 'responseBody' in e ? ` | responseBody: ${String(e.responseBody)}` : '';
|
|
326
|
-
if (errMsg.includes('data_inspection_failed') || errMsg.includes('content moderation')) {
|
|
327
|
-
logger_1.logger.error(`LLMCaller: DashScope content moderation triggered: ${errMsg}`);
|
|
328
|
-
}
|
|
329
|
-
else {
|
|
330
|
-
logger_1.logger.error(`LLMCaller: call failed: ${errMsg}${errDetails}`);
|
|
331
|
-
}
|
|
332
|
-
if (e instanceof Error && 'errorDetails' in e) {
|
|
333
|
-
logger_1.logger.error(`LLMCaller: errorDetails: ${JSON.stringify(e.errorDetails)}`);
|
|
334
|
-
}
|
|
335
|
-
throw new common_errors_1.AgentError('LLM_API_ERROR', `LLM call failed: ${errMsg}${errDetails}`);
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
async callWithMessages(opts) {
|
|
339
|
-
const cacheKey = 'msgs_' + this.computeMessagesCacheKey(opts.messages, opts.modelConfig);
|
|
340
|
-
const cached = await this.cacheTransport.getCachedResponse(cacheKey);
|
|
341
|
-
if (cached) {
|
|
342
|
-
try {
|
|
343
|
-
const parsed = JSON.parse(cached);
|
|
344
|
-
logger_1.logger.info(`LLMCaller: cache hit for key=${cacheKey}`);
|
|
345
|
-
return parsed;
|
|
346
|
-
}
|
|
347
|
-
catch {
|
|
348
|
-
logger_1.logger.warn(`LLMCaller: cache parse error, proceeding with live call`);
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
let capturedReasoning;
|
|
352
|
-
let capturedCacheDetails;
|
|
353
|
-
const provider = this.createProvider(opts.modelConfig, async (response) => {
|
|
354
|
-
const cloned = response.clone();
|
|
355
|
-
try {
|
|
356
|
-
const json = await cloned.json();
|
|
357
|
-
const rc = json?.choices?.[0]?.message?.reasoning_content;
|
|
358
|
-
if (rc)
|
|
359
|
-
capturedReasoning = rc;
|
|
360
|
-
const ptd = json?.usage?.prompt_tokens_details;
|
|
361
|
-
if (ptd && (ptd.cached_tokens || ptd.cache_creation_input_tokens)) {
|
|
362
|
-
capturedCacheDetails = {
|
|
363
|
-
cached_tokens: ptd.cached_tokens ?? 0,
|
|
364
|
-
cache_creation_input_tokens: ptd.cache_creation_input_tokens ?? 0,
|
|
365
|
-
};
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
catch {
|
|
369
|
-
// response not JSON or already consumed
|
|
370
|
-
}
|
|
371
|
-
});
|
|
372
|
-
const model = provider.chat(opts.modelConfig.name);
|
|
373
|
-
const tokenType = (0, token_usage_1.resolveTokenType)(opts.modelConfig.baseUrl);
|
|
374
|
-
logger_1.logger.debug(`LLM callWithMessages() input → model=${opts.modelConfig.name} messages=${opts.messages.length}`);
|
|
375
|
-
for (const m of opts.messages) {
|
|
376
|
-
const content = typeof m.content === 'string'
|
|
377
|
-
? m.content
|
|
378
|
-
: Array.isArray(m.content)
|
|
379
|
-
? m.content.filter((p) => p.type === 'text').map((p) => p.text ?? '').join('\n') || '[multimodal]'
|
|
380
|
-
: summarizeMessageContent(m.content);
|
|
381
|
-
if (m.role === 'user') {
|
|
382
|
-
logger_1.logger.info(`LLM callWithMessages() message [user]: ${content}`);
|
|
383
|
-
}
|
|
384
|
-
else if (m.role === 'system') {
|
|
385
|
-
// Skip system prompt logging (too verbose, printed once at startup)
|
|
386
|
-
}
|
|
387
|
-
else {
|
|
388
|
-
logger_1.logger.debug(`LLM callWithMessages() message [${m.role}]: ${content}`);
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
if (opts.tools)
|
|
392
|
-
logger_1.logger.debug(`LLM callWithMessages() tools: ${Object.keys(opts.tools).join(', ')}`);
|
|
393
|
-
try {
|
|
394
|
-
const generateOpts = {
|
|
395
|
-
model,
|
|
396
|
-
messages: opts.messages,
|
|
397
|
-
maxOutputTokens: opts.modelConfig.maxTokens,
|
|
398
|
-
temperature: opts.modelConfig.temperature,
|
|
399
|
-
topP: opts.modelConfig.topP,
|
|
400
|
-
frequencyPenalty: opts.modelConfig.frequencyPenalty,
|
|
401
|
-
presencePenalty: opts.modelConfig.presencePenalty,
|
|
402
|
-
};
|
|
403
|
-
if (opts.systemPrompt) {
|
|
404
|
-
generateOpts.system = opts.systemPrompt;
|
|
405
|
-
}
|
|
406
|
-
if (opts.tools) {
|
|
407
|
-
generateOpts.tools = opts.tools;
|
|
408
|
-
}
|
|
409
|
-
const result = await (0, ai_1.generateText)(generateOpts);
|
|
410
|
-
logger_1.logger.info(`LLM callWithMessages() output → finishReason=${result.finishReason} text=${result.text}`);
|
|
411
|
-
if (result.reasoningText)
|
|
412
|
-
logger_1.logger.debug(`LLM callWithMessages() reasoningText: ${result.reasoningText}`);
|
|
413
|
-
if (result.toolCalls && result.toolCalls.length > 0) {
|
|
414
|
-
logger_1.logger.debug(`LLM callWithMessages() toolCalls: ${result.toolCalls.map(tc => `${tc.toolName}(${JSON.stringify(tc.input)})`).join(', ')}`);
|
|
415
|
-
}
|
|
416
|
-
let reasoning;
|
|
417
|
-
if (result.reasoningText) {
|
|
418
|
-
reasoning = result.reasoningText;
|
|
419
|
-
}
|
|
420
|
-
else if (result.reasoning && result.reasoning.length > 0) {
|
|
421
|
-
reasoning = result.reasoning
|
|
422
|
-
.map((r) => (typeof r === 'object' && 'text' in r ? r.text : String(r)))
|
|
423
|
-
.join('\n');
|
|
424
|
-
}
|
|
425
|
-
else if (capturedReasoning) {
|
|
426
|
-
reasoning = capturedReasoning;
|
|
427
|
-
}
|
|
428
|
-
const toolCalls = [];
|
|
429
|
-
for (const tc of result.toolCalls) {
|
|
430
|
-
if ('input' in tc) {
|
|
431
|
-
toolCalls.push({
|
|
432
|
-
toolName: tc.toolName,
|
|
433
|
-
args: (typeof tc.input === 'object' && tc.input !== null)
|
|
434
|
-
? tc.input
|
|
435
|
-
: {},
|
|
436
|
-
toolCallId: tc.toolCallId,
|
|
437
|
-
});
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
const usage = result.usage;
|
|
441
|
-
const usageObj = {
|
|
442
|
-
input_tokens: usage.inputTokens ?? 0,
|
|
443
|
-
output_tokens: usage.outputTokens ?? 0,
|
|
444
|
-
total_tokens: usage.totalTokens ?? 0,
|
|
445
|
-
};
|
|
446
|
-
if (capturedCacheDetails) {
|
|
447
|
-
usageObj.input_tokens_details = capturedCacheDetails;
|
|
448
|
-
}
|
|
449
|
-
const tokenUsage = tokenType.fromUsageObj(usageObj);
|
|
450
|
-
const llmResult = {
|
|
451
|
-
text: result.text,
|
|
452
|
-
reasoning,
|
|
453
|
-
reasoningContent: capturedReasoning,
|
|
454
|
-
toolCalls: toolCalls.length > 0 ? toolCalls : undefined,
|
|
455
|
-
tokenUsage,
|
|
456
|
-
finishReason: result.finishReason ?? 'stop',
|
|
457
|
-
rawResponse: result.providerMetadata,
|
|
458
|
-
responseMessages: result.responseMessages,
|
|
459
|
-
};
|
|
460
|
-
await this.cacheTransport.setCachedResponse(cacheKey, JSON.stringify(llmResult));
|
|
461
|
-
logger_1.logger.info(`LLMCaller: callWithMessages succeeded, tokens=${tokenUsage?.toString() ?? 'N/A'}`);
|
|
462
|
-
return llmResult;
|
|
463
|
-
}
|
|
464
|
-
catch (e) {
|
|
465
|
-
const errMsg = e instanceof Error ? e.message : String(e);
|
|
466
|
-
if (errMsg.includes('data_inspection_failed') || errMsg.includes('content moderation')) {
|
|
467
|
-
logger_1.logger.error(`LLMCaller: DashScope content moderation triggered: ${errMsg}`);
|
|
468
|
-
}
|
|
469
|
-
else {
|
|
470
|
-
logger_1.logger.error(`LLMCaller: callWithMessages failed: ${errMsg}`);
|
|
471
|
-
}
|
|
472
|
-
throw new common_errors_1.AgentError('LLM_API_ERROR', `LLM call failed: ${errMsg}`);
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
computeMessagesCacheKey(messages, modelConfig) {
|
|
476
|
-
const parts = [modelConfig.name, modelConfig.baseUrl];
|
|
477
|
-
for (const m of messages) {
|
|
478
|
-
const content = typeof m.content === 'string'
|
|
479
|
-
? m.content
|
|
480
|
-
: JSON.stringify(m.content);
|
|
481
|
-
parts.push(`${m.role}:${content}`);
|
|
482
|
-
}
|
|
483
|
-
const raw = parts.join('|');
|
|
484
|
-
return crypto.createHash('sha256').update(raw).digest('hex');
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
exports.LLMCaller = LLMCaller;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LLMCaller = void 0;
|
|
4
|
-
var custom_model_1 = require("./custom_model");
|
|
5
|
-
Object.defineProperty(exports, "LLMCaller", { enumerable: true, get: function () { return custom_model_1.LLMCaller; } });
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.findDistRoot = findDistRoot;
|
|
37
|
-
exports.findProjectRoot = findProjectRoot;
|
|
38
|
-
exports.getReportBaseDir = getReportBaseDir;
|
|
39
|
-
const fs = __importStar(require("fs"));
|
|
40
|
-
const path = __importStar(require("path"));
|
|
41
|
-
const PROJECT_ROOT_MARKERS = ['package.json', 'pyproject.toml'];
|
|
42
|
-
/**
|
|
43
|
-
* 定位打包后 dist 根目录。
|
|
44
|
-
*
|
|
45
|
-
* 查找策略(从 __dirname 向上遍历):
|
|
46
|
-
* 1. 优先检查目录同时包含 common/ 和 core/ 子目录(最可靠,不依赖具体文件)
|
|
47
|
-
* 2. 回退检查 common/config/config.yaml 存在(兼容旧逻辑)
|
|
48
|
-
*
|
|
49
|
-
* 兼容普通构建(模块在 dist/core/... 子目录)与单文件 bundle(模块在 dist/index.js)。
|
|
50
|
-
*/
|
|
51
|
-
function findDistRoot() {
|
|
52
|
-
let current = __dirname;
|
|
53
|
-
for (let i = 0; i < 10; i++) {
|
|
54
|
-
if (_isDistRoot(current)) {
|
|
55
|
-
return current;
|
|
56
|
-
}
|
|
57
|
-
const parent = path.dirname(current);
|
|
58
|
-
if (parent === current)
|
|
59
|
-
break;
|
|
60
|
-
current = parent;
|
|
61
|
-
}
|
|
62
|
-
return __dirname;
|
|
63
|
-
}
|
|
64
|
-
function _isDistRoot(dir) {
|
|
65
|
-
return fs.existsSync(path.join(dir, 'common'))
|
|
66
|
-
&& fs.existsSync(path.join(dir, 'core'));
|
|
67
|
-
}
|
|
68
|
-
function findProjectRoot() {
|
|
69
|
-
let current = path.resolve(process.cwd());
|
|
70
|
-
for (let i = 0; i < 10; i++) {
|
|
71
|
-
for (const marker of PROJECT_ROOT_MARKERS) {
|
|
72
|
-
if (fs.existsSync(path.join(current, marker))) {
|
|
73
|
-
return current;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
const parent = path.dirname(current);
|
|
77
|
-
if (parent === current)
|
|
78
|
-
break;
|
|
79
|
-
current = parent;
|
|
80
|
-
}
|
|
81
|
-
return path.resolve(process.cwd());
|
|
82
|
-
}
|
|
83
|
-
function getReportBaseDir(config) {
|
|
84
|
-
const rootDir = config?.rootDir;
|
|
85
|
-
if (rootDir)
|
|
86
|
-
return path.resolve(rootDir);
|
|
87
|
-
return path.join(findProjectRoot(), 'reports');
|
|
88
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LONG_PRESS_ACTIONS = exports.DOUBLE_CLICK_ACTIONS = exports.SWIPE_LIKE_TOOLS = exports.CLICK_LIKE_TOOLS = void 0;
|
|
4
|
-
exports.parseTaskResult = parseTaskResult;
|
|
5
|
-
exports.hasVerdict = hasVerdict;
|
|
6
|
-
const PASS_KEYWORDS = ['pass', 'passed', 'success', 'successful', 'complete', 'completed', '通过', '成功', '完成'];
|
|
7
|
-
const FAIL_KEYWORDS = ['fail', 'failed', 'failure', 'incomplete', 'unsuccessful', '不通过', '失败', '未完成', '未成功', 'max steps', '最大步数', '步数超过'];
|
|
8
|
-
function parseTaskResult(agentStatus, resultText) {
|
|
9
|
-
if (agentStatus) {
|
|
10
|
-
const lower = agentStatus.toLowerCase();
|
|
11
|
-
if (lower === 'pass' || lower === 'passed')
|
|
12
|
-
return { status: 'PASS', reason: agentStatus };
|
|
13
|
-
if (lower === 'fail' || lower === 'failed' || lower === 'error')
|
|
14
|
-
return { status: 'FAIL', reason: agentStatus };
|
|
15
|
-
}
|
|
16
|
-
if (resultText.startsWith('Error:') || resultText.startsWith('错误')) {
|
|
17
|
-
return { status: 'FAIL', reason: resultText };
|
|
18
|
-
}
|
|
19
|
-
const structuredMatch = resultText.match(/(?:任务结果|判定结果)\s*[::]\s*(不?通过)/);
|
|
20
|
-
if (structuredMatch) {
|
|
21
|
-
const verdict = structuredMatch[1];
|
|
22
|
-
if (verdict === '通过')
|
|
23
|
-
return { status: 'PASS', reason: resultText };
|
|
24
|
-
if (verdict === '不通过')
|
|
25
|
-
return { status: 'FAIL', reason: resultText };
|
|
26
|
-
}
|
|
27
|
-
const lower = resultText.toLowerCase();
|
|
28
|
-
for (const kw of FAIL_KEYWORDS) {
|
|
29
|
-
if (lower.includes(kw.toLowerCase())) {
|
|
30
|
-
return { status: 'FAIL', reason: resultText };
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
for (const kw of PASS_KEYWORDS) {
|
|
34
|
-
if (lower.includes(kw.toLowerCase())) {
|
|
35
|
-
return { status: 'PASS', reason: resultText };
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return { status: 'UNKNOWN', reason: resultText };
|
|
39
|
-
}
|
|
40
|
-
function hasVerdict(text) {
|
|
41
|
-
const hasKeyword = text.includes('任务结果') || text.includes('判定结果');
|
|
42
|
-
const hasVerdict = text.includes('通过') || text.includes('不通过');
|
|
43
|
-
const hasEnglish = text.match(/PASS|FAIL/i);
|
|
44
|
-
return (hasKeyword && hasVerdict) || !!hasEnglish;
|
|
45
|
-
}
|
|
46
|
-
exports.CLICK_LIKE_TOOLS = ['click', 'tap', 'double_click', 'double_tap', 'long_press', 'long_click'];
|
|
47
|
-
exports.SWIPE_LIKE_TOOLS = ['swipe', 'drag', 'slide'];
|
|
48
|
-
exports.DOUBLE_CLICK_ACTIONS = ['double_click', 'double_tap', 'doubleclick'];
|
|
49
|
-
exports.LONG_PRESS_ACTIONS = ['long_press', 'long_click', 'longpress'];
|