@dcrays/dcgchat-test 0.2.0 → 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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/bot.ts +51 -18
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcrays/dcgchat-test",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "type": "module",
5
5
  "description": "OpenClaw channel plugin for 书灵墨宝 (WebSocket)",
6
6
  "main": "index.ts",
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";
@@ -164,6 +164,8 @@ export async function handleDcgchatMessage(params: {
164
164
 
165
165
  log(`dcgchat[${accountId}]: ctxPayload=${JSON.stringify(ctxPayload)}`);
166
166
 
167
+ let textChunk = ''
168
+
167
169
  const prefixContext = createReplyPrefixContext({ cfg, agentId: route.agentId });
168
170
 
169
171
  const { dispatcher, replyOptions, markDispatchIdle } =
@@ -173,7 +175,51 @@ export async function handleDcgchatMessage(params: {
173
175
  humanDelay: core.channel.reply.resolveHumanDelayConfig(cfg, route.agentId),
174
176
  onReplyStart: async () => {},
175
177
  deliver: async (payload) => {
176
- 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}`);
177
223
  const t = payload.text?.trim().replaceAll(
178
224
  "/root/.openclaw/workspace/moBooksAgentGenerate",
179
225
  "/upload"
@@ -192,30 +238,16 @@ export async function handleDcgchatMessage(params: {
192
238
  agent_id: msg.content.agent_id,
193
239
  session_id: msg.content.session_id,
194
240
  message_id: msg.content.message_id,
195
- response: t,
241
+ response: t.replace(textChunk, ''),
196
242
  state: 'chunk',
197
243
  },
198
244
  });
245
+ textChunk = t
199
246
  log(`dcgchat[${accountId}][deliver]: chunk sent successfully`);
200
247
  } else {
201
248
  log(`dcgchat[${accountId}][deliver]: skipping empty chunk`);
202
249
  }
203
250
  },
204
- onError: (err, info) => {
205
- error(`dcgchat[${accountId}] ${info.kind} reply failed: ${String(err)}`);
206
- },
207
- onIdle: () => {},
208
- });
209
-
210
- log(`dcgchat[${accountId}]: dispatching to agent (session=${route.sessionKey})`);
211
-
212
- await core.channel.reply.dispatchReplyFromConfig({
213
- ctx: ctxPayload,
214
- cfg,
215
- dispatcher,
216
- replyOptions: {
217
- ...replyOptions,
218
- onModelSelected: prefixContext.onModelSelected,
219
251
  },
220
252
  });
221
253
 
@@ -237,6 +269,7 @@ export async function handleDcgchatMessage(params: {
237
269
  },
238
270
  });
239
271
  setMsgStatus('finished');
272
+ textChunk = ''
240
273
  log(`dcgchat[${accountId}]: final state sent`);
241
274
 
242
275
  markDispatchIdle();