imtoagent 0.3.19 → 0.3.20
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.
|
@@ -69,7 +69,7 @@ export class ClaudeAdapter implements AgentAdapter {
|
|
|
69
69
|
private ctx: ClaudeAdapterContext;
|
|
70
70
|
private activeControllers: AbortController[] = [];
|
|
71
71
|
/** 单次调用最大超时(毫秒),0 = 不限制 */
|
|
72
|
-
static MAX_CALL_TIMEOUT_MS =
|
|
72
|
+
static MAX_CALL_TIMEOUT_MS = 15 * 60 * 1000; // 15 分钟
|
|
73
73
|
|
|
74
74
|
constructor(ctx: ClaudeAdapterContext) {
|
|
75
75
|
this.ctx = ctx;
|
|
@@ -64,12 +64,12 @@ async function ocSendPrompt(
|
|
|
64
64
|
initialText: string,
|
|
65
65
|
system: string,
|
|
66
66
|
defaultModel: { providerID: string; modelID: string },
|
|
67
|
-
|
|
67
|
+
onProgress?: (text: string) => void,
|
|
68
68
|
cancelSignal?: AbortSignal
|
|
69
69
|
): Promise<{ response: string; toolCalls: Array<{ name: string; summary: string }> }> {
|
|
70
70
|
const MAX_TURNS = 50;
|
|
71
|
-
const TURN_TIMEOUT =
|
|
72
|
-
const MAX_DURATION =
|
|
71
|
+
const TURN_TIMEOUT = 900_000; // 15 min per turn
|
|
72
|
+
const MAX_DURATION = 3_600_000; // total timeout 60 min
|
|
73
73
|
const startTime = Date.now();
|
|
74
74
|
|
|
75
75
|
let promptText = initialText;
|
|
@@ -79,7 +79,8 @@ async function ocSendPrompt(
|
|
|
79
79
|
|
|
80
80
|
while (turn < MAX_TURNS) {
|
|
81
81
|
if (Date.now() - startTime > MAX_DURATION) {
|
|
82
|
-
console.error(
|
|
82
|
+
console.error(`[OpenCodeAdapter] Task timed out (${MAX_DURATION / 60000}min)`);
|
|
83
|
+
if (onProgress) onProgress('⚠️ 任务超时,已停止');
|
|
83
84
|
break;
|
|
84
85
|
}
|
|
85
86
|
turn++;
|
|
@@ -130,7 +131,7 @@ async function ocSendPrompt(
|
|
|
130
131
|
const summary = args.command || args.cmd || args.file_path || args.query
|
|
131
132
|
|| JSON.stringify(args).slice(0, 80);
|
|
132
133
|
allToolCalls.push({ name, summary });
|
|
133
|
-
if (
|
|
134
|
+
if (onProgress) onProgress(`🔧 正在执行: ${name} — ${summary.slice(0, 60)}`);
|
|
134
135
|
console.log(`[OpenCodeAdapter] 🔧 turn ${turn}: ${name} ${summary.slice(0, 60)}`);
|
|
135
136
|
}
|
|
136
137
|
}
|
|
@@ -138,6 +139,7 @@ async function ocSendPrompt(
|
|
|
138
139
|
// 有文本回复 → 任务完成(OpenCode 内部已完成多轮 agent loop)
|
|
139
140
|
if (hasText) {
|
|
140
141
|
console.log(`[OpenCodeAdapter] ✅ completed at turn ${turn}/${MAX_TURNS}`);
|
|
142
|
+
if (onProgress) onProgress(`✅ 第 ${turn} 轮处理完成`);
|
|
141
143
|
break;
|
|
142
144
|
}
|
|
143
145
|
|
|
@@ -147,7 +149,8 @@ async function ocSendPrompt(
|
|
|
147
149
|
break;
|
|
148
150
|
}
|
|
149
151
|
|
|
150
|
-
// 仅有 tool_call 无文本 →
|
|
152
|
+
// 仅有 tool_call 无文本 → 推进下一轮
|
|
153
|
+
if (onProgress) onProgress(`⏳ 第 ${turn}/${MAX_TURNS} 轮,继续推进...`);
|
|
151
154
|
promptText = 'Continue executing, complete remaining tasks';
|
|
152
155
|
}
|
|
153
156
|
|
|
@@ -215,16 +218,18 @@ export class OpenCodeAdapter implements AgentAdapter {
|
|
|
215
218
|
console.log(`[OpenCodeAdapter] 📝 system prompt built (${systemPrompt.length} chars)`);
|
|
216
219
|
|
|
217
220
|
// 发送 prompt(多轮循环:自动推进 tool_call → 纯文本响应)
|
|
221
|
+
// 注意:ocSendPrompt 不直接依赖 ctx,由 handleMessage 传入 onProgress 回调
|
|
222
|
+
const onProgress = async (text: string) => {
|
|
223
|
+
try { await input.sendProgress?.(text); } catch {}
|
|
224
|
+
};
|
|
225
|
+
|
|
218
226
|
const { response, toolCalls } = await ocSendPrompt(
|
|
219
227
|
serverUrl,
|
|
220
228
|
sessionAny.ocSessionId,
|
|
221
229
|
effectiveText,
|
|
222
230
|
systemPrompt,
|
|
223
231
|
defaultModel,
|
|
224
|
-
|
|
225
|
-
(name, args) => {
|
|
226
|
-
// 工具调用日志由 Runtime 层统一格式化
|
|
227
|
-
},
|
|
232
|
+
onProgress,
|
|
228
233
|
input.cancelSignal
|
|
229
234
|
);
|
|
230
235
|
|
package/modules/core/runtime.ts
CHANGED
package/modules/core/types.ts
CHANGED