@wu529778790/open-im 1.10.6 → 1.10.7-beta.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.
@@ -31,5 +31,10 @@ export declare function extractBufferedPayloads(state: {
31
31
  export declare function flushBufferedPayloads(state: {
32
32
  buffer: string;
33
33
  }): string[];
34
+ /**
35
+ * CodeBuddy 会在工具调用前后发来多段 `assistant`:本轮内多为前缀增长的流式全文,
36
+ * 工具后的新轮次则是独立正文。不能每次 `accumulated = text`,否则只剩开场白。
37
+ */
38
+ export declare function mergeAssistantReply(previous: string, incoming: string): string;
34
39
  export declare function runCodeBuddy(cliPath: string, prompt: string, sessionId: string | undefined, workDir: string, callbacks: CodeBuddyRunCallbacks, options?: CodeBuddyRunOptions): CodeBuddyRunHandle;
35
40
  export declare function checkCodeBuddyCliAvailable(cliPath: string): boolean;
@@ -159,6 +159,29 @@ function extractToolUses(content) {
159
159
  }
160
160
  return toolUses;
161
161
  }
162
+ /**
163
+ * CodeBuddy 会在工具调用前后发来多段 `assistant`:本轮内多为前缀增长的流式全文,
164
+ * 工具后的新轮次则是独立正文。不能每次 `accumulated = text`,否则只剩开场白。
165
+ */
166
+ export function mergeAssistantReply(previous, incoming) {
167
+ const a = previous.trimEnd();
168
+ const b = incoming.trim();
169
+ if (!b)
170
+ return a;
171
+ if (!a)
172
+ return b;
173
+ if (a === b)
174
+ return a;
175
+ if (b.startsWith(a))
176
+ return b;
177
+ if (a.startsWith(b))
178
+ return a;
179
+ if (a.includes(b))
180
+ return a;
181
+ if (b.includes(a))
182
+ return b;
183
+ return `${a}\n\n${b}`;
184
+ }
162
185
  export function runCodeBuddy(cliPath, prompt, sessionId, workDir, callbacks, options) {
163
186
  const normalizedCliPath = normalizeCliPath(cliPath);
164
187
  const args = buildCodeBuddyArgs(prompt, sessionId, {
@@ -186,6 +209,7 @@ export function runCodeBuddy(cliPath, prompt, sessionId, workDir, callbacks, opt
186
209
  let completed = false;
187
210
  let sessionReported = false;
188
211
  let currentModel;
212
+ let assistantMessageCount = 0;
189
213
  const toolStats = {};
190
214
  const startTime = Date.now();
191
215
  const stdoutState = { buffer: '' };
@@ -220,6 +244,7 @@ export function runCodeBuddy(cliPath, prompt, sessionId, workDir, callbacks, opt
220
244
  : undefined;
221
245
  if (!message)
222
246
  return;
247
+ assistantMessageCount += 1;
223
248
  if (typeof message.model === 'string')
224
249
  currentModel = message.model;
225
250
  const { text, thinking } = extractTextBlocks(message.content);
@@ -228,11 +253,11 @@ export function runCodeBuddy(cliPath, prompt, sessionId, workDir, callbacks, opt
228
253
  callbacks.onToolUse?.(toolUse.name, toolUse.input);
229
254
  }
230
255
  if (thinking) {
231
- accumulatedThinking = thinking;
256
+ accumulatedThinking = mergeAssistantReply(accumulatedThinking, thinking);
232
257
  callbacks.onThinking?.(accumulatedThinking);
233
258
  }
234
259
  if (text) {
235
- accumulated = text;
260
+ accumulated = mergeAssistantReply(accumulated, text);
236
261
  callbacks.onText(accumulated);
237
262
  }
238
263
  return;
@@ -240,11 +265,14 @@ export function runCodeBuddy(cliPath, prompt, sessionId, workDir, callbacks, opt
240
265
  if (type === 'result') {
241
266
  if (completed)
242
267
  return;
243
- completed = true;
244
268
  const isError = payload.is_error === true;
245
- const resultText = typeof payload.result === 'string'
246
- ? payload.result
247
- : accumulated;
269
+ const rawResult = typeof payload.result === 'string' ? payload.result : undefined;
270
+ const resultText = rawResult !== undefined && rawResult.trim() !== '' ? rawResult : accumulated;
271
+ if (!isError && !resultText.trim()) {
272
+ log.debug('CodeBuddy: ignoring empty success result (waiting for more stream or process exit)');
273
+ return;
274
+ }
275
+ completed = true;
248
276
  if (isError) {
249
277
  const errors = Array.isArray(payload.errors)
250
278
  ? payload.errors.map((item) => String(item)).join('\n')
@@ -259,7 +287,7 @@ export function runCodeBuddy(cliPath, prompt, sessionId, workDir, callbacks, opt
259
287
  cost: 0,
260
288
  durationMs: Date.now() - startTime,
261
289
  model: currentModel,
262
- numTurns: 1,
290
+ numTurns: Math.max(1, assistantMessageCount),
263
291
  toolStats,
264
292
  });
265
293
  }
@@ -310,7 +338,7 @@ export function runCodeBuddy(cliPath, prompt, sessionId, workDir, callbacks, opt
310
338
  cost: 0,
311
339
  durationMs: Date.now() - startTime,
312
340
  model: currentModel,
313
- numTurns: accumulated ? 1 : 0,
341
+ numTurns: Math.max(accumulated ? 1 : 0, assistantMessageCount),
314
342
  toolStats,
315
343
  });
316
344
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wu529778790/open-im",
3
- "version": "1.10.6",
3
+ "version": "1.10.7-beta.0",
4
4
  "description": "Multi-platform IM bridge for AI CLI tools (Claude, Codex, CodeBuddy)",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",