@ynhcj/xiaoyi-channel 0.0.192-beta → 0.0.192-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 +56 -3
- package/dist/src/acp-session-binding.d.ts +37 -0
- package/dist/src/acp-session-binding.js +237 -0
- package/dist/src/bot.js +101 -34
- package/dist/src/channel.js +68 -64
- package/dist/src/client.d.ts +5 -0
- package/dist/src/client.js +10 -0
- package/dist/src/cspl/call_api.js +2 -0
- package/dist/src/cspl/sentinel_hook.js +9 -8
- package/dist/src/formatter.d.ts +5 -0
- package/dist/src/formatter.js +24 -34
- package/dist/src/log-reporter/config-loader.d.ts +11 -0
- package/dist/src/log-reporter/config-loader.js +68 -0
- package/dist/src/log-reporter/cursor-store.d.ts +5 -0
- package/dist/src/log-reporter/cursor-store.js +26 -0
- package/dist/src/log-reporter/index.d.ts +10 -0
- package/dist/src/log-reporter/index.js +77 -0
- package/dist/src/log-reporter/reporter.d.ts +6 -0
- package/dist/src/log-reporter/reporter.js +17 -0
- package/dist/src/log-reporter/scanner.d.ts +6 -0
- package/dist/src/log-reporter/scanner.js +82 -0
- package/dist/src/log-reporter/types.d.ts +59 -0
- package/dist/src/log-reporter/types.js +2 -0
- package/dist/src/log-reporter/uploader.d.ts +6 -0
- package/dist/src/log-reporter/uploader.js +32 -0
- package/dist/src/memory-query-handler.js +123 -4
- package/dist/src/monitor.js +20 -9
- package/dist/src/outbound.d.ts +7 -0
- package/dist/src/outbound.js +77 -5
- package/dist/src/parser.d.ts +12 -0
- package/dist/src/parser.js +32 -0
- package/dist/src/provider.js +69 -15
- package/dist/src/reply-dispatcher.d.ts +3 -0
- package/dist/src/reply-dispatcher.js +184 -154
- package/dist/src/self-evolution-handler.js +2 -1
- package/dist/src/subagent-wait-state.d.ts +66 -0
- package/dist/src/subagent-wait-state.js +226 -0
- package/dist/src/task-manager.d.ts +14 -7
- package/dist/src/task-manager.js +54 -15
- package/dist/src/tools/agent-as-skill-tool.d.ts +41 -2
- package/dist/src/tools/agent-as-skill-tool.js +144 -151
- package/dist/src/tools/calendar-tool.d.ts +24 -2
- package/dist/src/tools/calendar-tool.js +115 -117
- package/dist/src/tools/call-device-tool.d.ts +20 -6
- package/dist/src/tools/call-device-tool.js +116 -138
- package/dist/src/tools/call-phone-tool.d.ts +21 -2
- package/dist/src/tools/call-phone-tool.js +112 -114
- package/dist/src/tools/check-plugin-privilege-tool.d.ts +16 -2
- package/dist/src/tools/check-plugin-privilege-tool.js +141 -143
- package/dist/src/tools/create-alarm-tool.d.ts +39 -2
- package/dist/src/tools/create-alarm-tool.js +229 -231
- package/dist/src/tools/create-all-tools.js +2 -2
- package/dist/src/tools/delete-alarm-tool.d.ts +15 -2
- package/dist/src/tools/delete-alarm-tool.js +134 -136
- package/dist/src/tools/device-tool-map.js +1 -1
- package/dist/src/tools/discover-cross-devices-tool.d.ts +16 -2
- package/dist/src/tools/discover-cross-devices-tool.js +121 -124
- package/dist/src/tools/display-a2ui-card-bypath-tool.d.ts +21 -0
- package/dist/src/tools/display-a2ui-card-bypath-tool.js +65 -0
- package/dist/src/tools/get-alarm-tool-schema.d.ts +1 -2
- package/dist/src/tools/get-alarm-tool-schema.js +10 -16
- package/dist/src/tools/get-calendar-tool-schema.d.ts +1 -2
- package/dist/src/tools/get-calendar-tool-schema.js +8 -12
- package/dist/src/tools/get-collection-tool-schema.d.ts +1 -2
- package/dist/src/tools/get-collection-tool-schema.js +9 -11
- package/dist/src/tools/get-contact-tool-schema.d.ts +1 -2
- package/dist/src/tools/get-contact-tool-schema.js +10 -16
- package/dist/src/tools/get-device-file-tool-schema.d.ts +1 -2
- package/dist/src/tools/get-device-file-tool-schema.js +9 -13
- package/dist/src/tools/get-email-tool-schema.d.ts +1 -2
- package/dist/src/tools/get-email-tool-schema.js +8 -11
- package/dist/src/tools/get-note-tool-schema.d.ts +1 -2
- package/dist/src/tools/get-note-tool-schema.js +9 -14
- package/dist/src/tools/get-photo-tool-schema.d.ts +1 -2
- package/dist/src/tools/get-photo-tool-schema.js +9 -12
- package/dist/src/tools/image-reading-tool.d.ts +28 -2
- package/dist/src/tools/image-reading-tool.js +76 -76
- package/dist/src/tools/location-tool.d.ts +11 -2
- package/dist/src/tools/location-tool.js +93 -92
- package/dist/src/tools/login-token-tool.d.ts +20 -2
- package/dist/src/tools/login-token-tool.js +123 -125
- package/dist/src/tools/modify-alarm-tool.d.ts +47 -2
- package/dist/src/tools/modify-alarm-tool.js +250 -252
- package/dist/src/tools/modify-note-tool.d.ts +20 -2
- package/dist/src/tools/modify-note-tool.js +107 -109
- package/dist/src/tools/note-tool.d.ts +20 -2
- package/dist/src/tools/note-tool.js +106 -108
- package/dist/src/tools/query-app-message-tool.d.ts +28 -2
- package/dist/src/tools/query-app-message-tool.js +111 -113
- package/dist/src/tools/query-memory-data-tool.d.ts +28 -2
- package/dist/src/tools/query-memory-data-tool.js +112 -114
- package/dist/src/tools/query-todo-task-tool.d.ts +24 -2
- package/dist/src/tools/query-todo-task-tool.js +106 -108
- package/dist/src/tools/save-file-to-phone-tool.d.ts +24 -2
- package/dist/src/tools/save-file-to-phone-tool.js +130 -132
- package/dist/src/tools/save-media-to-gallery-tool.d.ts +24 -2
- package/dist/src/tools/save-media-to-gallery-tool.js +137 -139
- package/dist/src/tools/save-self-evolution-skill-tool.d.ts +54 -2
- package/dist/src/tools/save-self-evolution-skill-tool.js +194 -194
- package/dist/src/tools/search-alarm-tool.d.ts +34 -2
- package/dist/src/tools/search-alarm-tool.js +174 -176
- package/dist/src/tools/search-calendar-tool.d.ts +24 -2
- package/dist/src/tools/search-calendar-tool.js +148 -150
- package/dist/src/tools/search-contact-tool.d.ts +16 -2
- package/dist/src/tools/search-contact-tool.js +101 -103
- package/dist/src/tools/search-email-tool.d.ts +21 -2
- package/dist/src/tools/search-email-tool.js +110 -112
- package/dist/src/tools/search-file-tool.d.ts +16 -2
- package/dist/src/tools/search-file-tool.js +104 -106
- package/dist/src/tools/search-message-tool.d.ts +16 -2
- package/dist/src/tools/search-message-tool.js +103 -105
- package/dist/src/tools/search-note-tool.d.ts +16 -2
- package/dist/src/tools/search-note-tool.js +98 -100
- package/dist/src/tools/search-photo-gallery-tool.d.ts +21 -2
- package/dist/src/tools/search-photo-gallery-tool.js +35 -37
- package/dist/src/tools/send-cross-device-task-tool.d.ts +35 -2
- package/dist/src/tools/send-cross-device-task-tool.js +140 -143
- package/dist/src/tools/send-email-tool.d.ts +24 -2
- package/dist/src/tools/send-email-tool.js +108 -110
- package/dist/src/tools/send-file-to-user-tool.d.ts +20 -2
- package/dist/src/tools/send-file-to-user-tool.js +174 -176
- package/dist/src/tools/send-html-card-tool.d.ts +20 -2
- package/dist/src/tools/send-html-card-tool.js +85 -87
- package/dist/src/tools/send-message-tool.d.ts +20 -2
- package/dist/src/tools/send-message-tool.js +122 -124
- package/dist/src/tools/session-manager.d.ts +11 -50
- package/dist/src/tools/session-manager.js +40 -231
- package/dist/src/tools/upload-file-tool.d.ts +20 -2
- package/dist/src/tools/upload-file-tool.js +80 -82
- package/dist/src/tools/upload-photo-tool.d.ts +20 -2
- package/dist/src/tools/upload-photo-tool.js +68 -70
- package/dist/src/tools/xiaoyi-add-collection-tool.d.ts +32 -2
- package/dist/src/tools/xiaoyi-add-collection-tool.js +146 -148
- package/dist/src/tools/xiaoyi-collection-tool.d.ts +20 -2
- package/dist/src/tools/xiaoyi-collection-tool.js +114 -116
- package/dist/src/tools/xiaoyi-delete-collection-tool.d.ts +15 -2
- package/dist/src/tools/xiaoyi-delete-collection-tool.js +127 -129
- package/dist/src/tools/xiaoyi-gui-tool.d.ts +16 -2
- package/dist/src/tools/xiaoyi-gui-tool.js +92 -95
- package/dist/src/utils/logger.js +3 -14
- package/dist/src/websocket.d.ts +1 -1
- package/dist/src/websocket.js +4 -4
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -3,13 +3,15 @@ import { xiaoyiProvider } from "./src/provider.js";
|
|
|
3
3
|
import { xyPlugin } from "./src/channel.js";
|
|
4
4
|
import registerSentinelHook from "./src/cspl/sentinel_hook.js";
|
|
5
5
|
import { setXYRuntime } from "./src/runtime.js";
|
|
6
|
-
import { markCronToolCall, clearCronToolCall,
|
|
6
|
+
import { markCronToolCall, clearCronToolCall, getCurrentSessionContext } from "./src/tools/session-manager.js";
|
|
7
7
|
import { configManager } from "./src/utils/config-manager.js";
|
|
8
8
|
import { setJobPushId } from "./src/utils/cron-push-map.js";
|
|
9
9
|
import { getAllPushIds } from "./src/utils/pushid-manager.js";
|
|
10
10
|
import { registerSelfEvolutionToolResultNudge } from "./src/self-evolution-tool-result-nudge.js";
|
|
11
11
|
import { createBeforePromptBuildHandler } from "./src/skill-retriever/hooks.js";
|
|
12
12
|
import { normalizeToolRetrieverConfig } from "./src/skill-retriever/config.js";
|
|
13
|
+
import { markSubagentSpawned, markSubagentEnded, } from "./src/subagent-wait-state.js";
|
|
14
|
+
import { logger } from "./src/utils/logger.js";
|
|
13
15
|
/**
|
|
14
16
|
* Register the cron detection hook.
|
|
15
17
|
*
|
|
@@ -54,10 +56,10 @@ async function captureCronAddMapping(event, ctx) {
|
|
|
54
56
|
return;
|
|
55
57
|
}
|
|
56
58
|
console.log(`[CRONMAP] extracted jobId=${jobId}`);
|
|
57
|
-
const sessionCtx =
|
|
59
|
+
const sessionCtx = getCurrentSessionContext();
|
|
58
60
|
const sessionId = sessionCtx?.sessionId;
|
|
59
61
|
if (!sessionId) {
|
|
60
|
-
console.log(`[CRONMAP] skip: no sessionId (
|
|
62
|
+
console.log(`[CRONMAP] skip: no sessionId in ALS scope (ctxFound=${!!sessionCtx})`);
|
|
61
63
|
return;
|
|
62
64
|
}
|
|
63
65
|
const pushId = await resolvePushId(sessionId);
|
|
@@ -167,7 +169,58 @@ function readJobIdFromResult(result) {
|
|
|
167
169
|
}
|
|
168
170
|
return undefined;
|
|
169
171
|
}
|
|
172
|
+
function registerSubagentHooks(api) {
|
|
173
|
+
// subagent_spawned: fires after a subagent run is successfully registered.
|
|
174
|
+
// We increment the expected completion count so that onIdle knows to wait.
|
|
175
|
+
api.on("subagent_spawned", async (_event, ctx) => {
|
|
176
|
+
const requesterSessionKey = ctx?.requesterSessionKey;
|
|
177
|
+
if (!requesterSessionKey)
|
|
178
|
+
return;
|
|
179
|
+
const count = markSubagentSpawned(requesterSessionKey);
|
|
180
|
+
if (count > 0) {
|
|
181
|
+
logger.log(`[XY-SUBAGENT] spawned, requesterSessionKey=${requesterSessionKey.slice(0, 30)}, expected=${count}`);
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
// subagent_ended: fires when a subagent run terminates (complete/error/killed).
|
|
185
|
+
// This is the PRIMARY delivery tracking mechanism. When all expected
|
|
186
|
+
// subagents have ended and parent has settled, we finalize the A2A session.
|
|
187
|
+
api.on("subagent_ended", async (event, ctx) => {
|
|
188
|
+
try {
|
|
189
|
+
const requesterSessionKey = ctx?.requesterSessionKey;
|
|
190
|
+
if (!requesterSessionKey) {
|
|
191
|
+
logger.log(`[XY-SUBAGENT-END] no requesterSessionKey in ctx`);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
const transition = markSubagentEnded(requesterSessionKey);
|
|
195
|
+
logger.log(`[XY-SUBAGENT-END] ended, targetSessionKey=${event?.targetSessionKey?.slice(0, 30)}, outcome=${event?.outcome}, complete=${transition?.isComplete ?? false}, shouldFinalize=${transition?.shouldFinalize ?? false}, transition=${!!transition}`);
|
|
196
|
+
if (transition?.shouldFinalize) {
|
|
197
|
+
logger.log(`[XY-SUBAGENT-END] Starting finalization...`);
|
|
198
|
+
const [{ resolveXYConfig }, { deliverSubagentFinalResult }, { getXYRuntime }] = await Promise.all([
|
|
199
|
+
import("./src/config.js"),
|
|
200
|
+
import("./src/outbound.js"),
|
|
201
|
+
import("./src/runtime.js"),
|
|
202
|
+
]);
|
|
203
|
+
const rt = getXYRuntime();
|
|
204
|
+
logger.log(`[XY-SUBAGENT-END] Runtime config type: ${typeof rt.config}, hasConfig=${!!rt.config}`);
|
|
205
|
+
const cfg = rt.config;
|
|
206
|
+
const config = resolveXYConfig(cfg);
|
|
207
|
+
logger.log(`[XY-SUBAGENT-END] XY config resolved, wsUrl=${config.wsUrl?.slice(0, 20)}`);
|
|
208
|
+
await deliverSubagentFinalResult({
|
|
209
|
+
config,
|
|
210
|
+
state: transition.state,
|
|
211
|
+
reason: "all-subagents-ended-after-parent-settled",
|
|
212
|
+
});
|
|
213
|
+
logger.log(`[XY-SUBAGENT-END] Finalized A2A session after all subagents ended`);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
catch (err) {
|
|
217
|
+
logger.error(`[XY-SUBAGENT-END] Error in subagent_ended hook:`, err);
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
}
|
|
170
221
|
function registerFullHooks(api) {
|
|
222
|
+
// SUBAGENT HOOKS: track subagent spawn/end lifecycle for session keep-alive
|
|
223
|
+
registerSubagentHooks(api);
|
|
171
224
|
// SKILL RETRIEVER HOOK: before_prompt_build hook
|
|
172
225
|
const pluginConfig = api.pluginConfig || {};
|
|
173
226
|
const skillRetrieverConfig = normalizeToolRetrieverConfig({
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type BindingTargetKind } from "openclaw/plugin-sdk/conversation-runtime";
|
|
2
|
+
type XyBindingTargetKind = "subagent" | "acp";
|
|
3
|
+
type XyAcpBindingRecord = {
|
|
4
|
+
accountId: string;
|
|
5
|
+
conversationId: string;
|
|
6
|
+
parentConversationId?: string;
|
|
7
|
+
deliveryTo?: string;
|
|
8
|
+
targetKind: XyBindingTargetKind;
|
|
9
|
+
targetSessionKey: string;
|
|
10
|
+
agentId?: string;
|
|
11
|
+
label?: string;
|
|
12
|
+
boundBy?: string;
|
|
13
|
+
boundAt: number;
|
|
14
|
+
lastActivityAt: number;
|
|
15
|
+
};
|
|
16
|
+
type XyAcpBindingManager = {
|
|
17
|
+
accountId: string;
|
|
18
|
+
getByConversationId: (conversationId: string) => XyAcpBindingRecord | undefined;
|
|
19
|
+
listBySessionKey: (targetSessionKey: string) => XyAcpBindingRecord[];
|
|
20
|
+
bindConversation: (params: {
|
|
21
|
+
conversationId: string;
|
|
22
|
+
parentConversationId?: string;
|
|
23
|
+
targetKind: BindingTargetKind;
|
|
24
|
+
targetSessionKey: string;
|
|
25
|
+
metadata?: Record<string, unknown>;
|
|
26
|
+
}) => XyAcpBindingRecord | null;
|
|
27
|
+
touchConversation: (conversationId: string, at?: number) => XyAcpBindingRecord | null;
|
|
28
|
+
unbindConversation: (conversationId: string) => XyAcpBindingRecord | null;
|
|
29
|
+
unbindBySessionKey: (targetSessionKey: string) => XyAcpBindingRecord[];
|
|
30
|
+
stop: () => void;
|
|
31
|
+
};
|
|
32
|
+
export declare function createXyAcpBindingManager(params: {
|
|
33
|
+
accountId?: string;
|
|
34
|
+
cfg: any;
|
|
35
|
+
}): XyAcpBindingManager;
|
|
36
|
+
export declare function getXyAcpBindingManager(accountId?: string): XyAcpBindingManager | null;
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
// ACP Session Binding Adapter for xiaoyi-channel.
|
|
2
|
+
// Follows the feishu thread-bindings.ts pattern.
|
|
3
|
+
//
|
|
4
|
+
// Maps A2A sessionId (stable conversation identifier) to ACP/subagent
|
|
5
|
+
// session keys so that openclaw can bind spawned sessions to the
|
|
6
|
+
// current xiaoyi conversation.
|
|
7
|
+
//
|
|
8
|
+
// Key design: xiaoyi-channel only supports `placement: "current"` —
|
|
9
|
+
// it cannot create child threads (unlike Discord). All spawned sessions
|
|
10
|
+
// are bound to the current A2A conversation identified by sessionId.
|
|
11
|
+
// NOTE: Using `any` for cfg type to avoid version mismatch between
|
|
12
|
+
// local and global openclaw installs (auth.profiles.aws-sdk union).
|
|
13
|
+
import { resolveThreadBindingIdleTimeoutMsForChannel, resolveThreadBindingMaxAgeMsForChannel, resolveThreadBindingConversationIdFromBindingId, registerSessionBindingAdapter, unregisterSessionBindingAdapter, } from "openclaw/plugin-sdk/conversation-runtime";
|
|
14
|
+
import { normalizeAccountId, resolveAgentIdFromSessionKey } from "openclaw/plugin-sdk/routing";
|
|
15
|
+
import { normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
16
|
+
import { logger } from "./utils/logger.js";
|
|
17
|
+
// ─── Global state (survives module dedup) ─────────────────────
|
|
18
|
+
const XY_ACP_BINDINGS_KEY = Symbol.for("openclaw.xyAcpBindingsState");
|
|
19
|
+
let state;
|
|
20
|
+
function getState() {
|
|
21
|
+
if (!state) {
|
|
22
|
+
const globalStore = globalThis;
|
|
23
|
+
state = globalStore[XY_ACP_BINDINGS_KEY] ?? {
|
|
24
|
+
managersByAccountId: new Map(),
|
|
25
|
+
bindingsByAccountConversation: new Map(),
|
|
26
|
+
};
|
|
27
|
+
globalStore[XY_ACP_BINDINGS_KEY] = state;
|
|
28
|
+
}
|
|
29
|
+
return state;
|
|
30
|
+
}
|
|
31
|
+
function resolveBindingKey(params) {
|
|
32
|
+
return `${params.accountId}:${params.conversationId}`;
|
|
33
|
+
}
|
|
34
|
+
// ─── Kind conversion ──────────────────────────────────────────
|
|
35
|
+
function toSessionBindingTargetKind(raw) {
|
|
36
|
+
return raw === "subagent" ? "subagent" : "session";
|
|
37
|
+
}
|
|
38
|
+
function toXyTargetKind(raw) {
|
|
39
|
+
return raw === "subagent" ? "subagent" : "acp";
|
|
40
|
+
}
|
|
41
|
+
// ─── Record conversion ────────────────────────────────────────
|
|
42
|
+
function toSessionBindingRecord(record, defaults) {
|
|
43
|
+
const idleExpiresAt = defaults.idleTimeoutMs > 0 ? record.lastActivityAt + defaults.idleTimeoutMs : undefined;
|
|
44
|
+
const maxAgeExpiresAt = defaults.maxAgeMs > 0 ? record.boundAt + defaults.maxAgeMs : undefined;
|
|
45
|
+
const expiresAt = idleExpiresAt != null && maxAgeExpiresAt != null
|
|
46
|
+
? Math.min(idleExpiresAt, maxAgeExpiresAt)
|
|
47
|
+
: (idleExpiresAt ?? maxAgeExpiresAt);
|
|
48
|
+
return {
|
|
49
|
+
bindingId: resolveBindingKey({
|
|
50
|
+
accountId: record.accountId,
|
|
51
|
+
conversationId: record.conversationId,
|
|
52
|
+
}),
|
|
53
|
+
targetSessionKey: record.targetSessionKey,
|
|
54
|
+
targetKind: toSessionBindingTargetKind(record.targetKind),
|
|
55
|
+
conversation: {
|
|
56
|
+
channel: "xiaoyi-channel",
|
|
57
|
+
accountId: record.accountId,
|
|
58
|
+
conversationId: record.conversationId,
|
|
59
|
+
parentConversationId: record.parentConversationId,
|
|
60
|
+
},
|
|
61
|
+
status: "active",
|
|
62
|
+
boundAt: record.boundAt,
|
|
63
|
+
expiresAt,
|
|
64
|
+
metadata: {
|
|
65
|
+
agentId: record.agentId,
|
|
66
|
+
label: record.label,
|
|
67
|
+
boundBy: record.boundBy,
|
|
68
|
+
deliveryTo: record.deliveryTo,
|
|
69
|
+
lastActivityAt: record.lastActivityAt,
|
|
70
|
+
idleTimeoutMs: defaults.idleTimeoutMs,
|
|
71
|
+
maxAgeMs: defaults.maxAgeMs,
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
// ─── Manager factory ──────────────────────────────────────────
|
|
76
|
+
export function createXyAcpBindingManager(params) {
|
|
77
|
+
const accountId = normalizeAccountId(params.accountId);
|
|
78
|
+
const existing = getState().managersByAccountId.get(accountId);
|
|
79
|
+
if (existing) {
|
|
80
|
+
return existing;
|
|
81
|
+
}
|
|
82
|
+
const idleTimeoutMs = resolveThreadBindingIdleTimeoutMsForChannel({
|
|
83
|
+
cfg: params.cfg,
|
|
84
|
+
channel: "xiaoyi-channel",
|
|
85
|
+
accountId,
|
|
86
|
+
});
|
|
87
|
+
const maxAgeMs = resolveThreadBindingMaxAgeMsForChannel({
|
|
88
|
+
cfg: params.cfg,
|
|
89
|
+
channel: "xiaoyi-channel",
|
|
90
|
+
accountId,
|
|
91
|
+
});
|
|
92
|
+
const log = logger.withContext("", "");
|
|
93
|
+
const manager = {
|
|
94
|
+
accountId,
|
|
95
|
+
getByConversationId: (conversationId) => getState().bindingsByAccountConversation.get(resolveBindingKey({ accountId, conversationId })),
|
|
96
|
+
listBySessionKey: (targetSessionKey) => [...getState().bindingsByAccountConversation.values()].filter((record) => record.accountId === accountId && record.targetSessionKey === targetSessionKey),
|
|
97
|
+
bindConversation: ({ conversationId, parentConversationId, targetKind, targetSessionKey, metadata, }) => {
|
|
98
|
+
const normalizedConversationId = conversationId.trim();
|
|
99
|
+
const normalizedTargetSessionKey = targetSessionKey.trim();
|
|
100
|
+
if (!normalizedConversationId || !normalizedTargetSessionKey) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
const existingLocal = getState().bindingsByAccountConversation.get(resolveBindingKey({ accountId, conversationId: normalizedConversationId }));
|
|
104
|
+
const now = Date.now();
|
|
105
|
+
const record = {
|
|
106
|
+
accountId,
|
|
107
|
+
conversationId: normalizedConversationId,
|
|
108
|
+
parentConversationId: normalizeOptionalString(parentConversationId) ?? existingLocal?.parentConversationId,
|
|
109
|
+
deliveryTo: typeof metadata?.deliveryTo === "string" && metadata.deliveryTo.trim()
|
|
110
|
+
? metadata.deliveryTo.trim()
|
|
111
|
+
: existingLocal?.deliveryTo,
|
|
112
|
+
targetKind: toXyTargetKind(targetKind),
|
|
113
|
+
targetSessionKey: normalizedTargetSessionKey,
|
|
114
|
+
agentId: typeof metadata?.agentId === "string" && metadata.agentId.trim()
|
|
115
|
+
? metadata.agentId.trim()
|
|
116
|
+
: (existingLocal?.agentId ?? resolveAgentIdFromSessionKey(normalizedTargetSessionKey)),
|
|
117
|
+
label: typeof metadata?.label === "string" && metadata.label.trim()
|
|
118
|
+
? metadata.label.trim()
|
|
119
|
+
: existingLocal?.label,
|
|
120
|
+
boundBy: typeof metadata?.boundBy === "string" && metadata.boundBy.trim()
|
|
121
|
+
? metadata.boundBy.trim()
|
|
122
|
+
: existingLocal?.boundBy,
|
|
123
|
+
boundAt: now,
|
|
124
|
+
lastActivityAt: now,
|
|
125
|
+
};
|
|
126
|
+
getState().bindingsByAccountConversation.set(resolveBindingKey({ accountId, conversationId: normalizedConversationId }), record);
|
|
127
|
+
log.log(`[XY-ACP-BIND] Bound ${targetKind} session ${normalizedTargetSessionKey.slice(0, 30)} to conversation ${normalizedConversationId.slice(0, 12)}`);
|
|
128
|
+
return record;
|
|
129
|
+
},
|
|
130
|
+
touchConversation: (conversationId, at = Date.now()) => {
|
|
131
|
+
const key = resolveBindingKey({ accountId, conversationId });
|
|
132
|
+
const existingRecord = getState().bindingsByAccountConversation.get(key);
|
|
133
|
+
if (!existingRecord) {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
const updated = { ...existingRecord, lastActivityAt: at };
|
|
137
|
+
getState().bindingsByAccountConversation.set(key, updated);
|
|
138
|
+
return updated;
|
|
139
|
+
},
|
|
140
|
+
unbindConversation: (conversationId) => {
|
|
141
|
+
const key = resolveBindingKey({ accountId, conversationId });
|
|
142
|
+
const existingRecord = getState().bindingsByAccountConversation.get(key);
|
|
143
|
+
if (!existingRecord) {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
getState().bindingsByAccountConversation.delete(key);
|
|
147
|
+
return existingRecord;
|
|
148
|
+
},
|
|
149
|
+
unbindBySessionKey: (targetSessionKey) => {
|
|
150
|
+
const removed = [];
|
|
151
|
+
for (const record of getState().bindingsByAccountConversation.values()) {
|
|
152
|
+
if (record.accountId !== accountId || record.targetSessionKey !== targetSessionKey) {
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
getState().bindingsByAccountConversation.delete(resolveBindingKey({ accountId, conversationId: record.conversationId }));
|
|
156
|
+
removed.push(record);
|
|
157
|
+
}
|
|
158
|
+
return removed;
|
|
159
|
+
},
|
|
160
|
+
stop: () => {
|
|
161
|
+
for (const key of getState().bindingsByAccountConversation.keys()) {
|
|
162
|
+
if (key.startsWith(`${accountId}:`)) {
|
|
163
|
+
getState().bindingsByAccountConversation.delete(key);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
getState().managersByAccountId.delete(accountId);
|
|
167
|
+
unregisterSessionBindingAdapter({
|
|
168
|
+
channel: "xiaoyi-channel",
|
|
169
|
+
accountId,
|
|
170
|
+
adapter: sessionBindingAdapter,
|
|
171
|
+
});
|
|
172
|
+
log.log(`[XY-ACP-BIND] Stopped binding manager for account ${accountId}`);
|
|
173
|
+
},
|
|
174
|
+
};
|
|
175
|
+
const sessionBindingAdapter = {
|
|
176
|
+
channel: "xiaoyi-channel",
|
|
177
|
+
accountId,
|
|
178
|
+
capabilities: {
|
|
179
|
+
placements: ["current"],
|
|
180
|
+
},
|
|
181
|
+
bind: async (input) => {
|
|
182
|
+
if (input.conversation.channel !== "xiaoyi-channel" || input.placement === "child") {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
const bound = manager.bindConversation({
|
|
186
|
+
conversationId: input.conversation.conversationId,
|
|
187
|
+
parentConversationId: input.conversation.parentConversationId,
|
|
188
|
+
targetKind: input.targetKind,
|
|
189
|
+
targetSessionKey: input.targetSessionKey,
|
|
190
|
+
metadata: input.metadata,
|
|
191
|
+
});
|
|
192
|
+
return bound ? toSessionBindingRecord(bound, { idleTimeoutMs, maxAgeMs }) : null;
|
|
193
|
+
},
|
|
194
|
+
listBySession: (targetSessionKey) => manager
|
|
195
|
+
.listBySessionKey(targetSessionKey)
|
|
196
|
+
.map((entry) => toSessionBindingRecord(entry, { idleTimeoutMs, maxAgeMs })),
|
|
197
|
+
resolveByConversation: (ref) => {
|
|
198
|
+
if (ref.channel !== "xiaoyi-channel") {
|
|
199
|
+
return null;
|
|
200
|
+
}
|
|
201
|
+
const found = manager.getByConversationId(ref.conversationId);
|
|
202
|
+
return found ? toSessionBindingRecord(found, { idleTimeoutMs, maxAgeMs }) : null;
|
|
203
|
+
},
|
|
204
|
+
touch: (bindingId, at) => {
|
|
205
|
+
const conversationId = resolveThreadBindingConversationIdFromBindingId({
|
|
206
|
+
accountId,
|
|
207
|
+
bindingId,
|
|
208
|
+
});
|
|
209
|
+
if (conversationId) {
|
|
210
|
+
manager.touchConversation(conversationId, at);
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
unbind: async (input) => {
|
|
214
|
+
if (input.targetSessionKey?.trim()) {
|
|
215
|
+
return manager
|
|
216
|
+
.unbindBySessionKey(input.targetSessionKey.trim())
|
|
217
|
+
.map((entry) => toSessionBindingRecord(entry, { idleTimeoutMs, maxAgeMs }));
|
|
218
|
+
}
|
|
219
|
+
const conversationId = resolveThreadBindingConversationIdFromBindingId({
|
|
220
|
+
accountId,
|
|
221
|
+
bindingId: input.bindingId,
|
|
222
|
+
});
|
|
223
|
+
if (!conversationId) {
|
|
224
|
+
return [];
|
|
225
|
+
}
|
|
226
|
+
const removed = manager.unbindConversation(conversationId);
|
|
227
|
+
return removed ? [toSessionBindingRecord(removed, { idleTimeoutMs, maxAgeMs })] : [];
|
|
228
|
+
},
|
|
229
|
+
};
|
|
230
|
+
registerSessionBindingAdapter(sessionBindingAdapter);
|
|
231
|
+
getState().managersByAccountId.set(accountId, manager);
|
|
232
|
+
log.log(`[XY-ACP-BIND] Created binding manager for account ${accountId} (idleTimeout=${idleTimeoutMs}ms, maxAge=${maxAgeMs}ms)`);
|
|
233
|
+
return manager;
|
|
234
|
+
}
|
|
235
|
+
export function getXyAcpBindingManager(accountId) {
|
|
236
|
+
return getState().managersByAccountId.get(normalizeAccountId(accountId)) ?? null;
|
|
237
|
+
}
|
package/dist/src/bot.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
import { resolveRuntimeConversationBindingRoute } from "openclaw/plugin-sdk/conversation-runtime";
|
|
1
2
|
import { updateSessionStoreEntry, updateSessionStore, resolveStorePath } from "openclaw/plugin-sdk/session-store-runtime";
|
|
2
3
|
import { getXYRuntime } from "./runtime.js";
|
|
3
4
|
import { createXYReplyDispatcher } from "./reply-dispatcher.js";
|
|
4
|
-
import { parseA2AMessage, extractTextFromParts, extractFileParts, extractPushId, extractDeviceType, extractModelName, extractTriggerData, extractRunCrossTaskContext } from "./parser.js";
|
|
5
|
+
import { parseA2AMessage, extractTextFromParts, extractFileParts, extractPushId, extractDeviceType, extractAppVer, extractSdkApiVersion, extractModelName, extractTriggerData, extractRunCrossTaskContext } from "./parser.js";
|
|
5
6
|
import { downloadFilesFromParts } from "./file-download.js";
|
|
6
7
|
import { resolveXYConfig } from "./config.js";
|
|
7
8
|
import { sendStatusUpdate, sendClearContextResponse, sendTasksCancelResponse, sendA2AResponse } from "./formatter.js";
|
|
8
9
|
import { appendSelfEvolutionKeywordNudge, shouldNudgeForSelfEvolutionKeyword, } from "./self-evolution-keyword.js";
|
|
9
|
-
import {
|
|
10
|
+
import { runWithSessionContext } from "./tools/session-manager.js";
|
|
10
11
|
import { configManager } from "./utils/config-manager.js";
|
|
11
12
|
import { addPushId } from "./utils/pushid-manager.js";
|
|
12
13
|
import { getPushDataById } from "./utils/pushdata-manager.js";
|
|
@@ -15,6 +16,7 @@ import { saveRuntimeInfo } from "./utils/runtime-manager.js";
|
|
|
15
16
|
import { toolCallNudgeManager } from "./utils/tool-call-nudge-manager.js";
|
|
16
17
|
import { setCsplSteerContext } from "./cspl/steer-context.js";
|
|
17
18
|
import { registerTaskId, decrementTaskIdRef, hasActiveTask, } from "./task-manager.js";
|
|
19
|
+
import { registerSessionKeyMapping, getWaitState, hasWaitState, markParentSettled, } from "./subagent-wait-state.js";
|
|
18
20
|
import { logger } from "./utils/logger.js";
|
|
19
21
|
/**
|
|
20
22
|
* Handle an incoming A2A message.
|
|
@@ -113,6 +115,13 @@ export async function handleXYMessage(params) {
|
|
|
113
115
|
// Steer injections skip taskId registration to avoid overwriting the active taskId
|
|
114
116
|
if (!skipReg) {
|
|
115
117
|
registerTaskId(parsed.sessionId, parsed.taskId, parsed.messageId);
|
|
118
|
+
// 🔑 steer 场景:同步更新活跃 dispatcher 的 fallback taskId/messageId
|
|
119
|
+
if (isUpdate) {
|
|
120
|
+
const updater = dispatcherUpdaters.get(parsed.sessionId);
|
|
121
|
+
if (updater) {
|
|
122
|
+
updater(parsed.taskId, parsed.messageId);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
116
125
|
// Extract and update push_id if present
|
|
117
126
|
const pushId = extractPushId(parsed.parts);
|
|
118
127
|
if (pushId) {
|
|
@@ -139,6 +148,15 @@ export async function handleXYMessage(params) {
|
|
|
139
148
|
if (deviceType) {
|
|
140
149
|
log.log(`[BOT] Extracted deviceType: ${deviceType}`);
|
|
141
150
|
}
|
|
151
|
+
// Extract app_ver and sdk_api_version if present
|
|
152
|
+
const appVer = extractAppVer(parsed.parts);
|
|
153
|
+
if (appVer) {
|
|
154
|
+
log.log(`[BOT] Extracted app_ver: ${appVer}`);
|
|
155
|
+
}
|
|
156
|
+
const sdkApiVersion = extractSdkApiVersion(parsed.parts);
|
|
157
|
+
if (sdkApiVersion) {
|
|
158
|
+
log.log(`[BOT] Extracted sdk_api_version: ${sdkApiVersion}`);
|
|
159
|
+
}
|
|
142
160
|
// Extract modelName if present (used by provider.ts to override model.id)
|
|
143
161
|
const modelName = extractModelName(parsed.parts);
|
|
144
162
|
if (modelName) {
|
|
@@ -160,19 +178,28 @@ export async function handleXYMessage(params) {
|
|
|
160
178
|
},
|
|
161
179
|
});
|
|
162
180
|
log.log(`[BOT] Resolved route, sessionKey=${route.sessionKey}`);
|
|
163
|
-
//
|
|
181
|
+
// Register sessionKey→A2A sessionId mapping for subagent hook translation.
|
|
182
|
+
// Hooks receive openclaw sessionKey (e.g. "agent:main:direct:xxx") but
|
|
183
|
+
// xy_channel operates on A2A sessionId. This bridge lets subagent_spawned/
|
|
184
|
+
// subagent_ended hooks find the correct wait state.
|
|
185
|
+
registerSessionKeyMapping(route.sessionKey, parsed.sessionId, parsed.taskId, parsed.messageId);
|
|
186
|
+
// Check for ACP runtime binding on this A2A conversation
|
|
187
|
+
const runtimeRoute = resolveRuntimeConversationBindingRoute({
|
|
188
|
+
route,
|
|
189
|
+
channel: "xiaoyi-channel",
|
|
190
|
+
accountId,
|
|
191
|
+
conversationId: parsed.sessionId,
|
|
192
|
+
});
|
|
193
|
+
route = runtimeRoute.route;
|
|
194
|
+
if (runtimeRoute.bindingRecord) {
|
|
195
|
+
log.log(runtimeRoute.boundSessionKey
|
|
196
|
+
? `[BOT] routed via bound conversation ${parsed.sessionId} -> ${runtimeRoute.boundSessionKey}`
|
|
197
|
+
: `[BOT] plugin-bound conversation ${parsed.sessionId}`);
|
|
198
|
+
}
|
|
199
|
+
// ALS only: no registerSession. The sessionContext built below is handed
|
|
200
|
+
// to runWithSessionContext() inside withReplyDispatcher.run, which is the
|
|
201
|
+
// single wrap point for the whole agent turn.
|
|
164
202
|
if (!skipReg) {
|
|
165
|
-
registerSession(route.sessionKey, {
|
|
166
|
-
config,
|
|
167
|
-
sessionId: parsed.sessionId,
|
|
168
|
-
distributionSessionId,
|
|
169
|
-
taskId: parsed.taskId,
|
|
170
|
-
messageId: parsed.messageId,
|
|
171
|
-
agentId: route.accountId,
|
|
172
|
-
deviceType,
|
|
173
|
-
modelName,
|
|
174
|
-
runCrossTaskContext: runCrossTaskContext ?? undefined,
|
|
175
|
-
});
|
|
176
203
|
// 🔑 Sync A2A modelName to OpenClaw session store so that session_status
|
|
177
204
|
// reports the correct model. Without this, session_status returns the
|
|
178
205
|
// configured default model instead of the A2A-specified one.
|
|
@@ -343,7 +370,28 @@ export async function handleXYMessage(params) {
|
|
|
343
370
|
const steerState = { steered: false };
|
|
344
371
|
// 🔑 创建dispatcher
|
|
345
372
|
log.log(`[BOT-DISPATCHER] Creating reply dispatcher`);
|
|
346
|
-
|
|
373
|
+
// Cleanup: 必须在 onIdle 内部执行(参见 reply-dispatcher.ts 中 onIdleComplete 的注释)
|
|
374
|
+
let cleaned = false;
|
|
375
|
+
const cleanup = () => {
|
|
376
|
+
if (cleaned)
|
|
377
|
+
return;
|
|
378
|
+
// Check for pending subagent wait on this session (any taskId).
|
|
379
|
+
// Steer dispatches have a different taskId, so we check both
|
|
380
|
+
// exact match and session-wide presence.
|
|
381
|
+
const pendingWait = getWaitState(parsed.sessionId, parsed.taskId) ??
|
|
382
|
+
(hasWaitState(parsed.sessionId) ? { deliveredCompletions: 0, expectedCompletions: 1 } : null);
|
|
383
|
+
if (pendingWait && pendingWait.deliveredCompletions < pendingWait.expectedCompletions) {
|
|
384
|
+
// Subagent wait active — skip cleanup, session stays alive
|
|
385
|
+
log.log(`[BOT] Cleanup suppressed — subagent wait active on session, taskId=${parsed.taskId}`);
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
cleaned = true;
|
|
389
|
+
log.log(`[BOT] Cleanup started`);
|
|
390
|
+
streamingSignals.delete(parsed.sessionId);
|
|
391
|
+
decrementTaskIdRef(parsed.sessionId);
|
|
392
|
+
log.log(`[BOT] Cleanup completed`);
|
|
393
|
+
};
|
|
394
|
+
const { dispatcher, replyOptions, markDispatchIdle, startStatusInterval, updateFallbackTaskId } = createXYReplyDispatcher({
|
|
347
395
|
cfg,
|
|
348
396
|
runtime,
|
|
349
397
|
sessionId: parsed.sessionId,
|
|
@@ -351,7 +399,10 @@ export async function handleXYMessage(params) {
|
|
|
351
399
|
messageId: parsed.messageId,
|
|
352
400
|
accountId: route.accountId,
|
|
353
401
|
steerState,
|
|
402
|
+
onIdleComplete: cleanup,
|
|
354
403
|
});
|
|
404
|
+
// 🔑 注册 dispatcher 的 fallback taskId 更新函数,供 steer 路径调用
|
|
405
|
+
dispatcherUpdaters.set(parsed.sessionId, updateFallbackTaskId);
|
|
355
406
|
// Steer injections don't need status intervals
|
|
356
407
|
if (!skipReg) {
|
|
357
408
|
startStatusInterval();
|
|
@@ -365,23 +416,46 @@ export async function handleXYMessage(params) {
|
|
|
365
416
|
messageId: parsed.messageId,
|
|
366
417
|
agentId: route.accountId,
|
|
367
418
|
deviceType,
|
|
419
|
+
appVer: appVer ?? undefined,
|
|
420
|
+
sdkApiVersion: sdkApiVersion ?? undefined,
|
|
368
421
|
modelName,
|
|
369
422
|
runCrossTaskContext: runCrossTaskContext ?? undefined,
|
|
370
423
|
};
|
|
371
424
|
log.log(`[BOT-DISPATCH] withReplyDispatcher starting, sessionKey=${route.sessionKey}`);
|
|
372
425
|
await core.channel.reply.withReplyDispatcher({
|
|
373
426
|
dispatcher,
|
|
374
|
-
onSettled: () => {
|
|
427
|
+
onSettled: async () => {
|
|
375
428
|
log.log(`[BOT] onSettled, steered=${steerState.steered}`);
|
|
376
|
-
// 🔑 When steered, skip
|
|
429
|
+
// 🔑 When steered, skip cleanup — the first message's dispatcher is still running
|
|
377
430
|
if (steerState.steered) {
|
|
378
431
|
log.log(`[BOT] Steered dispatch settled, skipping cleanup`);
|
|
379
432
|
return;
|
|
380
433
|
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
434
|
+
// Subagent wait state: if parent has pending subagents, mark settled
|
|
435
|
+
// and defer finalization. Cleanup is suppressed so the session stays alive.
|
|
436
|
+
const pendingWait = getWaitState(parsed.sessionId, parsed.taskId);
|
|
437
|
+
if (pendingWait && !pendingWait.parentSettled) {
|
|
438
|
+
const transition = markParentSettled(parsed.sessionId, parsed.taskId);
|
|
439
|
+
if (transition?.shouldFinalize) {
|
|
440
|
+
// All completions arrived before parent settled → finalize now
|
|
441
|
+
const { deliverSubagentFinalResult } = await import("./outbound.js");
|
|
442
|
+
await deliverSubagentFinalResult({
|
|
443
|
+
config,
|
|
444
|
+
state: transition.state,
|
|
445
|
+
reason: "all-subagent-results-delivered-before-parent-settled",
|
|
446
|
+
});
|
|
447
|
+
streamingSignals.delete(parsed.sessionId);
|
|
448
|
+
log.log(`[BOT] Subagent wait complete on parent settled; final response delivered`);
|
|
449
|
+
}
|
|
450
|
+
else {
|
|
451
|
+
log.log(`[BOT] Subagent wait active, preserving session context for completion`);
|
|
452
|
+
}
|
|
453
|
+
dispatcherUpdaters.delete(parsed.sessionId);
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
// cleanup 已由 onIdleComplete 在 onIdle 的 finally 中执行。
|
|
457
|
+
// onSettled 不做任何清理(直接在这里清理会发生 race condition)。
|
|
458
|
+
dispatcherUpdaters.delete(parsed.sessionId);
|
|
385
459
|
},
|
|
386
460
|
run: () => {
|
|
387
461
|
// 🔐 Use AsyncLocalStorage to provide session context to tools.
|
|
@@ -390,6 +464,7 @@ export async function handleXYMessage(params) {
|
|
|
390
464
|
// signal init complete to release the global dispatch gate
|
|
391
465
|
// for the next session.
|
|
392
466
|
const dispatchPromise = runWithSessionContext(sessionContext, async () => {
|
|
467
|
+
log.log(`[ALS-PROOF] bot entered dispatch scope sessionId=${sessionContext.sessionId} taskId=${sessionContext.taskId} isSteer=false`);
|
|
393
468
|
log.log(`[BOT-DISPATCH] dispatchReplyFromConfig starting, body.length=${ctxPayload.Body?.length ?? 0}`);
|
|
394
469
|
try {
|
|
395
470
|
const result = await core.channel.reply.dispatchReplyFromConfig({
|
|
@@ -422,7 +497,7 @@ export async function handleXYMessage(params) {
|
|
|
422
497
|
errLog.error("Failed to handle XY message:", err);
|
|
423
498
|
runtime.error?.(`xy: Failed to handle message: ${String(err)}`);
|
|
424
499
|
errLog.log(`[BOT] Error occurred, attempting cleanup`);
|
|
425
|
-
// 🔑 错误时也要清理taskId
|
|
500
|
+
// 🔑 错误时也要清理taskId(session 走 ALS,作用域退出自动清理)
|
|
426
501
|
try {
|
|
427
502
|
const params = message.params;
|
|
428
503
|
const sessionId = params?.sessionId;
|
|
@@ -430,18 +505,6 @@ export async function handleXYMessage(params) {
|
|
|
430
505
|
errLog.log(`[BOT] Cleaning up after error`);
|
|
431
506
|
// 清理 taskId
|
|
432
507
|
decrementTaskIdRef(sessionId);
|
|
433
|
-
// 清理 session
|
|
434
|
-
const core = getXYRuntime();
|
|
435
|
-
const route = core.channel.routing.resolveAgentRoute({
|
|
436
|
-
cfg,
|
|
437
|
-
channel: "xiaoyi-channel",
|
|
438
|
-
accountId,
|
|
439
|
-
peer: {
|
|
440
|
-
kind: "direct",
|
|
441
|
-
id: sessionId,
|
|
442
|
-
},
|
|
443
|
-
});
|
|
444
|
-
unregisterSession(route.sessionKey);
|
|
445
508
|
errLog.log(`[BOT] Cleanup completed after error`);
|
|
446
509
|
}
|
|
447
510
|
}
|
|
@@ -476,8 +539,11 @@ if (!_g.__xyStreamingSignals)
|
|
|
476
539
|
_g.__xyStreamingSignals = new Map();
|
|
477
540
|
if (!_g.__xySteerQueues)
|
|
478
541
|
_g.__xySteerQueues = new Map();
|
|
542
|
+
if (!_g.__xyDispatcherUpdaters)
|
|
543
|
+
_g.__xyDispatcherUpdaters = new Map();
|
|
479
544
|
const streamingSignals = _g.__xyStreamingSignals;
|
|
480
545
|
const steerQueues = _g.__xySteerQueues;
|
|
546
|
+
const dispatcherUpdaters = _g.__xyDispatcherUpdaters;
|
|
481
547
|
/**
|
|
482
548
|
* 由 provider.ts 在 wrapStreamFn 调用时触发。
|
|
483
549
|
* 这是模型 API 被调用的精确时刻,此时 isStreaming 一定为 true。
|
|
@@ -626,6 +692,7 @@ async function dispatchSteerWhenReady(params) {
|
|
|
626
692
|
},
|
|
627
693
|
run: () => {
|
|
628
694
|
return runWithSessionContext(sessionContext, async () => {
|
|
695
|
+
log.log(`[ALS-PROOF] bot entered steer dispatch scope sessionId=${sessionContext.sessionId} taskId=${sessionContext.taskId} isSteer=true`);
|
|
629
696
|
const result = await core.channel.reply.dispatchReplyFromConfig({
|
|
630
697
|
ctx: ctxPayload,
|
|
631
698
|
cfg: params.cfg,
|