@honor-claw/yoyo 2026.6.9-alpha.2 → 2026.6.9-alpha.3
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/cloud-channel/transport/cloud-socket.mjs +2 -2
- package/dist/core/hooks/skill-refresh.mjs +9 -10
- package/dist/core/hooks/tool-trace.mjs +22 -44
- package/dist/core/prompt/skill.mjs +6 -7
- package/dist/core/runtime.mjs +5 -1
- package/dist/messaging/dispatchers/command/impl.mjs +53 -0
- package/dist/messaging/dispatchers/command/index.mjs +1 -0
- package/dist/messaging/dispatchers/stream/controller.mjs +138 -0
- package/dist/messaging/{stream → dispatchers/stream}/error.mjs +1 -1
- package/dist/messaging/dispatchers/stream/factory.mjs +17 -0
- package/dist/messaging/dispatchers/stream/hooks.mjs +54 -0
- package/dist/messaging/dispatchers/stream/index.mjs +4 -0
- package/dist/messaging/dispatchers/stream/registry.mjs +13 -0
- package/dist/messaging/{stream → dispatchers/stream}/resolvers.mjs +1 -1
- package/dist/messaging/{stream → dispatchers/stream}/session.mjs +15 -11
- package/dist/messaging/dispatchers/stream/tool/error.mjs +26 -0
- package/dist/messaging/dispatchers/stream/tool/event-builder.mjs +18 -0
- package/dist/messaging/{stream → dispatchers/stream}/tool/index.mjs +2 -2
- package/dist/messaging/{stream → dispatchers/stream}/tool/sanitize.mjs +1 -1
- package/dist/messaging/{stream → dispatchers/stream}/tool/trace-store.mjs +16 -61
- package/dist/messaging/inbound/agent.mjs +5 -4
- package/dist/messaging/inbound/command.mjs +38 -0
- package/dist/messaging/inbound/context.mjs +2 -0
- package/dist/messaging/inbound/dispatch.mjs +25 -15
- package/dist/messaging/index.mjs +1 -0
- package/dist/messaging/send/text.mjs +1 -0
- package/dist/messaging/session/defaults.mjs +41 -0
- package/dist/messaging/session/index.mjs +1 -0
- package/dist/messaging/target/chat-id.mjs +36 -14
- package/dist/messaging/target/index.mjs +3 -0
- package/dist/modules/configs/agent-defaults.mjs +25 -0
- package/dist/modules/configs/plugin-init.mjs +31 -25
- package/dist/modules/status/storage.mjs +17 -15
- package/dist/provisioning/toolset/artifacts.mjs +37 -36
- package/dist/provisioning/toolset/consts.mjs +2 -2
- package/dist/provisioning/toolset/processor.mjs +2 -2
- package/dist/provisioning/toolset/skill-refresh-marker.mjs +30 -25
- package/package.json +1 -1
- package/skills/yoyo-phone-control/SKILL.md +1 -51
- package/dist/messaging/stream/dispatcher.mjs +0 -74
- package/dist/messaging/stream/tool/callbacks.mjs +0 -36
- package/dist/messaging/stream/tool/output.mjs +0 -38
- package/dist/utils/base64-json.mjs +0 -14
|
@@ -5,7 +5,7 @@ import { emitStatusEvent as r } from "../../modules/status/global.mjs";
|
|
|
5
5
|
import { RecurringTimer as i } from "../../utils/recurring-timer.mjs";
|
|
6
6
|
import a from "ws";
|
|
7
7
|
//#region src/cloud-channel/transport/cloud-socket.ts
|
|
8
|
-
var o = e("cloud-socket"), s = 3e4, c =
|
|
8
|
+
var o = e("cloud-socket"), s = 3e4, c = 16e3, l = 1e3, u = 2, d = 999, f = class {
|
|
9
9
|
ws = null;
|
|
10
10
|
options;
|
|
11
11
|
retryCount = 0;
|
|
@@ -114,7 +114,7 @@ var o = e("cloud-socket"), s = 3e4, c = 4e3, l = 1e3, u = 2, d = 999, f = class
|
|
|
114
114
|
}), this.retryTimer.start(() => void this.connect(!0), e);
|
|
115
115
|
}
|
|
116
116
|
calculateRetryDelay() {
|
|
117
|
-
let e = l * u ** Math.min(this.retryCount,
|
|
117
|
+
let e = l * u ** Math.min(this.retryCount, 4);
|
|
118
118
|
return Math.min(e, c);
|
|
119
119
|
}
|
|
120
120
|
sendPing = () => {
|
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
import { clawLogger as e } from "../../utils/claw-logger.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import { isYoyoControlSkillReadPath as n, markYoyoControlSkillRead as r } from "../../provisioning/toolset/skill-refresh-marker.mjs";
|
|
2
|
+
import { isYoyoControlSkillReadPath as t, markYoyoControlSkillRead as n } from "../../provisioning/toolset/skill-refresh-marker.mjs";
|
|
4
3
|
//#region src/core/hooks/skill-refresh.ts
|
|
5
|
-
var
|
|
4
|
+
var r = e("skill-refresh"), i = [
|
|
6
5
|
"path",
|
|
7
6
|
"file_path",
|
|
8
7
|
"filePath",
|
|
9
8
|
"file"
|
|
10
9
|
];
|
|
11
|
-
function
|
|
12
|
-
return
|
|
10
|
+
function a(e) {
|
|
11
|
+
return i.some((n) => t(e[n]));
|
|
13
12
|
}
|
|
14
|
-
function
|
|
13
|
+
function o(e) {
|
|
15
14
|
e.on("after_tool_call", async (e) => {
|
|
16
|
-
if (!(e.toolName !== "read" || e.error || !
|
|
17
|
-
await
|
|
15
|
+
if (!(e.toolName !== "read" || e.error || !a(e.params))) try {
|
|
16
|
+
await n("after_tool_call:read_yoyo_control_skill"), r.info("yoyo-phone-control skill read marker updated");
|
|
18
17
|
} catch (e) {
|
|
19
|
-
|
|
18
|
+
r.warn("failed to update skill read marker", { error: String(e) });
|
|
20
19
|
}
|
|
21
20
|
});
|
|
22
21
|
}
|
|
23
22
|
//#endregion
|
|
24
|
-
export {
|
|
23
|
+
export { o as registerYoyoControlSkillReadHook };
|
|
@@ -1,48 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { clawLogger as t } from "../../utils/claw-logger.mjs";
|
|
3
|
-
import { sanitizeToolError as n, sanitizeTraceRecord as r, sanitizeTraceValue as i } from "../../messaging/stream/tool/sanitize.mjs";
|
|
4
|
-
import { recordToolUseEnd as a, recordToolUseStart as o } from "../../messaging/stream/tool/trace-store.mjs";
|
|
5
|
-
import "../../messaging/stream/tool/index.mjs";
|
|
1
|
+
import { recordToolCallEnd as e, recordToolCallStart as t } from "../../messaging/dispatchers/stream/hooks.mjs";
|
|
6
2
|
//#region src/core/hooks/tool-trace.ts
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
let e = i(t.result, 0, { source: "result" });
|
|
28
|
-
a({
|
|
29
|
-
sessionKey: o.sessionKey,
|
|
30
|
-
toolName: t.toolName,
|
|
31
|
-
toolParams: r(t.params, { source: "params" }),
|
|
32
|
-
toolCallId: t.toolCallId ?? o.toolCallId,
|
|
33
|
-
runId: t.runId ?? o.runId,
|
|
34
|
-
...e === void 0 ? {} : { result: e },
|
|
35
|
-
...typeof t.error == "string" ? { error: n(t.error) } : {},
|
|
36
|
-
...typeof t.durationMs == "number" ? { durationMs: t.durationMs } : {}
|
|
37
|
-
});
|
|
38
|
-
} catch (n) {
|
|
39
|
-
s.warn("failed to record tool end", {
|
|
40
|
-
toolName: t.toolName,
|
|
41
|
-
hasSessionKey: !!o.sessionKey,
|
|
42
|
-
error: e(n)
|
|
43
|
-
});
|
|
44
|
-
}
|
|
3
|
+
function n(n) {
|
|
4
|
+
n.on("before_tool_call", (e, n) => {
|
|
5
|
+
t({
|
|
6
|
+
sessionKey: n.sessionKey,
|
|
7
|
+
toolName: e.toolName,
|
|
8
|
+
params: e.params,
|
|
9
|
+
toolCallId: e.toolCallId ?? n.toolCallId,
|
|
10
|
+
runId: e.runId ?? n.runId
|
|
11
|
+
});
|
|
12
|
+
}), n.on("after_tool_call", (t, n) => {
|
|
13
|
+
e({
|
|
14
|
+
sessionKey: n.sessionKey,
|
|
15
|
+
toolName: t.toolName,
|
|
16
|
+
params: t.params,
|
|
17
|
+
toolCallId: t.toolCallId ?? n.toolCallId,
|
|
18
|
+
runId: t.runId ?? n.runId,
|
|
19
|
+
result: t.result,
|
|
20
|
+
error: typeof t.error == "string" ? t.error : void 0,
|
|
21
|
+
durationMs: typeof t.durationMs == "number" ? t.durationMs : void 0
|
|
22
|
+
});
|
|
45
23
|
});
|
|
46
24
|
}
|
|
47
25
|
//#endregion
|
|
48
|
-
export {
|
|
26
|
+
export { n as registerToolTraceHooks };
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { clawLogger as e } from "../../utils/claw-logger.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import { YOYO_CONTROL_SKILL_REFRESH_PROMPT as n, shouldRefreshYoyoControlSkillPrompt as r } from "../../provisioning/toolset/skill-refresh-marker.mjs";
|
|
2
|
+
import { YOYO_CONTROL_SKILL_REFRESH_PROMPT as t, shouldRefreshYoyoControlSkillPrompt as n } from "../../provisioning/toolset/skill-refresh-marker.mjs";
|
|
4
3
|
//#region src/core/prompt/skill.ts
|
|
5
|
-
var
|
|
6
|
-
async function
|
|
4
|
+
var r = e("skill-refresh");
|
|
5
|
+
async function i() {
|
|
7
6
|
try {
|
|
8
|
-
if (await
|
|
7
|
+
if (await n()) return { prependContext: t };
|
|
9
8
|
} catch (e) {
|
|
10
|
-
|
|
9
|
+
r.warn("failed to inspect skill marker", { error: String(e) });
|
|
11
10
|
}
|
|
12
11
|
return {};
|
|
13
12
|
}
|
|
14
13
|
//#endregion
|
|
15
|
-
export {
|
|
14
|
+
export { i as resolveSkillPromptContribution };
|
package/dist/core/runtime.mjs
CHANGED
|
@@ -8,7 +8,11 @@ function n() {
|
|
|
8
8
|
return e;
|
|
9
9
|
}
|
|
10
10
|
function r() {
|
|
11
|
+
let e = n().agent?.session;
|
|
12
|
+
return typeof e?.getSessionEntry == "function" && typeof e.patchSessionEntry == "function";
|
|
13
|
+
}
|
|
14
|
+
function i() {
|
|
11
15
|
return e;
|
|
12
16
|
}
|
|
13
17
|
//#endregion
|
|
14
|
-
export { n as getYoyoRuntime, t as setYoyoRuntime,
|
|
18
|
+
export { r as canHandleAgentSessionEntry, n as getYoyoRuntime, t as setYoyoRuntime, i as tryGetYoyoRuntime };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { toErrorMessage as e } from "../../../utils/error.mjs";
|
|
2
|
+
import { clawLogger as t } from "../../../utils/claw-logger.mjs";
|
|
3
|
+
import { classifyAndFormatModelError as n } from "../stream/error.mjs";
|
|
4
|
+
import { createStreamSession as r, finishStreamSession as i, pushFinalVisibleText as a, pushStreamDelta as o } from "../stream/session.mjs";
|
|
5
|
+
//#region src/messaging/dispatchers/command/impl.ts
|
|
6
|
+
var s = t("command/dispatcher");
|
|
7
|
+
function c(t) {
|
|
8
|
+
let c = r(t);
|
|
9
|
+
return {
|
|
10
|
+
dispatcherOptions: {
|
|
11
|
+
deliver: async (e, t) => {
|
|
12
|
+
let r = n(e);
|
|
13
|
+
if (r) {
|
|
14
|
+
s.warn("model api error", {
|
|
15
|
+
sender: c.target.deviceId,
|
|
16
|
+
turnId: c.turnId,
|
|
17
|
+
kind: r.kind,
|
|
18
|
+
rawTextLength: r.rawText.length
|
|
19
|
+
}), await o(c, r.userMessage);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
let i = e.text ?? "";
|
|
23
|
+
if (await o(c, i), t.kind === "final") {
|
|
24
|
+
await a(c, i);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
c.hasPushedAnswerText || await a(c, i);
|
|
28
|
+
},
|
|
29
|
+
onSkip: (e, t) => {
|
|
30
|
+
t.reason !== "silent" && s.debug("command reply skipped", {
|
|
31
|
+
sender: c.target.deviceId,
|
|
32
|
+
turnId: c.turnId,
|
|
33
|
+
reason: t.reason
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
onError: (t, n) => {
|
|
37
|
+
s.warn("command reply dispatcher error", {
|
|
38
|
+
sender: c.target.deviceId,
|
|
39
|
+
turnId: c.turnId,
|
|
40
|
+
kind: n.kind,
|
|
41
|
+
error: e(t)
|
|
42
|
+
});
|
|
43
|
+
},
|
|
44
|
+
onIdle: async () => {
|
|
45
|
+
await i(c);
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
replyOptions: { abortSignal: c.abortController.signal },
|
|
49
|
+
session: c
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
//#endregion
|
|
53
|
+
export { c as createCommandDispatcher };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./impl.mjs";
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { clawLogger as e } from "../../../utils/claw-logger.mjs";
|
|
2
|
+
import { classifyAndFormatModelError as t } from "./error.mjs";
|
|
3
|
+
import { resolveAnswerPartialDelta as n, resolveThinkingDelta as r } from "./resolvers.mjs";
|
|
4
|
+
import { getToolUseTraceSteps as i } from "./tool/trace-store.mjs";
|
|
5
|
+
import { finishStreamSession as a, finishThinking as o, pushFinalVisibleText as s, pushStreamDelta as c, pushThinkingDelta as l, pushToolEvent as u, resetAnswerSnapshot as d } from "./session.mjs";
|
|
6
|
+
import { buildToolResultEvent as f, buildToolStartEvent as p } from "./tool/event-builder.mjs";
|
|
7
|
+
import "./tool/index.mjs";
|
|
8
|
+
//#region src/messaging/dispatchers/stream/controller.ts
|
|
9
|
+
var m = e("stream/controller");
|
|
10
|
+
function h(e, t) {
|
|
11
|
+
return e ?? `no-id:${t}`;
|
|
12
|
+
}
|
|
13
|
+
var g = class {
|
|
14
|
+
session;
|
|
15
|
+
includeThinking;
|
|
16
|
+
includeToolCalls;
|
|
17
|
+
emittedToolStartKeys = /* @__PURE__ */ new Set();
|
|
18
|
+
pendingToolKeys = /* @__PURE__ */ new Set();
|
|
19
|
+
pendingReplyPayloads = [];
|
|
20
|
+
constructor(e) {
|
|
21
|
+
this.session = e.session, this.includeThinking = e.streamOptions?.includeThinking !== !1, this.includeToolCalls = e.streamOptions?.includeToolCalls !== !1;
|
|
22
|
+
}
|
|
23
|
+
get sessionKey() {
|
|
24
|
+
return this.session.sessionKey;
|
|
25
|
+
}
|
|
26
|
+
emitToolStart(e) {
|
|
27
|
+
if (!this.includeToolCalls || !e.name) return;
|
|
28
|
+
let t = h(e.toolCallId, e.name);
|
|
29
|
+
this.emittedToolStartKeys.has(t) || (this.emittedToolStartKeys.add(t), u(this.session, p(e)), this.pendingToolKeys.add(t), m.debug("tool start emitted", {
|
|
30
|
+
sessionKey: this.session.sessionKey,
|
|
31
|
+
toolName: e.name,
|
|
32
|
+
hasToolCallId: !!e.toolCallId,
|
|
33
|
+
pendingTools: this.pendingToolKeys.size
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
emitToolResult(e) {
|
|
37
|
+
this.includeToolCalls && (u(this.session, f(e)), this.pendingToolKeys.delete(h(e.toolCallId, e.toolName)), this.pendingToolKeys.size === 0 && (d(this.session), this.flushPendingReplyPayloads()));
|
|
38
|
+
}
|
|
39
|
+
onToolStart = (e) => {
|
|
40
|
+
e.phase && e.phase !== "start" || e.name && this.emitToolStart({
|
|
41
|
+
name: e.name,
|
|
42
|
+
toolCallId: e.toolCallId,
|
|
43
|
+
input: e.args
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
handleBeforeToolCall(e) {
|
|
47
|
+
this.emitToolStart(e);
|
|
48
|
+
}
|
|
49
|
+
handleAfterToolCall(e) {
|
|
50
|
+
let t = this.findLatestFinishedStep(e);
|
|
51
|
+
t && this.emitToolResult(t);
|
|
52
|
+
}
|
|
53
|
+
findLatestFinishedStep(e) {
|
|
54
|
+
let t = i(this.session.sessionKey);
|
|
55
|
+
if (e) for (let n = t.length - 1; n >= 0; --n) {
|
|
56
|
+
let r = t[n];
|
|
57
|
+
if (r.status !== "running" && r.toolCallId === e) return r;
|
|
58
|
+
}
|
|
59
|
+
for (let e = t.length - 1; e >= 0; --e) {
|
|
60
|
+
let n = t[e];
|
|
61
|
+
if (n.status !== "running") return n;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
get isGated() {
|
|
65
|
+
return this.pendingToolKeys.size > 0;
|
|
66
|
+
}
|
|
67
|
+
onPartialReply = async (e) => {
|
|
68
|
+
if (this.isGated) {
|
|
69
|
+
this.pendingReplyPayloads.push(e);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
let t = n(this.session, e);
|
|
73
|
+
t && c(this.session, t);
|
|
74
|
+
};
|
|
75
|
+
async flushPendingReplyPayloads() {
|
|
76
|
+
if (this.pendingReplyPayloads.length === 0) return;
|
|
77
|
+
let e = this.pendingReplyPayloads;
|
|
78
|
+
this.pendingReplyPayloads = [];
|
|
79
|
+
for (let t of e) {
|
|
80
|
+
let e = n(this.session, t);
|
|
81
|
+
e && await c(this.session, e);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
onReasoningStream = (e) => {
|
|
85
|
+
if (!this.includeThinking) return;
|
|
86
|
+
let t = r(this.session, e);
|
|
87
|
+
t && l(this.session, t);
|
|
88
|
+
};
|
|
89
|
+
onReasoningEnd = () => {
|
|
90
|
+
this.includeThinking && o(this.session);
|
|
91
|
+
};
|
|
92
|
+
deliver = async (e, n) => {
|
|
93
|
+
if (n.kind === "tool") return;
|
|
94
|
+
let r = t(e);
|
|
95
|
+
if (r) {
|
|
96
|
+
m.warn("model api error", {
|
|
97
|
+
sender: this.session.target.deviceId,
|
|
98
|
+
turnId: this.session.turnId,
|
|
99
|
+
kind: r.kind,
|
|
100
|
+
rawTextLength: r.rawText.length
|
|
101
|
+
}), await c(this.session, r.userMessage);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
let i = e.text ?? "";
|
|
105
|
+
(n.kind === "final" || !this.session.hasPushedAnswerText) && await s(this.session, i);
|
|
106
|
+
};
|
|
107
|
+
onError = (e) => {
|
|
108
|
+
m.warn("reply dispatcher error", {
|
|
109
|
+
sender: this.session.target.deviceId,
|
|
110
|
+
turnId: this.session.turnId,
|
|
111
|
+
error: e instanceof Error ? e.message : String(e)
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
onIdle = async () => {
|
|
115
|
+
await this.flushPendingReplyPayloads(), await a(this.session);
|
|
116
|
+
};
|
|
117
|
+
build() {
|
|
118
|
+
return {
|
|
119
|
+
dispatcherOptions: {
|
|
120
|
+
deliver: this.deliver,
|
|
121
|
+
onError: this.onError,
|
|
122
|
+
onIdle: this.onIdle
|
|
123
|
+
},
|
|
124
|
+
replyOptions: {
|
|
125
|
+
abortSignal: this.session.abortController.signal,
|
|
126
|
+
onToolStart: this.onToolStart,
|
|
127
|
+
onPartialReply: this.onPartialReply,
|
|
128
|
+
...this.includeThinking ? {
|
|
129
|
+
onReasoningStream: this.onReasoningStream,
|
|
130
|
+
onReasoningEnd: this.onReasoningEnd
|
|
131
|
+
} : {}
|
|
132
|
+
},
|
|
133
|
+
session: this.session
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
//#endregion
|
|
138
|
+
export { g as StreamingController };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createStreamSession as e } from "./session.mjs";
|
|
2
|
+
import { StreamingController as t } from "./controller.mjs";
|
|
3
|
+
import { registerStreamController as n, unregisterStreamController as r } from "./registry.mjs";
|
|
4
|
+
//#region src/messaging/dispatchers/stream/factory.ts
|
|
5
|
+
function i(i) {
|
|
6
|
+
let a = e(i), o = new t({
|
|
7
|
+
session: a,
|
|
8
|
+
streamOptions: i.streamOptions
|
|
9
|
+
});
|
|
10
|
+
return n(a.sessionKey, o), {
|
|
11
|
+
...o.build(),
|
|
12
|
+
controller: o,
|
|
13
|
+
dispose: () => r(a.sessionKey)
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { i as createStreamingDispatcher };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { toErrorMessage as e } from "../../../utils/error.mjs";
|
|
2
|
+
import { clawLogger as t } from "../../../utils/claw-logger.mjs";
|
|
3
|
+
import { sanitizeToolError as n, sanitizeTraceRecord as r, sanitizeTraceValue as i } from "./tool/sanitize.mjs";
|
|
4
|
+
import { recordToolUseEnd as a, recordToolUseStart as o } from "./tool/trace-store.mjs";
|
|
5
|
+
import "./tool/index.mjs";
|
|
6
|
+
import { getStreamController as s } from "./registry.mjs";
|
|
7
|
+
//#region src/messaging/dispatchers/stream/hooks.ts
|
|
8
|
+
var c = t("tool-events");
|
|
9
|
+
function l(t) {
|
|
10
|
+
try {
|
|
11
|
+
o({
|
|
12
|
+
sessionKey: t.sessionKey,
|
|
13
|
+
toolName: t.toolName,
|
|
14
|
+
toolParams: t.params ? r(t.params, { source: "params" }) : void 0,
|
|
15
|
+
toolCallId: t.toolCallId,
|
|
16
|
+
runId: t.runId
|
|
17
|
+
});
|
|
18
|
+
} catch (n) {
|
|
19
|
+
c.warn("failed to record tool start", {
|
|
20
|
+
toolName: t.toolName,
|
|
21
|
+
sessionKey: t.sessionKey,
|
|
22
|
+
error: e(n)
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
s(t.sessionKey)?.handleBeforeToolCall({
|
|
26
|
+
name: t.toolName,
|
|
27
|
+
toolCallId: t.toolCallId,
|
|
28
|
+
input: t.params
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
function u(t) {
|
|
32
|
+
try {
|
|
33
|
+
let e = t.params ? r(t.params, { source: "params" }) : void 0, o = i(t.result, 0, { source: "result" });
|
|
34
|
+
a({
|
|
35
|
+
sessionKey: t.sessionKey,
|
|
36
|
+
toolName: t.toolName,
|
|
37
|
+
toolParams: e,
|
|
38
|
+
toolCallId: t.toolCallId,
|
|
39
|
+
runId: t.runId,
|
|
40
|
+
...o === void 0 ? {} : { result: o },
|
|
41
|
+
...typeof t.error == "string" ? { error: n(t.error) } : {},
|
|
42
|
+
...typeof t.durationMs == "number" ? { durationMs: t.durationMs } : {}
|
|
43
|
+
});
|
|
44
|
+
} catch (n) {
|
|
45
|
+
c.warn("failed to record tool end", {
|
|
46
|
+
toolName: t.toolName,
|
|
47
|
+
sessionKey: t.sessionKey,
|
|
48
|
+
error: e(n)
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
s(t.sessionKey)?.handleAfterToolCall(t.toolCallId);
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
export { u as recordToolCallEnd, l as recordToolCallStart };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/messaging/dispatchers/stream/registry.ts
|
|
2
|
+
var e = /* @__PURE__ */ new Map();
|
|
3
|
+
function t(t, n) {
|
|
4
|
+
e.set(t, n);
|
|
5
|
+
}
|
|
6
|
+
function n(t) {
|
|
7
|
+
e.delete(t);
|
|
8
|
+
}
|
|
9
|
+
function r(t) {
|
|
10
|
+
if (t) return e.get(t);
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { r as getStreamController, t as registerStreamController, n as unregisterStreamController };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region src/messaging/stream/resolvers.ts
|
|
1
|
+
//#region src/messaging/dispatchers/stream/resolvers.ts
|
|
2
2
|
function e(e, t) {
|
|
3
3
|
if (t.delta) return typeof t.text == "string" ? (e.answerSnapshot = t.text, e.latestAnswerSnapshot = t.text) : (e.answerSnapshot += t.delta, e.latestAnswerSnapshot = e.answerSnapshot), t.delta;
|
|
4
4
|
if (typeof t.text != "string" || t.text.length === 0) return "";
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { uuid as e } from "
|
|
2
|
-
import { sendAgentReplyFrame as t } from "
|
|
3
|
-
import { stringifyValue as n } from "
|
|
1
|
+
import { uuid as e } from "../../../utils/id.mjs";
|
|
2
|
+
import { sendAgentReplyFrame as t } from "../../send/frame.mjs";
|
|
3
|
+
import { stringifyValue as n } from "../../../utils/stringify.mjs";
|
|
4
4
|
import { clearToolTraceSession as r } from "./tool/trace-store.mjs";
|
|
5
|
-
//#region src/messaging/stream/session.ts
|
|
5
|
+
//#region src/messaging/dispatchers/stream/session.ts
|
|
6
6
|
function i(e) {
|
|
7
7
|
return e.finished || e.abortController.signal.aborted;
|
|
8
8
|
}
|
|
9
9
|
function a(t) {
|
|
10
|
-
return {
|
|
10
|
+
return r(t.sessionKey), {
|
|
11
11
|
sessionKey: t.sessionKey,
|
|
12
12
|
target: t.target,
|
|
13
13
|
...t.replyToMessageId ? { replyToMessageId: t.replyToMessageId } : {},
|
|
@@ -17,7 +17,8 @@ function a(t) {
|
|
|
17
17
|
answerSnapshot: "",
|
|
18
18
|
thinkingSnapshot: "",
|
|
19
19
|
latestAnswerSnapshot: "",
|
|
20
|
-
hasPushedAnswerText: !1
|
|
20
|
+
hasPushedAnswerText: !1,
|
|
21
|
+
hasPushedThinkingText: !1
|
|
21
22
|
};
|
|
22
23
|
}
|
|
23
24
|
async function o(e) {
|
|
@@ -43,7 +44,7 @@ async function s(e, n) {
|
|
|
43
44
|
}), e.hasPushedAnswerText = !0);
|
|
44
45
|
}
|
|
45
46
|
async function c(e, n) {
|
|
46
|
-
i(e) || n.length === 0 || t({
|
|
47
|
+
i(e) || n.length === 0 || (t({
|
|
47
48
|
period: "thinking",
|
|
48
49
|
isFinish: !1,
|
|
49
50
|
content: [{
|
|
@@ -53,10 +54,10 @@ async function c(e, n) {
|
|
|
53
54
|
}, {
|
|
54
55
|
target: e.target,
|
|
55
56
|
turnId: e.turnId
|
|
56
|
-
});
|
|
57
|
+
}), e.hasPushedThinkingText = !0);
|
|
57
58
|
}
|
|
58
59
|
async function l(e) {
|
|
59
|
-
i(e) || t({
|
|
60
|
+
i(e) || !e.hasPushedThinkingText || t({
|
|
60
61
|
period: "thinking",
|
|
61
62
|
isFinish: !0
|
|
62
63
|
}, {
|
|
@@ -117,11 +118,14 @@ async function f(e, t) {
|
|
|
117
118
|
}
|
|
118
119
|
if (t.startsWith(e.answerSnapshot)) {
|
|
119
120
|
let n = t.slice(e.answerSnapshot.length);
|
|
120
|
-
e.answerSnapshot = t, e.latestAnswerSnapshot = t, await s(e, n);
|
|
121
|
+
e.answerSnapshot = t, e.latestAnswerSnapshot = t, n && await s(e, n);
|
|
121
122
|
return;
|
|
122
123
|
}
|
|
123
124
|
e.latestAnswerSnapshot = t;
|
|
124
125
|
}
|
|
125
126
|
}
|
|
127
|
+
function p(e) {
|
|
128
|
+
e.answerSnapshot = "", e.latestAnswerSnapshot = "", e.hasPushedAnswerText = !1;
|
|
129
|
+
}
|
|
126
130
|
//#endregion
|
|
127
|
-
export { a as createStreamSession, d as finishStreamSession, l as finishThinking, f as pushFinalVisibleText, s as pushStreamDelta, c as pushThinkingDelta, u as pushToolEvent, o as startStreamSession };
|
|
131
|
+
export { a as createStreamSession, d as finishStreamSession, l as finishThinking, f as pushFinalVisibleText, s as pushStreamDelta, c as pushThinkingDelta, u as pushToolEvent, p as resetAnswerSnapshot, o as startStreamSession };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region src/messaging/dispatchers/stream/tool/error.ts
|
|
2
|
+
var e = [
|
|
3
|
+
{
|
|
4
|
+
code: "timeout",
|
|
5
|
+
test: /timeout|timed out|etimedout/i
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
code: "not_found",
|
|
9
|
+
test: /not found|enoent|missing|does not exist/i
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
code: "auth_failed",
|
|
13
|
+
test: /unauthori[sz]ed|forbidden|permission|auth|api key|token/i
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
code: "network",
|
|
17
|
+
test: /network|econn|socket|dns|fetch|request failed/i
|
|
18
|
+
}
|
|
19
|
+
];
|
|
20
|
+
function t(t) {
|
|
21
|
+
let n = t?.toLowerCase() ?? "";
|
|
22
|
+
for (let { code: t, test: r } of e) if (r.test(n)) return t;
|
|
23
|
+
return "unknown";
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
export { t as classifyToolError };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { classifyToolError as e } from "./error.mjs";
|
|
2
|
+
//#region src/messaging/dispatchers/stream/tool/event-builder.ts
|
|
3
|
+
function t(e) {
|
|
4
|
+
let t = {
|
|
5
|
+
name: e.name,
|
|
6
|
+
phase: "call"
|
|
7
|
+
};
|
|
8
|
+
return e.toolCallId && (t.callId = e.toolCallId), e.input && (t.input = e.input), t;
|
|
9
|
+
}
|
|
10
|
+
function n(t) {
|
|
11
|
+
let n = {
|
|
12
|
+
name: t.toolName,
|
|
13
|
+
phase: t.status === "error" ? "error" : "result"
|
|
14
|
+
};
|
|
15
|
+
return t.toolCallId && (n.callId = t.toolCallId), t.status === "error" ? (n.error = t.error ?? "tool error", n.errorCode = e(t.error), n) : (n.output = t.result, n);
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { n as buildToolResultEvent, t as buildToolStartEvent };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region src/messaging/stream/tool/sanitize.ts
|
|
1
|
+
//#region src/messaging/dispatchers/stream/tool/sanitize.ts
|
|
2
2
|
var e = 512, t = 1024, n = 2048, r = 4096, i = 8, a = 12, o = 2, s = "[redacted]", c = "[truncated]", l = /(?:secret|token|password|authorization|cookie|api[_-]?key|credential|access[_-]?key|private[_-]?key|refresh[_-]?token)/i, u = /(?:command|cmd|script|description|prompt|task)/i, d = /(?:path|file|url|uri)/i, f = /\b([A-Za-z0-9_-]*(?:secret|token|password|authorization|cookie|api[_-]?key|credential|access[_-]?key|private[_-]?key|refresh[_-]?token)[A-Za-z0-9_-]*\s*=\s*)(?:"[^"]*"|'[^']*'|[^\s&;]+)/gi, p = /(--(?:secret|token|password|authorization|cookie|api[_-]?key|credential|access[_-]?key|private[_-]?key|refresh[_-]?token)\s+)(?:"[^"]*"|'[^']*'|[^\s&;]+)/gi, m = /((?:"|')?[A-Za-z0-9_-]*(?:secret|token|password|authorization|cookie|api[_-]?key|credential|access[_-]?key|private[_-]?key|refresh[_-]?token)[A-Za-z0-9_-]*(?:"|')?\s*:\s*)(?:"[^"]*"|'[^']*'|[^\s,}]+)/gi, h = /(authorization\s*:\s*)(?:(bearer|basic)\s+)?[^\s,;]+/gi, g = /([?&][^=\s&]*(?:secret|token|password|authorization|cookie|api[_-]?key|credential|access[_-]?key|private[_-]?key|refresh[_-]?token)[^=\s&]*=)([^&\s]+)/gi;
|
|
3
3
|
function _(e) {
|
|
4
4
|
return typeof e == "object" && !!e && !Array.isArray(e);
|