@dudko.dev/agent-web 0.0.1 → 0.0.3
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 +41 -1
- package/dist/agent-web.js +177 -0
- package/dist/agent-web.js.map +1 -0
- package/dist/index.cjs +186 -95
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +38 -7
- package/dist/index.d.ts +38 -7
- package/dist/index.js +186 -95
- package/dist/index.js.map +1 -1
- package/dist/mcp.cjs +71 -44
- package/dist/mcp.cjs.map +1 -1
- package/dist/mcp.d.cts +5 -1
- package/dist/mcp.d.ts +5 -1
- package/dist/mcp.js +71 -44
- package/dist/mcp.js.map +1 -1
- package/package.json +56 -15
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as ai from 'ai';
|
|
2
|
-
import { LanguageModel, ToolSet, Tool, ModelMessage, generateText, streamText
|
|
2
|
+
import { LanguageModel, ToolSet, Tool, ModelMessage, generateText, streamText } from 'ai';
|
|
3
3
|
import { z, ZodType } from 'zod';
|
|
4
4
|
import { IDBPDatabase } from 'idb';
|
|
5
5
|
|
|
@@ -105,6 +105,11 @@ interface PlannerPromptContext {
|
|
|
105
105
|
state?: string;
|
|
106
106
|
toolCatalog: string;
|
|
107
107
|
mode: ToolCallMode;
|
|
108
|
+
/** Prior session messages (oldest first), for resolving references to earlier turns. */
|
|
109
|
+
history?: {
|
|
110
|
+
role: string;
|
|
111
|
+
content: string;
|
|
112
|
+
}[];
|
|
108
113
|
}
|
|
109
114
|
interface ExecutorPromptContext {
|
|
110
115
|
goal: string;
|
|
@@ -242,7 +247,9 @@ interface BrowserAgentConfig {
|
|
|
242
247
|
clientName?: string;
|
|
243
248
|
/** Host tools the executor may call (an AI SDK ToolSet; use defineTool). */
|
|
244
249
|
tools?: AgentToolSet;
|
|
250
|
+
/** Whitelist: only these tool names from `tools` are mounted (default: all). */
|
|
245
251
|
availableTools?: string[];
|
|
252
|
+
/** Blacklist: these tool names are removed after the whitelist is applied. */
|
|
246
253
|
excludedTools?: string[];
|
|
247
254
|
/** Force native/prompted tool-calling; 'auto' picks per model (default 'auto'). */
|
|
248
255
|
toolMode?: ToolMode;
|
|
@@ -253,7 +260,11 @@ interface BrowserAgentConfig {
|
|
|
253
260
|
prompts?: Partial<Prompts>;
|
|
254
261
|
/** Serialize the host's current world state into prompt context (grounding). */
|
|
255
262
|
describeState?: () => string | Promise<string>;
|
|
256
|
-
/**
|
|
263
|
+
/**
|
|
264
|
+
* Persist the transcript (e.g. new IndexedDBStore()). The last few messages
|
|
265
|
+
* are also read back into the planner prompt, so follow-up goals can refer
|
|
266
|
+
* to earlier turns.
|
|
267
|
+
*/
|
|
257
268
|
memory?: ContextStore;
|
|
258
269
|
sessionId?: string;
|
|
259
270
|
/** Hard cap on executed steps incl. replans (default 8). */
|
|
@@ -486,6 +497,8 @@ interface AgentContext {
|
|
|
486
497
|
signal?: AbortSignal;
|
|
487
498
|
/** Current world state for grounding, or undefined when no describeState is configured. */
|
|
488
499
|
state: () => Promise<string | undefined>;
|
|
500
|
+
/** Session transcript loaded from memory BEFORE this run's goal was appended. */
|
|
501
|
+
history?: StoredMessage[];
|
|
489
502
|
}
|
|
490
503
|
|
|
491
504
|
/**
|
|
@@ -570,8 +583,10 @@ interface ReplanOutcome {
|
|
|
570
583
|
declare const decideReplan: (ctx: AgentContext, goal: string, done: string[], remaining: string[]) => Promise<ReplanOutcome>;
|
|
571
584
|
|
|
572
585
|
/**
|
|
573
|
-
* Write the final natural-language summary of what the run accomplished
|
|
574
|
-
*
|
|
586
|
+
* Write the final natural-language summary of what the run accomplished,
|
|
587
|
+
* streaming it as `final.text-delta` events. Plain text only (parsePlainText
|
|
588
|
+
* strips any stray JSON; deltas are suppressed entirely when the model drifts
|
|
589
|
+
* into JSON, so raw structure never reaches a UI). Falls back to a default
|
|
575
590
|
* sentence if the model returns nothing usable.
|
|
576
591
|
*/
|
|
577
592
|
declare const synthesizeAnswer: (ctx: AgentContext, goal: string, done: string[]) => Promise<{
|
|
@@ -646,6 +661,10 @@ declare const directBrowserOk: (p: ProviderType) => boolean;
|
|
|
646
661
|
* ever being exposed to JavaScript. Not even in-page script can read it out; it
|
|
647
662
|
* can only be used to encrypt / decrypt. That is what makes at-rest storage of
|
|
648
663
|
* the secrets meaningful (see IndexedDBVault's threat model).
|
|
664
|
+
*
|
|
665
|
+
* Concurrent callers share one in-flight promise per DB, and creation is
|
|
666
|
+
* double-checked in a single IDB transaction, so two racing writers can never
|
|
667
|
+
* end up encrypting under different keys.
|
|
649
668
|
*/
|
|
650
669
|
declare const getOrCreateVaultKey: (dbName?: string) => Promise<CryptoKey>;
|
|
651
670
|
interface EncryptedBlob {
|
|
@@ -716,7 +735,10 @@ interface ToolLoopOptions {
|
|
|
716
735
|
messages?: ModelMessage[];
|
|
717
736
|
/** In native mode: the callable tools. In prompted mode: used to dispatch salvaged calls. */
|
|
718
737
|
tools: ToolSet;
|
|
719
|
-
/**
|
|
738
|
+
/**
|
|
739
|
+
* Restrict callable tools to these names (plan-narrowed). Native mode passes
|
|
740
|
+
* them to the SDK's `activeTools`; prompted mode bounds `dispatch` to them.
|
|
741
|
+
*/
|
|
720
742
|
activeTools?: string[];
|
|
721
743
|
/** Native mode: cap on internal tool-calling steps (default 4). */
|
|
722
744
|
maxSteps?: number;
|
|
@@ -747,13 +769,17 @@ declare const normalizeUsage: (u?: {
|
|
|
747
769
|
totalTokens?: number;
|
|
748
770
|
}) => IUsage;
|
|
749
771
|
|
|
750
|
-
type ToolConfig = Parameters<typeof tool>[0];
|
|
751
772
|
/**
|
|
752
773
|
* Define a host tool. Thin wrapper over the AI SDK `tool()`: pass a
|
|
753
774
|
* `description`, an `inputSchema` (a Zod schema or the result of `jsonSchema()`),
|
|
754
775
|
* and an `execute` function. The returned tool works unchanged on the native
|
|
755
776
|
* tool-calling path.
|
|
756
777
|
*
|
|
778
|
+
* Generic over INPUT/OUTPUT so the schema's inferred type flows into
|
|
779
|
+
* `execute(input)` — `Parameters<typeof tool>[0]` must NOT be used here: with
|
|
780
|
+
* an overloaded `tool()` it resolves to the last overload (`Tool<never, never>`),
|
|
781
|
+
* which rejects every real schema and types `execute` as `undefined`.
|
|
782
|
+
*
|
|
757
783
|
* Optionally add `promptHint` — a short parameter hint like
|
|
758
784
|
* "{ text: string, x?: number }" — which the prompted/salvage path shows to
|
|
759
785
|
* weak local models that can't do native function-calling.
|
|
@@ -768,7 +794,7 @@ type ToolConfig = Parameters<typeof tool>[0];
|
|
|
768
794
|
* }),
|
|
769
795
|
* }
|
|
770
796
|
*/
|
|
771
|
-
declare const defineTool: (config:
|
|
797
|
+
declare const defineTool: <INPUT = unknown, OUTPUT = unknown>(config: Tool<INPUT, OUTPUT> & {
|
|
772
798
|
promptHint?: string;
|
|
773
799
|
}) => AgentTool;
|
|
774
800
|
|
|
@@ -795,6 +821,8 @@ declare const dispatch: (action: RawAction, tools: ToolSet, ctx?: DispatchContex
|
|
|
795
821
|
* Decide the tool-calling strategy for a resolved model. An explicit
|
|
796
822
|
* config.toolMode of 'native'/'prompted' always wins; 'auto' (default) inspects
|
|
797
823
|
* the model's provider id — local/on-device runtimes → 'prompted', cloud → 'native'.
|
|
824
|
+
* A string model is a gateway model id ("openai/gpt-4o") — always cloud; the
|
|
825
|
+
* LOCAL_RE must not see it, or model names like "gpt-5-nano" would match `nano`.
|
|
798
826
|
*/
|
|
799
827
|
declare const selectToolMode: (model: LanguageModel, mode?: ToolMode) => "native" | "prompted";
|
|
800
828
|
|
|
@@ -823,6 +851,9 @@ interface CompressOptions {
|
|
|
823
851
|
maxChars?: number;
|
|
824
852
|
/** How many most-recent messages to keep verbatim. */
|
|
825
853
|
keepRecent?: number;
|
|
854
|
+
/** Time-box the summarisation call so it can never hang the caller. */
|
|
855
|
+
timeoutMs?: number;
|
|
856
|
+
abortSignal?: AbortSignal;
|
|
826
857
|
}
|
|
827
858
|
/**
|
|
828
859
|
* When the transcript grows too long, summarise everything except the last
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as ai from 'ai';
|
|
2
|
-
import { LanguageModel, ToolSet, Tool, ModelMessage, generateText, streamText
|
|
2
|
+
import { LanguageModel, ToolSet, Tool, ModelMessage, generateText, streamText } from 'ai';
|
|
3
3
|
import { z, ZodType } from 'zod';
|
|
4
4
|
import { IDBPDatabase } from 'idb';
|
|
5
5
|
|
|
@@ -105,6 +105,11 @@ interface PlannerPromptContext {
|
|
|
105
105
|
state?: string;
|
|
106
106
|
toolCatalog: string;
|
|
107
107
|
mode: ToolCallMode;
|
|
108
|
+
/** Prior session messages (oldest first), for resolving references to earlier turns. */
|
|
109
|
+
history?: {
|
|
110
|
+
role: string;
|
|
111
|
+
content: string;
|
|
112
|
+
}[];
|
|
108
113
|
}
|
|
109
114
|
interface ExecutorPromptContext {
|
|
110
115
|
goal: string;
|
|
@@ -242,7 +247,9 @@ interface BrowserAgentConfig {
|
|
|
242
247
|
clientName?: string;
|
|
243
248
|
/** Host tools the executor may call (an AI SDK ToolSet; use defineTool). */
|
|
244
249
|
tools?: AgentToolSet;
|
|
250
|
+
/** Whitelist: only these tool names from `tools` are mounted (default: all). */
|
|
245
251
|
availableTools?: string[];
|
|
252
|
+
/** Blacklist: these tool names are removed after the whitelist is applied. */
|
|
246
253
|
excludedTools?: string[];
|
|
247
254
|
/** Force native/prompted tool-calling; 'auto' picks per model (default 'auto'). */
|
|
248
255
|
toolMode?: ToolMode;
|
|
@@ -253,7 +260,11 @@ interface BrowserAgentConfig {
|
|
|
253
260
|
prompts?: Partial<Prompts>;
|
|
254
261
|
/** Serialize the host's current world state into prompt context (grounding). */
|
|
255
262
|
describeState?: () => string | Promise<string>;
|
|
256
|
-
/**
|
|
263
|
+
/**
|
|
264
|
+
* Persist the transcript (e.g. new IndexedDBStore()). The last few messages
|
|
265
|
+
* are also read back into the planner prompt, so follow-up goals can refer
|
|
266
|
+
* to earlier turns.
|
|
267
|
+
*/
|
|
257
268
|
memory?: ContextStore;
|
|
258
269
|
sessionId?: string;
|
|
259
270
|
/** Hard cap on executed steps incl. replans (default 8). */
|
|
@@ -486,6 +497,8 @@ interface AgentContext {
|
|
|
486
497
|
signal?: AbortSignal;
|
|
487
498
|
/** Current world state for grounding, or undefined when no describeState is configured. */
|
|
488
499
|
state: () => Promise<string | undefined>;
|
|
500
|
+
/** Session transcript loaded from memory BEFORE this run's goal was appended. */
|
|
501
|
+
history?: StoredMessage[];
|
|
489
502
|
}
|
|
490
503
|
|
|
491
504
|
/**
|
|
@@ -570,8 +583,10 @@ interface ReplanOutcome {
|
|
|
570
583
|
declare const decideReplan: (ctx: AgentContext, goal: string, done: string[], remaining: string[]) => Promise<ReplanOutcome>;
|
|
571
584
|
|
|
572
585
|
/**
|
|
573
|
-
* Write the final natural-language summary of what the run accomplished
|
|
574
|
-
*
|
|
586
|
+
* Write the final natural-language summary of what the run accomplished,
|
|
587
|
+
* streaming it as `final.text-delta` events. Plain text only (parsePlainText
|
|
588
|
+
* strips any stray JSON; deltas are suppressed entirely when the model drifts
|
|
589
|
+
* into JSON, so raw structure never reaches a UI). Falls back to a default
|
|
575
590
|
* sentence if the model returns nothing usable.
|
|
576
591
|
*/
|
|
577
592
|
declare const synthesizeAnswer: (ctx: AgentContext, goal: string, done: string[]) => Promise<{
|
|
@@ -646,6 +661,10 @@ declare const directBrowserOk: (p: ProviderType) => boolean;
|
|
|
646
661
|
* ever being exposed to JavaScript. Not even in-page script can read it out; it
|
|
647
662
|
* can only be used to encrypt / decrypt. That is what makes at-rest storage of
|
|
648
663
|
* the secrets meaningful (see IndexedDBVault's threat model).
|
|
664
|
+
*
|
|
665
|
+
* Concurrent callers share one in-flight promise per DB, and creation is
|
|
666
|
+
* double-checked in a single IDB transaction, so two racing writers can never
|
|
667
|
+
* end up encrypting under different keys.
|
|
649
668
|
*/
|
|
650
669
|
declare const getOrCreateVaultKey: (dbName?: string) => Promise<CryptoKey>;
|
|
651
670
|
interface EncryptedBlob {
|
|
@@ -716,7 +735,10 @@ interface ToolLoopOptions {
|
|
|
716
735
|
messages?: ModelMessage[];
|
|
717
736
|
/** In native mode: the callable tools. In prompted mode: used to dispatch salvaged calls. */
|
|
718
737
|
tools: ToolSet;
|
|
719
|
-
/**
|
|
738
|
+
/**
|
|
739
|
+
* Restrict callable tools to these names (plan-narrowed). Native mode passes
|
|
740
|
+
* them to the SDK's `activeTools`; prompted mode bounds `dispatch` to them.
|
|
741
|
+
*/
|
|
720
742
|
activeTools?: string[];
|
|
721
743
|
/** Native mode: cap on internal tool-calling steps (default 4). */
|
|
722
744
|
maxSteps?: number;
|
|
@@ -747,13 +769,17 @@ declare const normalizeUsage: (u?: {
|
|
|
747
769
|
totalTokens?: number;
|
|
748
770
|
}) => IUsage;
|
|
749
771
|
|
|
750
|
-
type ToolConfig = Parameters<typeof tool>[0];
|
|
751
772
|
/**
|
|
752
773
|
* Define a host tool. Thin wrapper over the AI SDK `tool()`: pass a
|
|
753
774
|
* `description`, an `inputSchema` (a Zod schema or the result of `jsonSchema()`),
|
|
754
775
|
* and an `execute` function. The returned tool works unchanged on the native
|
|
755
776
|
* tool-calling path.
|
|
756
777
|
*
|
|
778
|
+
* Generic over INPUT/OUTPUT so the schema's inferred type flows into
|
|
779
|
+
* `execute(input)` — `Parameters<typeof tool>[0]` must NOT be used here: with
|
|
780
|
+
* an overloaded `tool()` it resolves to the last overload (`Tool<never, never>`),
|
|
781
|
+
* which rejects every real schema and types `execute` as `undefined`.
|
|
782
|
+
*
|
|
757
783
|
* Optionally add `promptHint` — a short parameter hint like
|
|
758
784
|
* "{ text: string, x?: number }" — which the prompted/salvage path shows to
|
|
759
785
|
* weak local models that can't do native function-calling.
|
|
@@ -768,7 +794,7 @@ type ToolConfig = Parameters<typeof tool>[0];
|
|
|
768
794
|
* }),
|
|
769
795
|
* }
|
|
770
796
|
*/
|
|
771
|
-
declare const defineTool: (config:
|
|
797
|
+
declare const defineTool: <INPUT = unknown, OUTPUT = unknown>(config: Tool<INPUT, OUTPUT> & {
|
|
772
798
|
promptHint?: string;
|
|
773
799
|
}) => AgentTool;
|
|
774
800
|
|
|
@@ -795,6 +821,8 @@ declare const dispatch: (action: RawAction, tools: ToolSet, ctx?: DispatchContex
|
|
|
795
821
|
* Decide the tool-calling strategy for a resolved model. An explicit
|
|
796
822
|
* config.toolMode of 'native'/'prompted' always wins; 'auto' (default) inspects
|
|
797
823
|
* the model's provider id — local/on-device runtimes → 'prompted', cloud → 'native'.
|
|
824
|
+
* A string model is a gateway model id ("openai/gpt-4o") — always cloud; the
|
|
825
|
+
* LOCAL_RE must not see it, or model names like "gpt-5-nano" would match `nano`.
|
|
798
826
|
*/
|
|
799
827
|
declare const selectToolMode: (model: LanguageModel, mode?: ToolMode) => "native" | "prompted";
|
|
800
828
|
|
|
@@ -823,6 +851,9 @@ interface CompressOptions {
|
|
|
823
851
|
maxChars?: number;
|
|
824
852
|
/** How many most-recent messages to keep verbatim. */
|
|
825
853
|
keepRecent?: number;
|
|
854
|
+
/** Time-box the summarisation call so it can never hang the caller. */
|
|
855
|
+
timeoutMs?: number;
|
|
856
|
+
abortSignal?: AbortSignal;
|
|
826
857
|
}
|
|
827
858
|
/**
|
|
828
859
|
* When the transcript grows too long, summarise everything except the last
|