opencode-chat-channel 1.2.9 → 1.2.11

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/channels/feishu/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,OAAO,KAAK,EAAe,cAAc,EAAiC,MAAM,gBAAgB,CAAC;AAoOjG;;;GAGG;AACH,eAAO,MAAM,oBAAoB,EAAE,cAuBlC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/channels/feishu/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,OAAO,KAAK,EAAe,cAAc,EAAiC,MAAM,gBAAgB,CAAC;AAmOjG;;;GAGG;AACH,eAAO,MAAM,oBAAoB,EAAE,cAuBlC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAyTlD,eAAO,MAAM,iBAAiB,EAAE,MAyF/B,CAAC;AAEF,eAAe,iBAAiB,CAAC;AAMjC,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,WAAW,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAsVlD,eAAO,MAAM,iBAAiB,EAAE,MAyF/B,CAAC;AAEF,eAAe,iBAAiB,CAAC;AAMjC,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,WAAW,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
package/dist/index.js CHANGED
@@ -221,14 +221,12 @@ class FeishuChannel {
221
221
  function buildThinkingCard(text) {
222
222
  return {
223
223
  config: { update_multi: true },
224
- body: {
225
- elements: [
226
- {
227
- tag: "markdown",
228
- content: text
229
- }
230
- ]
231
- }
224
+ elements: [
225
+ {
226
+ tag: "markdown",
227
+ content: text
228
+ }
229
+ ]
232
230
  };
233
231
  }
234
232
  var feishuChannelFactory = async (client) => {
@@ -406,32 +404,56 @@ async function consumeSessionEvents(client, channel, sessionId, replyTarget, thi
406
404
  await channel.updateThinkingCard(thinkingMsgId, text);
407
405
  }
408
406
  if (eventStream) {
407
+ let alreadyDone = false;
409
408
  try {
410
- for await (const event of eventStream.stream) {
411
- if (!isSessionEvent(event, sessionId))
412
- continue;
413
- if (event.type === "message.part.updated") {
414
- const part = event.properties?.part;
415
- if (!part)
409
+ const statusRes = await client.session.status();
410
+ const allStatuses = statusRes.data ?? {};
411
+ const sessionStatus = allStatuses[sessionId];
412
+ if (!sessionStatus || sessionStatus.type === "idle") {
413
+ alreadyDone = true;
414
+ log("info", `[${channel.name}] session 已完成,跳过 SSE 等待`);
415
+ }
416
+ } catch {}
417
+ if (!alreadyDone) {
418
+ const SSE_TIMEOUT_MS = 3 * 60 * 1000;
419
+ const abortController = new AbortController;
420
+ const timeoutId = setTimeout(() => {
421
+ log("warn", `[${channel.name}] SSE 等待超时,强制结束`);
422
+ abortController.abort();
423
+ }, SSE_TIMEOUT_MS);
424
+ try {
425
+ for await (const event of eventStream.stream) {
426
+ if (abortController.signal.aborted)
427
+ break;
428
+ if (!isSessionEvent(event, sessionId))
416
429
  continue;
417
- if (part.type === "reasoning" && part.text) {
418
- reasoningAccum = part.text;
419
- const preview = stripMarkdownTables(reasoningAccum.slice(0, REASONING_PREVIEW_LEN));
420
- const suffix = reasoningAccum.length > REASONING_PREVIEW_LEN ? "..." : "";
421
- await throttledPatch(`\uD83D\uDCAD **正在思考...**
430
+ if (event.type === "message.part.updated") {
431
+ const part = event.properties?.part;
432
+ if (!part)
433
+ continue;
434
+ if (part.type === "reasoning" && part.text) {
435
+ reasoningAccum = part.text;
436
+ const preview = stripMarkdownTables(reasoningAccum.slice(0, REASONING_PREVIEW_LEN));
437
+ const suffix = reasoningAccum.length > REASONING_PREVIEW_LEN ? "..." : "";
438
+ await throttledPatch(`\uD83D\uDCAD **正在思考...**
422
439
 
423
440
  ${preview}${suffix}`);
424
- } else if (part.type === "tool" && part.state?.status === "running") {
425
- const toolLabel = (part.tool ?? "") || "工具";
426
- await throttledPatch(`\uD83D\uDD27 **正在使用工具:${toolLabel}**`);
441
+ } else if (part.type === "tool" && part.state?.status === "running") {
442
+ const toolLabel = (part.tool ?? "") || "工具";
443
+ await throttledPatch(`\uD83D\uDD27 **正在使用工具:${toolLabel}**`);
444
+ }
445
+ }
446
+ if (event.type === "session.idle" || event.type === "session.error") {
447
+ break;
427
448
  }
428
449
  }
429
- if (event.type === "session.idle" || event.type === "session.error") {
430
- break;
450
+ } catch (err) {
451
+ if (!abortController.signal.aborted) {
452
+ log("warn", `[${channel.name}] SSE 事件流中断: ${String(err)}`);
431
453
  }
454
+ } finally {
455
+ clearTimeout(timeoutId);
432
456
  }
433
- } catch (err) {
434
- log("warn", `[${channel.name}] SSE 事件流中断: ${String(err)}`);
435
457
  }
436
458
  } else {
437
459
  await pollForSessionCompletion(client, channel.name, sessionId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-chat-channel",
3
- "version": "1.2.9",
3
+ "version": "1.2.11",
4
4
  "description": "opencode plugin — multi-channel bot (Feishu/Lark, WeCom) with extensible ChatChannel interface",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",