@dcrays/dcgchat-test 0.2.6 → 0.2.8
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/index.ts +2 -2
- package/package.json +1 -1
- package/src/bot.ts +80 -69
- package/src/channel.ts +34 -2
- package/src/skill.ts +2 -2
package/index.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
|
|
|
2
2
|
import { emptyPluginConfigSchema } from "openclaw/plugin-sdk";
|
|
3
3
|
import { dcgchatPlugin } from "./src/channel.js";
|
|
4
4
|
import { setDcgchatRuntime, setWorkspaceDir } from "./src/runtime.js";
|
|
5
|
-
import { monitoringToolMessage } from "./src/tool.js";
|
|
5
|
+
// import { monitoringToolMessage } from "./src/tool.js";
|
|
6
6
|
|
|
7
7
|
const plugin = {
|
|
8
8
|
id: "dcgchat-test",
|
|
@@ -11,7 +11,7 @@ const plugin = {
|
|
|
11
11
|
configSchema: emptyPluginConfigSchema(),
|
|
12
12
|
register(api: OpenClawPluginApi) {
|
|
13
13
|
setDcgchatRuntime(api.runtime);
|
|
14
|
-
monitoringToolMessage(api);
|
|
14
|
+
// monitoringToolMessage(api);
|
|
15
15
|
api.registerChannel({ plugin: dcgchatPlugin });
|
|
16
16
|
api.registerTool((ctx) => {
|
|
17
17
|
const workspaceDir = ctx.workspaceDir;
|
package/package.json
CHANGED
package/src/bot.ts
CHANGED
|
@@ -106,7 +106,7 @@ export async function handleDcgchatMessage(params: {
|
|
|
106
106
|
const userId = msg._userId.toString();
|
|
107
107
|
const text = msg.content.text?.trim();
|
|
108
108
|
|
|
109
|
-
if (!text
|
|
109
|
+
if (!text) {
|
|
110
110
|
params.onChunk({
|
|
111
111
|
messageType: "openclaw_bot_chat",
|
|
112
112
|
_userId: msg._userId,
|
|
@@ -200,82 +200,93 @@ export async function handleDcgchatMessage(params: {
|
|
|
200
200
|
onIdle: () => {},
|
|
201
201
|
});
|
|
202
202
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
203
|
+
if (text === '/new') {
|
|
204
|
+
log(`dcgchat[${accountId}]: skipping agent dispatch for /new`);
|
|
205
|
+
await core.channel.reply.dispatchReplyFromConfig({
|
|
206
|
+
ctx: ctxPayload,
|
|
207
|
+
cfg,
|
|
208
|
+
dispatcher,
|
|
209
|
+
replyOptions: {
|
|
210
|
+
...replyOptions,
|
|
211
|
+
onModelSelected: prefixContext.onModelSelected
|
|
212
|
+
},
|
|
213
|
+
});
|
|
214
|
+
} else {
|
|
215
|
+
log(`dcgchat[${accountId}]: dispatching to agent (session=${route.sessionKey})`);
|
|
216
|
+
await core.channel.reply.dispatchReplyFromConfig({
|
|
217
|
+
ctx: ctxPayload,
|
|
218
|
+
cfg,
|
|
219
|
+
dispatcher,
|
|
220
|
+
replyOptions: {
|
|
221
|
+
...replyOptions,
|
|
222
|
+
onModelSelected: prefixContext.onModelSelected,
|
|
223
|
+
onPartialReply: async (payload: ReplyPayload) => {
|
|
224
|
+
log(`dcgchat[${accountId}][deliver]: received chunk, text length=${payload.text?.length || 0}`);
|
|
225
|
+
const mediaList =
|
|
215
226
|
payload.mediaUrls && payload.mediaUrls.length > 0
|
|
216
227
|
? payload.mediaUrls
|
|
217
228
|
: payload.mediaUrl
|
|
218
229
|
? [payload.mediaUrl]
|
|
219
230
|
: [];
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
231
|
+
if (mediaList.length > 0) {
|
|
232
|
+
const files = []
|
|
233
|
+
for (let i = 0; i < mediaList.length; i++) {
|
|
234
|
+
const file = mediaList[i]
|
|
235
|
+
const fileName = file.split(/[\\/]/).pop() || ''
|
|
236
|
+
const url = await ossUpload(file, msg.content.bot_token)
|
|
237
|
+
files.push({
|
|
238
|
+
url: url,
|
|
239
|
+
name: fileName,
|
|
240
|
+
})
|
|
241
|
+
}
|
|
242
|
+
params.onChunk({
|
|
243
|
+
messageType: "openclaw_bot_chat",
|
|
244
|
+
_userId: msg._userId,
|
|
245
|
+
source: "client",
|
|
246
|
+
content: {
|
|
247
|
+
bot_token: msg.content.bot_token,
|
|
248
|
+
domain_id: msg.content.domain_id,
|
|
249
|
+
app_id: msg.content.app_id,
|
|
250
|
+
bot_id: msg.content.bot_id,
|
|
251
|
+
agent_id: msg.content.agent_id,
|
|
252
|
+
session_id: msg.content.session_id,
|
|
253
|
+
message_id: msg.content.message_id,
|
|
254
|
+
response: '',
|
|
255
|
+
files: files,
|
|
256
|
+
state: 'chunk',
|
|
257
|
+
},
|
|
258
|
+
});
|
|
230
259
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
messageType: "openclaw_bot_chat",
|
|
253
|
-
_userId: msg._userId,
|
|
254
|
-
source: "client",
|
|
255
|
-
content: {
|
|
256
|
-
bot_token: msg.content.bot_token,
|
|
257
|
-
domain_id: msg.content.domain_id,
|
|
258
|
-
app_id: msg.content.app_id,
|
|
259
|
-
bot_id: msg.content.bot_id,
|
|
260
|
-
agent_id: msg.content.agent_id,
|
|
261
|
-
session_id: msg.content.session_id,
|
|
262
|
-
message_id: msg.content.message_id,
|
|
263
|
-
response: payload.text.replace(textChunk, ''),
|
|
264
|
-
state: 'chunk',
|
|
265
|
-
},
|
|
266
|
-
});
|
|
267
|
-
textChunk = payload.text
|
|
268
|
-
log(`dcgchat[${accountId}][deliver]: chunk sent successfully`);
|
|
269
|
-
} else if (payload.mediaUrl && payload.mediaUrls) {
|
|
270
|
-
|
|
260
|
+
if (payload.text) {
|
|
261
|
+
log(`dcgchat[${accountId}][deliver]: sending chunk to user ${msg._userId}, text="${payload.text.slice(0, 50)}..."`);
|
|
262
|
+
params.onChunk({
|
|
263
|
+
messageType: "openclaw_bot_chat",
|
|
264
|
+
_userId: msg._userId,
|
|
265
|
+
source: "client",
|
|
266
|
+
content: {
|
|
267
|
+
bot_token: msg.content.bot_token,
|
|
268
|
+
domain_id: msg.content.domain_id,
|
|
269
|
+
app_id: msg.content.app_id,
|
|
270
|
+
bot_id: msg.content.bot_id,
|
|
271
|
+
agent_id: msg.content.agent_id,
|
|
272
|
+
session_id: msg.content.session_id,
|
|
273
|
+
message_id: msg.content.message_id,
|
|
274
|
+
response: payload.text.replace(textChunk, ''),
|
|
275
|
+
state: 'chunk',
|
|
276
|
+
},
|
|
277
|
+
});
|
|
278
|
+
textChunk = payload.text
|
|
279
|
+
log(`dcgchat[${accountId}][deliver]: chunk sent successfully`);
|
|
280
|
+
} else if (payload.mediaUrl && payload.mediaUrls) {
|
|
271
281
|
|
|
272
|
-
} else {
|
|
273
|
-
log(`dcgchat[${accountId}][deliver]: skipping empty chunk`);
|
|
274
|
-
}
|
|
275
|
-
},
|
|
276
|
-
},
|
|
277
|
-
});
|
|
278
282
|
|
|
283
|
+
} else {
|
|
284
|
+
log(`dcgchat[${accountId}][deliver]: skipping empty chunk`);
|
|
285
|
+
}
|
|
286
|
+
},
|
|
287
|
+
},
|
|
288
|
+
});
|
|
289
|
+
}
|
|
279
290
|
log(`dcgchat[${accountId}]: dispatch complete, sending final state`);
|
|
280
291
|
params.onChunk({
|
|
281
292
|
messageType: "openclaw_bot_chat",
|
package/src/channel.ts
CHANGED
|
@@ -119,7 +119,23 @@ export const dcgchatPlugin: ChannelPlugin<ResolvedDcgchatAccount> = {
|
|
|
119
119
|
},
|
|
120
120
|
};
|
|
121
121
|
ws.send(JSON.stringify(content));
|
|
122
|
-
|
|
122
|
+
ws.send(JSON.stringify({
|
|
123
|
+
messageType: "openclaw_bot_chat",
|
|
124
|
+
_userId: params.userId,
|
|
125
|
+
source: "client",
|
|
126
|
+
content: {
|
|
127
|
+
bot_token: botToken,
|
|
128
|
+
domain_id: params.domainId,
|
|
129
|
+
app_id: params.appId,
|
|
130
|
+
bot_id: params.botId,
|
|
131
|
+
agent_id: params.agentId,
|
|
132
|
+
ssession_id: params.sessionId,
|
|
133
|
+
message_id: params.messageId || Date.now().toString(),
|
|
134
|
+
response: '',
|
|
135
|
+
state: 'final',
|
|
136
|
+
},
|
|
137
|
+
}));
|
|
138
|
+
log(`dcgchat[${ctx.accountId}]: channel sendText to ${params.userId}, ${JSON.stringify(content)}`);
|
|
123
139
|
} else {
|
|
124
140
|
log(`[dcgchat][${ctx.accountId ?? DEFAULT_ACCOUNT_ID}] outbound -> ${ws?.readyState}: ${ctx.text}`);
|
|
125
141
|
}
|
|
@@ -176,10 +192,26 @@ export const dcgchatPlugin: ChannelPlugin<ResolvedDcgchatAccount> = {
|
|
|
176
192
|
name: fileName,
|
|
177
193
|
}],
|
|
178
194
|
session_id: params.sessionId || Date.now().toString(),
|
|
179
|
-
message_id:
|
|
195
|
+
message_id: Date.now().toString(),
|
|
180
196
|
},
|
|
181
197
|
};
|
|
182
198
|
ws.send(JSON.stringify(content));
|
|
199
|
+
ws.send(JSON.stringify({
|
|
200
|
+
messageType: "openclaw_bot_chat",
|
|
201
|
+
_userId: params.userId,
|
|
202
|
+
source: "client",
|
|
203
|
+
content: {
|
|
204
|
+
bot_token: botToken,
|
|
205
|
+
domain_id: params.domainId,
|
|
206
|
+
app_id: params.appId,
|
|
207
|
+
bot_id: params.botId,
|
|
208
|
+
agent_id: params.agentId,
|
|
209
|
+
ssession_id: params.sessionId,
|
|
210
|
+
message_id: Date.now().toString(),
|
|
211
|
+
response: '',
|
|
212
|
+
state: 'final',
|
|
213
|
+
},
|
|
214
|
+
}));
|
|
183
215
|
log(`dcgchat[${ctx.accountId}]: error sendMedia to ${params.userId}, ${JSON.stringify(content)}`);
|
|
184
216
|
}
|
|
185
217
|
} else {
|
package/src/skill.ts
CHANGED
|
@@ -136,7 +136,7 @@ export function uninstallSkill(params: Omit<ISkillParams, 'path'>, msgContent: R
|
|
|
136
136
|
|
|
137
137
|
const workspacePath = getWorkspaceDir();
|
|
138
138
|
if (!workspacePath) {
|
|
139
|
-
|
|
139
|
+
sendEvent({ ...msgContent, status: 'ok' })
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
const skillDir = path.join(workspacePath, 'skills', code);
|
|
@@ -145,6 +145,6 @@ export function uninstallSkill(params: Omit<ISkillParams, 'path'>, msgContent: R
|
|
|
145
145
|
fs.rmSync(skillDir, { recursive: true, force: true });
|
|
146
146
|
sendEvent({ ...msgContent, status: 'ok' })
|
|
147
147
|
} else {
|
|
148
|
-
sendEvent({ ...msgContent, status: '
|
|
148
|
+
sendEvent({ ...msgContent, status: 'ok' })
|
|
149
149
|
}
|
|
150
150
|
}
|