@dcrays/dcgchat 0.2.16 → 0.2.19
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/bot.ts +35 -3
- package/src/channel.ts +39 -39
- package/src/skill.ts +72 -72
package/package.json
CHANGED
package/src/bot.ts
CHANGED
|
@@ -367,7 +367,7 @@ export async function handleDcgchatMessage(params: {
|
|
|
367
367
|
log(`dcgchat[${accountId}]: ctxPayload=${JSON.stringify(ctxPayload)}`);
|
|
368
368
|
|
|
369
369
|
const sentMediaKeys = new Set<string>()
|
|
370
|
-
const getMediaKey = (url: string) => url.split(/[\\/]/).
|
|
370
|
+
const getMediaKey = (url: string) => url.split(/[\\/]/).pop() ?? url
|
|
371
371
|
let textChunk = ''
|
|
372
372
|
|
|
373
373
|
const prefixContext = createReplyPrefixContext({ cfg, agentId: route.agentId });
|
|
@@ -388,8 +388,7 @@ export async function handleDcgchatMessage(params: {
|
|
|
388
388
|
});
|
|
389
389
|
|
|
390
390
|
if (text === '/new') {
|
|
391
|
-
|
|
392
|
-
await core.channel.reply.dispatchReplyFromConfig({
|
|
391
|
+
await core.channel.reply.dispatchReplyFromConfig({
|
|
393
392
|
ctx: ctxPayload,
|
|
394
393
|
cfg,
|
|
395
394
|
dispatcher,
|
|
@@ -398,6 +397,39 @@ export async function handleDcgchatMessage(params: {
|
|
|
398
397
|
onModelSelected: prefixContext.onModelSelected
|
|
399
398
|
},
|
|
400
399
|
});
|
|
400
|
+
log(`dcgchat[${accountId}]: skipping agent dispatch for /new`);
|
|
401
|
+
params.onChunk({
|
|
402
|
+
messageType: "openclaw_bot_chat",
|
|
403
|
+
_userId: msg._userId,
|
|
404
|
+
source: "client",
|
|
405
|
+
content: {
|
|
406
|
+
bot_token: msg.content.bot_token,
|
|
407
|
+
domain_id: msg.content.domain_id,
|
|
408
|
+
app_id: msg.content.app_id,
|
|
409
|
+
bot_id: msg.content.bot_id,
|
|
410
|
+
agent_id: msg.content.agent_id,
|
|
411
|
+
session_id: msg.content.session_id,
|
|
412
|
+
message_id: msg.content.message_id,
|
|
413
|
+
response: '好呀~我不会忘记我们之前的聊天,只是暂时翻篇,让我们更轻松地开启新话题。',
|
|
414
|
+
state: 'chunk',
|
|
415
|
+
},
|
|
416
|
+
});
|
|
417
|
+
params.onChunk({
|
|
418
|
+
messageType: "openclaw_bot_chat",
|
|
419
|
+
_userId: msg._userId,
|
|
420
|
+
source: "client",
|
|
421
|
+
content: {
|
|
422
|
+
bot_token: msg.content.bot_token,
|
|
423
|
+
domain_id: msg.content.domain_id,
|
|
424
|
+
app_id: msg.content.app_id,
|
|
425
|
+
bot_id: msg.content.bot_id,
|
|
426
|
+
agent_id: msg.content.agent_id,
|
|
427
|
+
session_id: msg.content.session_id,
|
|
428
|
+
message_id: msg.content.message_id,
|
|
429
|
+
response: '',
|
|
430
|
+
state: 'final',
|
|
431
|
+
},
|
|
432
|
+
});
|
|
401
433
|
} else {
|
|
402
434
|
log(`dcgchat[${accountId}]: dispatching to agent (session=${route.sessionKey})`);
|
|
403
435
|
await core.channel.reply.dispatchReplyFromConfig({
|
package/src/channel.ts
CHANGED
|
@@ -185,47 +185,47 @@ export const dcgchatPlugin: ChannelPlugin<ResolvedDcgchatAccount> = {
|
|
|
185
185
|
// textChunkLimit: 25,
|
|
186
186
|
textChunkLimit: 4000,
|
|
187
187
|
sendText: async (ctx) => {
|
|
188
|
-
const ws = getWsConnection()
|
|
188
|
+
// const ws = getWsConnection()
|
|
189
189
|
const params = getMsgParams();
|
|
190
190
|
const log = console.log;
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
} else {
|
|
227
|
-
log(`[dcgchat][${ctx.accountId ?? DEFAULT_ACCOUNT_ID}] outbound ->
|
|
228
|
-
}
|
|
191
|
+
// if (ws?.readyState === WebSocket.OPEN) {
|
|
192
|
+
// const {botToken} = resolveAccount(ctx.cfg, ctx.accountId);
|
|
193
|
+
// const content = {
|
|
194
|
+
// messageType: "openclaw_bot_chat",
|
|
195
|
+
// _userId: params.userId,
|
|
196
|
+
// source: "client",
|
|
197
|
+
// content: {
|
|
198
|
+
// bot_token: botToken,
|
|
199
|
+
// domain_id: params.domainId,
|
|
200
|
+
// app_id: params.appId,
|
|
201
|
+
// bot_id: params.botId,
|
|
202
|
+
// agent_id: params.agentId,
|
|
203
|
+
// response: ctx.text,
|
|
204
|
+
// session_id: params.sessionId,
|
|
205
|
+
// message_id: params.messageId || Date.now().toString(),
|
|
206
|
+
// },
|
|
207
|
+
// };
|
|
208
|
+
// ws.send(JSON.stringify(content));
|
|
209
|
+
// ws.send(JSON.stringify({
|
|
210
|
+
// messageType: "openclaw_bot_chat",
|
|
211
|
+
// _userId: params.userId,
|
|
212
|
+
// source: "client",
|
|
213
|
+
// content: {
|
|
214
|
+
// bot_token: botToken,
|
|
215
|
+
// domain_id: params.domainId,
|
|
216
|
+
// app_id: params.appId,
|
|
217
|
+
// bot_id: params.botId,
|
|
218
|
+
// agent_id: params.agentId,
|
|
219
|
+
// ssession_id: params.sessionId,
|
|
220
|
+
// message_id: params.messageId || Date.now().toString(),
|
|
221
|
+
// response: '',
|
|
222
|
+
// state: 'final',
|
|
223
|
+
// },
|
|
224
|
+
// }));
|
|
225
|
+
// log(`dcgchat[${ctx.accountId}]: channel sendText to ${params.userId}, ${JSON.stringify(content)}`);
|
|
226
|
+
// } else {
|
|
227
|
+
log(`[dcgchat][${ctx.accountId ?? DEFAULT_ACCOUNT_ID}] outbound -> : ${ctx.text}`);
|
|
228
|
+
// }
|
|
229
229
|
return {
|
|
230
230
|
channel: "dcgchat",
|
|
231
231
|
messageId: `dcg-${Date.now()}`,
|
package/src/skill.ts
CHANGED
|
@@ -36,75 +36,75 @@ function sendEvent(msgContent: Record<string, any>) {
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
async function sendNewSessionCommand(ctx: SkillContext) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
39
|
+
// async function sendNewSessionCommand(ctx: SkillContext) {
|
|
40
|
+
// try {
|
|
41
|
+
// const core = getDcgchatRuntime();
|
|
42
|
+
// const log = ctx.runtime?.log ?? console.log;
|
|
43
|
+
// const params = getMsgParams();
|
|
44
|
+
// const account = resolveAccount(ctx.cfg, ctx.accountId);
|
|
45
|
+
// const userId = String(params.userId);
|
|
46
|
+
|
|
47
|
+
// const route = core.channel.routing.resolveAgentRoute({
|
|
48
|
+
// cfg: ctx.cfg,
|
|
49
|
+
// channel: "dcgchat",
|
|
50
|
+
// accountId: account.accountId,
|
|
51
|
+
// peer: { kind: "direct", id: userId },
|
|
52
|
+
// });
|
|
53
|
+
|
|
54
|
+
// const envelopeOptions = core.channel.reply.resolveEnvelopeFormatOptions(ctx.cfg);
|
|
55
|
+
// const bodyFormatted = core.channel.reply.formatAgentEnvelope({
|
|
56
|
+
// channel: "书灵墨宝",
|
|
57
|
+
// from: userId,
|
|
58
|
+
// timestamp: new Date(),
|
|
59
|
+
// envelope: envelopeOptions,
|
|
60
|
+
// body: "/new",
|
|
61
|
+
// });
|
|
62
|
+
|
|
63
|
+
// const ctxPayload = core.channel.reply.finalizeInboundContext({
|
|
64
|
+
// Body: bodyFormatted,
|
|
65
|
+
// RawBody: "/new",
|
|
66
|
+
// CommandBody: "/new",
|
|
67
|
+
// From: userId,
|
|
68
|
+
// To: userId,
|
|
69
|
+
// SessionKey: route.sessionKey,
|
|
70
|
+
// AccountId: params.sessionId,
|
|
71
|
+
// ChatType: "direct",
|
|
72
|
+
// SenderName: userId,
|
|
73
|
+
// SenderId: userId,
|
|
74
|
+
// Provider: "dcgchat" as const,
|
|
75
|
+
// Surface: "dcgchat" as const,
|
|
76
|
+
// MessageSid: Date.now().toString(),
|
|
77
|
+
// Timestamp: Date.now(),
|
|
78
|
+
// WasMentioned: true,
|
|
79
|
+
// CommandAuthorized: true,
|
|
80
|
+
// OriginatingChannel: "dcgchat" as const,
|
|
81
|
+
// OriginatingTo: `user:${userId}`,
|
|
82
|
+
// });
|
|
83
|
+
|
|
84
|
+
// const noopDispatcher = {
|
|
85
|
+
// sendToolResult: () => false,
|
|
86
|
+
// sendBlockReply: () => false,
|
|
87
|
+
// sendFinalReply: () => false,
|
|
88
|
+
// waitForIdle: async () => {},
|
|
89
|
+
// getQueuedCounts: () => ({ tool: 0, block: 0, final: 0 }),
|
|
90
|
+
// markComplete: () => {},
|
|
91
|
+
// };
|
|
92
|
+
|
|
93
|
+
// await core.channel.reply.withReplyDispatcher({
|
|
94
|
+
// dispatcher: noopDispatcher,
|
|
95
|
+
// run: () =>
|
|
96
|
+
// core.channel.reply.dispatchReplyFromConfig({
|
|
97
|
+
// ctx: ctxPayload,
|
|
98
|
+
// cfg: ctx.cfg,
|
|
99
|
+
// dispatcher: noopDispatcher,
|
|
100
|
+
// }),
|
|
101
|
+
// });
|
|
102
|
+
|
|
103
|
+
// log(`dcgchat: /new command dispatched silently after skill install`);
|
|
104
|
+
// } catch (err) {
|
|
105
|
+
// logDcgchat.error(`sendNewSessionCommand failed: ${err}`);
|
|
106
|
+
// }
|
|
107
|
+
// }
|
|
108
108
|
|
|
109
109
|
export async function installSkill(params: ISkillParams, msgContent: Record<string, any>, ctx?: SkillContext) {
|
|
110
110
|
const { path: cdnUrl, code } = params;
|
|
@@ -208,9 +208,9 @@ export async function installSkill(params: ISkillParams, msgContent: Record<stri
|
|
|
208
208
|
});
|
|
209
209
|
});
|
|
210
210
|
sendEvent({ ...msgContent, status: 'ok' })
|
|
211
|
-
if (ctx) {
|
|
212
|
-
|
|
213
|
-
}
|
|
211
|
+
// if (ctx) {
|
|
212
|
+
// await sendNewSessionCommand(ctx);
|
|
213
|
+
// }
|
|
214
214
|
} catch (error) {
|
|
215
215
|
// 如果安装失败,清理目录
|
|
216
216
|
if (fs.existsSync(skillDir)) {
|