@assistant-ui/react 0.4.8 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.d.mts CHANGED
@@ -2,7 +2,7 @@ import * as react from 'react';
2
2
  import { ReactNode, ComponentType, PropsWithChildren, ComponentPropsWithoutRef, FC } from 'react';
3
3
  import { z } from 'zod';
4
4
  import { JSONSchema7 } from 'json-schema';
5
- import { LanguageModelV1FinishReason, LanguageModelV1LogProbs, LanguageModelV1Message, LanguageModelV1FunctionTool } from '@ai-sdk/provider';
5
+ import { LanguageModelV1LogProbs, LanguageModelV1Message, LanguageModelV1FunctionTool } from '@ai-sdk/provider';
6
6
  import { UseBoundStore, StoreApi } from 'zustand';
7
7
  import { Primitive } from '@radix-ui/react-primitive';
8
8
  import * as PopoverPrimitive from '@radix-ui/react-popover';
@@ -100,19 +100,38 @@ type MessageCommonProps = {
100
100
  id: string;
101
101
  createdAt: Date;
102
102
  };
103
- type MessageStatus = {
104
- type: "in_progress" | "cancelled";
105
- } | {
106
- type: "done";
107
- finishReason?: LanguageModelV1FinishReason;
108
- logprops?: LanguageModelV1LogProbs;
103
+ type ThreadRoundtrip = {
104
+ logprobs?: LanguageModelV1LogProbs | undefined;
109
105
  usage?: {
110
106
  promptTokens: number;
111
107
  completionTokens: number;
112
- };
108
+ } | undefined;
109
+ };
110
+ type ContentPartStatus = {
111
+ type: "running";
112
+ } | {
113
+ type: "complete";
114
+ } | {
115
+ type: "incomplete";
116
+ reason: "cancelled" | "length" | "content-filter" | "other" | "error";
117
+ error?: unknown;
118
+ };
119
+ type ToolContentPartStatus = {
120
+ type: "requires-action";
121
+ reason: "tool-calls";
122
+ } | ContentPartStatus;
123
+ type MessageStatus = {
124
+ type: "running";
125
+ } | {
126
+ type: "requires-action";
127
+ reason: "tool-calls";
113
128
  } | {
114
- type: "error";
115
- error: unknown;
129
+ type: "complete";
130
+ reason: "stop" | "unknown";
131
+ } | {
132
+ type: "incomplete";
133
+ reason: "cancelled" | "tool-calls" | "length" | "content-filter" | "other" | "error";
134
+ error?: unknown;
116
135
  };
