@dcrays/dcgchat-test 0.3.4 → 0.3.5

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.4",
3
+ "version": "0.3.5",
4
4
  "type": "module",
5
5
  "description": "OpenClaw channel plugin for 书灵墨宝 (WebSocket)",
6
6
  "main": "index.ts",
package/src/bot.ts CHANGED
@@ -282,10 +282,7 @@ export async function handleDcgchatMessage(msg: InboundMessage, accountId: strin
282
282
  dcgLogger(`${info.kind} reply failed: ${String(err)}`, 'error')
283
283
  },
284
284
  onIdle: () => {
285
- activeRunIdBySessionKey.delete(effectiveSessionKey)
286
- streamChunkIdxBySessionKey.delete(effectiveSessionKey)
287
- if (sessionStreamSuppressed.has(effectiveSessionKey)) return
288
- safeSendFinal()
285
+ // safeSendFinal()
289
286
  }
290
287
  })
291
288
 
package/src/channel.ts CHANGED
@@ -159,7 +159,7 @@ export const dcgchatPlugin: ChannelPlugin<ResolvedDcgchatAccount> = {
159
159
  const outboundCtx = getEffectiveMsgParams(ctx.to)
160
160
  const messageId = getCronMessageId(ctx.to)
161
161
  const newCtx = messageId ? { ...outboundCtx, messageId } : outboundCtx
162
- wsSendRaw(newCtx, { response: ctx.text, is_finish: -1 })
162
+ wsSendRaw(newCtx, { response: ctx.text, is_finish: -1, message_tags: { source: 'channel' } })
163
163
  dcgLogger(`channel sendText to ${ctx.to} ${ctx.text?.slice(0, 50)}`)
164
164
  }
165
165
  return {
package/src/monitor.ts CHANGED
@@ -8,6 +8,7 @@ import { installSkill, uninstallSkill } from './skill.js'
8
8
  import { dcgLogger } from './utils/log.js'
9
9
  import { onDisabledCronJob, onEnabledCronJob, onRemoveCronJob, onRunCronJob } from './cron.js'
10
10
  import { ignoreToolCommand } from './utils/constant.js'
11
+ import { isWsOpen } from './transport.js'
11
12
 
12
13
  export type MonitorDcgchatOpts = {
13
14
  config?: ClawdbotConfig
@@ -64,22 +65,24 @@ export async function monitorDcgchatProvider(opts: MonitorDcgchatOpts): Promise<
64
65
  heartbeatTimer = null
65
66
  }
66
67
  }
67
-
68
+ function onHeartbeat() {
69
+ if (isWsOpen()) {
70
+ const heartbeat = {
71
+ messageType: 'openclaw_bot_heartbeat',
72
+ _userId: Number(account.userId) || 0,
73
+ source: 'client',
74
+ content: {
75
+ bot_token: account.botToken,
76
+ status: '1'
77
+ }
78
+ }
79
+ ws?.send(JSON.stringify(heartbeat))
80
+ }
81
+ }
68
82
  const startHeartbeat = () => {
69
83
  stopHeartbeat()
70
84
  heartbeatTimer = setInterval(() => {
71
- if (ws?.readyState === WebSocket.OPEN) {
72
- const heartbeat = {
73
- messageType: 'openclaw_bot_heartbeat',
74
- _userId: Number(account.userId) || 0,
75
- source: 'client',
76
- content: {
77
- bot_token: account.botToken,
78
- status: '1'
79
- }
80
- }
81
- ws.send(JSON.stringify(heartbeat))
82
- }
85
+ onHeartbeat()
83
86
  }, HEARTBEAT_INTERVAL_MS)
84
87
  }
85
88
 
@@ -94,6 +97,7 @@ export async function monitorDcgchatProvider(opts: MonitorDcgchatOpts): Promise<
94
97
  dcgLogger(`socket connected`)
95
98
  setWsConnection(ws)
96
99
  startHeartbeat()
100
+ onHeartbeat()
97
101
  })
98
102
 
99
103
  ws.on('message', async (data) => {
@@ -109,7 +113,7 @@ export async function monitorDcgchatProvider(opts: MonitorDcgchatOpts): Promise<
109
113
  const heartbeat = isOpenclawBotHeartbeat(data, parsed)
110
114
  if (heartbeat) {
111
115
  heartbeatLogCounter += 1
112
- if (heartbeatLogCounter % 10 === 0) {
116
+ if (heartbeatLogCounter % 10 === 0 || heartbeatLogCounter === 1) {
113
117
  dcgLogger(`${parsed?.messageType}, ${payloadStr}`)
114
118
  dcgLogger(`heartbeat ack received, ${payloadStr}`)
115
119
  }