@dudko.dev/agent-web 0.0.42 → 0.0.44
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 +150 -4
- package/dist/agent-web.js +155 -155
- 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 +1248 -108
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1777 -1643
- package/dist/index.d.ts +1777 -1643
- package/dist/index.js +996 -89
- 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/pipeline-engine.cjs +1130 -0
- package/dist/pipeline-engine.cjs.map +1 -0
- package/dist/pipeline-engine.d.cts +226 -0
- package/dist/pipeline-engine.d.ts +226 -0
- package/dist/pipeline-engine.js +1094 -0
- package/dist/pipeline-engine.js.map +1 -0
- 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 +13 -3
- 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) => {
|
|
@@ -1027,9 +1040,24 @@ var ORIGIN_FILE = ".origin.json";
|
|
|
1027
1040
|
var VfsSkillStore = class {
|
|
1028
1041
|
vfs;
|
|
1029
1042
|
dir;
|
|
1043
|
+
tab;
|
|
1030
1044
|
constructor(vfs, dir = "/skills") {
|
|
1031
1045
|
this.vfs = vfs;
|
|
1032
1046
|
this.dir = dir.replace(/\/+$/, "") || "/skills";
|
|
1047
|
+
this.tab = currentTab();
|
|
1048
|
+
}
|
|
1049
|
+
/** The file system's database (undefined in memory): where its `skills` notices go out. */
|
|
1050
|
+
get dbName() {
|
|
1051
|
+
return this.vfs.dbName;
|
|
1052
|
+
}
|
|
1053
|
+
/** The other tabs hear which lesson, in which folder - never its text. */
|
|
1054
|
+
announce(op, name) {
|
|
1055
|
+
postStorageChangeFrom(this.tab, this.vfs.dbName, {
|
|
1056
|
+
kind: "skills",
|
|
1057
|
+
op,
|
|
1058
|
+
key: name,
|
|
1059
|
+
namespace: this.dir
|
|
1060
|
+
});
|
|
1033
1061
|
}
|
|
1034
1062
|
async list() {
|
|
1035
1063
|
const out = [];
|
|
@@ -1063,12 +1091,14 @@ ${skill.content.trim()}
|
|
|
1063
1091
|
mimeType: "application/json"
|
|
1064
1092
|
});
|
|
1065
1093
|
}
|
|
1094
|
+
this.announce("put", skill.name);
|
|
1066
1095
|
}
|
|
1067
1096
|
async remove(name) {
|
|
1068
1097
|
if (!SKILL_NAME_RE.test(name)) return false;
|
|
1069
1098
|
const folder = `${this.dir}/${name}`;
|
|
1070
1099
|
const had = await this.vfs.delete(`${folder}/SKILL.md`);
|
|
1071
1100
|
await this.vfs.delete(`${folder}/${ORIGIN_FILE}`);
|
|
1101
|
+
if (had) this.announce("delete", name);
|
|
1072
1102
|
return had;
|
|
1073
1103
|
}
|
|
1074
1104
|
};
|
|
@@ -1076,12 +1106,10 @@ var createLearning = async (cfg, skills, warn) => {
|
|
|
1076
1106
|
const store = cfg.store ?? new MemorySkillStore();
|
|
1077
1107
|
const maxSkills = Math.max(1, cfg.maxSkills ?? DEFAULT_MAX_LEARNED_SKILLS);
|
|
1078
1108
|
const maxChars = Math.max(MIN_INSTRUCTIONS_CHARS, cfg.maxSkillChars ?? DEFAULT_MAX_SKILL_CHARS);
|
|
1109
|
+
const lessonOf = (stored) => defineSkill({ ...stored, origin: stored.origin ?? { kind: "learned", at: 0, revision: 1 } });
|
|
1079
1110
|
for (const stored of await store.list()) {
|
|
1080
1111
|
try {
|
|
1081
|
-
const skill =
|
|
1082
|
-
...stored,
|
|
1083
|
-
origin: stored.origin ?? { kind: "learned", at: 0, revision: 1 }
|
|
1084
|
-
});
|
|
1112
|
+
const skill = lessonOf(stored);
|
|
1085
1113
|
if (skills.some((s) => s.name === skill.name)) {
|
|
1086
1114
|
warn(
|
|
1087
1115
|
`[learning] a stored lesson named "${skill.name}" clashes with a configured skill; skipped`
|
|
@@ -1094,6 +1122,27 @@ var createLearning = async (cfg, skills, warn) => {
|
|
|
1094
1122
|
}
|
|
1095
1123
|
}
|
|
1096
1124
|
const learned = () => skills.filter((s) => s.origin?.kind === "learned");
|
|
1125
|
+
const reload = async () => {
|
|
1126
|
+
const fresh = /* @__PURE__ */ new Map();
|
|
1127
|
+
for (const stored of await store.list()) {
|
|
1128
|
+
try {
|
|
1129
|
+
const skill = lessonOf(stored);
|
|
1130
|
+
if (skills.some((s) => s.name === skill.name && s.origin?.kind !== "learned")) continue;
|
|
1131
|
+
fresh.set(skill.name, skill);
|
|
1132
|
+
} catch {
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
for (let i = skills.length - 1; i >= 0; i -= 1) {
|
|
1136
|
+
const s = skills[i];
|
|
1137
|
+
if (s.origin?.kind === "learned" && !fresh.has(s.name)) skills.splice(i, 1);
|
|
1138
|
+
}
|
|
1139
|
+
for (const [name, skill] of fresh) {
|
|
1140
|
+
const at = skills.findIndex((s) => s.name === name);
|
|
1141
|
+
if (at >= 0) skills[at] = skill;
|
|
1142
|
+
else skills.push(skill);
|
|
1143
|
+
}
|
|
1144
|
+
return learned();
|
|
1145
|
+
};
|
|
1097
1146
|
const save = async (input, options) => {
|
|
1098
1147
|
const name = normalizeSkillName(input.name);
|
|
1099
1148
|
if (!name) {
|
|
@@ -1204,7 +1253,7 @@ var createLearning = async (cfg, skills, warn) => {
|
|
|
1204
1253
|
}
|
|
1205
1254
|
})
|
|
1206
1255
|
};
|
|
1207
|
-
return { tools, learned, forget };
|
|
1256
|
+
return { tools, learned, forget, reload };
|
|
1208
1257
|
};
|
|
1209
1258
|
|
|
1210
1259
|
// src/prompts.ts
|
|
@@ -3553,6 +3602,12 @@ var followHumanWaits = (clock) => {
|
|
|
3553
3602
|
|
|
3554
3603
|
// src/agent/control.ts
|
|
3555
3604
|
var ports = /* @__PURE__ */ new WeakMap();
|
|
3605
|
+
var queuedEvent = (m) => ({
|
|
3606
|
+
type: "message.queued",
|
|
3607
|
+
id: m.id,
|
|
3608
|
+
text: m.text,
|
|
3609
|
+
...m.origin ? { origin: m.origin } : {}
|
|
3610
|
+
});
|
|
3556
3611
|
var portOf = (control) => {
|
|
3557
3612
|
if (!control) return void 0;
|
|
3558
3613
|
const port = ports.get(control);
|
|
@@ -3565,15 +3620,20 @@ var createRunControl = () => {
|
|
|
3565
3620
|
let emit;
|
|
3566
3621
|
let ended = false;
|
|
3567
3622
|
const children = /* @__PURE__ */ new Map();
|
|
3623
|
+
const queueMessage = (text, origin) => {
|
|
3624
|
+
const clean = typeof text === "string" ? text.trim() : "";
|
|
3625
|
+
if (!clean || ended) return false;
|
|
3626
|
+
const message = {
|
|
3627
|
+
id: `msg-${seq3 += 1}`,
|
|
3628
|
+
text: clean,
|
|
3629
|
+
...origin ? { origin } : {}
|
|
3630
|
+
};
|
|
3631
|
+
queue.push(message);
|
|
3632
|
+
emit?.(queuedEvent(message));
|
|
3633
|
+
return true;
|
|
3634
|
+
};
|
|
3568
3635
|
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
|
-
},
|
|
3636
|
+
send: (text) => queueMessage(text),
|
|
3577
3637
|
pending: () => queue.map((m) => m.text),
|
|
3578
3638
|
subagents: () => [...children.values()].map((c) => c.info).sort((a, b) => a.startedAt - b.startedAt),
|
|
3579
3639
|
stopSubagent(id) {
|
|
@@ -3591,7 +3651,7 @@ var createRunControl = () => {
|
|
|
3591
3651
|
}
|
|
3592
3652
|
emit = next;
|
|
3593
3653
|
ended = false;
|
|
3594
|
-
for (const m of queue) next(
|
|
3654
|
+
for (const m of queue) next(queuedEvent(m));
|
|
3595
3655
|
},
|
|
3596
3656
|
detach() {
|
|
3597
3657
|
emit = void 0;
|
|
@@ -3604,6 +3664,7 @@ var createRunControl = () => {
|
|
|
3604
3664
|
queue = [];
|
|
3605
3665
|
return out;
|
|
3606
3666
|
},
|
|
3667
|
+
sendFrom: (text, origin) => queueMessage(text, origin),
|
|
3607
3668
|
registerSubagent(info, stop) {
|
|
3608
3669
|
children.set(info.id, { info, stop });
|
|
3609
3670
|
return () => {
|
|
@@ -4162,6 +4223,7 @@ var SPAWN_INPUT_SCHEMA = {
|
|
|
4162
4223
|
description: "Optional: the names of YOUR tools the helper may use. Only tools you have can be named. Omit it for the default set; pass [] for a helper that only reasons."
|
|
4163
4224
|
}
|
|
4164
4225
|
},
|
|
4226
|
+
// A mutable array: JSON Schema 7's `required` is `string[]`, and `as const` would make it readonly.
|
|
4165
4227
|
required: ["task"],
|
|
4166
4228
|
additionalProperties: false
|
|
4167
4229
|
};
|
|
@@ -4581,8 +4643,69 @@ var resolveResume = async (persistence, resumeFromRunId) => {
|
|
|
4581
4643
|
`Run "${resumeFromRunId}" has no steps left to run (status="${snapshot.status}"); nothing to resume`
|
|
4582
4644
|
);
|
|
4583
4645
|
}
|
|
4646
|
+
if (snapshot.attempt !== void 0 && !(Number.isSafeInteger(snapshot.attempt) && snapshot.attempt >= 1)) {
|
|
4647
|
+
throw new Error(
|
|
4648
|
+
`Run "${resumeFromRunId}" has an invalid attempt (${JSON.stringify(snapshot.attempt)}); it must be a positive integer`
|
|
4649
|
+
);
|
|
4650
|
+
}
|
|
4584
4651
|
return snapshot;
|
|
4585
4652
|
};
|
|
4653
|
+
var resolveRunId = async (persistence, runId, resumeFromRunId) => {
|
|
4654
|
+
if (runId === void 0) return void 0;
|
|
4655
|
+
if (resumeFromRunId !== void 0) {
|
|
4656
|
+
throw new Error(
|
|
4657
|
+
"runId names a fresh run and cannot be combined with resumeFromRunId: a resume keeps the id of the run it resumes"
|
|
4658
|
+
);
|
|
4659
|
+
}
|
|
4660
|
+
assertSafeRunId(runId, "runId");
|
|
4661
|
+
const snapshot = await persistence?.loadRun?.(runId);
|
|
4662
|
+
if (snapshot) {
|
|
4663
|
+
throw new Error(
|
|
4664
|
+
`Run "${runId}" already exists (status "${snapshot.status}"); resume it with resumeFromRunId instead of starting it again`
|
|
4665
|
+
);
|
|
4666
|
+
}
|
|
4667
|
+
return runId;
|
|
4668
|
+
};
|
|
4669
|
+
var resumeAttemptOf = (snapshot) => (snapshot.attempt ?? 1) + 1;
|
|
4670
|
+
var recordResume = async (persistence, resumed, attempt, warn) => {
|
|
4671
|
+
const hook = persistence?.onRunResume ? "onRunResume" : persistence?.onStepComplete ? "onStepComplete" : void 0;
|
|
4672
|
+
if (!persistence || !hook) {
|
|
4673
|
+
warn(
|
|
4674
|
+
`persistence has neither onRunResume nor onStepComplete: attempt ${attempt} of run ${resumed.runId} is not on record until the run ends`
|
|
4675
|
+
);
|
|
4676
|
+
return;
|
|
4677
|
+
}
|
|
4678
|
+
const { error: _error, completedAt: _completedAt, text: _text, ...rest } = resumed;
|
|
4679
|
+
void [_error, _completedAt, _text];
|
|
4680
|
+
try {
|
|
4681
|
+
await persistence[hook]?.call(persistence, { ...rest, status: "executing", attempt });
|
|
4682
|
+
} catch (err) {
|
|
4683
|
+
throw new Error(
|
|
4684
|
+
`persistence.${hook} threw while recording attempt ${attempt} of run ${resumed.runId}; the resume was refused: ${err instanceof Error ? err.message : String(err)}`,
|
|
4685
|
+
{ cause: err }
|
|
4686
|
+
);
|
|
4687
|
+
}
|
|
4688
|
+
};
|
|
4689
|
+
var SERVER_ONLY = "is the server package's (@dudko.dev/agent), not this browser package's";
|
|
4690
|
+
var refuseServerOnlyConfig = (config) => {
|
|
4691
|
+
const c = config;
|
|
4692
|
+
for (const key of ["runLease", "sharedLimits"]) {
|
|
4693
|
+
if (c[key] !== void 0) {
|
|
4694
|
+
throw new Error(`${key} ${SERVER_ONLY}: a run in a page has no other worker to share with`);
|
|
4695
|
+
}
|
|
4696
|
+
}
|
|
4697
|
+
const persistence = c.persistence;
|
|
4698
|
+
if (persistence?.journal !== void 0) {
|
|
4699
|
+
throw new Error(
|
|
4700
|
+
`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`
|
|
4701
|
+
);
|
|
4702
|
+
}
|
|
4703
|
+
};
|
|
4704
|
+
var refuseServerOnlyRunOptions = (opts) => {
|
|
4705
|
+
if (opts.answers !== void 0) {
|
|
4706
|
+
throw new Error(`run({ answers }) ${SERVER_ONLY}: there are no parked runs here to answer`);
|
|
4707
|
+
}
|
|
4708
|
+
};
|
|
4586
4709
|
|
|
4587
4710
|
// src/agent/schemas.ts
|
|
4588
4711
|
import { z as z5 } from "zod";
|
|
@@ -5421,6 +5544,485 @@ var createDynamicSubagentTool = (deps) => {
|
|
|
5421
5544
|
return markReadOnly(t);
|
|
5422
5545
|
};
|
|
5423
5546
|
|
|
5547
|
+
// src/sync/session.ts
|
|
5548
|
+
var SESSION_LOCK_MODES = ["wait", "fail", "off"];
|
|
5549
|
+
var SessionBusyError = class extends Error {
|
|
5550
|
+
sessionId;
|
|
5551
|
+
heldBy;
|
|
5552
|
+
constructor(sessionId, heldBy) {
|
|
5553
|
+
super(
|
|
5554
|
+
`session "${sessionId}" is already running ${heldBy === "this-tab" ? "in this tab" : "in another tab"}; with sessionLock 'fail' a run does not wait for it`
|
|
5555
|
+
);
|
|
5556
|
+
this.name = "SessionBusyError";
|
|
5557
|
+
this.sessionId = sessionId;
|
|
5558
|
+
this.heldBy = heldBy;
|
|
5559
|
+
}
|
|
5560
|
+
};
|
|
5561
|
+
var sessionLockName = (dbName, sessionId) => `@dudko.dev/agent-web/session:${scopeOf(dbName)}:${encodeURIComponent(sessionId)}`;
|
|
5562
|
+
var RELAY_MAX_STRING = 8e3;
|
|
5563
|
+
var RELAY_MAX_ARRAY = 200;
|
|
5564
|
+
var RELAY_MAX_KEYS = 100;
|
|
5565
|
+
var RELAY_MAX_DEPTH = 8;
|
|
5566
|
+
var RELAY_MAX_REPLAY_EVENTS = 2e3;
|
|
5567
|
+
var RELAY_MAX_REPLAY_CHARS = 2e6;
|
|
5568
|
+
var RELAY_MAX_SEND_CHARS = 32e3;
|
|
5569
|
+
var RELAY_MAX_SENDS = 50;
|
|
5570
|
+
var RELAY_MAX_REPLAYS_PER_SECOND = 8;
|
|
5571
|
+
var WATCH_RESYNC_MS = 1e3;
|
|
5572
|
+
var WATCH_HOLDER_POLL_MS = 1e3;
|
|
5573
|
+
var WATCH_MAX_PENDING = 500;
|
|
5574
|
+
var ACK_TIMEOUT_MS = 3e3;
|
|
5575
|
+
var GONE_GRACE_MS = 300;
|
|
5576
|
+
var RUN_ID_RE = /^[A-Za-z0-9_-]{1,128}$/;
|
|
5577
|
+
var EVENT_TYPE_RE = /^[a-z][a-z0-9.-]{0,63}$/;
|
|
5578
|
+
var UNSAFE_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
5579
|
+
var clipText = (s) => s.length > RELAY_MAX_STRING ? `${s.slice(0, RELAY_MAX_STRING - 1)}\u2026` : s;
|
|
5580
|
+
var slimEvent = (value, depth = 0) => {
|
|
5581
|
+
if (typeof value === "string") return clipText(value);
|
|
5582
|
+
if (typeof value === "number" || typeof value === "boolean" || value === null) return value;
|
|
5583
|
+
if (typeof value === "bigint") return value.toString();
|
|
5584
|
+
if (typeof value !== "object") return void 0;
|
|
5585
|
+
if (value instanceof Error) return clipText(value.message);
|
|
5586
|
+
if (ArrayBuffer.isView(value) || value instanceof ArrayBuffer) {
|
|
5587
|
+
return `[${value.byteLength} bytes]`;
|
|
5588
|
+
}
|
|
5589
|
+
if (depth >= RELAY_MAX_DEPTH) return "[\u2026]";
|
|
5590
|
+
if (Array.isArray(value)) {
|
|
5591
|
+
const out2 = value.slice(0, RELAY_MAX_ARRAY).map((v) => slimEvent(v, depth + 1) ?? null);
|
|
5592
|
+
if (value.length > RELAY_MAX_ARRAY) out2.push(`[\u2026 ${value.length - RELAY_MAX_ARRAY} more]`);
|
|
5593
|
+
return out2;
|
|
5594
|
+
}
|
|
5595
|
+
const out = {};
|
|
5596
|
+
let keys = 0;
|
|
5597
|
+
for (const [k, v] of Object.entries(value)) {
|
|
5598
|
+
if (UNSAFE_KEYS.has(k)) continue;
|
|
5599
|
+
if (keys >= RELAY_MAX_KEYS) break;
|
|
5600
|
+
keys += 1;
|
|
5601
|
+
const s = slimEvent(v, depth + 1);
|
|
5602
|
+
if (s !== void 0) out[k] = s;
|
|
5603
|
+
}
|
|
5604
|
+
return out;
|
|
5605
|
+
};
|
|
5606
|
+
var charsOf = (value) => {
|
|
5607
|
+
if (typeof value === "string") return value.length;
|
|
5608
|
+
if (Array.isArray(value)) return value.reduce((n, v) => n + charsOf(v), 2);
|
|
5609
|
+
if (isRecord(value)) {
|
|
5610
|
+
let n = 2;
|
|
5611
|
+
for (const [k, v] of Object.entries(value)) n += k.length + charsOf(v);
|
|
5612
|
+
return n;
|
|
5613
|
+
}
|
|
5614
|
+
return 4;
|
|
5615
|
+
};
|
|
5616
|
+
var relayedEventOf = (value) => {
|
|
5617
|
+
if (!isRecord(value) || typeof value.type !== "string" || !EVENT_TYPE_RE.test(value.type)) {
|
|
5618
|
+
return void 0;
|
|
5619
|
+
}
|
|
5620
|
+
return slimEvent(value);
|
|
5621
|
+
};
|
|
5622
|
+
var idOk = (value) => typeof value === "string" && SYNC_ID_RE.test(value);
|
|
5623
|
+
var watcherMessageOf = (data) => {
|
|
5624
|
+
if (!isRecord(data) || data.v !== SYNC_VERSION || !idOk(data.from) || !idOk(data.id)) {
|
|
5625
|
+
return void 0;
|
|
5626
|
+
}
|
|
5627
|
+
if (data.t === "hello" || data.t === "stop") return { t: data.t, id: data.id };
|
|
5628
|
+
if (data.t === "send" && typeof data.text === "string") {
|
|
5629
|
+
return { t: "send", id: data.id, text: data.text };
|
|
5630
|
+
}
|
|
5631
|
+
return void 0;
|
|
5632
|
+
};
|
|
5633
|
+
var countOk = (value, min) => typeof value === "number" && Number.isSafeInteger(value) && value >= min;
|
|
5634
|
+
var holderMessageOf = (data) => {
|
|
5635
|
+
if (!isRecord(data) || data.v !== SYNC_VERSION || !idOk(data.from)) return void 0;
|
|
5636
|
+
if (data.t === "ack") {
|
|
5637
|
+
return idOk(data.id) && typeof data.ok === "boolean" ? { t: "ack", id: data.id, ok: data.ok } : void 0;
|
|
5638
|
+
}
|
|
5639
|
+
if (typeof data.runId !== "string" || !RUN_ID_RE.test(data.runId)) return void 0;
|
|
5640
|
+
const runId = data.runId;
|
|
5641
|
+
switch (data.t) {
|
|
5642
|
+
case "run":
|
|
5643
|
+
return data.state === "running" || data.state === "idle" ? { t: "run", runId, state: data.state, stopped: data.stopped === true } : void 0;
|
|
5644
|
+
case "event": {
|
|
5645
|
+
const event = relayedEventOf(data.event);
|
|
5646
|
+
return countOk(data.n, 1) && event ? { t: "event", runId, n: data.n, event } : void 0;
|
|
5647
|
+
}
|
|
5648
|
+
case "replay": {
|
|
5649
|
+
if (!idOk(data.to) || !countOk(data.n, 0) || !Array.isArray(data.events)) return void 0;
|
|
5650
|
+
if (data.events.length > RELAY_MAX_REPLAY_EVENTS) return void 0;
|
|
5651
|
+
const ns = data.ns;
|
|
5652
|
+
const top = data.n;
|
|
5653
|
+
if (!Array.isArray(ns) || ns.length !== data.events.length) return void 0;
|
|
5654
|
+
if (!ns.every((x, i) => countOk(x, 1) && x <= top && (i === 0 || x > ns[i - 1]))) {
|
|
5655
|
+
return void 0;
|
|
5656
|
+
}
|
|
5657
|
+
const events = [];
|
|
5658
|
+
for (const raw of data.events) {
|
|
5659
|
+
const event = relayedEventOf(raw);
|
|
5660
|
+
if (!event) return void 0;
|
|
5661
|
+
events.push(event);
|
|
5662
|
+
}
|
|
5663
|
+
return {
|
|
5664
|
+
t: "replay",
|
|
5665
|
+
to: data.to,
|
|
5666
|
+
runId,
|
|
5667
|
+
n: data.n,
|
|
5668
|
+
ns,
|
|
5669
|
+
events,
|
|
5670
|
+
truncated: data.truncated === true
|
|
5671
|
+
};
|
|
5672
|
+
}
|
|
5673
|
+
default:
|
|
5674
|
+
return void 0;
|
|
5675
|
+
}
|
|
5676
|
+
};
|
|
5677
|
+
var inheritedLocks = /* @__PURE__ */ new WeakMap();
|
|
5678
|
+
var withSessionLocks = (options, names) => {
|
|
5679
|
+
if (names.length) inheritedLocks.set(options, [...names]);
|
|
5680
|
+
return options;
|
|
5681
|
+
};
|
|
5682
|
+
var sessionLocksOf = (options) => inheritedLocks.get(options) ?? [];
|
|
5683
|
+
var abortError2 = () => {
|
|
5684
|
+
const err = new Error("The run was stopped while it waited for the session");
|
|
5685
|
+
err.name = "AbortError";
|
|
5686
|
+
return err;
|
|
5687
|
+
};
|
|
5688
|
+
var acquireSessionLock = async (o) => {
|
|
5689
|
+
const take = (options) => new Promise((resolve, reject) => {
|
|
5690
|
+
let granted = false;
|
|
5691
|
+
let request = void 0;
|
|
5692
|
+
request = o.locks.request(o.name, options, (lock) => {
|
|
5693
|
+
granted = true;
|
|
5694
|
+
if (!lock) {
|
|
5695
|
+
resolve(null);
|
|
5696
|
+
return void 0;
|
|
5697
|
+
}
|
|
5698
|
+
return new Promise((free) => {
|
|
5699
|
+
o.tab.held.add(o.name);
|
|
5700
|
+
let released;
|
|
5701
|
+
resolve({
|
|
5702
|
+
name: o.name,
|
|
5703
|
+
release: () => {
|
|
5704
|
+
if (!released) {
|
|
5705
|
+
o.tab.held.delete(o.name);
|
|
5706
|
+
free();
|
|
5707
|
+
released = request.then(
|
|
5708
|
+
() => void 0,
|
|
5709
|
+
() => void 0
|
|
5710
|
+
);
|
|
5711
|
+
}
|
|
5712
|
+
return released;
|
|
5713
|
+
}
|
|
5714
|
+
});
|
|
5715
|
+
});
|
|
5716
|
+
}).catch((err) => {
|
|
5717
|
+
if (!granted) reject(err);
|
|
5718
|
+
});
|
|
5719
|
+
});
|
|
5720
|
+
if (o.signal?.aborted) throw abortError2();
|
|
5721
|
+
let now;
|
|
5722
|
+
try {
|
|
5723
|
+
now = await take({ ifAvailable: true });
|
|
5724
|
+
} catch (err) {
|
|
5725
|
+
return { unavailable: err };
|
|
5726
|
+
}
|
|
5727
|
+
if (now) return { hold: now };
|
|
5728
|
+
const exclusive = await heldExclusively(o.locks, o.name);
|
|
5729
|
+
const busy = exclusive !== false;
|
|
5730
|
+
if (busy) {
|
|
5731
|
+
const heldBy = o.tab.held.has(o.name) ? "this-tab" : "another-tab";
|
|
5732
|
+
if (o.mode === "fail") throw new SessionBusyError(o.sessionId, heldBy);
|
|
5733
|
+
o.onBusy(heldBy);
|
|
5734
|
+
}
|
|
5735
|
+
const started = Date.now();
|
|
5736
|
+
try {
|
|
5737
|
+
const hold = await take(o.signal ? { signal: o.signal } : {});
|
|
5738
|
+
return { hold, ...busy ? { waitedMs: Date.now() - started } : {} };
|
|
5739
|
+
} catch (err) {
|
|
5740
|
+
if (o.signal?.aborted) throw abortError2();
|
|
5741
|
+
return { unavailable: err };
|
|
5742
|
+
}
|
|
5743
|
+
};
|
|
5744
|
+
var DELTAS = /* @__PURE__ */ new Set([
|
|
5745
|
+
"plan.thought-delta",
|
|
5746
|
+
"step.text-delta",
|
|
5747
|
+
"step.reasoning-delta",
|
|
5748
|
+
"final.text-delta",
|
|
5749
|
+
"final.reasoning-delta"
|
|
5750
|
+
]);
|
|
5751
|
+
var deltaKey = (e) => `${String(e.type)}\0${String(e.step?.id ?? "")}\0${String(e.nodeId ?? "")}\0${String(e.visit ?? "")}`;
|
|
5752
|
+
var anySignal = (host, own) => {
|
|
5753
|
+
if (!host) return own;
|
|
5754
|
+
const any = AbortSignal.any;
|
|
5755
|
+
if (typeof any === "function") return any([host, own]);
|
|
5756
|
+
const both = new AbortController();
|
|
5757
|
+
for (const s of [host, own]) {
|
|
5758
|
+
if (s.aborted) both.abort(s.reason);
|
|
5759
|
+
else s.addEventListener("abort", () => both.abort(s.reason), { once: true });
|
|
5760
|
+
}
|
|
5761
|
+
return both.signal;
|
|
5762
|
+
};
|
|
5763
|
+
var startSessionRelay = (o) => {
|
|
5764
|
+
const hub = hubOf(o.tab, sessionLockName(o.dbName, o.sessionId));
|
|
5765
|
+
if (!hub) return void 0;
|
|
5766
|
+
const stopper = new AbortController();
|
|
5767
|
+
const signal = anySignal(o.signal, stopper.signal);
|
|
5768
|
+
const from = o.tab.id;
|
|
5769
|
+
const buffer = [];
|
|
5770
|
+
let chars = 0;
|
|
5771
|
+
let truncated = false;
|
|
5772
|
+
let n = 0;
|
|
5773
|
+
let sends = 0;
|
|
5774
|
+
let ended = false;
|
|
5775
|
+
let watched = false;
|
|
5776
|
+
const replayed = /* @__PURE__ */ new Set();
|
|
5777
|
+
const recentReplays = [];
|
|
5778
|
+
const port = o.remoteControl ? portOf(o.control) : void 0;
|
|
5779
|
+
const post = (message) => hub.post({ v: SYNC_VERSION, from, runId: o.runId, ...message });
|
|
5780
|
+
const ack = (id, ok) => hub.post({ v: SYNC_VERSION, from, t: "ack", id, ok });
|
|
5781
|
+
const keep = (event) => {
|
|
5782
|
+
const last = buffer[buffer.length - 1];
|
|
5783
|
+
const key = DELTAS.has(String(event.type)) ? deltaKey(event) : void 0;
|
|
5784
|
+
if (key && last?.key === key) {
|
|
5785
|
+
const joined = `${String(last.event.delta ?? "")}${String(event.delta ?? "")}`;
|
|
5786
|
+
if (joined.length <= RELAY_MAX_STRING) {
|
|
5787
|
+
chars += String(event.delta ?? "").length;
|
|
5788
|
+
last.event = { ...last.event, delta: joined, ...event.seq ? { seq: event.seq } : {} };
|
|
5789
|
+
last.n = n;
|
|
5790
|
+
return;
|
|
5791
|
+
}
|
|
5792
|
+
}
|
|
5793
|
+
buffer.push({ n, event, ...key ? { key } : {} });
|
|
5794
|
+
chars += charsOf(event);
|
|
5795
|
+
while (buffer.length > 1 && (buffer.length > RELAY_MAX_REPLAY_EVENTS || chars > RELAY_MAX_REPLAY_CHARS)) {
|
|
5796
|
+
const [dropped] = buffer.splice(1, 1);
|
|
5797
|
+
chars -= charsOf(dropped.event);
|
|
5798
|
+
truncated = true;
|
|
5799
|
+
}
|
|
5800
|
+
};
|
|
5801
|
+
const unlisten = hub.listen((data) => {
|
|
5802
|
+
if (ended) return;
|
|
5803
|
+
const m = watcherMessageOf(data);
|
|
5804
|
+
if (!m) return;
|
|
5805
|
+
if (m.t === "hello") {
|
|
5806
|
+
if (replayed.has(m.id)) return;
|
|
5807
|
+
if (replayed.size >= 4096) replayed.clear();
|
|
5808
|
+
replayed.add(m.id);
|
|
5809
|
+
watched = true;
|
|
5810
|
+
const now = Date.now();
|
|
5811
|
+
while (recentReplays.length && now - recentReplays[0] >= 1e3) recentReplays.shift();
|
|
5812
|
+
const full = recentReplays.length < RELAY_MAX_REPLAYS_PER_SECOND;
|
|
5813
|
+
if (full) recentReplays.push(now);
|
|
5814
|
+
post({
|
|
5815
|
+
t: "replay",
|
|
5816
|
+
to: m.id,
|
|
5817
|
+
n,
|
|
5818
|
+
events: full ? buffer.map((b) => b.event) : [],
|
|
5819
|
+
ns: full ? buffer.map((b) => b.n) : [],
|
|
5820
|
+
...truncated || !full ? { truncated: true } : {}
|
|
5821
|
+
});
|
|
5822
|
+
return;
|
|
5823
|
+
}
|
|
5824
|
+
if (!o.remoteControl) {
|
|
5825
|
+
ack(m.id, false);
|
|
5826
|
+
return;
|
|
5827
|
+
}
|
|
5828
|
+
if (m.t === "stop") {
|
|
5829
|
+
stopper.abort();
|
|
5830
|
+
ack(m.id, true);
|
|
5831
|
+
return;
|
|
5832
|
+
}
|
|
5833
|
+
const text = m.text.trim();
|
|
5834
|
+
if (!port || !text || text.length > RELAY_MAX_SEND_CHARS || sends >= RELAY_MAX_SENDS) {
|
|
5835
|
+
ack(m.id, false);
|
|
5836
|
+
return;
|
|
5837
|
+
}
|
|
5838
|
+
sends += 1;
|
|
5839
|
+
ack(m.id, port.sendFrom(text, "another-tab"));
|
|
5840
|
+
});
|
|
5841
|
+
post({ t: "run", state: "running" });
|
|
5842
|
+
return {
|
|
5843
|
+
signal,
|
|
5844
|
+
event(event) {
|
|
5845
|
+
if (ended) return;
|
|
5846
|
+
const slim = slimEvent(event);
|
|
5847
|
+
n += 1;
|
|
5848
|
+
if (watched) post({ t: "event", n, event: slim });
|
|
5849
|
+
keep(slim);
|
|
5850
|
+
},
|
|
5851
|
+
end(stopped) {
|
|
5852
|
+
if (ended) return;
|
|
5853
|
+
ended = true;
|
|
5854
|
+
post({ t: "run", state: "idle", ...stopped ? { stopped: true } : {} });
|
|
5855
|
+
unlisten();
|
|
5856
|
+
}
|
|
5857
|
+
};
|
|
5858
|
+
};
|
|
5859
|
+
var watchSession = (options) => {
|
|
5860
|
+
const dbName = options.dbName ?? "agent-web";
|
|
5861
|
+
const name = sessionLockName(dbName, String(options.sessionId ?? ""));
|
|
5862
|
+
const tab = currentTab();
|
|
5863
|
+
const hub = options.sessionId ? hubOf(tab, name) : void 0;
|
|
5864
|
+
let state = { running: false };
|
|
5865
|
+
const inert = {
|
|
5866
|
+
get state() {
|
|
5867
|
+
return state;
|
|
5868
|
+
},
|
|
5869
|
+
send: async () => false,
|
|
5870
|
+
stop: async () => false,
|
|
5871
|
+
close: () => void 0
|
|
5872
|
+
};
|
|
5873
|
+
if (!hub) return inert;
|
|
5874
|
+
let id = newSyncId();
|
|
5875
|
+
let closed = false;
|
|
5876
|
+
let following;
|
|
5877
|
+
let lastN = 0;
|
|
5878
|
+
let pending = [];
|
|
5879
|
+
let lastHello = 0;
|
|
5880
|
+
let epoch = 0;
|
|
5881
|
+
const acks = /* @__PURE__ */ new Map();
|
|
5882
|
+
let holderPoll;
|
|
5883
|
+
const setState = (next) => {
|
|
5884
|
+
state = next;
|
|
5885
|
+
try {
|
|
5886
|
+
options.onState?.(next);
|
|
5887
|
+
} catch {
|
|
5888
|
+
}
|
|
5889
|
+
};
|
|
5890
|
+
const deliver = (event) => {
|
|
5891
|
+
try {
|
|
5892
|
+
options.onEvent?.(event);
|
|
5893
|
+
} catch {
|
|
5894
|
+
}
|
|
5895
|
+
};
|
|
5896
|
+
const hello = () => {
|
|
5897
|
+
id = newSyncId();
|
|
5898
|
+
lastHello = Date.now();
|
|
5899
|
+
hub.post({ v: SYNC_VERSION, from: tab.id, t: "hello", id });
|
|
5900
|
+
};
|
|
5901
|
+
const resync = () => {
|
|
5902
|
+
if (Date.now() - lastHello >= WATCH_RESYNC_MS) hello();
|
|
5903
|
+
};
|
|
5904
|
+
const stopPolling = () => {
|
|
5905
|
+
if (holderPoll !== void 0) clearInterval(holderPoll);
|
|
5906
|
+
holderPoll = void 0;
|
|
5907
|
+
};
|
|
5908
|
+
const endRun = (ended) => {
|
|
5909
|
+
stopPolling();
|
|
5910
|
+
setState({ running: false, ...state.runId ? { runId: state.runId } : {}, ended });
|
|
5911
|
+
following = void 0;
|
|
5912
|
+
pending = [];
|
|
5913
|
+
};
|
|
5914
|
+
const seeRun = (runId, truncated = false) => {
|
|
5915
|
+
if (!(state.running && state.runId === runId)) epoch += 1;
|
|
5916
|
+
setState({ running: true, runId, ...truncated ? { truncated: true } : {} });
|
|
5917
|
+
watchForEnd();
|
|
5918
|
+
};
|
|
5919
|
+
const watchForEnd = () => {
|
|
5920
|
+
const locks = lockManager();
|
|
5921
|
+
if (!locks || typeof locks.query !== "function" || holderPoll !== void 0 || closed) return;
|
|
5922
|
+
const armed = epoch;
|
|
5923
|
+
let checking = false;
|
|
5924
|
+
holderPoll = setInterval(() => {
|
|
5925
|
+
if (checking) return;
|
|
5926
|
+
checking = true;
|
|
5927
|
+
void heldExclusively(locks, name).then((held) => {
|
|
5928
|
+
checking = false;
|
|
5929
|
+
if (held !== false || closed || epoch !== armed || !state.running) return;
|
|
5930
|
+
stopPolling();
|
|
5931
|
+
setTimeout(() => {
|
|
5932
|
+
if (!closed && state.running && epoch === armed) endRun("gone");
|
|
5933
|
+
}, GONE_GRACE_MS);
|
|
5934
|
+
});
|
|
5935
|
+
}, WATCH_HOLDER_POLL_MS);
|
|
5936
|
+
holderPoll.unref?.();
|
|
5937
|
+
};
|
|
5938
|
+
const unlisten = hub.listen((data) => {
|
|
5939
|
+
if (closed) return;
|
|
5940
|
+
const m = holderMessageOf(data);
|
|
5941
|
+
if (!m) return;
|
|
5942
|
+
switch (m.t) {
|
|
5943
|
+
case "ack":
|
|
5944
|
+
acks.get(m.id)?.(m.ok);
|
|
5945
|
+
return;
|
|
5946
|
+
case "run":
|
|
5947
|
+
if (m.state === "running") {
|
|
5948
|
+
if (following === m.runId) return;
|
|
5949
|
+
seeRun(m.runId);
|
|
5950
|
+
hello();
|
|
5951
|
+
} else if (state.running && state.runId === m.runId) {
|
|
5952
|
+
endRun(m.stopped ? "stopped" : "done");
|
|
5953
|
+
}
|
|
5954
|
+
return;
|
|
5955
|
+
case "event":
|
|
5956
|
+
if (following === m.runId) {
|
|
5957
|
+
if (m.n <= lastN) return;
|
|
5958
|
+
if (m.n !== lastN + 1) {
|
|
5959
|
+
resync();
|
|
5960
|
+
return;
|
|
5961
|
+
}
|
|
5962
|
+
lastN = m.n;
|
|
5963
|
+
deliver(m.event);
|
|
5964
|
+
} else if (pending.length < WATCH_MAX_PENDING) {
|
|
5965
|
+
pending.push({ runId: m.runId, n: m.n, event: m.event });
|
|
5966
|
+
}
|
|
5967
|
+
return;
|
|
5968
|
+
case "replay": {
|
|
5969
|
+
if (m.to !== id) return;
|
|
5970
|
+
const known = following === m.runId ? lastN : 0;
|
|
5971
|
+
const later = pending.filter((p) => p.runId === m.runId && p.n > m.n).sort((a, b) => a.n - b.n);
|
|
5972
|
+
pending = [];
|
|
5973
|
+
following = m.runId;
|
|
5974
|
+
if (!(state.running && state.runId === m.runId)) seeRun(m.runId, m.truncated);
|
|
5975
|
+
else if (m.truncated && !state.truncated) setState({ ...state, truncated: true });
|
|
5976
|
+
m.events.forEach((event, i) => {
|
|
5977
|
+
if (m.ns[i] > known) deliver(event);
|
|
5978
|
+
});
|
|
5979
|
+
lastN = Math.max(known, m.n);
|
|
5980
|
+
for (const p of later) {
|
|
5981
|
+
if (p.n !== lastN + 1) break;
|
|
5982
|
+
lastN = p.n;
|
|
5983
|
+
deliver(p.event);
|
|
5984
|
+
}
|
|
5985
|
+
return;
|
|
5986
|
+
}
|
|
5987
|
+
}
|
|
5988
|
+
});
|
|
5989
|
+
const ask = (message) => {
|
|
5990
|
+
if (closed || !state.running) return Promise.resolve(false);
|
|
5991
|
+
const requestId = newSyncId();
|
|
5992
|
+
return new Promise((resolve) => {
|
|
5993
|
+
const timer = setTimeout(() => {
|
|
5994
|
+
acks.delete(requestId);
|
|
5995
|
+
resolve(false);
|
|
5996
|
+
}, ACK_TIMEOUT_MS);
|
|
5997
|
+
acks.set(requestId, (ok) => {
|
|
5998
|
+
clearTimeout(timer);
|
|
5999
|
+
acks.delete(requestId);
|
|
6000
|
+
resolve(ok);
|
|
6001
|
+
});
|
|
6002
|
+
hub.post({ v: SYNC_VERSION, from: tab.id, id: requestId, ...message });
|
|
6003
|
+
});
|
|
6004
|
+
};
|
|
6005
|
+
hello();
|
|
6006
|
+
return {
|
|
6007
|
+
get state() {
|
|
6008
|
+
return state;
|
|
6009
|
+
},
|
|
6010
|
+
send: (text) => {
|
|
6011
|
+
const clean = typeof text === "string" ? text.trim() : "";
|
|
6012
|
+
if (!clean || clean.length > RELAY_MAX_SEND_CHARS) return Promise.resolve(false);
|
|
6013
|
+
return ask({ t: "send", text: clean });
|
|
6014
|
+
},
|
|
6015
|
+
stop: () => ask({ t: "stop" }),
|
|
6016
|
+
close: () => {
|
|
6017
|
+
if (closed) return;
|
|
6018
|
+
closed = true;
|
|
6019
|
+
unlisten();
|
|
6020
|
+
stopPolling();
|
|
6021
|
+
for (const resolve of [...acks.values()]) resolve(false);
|
|
6022
|
+
}
|
|
6023
|
+
};
|
|
6024
|
+
};
|
|
6025
|
+
|
|
5424
6026
|
// src/agent/runner.ts
|
|
5425
6027
|
var newRunId = () => globalThis.crypto?.randomUUID?.() ?? `run-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
|
|
5426
6028
|
var errMessage = (err) => err instanceof Error ? err.message : String(err);
|
|
@@ -5443,7 +6045,21 @@ var asJson2 = (v) => {
|
|
|
5443
6045
|
var FINDING_CHARS = 600;
|
|
5444
6046
|
var FINDINGS_BUDGET = 6e3;
|
|
5445
6047
|
var createAgent = async (config) => {
|
|
6048
|
+
refuseServerOnlyConfig(config);
|
|
5446
6049
|
const cfg = resolveConfig(config);
|
|
6050
|
+
const lockMode = config.sessionLock ?? "wait";
|
|
6051
|
+
if (!SESSION_LOCK_MODES.includes(lockMode)) {
|
|
6052
|
+
throw new Error(`unknown sessionLock "${String(lockMode)}" (${SESSION_LOCK_MODES.join(" | ")})`);
|
|
6053
|
+
}
|
|
6054
|
+
const sharedDb = typeof config.memory?.dbName === "string" && config.memory.dbName ? config.memory.dbName : void 0;
|
|
6055
|
+
const tab = currentTab();
|
|
6056
|
+
let warnedNoLocks = false;
|
|
6057
|
+
let warnedBusy = false;
|
|
6058
|
+
const relayOn = config.sessionRelay !== false;
|
|
6059
|
+
const relayControl = typeof config.sessionRelay === "object" && config.sessionRelay !== null ? config.sessionRelay.control !== false : true;
|
|
6060
|
+
if (config.sessionRelay !== void 0 && config.sessionRelay !== false && (typeof config.sessionRelay !== "object" || config.sessionRelay === null)) {
|
|
6061
|
+
throw new Error("sessionRelay must be false or { control?: boolean }");
|
|
6062
|
+
}
|
|
5447
6063
|
const dynamicSubagents = resolveDynamicSubagents(config.subagents);
|
|
5448
6064
|
const seed = spawnSeedOf(config);
|
|
5449
6065
|
const buildStage = (override, stageName) => buildModelFromStage(
|
|
@@ -5553,7 +6169,7 @@ var createAgent = async (config) => {
|
|
|
5553
6169
|
config.availableTools,
|
|
5554
6170
|
config.excludedTools
|
|
5555
6171
|
);
|
|
5556
|
-
const sandbox = config.sandbox ? (await import("./sandbox-
|
|
6172
|
+
const sandbox = config.sandbox ? (await import("./sandbox-7CGSIIIZ.js")).createSandbox(
|
|
5557
6173
|
config.sandbox === true ? {} : config.sandbox,
|
|
5558
6174
|
hostTools,
|
|
5559
6175
|
(m) => log.warn(m)
|
|
@@ -5649,17 +6265,114 @@ ${renderActiveSkills(active)}`
|
|
|
5649
6265
|
spentAll = addUsage(spentAll, u);
|
|
5650
6266
|
spentBySession.set(sessionId, addUsage(spentBySession.get(sessionId) ?? emptyUsage(), u));
|
|
5651
6267
|
};
|
|
5652
|
-
const
|
|
5653
|
-
|
|
6268
|
+
const announce = (onEvent, event) => {
|
|
6269
|
+
try {
|
|
6270
|
+
onEvent?.(event);
|
|
6271
|
+
} catch {
|
|
6272
|
+
}
|
|
6273
|
+
};
|
|
6274
|
+
const noLocks = (why) => {
|
|
6275
|
+
if (!warnedNoLocks) {
|
|
6276
|
+
warnedNoLocks = true;
|
|
6277
|
+
log.warn(`sessionLock: ${why} - runs of one session in two tabs are not kept apart`);
|
|
6278
|
+
}
|
|
6279
|
+
return void 0;
|
|
6280
|
+
};
|
|
6281
|
+
const lockSession = async (given, mode = lockMode === "fail" ? "fail" : "wait") => {
|
|
6282
|
+
if (!sharedDb || lockMode === "off") return void 0;
|
|
6283
|
+
if (given.runId !== void 0) assertSafeRunId(given.runId, "runId");
|
|
6284
|
+
const sessionId = given.resumeFromRunId !== void 0 ? (await resolveResume(config.persistence, given.resumeFromRunId)).sessionId : given.sessionId ?? cfg.sessionId;
|
|
6285
|
+
const name = sessionLockName(sharedDb, sessionId);
|
|
6286
|
+
if (sessionLocksOf(given).includes(name)) return void 0;
|
|
6287
|
+
const locks = lockManager();
|
|
6288
|
+
if (!locks) return noLocks("this browser has no Web Locks (navigator.locks)");
|
|
6289
|
+
const taken = await acquireSessionLock({
|
|
6290
|
+
locks,
|
|
6291
|
+
tab,
|
|
6292
|
+
name,
|
|
6293
|
+
sessionId,
|
|
6294
|
+
mode,
|
|
6295
|
+
signal: given.signal,
|
|
6296
|
+
onBusy: (heldBy) => {
|
|
6297
|
+
if (!warnedBusy) {
|
|
6298
|
+
warnedBusy = true;
|
|
6299
|
+
log.warn(
|
|
6300
|
+
`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)`
|
|
6301
|
+
);
|
|
6302
|
+
} else log.info(`session "${sessionId}" is running ${heldBy}; waiting for it`);
|
|
6303
|
+
announce(given.onEvent, { type: "session.busy", sessionId, heldBy });
|
|
6304
|
+
}
|
|
6305
|
+
});
|
|
6306
|
+
if (taken.unavailable !== void 0 || !taken.hold) {
|
|
6307
|
+
return noLocks(`the lock manager refused (${errMessage(taken.unavailable)})`);
|
|
6308
|
+
}
|
|
6309
|
+
if (taken.waitedMs !== void 0) {
|
|
6310
|
+
announce(given.onEvent, { type: "session.acquired", sessionId, waitedMs: taken.waitedMs });
|
|
6311
|
+
}
|
|
6312
|
+
return taken.hold;
|
|
6313
|
+
};
|
|
6314
|
+
const runCore = async (goal, given, track, port) => {
|
|
6315
|
+
let hold;
|
|
6316
|
+
try {
|
|
6317
|
+
hold = await lockSession(given);
|
|
6318
|
+
} catch (err) {
|
|
6319
|
+
if (!given.signal?.aborted) throw err;
|
|
6320
|
+
announce(given.onEvent, { type: "stopped" });
|
|
6321
|
+
return {
|
|
6322
|
+
runId: given.resumeFromRunId ?? given.runId ?? newRunId(),
|
|
6323
|
+
goal: goal.trim(),
|
|
6324
|
+
final: "",
|
|
6325
|
+
plan: { thought: "", steps: [] },
|
|
6326
|
+
trace: [],
|
|
6327
|
+
steps: 0,
|
|
6328
|
+
applied: 0,
|
|
6329
|
+
stopped: true,
|
|
6330
|
+
usage: emptyUsage(),
|
|
6331
|
+
skills: []
|
|
6332
|
+
};
|
|
6333
|
+
}
|
|
6334
|
+
let relay;
|
|
6335
|
+
if (hold) {
|
|
6336
|
+
const held = hold;
|
|
6337
|
+
track.end = (stopped) => {
|
|
6338
|
+
relay?.end(stopped);
|
|
6339
|
+
return held.release();
|
|
6340
|
+
};
|
|
6341
|
+
}
|
|
6342
|
+
const ownRunId = await resolveRunId(config.persistence, given.runId, given.resumeFromRunId);
|
|
6343
|
+
const resumed = await resolveResume(config.persistence, given.resumeFromRunId);
|
|
6344
|
+
const sessionId = resumed?.sessionId ?? given.sessionId ?? cfg.sessionId;
|
|
6345
|
+
const runId = resumed?.runId ?? ownRunId ?? newRunId();
|
|
6346
|
+
if (hold && sharedDb && sessionLockName(sharedDb, sessionId) !== hold.name) {
|
|
6347
|
+
throw new Error(
|
|
6348
|
+
`persistence changed the session of run "${runId}" while it waited for it; refusing to run it`
|
|
6349
|
+
);
|
|
6350
|
+
}
|
|
6351
|
+
if (hold && sharedDb && relayOn) {
|
|
6352
|
+
relay = startSessionRelay({
|
|
6353
|
+
tab,
|
|
6354
|
+
dbName: sharedDb,
|
|
6355
|
+
sessionId,
|
|
6356
|
+
runId,
|
|
6357
|
+
remoteControl: relayControl,
|
|
6358
|
+
...given.control ? { control: given.control } : {},
|
|
6359
|
+
...given.signal ? { signal: given.signal } : {}
|
|
6360
|
+
});
|
|
6361
|
+
}
|
|
6362
|
+
const opts = relay ? { ...given, signal: relay.signal } : given;
|
|
6363
|
+
const sessionLocks = hold ? [...sessionLocksOf(given), hold.name] : sessionLocksOf(given);
|
|
6364
|
+
const attempt = resumed ? resumeAttemptOf(resumed) : 1;
|
|
6365
|
+
let seq3 = 0;
|
|
5654
6366
|
const emit = (event) => {
|
|
6367
|
+
const numbered2 = { ...event, seq: ++seq3, attempt };
|
|
5655
6368
|
try {
|
|
5656
|
-
opts.onEvent?.(
|
|
6369
|
+
opts.onEvent?.(numbered2);
|
|
5657
6370
|
} catch {
|
|
5658
6371
|
}
|
|
6372
|
+
relay?.event(numbered2);
|
|
5659
6373
|
};
|
|
6374
|
+
if (resumed) await recordResume(config.persistence, resumed, attempt, (m) => log.warn(m));
|
|
5660
6375
|
let text = (resumed?.goal ?? goal).trim();
|
|
5661
|
-
const sessionId = resumed?.sessionId ?? opts.sessionId ?? cfg.sessionId;
|
|
5662
|
-
const runId = resumed?.runId ?? newRunId();
|
|
5663
6376
|
const startedAt = resumed?.startedAt ?? Date.now();
|
|
5664
6377
|
let usage = resumed ? { ...resumed.usage } : emptyUsage();
|
|
5665
6378
|
const result = {
|
|
@@ -5817,7 +6530,8 @@ ${renderActiveSkills(active)}`
|
|
|
5817
6530
|
fetched,
|
|
5818
6531
|
stepWrites: () => stepWrites,
|
|
5819
6532
|
clock,
|
|
5820
|
-
mcpSkills: mcpSkillsActing
|
|
6533
|
+
mcpSkills: mcpSkillsActing,
|
|
6534
|
+
sessionLocks: () => sessionLocks
|
|
5821
6535
|
}
|
|
5822
6536
|
);
|
|
5823
6537
|
const deliver = (at) => {
|
|
@@ -5825,7 +6539,13 @@ ${renderActiveSkills(active)}`
|
|
|
5825
6539
|
const taken = port.drain();
|
|
5826
6540
|
for (const m of taken) {
|
|
5827
6541
|
userUpdates.push({ text: m.text, reconciled: false });
|
|
5828
|
-
emit({
|
|
6542
|
+
emit({
|
|
6543
|
+
type: "message.delivered",
|
|
6544
|
+
id: m.id,
|
|
6545
|
+
text: m.text,
|
|
6546
|
+
at,
|
|
6547
|
+
...m.origin ? { origin: m.origin } : {}
|
|
6548
|
+
});
|
|
5829
6549
|
log.info(`message from the user (delivered at ${at}):`, m.text);
|
|
5830
6550
|
void remember({ role: "user", content: m.text });
|
|
5831
6551
|
}
|
|
@@ -6021,6 +6741,7 @@ ${renderActiveSkills(active)}`
|
|
|
6021
6741
|
let remaining = resumed ? [...resumed.remaining] : [...planned.plan.steps];
|
|
6022
6742
|
let iter = resumed?.iterations ?? 0;
|
|
6023
6743
|
let revisions = resumed?.revisions ?? 0;
|
|
6744
|
+
let inFlight;
|
|
6024
6745
|
const buildSnapshot = (status, extra = {}) => ({
|
|
6025
6746
|
runId,
|
|
6026
6747
|
startedAt,
|
|
@@ -6029,12 +6750,12 @@ ${renderActiveSkills(active)}`
|
|
|
6029
6750
|
sessionId,
|
|
6030
6751
|
plan: planned.plan,
|
|
6031
6752
|
// Copies: a store that keeps the object must not watch the loop mutate it.
|
|
6032
|
-
remaining: [...remaining],
|
|
6753
|
+
remaining: inFlight ? [inFlight, ...remaining] : [...remaining],
|
|
6033
6754
|
trace: [...result.trace],
|
|
6034
6755
|
done: [...done],
|
|
6035
6756
|
findings: [...findings],
|
|
6036
6757
|
usage: { ...usage },
|
|
6037
|
-
iterations: iter,
|
|
6758
|
+
iterations: inFlight ? iter - 1 : iter,
|
|
6038
6759
|
revisions,
|
|
6039
6760
|
toolCalls: counter.calls,
|
|
6040
6761
|
applied: result.applied,
|
|
@@ -6044,6 +6765,7 @@ ${renderActiveSkills(active)}`
|
|
|
6044
6765
|
...userUpdates.length ? { userUpdates: userUpdates.map((u) => ({ ...u })) } : {},
|
|
6045
6766
|
...escalationCount ? { escalations: escalationCount } : {},
|
|
6046
6767
|
...spawnRun && !seed && spawnRun.root.spawned ? { subagentsSpawned: spawnRun.root.spawned } : {},
|
|
6768
|
+
attempt,
|
|
6047
6769
|
...extra
|
|
6048
6770
|
});
|
|
6049
6771
|
const persist = async (hook, snapshot) => {
|
|
@@ -6082,6 +6804,7 @@ ${renderActiveSkills(active)}`
|
|
|
6082
6804
|
}
|
|
6083
6805
|
iter += 1;
|
|
6084
6806
|
const step = remaining.shift();
|
|
6807
|
+
inFlight = step;
|
|
6085
6808
|
const stepNo = result.trace.length + 1;
|
|
6086
6809
|
const total = stepNo + remaining.length;
|
|
6087
6810
|
const routed = tiers ? pickTier(step.complexity, tiers.configured) : void 0;
|
|
@@ -6188,6 +6911,7 @@ ${renderActiveSkills(active)}`
|
|
|
6188
6911
|
stepWrites = void 0;
|
|
6189
6912
|
}
|
|
6190
6913
|
result.trace.push(stepResult);
|
|
6914
|
+
inFlight = void 0;
|
|
6191
6915
|
const applied = stepResult.toolCalls.filter((c) => c.ok && !isReplayed(c)).length;
|
|
6192
6916
|
const failed = stepResult.toolCalls.length - applied;
|
|
6193
6917
|
result.applied += applied;
|
|
@@ -6354,20 +7078,27 @@ ${renderActiveSkills(active)}`
|
|
|
6354
7078
|
}
|
|
6355
7079
|
};
|
|
6356
7080
|
const run = async (goal, opts = {}) => {
|
|
7081
|
+
refuseServerOnlyRunOptions(opts);
|
|
6357
7082
|
const port = portOf(opts.control);
|
|
6358
7083
|
const track = {};
|
|
6359
|
-
let
|
|
7084
|
+
let stopped = false;
|
|
6360
7085
|
try {
|
|
6361
|
-
result
|
|
6362
|
-
|
|
6363
|
-
|
|
6364
|
-
|
|
6365
|
-
|
|
6366
|
-
|
|
7086
|
+
let result;
|
|
7087
|
+
try {
|
|
7088
|
+
result = await runCore(goal, opts, track, port);
|
|
7089
|
+
} catch (err) {
|
|
7090
|
+
port?.detach();
|
|
7091
|
+
track.error = err instanceof Error ? err.message : String(err);
|
|
7092
|
+
await track.complete?.(void 0);
|
|
7093
|
+
throw err;
|
|
7094
|
+
}
|
|
7095
|
+
if (port) result.undelivered = port.detach();
|
|
7096
|
+
await track.complete?.(result);
|
|
7097
|
+
stopped = result.stopped;
|
|
7098
|
+
return result;
|
|
7099
|
+
} finally {
|
|
7100
|
+
await track.end?.(stopped);
|
|
6367
7101
|
}
|
|
6368
|
-
if (port) result.undelivered = port.detach();
|
|
6369
|
-
await track.complete?.(result);
|
|
6370
|
-
return result;
|
|
6371
7102
|
};
|
|
6372
7103
|
const compact = async (o = {}) => {
|
|
6373
7104
|
const empty = {
|
|
@@ -6378,6 +7109,18 @@ ${renderActiveSkills(active)}`
|
|
|
6378
7109
|
};
|
|
6379
7110
|
if (!config.memory) return empty;
|
|
6380
7111
|
const sessionId = o.sessionId ?? cfg.sessionId;
|
|
7112
|
+
const hold = await lockSession(
|
|
7113
|
+
{ sessionId, ...o.signal ? { signal: o.signal } : {} },
|
|
7114
|
+
o.wait === false || lockMode === "fail" ? "fail" : "wait"
|
|
7115
|
+
);
|
|
7116
|
+
try {
|
|
7117
|
+
return await compactSession(sessionId, o, empty);
|
|
7118
|
+
} finally {
|
|
7119
|
+
await hold?.release();
|
|
7120
|
+
}
|
|
7121
|
+
};
|
|
7122
|
+
const compactSession = async (sessionId, o, empty) => {
|
|
7123
|
+
if (!config.memory) return empty;
|
|
6381
7124
|
const transcript = await config.memory.load(sessionId);
|
|
6382
7125
|
const beforeTokens = messageTokens(transcript);
|
|
6383
7126
|
let usage = emptyUsage();
|
|
@@ -6554,6 +7297,7 @@ ${renderActiveSkills(active)}`
|
|
|
6554
7297
|
};
|
|
6555
7298
|
},
|
|
6556
7299
|
forgetSkill: async (name, onEvent) => learning ? learning.forget(name, onEvent) : false,
|
|
7300
|
+
reloadLearnedSkills: async () => learning ? (await learning.reload()).map((s) => ({ ...s })) : [],
|
|
6557
7301
|
capabilities: { images: accepts.image, pdf: accepts.pdf, files: accepts.file },
|
|
6558
7302
|
models: {
|
|
6559
7303
|
planner: plannerModel,
|
|
@@ -7062,18 +7806,18 @@ var testPipelineCondition = (when, output, matcher) => {
|
|
|
7062
7806
|
return false;
|
|
7063
7807
|
}
|
|
7064
7808
|
};
|
|
7065
|
-
var
|
|
7809
|
+
var isRecord2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
7066
7810
|
var isId = (v) => typeof v === "string" && v.trim().length > 0;
|
|
7067
|
-
var edgeIdOf = (edge, index) =>
|
|
7811
|
+
var edgeIdOf = (edge, index) => isRecord2(edge) && isId(edge.id) ? edge.id : `e${index}`;
|
|
7068
7812
|
var edgeRef = (edge, index) => ({
|
|
7069
7813
|
edgeId: edgeIdOf(edge, index),
|
|
7070
7814
|
edgeIndex: index
|
|
7071
7815
|
});
|
|
7072
7816
|
var normalizePipeline = (definition) => {
|
|
7073
7817
|
const def = JSON.parse(JSON.stringify(definition));
|
|
7074
|
-
if (
|
|
7818
|
+
if (isRecord2(def) && Array.isArray(def.edges)) {
|
|
7075
7819
|
def.edges.forEach((edge, index) => {
|
|
7076
|
-
if (
|
|
7820
|
+
if (isRecord2(edge)) edge.id = edgeIdOf(edge, index);
|
|
7077
7821
|
});
|
|
7078
7822
|
}
|
|
7079
7823
|
return def;
|
|
@@ -7087,7 +7831,7 @@ var validatePipeline = (definition) => {
|
|
|
7087
7831
|
};
|
|
7088
7832
|
const done = () => ({ ok: errors.length === 0, errors, warnings });
|
|
7089
7833
|
const def = definition;
|
|
7090
|
-
if (!
|
|
7834
|
+
if (!isRecord2(def)) {
|
|
7091
7835
|
error("definition", "a pipeline definition must be an object");
|
|
7092
7836
|
return done();
|
|
7093
7837
|
}
|
|
@@ -7107,7 +7851,7 @@ var validatePipeline = (definition) => {
|
|
|
7107
7851
|
const ids = /* @__PURE__ */ new Set();
|
|
7108
7852
|
const routesOf = /* @__PURE__ */ new Map();
|
|
7109
7853
|
for (const [index, node] of (nodes ?? []).entries()) {
|
|
7110
|
-
if (!
|
|
7854
|
+
if (!isRecord2(node) || !isId(node.id)) {
|
|
7111
7855
|
error("node.id", `node #${index + 1} has no id`);
|
|
7112
7856
|
continue;
|
|
7113
7857
|
}
|
|
@@ -7130,7 +7874,7 @@ var validatePipeline = (definition) => {
|
|
|
7130
7874
|
);
|
|
7131
7875
|
} else {
|
|
7132
7876
|
for (const route of node.routes) {
|
|
7133
|
-
if (!
|
|
7877
|
+
if (!isRecord2(route) || !isId(route.label)) {
|
|
7134
7878
|
error("node.routes", `node "${nodeId}": a route has no label`, { nodeId });
|
|
7135
7879
|
} else if (labels.includes(route.label)) {
|
|
7136
7880
|
error("node.routes", `node "${nodeId}": duplicate route "${route.label}"`, { nodeId });
|
|
@@ -7154,7 +7898,7 @@ var validatePipeline = (definition) => {
|
|
|
7154
7898
|
for (const [index, edge] of (edges ?? []).entries()) {
|
|
7155
7899
|
const at = edgeRef(edge, index);
|
|
7156
7900
|
const label = `edge "${at.edgeId}"`;
|
|
7157
|
-
if (!
|
|
7901
|
+
if (!isRecord2(edge)) {
|
|
7158
7902
|
error("edge", `${label} is not an object`, at);
|
|
7159
7903
|
continue;
|
|
7160
7904
|
}
|
|
@@ -7171,7 +7915,7 @@ var validatePipeline = (definition) => {
|
|
|
7171
7915
|
if (fromOk && toOk) out.set(from, [...out.get(from) ?? [], to]);
|
|
7172
7916
|
const when = edge.when;
|
|
7173
7917
|
if (when === void 0) continue;
|
|
7174
|
-
if (!
|
|
7918
|
+
if (!isRecord2(when) || !CONDITION_KINDS.includes(when.kind)) {
|
|
7175
7919
|
error("edge.when", `${label} has an unknown condition`, at);
|
|
7176
7920
|
continue;
|
|
7177
7921
|
}
|
|
@@ -7214,7 +7958,7 @@ var validatePipeline = (definition) => {
|
|
|
7214
7958
|
}
|
|
7215
7959
|
}
|
|
7216
7960
|
if (def.limits !== void 0) {
|
|
7217
|
-
if (!
|
|
7961
|
+
if (!isRecord2(def.limits)) {
|
|
7218
7962
|
error("limits", "`limits` must be an object");
|
|
7219
7963
|
} else {
|
|
7220
7964
|
const { maxNodeVisits, maxRuns } = def.limits;
|
|
@@ -7331,7 +8075,7 @@ var matchPipelineRoute = (node, answer) => {
|
|
|
7331
8075
|
value = text;
|
|
7332
8076
|
}
|
|
7333
8077
|
}
|
|
7334
|
-
if (
|
|
8078
|
+
if (isRecord2(value)) value = value.route;
|
|
7335
8079
|
if (typeof value !== "string") return void 0;
|
|
7336
8080
|
const wanted = value.trim().replace(/^["'`]+|["'`.]+$/g, "").toLowerCase();
|
|
7337
8081
|
return labels.find((label) => label.toLowerCase() === wanted);
|
|
@@ -7376,7 +8120,100 @@ var preparePipeline = (definition) => {
|
|
|
7376
8120
|
reaches: (from, to) => descendants(from).has(to)
|
|
7377
8121
|
};
|
|
7378
8122
|
};
|
|
7379
|
-
var
|
|
8123
|
+
var passReach = (plan) => {
|
|
8124
|
+
const entry = plan.definition.entry;
|
|
8125
|
+
const order = [entry];
|
|
8126
|
+
const preds = /* @__PURE__ */ new Map([[entry, []]]);
|
|
8127
|
+
for (let i = 0; i < order.length; i++) {
|
|
8128
|
+
for (const { edge } of plan.outgoing.get(order[i]) ?? []) {
|
|
8129
|
+
if (!preds.has(edge.to)) {
|
|
8130
|
+
preds.set(edge.to, []);
|
|
8131
|
+
order.push(edge.to);
|
|
8132
|
+
}
|
|
8133
|
+
;
|
|
8134
|
+
preds.get(edge.to).push(order[i]);
|
|
8135
|
+
}
|
|
8136
|
+
}
|
|
8137
|
+
const dom = /* @__PURE__ */ new Map();
|
|
8138
|
+
for (const nodeId of order) dom.set(nodeId, new Set(nodeId === entry ? [entry] : order));
|
|
8139
|
+
for (let changed = true; changed; ) {
|
|
8140
|
+
changed = false;
|
|
8141
|
+
for (const nodeId of order) {
|
|
8142
|
+
if (nodeId === entry) continue;
|
|
8143
|
+
const [first, ...rest] = preds.get(nodeId).map((p) => dom.get(p));
|
|
8144
|
+
const next = /* @__PURE__ */ new Set([nodeId]);
|
|
8145
|
+
for (const d of first) if (rest.every((set) => set.has(d))) next.add(d);
|
|
8146
|
+
if (next.size < dom.get(nodeId).size) {
|
|
8147
|
+
dom.set(nodeId, next);
|
|
8148
|
+
changed = true;
|
|
8149
|
+
}
|
|
8150
|
+
}
|
|
8151
|
+
}
|
|
8152
|
+
const closure = /* @__PURE__ */ new Map();
|
|
8153
|
+
return (from, to) => {
|
|
8154
|
+
let seen = closure.get(from);
|
|
8155
|
+
if (!seen) {
|
|
8156
|
+
const found = /* @__PURE__ */ new Set();
|
|
8157
|
+
const queue = [from];
|
|
8158
|
+
while (queue.length) {
|
|
8159
|
+
const at = queue.pop();
|
|
8160
|
+
for (const { edge } of plan.outgoing.get(at) ?? []) {
|
|
8161
|
+
if (dom.get(at)?.has(edge.to) || found.has(edge.to)) continue;
|
|
8162
|
+
found.add(edge.to);
|
|
8163
|
+
queue.push(edge.to);
|
|
8164
|
+
}
|
|
8165
|
+
}
|
|
8166
|
+
closure.set(from, seen = found);
|
|
8167
|
+
}
|
|
8168
|
+
return seen.has(to);
|
|
8169
|
+
};
|
|
8170
|
+
};
|
|
8171
|
+
var abortError3 = () => {
|
|
8172
|
+
if (typeof DOMException === "function") return new DOMException("Aborted", "AbortError");
|
|
8173
|
+
const error = new Error("Aborted");
|
|
8174
|
+
error.name = "AbortError";
|
|
8175
|
+
return error;
|
|
8176
|
+
};
|
|
8177
|
+
var createStopper = () => {
|
|
8178
|
+
if (typeof AbortController === "function") {
|
|
8179
|
+
const controller = new AbortController();
|
|
8180
|
+
return { signal: controller.signal, abort: () => controller.abort() };
|
|
8181
|
+
}
|
|
8182
|
+
const listeners = [];
|
|
8183
|
+
const signal = {
|
|
8184
|
+
aborted: false,
|
|
8185
|
+
reason: void 0,
|
|
8186
|
+
onabort: null,
|
|
8187
|
+
addEventListener(type, listener) {
|
|
8188
|
+
if (type === "abort" && listener && !listeners.includes(listener)) listeners.push(listener);
|
|
8189
|
+
},
|
|
8190
|
+
removeEventListener(type, listener) {
|
|
8191
|
+
const index = listener ? listeners.indexOf(listener) : -1;
|
|
8192
|
+
if (type === "abort" && index >= 0) listeners.splice(index, 1);
|
|
8193
|
+
},
|
|
8194
|
+
throwIfAborted() {
|
|
8195
|
+
if (signal.aborted) throw signal.reason;
|
|
8196
|
+
}
|
|
8197
|
+
};
|
|
8198
|
+
const abort = () => {
|
|
8199
|
+
if (signal.aborted) return;
|
|
8200
|
+
signal.aborted = true;
|
|
8201
|
+
signal.reason = abortError3();
|
|
8202
|
+
const event = { type: "abort", target: signal };
|
|
8203
|
+
const call = (fn, thisArg) => {
|
|
8204
|
+
try {
|
|
8205
|
+
fn.call(thisArg, event);
|
|
8206
|
+
} catch {
|
|
8207
|
+
}
|
|
8208
|
+
};
|
|
8209
|
+
for (const listener of listeners.splice(0)) {
|
|
8210
|
+
if (typeof listener === "function") call(listener, signal);
|
|
8211
|
+
else call(listener.handleEvent, listener);
|
|
8212
|
+
}
|
|
8213
|
+
if (typeof signal.onabort === "function") call(signal.onabort, signal);
|
|
8214
|
+
};
|
|
8215
|
+
return { signal, abort };
|
|
8216
|
+
};
|
|
7380
8217
|
var addUsage2 = (into, usage) => {
|
|
7381
8218
|
if (!usage) return;
|
|
7382
8219
|
const sum = into;
|
|
@@ -7384,9 +8221,10 @@ var addUsage2 = (into, usage) => {
|
|
|
7384
8221
|
if (typeof value === "number" && Number.isFinite(value)) sum[key] = (sum[key] ?? 0) + value;
|
|
7385
8222
|
}
|
|
7386
8223
|
};
|
|
7387
|
-
var runPipelineGraph = async (plan, runNode, options
|
|
8224
|
+
var runPipelineGraph = async (plan, runNode, options) => {
|
|
7388
8225
|
const { definition } = plan;
|
|
7389
|
-
const
|
|
8226
|
+
const onAbort = options.onAbort ?? "reject";
|
|
8227
|
+
const stopper = createStopper();
|
|
7390
8228
|
let halted;
|
|
7391
8229
|
let halt = () => {
|
|
7392
8230
|
};
|
|
@@ -7421,8 +8259,8 @@ ${t.text}`).join("\n\n");
|
|
|
7421
8259
|
const onOuterAbort = () => {
|
|
7422
8260
|
if (halted) return;
|
|
7423
8261
|
halted = "aborted";
|
|
7424
|
-
|
|
7425
|
-
halt(
|
|
8262
|
+
stopper.abort();
|
|
8263
|
+
halt(abortError3());
|
|
7426
8264
|
};
|
|
7427
8265
|
const visit = async (nodeId, activations) => {
|
|
7428
8266
|
const node = plan.nodes.get(nodeId);
|
|
@@ -7437,7 +8275,7 @@ ${t.text}`).join("\n\n");
|
|
|
7437
8275
|
node,
|
|
7438
8276
|
{ request: options.input, from: activations.map((a) => ({ ...a.source })), visit: number },
|
|
7439
8277
|
{
|
|
7440
|
-
signal:
|
|
8278
|
+
signal: stopper.signal,
|
|
7441
8279
|
pipeline: definition,
|
|
7442
8280
|
emit: (event) => {
|
|
7443
8281
|
if (!halted) emit({ ...event, nodeId, visit: number });
|
|
@@ -7454,7 +8292,7 @@ ${t.text}`).join("\n\n");
|
|
|
7454
8292
|
visit: number,
|
|
7455
8293
|
error: err instanceof Error ? err.message : String(err)
|
|
7456
8294
|
});
|
|
7457
|
-
|
|
8295
|
+
stopper.abort();
|
|
7458
8296
|
halt(failure);
|
|
7459
8297
|
return;
|
|
7460
8298
|
}
|
|
@@ -7510,7 +8348,8 @@ ${t.text}`).join("\n\n");
|
|
|
7510
8348
|
if (record2.live === 0) terminals.push(record2);
|
|
7511
8349
|
}
|
|
7512
8350
|
};
|
|
7513
|
-
const deferred = (nodeId, all) => (plan.nodes.get(nodeId)?.join ?? "all") === "all" && all.some((other) => other !== nodeId &&
|
|
8351
|
+
const deferred = (nodeId, all, reaches = plan.reaches) => (plan.nodes.get(nodeId)?.join ?? "all") === "all" && all.some((other) => other !== nodeId && reaches(other, nodeId));
|
|
8352
|
+
let inPass;
|
|
7514
8353
|
emit({ type: "pipeline.started", ...definition.name ? { pipeline: definition.name } : {} });
|
|
7515
8354
|
options.signal?.addEventListener("abort", onOuterAbort, { once: true });
|
|
7516
8355
|
try {
|
|
@@ -7518,6 +8357,10 @@ ${t.text}`).join("\n\n");
|
|
|
7518
8357
|
while (pending.size > 0 && !halted) {
|
|
7519
8358
|
const waiting = [...pending.keys()];
|
|
7520
8359
|
let ready = waiting.filter((nodeId) => !deferred(nodeId, waiting));
|
|
8360
|
+
if (ready.length === 0) {
|
|
8361
|
+
const reaches = inPass ??= passReach(plan);
|
|
8362
|
+
ready = waiting.filter((nodeId) => !deferred(nodeId, waiting, reaches));
|
|
8363
|
+
}
|
|
7521
8364
|
if (ready.length === 0) ready = waiting;
|
|
7522
8365
|
const starting = [];
|
|
7523
8366
|
for (const nodeId of ready) {
|
|
@@ -7605,6 +8448,21 @@ var pickRouteWithDecisionModel = async ({ agent, config }, node, text, signal, e
|
|
|
7605
8448
|
...outcome.accepted && outcome.choice !== void 0 ? { route: outcome.choice } : {}
|
|
7606
8449
|
};
|
|
7607
8450
|
};
|
|
8451
|
+
var pickPipelineRoute = async (node, text, options) => {
|
|
8452
|
+
if (!node.routes?.length) return { usage: normalizeUsage() };
|
|
8453
|
+
const entry = { agent: options.agent, config: options.config };
|
|
8454
|
+
const signal = options.signal ?? new AbortController().signal;
|
|
8455
|
+
const emit = (event) => {
|
|
8456
|
+
try {
|
|
8457
|
+
options.onEvent?.(event);
|
|
8458
|
+
} catch {
|
|
8459
|
+
}
|
|
8460
|
+
};
|
|
8461
|
+
const quick = await pickRouteWithDecisionModel(entry, node, text, signal, emit);
|
|
8462
|
+
if (quick?.route) return quick;
|
|
8463
|
+
const slow = await pickRoute(entry, node, text, signal);
|
|
8464
|
+
return quick ? { ...slow, usage: addUsage(quick.usage, slow.usage) } : slow;
|
|
8465
|
+
};
|
|
7608
8466
|
var createPipeline = (definition, options) => {
|
|
7609
8467
|
const plan = preparePipeline(definition);
|
|
7610
8468
|
const { resolveNode } = options;
|
|
@@ -7639,11 +8497,11 @@ var createPipeline = (definition, options) => {
|
|
|
7639
8497
|
if (result.stopped || ctx.signal.aborted) throw aborted();
|
|
7640
8498
|
if (failure !== void 0) throw new Error(failure);
|
|
7641
8499
|
if (!node.routes?.length) return { text: result.final, usage: result.usage };
|
|
7642
|
-
const
|
|
7643
|
-
|
|
7644
|
-
|
|
7645
|
-
|
|
7646
|
-
})
|
|
8500
|
+
const picked = await pickPipelineRoute(node, result.final, {
|
|
8501
|
+
...entry,
|
|
8502
|
+
signal: ctx.signal,
|
|
8503
|
+
onEvent: ctx.emit
|
|
8504
|
+
});
|
|
7647
8505
|
return {
|
|
7648
8506
|
text: result.final,
|
|
7649
8507
|
usage: addUsage(result.usage, picked.usage),
|
|
@@ -7652,12 +8510,12 @@ var createPipeline = (definition, options) => {
|
|
|
7652
8510
|
};
|
|
7653
8511
|
return {
|
|
7654
8512
|
definition: plan.definition,
|
|
7655
|
-
run: (run) => runPipelineGraph(
|
|
7656
|
-
|
|
7657
|
-
|
|
7658
|
-
|
|
7659
|
-
"resolve"
|
|
7660
|
-
),
|
|
8513
|
+
run: (run) => runPipelineGraph(plan, options.runNode ?? runWithAgent, {
|
|
8514
|
+
input: run.input,
|
|
8515
|
+
signal: run.signal,
|
|
8516
|
+
onEvent: run.onEvent,
|
|
8517
|
+
onAbort: "resolve"
|
|
8518
|
+
}),
|
|
7661
8519
|
close: async () => {
|
|
7662
8520
|
agents.clear();
|
|
7663
8521
|
}
|
|
@@ -7717,7 +8575,7 @@ var safePost = (target, message) => {
|
|
|
7717
8575
|
};
|
|
7718
8576
|
|
|
7719
8577
|
// src/subagent/tool.ts
|
|
7720
|
-
var
|
|
8578
|
+
var abortError4 = () => {
|
|
7721
8579
|
const e = new Error("The subagent was aborted");
|
|
7722
8580
|
e.name = "AbortError";
|
|
7723
8581
|
return e;
|
|
@@ -7735,7 +8593,7 @@ var createSemaphore = (size) => {
|
|
|
7735
8593
|
const onAbort = () => {
|
|
7736
8594
|
const i = queue.indexOf(go);
|
|
7737
8595
|
if (i >= 0) queue.splice(i, 1);
|
|
7738
|
-
reject(
|
|
8596
|
+
reject(abortError4());
|
|
7739
8597
|
};
|
|
7740
8598
|
queue.push(go);
|
|
7741
8599
|
signal?.addEventListener("abort", onAbort, { once: true });
|
|
@@ -7840,21 +8698,27 @@ var createSubagentTool = (opts) => {
|
|
|
7840
8698
|
})
|
|
7841
8699
|
);
|
|
7842
8700
|
};
|
|
7843
|
-
const runInProcess = async (task, signal, forward, hostTools, profile, id, elicitations) => {
|
|
8701
|
+
const runInProcess = async (task, signal, forward, hostTools, profile, id, elicitations, sessionLocks) => {
|
|
7844
8702
|
const config = { ...opts.config, ...profile?.config };
|
|
7845
8703
|
const agent = await createAgent({
|
|
7846
8704
|
...config,
|
|
7847
8705
|
tools: { ...asSubagentCalls(config.tools, id, elicitations), ...hostTools }
|
|
7848
8706
|
});
|
|
7849
8707
|
let runError;
|
|
7850
|
-
const result = await agent.run(
|
|
7851
|
-
|
|
7852
|
-
|
|
7853
|
-
|
|
7854
|
-
|
|
7855
|
-
|
|
7856
|
-
|
|
7857
|
-
|
|
8708
|
+
const result = await agent.run(
|
|
8709
|
+
task,
|
|
8710
|
+
withSessionLocks(
|
|
8711
|
+
{
|
|
8712
|
+
signal,
|
|
8713
|
+
onEvent: (e) => {
|
|
8714
|
+
if (e.type === "error" && e.phase === "run") runError = e.error;
|
|
8715
|
+
forward(e);
|
|
8716
|
+
}
|
|
8717
|
+
},
|
|
8718
|
+
sessionLocks
|
|
8719
|
+
)
|
|
8720
|
+
);
|
|
8721
|
+
if (result.stopped) throw abortError4();
|
|
7858
8722
|
if (runError) throw new Error(runError);
|
|
7859
8723
|
return { text: result.final, usage: result.usage };
|
|
7860
8724
|
};
|
|
@@ -7878,9 +8742,9 @@ var createSubagentTool = (opts) => {
|
|
|
7878
8742
|
return toCloneable({ ...cfg, model });
|
|
7879
8743
|
};
|
|
7880
8744
|
const runInWorker = async (task, signal, forward, hostTools, profile, clock) => {
|
|
7881
|
-
if (signal?.aborted) throw
|
|
8745
|
+
if (signal?.aborted) throw abortError4();
|
|
7882
8746
|
const [config, proxied] = await Promise.all([workerConfigFor(profile), proxiedSpecs()]);
|
|
7883
|
-
if (signal?.aborted) throw
|
|
8747
|
+
if (signal?.aborted) throw abortError4();
|
|
7884
8748
|
const worker = opts.worker();
|
|
7885
8749
|
return new Promise((resolve, reject) => {
|
|
7886
8750
|
let settled = false;
|
|
@@ -7897,7 +8761,7 @@ var createSubagentTool = (opts) => {
|
|
|
7897
8761
|
};
|
|
7898
8762
|
const onAbort = () => {
|
|
7899
8763
|
safePost(worker, { type: "abort" });
|
|
7900
|
-
finish(() => reject(
|
|
8764
|
+
finish(() => reject(abortError4()));
|
|
7901
8765
|
};
|
|
7902
8766
|
const onError = (ev) => finish(() => reject(new Error(`subagent worker failed: ${ev?.message ?? "unknown error"}`)));
|
|
7903
8767
|
const callHostTool = async (callId, name, input) => {
|
|
@@ -8028,7 +8892,8 @@ ${profileNames.map((n) => `- ${n}: ${profiles[n].description}`).join("\n")}` : o
|
|
|
8028
8892
|
hostTools,
|
|
8029
8893
|
profile,
|
|
8030
8894
|
id,
|
|
8031
|
-
runCtx?.elicitations
|
|
8895
|
+
runCtx?.elicitations,
|
|
8896
|
+
runCtx?.sessionLocks?.() ?? []
|
|
8032
8897
|
)).catch((err) => {
|
|
8033
8898
|
if (stoppedByUser)
|
|
8034
8899
|
throw new Error(
|
|
@@ -8069,18 +8934,25 @@ import { dynamicTool, jsonSchema as jsonSchema5 } from "ai";
|
|
|
8069
8934
|
|
|
8070
8935
|
// src/secrets/store.ts
|
|
8071
8936
|
var VaultCredentialStore = class {
|
|
8937
|
+
/** The database the vault lives in, and the name its change notices go out under. */
|
|
8938
|
+
dbName;
|
|
8072
8939
|
vault;
|
|
8940
|
+
tab;
|
|
8073
8941
|
constructor(opts = {}) {
|
|
8074
|
-
this.
|
|
8942
|
+
this.dbName = opts.dbName ?? "agent-web";
|
|
8943
|
+
this.vault = new IndexedDBVault({ ...opts, dbName: this.dbName });
|
|
8944
|
+
this.tab = currentTab();
|
|
8075
8945
|
}
|
|
8076
8946
|
getApiKey(ref) {
|
|
8077
8947
|
return this.vault.getSecret(ref);
|
|
8078
8948
|
}
|
|
8079
|
-
setApiKey(ref, key) {
|
|
8080
|
-
|
|
8949
|
+
async setApiKey(ref, key) {
|
|
8950
|
+
await this.vault.setSecret(ref, key);
|
|
8951
|
+
postStorageChangeFrom(this.tab, this.dbName, { kind: "credentials", op: "put" });
|
|
8081
8952
|
}
|
|
8082
|
-
deleteApiKey(ref) {
|
|
8083
|
-
|
|
8953
|
+
async deleteApiKey(ref) {
|
|
8954
|
+
await this.vault.deleteSecret(ref);
|
|
8955
|
+
postStorageChangeFrom(this.tab, this.dbName, { kind: "credentials", op: "delete" });
|
|
8084
8956
|
}
|
|
8085
8957
|
};
|
|
8086
8958
|
var MemoryCredentialStore = class {
|
|
@@ -8237,9 +9109,12 @@ var MemoryStore = class {
|
|
|
8237
9109
|
|
|
8238
9110
|
// src/memory/sessions.ts
|
|
8239
9111
|
var IndexedDBStore = class {
|
|
9112
|
+
/** The database it lives in - and the name its tabs share it under (`sessionLock`, notices). */
|
|
8240
9113
|
dbName;
|
|
9114
|
+
tab;
|
|
8241
9115
|
constructor(opts = {}) {
|
|
8242
|
-
this.dbName = opts.dbName;
|
|
9116
|
+
this.dbName = opts.dbName ?? "agent-web";
|
|
9117
|
+
this.tab = currentTab();
|
|
8243
9118
|
}
|
|
8244
9119
|
async load(sessionId) {
|
|
8245
9120
|
const db = await openAgentWebDB({ dbName: this.dbName });
|
|
@@ -8249,6 +9124,7 @@ var IndexedDBStore = class {
|
|
|
8249
9124
|
async replace(sessionId, messages) {
|
|
8250
9125
|
const db = await openAgentWebDB({ dbName: this.dbName });
|
|
8251
9126
|
await db.put(SESSIONS_STORE, messages, sessionId);
|
|
9127
|
+
postStorageChangeFrom(this.tab, this.dbName, { kind: "session", op: "put", key: sessionId });
|
|
8252
9128
|
}
|
|
8253
9129
|
async append(sessionId, message) {
|
|
8254
9130
|
const current = await this.load(sessionId);
|
|
@@ -8258,6 +9134,7 @@ var IndexedDBStore = class {
|
|
|
8258
9134
|
async clear(sessionId) {
|
|
8259
9135
|
const db = await openAgentWebDB({ dbName: this.dbName });
|
|
8260
9136
|
await db.delete(SESSIONS_STORE, sessionId);
|
|
9137
|
+
postStorageChangeFrom(this.tab, this.dbName, { kind: "session", op: "delete", key: sessionId });
|
|
8261
9138
|
}
|
|
8262
9139
|
/** List all stored session ids. */
|
|
8263
9140
|
async listSessions() {
|
|
@@ -8282,6 +9159,10 @@ var MemoryRunStore = class {
|
|
|
8282
9159
|
onStepComplete(snapshot) {
|
|
8283
9160
|
this.runs.set(snapshot.runId, snapshot);
|
|
8284
9161
|
}
|
|
9162
|
+
/** A resume started: its attempt is on record before any of its events. */
|
|
9163
|
+
onRunResume(snapshot) {
|
|
9164
|
+
this.runs.set(snapshot.runId, snapshot);
|
|
9165
|
+
}
|
|
8285
9166
|
onRunComplete(snapshot) {
|
|
8286
9167
|
if (snapshot.status === "complete" && !this.keepCompleted) this.runs.delete(snapshot.runId);
|
|
8287
9168
|
else this.runs.set(snapshot.runId, snapshot);
|
|
@@ -8311,11 +9192,14 @@ var jsonSafe = (value) => JSON.parse(
|
|
|
8311
9192
|
)
|
|
8312
9193
|
);
|
|
8313
9194
|
var IndexedDBRunStore = class {
|
|
9195
|
+
/** The database it lives in, and the name its change notices (`runs`) go out under. */
|
|
8314
9196
|
dbName;
|
|
8315
9197
|
keepCompleted;
|
|
9198
|
+
tab;
|
|
8316
9199
|
constructor(opts = {}) {
|
|
8317
|
-
this.dbName = opts.dbName;
|
|
9200
|
+
this.dbName = opts.dbName ?? "agent-web";
|
|
8318
9201
|
this.keepCompleted = opts.keepCompleted ?? false;
|
|
9202
|
+
this.tab = currentTab();
|
|
8319
9203
|
}
|
|
8320
9204
|
async put(snapshot) {
|
|
8321
9205
|
const db = await openAgentWebDB({ dbName: this.dbName });
|
|
@@ -8325,6 +9209,7 @@ var IndexedDBRunStore = class {
|
|
|
8325
9209
|
if (err?.name !== "DataCloneError") throw err;
|
|
8326
9210
|
await db.put(RUNS_STORE, jsonSafe(snapshot), snapshot.runId);
|
|
8327
9211
|
}
|
|
9212
|
+
postStorageChangeFrom(this.tab, this.dbName, { kind: "runs", op: "put", key: snapshot.runId });
|
|
8328
9213
|
}
|
|
8329
9214
|
onRunStart(snapshot) {
|
|
8330
9215
|
return this.put(snapshot);
|
|
@@ -8332,6 +9217,10 @@ var IndexedDBRunStore = class {
|
|
|
8332
9217
|
onStepComplete(snapshot) {
|
|
8333
9218
|
return this.put(snapshot);
|
|
8334
9219
|
}
|
|
9220
|
+
/** A resume started: its attempt is on record before any of its events. */
|
|
9221
|
+
onRunResume(snapshot) {
|
|
9222
|
+
return this.put(snapshot);
|
|
9223
|
+
}
|
|
8335
9224
|
async onRunComplete(snapshot) {
|
|
8336
9225
|
if (snapshot.status === "complete" && !this.keepCompleted) {
|
|
8337
9226
|
await this.delete(snapshot.runId);
|
|
@@ -8355,10 +9244,12 @@ var IndexedDBRunStore = class {
|
|
|
8355
9244
|
async delete(runId) {
|
|
8356
9245
|
const db = await openAgentWebDB({ dbName: this.dbName });
|
|
8357
9246
|
await db.delete(RUNS_STORE, runId);
|
|
9247
|
+
postStorageChangeFrom(this.tab, this.dbName, { kind: "runs", op: "delete", key: runId });
|
|
8358
9248
|
}
|
|
8359
9249
|
async clear() {
|
|
8360
9250
|
const db = await openAgentWebDB({ dbName: this.dbName });
|
|
8361
9251
|
await db.clear(RUNS_STORE);
|
|
9252
|
+
postStorageChangeFrom(this.tab, this.dbName, { kind: "runs", op: "clear" });
|
|
8362
9253
|
}
|
|
8363
9254
|
};
|
|
8364
9255
|
export {
|
|
@@ -8429,10 +9320,15 @@ export {
|
|
|
8429
9320
|
MemorySkillStore,
|
|
8430
9321
|
MemoryStore,
|
|
8431
9322
|
PIPELINE_LIMITS,
|
|
9323
|
+
PIPELINE_ROUTER_SYSTEM,
|
|
8432
9324
|
PipelineNodeError,
|
|
8433
9325
|
PipelineValidationError,
|
|
8434
9326
|
PlanSchema,
|
|
8435
9327
|
PlanStepSchema,
|
|
9328
|
+
RELAY_MAX_REPLAYS_PER_SECOND,
|
|
9329
|
+
RELAY_MAX_SENDS,
|
|
9330
|
+
RELAY_MAX_SEND_CHARS,
|
|
9331
|
+
RELAY_MAX_STRING,
|
|
8436
9332
|
REPLAY_NOTE,
|
|
8437
9333
|
RUNS_STORE,
|
|
8438
9334
|
ReplanSchema,
|
|
@@ -8451,11 +9347,14 @@ export {
|
|
|
8451
9347
|
SEARCH_PROVIDERS,
|
|
8452
9348
|
SECRETS_STORE,
|
|
8453
9349
|
SESSIONS_STORE,
|
|
9350
|
+
SESSION_LOCK_MODES,
|
|
8454
9351
|
SKILL_TOOL_NAMES,
|
|
8455
9352
|
SPAWN_INPUT_SCHEMA,
|
|
8456
9353
|
SPAWN_SUBAGENT_TOOL,
|
|
9354
|
+
STORAGE_CHANGE_KINDS,
|
|
8457
9355
|
SUBAGENT_DEFAULTS,
|
|
8458
9356
|
SUBAGENT_MAX_DEPTH_LIMIT,
|
|
9357
|
+
SessionBusyError,
|
|
8459
9358
|
SubagentSpawnError,
|
|
8460
9359
|
TOOL_APPROVAL_MODES,
|
|
8461
9360
|
TOOL_APPROVAL_TIMEOUT_MS,
|
|
@@ -8547,6 +9446,7 @@ export {
|
|
|
8547
9446
|
looksLikeJson,
|
|
8548
9447
|
markCodeExecution,
|
|
8549
9448
|
markReadOnly,
|
|
9449
|
+
matchPipelineRoute,
|
|
8550
9450
|
matchRule,
|
|
8551
9451
|
mcpAppOrigin,
|
|
8552
9452
|
mcpSkillEntryRefusal,
|
|
@@ -8563,6 +9463,7 @@ export {
|
|
|
8563
9463
|
normalizeSkillName,
|
|
8564
9464
|
normalizeSteps,
|
|
8565
9465
|
normalizeUsage,
|
|
9466
|
+
onStorageChange,
|
|
8566
9467
|
openAgentWebDB,
|
|
8567
9468
|
outputCapNotice,
|
|
8568
9469
|
parseExecutorResponse,
|
|
@@ -8571,12 +9472,16 @@ export {
|
|
|
8571
9472
|
parseReplannerResponse,
|
|
8572
9473
|
parseSearchResponse,
|
|
8573
9474
|
parseSkillMarkdown,
|
|
9475
|
+
pickPipelineRoute,
|
|
8574
9476
|
pickTier,
|
|
9477
|
+
postStorageChange,
|
|
8575
9478
|
preloadWebLLMModel,
|
|
9479
|
+
preparePipeline,
|
|
8576
9480
|
promptHintOf,
|
|
8577
9481
|
renderActiveSkills,
|
|
8578
9482
|
renderCatalog,
|
|
8579
9483
|
renderPipelineNodeInput,
|
|
9484
|
+
renderPipelineRoutePrompt,
|
|
8580
9485
|
renderSearchCatalog,
|
|
8581
9486
|
renderSkillIndex,
|
|
8582
9487
|
replanWanted,
|
|
@@ -8593,6 +9498,7 @@ export {
|
|
|
8593
9498
|
resolveResume,
|
|
8594
9499
|
resolveStage,
|
|
8595
9500
|
resolveThinking,
|
|
9501
|
+
runPipelineGraph,
|
|
8596
9502
|
runToolLoop,
|
|
8597
9503
|
sanitizeSearchResults,
|
|
8598
9504
|
schemaHintOf,
|
|
@@ -8623,6 +9529,7 @@ export {
|
|
|
8623
9529
|
toolRunContextOf,
|
|
8624
9530
|
unloadWebLLMModel,
|
|
8625
9531
|
validatePipeline,
|
|
9532
|
+
watchSession,
|
|
8626
9533
|
webLLMContextWindow,
|
|
8627
9534
|
withRollingBreakpoint,
|
|
8628
9535
|
withSystem,
|