@pi-oxide/pi-host-web 0.5.0 → 0.8.0
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/bindings.d.ts +2 -0
- package/dist/index-CAp51VNq.js +867 -0
- package/dist/index-Is-rTdaY.js +867 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1706 -0
- package/dist/sdk/agent.d.ts +21 -0
- package/dist/sdk/agent.d.ts.map +1 -0
- package/dist/sdk/artifacts.d.ts +29 -0
- package/dist/sdk/artifacts.d.ts.map +1 -0
- package/dist/sdk/bindings/host-agent.d.ts +16 -0
- package/dist/sdk/bindings/host-agent.d.ts.map +1 -0
- package/dist/sdk/bindings/index.d.ts +7 -0
- package/dist/sdk/bindings/index.d.ts.map +1 -0
- package/dist/sdk/bindings/index.js +14 -0
- package/dist/sdk/bindings/init.d.ts +30 -0
- package/dist/sdk/bindings/init.d.ts.map +1 -0
- package/dist/sdk/bindings/markers.d.ts +9 -0
- package/dist/sdk/bindings/markers.d.ts.map +1 -0
- package/dist/sdk/bindings/tool-preparation.d.ts +12 -0
- package/dist/sdk/bindings/tool-preparation.d.ts.map +1 -0
- package/dist/sdk/bindings/turn-loop.d.ts +5 -0
- package/dist/sdk/bindings/turn-loop.d.ts.map +1 -0
- package/dist/sdk/bindings/types.d.ts +60 -0
- package/dist/sdk/bindings/types.d.ts.map +1 -0
- package/dist/sdk/context.d.ts +2 -0
- package/dist/sdk/context.d.ts.map +1 -0
- package/dist/sdk/errors.d.ts +8 -0
- package/dist/sdk/errors.d.ts.map +1 -0
- package/dist/sdk/events.d.ts +9 -0
- package/dist/sdk/events.d.ts.map +1 -0
- package/dist/sdk/index.d.ts +16 -0
- package/dist/sdk/index.d.ts.map +1 -0
- package/dist/sdk/init.d.ts +2 -0
- package/dist/sdk/init.d.ts.map +1 -0
- package/dist/sdk/internal/engine.d.ts +4 -0
- package/dist/sdk/internal/engine.d.ts.map +1 -0
- package/dist/sdk/internal/events.d.ts +30 -0
- package/dist/sdk/internal/events.d.ts.map +1 -0
- package/dist/sdk/internal/logger.d.ts +51 -0
- package/dist/sdk/internal/logger.d.ts.map +1 -0
- package/dist/sdk/internal/providers/anthropic.d.ts +75 -0
- package/dist/sdk/internal/providers/anthropic.d.ts.map +1 -0
- package/dist/sdk/internal/providers/openai.d.ts +13 -0
- package/dist/sdk/internal/providers/openai.d.ts.map +1 -0
- package/dist/sdk/internal/providers/types.d.ts +57 -0
- package/dist/sdk/internal/providers/types.d.ts.map +1 -0
- package/dist/sdk/internal/stores/indexedDb.d.ts +3 -0
- package/dist/sdk/internal/stores/indexedDb.d.ts.map +1 -0
- package/dist/sdk/internal/stores/persistence.d.ts +13 -0
- package/dist/sdk/internal/stores/persistence.d.ts.map +1 -0
- package/dist/sdk/internal/tools/artifact.d.ts +3 -0
- package/dist/sdk/internal/tools/artifact.d.ts.map +1 -0
- package/dist/sdk/internal/tools/browser.d.ts +19 -0
- package/dist/sdk/internal/tools/browser.d.ts.map +1 -0
- package/dist/sdk/internal/tools/browserRuntime.d.ts +47 -0
- package/dist/sdk/internal/tools/browserRuntime.d.ts.map +1 -0
- package/dist/sdk/internal/tools/liveRuntime.d.ts +12 -0
- package/dist/sdk/internal/tools/liveRuntime.d.ts.map +1 -0
- package/dist/sdk/internal/tools/registry.d.ts +17 -0
- package/dist/sdk/internal/tools/registry.d.ts.map +1 -0
- package/dist/sdk/internal/tools/service.d.ts +15 -0
- package/dist/sdk/internal/tools/service.d.ts.map +1 -0
- package/dist/sdk/internal/util/types.d.ts +6 -0
- package/dist/sdk/internal/util/types.d.ts.map +1 -0
- package/dist/sdk/model.d.ts +16 -0
- package/dist/sdk/model.d.ts.map +1 -0
- package/dist/sdk/orchestration/agent-engine.d.ts +24 -0
- package/dist/sdk/orchestration/agent-engine.d.ts.map +1 -0
- package/dist/sdk/orchestration/config-builders.d.ts +13 -0
- package/dist/sdk/orchestration/config-builders.d.ts.map +1 -0
- package/dist/sdk/orchestration/model-adapter.d.ts +10 -0
- package/dist/sdk/orchestration/model-adapter.d.ts.map +1 -0
- package/dist/sdk/snapshot.d.ts +7 -0
- package/dist/sdk/snapshot.d.ts.map +1 -0
- package/dist/sdk/stores.d.ts +22 -0
- package/dist/sdk/stores.d.ts.map +1 -0
- package/dist/sdk/tools.d.ts +32 -0
- package/dist/sdk/tools.d.ts.map +1 -0
- package/dist/sdk/types.d.ts +200 -0
- package/dist/sdk/types.d.ts.map +1 -0
- package/package.json +107 -5
- package/pi_host_web.d.ts +4 -17
- package/pi_host_web.js +1 -13
- package/pi_host_web_bg.wasm +0 -0
- package/pi_host_web_bg.wasm.d.ts +36 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1706 @@
|
|
|
1
|
+
var U = Object.defineProperty;
|
|
2
|
+
var H = (t, e, s) => e in t ? U(t, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : t[e] = s;
|
|
3
|
+
var b = (t, e, s) => H(t, typeof e != "symbol" ? e + "" : e, s);
|
|
4
|
+
import { l as S, h as _, b as G, g as P, i as F, e as K, o as Q, c as X, r as V, w as Y, m as Z, n as ee } from "./index-CAp51VNq.js";
|
|
5
|
+
import { C as _t, a as yt, N as bt, f as xt, j as wt, k as St, s as kt, t as vt, v as Rt } from "./index-CAp51VNq.js";
|
|
6
|
+
import { zodToJsonSchema as te } from "zod-to-json-schema";
|
|
7
|
+
class se {
|
|
8
|
+
constructor() {
|
|
9
|
+
b(this, "handlers", {});
|
|
10
|
+
}
|
|
11
|
+
on(e, s) {
|
|
12
|
+
this.handlers[e] || (this.handlers[e] = /* @__PURE__ */ new Set());
|
|
13
|
+
const o = this.handlers[e];
|
|
14
|
+
return o.add(s), () => {
|
|
15
|
+
o.delete(s), o.size === 0 && delete this.handlers[e];
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
off(e, s) {
|
|
19
|
+
const o = this.handlers[e];
|
|
20
|
+
o && (o.delete(s), o.size === 0 && delete this.handlers[e]);
|
|
21
|
+
}
|
|
22
|
+
emit(e, s) {
|
|
23
|
+
const o = this.handlers[e];
|
|
24
|
+
if (o)
|
|
25
|
+
for (const r of o)
|
|
26
|
+
r(s);
|
|
27
|
+
}
|
|
28
|
+
clear() {
|
|
29
|
+
this.handlers = {};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const O = 1;
|
|
33
|
+
class J {
|
|
34
|
+
constructor() {
|
|
35
|
+
b(this, "logger", S("snapshot"));
|
|
36
|
+
}
|
|
37
|
+
serialize(e) {
|
|
38
|
+
return {
|
|
39
|
+
version: O,
|
|
40
|
+
data: e
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
deserialize(e) {
|
|
44
|
+
return e.version !== O ? (this.logger.warn("Snapshot version mismatch, starting fresh", {
|
|
45
|
+
expected: O,
|
|
46
|
+
got: e.version
|
|
47
|
+
}), null) : e.data;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
class oe {
|
|
51
|
+
createRunState() {
|
|
52
|
+
return {
|
|
53
|
+
messages: [],
|
|
54
|
+
toolCalls: [],
|
|
55
|
+
artifacts: [],
|
|
56
|
+
usage: { input: 0, output: 0, cache_read: 0, cache_write: 0, total_tokens: 0 },
|
|
57
|
+
text: "",
|
|
58
|
+
currentMessage: null,
|
|
59
|
+
currentTool: null
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
map(e, s) {
|
|
63
|
+
const o = [];
|
|
64
|
+
switch (e.type) {
|
|
65
|
+
case "agent_start": {
|
|
66
|
+
o.push({ type: "status", payload: { state: "loading", message: "Agent starting..." } });
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
case "turn_start": {
|
|
70
|
+
o.push({ type: "status", payload: { state: "thinking", message: "Thinking..." } });
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
case "message_start": {
|
|
74
|
+
const r = this.convertWasmMessage(e.message);
|
|
75
|
+
s.currentMessage = r, s.messages.push(r), o.push({ type: "messageStart", payload: r }), o.push({ type: "status", payload: { state: "thinking" } });
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
case "message_update": {
|
|
79
|
+
const r = e.delta;
|
|
80
|
+
r.kind === "text_delta" && r.text ? (s.text += r.text, o.push({ type: "text", payload: r.text })) : r.kind === "thinking_delta" && o.push({ type: "status", payload: { state: "thinking", message: "Thinking..." } });
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
case "message_end": {
|
|
84
|
+
const r = this.convertWasmMessage(e.message);
|
|
85
|
+
s.currentMessage = r;
|
|
86
|
+
const n = s.messages.findIndex((a) => a.id === r.id);
|
|
87
|
+
n >= 0 ? s.messages[n] = r : s.messages.push(r), o.push({ type: "messageEnd", payload: r });
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
case "tool_execution_start": {
|
|
91
|
+
const r = {
|
|
92
|
+
id: e.tool_call_id,
|
|
93
|
+
name: e.tool_name,
|
|
94
|
+
title: e.tool_name,
|
|
95
|
+
input: e.args ?? {},
|
|
96
|
+
status: "running",
|
|
97
|
+
startedAt: Date.now()
|
|
98
|
+
};
|
|
99
|
+
s.currentTool = r, s.toolCalls.push(r), o.push({ type: "toolStart", payload: r }), o.push({
|
|
100
|
+
type: "status",
|
|
101
|
+
payload: { state: "running_tool", message: `Running ${e.tool_name}...` }
|
|
102
|
+
});
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
case "tool_execution_update": {
|
|
106
|
+
const r = s.toolCalls.find((n) => n.id === e.tool_call_id);
|
|
107
|
+
r && (r.output = (r.output ?? "") + e.chunk, o.push({ type: "toolUpdate", payload: r }));
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
case "tool_execution_end": {
|
|
111
|
+
let r = s.toolCalls.find((a) => a.id === e.tool_call_id);
|
|
112
|
+
if (!r) {
|
|
113
|
+
const a = e.tool_name ?? "unknown";
|
|
114
|
+
r = {
|
|
115
|
+
id: e.tool_call_id,
|
|
116
|
+
name: a,
|
|
117
|
+
title: a,
|
|
118
|
+
input: e.args ?? {},
|
|
119
|
+
status: e.is_error ? "failed" : "completed",
|
|
120
|
+
startedAt: Date.now(),
|
|
121
|
+
endedAt: Date.now()
|
|
122
|
+
}, s.toolCalls.push(r);
|
|
123
|
+
}
|
|
124
|
+
r.status = e.is_error ? "failed" : "completed", r.endedAt = Date.now();
|
|
125
|
+
const n = e.result.content.filter((a) => a.type === "text").map((a) => a.text).join(`
|
|
126
|
+
`);
|
|
127
|
+
r.output = n, o.push({ type: "toolEnd", payload: r });
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
case "tool_execution_cancelled": {
|
|
131
|
+
const r = s.toolCalls.find((n) => n.id === e.tool_call_id);
|
|
132
|
+
r && (r.status = "cancelled", r.endedAt = Date.now(), o.push({ type: "toolEnd", payload: r }));
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
case "turn_end": {
|
|
136
|
+
const r = this.convertWasmMessage(e.message), n = s.messages.findIndex((a) => a.id === r.id);
|
|
137
|
+
n >= 0 ? s.messages[n] = r : s.messages.push(r);
|
|
138
|
+
for (const a of e.tool_results) {
|
|
139
|
+
let i = s.toolCalls.find((c) => c.id === a.tool_call_id);
|
|
140
|
+
if (!i) {
|
|
141
|
+
const c = a.tool_name ?? "unknown";
|
|
142
|
+
i = {
|
|
143
|
+
id: a.tool_call_id,
|
|
144
|
+
name: c,
|
|
145
|
+
title: c,
|
|
146
|
+
input: {},
|
|
147
|
+
status: a.is_error ? "failed" : "completed",
|
|
148
|
+
startedAt: Date.now(),
|
|
149
|
+
endedAt: Date.now()
|
|
150
|
+
}, s.toolCalls.push(i);
|
|
151
|
+
}
|
|
152
|
+
i.status = a.is_error ? "failed" : "completed", i.endedAt = Date.now();
|
|
153
|
+
const l = a.content.filter((c) => c.type === "text").map((c) => c.text).join(`
|
|
154
|
+
`);
|
|
155
|
+
i.output = l;
|
|
156
|
+
}
|
|
157
|
+
o.push({ type: "status", payload: { state: "completed" } });
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
case "save_point": {
|
|
161
|
+
o.push({ type: "status", payload: { state: "saving", message: "Saving session..." } });
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
case "settled": {
|
|
165
|
+
o.push({ type: "status", payload: { state: "completed" } });
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
case "queue_update":
|
|
169
|
+
break;
|
|
170
|
+
case "agent_end": {
|
|
171
|
+
o.push({ type: "status", payload: { state: "idle" } });
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return o;
|
|
176
|
+
}
|
|
177
|
+
buildRunResult(e, s) {
|
|
178
|
+
return s.aborted ? {
|
|
179
|
+
status: "aborted",
|
|
180
|
+
text: e.text,
|
|
181
|
+
toolCalls: e.toolCalls,
|
|
182
|
+
artifacts: e.artifacts,
|
|
183
|
+
usage: e.usage
|
|
184
|
+
} : {
|
|
185
|
+
status: "completed",
|
|
186
|
+
message: e.currentMessage ?? void 0,
|
|
187
|
+
text: e.text,
|
|
188
|
+
toolCalls: e.toolCalls,
|
|
189
|
+
artifacts: e.artifacts,
|
|
190
|
+
usage: e.usage
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
processMarkers(e, s) {
|
|
194
|
+
const o = [];
|
|
195
|
+
for (const r of e)
|
|
196
|
+
if (r.type === "new_artifacts" && r.entry_ids)
|
|
197
|
+
for (const n of r.entry_ids)
|
|
198
|
+
s.artifacts.push({ id: n, kind: "text" }), o.push({ type: "artifact", payload: { id: n, kind: "text" } });
|
|
199
|
+
return o;
|
|
200
|
+
}
|
|
201
|
+
convertWasmMessage(e) {
|
|
202
|
+
return {
|
|
203
|
+
id: this.generateStableId(e),
|
|
204
|
+
role: e.role,
|
|
205
|
+
content: e.content.map((o) => this.convertContent(o)),
|
|
206
|
+
timestamp: e.timestamp ?? Date.now(),
|
|
207
|
+
tool_call_id: e.role === "tool_result" ? e.tool_call_id : void 0
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
generateStableId(e) {
|
|
211
|
+
const s = e.content.map((o) => {
|
|
212
|
+
var r;
|
|
213
|
+
return o.type === "text" ? `t:${((r = o.text) == null ? void 0 : r.slice(0, 20)) ?? ""}` : o.type === "tool_call" ? `tc:${o.id ?? ""}:${o.name ?? ""}` : o.type === "image" ? `img:${o.media_type ?? ""}` : o.type;
|
|
214
|
+
}).join("|");
|
|
215
|
+
return `msg-${e.role}-${e.timestamp ?? 0}-${s}`;
|
|
216
|
+
}
|
|
217
|
+
convertContent(e) {
|
|
218
|
+
return e.type === "text" ? { type: "text", text: e.text } : e.type === "tool_call" ? { type: "tool_call", id: e.id, name: e.name, arguments: e.arguments } : e.type === "image" ? { type: "image", mimeType: e.media_type, data: e.data } : { type: "text", text: "" };
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
function v(t) {
|
|
222
|
+
return typeof t == "object" && t !== null;
|
|
223
|
+
}
|
|
224
|
+
function k(t, e) {
|
|
225
|
+
if (v(t)) {
|
|
226
|
+
const s = t[e];
|
|
227
|
+
return typeof s == "string" ? s : void 0;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
function ne(t, e) {
|
|
231
|
+
if (v(t)) {
|
|
232
|
+
const s = t[e];
|
|
233
|
+
return typeof s == "number" ? s : void 0;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
function re(t, e) {
|
|
237
|
+
if (v(t)) {
|
|
238
|
+
const s = t[e];
|
|
239
|
+
return typeof s == "boolean" ? s : void 0;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
const W = [], C = {
|
|
243
|
+
log: console.log.bind(console),
|
|
244
|
+
warn: console.warn.bind(console),
|
|
245
|
+
error: console.error.bind(console),
|
|
246
|
+
info: console.info.bind(console)
|
|
247
|
+
};
|
|
248
|
+
function E(t, e) {
|
|
249
|
+
W.push({ level: t, args: e.map(String), timestamp: Date.now() });
|
|
250
|
+
}
|
|
251
|
+
console.log = (...t) => {
|
|
252
|
+
E("log", t), C.log(...t);
|
|
253
|
+
};
|
|
254
|
+
console.warn = (...t) => {
|
|
255
|
+
E("warn", t), C.warn(...t);
|
|
256
|
+
};
|
|
257
|
+
console.error = (...t) => {
|
|
258
|
+
E("error", t), C.error(...t);
|
|
259
|
+
};
|
|
260
|
+
console.info = (...t) => {
|
|
261
|
+
E("info", t), C.info(...t);
|
|
262
|
+
};
|
|
263
|
+
function I(t, e) {
|
|
264
|
+
const s = (t.textContent || "").trim().slice(0, 500), o = {};
|
|
265
|
+
for (const a of Array.from(t.attributes))
|
|
266
|
+
o[a.name] = a.value;
|
|
267
|
+
const r = window.getComputedStyle(t), n = r.display !== "none" && r.visibility !== "hidden" && r.opacity !== "0";
|
|
268
|
+
return {
|
|
269
|
+
tag: t.tagName.toLowerCase(),
|
|
270
|
+
text: s,
|
|
271
|
+
attributes: o,
|
|
272
|
+
visible: n,
|
|
273
|
+
selector: e
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
class ae {
|
|
277
|
+
constructor() {
|
|
278
|
+
b(this, "logger", S("browser-runtime"));
|
|
279
|
+
}
|
|
280
|
+
getPage() {
|
|
281
|
+
const e = document.activeElement, s = e && e !== document.body ? I(e, "") : null;
|
|
282
|
+
return this.logger.debug("getPage", { url: location.href, title: document.title }), {
|
|
283
|
+
url: location.href,
|
|
284
|
+
title: document.title,
|
|
285
|
+
readyState: document.readyState,
|
|
286
|
+
focusedElement: s
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
evalJs(e) {
|
|
290
|
+
return this.logger.debug("evalJs", { sourceLength: e.length }), new Function(e)();
|
|
291
|
+
}
|
|
292
|
+
querySelector(e) {
|
|
293
|
+
const s = document.querySelector(e);
|
|
294
|
+
return this.logger.debug("querySelector", { selector: e, found: !!s }), s ? I(s, e) : null;
|
|
295
|
+
}
|
|
296
|
+
querySelectorAll(e) {
|
|
297
|
+
const s = Array.from(document.querySelectorAll(e));
|
|
298
|
+
return this.logger.debug("querySelectorAll", { selector: e, count: s.length }), s.map((o) => I(o, e));
|
|
299
|
+
}
|
|
300
|
+
click(e) {
|
|
301
|
+
this.logger.debug("click", { selector: e });
|
|
302
|
+
const s = document.querySelector(e);
|
|
303
|
+
return s ? (s.click(), { ok: !0 }) : (this.logger.warn("click failed: element not found", { selector: e }), {
|
|
304
|
+
ok: !1,
|
|
305
|
+
error: {
|
|
306
|
+
code: "element_not_found",
|
|
307
|
+
message: `No element matches: ${e}`
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
type(e, s) {
|
|
312
|
+
this.logger.debug("type", { selector: e, textLength: s.length });
|
|
313
|
+
const o = document.querySelector(e);
|
|
314
|
+
return o ? !(o instanceof HTMLInputElement) && !(o instanceof HTMLTextAreaElement) ? (this.logger.warn("type failed: not an input", { selector: e, tag: o.tagName }), {
|
|
315
|
+
ok: !1,
|
|
316
|
+
error: {
|
|
317
|
+
code: "not_input",
|
|
318
|
+
message: `Element is not an input or textarea: ${e}`
|
|
319
|
+
}
|
|
320
|
+
}) : (o.value = s, o.dispatchEvent(new Event("input", { bubbles: !0 })), { ok: !0 }) : (this.logger.warn("type failed: element not found", { selector: e }), {
|
|
321
|
+
ok: !1,
|
|
322
|
+
error: {
|
|
323
|
+
code: "element_not_found",
|
|
324
|
+
message: `No element matches: ${e}`
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
getConsole() {
|
|
329
|
+
const e = [...W];
|
|
330
|
+
return this.logger.debug("getConsole", { count: e.length }), e;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
const ie = {
|
|
334
|
+
type: "object",
|
|
335
|
+
properties: {},
|
|
336
|
+
additionalProperties: !1
|
|
337
|
+
}, le = {
|
|
338
|
+
type: "object",
|
|
339
|
+
properties: {
|
|
340
|
+
source: {
|
|
341
|
+
type: "string",
|
|
342
|
+
description: "JavaScript source code to evaluate in the page context."
|
|
343
|
+
}
|
|
344
|
+
},
|
|
345
|
+
required: ["source"],
|
|
346
|
+
additionalProperties: !1
|
|
347
|
+
}, ce = {
|
|
348
|
+
type: "object",
|
|
349
|
+
properties: {
|
|
350
|
+
selector: {
|
|
351
|
+
type: "string",
|
|
352
|
+
description: "CSS selector to match elements."
|
|
353
|
+
},
|
|
354
|
+
all: {
|
|
355
|
+
type: "boolean",
|
|
356
|
+
description: "If true, return all matching elements. Default: false (first match only)."
|
|
357
|
+
}
|
|
358
|
+
},
|
|
359
|
+
required: ["selector"],
|
|
360
|
+
additionalProperties: !1
|
|
361
|
+
}, ue = {
|
|
362
|
+
type: "object",
|
|
363
|
+
properties: {
|
|
364
|
+
selector: {
|
|
365
|
+
type: "string",
|
|
366
|
+
description: "CSS selector of the element to click."
|
|
367
|
+
}
|
|
368
|
+
},
|
|
369
|
+
required: ["selector"],
|
|
370
|
+
additionalProperties: !1
|
|
371
|
+
}, de = {
|
|
372
|
+
type: "object",
|
|
373
|
+
properties: {
|
|
374
|
+
selector: {
|
|
375
|
+
type: "string",
|
|
376
|
+
description: "CSS selector of the input element to type into."
|
|
377
|
+
},
|
|
378
|
+
text: {
|
|
379
|
+
type: "string",
|
|
380
|
+
description: "Text to type into the element."
|
|
381
|
+
}
|
|
382
|
+
},
|
|
383
|
+
required: ["selector", "text"],
|
|
384
|
+
additionalProperties: !1
|
|
385
|
+
}, me = {
|
|
386
|
+
type: "object",
|
|
387
|
+
properties: {
|
|
388
|
+
level: {
|
|
389
|
+
type: "string",
|
|
390
|
+
description: "Filter by level: 'log', 'warn', 'error', 'info'. Omit for all."
|
|
391
|
+
},
|
|
392
|
+
limit: {
|
|
393
|
+
type: "number",
|
|
394
|
+
description: "Maximum number of entries to return. Default: 50."
|
|
395
|
+
}
|
|
396
|
+
},
|
|
397
|
+
additionalProperties: !1
|
|
398
|
+
}, pe = {
|
|
399
|
+
name: "browser_get_page",
|
|
400
|
+
label: "Get Page",
|
|
401
|
+
description: "Get the current page state: URL, title, ready state, and focused element summary.",
|
|
402
|
+
parameters: ie,
|
|
403
|
+
execution_mode: "parallel"
|
|
404
|
+
}, ge = {
|
|
405
|
+
name: "browser_eval_js",
|
|
406
|
+
label: "Eval JS",
|
|
407
|
+
description: "Evaluate JavaScript in the page context and return the JSON-serializable result. Returns a typed error if the code throws.",
|
|
408
|
+
parameters: le,
|
|
409
|
+
execution_mode: "sequential"
|
|
410
|
+
}, fe = {
|
|
411
|
+
name: "browser_query_selector",
|
|
412
|
+
label: "Query Selector",
|
|
413
|
+
description: "Query elements by CSS selector. Returns tag, text preview, attributes, and visibility for each matched element. Use 'all: true' to return all matches.",
|
|
414
|
+
parameters: ce,
|
|
415
|
+
execution_mode: "parallel"
|
|
416
|
+
}, he = {
|
|
417
|
+
name: "browser_click",
|
|
418
|
+
label: "Click",
|
|
419
|
+
description: "Click an element by CSS selector.",
|
|
420
|
+
parameters: ue,
|
|
421
|
+
execution_mode: "sequential"
|
|
422
|
+
}, _e = {
|
|
423
|
+
name: "browser_type",
|
|
424
|
+
label: "Type",
|
|
425
|
+
description: "Type text into an input element by CSS selector.",
|
|
426
|
+
parameters: de,
|
|
427
|
+
execution_mode: "sequential"
|
|
428
|
+
}, ye = {
|
|
429
|
+
name: "browser_console",
|
|
430
|
+
label: "Console",
|
|
431
|
+
description: "Read captured console logs, warnings, and errors from the page. Optionally filter by level and limit count.",
|
|
432
|
+
parameters: me,
|
|
433
|
+
execution_mode: "parallel"
|
|
434
|
+
}, N = [
|
|
435
|
+
pe,
|
|
436
|
+
ge,
|
|
437
|
+
fe,
|
|
438
|
+
he,
|
|
439
|
+
_e,
|
|
440
|
+
ye
|
|
441
|
+
], be = '#{ action: "project", text: head(text, 3000) }', xe = '#{ action: "project", text: head(text, 5000) }', we = `let all = lines(text);
|
|
442
|
+
let errs = [];
|
|
443
|
+
for line in all {
|
|
444
|
+
if contains(line, "ERROR") || contains(line, "FATAL") {
|
|
445
|
+
errs.push(line);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
#{ action: "project", text: join(errs, "\\n") }`, Se = {
|
|
449
|
+
browser_get_page: be,
|
|
450
|
+
browser_console: we,
|
|
451
|
+
browser_eval_js: xe
|
|
452
|
+
}, ke = 500;
|
|
453
|
+
function D(t) {
|
|
454
|
+
return async (e) => {
|
|
455
|
+
try {
|
|
456
|
+
return await t(e);
|
|
457
|
+
} catch (s) {
|
|
458
|
+
return {
|
|
459
|
+
content: [{ type: "text", text: s instanceof Error ? s.message : String(s) }]
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
function ve(t, e) {
|
|
465
|
+
return t.length <= e ? { text: t, truncated: !1 } : { text: `${t.slice(0, e)}...`, truncated: !0 };
|
|
466
|
+
}
|
|
467
|
+
function M(t, e, s = !1) {
|
|
468
|
+
return {
|
|
469
|
+
content_kind: "generic_text",
|
|
470
|
+
strategy: {
|
|
471
|
+
type: "dynamic",
|
|
472
|
+
script: Se[t] || '#{ action: "project", text: head(text, 2000) }'
|
|
473
|
+
},
|
|
474
|
+
original_chars: Array.from(e).length,
|
|
475
|
+
truncated_by_tool: s
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
function $(t) {
|
|
479
|
+
const { text: e, truncated: s } = ve(t.text, ke);
|
|
480
|
+
return {
|
|
481
|
+
tag: t.tag,
|
|
482
|
+
text: e,
|
|
483
|
+
textTruncated: s,
|
|
484
|
+
attributes: t.attributes,
|
|
485
|
+
visible: t.visible,
|
|
486
|
+
selector: t.selector
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
function Re(t, e, s) {
|
|
490
|
+
let o = t;
|
|
491
|
+
e && (o = o.filter((i) => i.level === e));
|
|
492
|
+
const r = s ?? 50, n = o.length > r, a = o.slice(-r);
|
|
493
|
+
return {
|
|
494
|
+
entries: a.map((i) => ({
|
|
495
|
+
level: i.level,
|
|
496
|
+
args: i.args,
|
|
497
|
+
timestamp: i.timestamp
|
|
498
|
+
})),
|
|
499
|
+
count: a.length,
|
|
500
|
+
totalAvailable: o.length,
|
|
501
|
+
truncated: n
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
function T(t, e) {
|
|
505
|
+
const s = JSON.stringify(t(), null, 2);
|
|
506
|
+
return {
|
|
507
|
+
content: [{ type: "text", text: s }],
|
|
508
|
+
details: M(e, s, !1)
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
function Ae(t, e) {
|
|
512
|
+
switch (S("browser").info("Executing browser tool", { toolName: t.name }), t.name) {
|
|
513
|
+
case "browser_get_page": {
|
|
514
|
+
const o = e.getPage(), r = JSON.stringify(
|
|
515
|
+
{
|
|
516
|
+
url: o.url,
|
|
517
|
+
title: o.title,
|
|
518
|
+
readyState: o.readyState,
|
|
519
|
+
focusedElement: o.focusedElement ? $(o.focusedElement) : null
|
|
520
|
+
},
|
|
521
|
+
null,
|
|
522
|
+
2
|
|
523
|
+
);
|
|
524
|
+
return {
|
|
525
|
+
content: [{ type: "text", text: r }],
|
|
526
|
+
details: M("browser_get_page", r, !1)
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
case "browser_eval_js": {
|
|
530
|
+
const o = k(t.arguments, "source");
|
|
531
|
+
if (typeof o != "string" || o.length === 0)
|
|
532
|
+
throw new Error("source must be a non-empty string");
|
|
533
|
+
return T(() => ({ ok: !0, result: e.evalJs(o) }), "browser_eval_js");
|
|
534
|
+
}
|
|
535
|
+
case "browser_query_selector": {
|
|
536
|
+
const o = k(t.arguments, "selector"), r = re(t.arguments, "all");
|
|
537
|
+
if (!o)
|
|
538
|
+
throw new Error("selector is required");
|
|
539
|
+
return T(() => {
|
|
540
|
+
if (r) {
|
|
541
|
+
const a = e.querySelectorAll(o);
|
|
542
|
+
return {
|
|
543
|
+
selector: o,
|
|
544
|
+
matchCount: a.length,
|
|
545
|
+
elements: a.map($)
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
const n = e.querySelector(o);
|
|
549
|
+
return { selector: o, found: n ? $(n) : null };
|
|
550
|
+
}, "browser_query_selector");
|
|
551
|
+
}
|
|
552
|
+
case "browser_click": {
|
|
553
|
+
const o = k(t.arguments, "selector");
|
|
554
|
+
if (!o)
|
|
555
|
+
throw new Error("selector is required");
|
|
556
|
+
return T(() => {
|
|
557
|
+
const r = e.click(o);
|
|
558
|
+
if (!r.ok)
|
|
559
|
+
throw new Error(r.error.message);
|
|
560
|
+
return { ok: !0, action: "click", selector: o };
|
|
561
|
+
}, "browser_click");
|
|
562
|
+
}
|
|
563
|
+
case "browser_type": {
|
|
564
|
+
const o = k(t.arguments, "selector"), r = k(t.arguments, "text");
|
|
565
|
+
if (!o)
|
|
566
|
+
throw new Error("selector is required");
|
|
567
|
+
if (typeof r != "string")
|
|
568
|
+
throw new Error("text must be a string");
|
|
569
|
+
return T(() => {
|
|
570
|
+
const n = e.type(o, r);
|
|
571
|
+
if (!n.ok)
|
|
572
|
+
throw new Error(n.error.message);
|
|
573
|
+
return {
|
|
574
|
+
ok: !0,
|
|
575
|
+
action: "type",
|
|
576
|
+
selector: o,
|
|
577
|
+
textLength: r.length
|
|
578
|
+
};
|
|
579
|
+
}, "browser_type");
|
|
580
|
+
}
|
|
581
|
+
case "browser_console": {
|
|
582
|
+
const o = k(t.arguments, "level"), r = ne(t.arguments, "limit"), n = e.getConsole(), a = Re(n, o, r), i = JSON.stringify(a, null, 2);
|
|
583
|
+
return {
|
|
584
|
+
content: [{ type: "text", text: i }],
|
|
585
|
+
details: M("browser_console", i, !1)
|
|
586
|
+
};
|
|
587
|
+
}
|
|
588
|
+
default:
|
|
589
|
+
throw new Error(`no browser tool handler for: ${t.name}`);
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
function ot(t) {
|
|
593
|
+
const e = S("browser"), s = t ?? new ae();
|
|
594
|
+
e.info("Browser tools initialized");
|
|
595
|
+
const o = {};
|
|
596
|
+
for (const n of N)
|
|
597
|
+
o[n.name] = (a) => Ae(a, s);
|
|
598
|
+
return {
|
|
599
|
+
definitions: N.map((n) => ({
|
|
600
|
+
name: n.name,
|
|
601
|
+
description: n.description,
|
|
602
|
+
inputSchema: n.parameters,
|
|
603
|
+
run: (a) => {
|
|
604
|
+
const i = o[n.name];
|
|
605
|
+
return i ? i({ id: "", name: n.name, arguments: a }) : null;
|
|
606
|
+
}
|
|
607
|
+
})),
|
|
608
|
+
getHandler(n) {
|
|
609
|
+
const a = o[n];
|
|
610
|
+
return a ? async (i) => await a({ id: "", name: n, arguments: i }) : null;
|
|
611
|
+
}
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
const Te = {
|
|
615
|
+
type: "object",
|
|
616
|
+
properties: {
|
|
617
|
+
artifact_id: {
|
|
618
|
+
type: "string",
|
|
619
|
+
description: "The artifact id to retrieve (e.g. tool-result-abc123)."
|
|
620
|
+
}
|
|
621
|
+
},
|
|
622
|
+
required: ["artifact_id"],
|
|
623
|
+
additionalProperties: !1
|
|
624
|
+
}, Ce = 50, Ee = {
|
|
625
|
+
type: "object",
|
|
626
|
+
properties: {
|
|
627
|
+
pattern: {
|
|
628
|
+
type: "string",
|
|
629
|
+
description: "Text pattern to search for inside stored artifacts."
|
|
630
|
+
}
|
|
631
|
+
},
|
|
632
|
+
required: ["pattern"],
|
|
633
|
+
additionalProperties: !1
|
|
634
|
+
}, je = {
|
|
635
|
+
name: "artifact_read",
|
|
636
|
+
label: "Read Artifact",
|
|
637
|
+
description: "Read the full original text of a previously stored artifact by its id. Use this when a projected tool result references an artifact you need to inspect.",
|
|
638
|
+
parameters: Te,
|
|
639
|
+
execution_mode: "parallel"
|
|
640
|
+
}, Oe = {
|
|
641
|
+
name: "artifact_search",
|
|
642
|
+
label: "Search Artifacts",
|
|
643
|
+
description: "Search all stored artifacts for a text pattern. Returns up to 50 matching artifact ids, a short snippet around the first match, and the match count. Use artifact_read to retrieve the full text.",
|
|
644
|
+
parameters: Ee,
|
|
645
|
+
execution_mode: "parallel"
|
|
646
|
+
}, Ie = [je, Oe];
|
|
647
|
+
function $e(t, e, s) {
|
|
648
|
+
return {
|
|
649
|
+
artifact_read: D(async (o) => {
|
|
650
|
+
const r = k(o.arguments, "artifact_id");
|
|
651
|
+
if (typeof r != "string" || r.length === 0)
|
|
652
|
+
throw new Error("artifact_id must be a non-empty string");
|
|
653
|
+
let n;
|
|
654
|
+
if (e && s) {
|
|
655
|
+
const a = s();
|
|
656
|
+
a ? n = await e.load(a, r) ?? "" : n = "";
|
|
657
|
+
} else
|
|
658
|
+
n = "";
|
|
659
|
+
if (n === "")
|
|
660
|
+
throw new Error(`artifact not found: ${r}`);
|
|
661
|
+
return {
|
|
662
|
+
content: [{ type: "text", text: n }]
|
|
663
|
+
};
|
|
664
|
+
}),
|
|
665
|
+
artifact_search: D(async (o) => {
|
|
666
|
+
const r = k(o.arguments, "pattern");
|
|
667
|
+
if (typeof r != "string" || r.length === 0)
|
|
668
|
+
throw new Error("pattern must be a non-empty string");
|
|
669
|
+
let n;
|
|
670
|
+
if (e && s) {
|
|
671
|
+
const l = s();
|
|
672
|
+
l ? n = await e.search(l, r) : n = [];
|
|
673
|
+
} else
|
|
674
|
+
n = [];
|
|
675
|
+
const a = n.slice(0, Ce);
|
|
676
|
+
return {
|
|
677
|
+
content: [{ type: "text", text: JSON.stringify(
|
|
678
|
+
a.map((l) => ({
|
|
679
|
+
id: l.id,
|
|
680
|
+
snippet: l.snippet,
|
|
681
|
+
match_count: l.match_count
|
|
682
|
+
})),
|
|
683
|
+
null,
|
|
684
|
+
2
|
|
685
|
+
) }]
|
|
686
|
+
};
|
|
687
|
+
})
|
|
688
|
+
};
|
|
689
|
+
}
|
|
690
|
+
class Pe {
|
|
691
|
+
/**
|
|
692
|
+
* Build a WASM ToolMap from AgentTools packs.
|
|
693
|
+
* Artifact tools are wired with the store at build time.
|
|
694
|
+
*/
|
|
695
|
+
build(e, s, o) {
|
|
696
|
+
const r = {}, n = /* @__PURE__ */ new Set();
|
|
697
|
+
for (const i of e)
|
|
698
|
+
for (const l of i.definitions) {
|
|
699
|
+
if (n.has(l.name))
|
|
700
|
+
throw _("tool_duplicate", `Duplicate tool name: ${l.name}`, { recoverable: !1 });
|
|
701
|
+
n.add(l.name);
|
|
702
|
+
const c = i.getHandler(l.name);
|
|
703
|
+
c && (r[l.name] = async (d) => {
|
|
704
|
+
let u;
|
|
705
|
+
if (l.inputSchema && z(l.inputSchema)) {
|
|
706
|
+
const g = l.inputSchema.safeParse(d.arguments);
|
|
707
|
+
if (!g.success)
|
|
708
|
+
throw new G("tool_input_invalid", `Invalid input: ${g.error.message}`);
|
|
709
|
+
u = g.data;
|
|
710
|
+
} else
|
|
711
|
+
u = d.arguments;
|
|
712
|
+
const f = await c(u);
|
|
713
|
+
if (Me(f))
|
|
714
|
+
return f;
|
|
715
|
+
const m = {
|
|
716
|
+
content: [{ type: "text", text: typeof f == "string" ? f : JSON.stringify(f, null, 2) }]
|
|
717
|
+
};
|
|
718
|
+
return l.details && (m.details = l.details(f)), m;
|
|
719
|
+
});
|
|
720
|
+
}
|
|
721
|
+
if (e.some(
|
|
722
|
+
(i) => i.definitions.some((l) => l.name === "artifact_read" || l.name === "artifact_search")
|
|
723
|
+
)) {
|
|
724
|
+
const i = $e(
|
|
725
|
+
() => 0,
|
|
726
|
+
s,
|
|
727
|
+
() => o
|
|
728
|
+
);
|
|
729
|
+
for (const [l, c] of Object.entries(i)) {
|
|
730
|
+
if (n.has(l))
|
|
731
|
+
throw _("tool_duplicate", `Duplicate tool name: ${l}`, { recoverable: !1 });
|
|
732
|
+
r[l] = c;
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
return r;
|
|
736
|
+
}
|
|
737
|
+
/**
|
|
738
|
+
* Convert AgentToolDefinition[] to WASM ToolDefinition[] for the LLM.
|
|
739
|
+
* Uses zod-to-json-schema for Zod schemas; passes plain objects through.
|
|
740
|
+
*/
|
|
741
|
+
getLlmTools(e) {
|
|
742
|
+
const s = [], o = /* @__PURE__ */ new Set();
|
|
743
|
+
for (const r of e)
|
|
744
|
+
for (const n of r.definitions) {
|
|
745
|
+
if (o.has(n.name))
|
|
746
|
+
throw _("tool_duplicate", `Duplicate tool name: ${n.name}`, { recoverable: !1 });
|
|
747
|
+
o.add(n.name);
|
|
748
|
+
let a;
|
|
749
|
+
if (z(n.inputSchema)) {
|
|
750
|
+
const i = te(n.inputSchema, { name: n.name });
|
|
751
|
+
a = v(i) ? i : { type: "object", properties: {} };
|
|
752
|
+
} else v(n.inputSchema) ? a = n.inputSchema : a = { type: "object", properties: {} };
|
|
753
|
+
s.push({
|
|
754
|
+
name: n.name,
|
|
755
|
+
label: n.name,
|
|
756
|
+
description: n.description,
|
|
757
|
+
parameters: a,
|
|
758
|
+
execution_mode: "parallel"
|
|
759
|
+
});
|
|
760
|
+
}
|
|
761
|
+
return s;
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
function Me(t) {
|
|
765
|
+
return typeof t == "object" && t !== null && "content" in t && Array.isArray(t.content);
|
|
766
|
+
}
|
|
767
|
+
function z(t) {
|
|
768
|
+
var e, s;
|
|
769
|
+
return typeof t == "object" && t !== null && "_def" in t && typeof t._def == "object" && !!((s = (e = t._def) == null ? void 0 : e.typeName) != null && s.startsWith("Zod"));
|
|
770
|
+
}
|
|
771
|
+
function q(t) {
|
|
772
|
+
return typeof t == "string" ? t : JSON.stringify(t) ?? "";
|
|
773
|
+
}
|
|
774
|
+
function Le(t) {
|
|
775
|
+
try {
|
|
776
|
+
return JSON.parse(t);
|
|
777
|
+
} catch {
|
|
778
|
+
return t;
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
function L(t) {
|
|
782
|
+
switch (t) {
|
|
783
|
+
case "tool_call":
|
|
784
|
+
return "tool_use";
|
|
785
|
+
case "length":
|
|
786
|
+
return "max_tokens";
|
|
787
|
+
case "error":
|
|
788
|
+
return "error";
|
|
789
|
+
default:
|
|
790
|
+
return "end_turn";
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
function Ne(t, e, s) {
|
|
794
|
+
let o = "";
|
|
795
|
+
const r = /* @__PURE__ */ new Map();
|
|
796
|
+
let n = "end", a, i, l, c;
|
|
797
|
+
const d = new Promise((p) => {
|
|
798
|
+
c = p;
|
|
799
|
+
}), u = {
|
|
800
|
+
[Symbol.asyncIterator]: async function* () {
|
|
801
|
+
try {
|
|
802
|
+
for await (const p of t) {
|
|
803
|
+
if (e.aborted) return;
|
|
804
|
+
switch (p.type) {
|
|
805
|
+
case "start": {
|
|
806
|
+
yield { kind: "start", ...p.payload };
|
|
807
|
+
break;
|
|
808
|
+
}
|
|
809
|
+
case "text_delta": {
|
|
810
|
+
const m = p.payload;
|
|
811
|
+
o += m, yield { kind: "text_delta", text: m };
|
|
812
|
+
break;
|
|
813
|
+
}
|
|
814
|
+
case "tool_call_delta": {
|
|
815
|
+
const m = p.payload, h = r.get(m.id), g = q(m.arguments ?? m.delta ?? "");
|
|
816
|
+
r.set(m.id, {
|
|
817
|
+
id: m.id,
|
|
818
|
+
name: m.name || (h == null ? void 0 : h.name) || "",
|
|
819
|
+
arguments: ((h == null ? void 0 : h.arguments) ?? "") + g
|
|
820
|
+
}), yield {
|
|
821
|
+
kind: "tool_call_delta",
|
|
822
|
+
tool_call_id: m.id,
|
|
823
|
+
delta: { type: "string", value: g }
|
|
824
|
+
};
|
|
825
|
+
break;
|
|
826
|
+
}
|
|
827
|
+
case "done": {
|
|
828
|
+
const m = p.payload;
|
|
829
|
+
a = m.model, i = m.usage, m.usage && (s.usage = m.usage), n = m.stopReason;
|
|
830
|
+
for (const h of m.content)
|
|
831
|
+
h.type === "tool_call" && r.set(h.id, {
|
|
832
|
+
id: h.id,
|
|
833
|
+
name: h.name,
|
|
834
|
+
arguments: q(h.arguments)
|
|
835
|
+
});
|
|
836
|
+
break;
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
} catch (p) {
|
|
841
|
+
l = p;
|
|
842
|
+
} finally {
|
|
843
|
+
c();
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
}, f = (async () => {
|
|
847
|
+
if (await d, l)
|
|
848
|
+
return {
|
|
849
|
+
Err: {
|
|
850
|
+
error: {
|
|
851
|
+
code: "stream_error",
|
|
852
|
+
message: l instanceof Error ? l.message : String(l)
|
|
853
|
+
},
|
|
854
|
+
aborted: !1
|
|
855
|
+
}
|
|
856
|
+
};
|
|
857
|
+
const p = [];
|
|
858
|
+
o && p.push({ type: "text", text: o });
|
|
859
|
+
for (const m of r.values())
|
|
860
|
+
p.push({
|
|
861
|
+
type: "tool_call",
|
|
862
|
+
id: m.id,
|
|
863
|
+
name: m.name,
|
|
864
|
+
arguments: Le(m.arguments)
|
|
865
|
+
});
|
|
866
|
+
return {
|
|
867
|
+
Ok: {
|
|
868
|
+
content: p,
|
|
869
|
+
api: "sdk",
|
|
870
|
+
provider: "sdk",
|
|
871
|
+
model: a ?? "sdk-model",
|
|
872
|
+
stop_reason: L(n),
|
|
873
|
+
error_message: L(n) === "error" ? "Model returned an error stop reason" : void 0,
|
|
874
|
+
timestamp: Date.now(),
|
|
875
|
+
usage: {
|
|
876
|
+
input: (i == null ? void 0 : i.input) ?? 0,
|
|
877
|
+
output: (i == null ? void 0 : i.output) ?? 0,
|
|
878
|
+
cache_read: (i == null ? void 0 : i.cache_read) ?? 0,
|
|
879
|
+
cache_write: (i == null ? void 0 : i.cache_write) ?? 0,
|
|
880
|
+
total_tokens: (i == null ? void 0 : i.total_tokens) ?? 0
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
};
|
|
884
|
+
})();
|
|
885
|
+
return { chunks: u, result: f };
|
|
886
|
+
}
|
|
887
|
+
function De(t, e) {
|
|
888
|
+
var r, n, a, i, l;
|
|
889
|
+
const s = {
|
|
890
|
+
[Symbol.asyncIterator]: async function* () {
|
|
891
|
+
var c, d, u, f, p;
|
|
892
|
+
if (!e.aborted) {
|
|
893
|
+
yield {
|
|
894
|
+
kind: "start",
|
|
895
|
+
content: [{ type: "text", text: "" }],
|
|
896
|
+
api: "sdk",
|
|
897
|
+
provider: "sdk",
|
|
898
|
+
model: t.model ?? "sdk-model",
|
|
899
|
+
stop_reason: "end_turn",
|
|
900
|
+
error_message: void 0,
|
|
901
|
+
timestamp: Date.now(),
|
|
902
|
+
usage: {
|
|
903
|
+
input: ((c = t.usage) == null ? void 0 : c.input) ?? 0,
|
|
904
|
+
output: ((d = t.usage) == null ? void 0 : d.output) ?? 0,
|
|
905
|
+
cache_read: ((u = t.usage) == null ? void 0 : u.cache_read) ?? 0,
|
|
906
|
+
cache_write: ((f = t.usage) == null ? void 0 : f.cache_write) ?? 0,
|
|
907
|
+
total_tokens: ((p = t.usage) == null ? void 0 : p.total_tokens) ?? 0
|
|
908
|
+
}
|
|
909
|
+
};
|
|
910
|
+
for (const m of t.content) {
|
|
911
|
+
if (e.aborted) return;
|
|
912
|
+
if (m.type === "text" && m.text) {
|
|
913
|
+
const h = m.text.split(/(\s+)/);
|
|
914
|
+
for (const g of h) {
|
|
915
|
+
if (e.aborted) return;
|
|
916
|
+
g && (yield { kind: "text_delta", text: g }, await new Promise((y) => setTimeout(y, 10)));
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
}, o = Promise.resolve({
|
|
923
|
+
Ok: {
|
|
924
|
+
content: t.content.map((c) => c.type === "text" ? { type: "text", text: c.text } : c.type === "tool_call" ? { type: "tool_call", id: c.id, name: c.name, arguments: c.arguments } : { type: "text", text: "" }),
|
|
925
|
+
api: "sdk",
|
|
926
|
+
provider: "sdk",
|
|
927
|
+
model: t.model ?? "sdk-model",
|
|
928
|
+
stop_reason: L(t.stopReason),
|
|
929
|
+
error_message: t.stopReason === "error" ? "Model returned an error stop reason" : void 0,
|
|
930
|
+
timestamp: Date.now(),
|
|
931
|
+
usage: {
|
|
932
|
+
input: ((r = t.usage) == null ? void 0 : r.input) ?? 0,
|
|
933
|
+
output: ((n = t.usage) == null ? void 0 : n.output) ?? 0,
|
|
934
|
+
cache_read: ((a = t.usage) == null ? void 0 : a.cache_read) ?? 0,
|
|
935
|
+
cache_write: ((i = t.usage) == null ? void 0 : i.cache_write) ?? 0,
|
|
936
|
+
total_tokens: ((l = t.usage) == null ? void 0 : l.total_tokens) ?? 0
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
});
|
|
940
|
+
return { chunks: s, result: o };
|
|
941
|
+
}
|
|
942
|
+
async function ze(t, e, s) {
|
|
943
|
+
const o = {
|
|
944
|
+
instructions: "Summarize the following conversation context concisely. Preserve key facts, decisions, and action items. Omit redundant details.",
|
|
945
|
+
messages: P(e),
|
|
946
|
+
tools: [],
|
|
947
|
+
signal: s
|
|
948
|
+
};
|
|
949
|
+
return (await t.generate(o)).content.filter((a) => a.type === "text").map((a) => a.text).join(`
|
|
950
|
+
`) || "[Context summarized]";
|
|
951
|
+
}
|
|
952
|
+
async function qe(t, e) {
|
|
953
|
+
const s = t.logger ?? S("engine");
|
|
954
|
+
let o;
|
|
955
|
+
if (t.store) {
|
|
956
|
+
const r = await t.store.loadSession(t.sessionId);
|
|
957
|
+
r && (o = new J().deserialize(r), o ? s.info("Session snapshot loaded", { sessionId: t.sessionId }) : s.warn("Session snapshot version mismatch, starting fresh", { sessionId: t.sessionId }));
|
|
958
|
+
}
|
|
959
|
+
return F(t, o);
|
|
960
|
+
}
|
|
961
|
+
function Be(t) {
|
|
962
|
+
t.destroy();
|
|
963
|
+
}
|
|
964
|
+
async function Je(t, e, s, o, r, n) {
|
|
965
|
+
const a = e.logger ?? S("engine"), i = K(s), l = new oe(), c = l.createRunState(), d = new Pe(), u = Q(e.tools), f = X(e), p = d.build(u, f, e.sessionId), m = d.getLlmTools(u);
|
|
966
|
+
a.info("Running agent turn", {
|
|
967
|
+
sessionId: e.sessionId,
|
|
968
|
+
toolCount: m.length,
|
|
969
|
+
messageLength: typeof s == "string" ? s.length : s.text.length
|
|
970
|
+
});
|
|
971
|
+
const h = {
|
|
972
|
+
call: async (g, y) => {
|
|
973
|
+
const x = y || r;
|
|
974
|
+
n.onStatus({ state: "calling_model", message: "Calling model..." }), a.info("Calling model", { model: e.model.id ?? "custom" });
|
|
975
|
+
const w = {
|
|
976
|
+
instructions: g.system_prompt,
|
|
977
|
+
messages: P(g.messages),
|
|
978
|
+
tools: m.map((j) => ({
|
|
979
|
+
name: j.name,
|
|
980
|
+
description: j.description,
|
|
981
|
+
inputSchema: j.parameters,
|
|
982
|
+
run: () => null
|
|
983
|
+
})),
|
|
984
|
+
signal: x,
|
|
985
|
+
metadata: ee(s, o == null ? void 0 : o.metadata)
|
|
986
|
+
};
|
|
987
|
+
if (e.model.generateStream)
|
|
988
|
+
return a.debug("Using streaming model"), Ne(
|
|
989
|
+
e.model.generateStream(w, x),
|
|
990
|
+
x,
|
|
991
|
+
c
|
|
992
|
+
);
|
|
993
|
+
a.debug("Using non-streaming model");
|
|
994
|
+
const R = await e.model.generate(w);
|
|
995
|
+
return R.usage && (c.usage = R.usage, a.info("Model usage", { usage: R.usage })), De(R, x);
|
|
996
|
+
},
|
|
997
|
+
summarize: e.model.summarize ? async (g, y) => {
|
|
998
|
+
var w, R;
|
|
999
|
+
a.info("Calling model summarizer");
|
|
1000
|
+
const x = P(g);
|
|
1001
|
+
return (R = (w = e.model).summarize) == null ? void 0 : R.call(w, x, y);
|
|
1002
|
+
} : async (g, y) => (a.info("Using default summarizer"), ze(e.model, g, y))
|
|
1003
|
+
};
|
|
1004
|
+
try {
|
|
1005
|
+
const g = await V(t, i, {
|
|
1006
|
+
llm: h,
|
|
1007
|
+
tools: p,
|
|
1008
|
+
llmTools: m,
|
|
1009
|
+
logger: a,
|
|
1010
|
+
onEvent: (y) => {
|
|
1011
|
+
const x = l.map(y, c);
|
|
1012
|
+
for (const w of x)
|
|
1013
|
+
n.onEvent(w);
|
|
1014
|
+
},
|
|
1015
|
+
onMarkers: (y) => {
|
|
1016
|
+
const x = l.processMarkers(y, c);
|
|
1017
|
+
for (const w of x)
|
|
1018
|
+
n.onEvent(w);
|
|
1019
|
+
},
|
|
1020
|
+
onPersist: async (y) => {
|
|
1021
|
+
if (n.onStatus({ state: "saving", message: "Saving session..." }), a.info("Persisting session", { sessionId: e.sessionId }), e.store) {
|
|
1022
|
+
const w = new J().serialize(y);
|
|
1023
|
+
await e.store.saveSession(e.sessionId, w), a.info("Session saved", { sessionId: e.sessionId });
|
|
1024
|
+
}
|
|
1025
|
+
n.onStatus({ state: "completed" });
|
|
1026
|
+
},
|
|
1027
|
+
artifactStore: f,
|
|
1028
|
+
prepareToolCalls: e.prepareToolCalls,
|
|
1029
|
+
signal: r
|
|
1030
|
+
});
|
|
1031
|
+
return g.aborted ? (a.info("Turn aborted"), n.onStatus({ state: "aborted", message: "Stopped by user" })) : a.info("Turn completed", { status: "completed" }), l.buildRunResult(c, g);
|
|
1032
|
+
} catch (g) {
|
|
1033
|
+
throw a.error("Turn failed", { error: g instanceof Error ? g.message : String(g) }), g;
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
async function We(t, e) {
|
|
1037
|
+
const s = typeof e == "string" ? e : e.text;
|
|
1038
|
+
t.steer({
|
|
1039
|
+
role: "user",
|
|
1040
|
+
content: [{ type: "text", text: s }],
|
|
1041
|
+
timestamp: Date.now()
|
|
1042
|
+
});
|
|
1043
|
+
}
|
|
1044
|
+
async function Ue(t) {
|
|
1045
|
+
Y(Z(t.handle));
|
|
1046
|
+
}
|
|
1047
|
+
class nt {
|
|
1048
|
+
constructor(e) {
|
|
1049
|
+
b(this, "config");
|
|
1050
|
+
b(this, "emitter");
|
|
1051
|
+
b(this, "status", { state: "idle" });
|
|
1052
|
+
b(this, "currentRun", null);
|
|
1053
|
+
b(this, "currentAbortController", null);
|
|
1054
|
+
b(this, "disposed", !1);
|
|
1055
|
+
b(this, "engineAgent", null);
|
|
1056
|
+
b(this, "logger");
|
|
1057
|
+
this.config = e, this.emitter = new se(), this.logger = e.logger ?? S("agent");
|
|
1058
|
+
}
|
|
1059
|
+
on(e, s) {
|
|
1060
|
+
return this.disposed ? () => {
|
|
1061
|
+
} : this.emitter.on(e, s);
|
|
1062
|
+
}
|
|
1063
|
+
async run(e, s) {
|
|
1064
|
+
if (this.disposed) {
|
|
1065
|
+
this.logger.warn("Run called on disposed agent");
|
|
1066
|
+
const n = _("agent_disposed", "Agent has been disposed", { recoverable: !1 }), a = {
|
|
1067
|
+
status: "failed",
|
|
1068
|
+
text: "",
|
|
1069
|
+
toolCalls: [],
|
|
1070
|
+
artifacts: [],
|
|
1071
|
+
error: n
|
|
1072
|
+
};
|
|
1073
|
+
return this.emitter.emit("error", n), this.emitter.emit("status", { state: "failed", message: n.message }), this.emitter.emit("done", a), a;
|
|
1074
|
+
}
|
|
1075
|
+
if (this.currentRun) {
|
|
1076
|
+
this.logger.warn("Run called while agent is busy");
|
|
1077
|
+
const n = _("agent_busy", "Agent is already running a turn", { recoverable: !0 }), a = {
|
|
1078
|
+
status: "failed",
|
|
1079
|
+
text: "",
|
|
1080
|
+
toolCalls: [],
|
|
1081
|
+
artifacts: [],
|
|
1082
|
+
error: n
|
|
1083
|
+
};
|
|
1084
|
+
return this.emitter.emit("error", n), this.emitter.emit("status", { state: "failed", message: n.message }), this.emitter.emit("done", a), a;
|
|
1085
|
+
}
|
|
1086
|
+
const o = new AbortController();
|
|
1087
|
+
this.currentAbortController = o, this.logger.info("Starting run", { sessionId: this.config.sessionId }), s != null && s.signal && (s.signal.aborted ? o.abort(s.signal.reason) : s.signal.addEventListener(
|
|
1088
|
+
"abort",
|
|
1089
|
+
() => {
|
|
1090
|
+
var n;
|
|
1091
|
+
o.abort((n = s.signal) == null ? void 0 : n.reason);
|
|
1092
|
+
},
|
|
1093
|
+
{ once: !0 }
|
|
1094
|
+
));
|
|
1095
|
+
const r = this._doRun(e, s, o.signal);
|
|
1096
|
+
this.currentRun = r;
|
|
1097
|
+
try {
|
|
1098
|
+
const n = await r;
|
|
1099
|
+
return this.logger.info("Run completed", { status: n.status }), this.emitter.emit("done", n), n;
|
|
1100
|
+
} catch (n) {
|
|
1101
|
+
this.logger.error("Run failed", { error: n instanceof Error ? n.message : String(n) });
|
|
1102
|
+
const a = _("internal_error", n instanceof Error ? n.message : String(n), {
|
|
1103
|
+
cause: n,
|
|
1104
|
+
recoverable: !1
|
|
1105
|
+
}), i = {
|
|
1106
|
+
status: "failed",
|
|
1107
|
+
text: "",
|
|
1108
|
+
toolCalls: [],
|
|
1109
|
+
artifacts: [],
|
|
1110
|
+
error: a
|
|
1111
|
+
};
|
|
1112
|
+
return this.emitter.emit("error", a), this.emitter.emit("status", { state: "failed", message: a.message }), this.emitter.emit("done", i), i;
|
|
1113
|
+
} finally {
|
|
1114
|
+
this.currentRun = null, this.currentAbortController = null;
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
async _doRun(e, s, o) {
|
|
1118
|
+
this.engineAgent || (this.engineAgent = await qe(this.config));
|
|
1119
|
+
try {
|
|
1120
|
+
return await Je(this.engineAgent, this.config, e, s, o, {
|
|
1121
|
+
onEvent: (r) => this.emitter.emit(r.type, r.payload),
|
|
1122
|
+
onStatus: (r) => {
|
|
1123
|
+
this.status = r, this.emitter.emit("status", r);
|
|
1124
|
+
}
|
|
1125
|
+
});
|
|
1126
|
+
} catch (r) {
|
|
1127
|
+
if (o.aborted || r instanceof Error && r.name === "AbortError" || r instanceof Error && r.message.includes("user_aborted")) {
|
|
1128
|
+
const c = {
|
|
1129
|
+
status: "aborted",
|
|
1130
|
+
text: "",
|
|
1131
|
+
toolCalls: [],
|
|
1132
|
+
artifacts: []
|
|
1133
|
+
};
|
|
1134
|
+
return this.emitter.emit("status", {
|
|
1135
|
+
state: "aborted",
|
|
1136
|
+
message: "Stopped by user"
|
|
1137
|
+
}), c;
|
|
1138
|
+
}
|
|
1139
|
+
const a = r instanceof Error && "code" in r && typeof r.code == "string" ? r.code : "internal_error", i = _(a, r instanceof Error ? r.message : String(r), {
|
|
1140
|
+
cause: r,
|
|
1141
|
+
recoverable: !1
|
|
1142
|
+
}), l = {
|
|
1143
|
+
status: "failed",
|
|
1144
|
+
text: "",
|
|
1145
|
+
toolCalls: [],
|
|
1146
|
+
artifacts: [],
|
|
1147
|
+
error: i
|
|
1148
|
+
};
|
|
1149
|
+
return this.emitter.emit("error", i), this.emitter.emit("status", { state: "failed", message: i.message }), l;
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
stop(e) {
|
|
1153
|
+
this.disposed || !this.currentAbortController || (this.logger.info("Stopping agent", { reason: e ?? "user-requested" }), this.currentAbortController.abort(e ?? "user-requested"));
|
|
1154
|
+
}
|
|
1155
|
+
async steer(e) {
|
|
1156
|
+
if (this.disposed)
|
|
1157
|
+
throw this.logger.warn("Steer called on disposed agent"), _("agent_disposed", "Agent has been disposed", { recoverable: !1 });
|
|
1158
|
+
if (!this.engineAgent)
|
|
1159
|
+
throw this.logger.warn("Steer called on uninitialized agent"), _("agent_not_initialized", "Agent has not been run yet", { recoverable: !0 });
|
|
1160
|
+
return this.logger.info("Steering agent", { sessionId: this.config.sessionId }), We(this.engineAgent, e);
|
|
1161
|
+
}
|
|
1162
|
+
async reset() {
|
|
1163
|
+
if (this.disposed)
|
|
1164
|
+
throw this.logger.warn("Reset called on disposed agent"), _("agent_disposed", "Agent has been disposed", { recoverable: !1 });
|
|
1165
|
+
this.logger.info("Resetting agent", { sessionId: this.config.sessionId }), this.engineAgent && (await Ue(this.engineAgent), this.engineAgent = null), this.currentRun = null, this.currentAbortController = null, this.status = { state: "idle" }, this.emitter.emit("status", this.status);
|
|
1166
|
+
}
|
|
1167
|
+
dispose() {
|
|
1168
|
+
this.disposed || (this.logger.info("Disposing agent", { sessionId: this.config.sessionId }), this.disposed = !0, this.currentAbortController && (this.currentAbortController.abort("disposed"), this.currentAbortController = null), this.engineAgent && (Be(this.engineAgent), this.engineAgent = null), this.emitter.clear(), this.currentRun = null);
|
|
1169
|
+
}
|
|
1170
|
+
getStatus() {
|
|
1171
|
+
return this.status;
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
function He(t) {
|
|
1175
|
+
const e = [];
|
|
1176
|
+
let s = 0;
|
|
1177
|
+
for (; s < t.length; ) {
|
|
1178
|
+
const o = t[s];
|
|
1179
|
+
switch (o.role) {
|
|
1180
|
+
case "user": {
|
|
1181
|
+
const r = B(o.content);
|
|
1182
|
+
e.push({ role: "user", content: r }), s++;
|
|
1183
|
+
break;
|
|
1184
|
+
}
|
|
1185
|
+
case "assistant": {
|
|
1186
|
+
const r = [];
|
|
1187
|
+
for (const n of o.content)
|
|
1188
|
+
n.type === "text" && n.text !== void 0 ? r.push({ type: "text", text: n.text }) : n.type === "tool_call" && n.id && n.name && r.push({
|
|
1189
|
+
type: "tool_use",
|
|
1190
|
+
id: n.id,
|
|
1191
|
+
name: n.name,
|
|
1192
|
+
input: n.arguments ?? {}
|
|
1193
|
+
});
|
|
1194
|
+
e.push({ role: "assistant", content: r }), s++;
|
|
1195
|
+
break;
|
|
1196
|
+
}
|
|
1197
|
+
case "tool_result": {
|
|
1198
|
+
const r = [];
|
|
1199
|
+
for (; s < t.length && t[s].role === "tool_result"; ) {
|
|
1200
|
+
const n = t[s], a = B(n.content);
|
|
1201
|
+
r.push({
|
|
1202
|
+
type: "tool_result",
|
|
1203
|
+
tool_use_id: n.tool_call_id,
|
|
1204
|
+
content: a,
|
|
1205
|
+
is_error: n.is_error
|
|
1206
|
+
}), s++;
|
|
1207
|
+
}
|
|
1208
|
+
e.push({ role: "user", content: r });
|
|
1209
|
+
break;
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
return e;
|
|
1214
|
+
}
|
|
1215
|
+
function Ge(t) {
|
|
1216
|
+
return t.map((e) => ({
|
|
1217
|
+
name: e.name,
|
|
1218
|
+
description: `${e.label}: ${e.description}`,
|
|
1219
|
+
input_schema: e.parameters
|
|
1220
|
+
}));
|
|
1221
|
+
}
|
|
1222
|
+
function Fe(t, e, s) {
|
|
1223
|
+
const o = [];
|
|
1224
|
+
for (const l of t.content)
|
|
1225
|
+
l.type === "text" ? o.push({ type: "text", text: l.text }) : l.type === "tool_use" && o.push({
|
|
1226
|
+
type: "tool_call",
|
|
1227
|
+
id: l.id,
|
|
1228
|
+
name: l.name,
|
|
1229
|
+
arguments: l.input
|
|
1230
|
+
});
|
|
1231
|
+
const r = t.stop_reason === "tool_use" ? "tool_use" : "end_turn", n = {
|
|
1232
|
+
input: t.usage.input_tokens,
|
|
1233
|
+
output: t.usage.output_tokens,
|
|
1234
|
+
cache_read: t.usage.cache_read_input_tokens ?? 0,
|
|
1235
|
+
cache_write: t.usage.cache_creation_input_tokens ?? 0,
|
|
1236
|
+
total_tokens: t.usage.input_tokens + t.usage.output_tokens
|
|
1237
|
+
}, a = {
|
|
1238
|
+
content: o,
|
|
1239
|
+
api: e,
|
|
1240
|
+
provider: e,
|
|
1241
|
+
model: s,
|
|
1242
|
+
stop_reason: r,
|
|
1243
|
+
error_message: null,
|
|
1244
|
+
timestamp: Date.now(),
|
|
1245
|
+
usage: n
|
|
1246
|
+
}, i = [];
|
|
1247
|
+
i.push({
|
|
1248
|
+
kind: "start",
|
|
1249
|
+
content: [{ type: "text", text: "" }],
|
|
1250
|
+
api: e,
|
|
1251
|
+
provider: e,
|
|
1252
|
+
model: s,
|
|
1253
|
+
stop_reason: r,
|
|
1254
|
+
error_message: null,
|
|
1255
|
+
timestamp: 0,
|
|
1256
|
+
usage: {
|
|
1257
|
+
input: 0,
|
|
1258
|
+
output: 0,
|
|
1259
|
+
cache_read: 0,
|
|
1260
|
+
cache_write: 0,
|
|
1261
|
+
total_tokens: 0
|
|
1262
|
+
}
|
|
1263
|
+
});
|
|
1264
|
+
for (const l of t.content)
|
|
1265
|
+
l.type === "text" && l.text.length > 0 && i.push({ kind: "text_delta", text: l.text });
|
|
1266
|
+
return {
|
|
1267
|
+
llmResult: { Ok: a },
|
|
1268
|
+
chunks: i
|
|
1269
|
+
};
|
|
1270
|
+
}
|
|
1271
|
+
async function Ke(t, e) {
|
|
1272
|
+
var c;
|
|
1273
|
+
const s = [], o = "anthropic", r = {
|
|
1274
|
+
model: e.model,
|
|
1275
|
+
max_tokens: e.maxTokens ?? 4096,
|
|
1276
|
+
system: t.system_prompt,
|
|
1277
|
+
messages: He(t.messages),
|
|
1278
|
+
tools: Ge(t.tools)
|
|
1279
|
+
};
|
|
1280
|
+
s.push(`anthropic_request: model=${e.model}, messages=${r.messages.length}, tools=${r.tools.length}`);
|
|
1281
|
+
let n;
|
|
1282
|
+
try {
|
|
1283
|
+
n = await fetch(`${e.baseUrl}/v1/messages`, {
|
|
1284
|
+
method: "POST",
|
|
1285
|
+
headers: {
|
|
1286
|
+
"Content-Type": "application/json",
|
|
1287
|
+
"x-api-key": e.apiKey,
|
|
1288
|
+
"anthropic-version": "2023-06-01"
|
|
1289
|
+
},
|
|
1290
|
+
body: JSON.stringify(r)
|
|
1291
|
+
});
|
|
1292
|
+
} catch (d) {
|
|
1293
|
+
const u = d instanceof Error ? d.message : String(d);
|
|
1294
|
+
return s.push(`anthropic_network_error: ${u}`), {
|
|
1295
|
+
llmResult: {
|
|
1296
|
+
Err: { error: { code: "network_error", message: u }, aborted: !1 }
|
|
1297
|
+
},
|
|
1298
|
+
chunks: [],
|
|
1299
|
+
log: s
|
|
1300
|
+
};
|
|
1301
|
+
}
|
|
1302
|
+
if (!n.ok) {
|
|
1303
|
+
let d = null;
|
|
1304
|
+
try {
|
|
1305
|
+
d = await n.json();
|
|
1306
|
+
} catch {
|
|
1307
|
+
}
|
|
1308
|
+
const u = `http_${n.status}`, f = ((c = d == null ? void 0 : d.error) == null ? void 0 : c.message) ?? `HTTP ${n.status}: ${n.statusText}`;
|
|
1309
|
+
return s.push(`anthropic_error: ${u} - ${f}`), {
|
|
1310
|
+
llmResult: {
|
|
1311
|
+
Err: { error: { code: u, message: f }, aborted: !1 }
|
|
1312
|
+
},
|
|
1313
|
+
chunks: [],
|
|
1314
|
+
log: s
|
|
1315
|
+
};
|
|
1316
|
+
}
|
|
1317
|
+
const a = await n.json();
|
|
1318
|
+
s.push(`anthropic_response: stop_reason=${a.stop_reason}, content_blocks=${a.content.length}`);
|
|
1319
|
+
const { llmResult: i, chunks: l } = Fe(a, o, e.model);
|
|
1320
|
+
return { llmResult: i, chunks: l, log: s };
|
|
1321
|
+
}
|
|
1322
|
+
function rt(t) {
|
|
1323
|
+
const e = S("anthropic"), s = {
|
|
1324
|
+
apiKey: t.apiKey,
|
|
1325
|
+
baseUrl: t.baseUrl ?? "https://api.anthropic.com",
|
|
1326
|
+
model: t.model,
|
|
1327
|
+
maxTokens: t.maxTokens
|
|
1328
|
+
};
|
|
1329
|
+
return {
|
|
1330
|
+
id: t.model,
|
|
1331
|
+
contextWindow: 2e5,
|
|
1332
|
+
maxTokens: t.maxTokens ?? 4096,
|
|
1333
|
+
capabilities: {
|
|
1334
|
+
vision: t.model.includes("vision") || t.model.startsWith("claude-3-5"),
|
|
1335
|
+
jsonMode: !0,
|
|
1336
|
+
functionCalling: !0,
|
|
1337
|
+
streaming: !0
|
|
1338
|
+
},
|
|
1339
|
+
async generate(o) {
|
|
1340
|
+
e.info("Anthropic generate", { model: t.model, messageCount: o.messages.length });
|
|
1341
|
+
const r = {
|
|
1342
|
+
system_prompt: o.instructions,
|
|
1343
|
+
messages: o.messages.map((n) => {
|
|
1344
|
+
var l, c, d;
|
|
1345
|
+
const a = n.content.map((u) => u.type === "text" ? { type: "text", text: u.text } : u.type === "tool_call" ? { type: "tool_call", id: u.id, name: u.name, arguments: v(u.arguments) ? u.arguments : {} } : u.type === "image" ? { type: "image", media_type: u.mimeType, data: u.data } : { type: "text", text: "" }), i = n.timestamp ?? Date.now();
|
|
1346
|
+
return n.role === "user" ? { role: "user", content: a, timestamp: i } : n.role === "assistant" ? {
|
|
1347
|
+
role: "assistant",
|
|
1348
|
+
content: a,
|
|
1349
|
+
api: "sdk",
|
|
1350
|
+
provider: "sdk",
|
|
1351
|
+
model: ((l = o.tools[0]) == null ? void 0 : l.name) ?? "sdk-model",
|
|
1352
|
+
stop_reason: "end_turn",
|
|
1353
|
+
error_message: null,
|
|
1354
|
+
timestamp: i,
|
|
1355
|
+
usage: { input: 0, output: 0, cache_read: 0, cache_write: 0, total_tokens: 0 }
|
|
1356
|
+
} : {
|
|
1357
|
+
role: "tool_result",
|
|
1358
|
+
tool_call_id: n.tool_call_id ?? "",
|
|
1359
|
+
tool_name: ((d = (c = n.content.find((u) => u.type === "text")) == null ? void 0 : c.text) == null ? void 0 : d.slice(0, 50)) ?? "unknown",
|
|
1360
|
+
content: a,
|
|
1361
|
+
details: {},
|
|
1362
|
+
is_error: !1,
|
|
1363
|
+
timestamp: i
|
|
1364
|
+
};
|
|
1365
|
+
}),
|
|
1366
|
+
tools: o.tools.map((n) => ({
|
|
1367
|
+
name: n.name,
|
|
1368
|
+
label: n.name,
|
|
1369
|
+
description: n.description,
|
|
1370
|
+
parameters: v(n.inputSchema) ? n.inputSchema : { type: "object", properties: {} },
|
|
1371
|
+
execution_mode: "parallel"
|
|
1372
|
+
}))
|
|
1373
|
+
};
|
|
1374
|
+
try {
|
|
1375
|
+
const n = await Ke(r, s);
|
|
1376
|
+
if ("Err" in n.llmResult) {
|
|
1377
|
+
const i = n.llmResult.Err.error;
|
|
1378
|
+
throw e.warn("Anthropic API error", { code: i.code, message: i.message }), _(
|
|
1379
|
+
i.code === "network_error" ? "model_unavailable" : i.code.startsWith("http_401") ? "model_auth_failed" : i.code.startsWith("http_429") ? "model_rate_limited" : "model_unavailable",
|
|
1380
|
+
i.message,
|
|
1381
|
+
{ recoverable: i.code === "http_429" }
|
|
1382
|
+
);
|
|
1383
|
+
}
|
|
1384
|
+
const a = n.llmResult.Ok;
|
|
1385
|
+
return e.info("Anthropic response", { stopReason: a.stop_reason, contentBlocks: a.content.length }), {
|
|
1386
|
+
content: a.content.map((i) => i.type === "text" ? { type: "text", text: i.text ?? "" } : i.type === "tool_call" ? { type: "tool_call", id: i.id ?? "", name: i.name ?? "", arguments: i.arguments ?? {} } : { type: "text", text: "" }),
|
|
1387
|
+
stopReason: a.stop_reason === "tool_use" ? "tool_call" : "end",
|
|
1388
|
+
usage: a.usage,
|
|
1389
|
+
model: t.model,
|
|
1390
|
+
raw: n
|
|
1391
|
+
};
|
|
1392
|
+
} catch (n) {
|
|
1393
|
+
throw n && typeof n == "object" && "code" in n ? n : (e.error("Anthropic request failed", { error: n instanceof Error ? n.message : String(n) }), _("model_unavailable", n instanceof Error ? n.message : String(n), {
|
|
1394
|
+
cause: n,
|
|
1395
|
+
recoverable: !1
|
|
1396
|
+
}));
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
};
|
|
1400
|
+
}
|
|
1401
|
+
function B(t) {
|
|
1402
|
+
return t.filter((e) => e.type === "text" && e.text !== void 0).map((e) => e.text).join(`
|
|
1403
|
+
`);
|
|
1404
|
+
}
|
|
1405
|
+
function Qe(t) {
|
|
1406
|
+
const e = S("openai");
|
|
1407
|
+
return {
|
|
1408
|
+
id: t.model,
|
|
1409
|
+
contextWindow: 128e3,
|
|
1410
|
+
maxTokens: t.maxTokens ?? 4096,
|
|
1411
|
+
capabilities: {
|
|
1412
|
+
vision: t.model.includes("vision") || t.model.includes("gpt-4o"),
|
|
1413
|
+
jsonMode: !0,
|
|
1414
|
+
functionCalling: !0,
|
|
1415
|
+
streaming: !0
|
|
1416
|
+
},
|
|
1417
|
+
async generate(s) {
|
|
1418
|
+
var a, i;
|
|
1419
|
+
e.info("OpenAI generate", { model: t.model, messageCount: s.messages.length });
|
|
1420
|
+
const o = s.messages.map((l) => {
|
|
1421
|
+
switch (l.role) {
|
|
1422
|
+
case "user":
|
|
1423
|
+
return { role: "user", content: l.content.filter((d) => d.type === "text").map((d) => d.text).join(`
|
|
1424
|
+
`) };
|
|
1425
|
+
case "assistant": {
|
|
1426
|
+
const c = l.content.filter((u) => u.type === "text").map((u) => u.text).join(""), d = l.content.filter(
|
|
1427
|
+
(u) => u.type === "tool_call"
|
|
1428
|
+
).map((u) => ({
|
|
1429
|
+
id: u.id,
|
|
1430
|
+
type: "function",
|
|
1431
|
+
function: {
|
|
1432
|
+
name: u.name,
|
|
1433
|
+
arguments: JSON.stringify(u.arguments)
|
|
1434
|
+
}
|
|
1435
|
+
}));
|
|
1436
|
+
return {
|
|
1437
|
+
role: "assistant",
|
|
1438
|
+
content: c || null,
|
|
1439
|
+
tool_calls: d.length > 0 ? d : void 0
|
|
1440
|
+
};
|
|
1441
|
+
}
|
|
1442
|
+
case "tool_result": {
|
|
1443
|
+
const c = l.content.filter((d) => d.type === "text").map((d) => d.text).join(`
|
|
1444
|
+
`);
|
|
1445
|
+
return {
|
|
1446
|
+
role: "tool",
|
|
1447
|
+
tool_call_id: l.tool_call_id ?? "",
|
|
1448
|
+
content: c
|
|
1449
|
+
};
|
|
1450
|
+
}
|
|
1451
|
+
default:
|
|
1452
|
+
return { role: "user", content: "" };
|
|
1453
|
+
}
|
|
1454
|
+
}), r = s.tools.map((l) => ({
|
|
1455
|
+
type: "function",
|
|
1456
|
+
function: {
|
|
1457
|
+
name: l.name,
|
|
1458
|
+
description: l.description,
|
|
1459
|
+
parameters: v(l.inputSchema) ? l.inputSchema : { type: "object", properties: {} }
|
|
1460
|
+
}
|
|
1461
|
+
})), n = {
|
|
1462
|
+
model: t.model,
|
|
1463
|
+
messages: o,
|
|
1464
|
+
tools: r.length > 0 ? r : void 0,
|
|
1465
|
+
max_tokens: t.maxTokens
|
|
1466
|
+
};
|
|
1467
|
+
try {
|
|
1468
|
+
const l = await fetch(`${t.baseUrl.replace(/\/+$/, "")}/v1/chat/completions`, {
|
|
1469
|
+
method: "POST",
|
|
1470
|
+
headers: {
|
|
1471
|
+
"Content-Type": "application/json",
|
|
1472
|
+
Authorization: `Bearer ${t.apiKey}`
|
|
1473
|
+
},
|
|
1474
|
+
body: JSON.stringify(n),
|
|
1475
|
+
signal: s.signal
|
|
1476
|
+
});
|
|
1477
|
+
if (!l.ok) {
|
|
1478
|
+
const p = l.status, m = await l.text();
|
|
1479
|
+
throw e.warn("OpenAI API error", { status: p, body: m.slice(0, 500) }), _(
|
|
1480
|
+
p === 401 ? "model_auth_failed" : p === 429 ? "model_rate_limited" : "model_unavailable",
|
|
1481
|
+
`HTTP ${p}: ${m}`,
|
|
1482
|
+
{ recoverable: p === 429 }
|
|
1483
|
+
);
|
|
1484
|
+
}
|
|
1485
|
+
const c = await l.json(), d = (a = c.choices) == null ? void 0 : a[0], u = d == null ? void 0 : d.message;
|
|
1486
|
+
e.info("OpenAI response", { finishReason: d == null ? void 0 : d.finish_reason, model: c.model });
|
|
1487
|
+
const f = [];
|
|
1488
|
+
if (u != null && u.content && typeof u.content == "string" && f.push({ type: "text", text: u.content }), u != null && u.tool_calls && Array.isArray(u.tool_calls))
|
|
1489
|
+
for (const p of u.tool_calls)
|
|
1490
|
+
p.type === "function" && f.push({
|
|
1491
|
+
type: "tool_call",
|
|
1492
|
+
id: p.id ?? "",
|
|
1493
|
+
name: ((i = p.function) == null ? void 0 : i.name) ?? "",
|
|
1494
|
+
arguments: (() => {
|
|
1495
|
+
var m;
|
|
1496
|
+
try {
|
|
1497
|
+
return JSON.parse(((m = p.function) == null ? void 0 : m.arguments) ?? "{}");
|
|
1498
|
+
} catch {
|
|
1499
|
+
return {};
|
|
1500
|
+
}
|
|
1501
|
+
})()
|
|
1502
|
+
});
|
|
1503
|
+
return {
|
|
1504
|
+
content: f,
|
|
1505
|
+
stopReason: (d == null ? void 0 : d.finish_reason) === "tool_calls" ? "tool_call" : (d == null ? void 0 : d.finish_reason) === "stop" ? "end" : (d == null ? void 0 : d.finish_reason) === "length" ? "length" : "error",
|
|
1506
|
+
usage: c.usage ? {
|
|
1507
|
+
input: c.usage.prompt_tokens,
|
|
1508
|
+
output: c.usage.completion_tokens,
|
|
1509
|
+
cache_read: 0,
|
|
1510
|
+
cache_write: 0,
|
|
1511
|
+
total_tokens: c.usage.total_tokens
|
|
1512
|
+
} : void 0,
|
|
1513
|
+
model: t.model,
|
|
1514
|
+
raw: c
|
|
1515
|
+
};
|
|
1516
|
+
} catch (l) {
|
|
1517
|
+
throw l && typeof l == "object" && "code" in l ? l : (e.error("OpenAI request failed", { error: l instanceof Error ? l.message : String(l) }), _("model_unavailable", l instanceof Error ? l.message : String(l), {
|
|
1518
|
+
cause: l,
|
|
1519
|
+
recoverable: !1
|
|
1520
|
+
}));
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
};
|
|
1524
|
+
}
|
|
1525
|
+
function at(t) {
|
|
1526
|
+
return Qe({
|
|
1527
|
+
apiKey: t.apiKey,
|
|
1528
|
+
baseUrl: "https://api.openai.com",
|
|
1529
|
+
model: t.model,
|
|
1530
|
+
maxTokens: t.maxTokens
|
|
1531
|
+
});
|
|
1532
|
+
}
|
|
1533
|
+
function it() {
|
|
1534
|
+
return {
|
|
1535
|
+
definitions: Ie.map((e) => ({
|
|
1536
|
+
name: e.name,
|
|
1537
|
+
description: e.description,
|
|
1538
|
+
inputSchema: e.parameters,
|
|
1539
|
+
run: () => {
|
|
1540
|
+
throw new Error("artifactTools handlers are wired at build time by ToolRegistryBuilder");
|
|
1541
|
+
}
|
|
1542
|
+
})),
|
|
1543
|
+
getHandler() {
|
|
1544
|
+
return null;
|
|
1545
|
+
}
|
|
1546
|
+
};
|
|
1547
|
+
}
|
|
1548
|
+
function lt(t) {
|
|
1549
|
+
var e, s, o, r;
|
|
1550
|
+
return {
|
|
1551
|
+
id: t.id ?? "custom-model",
|
|
1552
|
+
contextWindow: t.contextWindow ?? 1e5,
|
|
1553
|
+
maxTokens: t.maxTokens ?? 4096,
|
|
1554
|
+
capabilities: {
|
|
1555
|
+
vision: ((e = t.capabilities) == null ? void 0 : e.vision) ?? !1,
|
|
1556
|
+
jsonMode: ((s = t.capabilities) == null ? void 0 : s.jsonMode) ?? !0,
|
|
1557
|
+
functionCalling: ((o = t.capabilities) == null ? void 0 : o.functionCalling) ?? !0,
|
|
1558
|
+
streaming: ((r = t.capabilities) == null ? void 0 : r.streaming) ?? !0
|
|
1559
|
+
},
|
|
1560
|
+
generate: t.generate,
|
|
1561
|
+
generateStream: t.generateStream,
|
|
1562
|
+
summarize: t.summarize
|
|
1563
|
+
};
|
|
1564
|
+
}
|
|
1565
|
+
const Xe = "pi-oxide-browser-agent", Ve = 3, A = "sessions";
|
|
1566
|
+
class Ye {
|
|
1567
|
+
constructor() {
|
|
1568
|
+
b(this, "dbPromise");
|
|
1569
|
+
this.dbPromise = this.openDB();
|
|
1570
|
+
}
|
|
1571
|
+
openDB() {
|
|
1572
|
+
return new Promise((e, s) => {
|
|
1573
|
+
const o = indexedDB.open(Xe, Ve);
|
|
1574
|
+
o.onupgradeneeded = () => {
|
|
1575
|
+
const r = o.result;
|
|
1576
|
+
r.objectStoreNames.contains("session") && r.deleteObjectStore("session"), r.objectStoreNames.contains("artifacts") && r.deleteObjectStore("artifacts"), r.objectStoreNames.contains(A) || r.createObjectStore(A, { keyPath: "sessionId" });
|
|
1577
|
+
}, o.onsuccess = () => e(o.result), o.onerror = () => s(o.error);
|
|
1578
|
+
});
|
|
1579
|
+
}
|
|
1580
|
+
async save(e, s) {
|
|
1581
|
+
const o = await this.dbPromise;
|
|
1582
|
+
return new Promise((r, n) => {
|
|
1583
|
+
const a = o.transaction(A, "readwrite");
|
|
1584
|
+
a.objectStore(A).put({
|
|
1585
|
+
sessionId: e,
|
|
1586
|
+
state: s,
|
|
1587
|
+
updatedAt: Date.now()
|
|
1588
|
+
}), a.oncomplete = () => r(), a.onerror = () => n(a.error);
|
|
1589
|
+
});
|
|
1590
|
+
}
|
|
1591
|
+
async load(e) {
|
|
1592
|
+
const s = await this.dbPromise;
|
|
1593
|
+
return new Promise((o, r) => {
|
|
1594
|
+
const a = s.transaction(A, "readonly").objectStore(A).get(e);
|
|
1595
|
+
a.onsuccess = () => {
|
|
1596
|
+
const i = a.result;
|
|
1597
|
+
o((i == null ? void 0 : i.state) ?? null);
|
|
1598
|
+
}, a.onerror = () => r(a.error);
|
|
1599
|
+
});
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
function Ze() {
|
|
1603
|
+
const t = new Ye();
|
|
1604
|
+
return {
|
|
1605
|
+
async loadSession(e) {
|
|
1606
|
+
const s = await t.load(e);
|
|
1607
|
+
return s ? { version: 1, data: s } : null;
|
|
1608
|
+
},
|
|
1609
|
+
async saveSession(e, s) {
|
|
1610
|
+
await t.save(e, s.data);
|
|
1611
|
+
}
|
|
1612
|
+
// Artifact methods are not supported by the raw IndexedDBSessionBackend.
|
|
1613
|
+
// If artifact support is needed, use a store that implements them.
|
|
1614
|
+
};
|
|
1615
|
+
}
|
|
1616
|
+
function ct() {
|
|
1617
|
+
return Ze();
|
|
1618
|
+
}
|
|
1619
|
+
function ut() {
|
|
1620
|
+
const t = /* @__PURE__ */ new Map();
|
|
1621
|
+
return {
|
|
1622
|
+
async loadSession(e) {
|
|
1623
|
+
return t.get(e) ?? null;
|
|
1624
|
+
},
|
|
1625
|
+
async saveSession(e, s) {
|
|
1626
|
+
t.set(e, s);
|
|
1627
|
+
}
|
|
1628
|
+
};
|
|
1629
|
+
}
|
|
1630
|
+
function dt() {
|
|
1631
|
+
return {
|
|
1632
|
+
async loadSession(t) {
|
|
1633
|
+
const e = localStorage.getItem(`pi-oxide-session-${t}`);
|
|
1634
|
+
return e ? JSON.parse(e) : null;
|
|
1635
|
+
},
|
|
1636
|
+
async saveSession(t, e) {
|
|
1637
|
+
localStorage.setItem(`pi-oxide-session-${t}`, JSON.stringify(e));
|
|
1638
|
+
}
|
|
1639
|
+
};
|
|
1640
|
+
}
|
|
1641
|
+
function mt(t) {
|
|
1642
|
+
const e = t.baseUrl.replace(/\/+$/, "");
|
|
1643
|
+
return {
|
|
1644
|
+
async loadSession(s) {
|
|
1645
|
+
const o = await fetch(`${e}/sessions/${s}`);
|
|
1646
|
+
return o.ok ? o.json() : null;
|
|
1647
|
+
},
|
|
1648
|
+
async saveSession(s, o) {
|
|
1649
|
+
await fetch(`${e}/sessions/${s}`, {
|
|
1650
|
+
method: "PUT",
|
|
1651
|
+
headers: { "Content-Type": "application/json" },
|
|
1652
|
+
body: JSON.stringify(o)
|
|
1653
|
+
});
|
|
1654
|
+
}
|
|
1655
|
+
};
|
|
1656
|
+
}
|
|
1657
|
+
function pt(t) {
|
|
1658
|
+
return {
|
|
1659
|
+
name: "",
|
|
1660
|
+
description: t.description,
|
|
1661
|
+
inputSchema: t.input,
|
|
1662
|
+
run: t.run,
|
|
1663
|
+
details: t.details ? t.details : void 0
|
|
1664
|
+
};
|
|
1665
|
+
}
|
|
1666
|
+
function gt(t) {
|
|
1667
|
+
const e = Object.entries(t).map(([s, o]) => ({
|
|
1668
|
+
...o,
|
|
1669
|
+
name: s
|
|
1670
|
+
}));
|
|
1671
|
+
return {
|
|
1672
|
+
definitions: e,
|
|
1673
|
+
getHandler(s) {
|
|
1674
|
+
const o = e.find((r) => r.name === s);
|
|
1675
|
+
return (o == null ? void 0 : o.run) ?? null;
|
|
1676
|
+
}
|
|
1677
|
+
};
|
|
1678
|
+
}
|
|
1679
|
+
export {
|
|
1680
|
+
nt as Agent,
|
|
1681
|
+
_t as CallbackLogger,
|
|
1682
|
+
yt as ConsoleLogger,
|
|
1683
|
+
G as HostError,
|
|
1684
|
+
bt as NoopLogger,
|
|
1685
|
+
rt as anthropic,
|
|
1686
|
+
it as artifactTools,
|
|
1687
|
+
ot as browserTools,
|
|
1688
|
+
xt as clearLoggers,
|
|
1689
|
+
_ as createAgentError,
|
|
1690
|
+
lt as defineModel,
|
|
1691
|
+
gt as defineTools,
|
|
1692
|
+
wt as ensureInit,
|
|
1693
|
+
St as getGlobalLogLevel,
|
|
1694
|
+
S as getLogger,
|
|
1695
|
+
mt as httpStore,
|
|
1696
|
+
ct as indexedDbStore,
|
|
1697
|
+
dt as localStorageStore,
|
|
1698
|
+
ut as memoryStore,
|
|
1699
|
+
at as openai,
|
|
1700
|
+
Qe as openaiCompatible,
|
|
1701
|
+
kt as setGlobalLogLevel,
|
|
1702
|
+
vt as setLogger,
|
|
1703
|
+
pt as tool,
|
|
1704
|
+
Rt as toolResult,
|
|
1705
|
+
Y as unwrap
|
|
1706
|
+
};
|