@dcrays/dcgchat-test 0.3.18 → 0.3.20
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/channel.ts +21 -26
- package/src/cron.ts +2 -2
- package/src/cronToolCall.ts +3 -3
- package/src/transport.ts +3 -1
- package/src/types.ts +1 -0
package/package.json
CHANGED
package/src/channel.ts
CHANGED
|
@@ -39,12 +39,14 @@ export async function sendDcgchatMedia(opts: DcgchatMediaSendOptions): Promise<v
|
|
|
39
39
|
const url = opts.mediaUrl ? await ossUpload(opts.mediaUrl, botToken, 1) : ''
|
|
40
40
|
wsSendRaw(msgCtx, {
|
|
41
41
|
response: opts.text ?? '',
|
|
42
|
+
message_tags: { source: 'file' },
|
|
42
43
|
files: [{ url, name: fileName }]
|
|
43
44
|
})
|
|
44
45
|
dcgLogger(`dcgchat: sendMedia to user ${msgCtx.userId}, file=${fileName}`)
|
|
45
46
|
} catch (error) {
|
|
46
47
|
wsSendRaw(msgCtx, {
|
|
47
48
|
response: opts.text ?? '',
|
|
49
|
+
message_tags: { source: 'file' },
|
|
48
50
|
files: [{ url: opts.mediaUrl ?? '', name: fileName }]
|
|
49
51
|
})
|
|
50
52
|
dcgLogger(`dcgchat: error sendMedia to user ${msgCtx.userId}: ${String(error)}`, 'error')
|
|
@@ -142,28 +144,18 @@ export const dcgchatPlugin: ChannelPlugin<ResolvedDcgchatAccount> = {
|
|
|
142
144
|
deliveryMode: 'direct',
|
|
143
145
|
textChunkLimit: 4000,
|
|
144
146
|
sendText: async (ctx) => {
|
|
147
|
+
const isCron = ctx.to.indexOf('dcg-cron:') >= 0
|
|
148
|
+
const to = ctx.to.replace('dcg-cron:', '')
|
|
149
|
+
dcgLogger(`channel sendText to ${ctx.to} `)
|
|
150
|
+
const outboundCtx = getEffectiveMsgParams(to)
|
|
151
|
+
const cronMsgId = getCronMessageId(to)
|
|
152
|
+
const messageId = !!cronMsgId ? cronMsgId : isCron ? `${Date.now()}` : outboundCtx?.messageId
|
|
145
153
|
if (isWsOpen()) {
|
|
146
|
-
// if (ctx.to.indexOf('cron:') >= 0) {
|
|
147
|
-
// const sessionInfo = ctx.to.split(':')[1]
|
|
148
|
-
// const sessionId = sessionInfo.split('-')[0]
|
|
149
|
-
// const agentId = sessionInfo.split('-')[1]
|
|
150
|
-
// const merged = mergeDefaultParams({
|
|
151
|
-
// agentId: agentId,
|
|
152
|
-
// sessionId: sessionId,
|
|
153
|
-
// messageId: `${Date.now()}`,
|
|
154
|
-
// is_finish: -1
|
|
155
|
-
// })
|
|
156
|
-
// wsSendRaw(merged, { response: ctx.text })
|
|
157
|
-
// } else {
|
|
158
|
-
// }
|
|
159
|
-
const outboundCtx = getEffectiveMsgParams(ctx.to)
|
|
160
|
-
const messageId = getCronMessageId(ctx.to)
|
|
161
154
|
if (outboundCtx?.sessionId) {
|
|
162
|
-
const newCtx =
|
|
155
|
+
const newCtx = { ...outboundCtx, messageId }
|
|
163
156
|
wsSendRaw(newCtx, { response: ctx.text, is_finish: -1, message_tags: { source: 'channel' } })
|
|
164
|
-
dcgLogger(`channel sendText to ${ctx.to} ${ctx.text?.slice(0, 50)}`)
|
|
165
157
|
} else {
|
|
166
|
-
const sessionInfo =
|
|
158
|
+
const sessionInfo = to.split(':')
|
|
167
159
|
const sessionId = sessionInfo.at(-1) ?? ''
|
|
168
160
|
const agentId = sessionInfo.at(-2) ?? ''
|
|
169
161
|
const merged = mergeDefaultParams({
|
|
@@ -173,23 +165,26 @@ export const dcgchatPlugin: ChannelPlugin<ResolvedDcgchatAccount> = {
|
|
|
173
165
|
is_finish: -1,
|
|
174
166
|
real_mobook: !sessionId ? 1 : ''
|
|
175
167
|
})
|
|
176
|
-
|
|
177
|
-
wsSendRaw(merged, { response: ctx.text })
|
|
168
|
+
wsSendRaw(merged, { response: ctx.text, message_tags: { source: 'channel' } })
|
|
178
169
|
}
|
|
179
170
|
}
|
|
180
171
|
return {
|
|
181
172
|
channel: "dcgchat-test",
|
|
182
|
-
messageId:
|
|
183
|
-
chatId:
|
|
173
|
+
messageId: `${messageId}`,
|
|
174
|
+
chatId: to
|
|
184
175
|
}
|
|
185
176
|
},
|
|
186
177
|
sendMedia: async (ctx) => {
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
|
|
178
|
+
const to = ctx.to.replace('dcg-cron:', '')
|
|
179
|
+
const msgCtx = getEffectiveMsgParams(to)
|
|
180
|
+
const cronMsgId = getCronMessageId(to)
|
|
181
|
+
const isCron = ctx.to.indexOf('dcg-cron:') >= 0
|
|
182
|
+
const messageId = !!cronMsgId ? cronMsgId : isCron ? `${Date.now()}` : msgCtx?.messageId
|
|
183
|
+
dcgLogger(`channel sendMedia to ${ctx.to}`)
|
|
184
|
+
await sendDcgchatMedia({ sessionKey: to ?? '', mediaUrl: ctx.mediaUrl ?? '' })
|
|
190
185
|
return {
|
|
191
186
|
channel: "dcgchat-test",
|
|
192
|
-
messageId:
|
|
187
|
+
messageId: `${messageId}`,
|
|
193
188
|
chatId: msgCtx.userId?.toString()
|
|
194
189
|
}
|
|
195
190
|
}
|
package/src/cron.ts
CHANGED
|
@@ -59,7 +59,7 @@ async function runCronJobsUpload(msgCtx: IMsgParams): Promise<void> {
|
|
|
59
59
|
const url = await ossUpload(jobPath, msgCtx.botToken ?? '', 0)
|
|
60
60
|
dcgLogger(`定时任务创建成功: ${url}`)
|
|
61
61
|
if (!msgCtx.sessionKey) {
|
|
62
|
-
dcgLogger(
|
|
62
|
+
dcgLogger(`runCronJobsUpload: missing sessionKey ${JSON.stringify(msgCtx)} on msgCtx`, 'error')
|
|
63
63
|
return
|
|
64
64
|
}
|
|
65
65
|
sendEventMessage(url, msgCtx.sessionKey)
|
|
@@ -155,7 +155,7 @@ export const finishedDcgchatCron = async (jobId: string) => {
|
|
|
155
155
|
const messageId = getCronMessageId(sessionKey)
|
|
156
156
|
if (outboundCtx?.sessionId) {
|
|
157
157
|
const newCtx = messageId ? { ...outboundCtx, messageId } : outboundCtx
|
|
158
|
-
sendFinal(newCtx)
|
|
158
|
+
sendFinal(newCtx, 'cron send')
|
|
159
159
|
} else {
|
|
160
160
|
const sessionInfo = sessionKey.split(':')
|
|
161
161
|
const sessionId = sessionInfo.at(-1) ?? ''
|
package/src/cronToolCall.ts
CHANGED
|
@@ -125,7 +125,7 @@ function injectBestEffort(params: Record<string, unknown>, sk: string): Record<s
|
|
|
125
125
|
// 顶层 delivery
|
|
126
126
|
if (newParams.delivery && typeof newParams.delivery === 'object') {
|
|
127
127
|
;(newParams.delivery as CronDelivery).bestEffort = true
|
|
128
|
-
;(newParams.delivery as CronDelivery).to =
|
|
128
|
+
;(newParams.delivery as CronDelivery).to = `dcg-cron:${sk}`
|
|
129
129
|
;(newParams.delivery as CronDelivery).accountId = agentId
|
|
130
130
|
;(newParams.delivery as CronDelivery).channel = "dcgchat-test"
|
|
131
131
|
newParams.sessionKey = sk
|
|
@@ -136,7 +136,7 @@ function injectBestEffort(params: Record<string, unknown>, sk: string): Record<s
|
|
|
136
136
|
const job = newParams.job as Record<string, unknown> | undefined
|
|
137
137
|
if (job?.delivery && typeof job.delivery === 'object') {
|
|
138
138
|
;(job.delivery as CronDelivery).bestEffort = true
|
|
139
|
-
;(newParams.delivery as CronDelivery).to =
|
|
139
|
+
;(newParams.delivery as CronDelivery).to = `dcg-cron:${sk}`
|
|
140
140
|
;(newParams.delivery as CronDelivery).accountId = agentId
|
|
141
141
|
;(newParams.delivery as CronDelivery).channel = "dcgchat-test"
|
|
142
142
|
newParams.sessionKey = sk
|
|
@@ -176,7 +176,7 @@ export function cronToolCall(event: { toolName: any; params: any; toolCallId: an
|
|
|
176
176
|
if (params.command.indexOf('cron create') > -1 || params.command.indexOf('cron add') > -1) {
|
|
177
177
|
const newParams = JSON.parse(JSON.stringify(params)) as Record<string, unknown>
|
|
178
178
|
newParams.command =
|
|
179
|
-
params.command.replace('--json', '') + ` --session-key ${sk} --channel ${"dcgchat-test"} --to
|
|
179
|
+
params.command.replace('--json', '') + ` --session-key ${sk} --channel ${"dcgchat-test"} --to dcg-cron:${sk} --json`
|
|
180
180
|
return { params: newParams }
|
|
181
181
|
} else {
|
|
182
182
|
return params
|
package/src/transport.ts
CHANGED
|
@@ -154,6 +154,8 @@ export function wsSendRaw(ctx: IMsgParams, content: Record<string, unknown>): bo
|
|
|
154
154
|
const ws = getWsConnection()
|
|
155
155
|
if (isWsOpen()) {
|
|
156
156
|
ws?.send(JSON.stringify(buildOpenclawBotChat(ctx, content, { mergeChannelDefaults: true })))
|
|
157
|
+
|
|
158
|
+
dcgLogger('已发送:' + JSON.stringify(buildOpenclawBotChat(ctx, content, { mergeChannelDefaults: true })))
|
|
157
159
|
}
|
|
158
160
|
return true
|
|
159
161
|
}
|
|
@@ -162,7 +164,7 @@ export function sendChunk(text: string, ctx: IMsgParams, chunkIdx: number): bool
|
|
|
162
164
|
return wsSend(ctx, { response: text, state: 'chunk', chunk_idx: chunkIdx })
|
|
163
165
|
}
|
|
164
166
|
|
|
165
|
-
export function sendFinal(ctx: IMsgParams, tag
|
|
167
|
+
export function sendFinal(ctx: IMsgParams, tag: string): boolean {
|
|
166
168
|
dcgLogger(` message handling complete state: final tag:${tag}`)
|
|
167
169
|
return wsSend(ctx, { response: '', state: 'final' })
|
|
168
170
|
}
|