@dudko.dev/agent-web 0.0.28 → 0.0.29
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 +8 -1
- package/dist/agent-web.js +111 -98
- package/dist/agent-web.js.map +1 -1
- package/dist/{chunk-V7COB2EA.js → chunk-CPSDKXO6.js} +5 -2
- package/dist/chunk-CPSDKXO6.js.map +1 -0
- package/dist/index.cjs +496 -63
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +347 -7
- package/dist/index.d.ts +347 -7
- package/dist/index.js +490 -63
- package/dist/index.js.map +1 -1
- package/dist/mcp.cjs +3 -1
- package/dist/mcp.cjs.map +1 -1
- package/dist/mcp.js +1 -1
- package/package.json +9 -9
- package/dist/chunk-V7COB2EA.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -46,6 +46,102 @@ interface IStepResult {
|
|
|
46
46
|
blocked: boolean;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
/**
|
|
50
|
+
* Run persistence: checkpoints a run so that a page reload, a crashed tab or a
|
|
51
|
+
* killed worker does not lose the work already done. Same hook names as the Node
|
|
52
|
+
* sibling (`@dudko.dev/agent`), where this contract originated.
|
|
53
|
+
*
|
|
54
|
+
* WHAT A CHECKPOINT IS. One is written when the plan is in hand (`onRunStart`)
|
|
55
|
+
* and again at the end of every iteration of the step loop (`onStepComplete`),
|
|
56
|
+
* so it always names a boundary: the steps finished so far, the steps still to
|
|
57
|
+
* run, and the counters. Resuming picks up exactly there — the planner does not
|
|
58
|
+
* run again and a finished step is not repeated.
|
|
59
|
+
*
|
|
60
|
+
* WHAT IT IS NOT. A step that was in flight when the page died is NOT
|
|
61
|
+
* checkpointed — it runs again from its start. For a read that is free; for a
|
|
62
|
+
* write it may apply twice, so a tool with side effects should be idempotent (or
|
|
63
|
+
* the host should keep the consent gate on). Attachments (images, files) are not
|
|
64
|
+
* stored — pass them again to `run()` when resuming.
|
|
65
|
+
*
|
|
66
|
+
* Persistence is observability, not a correctness boundary: a hook that throws is
|
|
67
|
+
* logged and the run carries on.
|
|
68
|
+
*/
|
|
69
|
+
type RunStatus = 'executing' | 'complete' | 'failed' | 'cancelled';
|
|
70
|
+
/** Everything needed to continue a run from the end of an iteration. */
|
|
71
|
+
interface RunSnapshot {
|
|
72
|
+
runId: string;
|
|
73
|
+
startedAt: number;
|
|
74
|
+
/**
|
|
75
|
+
* `executing` is the only non-terminal status the runtime writes. The others are
|
|
76
|
+
* written once, when the run resolves; `failed` and `cancelled` can still be
|
|
77
|
+
* resumed (a stopped run is not a lost one), `complete` cannot.
|
|
78
|
+
*/
|
|
79
|
+
status: RunStatus;
|
|
80
|
+
/** The goal as first given: a resumed run uses THIS one, whatever `run()` is passed. */
|
|
81
|
+
goal: string;
|
|
82
|
+
/** The session the run belongs to; a resumed run keeps it. */
|
|
83
|
+
sessionId: string;
|
|
84
|
+
/** The plan as first created (a `revise` later changes `remaining`, not this). */
|
|
85
|
+
plan: IPlan;
|
|
86
|
+
/** Steps still to run, after any `revise`. */
|
|
87
|
+
remaining: IPlanStep[];
|
|
88
|
+
/** Finished steps, as the run's trace. */
|
|
89
|
+
trace: IStepResult[];
|
|
90
|
+
/** The step log later steps and the answer are written from. */
|
|
91
|
+
done: string[];
|
|
92
|
+
/** Tool findings the synthesizer is given. */
|
|
93
|
+
findings: string[];
|
|
94
|
+
usage: IUsage;
|
|
95
|
+
/** Steps executed so far (the cap `maxIterations` counts these — across a crash). */
|
|
96
|
+
iterations: number;
|
|
97
|
+
/** Replanner `revise` decisions so far (`maxRevisions`). */
|
|
98
|
+
revisions: number;
|
|
99
|
+
/** Successful tool calls so far (`maxToolCalls`). */
|
|
100
|
+
toolCalls: number;
|
|
101
|
+
/** Tool calls that went through: `RunResult.applied`. */
|
|
102
|
+
applied: number;
|
|
103
|
+
/** Skills whose instructions are active. */
|
|
104
|
+
skills: string[];
|
|
105
|
+
/** Tools activated through `find_tools`, in order. */
|
|
106
|
+
discovered: string[];
|
|
107
|
+
/** How many images/files the run was given (their bytes are not kept). */
|
|
108
|
+
attachments: number;
|
|
109
|
+
/**
|
|
110
|
+
* What the user said while the run was going (`RunControl.send`), in order, and whether the
|
|
111
|
+
* replanner has already weighed each. A resumed run keeps them: otherwise it would forget a
|
|
112
|
+
* correction the user had already made.
|
|
113
|
+
*/
|
|
114
|
+
userUpdates?: {
|
|
115
|
+
text: string;
|
|
116
|
+
reconciled: boolean;
|
|
117
|
+
}[];
|
|
118
|
+
/** Final answer (status `complete`). */
|
|
119
|
+
text?: string;
|
|
120
|
+
/** What ended the run (status `failed`). */
|
|
121
|
+
error?: string;
|
|
122
|
+
completedAt?: number;
|
|
123
|
+
}
|
|
124
|
+
interface RunPersistence {
|
|
125
|
+
/** The plan is in hand and the loop is about to start. Not called again on resume. */
|
|
126
|
+
onRunStart?: (snapshot: RunSnapshot) => void | Promise<void>;
|
|
127
|
+
/** An iteration finished: a checkpoint to resume from. */
|
|
128
|
+
onStepComplete?: (snapshot: RunSnapshot) => void | Promise<void>;
|
|
129
|
+
/** The run resolved: `complete`, `failed` (it threw) or `cancelled` (it was stopped). */
|
|
130
|
+
onRunComplete?: (snapshot: RunSnapshot) => void | Promise<void>;
|
|
131
|
+
/**
|
|
132
|
+
* What `run(goal, { resumeFromRunId })` reads. Return `null` when there is none.
|
|
133
|
+
* An implementation that does not want to support resume can leave it out.
|
|
134
|
+
*/
|
|
135
|
+
loadRun?: (runId: string) => RunSnapshot | null | Promise<RunSnapshot | null>;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Load and validate the snapshot a `resumeFromRunId` names. Throws a message the
|
|
139
|
+
* caller can act on for: no `loadRun`, no such run, a store that answers with a
|
|
140
|
+
* different run, a run that already completed, a snapshot with nothing left to do.
|
|
141
|
+
* Persistence is host-controlled, so what `loadRun` returns is not trusted.
|
|
142
|
+
*/
|
|
143
|
+
declare const resolveResume: (persistence: RunPersistence | undefined, resumeFromRunId: string | undefined) => Promise<RunSnapshot | undefined>;
|
|
144
|
+
|
|
49
145
|
/**
|
|
50
146
|
* Thinking (a.k.a. reasoning) activation, portable across providers.
|
|
51
147
|
*
|
|
@@ -406,6 +502,8 @@ interface ExecutorPromptContext {
|
|
|
406
502
|
activeSkills?: string;
|
|
407
503
|
/** The executor can call find_tools to activate more tools. */
|
|
408
504
|
searchMode?: boolean;
|
|
505
|
+
/** What the user said while the run was going (`RunControl.send`), oldest first. */
|
|
506
|
+
updates?: string[];
|
|
409
507
|
}
|
|
410
508
|
interface ReplannerPromptContext {
|
|
411
509
|
goal: string;
|
|
@@ -414,6 +512,10 @@ interface ReplannerPromptContext {
|
|
|
414
512
|
remaining: string[];
|
|
415
513
|
mode: ToolCallMode;
|
|
416
514
|
activeSkills?: string;
|
|
515
|
+
/** What the user said while the run was going, oldest first. */
|
|
516
|
+
updates?: string[];
|
|
517
|
+
/** How many of `updates` (the last ones) the plan has not been weighed against yet. */
|
|
518
|
+
newUpdates?: number;
|
|
417
519
|
}
|
|
418
520
|
interface SynthesizerPromptContext {
|
|
419
521
|
goal: string;
|
|
@@ -422,6 +524,8 @@ interface SynthesizerPromptContext {
|
|
|
422
524
|
/** Excerpts of what the tools returned, for answering with real data. */
|
|
423
525
|
findings?: string[];
|
|
424
526
|
activeSkills?: string;
|
|
527
|
+
/** What the user said while the run was going, oldest first. */
|
|
528
|
+
updates?: string[];
|
|
425
529
|
}
|
|
426
530
|
interface Prompts {
|
|
427
531
|
planner(ctx: PlannerPromptContext): PromptParts;
|
|
@@ -643,6 +747,13 @@ interface BrowserAgentConfig {
|
|
|
643
747
|
*/
|
|
644
748
|
memory?: ContextStore;
|
|
645
749
|
sessionId?: string;
|
|
750
|
+
/**
|
|
751
|
+
* Checkpoint runs so a reload or a crashed tab does not lose finished work:
|
|
752
|
+
* `new IndexedDBRunStore()` survives a reload, `new MemoryRunStore()` does not.
|
|
753
|
+
* `run(goal, { resumeFromRunId })` then continues from the last checkpoint —
|
|
754
|
+
* see `RunSnapshot` for exactly what is, and is not, kept.
|
|
755
|
+
*/
|
|
756
|
+
persistence?: RunPersistence;
|
|
646
757
|
/** Hard cap on executed steps incl. replans (default 8). */
|
|
647
758
|
maxIterations?: number;
|
|
648
759
|
/** Cap on tool-calling rounds inside one executor call, both modes (default 4). */
|
|
@@ -734,9 +845,19 @@ type UsagePhase = Phase | 'compact' | 'subagent';
|
|
|
734
845
|
* event taxonomy (no persistence/otel events), plus `model.load` for WebLLM
|
|
735
846
|
* weight-download progress.
|
|
736
847
|
*/
|
|
737
|
-
type AgentEvent =
|
|
848
|
+
type AgentEvent =
|
|
849
|
+
/**
|
|
850
|
+
* `runId` names the run for `persistence` / `resumeFromRunId`. `resumed` is set when it
|
|
851
|
+
* continues a checkpointed run: the steps already done and the ones still to come.
|
|
852
|
+
*/
|
|
853
|
+
{
|
|
738
854
|
type: 'run.start';
|
|
739
855
|
goal: string;
|
|
856
|
+
runId?: string;
|
|
857
|
+
resumed?: {
|
|
858
|
+
completedSteps: number;
|
|
859
|
+
remainingSteps: number;
|
|
860
|
+
};
|
|
740
861
|
} | {
|
|
741
862
|
type: 'model.load';
|
|
742
863
|
progress: number;
|
|
@@ -785,10 +906,13 @@ type AgentEvent = {
|
|
|
785
906
|
type: 'step.complete';
|
|
786
907
|
step: IPlanStep;
|
|
787
908
|
result: IStepResult;
|
|
788
|
-
}
|
|
909
|
+
}
|
|
910
|
+
/** `byUser`: the replanner ran because the user sent a message (`RunControl.send`), not because a step failed. */
|
|
911
|
+
| {
|
|
789
912
|
type: 'replan.decision';
|
|
790
913
|
mode: ReplanMode;
|
|
791
914
|
reason: string;
|
|
915
|
+
byUser?: boolean;
|
|
792
916
|
} | {
|
|
793
917
|
type: 'final.text-delta';
|
|
794
918
|
delta: string;
|
|
@@ -855,11 +979,14 @@ type AgentEvent = {
|
|
|
855
979
|
approved: boolean;
|
|
856
980
|
reason?: string;
|
|
857
981
|
automatic: boolean;
|
|
858
|
-
}
|
|
982
|
+
}
|
|
983
|
+
/** `profile` is set when the parent chose one of the subagent's named profiles for this call. */
|
|
984
|
+
| {
|
|
859
985
|
type: 'subagent.start';
|
|
860
986
|
id: string;
|
|
861
987
|
name: string;
|
|
862
988
|
task: string;
|
|
989
|
+
profile?: string;
|
|
863
990
|
}
|
|
864
991
|
/** An event of a running subagent, forwarded verbatim. */
|
|
865
992
|
| {
|
|
@@ -873,11 +1000,32 @@ type AgentEvent = {
|
|
|
873
1000
|
name: string;
|
|
874
1001
|
text: string;
|
|
875
1002
|
usage: IUsage;
|
|
876
|
-
}
|
|
1003
|
+
}
|
|
1004
|
+
/** `stopped` is set when the user stopped this subagent (`RunControl.stopSubagent`), as opposed to it failing. */
|
|
1005
|
+
| {
|
|
877
1006
|
type: 'subagent.error';
|
|
878
1007
|
id: string;
|
|
879
1008
|
name: string;
|
|
880
1009
|
error: string;
|
|
1010
|
+
stopped?: boolean;
|
|
1011
|
+
}
|
|
1012
|
+
/** A message sent with `RunControl.send` is waiting for the next boundary. */
|
|
1013
|
+
| {
|
|
1014
|
+
type: 'message.queued';
|
|
1015
|
+
id: string;
|
|
1016
|
+
text: string;
|
|
1017
|
+
}
|
|
1018
|
+
/**
|
|
1019
|
+
* The message reached the model. `round` = between tool-calling rounds inside a step, so
|
|
1020
|
+
* the rest of that step can act on it (the replanner weighs it at the end of the step);
|
|
1021
|
+
* `step` = at a step boundary, where it forces the replanner to look at the plan;
|
|
1022
|
+
* `final` = just before the answer is written.
|
|
1023
|
+
*/
|
|
1024
|
+
| {
|
|
1025
|
+
type: 'message.delivered';
|
|
1026
|
+
id: string;
|
|
1027
|
+
text: string;
|
|
1028
|
+
at: 'round' | 'step' | 'final';
|
|
881
1029
|
} | {
|
|
882
1030
|
type: 'stopped';
|
|
883
1031
|
} | {
|
|
@@ -933,6 +1081,75 @@ declare const renderSearchCatalog: (catalog: ToolCatalogEntry[], budget?: number
|
|
|
933
1081
|
*/
|
|
934
1082
|
declare const createFindToolsTool: (catalog: () => ToolCatalogEntry[], onFound: (query: string, names: string[]) => void, hintOf?: (name: string) => string | undefined) => Tool;
|
|
935
1083
|
|
|
1084
|
+
/**
|
|
1085
|
+
* Steering a run that is already going.
|
|
1086
|
+
*
|
|
1087
|
+
* `run()` takes one goal and returns when the run is over, so a host that wants to
|
|
1088
|
+
* say something mid-run — "actually use the staging database" — or stop one
|
|
1089
|
+
* subagent out of several has nothing to call. A `RunControl` is the handle: create
|
|
1090
|
+
* one, pass it as `run(goal, { control })`, and use it from anywhere while the run
|
|
1091
|
+
* is in flight.
|
|
1092
|
+
*
|
|
1093
|
+
* A message is not interrupt. The run never cuts a tool call short (it may be a
|
|
1094
|
+
* write): the message is held until the next boundary — the next tool-calling round
|
|
1095
|
+
* inside a step, or the end of the step — and is then shown to the model. At a step
|
|
1096
|
+
* boundary it also forces the replanner to look at the plan again, because a plan
|
|
1097
|
+
* made before the user spoke may no longer be the right one.
|
|
1098
|
+
*/
|
|
1099
|
+
/** One running subagent, as the host sees it. */
|
|
1100
|
+
interface SubagentInfo {
|
|
1101
|
+
id: string;
|
|
1102
|
+
/** The subagent tool's `name`. */
|
|
1103
|
+
name: string;
|
|
1104
|
+
task: string;
|
|
1105
|
+
/** The profile the parent chose for this call, when it chose one. */
|
|
1106
|
+
profile?: string;
|
|
1107
|
+
startedAt: number;
|
|
1108
|
+
}
|
|
1109
|
+
interface RunControl {
|
|
1110
|
+
/**
|
|
1111
|
+
* Queue a message for the run. `false` when there is nothing to deliver it to — the text
|
|
1112
|
+
* is empty, or the run has already finished (send it as a new run instead).
|
|
1113
|
+
*
|
|
1114
|
+
* Accepted does not mean delivered: a message that arrives after the last boundary
|
|
1115
|
+
* (while the answer is being written) comes back in `RunResult.undelivered`, so the
|
|
1116
|
+
* host can send it next.
|
|
1117
|
+
*/
|
|
1118
|
+
send(text: string): boolean;
|
|
1119
|
+
/**
|
|
1120
|
+
* Messages sent and not yet delivered. Once the run is over: the ones it never got to show
|
|
1121
|
+
* the model (the same list as `RunResult.undelivered`, which a run that threw cannot return).
|
|
1122
|
+
*/
|
|
1123
|
+
pending(): string[];
|
|
1124
|
+
/** The subagents running under this run right now (a snapshot; `subagent.*` events are the stream). */
|
|
1125
|
+
subagents(): SubagentInfo[];
|
|
1126
|
+
/**
|
|
1127
|
+
* Stop ONE running subagent. Its delegation fails with a message the parent model can
|
|
1128
|
+
* route around, and the run carries on — unlike aborting the run, which stops everything.
|
|
1129
|
+
* `false` when no subagent with that id is running.
|
|
1130
|
+
*/
|
|
1131
|
+
stopSubagent(id: string): boolean;
|
|
1132
|
+
}
|
|
1133
|
+
interface QueuedMessage {
|
|
1134
|
+
id: string;
|
|
1135
|
+
text: string;
|
|
1136
|
+
}
|
|
1137
|
+
/** What the runner and the subagent tool use; deliberately not part of the public surface. */
|
|
1138
|
+
interface RunControlPort {
|
|
1139
|
+
/** The run starts reading: from now on `send` announces itself. */
|
|
1140
|
+
attach(emit: (event: AgentEvent) => void): void;
|
|
1141
|
+
/**
|
|
1142
|
+
* The run is over: whatever is still queued is returned, for the host to send as a
|
|
1143
|
+
* follow-up. It stays readable through `pending()` until the control serves another run.
|
|
1144
|
+
*/
|
|
1145
|
+
detach(): string[];
|
|
1146
|
+
/** Take every queued message, oldest first. */
|
|
1147
|
+
drain(): QueuedMessage[];
|
|
1148
|
+
/** A subagent started under this run; returns what unregisters it. */
|
|
1149
|
+
registerSubagent(info: SubagentInfo, stop: () => void): () => void;
|
|
1150
|
+
}
|
|
1151
|
+
declare const createRunControl: () => RunControl;
|
|
1152
|
+
|
|
936
1153
|
/**
|
|
937
1154
|
* Attachments sent with a run: images, PDFs and other files the provider can
|
|
938
1155
|
* read, given as bytes / base64 / a data URL — or as an http(s) URL, which
|
|
@@ -1025,6 +1242,13 @@ interface AgentContext {
|
|
|
1025
1242
|
setCurrentStep?: (step: IPlanStep | undefined) => void;
|
|
1026
1243
|
/** Images / PDFs / files the user sent with this run's goal. */
|
|
1027
1244
|
images?: RunFile[];
|
|
1245
|
+
/** Everything the user said while the run was going (`RunControl.send`), oldest first. */
|
|
1246
|
+
userUpdates?: () => string[];
|
|
1247
|
+
/**
|
|
1248
|
+
* Take what the user said since the last boundary, for delivery INSIDE a step (between
|
|
1249
|
+
* tool-calling rounds): records it, announces it, and returns the texts.
|
|
1250
|
+
*/
|
|
1251
|
+
takeRoundUpdates?: () => string[];
|
|
1028
1252
|
}
|
|
1029
1253
|
|
|
1030
1254
|
interface RunOptions {
|
|
@@ -1032,6 +1256,18 @@ interface RunOptions {
|
|
|
1032
1256
|
signal?: AbortSignal;
|
|
1033
1257
|
/** Override the config's sessionId for this run. */
|
|
1034
1258
|
sessionId?: string;
|
|
1259
|
+
/**
|
|
1260
|
+
* Continue a checkpointed run instead of starting one (needs `persistence.loadRun`). The
|
|
1261
|
+
* saved goal, plan, finished steps and counters win — whatever `goal` is passed, and without
|
|
1262
|
+
* planning again. Attachments are not stored: pass them again if the run needs them.
|
|
1263
|
+
*/
|
|
1264
|
+
resumeFromRunId?: string;
|
|
1265
|
+
/**
|
|
1266
|
+
* Steer the run while it goes: `control.send(text)` puts a message in front of the model
|
|
1267
|
+
* at the next boundary, `control.stopSubagent(id)` stops one subagent. Make it with
|
|
1268
|
+
* `createRunControl()`; one control per run.
|
|
1269
|
+
*/
|
|
1270
|
+
control?: RunControl;
|
|
1035
1271
|
/**
|
|
1036
1272
|
* Images sent with the goal (pasted screenshots, photos). They reach the
|
|
1037
1273
|
* planner, the executor and the synthesizer of a vision-capable model; a
|
|
@@ -1047,6 +1283,8 @@ interface RunOptions {
|
|
|
1047
1283
|
files?: RunFile[];
|
|
1048
1284
|
}
|
|
1049
1285
|
interface RunResult {
|
|
1286
|
+
/** Names this run for `persistence` / `resumeFromRunId`. */
|
|
1287
|
+
runId: string;
|
|
1050
1288
|
goal: string;
|
|
1051
1289
|
final: string;
|
|
1052
1290
|
plan: IPlan;
|
|
@@ -1060,6 +1298,12 @@ interface RunResult {
|
|
|
1060
1298
|
skills: string[];
|
|
1061
1299
|
/** The limit that stopped the run early, if any. */
|
|
1062
1300
|
budgetExceeded?: LimitBreach;
|
|
1301
|
+
/**
|
|
1302
|
+
* Set when the run was given a `control`: the messages sent with it that the run never got
|
|
1303
|
+
* to show the model (they arrived while the answer was being written, or after the run was
|
|
1304
|
+
* stopped or ended). Send them as the next run. Empty when everything was delivered.
|
|
1305
|
+
*/
|
|
1306
|
+
undelivered?: string[];
|
|
1063
1307
|
}
|
|
1064
1308
|
interface CompactOptions {
|
|
1065
1309
|
/** Session to compact (default: the config's sessionId). */
|
|
@@ -1260,7 +1504,9 @@ interface ReplanOutcome {
|
|
|
1260
1504
|
* mode salvages the decision from text. Any failure degrades to 'continue' so a
|
|
1261
1505
|
* flaky replanner never aborts the run.
|
|
1262
1506
|
*/
|
|
1263
|
-
declare const decideReplan: (ctx: AgentContext, goal: string, done: string[], remaining: string[]
|
|
1507
|
+
declare const decideReplan: (ctx: AgentContext, goal: string, done: string[], remaining: string[],
|
|
1508
|
+
/** How many of the user's latest messages (`ctx.userUpdates()`) the plan has not been weighed against yet. */
|
|
1509
|
+
newUpdates?: number) => Promise<ReplanOutcome>;
|
|
1264
1510
|
|
|
1265
1511
|
/**
|
|
1266
1512
|
* Write the final natural-language answer of the run, streaming it as
|
|
@@ -1345,6 +1591,22 @@ type SubagentWorkerConfig = Pick<BrowserAgentConfig, 'clientName' | 'systemPromp
|
|
|
1345
1591
|
rules?: Record<string, 'allow' | 'deny'>;
|
|
1346
1592
|
};
|
|
1347
1593
|
};
|
|
1594
|
+
/**
|
|
1595
|
+
* A named way to run the same subagent. Its fields are laid OVER the base
|
|
1596
|
+
* `config` / `workerConfig`, field by field and shallow: a profile's `limits`
|
|
1597
|
+
* replaces the base's `limits`, it is not merged into it. The PARENT model picks
|
|
1598
|
+
* one per call with the optional `profile` argument; the host decides what each
|
|
1599
|
+
* name means — a cheap model for a quick lookup, a strong one with thinking for
|
|
1600
|
+
* a hard question, a different system prompt, a narrower tool set.
|
|
1601
|
+
*/
|
|
1602
|
+
interface SubagentProfile {
|
|
1603
|
+
/** When to pick this profile — shown to the parent model, which chooses by it. */
|
|
1604
|
+
description: string;
|
|
1605
|
+
/** In-process subagent: fields laid over `config` (model, thinking, limits, systemPrompt, tools …). */
|
|
1606
|
+
config?: Partial<BrowserAgentConfig>;
|
|
1607
|
+
/** Worker subagent: fields laid over `workerConfig`. */
|
|
1608
|
+
workerConfig?: Partial<SubagentWorkerConfig>;
|
|
1609
|
+
}
|
|
1348
1610
|
interface SubagentToolOptions {
|
|
1349
1611
|
/** Label for events and logs (the tool's KEY in your ToolSet is up to you). */
|
|
1350
1612
|
name: string;
|
|
@@ -1379,6 +1641,14 @@ interface SubagentToolOptions {
|
|
|
1379
1641
|
outputMaxChars?: number;
|
|
1380
1642
|
/** Mark the tool read-only for the parent's consent gate (default false). */
|
|
1381
1643
|
readOnly?: boolean;
|
|
1644
|
+
/**
|
|
1645
|
+
* Named variants the parent model chooses between per call. The tool gains an
|
|
1646
|
+
* optional `profile` argument (one of these names); leaving it out runs the base
|
|
1647
|
+
* config. The child's context is still just `task` — a profile that changes
|
|
1648
|
+
* `systemPrompt`, `skills` or `tools` is how a child gets a different one.
|
|
1649
|
+
* Without profiles the tool is exactly what it was.
|
|
1650
|
+
*/
|
|
1651
|
+
profiles?: Record<string, SubagentProfile>;
|
|
1382
1652
|
}
|
|
1383
1653
|
/**
|
|
1384
1654
|
* Expose a subagent as a tool: the parent delegates `{ task }`, the child runs
|
|
@@ -1734,6 +2004,7 @@ declare const KEYS_STORE = "keys";
|
|
|
1734
2004
|
declare const SECRETS_STORE = "secrets";
|
|
1735
2005
|
declare const SESSIONS_STORE = "sessions";
|
|
1736
2006
|
declare const FILES_STORE = "files";
|
|
2007
|
+
declare const RUNS_STORE = "runs";
|
|
1737
2008
|
/**
|
|
1738
2009
|
* The single owner of the IndexedDB database. Every persistent store — the
|
|
1739
2010
|
* non-extractable crypto key, encrypted secrets, and session transcripts —
|
|
@@ -1853,6 +2124,13 @@ interface ToolLoopOptions {
|
|
|
1853
2124
|
caching?: ResolvedCaching;
|
|
1854
2125
|
/** Clear the oldest tool results once the loop's context grows past a threshold. */
|
|
1855
2126
|
clearToolResults?: ToolResultClearing;
|
|
2127
|
+
/**
|
|
2128
|
+
* Called at every round boundary — after a round's tool results, right before the model
|
|
2129
|
+
* is called again — for what the user said in the meantime. A non-empty answer is shown to
|
|
2130
|
+
* the model as a new user turn (so it can act on it within this call). Never called before
|
|
2131
|
+
* the first round, and not at all once the model has stopped calling tools.
|
|
2132
|
+
*/
|
|
2133
|
+
takeUpdates?: () => string[];
|
|
1856
2134
|
callbacks?: ToolLoopCallbacks;
|
|
1857
2135
|
}
|
|
1858
2136
|
interface ToolLoopResult {
|
|
@@ -1969,6 +2247,8 @@ interface ToolRunContext {
|
|
|
1969
2247
|
* tool a subagent calls). Resolves when allowed, throws ToolDeniedError.
|
|
1970
2248
|
*/
|
|
1971
2249
|
approve: (toolName: string, input: unknown, readOnly: boolean) => Promise<void>;
|
|
2250
|
+
/** The run's control, when the host passed one: subagents register here so they can be listed and stopped. */
|
|
2251
|
+
control?: RunControlPort;
|
|
1972
2252
|
}
|
|
1973
2253
|
/** Read the run context the agent passes to a tool's execute (undefined outside a run). */
|
|
1974
2254
|
declare const toolRunContextOf: (options: unknown) => ToolRunContext | undefined;
|
|
@@ -2005,5 +2285,65 @@ declare class IndexedDBStore implements ContextStore {
|
|
|
2005
2285
|
listSessions(): Promise<string[]>;
|
|
2006
2286
|
}
|
|
2007
2287
|
|
|
2008
|
-
|
|
2009
|
-
|
|
2288
|
+
interface RunStoreOptions {
|
|
2289
|
+
/**
|
|
2290
|
+
* Keep the snapshot of a run that completed (default false). A completed run has
|
|
2291
|
+
* nothing to resume, and its transcript lives in the session store, so keeping it
|
|
2292
|
+
* only grows the database — but a host that wants an audit trail can.
|
|
2293
|
+
*/
|
|
2294
|
+
keepCompleted?: boolean;
|
|
2295
|
+
}
|
|
2296
|
+
/**
|
|
2297
|
+
* Checkpoints in memory: enough to resume within one page's life (a stopped run, a
|
|
2298
|
+
* failed step) and for tests, but a reload loses them — use `IndexedDBRunStore` for that.
|
|
2299
|
+
*/
|
|
2300
|
+
declare class MemoryRunStore implements RunPersistence {
|
|
2301
|
+
private readonly runs;
|
|
2302
|
+
private readonly keepCompleted;
|
|
2303
|
+
constructor(opts?: RunStoreOptions);
|
|
2304
|
+
onRunStart(snapshot: RunSnapshot): void;
|
|
2305
|
+
onStepComplete(snapshot: RunSnapshot): void;
|
|
2306
|
+
onRunComplete(snapshot: RunSnapshot): void;
|
|
2307
|
+
loadRun(runId: string): RunSnapshot | null;
|
|
2308
|
+
/** Runs that can still be resumed (executing, stopped or failed), newest first. */
|
|
2309
|
+
resumable(sessionId?: string): RunSnapshot[];
|
|
2310
|
+
/** The most recent run that can be resumed — what to offer after a reload. */
|
|
2311
|
+
latestResumable(sessionId?: string): RunSnapshot | undefined;
|
|
2312
|
+
delete(runId: string): void;
|
|
2313
|
+
clear(): void;
|
|
2314
|
+
}
|
|
2315
|
+
interface IndexedDBRunStoreOptions extends RunStoreOptions {
|
|
2316
|
+
/** Database name, forwarded to the shared IDB owner (default 'agent-web'). */
|
|
2317
|
+
dbName?: string;
|
|
2318
|
+
}
|
|
2319
|
+
/**
|
|
2320
|
+
* Checkpoints in IndexedDB — one record per run, in the shared `runs` object store
|
|
2321
|
+
* (see storage/db.ts) — so a reload or a crashed tab can resume where it stopped:
|
|
2322
|
+
*
|
|
2323
|
+
* ```ts
|
|
2324
|
+
* const runs = new IndexedDBRunStore()
|
|
2325
|
+
* const agent = await createAgent({ model, persistence: runs })
|
|
2326
|
+
* // after a reload:
|
|
2327
|
+
* const unfinished = await runs.latestResumable(sessionId)
|
|
2328
|
+
* if (unfinished) await agent.run('', { resumeFromRunId: unfinished.runId })
|
|
2329
|
+
* ```
|
|
2330
|
+
*/
|
|
2331
|
+
declare class IndexedDBRunStore implements RunPersistence {
|
|
2332
|
+
private readonly dbName?;
|
|
2333
|
+
private readonly keepCompleted;
|
|
2334
|
+
constructor(opts?: IndexedDBRunStoreOptions);
|
|
2335
|
+
private put;
|
|
2336
|
+
onRunStart(snapshot: RunSnapshot): Promise<void>;
|
|
2337
|
+
onStepComplete(snapshot: RunSnapshot): Promise<void>;
|
|
2338
|
+
onRunComplete(snapshot: RunSnapshot): Promise<void>;
|
|
2339
|
+
loadRun(runId: string): Promise<RunSnapshot | null>;
|
|
2340
|
+
/** Runs that can still be resumed (executing, stopped or failed), newest first. */
|
|
2341
|
+
resumable(sessionId?: string): Promise<RunSnapshot[]>;
|
|
2342
|
+
/** The most recent run that can be resumed — what to offer after a reload. */
|
|
2343
|
+
latestResumable(sessionId?: string): Promise<RunSnapshot | undefined>;
|
|
2344
|
+
delete(runId: string): Promise<void>;
|
|
2345
|
+
clear(): Promise<void>;
|
|
2346
|
+
}
|
|
2347
|
+
|
|
2348
|
+
export { AgentTool, AgentToolSet, AttachmentsNotSupportedError, ContextWindowExceededError, FILES_STORE, FIND_TOOLS_NAME, ImagesNotSupportedError, IndexedDBRunStore, IndexedDBStore, KEYS_STORE, MemoryCredentialStore, MemoryRunStore, MemoryStore, PlanSchema, PlanStepSchema, RUNS_STORE, ReplanSchema, SECRETS_STORE, SESSIONS_STORE, SKILL_TOOL_NAMES, TOOL_APPROVAL_MODES, TOOL_SEARCH_WINDOW_SHARE, ToolBudgetError, ToolDeniedError, VaultCredentialStore, VaultOptions, VirtualFileSystem, WEBLLM_DEFAULT_CONTEXT_WINDOW, attachmentKind, buildModelFromStage, bytesToBase64, checkLimits, compactHistory, compactSteps, compressHistory, contextOverflowOf, contextWindowOf, createAgent, createFileTools, createFindToolsTool, createLogger, createPlan, createRunControl, createSkillTools, createSubagentTool, createToolResultClearer, createWebLLMModel, decideReplan, decideToolPermission, decryptJSON, defaultPrompts, defineSkill, defineTool, directBrowserOk, dispatch, encryptJSON, messageTokens as estimateMessagesTokens, estimateTokens, executeStep, fitCompactionToWindow, generate, generateStructured, getOrCreateVaultKey, isAttachmentRefusal, isDirectModel, isImageRefusal, isProviderSpec, isReadOnlyTool, isTextMime, isWebGPUAvailable, limitModelOutput, loadSkillFromUrl, looksLikeJson, markReadOnly, matchRule, mediaTypeOf, mergeProviderOptions, mimeFromPath, normalizePath, normalizeSteps, normalizeUsage, openAgentWebDB, parseExecutorResponse, parsePlainText, parsePlannerResponse, parseReplannerResponse, parseSkillMarkdown, preloadWebLLMModel, renderActiveSkills, renderCatalog, renderSearchCatalog, renderSkillIndex, replanWanted, resolveCaching, resolveCompaction, resolveConfig, resolveModel, resolveResume, resolveStage, resolveThinking, runToolLoop, schemaHintOf, searchTools, selectToolMode, serveSubagentWorker, shouldReplan, splitBlocker, stream, supportsImages, supportsNativeTools, supportsPdf, supportsStructuredOutput, synthesizeAnswer, thinkingFor, toFilePart, toImagePart, tokenize, toolCatalogOf, toolDefinitionTokens, toolRunContextOf, unloadWebLLMModel, webLLMContextWindow, withRollingBreakpoint, withSystem, withWebLLMContextWindow };
|
|
2349
|
+
export type { Agent, AgentContext, AgentEvent, AgentEventHandler, AgentLogger, AgentLoggerSink, AgentWebDBOptions, AttachmentKind, BrowserAgentConfig, ClearedInfo, CompactOptions, CompactResult, CompactionConfig, CompressOptions, ContextStore, CredentialStore, EffectiveToolStrategy, EncryptedBlob, ExecutorPromptContext, ExecutorResult, FileToolsOptions, GenerateOptions, IPlan, IPlanStep, IStepResult, IToolCall, IUsage, IndexedDBRunStoreOptions, IndexedDBStoreOptions, LimitBreach, LimitKind, LoadSkillOptions, LogLevel, MessageEndpoint, ModelInput, ParentToWorker, Phase, PhaseBudgets, PlanShape, PlannerPromptContext, PlannerResult, PromptCachingSetting, PromptParts, Prompts, ProviderModelSpec, ProviderOptionsMap, ProviderType, ProxiedToolSpec, RawAction, ReplanDecision, ReplanMode, ReplanShape, ReplanTrigger, ReplannerPromptContext, ReplannerResult, ResolvedCaching, ResolvedCompaction, ResolvedConfig, ResolvedStage, ResolvedThinking, RunControl, RunFile, RunImage, RunOptions, RunPersistence, RunResult, RunSnapshot, RunStatus, RunStoreOptions, SearchToolsOptions, ServeSubagentOptions, Skill, StageInput, StageOverride, StoredMessage, SubagentInfo, SubagentProfile, SubagentToolOptions, SubagentWorkerConfig, SynthesizerPromptContext, ThinkingConfig, ThinkingLevel, ThinkingSetting, ThinkingStage, TokenLimits, ToolApprovalConfig, ToolApprovalDecision, ToolApprovalMode, ToolApprovalRequest, ToolCallMode, ToolCatalogEntry, ToolLoopCallbacks, ToolLoopOptions, ToolLoopResult, ToolMode, ToolPermission, ToolResultClearing, ToolRunContext, ToolSelectionStrategy, UsagePhase, VfsListener, VirtualFile, VirtualFileInfo, VirtualFileSystemOptions, WebLLMAppConfigLike, WebLLMModelOptions, WorkerLike, WorkerToParent };
|