@dudko.dev/agent-web-react 0.0.17 → 0.0.19
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 +33 -4
- package/dist/index.cjs +84 -767
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -264
- package/dist/index.d.ts +3 -264
- package/dist/index.js +72 -738
- package/dist/index.js.map +1 -1
- package/dist/mcp.cjs +711 -0
- package/dist/mcp.cjs.map +1 -0
- package/dist/mcp.d.cts +265 -0
- package/dist/mcp.d.ts +265 -0
- package/dist/mcp.js +668 -0
- package/dist/mcp.js.map +1 -0
- package/package.json +13 -3
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { DependencyList, ReactNode, RefObject, ComponentType, CSSProperties } from 'react';
|
|
3
|
-
import { IPlan, IPlanStep, IUsage, ReplanMode, AgentEvent, RunFile, RunResult, Agent, ToolApprovalMode, CompactResult, AgentEventHandler, BrowserAgentConfig, VirtualFileInfo, VirtualFileSystem, CredentialStore,
|
|
3
|
+
import { IPlan, IPlanStep, IUsage, ReplanMode, AgentEvent, RunFile, RunResult, Agent, ToolApprovalMode, CompactResult, AgentEventHandler, BrowserAgentConfig, VirtualFileInfo, VirtualFileSystem, CredentialStore, createWebLLMModel, WebLLMModelOptions } from '@dudko.dev/agent-web';
|
|
4
4
|
export { Agent, AgentEvent, AgentEventHandler, AgentLoggerSink, AgentTool, AgentToolSet, AttachmentsNotSupportedError, BrowserAgentConfig, CompactResult, CompactionConfig, CredentialStore, FileToolsOptions, IPlan, IPlanStep, IStepResult, IToolCall, IUsage, ImagesNotSupportedError, IndexedDBStore, LogLevel, MemoryCredentialStore, MemoryStore, ModelInput, ProviderModelSpec, ProviderType, RunFile, RunOptions, RunResult, Skill, SubagentToolOptions, SubagentWorkerConfig, ThinkingLevel, ThinkingSetting, TokenLimits, ToolApprovalConfig, ToolApprovalMode, ToolApprovalRequest, VaultCredentialStore, VirtualFile, VirtualFileInfo, VirtualFileSystem, createAgent, createFileTools, createSubagentTool, createWebLLMModel, defineSkill, defineTool, isWebGPUAvailable, loadSkillFromUrl, markReadOnly, parseSkillMarkdown, preloadWebLLMModel, serveSubagentWorker, supportsImages, supportsPdf, unloadWebLLMModel } from '@dudko.dev/agent-web';
|
|
5
5
|
|
|
6
6
|
/** Why a run stopped early (a `budget.exceeded` event). */
|
|
@@ -465,267 +465,6 @@ interface UseCredentialsReturn {
|
|
|
465
465
|
*/
|
|
466
466
|
declare const useCredentials: (store?: CredentialStore) => UseCredentialsReturn;
|
|
467
467
|
|
|
468
|
-
/**
|
|
469
|
-
* Structural types for the core's OPTIONAL `@dudko.dev/agent-web/mcp` subpath.
|
|
470
|
-
*
|
|
471
|
-
* The subpath is loaded with a dynamic import and typed here rather than
|
|
472
|
-
* imported, for two reasons: it drags in `@modelcontextprotocol/sdk` (an
|
|
473
|
-
* optional peer of the core, which apps without MCP must not have to install),
|
|
474
|
-
* and the OAuth half only exists in newer cores while this package supports
|
|
475
|
-
* `@dudko.dev/agent-web >= 0.0.6`. `useMcp` feature-detects at runtime and
|
|
476
|
-
* reports `oauthSupported: false` on an older core instead of crashing.
|
|
477
|
-
*/
|
|
478
|
-
interface McpCatalogEntry {
|
|
479
|
-
name: string;
|
|
480
|
-
description: string;
|
|
481
|
-
server: string;
|
|
482
|
-
/** The server marked the tool read-only (newer cores). */
|
|
483
|
-
readOnly?: boolean;
|
|
484
|
-
}
|
|
485
|
-
interface McpServerResult {
|
|
486
|
-
name: string;
|
|
487
|
-
connected: boolean;
|
|
488
|
-
error?: string;
|
|
489
|
-
needsAuthorization?: boolean;
|
|
490
|
-
}
|
|
491
|
-
interface ConnectedMcp {
|
|
492
|
-
tools: AgentToolSet;
|
|
493
|
-
catalog: McpCatalogEntry[];
|
|
494
|
-
results: McpServerResult[];
|
|
495
|
-
refreshServer?: (name: string) => Promise<void>;
|
|
496
|
-
close: () => Promise<void>;
|
|
497
|
-
}
|
|
498
|
-
interface McpHttpServerConfig {
|
|
499
|
-
url: string;
|
|
500
|
-
headers?: Record<string, string>;
|
|
501
|
-
authProvider?: unknown;
|
|
502
|
-
/** Per-server connect deadline (newer cores; ignored by older ones). */
|
|
503
|
-
connectTimeoutMs?: number;
|
|
504
|
-
}
|
|
505
|
-
interface McpOAuthCallback {
|
|
506
|
-
code?: string;
|
|
507
|
-
state?: string;
|
|
508
|
-
error?: string;
|
|
509
|
-
errorDescription?: string;
|
|
510
|
-
}
|
|
511
|
-
interface BrowserOAuthProvider {
|
|
512
|
-
serverUrl: string;
|
|
513
|
-
authorizationUrl?: URL;
|
|
514
|
-
isAuthorized(): Promise<boolean>;
|
|
515
|
-
reset(): Promise<void>;
|
|
516
|
-
}
|
|
517
|
-
interface BrowserOAuthProviderOptions {
|
|
518
|
-
serverUrl: string;
|
|
519
|
-
redirectUrl: string;
|
|
520
|
-
clientName?: string;
|
|
521
|
-
scope?: string;
|
|
522
|
-
}
|
|
523
|
-
/** The shape of the subpath module, as far as this package uses it. */
|
|
524
|
-
interface McpModule {
|
|
525
|
-
connectMcpHttp: (servers: Record<string, McpHttpServerConfig>, opts?: {
|
|
526
|
-
clientName?: string;
|
|
527
|
-
onLog?: (level: string, message: string) => void;
|
|
528
|
-
connectTimeoutMs?: number;
|
|
529
|
-
}) => Promise<ConnectedMcp>;
|
|
530
|
-
BrowserOAuthProvider?: new (opts: BrowserOAuthProviderOptions) => BrowserOAuthProvider;
|
|
531
|
-
readOAuthCallback?: (input?: string | URL) => McpOAuthCallback | undefined;
|
|
532
|
-
finishMcpOAuth?: (provider: BrowserOAuthProvider, callback: McpOAuthCallback) => Promise<void>;
|
|
533
|
-
/**
|
|
534
|
-
* The SDK's error class, re-exported by the core so an authorization failure
|
|
535
|
-
* can be recognised by identity. Absent on cores older than 0.0.12.
|
|
536
|
-
*/
|
|
537
|
-
UnauthorizedError?: new (message?: string) => Error;
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
type McpStatus = 'idle' | 'connecting' | 'connected' | 'needs-authorization' | 'error';
|
|
541
|
-
interface McpConnectOptions {
|
|
542
|
-
/** The server's StreamableHTTP endpoint. */
|
|
543
|
-
url: string;
|
|
544
|
-
/** Prefix for the discovered tool names ("<name>__<tool>"). Default 'mcp'. */
|
|
545
|
-
name?: string;
|
|
546
|
-
/** Static headers, e.g. `{ Authorization: 'Bearer …' }`. Ignored when `oauth` is set. */
|
|
547
|
-
headers?: Record<string, string>;
|
|
548
|
-
/**
|
|
549
|
-
* Authenticate with OAuth 2.1 + dynamic client registration. Requires a core
|
|
550
|
-
* that ships the OAuth provider; check `oauthSupported` before offering it.
|
|
551
|
-
*/
|
|
552
|
-
oauth?: boolean | {
|
|
553
|
-
redirectUrl?: string;
|
|
554
|
-
scope?: string;
|
|
555
|
-
clientName?: string;
|
|
556
|
-
};
|
|
557
|
-
}
|
|
558
|
-
interface UseMcpOptions {
|
|
559
|
-
/** Client name reported to the MCP server during initialize. */
|
|
560
|
-
clientName?: string;
|
|
561
|
-
/** Called with connector log lines — handy while debugging a server. */
|
|
562
|
-
onLog?: (level: string, message: string) => void;
|
|
563
|
-
}
|
|
564
|
-
interface UseMcpReturn {
|
|
565
|
-
status: McpStatus;
|
|
566
|
-
/** Merge into `BrowserAgentConfig.tools` once `status === 'connected'`. */
|
|
567
|
-
tools?: AgentToolSet;
|
|
568
|
-
catalog: McpCatalogEntry[];
|
|
569
|
-
error?: string;
|
|
570
|
-
/** Where to send the user when `status === 'needs-authorization'`. */
|
|
571
|
-
authorizationUrl?: string;
|
|
572
|
-
/**
|
|
573
|
-
* Whether the installed core exposes the OAuth API. `undefined` until the
|
|
574
|
-
* optional subpath has been loaded once — call `checkOAuthSupport()` to
|
|
575
|
-
* resolve it before offering OAuth in your UI.
|
|
576
|
-
*/
|
|
577
|
-
oauthSupported?: boolean;
|
|
578
|
-
/** True while an OAuth redirect is being finished on mount. */
|
|
579
|
-
completingAuthorization: boolean;
|
|
580
|
-
connect: (options: McpConnectOptions) => Promise<void>;
|
|
581
|
-
disconnect: () => Promise<void>;
|
|
582
|
-
/** Navigate to the authorization server. Call it from a user gesture. */
|
|
583
|
-
authorize: () => void;
|
|
584
|
-
/** Drop the stored tokens and dynamic registration for the current server. */
|
|
585
|
-
forgetAuthorization: () => Promise<void>;
|
|
586
|
-
/** Load the optional subpath and report whether it can do OAuth. */
|
|
587
|
-
checkOAuthSupport: () => Promise<boolean>;
|
|
588
|
-
}
|
|
589
|
-
/** Map a single server's connect outcome onto the hook's status. Pure. */
|
|
590
|
-
declare const describeMcpResult: (result: McpServerResult | undefined) => {
|
|
591
|
-
status: McpStatus;
|
|
592
|
-
error?: string;
|
|
593
|
-
};
|
|
594
|
-
/**
|
|
595
|
-
* Read the authorization-code parameters out of a URL **synchronously**.
|
|
596
|
-
*
|
|
597
|
-
* The core exports an equivalent, but it lives behind a dynamic import: by the
|
|
598
|
-
* time that import resolves, React has flushed the rest of the app's effects,
|
|
599
|
-
* and any one of them may have rewritten `location` (the demo's own view
|
|
600
|
-
* router did exactly that). The callback has to be captured before the first
|
|
601
|
-
* await, so this parser is duplicated here on purpose.
|
|
602
|
-
*
|
|
603
|
-
* Reads the query string and, for hash-routed apps, the fragment. Returns
|
|
604
|
-
* undefined when neither a `code` nor an `error` is present.
|
|
605
|
-
*/
|
|
606
|
-
declare const readCallbackParams: (href?: string) => McpOAuthCallback | undefined;
|
|
607
|
-
/**
|
|
608
|
-
* Remove the OAuth response parameters from a URL, leaving the rest intact —
|
|
609
|
-
* query string and fragment alike. The code is single-use and lands in history,
|
|
610
|
-
* referrers and screenshots, so it goes as soon as it has been read.
|
|
611
|
-
*/
|
|
612
|
-
declare const stripOAuthParams: (href: string) => string;
|
|
613
|
-
declare const claimOAuthCallback: (callback: McpOAuthCallback) => boolean;
|
|
614
|
-
/**
|
|
615
|
-
* Did this error come from the server refusing our authorization?
|
|
616
|
-
*
|
|
617
|
-
* Identity, not strings: the SDK's `UnauthorizedError` never assigns
|
|
618
|
-
* `this.name` (so it reads as "Error"), and its message would also match a
|
|
619
|
-
* tool whose own error text mentions "unauthorized" — the connector throws a
|
|
620
|
-
* failing tool's text verbatim. The class is re-exported by the core's `./mcp`
|
|
621
|
-
* subpath for exactly this; `constructor.name` is the fallback for a core too
|
|
622
|
-
* old to export it.
|
|
623
|
-
*/
|
|
624
|
-
declare const isUnauthorizedError: (err: unknown, mod?: McpModule) => boolean;
|
|
625
|
-
/**
|
|
626
|
-
* Connect the browser agent to a remote MCP server the user names at runtime —
|
|
627
|
-
* static header, or full OAuth 2.1 with dynamic client registration.
|
|
628
|
-
*
|
|
629
|
-
* The OAuth round-trip leaves the page, so the hook persists what it needs to
|
|
630
|
-
* resume: on mount it detects `?code=…`, finishes the exchange, cleans the URL
|
|
631
|
-
* and reconnects, all before the app renders anything MCP-related.
|
|
632
|
-
*
|
|
633
|
-
* ```tsx
|
|
634
|
-
* const mcp = useMcp()
|
|
635
|
-
* // await mcp.connect({ url, oauth: true })
|
|
636
|
-
* // mcp.status === 'needs-authorization' && <button onClick={mcp.authorize}>Authorize</button>
|
|
637
|
-
* // <AgentProvider config={{ model, tools: { ...local, ...mcp.tools } }}>
|
|
638
|
-
* ```
|
|
639
|
-
*/
|
|
640
|
-
declare const useMcp: (options?: UseMcpOptions) => UseMcpReturn;
|
|
641
|
-
|
|
642
|
-
type McpAuthMode = 'none' | 'bearer' | 'oauth';
|
|
643
|
-
/** One server the user wants connected. */
|
|
644
|
-
interface McpServerSpec {
|
|
645
|
-
/**
|
|
646
|
-
* Unique name; also the tool prefix ("<name>__<tool>"). Sanitised to
|
|
647
|
-
* `[a-zA-Z0-9_-]`; a taken name gets a numeric suffix.
|
|
648
|
-
*/
|
|
649
|
-
name: string;
|
|
650
|
-
/** The server's StreamableHTTP endpoint. */
|
|
651
|
-
url: string;
|
|
652
|
-
auth?: McpAuthMode;
|
|
653
|
-
/** Bearer token for `auth: 'bearer'` — kept in memory only, never persisted. */
|
|
654
|
-
token?: string;
|
|
655
|
-
/** OAuth details for `auth: 'oauth'`. */
|
|
656
|
-
oauth?: {
|
|
657
|
-
redirectUrl?: string;
|
|
658
|
-
scope?: string;
|
|
659
|
-
clientName?: string;
|
|
660
|
-
};
|
|
661
|
-
}
|
|
662
|
-
/** A server's live state. */
|
|
663
|
-
interface McpServerView {
|
|
664
|
-
name: string;
|
|
665
|
-
url: string;
|
|
666
|
-
auth: McpAuthMode;
|
|
667
|
-
status: McpStatus;
|
|
668
|
-
error?: string;
|
|
669
|
-
/** Where to send the user when `status === 'needs-authorization'`. */
|
|
670
|
-
authorizationUrl?: string;
|
|
671
|
-
catalog: McpCatalogEntry[];
|
|
672
|
-
}
|
|
673
|
-
interface UseMcpServersOptions extends UseMcpOptions {
|
|
674
|
-
/**
|
|
675
|
-
* Remember the server list (never tokens) in localStorage so it survives a
|
|
676
|
-
* reload — and the OAuth redirect, which IS a reload (default true).
|
|
677
|
-
*/
|
|
678
|
-
persist?: boolean;
|
|
679
|
-
/** localStorage key of the list (default 'agent-web-react:mcp-servers'). */
|
|
680
|
-
storageKey?: string;
|
|
681
|
-
/** Reconnect remembered servers on mount (default true). Bearer servers wait for their token. */
|
|
682
|
-
autoConnect?: boolean;
|
|
683
|
-
/** Per-server connect deadline in ms (default: the core's, 30 s). */
|
|
684
|
-
connectTimeoutMs?: number;
|
|
685
|
-
}
|
|
686
|
-
interface UseMcpServersReturn {
|
|
687
|
-
servers: McpServerView[];
|
|
688
|
-
/** Tools of every connected server, merged — pass to `BrowserAgentConfig.tools`. */
|
|
689
|
-
tools: AgentToolSet;
|
|
690
|
-
/** Catalogue of every connected server, merged. */
|
|
691
|
-
catalog: McpCatalogEntry[];
|
|
692
|
-
connectedCount: number;
|
|
693
|
-
/** True while an OAuth redirect is being finished on mount. */
|
|
694
|
-
completingAuthorization: boolean;
|
|
695
|
-
/** Whether the installed core can do OAuth (undefined until checked). */
|
|
696
|
-
oauthSupported?: boolean;
|
|
697
|
-
checkOAuthSupport: () => Promise<boolean>;
|
|
698
|
-
/** Add (or replace, by name) a server and connect it. Resolves with the final name. */
|
|
699
|
-
add: (spec: McpServerSpec) => Promise<string>;
|
|
700
|
-
/** Disconnect and forget a server. */
|
|
701
|
-
remove: (name: string) => Promise<void>;
|
|
702
|
-
/** Connect again — optionally with a fresh bearer token. */
|
|
703
|
-
reconnect: (name: string, token?: string) => Promise<void>;
|
|
704
|
-
/** Navigate to the server's authorization page. Call it from a user gesture. */
|
|
705
|
-
authorize: (name: string) => void;
|
|
706
|
-
/** Drop a server's stored OAuth tokens and registration. */
|
|
707
|
-
forgetAuthorization: (name: string) => Promise<void>;
|
|
708
|
-
}
|
|
709
|
-
/**
|
|
710
|
-
* Connect the browser agent to SEVERAL remote MCP servers at once, each with
|
|
711
|
-
* its own auth (none, a bearer token, or OAuth 2.1 + dynamic registration).
|
|
712
|
-
* Every server is its own connection — adding or removing one never touches
|
|
713
|
-
* the others — and their tools merge into one `tools` set, prefixed by server
|
|
714
|
-
* name. The list is remembered across reloads (tokens excepted), and an OAuth
|
|
715
|
-
* round-trip resumes on return.
|
|
716
|
-
*
|
|
717
|
-
* ```tsx
|
|
718
|
-
* const mcp = useMcpServers()
|
|
719
|
-
* // await mcp.add({ name: 'github', url, auth: 'oauth' })
|
|
720
|
-
* // await mcp.add({ name: 'docs', url, auth: 'bearer', token })
|
|
721
|
-
* const agent = useAgent({ model, tools: { ...local, ...mcp.tools } }, { deps: [mcp.tools] })
|
|
722
|
-
* ```
|
|
723
|
-
*
|
|
724
|
-
* With many servers the merged catalogue can reach hundreds of tools; the core
|
|
725
|
-
* switches to tool search above `toolSearchThreshold` automatically.
|
|
726
|
-
*/
|
|
727
|
-
declare const useMcpServers: (options?: UseMcpServersOptions) => UseMcpServersReturn;
|
|
728
|
-
|
|
729
468
|
/** An AI SDK `LanguageModel` (the type, via the core — no `ai` import here). */
|
|
730
469
|
type LanguageModel = Awaited<ReturnType<typeof createWebLLMModel>>;
|
|
731
470
|
/** Download / initialisation progress of a local model. */
|
|
@@ -1668,5 +1407,5 @@ interface ApiKeyFormProps {
|
|
|
1668
1407
|
*/
|
|
1669
1408
|
declare const ApiKeyForm: ({ credentials, credentialRef, label, placeholder, onChange, className, }: ApiKeyFormProps) => react.JSX.Element;
|
|
1670
1409
|
|
|
1671
|
-
export { AgentChat, AgentComposer, AgentLabelsProvider, AgentProvider, ApiKeyForm, ApprovalModeSwitch, AttachmentView, ChatHistoryList, ChatHistoryStore, Composer, ContextMeter, FilesPanel, MessageList, ModelLoadBar, PlanView, StepList, SubagentRow, ToolApprovalPrompt, ToolCallRow, UsageBadge, agentStateReducer, attachmentKindOf, attachmentRefusal, chatTitle,
|
|
1672
|
-
export type { AgentAction, AgentChatClassNames, AgentChatComponents, AgentChatProps, AgentChatSlots, AgentComposerProps, AgentLabels, AgentLabelsOverride, AgentLabelsProviderProps, AgentProviderProps, AgentStatus, AgentUiState, ApiKeyFormProps, ApprovalModeSwitchProps, ApprovalView, ApproveOptions, BudgetView, ChatAttachment, ChatHistoryListProps, ChatHistoryStoreOptions, ChatMessage, ChatRecord, ChatSummary, CompactionView, ComposerAttachment, ComposerModelChip, ComposerNotice, ComposerProps, ComposerThinkingChip,
|
|
1410
|
+
export { AgentChat, AgentComposer, AgentLabelsProvider, AgentProvider, ApiKeyForm, ApprovalModeSwitch, AttachmentView, ChatHistoryList, ChatHistoryStore, Composer, ContextMeter, FilesPanel, MessageList, ModelLoadBar, PlanView, StepList, SubagentRow, ToolApprovalPrompt, ToolCallRow, UsageBadge, agentStateReducer, attachmentKindOf, attachmentRefusal, chatTitle, createInitialAgentState, createWebLLMEngine, defaultLabels, downscaleImage, filterCommands, formatElapsed, mergeLabels, newChatId, noticesOf, parseSlash, usageLine, useAgent, useAgentContext, useChatHistory, useCredentials, useLabels, useLocalModel, useOptionalAgentContext, useSpeechToText, useVirtualFiles, useWebLLMModel, withAttachments };
|
|
1411
|
+
export type { AgentAction, AgentChatClassNames, AgentChatComponents, AgentChatProps, AgentChatSlots, AgentComposerProps, AgentLabels, AgentLabelsOverride, AgentLabelsProviderProps, AgentProviderProps, AgentStatus, AgentUiState, ApiKeyFormProps, ApprovalModeSwitchProps, ApprovalView, ApproveOptions, BudgetView, ChatAttachment, ChatHistoryListProps, ChatHistoryStoreOptions, ChatMessage, ChatRecord, ChatSummary, CompactionView, ComposerAttachment, ComposerModelChip, ComposerNotice, ComposerProps, ComposerThinkingChip, ContextMeterProps, ConvertedFile, DownscaleOptions, FilesPanelProps, LocalModelEngine, LocalModelLoadContext, LocalModelProgress, MessageListProps, ModelLoadBarProps, ModelLoadState, NoticeTexts, PlanViewProps, RenderToolCall, ReplanState, RunGoalOptions, SlashCommand, SpeechRecognizerLike, StepListProps, StepView, SubagentView, ToolApprovalPromptProps, ToolCallRowProps, ToolCallView, UsageBadgeProps, UseAgentOptions, UseAgentReturn, UseChatHistoryOptions, UseChatHistoryReturn, UseCredentialsReturn, UseLocalModelOptions, UseLocalModelReturn, UseSpeechToTextOptions, UseSpeechToTextReturn, UseVirtualFilesReturn, UseWebLLMModelOptions, UseWebLLMModelReturn, WebLLMModelFactory };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { DependencyList, ReactNode, RefObject, ComponentType, CSSProperties } from 'react';
|
|
3
|
-
import { IPlan, IPlanStep, IUsage, ReplanMode, AgentEvent, RunFile, RunResult, Agent, ToolApprovalMode, CompactResult, AgentEventHandler, BrowserAgentConfig, VirtualFileInfo, VirtualFileSystem, CredentialStore,
|
|
3
|
+
import { IPlan, IPlanStep, IUsage, ReplanMode, AgentEvent, RunFile, RunResult, Agent, ToolApprovalMode, CompactResult, AgentEventHandler, BrowserAgentConfig, VirtualFileInfo, VirtualFileSystem, CredentialStore, createWebLLMModel, WebLLMModelOptions } from '@dudko.dev/agent-web';
|
|
4
4
|
export { Agent, AgentEvent, AgentEventHandler, AgentLoggerSink, AgentTool, AgentToolSet, AttachmentsNotSupportedError, BrowserAgentConfig, CompactResult, CompactionConfig, CredentialStore, FileToolsOptions, IPlan, IPlanStep, IStepResult, IToolCall, IUsage, ImagesNotSupportedError, IndexedDBStore, LogLevel, MemoryCredentialStore, MemoryStore, ModelInput, ProviderModelSpec, ProviderType, RunFile, RunOptions, RunResult, Skill, SubagentToolOptions, SubagentWorkerConfig, ThinkingLevel, ThinkingSetting, TokenLimits, ToolApprovalConfig, ToolApprovalMode, ToolApprovalRequest, VaultCredentialStore, VirtualFile, VirtualFileInfo, VirtualFileSystem, createAgent, createFileTools, createSubagentTool, createWebLLMModel, defineSkill, defineTool, isWebGPUAvailable, loadSkillFromUrl, markReadOnly, parseSkillMarkdown, preloadWebLLMModel, serveSubagentWorker, supportsImages, supportsPdf, unloadWebLLMModel } from '@dudko.dev/agent-web';
|
|
5
5
|
|
|
6
6
|
/** Why a run stopped early (a `budget.exceeded` event). */
|
|
@@ -465,267 +465,6 @@ interface UseCredentialsReturn {
|
|
|
465
465
|
*/
|
|
466
466
|
declare const useCredentials: (store?: CredentialStore) => UseCredentialsReturn;
|
|
467
467
|
|
|
468
|
-
/**
|
|
469
|
-
* Structural types for the core's OPTIONAL `@dudko.dev/agent-web/mcp` subpath.
|
|
470
|
-
*
|
|
471
|
-
* The subpath is loaded with a dynamic import and typed here rather than
|
|
472
|
-
* imported, for two reasons: it drags in `@modelcontextprotocol/sdk` (an
|
|
473
|
-
* optional peer of the core, which apps without MCP must not have to install),
|
|
474
|
-
* and the OAuth half only exists in newer cores while this package supports
|
|
475
|
-
* `@dudko.dev/agent-web >= 0.0.6`. `useMcp` feature-detects at runtime and
|
|
476
|
-
* reports `oauthSupported: false` on an older core instead of crashing.
|
|
477
|
-
*/
|
|
478
|
-
interface McpCatalogEntry {
|
|
479
|
-
name: string;
|
|
480
|
-
description: string;
|
|
481
|
-
server: string;
|
|
482
|
-
/** The server marked the tool read-only (newer cores). */
|
|
483
|
-
readOnly?: boolean;
|
|
484
|
-
}
|
|
485
|
-
interface McpServerResult {
|
|
486
|
-
name: string;
|
|
487
|
-
connected: boolean;
|
|
488
|
-
error?: string;
|
|
489
|
-
needsAuthorization?: boolean;
|
|
490
|
-
}
|
|
491
|
-
interface ConnectedMcp {
|
|
492
|
-
tools: AgentToolSet;
|
|
493
|
-
catalog: McpCatalogEntry[];
|
|
494
|
-
results: McpServerResult[];
|
|
495
|
-
refreshServer?: (name: string) => Promise<void>;
|
|
496
|
-
close: () => Promise<void>;
|
|
497
|
-
}
|
|
498
|
-
interface McpHttpServerConfig {
|
|
499
|
-
url: string;
|
|
500
|
-
headers?: Record<string, string>;
|
|
501
|
-
authProvider?: unknown;
|
|
502
|
-
/** Per-server connect deadline (newer cores; ignored by older ones). */
|
|
503
|
-
connectTimeoutMs?: number;
|
|
504
|
-
}
|
|
505
|
-
interface McpOAuthCallback {
|
|
506
|
-
code?: string;
|
|
507
|
-
state?: string;
|
|
508
|
-
error?: string;
|
|
509
|
-
errorDescription?: string;
|
|
510
|
-
}
|
|
511
|
-
interface BrowserOAuthProvider {
|
|
512
|
-
serverUrl: string;
|
|
513
|
-
authorizationUrl?: URL;
|
|
514
|
-
isAuthorized(): Promise<boolean>;
|
|
515
|
-
reset(): Promise<void>;
|
|
516
|
-
}
|
|
517
|
-
interface BrowserOAuthProviderOptions {
|
|
518
|
-
serverUrl: string;
|
|
519
|
-
redirectUrl: string;
|
|
520
|
-
clientName?: string;
|
|
521
|
-
scope?: string;
|
|
522
|
-
}
|
|
523
|
-
/** The shape of the subpath module, as far as this package uses it. */
|
|
524
|
-
interface McpModule {
|
|
525
|
-
connectMcpHttp: (servers: Record<string, McpHttpServerConfig>, opts?: {
|
|
526
|
-
clientName?: string;
|
|
527
|
-
onLog?: (level: string, message: string) => void;
|
|
528
|
-
connectTimeoutMs?: number;
|
|
529
|
-
}) => Promise<ConnectedMcp>;
|
|
530
|
-
BrowserOAuthProvider?: new (opts: BrowserOAuthProviderOptions) => BrowserOAuthProvider;
|
|
531
|
-
readOAuthCallback?: (input?: string | URL) => McpOAuthCallback | undefined;
|
|
532
|
-
finishMcpOAuth?: (provider: BrowserOAuthProvider, callback: McpOAuthCallback) => Promise<void>;
|
|
533
|
-
/**
|
|
534
|
-
* The SDK's error class, re-exported by the core so an authorization failure
|
|
535
|
-
* can be recognised by identity. Absent on cores older than 0.0.12.
|
|
536
|
-
*/
|
|
537
|
-
UnauthorizedError?: new (message?: string) => Error;
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
type McpStatus = 'idle' | 'connecting' | 'connected' | 'needs-authorization' | 'error';
|
|
541
|
-
interface McpConnectOptions {
|
|
542
|
-
/** The server's StreamableHTTP endpoint. */
|
|
543
|
-
url: string;
|
|
544
|
-
/** Prefix for the discovered tool names ("<name>__<tool>"). Default 'mcp'. */
|
|
545
|
-
name?: string;
|
|
546
|
-
/** Static headers, e.g. `{ Authorization: 'Bearer …' }`. Ignored when `oauth` is set. */
|
|
547
|
-
headers?: Record<string, string>;
|
|
548
|
-
/**
|
|
549
|
-
* Authenticate with OAuth 2.1 + dynamic client registration. Requires a core
|
|
550
|
-
* that ships the OAuth provider; check `oauthSupported` before offering it.
|
|
551
|
-
*/
|
|
552
|
-
oauth?: boolean | {
|
|
553
|
-
redirectUrl?: string;
|
|
554
|
-
scope?: string;
|
|
555
|
-
clientName?: string;
|
|
556
|
-
};
|
|
557
|
-
}
|
|
558
|
-
interface UseMcpOptions {
|
|
559
|
-
/** Client name reported to the MCP server during initialize. */
|
|
560
|
-
clientName?: string;
|
|
561
|
-
/** Called with connector log lines — handy while debugging a server. */
|
|
562
|
-
onLog?: (level: string, message: string) => void;
|
|
563
|
-
}
|
|
564
|
-
interface UseMcpReturn {
|
|
565
|
-
status: McpStatus;
|
|
566
|
-
/** Merge into `BrowserAgentConfig.tools` once `status === 'connected'`. */
|
|
567
|
-
tools?: AgentToolSet;
|
|
568
|
-
catalog: McpCatalogEntry[];
|
|
569
|
-
error?: string;
|
|
570
|
-
/** Where to send the user when `status === 'needs-authorization'`. */
|
|
571
|
-
authorizationUrl?: string;
|
|
572
|
-
/**
|
|
573
|
-
* Whether the installed core exposes the OAuth API. `undefined` until the
|
|
574
|
-
* optional subpath has been loaded once — call `checkOAuthSupport()` to
|
|
575
|
-
* resolve it before offering OAuth in your UI.
|
|
576
|
-
*/
|
|
577
|
-
oauthSupported?: boolean;
|
|
578
|
-
/** True while an OAuth redirect is being finished on mount. */
|
|
579
|
-
completingAuthorization: boolean;
|
|
580
|
-
connect: (options: McpConnectOptions) => Promise<void>;
|
|
581
|
-
disconnect: () => Promise<void>;
|
|
582
|
-
/** Navigate to the authorization server. Call it from a user gesture. */
|
|
583
|
-
authorize: () => void;
|
|
584
|
-
/** Drop the stored tokens and dynamic registration for the current server. */
|
|
585
|
-
forgetAuthorization: () => Promise<void>;
|
|
586
|
-
/** Load the optional subpath and report whether it can do OAuth. */
|
|
587
|
-
checkOAuthSupport: () => Promise<boolean>;
|
|
588
|
-
}
|
|
589
|
-
/** Map a single server's connect outcome onto the hook's status. Pure. */
|
|
590
|
-
declare const describeMcpResult: (result: McpServerResult | undefined) => {
|
|
591
|
-
status: McpStatus;
|
|
592
|
-
error?: string;
|
|
593
|
-
};
|
|
594
|
-
/**
|
|
595
|
-
* Read the authorization-code parameters out of a URL **synchronously**.
|
|
596
|
-
*
|
|
597
|
-
* The core exports an equivalent, but it lives behind a dynamic import: by the
|
|
598
|
-
* time that import resolves, React has flushed the rest of the app's effects,
|
|
599
|
-
* and any one of them may have rewritten `location` (the demo's own view
|
|
600
|
-
* router did exactly that). The callback has to be captured before the first
|
|
601
|
-
* await, so this parser is duplicated here on purpose.
|
|
602
|
-
*
|
|
603
|
-
* Reads the query string and, for hash-routed apps, the fragment. Returns
|
|
604
|
-
* undefined when neither a `code` nor an `error` is present.
|
|
605
|
-
*/
|
|
606
|
-
declare const readCallbackParams: (href?: string) => McpOAuthCallback | undefined;
|
|
607
|
-
/**
|
|
608
|
-
* Remove the OAuth response parameters from a URL, leaving the rest intact —
|
|
609
|
-
* query string and fragment alike. The code is single-use and lands in history,
|
|
610
|
-
* referrers and screenshots, so it goes as soon as it has been read.
|
|
611
|
-
*/
|
|
612
|
-
declare const stripOAuthParams: (href: string) => string;
|
|
613
|
-
declare const claimOAuthCallback: (callback: McpOAuthCallback) => boolean;
|
|
614
|
-
/**
|
|
615
|
-
* Did this error come from the server refusing our authorization?
|
|
616
|
-
*
|
|
617
|
-
* Identity, not strings: the SDK's `UnauthorizedError` never assigns
|
|
618
|
-
* `this.name` (so it reads as "Error"), and its message would also match a
|
|
619
|
-
* tool whose own error text mentions "unauthorized" — the connector throws a
|
|
620
|
-
* failing tool's text verbatim. The class is re-exported by the core's `./mcp`
|
|
621
|
-
* subpath for exactly this; `constructor.name` is the fallback for a core too
|
|
622
|
-
* old to export it.
|
|
623
|
-
*/
|
|
624
|
-
declare const isUnauthorizedError: (err: unknown, mod?: McpModule) => boolean;
|
|
625
|
-
/**
|
|
626
|
-
* Connect the browser agent to a remote MCP server the user names at runtime —
|
|
627
|
-
* static header, or full OAuth 2.1 with dynamic client registration.
|
|
628
|
-
*
|
|
629
|
-
* The OAuth round-trip leaves the page, so the hook persists what it needs to
|
|
630
|
-
* resume: on mount it detects `?code=…`, finishes the exchange, cleans the URL
|
|
631
|
-
* and reconnects, all before the app renders anything MCP-related.
|
|
632
|
-
*
|
|
633
|
-
* ```tsx
|
|
634
|
-
* const mcp = useMcp()
|
|
635
|
-
* // await mcp.connect({ url, oauth: true })
|
|
636
|
-
* // mcp.status === 'needs-authorization' && <button onClick={mcp.authorize}>Authorize</button>
|
|
637
|
-
* // <AgentProvider config={{ model, tools: { ...local, ...mcp.tools } }}>
|
|
638
|
-
* ```
|
|
639
|
-
*/
|
|
640
|
-
declare const useMcp: (options?: UseMcpOptions) => UseMcpReturn;
|
|
641
|
-
|
|
642
|
-
type McpAuthMode = 'none' | 'bearer' | 'oauth';
|
|
643
|
-
/** One server the user wants connected. */
|
|
644
|
-
interface McpServerSpec {
|
|
645
|
-
/**
|
|
646
|
-
* Unique name; also the tool prefix ("<name>__<tool>"). Sanitised to
|
|
647
|
-
* `[a-zA-Z0-9_-]`; a taken name gets a numeric suffix.
|
|
648
|
-
*/
|
|
649
|
-
name: string;
|
|
650
|
-
/** The server's StreamableHTTP endpoint. */
|
|
651
|
-
url: string;
|
|
652
|
-
auth?: McpAuthMode;
|
|
653
|
-
/** Bearer token for `auth: 'bearer'` — kept in memory only, never persisted. */
|
|
654
|
-
token?: string;
|
|
655
|
-
/** OAuth details for `auth: 'oauth'`. */
|
|
656
|
-
oauth?: {
|
|
657
|
-
redirectUrl?: string;
|
|
658
|
-
scope?: string;
|
|
659
|
-
clientName?: string;
|
|
660
|
-
};
|
|
661
|
-
}
|
|
662
|
-
/** A server's live state. */
|
|
663
|
-
interface McpServerView {
|
|
664
|
-
name: string;
|
|
665
|
-
url: string;
|
|
666
|
-
auth: McpAuthMode;
|
|
667
|
-
status: McpStatus;
|
|
668
|
-
error?: string;
|
|
669
|
-
/** Where to send the user when `status === 'needs-authorization'`. */
|
|
670
|
-
authorizationUrl?: string;
|
|
671
|
-
catalog: McpCatalogEntry[];
|
|
672
|
-
}
|
|
673
|
-
interface UseMcpServersOptions extends UseMcpOptions {
|
|
674
|
-
/**
|
|
675
|
-
* Remember the server list (never tokens) in localStorage so it survives a
|
|
676
|
-
* reload — and the OAuth redirect, which IS a reload (default true).
|
|
677
|
-
*/
|
|
678
|
-
persist?: boolean;
|
|
679
|
-
/** localStorage key of the list (default 'agent-web-react:mcp-servers'). */
|
|
680
|
-
storageKey?: string;
|
|
681
|
-
/** Reconnect remembered servers on mount (default true). Bearer servers wait for their token. */
|
|
682
|
-
autoConnect?: boolean;
|
|
683
|
-
/** Per-server connect deadline in ms (default: the core's, 30 s). */
|
|
684
|
-
connectTimeoutMs?: number;
|
|
685
|
-
}
|
|
686
|
-
interface UseMcpServersReturn {
|
|
687
|
-
servers: McpServerView[];
|
|
688
|
-
/** Tools of every connected server, merged — pass to `BrowserAgentConfig.tools`. */
|
|
689
|
-
tools: AgentToolSet;
|
|
690
|
-
/** Catalogue of every connected server, merged. */
|
|
691
|
-
catalog: McpCatalogEntry[];
|
|
692
|
-
connectedCount: number;
|
|
693
|
-
/** True while an OAuth redirect is being finished on mount. */
|
|
694
|
-
completingAuthorization: boolean;
|
|
695
|
-
/** Whether the installed core can do OAuth (undefined until checked). */
|
|
696
|
-
oauthSupported?: boolean;
|
|
697
|
-
checkOAuthSupport: () => Promise<boolean>;
|
|
698
|
-
/** Add (or replace, by name) a server and connect it. Resolves with the final name. */
|
|
699
|
-
add: (spec: McpServerSpec) => Promise<string>;
|
|
700
|
-
/** Disconnect and forget a server. */
|
|
701
|
-
remove: (name: string) => Promise<void>;
|
|
702
|
-
/** Connect again — optionally with a fresh bearer token. */
|
|
703
|
-
reconnect: (name: string, token?: string) => Promise<void>;
|
|
704
|
-
/** Navigate to the server's authorization page. Call it from a user gesture. */
|
|
705
|
-
authorize: (name: string) => void;
|
|
706
|
-
/** Drop a server's stored OAuth tokens and registration. */
|
|
707
|
-
forgetAuthorization: (name: string) => Promise<void>;
|
|
708
|
-
}
|
|
709
|
-
/**
|
|
710
|
-
* Connect the browser agent to SEVERAL remote MCP servers at once, each with
|
|
711
|
-
* its own auth (none, a bearer token, or OAuth 2.1 + dynamic registration).
|
|
712
|
-
* Every server is its own connection — adding or removing one never touches
|
|
713
|
-
* the others — and their tools merge into one `tools` set, prefixed by server
|
|
714
|
-
* name. The list is remembered across reloads (tokens excepted), and an OAuth
|
|
715
|
-
* round-trip resumes on return.
|
|
716
|
-
*
|
|
717
|
-
* ```tsx
|
|
718
|
-
* const mcp = useMcpServers()
|
|
719
|
-
* // await mcp.add({ name: 'github', url, auth: 'oauth' })
|
|
720
|
-
* // await mcp.add({ name: 'docs', url, auth: 'bearer', token })
|
|
721
|
-
* const agent = useAgent({ model, tools: { ...local, ...mcp.tools } }, { deps: [mcp.tools] })
|
|
722
|
-
* ```
|
|
723
|
-
*
|
|
724
|
-
* With many servers the merged catalogue can reach hundreds of tools; the core
|
|
725
|
-
* switches to tool search above `toolSearchThreshold` automatically.
|
|
726
|
-
*/
|
|
727
|
-
declare const useMcpServers: (options?: UseMcpServersOptions) => UseMcpServersReturn;
|
|
728
|
-
|
|
729
468
|
/** An AI SDK `LanguageModel` (the type, via the core — no `ai` import here). */
|
|
730
469
|
type LanguageModel = Awaited<ReturnType<typeof createWebLLMModel>>;
|
|
731
470
|
/** Download / initialisation progress of a local model. */
|
|
@@ -1668,5 +1407,5 @@ interface ApiKeyFormProps {
|
|
|
1668
1407
|
*/
|
|
1669
1408
|
declare const ApiKeyForm: ({ credentials, credentialRef, label, placeholder, onChange, className, }: ApiKeyFormProps) => react.JSX.Element;
|
|
1670
1409
|
|
|
1671
|
-
export { AgentChat, AgentComposer, AgentLabelsProvider, AgentProvider, ApiKeyForm, ApprovalModeSwitch, AttachmentView, ChatHistoryList, ChatHistoryStore, Composer, ContextMeter, FilesPanel, MessageList, ModelLoadBar, PlanView, StepList, SubagentRow, ToolApprovalPrompt, ToolCallRow, UsageBadge, agentStateReducer, attachmentKindOf, attachmentRefusal, chatTitle,
|
|
1672
|
-
export type { AgentAction, AgentChatClassNames, AgentChatComponents, AgentChatProps, AgentChatSlots, AgentComposerProps, AgentLabels, AgentLabelsOverride, AgentLabelsProviderProps, AgentProviderProps, AgentStatus, AgentUiState, ApiKeyFormProps, ApprovalModeSwitchProps, ApprovalView, ApproveOptions, BudgetView, ChatAttachment, ChatHistoryListProps, ChatHistoryStoreOptions, ChatMessage, ChatRecord, ChatSummary, CompactionView, ComposerAttachment, ComposerModelChip, ComposerNotice, ComposerProps, ComposerThinkingChip,
|
|
1410
|
+
export { AgentChat, AgentComposer, AgentLabelsProvider, AgentProvider, ApiKeyForm, ApprovalModeSwitch, AttachmentView, ChatHistoryList, ChatHistoryStore, Composer, ContextMeter, FilesPanel, MessageList, ModelLoadBar, PlanView, StepList, SubagentRow, ToolApprovalPrompt, ToolCallRow, UsageBadge, agentStateReducer, attachmentKindOf, attachmentRefusal, chatTitle, createInitialAgentState, createWebLLMEngine, defaultLabels, downscaleImage, filterCommands, formatElapsed, mergeLabels, newChatId, noticesOf, parseSlash, usageLine, useAgent, useAgentContext, useChatHistory, useCredentials, useLabels, useLocalModel, useOptionalAgentContext, useSpeechToText, useVirtualFiles, useWebLLMModel, withAttachments };
|
|
1411
|
+
export type { AgentAction, AgentChatClassNames, AgentChatComponents, AgentChatProps, AgentChatSlots, AgentComposerProps, AgentLabels, AgentLabelsOverride, AgentLabelsProviderProps, AgentProviderProps, AgentStatus, AgentUiState, ApiKeyFormProps, ApprovalModeSwitchProps, ApprovalView, ApproveOptions, BudgetView, ChatAttachment, ChatHistoryListProps, ChatHistoryStoreOptions, ChatMessage, ChatRecord, ChatSummary, CompactionView, ComposerAttachment, ComposerModelChip, ComposerNotice, ComposerProps, ComposerThinkingChip, ContextMeterProps, ConvertedFile, DownscaleOptions, FilesPanelProps, LocalModelEngine, LocalModelLoadContext, LocalModelProgress, MessageListProps, ModelLoadBarProps, ModelLoadState, NoticeTexts, PlanViewProps, RenderToolCall, ReplanState, RunGoalOptions, SlashCommand, SpeechRecognizerLike, StepListProps, StepView, SubagentView, ToolApprovalPromptProps, ToolCallRowProps, ToolCallView, UsageBadgeProps, UseAgentOptions, UseAgentReturn, UseChatHistoryOptions, UseChatHistoryReturn, UseCredentialsReturn, UseLocalModelOptions, UseLocalModelReturn, UseSpeechToTextOptions, UseSpeechToTextReturn, UseVirtualFilesReturn, UseWebLLMModelOptions, UseWebLLMModelReturn, WebLLMModelFactory };
|