@tanstack/ai-preact 0.15.0 → 0.16.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.
package/dist/esm/index.d.ts
CHANGED
|
@@ -3,5 +3,7 @@ export { createChatHook } from './create-chat-hook.js';
|
|
|
3
3
|
export { useByok } from './use-byok.js';
|
|
4
4
|
export { useMcpAppBridge } from './use-mcp-app-bridge.js';
|
|
5
5
|
export type { UseMcpAppBridgeOptions } from './use-mcp-app-bridge.js';
|
|
6
|
+
export { useWebMCPTools } from './use-web-mcp-tools.js';
|
|
7
|
+
export type { UseWebMCPToolsOptions } from './use-web-mcp-tools.js';
|
|
6
8
|
export type { UseChatOptions, UseChatReturn, UIMessage, ChatRequestBody, QueuedMessage, SendMessageOptions, WhenBusy, QueueConfig, QueueStrategy, QueueOption, } from './types.js';
|
|
7
9
|
export { fetchServerSentEvents, localStoragePersistence, sessionStoragePersistence, indexedDBPersistence, StorageUnavailableError, type ChatClientPersistence, type ChatPersistedState, type ChatPersistenceOption, type ChatStorageAdapter, type WebStoragePersistenceOptions, type IndexedDBPersistenceOptions, fetchHttpStream, xhrServerSentEvents, xhrHttpStream, stream, rpcStream, createChatClientOptions, createMcpAppBridge, type McpAppBridge, type CreateMcpAppBridgeOptions, type ConnectionAdapter, type ConnectConnectionAdapter, type SubscribeConnectionAdapter, type RunAgentInputContext, type FetchConnectionOptions, type XhrConnectionOptions, type InferChatMessages, } from '@tanstack/ai-client';
|
package/dist/esm/index.js
CHANGED
|
@@ -2,5 +2,6 @@ import { useChat } from "./use-chat.js";
|
|
|
2
2
|
import { createChatHook } from "./create-chat-hook.js";
|
|
3
3
|
import { useByok } from "./use-byok.js";
|
|
4
4
|
import { useMcpAppBridge } from "./use-mcp-app-bridge.js";
|
|
5
|
+
import { useWebMCPTools } from "./use-web-mcp-tools.js";
|
|
5
6
|
import { StorageUnavailableError, createChatClientOptions, createMcpAppBridge, fetchHttpStream, fetchServerSentEvents, indexedDBPersistence, localStoragePersistence, rpcStream, sessionStoragePersistence, stream, xhrHttpStream, xhrServerSentEvents } from "@tanstack/ai-client";
|
|
6
|
-
export { StorageUnavailableError, createChatClientOptions, createChatHook, createMcpAppBridge, fetchHttpStream, fetchServerSentEvents, indexedDBPersistence, localStoragePersistence, rpcStream, sessionStoragePersistence, stream, useByok, useChat, useMcpAppBridge, xhrHttpStream, xhrServerSentEvents };
|
|
7
|
+
export { StorageUnavailableError, createChatClientOptions, createChatHook, createMcpAppBridge, fetchHttpStream, fetchServerSentEvents, indexedDBPersistence, localStoragePersistence, rpcStream, sessionStoragePersistence, stream, useByok, useChat, useMcpAppBridge, useWebMCPTools, xhrHttpStream, xhrServerSentEvents };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { AnyClientTool, InferredClientContext, RegisterWebMCPToolsOptions } from '@tanstack/ai-client';
|
|
2
|
+
/** Options for the Preact {@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 Preact 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 "preact/hooks";
|
|
3
|
+
//#region src/use-web-mcp-tools.ts
|
|
4
|
+
/**
|
|
5
|
+
* Registers client tools with WebMCP for the lifetime of a Preact 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 'preact/hooks'\nimport { registerWebMCPTools } from '@tanstack/ai-client'\nimport type {\n AnyClientTool,\n InferredClientContext,\n RegisterWebMCPToolsOptions,\n} from '@tanstack/ai-client'\n\n/** Options for the Preact {@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 Preact 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-preact",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"description": "Preact hooks for TanStack AI streaming chat and typed messages.",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"tool-calling"
|
|
51
51
|
],
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@tanstack/ai-client": "^0.
|
|
53
|
+
"@tanstack/ai-client": "^0.31.0"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@mcp-ui/client": "^7.1.1",
|
|
@@ -59,12 +59,12 @@
|
|
|
59
59
|
"jsdom": "^27.4.0",
|
|
60
60
|
"preact": "^10.26.9",
|
|
61
61
|
"vite": "^8.2.1",
|
|
62
|
-
"@tanstack/ai": "0.
|
|
62
|
+
"@tanstack/ai": "0.53.0"
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|
|
65
65
|
"@mcp-ui/client": "^7",
|
|
66
66
|
"preact": ">=10.11.0",
|
|
67
|
-
"@tanstack/ai": "^0.
|
|
67
|
+
"@tanstack/ai": "^0.53.0"
|
|
68
68
|
},
|
|
69
69
|
"peerDependenciesMeta": {
|
|
70
70
|
"@mcp-ui/client": {
|
package/src/index.ts
CHANGED
|
@@ -3,6 +3,8 @@ export { createChatHook } from './create-chat-hook'
|
|
|
3
3
|
export { useByok } from './use-byok'
|
|
4
4
|
export { useMcpAppBridge } from './use-mcp-app-bridge'
|
|
5
5
|
export type { UseMcpAppBridgeOptions } from './use-mcp-app-bridge'
|
|
6
|
+
export { useWebMCPTools } from './use-web-mcp-tools'
|
|
7
|
+
export type { UseWebMCPToolsOptions } from './use-web-mcp-tools'
|
|
6
8
|
export type {
|
|
7
9
|
UseChatOptions,
|
|
8
10
|
UseChatReturn,
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { useEffect } from 'preact/hooks'
|
|
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 Preact {@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 Preact 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
|
+
}
|