imtoagent 0.3.20 → 0.3.21

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.
@@ -100,6 +100,10 @@ export class ClaudeAdapter implements AgentAdapter {
100
100
  const { text, session, workingDir, model, systemPrompt: overrideSystemPrompt } = input;
101
101
  const sessionAny = session as any; // 向后兼容:访问旧字段
102
102
 
103
+ // 进度回调
104
+ const onProgress = async (t: string) => { try { await input.sendProgress?.(t); } catch {} };
105
+ let turnCount = 0;
106
+
103
107
  // 创建 AbortController 并注册(用于超时 + shutdown 清理)
104
108
  const abortCtrl = new AbortController();
105
109
  this.activeControllers.push(abortCtrl);
@@ -205,6 +209,16 @@ export class ClaudeAdapter implements AgentAdapter {
205
209
  const calls = extractToolCalls(msg);
206
210
  toolCalls.push(...calls);
207
211
 
212
+ // 进度输出(仅 assistant 消息)
213
+ if (msg.type === 'assistant') {
214
+ turnCount++;
215
+ if (calls.length > 0) {
216
+ const names = calls.map(c => c.name).join(', ');
217
+ const summary = calls[0].summary.slice(0, 60);
218
+ onProgress(`🔧 Executing: ${names} — ${summary}`);
219
+ }
220
+ }
221
+
208
222
  // 处理最终结果
209
223
  if (msg.type === 'result') {
210
224
  const result = msgAny;
@@ -222,6 +236,7 @@ export class ClaudeAdapter implements AgentAdapter {
222
236
  };
223
237
 
224
238
  if (timeoutId) clearTimeout(timeoutId);
239
+ if (turnCount > 0) onProgress(`✅ Turn ${turnCount} completed`);
225
240
  const responseText = fullResponse || `✅ Completed (${toolCalls.length} steps)`;
226
241
 
227
242
  return {
@@ -106,8 +106,9 @@ async function spawnCodexResume(cwd: string, threadId: string, prompt: string):
106
106
 
107
107
  async function runViaAppServer(
108
108
  cwd: string, prompt: string, chatId: string, session: Session,
109
- isFresh: boolean
109
+ isFresh: boolean, onProgress?: (text: string) => Promise<void>
110
110
  ): Promise<{ threadId: string; response: string; usage: { inputTokens: number; outputTokens: number } }> {
111
+ let turnCount = 0;
111
112
  const manager = getAppServerManager();
112
113
  const client = await manager.getClient(chatId);
113
114
 
@@ -138,9 +139,14 @@ async function runViaAppServer(
138
139
  case 'text_delta':
139
140
  response += event.textDelta || '';
140
141
  break;
141
- case 'tool_call':
142
- break; // tool 日志由 Runtime 层处理
142
+ case 'tool_call': {
143
+ const name = (event as any).toolCall?.name || (event as any).tool?.name || 'Tool';
144
+ onProgress?.(`🔧 Executing: ${name}`);
145
+ break;
146
+ }
143
147
  case 'turn_result':
148
+ turnCount++;
149
+ onProgress?.(`✅ Turn ${turnCount} completed`);
144
150
  totalUsage.inputTokens += event.usage?.inputTokens || 0;
145
151
  totalUsage.outputTokens += event.usage?.outputTokens || 0;
146
152
  break;
@@ -189,7 +195,8 @@ export class CodexAdapter implements AgentAdapter {
189
195
  let execServerUsage: { inputTokens: number; outputTokens: number } | null = null;
190
196
 
191
197
  try {
192
- const r = await runViaAppServer(cwd, effectiveText, input.chatId, session, isFresh);
198
+ const r = await runViaAppServer(cwd, effectiveText, input.chatId, session, isFresh,
199
+ async (t: string) => { try { await input.sendProgress?.(t); } catch {} });
193
200
  response = r.response;
194
201
  execServerUsage = r.usage;
195
202
  } catch (appErr: any) {
@@ -199,7 +206,8 @@ export class CodexAdapter implements AgentAdapter {
199
206
  if (errMsg.includes('thread not found') || errMsg.includes('Thread not found')) {
200
207
  try {
201
208
  sessionAny.codexThreadId = undefined;
202
- const r2 = await runViaAppServer(cwd, effectiveText, input.chatId, session, true);
209
+ const r2 = await runViaAppServer(cwd, effectiveText, input.chatId, session, true,
210
+ async (t: string) => { try { await input.sendProgress?.(t); } catch {} });
203
211
  response = r2.response;
204
212
  execServerUsage = r2.usage;
205
213
  console.error(`[CodexAdapter] app-server thread rebuilt successfully`);
@@ -213,6 +221,7 @@ export class CodexAdapter implements AgentAdapter {
213
221
 
214
222
  if (useExecFallback) {
215
223
  getAppServerManager().removeClient(input.chatId);
224
+ input.sendProgress?.('⚙️ Processing... (CLI mode, no streaming progress)').catch(() => {});
216
225
  if (isFresh || !sessionAny.codexThreadId) {
217
226
  const r = await spawnCodexExec(cwd, effectiveText);
218
227
  sessionAny.codexThreadId = r.threadId;
@@ -80,7 +80,7 @@ async function ocSendPrompt(
80
80
  while (turn < MAX_TURNS) {
81
81
  if (Date.now() - startTime > MAX_DURATION) {
82
82
  console.error(`[OpenCodeAdapter] Task timed out (${MAX_DURATION / 60000}min)`);
83
- if (onProgress) onProgress('⚠️ 任务超时,已停止');
83
+ if (onProgress) onProgress('⚠️ Task timed out, stopped');
84
84
  break;
85
85
  }
86
86
  turn++;
@@ -131,7 +131,7 @@ async function ocSendPrompt(
131
131
  const summary = args.command || args.cmd || args.file_path || args.query
132
132
  || JSON.stringify(args).slice(0, 80);
133
133
  allToolCalls.push({ name, summary });
134
- if (onProgress) onProgress(`🔧 正在执行: ${name} — ${summary.slice(0, 60)}`);
134
+ if (onProgress) onProgress(`🔧 Executing: ${name} — ${summary.slice(0, 60)}`);
135
135
  console.log(`[OpenCodeAdapter] 🔧 turn ${turn}: ${name} ${summary.slice(0, 60)}`);
136
136
  }
137
137
  }
@@ -139,7 +139,7 @@ async function ocSendPrompt(
139
139
  // 有文本回复 → 任务完成(OpenCode 内部已完成多轮 agent loop)
140
140
  if (hasText) {
141
141
  console.log(`[OpenCodeAdapter] ✅ completed at turn ${turn}/${MAX_TURNS}`);
142
- if (onProgress) onProgress(`✅ ${turn} 轮处理完成`);
142
+ if (onProgress) onProgress(`✅ Turn ${turn} completed`);
143
143
  break;
144
144
  }
145
145
 
@@ -150,7 +150,7 @@ async function ocSendPrompt(
150
150
  }
151
151
 
152
152
  // 仅有 tool_call 无文本 → 推进下一轮
153
- if (onProgress) onProgress(`⏳ ${turn}/${MAX_TURNS} 轮,继续推进...`);
153
+ if (onProgress) onProgress(`⏳ Turn ${turn}/${MAX_TURNS}, continuing...`);
154
154
  promptText = 'Continue executing, complete remaining tasks';
155
155
  }
156
156
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "imtoagent",
3
- "version": "0.3.20",
3
+ "version": "0.3.21",
4
4
  "description": "IM ↔ Agent 统一网关 — 飞书/Telegram/微信/企业微信对接 Claude Code/Codex/OpenCode",
5
5
  "type": "module",
6
6
  "bin": {