@dudko.dev/agent-web 0.0.43 → 0.0.45
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/README.md +56 -3
- package/dist/agent-web.js +167 -161
- package/dist/agent-web.js.map +1 -1
- package/dist/{chunk-DAREMCXF.js → chunk-236RCVAZ.js} +40 -8
- package/dist/chunk-236RCVAZ.js.map +1 -0
- package/dist/{chunk-2MLHZ6LQ.js → chunk-Y4MIIBPB.js} +2 -2
- package/dist/{chunk-ZSZSSJS4.js → chunk-Y6CD3WOK.js} +176 -10
- package/dist/chunk-Y6CD3WOK.js.map +1 -0
- package/dist/{chunk-YPCHD6DV.js → chunk-YGWIOO27.js} +31 -12
- package/dist/chunk-YGWIOO27.js.map +1 -0
- package/dist/index.cjs +1300 -171
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1794 -1466
- package/dist/index.d.ts +1794 -1466
- package/dist/index.js +1044 -145
- package/dist/index.js.map +1 -1
- package/dist/mcp.cjs +136 -5
- package/dist/mcp.cjs.map +1 -1
- package/dist/mcp.d.cts +5 -2
- package/dist/mcp.d.ts +5 -2
- package/dist/mcp.js +19 -8
- package/dist/mcp.js.map +1 -1
- package/dist/{sandbox-3VRX47UY.js → sandbox-7CGSIIIZ.js} +4 -4
- package/dist/sandbox-worker.cjs +30 -11
- package/dist/sandbox-worker.cjs.map +1 -1
- package/dist/sandbox-worker.js +1 -1
- package/dist/{elicitation-DS-84_bF.d.cts → vault-Mar2CY0J.d.cts} +526 -526
- package/dist/{elicitation-DS-84_bF.d.ts → vault-Mar2CY0J.d.ts} +526 -526
- package/package.json +1 -1
- package/dist/chunk-DAREMCXF.js.map +0 -1
- package/dist/chunk-YPCHD6DV.js.map +0 -1
- package/dist/chunk-ZSZSSJS4.js.map +0 -1
- /package/dist/{chunk-2MLHZ6LQ.js.map → chunk-Y4MIIBPB.js.map} +0 -0
- /package/dist/{sandbox-3VRX47UY.js.map → sandbox-7CGSIIIZ.js.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
getOrCreateVaultKey,
|
|
12
12
|
mcpAppOrigin,
|
|
13
13
|
renderMcpInstructions
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-Y4MIIBPB.js";
|
|
15
15
|
import {
|
|
16
16
|
AttachmentsNotSupportedError,
|
|
17
17
|
ContextWindowExceededError,
|
|
@@ -95,7 +95,7 @@ import {
|
|
|
95
95
|
toolRunContextOf,
|
|
96
96
|
withDeadline,
|
|
97
97
|
wrapToolsForRun
|
|
98
|
-
} from "./chunk-
|
|
98
|
+
} from "./chunk-236RCVAZ.js";
|
|
99
99
|
import {
|
|
100
100
|
FILES_STORE,
|
|
101
101
|
KEYS_STORE,
|
|
@@ -117,13 +117,21 @@ import {
|
|
|
117
117
|
RUNS_STORE,
|
|
118
118
|
SECRETS_STORE,
|
|
119
119
|
SESSIONS_STORE,
|
|
120
|
+
STORAGE_CHANGE_KINDS,
|
|
121
|
+
SYNC_ID_RE,
|
|
122
|
+
SYNC_VERSION,
|
|
120
123
|
assignAddedMcpSkillName,
|
|
121
124
|
assignMcpSkillNames,
|
|
122
125
|
collectMcpSkillSources,
|
|
123
126
|
createMcpSkillRunConsent,
|
|
124
127
|
createMcpSkillSnapshotMemory,
|
|
128
|
+
currentTab,
|
|
125
129
|
decideMcpSkillConsent,
|
|
130
|
+
heldExclusively,
|
|
131
|
+
hubOf,
|
|
126
132
|
isMcpSkillName,
|
|
133
|
+
isRecord,
|
|
134
|
+
lockManager,
|
|
127
135
|
mcpSkillBodyText,
|
|
128
136
|
mcpSkillConsentOf,
|
|
129
137
|
mcpSkillConsentView,
|
|
@@ -137,15 +145,20 @@ import {
|
|
|
137
145
|
mcpSkillPreamble,
|
|
138
146
|
mcpSkillRoomRefusal,
|
|
139
147
|
mcpSkillUriRefusal,
|
|
148
|
+
newSyncId,
|
|
149
|
+
onStorageChange,
|
|
140
150
|
openAgentWebDB,
|
|
151
|
+
postStorageChange,
|
|
152
|
+
postStorageChangeFrom,
|
|
141
153
|
recordMcpSkillConsent,
|
|
142
154
|
resolveMcpSkillConsent,
|
|
143
155
|
resolveMcpSkillPath,
|
|
144
156
|
resolveMcpSkillServer,
|
|
157
|
+
scopeOf,
|
|
145
158
|
selectMcpSkills,
|
|
146
159
|
skillDirectoryListing,
|
|
147
160
|
skillDirectoryOf
|
|
148
|
-
} from "./chunk-
|
|
161
|
+
} from "./chunk-Y6CD3WOK.js";
|
|
149
162
|
|
|
150
163
|
// src/caching.ts
|
|
151
164
|
var resolveCaching = (s) => {
|
|
@@ -252,6 +265,16 @@ var BUDGET_SHARES = {
|
|
|
252
265
|
compaction: { num: 1, den: 125, min: 256, max: 4096 }
|
|
253
266
|
};
|
|
254
267
|
var share = (window, s) => Math.min(s.max, Math.max(s.min, Math.round(window * s.num / s.den)));
|
|
268
|
+
var reasoningStages = /* @__PURE__ */ new WeakMap();
|
|
269
|
+
var stageReasons = (c, stage) => reasoningStages.get(c)?.has(stage) === true;
|
|
270
|
+
var observeReasoning = (c, stage, contextWindowTokens, finishReason, reasoningTokens) => {
|
|
271
|
+
if (!(typeof reasoningTokens === "number" && reasoningTokens > 0)) return false;
|
|
272
|
+
const cap = stageOutputCap(c, stage, contextWindowTokens);
|
|
273
|
+
const seen = reasoningStages.get(c) ?? /* @__PURE__ */ new Set();
|
|
274
|
+
seen.add(stage);
|
|
275
|
+
reasoningStages.set(c, seen);
|
|
276
|
+
return finishReason === "length" && cap.derived && cap.tokens !== void 0;
|
|
277
|
+
};
|
|
255
278
|
var stageOutputCap = (c, stage, contextWindowTokens) => {
|
|
256
279
|
const set = c.limits?.perCall?.[stage] ?? c.budgets?.[stage];
|
|
257
280
|
if (typeof set === "number" && Number.isFinite(set)) {
|
|
@@ -259,6 +282,7 @@ var stageOutputCap = (c, stage, contextWindowTokens) => {
|
|
|
259
282
|
}
|
|
260
283
|
const thinking = resolveThinking(thinkingFor(stage, c.thinking, c.stageThinking));
|
|
261
284
|
if (thinking.reasoning && thinking.reasoning !== "none") return { derived: false };
|
|
285
|
+
if (stageReasons(c, stage)) return { derived: false };
|
|
262
286
|
return { tokens: share(contextWindowTokens, BUDGET_SHARES[stage]), derived: true };
|
|
263
287
|
};
|
|
264
288
|
var outputCapNotice = (c, stage, contextWindowTokens, finishReason) => {
|
|
@@ -1027,9 +1051,24 @@ var ORIGIN_FILE = ".origin.json";
|
|
|
1027
1051
|
var VfsSkillStore = class {
|
|
1028
1052
|
vfs;
|
|
1029
1053
|
dir;
|
|
1054
|
+
tab;
|
|
1030
1055
|
constructor(vfs, dir = "/skills") {
|
|
1031
1056
|
this.vfs = vfs;
|
|
1032
1057
|
this.dir = dir.replace(/\/+$/, "") || "/skills";
|
|
1058
|
+
this.tab = currentTab();
|
|
1059
|
+
}
|
|
1060
|
+
/** The file system's database (undefined in memory): where its `skills` notices go out. */
|
|
1061
|
+
get dbName() {
|
|
1062
|
+
return this.vfs.dbName;
|
|
1063
|
+
}
|
|
1064
|
+
/** The other tabs hear which lesson, in which folder - never its text. */
|
|
1065
|
+
announce(op, name) {
|
|
1066
|
+
postStorageChangeFrom(this.tab, this.vfs.dbName, {
|
|
1067
|
+
kind: "skills",
|
|
1068
|
+
op,
|
|
1069
|
+
key: name,
|
|
1070
|
+
namespace: this.dir
|
|
1071
|
+
});
|
|
1033
1072
|
}
|
|
1034
1073
|
async list() {
|
|
1035
1074
|
const out = [];
|
|
@@ -1063,12 +1102,14 @@ ${skill.content.trim()}
|
|
|
1063
1102
|
mimeType: "application/json"
|
|
1064
1103
|
});
|
|
1065
1104
|
}
|
|
1105
|
+
this.announce("put", skill.name);
|
|
1066
1106
|
}
|
|
1067
1107
|
async remove(name) {
|
|
1068
1108
|
if (!SKILL_NAME_RE.test(name)) return false;
|
|
1069
1109
|
const folder = `${this.dir}/${name}`;
|
|
1070
1110
|
const had = await this.vfs.delete(`${folder}/SKILL.md`);
|
|
1071
1111
|
await this.vfs.delete(`${folder}/${ORIGIN_FILE}`);
|
|
1112
|
+
if (had) this.announce("delete", name);
|
|
1072
1113
|
return had;
|
|
1073
1114
|
}
|
|
1074
1115
|
};
|
|
@@ -1076,12 +1117,10 @@ var createLearning = async (cfg, skills, warn) => {
|
|
|
1076
1117
|
const store = cfg.store ?? new MemorySkillStore();
|
|
1077
1118
|
const maxSkills = Math.max(1, cfg.maxSkills ?? DEFAULT_MAX_LEARNED_SKILLS);
|
|
1078
1119
|
const maxChars = Math.max(MIN_INSTRUCTIONS_CHARS, cfg.maxSkillChars ?? DEFAULT_MAX_SKILL_CHARS);
|
|
1120
|
+
const lessonOf = (stored) => defineSkill({ ...stored, origin: stored.origin ?? { kind: "learned", at: 0, revision: 1 } });
|
|
1079
1121
|
for (const stored of await store.list()) {
|
|
1080
1122
|
try {
|
|
1081
|
-
const skill =
|
|
1082
|
-
...stored,
|
|
1083
|
-
origin: stored.origin ?? { kind: "learned", at: 0, revision: 1 }
|
|
1084
|
-
});
|
|
1123
|
+
const skill = lessonOf(stored);
|
|
1085
1124
|
if (skills.some((s) => s.name === skill.name)) {
|
|
1086
1125
|
warn(
|
|
1087
1126
|
`[learning] a stored lesson named "${skill.name}" clashes with a configured skill; skipped`
|
|
@@ -1094,6 +1133,27 @@ var createLearning = async (cfg, skills, warn) => {
|
|
|
1094
1133
|
}
|
|
1095
1134
|
}
|
|
1096
1135
|
const learned = () => skills.filter((s) => s.origin?.kind === "learned");
|
|
1136
|
+
const reload = async () => {
|
|
1137
|
+
const fresh = /* @__PURE__ */ new Map();
|
|
1138
|
+
for (const stored of await store.list()) {
|
|
1139
|
+
try {
|
|
1140
|
+
const skill = lessonOf(stored);
|
|
1141
|
+
if (skills.some((s) => s.name === skill.name && s.origin?.kind !== "learned")) continue;
|
|
1142
|
+
fresh.set(skill.name, skill);
|
|
1143
|
+
} catch {
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
for (let i = skills.length - 1; i >= 0; i -= 1) {
|
|
1147
|
+
const s = skills[i];
|
|
1148
|
+
if (s.origin?.kind === "learned" && !fresh.has(s.name)) skills.splice(i, 1);
|
|
1149
|
+
}
|
|
1150
|
+
for (const [name, skill] of fresh) {
|
|
1151
|
+
const at = skills.findIndex((s) => s.name === name);
|
|
1152
|
+
if (at >= 0) skills[at] = skill;
|
|
1153
|
+
else skills.push(skill);
|
|
1154
|
+
}
|
|
1155
|
+
return learned();
|
|
1156
|
+
};
|
|
1097
1157
|
const save = async (input, options) => {
|
|
1098
1158
|
const name = normalizeSkillName(input.name);
|
|
1099
1159
|
if (!name) {
|
|
@@ -1204,7 +1264,7 @@ var createLearning = async (cfg, skills, warn) => {
|
|
|
1204
1264
|
}
|
|
1205
1265
|
})
|
|
1206
1266
|
};
|
|
1207
|
-
return { tools, learned, forget };
|
|
1267
|
+
return { tools, learned, forget, reload };
|
|
1208
1268
|
};
|
|
1209
1269
|
|
|
1210
1270
|
// src/prompts.ts
|
|
@@ -1213,14 +1273,22 @@ var stateBlock = (state) => state && state.trim() ? `
|
|
|
1213
1273
|
|
|
1214
1274
|
STATE:
|
|
1215
1275
|
${state}` : "";
|
|
1216
|
-
var
|
|
1276
|
+
var ATTACHED_MARK = /\n\[attached: [^\]\n]*\]$/;
|
|
1277
|
+
var historyLine = (content, max) => {
|
|
1278
|
+
const mark = ATTACHED_MARK.exec(content)?.[0];
|
|
1279
|
+
if (!mark || content.length <= max) return clip(content, max);
|
|
1280
|
+
return `${clip(content.slice(0, -mark.length), Math.max(1, max - mark.length))}${mark}`;
|
|
1281
|
+
};
|
|
1282
|
+
var historyBlock = (history, perMessage = 400) => {
|
|
1217
1283
|
if (!history || history.length === 0) return "";
|
|
1218
|
-
const lines = history.slice(-8).map((m) => `${m.role}: ${
|
|
1284
|
+
const lines = history.slice(-8).map((m) => `${m.role}: ${historyLine(m.content, perMessage)}`);
|
|
1219
1285
|
return `
|
|
1220
1286
|
|
|
1221
1287
|
CONVERSATION SO FAR:
|
|
1222
1288
|
${lines.join("\n")}`;
|
|
1223
1289
|
};
|
|
1290
|
+
var hasAttachedMark = (content) => ATTACHED_MARK.test(content);
|
|
1291
|
+
var NO_ATTACHMENT_NOTE = `NOTE: nothing is attached to THIS message. The files of earlier messages (marked "[attached: ...]" in the conversation) are not visible to you now - only what was said about them then is. If this message is about a file you cannot see, say so and ask the user to attach it again; never describe a file you cannot see.`;
|
|
1224
1292
|
var section = (title, body) => body && body.trim() ? `
|
|
1225
1293
|
|
|
1226
1294
|
${title}:
|
|
@@ -1249,17 +1317,17 @@ var PLANNER_RULES = `- Act autonomously: whenever the TOOLS can do the work or l
|
|
|
1249
1317
|
- Never repeat or pad steps.`;
|
|
1250
1318
|
var PLANNER_NATIVE = `You are the PLANNER of an autonomous tool-using agent that works step by step.
|
|
1251
1319
|
Produce a brief "thought" and an ordered "steps" list (1\u20136 DISTINCT, self-contained steps).
|
|
1252
|
-
Return an EMPTY steps list ONLY for a pure greeting, thanks or small talk, or a question
|
|
1320
|
+
Return an EMPTY steps list ONLY for a pure greeting, thanks or small talk, or a question that can be answered completely from the conversation, the STATE, what is attached to the message and general knowledge without any tool. Do NOT write the answer yourself: it is written right after you, from the same message. "thought" is your private one-sentence note; the user never sees it.
|
|
1253
1321
|
${PLANNER_RULES}`;
|
|
1254
1322
|
var PLANNER_PROMPTED = `You are the PLANNER of an autonomous tool-using agent that works step by step.
|
|
1255
1323
|
|
|
1256
1324
|
Reply with a single JSON object, nothing else:
|
|
1257
1325
|
{ "reply": string, "plan": string[], "skills": string[] }
|
|
1258
|
-
-
|
|
1259
|
-
- Set "plan": [] ONLY for a pure greeting, thanks or small talk, or a question
|
|
1326
|
+
- "reply" is your private one-sentence note (the user never sees it); for a real goal "plan" is 1\u20136 DISTINCT, self-contained steps.
|
|
1327
|
+
- Set "plan": [] ONLY for a pure greeting, thanks or small talk, or a question that can be answered completely from the conversation, the STATE and general knowledge without any tool. Do NOT write the answer yourself: it is written right after you, from the same message.
|
|
1260
1328
|
${PLANNER_RULES}`;
|
|
1261
1329
|
var PLANNER_SKILLS = `
|
|
1262
|
-
|
|
1330
|
+
"skills" takes names from the SKILLS list ONLY - packaged instructions, not tools: list the ones that apply to this goal, or leave it empty. Never put a name from TOOLS there.`;
|
|
1263
1331
|
var COMPLEXITY_LEVELS = `low = mechanical work (a lookup, one obvious tool call, copying or reformatting data); medium = ordinary work (a few tool calls, some judgement); high = hard work (multi-part reasoning, analysis, writing or fixing code, weighing conflicting data). When unsure between two, choose the higher.`;
|
|
1264
1332
|
var PLANNER_TIERS_NATIVE = `
|
|
1265
1333
|
Steps run on models of different strength: set "complexity" on every step. ${COMPLEXITY_LEVELS}`;
|
|
@@ -1310,6 +1378,13 @@ var SYNTHESIZER_SYSTEM = `You are the SYNTHESIZER. Answer the user's goal from w
|
|
|
1310
1378
|
- Mention any assumption the agent made. If something could not be done, say so plainly and why.
|
|
1311
1379
|
- Do not ask follow-up questions unless the goal genuinely cannot be completed without the user.
|
|
1312
1380
|
- Be concise and friendly. Plain text (light markdown is fine) \u2014 no JSON, no code.`;
|
|
1381
|
+
var SYNTHESIZER_DIRECT = `You are the SYNTHESIZER of an autonomous tool-using agent. The planner found that this message needs no tool, so no tool was run: write the answer to the user yourself.
|
|
1382
|
+
- Answer the message under GOAL from the CONVERSATION SO FAR, the STATE, anything attached to this message and general knowledge.
|
|
1383
|
+
- Nothing was done in this turn: never say that something was looked up, changed or created now. If the message needs an action or data you do not have, say plainly what is missing.
|
|
1384
|
+
- Answer in the language of the user's message. Be concise and friendly. Plain text (light markdown is fine) \u2014 no JSON.`;
|
|
1385
|
+
var DIRECT_HISTORY_CHARS = 2e3;
|
|
1386
|
+
var noteLine = (note) => note && note.trim() ? `
|
|
1387
|
+
${note.trim()}` : "";
|
|
1313
1388
|
var defaultPrompts = {
|
|
1314
1389
|
planner: (ctx) => ({
|
|
1315
1390
|
system: (ctx.mode === "prompted" ? PLANNER_PROMPTED : PLANNER_NATIVE) + (ctx.skills ? PLANNER_SKILLS : "") + (ctx.tiers ? ctx.mode === "prompted" ? PLANNER_TIERS_PROMPTED : PLANNER_TIERS_NATIVE : "") + (ctx.searchMode ? PLANNER_SEARCH : "") + (ctx.sandbox ? `
|
|
@@ -1317,13 +1392,13 @@ ${ctx.sandbox}` : "") + section("HELPERS", ctx.subagents) + section("SKILLS", ct
|
|
|
1317
1392
|
|
|
1318
1393
|
TOOLS:
|
|
1319
1394
|
${ctx.toolCatalog}`,
|
|
1320
|
-
prompt: `GOAL: ${ctx.goal}${historyBlock(ctx.history)}${stateBlock(ctx.state)}`
|
|
1395
|
+
prompt: `GOAL: ${ctx.goal}${noteLine(ctx.attachments)}${historyBlock(ctx.history)}${stateBlock(ctx.state)}`
|
|
1321
1396
|
}),
|
|
1322
1397
|
executor: (ctx) => ({
|
|
1323
1398
|
system: (ctx.mode === "prompted" ? EXECUTOR_PROMPTED : EXECUTOR_NATIVE) + (ctx.searchMode ? EXECUTOR_SEARCH : "") + (ctx.skills ? EXECUTOR_SKILLS : "") + (ctx.learning ? executorLearning(ctx.learning.fetch) : "") + (ctx.sandbox ? `
|
|
1324
1399
|
- ${ctx.sandbox}` : "") + section("HELPERS", ctx.subagents) + section("SKILLS", ctx.skills) + section("ACTIVE SKILL INSTRUCTIONS", ctx.activeSkills),
|
|
1325
1400
|
prompt: [
|
|
1326
|
-
`GOAL: ${ctx.goal}`,
|
|
1401
|
+
`GOAL: ${ctx.goal}${noteLine(ctx.attachments)}`,
|
|
1327
1402
|
stateBlock(ctx.state).trimStart(),
|
|
1328
1403
|
ctx.mode === "prompted" ? `TOOLS:
|
|
1329
1404
|
${ctx.toolCatalog}` : "",
|
|
@@ -1347,10 +1422,16 @@ ${numbered(ctx.remaining, "(none)")}`,
|
|
|
1347
1422
|
].filter(Boolean).join("\n\n")
|
|
1348
1423
|
}),
|
|
1349
1424
|
synthesizer: (ctx) => ({
|
|
1350
|
-
system: SYNTHESIZER_SYSTEM + (ctx.sandbox ? `
|
|
1425
|
+
system: (ctx.direct ? SYNTHESIZER_DIRECT : SYNTHESIZER_SYSTEM) + (ctx.sandbox ? `
|
|
1351
1426
|
- ${ctx.sandbox}` : "") + section("ACTIVE SKILL INSTRUCTIONS", ctx.activeSkills),
|
|
1352
|
-
prompt: [
|
|
1353
|
-
`GOAL: ${ctx.goal}`,
|
|
1427
|
+
prompt: ctx.direct ? [
|
|
1428
|
+
`GOAL: ${ctx.goal}${noteLine(ctx.attachments)}`,
|
|
1429
|
+
historyBlock(ctx.history, DIRECT_HISTORY_CHARS).trimStart(),
|
|
1430
|
+
stateBlock(ctx.state).trimStart(),
|
|
1431
|
+
updatesBlock(ctx.updates, 0, SYNTHESIZER_UPDATES_ADVICE),
|
|
1432
|
+
"Write the answer for the user."
|
|
1433
|
+
].filter(Boolean).join("\n\n") : [
|
|
1434
|
+
`GOAL: ${ctx.goal}${noteLine(ctx.attachments)}`,
|
|
1354
1435
|
stateBlock(ctx.state).trimStart(),
|
|
1355
1436
|
updatesBlock(ctx.updates, 0, SYNTHESIZER_UPDATES_ADVICE),
|
|
1356
1437
|
`What was done:
|
|
@@ -3553,6 +3634,12 @@ var followHumanWaits = (clock) => {
|
|
|
3553
3634
|
|
|
3554
3635
|
// src/agent/control.ts
|
|
3555
3636
|
var ports = /* @__PURE__ */ new WeakMap();
|
|
3637
|
+
var queuedEvent = (m) => ({
|
|
3638
|
+
type: "message.queued",
|
|
3639
|
+
id: m.id,
|
|
3640
|
+
text: m.text,
|
|
3641
|
+
...m.origin ? { origin: m.origin } : {}
|
|
3642
|
+
});
|
|
3556
3643
|
var portOf = (control) => {
|
|
3557
3644
|
if (!control) return void 0;
|
|
3558
3645
|
const port = ports.get(control);
|
|
@@ -3565,15 +3652,20 @@ var createRunControl = () => {
|
|
|
3565
3652
|
let emit;
|
|
3566
3653
|
let ended = false;
|
|
3567
3654
|
const children = /* @__PURE__ */ new Map();
|
|
3655
|
+
const queueMessage = (text, origin) => {
|
|
3656
|
+
const clean = typeof text === "string" ? text.trim() : "";
|
|
3657
|
+
if (!clean || ended) return false;
|
|
3658
|
+
const message = {
|
|
3659
|
+
id: `msg-${seq3 += 1}`,
|
|
3660
|
+
text: clean,
|
|
3661
|
+
...origin ? { origin } : {}
|
|
3662
|
+
};
|
|
3663
|
+
queue.push(message);
|
|
3664
|
+
emit?.(queuedEvent(message));
|
|
3665
|
+
return true;
|
|
3666
|
+
};
|
|
3568
3667
|
const control = {
|
|
3569
|
-
send(text)
|
|
3570
|
-
const clean = typeof text === "string" ? text.trim() : "";
|
|
3571
|
-
if (!clean || ended) return false;
|
|
3572
|
-
const message = { id: `msg-${seq3 += 1}`, text: clean };
|
|
3573
|
-
queue.push(message);
|
|
3574
|
-
emit?.({ type: "message.queued", id: message.id, text: message.text });
|
|
3575
|
-
return true;
|
|
3576
|
-
},
|
|
3668
|
+
send: (text) => queueMessage(text),
|
|
3577
3669
|
pending: () => queue.map((m) => m.text),
|
|
3578
3670
|
subagents: () => [...children.values()].map((c) => c.info).sort((a, b) => a.startedAt - b.startedAt),
|
|
3579
3671
|
stopSubagent(id) {
|
|
@@ -3591,7 +3683,7 @@ var createRunControl = () => {
|
|
|
3591
3683
|
}
|
|
3592
3684
|
emit = next;
|
|
3593
3685
|
ended = false;
|
|
3594
|
-
for (const m of queue) next(
|
|
3686
|
+
for (const m of queue) next(queuedEvent(m));
|
|
3595
3687
|
},
|
|
3596
3688
|
detach() {
|
|
3597
3689
|
emit = void 0;
|
|
@@ -3604,6 +3696,7 @@ var createRunControl = () => {
|
|
|
3604
3696
|
queue = [];
|
|
3605
3697
|
return out;
|
|
3606
3698
|
},
|
|
3699
|
+
sendFrom: (text, origin) => queueMessage(text, origin),
|
|
3607
3700
|
registerSubagent(info, stop) {
|
|
3608
3701
|
children.set(info.id, { info, stop });
|
|
3609
3702
|
return () => {
|
|
@@ -4052,6 +4145,7 @@ var imageRefusal = (ctx, err, model) => {
|
|
|
4052
4145
|
return unsupportedAttachment(modelLabel(model), kind, detail && `the provider said: ${detail}`);
|
|
4053
4146
|
};
|
|
4054
4147
|
var systemFor = (ctx, base) => withSystem(base, ctx.raw.systemPrompt);
|
|
4148
|
+
var aborted = (ctx) => ctx.signal?.aborted === true;
|
|
4055
4149
|
var stageCall = (ctx, stage, baseSystem) => {
|
|
4056
4150
|
const withMcp = ctx.mcpInstructions && (stage === "planner" || stage === "executor") ? `${baseSystem}
|
|
4057
4151
|
|
|
@@ -4063,23 +4157,44 @@ ${ctx.mcpInstructions}` : baseSystem;
|
|
|
4063
4157
|
cachingProviderOptions(caching, ctx.config.clientName, stage),
|
|
4064
4158
|
thinking.providerOptions
|
|
4065
4159
|
);
|
|
4160
|
+
const cap = stageReasons(ctx.raw, stage) ? stageOutputCap(ctx.raw, stage, capWindow(ctx, stage)).tokens ?? 0 : ctx.config.budgets[stage];
|
|
4066
4161
|
return {
|
|
4067
4162
|
system: cachedInstructions(system, caching),
|
|
4068
4163
|
...thinking.reasoning ? { reasoning: thinking.reasoning } : {},
|
|
4069
4164
|
...providerOptions ? { providerOptions } : {},
|
|
4070
|
-
...
|
|
4165
|
+
...cap > 0 ? { maxOutputTokens: cap } : {}
|
|
4071
4166
|
};
|
|
4072
4167
|
};
|
|
4073
|
-
var
|
|
4074
|
-
|
|
4075
|
-
|
|
4076
|
-
|
|
4077
|
-
|
|
4078
|
-
)
|
|
4168
|
+
var capWindow = (ctx, stage) => (stage === "executor" ? ctx.executorWindowTokens : void 0) ?? ctx.config.compaction.contextWindowTokens;
|
|
4169
|
+
var cutWhileReasoning = (ctx, stage, finishReason, usage) => observeReasoning(ctx.raw, stage, capWindow(ctx, stage), finishReason, usage?.reasoningTokens);
|
|
4170
|
+
var withReasoningRoom = async (ctx, stage, phase, run, onWasted) => {
|
|
4171
|
+
const again = (why, spent2) => {
|
|
4172
|
+
onWasted(spent2);
|
|
4173
|
+
const message = `${why} - the model spent ${spent2.reasoningTokens ?? 0} of them reasoning: repeating the call without the default cap (this stage is not capped for this agent from now on)`;
|
|
4174
|
+
ctx.log.warn(message);
|
|
4175
|
+
ctx.emit({ type: "retry", phase, attempt: 1, error: message });
|
|
4176
|
+
return run();
|
|
4177
|
+
};
|
|
4178
|
+
let first;
|
|
4179
|
+
try {
|
|
4180
|
+
first = await run();
|
|
4181
|
+
} catch (err) {
|
|
4182
|
+
if (aborted(ctx) || !NoObjectGeneratedError.isInstance(err)) throw err;
|
|
4183
|
+
withCapHint(ctx, stage, err);
|
|
4184
|
+
const spent2 = usageOfError(err);
|
|
4185
|
+
if (!cutWhileReasoning(ctx, stage, err.finishReason, spent2)) throw err;
|
|
4186
|
+
return again(err.message, spent2);
|
|
4187
|
+
}
|
|
4188
|
+
const spent = normalizeUsage(first.usage);
|
|
4189
|
+
const notice = capNotice(ctx, stage, first.finishReason);
|
|
4190
|
+
if (!cutWhileReasoning(ctx, stage, first.finishReason, spent)) return first;
|
|
4191
|
+
return again(notice ?? `[${stage}] the model's output was cut off`, spent);
|
|
4192
|
+
};
|
|
4193
|
+
var capNotice = (ctx, stage, finishReason) => outputCapNotice(ctx.raw, stage, capWindow(ctx, stage), finishReason);
|
|
4079
4194
|
var withCapHint = (ctx, stage, err) => {
|
|
4080
4195
|
if (NoObjectGeneratedError.isInstance(err)) {
|
|
4081
4196
|
const notice = capNotice(ctx, stage, err.finishReason);
|
|
4082
|
-
if (notice) err.message = `${err.message} - ${notice}`;
|
|
4197
|
+
if (notice && !err.message.includes(notice)) err.message = `${err.message} - ${notice}`;
|
|
4083
4198
|
}
|
|
4084
4199
|
return err;
|
|
4085
4200
|
};
|
|
@@ -4308,14 +4423,14 @@ var shareSubagentBudget = (parent, running, settings) => {
|
|
|
4308
4423
|
var createSpawnGate = (max) => {
|
|
4309
4424
|
let active = 0;
|
|
4310
4425
|
const queue = [];
|
|
4311
|
-
const
|
|
4426
|
+
const aborted3 = () => {
|
|
4312
4427
|
const e = new Error("Aborted");
|
|
4313
4428
|
e.name = "AbortError";
|
|
4314
4429
|
return e;
|
|
4315
4430
|
};
|
|
4316
4431
|
return (signal) => new Promise((resolve, reject) => {
|
|
4317
4432
|
if (signal?.aborted) {
|
|
4318
|
-
reject(
|
|
4433
|
+
reject(aborted3());
|
|
4319
4434
|
return;
|
|
4320
4435
|
}
|
|
4321
4436
|
const grant = () => {
|
|
@@ -4336,7 +4451,7 @@ var createSpawnGate = (max) => {
|
|
|
4336
4451
|
if (i >= 0) {
|
|
4337
4452
|
queue.splice(i, 1);
|
|
4338
4453
|
}
|
|
4339
|
-
reject(
|
|
4454
|
+
reject(aborted3());
|
|
4340
4455
|
}
|
|
4341
4456
|
if (active < max) {
|
|
4342
4457
|
grant();
|
|
@@ -4425,6 +4540,7 @@ var executeStep = async (base, goal, step, index, total, done, attempt = {}) =>
|
|
|
4425
4540
|
const active = ctx.activeSkills?.() ?? [];
|
|
4426
4541
|
const parts = ctx.prompts.executor({
|
|
4427
4542
|
goal,
|
|
4543
|
+
...ctx.attachmentsNote ? { attachments: ctx.attachmentsNote } : {},
|
|
4428
4544
|
state,
|
|
4429
4545
|
step: step.description,
|
|
4430
4546
|
index,
|
|
@@ -4498,6 +4614,7 @@ ${renderEarlierAttempts(attempt.earlier)}` : parts.prompt;
|
|
|
4498
4614
|
ctx.log.debug("executor text:", loop.text);
|
|
4499
4615
|
const cut = capNotice(ctx, "executor", loop.finishReason);
|
|
4500
4616
|
if (cut) ctx.log.warn(cut);
|
|
4617
|
+
cutWhileReasoning(ctx, "executor", loop.finishReason, loop.usage);
|
|
4501
4618
|
const { summary, blocked } = splitBlocker(loop.text);
|
|
4502
4619
|
return {
|
|
4503
4620
|
result: {
|
|
@@ -4625,6 +4742,26 @@ var recordResume = async (persistence, resumed, attempt, warn) => {
|
|
|
4625
4742
|
);
|
|
4626
4743
|
}
|
|
4627
4744
|
};
|
|
4745
|
+
var SERVER_ONLY = "is the server package's (@dudko.dev/agent), not this browser package's";
|
|
4746
|
+
var refuseServerOnlyConfig = (config) => {
|
|
4747
|
+
const c = config;
|
|
4748
|
+
for (const key of ["runLease", "sharedLimits"]) {
|
|
4749
|
+
if (c[key] !== void 0) {
|
|
4750
|
+
throw new Error(`${key} ${SERVER_ONLY}: a run in a page has no other worker to share with`);
|
|
4751
|
+
}
|
|
4752
|
+
}
|
|
4753
|
+
const persistence = c.persistence;
|
|
4754
|
+
if (persistence?.journal !== void 0) {
|
|
4755
|
+
throw new Error(
|
|
4756
|
+
`persistence.journal ${SERVER_ONLY}: a page's run is not resumed by another worker, and IndexedDB in a tab that may close at any moment is not the fail-closed store a journal needs`
|
|
4757
|
+
);
|
|
4758
|
+
}
|
|
4759
|
+
};
|
|
4760
|
+
var refuseServerOnlyRunOptions = (opts) => {
|
|
4761
|
+
if (opts.answers !== void 0) {
|
|
4762
|
+
throw new Error(`run({ answers }) ${SERVER_ONLY}: there are no parked runs here to answer`);
|
|
4763
|
+
}
|
|
4764
|
+
};
|
|
4628
4765
|
|
|
4629
4766
|
// src/agent/schemas.ts
|
|
4630
4767
|
import { z as z5 } from "zod";
|
|
@@ -4637,7 +4774,11 @@ var TieredPlanStepSchema = PlanStepSchema.extend({
|
|
|
4637
4774
|
complexity: z5.enum(["low", "medium", "high"]).optional()
|
|
4638
4775
|
});
|
|
4639
4776
|
var PlanSchema = z5.object({
|
|
4640
|
-
/**
|
|
4777
|
+
/**
|
|
4778
|
+
* The planner's private one-sentence note. Never shown as an answer: with an empty `steps` (a
|
|
4779
|
+
* greeting, small talk, a question that needs no tool) the answer is written by the answering
|
|
4780
|
+
* stage.
|
|
4781
|
+
*/
|
|
4641
4782
|
thought: z5.string(),
|
|
4642
4783
|
steps: z5.array(PlanStepSchema),
|
|
4643
4784
|
/** Names of the configured skills that apply to this goal. */
|
|
@@ -4674,6 +4815,7 @@ ${nudge}` : goal;
|
|
|
4674
4815
|
toolCatalog: ctx.toolCatalog,
|
|
4675
4816
|
mode,
|
|
4676
4817
|
history: ctx.history,
|
|
4818
|
+
...ctx.attachmentsNote ? { attachments: ctx.attachmentsNote } : {},
|
|
4677
4819
|
skills: skillIndex,
|
|
4678
4820
|
searchMode: ctx.strategy === "search",
|
|
4679
4821
|
...ctx.sandbox ? { sandbox: ctx.sandbox.planner } : {},
|
|
@@ -4703,15 +4845,23 @@ ${nudge}` : goal;
|
|
|
4703
4845
|
let wasted = normalizeUsage();
|
|
4704
4846
|
if (ctx.plannerMode === "native") {
|
|
4705
4847
|
try {
|
|
4706
|
-
const result2 = await
|
|
4707
|
-
ctx
|
|
4708
|
-
|
|
4709
|
-
|
|
4848
|
+
const result2 = await withReasoningRoom(
|
|
4849
|
+
ctx,
|
|
4850
|
+
"planner",
|
|
4851
|
+
"plan",
|
|
4852
|
+
() => generateStructured(
|
|
4853
|
+
ctx.plannerModel,
|
|
4854
|
+
ctx.tiers ? TieredPlanSchema : PlanSchema,
|
|
4855
|
+
commonFor("native")
|
|
4856
|
+
),
|
|
4857
|
+
(spent) => {
|
|
4858
|
+
wasted = addUsage(wasted, spent);
|
|
4859
|
+
}
|
|
4710
4860
|
);
|
|
4711
4861
|
ctx.log.debug("planner (native):", result2.object);
|
|
4712
4862
|
return {
|
|
4713
4863
|
plan: { thought: result2.object.thought, steps: toSteps(result2.object.steps, cap) },
|
|
4714
|
-
usage: normalizeUsage(result2.usage),
|
|
4864
|
+
usage: addUsage(wasted, normalizeUsage(result2.usage)),
|
|
4715
4865
|
skills: validSkills(result2.object.skills)
|
|
4716
4866
|
};
|
|
4717
4867
|
} catch (err) {
|
|
@@ -4720,16 +4870,26 @@ ${nudge}` : goal;
|
|
|
4720
4870
|
if (refused) throw refused;
|
|
4721
4871
|
const overflow = contextOverflowOf(err, ctx.plannerModel);
|
|
4722
4872
|
if (overflow) throw overflow;
|
|
4723
|
-
wasted = usageOfError(err);
|
|
4873
|
+
wasted = addUsage(wasted, usageOfError(err));
|
|
4724
4874
|
const why = asMessage(withCapHint(ctx, "planner", err));
|
|
4725
4875
|
ctx.log.warn("planner: native structured output failed, salvaging:", why);
|
|
4726
4876
|
ctx.emit({ type: "retry", phase: "plan", attempt: 1, error: why });
|
|
4727
4877
|
}
|
|
4728
4878
|
}
|
|
4729
|
-
const result = await
|
|
4879
|
+
const result = await withReasoningRoom(
|
|
4880
|
+
ctx,
|
|
4881
|
+
"planner",
|
|
4882
|
+
"plan",
|
|
4883
|
+
() => generate(ctx.plannerModel, commonFor("prompted")),
|
|
4884
|
+
(spent) => {
|
|
4885
|
+
wasted = addUsage(wasted, spent);
|
|
4886
|
+
}
|
|
4887
|
+
).catch((err) => {
|
|
4730
4888
|
throw imageRefusal(ctx, err, ctx.plannerModel) ?? contextOverflowOf(err, ctx.plannerModel) ?? err;
|
|
4731
4889
|
});
|
|
4732
4890
|
const parsed = parsePlannerResponse(result.text);
|
|
4891
|
+
const cut = result.finishReason === "length";
|
|
4892
|
+
const failed = parsed.plan.length === 0 && (cut || !result.text.trim()) ? capNotice(ctx, "planner", result.finishReason) ?? (cut ? "[planner] the model's output was cut off before it wrote a plan" : `[planner] the model returned no text (finish reason: ${result.finishReason})`) : void 0;
|
|
4733
4893
|
ctx.log.debug("planner (prompted) raw:", result.text);
|
|
4734
4894
|
ctx.log.debug("planner (prompted) parsed:", parsed);
|
|
4735
4895
|
return {
|
|
@@ -4744,7 +4904,8 @@ ${nudge}` : goal;
|
|
|
4744
4904
|
)
|
|
4745
4905
|
},
|
|
4746
4906
|
usage: addUsage(wasted, normalizeUsage(result.usage)),
|
|
4747
|
-
skills: validSkills(parsed.skills)
|
|
4907
|
+
skills: validSkills(parsed.skills),
|
|
4908
|
+
...failed ? { failed } : {}
|
|
4748
4909
|
};
|
|
4749
4910
|
};
|
|
4750
4911
|
var asMessage = (err) => err instanceof Error ? err.message : String(err);
|
|
@@ -5055,23 +5216,39 @@ var decideReplan = async (ctx, goal, done, remaining, newUpdates = 0) => {
|
|
|
5055
5216
|
let wasted = normalizeUsage();
|
|
5056
5217
|
if (ctx.plannerMode === "native") {
|
|
5057
5218
|
try {
|
|
5058
|
-
const result = await
|
|
5219
|
+
const result = await withReasoningRoom(
|
|
5220
|
+
ctx,
|
|
5221
|
+
"replanner",
|
|
5222
|
+
"replan",
|
|
5223
|
+
() => generateStructured(ctx.plannerModel, ReplanSchema, commonFor("native")),
|
|
5224
|
+
(spent) => {
|
|
5225
|
+
wasted = addUsage(wasted, spent);
|
|
5226
|
+
}
|
|
5227
|
+
);
|
|
5059
5228
|
return {
|
|
5060
5229
|
decision: result.object.decision,
|
|
5061
5230
|
reason: result.object.reason,
|
|
5062
5231
|
plan: result.object.plan ?? [],
|
|
5063
|
-
usage: normalizeUsage(result.usage)
|
|
5232
|
+
usage: addUsage(wasted, normalizeUsage(result.usage))
|
|
5064
5233
|
};
|
|
5065
5234
|
} catch (err) {
|
|
5066
5235
|
if (ctx.signal?.aborted) throw err;
|
|
5067
|
-
wasted = usageOfError(err);
|
|
5236
|
+
wasted = addUsage(wasted, usageOfError(err));
|
|
5068
5237
|
const why = asMessage2(withCapHint(ctx, "replanner", err));
|
|
5069
5238
|
ctx.log.warn("replanner: native structured output failed, salvaging:", why);
|
|
5070
5239
|
ctx.emit({ type: "retry", phase: "replan", attempt: 1, error: why });
|
|
5071
5240
|
}
|
|
5072
5241
|
}
|
|
5073
5242
|
try {
|
|
5074
|
-
const result = await
|
|
5243
|
+
const result = await withReasoningRoom(
|
|
5244
|
+
ctx,
|
|
5245
|
+
"replanner",
|
|
5246
|
+
"replan",
|
|
5247
|
+
() => generate(ctx.plannerModel, commonFor("prompted")),
|
|
5248
|
+
(spent) => {
|
|
5249
|
+
wasted = addUsage(wasted, spent);
|
|
5250
|
+
}
|
|
5251
|
+
);
|
|
5075
5252
|
const parsed = parseReplannerResponse(result.text);
|
|
5076
5253
|
return {
|
|
5077
5254
|
decision: parsed.decision,
|
|
@@ -5130,7 +5307,7 @@ var decideReplanWithDecisionModel = async (ctx, goal, done, remaining, onUsage)
|
|
|
5130
5307
|
var asMessage2 = (err) => err instanceof Error ? err.message : String(err);
|
|
5131
5308
|
|
|
5132
5309
|
// src/agent/synthesizer.ts
|
|
5133
|
-
var synthesizeAnswer = async (ctx, goal, done, findings = []) => {
|
|
5310
|
+
var synthesizeAnswer = async (ctx, goal, done, findings = [], options = {}) => {
|
|
5134
5311
|
const state = await ctx.state();
|
|
5135
5312
|
const active = ctx.activeSkills?.() ?? [];
|
|
5136
5313
|
const parts = ctx.prompts.synthesizer({
|
|
@@ -5140,8 +5317,32 @@ var synthesizeAnswer = async (ctx, goal, done, findings = []) => {
|
|
|
5140
5317
|
findings,
|
|
5141
5318
|
activeSkills: active.length ? renderActiveSkills(active) : void 0,
|
|
5142
5319
|
updates: ctx.userUpdates?.(),
|
|
5143
|
-
...ctx.sandbox ? { sandbox: ctx.sandbox.synthesizer } : {}
|
|
5320
|
+
...ctx.sandbox ? { sandbox: ctx.sandbox.synthesizer } : {},
|
|
5321
|
+
...ctx.attachmentsNote ? { attachments: ctx.attachmentsNote } : {},
|
|
5322
|
+
...options.direct ? { direct: true, history: ctx.history } : {}
|
|
5144
5323
|
});
|
|
5324
|
+
const first = await streamAnswer(ctx, parts);
|
|
5325
|
+
let last = first;
|
|
5326
|
+
let usage = first.usage;
|
|
5327
|
+
if (cutWhileReasoning(ctx, "synthesizer", first.finishReason, first.usage) && !first.shown) {
|
|
5328
|
+
const message = `${first.cut ?? "[synthesizer] the model's output was cut off"} - the model spent ${first.usage.reasoningTokens ?? 0} of them reasoning: repeating the call without the default cap`;
|
|
5329
|
+
ctx.log.warn(message);
|
|
5330
|
+
ctx.emit({ type: "retry", phase: "synthesize", attempt: 1, error: message });
|
|
5331
|
+
last = await streamAnswer(ctx, parts);
|
|
5332
|
+
usage = addUsage(usage, last.usage);
|
|
5333
|
+
} else if (first.cut) {
|
|
5334
|
+
ctx.log.warn(first.cut);
|
|
5335
|
+
}
|
|
5336
|
+
const text = parsePlainText(last.text);
|
|
5337
|
+
return {
|
|
5338
|
+
text,
|
|
5339
|
+
usage,
|
|
5340
|
+
...text ? {} : {
|
|
5341
|
+
empty: last.cut ?? `[synthesizer] the model returned no text (finish reason: ${last.finishReason ?? "unknown"})`
|
|
5342
|
+
}
|
|
5343
|
+
};
|
|
5344
|
+
};
|
|
5345
|
+
var streamAnswer = async (ctx, parts) => {
|
|
5145
5346
|
const result = stream(ctx.synthesizerModel, {
|
|
5146
5347
|
...stageCall(ctx, "synthesizer", parts.system),
|
|
5147
5348
|
...promptFor(ctx, parts.prompt),
|
|
@@ -5150,6 +5351,11 @@ var synthesizeAnswer = async (ctx, goal, done, findings = []) => {
|
|
|
5150
5351
|
timeoutMs: ctx.config.chatTimeoutMs
|
|
5151
5352
|
});
|
|
5152
5353
|
let text = "";
|
|
5354
|
+
let shown = false;
|
|
5355
|
+
const show = (delta) => {
|
|
5356
|
+
shown = true;
|
|
5357
|
+
ctx.emit({ type: "final.text-delta", delta });
|
|
5358
|
+
};
|
|
5153
5359
|
let verdict = "unknown";
|
|
5154
5360
|
for await (const part of result.fullStream) {
|
|
5155
5361
|
if (part.type === "reasoning-delta") {
|
|
@@ -5170,19 +5376,19 @@ var synthesizeAnswer = async (ctx, goal, done, findings = []) => {
|
|
|
5170
5376
|
verdict = looksLikeJson(lead) ? "suppress" : "emit";
|
|
5171
5377
|
if (verdict === "emit") {
|
|
5172
5378
|
const visible = text.includes("</think>") ? text.slice(text.lastIndexOf("</think>") + "</think>".length).trimStart() : text;
|
|
5173
|
-
if (visible)
|
|
5379
|
+
if (visible) show(visible);
|
|
5174
5380
|
}
|
|
5175
5381
|
} else if (verdict === "emit") {
|
|
5176
|
-
|
|
5382
|
+
show(delta);
|
|
5177
5383
|
}
|
|
5178
5384
|
}
|
|
5179
5385
|
const [usage, finishReason] = await Promise.all([result.usage, result.finishReason]);
|
|
5180
|
-
const cut = capNotice(ctx, "synthesizer", finishReason);
|
|
5181
|
-
if (cut) ctx.log.warn(cut);
|
|
5182
|
-
const clean = parsePlainText(text);
|
|
5183
5386
|
return {
|
|
5184
|
-
text
|
|
5185
|
-
usage: normalizeUsage(usage)
|
|
5387
|
+
text,
|
|
5388
|
+
usage: normalizeUsage(usage),
|
|
5389
|
+
finishReason,
|
|
5390
|
+
cut: capNotice(ctx, "synthesizer", finishReason),
|
|
5391
|
+
shown
|
|
5186
5392
|
};
|
|
5187
5393
|
};
|
|
5188
5394
|
|
|
@@ -5463,6 +5669,485 @@ var createDynamicSubagentTool = (deps) => {
|
|
|
5463
5669
|
return markReadOnly(t);
|
|
5464
5670
|
};
|
|
5465
5671
|
|
|
5672
|
+
// src/sync/session.ts
|
|
5673
|
+
var SESSION_LOCK_MODES = ["wait", "fail", "off"];
|
|
5674
|
+
var SessionBusyError = class extends Error {
|
|
5675
|
+
sessionId;
|
|
5676
|
+
heldBy;
|
|
5677
|
+
constructor(sessionId, heldBy) {
|
|
5678
|
+
super(
|
|
5679
|
+
`session "${sessionId}" is already running ${heldBy === "this-tab" ? "in this tab" : "in another tab"}; with sessionLock 'fail' a run does not wait for it`
|
|
5680
|
+
);
|
|
5681
|
+
this.name = "SessionBusyError";
|
|
5682
|
+
this.sessionId = sessionId;
|
|
5683
|
+
this.heldBy = heldBy;
|
|
5684
|
+
}
|
|
5685
|
+
};
|
|
5686
|
+
var sessionLockName = (dbName, sessionId) => `@dudko.dev/agent-web/session:${scopeOf(dbName)}:${encodeURIComponent(sessionId)}`;
|
|
5687
|
+
var RELAY_MAX_STRING = 8e3;
|
|
5688
|
+
var RELAY_MAX_ARRAY = 200;
|
|
5689
|
+
var RELAY_MAX_KEYS = 100;
|
|
5690
|
+
var RELAY_MAX_DEPTH = 8;
|
|
5691
|
+
var RELAY_MAX_REPLAY_EVENTS = 2e3;
|
|
5692
|
+
var RELAY_MAX_REPLAY_CHARS = 2e6;
|
|
5693
|
+
var RELAY_MAX_SEND_CHARS = 32e3;
|
|
5694
|
+
var RELAY_MAX_SENDS = 50;
|
|
5695
|
+
var RELAY_MAX_REPLAYS_PER_SECOND = 8;
|
|
5696
|
+
var WATCH_RESYNC_MS = 1e3;
|
|
5697
|
+
var WATCH_HOLDER_POLL_MS = 1e3;
|
|
5698
|
+
var WATCH_MAX_PENDING = 500;
|
|
5699
|
+
var ACK_TIMEOUT_MS = 3e3;
|
|
5700
|
+
var GONE_GRACE_MS = 300;
|
|
5701
|
+
var RUN_ID_RE = /^[A-Za-z0-9_-]{1,128}$/;
|
|
5702
|
+
var EVENT_TYPE_RE = /^[a-z][a-z0-9.-]{0,63}$/;
|
|
5703
|
+
var UNSAFE_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
5704
|
+
var clipText = (s) => s.length > RELAY_MAX_STRING ? `${s.slice(0, RELAY_MAX_STRING - 1)}\u2026` : s;
|
|
5705
|
+
var slimEvent = (value, depth = 0) => {
|
|
5706
|
+
if (typeof value === "string") return clipText(value);
|
|
5707
|
+
if (typeof value === "number" || typeof value === "boolean" || value === null) return value;
|
|
5708
|
+
if (typeof value === "bigint") return value.toString();
|
|
5709
|
+
if (typeof value !== "object") return void 0;
|
|
5710
|
+
if (value instanceof Error) return clipText(value.message);
|
|
5711
|
+
if (ArrayBuffer.isView(value) || value instanceof ArrayBuffer) {
|
|
5712
|
+
return `[${value.byteLength} bytes]`;
|
|
5713
|
+
}
|
|
5714
|
+
if (depth >= RELAY_MAX_DEPTH) return "[\u2026]";
|
|
5715
|
+
if (Array.isArray(value)) {
|
|
5716
|
+
const out2 = value.slice(0, RELAY_MAX_ARRAY).map((v) => slimEvent(v, depth + 1) ?? null);
|
|
5717
|
+
if (value.length > RELAY_MAX_ARRAY) out2.push(`[\u2026 ${value.length - RELAY_MAX_ARRAY} more]`);
|
|
5718
|
+
return out2;
|
|
5719
|
+
}
|
|
5720
|
+
const out = {};
|
|
5721
|
+
let keys = 0;
|
|
5722
|
+
for (const [k, v] of Object.entries(value)) {
|
|
5723
|
+
if (UNSAFE_KEYS.has(k)) continue;
|
|
5724
|
+
if (keys >= RELAY_MAX_KEYS) break;
|
|
5725
|
+
keys += 1;
|
|
5726
|
+
const s = slimEvent(v, depth + 1);
|
|
5727
|
+
if (s !== void 0) out[k] = s;
|
|
5728
|
+
}
|
|
5729
|
+
return out;
|
|
5730
|
+
};
|
|
5731
|
+
var charsOf = (value) => {
|
|
5732
|
+
if (typeof value === "string") return value.length;
|
|
5733
|
+
if (Array.isArray(value)) return value.reduce((n, v) => n + charsOf(v), 2);
|
|
5734
|
+
if (isRecord(value)) {
|
|
5735
|
+
let n = 2;
|
|
5736
|
+
for (const [k, v] of Object.entries(value)) n += k.length + charsOf(v);
|
|
5737
|
+
return n;
|
|
5738
|
+
}
|
|
5739
|
+
return 4;
|
|
5740
|
+
};
|
|
5741
|
+
var relayedEventOf = (value) => {
|
|
5742
|
+
if (!isRecord(value) || typeof value.type !== "string" || !EVENT_TYPE_RE.test(value.type)) {
|
|
5743
|
+
return void 0;
|
|
5744
|
+
}
|
|
5745
|
+
return slimEvent(value);
|
|
5746
|
+
};
|
|
5747
|
+
var idOk = (value) => typeof value === "string" && SYNC_ID_RE.test(value);
|
|
5748
|
+
var watcherMessageOf = (data) => {
|
|
5749
|
+
if (!isRecord(data) || data.v !== SYNC_VERSION || !idOk(data.from) || !idOk(data.id)) {
|
|
5750
|
+
return void 0;
|
|
5751
|
+
}
|
|
5752
|
+
if (data.t === "hello" || data.t === "stop") return { t: data.t, id: data.id };
|
|
5753
|
+
if (data.t === "send" && typeof data.text === "string") {
|
|
5754
|
+
return { t: "send", id: data.id, text: data.text };
|
|
5755
|
+
}
|
|
5756
|
+
return void 0;
|
|
5757
|
+
};
|
|
5758
|
+
var countOk = (value, min) => typeof value === "number" && Number.isSafeInteger(value) && value >= min;
|
|
5759
|
+
var holderMessageOf = (data) => {
|
|
5760
|
+
if (!isRecord(data) || data.v !== SYNC_VERSION || !idOk(data.from)) return void 0;
|
|
5761
|
+
if (data.t === "ack") {
|
|
5762
|
+
return idOk(data.id) && typeof data.ok === "boolean" ? { t: "ack", id: data.id, ok: data.ok } : void 0;
|
|
5763
|
+
}
|
|
5764
|
+
if (typeof data.runId !== "string" || !RUN_ID_RE.test(data.runId)) return void 0;
|
|
5765
|
+
const runId = data.runId;
|
|
5766
|
+
switch (data.t) {
|
|
5767
|
+
case "run":
|
|
5768
|
+
return data.state === "running" || data.state === "idle" ? { t: "run", runId, state: data.state, stopped: data.stopped === true } : void 0;
|
|
5769
|
+
case "event": {
|
|
5770
|
+
const event = relayedEventOf(data.event);
|
|
5771
|
+
return countOk(data.n, 1) && event ? { t: "event", runId, n: data.n, event } : void 0;
|
|
5772
|
+
}
|
|
5773
|
+
case "replay": {
|
|
5774
|
+
if (!idOk(data.to) || !countOk(data.n, 0) || !Array.isArray(data.events)) return void 0;
|
|
5775
|
+
if (data.events.length > RELAY_MAX_REPLAY_EVENTS) return void 0;
|
|
5776
|
+
const ns = data.ns;
|
|
5777
|
+
const top = data.n;
|
|
5778
|
+
if (!Array.isArray(ns) || ns.length !== data.events.length) return void 0;
|
|
5779
|
+
if (!ns.every((x, i) => countOk(x, 1) && x <= top && (i === 0 || x > ns[i - 1]))) {
|
|
5780
|
+
return void 0;
|
|
5781
|
+
}
|
|
5782
|
+
const events = [];
|
|
5783
|
+
for (const raw of data.events) {
|
|
5784
|
+
const event = relayedEventOf(raw);
|
|
5785
|
+
if (!event) return void 0;
|
|
5786
|
+
events.push(event);
|
|
5787
|
+
}
|
|
5788
|
+
return {
|
|
5789
|
+
t: "replay",
|
|
5790
|
+
to: data.to,
|
|
5791
|
+
runId,
|
|
5792
|
+
n: data.n,
|
|
5793
|
+
ns,
|
|
5794
|
+
events,
|
|
5795
|
+
truncated: data.truncated === true
|
|
5796
|
+
};
|
|
5797
|
+
}
|
|
5798
|
+
default:
|
|
5799
|
+
return void 0;
|
|
5800
|
+
}
|
|
5801
|
+
};
|
|
5802
|
+
var inheritedLocks = /* @__PURE__ */ new WeakMap();
|
|
5803
|
+
var withSessionLocks = (options, names) => {
|
|
5804
|
+
if (names.length) inheritedLocks.set(options, [...names]);
|
|
5805
|
+
return options;
|
|
5806
|
+
};
|
|
5807
|
+
var sessionLocksOf = (options) => inheritedLocks.get(options) ?? [];
|
|
5808
|
+
var abortError2 = () => {
|
|
5809
|
+
const err = new Error("The run was stopped while it waited for the session");
|
|
5810
|
+
err.name = "AbortError";
|
|
5811
|
+
return err;
|
|
5812
|
+
};
|
|
5813
|
+
var acquireSessionLock = async (o) => {
|
|
5814
|
+
const take = (options) => new Promise((resolve, reject) => {
|
|
5815
|
+
let granted = false;
|
|
5816
|
+
let request = void 0;
|
|
5817
|
+
request = o.locks.request(o.name, options, (lock) => {
|
|
5818
|
+
granted = true;
|
|
5819
|
+
if (!lock) {
|
|
5820
|
+
resolve(null);
|
|
5821
|
+
return void 0;
|
|
5822
|
+
}
|
|
5823
|
+
return new Promise((free) => {
|
|
5824
|
+
o.tab.held.add(o.name);
|
|
5825
|
+
let released;
|
|
5826
|
+
resolve({
|
|
5827
|
+
name: o.name,
|
|
5828
|
+
release: () => {
|
|
5829
|
+
if (!released) {
|
|
5830
|
+
o.tab.held.delete(o.name);
|
|
5831
|
+
free();
|
|
5832
|
+
released = request.then(
|
|
5833
|
+
() => void 0,
|
|
5834
|
+
() => void 0
|
|
5835
|
+
);
|
|
5836
|
+
}
|
|
5837
|
+
return released;
|
|
5838
|
+
}
|
|
5839
|
+
});
|
|
5840
|
+
});
|
|
5841
|
+
}).catch((err) => {
|
|
5842
|
+
if (!granted) reject(err);
|
|
5843
|
+
});
|
|
5844
|
+
});
|
|
5845
|
+
if (o.signal?.aborted) throw abortError2();
|
|
5846
|
+
let now;
|
|
5847
|
+
try {
|
|
5848
|
+
now = await take({ ifAvailable: true });
|
|
5849
|
+
} catch (err) {
|
|
5850
|
+
return { unavailable: err };
|
|
5851
|
+
}
|
|
5852
|
+
if (now) return { hold: now };
|
|
5853
|
+
const exclusive = await heldExclusively(o.locks, o.name);
|
|
5854
|
+
const busy = exclusive !== false;
|
|
5855
|
+
if (busy) {
|
|
5856
|
+
const heldBy = o.tab.held.has(o.name) ? "this-tab" : "another-tab";
|
|
5857
|
+
if (o.mode === "fail") throw new SessionBusyError(o.sessionId, heldBy);
|
|
5858
|
+
o.onBusy(heldBy);
|
|
5859
|
+
}
|
|
5860
|
+
const started = Date.now();
|
|
5861
|
+
try {
|
|
5862
|
+
const hold = await take(o.signal ? { signal: o.signal } : {});
|
|
5863
|
+
return { hold, ...busy ? { waitedMs: Date.now() - started } : {} };
|
|
5864
|
+
} catch (err) {
|
|
5865
|
+
if (o.signal?.aborted) throw abortError2();
|
|
5866
|
+
return { unavailable: err };
|
|
5867
|
+
}
|
|
5868
|
+
};
|
|
5869
|
+
var DELTAS = /* @__PURE__ */ new Set([
|
|
5870
|
+
"plan.thought-delta",
|
|
5871
|
+
"step.text-delta",
|
|
5872
|
+
"step.reasoning-delta",
|
|
5873
|
+
"final.text-delta",
|
|
5874
|
+
"final.reasoning-delta"
|
|
5875
|
+
]);
|
|
5876
|
+
var deltaKey = (e) => `${String(e.type)}\0${String(e.step?.id ?? "")}\0${String(e.nodeId ?? "")}\0${String(e.visit ?? "")}`;
|
|
5877
|
+
var anySignal = (host, own) => {
|
|
5878
|
+
if (!host) return own;
|
|
5879
|
+
const any = AbortSignal.any;
|
|
5880
|
+
if (typeof any === "function") return any([host, own]);
|
|
5881
|
+
const both = new AbortController();
|
|
5882
|
+
for (const s of [host, own]) {
|
|
5883
|
+
if (s.aborted) both.abort(s.reason);
|
|
5884
|
+
else s.addEventListener("abort", () => both.abort(s.reason), { once: true });
|
|
5885
|
+
}
|
|
5886
|
+
return both.signal;
|
|
5887
|
+
};
|
|
5888
|
+
var startSessionRelay = (o) => {
|
|
5889
|
+
const hub = hubOf(o.tab, sessionLockName(o.dbName, o.sessionId));
|
|
5890
|
+
if (!hub) return void 0;
|
|
5891
|
+
const stopper = new AbortController();
|
|
5892
|
+
const signal = anySignal(o.signal, stopper.signal);
|
|
5893
|
+
const from = o.tab.id;
|
|
5894
|
+
const buffer = [];
|
|
5895
|
+
let chars = 0;
|
|
5896
|
+
let truncated = false;
|
|
5897
|
+
let n = 0;
|
|
5898
|
+
let sends = 0;
|
|
5899
|
+
let ended = false;
|
|
5900
|
+
let watched = false;
|
|
5901
|
+
const replayed = /* @__PURE__ */ new Set();
|
|
5902
|
+
const recentReplays = [];
|
|
5903
|
+
const port = o.remoteControl ? portOf(o.control) : void 0;
|
|
5904
|
+
const post = (message) => hub.post({ v: SYNC_VERSION, from, runId: o.runId, ...message });
|
|
5905
|
+
const ack = (id, ok) => hub.post({ v: SYNC_VERSION, from, t: "ack", id, ok });
|
|
5906
|
+
const keep = (event) => {
|
|
5907
|
+
const last = buffer[buffer.length - 1];
|
|
5908
|
+
const key = DELTAS.has(String(event.type)) ? deltaKey(event) : void 0;
|
|
5909
|
+
if (key && last?.key === key) {
|
|
5910
|
+
const joined = `${String(last.event.delta ?? "")}${String(event.delta ?? "")}`;
|
|
5911
|
+
if (joined.length <= RELAY_MAX_STRING) {
|
|
5912
|
+
chars += String(event.delta ?? "").length;
|
|
5913
|
+
last.event = { ...last.event, delta: joined, ...event.seq ? { seq: event.seq } : {} };
|
|
5914
|
+
last.n = n;
|
|
5915
|
+
return;
|
|
5916
|
+
}
|
|
5917
|
+
}
|
|
5918
|
+
buffer.push({ n, event, ...key ? { key } : {} });
|
|
5919
|
+
chars += charsOf(event);
|
|
5920
|
+
while (buffer.length > 1 && (buffer.length > RELAY_MAX_REPLAY_EVENTS || chars > RELAY_MAX_REPLAY_CHARS)) {
|
|
5921
|
+
const [dropped] = buffer.splice(1, 1);
|
|
5922
|
+
chars -= charsOf(dropped.event);
|
|
5923
|
+
truncated = true;
|
|
5924
|
+
}
|
|
5925
|
+
};
|
|
5926
|
+
const unlisten = hub.listen((data) => {
|
|
5927
|
+
if (ended) return;
|
|
5928
|
+
const m = watcherMessageOf(data);
|
|
5929
|
+
if (!m) return;
|
|
5930
|
+
if (m.t === "hello") {
|
|
5931
|
+
if (replayed.has(m.id)) return;
|
|
5932
|
+
if (replayed.size >= 4096) replayed.clear();
|
|
5933
|
+
replayed.add(m.id);
|
|
5934
|
+
watched = true;
|
|
5935
|
+
const now = Date.now();
|
|
5936
|
+
while (recentReplays.length && now - recentReplays[0] >= 1e3) recentReplays.shift();
|
|
5937
|
+
const full = recentReplays.length < RELAY_MAX_REPLAYS_PER_SECOND;
|
|
5938
|
+
if (full) recentReplays.push(now);
|
|
5939
|
+
post({
|
|
5940
|
+
t: "replay",
|
|
5941
|
+
to: m.id,
|
|
5942
|
+
n,
|
|
5943
|
+
events: full ? buffer.map((b) => b.event) : [],
|
|
5944
|
+
ns: full ? buffer.map((b) => b.n) : [],
|
|
5945
|
+
...truncated || !full ? { truncated: true } : {}
|
|
5946
|
+
});
|
|
5947
|
+
return;
|
|
5948
|
+
}
|
|
5949
|
+
if (!o.remoteControl) {
|
|
5950
|
+
ack(m.id, false);
|
|
5951
|
+
return;
|
|
5952
|
+
}
|
|
5953
|
+
if (m.t === "stop") {
|
|
5954
|
+
stopper.abort();
|
|
5955
|
+
ack(m.id, true);
|
|
5956
|
+
return;
|
|
5957
|
+
}
|
|
5958
|
+
const text = m.text.trim();
|
|
5959
|
+
if (!port || !text || text.length > RELAY_MAX_SEND_CHARS || sends >= RELAY_MAX_SENDS) {
|
|
5960
|
+
ack(m.id, false);
|
|
5961
|
+
return;
|
|
5962
|
+
}
|
|
5963
|
+
sends += 1;
|
|
5964
|
+
ack(m.id, port.sendFrom(text, "another-tab"));
|
|
5965
|
+
});
|
|
5966
|
+
post({ t: "run", state: "running" });
|
|
5967
|
+
return {
|
|
5968
|
+
signal,
|
|
5969
|
+
event(event) {
|
|
5970
|
+
if (ended) return;
|
|
5971
|
+
const slim = slimEvent(event);
|
|
5972
|
+
n += 1;
|
|
5973
|
+
if (watched) post({ t: "event", n, event: slim });
|
|
5974
|
+
keep(slim);
|
|
5975
|
+
},
|
|
5976
|
+
end(stopped) {
|
|
5977
|
+
if (ended) return;
|
|
5978
|
+
ended = true;
|
|
5979
|
+
post({ t: "run", state: "idle", ...stopped ? { stopped: true } : {} });
|
|
5980
|
+
unlisten();
|
|
5981
|
+
}
|
|
5982
|
+
};
|
|
5983
|
+
};
|
|
5984
|
+
var watchSession = (options) => {
|
|
5985
|
+
const dbName = options.dbName ?? "agent-web";
|
|
5986
|
+
const name = sessionLockName(dbName, String(options.sessionId ?? ""));
|
|
5987
|
+
const tab = currentTab();
|
|
5988
|
+
const hub = options.sessionId ? hubOf(tab, name) : void 0;
|
|
5989
|
+
let state = { running: false };
|
|
5990
|
+
const inert = {
|
|
5991
|
+
get state() {
|
|
5992
|
+
return state;
|
|
5993
|
+
},
|
|
5994
|
+
send: async () => false,
|
|
5995
|
+
stop: async () => false,
|
|
5996
|
+
close: () => void 0
|
|
5997
|
+
};
|
|
5998
|
+
if (!hub) return inert;
|
|
5999
|
+
let id = newSyncId();
|
|
6000
|
+
let closed = false;
|
|
6001
|
+
let following;
|
|
6002
|
+
let lastN = 0;
|
|
6003
|
+
let pending = [];
|
|
6004
|
+
let lastHello = 0;
|
|
6005
|
+
let epoch = 0;
|
|
6006
|
+
const acks = /* @__PURE__ */ new Map();
|
|
6007
|
+
let holderPoll;
|
|
6008
|
+
const setState = (next) => {
|
|
6009
|
+
state = next;
|
|
6010
|
+
try {
|
|
6011
|
+
options.onState?.(next);
|
|
6012
|
+
} catch {
|
|
6013
|
+
}
|
|
6014
|
+
};
|
|
6015
|
+
const deliver = (event) => {
|
|
6016
|
+
try {
|
|
6017
|
+
options.onEvent?.(event);
|
|
6018
|
+
} catch {
|
|
6019
|
+
}
|
|
6020
|
+
};
|
|
6021
|
+
const hello = () => {
|
|
6022
|
+
id = newSyncId();
|
|
6023
|
+
lastHello = Date.now();
|
|
6024
|
+
hub.post({ v: SYNC_VERSION, from: tab.id, t: "hello", id });
|
|
6025
|
+
};
|
|
6026
|
+
const resync = () => {
|
|
6027
|
+
if (Date.now() - lastHello >= WATCH_RESYNC_MS) hello();
|
|
6028
|
+
};
|
|
6029
|
+
const stopPolling = () => {
|
|
6030
|
+
if (holderPoll !== void 0) clearInterval(holderPoll);
|
|
6031
|
+
holderPoll = void 0;
|
|
6032
|
+
};
|
|
6033
|
+
const endRun = (ended) => {
|
|
6034
|
+
stopPolling();
|
|
6035
|
+
setState({ running: false, ...state.runId ? { runId: state.runId } : {}, ended });
|
|
6036
|
+
following = void 0;
|
|
6037
|
+
pending = [];
|
|
6038
|
+
};
|
|
6039
|
+
const seeRun = (runId, truncated = false) => {
|
|
6040
|
+
if (!(state.running && state.runId === runId)) epoch += 1;
|
|
6041
|
+
setState({ running: true, runId, ...truncated ? { truncated: true } : {} });
|
|
6042
|
+
watchForEnd();
|
|
6043
|
+
};
|
|
6044
|
+
const watchForEnd = () => {
|
|
6045
|
+
const locks = lockManager();
|
|
6046
|
+
if (!locks || typeof locks.query !== "function" || holderPoll !== void 0 || closed) return;
|
|
6047
|
+
const armed = epoch;
|
|
6048
|
+
let checking = false;
|
|
6049
|
+
holderPoll = setInterval(() => {
|
|
6050
|
+
if (checking) return;
|
|
6051
|
+
checking = true;
|
|
6052
|
+
void heldExclusively(locks, name).then((held) => {
|
|
6053
|
+
checking = false;
|
|
6054
|
+
if (held !== false || closed || epoch !== armed || !state.running) return;
|
|
6055
|
+
stopPolling();
|
|
6056
|
+
setTimeout(() => {
|
|
6057
|
+
if (!closed && state.running && epoch === armed) endRun("gone");
|
|
6058
|
+
}, GONE_GRACE_MS);
|
|
6059
|
+
});
|
|
6060
|
+
}, WATCH_HOLDER_POLL_MS);
|
|
6061
|
+
holderPoll.unref?.();
|
|
6062
|
+
};
|
|
6063
|
+
const unlisten = hub.listen((data) => {
|
|
6064
|
+
if (closed) return;
|
|
6065
|
+
const m = holderMessageOf(data);
|
|
6066
|
+
if (!m) return;
|
|
6067
|
+
switch (m.t) {
|
|
6068
|
+
case "ack":
|
|
6069
|
+
acks.get(m.id)?.(m.ok);
|
|
6070
|
+
return;
|
|
6071
|
+
case "run":
|
|
6072
|
+
if (m.state === "running") {
|
|
6073
|
+
if (following === m.runId) return;
|
|
6074
|
+
seeRun(m.runId);
|
|
6075
|
+
hello();
|
|
6076
|
+
} else if (state.running && state.runId === m.runId) {
|
|
6077
|
+
endRun(m.stopped ? "stopped" : "done");
|
|
6078
|
+
}
|
|
6079
|
+
return;
|
|
6080
|
+
case "event":
|
|
6081
|
+
if (following === m.runId) {
|
|
6082
|
+
if (m.n <= lastN) return;
|
|
6083
|
+
if (m.n !== lastN + 1) {
|
|
6084
|
+
resync();
|
|
6085
|
+
return;
|
|
6086
|
+
}
|
|
6087
|
+
lastN = m.n;
|
|
6088
|
+
deliver(m.event);
|
|
6089
|
+
} else if (pending.length < WATCH_MAX_PENDING) {
|
|
6090
|
+
pending.push({ runId: m.runId, n: m.n, event: m.event });
|
|
6091
|
+
}
|
|
6092
|
+
return;
|
|
6093
|
+
case "replay": {
|
|
6094
|
+
if (m.to !== id) return;
|
|
6095
|
+
const known = following === m.runId ? lastN : 0;
|
|
6096
|
+
const later = pending.filter((p) => p.runId === m.runId && p.n > m.n).sort((a, b) => a.n - b.n);
|
|
6097
|
+
pending = [];
|
|
6098
|
+
following = m.runId;
|
|
6099
|
+
if (!(state.running && state.runId === m.runId)) seeRun(m.runId, m.truncated);
|
|
6100
|
+
else if (m.truncated && !state.truncated) setState({ ...state, truncated: true });
|
|
6101
|
+
m.events.forEach((event, i) => {
|
|
6102
|
+
if (m.ns[i] > known) deliver(event);
|
|
6103
|
+
});
|
|
6104
|
+
lastN = Math.max(known, m.n);
|
|
6105
|
+
for (const p of later) {
|
|
6106
|
+
if (p.n !== lastN + 1) break;
|
|
6107
|
+
lastN = p.n;
|
|
6108
|
+
deliver(p.event);
|
|
6109
|
+
}
|
|
6110
|
+
return;
|
|
6111
|
+
}
|
|
6112
|
+
}
|
|
6113
|
+
});
|
|
6114
|
+
const ask = (message) => {
|
|
6115
|
+
if (closed || !state.running) return Promise.resolve(false);
|
|
6116
|
+
const requestId = newSyncId();
|
|
6117
|
+
return new Promise((resolve) => {
|
|
6118
|
+
const timer = setTimeout(() => {
|
|
6119
|
+
acks.delete(requestId);
|
|
6120
|
+
resolve(false);
|
|
6121
|
+
}, ACK_TIMEOUT_MS);
|
|
6122
|
+
acks.set(requestId, (ok) => {
|
|
6123
|
+
clearTimeout(timer);
|
|
6124
|
+
acks.delete(requestId);
|
|
6125
|
+
resolve(ok);
|
|
6126
|
+
});
|
|
6127
|
+
hub.post({ v: SYNC_VERSION, from: tab.id, id: requestId, ...message });
|
|
6128
|
+
});
|
|
6129
|
+
};
|
|
6130
|
+
hello();
|
|
6131
|
+
return {
|
|
6132
|
+
get state() {
|
|
6133
|
+
return state;
|
|
6134
|
+
},
|
|
6135
|
+
send: (text) => {
|
|
6136
|
+
const clean = typeof text === "string" ? text.trim() : "";
|
|
6137
|
+
if (!clean || clean.length > RELAY_MAX_SEND_CHARS) return Promise.resolve(false);
|
|
6138
|
+
return ask({ t: "send", text: clean });
|
|
6139
|
+
},
|
|
6140
|
+
stop: () => ask({ t: "stop" }),
|
|
6141
|
+
close: () => {
|
|
6142
|
+
if (closed) return;
|
|
6143
|
+
closed = true;
|
|
6144
|
+
unlisten();
|
|
6145
|
+
stopPolling();
|
|
6146
|
+
for (const resolve of [...acks.values()]) resolve(false);
|
|
6147
|
+
}
|
|
6148
|
+
};
|
|
6149
|
+
};
|
|
6150
|
+
|
|
5466
6151
|
// src/agent/runner.ts
|
|
5467
6152
|
var newRunId = () => globalThis.crypto?.randomUUID?.() ?? `run-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
|
|
5468
6153
|
var errMessage = (err) => err instanceof Error ? err.message : String(err);
|
|
@@ -5485,7 +6170,21 @@ var asJson2 = (v) => {
|
|
|
5485
6170
|
var FINDING_CHARS = 600;
|
|
5486
6171
|
var FINDINGS_BUDGET = 6e3;
|
|
5487
6172
|
var createAgent = async (config) => {
|
|
6173
|
+
refuseServerOnlyConfig(config);
|
|
5488
6174
|
const cfg = resolveConfig(config);
|
|
6175
|
+
const lockMode = config.sessionLock ?? "wait";
|
|
6176
|
+
if (!SESSION_LOCK_MODES.includes(lockMode)) {
|
|
6177
|
+
throw new Error(`unknown sessionLock "${String(lockMode)}" (${SESSION_LOCK_MODES.join(" | ")})`);
|
|
6178
|
+
}
|
|
6179
|
+
const sharedDb = typeof config.memory?.dbName === "string" && config.memory.dbName ? config.memory.dbName : void 0;
|
|
6180
|
+
const tab = currentTab();
|
|
6181
|
+
let warnedNoLocks = false;
|
|
6182
|
+
let warnedBusy = false;
|
|
6183
|
+
const relayOn = config.sessionRelay !== false;
|
|
6184
|
+
const relayControl = typeof config.sessionRelay === "object" && config.sessionRelay !== null ? config.sessionRelay.control !== false : true;
|
|
6185
|
+
if (config.sessionRelay !== void 0 && config.sessionRelay !== false && (typeof config.sessionRelay !== "object" || config.sessionRelay === null)) {
|
|
6186
|
+
throw new Error("sessionRelay must be false or { control?: boolean }");
|
|
6187
|
+
}
|
|
5489
6188
|
const dynamicSubagents = resolveDynamicSubagents(config.subagents);
|
|
5490
6189
|
const seed = spawnSeedOf(config);
|
|
5491
6190
|
const buildStage = (override, stageName) => buildModelFromStage(
|
|
@@ -5595,7 +6294,7 @@ var createAgent = async (config) => {
|
|
|
5595
6294
|
config.availableTools,
|
|
5596
6295
|
config.excludedTools
|
|
5597
6296
|
);
|
|
5598
|
-
const sandbox = config.sandbox ? (await import("./sandbox-
|
|
6297
|
+
const sandbox = config.sandbox ? (await import("./sandbox-7CGSIIIZ.js")).createSandbox(
|
|
5599
6298
|
config.sandbox === true ? {} : config.sandbox,
|
|
5600
6299
|
hostTools,
|
|
5601
6300
|
(m) => log.warn(m)
|
|
@@ -5691,21 +6390,114 @@ ${renderActiveSkills(active)}`
|
|
|
5691
6390
|
spentAll = addUsage(spentAll, u);
|
|
5692
6391
|
spentBySession.set(sessionId, addUsage(spentBySession.get(sessionId) ?? emptyUsage(), u));
|
|
5693
6392
|
};
|
|
5694
|
-
const
|
|
5695
|
-
|
|
5696
|
-
|
|
6393
|
+
const announce = (onEvent, event) => {
|
|
6394
|
+
try {
|
|
6395
|
+
onEvent?.(event);
|
|
6396
|
+
} catch {
|
|
6397
|
+
}
|
|
6398
|
+
};
|
|
6399
|
+
const noLocks = (why) => {
|
|
6400
|
+
if (!warnedNoLocks) {
|
|
6401
|
+
warnedNoLocks = true;
|
|
6402
|
+
log.warn(`sessionLock: ${why} - runs of one session in two tabs are not kept apart`);
|
|
6403
|
+
}
|
|
6404
|
+
return void 0;
|
|
6405
|
+
};
|
|
6406
|
+
const lockSession = async (given, mode = lockMode === "fail" ? "fail" : "wait") => {
|
|
6407
|
+
if (!sharedDb || lockMode === "off") return void 0;
|
|
6408
|
+
if (given.runId !== void 0) assertSafeRunId(given.runId, "runId");
|
|
6409
|
+
const sessionId = given.resumeFromRunId !== void 0 ? (await resolveResume(config.persistence, given.resumeFromRunId)).sessionId : given.sessionId ?? cfg.sessionId;
|
|
6410
|
+
const name = sessionLockName(sharedDb, sessionId);
|
|
6411
|
+
if (sessionLocksOf(given).includes(name)) return void 0;
|
|
6412
|
+
const locks = lockManager();
|
|
6413
|
+
if (!locks) return noLocks("this browser has no Web Locks (navigator.locks)");
|
|
6414
|
+
const taken = await acquireSessionLock({
|
|
6415
|
+
locks,
|
|
6416
|
+
tab,
|
|
6417
|
+
name,
|
|
6418
|
+
sessionId,
|
|
6419
|
+
mode,
|
|
6420
|
+
signal: given.signal,
|
|
6421
|
+
onBusy: (heldBy) => {
|
|
6422
|
+
if (!warnedBusy) {
|
|
6423
|
+
warnedBusy = true;
|
|
6424
|
+
log.warn(
|
|
6425
|
+
`session "${sessionId}" is already running ${heldBy === "this-tab" ? "in this tab" : "in another tab"}: this run waits for it (sessionLock 'wait'; 'fail' refuses, 'off' runs both)`
|
|
6426
|
+
);
|
|
6427
|
+
} else log.info(`session "${sessionId}" is running ${heldBy}; waiting for it`);
|
|
6428
|
+
announce(given.onEvent, { type: "session.busy", sessionId, heldBy });
|
|
6429
|
+
}
|
|
6430
|
+
});
|
|
6431
|
+
if (taken.unavailable !== void 0 || !taken.hold) {
|
|
6432
|
+
return noLocks(`the lock manager refused (${errMessage(taken.unavailable)})`);
|
|
6433
|
+
}
|
|
6434
|
+
if (taken.waitedMs !== void 0) {
|
|
6435
|
+
announce(given.onEvent, { type: "session.acquired", sessionId, waitedMs: taken.waitedMs });
|
|
6436
|
+
}
|
|
6437
|
+
return taken.hold;
|
|
6438
|
+
};
|
|
6439
|
+
const runCore = async (goal, given, track, port) => {
|
|
6440
|
+
let hold;
|
|
6441
|
+
try {
|
|
6442
|
+
hold = await lockSession(given);
|
|
6443
|
+
} catch (err) {
|
|
6444
|
+
if (!given.signal?.aborted) throw err;
|
|
6445
|
+
announce(given.onEvent, { type: "stopped" });
|
|
6446
|
+
return {
|
|
6447
|
+
runId: given.resumeFromRunId ?? given.runId ?? newRunId(),
|
|
6448
|
+
goal: goal.trim(),
|
|
6449
|
+
final: "",
|
|
6450
|
+
plan: { thought: "", steps: [] },
|
|
6451
|
+
trace: [],
|
|
6452
|
+
steps: 0,
|
|
6453
|
+
applied: 0,
|
|
6454
|
+
stopped: true,
|
|
6455
|
+
usage: emptyUsage(),
|
|
6456
|
+
skills: []
|
|
6457
|
+
};
|
|
6458
|
+
}
|
|
6459
|
+
let relay;
|
|
6460
|
+
if (hold) {
|
|
6461
|
+
const held = hold;
|
|
6462
|
+
track.end = (stopped) => {
|
|
6463
|
+
relay?.end(stopped);
|
|
6464
|
+
return held.release();
|
|
6465
|
+
};
|
|
6466
|
+
}
|
|
6467
|
+
const ownRunId = await resolveRunId(config.persistence, given.runId, given.resumeFromRunId);
|
|
6468
|
+
const resumed = await resolveResume(config.persistence, given.resumeFromRunId);
|
|
6469
|
+
const sessionId = resumed?.sessionId ?? given.sessionId ?? cfg.sessionId;
|
|
6470
|
+
const runId = resumed?.runId ?? ownRunId ?? newRunId();
|
|
6471
|
+
if (hold && sharedDb && sessionLockName(sharedDb, sessionId) !== hold.name) {
|
|
6472
|
+
throw new Error(
|
|
6473
|
+
`persistence changed the session of run "${runId}" while it waited for it; refusing to run it`
|
|
6474
|
+
);
|
|
6475
|
+
}
|
|
6476
|
+
if (hold && sharedDb && relayOn) {
|
|
6477
|
+
relay = startSessionRelay({
|
|
6478
|
+
tab,
|
|
6479
|
+
dbName: sharedDb,
|
|
6480
|
+
sessionId,
|
|
6481
|
+
runId,
|
|
6482
|
+
remoteControl: relayControl,
|
|
6483
|
+
...given.control ? { control: given.control } : {},
|
|
6484
|
+
...given.signal ? { signal: given.signal } : {}
|
|
6485
|
+
});
|
|
6486
|
+
}
|
|
6487
|
+
const opts = relay ? { ...given, signal: relay.signal } : given;
|
|
6488
|
+
const sessionLocks = hold ? [...sessionLocksOf(given), hold.name] : sessionLocksOf(given);
|
|
5697
6489
|
const attempt = resumed ? resumeAttemptOf(resumed) : 1;
|
|
5698
6490
|
let seq3 = 0;
|
|
5699
6491
|
const emit = (event) => {
|
|
6492
|
+
const numbered2 = { ...event, seq: ++seq3, attempt };
|
|
5700
6493
|
try {
|
|
5701
|
-
opts.onEvent?.(
|
|
6494
|
+
opts.onEvent?.(numbered2);
|
|
5702
6495
|
} catch {
|
|
5703
6496
|
}
|
|
6497
|
+
relay?.event(numbered2);
|
|
5704
6498
|
};
|
|
5705
6499
|
if (resumed) await recordResume(config.persistence, resumed, attempt, (m) => log.warn(m));
|
|
5706
6500
|
let text = (resumed?.goal ?? goal).trim();
|
|
5707
|
-
const sessionId = resumed?.sessionId ?? opts.sessionId ?? cfg.sessionId;
|
|
5708
|
-
const runId = resumed?.runId ?? ownRunId ?? newRunId();
|
|
5709
6501
|
const startedAt = resumed?.startedAt ?? Date.now();
|
|
5710
6502
|
let usage = resumed ? { ...resumed.usage } : emptyUsage();
|
|
5711
6503
|
const result = {
|
|
@@ -5863,7 +6655,8 @@ ${renderActiveSkills(active)}`
|
|
|
5863
6655
|
fetched,
|
|
5864
6656
|
stepWrites: () => stepWrites,
|
|
5865
6657
|
clock,
|
|
5866
|
-
mcpSkills: mcpSkillsActing
|
|
6658
|
+
mcpSkills: mcpSkillsActing,
|
|
6659
|
+
sessionLocks: () => sessionLocks
|
|
5867
6660
|
}
|
|
5868
6661
|
);
|
|
5869
6662
|
const deliver = (at) => {
|
|
@@ -5871,7 +6664,13 @@ ${renderActiveSkills(active)}`
|
|
|
5871
6664
|
const taken = port.drain();
|
|
5872
6665
|
for (const m of taken) {
|
|
5873
6666
|
userUpdates.push({ text: m.text, reconciled: false });
|
|
5874
|
-
emit({
|
|
6667
|
+
emit({
|
|
6668
|
+
type: "message.delivered",
|
|
6669
|
+
id: m.id,
|
|
6670
|
+
text: m.text,
|
|
6671
|
+
at,
|
|
6672
|
+
...m.origin ? { origin: m.origin } : {}
|
|
6673
|
+
});
|
|
5875
6674
|
log.info(`message from the user (delivered at ${at}):`, m.text);
|
|
5876
6675
|
void remember({ role: "user", content: m.text });
|
|
5877
6676
|
}
|
|
@@ -6008,6 +6807,9 @@ ${renderActiveSkills(active)}`
|
|
|
6008
6807
|
currentStep = step;
|
|
6009
6808
|
},
|
|
6010
6809
|
images: images.length ? images : void 0,
|
|
6810
|
+
// No file now, but one in an earlier turn: the model is told, or it answers about a
|
|
6811
|
+
// picture it only read the name of.
|
|
6812
|
+
...!images.length && history.some((m) => m.role === "user" && hasAttachedMark(m.content)) ? { attachmentsNote: NO_ATTACHMENT_NOTE } : {},
|
|
6011
6813
|
userUpdates: () => userUpdates.map((u) => u.text),
|
|
6012
6814
|
...port ? { takeRoundUpdates: () => deliver("round") } : {}
|
|
6013
6815
|
};
|
|
@@ -6027,7 +6829,14 @@ ${renderActiveSkills(active)}`
|
|
|
6027
6829
|
let planned = resumed ? { plan: resumed.plan, usage: emptyUsage(), skills: [] } : await createPlan(ctx, text);
|
|
6028
6830
|
if (!resumed) bumpUsage(planned.usage, "plan");
|
|
6029
6831
|
if (isAborted()) return stop();
|
|
6030
|
-
if (planned.
|
|
6832
|
+
if (planned.failed) {
|
|
6833
|
+
log.warn("planner failed:", planned.failed);
|
|
6834
|
+
emit({ type: "error", phase: "run", error: planned.failed, code: "no-plan" });
|
|
6835
|
+
result.final = planned.failed;
|
|
6836
|
+
track.error = planned.failed;
|
|
6837
|
+
return result;
|
|
6838
|
+
}
|
|
6839
|
+
if (planned.plan.steps.length === 0 && plannerMode === "prompted" && catalog.length > 0 && text.split(/\s+/).length > 2) {
|
|
6031
6840
|
log.warn(
|
|
6032
6841
|
"planner returned no steps for a multi-word goal \u2014 retrying with a nudge. thought:",
|
|
6033
6842
|
planned.plan.thought
|
|
@@ -6044,10 +6853,27 @@ ${renderActiveSkills(active)}`
|
|
|
6044
6853
|
if (isAborted()) return stop();
|
|
6045
6854
|
if (planned.plan.steps.length === 0) {
|
|
6046
6855
|
log.info("no plan \u2014 answering directly (no tools will run)");
|
|
6047
|
-
|
|
6048
|
-
|
|
6049
|
-
|
|
6050
|
-
|
|
6856
|
+
deliver("final");
|
|
6857
|
+
let direct;
|
|
6858
|
+
try {
|
|
6859
|
+
direct = await synthesizeAnswer(ctx, text, [], [], { direct: true });
|
|
6860
|
+
} catch (err) {
|
|
6861
|
+
if (isAborted()) return stop();
|
|
6862
|
+
throw err;
|
|
6863
|
+
}
|
|
6864
|
+
bumpUsage(direct.usage, "synthesize");
|
|
6865
|
+
if (isAborted()) return stop();
|
|
6866
|
+
if (!direct.text) {
|
|
6867
|
+
const message = direct.empty ?? "[synthesizer] the model returned no answer";
|
|
6868
|
+
log.warn(message);
|
|
6869
|
+
emit({ type: "error", phase: "run", error: message, code: "no-answer" });
|
|
6870
|
+
result.final = message;
|
|
6871
|
+
track.error = message;
|
|
6872
|
+
return result;
|
|
6873
|
+
}
|
|
6874
|
+
emit({ type: "final", text: direct.text });
|
|
6875
|
+
await remember({ role: "assistant", content: direct.text });
|
|
6876
|
+
result.final = direct.text;
|
|
6051
6877
|
return result;
|
|
6052
6878
|
}
|
|
6053
6879
|
log.info(
|
|
@@ -6067,6 +6893,7 @@ ${renderActiveSkills(active)}`
|
|
|
6067
6893
|
let remaining = resumed ? [...resumed.remaining] : [...planned.plan.steps];
|
|
6068
6894
|
let iter = resumed?.iterations ?? 0;
|
|
6069
6895
|
let revisions = resumed?.revisions ?? 0;
|
|
6896
|
+
let inFlight;
|
|
6070
6897
|
const buildSnapshot = (status, extra = {}) => ({
|
|
6071
6898
|
runId,
|
|
6072
6899
|
startedAt,
|
|
@@ -6075,12 +6902,12 @@ ${renderActiveSkills(active)}`
|
|
|
6075
6902
|
sessionId,
|
|
6076
6903
|
plan: planned.plan,
|
|
6077
6904
|
// Copies: a store that keeps the object must not watch the loop mutate it.
|
|
6078
|
-
remaining: [...remaining],
|
|
6905
|
+
remaining: inFlight ? [inFlight, ...remaining] : [...remaining],
|
|
6079
6906
|
trace: [...result.trace],
|
|
6080
6907
|
done: [...done],
|
|
6081
6908
|
findings: [...findings],
|
|
6082
6909
|
usage: { ...usage },
|
|
6083
|
-
iterations: iter,
|
|
6910
|
+
iterations: inFlight ? iter - 1 : iter,
|
|
6084
6911
|
revisions,
|
|
6085
6912
|
toolCalls: counter.calls,
|
|
6086
6913
|
applied: result.applied,
|
|
@@ -6129,6 +6956,7 @@ ${renderActiveSkills(active)}`
|
|
|
6129
6956
|
}
|
|
6130
6957
|
iter += 1;
|
|
6131
6958
|
const step = remaining.shift();
|
|
6959
|
+
inFlight = step;
|
|
6132
6960
|
const stepNo = result.trace.length + 1;
|
|
6133
6961
|
const total = stepNo + remaining.length;
|
|
6134
6962
|
const routed = tiers ? pickTier(step.complexity, tiers.configured) : void 0;
|
|
@@ -6235,6 +7063,7 @@ ${renderActiveSkills(active)}`
|
|
|
6235
7063
|
stepWrites = void 0;
|
|
6236
7064
|
}
|
|
6237
7065
|
result.trace.push(stepResult);
|
|
7066
|
+
inFlight = void 0;
|
|
6238
7067
|
const applied = stepResult.toolCalls.filter((c) => c.ok && !isReplayed(c)).length;
|
|
6239
7068
|
const failed = stepResult.toolCalls.length - applied;
|
|
6240
7069
|
result.applied += applied;
|
|
@@ -6401,20 +7230,27 @@ ${renderActiveSkills(active)}`
|
|
|
6401
7230
|
}
|
|
6402
7231
|
};
|
|
6403
7232
|
const run = async (goal, opts = {}) => {
|
|
7233
|
+
refuseServerOnlyRunOptions(opts);
|
|
6404
7234
|
const port = portOf(opts.control);
|
|
6405
7235
|
const track = {};
|
|
6406
|
-
let
|
|
7236
|
+
let stopped = false;
|
|
6407
7237
|
try {
|
|
6408
|
-
result
|
|
6409
|
-
|
|
6410
|
-
|
|
6411
|
-
|
|
6412
|
-
|
|
6413
|
-
|
|
7238
|
+
let result;
|
|
7239
|
+
try {
|
|
7240
|
+
result = await runCore(goal, opts, track, port);
|
|
7241
|
+
} catch (err) {
|
|
7242
|
+
port?.detach();
|
|
7243
|
+
track.error = err instanceof Error ? err.message : String(err);
|
|
7244
|
+
await track.complete?.(void 0);
|
|
7245
|
+
throw err;
|
|
7246
|
+
}
|
|
7247
|
+
if (port) result.undelivered = port.detach();
|
|
7248
|
+
await track.complete?.(result);
|
|
7249
|
+
stopped = result.stopped;
|
|
7250
|
+
return result;
|
|
7251
|
+
} finally {
|
|
7252
|
+
await track.end?.(stopped);
|
|
6414
7253
|
}
|
|
6415
|
-
if (port) result.undelivered = port.detach();
|
|
6416
|
-
await track.complete?.(result);
|
|
6417
|
-
return result;
|
|
6418
7254
|
};
|
|
6419
7255
|
const compact = async (o = {}) => {
|
|
6420
7256
|
const empty = {
|
|
@@ -6425,6 +7261,18 @@ ${renderActiveSkills(active)}`
|
|
|
6425
7261
|
};
|
|
6426
7262
|
if (!config.memory) return empty;
|
|
6427
7263
|
const sessionId = o.sessionId ?? cfg.sessionId;
|
|
7264
|
+
const hold = await lockSession(
|
|
7265
|
+
{ sessionId, ...o.signal ? { signal: o.signal } : {} },
|
|
7266
|
+
o.wait === false || lockMode === "fail" ? "fail" : "wait"
|
|
7267
|
+
);
|
|
7268
|
+
try {
|
|
7269
|
+
return await compactSession(sessionId, o, empty);
|
|
7270
|
+
} finally {
|
|
7271
|
+
await hold?.release();
|
|
7272
|
+
}
|
|
7273
|
+
};
|
|
7274
|
+
const compactSession = async (sessionId, o, empty) => {
|
|
7275
|
+
if (!config.memory) return empty;
|
|
6428
7276
|
const transcript = await config.memory.load(sessionId);
|
|
6429
7277
|
const beforeTokens = messageTokens(transcript);
|
|
6430
7278
|
let usage = emptyUsage();
|
|
@@ -6601,6 +7449,7 @@ ${renderActiveSkills(active)}`
|
|
|
6601
7449
|
};
|
|
6602
7450
|
},
|
|
6603
7451
|
forgetSkill: async (name, onEvent) => learning ? learning.forget(name, onEvent) : false,
|
|
7452
|
+
reloadLearnedSkills: async () => learning ? (await learning.reload()).map((s) => ({ ...s })) : [],
|
|
6604
7453
|
capabilities: { images: accepts.image, pdf: accepts.pdf, files: accepts.file },
|
|
6605
7454
|
models: {
|
|
6606
7455
|
planner: plannerModel,
|
|
@@ -6613,6 +7462,7 @@ ${renderActiveSkills(active)}`
|
|
|
6613
7462
|
};
|
|
6614
7463
|
|
|
6615
7464
|
// src/pipeline/index.ts
|
|
7465
|
+
import { NoObjectGeneratedError as NoObjectGeneratedError2 } from "ai";
|
|
6616
7466
|
import { z as z6 } from "zod";
|
|
6617
7467
|
|
|
6618
7468
|
// src/pipeline/engine.ts
|
|
@@ -7109,18 +7959,18 @@ var testPipelineCondition = (when, output, matcher) => {
|
|
|
7109
7959
|
return false;
|
|
7110
7960
|
}
|
|
7111
7961
|
};
|
|
7112
|
-
var
|
|
7962
|
+
var isRecord2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
7113
7963
|
var isId = (v) => typeof v === "string" && v.trim().length > 0;
|
|
7114
|
-
var edgeIdOf = (edge, index) =>
|
|
7964
|
+
var edgeIdOf = (edge, index) => isRecord2(edge) && isId(edge.id) ? edge.id : `e${index}`;
|
|
7115
7965
|
var edgeRef = (edge, index) => ({
|
|
7116
7966
|
edgeId: edgeIdOf(edge, index),
|
|
7117
7967
|
edgeIndex: index
|
|
7118
7968
|
});
|
|
7119
7969
|
var normalizePipeline = (definition) => {
|
|
7120
7970
|
const def = JSON.parse(JSON.stringify(definition));
|
|
7121
|
-
if (
|
|
7971
|
+
if (isRecord2(def) && Array.isArray(def.edges)) {
|
|
7122
7972
|
def.edges.forEach((edge, index) => {
|
|
7123
|
-
if (
|
|
7973
|
+
if (isRecord2(edge)) edge.id = edgeIdOf(edge, index);
|
|
7124
7974
|
});
|
|
7125
7975
|
}
|
|
7126
7976
|
return def;
|
|
@@ -7134,7 +7984,7 @@ var validatePipeline = (definition) => {
|
|
|
7134
7984
|
};
|
|
7135
7985
|
const done = () => ({ ok: errors.length === 0, errors, warnings });
|
|
7136
7986
|
const def = definition;
|
|
7137
|
-
if (!
|
|
7987
|
+
if (!isRecord2(def)) {
|
|
7138
7988
|
error("definition", "a pipeline definition must be an object");
|
|
7139
7989
|
return done();
|
|
7140
7990
|
}
|
|
@@ -7154,7 +8004,7 @@ var validatePipeline = (definition) => {
|
|
|
7154
8004
|
const ids = /* @__PURE__ */ new Set();
|
|
7155
8005
|
const routesOf = /* @__PURE__ */ new Map();
|
|
7156
8006
|
for (const [index, node] of (nodes ?? []).entries()) {
|
|
7157
|
-
if (!
|
|
8007
|
+
if (!isRecord2(node) || !isId(node.id)) {
|
|
7158
8008
|
error("node.id", `node #${index + 1} has no id`);
|
|
7159
8009
|
continue;
|
|
7160
8010
|
}
|
|
@@ -7177,7 +8027,7 @@ var validatePipeline = (definition) => {
|
|
|
7177
8027
|
);
|
|
7178
8028
|
} else {
|
|
7179
8029
|
for (const route of node.routes) {
|
|
7180
|
-
if (!
|
|
8030
|
+
if (!isRecord2(route) || !isId(route.label)) {
|
|
7181
8031
|
error("node.routes", `node "${nodeId}": a route has no label`, { nodeId });
|
|
7182
8032
|
} else if (labels.includes(route.label)) {
|
|
7183
8033
|
error("node.routes", `node "${nodeId}": duplicate route "${route.label}"`, { nodeId });
|
|
@@ -7201,7 +8051,7 @@ var validatePipeline = (definition) => {
|
|
|
7201
8051
|
for (const [index, edge] of (edges ?? []).entries()) {
|
|
7202
8052
|
const at = edgeRef(edge, index);
|
|
7203
8053
|
const label = `edge "${at.edgeId}"`;
|
|
7204
|
-
if (!
|
|
8054
|
+
if (!isRecord2(edge)) {
|
|
7205
8055
|
error("edge", `${label} is not an object`, at);
|
|
7206
8056
|
continue;
|
|
7207
8057
|
}
|
|
@@ -7218,7 +8068,7 @@ var validatePipeline = (definition) => {
|
|
|
7218
8068
|
if (fromOk && toOk) out.set(from, [...out.get(from) ?? [], to]);
|
|
7219
8069
|
const when = edge.when;
|
|
7220
8070
|
if (when === void 0) continue;
|
|
7221
|
-
if (!
|
|
8071
|
+
if (!isRecord2(when) || !CONDITION_KINDS.includes(when.kind)) {
|
|
7222
8072
|
error("edge.when", `${label} has an unknown condition`, at);
|
|
7223
8073
|
continue;
|
|
7224
8074
|
}
|
|
@@ -7261,7 +8111,7 @@ var validatePipeline = (definition) => {
|
|
|
7261
8111
|
}
|
|
7262
8112
|
}
|
|
7263
8113
|
if (def.limits !== void 0) {
|
|
7264
|
-
if (!
|
|
8114
|
+
if (!isRecord2(def.limits)) {
|
|
7265
8115
|
error("limits", "`limits` must be an object");
|
|
7266
8116
|
} else {
|
|
7267
8117
|
const { maxNodeVisits, maxRuns } = def.limits;
|
|
@@ -7378,7 +8228,7 @@ var matchPipelineRoute = (node, answer) => {
|
|
|
7378
8228
|
value = text;
|
|
7379
8229
|
}
|
|
7380
8230
|
}
|
|
7381
|
-
if (
|
|
8231
|
+
if (isRecord2(value)) value = value.route;
|
|
7382
8232
|
if (typeof value !== "string") return void 0;
|
|
7383
8233
|
const wanted = value.trim().replace(/^["'`]+|["'`.]+$/g, "").toLowerCase();
|
|
7384
8234
|
return labels.find((label) => label.toLowerCase() === wanted);
|
|
@@ -7471,7 +8321,7 @@ var passReach = (plan) => {
|
|
|
7471
8321
|
return seen.has(to);
|
|
7472
8322
|
};
|
|
7473
8323
|
};
|
|
7474
|
-
var
|
|
8324
|
+
var abortError3 = () => {
|
|
7475
8325
|
if (typeof DOMException === "function") return new DOMException("Aborted", "AbortError");
|
|
7476
8326
|
const error = new Error("Aborted");
|
|
7477
8327
|
error.name = "AbortError";
|
|
@@ -7501,7 +8351,7 @@ var createStopper = () => {
|
|
|
7501
8351
|
const abort = () => {
|
|
7502
8352
|
if (signal.aborted) return;
|
|
7503
8353
|
signal.aborted = true;
|
|
7504
|
-
signal.reason =
|
|
8354
|
+
signal.reason = abortError3();
|
|
7505
8355
|
const event = { type: "abort", target: signal };
|
|
7506
8356
|
const call = (fn, thisArg) => {
|
|
7507
8357
|
try {
|
|
@@ -7563,7 +8413,7 @@ ${t.text}`).join("\n\n");
|
|
|
7563
8413
|
if (halted) return;
|
|
7564
8414
|
halted = "aborted";
|
|
7565
8415
|
stopper.abort();
|
|
7566
|
-
halt(
|
|
8416
|
+
halt(abortError3());
|
|
7567
8417
|
};
|
|
7568
8418
|
const visit = async (nodeId, activations) => {
|
|
7569
8419
|
const node = plan.nodes.get(nodeId);
|
|
@@ -7696,38 +8546,50 @@ ${t.text}`).join("\n\n");
|
|
|
7696
8546
|
};
|
|
7697
8547
|
|
|
7698
8548
|
// src/pipeline/index.ts
|
|
7699
|
-
var
|
|
8549
|
+
var aborted2 = () => new DOMException("Aborted", "AbortError");
|
|
7700
8550
|
var pickRoute = async ({ agent, config }, node, text, signal) => {
|
|
7701
8551
|
const cfg = resolveConfig(config);
|
|
7702
8552
|
const labels = (node.routes ?? []).map((r) => r.label);
|
|
7703
|
-
const
|
|
7704
|
-
|
|
7705
|
-
|
|
7706
|
-
|
|
7707
|
-
|
|
7708
|
-
|
|
7709
|
-
|
|
7710
|
-
|
|
8553
|
+
const window = cfg.compaction.contextWindowTokens;
|
|
8554
|
+
const call = () => {
|
|
8555
|
+
const cap = stageOutputCap(config, "replanner", window).tokens;
|
|
8556
|
+
return {
|
|
8557
|
+
system: PIPELINE_ROUTER_SYSTEM,
|
|
8558
|
+
prompt: renderPipelineRoutePrompt(node, text),
|
|
8559
|
+
// No cap: the host turned it off, or the stage thinks.
|
|
8560
|
+
...cap ? { maxOutputTokens: cap } : {},
|
|
8561
|
+
temperature: cfg.temperature,
|
|
8562
|
+
abortSignal: signal,
|
|
8563
|
+
timeoutMs: cfg.chatTimeoutMs
|
|
8564
|
+
};
|
|
7711
8565
|
};
|
|
7712
8566
|
let wasted = normalizeUsage();
|
|
7713
|
-
|
|
7714
|
-
|
|
7715
|
-
|
|
7716
|
-
|
|
7717
|
-
|
|
7718
|
-
|
|
7719
|
-
|
|
7720
|
-
|
|
7721
|
-
|
|
8567
|
+
const schema = z6.object({
|
|
8568
|
+
route: z6.enum(labels).describe("The label of the chosen route")
|
|
8569
|
+
});
|
|
8570
|
+
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
8571
|
+
try {
|
|
8572
|
+
const r = await generateStructured(agent.models.planner, schema, call());
|
|
8573
|
+
return {
|
|
8574
|
+
route: matchPipelineRoute(node, r.object),
|
|
8575
|
+
usage: addUsage(wasted, normalizeUsage(r.usage))
|
|
8576
|
+
};
|
|
8577
|
+
} catch (err) {
|
|
8578
|
+
if (signal.aborted) throw aborted2();
|
|
8579
|
+
const spent = usageOfError(err);
|
|
8580
|
+
wasted = addUsage(wasted, spent);
|
|
8581
|
+
const finishReason = NoObjectGeneratedError2.isInstance(err) ? err.finishReason : void 0;
|
|
8582
|
+
if (!observeReasoning(config, "replanner", window, finishReason, spent.reasoningTokens)) break;
|
|
8583
|
+
}
|
|
7722
8584
|
}
|
|
7723
8585
|
try {
|
|
7724
|
-
const r = await generate(agent.models.planner, call);
|
|
8586
|
+
const r = await generate(agent.models.planner, call());
|
|
7725
8587
|
return {
|
|
7726
8588
|
route: matchPipelineRoute(node, r.text),
|
|
7727
8589
|
usage: addUsage(wasted, normalizeUsage(r.usage))
|
|
7728
8590
|
};
|
|
7729
8591
|
} catch {
|
|
7730
|
-
if (signal.aborted) throw
|
|
8592
|
+
if (signal.aborted) throw aborted2();
|
|
7731
8593
|
return { usage: wasted };
|
|
7732
8594
|
}
|
|
7733
8595
|
};
|
|
@@ -7740,7 +8602,7 @@ var pickRouteWithDecisionModel = async ({ agent, config }, node, text, signal, e
|
|
|
7740
8602
|
try {
|
|
7741
8603
|
outcome = await askDecisionModel(model, question, config.decision, signal);
|
|
7742
8604
|
} catch (err) {
|
|
7743
|
-
if (signal.aborted) throw
|
|
8605
|
+
if (signal.aborted) throw aborted2();
|
|
7744
8606
|
throw err;
|
|
7745
8607
|
}
|
|
7746
8608
|
const usage = decisionUsageOf(outcome);
|
|
@@ -7797,7 +8659,7 @@ var createPipeline = (definition, options) => {
|
|
|
7797
8659
|
ctx.emit(event);
|
|
7798
8660
|
}
|
|
7799
8661
|
});
|
|
7800
|
-
if (result.stopped || ctx.signal.aborted) throw
|
|
8662
|
+
if (result.stopped || ctx.signal.aborted) throw aborted2();
|
|
7801
8663
|
if (failure !== void 0) throw new Error(failure);
|
|
7802
8664
|
if (!node.routes?.length) return { text: result.final, usage: result.usage };
|
|
7803
8665
|
const picked = await pickPipelineRoute(node, result.final, {
|
|
@@ -7878,7 +8740,7 @@ var safePost = (target, message) => {
|
|
|
7878
8740
|
};
|
|
7879
8741
|
|
|
7880
8742
|
// src/subagent/tool.ts
|
|
7881
|
-
var
|
|
8743
|
+
var abortError4 = () => {
|
|
7882
8744
|
const e = new Error("The subagent was aborted");
|
|
7883
8745
|
e.name = "AbortError";
|
|
7884
8746
|
return e;
|
|
@@ -7896,7 +8758,7 @@ var createSemaphore = (size) => {
|
|
|
7896
8758
|
const onAbort = () => {
|
|
7897
8759
|
const i = queue.indexOf(go);
|
|
7898
8760
|
if (i >= 0) queue.splice(i, 1);
|
|
7899
|
-
reject(
|
|
8761
|
+
reject(abortError4());
|
|
7900
8762
|
};
|
|
7901
8763
|
queue.push(go);
|
|
7902
8764
|
signal?.addEventListener("abort", onAbort, { once: true });
|
|
@@ -8001,21 +8863,27 @@ var createSubagentTool = (opts) => {
|
|
|
8001
8863
|
})
|
|
8002
8864
|
);
|
|
8003
8865
|
};
|
|
8004
|
-
const runInProcess = async (task, signal, forward, hostTools, profile, id, elicitations) => {
|
|
8866
|
+
const runInProcess = async (task, signal, forward, hostTools, profile, id, elicitations, sessionLocks) => {
|
|
8005
8867
|
const config = { ...opts.config, ...profile?.config };
|
|
8006
8868
|
const agent = await createAgent({
|
|
8007
8869
|
...config,
|
|
8008
8870
|
tools: { ...asSubagentCalls(config.tools, id, elicitations), ...hostTools }
|
|
8009
8871
|
});
|
|
8010
8872
|
let runError;
|
|
8011
|
-
const result = await agent.run(
|
|
8012
|
-
|
|
8013
|
-
|
|
8014
|
-
|
|
8015
|
-
|
|
8016
|
-
|
|
8017
|
-
|
|
8018
|
-
|
|
8873
|
+
const result = await agent.run(
|
|
8874
|
+
task,
|
|
8875
|
+
withSessionLocks(
|
|
8876
|
+
{
|
|
8877
|
+
signal,
|
|
8878
|
+
onEvent: (e) => {
|
|
8879
|
+
if (e.type === "error" && e.phase === "run") runError = e.error;
|
|
8880
|
+
forward(e);
|
|
8881
|
+
}
|
|
8882
|
+
},
|
|
8883
|
+
sessionLocks
|
|
8884
|
+
)
|
|
8885
|
+
);
|
|
8886
|
+
if (result.stopped) throw abortError4();
|
|
8019
8887
|
if (runError) throw new Error(runError);
|
|
8020
8888
|
return { text: result.final, usage: result.usage };
|
|
8021
8889
|
};
|
|
@@ -8039,9 +8907,9 @@ var createSubagentTool = (opts) => {
|
|
|
8039
8907
|
return toCloneable({ ...cfg, model });
|
|
8040
8908
|
};
|
|
8041
8909
|
const runInWorker = async (task, signal, forward, hostTools, profile, clock) => {
|
|
8042
|
-
if (signal?.aborted) throw
|
|
8910
|
+
if (signal?.aborted) throw abortError4();
|
|
8043
8911
|
const [config, proxied] = await Promise.all([workerConfigFor(profile), proxiedSpecs()]);
|
|
8044
|
-
if (signal?.aborted) throw
|
|
8912
|
+
if (signal?.aborted) throw abortError4();
|
|
8045
8913
|
const worker = opts.worker();
|
|
8046
8914
|
return new Promise((resolve, reject) => {
|
|
8047
8915
|
let settled = false;
|
|
@@ -8058,7 +8926,7 @@ var createSubagentTool = (opts) => {
|
|
|
8058
8926
|
};
|
|
8059
8927
|
const onAbort = () => {
|
|
8060
8928
|
safePost(worker, { type: "abort" });
|
|
8061
|
-
finish(() => reject(
|
|
8929
|
+
finish(() => reject(abortError4()));
|
|
8062
8930
|
};
|
|
8063
8931
|
const onError = (ev) => finish(() => reject(new Error(`subagent worker failed: ${ev?.message ?? "unknown error"}`)));
|
|
8064
8932
|
const callHostTool = async (callId, name, input) => {
|
|
@@ -8189,7 +9057,8 @@ ${profileNames.map((n) => `- ${n}: ${profiles[n].description}`).join("\n")}` : o
|
|
|
8189
9057
|
hostTools,
|
|
8190
9058
|
profile,
|
|
8191
9059
|
id,
|
|
8192
|
-
runCtx?.elicitations
|
|
9060
|
+
runCtx?.elicitations,
|
|
9061
|
+
runCtx?.sessionLocks?.() ?? []
|
|
8193
9062
|
)).catch((err) => {
|
|
8194
9063
|
if (stoppedByUser)
|
|
8195
9064
|
throw new Error(
|
|
@@ -8230,18 +9099,25 @@ import { dynamicTool, jsonSchema as jsonSchema5 } from "ai";
|
|
|
8230
9099
|
|
|
8231
9100
|
// src/secrets/store.ts
|
|
8232
9101
|
var VaultCredentialStore = class {
|
|
9102
|
+
/** The database the vault lives in, and the name its change notices go out under. */
|
|
9103
|
+
dbName;
|
|
8233
9104
|
vault;
|
|
9105
|
+
tab;
|
|
8234
9106
|
constructor(opts = {}) {
|
|
8235
|
-
this.
|
|
9107
|
+
this.dbName = opts.dbName ?? "agent-web";
|
|
9108
|
+
this.vault = new IndexedDBVault({ ...opts, dbName: this.dbName });
|
|
9109
|
+
this.tab = currentTab();
|
|
8236
9110
|
}
|
|
8237
9111
|
getApiKey(ref) {
|
|
8238
9112
|
return this.vault.getSecret(ref);
|
|
8239
9113
|
}
|
|
8240
|
-
setApiKey(ref, key) {
|
|
8241
|
-
|
|
9114
|
+
async setApiKey(ref, key) {
|
|
9115
|
+
await this.vault.setSecret(ref, key);
|
|
9116
|
+
postStorageChangeFrom(this.tab, this.dbName, { kind: "credentials", op: "put" });
|
|
8242
9117
|
}
|
|
8243
|
-
deleteApiKey(ref) {
|
|
8244
|
-
|
|
9118
|
+
async deleteApiKey(ref) {
|
|
9119
|
+
await this.vault.deleteSecret(ref);
|
|
9120
|
+
postStorageChangeFrom(this.tab, this.dbName, { kind: "credentials", op: "delete" });
|
|
8245
9121
|
}
|
|
8246
9122
|
};
|
|
8247
9123
|
var MemoryCredentialStore = class {
|
|
@@ -8398,9 +9274,12 @@ var MemoryStore = class {
|
|
|
8398
9274
|
|
|
8399
9275
|
// src/memory/sessions.ts
|
|
8400
9276
|
var IndexedDBStore = class {
|
|
9277
|
+
/** The database it lives in - and the name its tabs share it under (`sessionLock`, notices). */
|
|
8401
9278
|
dbName;
|
|
9279
|
+
tab;
|
|
8402
9280
|
constructor(opts = {}) {
|
|
8403
|
-
this.dbName = opts.dbName;
|
|
9281
|
+
this.dbName = opts.dbName ?? "agent-web";
|
|
9282
|
+
this.tab = currentTab();
|
|
8404
9283
|
}
|
|
8405
9284
|
async load(sessionId) {
|
|
8406
9285
|
const db = await openAgentWebDB({ dbName: this.dbName });
|
|
@@ -8410,6 +9289,7 @@ var IndexedDBStore = class {
|
|
|
8410
9289
|
async replace(sessionId, messages) {
|
|
8411
9290
|
const db = await openAgentWebDB({ dbName: this.dbName });
|
|
8412
9291
|
await db.put(SESSIONS_STORE, messages, sessionId);
|
|
9292
|
+
postStorageChangeFrom(this.tab, this.dbName, { kind: "session", op: "put", key: sessionId });
|
|
8413
9293
|
}
|
|
8414
9294
|
async append(sessionId, message) {
|
|
8415
9295
|
const current = await this.load(sessionId);
|
|
@@ -8419,6 +9299,7 @@ var IndexedDBStore = class {
|
|
|
8419
9299
|
async clear(sessionId) {
|
|
8420
9300
|
const db = await openAgentWebDB({ dbName: this.dbName });
|
|
8421
9301
|
await db.delete(SESSIONS_STORE, sessionId);
|
|
9302
|
+
postStorageChangeFrom(this.tab, this.dbName, { kind: "session", op: "delete", key: sessionId });
|
|
8422
9303
|
}
|
|
8423
9304
|
/** List all stored session ids. */
|
|
8424
9305
|
async listSessions() {
|
|
@@ -8476,11 +9357,14 @@ var jsonSafe = (value) => JSON.parse(
|
|
|
8476
9357
|
)
|
|
8477
9358
|
);
|
|
8478
9359
|
var IndexedDBRunStore = class {
|
|
9360
|
+
/** The database it lives in, and the name its change notices (`runs`) go out under. */
|
|
8479
9361
|
dbName;
|
|
8480
9362
|
keepCompleted;
|
|
9363
|
+
tab;
|
|
8481
9364
|
constructor(opts = {}) {
|
|
8482
|
-
this.dbName = opts.dbName;
|
|
9365
|
+
this.dbName = opts.dbName ?? "agent-web";
|
|
8483
9366
|
this.keepCompleted = opts.keepCompleted ?? false;
|
|
9367
|
+
this.tab = currentTab();
|
|
8484
9368
|
}
|
|
8485
9369
|
async put(snapshot) {
|
|
8486
9370
|
const db = await openAgentWebDB({ dbName: this.dbName });
|
|
@@ -8490,6 +9374,7 @@ var IndexedDBRunStore = class {
|
|
|
8490
9374
|
if (err?.name !== "DataCloneError") throw err;
|
|
8491
9375
|
await db.put(RUNS_STORE, jsonSafe(snapshot), snapshot.runId);
|
|
8492
9376
|
}
|
|
9377
|
+
postStorageChangeFrom(this.tab, this.dbName, { kind: "runs", op: "put", key: snapshot.runId });
|
|
8493
9378
|
}
|
|
8494
9379
|
onRunStart(snapshot) {
|
|
8495
9380
|
return this.put(snapshot);
|
|
@@ -8524,10 +9409,12 @@ var IndexedDBRunStore = class {
|
|
|
8524
9409
|
async delete(runId) {
|
|
8525
9410
|
const db = await openAgentWebDB({ dbName: this.dbName });
|
|
8526
9411
|
await db.delete(RUNS_STORE, runId);
|
|
9412
|
+
postStorageChangeFrom(this.tab, this.dbName, { kind: "runs", op: "delete", key: runId });
|
|
8527
9413
|
}
|
|
8528
9414
|
async clear() {
|
|
8529
9415
|
const db = await openAgentWebDB({ dbName: this.dbName });
|
|
8530
9416
|
await db.clear(RUNS_STORE);
|
|
9417
|
+
postStorageChangeFrom(this.tab, this.dbName, { kind: "runs", op: "clear" });
|
|
8531
9418
|
}
|
|
8532
9419
|
};
|
|
8533
9420
|
export {
|
|
@@ -8597,12 +9484,17 @@ export {
|
|
|
8597
9484
|
MemoryRunStore,
|
|
8598
9485
|
MemorySkillStore,
|
|
8599
9486
|
MemoryStore,
|
|
9487
|
+
NO_ATTACHMENT_NOTE,
|
|
8600
9488
|
PIPELINE_LIMITS,
|
|
8601
9489
|
PIPELINE_ROUTER_SYSTEM,
|
|
8602
9490
|
PipelineNodeError,
|
|
8603
9491
|
PipelineValidationError,
|
|
8604
9492
|
PlanSchema,
|
|
8605
9493
|
PlanStepSchema,
|
|
9494
|
+
RELAY_MAX_REPLAYS_PER_SECOND,
|
|
9495
|
+
RELAY_MAX_SENDS,
|
|
9496
|
+
RELAY_MAX_SEND_CHARS,
|
|
9497
|
+
RELAY_MAX_STRING,
|
|
8606
9498
|
REPLAY_NOTE,
|
|
8607
9499
|
RUNS_STORE,
|
|
8608
9500
|
ReplanSchema,
|
|
@@ -8621,11 +9513,14 @@ export {
|
|
|
8621
9513
|
SEARCH_PROVIDERS,
|
|
8622
9514
|
SECRETS_STORE,
|
|
8623
9515
|
SESSIONS_STORE,
|
|
9516
|
+
SESSION_LOCK_MODES,
|
|
8624
9517
|
SKILL_TOOL_NAMES,
|
|
8625
9518
|
SPAWN_INPUT_SCHEMA,
|
|
8626
9519
|
SPAWN_SUBAGENT_TOOL,
|
|
9520
|
+
STORAGE_CHANGE_KINDS,
|
|
8627
9521
|
SUBAGENT_DEFAULTS,
|
|
8628
9522
|
SUBAGENT_MAX_DEPTH_LIMIT,
|
|
9523
|
+
SessionBusyError,
|
|
8629
9524
|
SubagentSpawnError,
|
|
8630
9525
|
TOOL_APPROVAL_MODES,
|
|
8631
9526
|
TOOL_APPROVAL_TIMEOUT_MS,
|
|
@@ -8734,6 +9629,7 @@ export {
|
|
|
8734
9629
|
normalizeSkillName,
|
|
8735
9630
|
normalizeSteps,
|
|
8736
9631
|
normalizeUsage,
|
|
9632
|
+
onStorageChange,
|
|
8737
9633
|
openAgentWebDB,
|
|
8738
9634
|
outputCapNotice,
|
|
8739
9635
|
parseExecutorResponse,
|
|
@@ -8744,6 +9640,7 @@ export {
|
|
|
8744
9640
|
parseSkillMarkdown,
|
|
8745
9641
|
pickPipelineRoute,
|
|
8746
9642
|
pickTier,
|
|
9643
|
+
postStorageChange,
|
|
8747
9644
|
preloadWebLLMModel,
|
|
8748
9645
|
preparePipeline,
|
|
8749
9646
|
promptHintOf,
|
|
@@ -8782,6 +9679,7 @@ export {
|
|
|
8782
9679
|
sniffMediaType,
|
|
8783
9680
|
splitBlocker,
|
|
8784
9681
|
stageOutputCap,
|
|
9682
|
+
stageReasons,
|
|
8785
9683
|
stream,
|
|
8786
9684
|
supportsImages,
|
|
8787
9685
|
supportsNativeTools,
|
|
@@ -8798,6 +9696,7 @@ export {
|
|
|
8798
9696
|
toolRunContextOf,
|
|
8799
9697
|
unloadWebLLMModel,
|
|
8800
9698
|
validatePipeline,
|
|
9699
|
+
watchSession,
|
|
8801
9700
|
webLLMContextWindow,
|
|
8802
9701
|
withRollingBreakpoint,
|
|
8803
9702
|
withSystem,
|