@dcrays/dcgchat-test 0.3.33 → 0.3.35

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.33",
3
+ "version": "0.3.35",
4
4
  "type": "module",
5
5
  "description": "OpenClaw channel plugin for 书灵墨宝 (WebSocket)",
6
6
  "main": "index.ts",
package/src/cron.ts CHANGED
@@ -55,12 +55,8 @@ async function runCronJobsUpload(sessionKey: string): Promise<void> {
55
55
  if (fs.existsSync(jobPath)) {
56
56
  try {
57
57
  const url = await ossUpload(jobPath, botToken ?? '', 0)
58
- dcgLogger(`定时任务创建成功: ${url}`)
59
- if (!sessionKey) {
60
- dcgLogger(`runCronJobsUpload: missing sessionKey on msgCtx`, 'error')
61
- return
62
- }
63
- const sessionInfo = sessionKey.split(':')
58
+ dcgLogger(`定时任务更新成功: ${url}`)
59
+ const sessionInfo = sessionKey?.split(':') || []
64
60
  const sessionId = sessionInfo.at(-1) ?? ''
65
61
  const agentId = sessionInfo.at(-2) ?? ''
66
62
  const params = {
@@ -85,10 +81,6 @@ async function runCronJobsUpload(sessionKey: string): Promise<void> {
85
81
  export function sendDcgchatCron(jobId: string): void {
86
82
  const jobPath = getCronJobsPath()
87
83
  const { sessionKey } = readCronJob(jobPath, jobId) || {}
88
- if (!sessionKey) {
89
- dcgLogger('sendDcgchatCron: no message context (missing token / params)', 'error')
90
- return
91
- }
92
84
  dcgLogger(`sessionKey: ${sessionKey}, jobId: ${jobId}`)
93
85
  if (cronUploadFlushTimer !== null) {
94
86
  clearTimeout(cronUploadFlushTimer)
@@ -368,6 +368,9 @@ export class GatewayConnection {
368
368
  if (msg.payload?.action === 'updated') {
369
369
  sendDcgchatCron(msg.payload?.jobId as string)
370
370
  }
371
+ if (msg.payload?.action === 'removed') {
372
+ sendDcgchatCron(msg.payload?.jobId as string)
373
+ }
371
374
  if (msg.payload?.action === 'finished') {
372
375
  finishedDcgchatCron(msg.payload?.jobId as string)
373
376
  }
package/src/monitor.ts CHANGED
@@ -9,6 +9,7 @@ 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
11
  import { isWsOpen } from './transport.js'
12
+ import { onRemoveSession } from './session.js'
12
13
 
13
14
  export type MonitorDcgchatOpts = {
14
15
  config?: ClawdbotConfig
@@ -142,15 +143,7 @@ export async function monitorDcgchatProvider(opts: MonitorDcgchatOpts): Promise<
142
143
  const { event_type, operation_type } = parsed.content ? parsed.content : ({} as Record<string, any>)
143
144
  if (event_type === 'skill') {
144
145
  const { skill_url, skill_code, skill_id, bot_token, websocket_trace_id } = parsed.content
145
- const content = {
146
- event_type,
147
- operation_type,
148
- skill_url,
149
- skill_code,
150
- skill_id,
151
- bot_token,
152
- websocket_trace_id
153
- }
146
+ const content = { event_type, operation_type, skill_url, skill_code, skill_id, bot_token, websocket_trace_id }
154
147
  if (operation_type === 'install' || operation_type === 'enable' || operation_type === 'update') {
155
148
  installSkill({ path: skill_url, code: skill_code }, content)
156
149
  } else if (operation_type === 'remove' || operation_type === 'disable') {
@@ -169,6 +162,11 @@ export async function monitorDcgchatProvider(opts: MonitorDcgchatOpts): Promise<
169
162
  } else if (operation_type === 'run') {
170
163
  await onRunCronJob(job_id, message_id)
171
164
  }
165
+ } else if (event_type === 'session') {
166
+ const { agent_id, session_id, agent_clone_code } = parsed.content
167
+ if (operation_type === 'remove') {
168
+ await onRemoveSession({ agent_id, session_id, agent_clone_code, account_id: accountId })
169
+ }
172
170
  } else {
173
171
  dcgLogger(`openclaw_bot_event unknown operation_type: ${operation_type}, ${data.toString()}`)
174
172
  }
package/src/session.ts ADDED
@@ -0,0 +1,19 @@
1
+ import { sendMessageToGateway } from './gateway/socket.js'
2
+ import { getSessionKey } from './utils/global.js'
3
+ import { dcgLogger } from './utils/log.js'
4
+
5
+ interface TSession {
6
+ agent_id: string
7
+ session_id: string
8
+ agent_clone_code?: string
9
+ account_id?: string
10
+ }
11
+
12
+ export const onRemoveSession = async ({ agent_id, session_id, agent_clone_code, account_id }: TSession) => {
13
+ const sessionKey = getSessionKey({ agent_id, session_id }, account_id)
14
+ if (!session_id) {
15
+ dcgLogger('onRemoveSession: empty session_id', 'error')
16
+ return
17
+ }
18
+ sendMessageToGateway(JSON.stringify({ method: 'sessions.delete', params: { key: sessionKey, deleteTranscript: true } }))
19
+ }
@@ -117,7 +117,7 @@ export function clearSentMediaKeys(messageId?: string) {
117
117
  }
118
118
  }
119
119
 
120
- export const getSessionKey = (content: any, accountId: string) => {
120
+ export const getSessionKey = (content: any, accountId?: string) => {
121
121
  const { real_mobook, agent_id, conversation_id, session_id } = content
122
122
  const core = getDcgchatRuntime()
123
123