@dcrays/dcgchat-test 0.1.25 → 0.2.1
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 +67 -18
- package/src/channel.ts +8 -0
- package/src/monitor.ts +4 -0
- package/src/tool.ts +11 -3
- package/src/types.ts +8 -0
package/package.json
CHANGED
package/src/bot.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import os from "node:os";
|
|
3
|
-
import type { ClawdbotConfig, RuntimeEnv } from "openclaw/plugin-sdk";
|
|
3
|
+
import type { ClawdbotConfig, ReplyPayload, RuntimeEnv } from "openclaw/plugin-sdk";
|
|
4
4
|
import { createReplyPrefixContext } from "openclaw/plugin-sdk";
|
|
5
5
|
import type { InboundMessage, OutboundReply } from "./types.js";
|
|
6
6
|
import { getDcgchatRuntime } from "./runtime.js";
|
|
@@ -89,6 +89,10 @@ export async function handleDcgchatMessage(params: {
|
|
|
89
89
|
// @ts-ignore
|
|
90
90
|
content: {
|
|
91
91
|
bot_token: msg.content.bot_token,
|
|
92
|
+
domain_id: msg.content.domain_id,
|
|
93
|
+
app_id: msg.content.app_id,
|
|
94
|
+
bot_id: msg.content.bot_id,
|
|
95
|
+
agent_id: msg.content.agent_id,
|
|
92
96
|
session_id: msg.content.session_id,
|
|
93
97
|
message_id: msg.content.message_id,
|
|
94
98
|
response: "[错误] 消息格式不正确",
|
|
@@ -160,6 +164,8 @@ export async function handleDcgchatMessage(params: {
|
|
|
160
164
|
|
|
161
165
|
log(`dcgchat[${accountId}]: ctxPayload=${JSON.stringify(ctxPayload)}`);
|
|
162
166
|
|
|
167
|
+
let textChunk = ''
|
|
168
|
+
|
|
163
169
|
const prefixContext = createReplyPrefixContext({ cfg, agentId: route.agentId });
|
|
164
170
|
|
|
165
171
|
const { dispatcher, replyOptions, markDispatchIdle } =
|
|
@@ -169,7 +175,51 @@ export async function handleDcgchatMessage(params: {
|
|
|
169
175
|
humanDelay: core.channel.reply.resolveHumanDelayConfig(cfg, route.agentId),
|
|
170
176
|
onReplyStart: async () => {},
|
|
171
177
|
deliver: async (payload) => {
|
|
172
|
-
log(`dcgchat[${accountId}][deliver]: received chunk, text length=${payload.text?.length || 0}`);
|
|
178
|
+
// log(`dcgchat[${accountId}][deliver]: received chunk, text length=${payload.text?.length || 0}`);
|
|
179
|
+
// const t = payload.text?.trim().replaceAll(
|
|
180
|
+
// "/root/.openclaw/workspace/moBooksAgentGenerate",
|
|
181
|
+
// "/upload"
|
|
182
|
+
// );
|
|
183
|
+
// if (t) {
|
|
184
|
+
// log(`dcgchat[${accountId}][deliver]: sending chunk to user ${msg._userId}, text="${t.slice(0, 50)}..."`);
|
|
185
|
+
// params.onChunk({
|
|
186
|
+
// messageType: "openclaw_bot_chat",
|
|
187
|
+
// _userId: msg._userId,
|
|
188
|
+
// source: "client",
|
|
189
|
+
// content: {
|
|
190
|
+
// bot_token: msg.content.bot_token,
|
|
191
|
+
// domain_id: msg.content.domain_id,
|
|
192
|
+
// app_id: msg.content.app_id,
|
|
193
|
+
// bot_id: msg.content.bot_id,
|
|
194
|
+
// agent_id: msg.content.agent_id,
|
|
195
|
+
// session_id: msg.content.session_id,
|
|
196
|
+
// message_id: msg.content.message_id,
|
|
197
|
+
// response: t,
|
|
198
|
+
// state: 'chunk',
|
|
199
|
+
// },
|
|
200
|
+
// });
|
|
201
|
+
// log(`dcgchat[${accountId}][deliver]: chunk sent successfully`);
|
|
202
|
+
// } else {
|
|
203
|
+
// log(`dcgchat[${accountId}][deliver]: skipping empty chunk`);
|
|
204
|
+
// }
|
|
205
|
+
},
|
|
206
|
+
onError: (err, info) => {
|
|
207
|
+
error(`dcgchat[${accountId}] ${info.kind} reply failed: ${String(err)}`);
|
|
208
|
+
},
|
|
209
|
+
onIdle: () => {},
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
log(`dcgchat[${accountId}]: dispatching to agent (session=${route.sessionKey})`);
|
|
213
|
+
|
|
214
|
+
await core.channel.reply.dispatchReplyFromConfig({
|
|
215
|
+
ctx: ctxPayload,
|
|
216
|
+
cfg,
|
|
217
|
+
dispatcher,
|
|
218
|
+
replyOptions: {
|
|
219
|
+
...replyOptions,
|
|
220
|
+
onModelSelected: prefixContext.onModelSelected,
|
|
221
|
+
onPartialReply: (payload: ReplyPayload) => {
|
|
222
|
+
log(`dcgchat[${accountId}][deliver]: received chunk, text length=${payload.text?.length || 0}`);
|
|
173
223
|
const t = payload.text?.trim().replaceAll(
|
|
174
224
|
"/root/.openclaw/workspace/moBooksAgentGenerate",
|
|
175
225
|
"/upload"
|
|
@@ -182,32 +232,22 @@ export async function handleDcgchatMessage(params: {
|
|
|
182
232
|
source: "client",
|
|
183
233
|
content: {
|
|
184
234
|
bot_token: msg.content.bot_token,
|
|
235
|
+
domain_id: msg.content.domain_id,
|
|
236
|
+
app_id: msg.content.app_id,
|
|
237
|
+
bot_id: msg.content.bot_id,
|
|
238
|
+
agent_id: msg.content.agent_id,
|
|
185
239
|
session_id: msg.content.session_id,
|
|
186
240
|
message_id: msg.content.message_id,
|
|
187
|
-
response: t,
|
|
241
|
+
response: t.replace(textChunk, ''),
|
|
188
242
|
state: 'chunk',
|
|
189
243
|
},
|
|
190
244
|
});
|
|
245
|
+
textChunk = t
|
|
191
246
|
log(`dcgchat[${accountId}][deliver]: chunk sent successfully`);
|
|
192
247
|
} else {
|
|
193
248
|
log(`dcgchat[${accountId}][deliver]: skipping empty chunk`);
|
|
194
249
|
}
|
|
195
250
|
},
|
|
196
|
-
onError: (err, info) => {
|
|
197
|
-
error(`dcgchat[${accountId}] ${info.kind} reply failed: ${String(err)}`);
|
|
198
|
-
},
|
|
199
|
-
onIdle: () => {},
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
log(`dcgchat[${accountId}]: dispatching to agent (session=${route.sessionKey})`);
|
|
203
|
-
|
|
204
|
-
await core.channel.reply.dispatchReplyFromConfig({
|
|
205
|
-
ctx: ctxPayload,
|
|
206
|
-
cfg,
|
|
207
|
-
dispatcher,
|
|
208
|
-
replyOptions: {
|
|
209
|
-
...replyOptions,
|
|
210
|
-
onModelSelected: prefixContext.onModelSelected,
|
|
211
251
|
},
|
|
212
252
|
});
|
|
213
253
|
|
|
@@ -218,6 +258,10 @@ export async function handleDcgchatMessage(params: {
|
|
|
218
258
|
source: "client",
|
|
219
259
|
content: {
|
|
220
260
|
bot_token: msg.content.bot_token,
|
|
261
|
+
domain_id: msg.content.domain_id,
|
|
262
|
+
app_id: msg.content.app_id,
|
|
263
|
+
bot_id: msg.content.bot_id,
|
|
264
|
+
agent_id: msg.content.agent_id,
|
|
221
265
|
session_id: msg.content.session_id,
|
|
222
266
|
message_id: msg.content.message_id,
|
|
223
267
|
response: '',
|
|
@@ -225,6 +269,7 @@ export async function handleDcgchatMessage(params: {
|
|
|
225
269
|
},
|
|
226
270
|
});
|
|
227
271
|
setMsgStatus('finished');
|
|
272
|
+
textChunk = ''
|
|
228
273
|
log(`dcgchat[${accountId}]: final state sent`);
|
|
229
274
|
|
|
230
275
|
markDispatchIdle();
|
|
@@ -238,6 +283,10 @@ export async function handleDcgchatMessage(params: {
|
|
|
238
283
|
source: "client",
|
|
239
284
|
content: {
|
|
240
285
|
bot_token: msg.content.bot_token,
|
|
286
|
+
domain_id: msg.content.domain_id,
|
|
287
|
+
app_id: msg.content.app_id,
|
|
288
|
+
bot_id: msg.content.bot_id,
|
|
289
|
+
agent_id: msg.content.agent_id,
|
|
241
290
|
session_id: msg.content.session_id,
|
|
242
291
|
message_id: msg.content.message_id,
|
|
243
292
|
response: `[错误] ${err instanceof Error ? err.message : String(err)}`,
|
package/src/channel.ts
CHANGED
|
@@ -153,6 +153,10 @@ export const dcgchatPlugin: ChannelPlugin<ResolvedDcgchatAccount> = {
|
|
|
153
153
|
source: "client",
|
|
154
154
|
content: {
|
|
155
155
|
bot_token: botToken,
|
|
156
|
+
domain_id: params.domainId,
|
|
157
|
+
app_id: params.appId,
|
|
158
|
+
bot_id: params.botId,
|
|
159
|
+
agent_id: params.agentId,
|
|
156
160
|
response: ctx.text.replaceAll(
|
|
157
161
|
"/root/.openclaw/workspace/moBooksAgentGenerate",
|
|
158
162
|
"/upload"
|
|
@@ -188,6 +192,10 @@ export const dcgchatPlugin: ChannelPlugin<ResolvedDcgchatAccount> = {
|
|
|
188
192
|
source: "client",
|
|
189
193
|
content: {
|
|
190
194
|
bot_token: botToken,
|
|
195
|
+
domain_id: params.domainId,
|
|
196
|
+
app_id: params.appId,
|
|
197
|
+
bot_id: params.botId,
|
|
198
|
+
agent_id: params.agentId,
|
|
191
199
|
response: ctx.text.replaceAll(
|
|
192
200
|
"/root/.openclaw/workspace/moBooksAgentGenerate",
|
|
193
201
|
"/upload"
|
package/src/monitor.ts
CHANGED
|
@@ -117,6 +117,10 @@ export async function monitorDcgchatProvider(opts: MonitorDcgchatOpts): Promise<
|
|
|
117
117
|
token: msg.content.bot_token,
|
|
118
118
|
sessionId: msg.content.session_id,
|
|
119
119
|
messageId: msg.content.message_id,
|
|
120
|
+
domainId: msg.content.domain_id,
|
|
121
|
+
appId: msg.content.app_id,
|
|
122
|
+
botId: msg.content.bot_id,
|
|
123
|
+
agentId: msg.content.agent_id,
|
|
120
124
|
});
|
|
121
125
|
await handleDcgchatMessage({
|
|
122
126
|
cfg,
|
package/src/tool.ts
CHANGED
|
@@ -5,9 +5,13 @@ import { logDcgchat } from "./log.js";
|
|
|
5
5
|
|
|
6
6
|
let msgParams = {} as {
|
|
7
7
|
userId: number;
|
|
8
|
-
token: string
|
|
9
|
-
sessionId: string
|
|
10
|
-
messageId: string
|
|
8
|
+
token: string;
|
|
9
|
+
sessionId: string;
|
|
10
|
+
messageId: string;
|
|
11
|
+
domainId: string;
|
|
12
|
+
appId: string;
|
|
13
|
+
botId: string;
|
|
14
|
+
agentId: string;
|
|
11
15
|
}
|
|
12
16
|
let msgStatus: 'running' | 'finished' | '' = '';
|
|
13
17
|
export function setMsgParams(params: any) {
|
|
@@ -57,6 +61,10 @@ export function monitoringToolMessage(api: OpenClawPluginApi) {
|
|
|
57
61
|
source: "client",
|
|
58
62
|
content: {
|
|
59
63
|
bot_token: params?.token,
|
|
64
|
+
domain_id: params?.domainId,
|
|
65
|
+
app_id: params?.appId,
|
|
66
|
+
bot_id: params?.botId,
|
|
67
|
+
agent_id: params?.agentId,
|
|
60
68
|
response: text,
|
|
61
69
|
session_id:params?.sessionId,
|
|
62
70
|
message_id: params?.messageId || Date.now().toString()
|
package/src/types.ts
CHANGED
|
@@ -39,6 +39,10 @@ export type InboundMessage = {
|
|
|
39
39
|
// content: string;
|
|
40
40
|
content: {
|
|
41
41
|
bot_token: string;
|
|
42
|
+
domain_id?: string;
|
|
43
|
+
app_id?: string;
|
|
44
|
+
bot_id?: string;
|
|
45
|
+
agent_id?: string;
|
|
42
46
|
session_id: string;
|
|
43
47
|
message_id: string;
|
|
44
48
|
text: string;
|
|
@@ -71,6 +75,10 @@ export type OutboundReply = {
|
|
|
71
75
|
message_id: string; // ""
|
|
72
76
|
response: string; // ""
|
|
73
77
|
state: string; // final, chunk
|
|
78
|
+
domain_id?: string;
|
|
79
|
+
app_id?: string;
|
|
80
|
+
bot_id?: string;
|
|
81
|
+
agent_id?: string;
|
|
74
82
|
};
|
|
75
83
|
};
|
|
76
84
|
|