@dudko.dev/agent-web 0.0.20 → 0.0.22
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 +14 -8
- package/dist/agent-web.js +93 -91
- package/dist/agent-web.js.map +1 -1
- package/dist/chunk-YA6TQQ3Q.js +425 -0
- package/dist/chunk-YA6TQQ3Q.js.map +1 -0
- package/dist/index.cjs +511 -274
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +105 -9
- package/dist/index.d.ts +105 -9
- package/dist/index.js +83 -248
- package/dist/index.js.map +1 -1
- package/dist/{webllm-XUBUNKFN.js → webllm-QTJ3EGTG.js} +2 -2
- package/package.json +1 -1
- package/dist/chunk-IT65EW77.js +0 -38
- package/dist/chunk-IT65EW77.js.map +0 -1
- /package/dist/{webllm-XUBUNKFN.js.map → webllm-QTJ3EGTG.js.map} +0 -0
package/dist/index.d.cts
CHANGED
|
@@ -53,6 +53,9 @@ interface IStepResult {
|
|
|
53
53
|
* so a `budgetTokens` is mapped to the provider-specific options of the two
|
|
54
54
|
* providers that take one (Anthropic, Google); provider options win over the
|
|
55
55
|
* portable level by the SDK's precedence rules.
|
|
56
|
+
*
|
|
57
|
+
* WebLLM ignores the portable level: its thinking models (Qwen3) are switched
|
|
58
|
+
* by `extra_body.enable_thinking`, so every setting carries that too.
|
|
56
59
|
*/
|
|
57
60
|
type ThinkingLevel = 'provider-default' | 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh';
|
|
58
61
|
interface ThinkingConfig {
|
|
@@ -1095,8 +1098,16 @@ interface Agent {
|
|
|
1095
1098
|
readonly toolApprovalMode: ToolApprovalMode;
|
|
1096
1099
|
/** The tool catalogue (host + MCP tools after filtering). */
|
|
1097
1100
|
listTools(): ToolCatalogEntry[];
|
|
1098
|
-
/**
|
|
1101
|
+
/**
|
|
1102
|
+
* The effective tool selection ('auto' resolved by the catalogue's size: its
|
|
1103
|
+
* count, or its definitions' share of the context window).
|
|
1104
|
+
*/
|
|
1099
1105
|
readonly toolStrategy: EffectiveToolStrategy;
|
|
1106
|
+
/**
|
|
1107
|
+
* The context window the agent fits its runs into: the configured one, never
|
|
1108
|
+
* more than the model's own (read from local WebLLM models).
|
|
1109
|
+
*/
|
|
1110
|
+
readonly contextWindowTokens: number;
|
|
1100
1111
|
/** Configured skills (name + description). */
|
|
1101
1112
|
readonly skills: {
|
|
1102
1113
|
name: string;
|
|
@@ -1561,6 +1572,15 @@ interface WebLLMModelOptions {
|
|
|
1561
1572
|
* Set to `false` to keep the lazy behavior.
|
|
1562
1573
|
*/
|
|
1563
1574
|
preload?: boolean;
|
|
1575
|
+
/**
|
|
1576
|
+
* The context window to load the model with, in tokens. WebLLM loads its
|
|
1577
|
+
* prebuilt models with 4096 (to save VRAM), far below what Qwen3 or Llama
|
|
1578
|
+
* 3.x were trained on; a larger window costs KV-cache memory, not a new
|
|
1579
|
+
* download. Applied through `engineConfig.appConfig` (WebLLM's prebuilt
|
|
1580
|
+
* config with this model's `context_window_size` overridden) unless you pass
|
|
1581
|
+
* an `appConfig` of your own; see `withWebLLMContextWindow`.
|
|
1582
|
+
*/
|
|
1583
|
+
contextWindowTokens?: number;
|
|
1564
1584
|
/** Any other @browser-ai/web-llm setting (temperature, worker handler, …). */
|
|
1565
1585
|
[k: string]: unknown;
|
|
1566
1586
|
}
|
|
@@ -1590,6 +1610,81 @@ declare const unloadWebLLMModel: (model: LanguageModel) => Promise<void>;
|
|
|
1590
1610
|
*/
|
|
1591
1611
|
declare const createWebLLMModel: (model: string, options?: WebLLMModelOptions) => Promise<LanguageModel>;
|
|
1592
1612
|
|
|
1613
|
+
/**
|
|
1614
|
+
* The model's context window is a hard limit: a prompt that does not fit is
|
|
1615
|
+
* refused outright (WebLLM: "Prompt tokens exceed context window size"). The
|
|
1616
|
+
* agent sizes everything that grows — compaction thresholds, tool-result
|
|
1617
|
+
* clearing, the cap on one tool result, whether tools are listed or searched —
|
|
1618
|
+
* from the window, so it has to be the model's real one.
|
|
1619
|
+
*
|
|
1620
|
+
* Cloud windows are large and the host states them (`compaction.
|
|
1621
|
+
* contextWindowTokens`); a local WebLLM model's window is small (4096 tokens
|
|
1622
|
+
* by default — WebLLM's choice to save VRAM, not the model's limit) and is read
|
|
1623
|
+
* from the model itself.
|
|
1624
|
+
*/
|
|
1625
|
+
interface WebLLMRecordLike {
|
|
1626
|
+
model_id: string;
|
|
1627
|
+
overrides?: {
|
|
1628
|
+
context_window_size?: number;
|
|
1629
|
+
} & Record<string, unknown>;
|
|
1630
|
+
}
|
|
1631
|
+
/** The shape of a WebLLM `AppConfig` this module touches. */
|
|
1632
|
+
interface WebLLMAppConfigLike {
|
|
1633
|
+
model_list: WebLLMRecordLike[];
|
|
1634
|
+
}
|
|
1635
|
+
/** WebLLM's default window for its prebuilt models. */
|
|
1636
|
+
declare const WEBLLM_DEFAULT_CONTEXT_WINDOW = 4096;
|
|
1637
|
+
/**
|
|
1638
|
+
* A copy of a WebLLM app config (e.g. `prebuiltAppConfig` from
|
|
1639
|
+
* `@mlc-ai/web-llm`) with one model's context window set. Pass it as
|
|
1640
|
+
* `engineConfig.appConfig` when building the model: the weights are the same,
|
|
1641
|
+
* only the KV cache (VRAM) grows with the window. Models trained on long
|
|
1642
|
+
* contexts (Qwen3, Llama 3.x) take far more than the default 4096; models
|
|
1643
|
+
* trained on 4k (Llama 2) don't.
|
|
1644
|
+
*/
|
|
1645
|
+
declare const withWebLLMContextWindow: <T extends WebLLMAppConfigLike>(appConfig: T, modelId: string, tokens: number) => T;
|
|
1646
|
+
/**
|
|
1647
|
+
* The context window of a WebLLM model (`@browser-ai/web-llm`), or undefined
|
|
1648
|
+
* for any other model. Read from the loaded engine when it runs in this
|
|
1649
|
+
* thread, else from the app config it was built with, else WebLLM's defaults
|
|
1650
|
+
* (1024 for its "-1k" builds, 4096 otherwise). The provider keeps these
|
|
1651
|
+
* private, so this reaches in defensively.
|
|
1652
|
+
*/
|
|
1653
|
+
declare const webLLMContextWindow: (model: unknown) => number | undefined;
|
|
1654
|
+
/**
|
|
1655
|
+
* The model's own context window when it can be known (local models), else
|
|
1656
|
+
* undefined: WebLLM's (see above), or the browser's built-in model's
|
|
1657
|
+
* (`@browser-ai/core` reports it once its session exists).
|
|
1658
|
+
*/
|
|
1659
|
+
declare const contextWindowOf: (model: unknown) => number | undefined;
|
|
1660
|
+
/**
|
|
1661
|
+
* Fit the compaction settings to the model's window: the window in use is the
|
|
1662
|
+
* configured one, never larger than the model's own, and every size derived
|
|
1663
|
+
* from it shrinks with it — also a size the host set for a larger window.
|
|
1664
|
+
*/
|
|
1665
|
+
declare const fitCompactionToWindow: (resolved: ResolvedCompaction, configured: CompactionConfig | undefined, modelWindow: number | undefined) => ResolvedCompaction;
|
|
1666
|
+
/**
|
|
1667
|
+
* Estimated tokens of the tool definitions a model is sent (name, description,
|
|
1668
|
+
* JSON schema of the input) — for tools natively, or rendered into the prompt.
|
|
1669
|
+
*/
|
|
1670
|
+
declare const toolDefinitionTokens: (tools: ToolSet) => Promise<number>;
|
|
1671
|
+
/** 'auto' switches to tool search once the definitions would take this share of the window. */
|
|
1672
|
+
declare const TOOL_SEARCH_WINDOW_SHARE = 0.25;
|
|
1673
|
+
/** Raised when a prompt does not fit the model's context window. */
|
|
1674
|
+
declare class ContextWindowExceededError extends Error {
|
|
1675
|
+
/** The prompt's size as the provider counted it, when it said. */
|
|
1676
|
+
readonly promptTokens?: number;
|
|
1677
|
+
/** The model's window as the provider reported it, when it said. */
|
|
1678
|
+
readonly contextWindowTokens?: number;
|
|
1679
|
+
constructor(model: string, promptTokens?: number, contextWindowTokens?: number);
|
|
1680
|
+
toJSON(): string;
|
|
1681
|
+
}
|
|
1682
|
+
/**
|
|
1683
|
+
* The clear error to raise when a provider refused a prompt for its length
|
|
1684
|
+
* (else undefined) — instead of the provider's raw text.
|
|
1685
|
+
*/
|
|
1686
|
+
declare const contextOverflowOf: (err: unknown, model: unknown) => ContextWindowExceededError | undefined;
|
|
1687
|
+
|
|
1593
1688
|
/** Whether native tool-calling is reliable enough to be the default for a provider. */
|
|
1594
1689
|
declare const supportsNativeTools: (p: ProviderType) => boolean;
|
|
1595
1690
|
/** Whether native structured output (generateObject) is the default for a provider. */
|
|
@@ -1599,18 +1694,19 @@ declare const supportsStructuredOutput: (p: ProviderType) => boolean;
|
|
|
1599
1694
|
* is expected to work (CORS + browser-access policy). Hosts can use this to
|
|
1600
1695
|
* warn users before a direct call fails.
|
|
1601
1696
|
*
|
|
1602
|
-
*
|
|
1603
|
-
*
|
|
1697
|
+
* Checked October 2026 (a preflight from a page origin, then the API's answer):
|
|
1698
|
+
*
|
|
1699
|
+
* - `google`, `openai`, `xai`, `deepseek`: the APIs send CORS headers.
|
|
1604
1700
|
* - `anthropic`: works, but only with the direct-browser-access header, which
|
|
1605
1701
|
* the registry injects automatically.
|
|
1606
|
-
* - `openai`:
|
|
1607
|
-
*
|
|
1608
|
-
* - `xai` / `deepseek`: unreliable from the browser; prefer a proxy.
|
|
1702
|
+
* - `gateway` / `openai-compatible`: the host controls the endpoint / CORS.
|
|
1703
|
+
* - `web-llm`: runs in the page — nothing to call.
|
|
1609
1704
|
*/
|
|
1610
1705
|
declare const directBrowserOk: (p: ProviderType) => boolean;
|
|
1611
1706
|
/**
|
|
1612
|
-
* Whether a model accepts image input: `true` (expected to
|
|
1613
|
-
*
|
|
1707
|
+
* Whether a model accepts image input: `true` (expected to — also a local
|
|
1708
|
+
* vision model such as WebLLM's Phi-3.5-vision), `false` (known not to — other
|
|
1709
|
+
* local models, DeepSeek, text-only families), or `undefined`
|
|
1614
1710
|
* (unknown, e.g. an OpenAI-compatible server — the agent tries and turns a
|
|
1615
1711
|
* provider refusal into a clear error). Override per agent with `vision`.
|
|
1616
1712
|
*/
|
|
@@ -1924,4 +2020,4 @@ declare class IndexedDBStore implements ContextStore {
|
|
|
1924
2020
|
listSessions(): Promise<string[]>;
|
|
1925
2021
|
}
|
|
1926
2022
|
|
|
1927
|
-
export { type Agent, type AgentContext, type AgentEvent, type AgentEventHandler, type AgentLogger, type AgentLoggerSink, type AgentTool, type AgentToolSet, type AgentWebDBOptions, type AttachmentKind, AttachmentsNotSupportedError, type BrowserAgentConfig, type ClearedInfo, type CompactOptions, type CompactResult, type CompactionConfig, type CompressOptions, type ContextStore, type CredentialStore, type EffectiveToolStrategy, type EncryptedBlob, type ExecutorPromptContext, type ExecutorResult, FILES_STORE, FIND_TOOLS_NAME, type FileToolsOptions, type GenerateOptions, type IPlan, type IPlanStep, type IStepResult, type IToolCall, type IUsage, ImagesNotSupportedError, IndexedDBStore, type IndexedDBStoreOptions, KEYS_STORE, type LimitBreach, type LimitKind, type LoadSkillOptions, type LogLevel, MemoryCredentialStore, MemoryStore, type MessageEndpoint, type ModelInput, type ParentToWorker, type Phase, type PhaseBudgets, PlanSchema, type PlanShape, PlanStepSchema, type PlannerPromptContext, type PlannerResult, type PromptCachingSetting, type PromptParts, type Prompts, type ProviderModelSpec, type ProviderOptionsMap, type ProviderType, type ProxiedToolSpec, type RawAction, type ReplanDecision, type ReplanMode, ReplanSchema, type ReplanShape, type ReplanTrigger, type ReplannerPromptContext, type ReplannerResult, type ResolvedCaching, type ResolvedCompaction, type ResolvedConfig, type ResolvedStage, type ResolvedThinking, type RunFile, type RunImage, type RunOptions, type RunResult, SECRETS_STORE, SESSIONS_STORE, SKILL_TOOL_NAMES, type SearchToolsOptions, type ServeSubagentOptions, type Skill, type StageInput, type StageOverride, type StoredMessage, type SubagentToolOptions, type SubagentWorkerConfig, type SynthesizerPromptContext, TOOL_APPROVAL_MODES, type ThinkingConfig, type ThinkingLevel, type ThinkingSetting, type ThinkingStage, type TokenLimits, type ToolApprovalConfig, type ToolApprovalDecision, type ToolApprovalMode, type ToolApprovalRequest, ToolBudgetError, type ToolCallMode, type ToolCatalogEntry, ToolDeniedError, type ToolLoopCallbacks, type ToolLoopOptions, type ToolLoopResult, type ToolMode, type ToolPermission, type ToolResultClearing, type ToolRunContext, type ToolSelectionStrategy, type UsagePhase, VaultCredentialStore, VaultOptions, type VfsListener, type VirtualFile, type VirtualFileInfo, VirtualFileSystem, type VirtualFileSystemOptions, type WebLLMModelOptions, type WorkerLike, type WorkerToParent, attachmentKind, buildModelFromStage, bytesToBase64, checkLimits, compactHistory, compactSteps, compressHistory, createAgent, createFileTools, createFindToolsTool, createLogger, createPlan, createSkillTools, createSubagentTool, createToolResultClearer, createWebLLMModel, decideReplan, decideToolPermission, decryptJSON, defaultPrompts, defineSkill, defineTool, directBrowserOk, dispatch, encryptJSON, messageTokens as estimateMessagesTokens, estimateTokens, executeStep, 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, promptHintOf, renderActiveSkills, renderCatalog, renderSearchCatalog, renderSkillIndex, replanWanted, resolveCaching, resolveCompaction, resolveConfig, resolveModel, resolveStage, resolveThinking, runToolLoop, schemaHintOf, searchTools, selectToolMode, serveSubagentWorker, shouldReplan, splitBlocker, stream, supportsImages, supportsNativeTools, supportsPdf, supportsStructuredOutput, synthesizeAnswer, thinkingFor, toFilePart, toImagePart, tokenize, toolCatalogOf, toolRunContextOf, unloadWebLLMModel, withRollingBreakpoint, withSystem };
|
|
2023
|
+
export { type Agent, type AgentContext, type AgentEvent, type AgentEventHandler, type AgentLogger, type AgentLoggerSink, type AgentTool, type AgentToolSet, type AgentWebDBOptions, type AttachmentKind, AttachmentsNotSupportedError, type BrowserAgentConfig, type ClearedInfo, type CompactOptions, type CompactResult, type CompactionConfig, type CompressOptions, type ContextStore, ContextWindowExceededError, type CredentialStore, type EffectiveToolStrategy, type EncryptedBlob, type ExecutorPromptContext, type ExecutorResult, FILES_STORE, FIND_TOOLS_NAME, type FileToolsOptions, type GenerateOptions, type IPlan, type IPlanStep, type IStepResult, type IToolCall, type IUsage, ImagesNotSupportedError, IndexedDBStore, type IndexedDBStoreOptions, KEYS_STORE, type LimitBreach, type LimitKind, type LoadSkillOptions, type LogLevel, MemoryCredentialStore, MemoryStore, type MessageEndpoint, type ModelInput, type ParentToWorker, type Phase, type PhaseBudgets, PlanSchema, type PlanShape, PlanStepSchema, type PlannerPromptContext, type PlannerResult, type PromptCachingSetting, type PromptParts, type Prompts, type ProviderModelSpec, type ProviderOptionsMap, type ProviderType, type ProxiedToolSpec, type RawAction, type ReplanDecision, type ReplanMode, ReplanSchema, type ReplanShape, type ReplanTrigger, type ReplannerPromptContext, type ReplannerResult, type ResolvedCaching, type ResolvedCompaction, type ResolvedConfig, type ResolvedStage, type ResolvedThinking, type RunFile, type RunImage, type RunOptions, type RunResult, SECRETS_STORE, SESSIONS_STORE, SKILL_TOOL_NAMES, type SearchToolsOptions, type ServeSubagentOptions, type Skill, type StageInput, type StageOverride, type StoredMessage, type SubagentToolOptions, type SubagentWorkerConfig, type SynthesizerPromptContext, TOOL_APPROVAL_MODES, TOOL_SEARCH_WINDOW_SHARE, type ThinkingConfig, type ThinkingLevel, type ThinkingSetting, type ThinkingStage, type TokenLimits, type ToolApprovalConfig, type ToolApprovalDecision, type ToolApprovalMode, type ToolApprovalRequest, ToolBudgetError, type ToolCallMode, type ToolCatalogEntry, ToolDeniedError, type ToolLoopCallbacks, type ToolLoopOptions, type ToolLoopResult, type ToolMode, type ToolPermission, type ToolResultClearing, type ToolRunContext, type ToolSelectionStrategy, type UsagePhase, VaultCredentialStore, VaultOptions, type VfsListener, type VirtualFile, type VirtualFileInfo, VirtualFileSystem, type VirtualFileSystemOptions, WEBLLM_DEFAULT_CONTEXT_WINDOW, type WebLLMAppConfigLike, type WebLLMModelOptions, type WorkerLike, type WorkerToParent, attachmentKind, buildModelFromStage, bytesToBase64, checkLimits, compactHistory, compactSteps, compressHistory, contextOverflowOf, contextWindowOf, createAgent, createFileTools, createFindToolsTool, createLogger, createPlan, 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, promptHintOf, renderActiveSkills, renderCatalog, renderSearchCatalog, renderSkillIndex, replanWanted, resolveCaching, resolveCompaction, resolveConfig, resolveModel, 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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -53,6 +53,9 @@ interface IStepResult {
|
|
|
53
53
|
* so a `budgetTokens` is mapped to the provider-specific options of the two
|
|
54
54
|
* providers that take one (Anthropic, Google); provider options win over the
|
|
55
55
|
* portable level by the SDK's precedence rules.
|
|
56
|
+
*
|
|
57
|
+
* WebLLM ignores the portable level: its thinking models (Qwen3) are switched
|
|
58
|
+
* by `extra_body.enable_thinking`, so every setting carries that too.
|
|
56
59
|
*/
|
|
57
60
|
type ThinkingLevel = 'provider-default' | 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh';
|
|
58
61
|
interface ThinkingConfig {
|
|
@@ -1095,8 +1098,16 @@ interface Agent {
|
|
|
1095
1098
|
readonly toolApprovalMode: ToolApprovalMode;
|
|
1096
1099
|
/** The tool catalogue (host + MCP tools after filtering). */
|
|
1097
1100
|
listTools(): ToolCatalogEntry[];
|
|
1098
|
-
/**
|
|
1101
|
+
/**
|
|
1102
|
+
* The effective tool selection ('auto' resolved by the catalogue's size: its
|
|
1103
|
+
* count, or its definitions' share of the context window).
|
|
1104
|
+
*/
|
|
1099
1105
|
readonly toolStrategy: EffectiveToolStrategy;
|
|
1106
|
+
/**
|
|
1107
|
+
* The context window the agent fits its runs into: the configured one, never
|
|
1108
|
+
* more than the model's own (read from local WebLLM models).
|
|
1109
|
+
*/
|
|
1110
|
+
readonly contextWindowTokens: number;
|
|
1100
1111
|
/** Configured skills (name + description). */
|
|
1101
1112
|
readonly skills: {
|
|
1102
1113
|
name: string;
|
|
@@ -1561,6 +1572,15 @@ interface WebLLMModelOptions {
|
|
|
1561
1572
|
* Set to `false` to keep the lazy behavior.
|
|
1562
1573
|
*/
|
|
1563
1574
|
preload?: boolean;
|
|
1575
|
+
/**
|
|
1576
|
+
* The context window to load the model with, in tokens. WebLLM loads its
|
|
1577
|
+
* prebuilt models with 4096 (to save VRAM), far below what Qwen3 or Llama
|
|
1578
|
+
* 3.x were trained on; a larger window costs KV-cache memory, not a new
|
|
1579
|
+
* download. Applied through `engineConfig.appConfig` (WebLLM's prebuilt
|
|
1580
|
+
* config with this model's `context_window_size` overridden) unless you pass
|
|
1581
|
+
* an `appConfig` of your own; see `withWebLLMContextWindow`.
|
|
1582
|
+
*/
|
|
1583
|
+
contextWindowTokens?: number;
|
|
1564
1584
|
/** Any other @browser-ai/web-llm setting (temperature, worker handler, …). */
|
|
1565
1585
|
[k: string]: unknown;
|
|
1566
1586
|
}
|
|
@@ -1590,6 +1610,81 @@ declare const unloadWebLLMModel: (model: LanguageModel) => Promise<void>;
|
|
|
1590
1610
|
*/
|
|
1591
1611
|
declare const createWebLLMModel: (model: string, options?: WebLLMModelOptions) => Promise<LanguageModel>;
|
|
1592
1612
|
|
|
1613
|
+
/**
|
|
1614
|
+
* The model's context window is a hard limit: a prompt that does not fit is
|
|
1615
|
+
* refused outright (WebLLM: "Prompt tokens exceed context window size"). The
|
|
1616
|
+
* agent sizes everything that grows — compaction thresholds, tool-result
|
|
1617
|
+
* clearing, the cap on one tool result, whether tools are listed or searched —
|
|
1618
|
+
* from the window, so it has to be the model's real one.
|
|
1619
|
+
*
|
|
1620
|
+
* Cloud windows are large and the host states them (`compaction.
|
|
1621
|
+
* contextWindowTokens`); a local WebLLM model's window is small (4096 tokens
|
|
1622
|
+
* by default — WebLLM's choice to save VRAM, not the model's limit) and is read
|
|
1623
|
+
* from the model itself.
|
|
1624
|
+
*/
|
|
1625
|
+
interface WebLLMRecordLike {
|
|
1626
|
+
model_id: string;
|
|
1627
|
+
overrides?: {
|
|
1628
|
+
context_window_size?: number;
|
|
1629
|
+
} & Record<string, unknown>;
|
|
1630
|
+
}
|
|
1631
|
+
/** The shape of a WebLLM `AppConfig` this module touches. */
|
|
1632
|
+
interface WebLLMAppConfigLike {
|
|
1633
|
+
model_list: WebLLMRecordLike[];
|
|
1634
|
+
}
|
|
1635
|
+
/** WebLLM's default window for its prebuilt models. */
|
|
1636
|
+
declare const WEBLLM_DEFAULT_CONTEXT_WINDOW = 4096;
|
|
1637
|
+
/**
|
|
1638
|
+
* A copy of a WebLLM app config (e.g. `prebuiltAppConfig` from
|
|
1639
|
+
* `@mlc-ai/web-llm`) with one model's context window set. Pass it as
|
|
1640
|
+
* `engineConfig.appConfig` when building the model: the weights are the same,
|
|
1641
|
+
* only the KV cache (VRAM) grows with the window. Models trained on long
|
|
1642
|
+
* contexts (Qwen3, Llama 3.x) take far more than the default 4096; models
|
|
1643
|
+
* trained on 4k (Llama 2) don't.
|
|
1644
|
+
*/
|
|
1645
|
+
declare const withWebLLMContextWindow: <T extends WebLLMAppConfigLike>(appConfig: T, modelId: string, tokens: number) => T;
|
|
1646
|
+
/**
|
|
1647
|
+
* The context window of a WebLLM model (`@browser-ai/web-llm`), or undefined
|
|
1648
|
+
* for any other model. Read from the loaded engine when it runs in this
|
|
1649
|
+
* thread, else from the app config it was built with, else WebLLM's defaults
|
|
1650
|
+
* (1024 for its "-1k" builds, 4096 otherwise). The provider keeps these
|
|
1651
|
+
* private, so this reaches in defensively.
|
|
1652
|
+
*/
|
|
1653
|
+
declare const webLLMContextWindow: (model: unknown) => number | undefined;
|
|
1654
|
+
/**
|
|
1655
|
+
* The model's own context window when it can be known (local models), else
|
|
1656
|
+
* undefined: WebLLM's (see above), or the browser's built-in model's
|
|
1657
|
+
* (`@browser-ai/core` reports it once its session exists).
|
|
1658
|
+
*/
|
|
1659
|
+
declare const contextWindowOf: (model: unknown) => number | undefined;
|
|
1660
|
+
/**
|
|
1661
|
+
* Fit the compaction settings to the model's window: the window in use is the
|
|
1662
|
+
* configured one, never larger than the model's own, and every size derived
|
|
1663
|
+
* from it shrinks with it — also a size the host set for a larger window.
|
|
1664
|
+
*/
|
|
1665
|
+
declare const fitCompactionToWindow: (resolved: ResolvedCompaction, configured: CompactionConfig | undefined, modelWindow: number | undefined) => ResolvedCompaction;
|
|
1666
|
+
/**
|
|
1667
|
+
* Estimated tokens of the tool definitions a model is sent (name, description,
|
|
1668
|
+
* JSON schema of the input) — for tools natively, or rendered into the prompt.
|
|
1669
|
+
*/
|
|
1670
|
+
declare const toolDefinitionTokens: (tools: ToolSet) => Promise<number>;
|
|
1671
|
+
/** 'auto' switches to tool search once the definitions would take this share of the window. */
|
|
1672
|
+
declare const TOOL_SEARCH_WINDOW_SHARE = 0.25;
|
|
1673
|
+
/** Raised when a prompt does not fit the model's context window. */
|
|
1674
|
+
declare class ContextWindowExceededError extends Error {
|
|
1675
|
+
/** The prompt's size as the provider counted it, when it said. */
|
|
1676
|
+
readonly promptTokens?: number;
|
|
1677
|
+
/** The model's window as the provider reported it, when it said. */
|
|
1678
|
+
readonly contextWindowTokens?: number;
|
|
1679
|
+
constructor(model: string, promptTokens?: number, contextWindowTokens?: number);
|
|
1680
|
+
toJSON(): string;
|
|
1681
|
+
}
|
|
1682
|
+
/**
|
|
1683
|
+
* The clear error to raise when a provider refused a prompt for its length
|
|
1684
|
+
* (else undefined) — instead of the provider's raw text.
|
|
1685
|
+
*/
|
|
1686
|
+
declare const contextOverflowOf: (err: unknown, model: unknown) => ContextWindowExceededError | undefined;
|
|
1687
|
+
|
|
1593
1688
|
/** Whether native tool-calling is reliable enough to be the default for a provider. */
|
|
1594
1689
|
declare const supportsNativeTools: (p: ProviderType) => boolean;
|
|
1595
1690
|
/** Whether native structured output (generateObject) is the default for a provider. */
|
|
@@ -1599,18 +1694,19 @@ declare const supportsStructuredOutput: (p: ProviderType) => boolean;
|
|
|
1599
1694
|
* is expected to work (CORS + browser-access policy). Hosts can use this to
|
|
1600
1695
|
* warn users before a direct call fails.
|
|
1601
1696
|
*
|
|
1602
|
-
*
|
|
1603
|
-
*
|
|
1697
|
+
* Checked October 2026 (a preflight from a page origin, then the API's answer):
|
|
1698
|
+
*
|
|
1699
|
+
* - `google`, `openai`, `xai`, `deepseek`: the APIs send CORS headers.
|
|
1604
1700
|
* - `anthropic`: works, but only with the direct-browser-access header, which
|
|
1605
1701
|
* the registry injects automatically.
|
|
1606
|
-
* - `openai`:
|
|
1607
|
-
*
|
|
1608
|
-
* - `xai` / `deepseek`: unreliable from the browser; prefer a proxy.
|
|
1702
|
+
* - `gateway` / `openai-compatible`: the host controls the endpoint / CORS.
|
|
1703
|
+
* - `web-llm`: runs in the page — nothing to call.
|
|
1609
1704
|
*/
|
|
1610
1705
|
declare const directBrowserOk: (p: ProviderType) => boolean;
|
|
1611
1706
|
/**
|
|
1612
|
-
* Whether a model accepts image input: `true` (expected to
|
|
1613
|
-
*
|
|
1707
|
+
* Whether a model accepts image input: `true` (expected to — also a local
|
|
1708
|
+
* vision model such as WebLLM's Phi-3.5-vision), `false` (known not to — other
|
|
1709
|
+
* local models, DeepSeek, text-only families), or `undefined`
|
|
1614
1710
|
* (unknown, e.g. an OpenAI-compatible server — the agent tries and turns a
|
|
1615
1711
|
* provider refusal into a clear error). Override per agent with `vision`.
|
|
1616
1712
|
*/
|
|
@@ -1924,4 +2020,4 @@ declare class IndexedDBStore implements ContextStore {
|
|
|
1924
2020
|
listSessions(): Promise<string[]>;
|
|
1925
2021
|
}
|
|
1926
2022
|
|
|
1927
|
-
export { type Agent, type AgentContext, type AgentEvent, type AgentEventHandler, type AgentLogger, type AgentLoggerSink, type AgentTool, type AgentToolSet, type AgentWebDBOptions, type AttachmentKind, AttachmentsNotSupportedError, type BrowserAgentConfig, type ClearedInfo, type CompactOptions, type CompactResult, type CompactionConfig, type CompressOptions, type ContextStore, type CredentialStore, type EffectiveToolStrategy, type EncryptedBlob, type ExecutorPromptContext, type ExecutorResult, FILES_STORE, FIND_TOOLS_NAME, type FileToolsOptions, type GenerateOptions, type IPlan, type IPlanStep, type IStepResult, type IToolCall, type IUsage, ImagesNotSupportedError, IndexedDBStore, type IndexedDBStoreOptions, KEYS_STORE, type LimitBreach, type LimitKind, type LoadSkillOptions, type LogLevel, MemoryCredentialStore, MemoryStore, type MessageEndpoint, type ModelInput, type ParentToWorker, type Phase, type PhaseBudgets, PlanSchema, type PlanShape, PlanStepSchema, type PlannerPromptContext, type PlannerResult, type PromptCachingSetting, type PromptParts, type Prompts, type ProviderModelSpec, type ProviderOptionsMap, type ProviderType, type ProxiedToolSpec, type RawAction, type ReplanDecision, type ReplanMode, ReplanSchema, type ReplanShape, type ReplanTrigger, type ReplannerPromptContext, type ReplannerResult, type ResolvedCaching, type ResolvedCompaction, type ResolvedConfig, type ResolvedStage, type ResolvedThinking, type RunFile, type RunImage, type RunOptions, type RunResult, SECRETS_STORE, SESSIONS_STORE, SKILL_TOOL_NAMES, type SearchToolsOptions, type ServeSubagentOptions, type Skill, type StageInput, type StageOverride, type StoredMessage, type SubagentToolOptions, type SubagentWorkerConfig, type SynthesizerPromptContext, TOOL_APPROVAL_MODES, type ThinkingConfig, type ThinkingLevel, type ThinkingSetting, type ThinkingStage, type TokenLimits, type ToolApprovalConfig, type ToolApprovalDecision, type ToolApprovalMode, type ToolApprovalRequest, ToolBudgetError, type ToolCallMode, type ToolCatalogEntry, ToolDeniedError, type ToolLoopCallbacks, type ToolLoopOptions, type ToolLoopResult, type ToolMode, type ToolPermission, type ToolResultClearing, type ToolRunContext, type ToolSelectionStrategy, type UsagePhase, VaultCredentialStore, VaultOptions, type VfsListener, type VirtualFile, type VirtualFileInfo, VirtualFileSystem, type VirtualFileSystemOptions, type WebLLMModelOptions, type WorkerLike, type WorkerToParent, attachmentKind, buildModelFromStage, bytesToBase64, checkLimits, compactHistory, compactSteps, compressHistory, createAgent, createFileTools, createFindToolsTool, createLogger, createPlan, createSkillTools, createSubagentTool, createToolResultClearer, createWebLLMModel, decideReplan, decideToolPermission, decryptJSON, defaultPrompts, defineSkill, defineTool, directBrowserOk, dispatch, encryptJSON, messageTokens as estimateMessagesTokens, estimateTokens, executeStep, 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, promptHintOf, renderActiveSkills, renderCatalog, renderSearchCatalog, renderSkillIndex, replanWanted, resolveCaching, resolveCompaction, resolveConfig, resolveModel, resolveStage, resolveThinking, runToolLoop, schemaHintOf, searchTools, selectToolMode, serveSubagentWorker, shouldReplan, splitBlocker, stream, supportsImages, supportsNativeTools, supportsPdf, supportsStructuredOutput, synthesizeAnswer, thinkingFor, toFilePart, toImagePart, tokenize, toolCatalogOf, toolRunContextOf, unloadWebLLMModel, withRollingBreakpoint, withSystem };
|
|
2023
|
+
export { type Agent, type AgentContext, type AgentEvent, type AgentEventHandler, type AgentLogger, type AgentLoggerSink, type AgentTool, type AgentToolSet, type AgentWebDBOptions, type AttachmentKind, AttachmentsNotSupportedError, type BrowserAgentConfig, type ClearedInfo, type CompactOptions, type CompactResult, type CompactionConfig, type CompressOptions, type ContextStore, ContextWindowExceededError, type CredentialStore, type EffectiveToolStrategy, type EncryptedBlob, type ExecutorPromptContext, type ExecutorResult, FILES_STORE, FIND_TOOLS_NAME, type FileToolsOptions, type GenerateOptions, type IPlan, type IPlanStep, type IStepResult, type IToolCall, type IUsage, ImagesNotSupportedError, IndexedDBStore, type IndexedDBStoreOptions, KEYS_STORE, type LimitBreach, type LimitKind, type LoadSkillOptions, type LogLevel, MemoryCredentialStore, MemoryStore, type MessageEndpoint, type ModelInput, type ParentToWorker, type Phase, type PhaseBudgets, PlanSchema, type PlanShape, PlanStepSchema, type PlannerPromptContext, type PlannerResult, type PromptCachingSetting, type PromptParts, type Prompts, type ProviderModelSpec, type ProviderOptionsMap, type ProviderType, type ProxiedToolSpec, type RawAction, type ReplanDecision, type ReplanMode, ReplanSchema, type ReplanShape, type ReplanTrigger, type ReplannerPromptContext, type ReplannerResult, type ResolvedCaching, type ResolvedCompaction, type ResolvedConfig, type ResolvedStage, type ResolvedThinking, type RunFile, type RunImage, type RunOptions, type RunResult, SECRETS_STORE, SESSIONS_STORE, SKILL_TOOL_NAMES, type SearchToolsOptions, type ServeSubagentOptions, type Skill, type StageInput, type StageOverride, type StoredMessage, type SubagentToolOptions, type SubagentWorkerConfig, type SynthesizerPromptContext, TOOL_APPROVAL_MODES, TOOL_SEARCH_WINDOW_SHARE, type ThinkingConfig, type ThinkingLevel, type ThinkingSetting, type ThinkingStage, type TokenLimits, type ToolApprovalConfig, type ToolApprovalDecision, type ToolApprovalMode, type ToolApprovalRequest, ToolBudgetError, type ToolCallMode, type ToolCatalogEntry, ToolDeniedError, type ToolLoopCallbacks, type ToolLoopOptions, type ToolLoopResult, type ToolMode, type ToolPermission, type ToolResultClearing, type ToolRunContext, type ToolSelectionStrategy, type UsagePhase, VaultCredentialStore, VaultOptions, type VfsListener, type VirtualFile, type VirtualFileInfo, VirtualFileSystem, type VirtualFileSystemOptions, WEBLLM_DEFAULT_CONTEXT_WINDOW, type WebLLMAppConfigLike, type WebLLMModelOptions, type WorkerLike, type WorkerToParent, attachmentKind, buildModelFromStage, bytesToBase64, checkLimits, compactHistory, compactSteps, compressHistory, contextOverflowOf, contextWindowOf, createAgent, createFileTools, createFindToolsTool, createLogger, createPlan, 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, promptHintOf, renderActiveSkills, renderCatalog, renderSearchCatalog, renderSkillIndex, replanWanted, resolveCaching, resolveCompaction, resolveConfig, resolveModel, 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 };
|