@assistant-ui/react 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.d.mts CHANGED
@@ -2,6 +2,7 @@ import * as react from 'react';
2
2
  import { FC, ReactNode, PropsWithChildren, ComponentType } from 'react';
3
3
  import { TextareaAutosizeProps } from 'react-textarea-autosize';
4
4
  import { UseChatHelpers, UseAssistantHelpers } from 'ai/react';
5
+ import * as react_jsx_runtime from 'react/jsx-runtime';
5
6
  import { UseBoundStore, StoreApi } from 'zustand';
6
7
 
7
8
  declare const ThreadRoot: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
@@ -112,50 +113,49 @@ type MessageComposerState = BaseComposerState & {
112
113
  cancel: () => boolean;
113
114
  };
114
115
 
115
- type ThreadMessageTextPart = {
116
+ type TextContentPart = {
116
117
  type: "text";
117
118
  text: string;
118
119
  };
119
- type ThreadMessageImagePart = {
120
+ type ImageContentPart = {
120
121
  type: "image";
121
122
  image: string;
122
123
  };
123
- type ThreadMessageUIPart = {
124
+ type UIContentPart = {
124
125
  type: "ui";
125
126
  display: ReactNode;
126
127
  };
127
- type ThreadMessageToolCallPart = {
128
+ type ToolCallContentPart = {
128
129
  type: "tool-call";
129
130
  name: string;
130
131
  args: object;
131
132
  result?: object;
132
133
  };
133
- type CreateThreadUserMessageContent = ThreadMessageTextPart | ThreadMessageImagePart;
134
- type ThreadUserMessageContent = ThreadMessageTextPart | ThreadMessageImagePart | ThreadMessageUIPart;
135
- type ThreadAssistantMessageContent = ThreadMessageTextPart | ThreadMessageImagePart | ThreadMessageUIPart | ThreadMessageToolCallPart;
136
- type ThreadMessageBase = {
134
+ type UserContentPart = TextContentPart | ImageContentPart | UIContentPart;
135
+ type AssistantContentPart = TextContentPart | ImageContentPart | UIContentPart | ToolCallContentPart;
136
+ type AppendContentPart = TextContentPart | ImageContentPart;
137
+ type BaseMessage = {
137
138
  id: string;
138
- parentId: string | null;
139
139
  createdAt: Date;
140
140
  };
141
- type ThreadUserMessage = ThreadMessageBase & {
141
+ type UserMessage = BaseMessage & {
142
142
  role: "user";
143
- content: ThreadUserMessageContent[];
143
+ content: UserContentPart[];
144
144
  };
145
- type ThreadAssistantMessage = ThreadMessageBase & {
145
+ type AssistantMessage = BaseMessage & {
146
146
  role: "assistant";
147
- content: ThreadAssistantMessageContent[];
147
+ content: AssistantContentPart[];
148
148
  };
149
- type CreateThreadMessage = {
149
+ type AppendMessage = {
150
150
  parentId: string | null;
151
- content: CreateThreadUserMessageContent[];
151
+ content: AppendContentPart[];
152
152
  };
153
- type ThreadMessage = ThreadUserMessage | ThreadAssistantMessage;
153
+ type ThreadMessage = UserMessage | AssistantMessage;
154
154
 
155
- type MessageProviderProps = {
156
- children?: ReactNode;
155
+ type MessageProviderProps = PropsWithChildren<{
157
156
  message: ThreadMessage;
158
- };
157
+ parentId: string | null;
158
+ }>;
159
159
  declare const MessageProvider: FC<MessageProviderProps>;
160
160
 
161
161
  declare const MessageRoot: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
@@ -179,20 +179,20 @@ declare const MessageIf: FC<MessageIfProps>;
179
179
  type MessageContentProps = {
180
180
  components?: {
181
181
  Text?: ComponentType<{
182
- part: ThreadMessageTextPart;
182
+ part: TextContentPart;
183
183
  }>;
184
184
  Image?: ComponentType<{
185
- part: ThreadMessageImagePart;
185
+ part: ImageContentPart;
186
186
  }>;
187
187
  UI?: ComponentType<{
188
- part: ThreadMessageUIPart;
188
+ part: UIContentPart;
189
189
  }>;
190
190
  tools?: {
191
191
  by_name?: Record<string, ComponentType<{
192
- part: ThreadMessageToolCallPart;
192
+ part: ToolCallContentPart;
193
193
  }>>;
194
194
  Fallback?: ComponentType<{
195
- part: ThreadMessageToolCallPart;
195
+ part: ToolCallContentPart;
196
196
  }>;
197
197
  };
198
198
  };
@@ -279,14 +279,22 @@ type VercelRSCMessage = {
279
279
  display: ReactNode;
280
280
  createdAt?: Date;
281
281
  };
282
- type VercelRSCAssistantProviderProps = PropsWithChildren<{
283
- messages: VercelRSCMessage[];
284
- append: (message: CreateThreadMessage) => Promise<void>;
282
+ type VercelRSCAssistantProviderBaseProps<T> = PropsWithChildren<{
283
+ messages: T[];
284
+ append: (message: AppendMessage) => Promise<void>;
285
+ edit?: (message: AppendMessage) => Promise<void>;
286
+ reload?: (parentId: string | null) => Promise<void>;
287
+ convertMessage?: (message: T) => VercelRSCMessage;
285
288
  }>;
286
- declare const VercelRSCAssistantProvider: FC<VercelRSCAssistantProviderProps>;
289
+ type RSCMessageConverter<T> = {
290
+ convertMessage: (message: T) => VercelRSCMessage;
291
+ };
292
+ type VercelRSCAssistantProviderProps<T = VercelRSCMessage> = VercelRSCAssistantProviderBaseProps<T> & (T extends VercelRSCMessage ? object : RSCMessageConverter<T>);
293
+ declare const VercelRSCAssistantProvider: <T extends WeakKey = VercelRSCMessage>({ children, convertMessage, messages: vercelMessages, append: appendCallback, edit, reload, }: VercelRSCAssistantProviderProps<T>) => react_jsx_runtime.JSX.Element;
287
294
 
288
295
  type MessageState = {
289
296
  message: ThreadMessage;
297
+ parentId: string | null;
290
298
  branches: string[];
291
299
  isLast: boolean;
292
300
  isCopied: boolean;
@@ -313,4 +321,4 @@ declare const useGoToNextBranch: () => (() => void) | null;
313
321
 
314
322
  declare const useGoToPreviousBranch: () => (() => void) | null;
315
323
 
316
- export { index as ActionBarPrimitive, index$1 as BranchPickerPrimitive, index$3 as ComposerPrimitive, type CreateThreadMessage, type CreateThreadUserMessageContent, index$2 as MessagePrimitive, type VercelRSCMessage as RSCMessage, type ThreadMessageImagePart, type ThreadMessageTextPart, index$4 as ThreadPrimitive, VercelAIAssistantProvider, type VercelAIAssistantProviderProps, VercelRSCAssistantProvider, type VercelRSCAssistantProviderProps, useMessageContext as unstable_useMessageContext, useBeginMessageEdit, useCopyMessage, useGoToNextBranch, useGoToPreviousBranch, useReloadMessage };
324
+ export { index as ActionBarPrimitive, type AppendContentPart, type AppendMessage, index$1 as BranchPickerPrimitive, index$3 as ComposerPrimitive, type ImageContentPart, index$2 as MessagePrimitive, type VercelRSCMessage as RSCMessage, type TextContentPart, index$4 as ThreadPrimitive, VercelAIAssistantProvider, type VercelAIAssistantProviderProps, VercelRSCAssistantProvider, type VercelRSCAssistantProviderProps, useMessageContext as unstable_useMessageContext, useBeginMessageEdit, useCopyMessage, useGoToNextBranch, useGoToPreviousBranch, useReloadMessage };
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ import * as react from 'react';
2
2
  import { FC, ReactNode, PropsWithChildren, ComponentType } from 'react';
3
3
  import { TextareaAutosizeProps } from 'react-textarea-autosize';
4
4
  import { UseChatHelpers, UseAssistantHelpers } from 'ai/react';
5
+ import * as react_jsx_runtime from 'react/jsx-runtime';
5
6
  import { UseBoundStore, StoreApi } from 'zustand';
6
7
 
7
8
  declare const ThreadRoot: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
@@ -112,50 +113,49 @@ type MessageComposerState = BaseComposerState & {
112
113
  cancel: () => boolean;
113
114
  };
114
115
 
115
- type ThreadMessageTextPart = {
116
+ type TextContentPart = {
116
117
  type: "text";
117
118
  text: string;
118
119
  };
119
- type ThreadMessageImagePart = {
120
+ type ImageContentPart = {
120
121
  type: "image";
121
122
  image: string;
122
123
  };
123
- type ThreadMessageUIPart = {
124
+ type UIContentPart = {
124
125
  type: "ui";
125
126
  display: ReactNode;
126
127
  };
127
- type ThreadMessageToolCallPart = {
128
+ type ToolCallContentPart = {
128
129
  type: "tool-call";
129
130
  name: string;
130
131
  args: object;
131
132
  result?: object;
132
133
  };
133
- type CreateThreadUserMessageContent = ThreadMessageTextPart | ThreadMessageImagePart;
134
- type ThreadUserMessageContent = ThreadMessageTextPart | ThreadMessageImagePart | ThreadMessageUIPart;
135
- type ThreadAssistantMessageContent = ThreadMessageTextPart | ThreadMessageImagePart | ThreadMessageUIPart | ThreadMessageToolCallPart;
136
- type ThreadMessageBase = {
134
+ type UserContentPart = TextContentPart | ImageContentPart | UIContentPart;
135
+ type AssistantContentPart = TextContentPart | ImageContentPart | UIContentPart | ToolCallContentPart;
136
+ type AppendContentPart = TextContentPart | ImageContentPart;
137
+ type BaseMessage = {
137
138
  id: string;
138
- parentId: string | null;
139
139
  createdAt: Date;
140
140
  };
141
- type ThreadUserMessage = ThreadMessageBase & {
141
+ type UserMessage = BaseMessage & {
142
142
  role: "user";
143
- content: ThreadUserMessageContent[];
143
+ content: UserContentPart[];
144
144
  };
145
- type ThreadAssistantMessage = ThreadMessageBase & {
145
+ type AssistantMessage = BaseMessage & {
146
146
  role: "assistant";
147
- content: ThreadAssistantMessageContent[];
147
+ content: AssistantContentPart[];
148
148
  };
149
- type CreateThreadMessage = {
149
+ type AppendMessage = {
150
150
  parentId: string | null;
151
- content: CreateThreadUserMessageContent[];
151
+ content: AppendContentPart[];
152
152
  };
153
- type ThreadMessage = ThreadUserMessage | ThreadAssistantMessage;
153
+ type ThreadMessage = UserMessage | AssistantMessage;
154
154
 
155
- type MessageProviderProps = {
156
- children?: ReactNode;
155
+ type MessageProviderProps = PropsWithChildren<{
157
156
  message: ThreadMessage;
158
- };
157
+ parentId: string | null;
158
+ }>;
159
159
  declare const MessageProvider: FC<MessageProviderProps>;
160
160
 
161
161
  declare const MessageRoot: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
@@ -179,20 +179,20 @@ declare const MessageIf: FC<MessageIfProps>;
179
179
  type MessageContentProps = {
180
180
  components?: {
181
181
  Text?: ComponentType<{
182
- part: ThreadMessageTextPart;
182
+ part: TextContentPart;
183
183
  }>;
184
184
  Image?: ComponentType<{
185
- part: ThreadMessageImagePart;
185
+ part: ImageContentPart;
186
186
  }>;
187
187
  UI?: ComponentType<{
188
- part: ThreadMessageUIPart;
188
+ part: UIContentPart;
189
189
  }>;
190
190
  tools?: {
191
191
  by_name?: Record<string, ComponentType<{
192
- part: ThreadMessageToolCallPart;
192
+ part: ToolCallContentPart;
193
193
  }>>;
194
194
  Fallback?: ComponentType<{
195
- part: ThreadMessageToolCallPart;
195
+ part: ToolCallContentPart;
196
196
  }>;
197
197
  };
198
198
  };
@@ -279,14 +279,22 @@ type VercelRSCMessage = {
279
279
  display: ReactNode;
280
280
  createdAt?: Date;
281
281
  };
282
- type VercelRSCAssistantProviderProps = PropsWithChildren<{
283
- messages: VercelRSCMessage[];
284
- append: (message: CreateThreadMessage) => Promise<void>;
282
+ type VercelRSCAssistantProviderBaseProps<T> = PropsWithChildren<{
283
+ messages: T[];
284
+ append: (message: AppendMessage) => Promise<void>;
285
+ edit?: (message: AppendMessage) => Promise<void>;
286
+ reload?: (parentId: string | null) => Promise<void>;
287
+ convertMessage?: (message: T) => VercelRSCMessage;
285
288
  }>;
286
- declare const VercelRSCAssistantProvider: FC<VercelRSCAssistantProviderProps>;
289
+ type RSCMessageConverter<T> = {
290
+ convertMessage: (message: T) => VercelRSCMessage;
291
+ };
292
+ type VercelRSCAssistantProviderProps<T = VercelRSCMessage> = VercelRSCAssistantProviderBaseProps<T> & (T extends VercelRSCMessage ? object : RSCMessageConverter<T>);
293
+ declare const VercelRSCAssistantProvider: <T extends WeakKey = VercelRSCMessage>({ children, convertMessage, messages: vercelMessages, append: appendCallback, edit, reload, }: VercelRSCAssistantProviderProps<T>) => react_jsx_runtime.JSX.Element;
287
294
 
288
295
  type MessageState = {
289
296
  message: ThreadMessage;
297
+ parentId: string | null;
290
298
  branches: string[];
291
299
  isLast: boolean;
292
300
  isCopied: boolean;
@@ -313,4 +321,4 @@ declare const useGoToNextBranch: () => (() => void) | null;
313
321
 
314
322
  declare const useGoToPreviousBranch: () => (() => void) | null;
315
323
 
316
- export { index as ActionBarPrimitive, index$1 as BranchPickerPrimitive, index$3 as ComposerPrimitive, type CreateThreadMessage, type CreateThreadUserMessageContent, index$2 as MessagePrimitive, type VercelRSCMessage as RSCMessage, type ThreadMessageImagePart, type ThreadMessageTextPart, index$4 as ThreadPrimitive, VercelAIAssistantProvider, type VercelAIAssistantProviderProps, VercelRSCAssistantProvider, type VercelRSCAssistantProviderProps, useMessageContext as unstable_useMessageContext, useBeginMessageEdit, useCopyMessage, useGoToNextBranch, useGoToPreviousBranch, useReloadMessage };
324
+ export { index as ActionBarPrimitive, type AppendContentPart, type AppendMessage, index$1 as BranchPickerPrimitive, index$3 as ComposerPrimitive, type ImageContentPart, index$2 as MessagePrimitive, type VercelRSCMessage as RSCMessage, type TextContentPart, index$4 as ThreadPrimitive, VercelAIAssistantProvider, type VercelAIAssistantProviderProps, VercelRSCAssistantProvider, type VercelRSCAssistantProviderProps, useMessageContext as unstable_useMessageContext, useBeginMessageEdit, useCopyMessage, useGoToNextBranch, useGoToPreviousBranch, useReloadMessage };