@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 +1 -1
- package/src/cronToolCall.ts +5 -6
- package/src/utils/global.ts +20 -4
package/package.json
CHANGED
package/src/cronToolCall.ts
CHANGED
|
@@ -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
|
|
135
|
+
// job.delivery
|
|
136
136
|
const job = newParams.job as Record<string, unknown> | undefined
|
|
137
137
|
if (job?.delivery && typeof job.delivery === 'object') {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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
|
}
|
package/src/utils/global.ts
CHANGED
|
@@ -108,18 +108,34 @@ export function clearSentMediaKeys(messageId?: string) {
|
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
|
|
111
|
+
/** 每个 sessionKey 下多个定时任务 messageId,入队在尾、出队在头(FIFO) */
|
|
112
|
+
const cronMessageIdMap = new Map<string, string[]>()
|
|
112
113
|
|
|
113
114
|
export function setCronMessageId(sk: string, messageId: string) {
|
|
114
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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) => {
|