@ynhcj/xiaoyi 2.1.0 → 2.1.2
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.d.ts +1 -7
- package/dist/channel.js +42 -11
- package/dist/config-schema.d.ts +4 -0
- package/dist/config-schema.js +2 -0
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
package/dist/channel.d.ts
CHANGED
|
@@ -37,13 +37,7 @@ export declare const xiaoyiPlugin: {
|
|
|
37
37
|
listAccountIds: (cfg: OpenClawConfig) => string[];
|
|
38
38
|
resolveAccount: (cfg: OpenClawConfig, accountId?: string | null) => {
|
|
39
39
|
accountId: string;
|
|
40
|
-
config:
|
|
41
|
-
enabled: boolean;
|
|
42
|
-
wsUrl: string;
|
|
43
|
-
ak: string;
|
|
44
|
-
sk: string;
|
|
45
|
-
agentId: string;
|
|
46
|
-
};
|
|
40
|
+
config: XiaoYiChannelConfig;
|
|
47
41
|
enabled: boolean;
|
|
48
42
|
};
|
|
49
43
|
defaultAccountId: (cfg: OpenClawConfig) => "default" | undefined;
|
package/dist/channel.js
CHANGED
|
@@ -247,19 +247,36 @@ exports.xiaoyiPlugin = {
|
|
|
247
247
|
};
|
|
248
248
|
// Use the correct API to dispatch the message (streaming mode enabled)
|
|
249
249
|
try {
|
|
250
|
+
const streamingEnabled = resolvedAccount.config.enableStreaming === true;
|
|
251
|
+
console.log("\n" + "=".repeat(60));
|
|
252
|
+
console.log(`XiaoYi: [STREAMING] Starting message processing`);
|
|
253
|
+
console.log(` Session: ${message.sessionId}`);
|
|
254
|
+
console.log(` Task ID: ${message.params.id}`);
|
|
255
|
+
console.log(` User input: ${bodyText.substring(0, 50)}${bodyText.length > 50 ? "..." : ""}`);
|
|
256
|
+
console.log(` Streaming: ${streamingEnabled ? "ENABLED" : "DISABLED (enableStreaming=false)"}`);
|
|
257
|
+
console.log("=".repeat(60) + "\n");
|
|
250
258
|
// Track response state for streaming
|
|
251
259
|
let accumulatedText = "";
|
|
252
260
|
let taskId = runtime.getTaskIdForSession(message.sessionId) || `task_${Date.now()}`;
|
|
253
261
|
let frameCount = 0;
|
|
262
|
+
let partialCount = 0;
|
|
263
|
+
const startTime = Date.now();
|
|
254
264
|
await pluginRuntime.channel.reply.dispatchReplyWithBufferedBlockDispatcher({
|
|
255
265
|
ctx: msgContext,
|
|
256
266
|
cfg: config,
|
|
257
267
|
dispatcherOptions: {
|
|
258
268
|
deliver: async (payload) => {
|
|
259
|
-
|
|
260
|
-
// Get the complete text
|
|
269
|
+
const elapsed = Date.now() - startTime;
|
|
261
270
|
const completeText = payload.text || "";
|
|
262
271
|
accumulatedText = completeText;
|
|
272
|
+
console.log("\n" + "-".repeat(60));
|
|
273
|
+
console.log(`XiaoYi: [STREAMING] DELIVER callback triggered`);
|
|
274
|
+
console.log(` Elapsed: ${elapsed}ms`);
|
|
275
|
+
console.log(` Frame: #${++frameCount}`);
|
|
276
|
+
console.log(` Total length: ${completeText.length} chars`);
|
|
277
|
+
console.log(` Partial frames sent: ${partialCount}`);
|
|
278
|
+
console.log(` Content preview: ${completeText.substring(0, 100)}...`);
|
|
279
|
+
console.log("-".repeat(60) + "\n");
|
|
263
280
|
// Send FINAL frame with complete content
|
|
264
281
|
const response = {
|
|
265
282
|
sessionId: message.sessionId,
|
|
@@ -281,26 +298,40 @@ exports.xiaoyiPlugin = {
|
|
|
281
298
|
if (conn) {
|
|
282
299
|
// Use append=false for final frame (complete content)
|
|
283
300
|
await conn.sendResponse(response, taskId, message.sessionId, true, false);
|
|
284
|
-
console.log(
|
|
301
|
+
console.log(`✓ XiaoYi: FINAL frame sent (isFinal=true, append=false, length=${accumulatedText.length})\n`);
|
|
285
302
|
}
|
|
286
303
|
},
|
|
287
304
|
onIdle: async () => {
|
|
288
|
-
|
|
289
|
-
|
|
305
|
+
const elapsed = Date.now() - startTime;
|
|
306
|
+
console.log("\n" + "=".repeat(60));
|
|
307
|
+
console.log(`XiaoYi: [STREAMING] Processing complete`);
|
|
308
|
+
console.log(` Total time: ${elapsed}ms`);
|
|
309
|
+
console.log(` Total frames: ${frameCount}`);
|
|
310
|
+
console.log(` Partial frames: ${partialCount}`);
|
|
311
|
+
console.log(` Final length: ${accumulatedText.length} chars`);
|
|
312
|
+
console.log("=".repeat(60) + "\n");
|
|
290
313
|
},
|
|
291
314
|
},
|
|
292
|
-
replyOptions: {
|
|
315
|
+
replyOptions: streamingEnabled ? {
|
|
293
316
|
// Enable streaming responses through onPartialReply callback
|
|
317
|
+
disableBlockStreaming: false, // CRITICAL: Enable block streaming
|
|
294
318
|
onPartialReply: async (payload) => {
|
|
319
|
+
const elapsed = Date.now() - startTime;
|
|
295
320
|
const newText = payload.text || "";
|
|
296
321
|
if (!newText) {
|
|
297
|
-
|
|
322
|
+
console.log(`XiaoYi: [STREAMING] Skipping empty partial response at ${elapsed}ms`);
|
|
323
|
+
return;
|
|
298
324
|
}
|
|
299
|
-
console.log("XiaoYi: Streaming partial response:", newText.substring(0, 30) + "...");
|
|
300
325
|
// Calculate delta text (增量部分)
|
|
301
326
|
const previousLength = accumulatedText.length;
|
|
302
327
|
accumulatedText = newText;
|
|
303
328
|
const deltaText = newText.slice(previousLength);
|
|
329
|
+
console.log(`\n>>> XiaoYi: [PARTIAL] Frame #${++partialCount} at ${elapsed}ms`);
|
|
330
|
+
console.log(` Previous length: ${previousLength}`);
|
|
331
|
+
console.log(` New length: ${newText.length}`);
|
|
332
|
+
console.log(` Delta length: ${deltaText.length}`);
|
|
333
|
+
console.log(` Delta content: "${deltaText}"`);
|
|
334
|
+
console.log(` Accumulated so far: "${newText}"`);
|
|
304
335
|
// Send PARTIAL frame with delta content
|
|
305
336
|
const partialResponse = {
|
|
306
337
|
sessionId: message.sessionId,
|
|
@@ -322,14 +353,14 @@ exports.xiaoyiPlugin = {
|
|
|
322
353
|
if (conn) {
|
|
323
354
|
// Use append=true for streaming frames (服务端会追加)
|
|
324
355
|
await conn.sendResponse(partialResponse, taskId, message.sessionId, false, true);
|
|
325
|
-
console.log(`
|
|
356
|
+
console.log(` ✓ SENT (isFinal=false, append=true)\n`);
|
|
326
357
|
}
|
|
327
358
|
},
|
|
328
|
-
},
|
|
359
|
+
} : undefined, // No replyOptions when streaming is disabled
|
|
329
360
|
});
|
|
330
361
|
}
|
|
331
362
|
catch (error) {
|
|
332
|
-
console.error("Error dispatching message:", error);
|
|
363
|
+
console.error("XiaoYi: [ERROR] Error dispatching message:", error);
|
|
333
364
|
}
|
|
334
365
|
});
|
|
335
366
|
// Setup cancel handler
|
package/dist/config-schema.d.ts
CHANGED
|
@@ -18,11 +18,14 @@ export declare const XiaoYiConfigSchema: z.ZodObject<{
|
|
|
18
18
|
agentId: z.ZodOptional<z.ZodString>;
|
|
19
19
|
/** Enable debug logging */
|
|
20
20
|
debug: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
21
|
+
/** Enable streaming responses (default: false) */
|
|
22
|
+
enableStreaming: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
21
23
|
/** Multi-account configuration */
|
|
22
24
|
accounts: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
23
25
|
}, "strip", z.ZodTypeAny, {
|
|
24
26
|
enabled: boolean;
|
|
25
27
|
debug: boolean;
|
|
28
|
+
enableStreaming: boolean;
|
|
26
29
|
name?: string | undefined;
|
|
27
30
|
wsUrl?: string | undefined;
|
|
28
31
|
ak?: string | undefined;
|
|
@@ -37,6 +40,7 @@ export declare const XiaoYiConfigSchema: z.ZodObject<{
|
|
|
37
40
|
sk?: string | undefined;
|
|
38
41
|
agentId?: string | undefined;
|
|
39
42
|
debug?: boolean | undefined;
|
|
43
|
+
enableStreaming?: boolean | undefined;
|
|
40
44
|
accounts?: Record<string, unknown> | undefined;
|
|
41
45
|
}>;
|
|
42
46
|
export type XiaoYiConfig = z.infer<typeof XiaoYiConfigSchema>;
|
package/dist/config-schema.js
CHANGED
|
@@ -21,6 +21,8 @@ exports.XiaoYiConfigSchema = zod_1.z.object({
|
|
|
21
21
|
agentId: zod_1.z.string().optional(),
|
|
22
22
|
/** Enable debug logging */
|
|
23
23
|
debug: zod_1.z.boolean().optional().default(false),
|
|
24
|
+
/** Enable streaming responses (default: false) */
|
|
25
|
+
enableStreaming: zod_1.z.boolean().optional().default(false),
|
|
24
26
|
/** Multi-account configuration */
|
|
25
27
|
accounts: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).optional(),
|
|
26
28
|
});
|
package/dist/types.d.ts
CHANGED