@dcrays/dcgchat-test 0.4.14 → 0.4.15

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.14",
3
+ "version": "0.4.15",
4
4
  "type": "module",
5
5
  "description": "OpenClaw channel plugin for 书灵墨宝 (WebSocket)",
6
6
  "main": "index.ts",
@@ -132,14 +132,13 @@ function injectBestEffort(params: Record<string, unknown>, sk: string): Record<s
132
132
  return newParams
133
133
  }
134
134
 
135
- // job.delivery(须改 job 内对象,勿写 newParams.delivery——顶层可能不存在)
135
+ // job.delivery
136
136
  const job = newParams.job as Record<string, unknown> | undefined
137
137
  if (job?.delivery && typeof job.delivery === 'object') {
138
- const del = job.delivery as CronDelivery
139
- del.bestEffort = true
140
- del.to = `dcg-cron:${sk}`
141
- del.accountId = agentId
142
- del.channel = "dcgchat-test"
138
+ ;(job.delivery as CronDelivery).bestEffort = true
139
+ ;(newParams.delivery as CronDelivery).to = `dcg-cron:${sk}`
140
+ ;(newParams.delivery as CronDelivery).accountId = agentId
141
+ ;(newParams.delivery as CronDelivery).channel = "dcgchat-test"
143
142
  newParams.sessionKey = sk
144
143
  return newParams
145
144
  }
@@ -108,18 +108,34 @@ export function clearSentMediaKeys(messageId?: string) {
108
108
  }
109
109
  }
110
110
 
111
- const cronMessageIdMap = new Map<string, string>()
111
+ /** 每个 sessionKey 下多个定时任务 messageId,入队在尾、出队在头(FIFO) */
112
+ const cronMessageIdMap = new Map<string, string[]>()
112
113
 
113
114
  export function setCronMessageId(sk: string, messageId: string) {
114
- cronMessageIdMap.set(sk, messageId)
115
+ if (!sk?.trim() || !messageId?.trim()) return
116
+ let q = cronMessageIdMap.get(sk)
117
+ if (!q) {
118
+ q = []
119
+ cronMessageIdMap.set(sk, q)
120
+ }
121
+ q.push(messageId)
115
122
  }
116
123
 
124
+ /** 窥视队首 messageId(不移除),供发送中与 finished 配对使用 */
117
125
  export function getCronMessageId(sk: string): string {
118
- return cronMessageIdMap.get(sk) ?? ''
126
+ if (!sk?.trim()) return ''
127
+ return cronMessageIdMap.get(sk)?.[0] ?? ''
119
128
  }
120
129
 
130
+ /** 弹出队首一条,与一次 finished 对应;队列为空时移除 key */
121
131
  export function removeCronMessageId(sk: string) {
122
- cronMessageIdMap.delete(sk)
132
+ if (!sk?.trim()) return
133
+ const q = cronMessageIdMap.get(sk)
134
+ if (!q?.length) return
135
+ q.shift()
136
+ if (q.length === 0) {
137
+ cronMessageIdMap.delete(sk)
138
+ }
123
139
  }
124
140
 
125
141
  export const getSessionKey = (content: any, accountId: string) => {