@ynhcj/xiaoyi-channel 0.0.21-next → 0.0.22-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 +3 -17
- package/dist/src/steer-injector.js +0 -14
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -28,13 +28,7 @@ const plugin = {
|
|
|
28
28
|
try {
|
|
29
29
|
const resultText = extractResultText(event, event.toolName);
|
|
30
30
|
const resultLength = resultText.length;
|
|
31
|
-
|
|
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
|
+
if (resultLength <= MIN_TEXT_LENGTH || resultLength > MAX_TOTAL_LENGTH) {
|
|
38
32
|
return;
|
|
39
33
|
}
|
|
40
34
|
// 构造 sentinel_hook 格式的 payload: { tool, output: [{ content }] }
|
|
@@ -47,26 +41,18 @@ const plugin = {
|
|
|
47
41
|
let finalJson = JSON.stringify(questionText);
|
|
48
42
|
if (finalJson.length > MAX_TEXT_LENGTH) {
|
|
49
43
|
const diff = finalJson.length - MAX_TEXT_LENGTH;
|
|
50
|
-
console.log(`[CSPL] finalJson exceeds MAX_TEXT_LENGTH(${MAX_TEXT_LENGTH}), truncating by ${diff} chars`);
|
|
51
44
|
const { text: trimmed } = validateAndTruncateText(originText, MAX_TEXT_LENGTH - diff);
|
|
52
45
|
questionText.output[0].content = trimmed;
|
|
53
46
|
finalJson = JSON.stringify(questionText);
|
|
54
47
|
}
|
|
55
|
-
console.log(`[CSPL] Sending to API, payload length=${finalJson.length}`);
|
|
56
|
-
console.log(`[CSPL] Payload: ${finalJson}`);
|
|
57
48
|
const response = await callCsplApi(finalJson, api.config);
|
|
58
|
-
console.log(`[CSPL] API response: ${JSON.stringify(response)}`);
|
|
59
49
|
const result = parseSecurityResult(response);
|
|
60
50
|
console.log(`[CSPL] Security result: status=${result.status}`);
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
console.log(`[CSPL] ${result.status} received, injecting steer message (MOCK MODE)`);
|
|
64
|
-
const injected = await tryInjectSteer(ctx.sessionKey, STEER_ABORT_MESSAGE);
|
|
65
|
-
console.log(`[CSPL] Steer injection result: ${injected}`);
|
|
51
|
+
if (result.status === "REJECT") {
|
|
52
|
+
await tryInjectSteer(ctx.sessionKey, STEER_ABORT_MESSAGE);
|
|
66
53
|
}
|
|
67
54
|
}
|
|
68
55
|
catch (err) {
|
|
69
|
-
console.log(`[CSPL] after_tool_call error: ${err}`);
|
|
70
56
|
api.logger.error(`[CSPL] after_tool_call error: ${err}`);
|
|
71
57
|
}
|
|
72
58
|
});
|
|
@@ -27,27 +27,18 @@ export function setCachedContext(cfg, runtime, accountId) {
|
|
|
27
27
|
*/
|
|
28
28
|
export async function tryInjectSteer(sessionKey, message) {
|
|
29
29
|
if (!sessionKey) {
|
|
30
|
-
console.log("[STEER] No sessionKey provided, skipping");
|
|
31
30
|
return false;
|
|
32
31
|
}
|
|
33
|
-
console.log(`[STEER] Looking up sessionKey=${sessionKey}`);
|
|
34
|
-
// 1. 通过 sessionKey 查找活跃 session(per-peer 模式下 1:1 对应)
|
|
35
32
|
const sessionCtx = getSessionContext(sessionKey);
|
|
36
33
|
if (!sessionCtx) {
|
|
37
|
-
console.log(`[STEER] sessionKey=${sessionKey} not in activeSessions, skipping`);
|
|
38
34
|
return false;
|
|
39
35
|
}
|
|
40
36
|
const { sessionId } = sessionCtx;
|
|
41
|
-
console.log(`[STEER] Found sessionId=${sessionId}`);
|
|
42
|
-
// 2. 确认任务仍在运行
|
|
43
37
|
const activeTaskId = getCurrentTaskId(sessionId);
|
|
44
|
-
console.log(`[STEER] hasActiveTask=${hasActiveTask(sessionId)}, activeTaskId=${activeTaskId ?? "none"}`);
|
|
45
38
|
if (!hasActiveTask(sessionId)) {
|
|
46
|
-
console.log(`[STEER] Task already ended for sessionId=${sessionId}, skipping`);
|
|
47
39
|
return false;
|
|
48
40
|
}
|
|
49
41
|
if (!cachedCfg || !cachedRuntime) {
|
|
50
|
-
console.log("[STEER] No cached cfg/runtime available, cannot inject");
|
|
51
42
|
logger.error("[STEER] No cached cfg/runtime available, cannot inject");
|
|
52
43
|
return false;
|
|
53
44
|
}
|
|
@@ -67,21 +58,16 @@ export async function tryInjectSteer(sessionKey, message) {
|
|
|
67
58
|
},
|
|
68
59
|
};
|
|
69
60
|
console.log(`[STEER] Injecting steer for sessionId=${sessionId}, taskId=${syntheticMessage.params.id}`);
|
|
70
|
-
console.log(`[STEER] Synthetic message: ${JSON.stringify(syntheticMessage)}`);
|
|
71
61
|
try {
|
|
72
|
-
// 4. 走完整 handleXYMessage 流程
|
|
73
|
-
// 由于 hasActiveTask(sessionId)=true,会自动触发 isSecondMessage=true 的 steer 模式
|
|
74
62
|
await handleXYMessage({
|
|
75
63
|
cfg: cachedCfg,
|
|
76
64
|
runtime: cachedRuntime,
|
|
77
65
|
message: syntheticMessage,
|
|
78
66
|
accountId: cachedAccountId,
|
|
79
67
|
});
|
|
80
|
-
console.log(`[STEER] Steer injected successfully for sessionId=${sessionId}`);
|
|
81
68
|
return true;
|
|
82
69
|
}
|
|
83
70
|
catch (err) {
|
|
84
|
-
console.log(`[STEER] Failed to inject steer: ${err}`);
|
|
85
71
|
logger.error(`[STEER] ❌ Failed to inject steer: ${err}`);
|
|
86
72
|
return false;
|
|
87
73
|
}
|