@ynhcj/xiaoyi-channel 0.0.18-next → 0.0.19-next

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/index.js CHANGED
@@ -24,10 +24,17 @@ const plugin = {
24
24
  if (!ALLOWED_TOOLS.includes(event.toolName)) {
25
25
  return;
26
26
  }
27
+ console.log(`[CSPL] after_tool_call triggered: toolName=${event.toolName}, sessionKey=${ctx.sessionKey ?? "none"}`);
27
28
  try {
28
29
  const resultText = extractResultText(event, event.toolName);
29
30
  const resultLength = resultText.length;
30
- if (resultLength <= MIN_TEXT_LENGTH || resultLength > MAX_TOTAL_LENGTH) {
31
+ console.log(`[CSPL] Extracted result text, length=${resultLength}`);
32
+ if (resultLength <= MIN_TEXT_LENGTH) {
33
+ console.log("[CSPL] Result text is empty, skipping");
34
+ return;
35
+ }
36
+ if (resultLength > MAX_TOTAL_LENGTH) {
37
+ console.log(`[CSPL] Result text exceeds MAX_TOTAL_LENGTH(${MAX_TOTAL_LENGTH}), actual=${resultLength}, skipping`);
31
38
  return;
32
39
  }
33
40
  // 构造 sentinel_hook 格式的 payload: { tool, output: [{ content }] }
@@ -40,17 +47,28 @@ const plugin = {
40
47
  let finalJson = JSON.stringify(questionText);
41
48
  if (finalJson.length > MAX_TEXT_LENGTH) {
42
49
  const diff = finalJson.length - MAX_TEXT_LENGTH;
50
+ console.log(`[CSPL] finalJson exceeds MAX_TEXT_LENGTH(${MAX_TEXT_LENGTH}), truncating by ${diff} chars`);
43
51
  const { text: trimmed } = validateAndTruncateText(originText, MAX_TEXT_LENGTH - diff);
44
52
  questionText.output[0].content = trimmed;
45
53
  finalJson = JSON.stringify(questionText);
46
54
  }
55
+ console.log(`[CSPL] Sending to API, payload length=${finalJson.length}`);
56
+ console.log(`[CSPL] Payload: ${finalJson}`);
47
57
  const response = await callCsplApi(finalJson, api.config);
58
+ console.log(`[CSPL] API response: ${JSON.stringify(response)}`);
48
59
  const result = parseSecurityResult(response);
60
+ console.log(`[CSPL] Security result: status=${result.status}`);
49
61
  if (result.status === "REJECT") {
50
- await tryInjectSteer(ctx.sessionKey, STEER_ABORT_MESSAGE);
62
+ console.log(`[CSPL] REJECT received, injecting steer message`);
63
+ const injected = await tryInjectSteer(ctx.sessionKey, STEER_ABORT_MESSAGE);
64
+ console.log(`[CSPL] Steer injection result: ${injected}`);
65
+ }
66
+ else {
67
+ console.log(`[CSPL] ACCEPT, no action needed`);
51
68
  }
52
69
  }
53
70
  catch (err) {
71
+ console.log(`[CSPL] after_tool_call error: ${err}`);
54
72
  api.logger.error(`[CSPL] after_tool_call error: ${err}`);
55
73
  }
56
74
  });
@@ -27,27 +27,30 @@ export function setCachedContext(cfg, runtime, accountId) {
27
27
  */
28
28
  export async function tryInjectSteer(sessionKey, message) {
29
29
  if (!sessionKey) {
30
- logger.log("[STEER] No sessionKey provided, skipping");
30
+ console.log("[STEER] No sessionKey provided, skipping");
31
31
  return false;
32
32
  }
33
+ console.log(`[STEER] Looking up sessionKey=${sessionKey}`);
33
34
  // 1. 通过 sessionKey 查找活跃 session(per-peer 模式下 1:1 对应)
34
35
  const sessionCtx = getSessionContext(sessionKey);
35
36
  if (!sessionCtx) {
36
- logger.log(`[STEER] sessionKey=${sessionKey} not in activeSessions, skipping`);
37
+ console.log(`[STEER] sessionKey=${sessionKey} not in activeSessions, skipping`);
37
38
  return false;
38
39
  }
39
40
  const { sessionId } = sessionCtx;
41
+ console.log(`[STEER] Found sessionId=${sessionId}`);
40
42
  // 2. 确认任务仍在运行
43
+ const activeTaskId = getCurrentTaskId(sessionId);
44
+ console.log(`[STEER] hasActiveTask=${hasActiveTask(sessionId)}, activeTaskId=${activeTaskId ?? "none"}`);
41
45
  if (!hasActiveTask(sessionId)) {
42
- logger.log(`[STEER] Task already ended for sessionId=${sessionId}, skipping`);
46
+ console.log(`[STEER] Task already ended for sessionId=${sessionId}, skipping`);
43
47
  return false;
44
48
  }
45
49
  if (!cachedCfg || !cachedRuntime) {
50
+ console.log("[STEER] No cached cfg/runtime available, cannot inject");
46
51
  logger.error("[STEER] No cached cfg/runtime available, cannot inject");
47
52
  return false;
48
53
  }
49
- logger.log(`[STEER] ⚡ Injecting steer for sessionId=${sessionId}`);
50
- logger.log(`[STEER] - message: "${message}"`);
51
54
  // 3. 构造合成 A2A 消息(伪装成用户在当前会话中发送的新消息)
52
55
  const syntheticMessage = {
53
56
  jsonrpc: "2.0",
@@ -55,7 +58,7 @@ export async function tryInjectSteer(sessionKey, message) {
55
58
  id: `steer-msg-${randomUUID()}`,
56
59
  params: {
57
60
  sessionId,
58
- id: getCurrentTaskId(sessionId) ?? `steer-task-${randomUUID()}`,
61
+ id: activeTaskId ?? `steer-task-${randomUUID()}`,
59
62
  agentLoginSessionId: "",
60
63
  message: {
61
64
  role: "user",
@@ -63,6 +66,8 @@ export async function tryInjectSteer(sessionKey, message) {
63
66
  },
64
67
  },
65
68
  };
69
+ console.log(`[STEER] Injecting steer for sessionId=${sessionId}, taskId=${syntheticMessage.params.id}`);
70
+ console.log(`[STEER] Synthetic message: ${JSON.stringify(syntheticMessage)}`);
66
71
  try {
67
72
  // 4. 走完整 handleXYMessage 流程
68
73
  // 由于 hasActiveTask(sessionId)=true,会自动触发 isSecondMessage=true 的 steer 模式
@@ -72,10 +77,11 @@ export async function tryInjectSteer(sessionKey, message) {
72
77
  message: syntheticMessage,
73
78
  accountId: cachedAccountId,
74
79
  });
75
- logger.log(`[STEER] Steer injected successfully for sessionId=${sessionId}`);
80
+ console.log(`[STEER] Steer injected successfully for sessionId=${sessionId}`);
76
81
  return true;
77
82
  }
78
83
  catch (err) {
84
+ console.log(`[STEER] Failed to inject steer: ${err}`);
79
85
  logger.error(`[STEER] ❌ Failed to inject steer: ${err}`);
80
86
  return false;
81
87
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ynhcj/xiaoyi-channel",
3
- "version": "0.0.18-next",
3
+ "version": "0.0.19-next",
4
4
  "description": "OpenClaw Xiaoyi Channel plugin - Xiaoyi A2A protocol integration",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",