@dcrays/dcgchat-test 0.3.14 → 0.3.16

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.
Files changed (3) hide show
  1. package/package.json +1 -1
  2. package/src/bot.ts +14 -6
  3. package/src/cron.ts +19 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcrays/dcgchat-test",
3
- "version": "0.3.14",
3
+ "version": "0.3.16",
4
4
  "type": "module",
5
5
  "description": "OpenClaw channel plugin for 书灵墨宝 (WebSocket)",
6
6
  "main": "index.ts",
package/src/bot.ts CHANGED
@@ -3,6 +3,7 @@ import path from 'node:path'
3
3
  import type { ReplyPayload } from 'openclaw/plugin-sdk'
4
4
  import { createReplyPrefixContext } from 'openclaw/plugin-sdk'
5
5
  import type { InboundMessage } from './types.js'
6
+ import os from 'node:os'
6
7
  import {
7
8
  clearSentMediaKeys,
8
9
  getDcgchatRuntime,
@@ -274,10 +275,15 @@ export async function handleDcgchatMessage(msg: InboundMessage, accountId: strin
274
275
  onError: (err: unknown, info: { kind: string }) => {
275
276
  safeSendFinal('error')
276
277
  dcgLogger(`${info.kind} reply failed: ${String(err)}`, 'error')
278
+ activeRunIdBySessionKey.delete(effectiveSessionKey)
279
+ streamChunkIdxBySessionKey.delete(effectiveSessionKey)
280
+ if (sessionStreamSuppressed.has(effectiveSessionKey)) {
281
+ dcgLogger(`${info.kind} reply failed (stream suppressed): ${String(err)}`, 'error')
282
+ return
283
+ }
284
+ dcgLogger(`${info.kind} reply failed: ${String(err)}`, 'error')
277
285
  },
278
- onIdle: () => {
279
- // safeSendFinal()
280
- }
286
+ onIdle: () => {}
281
287
  })
282
288
 
283
289
  try {
@@ -409,10 +415,12 @@ export async function handleDcgchatMessage(msg: InboundMessage, accountId: strin
409
415
  const candidates: string[] = [file]
410
416
  candidates.push(path.join(getWorkspaceDir(), file))
411
417
  candidates.push(path.join(getWorkspaceDir(), file.replace(/^\//, '')))
412
- if (process.platform === 'win32') {
413
- const underMobook = file.replace(/^\/mobook\//i, '').replace(/^mobook[\\/]/i, '')
414
- if (underMobook) {
418
+ const underMobook = file.replace(/^\/mobook\//i, '').replace(/^mobook[\\/]/i, '')
419
+ if (underMobook) {
420
+ if (process.platform === 'win32') {
415
421
  candidates.push(path.join('C:\\', 'mobook', underMobook))
422
+ } else if (process.platform === 'darwin') {
423
+ candidates.push(path.join(os.homedir(), 'mobook', underMobook))
416
424
  }
417
425
  }
418
426
  const resolved = candidates.find((p) => fs.existsSync(p))
package/src/cron.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import path from 'node:path'
2
2
  import fs from 'node:fs'
3
3
  import type { IMsgParams } from './types.js'
4
- import { sendEventMessage, sendFinal } from './transport.js'
5
- import { getWorkspaceDir, removeCronMessageId, setCronMessageId, setMsgStatus } from './utils/global.js'
4
+ import { mergeDefaultParams, sendEventMessage, sendFinal } from './transport.js'
5
+ import { getCronMessageId, getWorkspaceDir, removeCronMessageId, setCronMessageId, setMsgStatus } from './utils/global.js'
6
6
  import { ossUpload } from './request/oss.js'
7
7
  import { dcgLogger } from './utils/log.js'
8
8
  import { sendMessageToGateway } from './gateway/socket.js'
@@ -152,7 +152,23 @@ export const finishedDcgchatCron = async (jobId: string) => {
152
152
  return
153
153
  }
154
154
  const outboundCtx = getEffectiveMsgParams(sessionKey)
155
- sendFinal(outboundCtx)
155
+ const messageId = getCronMessageId(sessionKey)
156
+ if (outboundCtx?.sessionId) {
157
+ const newCtx = messageId ? { ...outboundCtx, messageId } : outboundCtx
158
+ sendFinal(newCtx)
159
+ } else {
160
+ const sessionInfo = sessionKey.split(':')
161
+ const sessionId = sessionInfo.at(-1) ?? ''
162
+ const agentId = sessionInfo.at(-2) ?? ''
163
+ const merged = mergeDefaultParams({
164
+ agentId: agentId,
165
+ sessionId: `${sessionId}`,
166
+ messageId: messageId,
167
+ is_finish: -1,
168
+ real_mobook: !sessionId ? 1 : ''
169
+ })
170
+ sendFinal(merged, 'cron send')
171
+ }
156
172
  removeCronMessageId(sessionKey)
157
173
  dcgLogger(`finishedDcgchatCron: job=${id} sessionKey=${sessionKey}`)
158
174
  }