@assistant-ui/react 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -1,6 +1,8 @@
1
- # `assistant-ui`
1
+ <a href="https://www.assistant-ui.com">
2
+ <img src="https://raw.githubusercontent.com/Yonom/assistant-ui/main/.github/assets/header.svg" alt="assistant-ui Header" width="100%" />
3
+ </a>
2
4
 
3
- `assistant-ui` is a set of React components for AI chat.
5
+ assistant-ui is a set of React components for AI chat.
4
6
 
5
7
  - [Discord](https://discord.gg/S9dwgCNEFs)
6
8
  - [Website](https://assistant-ui.com/)
@@ -10,105 +12,19 @@
10
12
 
11
13
  - [Documentation](https://www.assistant-ui.com/docs/getting-started)
12
14
 
13
- ## Starter Template
15
+ ## Quick Start
14
16
 
15
- ```
16
- npx assistant-ui@latest create
17
- ```
18
-
19
- ## Quick Start In Existing Project
20
- ![Demo of my project](demo.gif)
17
+ Step 1: Create a new project with `assistant-ui` pre-configured:
21
18
 
22
- ### PREREQUISITES:
23
- It is assumed that you have already installed and initialized node.js, tailwind, typescript, react, next.js. If not, follow the instructions:
24
- ```sh
25
- npx create-next-app@latest my-app --typescript --tailwind
26
- ```
27
19
  ```sh
20
+ npx assistant-ui@latest create my-app
28
21
  cd my-app
29
22
  ```
30
- ```sh
31
- npm install @ai-sdk/react @assistant-ui/react @assistant-ui/react-ai-sdk
32
- ```
33
- Install shadcn react components, follow instructins with default answers
34
- ```sh
35
- npx shadcn-ui init
36
- ```
37
-
38
- GETTING STARTED:
39
- ```sh
40
- npx assistant-ui@latest add modal
41
- ```
42
-
43
- Create/edit your desired page file:
44
- ```
45
- /src/app/pages.tsx
46
- ```
47
-
48
- ```tsx
49
- "use client";
50
-
51
- import { useChat } from "@ai-sdk/react";
52
- import { AssistantRuntimeProvider } from "@assistant-ui/react";
53
- import { useVercelUseChatRuntime } from "@assistant-ui/react-ai-sdk";
54
- import { AssistantModal } from "@/components/ui/assistant-ui/assistant-modal";
55
-
56
- const MyApp = () => {
57
- const chat = useChat({
58
- api: "/api/chat" // your backend route
59
- });
60
- const runtime = useVercelUseChatRuntime(chat);
61
-
62
- return (
63
- <AssistantRuntimeProvider runtime={runtime}>
64
- <AssistantModal />
65
- </AssistantRuntimeProvider>
66
- );
67
- }
68
-
69
- export default MyApp;
70
- ```
71
-
72
-
73
- ### Backend connection using Vercel AI SDK:
74
-
75
- ```sh
76
- npm install @ai-sdk/openai
77
- ```
78
-
79
- ```sh
80
- npm install @assistant-ui/react-hook-form
81
- ```
82
23
 
83
- Create backend route file:
84
- ```
85
- /src/app/api/chat/route.ts
86
- ```
24
+ Step 2: Update the `.env` file with your OpenAI API key.
87
25
 
88
- ```tsx
89
- import { openai } from '@ai-sdk/openai';
90
- import { streamText } from 'ai';
91
-
92
- export const maxDuration = 30;
93
-
94
- export async function POST(req: Request) {
95
- const { messages } = await req.json();
96
-
97
- const result = await streamText({
98
- model: openai('gpt-4o'),
99
- messages,
100
- });
101
-
102
- return result.toAIStreamResponse();
103
- }
104
- ```
105
-
106
- ```sh
107
- export OPENAI_API_KEY="skXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
108
- ```
26
+ Step 3: Run the app:
109
27
 
110
28
  ```sh
111
29
  npm run dev
112
30
  ```
113
-
114
- Now Open: [http://localhost:3000](http://localhost:3000)
@@ -80,15 +80,18 @@ type ModelConfigProvider = () => ModelConfig;
80
80
 
81
81
  type Unsubscribe = () => void;
82
82
 
83
- type ThreadState = {
83
+ type ThreadState = Readonly<{
84
84
  messages: readonly ThreadMessage[];
85
85
  isRunning: boolean;
86
+ }>;
87
+
88
+ type ThreadActionsState = Readonly<{
86
89
  getBranches: (messageId: string) => readonly string[];
87
90
  switchToBranch: (branchId: string) => void;
88
91
  append: (message: AppendMessage) => void;
89
92
  startRun: (parentId: string | null) => void;
90
93
  cancelRun: () => void;
91
94
  addToolResult: (toolCallId: string, result: any) => void;
92
- };
95
+ }>;
93
96
 
94
- export type { AssistantContentPart as A, ImageContentPartComponent as I, ModelConfigProvider as M, TextContentPartComponent as T, UIContentPartComponent as U, ToolCallContentPartComponent as a, ToolCallContentPartProps as b, ThreadState as c, Unsubscribe as d, ThreadMessage as e, ModelConfig as f, AppendMessage as g, AssistantMessage as h, UserMessage as i, UserContentPart as j, AppendContentPart as k, TextContentPart as l, Tool as m, ImageContentPart as n, ToolCallContentPart as o, UIContentPart as p, TextContentPartProps as q, ImageContentPartProps as r, UIContentPartProps as s };
97
+ export type { AssistantContentPart as A, ImageContentPartComponent as I, ModelConfigProvider as M, TextContentPartComponent as T, UIContentPartComponent as U, ToolCallContentPartComponent as a, ToolCallContentPartProps as b, ThreadState as c, ThreadActionsState as d, Unsubscribe as e, ThreadMessage as f, ModelConfig as g, AppendMessage as h, AssistantMessage as i, UserMessage as j, UserContentPart as k, AppendContentPart as l, TextContentPart as m, Tool as n, ImageContentPart as o, ToolCallContentPart as p, UIContentPart as q, TextContentPartProps as r, ImageContentPartProps as s, UIContentPartProps as t };
@@ -80,15 +80,18 @@ type ModelConfigProvider = () => ModelConfig;
80
80
 
81
81
  type Unsubscribe = () => void;
82
82
 
83
- type ThreadState = {
83
+ type ThreadState = Readonly<{
84
84
  messages: readonly ThreadMessage[];
85
85
  isRunning: boolean;
86
+ }>;
87
+
88
+ type ThreadActionsState = Readonly<{
86
89
  getBranches: (messageId: string) => readonly string[];
87
90
  switchToBranch: (branchId: string) => void;
88
91
  append: (message: AppendMessage) => void;
89
92
  startRun: (parentId: string | null) => void;
90
93
  cancelRun: () => void;
91
94
  addToolResult: (toolCallId: string, result: any) => void;
92
- };
95
+ }>;
93
96
 
94
- export type { AssistantContentPart as A, ImageContentPartComponent as I, ModelConfigProvider as M, TextContentPartComponent as T, UIContentPartComponent as U, ToolCallContentPartComponent as a, ToolCallContentPartProps as b, ThreadState as c, Unsubscribe as d, ThreadMessage as e, ModelConfig as f, AppendMessage as g, AssistantMessage as h, UserMessage as i, UserContentPart as j, AppendContentPart as k, TextContentPart as l, Tool as m, ImageContentPart as n, ToolCallContentPart as o, UIContentPart as p, TextContentPartProps as q, ImageContentPartProps as r, UIContentPartProps as s };
97
+ export type { AssistantContentPart as A, ImageContentPartComponent as I, ModelConfigProvider as M, TextContentPartComponent as T, UIContentPartComponent as U, ToolCallContentPartComponent as a, ToolCallContentPartProps as b, ThreadState as c, ThreadActionsState as d, Unsubscribe as e, ThreadMessage as f, ModelConfig as g, AppendMessage as h, AssistantMessage as i, UserMessage as j, UserContentPart as k, AppendContentPart as l, TextContentPart as m, Tool as n, ImageContentPart as o, ToolCallContentPart as p, UIContentPart as q, TextContentPartProps as r, ImageContentPartProps as s, UIContentPartProps as t };
@@ -82,4 +82,4 @@ export {
82
82
  ContentPartContext,
83
83
  useContentPartContext
84
84
  };
85
- //# sourceMappingURL=chunk-RITM2IUH.mjs.map
85
+ //# sourceMappingURL=chunk-7O2URLFI.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/context/MessageContext.ts","../src/context/ThreadContext.ts","../src/context/ComposerContext.ts","../src/context/AssistantContext.ts","../src/context/ContentPartContext.ts"],"sourcesContent":["import { createContext, useContext } from \"react\";\nimport type { MessageState } from \"./stores/Message\";\nimport type { EditComposerState } from \"./stores/MessageComposer\";\nimport { ReadonlyStore } from \"./ReadonlyStore\";\nimport { MessageUtilsState } from \"./stores/MessageUtils\";\n\nexport type MessageContextValue = {\n useMessage: ReadonlyStore<MessageState>;\n useMessageUtils: ReadonlyStore<MessageUtilsState>;\n useComposer: ReadonlyStore<EditComposerState>;\n};\n\nexport const MessageContext = createContext<MessageContextValue | null>(null);\n\nexport const useMessageContext = () => {\n const context = useContext(MessageContext);\n if (!context)\n throw new Error(\n \"This component can only be used inside a component passed to <ThreadPrimitive.Messages components={...} />.\",\n );\n return context;\n};\n","import { createContext, useContext } from \"react\";\nimport type { ComposerState } from \"./stores/Composer\";\nimport type { ThreadState } from \"./stores/Thread\";\nimport type { ThreadViewportState } from \"./stores/ThreadViewport\";\nimport { ThreadActionsState } from \"./stores/ThreadActions\";\nimport { ReadonlyStore } from \"./ReadonlyStore\";\n\nexport type ThreadContextValue = {\n useThread: ReadonlyStore<ThreadState>;\n useThreadActions: ReadonlyStore<ThreadActionsState>;\n useComposer: ReadonlyStore<ComposerState>;\n useViewport: ReadonlyStore<ThreadViewportState>;\n};\n\nexport const ThreadContext = createContext<ThreadContextValue | null>(null);\n\nexport const useThreadContext = (): ThreadContextValue => {\n const context = useContext(ThreadContext);\n if (!context)\n throw new Error(\n \"This component must be used within an AssistantRuntimeProvider.\",\n );\n return context;\n};\n","import { useContext, useMemo } from \"react\";\nimport { MessageContext } from \"./MessageContext\";\nimport { useThreadContext } from \"./ThreadContext\";\nimport type { ComposerState } from \"./stores/Composer\";\nimport type { EditComposerState } from \"./stores/MessageComposer\";\nimport { ReadonlyStore } from \"./ReadonlyStore\";\n\nexport type ComposerContextValue = {\n useComposer: ReadonlyStore<EditComposerState | ComposerState>;\n type: \"edit\" | \"new\";\n};\n\nexport const useComposerContext = (): ComposerContextValue => {\n const { useComposer } = useThreadContext();\n const { useComposer: useEditComposer } = useContext(MessageContext) ?? {};\n return useMemo(\n () => ({\n useComposer: (useEditComposer ?? useComposer) as ReadonlyStore<\n EditComposerState | ComposerState\n >,\n type: useEditComposer ? (\"edit\" as const) : (\"new\" as const),\n }),\n [useEditComposer, useComposer],\n );\n};\n","import { createContext, useContext } from \"react\";\nimport type { AssistantModelConfigState } from \"./stores/AssistantModelConfig\";\nimport type { AssistantToolUIsState } from \"./stores/AssistantToolUIs\";\nimport { ReadonlyStore } from \"./ReadonlyStore\";\n\nexport type AssistantContextValue = {\n useModelConfig: ReadonlyStore<AssistantModelConfigState>;\n useToolUIs: ReadonlyStore<AssistantToolUIsState>;\n};\n\nexport const AssistantContext = createContext<AssistantContextValue | null>(\n null,\n);\n\nexport const useAssistantContext = (): AssistantContextValue => {\n const context = useContext(AssistantContext);\n if (!context)\n throw new Error(\n \"This component must be used within an AssistantRuntimeProvider.\",\n );\n return context;\n};\n","import { createContext, useContext } from \"react\";\nimport type { ContentPartState } from \"./stores/ContentPart\";\nimport { ReadonlyStore } from \"./ReadonlyStore\";\n\nexport type ContentPartContextValue = {\n useContentPart: ReadonlyStore<ContentPartState>;\n};\n\nexport const ContentPartContext = createContext<ContentPartContextValue | null>(\n null,\n);\n\nexport const useContentPartContext = (): ContentPartContextValue => {\n const context = useContext(ContentPartContext);\n if (!context)\n throw new Error(\n \"This component can only be used inside a component passed to <MessagePrimitive.Content components={...} >.\",\n );\n return context;\n};\n"],"mappings":";;;;;;;AAAA,SAAS,eAAe,kBAAkB;AAYnC,IAAM,iBAAiB,cAA0C,IAAI;AAErE,IAAM,oBAAoB,MAAM;AACrC,QAAM,UAAU,WAAW,cAAc;AACzC,MAAI,CAAC;AACH,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,SAAO;AACT;;;ACrBA,SAAS,iBAAAA,gBAAe,cAAAC,mBAAkB;AAcnC,IAAM,gBAAgBD,eAAyC,IAAI;AAEnE,IAAM,mBAAmB,MAA0B;AACxD,QAAM,UAAUC,YAAW,aAAa;AACxC,MAAI,CAAC;AACH,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,SAAO;AACT;;;ACvBA,SAAS,cAAAC,aAAY,eAAe;AAY7B,IAAM,qBAAqB,MAA4B;AAC5D,QAAM,EAAE,YAAY,IAAI,iBAAiB;AACzC,QAAM,EAAE,aAAa,gBAAgB,IAAIC,YAAW,cAAc,KAAK,CAAC;AACxE,SAAO;AAAA,IACL,OAAO;AAAA,MACL,aAAc,mBAAmB;AAAA,MAGjC,MAAM,kBAAmB,SAAoB;AAAA,IAC/C;AAAA,IACA,CAAC,iBAAiB,WAAW;AAAA,EAC/B;AACF;;;ACxBA,SAAS,iBAAAC,gBAAe,cAAAC,mBAAkB;AAUnC,IAAM,mBAAmBD;AAAA,EAC9B;AACF;AAEO,IAAM,sBAAsB,MAA6B;AAC9D,QAAM,UAAUC,YAAW,gBAAgB;AAC3C,MAAI,CAAC;AACH,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,SAAO;AACT;;;ACrBA,SAAS,iBAAAC,gBAAe,cAAAC,mBAAkB;AAQnC,IAAM,qBAAqBD;AAAA,EAChC;AACF;AAEO,IAAM,wBAAwB,MAA+B;AAClE,QAAM,UAAUC,YAAW,kBAAkB;AAC7C,MAAI,CAAC;AACH,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,SAAO;AACT;","names":["createContext","useContext","useContext","useContext","createContext","useContext","createContext","useContext"]}
@@ -1,13 +1,13 @@
1
- import { M as ModelConfigProvider, e as ThreadMessage, d as Unsubscribe, a as ToolCallContentPartComponent, c as ThreadState, m as Tool } from './Thread-CoxBELWy.mjs';
2
- export { n as ImageContentPart, I as ImageContentPartComponent, r as ImageContentPartProps, f as ModelConfig, T as TextContentPartComponent, q as TextContentPartProps, o as ToolCallContentPart, b as ToolCallContentPartProps, p as UIContentPart, U as UIContentPartComponent, s as UIContentPartProps } from './Thread-CoxBELWy.mjs';
3
- import { ReactNode } from 'react';
1
+ import { M as ModelConfigProvider, f as ThreadMessage, e as Unsubscribe, a as ToolCallContentPartComponent, c as ThreadState, d as ThreadActionsState, n as Tool } from './ThreadActions-DqqhRbf1.mjs';
2
+ export { o as ImageContentPart, I as ImageContentPartComponent, s as ImageContentPartProps, g as ModelConfig, T as TextContentPartComponent, r as TextContentPartProps, p as ToolCallContentPart, b as ToolCallContentPartProps, q as UIContentPart, U as UIContentPartComponent, t as UIContentPartProps } from './ThreadActions-DqqhRbf1.mjs';
4
3
  import { UseBoundStore, StoreApi } from 'zustand';
4
+ import { ReactNode } from 'react';
5
5
  import 'zod';
6
6
 
7
- type AssistantModelConfigState = {
7
+ type AssistantModelConfigState = Readonly<{
8
8
  getModelConfig: ModelConfigProvider;
9
9
  registerModelConfigProvider: (provider: ModelConfigProvider) => () => void;
10
- };
10
+ }>;
11
11
 
12
12
  type ContentPartState = Readonly<{
13
13
  status: "in_progress" | "done" | "error";
@@ -19,12 +19,6 @@ type MessageState = Readonly<{
19
19
  parentId: string | null;
20
20
  branches: readonly string[];
21
21
  isLast: boolean;
22
- inProgressIndicator: ReactNode | null;
23
- setInProgressIndicator: (value: ReactNode | null) => void;
24
- isCopied: boolean;
25
- setIsCopied: (value: boolean) => void;
26
- isHovering: boolean;
27
- setIsHovering: (value: boolean) => void;
28
22
  }>;
29
23
 
30
24
  type BaseComposerState = Readonly<{
@@ -32,6 +26,8 @@ type BaseComposerState = Readonly<{
32
26
  setValue: (value: string) => void;
33
27
  }>;
34
28
 
29
+ type ReadonlyStore<T> = UseBoundStore<Omit<StoreApi<T>, "setState" | "destroy" | "getInitialState">>;
30
+
35
31
  type EditComposerState = BaseComposerState & Readonly<{
36
32
  isEditing: boolean;
37
33
  edit: () => void;
@@ -45,44 +41,55 @@ type ComposerState = BaseComposerState & Readonly<{
45
41
  cancel: () => boolean;
46
42
  }>;
47
43
 
48
- type ThreadViewportState = {
44
+ type ThreadViewportState = Readonly<{
49
45
  isAtBottom: boolean;
50
46
  scrollToBottom: () => void;
51
47
  onScrollToBottom: (callback: () => void) => Unsubscribe;
52
- };
48
+ }>;
53
49
 
54
- type AssistantToolUIsState = {
50
+ type AssistantToolUIsState = Readonly<{
55
51
  getToolUI: (toolName: string) => ToolCallContentPartComponent | null;
56
52
  setToolUI: (toolName: string, render: ToolCallContentPartComponent) => () => void;
57
- };
53
+ }>;
58
54
 
59
55
  type AssistantContextValue = {
60
- useModelConfig: UseBoundStore<StoreApi<AssistantModelConfigState>>;
61
- useToolUIs: UseBoundStore<StoreApi<AssistantToolUIsState>>;
56
+ useModelConfig: ReadonlyStore<AssistantModelConfigState>;
57
+ useToolUIs: ReadonlyStore<AssistantToolUIsState>;
62
58
  };
63
59
  declare const useAssistantContext: () => AssistantContextValue;
64
60
 
65
61
  type ThreadContextValue = {
66
- useThread: UseBoundStore<StoreApi<ThreadState>>;
67
- useComposer: UseBoundStore<StoreApi<ComposerState>>;
68
- useViewport: UseBoundStore<StoreApi<ThreadViewportState>>;
62
+ useThread: ReadonlyStore<ThreadState>;
63
+ useThreadActions: ReadonlyStore<ThreadActionsState>;
64
+ useComposer: ReadonlyStore<ComposerState>;
65
+ useViewport: ReadonlyStore<ThreadViewportState>;
69
66
  };
70
67
  declare const useThreadContext: () => ThreadContextValue;
71
68
 
72
69
  type ComposerContextValue = {
73
- useComposer: UseBoundStore<StoreApi<EditComposerState | ComposerState>>;
70
+ useComposer: ReadonlyStore<EditComposerState | ComposerState>;
74
71
  type: "edit" | "new";
75
72
  };
76
73
  declare const useComposerContext: () => ComposerContextValue;
77
74
 
75
+ type MessageUtilsState = Readonly<{
76
+ inProgressIndicator: ReactNode | null;
77
+ setInProgressIndicator: (value: ReactNode | null) => void;
78
+ isCopied: boolean;
79
+ setIsCopied: (value: boolean) => void;
80
+ isHovering: boolean;
81
+ setIsHovering: (value: boolean) => void;
82
+ }>;
83
+
78
84
  type MessageContextValue = {
79
- useMessage: UseBoundStore<StoreApi<MessageState>>;
80
- useComposer: UseBoundStore<StoreApi<EditComposerState>>;
85
+ useMessage: ReadonlyStore<MessageState>;
86
+ useMessageUtils: ReadonlyStore<MessageUtilsState>;
87
+ useComposer: ReadonlyStore<EditComposerState>;
81
88
  };
82
89
  declare const useMessageContext: () => MessageContextValue;
83
90
 
84
91
  type ContentPartContextValue = {
85
- useContentPart: UseBoundStore<StoreApi<ContentPartState>>;
92
+ useContentPart: ReadonlyStore<ContentPartState>;
86
93
  };
87
94
  declare const useContentPartContext: () => ContentPartContextValue;
88
95
 
@@ -1,13 +1,13 @@
1
- import { M as ModelConfigProvider, e as ThreadMessage, d as Unsubscribe, a as ToolCallContentPartComponent, c as ThreadState, m as Tool } from './Thread-CoxBELWy.js';
2
- export { n as ImageContentPart, I as ImageContentPartComponent, r as ImageContentPartProps, f as ModelConfig, T as TextContentPartComponent, q as TextContentPartProps, o as ToolCallContentPart, b as ToolCallContentPartProps, p as UIContentPart, U as UIContentPartComponent, s as UIContentPartProps } from './Thread-CoxBELWy.js';
3
- import { ReactNode } from 'react';
1
+ import { M as ModelConfigProvider, f as ThreadMessage, e as Unsubscribe, a as ToolCallContentPartComponent, c as ThreadState, d as ThreadActionsState, n as Tool } from './ThreadActions-DqqhRbf1.js';
2
+ export { o as ImageContentPart, I as ImageContentPartComponent, s as ImageContentPartProps, g as ModelConfig, T as TextContentPartComponent, r as TextContentPartProps, p as ToolCallContentPart, b as ToolCallContentPartProps, q as UIContentPart, U as UIContentPartComponent, t as UIContentPartProps } from './ThreadActions-DqqhRbf1.js';
4
3
  import { UseBoundStore, StoreApi } from 'zustand';
4
+ import { ReactNode } from 'react';
5
5
  import 'zod';
6
6
 
7
- type AssistantModelConfigState = {
7
+ type AssistantModelConfigState = Readonly<{
8
8
  getModelConfig: ModelConfigProvider;
9
9
  registerModelConfigProvider: (provider: ModelConfigProvider) => () => void;
10
- };
10
+ }>;
11
11
 
12
12
  type ContentPartState = Readonly<{
13
13
  status: "in_progress" | "done" | "error";
@@ -19,12 +19,6 @@ type MessageState = Readonly<{
19
19
  parentId: string | null;
20
20
  branches: readonly string[];
21
21
  isLast: boolean;
22
- inProgressIndicator: ReactNode | null;
23
- setInProgressIndicator: (value: ReactNode | null) => void;
24
- isCopied: boolean;
25
- setIsCopied: (value: boolean) => void;
26
- isHovering: boolean;
27
- setIsHovering: (value: boolean) => void;
28
22
  }>;
29
23
 
30
24
  type BaseComposerState = Readonly<{
@@ -32,6 +26,8 @@ type BaseComposerState = Readonly<{
32
26
  setValue: (value: string) => void;
33
27
  }>;
34
28
 
29
+ type ReadonlyStore<T> = UseBoundStore<Omit<StoreApi<T>, "setState" | "destroy" | "getInitialState">>;
30
+
35
31
  type EditComposerState = BaseComposerState & Readonly<{
36
32
  isEditing: boolean;
37
33
  edit: () => void;
@@ -45,44 +41,55 @@ type ComposerState = BaseComposerState & Readonly<{
45
41
  cancel: () => boolean;
46
42
  }>;
47
43
 
48
- type ThreadViewportState = {
44
+ type ThreadViewportState = Readonly<{
49
45
  isAtBottom: boolean;
50
46
  scrollToBottom: () => void;
51
47
  onScrollToBottom: (callback: () => void) => Unsubscribe;
52
- };
48
+ }>;
53
49
 
54
- type AssistantToolUIsState = {
50
+ type AssistantToolUIsState = Readonly<{
55
51
  getToolUI: (toolName: string) => ToolCallContentPartComponent | null;
56
52
  setToolUI: (toolName: string, render: ToolCallContentPartComponent) => () => void;
57
- };
53
+ }>;
58
54
 
59
55
  type AssistantContextValue = {
60
- useModelConfig: UseBoundStore<StoreApi<AssistantModelConfigState>>;
61
- useToolUIs: UseBoundStore<StoreApi<AssistantToolUIsState>>;
56
+ useModelConfig: ReadonlyStore<AssistantModelConfigState>;
57
+ useToolUIs: ReadonlyStore<AssistantToolUIsState>;
62
58
  };
63
59
  declare const useAssistantContext: () => AssistantContextValue;
64
60
 
65
61
  type ThreadContextValue = {
66
- useThread: UseBoundStore<StoreApi<ThreadState>>;
67
- useComposer: UseBoundStore<StoreApi<ComposerState>>;
68
- useViewport: UseBoundStore<StoreApi<ThreadViewportState>>;
62
+ useThread: ReadonlyStore<ThreadState>;
63
+ useThreadActions: ReadonlyStore<ThreadActionsState>;
64
+ useComposer: ReadonlyStore<ComposerState>;
65
+ useViewport: ReadonlyStore<ThreadViewportState>;
69
66
  };
70
67
  declare const useThreadContext: () => ThreadContextValue;
71
68
 
72
69
  type ComposerContextValue = {
73
- useComposer: UseBoundStore<StoreApi<EditComposerState | ComposerState>>;
70
+ useComposer: ReadonlyStore<EditComposerState | ComposerState>;
74
71
  type: "edit" | "new";
75
72
  };
76
73
  declare const useComposerContext: () => ComposerContextValue;
77
74
 
75
+ type MessageUtilsState = Readonly<{
76
+ inProgressIndicator: ReactNode | null;
77
+ setInProgressIndicator: (value: ReactNode | null) => void;
78
+ isCopied: boolean;
79
+ setIsCopied: (value: boolean) => void;
80
+ isHovering: boolean;
81
+ setIsHovering: (value: boolean) => void;
82
+ }>;
83
+
78
84
  type MessageContextValue = {
79
- useMessage: UseBoundStore<StoreApi<MessageState>>;
80
- useComposer: UseBoundStore<StoreApi<EditComposerState>>;
85
+ useMessage: ReadonlyStore<MessageState>;
86
+ useMessageUtils: ReadonlyStore<MessageUtilsState>;
87
+ useComposer: ReadonlyStore<EditComposerState>;
81
88
  };
82
89
  declare const useMessageContext: () => MessageContextValue;
83
90
 
84
91
  type ContentPartContextValue = {
85
- useContentPart: UseBoundStore<StoreApi<ContentPartState>>;
92
+ useContentPart: ReadonlyStore<ContentPartState>;
86
93
  };
87
94
  declare const useContentPartContext: () => ContentPartContextValue;
88
95
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/experimental.ts","../src/context/AssistantContext.ts","../src/context/ThreadContext.ts","../src/context/ComposerContext.ts","../src/context/MessageContext.ts","../src/context/ContentPartContext.ts","../src/model-config/useAssistantInstructions.tsx","../src/model-config/useAssistantTool.tsx","../src/model-config/useAssistantToolUI.tsx","../src/model-config/makeAssistantTool.tsx","../src/model-config/makeAssistantToolUI.tsx"],"sourcesContent":["export type {\n ImageContentPart,\n ToolCallContentPart,\n UIContentPart,\n} from \"./utils/AssistantTypes\";\n\nexport type {\n ModelConfigProvider,\n ModelConfig,\n} from \"./utils/ModelConfigTypes\";\n\nexport type {\n TextContentPartProps,\n TextContentPartComponent,\n ImageContentPartProps,\n ImageContentPartComponent,\n UIContentPartProps,\n UIContentPartComponent,\n ToolCallContentPartProps,\n ToolCallContentPartComponent,\n} from \"./primitives/message/ContentPartComponentTypes\";\n\nexport * from \"./context\";\nexport { useAssistantInstructions } from \"./model-config/useAssistantInstructions\";\nexport {\n useAssistantTool,\n type AssistantToolProps,\n} from \"./model-config/useAssistantTool\";\nexport {\n useAssistantToolUI,\n type AssistantToolUIProps,\n} from \"./model-config/useAssistantToolUI\";\nexport { makeAssistantTool } from \"./model-config/makeAssistantTool\";\nexport { makeAssistantToolUI } from \"./model-config/makeAssistantToolUI\";\n","import { createContext, useContext } from \"react\";\nimport type { StoreApi, UseBoundStore } from \"zustand\";\nimport type { AssistantModelConfigState } from \"./stores/AssistantModelConfig\";\nimport type { AssistantToolUIsState } from \"./stores/AssistantToolUIs\";\n\nexport type AssistantContextValue = {\n useModelConfig: UseBoundStore<StoreApi<AssistantModelConfigState>>;\n useToolUIs: UseBoundStore<StoreApi<AssistantToolUIsState>>;\n};\n\nexport const AssistantContext = createContext<AssistantContextValue | null>(\n null,\n);\n\nexport const useAssistantContext = (): AssistantContextValue => {\n const context = useContext(AssistantContext);\n if (!context)\n throw new Error(\n \"This component must be used within an AssistantRuntimeProvider.\",\n );\n return context;\n};\n","import { createContext, useContext } from \"react\";\nimport type { StoreApi, UseBoundStore } from \"zustand\";\nimport type { ComposerState } from \"./stores/Composer\";\nimport type { ThreadState } from \"./stores/Thread\";\nimport type { ThreadViewportState } from \"./stores/ThreadViewport\";\n\nexport type ThreadContextValue = {\n useThread: UseBoundStore<StoreApi<ThreadState>>;\n useComposer: UseBoundStore<StoreApi<ComposerState>>;\n useViewport: UseBoundStore<StoreApi<ThreadViewportState>>;\n};\n\nexport const ThreadContext = createContext<ThreadContextValue | null>(null);\n\nexport const useThreadContext = (): ThreadContextValue => {\n const context = useContext(ThreadContext);\n if (!context)\n throw new Error(\n \"This component must be used within an AssistantRuntimeProvider.\",\n );\n return context;\n};\n","import { useContext, useMemo } from \"react\";\nimport type { StoreApi, UseBoundStore } from \"zustand\";\nimport { MessageContext } from \"./MessageContext\";\nimport { useThreadContext } from \"./ThreadContext\";\nimport type { ComposerState } from \"./stores/Composer\";\nimport type { EditComposerState } from \"./stores/MessageComposer\";\n\nexport type ComposerContextValue = {\n useComposer: UseBoundStore<StoreApi<EditComposerState | ComposerState>>;\n type: \"edit\" | \"new\";\n};\n\nexport const useComposerContext = (): ComposerContextValue => {\n const { useComposer } = useThreadContext();\n const { useComposer: useEditComposer } = useContext(MessageContext) ?? {};\n return useMemo(\n () => ({\n useComposer: (useEditComposer ?? useComposer) as UseBoundStore<\n StoreApi<EditComposerState | ComposerState>\n >,\n type: useEditComposer ? (\"edit\" as const) : (\"new\" as const),\n }),\n [useEditComposer, useComposer],\n );\n};\n","import { createContext, useContext } from \"react\";\nimport type { StoreApi, UseBoundStore } from \"zustand\";\nimport type { MessageState } from \"./stores/Message\";\nimport type { EditComposerState } from \"./stores/MessageComposer\";\n\nexport type MessageContextValue = {\n useMessage: UseBoundStore<StoreApi<MessageState>>;\n useComposer: UseBoundStore<StoreApi<EditComposerState>>;\n};\n\nexport const MessageContext = createContext<MessageContextValue | null>(null);\n\nexport const useMessageContext = () => {\n const context = useContext(MessageContext);\n if (!context)\n throw new Error(\n \"This component can only be used inside a component passed to <ThreadPrimitive.Messages components={...} />.\",\n );\n return context;\n};\n","import { createContext, useContext } from \"react\";\nimport type { StoreApi, UseBoundStore } from \"zustand\";\nimport type { ContentPartState } from \"./stores/ContentPart\";\n\nexport type ContentPartContextValue = {\n useContentPart: UseBoundStore<StoreApi<ContentPartState>>;\n};\n\nexport const ContentPartContext = createContext<ContentPartContextValue | null>(\n null,\n);\n\nexport const useContentPartContext = (): ContentPartContextValue => {\n const context = useContext(ContentPartContext);\n if (!context)\n throw new Error(\n \"This component can only be used inside a component passed to <MessagePrimitive.Content components={...} >.\",\n );\n return context;\n};\n","\"use client\";\n\nimport { useEffect } from \"react\";\nimport { useAssistantContext } from \"../context/AssistantContext\";\n\nexport const useAssistantInstructions = (instruction: string) => {\n const { useModelConfig } = useAssistantContext();\n const registerModelConfigProvider = useModelConfig(\n (s) => s.registerModelConfigProvider,\n );\n useEffect(() => {\n const config = {\n system: instruction,\n };\n return registerModelConfigProvider(() => config);\n }, [registerModelConfigProvider, instruction]);\n};\n","\"use client\";\n\nimport { useEffect } from \"react\";\nimport { useAssistantContext } from \"../context/AssistantContext\";\nimport type { ToolCallContentPartComponent } from \"../primitives/message/ContentPartComponentTypes\";\nimport type { Tool } from \"../utils/ModelConfigTypes\";\n\nexport type AssistantToolProps<TArgs, TResult> = Tool<TArgs, TResult> & {\n toolName: string;\n render?: ToolCallContentPartComponent<TArgs, TResult>;\n};\n\nexport const useAssistantTool = <TArgs, TResult>(\n tool: AssistantToolProps<TArgs, TResult>,\n) => {\n const { useModelConfig, useToolUIs } = useAssistantContext();\n const registerModelConfigProvider = useModelConfig(\n (s) => s.registerModelConfigProvider,\n );\n const setToolUI = useToolUIs((s) => s.setToolUI);\n useEffect(() => {\n const { toolName, render, ...rest } = tool;\n const config = {\n tools: {\n [tool.toolName]: rest,\n },\n };\n const unsub1 = registerModelConfigProvider(() => config);\n const unsub2 = render ? setToolUI(toolName, render) : undefined;\n return () => {\n unsub1();\n unsub2?.();\n };\n }, [registerModelConfigProvider, setToolUI, tool]);\n};\n","\"use client\";\nimport { useEffect } from \"react\";\nimport { useAssistantContext } from \"../context/AssistantContext\";\nimport type { ToolCallContentPartComponent } from \"../primitives/message/ContentPartComponentTypes\";\n\nexport type AssistantToolUIProps<TArgs, TResult> = {\n toolName: string;\n render: ToolCallContentPartComponent<TArgs, TResult>;\n};\n\nexport const useAssistantToolUI = (\n tool: AssistantToolUIProps<any, any> | null,\n) => {\n const { useToolUIs } = useAssistantContext();\n const setToolUI = useToolUIs((s) => s.setToolUI);\n useEffect(() => {\n if (!tool) return;\n const { toolName, render } = tool;\n return setToolUI(toolName, render);\n }, [setToolUI, tool]);\n};\n","\"use client\";\nimport { type AssistantToolProps, useAssistantTool } from \"./useAssistantTool\";\n\nexport const makeAssistantTool = <TArgs, TResult>(\n tool: AssistantToolProps<TArgs, TResult>,\n) => {\n const Tool = () => {\n useAssistantTool(tool);\n return null;\n };\n return Tool;\n};\n","\"use client\";\nimport {\n type AssistantToolUIProps,\n useAssistantToolUI,\n} from \"./useAssistantToolUI\";\n\nexport const makeAssistantToolUI = <TArgs, TResult>(\n tool: AssistantToolUIProps<TArgs, TResult>,\n) => {\n const ToolUI = () => {\n useAssistantToolUI(tool);\n return null;\n };\n return ToolUI;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;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O;AAAA,EACT;AACA,SAAO;AACT;","names":["import_react","import_react","import_react","import_react","import_react","import_react","import_react"]}
1
+ {"version":3,"sources":["../src/experimental.ts","../src/context/AssistantContext.ts","../src/context/ThreadContext.ts","../src/context/ComposerContext.ts","../src/context/MessageContext.ts","../src/context/ContentPartContext.ts","../src/model-config/useAssistantInstructions.tsx","../src/model-config/useAssistantTool.tsx","../src/model-config/useAssistantToolUI.tsx","../src/model-config/makeAssistantTool.tsx","../src/model-config/makeAssistantToolUI.tsx"],"sourcesContent":["export type {\n ImageContentPart,\n ToolCallContentPart,\n UIContentPart,\n} from \"./utils/AssistantTypes\";\n\nexport type {\n ModelConfigProvider,\n ModelConfig,\n} from \"./utils/ModelConfigTypes\";\n\nexport type {\n TextContentPartProps,\n TextContentPartComponent,\n ImageContentPartProps,\n ImageContentPartComponent,\n UIContentPartProps,\n UIContentPartComponent,\n ToolCallContentPartProps,\n ToolCallContentPartComponent,\n} from \"./primitives/message/ContentPartComponentTypes\";\n\nexport * from \"./context\";\nexport { useAssistantInstructions } from \"./model-config/useAssistantInstructions\";\nexport {\n useAssistantTool,\n type AssistantToolProps,\n} from \"./model-config/useAssistantTool\";\nexport {\n useAssistantToolUI,\n type AssistantToolUIProps,\n} from \"./model-config/useAssistantToolUI\";\nexport { makeAssistantTool } from \"./model-config/makeAssistantTool\";\nexport { makeAssistantToolUI } from \"./model-config/makeAssistantToolUI\";\n","import { createContext, useContext } from \"react\";\nimport type { AssistantModelConfigState } from \"./stores/AssistantModelConfig\";\nimport type { AssistantToolUIsState } from \"./stores/AssistantToolUIs\";\nimport { ReadonlyStore } from \"./ReadonlyStore\";\n\nexport type AssistantContextValue = {\n useModelConfig: ReadonlyStore<AssistantModelConfigState>;\n useToolUIs: ReadonlyStore<AssistantToolUIsState>;\n};\n\nexport const AssistantContext = createContext<AssistantContextValue | null>(\n null,\n);\n\nexport const useAssistantContext = (): AssistantContextValue => {\n const context = useContext(AssistantContext);\n if (!context)\n throw new Error(\n \"This component must be used within an AssistantRuntimeProvider.\",\n );\n return context;\n};\n","import { createContext, useContext } from \"react\";\nimport type { ComposerState } from \"./stores/Composer\";\nimport type { ThreadState } from \"./stores/Thread\";\nimport type { ThreadViewportState } from \"./stores/ThreadViewport\";\nimport { ThreadActionsState } from \"./stores/ThreadActions\";\nimport { ReadonlyStore } from \"./ReadonlyStore\";\n\nexport type ThreadContextValue = {\n useThread: ReadonlyStore<ThreadState>;\n useThreadActions: ReadonlyStore<ThreadActionsState>;\n useComposer: ReadonlyStore<ComposerState>;\n useViewport: ReadonlyStore<ThreadViewportState>;\n};\n\nexport const ThreadContext = createContext<ThreadContextValue | null>(null);\n\nexport const useThreadContext = (): ThreadContextValue => {\n const context = useContext(ThreadContext);\n if (!context)\n throw new Error(\n \"This component must be used within an AssistantRuntimeProvider.\",\n );\n return context;\n};\n","import { useContext, useMemo } from \"react\";\nimport { MessageContext } from \"./MessageContext\";\nimport { useThreadContext } from \"./ThreadContext\";\nimport type { ComposerState } from \"./stores/Composer\";\nimport type { EditComposerState } from \"./stores/MessageComposer\";\nimport { ReadonlyStore } from \"./ReadonlyStore\";\n\nexport type ComposerContextValue = {\n useComposer: ReadonlyStore<EditComposerState | ComposerState>;\n type: \"edit\" | \"new\";\n};\n\nexport const useComposerContext = (): ComposerContextValue => {\n const { useComposer } = useThreadContext();\n const { useComposer: useEditComposer } = useContext(MessageContext) ?? {};\n return useMemo(\n () => ({\n useComposer: (useEditComposer ?? useComposer) as ReadonlyStore<\n EditComposerState | ComposerState\n >,\n type: useEditComposer ? (\"edit\" as const) : (\"new\" as const),\n }),\n [useEditComposer, useComposer],\n );\n};\n","import { createContext, useContext } from \"react\";\nimport type { MessageState } from \"./stores/Message\";\nimport type { EditComposerState } from \"./stores/MessageComposer\";\nimport { ReadonlyStore } from \"./ReadonlyStore\";\nimport { MessageUtilsState } from \"./stores/MessageUtils\";\n\nexport type MessageContextValue = {\n useMessage: ReadonlyStore<MessageState>;\n useMessageUtils: ReadonlyStore<MessageUtilsState>;\n useComposer: ReadonlyStore<EditComposerState>;\n};\n\nexport const MessageContext = createContext<MessageContextValue | null>(null);\n\nexport const useMessageContext = () => {\n const context = useContext(MessageContext);\n if (!context)\n throw new Error(\n \"This component can only be used inside a component passed to <ThreadPrimitive.Messages components={...} />.\",\n );\n return context;\n};\n","import { createContext, useContext } from \"react\";\nimport type { ContentPartState } from \"./stores/ContentPart\";\nimport { ReadonlyStore } from \"./ReadonlyStore\";\n\nexport type ContentPartContextValue = {\n useContentPart: ReadonlyStore<ContentPartState>;\n};\n\nexport const ContentPartContext = createContext<ContentPartContextValue | null>(\n null,\n);\n\nexport const useContentPartContext = (): ContentPartContextValue => {\n const context = useContext(ContentPartContext);\n if (!context)\n throw new Error(\n \"This component can only be used inside a component passed to <MessagePrimitive.Content components={...} >.\",\n );\n return context;\n};\n","\"use client\";\n\nimport { useEffect } from \"react\";\nimport { useAssistantContext } from \"../context/AssistantContext\";\n\nexport const useAssistantInstructions = (instruction: string) => {\n const { useModelConfig } = useAssistantContext();\n const registerModelConfigProvider = useModelConfig(\n (s) => s.registerModelConfigProvider,\n );\n useEffect(() => {\n const config = {\n system: instruction,\n };\n return registerModelConfigProvider(() => config);\n }, [registerModelConfigProvider, instruction]);\n};\n","\"use client\";\n\nimport { useEffect } from \"react\";\nimport { useAssistantContext } from \"../context/AssistantContext\";\nimport type { ToolCallContentPartComponent } from \"../primitives/message/ContentPartComponentTypes\";\nimport type { Tool } from \"../utils/ModelConfigTypes\";\n\nexport type AssistantToolProps<TArgs, TResult> = Tool<TArgs, TResult> & {\n toolName: string;\n render?: ToolCallContentPartComponent<TArgs, TResult>;\n};\n\nexport const useAssistantTool = <TArgs, TResult>(\n tool: AssistantToolProps<TArgs, TResult>,\n) => {\n const { useModelConfig, useToolUIs } = useAssistantContext();\n const registerModelConfigProvider = useModelConfig(\n (s) => s.registerModelConfigProvider,\n );\n const setToolUI = useToolUIs((s) => s.setToolUI);\n useEffect(() => {\n const { toolName, render, ...rest } = tool;\n const config = {\n tools: {\n [tool.toolName]: rest,\n },\n };\n const unsub1 = registerModelConfigProvider(() => config);\n const unsub2 = render ? setToolUI(toolName, render) : undefined;\n return () => {\n unsub1();\n unsub2?.();\n };\n }, [registerModelConfigProvider, setToolUI, tool]);\n};\n","\"use client\";\nimport { useEffect } from \"react\";\nimport { useAssistantContext } from \"../context/AssistantContext\";\nimport type { ToolCallContentPartComponent } from \"../primitives/message/ContentPartComponentTypes\";\n\nexport type AssistantToolUIProps<TArgs, TResult> = {\n toolName: string;\n render: ToolCallContentPartComponent<TArgs, TResult>;\n};\n\nexport const useAssistantToolUI = (\n tool: AssistantToolUIProps<any, any> | null,\n) => {\n const { useToolUIs } = useAssistantContext();\n const setToolUI = useToolUIs((s) => s.setToolUI);\n useEffect(() => {\n if (!tool) return;\n const { toolName, render } = tool;\n return setToolUI(toolName, render);\n }, [setToolUI, tool]);\n};\n","\"use client\";\nimport { type AssistantToolProps, useAssistantTool } from \"./useAssistantTool\";\n\nexport const makeAssistantTool = <TArgs, TResult>(\n tool: AssistantToolProps<TArgs, TResult>,\n) => {\n const Tool = () => {\n useAssistantTool(tool);\n return null;\n };\n return Tool;\n};\n","\"use client\";\nimport {\n type AssistantToolUIProps,\n useAssistantToolUI,\n} from \"./useAssistantToolUI\";\n\nexport const makeAssistantToolUI = <TArgs, TResult>(\n tool: AssistantToolUIProps<TArgs, TResult>,\n) => {\n const ToolUI = () => {\n useAssistantToolUI(tool);\n return null;\n };\n return ToolUI;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAA0C;AAUnC,IAAM,uBAAmB;AAAA,EAC9B;AACF;AAEO,IAAM,sBAAsB,MAA6B;AAC9D,QAAM,cAAU,yBAAW,gBAAgB;AAC3C,MAAI,CAAC;AACH,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,SAAO;A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UnB,IAAM,mBAAmB,CAC9B,SACG;AACH,QAAM,EAAE,gBAAgB,WAAW,IAAI,oBAAoB;AAC3D,QAAM,8BAA8B;AAAA,IAClC,CAAC,MAAM,EAAE;AAAA,EACX;AACA,QAAM,YAAY,WAAW,CAAC,MAAM,EAAE,SAAS;AAC/C,+BAAU,MAAM;AACd,UAAM,EAAE,UAAU,QAAQ,GAAG,KAAK,IAAI;AACtC,UAAM,SAAS;AAAA,MACb,OAAO;AAAA,QACL,CAAC,KAAK,QAAQ,GAAG;AAAA,MACnB;AAAA,IACF;AACA,UAAM,SAAS,4BAA4B,MAAM,MAAM;AACvD,UAAM,SAAS,SAAS,UAAU,UAAU,MAAM,IAAI;AACtD,WAAO,MAAM;AACX,aAAO;AACP,eAAS;AAAA,IACX;AAAA,EACF,GAAG,CAAC,6BAA6B,WAAW,IAAI,CAAC;AACnD;;;ACjCA,IAAAC,gBAA0B;AASnB,IAAM,qBAAqB,CAChC,SACG;AACH,QAAM,EAAE,WAAW,IAAI,oBAAoB;AAC3C,QAAM,YAAY,WAAW,CAAC,MAAM,EAAE,SAAS;AAC/C,+BAAU,MAAM;AACd,QAAI,CAAC,KAAM;AACX,UAAM,EAAE,UAAU,OAAO,IAAI;AAC7B,WAAO,UAAU,UAAU,MAAM;AAAA,EACnC,GAAG,CAAC,WAAW,IAAI,CAAC;AACtB;;;ACjBO,IAAM,oBAAoB,CAC/B,SACG;AACH,QAAM,OAAO,MAAM;AACjB,qBAAiB,IAAI;AACrB,WAAO;AAAA,EACT;AACA,SAAO;AACT;;;ACLO,IAAM,sBAAsB,CACjC,SACG;AACH,QAAM,SAAS,MAAM;AACnB,uBAAmB,IAAI;AACvB,WAAO;AAAA,EACT;AACA,SAAO;AACT;","names":["import_react","import_react","import_react","import_react","import_react","import_react","import_react"]}
@@ -4,7 +4,7 @@ import {
4
4
  useContentPartContext,
5
5
  useMessageContext,
6
6
  useThreadContext
7
- } from "./chunk-RITM2IUH.mjs";
7
+ } from "./chunk-7O2URLFI.mjs";
8
8
 
9
9
  // src/model-config/useAssistantInstructions.tsx
10
10
  import { useEffect } from "react";
package/dist/index.d.mts CHANGED
@@ -1,8 +1,8 @@
1
1
  import * as react from 'react';
2
2
  import { FC, ReactNode, PropsWithChildren, ComponentType, ComponentPropsWithoutRef } from 'react';
3
3
  import { TextareaAutosizeProps } from 'react-textarea-autosize';
4
- import { T as TextContentPartComponent, I as ImageContentPartComponent, U as UIContentPartComponent, a as ToolCallContentPartComponent, b as ToolCallContentPartProps, c as ThreadState, d as Unsubscribe, M as ModelConfigProvider, e as ThreadMessage, f as ModelConfig, A as AssistantContentPart, g as AppendMessage } from './Thread-CoxBELWy.mjs';
5
- export { k as AppendContentPart, h as AssistantMessage, l as TextContentPart, j as UserContentPart, i as UserMessage } from './Thread-CoxBELWy.mjs';
4
+ import { T as TextContentPartComponent, I as ImageContentPartComponent, U as UIContentPartComponent, a as ToolCallContentPartComponent, b as ToolCallContentPartProps, c as ThreadState, d as ThreadActionsState, e as Unsubscribe, M as ModelConfigProvider, f as ThreadMessage, g as ModelConfig, A as AssistantContentPart, h as AppendMessage } from './ThreadActions-DqqhRbf1.mjs';
5
+ export { l as AppendContentPart, i as AssistantMessage, m as TextContentPart, k as UserContentPart, j as UserMessage } from './ThreadActions-DqqhRbf1.mjs';
6
6
  import { Primitive } from '@radix-ui/react-primitive';
7
7
  import 'zod';
8
8
 
@@ -237,7 +237,7 @@ declare namespace index {
237
237
  export { ContentPartDisplay as Display, ContentPartImage as Image, ContentPartInProgressIndicator as InProgressIndicator, ContentPartText as Text };
238
238
  }
239
239
 
240
- type ThreadRuntime = Readonly<ThreadState & {
240
+ type ThreadRuntime = Readonly<ThreadState & ThreadActionsState & {
241
241
  subscribe: (callback: () => void) => Unsubscribe;
242
242
  }>;
243
243
 
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import * as react from 'react';
2
2
  import { FC, ReactNode, PropsWithChildren, ComponentType, ComponentPropsWithoutRef } from 'react';
3
3
  import { TextareaAutosizeProps } from 'react-textarea-autosize';
4
- import { T as TextContentPartComponent, I as ImageContentPartComponent, U as UIContentPartComponent, a as ToolCallContentPartComponent, b as ToolCallContentPartProps, c as ThreadState, d as Unsubscribe, M as ModelConfigProvider, e as ThreadMessage, f as ModelConfig, A as AssistantContentPart, g as AppendMessage } from './Thread-CoxBELWy.js';
5
- export { k as AppendContentPart, h as AssistantMessage, l as TextContentPart, j as UserContentPart, i as UserMessage } from './Thread-CoxBELWy.js';
4
+ import { T as TextContentPartComponent, I as ImageContentPartComponent, U as UIContentPartComponent, a as ToolCallContentPartComponent, b as ToolCallContentPartProps, c as ThreadState, d as ThreadActionsState, e as Unsubscribe, M as ModelConfigProvider, f as ThreadMessage, g as ModelConfig, A as AssistantContentPart, h as AppendMessage } from './ThreadActions-DqqhRbf1.js';
5
+ export { l as AppendContentPart, i as AssistantMessage, m as TextContentPart, k as UserContentPart, j as UserMessage } from './ThreadActions-DqqhRbf1.js';
6
6
  import { Primitive } from '@radix-ui/react-primitive';
7
7
  import 'zod';
8
8
 
@@ -237,7 +237,7 @@ declare namespace index {
237
237
  export { ContentPartDisplay as Display, ContentPartImage as Image, ContentPartInProgressIndicator as InProgressIndicator, ContentPartText as Text };
238
238
  }
239
239
 
240
- type ThreadRuntime = Readonly<ThreadState & {
240
+ type ThreadRuntime = Readonly<ThreadState & ThreadActionsState & {
241
241
  subscribe: (callback: () => void) => Unsubscribe;
242
242
  }>;
243
243