@ynhcj/xiaoyi 2.2.3 → 2.2.4

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/dist/channel.js +51 -17
  2. package/package.json +1 -1
package/dist/channel.js CHANGED
@@ -8,15 +8,51 @@ const file_handler_1 = require("./file-handler");
8
8
  let onAgentEvent = null;
9
9
  let registerAgentRunContext = null;
10
10
  try {
11
- // Try to import from the built openclaw package
12
- const agentEvents = require("openclaw/dist/infra/agent-events");
13
- onAgentEvent = agentEvents.onAgentEvent;
14
- registerAgentRunContext = agentEvents.registerAgentRunContext;
15
- console.log("XiaoYi: [AGENT EVENT] Successfully imported agent event functions");
11
+ // Try multiple import paths
12
+ let agentEvents = null;
13
+ // Try path 1: openclaw/dist/infra/agent-events
14
+ try {
15
+ agentEvents = require("openclaw/dist/infra/agent-events");
16
+ console.log("XiaoYi: [AGENT EVENT] Imported from openclaw/dist/infra/agent-events");
17
+ }
18
+ catch (e1) {
19
+ console.log("XiaoYi: [AGENT EVENT] Path 1 failed:", e1?.message || e1);
20
+ // Try path 2: ../openclaw/dist/infra/agent-events
21
+ try {
22
+ agentEvents = require("../openclaw/dist/infra/agent-events");
23
+ console.log("XiaoYi: [AGENT EVENT] Imported from ../openclaw/dist/infra/agent-events");
24
+ }
25
+ catch (e2) {
26
+ console.log("XiaoYi: [AGENT EVENT] Path 2 failed:", e2?.message || e2);
27
+ // Try path 3: ../../openclaw/dist/infra/agent-events
28
+ try {
29
+ agentEvents = require("../../openclaw/dist/infra/agent-events");
30
+ console.log("XiaoYi: [AGENT EVENT] Imported from ../../openclaw/dist/infra/agent-events");
31
+ }
32
+ catch (e3) {
33
+ console.error("XiaoYi: [AGENT EVENT] All import paths failed:");
34
+ console.error(" Path 1 (openclaw/dist/infra/agent-events):", e1?.message || e1);
35
+ console.error(" Path 2 (../openclaw/dist/infra/agent-events):", e2?.message || e2);
36
+ console.error(" Path 3 (../../openclaw/dist/infra/agent-events):", e3?.message || e3);
37
+ }
38
+ }
39
+ }
40
+ if (agentEvents) {
41
+ onAgentEvent = agentEvents.onAgentEvent;
42
+ registerAgentRunContext = agentEvents.registerAgentRunContext;
43
+ if (typeof onAgentEvent === "function") {
44
+ console.log("XiaoYi: [AGENT EVENT] ✓ onAgentEvent function imported successfully");
45
+ }
46
+ else {
47
+ console.error("XiaoYi: [AGENT EVENT] ✗ onAgentEvent is not a function, type:", typeof onAgentEvent);
48
+ }
49
+ }
50
+ else {
51
+ console.warn("XiaoYi: [AGENT EVENT] Could not import agent event module");
52
+ }
16
53
  }
17
54
  catch (error) {
18
- console.warn("XiaoYi: [AGENT EVENT] Could not import agent event functions:", error);
19
- console.warn("XiaoYi: [AGENT EVENT] Streaming will be disabled");
55
+ console.error("XiaoYi: [AGENT EVENT] Fatal import error:", error?.message || error);
20
56
  }
21
57
  /**
22
58
  * XiaoYi Channel Plugin
@@ -467,21 +503,19 @@ exports.xiaoyiPlugin = {
467
503
  cfg: config,
468
504
  dispatcherOptions: {
469
505
  deliver: async (payload) => {
470
- // This is the fallback for when streaming is disabled
471
- if (streamingEnabled) {
472
- // Streaming mode: deliver is handled by onAgentEvent
473
- console.log(`XiaoYi: [DELIVER] Skipping (handled by onAgentEvent)`);
474
- return;
475
- }
506
+ // NOTE: onAgentEvent does NOT emit "assistant" stream events in production
507
+ // Only lifecycle and tool events are emitted
508
+ // So we must handle the final result here
476
509
  const elapsed = Date.now() - startTime;
477
510
  const completeText = payload.text || "";
478
511
  accumulatedText = completeText;
479
512
  console.log("\n" + "-".repeat(60));
480
- console.log(`XiaoYi: [DELIVER] Non-streaming mode`);
513
+ console.log(`XiaoYi: [DELIVER] Final result received`);
481
514
  console.log(` Elapsed: ${elapsed}ms`);
482
515
  console.log(` Length: ${completeText.length} chars`);
516
+ console.log(` Streaming frames sent: ${partialCount}`);
483
517
  console.log("-".repeat(60) + "\n");
484
- // Send final frame
518
+ // Send FINAL frame
485
519
  const response = {
486
520
  sessionId: message.sessionId,
487
521
  messageId: `msg_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
@@ -501,7 +535,7 @@ exports.xiaoyiPlugin = {
501
535
  const conn = runtime.getConnection();
502
536
  if (conn) {
503
537
  await conn.sendResponse(response, taskId, message.sessionId, true, false);
504
- console.log(`✓ XiaoYi: FINAL frame sent (non-streaming)\n`);
538
+ console.log(`✓ XiaoYi: FINAL frame sent (isFinal=true, append=false)\n`);
505
539
  }
506
540
  },
507
541
  onIdle: async () => {
@@ -520,7 +554,7 @@ exports.xiaoyiPlugin = {
520
554
  }
521
555
  },
522
556
  },
523
- replyOptions: undefined, // NOT using onPartialReply anymore
557
+ replyOptions: undefined, // onPartialReply is not used
524
558
  images: images.length > 0 ? images : undefined,
525
559
  });
526
560
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ynhcj/xiaoyi",
3
- "version": "2.2.3",
3
+ "version": "2.2.4",
4
4
  "description": "XiaoYi channel plugin for OpenClaw",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",