@tanstack/ai-react 0.23.0 → 0.24.0

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.
@@ -4,6 +4,8 @@ export { useByok } from './use-byok.js';
4
4
  export { useRealtimeChat } from './use-realtime-chat.js';
5
5
  export { useMcpAppBridge } from './use-mcp-app-bridge.js';
6
6
  export type { UseMcpAppBridgeOptions } from './use-mcp-app-bridge.js';
7
+ export { useWebMCPTools } from './use-web-mcp-tools.js';
8
+ export type { UseWebMCPToolsOptions } from './use-web-mcp-tools.js';
7
9
  export type { DeepPartial, UseChatOptions, UseChatReturn, UIMessage, ChatRequestBody, QueuedMessage, SendMessageOptions, WhenBusy, QueueConfig, QueueStrategy, QueueOption, } from './types.js';
8
10
  export type { UseRealtimeChatOptions, UseRealtimeChatReturn, } from './realtime-types.js';
9
11
  export { useGeneration } from './use-generation.js';
package/dist/esm/index.js CHANGED
@@ -3,6 +3,7 @@ import { createChatHook } from "./create-chat-hook.js";
3
3
  import { useByok } from "./use-byok.js";
4
4
  import { useRealtimeChat } from "./use-realtime-chat.js";
5
5
  import { useMcpAppBridge } from "./use-mcp-app-bridge.js";
6
+ import { useWebMCPTools } from "./use-web-mcp-tools.js";
6
7
  import { useGeneration } from "./use-generation.js";
7
8
  import { useGenerateImage } from "./use-generate-image.js";
8
9
  import { useGenerateAudio } from "./use-generate-audio.js";
@@ -12,4 +13,4 @@ import { useSummarize } from "./use-summarize.js";
12
13
  import { useGenerateVideo } from "./use-generate-video.js";
13
14
  import { useAudioRecorder } from "./use-audio-recorder.js";
14
15
  import { StorageUnavailableError, createChatClientOptions, createMcpAppBridge, fetchHttpStream, fetchServerSentEvents, indexedDBPersistence, localStoragePersistence, rpcStream, sessionStoragePersistence, stream, webSocket, xhrHttpStream, xhrServerSentEvents } from "@tanstack/ai-client";
