@ynhcj/xiaoyi 2.1.0 → 2.1.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/dist/channel.js +37 -9
- package/package.json +1 -1
package/dist/channel.js
CHANGED
|
@@ -247,19 +247,34 @@ exports.xiaoyiPlugin = {
|
|
|
247
247
|
};
|
|
248
248
|
// Use the correct API to dispatch the message (streaming mode enabled)
|
|
249
249
|
try {
|
|
250
|
+
console.log("\n" + "=".repeat(60));
|
|
251
|
+
console.log(`XiaoYi: [STREAMING] Starting message processing`);
|
|
252
|
+
console.log(` Session: ${message.sessionId}`);
|
|
253
|
+
console.log(` Task ID: ${message.params.id}`);
|
|
254
|
+
console.log(` User input: ${bodyText.substring(0, 50)}${bodyText.length > 50 ? "..." : ""}`);
|
|
255
|
+
console.log("=".repeat(60) + "\n");
|
|
250
256
|
// Track response state for streaming
|
|
251
257
|
let accumulatedText = "";
|
|
252
258
|
let taskId = runtime.getTaskIdForSession(message.sessionId) || `task_${Date.now()}`;
|
|
253
259
|
let frameCount = 0;
|
|
260
|
+
let partialCount = 0;
|
|
261
|
+
const startTime = Date.now();
|
|
254
262
|
await pluginRuntime.channel.reply.dispatchReplyWithBufferedBlockDispatcher({
|
|
255
263
|
ctx: msgContext,
|
|
256
264
|
cfg: config,
|
|
257
265
|
dispatcherOptions: {
|
|
258
266
|
deliver: async (payload) => {
|
|
259
|
-
|
|
260
|
-
// Get the complete text
|
|
267
|
+
const elapsed = Date.now() - startTime;
|
|
261
268
|
const completeText = payload.text || "";
|
|
262
269
|
accumulatedText = completeText;
|
|
270
|
+
console.log("\n" + "-".repeat(60));
|
|
271
|
+
console.log(`XiaoYi: [STREAMING] DELIVER callback triggered`);
|
|
272
|
+
console.log(` Elapsed: ${elapsed}ms`);
|
|
273
|
+
console.log(` Frame: #${++frameCount}`);
|
|
274
|
+
console.log(` Total length: ${completeText.length} chars`);
|
|
275
|
+
console.log(` Partial frames sent: ${partialCount}`);
|
|
276
|
+
console.log(` Content preview: ${completeText.substring(0, 100)}...`);
|
|
277
|
+
console.log("-".repeat(60) + "\n");
|
|
263
278
|
// Send FINAL frame with complete content
|
|
264
279
|
const response = {
|
|
265
280
|
sessionId: message.sessionId,
|
|
@@ -281,26 +296,39 @@ exports.xiaoyiPlugin = {
|
|
|
281
296
|
if (conn) {
|
|
282
297
|
// Use append=false for final frame (complete content)
|
|
283
298
|
await conn.sendResponse(response, taskId, message.sessionId, true, false);
|
|
284
|
-
console.log(
|
|
299
|
+
console.log(`✓ XiaoYi: FINAL frame sent (isFinal=true, append=false, length=${accumulatedText.length})\n`);
|
|
285
300
|
}
|
|
286
301
|
},
|
|
287
302
|
onIdle: async () => {
|
|
288
|
-
|
|
289
|
-
|
|
303
|
+
const elapsed = Date.now() - startTime;
|
|
304
|
+
console.log("\n" + "=".repeat(60));
|
|
305
|
+
console.log(`XiaoYi: [STREAMING] Processing complete`);
|
|
306
|
+
console.log(` Total time: ${elapsed}ms`);
|
|
307
|
+
console.log(` Total frames: ${frameCount}`);
|
|
308
|
+
console.log(` Partial frames: ${partialCount}`);
|
|
309
|
+
console.log(` Final length: ${accumulatedText.length} chars`);
|
|
310
|
+
console.log("=".repeat(60) + "\n");
|
|
290
311
|
},
|
|
291
312
|
},
|
|
292
313
|
replyOptions: {
|
|
293
314
|
// Enable streaming responses through onPartialReply callback
|
|
294
315
|
onPartialReply: async (payload) => {
|
|
316
|
+
const elapsed = Date.now() - startTime;
|
|
295
317
|
const newText = payload.text || "";
|
|
296
318
|
if (!newText) {
|
|
297
|
-
|
|
319
|
+
console.log(`XiaoYi: [STREAMING] Skipping empty partial response at ${elapsed}ms`);
|
|
320
|
+
return;
|
|
298
321
|
}
|
|
299
|
-
console.log("XiaoYi: Streaming partial response:", newText.substring(0, 30) + "...");
|
|
300
322
|
// Calculate delta text (增量部分)
|
|
301
323
|
const previousLength = accumulatedText.length;
|
|
302
324
|
accumulatedText = newText;
|
|
303
325
|
const deltaText = newText.slice(previousLength);
|
|
326
|
+
console.log(`\n>>> XiaoYi: [PARTIAL] Frame #${++partialCount} at ${elapsed}ms`);
|
|
327
|
+
console.log(` Previous length: ${previousLength}`);
|
|
328
|
+
console.log(` New length: ${newText.length}`);
|
|
329
|
+
console.log(` Delta length: ${deltaText.length}`);
|
|
330
|
+
console.log(` Delta content: "${deltaText}"`);
|
|
331
|
+
console.log(` Accumulated so far: "${newText}"`);
|
|
304
332
|
// Send PARTIAL frame with delta content
|
|
305
333
|
const partialResponse = {
|
|
306
334
|
sessionId: message.sessionId,
|
|
@@ -322,14 +350,14 @@ exports.xiaoyiPlugin = {
|
|
|
322
350
|
if (conn) {
|
|
323
351
|
// Use append=true for streaming frames (服务端会追加)
|
|
324
352
|
await conn.sendResponse(partialResponse, taskId, message.sessionId, false, true);
|
|
325
|
-
console.log(`
|
|
353
|
+
console.log(` ✓ SENT (isFinal=false, append=true)\n`);
|
|
326
354
|
}
|
|
327
355
|
},
|
|
328
356
|
},
|
|
329
357
|
});
|
|
330
358
|
}
|
|
331
359
|
catch (error) {
|
|
332
|
-
console.error("Error dispatching message:", error);
|
|
360
|
+
console.error("XiaoYi: [ERROR] Error dispatching message:", error);
|
|
333
361
|
}
|
|
334
362
|
});
|
|
335
363
|
// Setup cancel handler
|