@dudko.dev/agent-web 0.0.27 → 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 +39 -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 +349 -24
- package/dist/index.d.ts +349 -24
- 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/dist/types-DwSMj_Xs.d.cts +21 -0
- package/dist/types-DwSMj_Xs.d.ts +21 -0
- package/dist/webmcp.cjs +208 -0
- package/dist/webmcp.cjs.map +1 -0
- package/dist/webmcp.d.cts +131 -0
- package/dist/webmcp.d.ts +131 -0
- package/dist/webmcp.js +179 -0
- package/dist/webmcp.js.map +1 -0
- package/package.json +19 -9
- package/dist/chunk-V7COB2EA.js.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -2,6 +2,8 @@ import * as ai from 'ai';
|
|
|
2
2
|
import { LanguageModel, ToolSet, Tool, FilePart, SystemModelMessage, ModelMessage, generateText, streamText } from 'ai';
|
|
3
3
|
import { V as VaultOptions } from './vault-BatBaRQP.cjs';
|
|
4
4
|
export { I as IndexedDBVault } from './vault-BatBaRQP.cjs';
|
|
5
|
+
import { A as AgentToolSet, a as AgentTool } from './types-DwSMj_Xs.cjs';
|
|
6
|
+
export { p as promptHintOf } from './types-DwSMj_Xs.cjs';
|
|
5
7
|
import { z, ZodType } from 'zod';
|
|
6
8
|
import { IDBPDatabase } from 'idb';
|
|
7
9
|
|
|
@@ -44,6 +46,102 @@ interface IStepResult {
|
|
|
44
46
|
blocked: boolean;
|
|
45
47
|
}
|
|
46
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
|
+
|
|
47
145
|
/**
|
|
48
146
|
* Thinking (a.k.a. reasoning) activation, portable across providers.
|
|
49
147
|
*
|
|
@@ -404,6 +502,8 @@ interface ExecutorPromptContext {
|
|
|
404
502
|
activeSkills?: string;
|
|
405
503
|
/** The executor can call find_tools to activate more tools. */
|
|
406
504
|
searchMode?: boolean;
|
|
505
|
+
/** What the user said while the run was going (`RunControl.send`), oldest first. */
|
|
506
|
+
updates?: string[];
|
|
407
507
|
}
|
|
408
508
|
interface ReplannerPromptContext {
|
|
409
509
|
goal: string;
|
|
@@ -412,6 +512,10 @@ interface ReplannerPromptContext {
|
|
|
412
512
|
remaining: string[];
|
|
413
513
|
mode: ToolCallMode;
|
|
414
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;
|
|
415
519
|
}
|
|
416
520
|
interface SynthesizerPromptContext {
|
|
417
521
|
goal: string;
|
|
@@ -420,6 +524,8 @@ interface SynthesizerPromptContext {
|
|
|
420
524
|
/** Excerpts of what the tools returned, for answering with real data. */
|
|
421
525
|
findings?: string[];
|
|
422
526
|
activeSkills?: string;
|
|
527
|
+
/** What the user said while the run was going, oldest first. */
|
|
528
|
+
updates?: string[];
|
|
423
529
|
}
|
|
424
530
|
interface Prompts {
|
|
425
531
|
planner(ctx: PlannerPromptContext): PromptParts;
|
|
@@ -574,23 +680,6 @@ declare const decideToolPermission: (opts: {
|
|
|
574
680
|
remembered?: ReadonlySet<string>;
|
|
575
681
|
}) => ToolPermission;
|
|
576
682
|
|
|
577
|
-
/**
|
|
578
|
-
* The canonical tool shape is the AI SDK `Tool` — the same object the native
|
|
579
|
-
* tool-calling path passes straight to `streamText({ tools })`, and the same
|
|
580
|
-
* shape MCP tools take. We add one optional field, `promptHint`, a short
|
|
581
|
-
* human-readable parameter hint (e.g. "{ text: string, x?: number }") used only
|
|
582
|
-
* by the prompted/salvage path when it renders the tool catalogue into a text
|
|
583
|
-
* prompt for weak local models.
|
|
584
|
-
*/
|
|
585
|
-
type AgentTool = Tool & {
|
|
586
|
-
promptHint?: string;
|
|
587
|
-
readOnly?: boolean;
|
|
588
|
-
};
|
|
589
|
-
/** A named collection of tools — a plain AI SDK ToolSet, usable directly. */
|
|
590
|
-
type AgentToolSet = ToolSet;
|
|
591
|
-
/** Read the optional promptHint attached by defineTool, if any. */
|
|
592
|
-
declare const promptHintOf: (tool: Tool) => string | undefined;
|
|
593
|
-
|
|
594
683
|
/** Force a tool-calling strategy, or let the agent pick per model ('auto'). */
|
|
595
684
|
type ToolMode = 'auto' | 'native' | 'prompted';
|
|
596
685
|
/**
|
|
@@ -658,6 +747,13 @@ interface BrowserAgentConfig {
|
|
|
658
747
|
*/
|
|
659
748
|
memory?: ContextStore;
|
|
660
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;
|
|
661
757
|
/** Hard cap on executed steps incl. replans (default 8). */
|
|
662
758
|
maxIterations?: number;
|
|
663
759
|
/** Cap on tool-calling rounds inside one executor call, both modes (default 4). */
|
|
@@ -749,9 +845,19 @@ type UsagePhase = Phase | 'compact' | 'subagent';
|
|
|
749
845
|
* event taxonomy (no persistence/otel events), plus `model.load` for WebLLM
|
|
750
846
|
* weight-download progress.
|
|
751
847
|
*/
|
|
752
|
-
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
|
+
{
|
|
753
854
|
type: 'run.start';
|
|
754
855
|
goal: string;
|
|
856
|
+
runId?: string;
|
|
857
|
+
resumed?: {
|
|
858
|
+
completedSteps: number;
|
|
859
|
+
remainingSteps: number;
|
|
860
|
+
};
|
|
755
861
|
} | {
|
|
756
862
|
type: 'model.load';
|
|
757
863
|
progress: number;
|
|
@@ -800,10 +906,13 @@ type AgentEvent = {
|
|
|
800
906
|
type: 'step.complete';
|
|
801
907
|
step: IPlanStep;
|
|
802
908
|
result: IStepResult;
|
|
803
|
-
}
|
|
909
|
+
}
|
|
910
|
+
/** `byUser`: the replanner ran because the user sent a message (`RunControl.send`), not because a step failed. */
|
|
911
|
+
| {
|
|
804
912
|
type: 'replan.decision';
|
|
805
913
|
mode: ReplanMode;
|
|
806
914
|
reason: string;
|
|
915
|
+
byUser?: boolean;
|
|
807
916
|
} | {
|
|
808
917
|
type: 'final.text-delta';
|
|
809
918
|
delta: string;
|
|
@@ -870,11 +979,14 @@ type AgentEvent = {
|
|
|
870
979
|
approved: boolean;
|
|
871
980
|
reason?: string;
|
|
872
981
|
automatic: boolean;
|
|
873
|
-
}
|
|
982
|
+
}
|
|
983
|
+
/** `profile` is set when the parent chose one of the subagent's named profiles for this call. */
|
|
984
|
+
| {
|
|
874
985
|
type: 'subagent.start';
|
|
875
986
|
id: string;
|
|
876
987
|
name: string;
|
|
877
988
|
task: string;
|
|
989
|
+
profile?: string;
|
|
878
990
|
}
|
|
879
991
|
/** An event of a running subagent, forwarded verbatim. */
|
|
880
992
|
| {
|
|
@@ -888,11 +1000,32 @@ type AgentEvent = {
|
|
|
888
1000
|
name: string;
|
|
889
1001
|
text: string;
|
|
890
1002
|
usage: IUsage;
|
|
891
|
-
}
|
|
1003
|
+
}
|
|
1004
|
+
/** `stopped` is set when the user stopped this subagent (`RunControl.stopSubagent`), as opposed to it failing. */
|
|
1005
|
+
| {
|
|
892
1006
|
type: 'subagent.error';
|
|
893
1007
|
id: string;
|
|
894
1008
|
name: string;
|
|
895
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';
|
|
896
1029
|
} | {
|
|
897
1030
|
type: 'stopped';
|
|
898
1031
|
} | {
|
|
@@ -948,6 +1081,75 @@ declare const renderSearchCatalog: (catalog: ToolCatalogEntry[], budget?: number
|
|
|
948
1081
|
*/
|
|
949
1082
|
declare const createFindToolsTool: (catalog: () => ToolCatalogEntry[], onFound: (query: string, names: string[]) => void, hintOf?: (name: string) => string | undefined) => Tool;
|
|
950
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
|
+
|
|
951
1153
|
/**
|
|
952
1154
|
* Attachments sent with a run: images, PDFs and other files the provider can
|
|
953
1155
|
* read, given as bytes / base64 / a data URL — or as an http(s) URL, which
|
|
@@ -1040,6 +1242,13 @@ interface AgentContext {
|
|
|
1040
1242
|
setCurrentStep?: (step: IPlanStep | undefined) => void;
|
|
1041
1243
|
/** Images / PDFs / files the user sent with this run's goal. */
|
|
1042
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[];
|
|
1043
1252
|
}
|
|
1044
1253
|
|
|
1045
1254
|
interface RunOptions {
|
|
@@ -1047,6 +1256,18 @@ interface RunOptions {
|
|
|
1047
1256
|
signal?: AbortSignal;
|
|
1048
1257
|
/** Override the config's sessionId for this run. */
|
|
1049
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;
|
|
1050
1271
|
/**
|
|
1051
1272
|
* Images sent with the goal (pasted screenshots, photos). They reach the
|
|
1052
1273
|
* planner, the executor and the synthesizer of a vision-capable model; a
|
|
@@ -1062,6 +1283,8 @@ interface RunOptions {
|
|
|
1062
1283
|
files?: RunFile[];
|
|
1063
1284
|
}
|
|
1064
1285
|
interface RunResult {
|
|
1286
|
+
/** Names this run for `persistence` / `resumeFromRunId`. */
|
|
1287
|
+
runId: string;
|
|
1065
1288
|
goal: string;
|
|
1066
1289
|
final: string;
|
|
1067
1290
|
plan: IPlan;
|
|
@@ -1075,6 +1298,12 @@ interface RunResult {
|
|
|
1075
1298
|
skills: string[];
|
|
1076
1299
|
/** The limit that stopped the run early, if any. */
|
|
1077
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[];
|
|
1078
1307
|
}
|
|
1079
1308
|
interface CompactOptions {
|
|
1080
1309
|
/** Session to compact (default: the config's sessionId). */
|
|
@@ -1275,7 +1504,9 @@ interface ReplanOutcome {
|
|
|
1275
1504
|
* mode salvages the decision from text. Any failure degrades to 'continue' so a
|
|
1276
1505
|
* flaky replanner never aborts the run.
|
|
1277
1506
|
*/
|
|
1278
|
-
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>;
|
|
1279
1510
|
|
|
1280
1511
|
/**
|
|
1281
1512
|
* Write the final natural-language answer of the run, streaming it as
|
|
@@ -1360,6 +1591,22 @@ type SubagentWorkerConfig = Pick<BrowserAgentConfig, 'clientName' | 'systemPromp
|
|
|
1360
1591
|
rules?: Record<string, 'allow' | 'deny'>;
|
|
1361
1592
|
};
|
|
1362
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
|
+
}
|
|
1363
1610
|
interface SubagentToolOptions {
|
|
1364
1611
|
/** Label for events and logs (the tool's KEY in your ToolSet is up to you). */
|
|
1365
1612
|
name: string;
|
|
@@ -1394,6 +1641,14 @@ interface SubagentToolOptions {
|
|
|
1394
1641
|
outputMaxChars?: number;
|
|
1395
1642
|
/** Mark the tool read-only for the parent's consent gate (default false). */
|
|
1396
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>;
|
|
1397
1652
|
}
|
|
1398
1653
|
/**
|
|
1399
1654
|
* Expose a subagent as a tool: the parent delegates `{ task }`, the child runs
|
|
@@ -1749,6 +2004,7 @@ declare const KEYS_STORE = "keys";
|
|
|
1749
2004
|
declare const SECRETS_STORE = "secrets";
|
|
1750
2005
|
declare const SESSIONS_STORE = "sessions";
|
|
1751
2006
|
declare const FILES_STORE = "files";
|
|
2007
|
+
declare const RUNS_STORE = "runs";
|
|
1752
2008
|
/**
|
|
1753
2009
|
* The single owner of the IndexedDB database. Every persistent store — the
|
|
1754
2010
|
* non-extractable crypto key, encrypted secrets, and session transcripts —
|
|
@@ -1868,6 +2124,13 @@ interface ToolLoopOptions {
|
|
|
1868
2124
|
caching?: ResolvedCaching;
|
|
1869
2125
|
/** Clear the oldest tool results once the loop's context grows past a threshold. */
|
|
1870
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[];
|
|
1871
2134
|
callbacks?: ToolLoopCallbacks;
|
|
1872
2135
|
}
|
|
1873
2136
|
interface ToolLoopResult {
|
|
@@ -1984,6 +2247,8 @@ interface ToolRunContext {
|
|
|
1984
2247
|
* tool a subagent calls). Resolves when allowed, throws ToolDeniedError.
|
|
1985
2248
|
*/
|
|
1986
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;
|
|
1987
2252
|
}
|
|
1988
2253
|
/** Read the run context the agent passes to a tool's execute (undefined outside a run). */
|
|
1989
2254
|
declare const toolRunContextOf: (options: unknown) => ToolRunContext | undefined;
|
|
@@ -2020,5 +2285,65 @@ declare class IndexedDBStore implements ContextStore {
|
|
|
2020
2285
|
listSessions(): Promise<string[]>;
|
|
2021
2286
|
}
|
|
2022
2287
|
|
|
2023
|
-
|
|
2024
|
-
|
|
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 };
|