@tanstack/ai-svelte 0.23.3 → 0.24.1

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.
@@ -83,7 +83,7 @@ export declare function getUIContext<TOptions>(ui: UIDescriptor<TOptions>): {
83
83
  chat: ChatUIHost<TOptions>;
84
84
  components: ChatUIComponents<TOptions>;
85
85
  };
86
- export declare function readMessages<TOptions>(chat: ChatUIHost<TOptions>): UIMessage<ChatUIToolsOf<TOptions>, ChatUISchemaOf<TOptions> extends infer T ? T extends ChatUISchemaOf<TOptions> ? T extends import("@tanstack/ai").SchemaInput ? import("@tanstack/ai").InferSchemaType<T> : unknown : never : never>[];
86
+ export declare function readMessages<TOptions>(chat: ChatUIHost<TOptions>): UIMessage<ChatUIToolsOf<TOptions>, ChatUISchemaOf<TOptions> extends infer T ? T extends ChatUISchemaOf<TOptions> ? T extends import("@tanstack/ai").SchemaInput ? import("@tanstack/ai").InferSchemaType<T> : unknown : never : never, undefined>[];
87
87
  export declare function readInterrupts<TOptions>(chat: ChatUIHost<TOptions>): import("@tanstack/ai-client").BoundInterrupts<ChatUIToolsOf<TOptions>, ChatUIInterruptsOf<TOptions>>;