117
136
  type ThreadSystemMessage = MessageCommonProps & {
118
137
  role: "system";
@@ -126,6 +145,7 @@ type ThreadAssistantMessage = MessageCommonProps & {
126
145
  role: "assistant";
127
146
  content: ThreadAssistantContentPart[];
128
147
  status: MessageStatus;
148
+ roundtrips?: ThreadRoundtrip[] | undefined;
129
149
  };
130
150
  type AppendMessage = CoreMessage & {
131
151
  parentId: string | null;
@@ -160,12 +180,13 @@ type ChatModelRunUpdate = {
160
180
  type ChatModelRunResult = {
161
181
  content: ThreadAssistantContentPart[];
162
182
  status?: MessageStatus;
183
+ roundtrips?: ThreadRoundtrip[];
163
184
  };
164
185
  type ChatModelRunOptions = {
165
186
  messages: ThreadMessage[];
166
187
  abortSignal: AbortSignal;
167
188
  config: ModelConfig;
168
- onUpdate: (result: ChatModelRunUpdate) => ThreadMessage;
189
+ onUpdate: (result: ChatModelRunUpdate) => void;
169
190
  };
170
191
  type ChatModelAdapter = {
171
192
  run: (options: ChatModelRunOptions) => Promise<ChatModelRunResult>;
@@ -183,19 +204,37 @@ declare abstract class BaseAssistantRuntime<TThreadRuntime extends ReactThreadRu
183
204
  private subscriptionHandler;
184
205
  }
185
206
 
207
+ type TextContentPartProps = {
208
+ part: TextContentPart;
209
+ status: ContentPartStatus;
210
+ };
211
+ type TextContentPartComponent = ComponentType<TextContentPartProps>;
212
+ type ImageContentPartProps = {
213
+ part: ImageContentPart;
214
+ status: ContentPartStatus;
215
+ };
216
+ type ImageContentPartComponent = ComponentType<ImageContentPartProps>;
217
+ type UIContentPartProps = {
218
+ part: UIContentPart;
219
+ status: ContentPartStatus;
220
+ };
221
+ type UIContentPartComponent = ComponentType<UIContentPartProps>;
222
+ type ToolCallContentPartProps<TArgs extends Record<string, unknown> = any, TResult = unknown> = {
223
+ part: ToolCallContentPart<TArgs, TResult>;
224
+ status: ToolContentPartStatus;
225
+ addResult: (result: any) => void;
226
+ };
227
+ type ToolCallContentPartComponent<TArgs extends Record<string, unknown> = any, TResult = any> = ComponentType<ToolCallContentPartProps<TArgs, TResult>>;
228
+
186
229
  type LocalRuntimeOptions = {
187
230
  initialMessages?: readonly CoreMessage[] | undefined;
231
+ maxToolRoundtrips?: number;
188
232
  };
189
- declare class LocalRuntime extends BaseAssistantRuntime<LocalThreadRuntime> {
190
- private readonly _proxyConfigProvider;
191
- constructor(adapter: ChatModelAdapter, options?: LocalRuntimeOptions);
192
- set adapter(adapter: ChatModelAdapter);
193
- registerModelConfigProvider(provider: ModelConfigProvider): () => void;
194
- switchToThread(threadId: string | null): LocalThreadRuntime;
195
- }
233
+
196
234
  declare class LocalThreadRuntime implements ThreadRuntime {
197
235
  private configProvider;
198
236
  adapter: ChatModelAdapter;
237
+ private options?;
199
238
  private _subscriptions;
200
239
  private abortController;
201
240
  private readonly repository;
@@ -207,51 +246,43 @@ declare class LocalThreadRuntime implements ThreadRuntime {
207
246
  }>;
208
247
  get messages(): ThreadMessage[];
209
248
  get isRunning(): boolean;
210
- constructor(configProvider: ModelConfigProvider, adapter: ChatModelAdapter, options?: LocalRuntimeOptions);
249
+ constructor(configProvider: ModelConfigProvider, adapter: ChatModelAdapter, options?: LocalRuntimeOptions | undefined);
211
250
  getBranches(messageId: string): string[];
212
251
  switchToBranch(branchId: string): void;
213
252
  append(message: AppendMessage): Promise<void>;
214
253
  startRun(parentId: string | null): Promise<void>;
254
+ private performRoundtrip;
215
255
  cancelRun(): void;
216
256
  private notifySubscribers;
217
257
  subscribe(callback: () => void): Unsubscribe;
218
258
  addToolResult({ messageId, toolCallId, result }: AddToolResultOptions): void;
219
259
  }
220
260
 
261
+ declare class LocalRuntime extends BaseAssistantRuntime<LocalThreadRuntime> {
262
+ private readonly _proxyConfigProvider;
263
+ constructor(adapter: ChatModelAdapter, options?: LocalRuntimeOptions);
264
+ set adapter(adapter: ChatModelAdapter);
265
+ registerModelConfigProvider(provider: ModelConfigProvider): () => void;
266
+ switchToThread(threadId: string | null): LocalThreadRuntime;
267
+ }
268
+
221
269
  declare const useLocalRuntime: (adapter: ChatModelAdapter, options?: LocalRuntimeOptions) => LocalRuntime;
222
270
 
223
271
  declare function toLanguageModelMessages(message: readonly CoreMessage[] | readonly ThreadMessage[]): LanguageModelV1Message[];
224
272
 
225
- type TextContentPartProps = {
226
- part: TextContentPart;
227
- status: MessageStatus;
228
- };
229
- type TextContentPartComponent = ComponentType<TextContentPartProps>;
230
- type ImageContentPartProps = {
231
- part: ImageContentPart;
232
- status: MessageStatus;
233
- };
234
- type ImageContentPartComponent = ComponentType<ImageContentPartProps>;
235
- type UIContentPartProps = {
236
- part: UIContentPart;
237
- status: MessageStatus;
238
- };
239
- type UIContentPartComponent = ComponentType<UIContentPartProps>;
240
- type ToolCallContentPartProps<TArgs extends Record<string, unknown> = any, TResult = unknown> = {
241
- part: ToolCallContentPart<TArgs, TResult>;
242
- status: MessageStatus;
243
- addResult: (result: any) => void;
244
- };
245
- type ToolCallContentPartComponent<TArgs extends Record<string, unknown> = any, TResult = any> = ComponentType<ToolCallContentPartProps<TArgs, TResult>>;
246
-
247
273
  type fromLanguageModelMessagesOptions = {
248
274
  mergeRoundtrips: boolean;
249
275
  };
250
276
  declare const fromLanguageModelMessages: (lm: LanguageModelV1Message[], { mergeRoundtrips }: fromLanguageModelMessagesOptions) => CoreMessage[];
251
277
 
252
278
  declare const fromCoreMessages: (message: readonly CoreMessage[]) => ThreadMessage[];
279
+ declare const fromCoreMessage: (message: CoreMessage, { id, status, }?: {
280
+ id?: string | undefined;
281
+ status?: MessageStatus | undefined;
282
+ }) => ThreadMessage;
253
283
 
254
284
  declare const toCoreMessages: (message: ThreadMessage[]) => CoreMessage[];
285
+ declare const toCoreMessage: (message: ThreadMessage) => CoreMessage;
255
286
 
256
287
  declare const fromLanguageModelTools: (tools: LanguageModelV1FunctionTool[]) => Record<string, Tool<any, any>>;
257
288
 
@@ -259,12 +290,10 @@ declare const toLanguageModelTools: (tools: Record<string, Tool<any, any>>) => L
259
290
 
260
291
  type EdgeChatAdapterOptions = {
261
292
  api: string;
262
- maxToolRoundtrips?: number;
263
293
  };
264
294
  declare class EdgeChatAdapter implements ChatModelAdapter {
265
295
  private options;
266
296
  constructor(options: EdgeChatAdapterOptions);
267
- roundtrip(initialContent: ThreadAssistantContentPart[], { messages, abortSignal, config, onUpdate }: ChatModelRunOptions): Promise<readonly [ThreadMessage | undefined, ChatModelRunResult]>;
268
297
  run({ messages, abortSignal, config, onUpdate }: ChatModelRunOptions): Promise<ChatModelRunResult>;
269
298
  }
270
299
 
@@ -655,7 +684,7 @@ declare function useMessageContext(options: {
655
684
  }): MessageContextValue | null;
656
685
 
657
686
  type ContentPartState = Readonly<{
658
- status: MessageStatus;
687
+ status: ToolContentPartStatus;
659
688
  part: TextContentPart | ImageContentPart | UIContentPart | ToolCallContentPart;
660
689
  }>;
661
690
 
@@ -735,17 +764,17 @@ declare const useComposerIf: (props: UseComposerIfProps) => boolean;
735
764
  declare const useComposerSend: () => (() => void) | null;
736
765
 
737
766
  declare const useContentPartDisplay: () => Readonly<{
738
- status: MessageStatus;
767
+ status: ContentPartStatus;
739
768
  part: UIContentPart;
740
769
  }>;
741
770
 
742
771
  declare const useContentPartImage: () => Readonly<{
743
- status: MessageStatus;
772
+ status: ContentPartStatus;
744
773
  part: ImageContentPart;
745
774
  }>;
746
775
 
747
776
  declare const useContentPartText: () => Readonly<{
748
- status: MessageStatus;
777
+ status: ContentPartStatus;
749
778
  part: TextContentPart;
750
779
  }>;
751
780
 
@@ -1349,7 +1378,7 @@ declare class MessageRepository {
1349
1378
  parentId: string | null;
1350
1379
  message: ThreadMessage;
1351
1380
  };
1352
- appendOptimisticMessage(parentId: string | null, message: Omit<ThreadMessage, "id" | "createdAt">): string;
1381
+ appendOptimisticMessage(parentId: string | null, message: CoreMessage): string;
1353
1382
  deleteMessage(messageId: string, replacementId?: string | null | undefined): void;
1354
1383
  getBranches(messageId: string): string[];
1355
1384
  switchToBranch(messageId: string): void;
@@ -1373,4 +1402,4 @@ declare namespace internal {
1373
1402
  export { internal_BaseAssistantRuntime as BaseAssistantRuntime, internal_MessageRepository as MessageRepository, internal_ProxyConfigProvider as ProxyConfigProvider, internal_TooltipIconButton as TooltipIconButton, internal_generateId as generateId, internal_useSmooth as useSmooth };
1374
1403
  }
1375
1404
 
1376
- export { index$6 as ActionBarPrimitive, type ActionBarPrimitiveCopyProps, type ActionBarPrimitiveEditProps, type ActionBarPrimitiveReloadProps, type ActionBarPrimitiveRootProps, type AddToolResultOptions, type AppendMessage, _default$9 as AssistantActionBar, type AssistantActionsState, type AssistantContextValue, _default$8 as AssistantMessage, type AssistantMessageConfig, type AssistantMessageContentProps, _default$7 as AssistantModal, index$5 as AssistantModalPrimitive, type AssistantModalPrimitiveContentProps, type AssistantModalPrimitiveRootProps, type AssistantModalPrimitiveTriggerProps, type AssistantModelConfigState, type AssistantRuntime, AssistantRuntimeProvider, type AssistantToolProps, type AssistantToolUIProps, type AssistantToolUIsState, _default$6 as BranchPicker, index$4 as BranchPickerPrimitive, type BranchPickerPrimitiveCountProps, type BranchPickerPrimitiveNextProps, type BranchPickerPrimitiveNumberProps, type BranchPickerPrimitivePreviousProps, type BranchPickerPrimitiveRootProps, type ChatModelAdapter, type ChatModelRunOptions, type ChatModelRunResult, type ChatModelRunUpdate, _default$5 as Composer, type ComposerContextValue, type ComposerInputProps, index$3 as ComposerPrimitive, type ComposerPrimitiveCancelProps, type ComposerPrimitiveIfProps, type ComposerPrimitiveInputProps, type ComposerPrimitiveRootProps, type ComposerPrimitiveSendProps, type ComposerState, exports as ContentPart, type ContentPartContextValue, index$2 as ContentPartPrimitive, type ContentPartPrimitiveDisplayProps, type ContentPartPrimitiveImageProps, type ContentPartPrimitiveInProgressProps, type ContentPartPrimitiveTextProps, type ContentPartState, type CoreAssistantContentPart, type CoreAssistantMessage, type CoreMessage, type CoreSystemMessage, type CoreUserContentPart, type CoreUserMessage, EdgeChatAdapter, type EdgeRuntimeOptions, type EdgeRuntimeRequestOptions, _default$4 as EditComposer, type EditComposerState, internal as INTERNAL, type ImageContentPart, type ImageContentPartComponent, type ImageContentPartProps, type LocalRuntimeOptions, type MessageContextValue, index$1 as MessagePrimitive, type MessagePrimitiveContentProps, type MessagePrimitiveIfProps, type MessagePrimitiveInProgressProps, type MessagePrimitiveRootProps, type MessageState, type MessageStatus, type MessageUtilsState, type ModelConfig, type ModelConfigProvider, type ReactThreadRuntime, type StringsConfig, type SuggestionConfig, type TextContentPart, type TextContentPartComponent, type TextContentPartProps, _default$3 as Thread, type ThreadActionsState, type ThreadAssistantContentPart, type ThreadAssistantMessage, type ThreadConfig, ThreadConfigProvider, type ThreadConfigProviderProps, type ThreadContextValue, type ThreadMessage, type ThreadMessagesState, index as ThreadPrimitive, type ThreadPrimitiveEmptyProps, type ThreadPrimitiveIfProps, type ThreadPrimitiveMessagesProps, type ThreadPrimitiveRootProps, type ThreadPrimitiveScrollToBottomProps, type ThreadPrimitiveSuggestionProps, type ThreadPrimitiveViewportProps, type ThreadRootProps, type ThreadRuntime, type ThreadState, type ThreadSystemMessage, type ThreadUserContentPart, type ThreadUserMessage, type ThreadViewportState, _default as ThreadWelcome, type ThreadWelcomeConfig, type ThreadWelcomeMessageProps, type ThreadWelcomeSuggestionProps, type Tool, type ToolCallContentPart, type ToolCallContentPartComponent, type ToolCallContentPartProps, type UIContentPart, type UIContentPartComponent, type UIContentPartProps, type Unsubscribe, type UseActionBarCopyProps, _default$1 as UserActionBar, _default$2 as UserMessage, type UserMessageConfig, type UserMessageContentProps, fromCoreMessages, fromLanguageModelMessages, fromLanguageModelTools, makeAssistantTool, makeAssistantToolUI, toCoreMessages, toLanguageModelMessages, toLanguageModelTools, useActionBarCopy, useActionBarEdit, useActionBarReload, useAppendMessage, useAssistantContext, useAssistantInstructions, useAssistantTool, useAssistantToolUI, useBranchPickerCount, useBranchPickerNext, useBranchPickerNumber, useBranchPickerPrevious, useComposerCancel, useComposerContext, useComposerIf, useComposerSend, useContentPartContext, useContentPartDisplay, useContentPartImage, useContentPartText, useEdgeRuntime, useLocalRuntime, useMessageContext, useMessageIf, useSwitchToNewThread, useThreadConfig, useThreadContext, useThreadEmpty, useThreadIf, useThreadScrollToBottom, useThreadSuggestion };
1405
+ export { index$6 as ActionBarPrimitive, type ActionBarPrimitiveCopyProps, type ActionBarPrimitiveEditProps, type ActionBarPrimitiveReloadProps, type ActionBarPrimitiveRootProps, type AddToolResultOptions, type AppendMessage, _default$9 as AssistantActionBar, type AssistantActionsState, type AssistantContextValue, _default$8 as AssistantMessage, type AssistantMessageConfig, type AssistantMessageContentProps, _default$7 as AssistantModal, index$5 as AssistantModalPrimitive, type AssistantModalPrimitiveContentProps, type AssistantModalPrimitiveRootProps, type AssistantModalPrimitiveTriggerProps, type AssistantModelConfigState, type AssistantRuntime, AssistantRuntimeProvider, type AssistantToolProps, type AssistantToolUIProps, type AssistantToolUIsState, _default$6 as BranchPicker, index$4 as BranchPickerPrimitive, type BranchPickerPrimitiveCountProps, type BranchPickerPrimitiveNextProps, type BranchPickerPrimitiveNumberProps, type BranchPickerPrimitivePreviousProps, type BranchPickerPrimitiveRootProps, type ChatModelAdapter, type ChatModelRunOptions, type ChatModelRunResult, type ChatModelRunUpdate, _default$5 as Composer, type ComposerContextValue, type ComposerInputProps, index$3 as ComposerPrimitive, type ComposerPrimitiveCancelProps, type ComposerPrimitiveIfProps, type ComposerPrimitiveInputProps, type ComposerPrimitiveRootProps, type ComposerPrimitiveSendProps, type ComposerState, exports as ContentPart, type ContentPartContextValue, index$2 as ContentPartPrimitive, type ContentPartPrimitiveDisplayProps, type ContentPartPrimitiveImageProps, type ContentPartPrimitiveInProgressProps, type ContentPartPrimitiveTextProps, type ContentPartState, type CoreAssistantContentPart, type CoreAssistantMessage, type CoreMessage, type CoreSystemMessage, type CoreUserContentPart, type CoreUserMessage, EdgeChatAdapter, type EdgeRuntimeOptions, type EdgeRuntimeRequestOptions, _default$4 as EditComposer, type EditComposerState, internal as INTERNAL, type ImageContentPart, type ImageContentPartComponent, type ImageContentPartProps, type LocalRuntimeOptions, type MessageContextValue, index$1 as MessagePrimitive, type MessagePrimitiveContentProps, type MessagePrimitiveIfProps, type MessagePrimitiveInProgressProps, type MessagePrimitiveRootProps, type MessageState, type MessageStatus, type MessageUtilsState, type ModelConfig, type ModelConfigProvider, type ReactThreadRuntime, type StringsConfig, type SuggestionConfig, type TextContentPart, type TextContentPartComponent, type TextContentPartProps, _default$3 as Thread, type ThreadActionsState, type ThreadAssistantContentPart, type ThreadAssistantMessage, type ThreadConfig, ThreadConfigProvider, type ThreadConfigProviderProps, type ThreadContextValue, type ThreadMessage, type ThreadMessagesState, index as ThreadPrimitive, type ThreadPrimitiveEmptyProps, type ThreadPrimitiveIfProps, type ThreadPrimitiveMessagesProps, type ThreadPrimitiveRootProps, type ThreadPrimitiveScrollToBottomProps, type ThreadPrimitiveSuggestionProps, type ThreadPrimitiveViewportProps, type ThreadRootProps, type ThreadRuntime, type ThreadState, type ThreadSystemMessage, type ThreadUserContentPart, type ThreadUserMessage, type ThreadViewportState, _default as ThreadWelcome, type ThreadWelcomeConfig, type ThreadWelcomeMessageProps, type ThreadWelcomeSuggestionProps, type Tool, type ToolCallContentPart, type ToolCallContentPartComponent, type ToolCallContentPartProps, type UIContentPart, type UIContentPartComponent, type UIContentPartProps, type Unsubscribe, type UseActionBarCopyProps, _default$1 as UserActionBar, _default$2 as UserMessage, type UserMessageConfig, type UserMessageContentProps, fromCoreMessage, fromCoreMessages, fromLanguageModelMessages, fromLanguageModelTools, makeAssistantTool, makeAssistantToolUI, toCoreMessage, toCoreMessages, toLanguageModelMessages, toLanguageModelTools, useActionBarCopy, useActionBarEdit, useActionBarReload, useAppendMessage, useAssistantContext, useAssistantInstructions, useAssistantTool, useAssistantToolUI, useBranchPickerCount, useBranchPickerNext, useBranchPickerNumber, useBranchPickerPrevious, useComposerCancel, useComposerContext, useComposerIf, useComposerSend, useContentPartContext, useContentPartDisplay, useContentPartImage, useContentPartText, useEdgeRuntime, useLocalRuntime, useMessageContext, useMessageIf, useSwitchToNewThread, useThreadConfig, useThreadContext, useThreadEmpty, useThreadIf, useThreadScrollToBottom, useThreadSuggestion };
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ import * as react from 'react';
2
2
  import { ReactNode, ComponentType, PropsWithChildren, ComponentPropsWithoutRef, FC } from 'react';
3
3
  import { z } from 'zod';
4
4
  import { JSONSchema7 } from 'json-schema';
5
- import { LanguageModelV1FinishReason, LanguageModelV1LogProbs, LanguageModelV1Message, LanguageModelV1FunctionTool } from '@ai-sdk/provider';
5
+ import { LanguageModelV1LogProbs, LanguageModelV1Message, LanguageModelV1FunctionTool } from '@ai-sdk/provider';
6
6
  import { UseBoundStore, StoreApi } from 'zustand';
7
7
  import { Primitive } from '@radix-ui/react-primitive';
8
8
  import * as PopoverPrimitive from '@radix-ui/react-popover';
@@ -100,19 +100,38 @@ type MessageCommonProps = {
100
100
  id: string;
101
101
  createdAt: Date;
102
102
  };
103
- type MessageStatus = {
104
- type: "in_progress" | "cancelled";
105
- } | {
106
- type: "done";
107
- finishReason?: LanguageModelV1FinishReason;
108
- logprops?: LanguageModelV1LogProbs;
103
+ type ThreadRoundtrip = {
104
+ logprobs?: LanguageModelV1LogProbs | undefined;
109
105
  usage?: {
110
106
  promptTokens: number;
111
107
  completionTokens: number;
112
- };
108
+ } | undefined;
109
+ };
110
+ type ContentPartStatus = {
111
+ type: "running";
112
+ } | {
113
+ type: "complete";
114
+ } | {
115
+ type: "incomplete";
116
+ reason: "cancelled" | "length" | "content-filter" | "other" | "error";
117
+ error?: unknown;
118
+ };
119
+ type ToolContentPartStatus = {
120
+ type: "requires-action";
121
+ reason: "tool-calls";
122
+ } | ContentPartStatus;
123
+ type MessageStatus = {
124
+ type: "running";
125
+ } | {
126
+ type: "requires-action";
127
+ reason: "tool-calls";
113
128
  } | {
114
- type: "error";
115
- error: unknown;
129
+ type: "complete";
130
+ reason: "stop" | "unknown";
131
+ } | {
132
+ type: "incomplete";
133
+ reason: "cancelled" | "tool-calls" | "length" | "content-filter" | "other" | "error";
134
+ error?: unknown;
116
135
  };
117
136
  type ThreadSystemMessage = MessageCommonProps & {
118
137
  role: "system";
@@ -126,6 +145,7 @@ type ThreadAssistantMessage = MessageCommonProps & {
126
145
  role: "assistant";
127
146
  content: ThreadAssistantContentPart[];
128
147
  status: MessageStatus;
148
+ roundtrips?: ThreadRoundtrip[] | undefined;
129
149
  };
130
150
  type AppendMessage = CoreMessage & {
131
151
  parentId: string | null;
@@ -160,12 +180,13 @@ type ChatModelRunUpdate = {
160
180
  type ChatModelRunResult = {
161
181
  content: ThreadAssistantContentPart[];
162
182
  status?: MessageStatus;
183
+ roundtrips?: ThreadRoundtrip[];
163
184
  };
164
185
  type ChatModelRunOptions = {
165
186
  messages: ThreadMessage[];
166
187
  abortSignal: AbortSignal;
167
188
  config: ModelConfig;
168
- onUpdate: (result: ChatModelRunUpdate) => ThreadMessage;
189
+ onUpdate: (result: ChatModelRunUpdate) => void;
169
190
  };
170
191
  type ChatModelAdapter = {
171
192
  run: (options: ChatModelRunOptions) => Promise<ChatModelRunResult>;
@@ -183,19 +204,37 @@ declare abstract class BaseAssistantRuntime<TThreadRuntime extends ReactThreadRu
183
204
  private subscriptionHandler;
184
205
  }
185
206
 
207
+ type TextContentPartProps = {
208
+ part: TextContentPart;
209
+ status: ContentPartStatus;
210
+ };
211
+ type TextContentPartComponent = ComponentType<TextContentPartProps>;
212
+ type ImageContentPartProps = {
213
+ part: ImageContentPart;
214
+ status: ContentPartStatus;
215
+ };
216
+ type ImageContentPartComponent = ComponentType<ImageContentPartProps>;
217
+ type UIContentPartProps = {
218
+ part: UIContentPart;
219
+ status: ContentPartStatus;
220
+ };
221
+ type UIContentPartComponent = ComponentType<UIContentPartProps>;
222
+ type ToolCallContentPartProps<TArgs extends Record<string, unknown> = any, TResult = unknown> = {
223
+ part: ToolCallContentPart<TArgs, TResult>;
224
+ status: ToolContentPartStatus;
225
+ addResult: (result: any) => void;
226
+ };
227
+ type ToolCallContentPartComponent<TArgs extends Record<string, unknown> = any, TResult = any> = ComponentType<ToolCallContentPartProps<TArgs, TResult>>;
228
+
186
229
  type LocalRuntimeOptions = {
187
230
  initialMessages?: readonly CoreMessage[] | undefined;
231
+ maxToolRoundtrips?: number;
188
232
  };
189
- declare class LocalRuntime extends BaseAssistantRuntime<LocalThreadRuntime> {
190
- private readonly _proxyConfigProvider;
191
- constructor(adapter: ChatModelAdapter, options?: LocalRuntimeOptions);
192
- set adapter(adapter: ChatModelAdapter);
193
- registerModelConfigProvider(provider: ModelConfigProvider): () => void;
194
- switchToThread(threadId: string | null): LocalThreadRuntime;
195
- }
233
+
196
234
  declare class LocalThreadRuntime implements ThreadRuntime {
197
235
  private configProvider;
198
236
  adapter: ChatModelAdapter;
237
+ private options?;
199
238
  private _subscriptions;
200
239
  private abortController;
201
240
  private readonly repository;
@@ -207,51 +246,43 @@ declare class LocalThreadRuntime implements ThreadRuntime {
207
246
  }>;
208
247
  get messages(): ThreadMessage[];
209
248
  get isRunning(): boolean;
210
- constructor(configProvider: ModelConfigProvider, adapter: ChatModelAdapter, options?: LocalRuntimeOptions);
249
+ constructor(configProvider: ModelConfigProvider, adapter: ChatModelAdapter, options?: LocalRuntimeOptions | undefined);
211
250
  getBranches(messageId: string): string[];
212
251
  switchToBranch(branchId: string): void;
213
252
  append(message: AppendMessage): Promise<void>;
214
253
  startRun(parentId: string | null): Promise<void>;
254
+ private performRoundtrip;
215
255
  cancelRun(): void;
216
256
  private notifySubscribers;
217
257
  subscribe(callback: () => void): Unsubscribe;
218
258
  addToolResult({ messageId, toolCallId, result }: AddToolResultOptions): void;
219
259
  }
220
260
 
261
+ declare class LocalRuntime extends BaseAssistantRuntime<LocalThreadRuntime> {
262
+ private readonly _proxyConfigProvider;
263
+ constructor(adapter: ChatModelAdapter, options?: LocalRuntimeOptions);
264
+ set adapter(adapter: ChatModelAdapter);
265
+ registerModelConfigProvider(provider: ModelConfigProvider): () => void;
266
+ switchToThread(threadId: string | null): LocalThreadRuntime;
267
+ }
268
+
221
269
  declare const useLocalRuntime: (adapter: ChatModelAdapter, options?: LocalRuntimeOptions) => LocalRuntime;
222
270
 
223
271
  declare function toLanguageModelMessages(message: readonly CoreMessage[] | readonly ThreadMessage[]): LanguageModelV1Message[];
224
272
 
225
- type TextContentPartProps = {
226
- part: TextContentPart;
227
- status: MessageStatus;
228
- };
229
- type TextContentPartComponent = ComponentType<TextContentPartProps>;
230
- type ImageContentPartProps = {
231
- part: ImageContentPart;
232
- status: MessageStatus;
233
- };
234
- type ImageContentPartComponent = ComponentType<ImageContentPartProps>;
235
- type UIContentPartProps = {
236
- part: UIContentPart;
237
- status: MessageStatus;
238
- };
239
- type UIContentPartComponent = ComponentType<UIContentPartProps>;
240
- type ToolCallContentPartProps<TArgs extends Record<string, unknown> = any, TResult = unknown> = {
241
- part: ToolCallContentPart<TArgs, TResult>;
242
- status: MessageStatus;
243
- addResult: (result: any) => void;
244
- };
245
- type ToolCallContentPartComponent<TArgs extends Record<string, unknown> = any, TResult = any> = ComponentType<ToolCallContentPartProps<TArgs, TResult>>;
246
-
247
273
  type fromLanguageModelMessagesOptions = {
248
274
  mergeRoundtrips: boolean;
249
275
  };
250
276
  declare const fromLanguageModelMessages: (lm: LanguageModelV1Message[], { mergeRoundtrips }: fromLanguageModelMessagesOptions) => CoreMessage[];
251
277
 
252
278
  declare const fromCoreMessages: (message: readonly CoreMessage[]) => ThreadMessage[];
279
+ declare const fromCoreMessage: (message: CoreMessage, { id, status, }?: {
280
+ id?: string | undefined;
281
+ status?: MessageStatus | undefined;
282
+ }) => ThreadMessage;
253
283
 
254
284
  declare const toCoreMessages: (message: ThreadMessage[]) => CoreMessage[];
285
+ declare const toCoreMessage: (message: ThreadMessage) => CoreMessage;
255
286
 
256
287
  declare const fromLanguageModelTools: (tools: LanguageModelV1FunctionTool[]) => Record<string, Tool<any, any>>;
257
288
 
@@ -259,12 +290,10 @@ declare const toLanguageModelTools: (tools: Record<string, Tool<any, any>>) => L
259
290
 
260
291
  type EdgeChatAdapterOptions = {
261
292
  api: string;
262
- maxToolRoundtrips?: number;
263
293
  };
264
294
  declare class EdgeChatAdapter implements ChatModelAdapter {
265
295
  private options;
266
296
  constructor(options: EdgeChatAdapterOptions);
267
- roundtrip(initialContent: ThreadAssistantContentPart[], { messages, abortSignal, config, onUpdate }: ChatModelRunOptions): Promise<readonly [ThreadMessage | undefined, ChatModelRunResult]>;
268
297
  run({ messages, abortSignal, config, onUpdate }: ChatModelRunOptions): Promise<ChatModelRunResult>;
269
298
  }
270
299
 
@@ -655,7 +684,7 @@ declare function useMessageContext(options: {
655
684
  }): MessageContextValue | null;
656
685
 
657
686
  type ContentPartState = Readonly<{
658
- status: MessageStatus;
687
+ status: ToolContentPartStatus;
659
688
  part: TextContentPart | ImageContentPart | UIContentPart | ToolCallContentPart;
660
689
  }>;
661
690
 
@@ -735,17 +764,17 @@ declare const useComposerIf: (props: UseComposerIfProps) => boolean;
735
764
  declare const useComposerSend: () => (() => void) | null;
736
765
 
737
766
  declare const useContentPartDisplay: () => Readonly<{
738
- status: MessageStatus;
767
+ status: ContentPartStatus;
739
768
  part: UIContentPart;
740
769
  }>;
741
770
 
742
771
  declare const useContentPartImage: () => Readonly<{
743
- status: MessageStatus;
772
+ status: ContentPartStatus;
744
773
  part: ImageContentPart;
745
774
  }>;
746
775
 
747
776
  declare const useContentPartText: () => Readonly<{
748
- status: MessageStatus;
777
+ status: ContentPartStatus;
749
778
  part: TextContentPart;
750
779
  }>;
751
780
 
@@ -1349,7 +1378,7 @@ declare class MessageRepository {
1349
1378
  parentId: string | null;
1350
1379
  message: ThreadMessage;
1351
1380
  };
1352
- appendOptimisticMessage(parentId: string | null, message: Omit<ThreadMessage, "id" | "createdAt">): string;
1381
+ appendOptimisticMessage(parentId: string | null, message: CoreMessage): string;
1353
1382
  deleteMessage(messageId: string, replacementId?: string | null | undefined): void;
1354
1383
  getBranches(messageId: string): string[];
1355
1384
  switchToBranch(messageId: string): void;
@@ -1373,4 +1402,4 @@ declare namespace internal {
1373
1402
  export { internal_BaseAssistantRuntime as BaseAssistantRuntime, internal_MessageRepository as MessageRepository, internal_ProxyConfigProvider as ProxyConfigProvider, internal_TooltipIconButton as TooltipIconButton, internal_generateId as generateId, internal_useSmooth as useSmooth };
1374
1403
  }
1375
1404
 
1376
- export { index$6 as ActionBarPrimitive, type ActionBarPrimitiveCopyProps, type ActionBarPrimitiveEditProps, type ActionBarPrimitiveReloadProps, type ActionBarPrimitiveRootProps, type AddToolResultOptions, type AppendMessage, _default$9 as AssistantActionBar, type AssistantActionsState, type AssistantContextValue, _default$8 as AssistantMessage, type AssistantMessageConfig, type AssistantMessageContentProps, _default$7 as AssistantModal, index$5 as AssistantModalPrimitive, type AssistantModalPrimitiveContentProps, type AssistantModalPrimitiveRootProps, type AssistantModalPrimitiveTriggerProps, type AssistantModelConfigState, type AssistantRuntime, AssistantRuntimeProvider, type AssistantToolProps, type AssistantToolUIProps, type AssistantToolUIsState, _default$6 as BranchPicker, index$4 as BranchPickerPrimitive, type BranchPickerPrimitiveCountProps, type BranchPickerPrimitiveNextProps, type BranchPickerPrimitiveNumberProps, type BranchPickerPrimitivePreviousProps, type BranchPickerPrimitiveRootProps, type ChatModelAdapter, type ChatModelRunOptions, type ChatModelRunResult, type ChatModelRunUpdate, _default$5 as Composer, type ComposerContextValue, type ComposerInputProps, index$3 as ComposerPrimitive, type ComposerPrimitiveCancelProps, type ComposerPrimitiveIfProps, type ComposerPrimitiveInputProps, type ComposerPrimitiveRootProps, type ComposerPrimitiveSendProps, type ComposerState, exports as ContentPart, type ContentPartContextValue, index$2 as ContentPartPrimitive, type ContentPartPrimitiveDisplayProps, type ContentPartPrimitiveImageProps, type ContentPartPrimitiveInProgressProps, type ContentPartPrimitiveTextProps, type ContentPartState, type CoreAssistantContentPart, type CoreAssistantMessage, type CoreMessage, type CoreSystemMessage, type CoreUserContentPart, type CoreUserMessage, EdgeChatAdapter, type EdgeRuntimeOptions, type EdgeRuntimeRequestOptions, _default$4 as EditComposer, type EditComposerState, internal as INTERNAL, type ImageContentPart, type ImageContentPartComponent, type ImageContentPartProps, type LocalRuntimeOptions, type MessageContextValue, index$1 as MessagePrimitive, type MessagePrimitiveContentProps, type MessagePrimitiveIfProps, type MessagePrimitiveInProgressProps, type MessagePrimitiveRootProps, type MessageState, type MessageStatus, type MessageUtilsState, type ModelConfig, type ModelConfigProvider, type ReactThreadRuntime, type StringsConfig, type SuggestionConfig, type TextContentPart, type TextContentPartComponent, type TextContentPartProps, _default$3 as Thread, type ThreadActionsState, type ThreadAssistantContentPart, type ThreadAssistantMessage, type ThreadConfig, ThreadConfigProvider, type ThreadConfigProviderProps, type ThreadContextValue, type ThreadMessage, type ThreadMessagesState, index as ThreadPrimitive, type ThreadPrimitiveEmptyProps, type ThreadPrimitiveIfProps, type ThreadPrimitiveMessagesProps, type ThreadPrimitiveRootProps, type ThreadPrimitiveScrollToBottomProps, type ThreadPrimitiveSuggestionProps, type ThreadPrimitiveViewportProps, type ThreadRootProps, type ThreadRuntime, type ThreadState, type ThreadSystemMessage, type ThreadUserContentPart, type ThreadUserMessage, type ThreadViewportState, _default as ThreadWelcome, type ThreadWelcomeConfig, type ThreadWelcomeMessageProps, type ThreadWelcomeSuggestionProps, type Tool, type ToolCallContentPart, type ToolCallContentPartComponent, type ToolCallContentPartProps, type UIContentPart, type UIContentPartComponent, type UIContentPartProps, type Unsubscribe, type UseActionBarCopyProps, _default$1 as UserActionBar, _default$2 as UserMessage, type UserMessageConfig, type UserMessageContentProps, fromCoreMessages, fromLanguageModelMessages, fromLanguageModelTools, makeAssistantTool, makeAssistantToolUI, toCoreMessages, toLanguageModelMessages, toLanguageModelTools, useActionBarCopy, useActionBarEdit, useActionBarReload, useAppendMessage, useAssistantContext, useAssistantInstructions, useAssistantTool, useAssistantToolUI, useBranchPickerCount, useBranchPickerNext, useBranchPickerNumber, useBranchPickerPrevious, useComposerCancel, useComposerContext, useComposerIf, useComposerSend, useContentPartContext, useContentPartDisplay, useContentPartImage, useContentPartText, useEdgeRuntime, useLocalRuntime, useMessageContext, useMessageIf, useSwitchToNewThread, useThreadConfig, useThreadContext, useThreadEmpty, useThreadIf, useThreadScrollToBottom, useThreadSuggestion };
1405
+ export { index$6 as ActionBarPrimitive, type ActionBarPrimitiveCopyProps, type ActionBarPrimitiveEditProps, type ActionBarPrimitiveReloadProps, type ActionBarPrimitiveRootProps, type AddToolResultOptions, type AppendMessage, _default$9 as AssistantActionBar, type AssistantActionsState, type AssistantContextValue, _default$8 as AssistantMessage, type AssistantMessageConfig, type AssistantMessageContentProps, _default$7 as AssistantModal, index$5 as AssistantModalPrimitive, type AssistantModalPrimitiveContentProps, type AssistantModalPrimitiveRootProps, type AssistantModalPrimitiveTriggerProps, type AssistantModelConfigState, type AssistantRuntime, AssistantRuntimeProvider, type AssistantToolProps, type AssistantToolUIProps, type AssistantToolUIsState, _default$6 as BranchPicker, index$4 as BranchPickerPrimitive, type BranchPickerPrimitiveCountProps, type BranchPickerPrimitiveNextProps, type BranchPickerPrimitiveNumberProps, type BranchPickerPrimitivePreviousProps, type BranchPickerPrimitiveRootProps, type ChatModelAdapter, type ChatModelRunOptions, type ChatModelRunResult, type ChatModelRunUpdate, _default$5 as Composer, type ComposerContextValue, type ComposerInputProps, index$3 as ComposerPrimitive, type ComposerPrimitiveCancelProps, type ComposerPrimitiveIfProps, type ComposerPrimitiveInputProps, type ComposerPrimitiveRootProps, type ComposerPrimitiveSendProps, type ComposerState, exports as ContentPart, type ContentPartContextValue, index$2 as ContentPartPrimitive, type ContentPartPrimitiveDisplayProps, type ContentPartPrimitiveImageProps, type ContentPartPrimitiveInProgressProps, type ContentPartPrimitiveTextProps, type ContentPartState, type CoreAssistantContentPart, type CoreAssistantMessage, type CoreMessage, type CoreSystemMessage, type CoreUserContentPart, type CoreUserMessage, EdgeChatAdapter, type EdgeRuntimeOptions, type EdgeRuntimeRequestOptions, _default$4 as EditComposer, type EditComposerState, internal as INTERNAL, type ImageContentPart, type ImageContentPartComponent, type ImageContentPartProps, type LocalRuntimeOptions, type MessageContextValue, index$1 as MessagePrimitive, type MessagePrimitiveContentProps, type MessagePrimitiveIfProps, type MessagePrimitiveInProgressProps, type MessagePrimitiveRootProps, type MessageState, type MessageStatus, type MessageUtilsState, type ModelConfig, type ModelConfigProvider, type ReactThreadRuntime, type StringsConfig, type SuggestionConfig, type TextContentPart, type TextContentPartComponent, type TextContentPartProps, _default$3 as Thread, type ThreadActionsState, type ThreadAssistantContentPart, type ThreadAssistantMessage, type ThreadConfig, ThreadConfigProvider, type ThreadConfigProviderProps, type ThreadContextValue, type ThreadMessage, type ThreadMessagesState, index as ThreadPrimitive, type ThreadPrimitiveEmptyProps, type ThreadPrimitiveIfProps, type ThreadPrimitiveMessagesProps, type ThreadPrimitiveRootProps, type ThreadPrimitiveScrollToBottomProps, type ThreadPrimitiveSuggestionProps, type ThreadPrimitiveViewportProps, type ThreadRootProps, type ThreadRuntime, type ThreadState, type ThreadSystemMessage, type ThreadUserContentPart, type ThreadUserMessage, type ThreadViewportState, _default as ThreadWelcome, type ThreadWelcomeConfig, type ThreadWelcomeMessageProps, type ThreadWelcomeSuggestionProps, type Tool, type ToolCallContentPart, type ToolCallContentPartComponent, type ToolCallContentPartProps, type UIContentPart, type UIContentPartComponent, type UIContentPartProps, type Unsubscribe, type UseActionBarCopyProps, _default$1 as UserActionBar, _default$2 as UserMessage, type UserMessageConfig, type UserMessageContentProps, fromCoreMessage, fromCoreMessages, fromLanguageModelMessages, fromLanguageModelTools, makeAssistantTool, makeAssistantToolUI, toCoreMessage, toCoreMessages, toLanguageModelMessages, toLanguageModelTools, useActionBarCopy, useActionBarEdit, useActionBarReload, useAppendMessage, useAssistantContext, useAssistantInstructions, useAssistantTool, useAssistantToolUI, useBranchPickerCount, useBranchPickerNext, useBranchPickerNumber, useBranchPickerPrevious, useComposerCancel, useComposerContext, useComposerIf, useComposerSend, useContentPartContext, useContentPartDisplay, useContentPartImage, useContentPartText, useEdgeRuntime, useLocalRuntime, useMessageContext, useMessageIf, useSwitchToNewThread, useThreadConfig, useThreadContext, useThreadEmpty, useThreadIf, useThreadScrollToBottom, useThreadSuggestion };