@dcrays/dcgchat-test 0.4.13 → 0.4.14

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.4.13",
3
+ "version": "0.4.14",
4
4
  "type": "module",
5
5
  "description": "OpenClaw channel plugin for 书灵墨宝 (WebSocket)",
6
6
  "main": "index.ts",
package/src/channel.ts CHANGED
@@ -254,19 +254,19 @@ export const dcgchatPlugin: ChannelPlugin<ResolvedDcgchatAccount> = {
254
254
  const isCron = ctx.to.indexOf('dcg-cron:') >= 0
255
255
  const outboundCtx = getOutboundMsgParams(to)
256
256
  const content: Record<string, unknown> = { response: ctx.text }
257
- if (isCron) {
258
- messageId = getCronMessageId(to) || `${Date.now()}`
259
- const { sessionId, agentId } = getInfoBySessionKey(to)
260
- content.is_finish = -1
261
- content.message_tags = { source: 'cron' }
262
- const merged = mergeDefaultParams({
263
- agentId: agentId,
264
- sessionId: `${sessionId}`,
265
- messageId: messageId,
266
- real_mobook: !sessionId ? 1 : ''
267
- })
268
- wsSendRaw(merged, content)
269
- } else {
257
+ if (!isCron) {
258
+ // messageId = getCronMessageId(to) || `${Date.now()}`
259
+ // const { sessionId, agentId } = getInfoBySessionKey(to)
260
+ // content.is_finish = -1
261
+ // content.message_tags = { source: 'cron' }
262
+ // const merged = mergeDefaultParams({
263
+ // agentId: agentId,
264
+ // sessionId: `${sessionId}`,
265
+ // messageId: messageId,
266
+ // real_mobook: !sessionId ? 1 : ''
267
+ // })
268
+ // wsSendRaw(merged, content)
269
+ // } else {
270
270
  if (outboundCtx?.sessionId) {
271
271
  messageId = outboundCtx?.messageId || `${Date.now()}`
272
272
  const newCtx = { ...outboundCtx, messageId }
package/src/cron.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import path from 'node:path'
2
2
  import fs from 'node:fs'
3
3
  import type { IMsgParams } from './types.js'
4
- import { isWsOpen, mergeDefaultParams, sendEventMessage, sendFinal } from './transport.js'
4
+ import { isWsOpen, mergeDefaultParams, sendEventMessage, sendFinal, wsSendRaw } from './transport.js'
5
5
  import { getCronMessageId, getWorkspaceDir, getWsConnection, removeCronMessageId, setCronMessageId } from './utils/global.js'
6
6
  import { ossUpload } from './request/oss.js'
7
7
  import { dcgLogger } from './utils/log.js'
@@ -135,7 +135,7 @@ export const onRunCronJob = async (jobId: string, messageId: string) => {
135
135
  )
136
136
  sendMessageToGateway(JSON.stringify({ method: 'cron.run', params: { id: jobId, mode: 'force' } }))
137
137
  }
138
- export const finishedDcgchatCron = async (jobId: string) => {
138
+ export const finishedDcgchatCron = async (jobId: string, summary: string) => {
139
139
  const id = jobId?.trim()
140
140
  if (!id) {
141
141
  dcgLogger('finishedDcgchatCron: empty jobId', 'error')
@@ -147,24 +147,23 @@ export const finishedDcgchatCron = async (jobId: string) => {
147
147
  dcgLogger(`finishedDcgchatCron: no sessionKey for job id=${id}`, 'error')
148
148
  return
149
149
  }
150
- const outboundCtx = getEffectiveMsgParams(sessionKey)
151
- const messageId = getCronMessageId(sessionKey)
150
+ const messageId = getCronMessageId(sessionKey) || `${Date.now()}`
152
151
  const sessionInfo = sessionKey.split(':')
153
152
  const sessionId = sessionInfo.at(-1) ?? ''
154
153
  const agentId = sessionInfo.at(-2) ?? ''
155
- if (outboundCtx?.sessionId) {
156
- const newCtx = messageId ? { ...outboundCtx, messageId } : outboundCtx
157
- sendFinal(newCtx, 'cron send')
158
- } else {
159
- const merged = mergeDefaultParams({
160
- agentId: agentId,
161
- sessionId: `${sessionId}`,
162
- messageId: messageId,
163
- is_finish: -1,
164
- real_mobook: !sessionId ? 1 : ''
165
- })
154
+ // if (outboundCtx?.sessionId) {
155
+
156
+ const merged = mergeDefaultParams({
157
+ agentId: agentId,
158
+ sessionId: `${sessionId}`,
159
+ messageId: messageId || `${Date.now()}`,
160
+ real_mobook: !sessionId ? 1 : ''
161
+ })
162
+ wsSendRaw(merged, { response: summary, message_tags: { source: 'cron' }, is_finish: -1 })
163
+ setTimeout(() => {
166
164
  sendFinal(merged, 'cron send')
167
- }
165
+ }, 200)
166
+ // }
168
167
  const ws = getWsConnection()
169
168
  const baseContent = getParamsDefaults()
170
169
  if (isWsOpen()) {
@@ -32,7 +32,7 @@ export function handleGatewayEventMessage(msg: { event?: string; payload?: Recor
32
32
  sendDcgchatCron(p?.jobId as string)
33
33
  }
34
34
  if (p?.action === 'finished') {
35
- finishedDcgchatCron(p?.jobId as string)
35
+ finishedDcgchatCron(p?.jobId as string, p?.summary as string)
36
36
  }
37
37
  }
38
38
  } catch (error) {