@dudko.dev/agent-web 0.0.29 → 0.0.31
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 +1 -1
- package/dist/agent-web.js +107 -94
- package/dist/agent-web.js.map +1 -1
- package/dist/index.cjs +1239 -400
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +293 -75
- package/dist/index.d.ts +293 -75
- package/dist/index.js +1209 -388
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -504,6 +504,10 @@ interface ExecutorPromptContext {
|
|
|
504
504
|
searchMode?: boolean;
|
|
505
505
|
/** What the user said while the run was going (`RunControl.send`), oldest first. */
|
|
506
506
|
updates?: string[];
|
|
507
|
+
/** Set when `config.learning` is on (and not muted): the executor is told to keep a notebook. */
|
|
508
|
+
learning?: {
|
|
509
|
+
fetch: boolean;
|
|
510
|
+
};
|
|
507
511
|
}
|
|
508
512
|
interface ReplannerPromptContext {
|
|
509
513
|
goal: string;
|
|
@@ -564,6 +568,78 @@ declare class MemoryCredentialStore implements CredentialStore {
|
|
|
564
568
|
deleteApiKey(ref: string): Promise<void>;
|
|
565
569
|
}
|
|
566
570
|
|
|
571
|
+
/**
|
|
572
|
+
* A small virtual file system for the browser — the agent's (and the user's)
|
|
573
|
+
* workspace: attachments the user drops in, reports the agent writes, images
|
|
574
|
+
* pasted into the chat. Persistent in IndexedDB by default, in-memory on
|
|
575
|
+
* request (tests, private mode). Paths are POSIX-like and always absolute
|
|
576
|
+
* ("/notes/todo.md"); there are no real directories — a "directory" is a path
|
|
577
|
+
* prefix.
|
|
578
|
+
*/
|
|
579
|
+
interface VirtualFile {
|
|
580
|
+
path: string;
|
|
581
|
+
/** Text, or base64 for binary content (see `encoding`). */
|
|
582
|
+
content: string;
|
|
583
|
+
encoding: 'utf8' | 'base64';
|
|
584
|
+
mimeType: string;
|
|
585
|
+
/** Size of the decoded content in bytes. */
|
|
586
|
+
size: number;
|
|
587
|
+
updatedAt: number;
|
|
588
|
+
}
|
|
589
|
+
/** A listing entry (no content). */
|
|
590
|
+
type VirtualFileInfo = Omit<VirtualFile, 'content'>;
|
|
591
|
+
interface VirtualFileSystemOptions {
|
|
592
|
+
/** Keep files in memory only (default false: IndexedDB). */
|
|
593
|
+
memory?: boolean;
|
|
594
|
+
/** IndexedDB database name, forwarded to the shared owner (default 'agent-web'). */
|
|
595
|
+
dbName?: string;
|
|
596
|
+
/** Isolates several file systems in one database (default 'default'). */
|
|
597
|
+
namespace?: string;
|
|
598
|
+
/** Refuse a single file larger than this many bytes (default 10 MB). */
|
|
599
|
+
maxFileBytes?: number;
|
|
600
|
+
}
|
|
601
|
+
type VfsListener = (change: {
|
|
602
|
+
type: 'write' | 'delete';
|
|
603
|
+
path: string;
|
|
604
|
+
}) => void;
|
|
605
|
+
/** A best-effort MIME type from a file name. */
|
|
606
|
+
declare const mimeFromPath: (path: string) => string;
|
|
607
|
+
/** True for MIME types the agent can read as text. */
|
|
608
|
+
declare const isTextMime: (mime: string) => boolean;
|
|
609
|
+
/**
|
|
610
|
+
* Normalise a path: absolute, forward slashes, no "." / ".." / empty segments.
|
|
611
|
+
* Throws on a path that escapes the root.
|
|
612
|
+
*/
|
|
613
|
+
declare const normalizePath: (input: string) => string;
|
|
614
|
+
/** Base64 of bytes, chunked so a large file can't blow the call stack. */
|
|
615
|
+
declare const bytesToBase64: (bytes: Uint8Array) => string;
|
|
616
|
+
declare class VirtualFileSystem {
|
|
617
|
+
private readonly memory?;
|
|
618
|
+
private readonly dbName?;
|
|
619
|
+
private readonly ns;
|
|
620
|
+
private readonly maxFileBytes;
|
|
621
|
+
private readonly listeners;
|
|
622
|
+
constructor(opts?: VirtualFileSystemOptions);
|
|
623
|
+
private key;
|
|
624
|
+
/** Subscribe to writes and deletes (e.g. to refresh a file list). Returns an unsubscribe. */
|
|
625
|
+
onChange(listener: VfsListener): () => void;
|
|
626
|
+
private notify;
|
|
627
|
+
write(path: string, content: string | Uint8Array, opts?: {
|
|
628
|
+
mimeType?: string;
|
|
629
|
+
encoding?: VirtualFile['encoding'];
|
|
630
|
+
}): Promise<VirtualFileInfo>;
|
|
631
|
+
/** Store a data URL ("data:image/png;base64,…") as a file. */
|
|
632
|
+
writeDataUrl(path: string, dataUrl: string): Promise<VirtualFileInfo>;
|
|
633
|
+
read(path: string): Promise<VirtualFile | undefined>;
|
|
634
|
+
/** The file as a data URL (for <img src>, downloads). */
|
|
635
|
+
readDataUrl(path: string): Promise<string | undefined>;
|
|
636
|
+
delete(path: string): Promise<boolean>;
|
|
637
|
+
/** Files under a prefix ("/" = all), sorted by path. */
|
|
638
|
+
list(prefix?: string): Promise<VirtualFileInfo[]>;
|
|
639
|
+
/** Remove every file (of this namespace). */
|
|
640
|
+
clear(): Promise<void>;
|
|
641
|
+
}
|
|
642
|
+
|
|
567
643
|
/**
|
|
568
644
|
* Skills — reusable instruction bundles in the agentskills.io shape
|
|
569
645
|
* (`SKILL.md` with `name`/`description` frontmatter, a markdown body, optional
|
|
@@ -583,6 +659,21 @@ interface Skill {
|
|
|
583
659
|
path: string;
|
|
584
660
|
content: string;
|
|
585
661
|
}[];
|
|
662
|
+
/** Set on a skill the AGENT wrote (`config.learning`); absent on the host's own. */
|
|
663
|
+
origin?: SkillOrigin;
|
|
664
|
+
}
|
|
665
|
+
/** Where a learned skill came from. */
|
|
666
|
+
interface SkillOrigin {
|
|
667
|
+
kind: 'learned';
|
|
668
|
+
/** Epoch ms of the last write. */
|
|
669
|
+
at: number;
|
|
670
|
+
/** 1 for a new lesson, +1 each time the agent rewrites it. */
|
|
671
|
+
revision: number;
|
|
672
|
+
runId?: string;
|
|
673
|
+
/** What the model said it consulted (URLs without query strings, doc names). */
|
|
674
|
+
sources?: string[];
|
|
675
|
+
/** Pages web_fetch read during the run that wrote it - recorded by the harness, not the model. */
|
|
676
|
+
fetched?: string[];
|
|
586
677
|
}
|
|
587
678
|
/** Names of the built-in skill tools (reserved when skills are configured). */
|
|
588
679
|
declare const SKILL_TOOL_NAMES: readonly ["load_skill", "read_skill_file"];
|
|
@@ -603,6 +694,11 @@ interface LoadSkillOptions {
|
|
|
603
694
|
}
|
|
604
695
|
/** Fetch a SKILL.md (and optionally its bundled files) over HTTP. */
|
|
605
696
|
declare const loadSkillFromUrl: (url: string, opts?: LoadSkillOptions) => Promise<Skill>;
|
|
697
|
+
/**
|
|
698
|
+
* How a learned skill is introduced wherever its text is shown to the model: as a note of the
|
|
699
|
+
* agent's own, subordinate to the user - never as an instruction.
|
|
700
|
+
*/
|
|
701
|
+
declare const learnedPreamble: (skill: Skill) => string;
|
|
606
702
|
/** "- name: description" lines for the prompts. */
|
|
607
703
|
declare const renderSkillIndex: (skills: Skill[]) => string;
|
|
608
704
|
/** The full instructions of the active skills, within a total character budget. */
|
|
@@ -613,6 +709,139 @@ declare const renderActiveSkills: (skills: Skill[]) => string;
|
|
|
613
709
|
*/
|
|
614
710
|
declare const createSkillTools: (skills: Skill[], onLoad?: (skill: Skill) => void) => ToolSet;
|
|
615
711
|
|
|
712
|
+
declare const SAVE_SKILL_TOOL = "save_skill";
|
|
713
|
+
declare const FORGET_SKILL_TOOL = "forget_skill";
|
|
714
|
+
/** Where learned skills are kept. {@link MemorySkillStore} and {@link VfsSkillStore} are provided. */
|
|
715
|
+
interface SkillStore {
|
|
716
|
+
list(): Skill[] | Promise<Skill[]>;
|
|
717
|
+
save(skill: Skill): void | Promise<void>;
|
|
718
|
+
/** false when there was nothing to remove. */
|
|
719
|
+
remove(name: string): boolean | Promise<boolean>;
|
|
720
|
+
}
|
|
721
|
+
interface LearningConfig {
|
|
722
|
+
/** Where lessons are kept. Default: in memory, for the life of the agent (the open session). */
|
|
723
|
+
store?: SkillStore;
|
|
724
|
+
/** At most this many lessons (default 50). */
|
|
725
|
+
maxSkills?: number;
|
|
726
|
+
/** At most this many characters of instructions per lesson (default 6000). */
|
|
727
|
+
maxSkillChars?: number;
|
|
728
|
+
/** false keeps the tools but drops the executor guidance to write lessons down (default true). */
|
|
729
|
+
nudge?: boolean;
|
|
730
|
+
}
|
|
731
|
+
/** What a credential looks like, or undefined. */
|
|
732
|
+
declare const findSecret: (text: string) => string | undefined;
|
|
733
|
+
/** "My Trick_1" -> "my-trick-1"; undefined when nothing usable is left. */
|
|
734
|
+
declare const normalizeSkillName: (raw: string) => string | undefined;
|
|
735
|
+
/** Lives as long as the agent: the "open session". */
|
|
736
|
+
declare class MemorySkillStore implements SkillStore {
|
|
737
|
+
private readonly skills;
|
|
738
|
+
list(): Skill[];
|
|
739
|
+
save(skill: Skill): void;
|
|
740
|
+
remove(name: string): boolean;
|
|
741
|
+
}
|
|
742
|
+
/**
|
|
743
|
+
* `<dir>/<name>/SKILL.md` in the agent's virtual file system (IndexedDB, or memory): the user can
|
|
744
|
+
* see and edit lessons in the files panel like any file. A sidecar `.origin.json` says where each
|
|
745
|
+
* came from. Default dir `/skills`.
|
|
746
|
+
*/
|
|
747
|
+
declare class VfsSkillStore implements SkillStore {
|
|
748
|
+
private readonly vfs;
|
|
749
|
+
private readonly dir;
|
|
750
|
+
constructor(vfs: VirtualFileSystem, dir?: string);
|
|
751
|
+
list(): Promise<Skill[]>;
|
|
752
|
+
save(skill: Skill): Promise<void>;
|
|
753
|
+
remove(name: string): Promise<boolean>;
|
|
754
|
+
}
|
|
755
|
+
interface Learning {
|
|
756
|
+
/** The tools the model learns with (normal tools: gated, counted). */
|
|
757
|
+
tools: AgentToolSet;
|
|
758
|
+
/** The agent's own skills (not the host's). */
|
|
759
|
+
learned: () => Skill[];
|
|
760
|
+
/** Forget one of them. false when there is no such learned skill. */
|
|
761
|
+
forget: (name: string, emit?: (event: {
|
|
762
|
+
type: 'skill.forgotten';
|
|
763
|
+
name: string;
|
|
764
|
+
}) => void) => Promise<boolean>;
|
|
765
|
+
}
|
|
766
|
+
interface SaveSkillInput {
|
|
767
|
+
name: string;
|
|
768
|
+
description: string;
|
|
769
|
+
instructions: string;
|
|
770
|
+
sources?: string[];
|
|
771
|
+
}
|
|
772
|
+
/**
|
|
773
|
+
* Wires learning to the agent's LIVE skill list (`skills` is mutated in place, so every prompt
|
|
774
|
+
* that renders the index sees a new lesson at once).
|
|
775
|
+
*/
|
|
776
|
+
declare const createLearning: (cfg: LearningConfig, skills: Skill[], warn: (message: string) => void) => Promise<Learning>;
|
|
777
|
+
|
|
778
|
+
type EgressErrorCode = 'disabled' | 'bad-url' | 'bad-protocol' | 'bad-port' | 'bad-method' | 'credentials-in-url' | 'denied-host' | 'not-allowed-host' | 'denied-address' | 'bad-redirect' | 'network' | 'too-large' | 'timeout';
|
|
779
|
+
declare class EgressError extends Error {
|
|
780
|
+
readonly code: EgressErrorCode;
|
|
781
|
+
constructor(code: EgressErrorCode, message: string);
|
|
782
|
+
toJSON(): string;
|
|
783
|
+
}
|
|
784
|
+
interface IEgressPolicy {
|
|
785
|
+
/** Hosts the agent may reach; empty/absent = any host that passes the other checks. "example.com" (that host only), "*.example.com" (its subdomains, not the apex), an IP or a CIDR for IP-literal URLs. */
|
|
786
|
+
allow?: string[];
|
|
787
|
+
/** Always refused; wins over `allow`. Same patterns. */
|
|
788
|
+
deny?: string[];
|
|
789
|
+
/** Allow IP literals and internal-looking names in private ranges (default false). Metadata endpoints stay refused. */
|
|
790
|
+
allowPrivateNetwork?: boolean;
|
|
791
|
+
/** Default ['https']. */
|
|
792
|
+
protocols?: ('https' | 'http')[];
|
|
793
|
+
/** Default [443] (and 80 once 'http' is allowed). */
|
|
794
|
+
ports?: number[];
|
|
795
|
+
/** Default ['GET']. */
|
|
796
|
+
methods?: string[];
|
|
797
|
+
/** Follow redirects, judging only the final URL after the fact (default false: a redirect fails the request). */
|
|
798
|
+
followRedirects?: boolean;
|
|
799
|
+
/** Cap on the body, in bytes. Default 2_000_000. */
|
|
800
|
+
maxResponseBytes?: number;
|
|
801
|
+
/** Whole request, in ms. Default 15_000. */
|
|
802
|
+
timeoutMs?: number;
|
|
803
|
+
/** The fetch to use (default `globalThis.fetch`). Point it at a gateway to get server-side protection. */
|
|
804
|
+
fetch?: typeof fetch;
|
|
805
|
+
}
|
|
806
|
+
interface IResolvedEgressPolicy {
|
|
807
|
+
allow: string[];
|
|
808
|
+
deny: string[];
|
|
809
|
+
allowPrivateNetwork: boolean;
|
|
810
|
+
protocols: ('https' | 'http')[];
|
|
811
|
+
ports: number[];
|
|
812
|
+
methods: string[];
|
|
813
|
+
followRedirects: boolean;
|
|
814
|
+
maxResponseBytes: number;
|
|
815
|
+
timeoutMs: number;
|
|
816
|
+
fetch: typeof fetch;
|
|
817
|
+
}
|
|
818
|
+
declare const resolveEgressPolicy: (policy?: IEgressPolicy) => IResolvedEgressPolicy;
|
|
819
|
+
type AddressClass = 'public' | 'private' | 'never';
|
|
820
|
+
declare const classifyAddress: (address: string) => AddressClass;
|
|
821
|
+
declare const hostMatches: (host: string, pattern: string) => boolean;
|
|
822
|
+
declare const checkEgressUrl: (url: URL, policy: IResolvedEgressPolicy, method?: string) => void;
|
|
823
|
+
declare const htmlToText: (html: string) => {
|
|
824
|
+
title?: string;
|
|
825
|
+
text: string;
|
|
826
|
+
};
|
|
827
|
+
type GuardedFetch = (input: string | URL, init?: RequestInit) => Promise<Response>;
|
|
828
|
+
/** A `fetch` bound to a policy. */
|
|
829
|
+
declare const createGuardedFetch: (policy?: IEgressPolicy) => GuardedFetch;
|
|
830
|
+
declare const WEB_FETCH_TOOL = "web_fetch";
|
|
831
|
+
interface IWebFetchOptions {
|
|
832
|
+
policy?: IEgressPolicy;
|
|
833
|
+
fetch?: GuardedFetch;
|
|
834
|
+
}
|
|
835
|
+
/**
|
|
836
|
+
* `web_fetch({ url })`: read one page or API response. Every request goes through the egress
|
|
837
|
+
* policy; a refusal comes back as a tool error that says why. Read-only for the consent gate
|
|
838
|
+
* only when the policy names the hosts it may reach - an open GET is a channel to leak data
|
|
839
|
+
* through the URL, so it asks like a write.
|
|
840
|
+
*/
|
|
841
|
+
declare const createWebFetchTool: (options?: IWebFetchOptions) => AgentTool;
|
|
842
|
+
/** The tools `config.egress` turns on (none when it is off). */
|
|
843
|
+
declare const createEgressTools: (egress: boolean | IEgressPolicy | undefined) => AgentToolSet | undefined;
|
|
844
|
+
|
|
616
845
|
/**
|
|
617
846
|
* Tool consent. Every tool call passes a gate that decides allow / ask / deny:
|
|
618
847
|
*
|
|
@@ -718,6 +947,14 @@ interface BrowserAgentConfig {
|
|
|
718
947
|
credentials?: CredentialStore;
|
|
719
948
|
/** Propagated to the openai-compatible provider name and the MCP client. */
|
|
720
949
|
clientName?: string;
|
|
950
|
+
/**
|
|
951
|
+
* Requests the MODEL may make (the `web_fetch` tool). Off unless set: with it off there is no
|
|
952
|
+
* way to fetch. `true` = any public host over https; an object narrows or widens that (allow /
|
|
953
|
+
* deny lists, ...) - see `IEgressPolicy`. A browser cannot pin DNS: prefer an `allow` list, or a
|
|
954
|
+
* `fetch` that goes through a server-side safe fetch. Not the provider's own calls, MCP servers
|
|
955
|
+
* or tools you pass yourself - those are your configuration, not the model's.
|
|
956
|
+
*/
|
|
957
|
+
egress?: boolean | IEgressPolicy;
|
|
721
958
|
/** Host tools the executor may call (an AI SDK ToolSet; use defineTool). */
|
|
722
959
|
tools?: AgentToolSet;
|
|
723
960
|
/** Whitelist: only these tool names from `tools` are mounted (default: all). */
|
|
@@ -734,6 +971,12 @@ interface BrowserAgentConfig {
|
|
|
734
971
|
toolApproval?: ToolApprovalConfig;
|
|
735
972
|
/** Reusable instruction bundles (SKILL.md) the planner/executor can pull in. */
|
|
736
973
|
skills?: Skill[];
|
|
974
|
+
/**
|
|
975
|
+
* Let the agent write down lessons as skills (`save_skill` / `forget_skill`) for the rest of the
|
|
976
|
+
* session: `true` keeps them in memory; `{ store: new VfsSkillStore(vfs) }` keeps them in the
|
|
977
|
+
* file system across sessions. Off by default. Knowledge only - see `learning.ts`.
|
|
978
|
+
*/
|
|
979
|
+
learning?: boolean | LearningConfig;
|
|
737
980
|
/** Prepended to every phase's system prompt. */
|
|
738
981
|
systemPrompt?: string;
|
|
739
982
|
/** Override any phase prompt builder. */
|
|
@@ -955,6 +1198,22 @@ type AgentEvent =
|
|
|
955
1198
|
name: string;
|
|
956
1199
|
by: 'plan' | 'tool';
|
|
957
1200
|
}
|
|
1201
|
+
/** The agent wrote a lesson down as a skill (`config.learning`). */
|
|
1202
|
+
| {
|
|
1203
|
+
type: 'skill.learned';
|
|
1204
|
+
name: string;
|
|
1205
|
+
description: string;
|
|
1206
|
+
/** true when it rewrote an earlier lesson of the same name. */
|
|
1207
|
+
update: boolean;
|
|
1208
|
+
chars: number;
|
|
1209
|
+
/** What it consulted: the sources it named, then the pages web_fetch read in the run. */
|
|
1210
|
+
sources: string[];
|
|
1211
|
+
}
|
|
1212
|
+
/** A lesson was deleted (by the agent's forget_skill, or the host's forgetSkill). */
|
|
1213
|
+
| {
|
|
1214
|
+
type: 'skill.forgotten';
|
|
1215
|
+
name: string;
|
|
1216
|
+
}
|
|
958
1217
|
/** find_tools activated more tools (large-catalogue search mode). */
|
|
959
1218
|
| {
|
|
960
1219
|
type: 'tools.discovered';
|
|
@@ -1010,7 +1269,17 @@ type AgentEvent =
|
|
|
1010
1269
|
stopped?: boolean;
|
|
1011
1270
|
}
|
|
1012
1271
|
/** A message sent with `RunControl.send` is waiting for the next boundary. */
|
|
1272
|
+
/**
|
|
1273
|
+
* A request of the `web_fetch` tool, allowed or refused by the egress policy. `url` is origin and
|
|
1274
|
+
* path only (a query string can carry a secret).
|
|
1275
|
+
*/
|
|
1013
1276
|
| {
|
|
1277
|
+
type: 'egress.request';
|
|
1278
|
+
url: string;
|
|
1279
|
+
allowed: boolean;
|
|
1280
|
+
status?: number;
|
|
1281
|
+
reason?: string;
|
|
1282
|
+
} | {
|
|
1014
1283
|
type: 'message.queued';
|
|
1015
1284
|
id: string;
|
|
1016
1285
|
text: string;
|
|
@@ -1228,6 +1497,15 @@ interface AgentContext {
|
|
|
1228
1497
|
skills?: Skill[];
|
|
1229
1498
|
/** Skills whose instructions are in play for this run. */
|
|
1230
1499
|
activeSkills?: () => Skill[];
|
|
1500
|
+
/**
|
|
1501
|
+
* Set when `config.learning` is on: whether the executor is told to write lessons down, and the
|
|
1502
|
+
* notebook's tool names - callable in every step whatever the strategy narrows to (they are
|
|
1503
|
+
* still wrapped and gated like any other tool).
|
|
1504
|
+
*/
|
|
1505
|
+
learning?: {
|
|
1506
|
+
nudge: boolean;
|
|
1507
|
+
tools: string[];
|
|
1508
|
+
};
|
|
1231
1509
|
/** Tools find_tools activated during this run (search mode). */
|
|
1232
1510
|
discovered?: () => string[];
|
|
1233
1511
|
/** Built-in tool names (find_tools, skill tools) — always callable. */
|
|
@@ -1337,11 +1615,19 @@ interface Agent {
|
|
|
1337
1615
|
* more than the model's own (read from local WebLLM models).
|
|
1338
1616
|
*/
|
|
1339
1617
|
readonly contextWindowTokens: number;
|
|
1340
|
-
/**
|
|
1618
|
+
/** Skills (name + description) - the host's, and the agent's own lessons, marked `learned`. Live. */
|
|
1341
1619
|
readonly skills: {
|
|
1342
1620
|
name: string;
|
|
1343
1621
|
description: string;
|
|
1622
|
+
learned?: true;
|
|
1344
1623
|
}[];
|
|
1624
|
+
/** The agent's own lessons (`config.learning`), with where each came from. Empty without it. */
|
|
1625
|
+
listLearnedSkills(): Skill[];
|
|
1626
|
+
/**
|
|
1627
|
+
* Delete one of the agent's own lessons (a stale one). false when there is no such lesson.
|
|
1628
|
+
* Pass `onEvent` to receive the `skill.forgotten` event.
|
|
1629
|
+
*/
|
|
1630
|
+
forgetSkill(name: string, onEvent?: (event: AgentEvent) => void): Promise<boolean>;
|
|
1345
1631
|
/**
|
|
1346
1632
|
* What the executor model can take, per attachment kind: true / false, or
|
|
1347
1633
|
* undefined when unknown (the run tries, and a provider refusal becomes a
|
|
@@ -1697,78 +1983,6 @@ interface ServeSubagentOptions {
|
|
|
1697
1983
|
*/
|
|
1698
1984
|
declare const serveSubagentWorker: (opts?: ServeSubagentOptions) => void;
|
|
1699
1985
|
|
|
1700
|
-
/**
|
|
1701
|
-
* A small virtual file system for the browser — the agent's (and the user's)
|
|
1702
|
-
* workspace: attachments the user drops in, reports the agent writes, images
|
|
1703
|
-
* pasted into the chat. Persistent in IndexedDB by default, in-memory on
|
|
1704
|
-
* request (tests, private mode). Paths are POSIX-like and always absolute
|
|
1705
|
-
* ("/notes/todo.md"); there are no real directories — a "directory" is a path
|
|
1706
|
-
* prefix.
|
|
1707
|
-
*/
|
|
1708
|
-
interface VirtualFile {
|
|
1709
|
-
path: string;
|
|
1710
|
-
/** Text, or base64 for binary content (see `encoding`). */
|
|
1711
|
-
content: string;
|
|
1712
|
-
encoding: 'utf8' | 'base64';
|
|
1713
|
-
mimeType: string;
|
|
1714
|
-
/** Size of the decoded content in bytes. */
|
|
1715
|
-
size: number;
|
|
1716
|
-
updatedAt: number;
|
|
1717
|
-
}
|
|
1718
|
-
/** A listing entry (no content). */
|
|
1719
|
-
type VirtualFileInfo = Omit<VirtualFile, 'content'>;
|
|
1720
|
-
interface VirtualFileSystemOptions {
|
|
1721
|
-
/** Keep files in memory only (default false: IndexedDB). */
|
|
1722
|
-
memory?: boolean;
|
|
1723
|
-
/** IndexedDB database name, forwarded to the shared owner (default 'agent-web'). */
|
|
1724
|
-
dbName?: string;
|
|
1725
|
-
/** Isolates several file systems in one database (default 'default'). */
|
|
1726
|
-
namespace?: string;
|
|
1727
|
-
/** Refuse a single file larger than this many bytes (default 10 MB). */
|
|
1728
|
-
maxFileBytes?: number;
|
|
1729
|
-
}
|
|
1730
|
-
type VfsListener = (change: {
|
|
1731
|
-
type: 'write' | 'delete';
|
|
1732
|
-
path: string;
|
|
1733
|
-
}) => void;
|
|
1734
|
-
/** A best-effort MIME type from a file name. */
|
|
1735
|
-
declare const mimeFromPath: (path: string) => string;
|
|
1736
|
-
/** True for MIME types the agent can read as text. */
|
|
1737
|
-
declare const isTextMime: (mime: string) => boolean;
|
|
1738
|
-
/**
|
|
1739
|
-
* Normalise a path: absolute, forward slashes, no "." / ".." / empty segments.
|
|
1740
|
-
* Throws on a path that escapes the root.
|
|
1741
|
-
*/
|
|
1742
|
-
declare const normalizePath: (input: string) => string;
|
|
1743
|
-
/** Base64 of bytes, chunked so a large file can't blow the call stack. */
|
|
1744
|
-
declare const bytesToBase64: (bytes: Uint8Array) => string;
|
|
1745
|
-
declare class VirtualFileSystem {
|
|
1746
|
-
private readonly memory?;
|
|
1747
|
-
private readonly dbName?;
|
|
1748
|
-
private readonly ns;
|
|
1749
|
-
private readonly maxFileBytes;
|
|
1750
|
-
private readonly listeners;
|
|
1751
|
-
constructor(opts?: VirtualFileSystemOptions);
|
|
1752
|
-
private key;
|
|
1753
|
-
/** Subscribe to writes and deletes (e.g. to refresh a file list). Returns an unsubscribe. */
|
|
1754
|
-
onChange(listener: VfsListener): () => void;
|
|
1755
|
-
private notify;
|
|
1756
|
-
write(path: string, content: string | Uint8Array, opts?: {
|
|
1757
|
-
mimeType?: string;
|
|
1758
|
-
encoding?: VirtualFile['encoding'];
|
|
1759
|
-
}): Promise<VirtualFileInfo>;
|
|
1760
|
-
/** Store a data URL ("data:image/png;base64,…") as a file. */
|
|
1761
|
-
writeDataUrl(path: string, dataUrl: string): Promise<VirtualFileInfo>;
|
|
1762
|
-
read(path: string): Promise<VirtualFile | undefined>;
|
|
1763
|
-
/** The file as a data URL (for <img src>, downloads). */
|
|
1764
|
-
readDataUrl(path: string): Promise<string | undefined>;
|
|
1765
|
-
delete(path: string): Promise<boolean>;
|
|
1766
|
-
/** Files under a prefix ("/" = all), sorted by path. */
|
|
1767
|
-
list(prefix?: string): Promise<VirtualFileInfo[]>;
|
|
1768
|
-
/** Remove every file (of this namespace). */
|
|
1769
|
-
clear(): Promise<void>;
|
|
1770
|
-
}
|
|
1771
|
-
|
|
1772
1986
|
interface FileToolsOptions {
|
|
1773
1987
|
/** Tool-name prefix (default 'fs_' → fs_list, fs_read, fs_write, fs_delete). */
|
|
1774
1988
|
prefix?: string;
|
|
@@ -2249,6 +2463,10 @@ interface ToolRunContext {
|
|
|
2249
2463
|
approve: (toolName: string, input: unknown, readOnly: boolean) => Promise<void>;
|
|
2250
2464
|
/** The run's control, when the host passed one: subagents register here so they can be listed and stopped. */
|
|
2251
2465
|
control?: RunControlPort;
|
|
2466
|
+
/** The run's id (for provenance). */
|
|
2467
|
+
runId?: string;
|
|
2468
|
+
/** Pages web_fetch read in this run (origin + path), kept as provenance for any lesson the run writes. */
|
|
2469
|
+
fetched?: string[];
|
|
2252
2470
|
}
|
|
2253
2471
|
/** Read the run context the agent passes to a tool's execute (undefined outside a run). */
|
|
2254
2472
|
declare const toolRunContextOf: (options: unknown) => ToolRunContext | undefined;
|
|
@@ -2345,5 +2563,5 @@ declare class IndexedDBRunStore implements RunPersistence {
|
|
|
2345
2563
|
clear(): Promise<void>;
|
|
2346
2564
|
}
|
|
2347
2565
|
|
|
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 };
|
|
2566
|
+
export { AgentTool, AgentToolSet, AttachmentsNotSupportedError, ContextWindowExceededError, EgressError, FILES_STORE, FIND_TOOLS_NAME, FORGET_SKILL_TOOL, ImagesNotSupportedError, IndexedDBRunStore, IndexedDBStore, KEYS_STORE, MemoryCredentialStore, MemoryRunStore, MemorySkillStore, MemoryStore, PlanSchema, PlanStepSchema, RUNS_STORE, ReplanSchema, SAVE_SKILL_TOOL, SECRETS_STORE, SESSIONS_STORE, SKILL_TOOL_NAMES, TOOL_APPROVAL_MODES, TOOL_SEARCH_WINDOW_SHARE, ToolBudgetError, ToolDeniedError, VaultCredentialStore, VaultOptions, VfsSkillStore, VirtualFileSystem, WEBLLM_DEFAULT_CONTEXT_WINDOW, WEB_FETCH_TOOL, attachmentKind, buildModelFromStage, bytesToBase64, checkEgressUrl, checkLimits, classifyAddress, compactHistory, compactSteps, compressHistory, contextOverflowOf, contextWindowOf, createAgent, createEgressTools, createFileTools, createFindToolsTool, createGuardedFetch, createLearning, createLogger, createPlan, createRunControl, createSkillTools, createSubagentTool, createToolResultClearer, createWebFetchTool, createWebLLMModel, decideReplan, decideToolPermission, decryptJSON, defaultPrompts, defineSkill, defineTool, directBrowserOk, dispatch, encryptJSON, messageTokens as estimateMessagesTokens, estimateTokens, executeStep, findSecret, fitCompactionToWindow, generate, generateStructured, getOrCreateVaultKey, hostMatches, htmlToText, isAttachmentRefusal, isDirectModel, isImageRefusal, isProviderSpec, isReadOnlyTool, isTextMime, isWebGPUAvailable, learnedPreamble, limitModelOutput, loadSkillFromUrl, looksLikeJson, markReadOnly, matchRule, mediaTypeOf, mergeProviderOptions, mimeFromPath, normalizePath, normalizeSkillName, normalizeSteps, normalizeUsage, openAgentWebDB, parseExecutorResponse, parsePlainText, parsePlannerResponse, parseReplannerResponse, parseSkillMarkdown, preloadWebLLMModel, renderActiveSkills, renderCatalog, renderSearchCatalog, renderSkillIndex, replanWanted, resolveCaching, resolveCompaction, resolveConfig, resolveEgressPolicy, 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 };
|
|
2567
|
+
export type { Agent, AgentContext, AgentEvent, AgentEventHandler, AgentLogger, AgentLoggerSink, AgentWebDBOptions, AttachmentKind, BrowserAgentConfig, ClearedInfo, CompactOptions, CompactResult, CompactionConfig, CompressOptions, ContextStore, CredentialStore, EffectiveToolStrategy, EgressErrorCode, EncryptedBlob, ExecutorPromptContext, ExecutorResult, FileToolsOptions, GenerateOptions, GuardedFetch, IEgressPolicy, IPlan, IPlanStep, IResolvedEgressPolicy, IStepResult, IToolCall, IUsage, IWebFetchOptions, IndexedDBRunStoreOptions, IndexedDBStoreOptions, Learning, LearningConfig, 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, SaveSkillInput, SearchToolsOptions, ServeSubagentOptions, Skill, SkillOrigin, SkillStore, 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 };
|