@dcrays/dcgchat-test 0.2.11 → 0.2.12

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/bot.ts +32 -19
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcrays/dcgchat-test",
3
- "version": "0.2.11",
3
+ "version": "0.2.12",
4
4
  "type": "module",
5
5
  "description": "OpenClaw channel plugin for 书灵墨宝 (WebSocket)",
6
6
  "main": "index.ts",
package/src/bot.ts CHANGED
@@ -247,6 +247,8 @@ export async function handleDcgchatMessage(params: {
247
247
 
248
248
  log(`dcgchat[${accountId}]: ctxPayload=${JSON.stringify(ctxPayload)}`);
249
249
 
250
+ const sentMediaKeys = new Set<string>()
251
+ const getMediaKey = (url: string) => url.split(/[\\/]/).slice(-2).join('/')
250
252
  let textChunk = ''
251
253
 
252
254
  const prefixContext = createReplyPrefixContext({ cfg, agentId: route.agentId });
@@ -294,11 +296,15 @@ export async function handleDcgchatMessage(params: {
294
296
  const mediaList = resolveReplyMediaList(payload);
295
297
  if (mediaList.length > 0) {
296
298
  for (let i = 0; i < mediaList.length; i++) {
299
+ const mediaUrl = mediaList[i];
300
+ const key = getMediaKey(mediaUrl);
301
+ if (sentMediaKeys.has(key)) continue;
302
+ sentMediaKeys.add(key);
297
303
  await sendDcgchatMedia({
298
304
  cfg,
299
305
  accountId,
300
306
  log,
301
- mediaUrl: mediaList[i],
307
+ mediaUrl,
302
308
  text: "",
303
309
  });
304
310
  }
@@ -334,23 +340,7 @@ export async function handleDcgchatMessage(params: {
334
340
  },
335
341
  });
336
342
  }
337
- log(`dcgchat[${accountId}]: dispatch complete, sending final state`);
338
- params.onChunk({
339
- messageType: "openclaw_bot_chat",
340
- _userId: msg._userId,
341
- source: "client",
342
- content: {
343
- bot_token: msg.content.bot_token,
344
- domain_id: msg.content.domain_id,
345
- app_id: msg.content.app_id,
346
- bot_id: msg.content.bot_id,
347
- agent_id: msg.content.agent_id,
348
- session_id: msg.content.session_id,
349
- message_id: msg.content.message_id,
350
- response: '',
351
- state: 'final',
352
- },
353
- });
343
+
354
344
  const extractor = createFileExtractor()
355
345
  const completeFiles = extractor.getNewFiles(completeText)
356
346
  if (completeFiles.length > 0) {
@@ -359,10 +349,16 @@ export async function handleDcgchatMessage(params: {
359
349
  if (!path.isAbsolute(url)) {
360
350
  url = path.join(getWorkspaceDir(), url)
361
351
  }
352
+ const key = getMediaKey(url);
353
+ if (sentMediaKeys.has(key)) {
354
+ log(`dcgchat[${accountId}]: completeFiles already sent, skipping: ${url}`);
355
+ continue;
356
+ }
362
357
  if (!fs.existsSync(url)) {
363
- log(`dcgchat[${accountId}]: completeFiles file not found, skipping: ${url}`);
358
+ log(`dcgchat[${accountId}]: completeFiles file not found, skipping: ${url}`);
364
359
  continue;
365
360
  }
361
+ sentMediaKeys.add(key);
366
362
  await sendDcgchatMedia({
367
363
  cfg,
368
364
  accountId,
@@ -373,6 +369,23 @@ export async function handleDcgchatMessage(params: {
373
369
  }
374
370
  log(`dcgchat[${accountId}][deliver]: sent ${completeFiles.length} media file(s) through channel adapter`);
375
371
  }
372
+ log(`dcgchat[${accountId}]: dispatch complete, sending final state`);
373
+ params.onChunk({
374
+ messageType: "openclaw_bot_chat",
375
+ _userId: msg._userId,
376
+ source: "client",
377
+ content: {
378
+ bot_token: msg.content.bot_token,
379
+ domain_id: msg.content.domain_id,
380
+ app_id: msg.content.app_id,
381
+ bot_id: msg.content.bot_id,
382
+ agent_id: msg.content.agent_id,
383
+ session_id: msg.content.session_id,
384
+ message_id: msg.content.message_id,
385
+ response: '',
386
+ state: 'final',
387
+ },
388
+ });
376
389
 
377
390
  setMsgStatus('finished');
378
391
  textChunk = ''