15
- export { StorageUnavailableError, createChatClientOptions, createChatHook, createMcpAppBridge, fetchHttpStream, fetchServerSentEvents, indexedDBPersistence, localStoragePersistence, rpcStream, sessionStoragePersistence, stream, useAudioRecorder, useByok, useChat, useGenerateAudio, useGenerateImage, useGenerateSpeech, useGenerateVideo, useGeneration, useMcpAppBridge, useRealtimeChat, useSummarize, useTranscription, webSocket, xhrHttpStream, xhrServerSentEvents };
16
+ export { StorageUnavailableError, createChatClientOptions, createChatHook, createMcpAppBridge, fetchHttpStream, fetchServerSentEvents, indexedDBPersistence, localStoragePersistence, rpcStream, sessionStoragePersistence, stream, useAudioRecorder, useByok, useChat, useGenerateAudio, useGenerateImage, useGenerateSpeech, useGenerateVideo, useGeneration, useMcpAppBridge, useRealtimeChat, useSummarize, useTranscription, useWebMCPTools, webSocket, xhrHttpStream, xhrServerSentEvents };
@@ -0,0 +1,27 @@
1
+ import { AnyClientTool, InferredClientContext, RegisterWebMCPToolsOptions } from '@tanstack/ai-client';
2
+ /** Options for the React {@link useWebMCPTools} lifecycle hook. */
3
+ export type UseWebMCPToolsOptions<TTools extends ReadonlyArray<AnyClientTool>, TContext = InferredClientContext<TTools>> = Omit<RegisterWebMCPToolsOptions<TTools, TContext>, 'signal'> & {
4
+ /** Receives an asynchronous registration failure. */
5
+ onError?: (error: unknown) => void;
6
+ };
7
+ type UseWebMCPToolsArguments<TTools extends ReadonlyArray<AnyClientTool>, TContext> = RegisterWebMCPToolsOptions<TTools, TContext> extends {
8
+ context: unknown;
9
+ } ? [options: UseWebMCPToolsOptions<TTools, TContext>] : [options?: UseWebMCPToolsOptions<TTools, TContext>];
10
+ /**
11
+ * Registers client tools with WebMCP for the lifetime of a React component.
12
+ *
13
+ * The hook replaces the registration when `tools` or `options` changes.
14
+ * Unsupported browsers and server rendering do not register tools.
15
+ *
16
+ * @param tools - The executable client tools to expose through WebMCP.
17
+ * @param options - Runtime context, per-tool options, and an error callback.
18
+ *
19
+ * @example
20
+ * ```tsx
21
+ * useWebMCPTools([searchProducts], {
22
+ * toolOptions: { searchProducts: { title: 'Search products' } },
23
+ * })
24
+ * ```
25
+ */
26
+ export declare function useWebMCPTools<const TTools extends ReadonlyArray<AnyClientTool>, TContext = InferredClientContext<TTools>>(tools: TTools, ...[options]: UseWebMCPToolsArguments<TTools, TContext>): void;
27
+ export {};
@@ -0,0 +1,36 @@
1
+ import { registerWebMCPTools } from "@tanstack/ai-client";
2
+ import { useEffect } from "react";
3
+ //#region src/use-web-mcp-tools.ts
4
+ /**
5
+ * Registers client tools with WebMCP for the lifetime of a React component.
6
+ *
7
+ * The hook replaces the registration when `tools` or `options` changes.
8
+ * Unsupported browsers and server rendering do not register tools.
9
+ *
10
+ * @param tools - The executable client tools to expose through WebMCP.
11
+ * @param options - Runtime context, per-tool options, and an error callback.
12
+ *
13
+ * @example
14
+ * ```tsx
15
+ * useWebMCPTools([searchProducts], {
16
+ * toolOptions: { searchProducts: { title: 'Search products' } },
17
+ * })
18
+ * ```
19
+ */
20
+ function useWebMCPTools(tools, ...[options]) {
21
+ useEffect(() => {
22
+ const controller = new AbortController();
23
+ const { onError, ...registrationOptions } = options ?? {};
24
+ registerWebMCPTools(tools, {
25
+ ...registrationOptions,
26
+ signal: controller.signal
27
+ }).catch((error) => {
28
+ if (!controller.signal.aborted) onError?.(error);
29
+ });
30
+ return () => controller.abort();
31
+ }, [tools, options]);
32
+ }
33
+ //#endregion
34
+ export { useWebMCPTools };
35
+
36
+ //# sourceMappingURL=use-web-mcp-tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-web-mcp-tools.js","names":[],"sources":["../../src/use-web-mcp-tools.ts"],"sourcesContent":["import { useEffect } from 'react'\nimport { registerWebMCPTools } from '@tanstack/ai-client'\nimport type {\n AnyClientTool,\n InferredClientContext,\n RegisterWebMCPToolsOptions,\n} from '@tanstack/ai-client'\n\n/** Options for the React {@link useWebMCPTools} lifecycle hook. */\nexport type UseWebMCPToolsOptions<\n TTools extends ReadonlyArray<AnyClientTool>,\n TContext = InferredClientContext<TTools>,\n> = Omit<RegisterWebMCPToolsOptions<TTools, TContext>, 'signal'> & {\n /** Receives an asynchronous registration failure. */\n onError?: (error: unknown) => void\n}\n\ntype UseWebMCPToolsArguments<\n TTools extends ReadonlyArray<AnyClientTool>,\n TContext,\n> =\n RegisterWebMCPToolsOptions<TTools, TContext> extends { context: unknown }\n ? [options: UseWebMCPToolsOptions<TTools, TContext>]\n : [options?: UseWebMCPToolsOptions<TTools, TContext>]\n\n/**\n * Registers client tools with WebMCP for the lifetime of a React component.\n *\n * The hook replaces the registration when `tools` or `options` changes.\n * Unsupported browsers and server rendering do not register tools.\n *\n * @param tools - The executable client tools to expose through WebMCP.\n * @param options - Runtime context, per-tool options, and an error callback.\n *\n * @example\n * ```tsx\n * useWebMCPTools([searchProducts], {\n * toolOptions: { searchProducts: { title: 'Search products' } },\n * })\n * ```\n */\nexport function useWebMCPTools<\n const TTools extends ReadonlyArray<AnyClientTool>,\n TContext = InferredClientContext<TTools>,\n>(tools: TTools, ...[options]: UseWebMCPToolsArguments<TTools, TContext>) {\n useEffect(() => {\n const controller = new AbortController()\n const { onError, ...registrationOptions } = options ?? {}\n\n registerWebMCPTools(tools, {\n ...registrationOptions,\n signal: controller.signal,\n }).catch((error) => {\n if (!controller.signal.aborted) onError?.(error)\n })\n\n return () => controller.abort()\n }, [tools, options])\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAyCA,SAAgB,eAGd,OAAe,GAAG,CAAC,UAAqD;CACxE,gBAAgB;EACd,MAAM,aAAa,IAAI,gBAAgB;EACvC,MAAM,EAAE,SAAS,GAAG,wBAAwB,WAAW,CAAC;EAExD,oBAAoB,OAAO;GACzB,GAAG;GACH,QAAQ,WAAW;EACrB,CAAC,CAAC,CAAC,OAAO,UAAU;GAClB,IAAI,CAAC,WAAW,OAAO,SAAS,UAAU,KAAK;EACjD,CAAC;EAED,aAAa,WAAW,MAAM;CAChC,GAAG,CAAC,OAAO,OAAO,CAAC;AACrB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/ai-react",
3
- "version": "0.23.0",
3
+ "version": "0.24.0",
4
4
  "description": "React hooks for TanStack AI streaming chat, realtime voice, structured outputs, and media generation.",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -58,14 +58,14 @@