88
88
  export declare function readQueue<TOptions>(chat: ChatUIHost<TOptions>): {
89
89
  cancelQueued: () => void;
@@ -173,6 +173,18 @@ export function createChat(options) {
173
173
  }
174
174
  client.mountDevtools();
175
175
  if (typeof window !== 'undefined') {
176
+ try {
177
+ // Sync tools, so a getter such as `get tools() { return page.tools }`
178
+ // updates the client.
179
+ $effect.pre(() => {
180
+ const tools = options.tools;
181
+ if (tools !== undefined)
182
+ client.updateOptions({ tools });
183
+ });
184
+ }
185
+ catch {
186
+ // Effects are only valid during component initialization.
187
+ }
176
188
  try {
177
189
  onMount(() => {
178
190
  // Delivery-durability resume is transparent: the resumable SSE
@@ -1,10 +1,12 @@
1
- import type { AnyClientTool, InferredClientContext, RegisterWebMCPToolsOptions } from '@tanstack/ai-client';
2
- /** Options for {@link createWebMCPTools}. */
3
- export type CreateWebMCPToolsOptions<TTools extends ReadonlyArray<AnyClientTool>, TContext = InferredClientContext<TTools>> = Omit<RegisterWebMCPToolsOptions<TTools, TContext>, 'signal'> & {
1
+ import type { AnyClientTool, InferredClientContext, RegisterWebMCPToolsOptions, SubscribeWebMCPToolsOptions } from '@tanstack/ai-client';
2
+ /** Options for {@link createRegisterWebMCPTools}. */
3
+ export type CreateRegisterWebMCPToolsOptions<TTools extends ReadonlyArray<AnyClientTool>, TContext = InferredClientContext<TTools>> = Omit<RegisterWebMCPToolsOptions<TTools, TContext>, 'signal'> & {
4
4
  /** Receives an asynchronous registration error. */
5
5
  onError?: (error: unknown) => void;
6
6
  };
7
- type CreateWebMCPToolsArguments<TTools extends ReadonlyArray<AnyClientTool>, TContext> = {} extends CreateWebMCPToolsOptions<TTools, TContext> ? [options?: CreateWebMCPToolsOptions<TTools, TContext>] : [options: CreateWebMCPToolsOptions<TTools, TContext>];
7
+ /** @deprecated Use `CreateRegisterWebMCPToolsOptions`. Removed in 1.0.0. */
8
+ export type CreateWebMCPToolsOptions<TTools extends ReadonlyArray<AnyClientTool>, TContext = InferredClientContext<TTools>> = CreateRegisterWebMCPToolsOptions<TTools, TContext>;
9
+ type CreateRegisterWebMCPToolsArguments<TTools extends ReadonlyArray<AnyClientTool>, TContext> = {} extends CreateRegisterWebMCPToolsOptions<TTools, TContext> ? [options?: CreateRegisterWebMCPToolsOptions<TTools, TContext>] : [options: CreateRegisterWebMCPToolsOptions<TTools, TContext>];
8
10
  /**
9
11
  * Registers executable client tools with WebMCP for the current Svelte component.
10
12
  *
@@ -16,9 +18,44 @@ type CreateWebMCPToolsArguments<TTools extends ReadonlyArray<AnyClientTool>, TCo
16
18
  * @example
17
19
  * ```svelte
18
20
  * <script lang="ts">
19
- * createWebMCPTools([searchProducts])
21
+ * createRegisterWebMCPTools([searchProducts])
20
22
  * </script>
21
23
  * ```
22
24
  */
23
- export declare function createWebMCPTools<const TTools extends ReadonlyArray<AnyClientTool>, TContext = InferredClientContext<TTools>>(tools: TTools, ...[options]: CreateWebMCPToolsArguments<TTools, TContext>): void;
25
+ export declare function createRegisterWebMCPTools<const TTools extends ReadonlyArray<AnyClientTool>, TContext = InferredClientContext<TTools>>(tools: TTools, ...[options]: CreateRegisterWebMCPToolsArguments<TTools, TContext>): void;
26
+ /**
27
+ * @deprecated Use `createRegisterWebMCPTools`. Removed in 1.0.0.
28
+ * @alias
29
+ */
30
+ export declare const createWebMCPTools: typeof createRegisterWebMCPTools;
31
+ /** Options for {@link createPageWebMCPTools}. */
32
+ export type CreatePageWebMCPToolsOptions = Omit<SubscribeWebMCPToolsOptions, 'signal'>;
33
+ /**
34
+ * Reads the WebMCP tools on the page as client tools for `createChat`.
35
+ *
36
+ * `tools` starts empty and updates when the page registers or removes a tool.
37
+ * Component destruction stops the updates. Unsupported browsers and server
38
+ * rendering keep an empty array.
39
+ *
40
+ * @param options - A filter that skips tools, and an error callback.
41
+ *
42
+ * @example
43
+ * ```svelte
44
+ * <script lang="ts">
45
+ * const page = createPageWebMCPTools({
46
+ * filter: (tool) => tool.origin === location.origin,
47
+ * })
48
+ * const chat = createChat({
49
+ * connection,
50
+ * get tools() {
51
+ * return page.tools
52
+ * },
53
+ * })
54
+ * </script>
55
+ * ```
56
+ */
57
+ export declare function createPageWebMCPTools(options?: CreatePageWebMCPToolsOptions): {
58
+ /** The current page tools. */
59
+ readonly tools: AnyClientTool[];
60
+ };
24
61
  export {};
@@ -1,5 +1,5 @@
1
1
  import { onDestroy } from 'svelte';
2
- import { registerWebMCPTools } from '@tanstack/ai-client';
2
+ import { registerWebMCPTools, subscribeWebMCPTools } from '@tanstack/ai-client';
3
3
  /**
4
4
  * Registers executable client tools with WebMCP for the current Svelte component.
5
5
  *
@@ -11,11 +11,11 @@ import { registerWebMCPTools } from '@tanstack/ai-client';
11
11
  * @example
12
12
  * ```svelte
13
13
  * <script lang="ts">
14
- * createWebMCPTools([searchProducts])
14
+ * createRegisterWebMCPTools([searchProducts])
15
15
  * </script>
16
16
  * ```
17
17
  */
18
- export function createWebMCPTools(tools, ...[options]) {
18
+ export function createRegisterWebMCPTools(tools, ...[options]) {
19
19
  const controller = new AbortController();
20
20
  void registerWebMCPTools(tools, {
21
21
  ...options,
@@ -27,3 +27,48 @@ export function createWebMCPTools(tools, ...[options]) {
27
27
  });
28
28
  onDestroy(() => controller.abort());
29
29
  }
30
+ /**
31
+ * @deprecated Use `createRegisterWebMCPTools`. Removed in 1.0.0.
32
+ * @alias
33
+ */
34
+ export const createWebMCPTools = createRegisterWebMCPTools;
35
+ /**
36
+ * Reads the WebMCP tools on the page as client tools for `createChat`.
37
+ *
38
+ * `tools` starts empty and updates when the page registers or removes a tool.
39
+ * Component destruction stops the updates. Unsupported browsers and server
40
+ * rendering keep an empty array.
41
+ *
42
+ * @param options - A filter that skips tools, and an error callback.
43
+ *
44
+ * @example
45
+ * ```svelte
46
+ * <script lang="ts">
47
+ * const page = createPageWebMCPTools({
48
+ * filter: (tool) => tool.origin === location.origin,
49
+ * })
50
+ * const chat = createChat({
51
+ * connection,
52
+ * get tools() {
53
+ * return page.tools
54
+ * },
55
+ * })
56
+ * </script>
57
+ * ```
58
+ */
59
+ export function createPageWebMCPTools(options) {
60
+ let tools = $state.raw([]);
61
+ const controller = new AbortController();
62
+ subscribeWebMCPTools((nextTools) => (tools = nextTools), {
63
+ signal: controller.signal,
64
+ filter: (tool) => options?.filter?.(tool) ?? true,
65
+ onError: (error) => options?.onError?.(error),
66
+ });
67
+ onDestroy(() => controller.abort());
68
+ return {
69
+ /** The current page tools. */
70
+ get tools() {
71
+ return tools;
72
+ },
73
+ };
74
+ }
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  export { createChat } from './create-chat.svelte';
2
2
  export { createChatHook } from './create-chat-hook';
3
3
  export { createByok } from './create-byok.svelte';
4
- export { createWebMCPTools } from './create-web-mcp-tools.svelte';
5
- export type { CreateWebMCPToolsOptions } from './create-web-mcp-tools.svelte';
4
+ export { createPageWebMCPTools, createRegisterWebMCPTools, createWebMCPTools, } from './create-web-mcp-tools.svelte';
5
+ export type { CreatePageWebMCPToolsOptions, CreateRegisterWebMCPToolsOptions, CreateWebMCPToolsOptions, } from './create-web-mcp-tools.svelte';
6
6
  export type { CreateChatOptions, CreateChatReturn, DeepPartial, UIMessage, ChatRequestBody, QueuedMessage, SendMessageOptions, WhenBusy, QueueConfig, QueueStrategy, QueueOption, } from './types';
7
7
  export { createGeneration } from './create-generation.svelte';
8
8
  export type { CreateGenerationOptions, CreateGenerationReturn, } from './create-generation.svelte';
@@ -20,4 +20,4 @@ export { createGenerateVideo } from './create-generate-video.svelte';
20
20
  export type { CreateGenerateVideoOptions, CreateGenerateVideoReturn, } from './create-generate-video.svelte';
21
21
  export { createAudioRecorder } from './create-audio-recorder.svelte';
22
22
  export type { CreateAudioRecorderOptions, CreateAudioRecorderReturn, } from './create-audio-recorder.svelte';
23
- export { AudioRecorder, ChatClient, InterruptManager, RealtimeClient, GenerationClient, VideoGenerationClient, GENERATION_EVENTS, reconstructImageResult, reconstructAudioResult, reconstructSpeechResult, reconstructTranscriptionResult, reconstructSummarizeResult, UnsupportedResponseStreamError, createAIDevtoolsGenerationPreview, StreamTruncatedError, DurableStreamIncompleteError, StreamReconnectLimitError, uiMessageToModelMessages, modelMessageToUIMessage, modelMessagesToUIMessages, convertMessagesToModelMessages, normalizeToUIMessage, generateMessageId, StreamProcessor, ImmediateStrategy, PunctuationStrategy, BatchStrategy, WordBoundaryStrategy, CompositeStrategy, parsePartialJSON, PartialJSONParser, defaultJSONParser, registerWebMCPTools, createMcpAppBridge, type McpAppBridge, type CreateMcpAppBridgeOptions, fetchServerSentEvents, localStoragePersistence, sessionStoragePersistence, indexedDBPersistence, StorageUnavailableError, type ChatClientPersistence, type ChatPersistedState, type ChatPersistenceOption, type ChatStorageAdapter, type WebStoragePersistenceOptions, type IndexedDBPersistenceOptions, fetchHttpStream, xhrServerSentEvents, xhrHttpStream, stream, rpcStream, webSocket, createChatClientOptions, clientTools, type ConnectionAdapter, type ConnectConnectionAdapter, type SubscribeConnectionAdapter, type RunAgentInputContext, type FetchConnectionOptions, type XhrConnectionOptions, type WebSocketConnectionOptions, type InferChatMessages, type GenerationClientState, type ImageGenerateInput, type AudioGenerateInput, type SpeechGenerateInput, type TranscriptionGenerateInput, type SummarizeGenerateInput, type VideoGenerateInput, type VideoGenerateResult, type VideoStatusInfo, } from '@tanstack/ai-client';
23
+ export { AudioRecorder, ChatClient, InterruptManager, RealtimeClient, GenerationClient, VideoGenerationClient, GENERATION_EVENTS, reconstructImageResult, reconstructAudioResult, reconstructSpeechResult, reconstructTranscriptionResult, reconstructSummarizeResult, UnsupportedResponseStreamError, createAIDevtoolsGenerationPreview, StreamTruncatedError, DurableStreamIncompleteError, StreamReconnectLimitError, uiMessageToModelMessages, modelMessageToUIMessage, modelMessagesToUIMessages, convertMessagesToModelMessages, normalizeToUIMessage, generateMessageId, StreamProcessor, ImmediateStrategy, PunctuationStrategy, BatchStrategy, WordBoundaryStrategy, CompositeStrategy, parsePartialJSON, PartialJSONParser, defaultJSONParser, registerWebMCPTools, getWebMCPTools, subscribeWebMCPTools, type GetWebMCPToolsOptions, type SubscribeWebMCPToolsOptions, type WebMCPPageTool, createMcpAppBridge, type McpAppBridge, type CreateMcpAppBridgeOptions, fetchServerSentEvents, localStoragePersistence, sessionStoragePersistence, indexedDBPersistence, StorageUnavailableError, type ChatClientPersistence, type ChatPersistedState, type ChatPersistenceOption, type ChatStorageAdapter, type WebStoragePersistenceOptions, type IndexedDBPersistenceOptions, fetchHttpStream, xhrServerSentEvents, xhrHttpStream, stream, rpcStream, webSocket, createChatClientOptions, clientTools, type ConnectionAdapter, type ConnectConnectionAdapter, type SubscribeConnectionAdapter, type RunAgentInputContext, type FetchConnectionOptions, type XhrConnectionOptions, type WebSocketConnectionOptions, type InferChatMessages, type GenerationClientState, type ImageGenerateInput, type AudioGenerateInput, type SpeechGenerateInput, type TranscriptionGenerateInput, type SummarizeGenerateInput, type VideoGenerateInput, type VideoGenerateResult, type VideoStatusInfo, } from '@tanstack/ai-client';
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  export { createChat } from './create-chat.svelte';
2
2
  export { createChatHook } from './create-chat-hook';
3
3
  export { createByok } from './create-byok.svelte';
4
- export { createWebMCPTools } from './create-web-mcp-tools.svelte';
4
+ export { createPageWebMCPTools, createRegisterWebMCPTools, createWebMCPTools, } from './create-web-mcp-tools.svelte';
5
5
  // Generation hooks
6
6
  export { createGeneration } from './create-generation.svelte';
7
7
  export { createGenerateImage } from './create-generate-image.svelte';
@@ -12,4 +12,4 @@ export { createSummarize } from './create-summarize.svelte';
12
12
  export { createGenerateVideo } from './create-generate-video.svelte';
13
13
  export { createAudioRecorder } from './create-audio-recorder.svelte';
14
14
  // Re-export from ai-client for convenience
15
- export { AudioRecorder, ChatClient, InterruptManager, RealtimeClient, GenerationClient, VideoGenerationClient, GENERATION_EVENTS, reconstructImageResult, reconstructAudioResult, reconstructSpeechResult, reconstructTranscriptionResult, reconstructSummarizeResult, UnsupportedResponseStreamError, createAIDevtoolsGenerationPreview, StreamTruncatedError, DurableStreamIncompleteError, StreamReconnectLimitError, uiMessageToModelMessages, modelMessageToUIMessage, modelMessagesToUIMessages, convertMessagesToModelMessages, normalizeToUIMessage, generateMessageId, StreamProcessor, ImmediateStrategy, PunctuationStrategy, BatchStrategy, WordBoundaryStrategy, CompositeStrategy, parsePartialJSON, PartialJSONParser, defaultJSONParser, registerWebMCPTools, createMcpAppBridge, fetchServerSentEvents, localStoragePersistence, sessionStoragePersistence, indexedDBPersistence, StorageUnavailableError, fetchHttpStream, xhrServerSentEvents, xhrHttpStream, stream, rpcStream, webSocket, createChatClientOptions, clientTools, } from '@tanstack/ai-client';
15
+ export { AudioRecorder, ChatClient, InterruptManager, RealtimeClient, GenerationClient, VideoGenerationClient, GENERATION_EVENTS, reconstructImageResult, reconstructAudioResult, reconstructSpeechResult, reconstructTranscriptionResult, reconstructSummarizeResult, UnsupportedResponseStreamError, createAIDevtoolsGenerationPreview, StreamTruncatedError, DurableStreamIncompleteError, StreamReconnectLimitError, uiMessageToModelMessages, modelMessageToUIMessage, modelMessagesToUIMessages, convertMessagesToModelMessages, normalizeToUIMessage, generateMessageId, StreamProcessor, ImmediateStrategy, PunctuationStrategy, BatchStrategy, WordBoundaryStrategy, CompositeStrategy, parsePartialJSON, PartialJSONParser, defaultJSONParser, registerWebMCPTools, getWebMCPTools, subscribeWebMCPTools, createMcpAppBridge, fetchServerSentEvents, localStoragePersistence, sessionStoragePersistence, indexedDBPersistence, StorageUnavailableError, fetchHttpStream, xhrServerSentEvents, xhrHttpStream, stream, rpcStream, webSocket, createChatClientOptions, clientTools, } from '@tanstack/ai-client';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/ai-svelte",
3
- "version": "0.23.3",
3
+ "version": "0.24.1",
4
4
  "description": "Svelte 5 bindings for TanStack AI streaming chat, structured outputs, and media generation.",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -56,11 +56,11 @@
56
56
  "media-generation"
57
57
  ],
58
58
  "dependencies": {
59
- "@tanstack/ai-client": "^0.33.2"
59
+ "@tanstack/ai-client": "^0.35.1"
60
60
  },
61
61
  "peerDependencies": {
62
62
  "svelte": "^5.0.0",
63
- "@tanstack/ai": "^0.58.0"
63
+ "@tanstack/ai": "^0.61.0"
64
64
  },
65
65
  "devDependencies": {
66
66
  "@standard-schema/spec": "^1.1.0",
@@ -73,7 +73,7 @@
73
73
  "svelte-check": "^4.2.0",
74
74
  "typescript": "5.9.3",
75
75
  "vite": "^8.2.1",
76
- "@tanstack/ai": "0.58.0"
76
+ "@tanstack/ai": "0.61.0"
77
77
  },
78
78
  "scripts": {
79
79
  "clean": "rm -rf ./dist",
@@ -225,6 +225,16 @@ export function createChat<
225
225
  client.mountDevtools()
226
226
 
227
227
  if (typeof window !== 'undefined') {
228
+ try {
229
+ // Sync tools, so a getter such as `get tools() { return page.tools }`
230
+ // updates the client.
231
+ $effect.pre(() => {
232
+ const tools = options.tools
233
+ if (tools !== undefined) client.updateOptions({ tools })
234
+ })
235
+ } catch {
236
+ // Effects are only valid during component initialization.
237
+ }
228
238
  try {
229
239
  onMount(() => {
230
240
  // Delivery-durability resume is transparent: the resumable SSE
@@ -1,13 +1,14 @@
1
1
  import { onDestroy } from 'svelte'
2
- import { registerWebMCPTools } from '@tanstack/ai-client'
2
+ import { registerWebMCPTools, subscribeWebMCPTools } from '@tanstack/ai-client'
3
3
  import type {
4
4
  AnyClientTool,
5
5
  InferredClientContext,
6
6
  RegisterWebMCPToolsOptions,
7
+ SubscribeWebMCPToolsOptions,
7
8
  } from '@tanstack/ai-client'
8
9
 
9
- /** Options for {@link createWebMCPTools}. */
10
- export type CreateWebMCPToolsOptions<
10
+ /** Options for {@link createRegisterWebMCPTools}. */
11
+ export type CreateRegisterWebMCPToolsOptions<
11
12
  TTools extends ReadonlyArray<AnyClientTool>,
12
13
  TContext = InferredClientContext<TTools>,
13
14
  > = Omit<RegisterWebMCPToolsOptions<TTools, TContext>, 'signal'> & {
@@ -15,13 +16,19 @@ export type CreateWebMCPToolsOptions<
15
16
  onError?: (error: unknown) => void
16
17
  }
17
18
 
18
- type CreateWebMCPToolsArguments<
19
+ /** @deprecated Use `CreateRegisterWebMCPToolsOptions`. Removed in 1.0.0. */
20
+ export type CreateWebMCPToolsOptions<
21
+ TTools extends ReadonlyArray<AnyClientTool>,
22
+ TContext = InferredClientContext<TTools>,
23
+ > = CreateRegisterWebMCPToolsOptions<TTools, TContext>
24
+
25
+ type CreateRegisterWebMCPToolsArguments<
19
26
  TTools extends ReadonlyArray<AnyClientTool>,
20
27
  TContext,
21
28
  > =
22
- {} extends CreateWebMCPToolsOptions<TTools, TContext>
23
- ? [options?: CreateWebMCPToolsOptions<TTools, TContext>]
24
- : [options: CreateWebMCPToolsOptions<TTools, TContext>]
29
+ {} extends CreateRegisterWebMCPToolsOptions<TTools, TContext>
30
+ ? [options?: CreateRegisterWebMCPToolsOptions<TTools, TContext>]
31
+ : [options: CreateRegisterWebMCPToolsOptions<TTools, TContext>]
25
32
 
26
33
  /**
27
34
  * Registers executable client tools with WebMCP for the current Svelte component.
@@ -34,14 +41,17 @@ type CreateWebMCPToolsArguments<
34
41
  * @example
35
42
  * ```svelte
36
43
  * <script lang="ts">
37
- * createWebMCPTools([searchProducts])
44
+ * createRegisterWebMCPTools([searchProducts])
38
45
  * </script>
39
46
  * ```
40
47
  */
41
- export function createWebMCPTools<
48
+ export function createRegisterWebMCPTools<
42
49
  const TTools extends ReadonlyArray<AnyClientTool>,
43
50
  TContext = InferredClientContext<TTools>,
44
- >(tools: TTools, ...[options]: CreateWebMCPToolsArguments<TTools, TContext>) {
51
+ >(
52
+ tools: TTools,
53
+ ...[options]: CreateRegisterWebMCPToolsArguments<TTools, TContext>
54
+ ) {
45
55
  const controller = new AbortController()
46
56
 
47
57
  void registerWebMCPTools(tools, {
@@ -55,3 +65,58 @@ export function createWebMCPTools<
55
65
 
56
66
  onDestroy(() => controller.abort())
57
67
  }
68
+
69
+ /**
70
+ * @deprecated Use `createRegisterWebMCPTools`. Removed in 1.0.0.
71
+ * @alias
72
+ */
73
+ export const createWebMCPTools = createRegisterWebMCPTools
74
+
75
+ /** Options for {@link createPageWebMCPTools}. */
76
+ export type CreatePageWebMCPToolsOptions = Omit<
77
+ SubscribeWebMCPToolsOptions,
78
+ 'signal'
79
+ >
80
+
81
+ /**
82
+ * Reads the WebMCP tools on the page as client tools for `createChat`.
83
+ *
84
+ * `tools` starts empty and updates when the page registers or removes a tool.
85
+ * Component destruction stops the updates. Unsupported browsers and server
86
+ * rendering keep an empty array.
87
+ *
88
+ * @param options - A filter that skips tools, and an error callback.
89
+ *
90
+ * @example
91
+ * ```svelte
92
+ * <script lang="ts">
93
+ * const page = createPageWebMCPTools({
94
+ * filter: (tool) => tool.origin === location.origin,
95
+ * })
96
+ * const chat = createChat({
97
+ * connection,
98
+ * get tools() {
99
+ * return page.tools
100
+ * },
101
+ * })
102
+ * </script>
103
+ * ```
104
+ */
105
+ export function createPageWebMCPTools(options?: CreatePageWebMCPToolsOptions) {
106
+ let tools = $state.raw<Array<AnyClientTool>>([])
107
+ const controller = new AbortController()
108
+
109
+ subscribeWebMCPTools((nextTools) => (tools = nextTools), {
110
+ signal: controller.signal,
111
+ filter: (tool) => options?.filter?.(tool) ?? true,
112
+ onError: (error) => options?.onError?.(error),
113
+ })
114
+
115
+ onDestroy(() => controller.abort())
116
+ return {
117
+ /** The current page tools. */
118
+ get tools() {
119
+ return tools
120
+ },
121
+ }
122
+ }
package/src/index.ts CHANGED
@@ -1,8 +1,16 @@
1
1
  export { createChat } from './create-chat.svelte'
2
2
  export { createChatHook } from './create-chat-hook'
3
3
  export { createByok } from './create-byok.svelte'
4
- export { createWebMCPTools } from './create-web-mcp-tools.svelte'
5
- export type { CreateWebMCPToolsOptions } from './create-web-mcp-tools.svelte'
4
+ export {
5
+ createPageWebMCPTools,
6
+ createRegisterWebMCPTools,
7
+ createWebMCPTools,
8
+ } from './create-web-mcp-tools.svelte'
9
+ export type {
10
+ CreatePageWebMCPToolsOptions,
11
+ CreateRegisterWebMCPToolsOptions,
12
+ CreateWebMCPToolsOptions,
13
+ } from './create-web-mcp-tools.svelte'
6
14
  export type {
7
15
  CreateChatOptions,
8
16
  CreateChatReturn,
@@ -101,6 +109,11 @@ export {
101
109
  PartialJSONParser,
102
110
  defaultJSONParser,
103
111
  registerWebMCPTools,
112
+ getWebMCPTools,
113
+ subscribeWebMCPTools,
114
+ type GetWebMCPToolsOptions,
115
+ type SubscribeWebMCPToolsOptions,
116
+ type WebMCPPageTool,
104
117
  createMcpAppBridge,
105
118
  type McpAppBridge,
106
119
  type CreateMcpAppBridgeOptions,