@tanstack/ai-octane 0.2.0 → 0.3.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.
package/README.md CHANGED
@@ -1,3 +1,23 @@
1
+ <div align="center">
2
+ <picture>
3
+ <source
4
+ media="(prefers-color-scheme: dark)"
5
+ srcset="https://tanstack.com/api/readme/ai.png?theme=dark"
6
+ />
7
+ <source
8
+ media="(prefers-color-scheme: light)"
9
+ srcset="https://tanstack.com/api/readme/ai.png"
10
+ />
11
+ <img
12
+ src="https://tanstack.com/api/readme/ai.png"
13
+ alt="TanStack AI"
14
+ width="900"
15
+ />
16
+ </picture>
17
+ </div>
18
+
19
+ <br />
20
+
1
21
  # @tanstack/ai-octane
2
22
 
3
23
  [TanStack AI](https://tanstack.com/ai) bindings for the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/ai-octane",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "description": "Octane bindings for TanStack AI streaming chat, structured outputs, and media generation.",
5
5
  "author": "Dominic Gannaway",
6
6
  "license": "MIT",
@@ -47,11 +47,11 @@
47
47
  ],
48
48
  "//lint": "The .tsrx.d.ts companions are generated declaration emits of the .tsrx implementations, so they are not hand-formatted and are excluded from lint rather than edited in place (a regeneration would undo any fix).",
49
49
  "dependencies": {
50
- "@tanstack/ai-client": "0.30.0"
50
+ "@tanstack/ai-client": "0.31.1"
51
51
  },
52
52
  "peerDependencies": {
53
53
  "octane": "^0.1.17",
54
- "@tanstack/ai": "^0.52.1"
54
+ "@tanstack/ai": "^0.54.0"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@octanejs/testing-library": "0.1.14",
@@ -62,7 +62,7 @@
62
62
  "octane": "0.1.17",
63
63
  "vite": "^8.2.1",
64
64
  "zod": "^4.2.0",
65
- "@tanstack/ai": "0.52.1"
65
+ "@tanstack/ai": "0.54.0"
66
66
  },
67
67
  "scripts": {
68
68
  "lint:fix": "oxlint src --type-aware --ignore-pattern '**/*.tsrx.d.ts' --fix",
package/src/index.ts CHANGED
@@ -3,6 +3,8 @@ export { createChatHook } from './create-chat-hook'
3
3
  export { useRealtimeChat } from './use-realtime-chat.tsrx'
4
4
  export { useMcpAppBridge } from './use-mcp-app-bridge.tsrx'
5
5
  export type { UseMcpAppBridgeOptions } from './use-mcp-app-bridge.tsrx'
6
+ export { useWebMCPTools } from './use-web-mcp-tools.tsrx'
7
+ export type { UseWebMCPToolsOptions } from './use-web-mcp-tools.tsrx'
6
8
  export type {
7
9
  DeepPartial,
8
10
  UseChatOptions,
@@ -0,0 +1,61 @@
1
+ import { useEffect } from 'octane'
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 Octane {@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
+ > = RegisterWebMCPToolsOptions<TTools, TContext> extends { context: unknown }
22
+ ? [options: UseWebMCPToolsOptions<TTools, TContext>]
23
+ : [options?: UseWebMCPToolsOptions<TTools, TContext>]
24
+
25
+ /**
26
+ * Registers client tools with WebMCP for the lifetime of an Octane component.
27
+ *
28
+ * The hook replaces the registration when `tools` or `options` changes.
29
+ * Unsupported browsers and server rendering do not register tools.
30
+ *
31
+ * @param tools - The executable client tools to expose through WebMCP.
32
+ * @param options - Runtime context, per-tool options, and an error callback.
33
+ *
34
+ * @example
35
+ * ```tsx
36
+ * useWebMCPTools([searchProducts], {
37
+ * toolOptions: { searchProducts: { title: 'Search products' } },
38
+ * })
39
+ * ```
40
+ */
41
+ export function useWebMCPTools<
42
+ const TTools extends ReadonlyArray<AnyClientTool>,
43
+ TContext = InferredClientContext<TTools>,
44
+ >(
45
+ tools: TTools,
46
+ ...[options]: UseWebMCPToolsArguments<TTools, TContext>
47
+ ) {
48
+ useEffect(() => {
49
+ const controller = new AbortController()
50
+ const { onError, ...registrationOptions } = options ?? {}
51
+
52
+ registerWebMCPTools(tools, {
53
+ ...registrationOptions,
54
+ signal: controller.signal,
55
+ }).catch((error) => {
56
+ if (!controller.signal.aborted) onError?.(error)
57
+ })
58
+
59
+ return () => controller.abort()
60
+ }, [tools, options])
61
+ }
@@ -0,0 +1,42 @@
1
+ // Declaration companion generated from use-web-mcp-tools.tsrx.
2
+ import type {
3
+ AnyClientTool,
4
+ InferredClientContext,
5
+ RegisterWebMCPToolsOptions,
6
+ } from '@tanstack/ai-client'
7
+
8
+ /** Options for the Octane {@link useWebMCPTools} lifecycle hook. */
9
+ export type UseWebMCPToolsOptions<
10
+ TTools extends ReadonlyArray<AnyClientTool>,
11
+ TContext = InferredClientContext<TTools>,
12
+ > = Omit<RegisterWebMCPToolsOptions<TTools, TContext>, 'signal'> & {
13
+ /** Receives an asynchronous registration failure. */
14
+ onError?: (error: unknown) => void
15
+ }
16
+ type UseWebMCPToolsArguments<
17
+ TTools extends ReadonlyArray<AnyClientTool>,
18
+ TContext,
19
+ > =
20
+ RegisterWebMCPToolsOptions<TTools, TContext> extends { context: unknown }
21
+ ? [options: UseWebMCPToolsOptions<TTools, TContext>]
22
+ : [options?: UseWebMCPToolsOptions<TTools, TContext>]
23
+ /**
24
+ * Registers client tools with WebMCP for the lifetime of an Octane component.
25
+ *
26
+ * The hook replaces the registration when `tools` or `options` changes.
27
+ * Unsupported browsers and server rendering do not register tools.
28
+ *
29
+ * @param tools - The executable client tools to expose through WebMCP.
30
+ * @param options - Runtime context, per-tool options, and an error callback.
31
+ *
32
+ * @example
33
+ * ```tsx
34
+ * useWebMCPTools([searchProducts], {
35
+ * toolOptions: { searchProducts: { title: 'Search products' } },
36
+ * })
37
+ * ```
38
+ */
39
+ export declare function useWebMCPTools<
40
+ const TTools extends ReadonlyArray<AnyClientTool>,
41
+ TContext = InferredClientContext<TTools>,
42
+ >(tools: TTools, ...[options]: UseWebMCPToolsArguments<TTools, TContext>): void