58
58
  "rehype-raw": "^7.0.0",
59
59
  "rehype-sanitize": "^6.0.0",
60
60
  "remark-gfm": "^4.0.1",
61
- "@tanstack/ai-client": "^0.30.0"
61
+ "@tanstack/ai-client": "^0.31.0"
62
62
  },
63
63
  "peerDependencies": {
64
64
  "@mcp-ui/client": "^7",
65
65
  "@types/react": ">=18.0.0",
66
66
  "react": ">=18.0.0",
67
67
  "react-dom": ">=18.0.0",
68
- "@tanstack/ai": "^0.52.1"
68
+ "@tanstack/ai": "^0.53.0"
69
69
  },
70
70
  "peerDependenciesMeta": {
71
71
  "@mcp-ui/client": {
@@ -85,7 +85,7 @@
85
85
  "react": "^19.2.3",
86
86
  "react-dom": "^19.2.3",
87
87
  "vite": "^8.2.1",
88
- "@tanstack/ai": "0.52.1"
88
+ "@tanstack/ai": "0.53.0"
89
89
  },
90
90
  "scripts": {
91
91
  "clean": "premove ./build ./dist",
package/src/index.ts CHANGED
@@ -4,6 +4,8 @@ export { useByok } from './use-byok'
4
4
  export { useRealtimeChat } from './use-realtime-chat'
5
5
  export { useMcpAppBridge } from './use-mcp-app-bridge'
6
6
  export type { UseMcpAppBridgeOptions } from './use-mcp-app-bridge'
7
+ export { useWebMCPTools } from './use-web-mcp-tools'
8
+ export type { UseWebMCPToolsOptions } from './use-web-mcp-tools'
7
9
  export type {
8
10
  DeepPartial,
9
11
  UseChatOptions,
@@ -0,0 +1,59 @@
1
+ import { useEffect } from 'react'
2
+ import { registerWebMCPTools } from '@tanstack/ai-client'
3
+ import type {
4
+ AnyClientTool,
5
+ InferredClientContext,
6
+ RegisterWebMCPToolsOptions,
7
+ } from '@tanstack/ai-client'
8
+
9
+ /** Options for the React {@link useWebMCPTools} lifecycle hook. */
10
+ export type UseWebMCPToolsOptions<
11
+ TTools extends ReadonlyArray<AnyClientTool>,
12
+ TContext = InferredClientContext<TTools>,
13
+ > = Omit<RegisterWebMCPToolsOptions<TTools, TContext>, 'signal'> & {
14
+ /** Receives an asynchronous registration failure. */
15
+ onError?: (error: unknown) => void
16
+ }
17
+
18
+ type UseWebMCPToolsArguments<
19
+ TTools extends ReadonlyArray<AnyClientTool>,
20
+ TContext,
21
+ > =
22
+ RegisterWebMCPToolsOptions<TTools, TContext> extends { context: unknown }
23
+ ? [options: UseWebMCPToolsOptions<TTools, TContext>]
24
+ : [options?: UseWebMCPToolsOptions<TTools, TContext>]
25
+
26
+ /**
27
+ * Registers client tools with WebMCP for the lifetime of a React component.
28
+ *
29
+ * The hook replaces the registration when `tools` or `options` changes.
30
+ * Unsupported browsers and server rendering do not register tools.
31
+ *
32
+ * @param tools - The executable client tools to expose through WebMCP.
33
+ * @param options - Runtime context, per-tool options, and an error callback.
34
+ *
35
+ * @example
36
+ * ```tsx
37
+ * useWebMCPTools([searchProducts], {
38
+ * toolOptions: { searchProducts: { title: 'Search products' } },
39
+ * })
40
+ * ```
41
+ */
42
+ export function useWebMCPTools<
43
+ const TTools extends ReadonlyArray<AnyClientTool>,
44
+ TContext = InferredClientContext<TTools>,
45
+ >(tools: TTools, ...[options]: UseWebMCPToolsArguments<TTools, TContext>) {
46
+ useEffect(() => {
47
+ const controller = new AbortController()
48
+ const { onError, ...registrationOptions } = options ?? {}
49
+
50
+ registerWebMCPTools(tools, {
51
+ ...registrationOptions,
52
+ signal: controller.signal,
53
+ }).catch((error) => {
54
+ if (!controller.signal.aborted) onError?.(error)
55
+ })
56
+
57
+ return () => controller.abort()
58
+ }, [tools, options])
59
+ }