@tanstack/ai-preact 0.14.3 → 0.15.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.
@@ -0,0 +1,47 @@
1
+ import { useChat as useUnboundChat } from './use-chat'
2
+ import type { AnyClientTool, InterruptDefinition } from '@tanstack/ai/client'
3
+ import type { InferredClientContext } from '@tanstack/ai-client'
4
+ import type { UseChatOptions } from './types'
5
+
6
+ type ChatHookOverrides<
7
+ TTools extends ReadonlyArray<AnyClientTool>,
8
+ TContext,
9
+ TInterrupts extends ReadonlyArray<InterruptDefinition<any, any, any, any>>,
10
+ > = {
11
+ threadId?: string
12
+ live?: boolean
13
+ forwardedProps?: Record<string, any>
14
+ body?: Record<string, any>
15
+ initialMessages?: UseChatOptions<
16
+ TTools,
17
+ TContext,
18
+ TInterrupts
19
+ >['initialMessages']
20
+ }
21
+
22
+ /**
23
+ * Bind chat options once at module scope. The returned `useChat` hook
24
+ * creates a chat instance from those options.
25
+ *
26
+ * Pass per-call overrides for instance keys such as `threadId`,
27
+ * `initialMessages`, `live`, and `forwardedProps`. Do not change `tools`,
28
+ * `interrupts`, or `outputSchema` here. Those stay on the factory options.
29
+ */
30
+ export function createChatHook<
31
+ const TTools extends ReadonlyArray<AnyClientTool> = any,
32
+ TContext = InferredClientContext<TTools>,
33
+ const TInterrupts extends ReadonlyArray<
34
+ InterruptDefinition<any, any, any, any>
35
+ > = readonly [],
36
+ >(options: UseChatOptions<TTools, TContext, TInterrupts>) {
37
+ function useChat(
38
+ overrides?: ChatHookOverrides<TTools, TContext, TInterrupts>,
39
+ ) {
40
+ if (!overrides) {
41
+ return useUnboundChat(options)
42
+ }
43
+ return useUnboundChat({ ...options, ...overrides })
44
+ }
45
+
46
+ return { useChat }
47
+ }
package/src/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { useChat } from './use-chat'
2
+ export { createChatHook } from './create-chat-hook'
2
3
  export { useByok } from './use-byok'
3
4
  export { useMcpAppBridge } from './use-mcp-app-bridge'
4
5
  export type { UseMcpAppBridgeOptions } from './use-mcp-app-bridge'
package/src/ui.ts ADDED
@@ -0,0 +1,20 @@
1
+ // Barrel entry for the `@tanstack/ai-preact/ui` subpath.
2
+ export {
3
+ createChatUI,
4
+ type ChatUIComponents,
5
+ type ChatUIFactoryConfig,
6
+ type ChatUIHost,
7
+ type ChatUIQueueItem,
8
+ type InputProps,
9
+ type InterruptProps,
10
+ type LayoutProps,
11
+ type MessageProps,
12
+ type PartProps,
13
+ type QueueProps,
14
+ type ToolProps,
15
+ } from './chat-ui/create-ui'
16
+ export { createChatHook } from './chat-ui/create-chat-hook'
17
+ export {
18
+ createChatHookContexts,
19
+ type ChatUIContexts,
20
+ } from './chat-ui/create-ui-contexts'