@dcrays/dcgchat-test 0.3.5 → 0.3.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcrays/dcgchat-test",
3
- "version": "0.3.5",
3
+ "version": "0.3.6",
4
4
  "type": "module",
5
5
  "description": "OpenClaw channel plugin for 书灵墨宝 (WebSocket)",
6
6
  "main": "index.ts",
package/src/bot.ts CHANGED
@@ -182,10 +182,10 @@ export async function handleDcgchatMessage(msg: InboundMessage, accountId: strin
182
182
  effectiveAgentId && effectiveAgentId !== 'main' ? config.agents?.list?.find((a) => a.id === effectiveAgentId) : undefined
183
183
  const agentDisplayName = agentEntry?.name ?? (effectiveAgentId && effectiveAgentId !== 'main' ? effectiveAgentId : undefined)
184
184
 
185
- const safeSendFinal = () => {
185
+ const safeSendFinal = (tag: string) => {
186
186
  if (finalSent) return
187
187
  finalSent = true
188
- sendFinal(outboundCtx)
188
+ sendFinal(outboundCtx, tag)
189
189
  setMsgStatus(effectiveSessionKey, 'finished')
190
190
  }
191
191
 
@@ -193,7 +193,7 @@ export async function handleDcgchatMessage(msg: InboundMessage, accountId: strin
193
193
 
194
194
  if (!text) {
195
195
  sendTextMsg('你需要我帮你做什么呢?', outboundCtx)
196
- safeSendFinal()
196
+ safeSendFinal('not text')
197
197
  return
198
198
  }
199
199
 
@@ -272,13 +272,7 @@ export async function handleDcgchatMessage(msg: InboundMessage, accountId: strin
272
272
  }
273
273
  },
274
274
  onError: (err: unknown, info: { kind: string }) => {
275
- activeRunIdBySessionKey.delete(effectiveSessionKey)
276
- streamChunkIdxBySessionKey.delete(effectiveSessionKey)
277
- if (sessionStreamSuppressed.has(effectiveSessionKey)) {
278
- dcgLogger(`${info.kind} reply failed (stream suppressed): ${String(err)}`, 'error')
279
- return
280
- }
281
- safeSendFinal()
275
+ safeSendFinal('error')
282
276
  dcgLogger(`${info.kind} reply failed: ${String(err)}`, 'error')
283
277
  },
284
278
  onIdle: () => {
@@ -309,7 +303,6 @@ export async function handleDcgchatMessage(msg: InboundMessage, accountId: strin
309
303
  } else if (interruptCommand.includes(text?.trim())) {
310
304
  dcgLogger(`interrupt command: ${text}`)
311
305
  sendText('会话已终止', outboundCtx)
312
- safeSendFinal()
313
306
  sessionStreamSuppressed.add(effectiveSessionKey)
314
307
  const runId = activeRunIdBySessionKey.get(effectiveSessionKey)
315
308
  sendMessageToGateway(
@@ -322,6 +315,7 @@ export async function handleDcgchatMessage(msg: InboundMessage, accountId: strin
322
315
  })
323
316
  )
324
317
  if (runId) activeRunIdBySessionKey.delete(effectiveSessionKey)
318
+ safeSendFinal('stop')
325
319
  return
326
320
  } else {
327
321
  dcgLogger(`dispatching to agent (session=${route.sessionKey})`)
@@ -430,7 +424,7 @@ export async function handleDcgchatMessage(msg: InboundMessage, accountId: strin
430
424
  }
431
425
  }
432
426
  }
433
- safeSendFinal()
427
+ safeSendFinal('end')
434
428
  clearSentMediaKeys(msg.content.message_id)
435
429
 
436
430
  // Record session metadata
@@ -451,6 +445,6 @@ export async function handleDcgchatMessage(msg: InboundMessage, accountId: strin
451
445
  dcgLogger(` handle message failed: ${String(err)}`, 'error')
452
446
  sendError(err instanceof Error ? err.message : String(err), outboundCtx)
453
447
  } finally {
454
- safeSendFinal()
448
+ safeSendFinal('finally')
455
449
  }
456
450
  }
package/src/tool.ts CHANGED
@@ -109,7 +109,7 @@ export function monitoringToolMessage(api: OpenClawPluginApi) {
109
109
  if (event.lastAssistant?.errorMessage === '429-账户额度耗尽') {
110
110
  const message = '您的积分已消耗完,您可以通过充值积分来继续使用'
111
111
  sendText(message, msgCtx, { message_tags: { insufficient_balance: 1 }, is_finish: -1 })
112
- sendFinal(msgCtx)
112
+ sendFinal(msgCtx, '积分不足')
113
113
  return
114
114
  }
115
115
  }
package/src/transport.ts CHANGED
@@ -162,8 +162,8 @@ export function sendChunk(text: string, ctx: IMsgParams, chunkIdx: number): bool
162
162
  return wsSend(ctx, { response: text, state: 'chunk', chunk_idx: chunkIdx })
163
163
  }
164
164
 
165
- export function sendFinal(ctx: IMsgParams): boolean {
166
- dcgLogger(` message handling complete state: final`)
165
+ export function sendFinal(ctx: IMsgParams, tag?: string): boolean {
166
+ dcgLogger(` message handling complete state: final tag:${tag}`)
167
167
  return wsSend(ctx, { response: '', state: 'final' })
168
168
  }
169
169