@assistant-ui/react 0.4.3 → 0.4.5
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/edge.d.mts +94 -3
- package/dist/edge.d.ts +94 -3
- package/dist/edge.js +754 -107
- package/dist/edge.js.map +1 -1
- package/dist/edge.mjs +744 -107
- package/dist/edge.mjs.map +1 -1
- package/dist/index.d.mts +79 -65
- package/dist/index.d.ts +79 -65
- package/dist/index.js +671 -381
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +670 -384
- package/dist/index.mjs.map +1 -1
- package/dist/styles/index.css +155 -155
- package/dist/styles/index.css.map +1 -1
- package/dist/styles/modal.css +22 -22
- package/dist/styles/modal.css.map +1 -1
- package/dist/styles/tailwindcss/base-components.css +11 -11
- package/dist/styles/tailwindcss/modal.css +5 -5
- package/dist/styles/tailwindcss/thread.css +35 -35
- package/package.json +3 -3
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 } from '@ai-sdk/provider';
|
5
|
+
import { LanguageModelV1FinishReason, LanguageModelV1LogProbs, LanguageModelV1Message } 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';
|
@@ -16,14 +16,16 @@ type ToolExecuteFunction<TArgs, TResult> = (args: TArgs) => TResult | Promise<TR
|
|
16
16
|
type Tool<TArgs = unknown, TResult = unknown> = {
|
17
17
|
description?: string | undefined;
|
18
18
|
parameters: z.ZodSchema<TArgs> | JSONSchema7;
|
19
|
-
execute
|
19
|
+
execute?: ToolExecuteFunction<TArgs, TResult>;
|
20
20
|
};
|
21
21
|
type ModelConfig = {
|
22
22
|
priority?: number | undefined;
|
23
23
|
system?: string | undefined;
|
24
24
|
tools?: Record<string, Tool<any, any>> | undefined;
|
25
25
|
};
|
26
|
-
type ModelConfigProvider =
|
26
|
+
type ModelConfigProvider = {
|
27
|
+
getModelConfig: () => ModelConfig;
|
28
|
+
};
|
27
29
|
|
28
30
|
type Unsubscribe = () => void;
|
29
31
|
|
@@ -43,12 +45,13 @@ type ToolCallContentPart<TArgs = unknown, TResult = unknown> = {
|
|
43
45
|
type: "tool-call";
|
44
46
|
toolCallId: string;
|
45
47
|
toolName: string;
|
48
|
+
argsText: string;
|
46
49
|
args: TArgs;
|
47
50
|
result?: TResult;
|
51
|
+
isError?: boolean;
|
48
52
|
};
|
49
53
|
type ThreadUserContentPart = TextContentPart | ImageContentPart | UIContentPart;
|
50
54
|
type ThreadAssistantContentPart = TextContentPart | ToolCallContentPart | UIContentPart;
|
51
|
-
type AppendContentPart = TextContentPart | ImageContentPart;
|
52
55
|
type MessageCommonProps = {
|
53
56
|
id: string;
|
54
57
|
createdAt: Date;
|
@@ -80,25 +83,26 @@ type ThreadAssistantMessage = MessageCommonProps & {
|
|
80
83
|
content: ThreadAssistantContentPart[];
|
81
84
|
status: MessageStatus;
|
82
85
|
};
|
83
|
-
type AppendMessage = {
|
86
|
+
type AppendMessage = CoreMessage & {
|
84
87
|
parentId: string | null;
|
85
|
-
role: "user";
|
86
|
-
content: AppendContentPart[];
|
87
88
|
};
|
88
89
|
type ThreadMessage = ThreadSystemMessage | ThreadUserMessage | ThreadAssistantMessage;
|
89
90
|
/** Core Message Types (without UI content parts) */
|
90
91
|
type CoreUserContentPart = TextContentPart | ImageContentPart;
|
91
92
|
type CoreAssistantContentPart = TextContentPart | ToolCallContentPart;
|
92
|
-
type
|
93
|
+
type CoreSystemMessage = {
|
94
|
+
role: "system";
|
95
|
+
content: [TextContentPart];
|
96
|
+
};
|
97
|
+
type CoreUserMessage = {
|
93
98
|
role: "user";
|
94
99
|
content: CoreUserContentPart[];
|
95
100
|
};
|
96
|
-
type CoreAssistantMessage =
|
101
|
+
type CoreAssistantMessage = {
|
97
102
|
role: "assistant";
|
98
103
|
content: CoreAssistantContentPart[];
|
99
|
-
status: MessageStatus;
|
100
104
|
};
|
101
|
-
type
|
105
|
+
type CoreMessage = CoreSystemMessage | CoreUserMessage | CoreAssistantMessage;
|
102
106
|
|
103
107
|
type ReactThreadRuntime = ThreadRuntime & {
|
104
108
|
unstable_synchronizer?: ComponentType;
|
@@ -115,7 +119,7 @@ type ChatModelRunOptions = {
|
|
115
119
|
messages: ThreadMessage[];
|
116
120
|
abortSignal: AbortSignal;
|
117
121
|
config: ModelConfig;
|
118
|
-
onUpdate: (result: ChatModelRunUpdate) =>
|
122
|
+
onUpdate: (result: ChatModelRunUpdate) => ThreadMessage;
|
119
123
|
};
|
120
124
|
type ChatModelAdapter = {
|
121
125
|
run: (options: ChatModelRunOptions) => Promise<ChatModelRunResult>;
|
@@ -123,41 +127,28 @@ type ChatModelAdapter = {
|
|
123
127
|
|
124
128
|
declare abstract class BaseAssistantRuntime<TThreadRuntime extends ReactThreadRuntime> implements AssistantRuntime {
|
125
129
|
private _thread;
|
126
|
-
get capabilities(): Readonly<{
|
127
|
-
edit: boolean;
|
128
|
-
reload: boolean;
|
129
|
-
cancel: boolean;
|
130
|
-
copy: boolean;
|
131
|
-
}>;
|
132
130
|
constructor(_thread: TThreadRuntime);
|
133
|
-
private _unsubscribe;
|
134
131
|
get thread(): TThreadRuntime;
|
135
132
|
set thread(thread: TThreadRuntime);
|
136
133
|
abstract registerModelConfigProvider(provider: ModelConfigProvider): Unsubscribe;
|
137
134
|
abstract switchToThread(threadId: string | null): void;
|
138
|
-
get messages(): readonly ThreadMessage[];
|
139
|
-
get isRunning(): boolean;
|
140
|
-
getBranches(messageId: string): readonly string[];
|
141
|
-
switchToBranch(branchId: string): void;
|
142
|
-
append(message: AppendMessage): void;
|
143
|
-
startRun(parentId: string | null): void;
|
144
|
-
cancelRun(): void;
|
145
|
-
addToolResult(options: AddToolResultOptions): void;
|
146
135
|
private _subscriptions;
|
147
136
|
subscribe(callback: () => void): Unsubscribe;
|
148
137
|
private subscriptionHandler;
|
149
|
-
get unstable_synchronizer(): react.ComponentType | undefined;
|
150
138
|
}
|
151
139
|
|
140
|
+
type LocalRuntimeOptions = {
|
141
|
+
initialMessages?: readonly CoreMessage[] | undefined;
|
142
|
+
};
|
152
143
|
declare class LocalRuntime extends BaseAssistantRuntime<LocalThreadRuntime> {
|
153
|
-
private readonly
|
154
|
-
constructor(adapter: ChatModelAdapter);
|
144
|
+
private readonly _proxyConfigProvider;
|
145
|
+
constructor(adapter: ChatModelAdapter, options?: LocalRuntimeOptions);
|
155
146
|
set adapter(adapter: ChatModelAdapter);
|
156
|
-
registerModelConfigProvider(provider: ModelConfigProvider): () =>
|
147
|
+
registerModelConfigProvider(provider: ModelConfigProvider): () => void;
|
157
148
|
switchToThread(threadId: string | null): LocalThreadRuntime;
|
158
149
|
}
|
159
150
|
declare class LocalThreadRuntime implements ThreadRuntime {
|
160
|
-
private
|
151
|
+
private configProvider;
|
161
152
|
adapter: ChatModelAdapter;
|
162
153
|
private _subscriptions;
|
163
154
|
private abortController;
|
@@ -170,7 +161,7 @@ declare class LocalThreadRuntime implements ThreadRuntime {
|
|
170
161
|
}>;
|
171
162
|
get messages(): ThreadMessage[];
|
172
163
|
get isRunning(): boolean;
|
173
|
-
constructor(
|
164
|
+
constructor(configProvider: ModelConfigProvider, adapter: ChatModelAdapter, options?: LocalRuntimeOptions);
|
174
165
|
getBranches(messageId: string): string[];
|
175
166
|
switchToBranch(branchId: string): void;
|
176
167
|
append(message: AppendMessage): Promise<void>;
|
@@ -181,12 +172,49 @@ declare class LocalThreadRuntime implements ThreadRuntime {
|
|
181
172
|
addToolResult({ messageId, toolCallId, result }: AddToolResultOptions): void;
|
182
173
|
}
|
183
174
|
|
184
|
-
declare const useLocalRuntime: (adapter: ChatModelAdapter) => LocalRuntime;
|
175
|
+
declare const useLocalRuntime: (adapter: ChatModelAdapter, options?: LocalRuntimeOptions) => LocalRuntime;
|
176
|
+
|
177
|
+
type TextContentPartProps = {
|
178
|
+
part: TextContentPart;
|
179
|
+
status: MessageStatus;
|
180
|
+
};
|
181
|
+
type TextContentPartComponent = ComponentType<TextContentPartProps>;
|
182
|
+
type ImageContentPartProps = {
|
183
|
+
part: ImageContentPart;
|
184
|
+
status: MessageStatus;
|
185
|
+
};
|
186
|
+
type ImageContentPartComponent = ComponentType<ImageContentPartProps>;
|
187
|
+
type UIContentPartProps = {
|
188
|
+
part: UIContentPart;
|
189
|
+
status: MessageStatus;
|
190
|
+
};
|
191
|
+
type UIContentPartComponent = ComponentType<UIContentPartProps>;
|
192
|
+
type ToolCallContentPartProps<TArgs = any, TResult = any> = {
|
193
|
+
part: ToolCallContentPart<TArgs, TResult>;
|
194
|
+
status: MessageStatus;
|
195
|
+
addResult: (result: any) => void;
|
196
|
+
};
|
197
|
+
type ToolCallContentPartComponent<TArgs = any, TResult = any> = ComponentType<ToolCallContentPartProps<TArgs, TResult>>;
|
185
198
|
|
186
|
-
type
|
199
|
+
type EdgeChatAdapterOptions = {
|
187
200
|
api: string;
|
201
|
+
maxToolRoundtrips?: number;
|
188
202
|
};
|
189
|
-
declare
|
203
|
+
declare class EdgeChatAdapter implements ChatModelAdapter {
|
204
|
+
private options;
|
205
|
+
constructor(options: EdgeChatAdapterOptions);
|
206
|
+
roundtrip(initialContent: ThreadAssistantContentPart[], { messages, abortSignal, config, onUpdate }: ChatModelRunOptions): Promise<readonly [ThreadMessage | undefined, ChatModelRunResult]>;
|
207
|
+
run({ messages, abortSignal, config, onUpdate }: ChatModelRunOptions): Promise<ChatModelRunResult>;
|
208
|
+
}
|
209
|
+
|
210
|
+
type EdgeRuntimeOptions = EdgeChatAdapterOptions & LocalRuntimeOptions;
|
211
|
+
declare const useEdgeRuntime: ({ initialMessages, ...options }: EdgeRuntimeOptions) => LocalRuntime;
|
212
|
+
|
213
|
+
declare function toLanguageModelMessages(message: readonly CoreMessage[] | readonly ThreadMessage[]): LanguageModelV1Message[];
|
214
|
+
|
215
|
+
declare const fromLanguageModelMessages: (lm: LanguageModelV1Message[], mergeRoundtrips: boolean) => CoreMessage[];
|
216
|
+
|
217
|
+
declare const fromCoreMessages: (message: readonly CoreMessage[]) => ThreadMessage[];
|
190
218
|
|
191
219
|
type AddToolResultOptions = {
|
192
220
|
messageId: string;
|
@@ -206,36 +234,19 @@ type ThreadActionsState = Readonly<{
|
|
206
234
|
startRun: (parentId: string | null) => void;
|
207
235
|
cancelRun: () => void;
|
208
236
|
addToolResult: (options: AddToolResultOptions) => void;
|
237
|
+
getRuntime: () => ThreadRuntime;
|
209
238
|
}>;
|
210
239
|
|
211
|
-
type
|
212
|
-
part: TextContentPart;
|
213
|
-
status: MessageStatus;
|
214
|
-
};
|
215
|
-
type TextContentPartComponent = ComponentType<TextContentPartProps>;
|
216
|
-
type ImageContentPartProps = {
|
217
|
-
part: ImageContentPart;
|
218
|
-
status: MessageStatus;
|
219
|
-
};
|
220
|
-
type ImageContentPartComponent = ComponentType<ImageContentPartProps>;
|
221
|
-
type UIContentPartProps = {
|
222
|
-
part: UIContentPart;
|
223
|
-
status: MessageStatus;
|
224
|
-
};
|
225
|
-
type UIContentPartComponent = ComponentType<UIContentPartProps>;
|
226
|
-
type ToolCallContentPartProps<TArgs = any, TResult = any> = {
|
227
|
-
part: ToolCallContentPart<TArgs, TResult>;
|
228
|
-
status: MessageStatus;
|
229
|
-
addResult: (result: any) => void;
|
230
|
-
};
|
231
|
-
type ToolCallContentPartComponent<TArgs = any, TResult = any> = ComponentType<ToolCallContentPartProps<TArgs, TResult>>;
|
232
|
-
|
233
|
-
type ThreadRuntime = Readonly<ThreadState & ThreadActionsState & {
|
240
|
+
type ThreadRuntime = Readonly<ThreadState & Omit<ThreadActionsState, "getRuntime"> & {
|
234
241
|
messages: readonly ThreadMessage[];
|
235
242
|
subscribe: (callback: () => void) => Unsubscribe;
|
236
243
|
}>;
|
237
244
|
|
238
|
-
type
|
245
|
+
type ThreadRuntimeWithSubscribe = {
|
246
|
+
readonly thread: ThreadRuntime;
|
247
|
+
subscribe: (callback: () => void) => Unsubscribe;
|
248
|
+
};
|
249
|
+
type AssistantRuntime = ThreadRuntimeWithSubscribe & {
|
239
250
|
switchToThread: (threadId: string | null) => void;
|
240
251
|
registerModelConfigProvider: (provider: ModelConfigProvider) => Unsubscribe;
|
241
252
|
};
|
@@ -247,10 +258,10 @@ declare const AssistantRuntimeProvider: react.NamedExoticComponent<PropsWithChil
|
|
247
258
|
|
248
259
|
type AssistantActionsState = Readonly<{
|
249
260
|
switchToThread: (threadId: string | null) => void;
|
261
|
+
getRuntime: () => AssistantRuntime;
|
250
262
|
}>;
|
251
263
|
|
252
|
-
type AssistantModelConfigState = Readonly<{
|
253
|
-
getModelConfig: ModelConfigProvider;
|
264
|
+
type AssistantModelConfigState = Readonly<ModelConfigProvider & {
|
254
265
|
registerModelConfigProvider: (provider: ModelConfigProvider) => () => void;
|
255
266
|
}>;
|
256
267
|
|
@@ -1016,7 +1027,7 @@ declare const exports: {
|
|
1016
1027
|
Text: FC<TextContentPartProps>;
|
1017
1028
|
};
|
1018
1029
|
|
1019
|
-
declare class ProxyConfigProvider {
|
1030
|
+
declare class ProxyConfigProvider implements ModelConfigProvider {
|
1020
1031
|
private _providers;
|
1021
1032
|
getModelConfig(): ModelConfig;
|
1022
1033
|
registerModelConfigProvider(provider: ModelConfigProvider): () => void;
|
@@ -1042,6 +1053,8 @@ declare class MessageRepository {
|
|
1042
1053
|
|
1043
1054
|
declare const useSmooth: (text: string, smooth?: boolean) => string;
|
1044
1055
|
|
1056
|
+
declare const generateId: (size?: number) => string;
|
1057
|
+
|
1045
1058
|
type internal_BaseAssistantRuntime<TThreadRuntime extends ReactThreadRuntime> = BaseAssistantRuntime<TThreadRuntime>;
|
1046
1059
|
declare const internal_BaseAssistantRuntime: typeof BaseAssistantRuntime;
|
1047
1060
|
type internal_MessageRepository = MessageRepository;
|
@@ -1049,9 +1062,10 @@ declare const internal_MessageRepository: typeof MessageRepository;
|
|
1049
1062
|
type internal_ProxyConfigProvider = ProxyConfigProvider;
|
1050
1063
|
declare const internal_ProxyConfigProvider: typeof ProxyConfigProvider;
|
1051
1064
|
declare const internal_TooltipIconButton: typeof TooltipIconButton;
|
1065
|
+
declare const internal_generateId: typeof generateId;
|
1052
1066
|
declare const internal_useSmooth: typeof useSmooth;
|
1053
1067
|
declare namespace internal {
|
1054
|
-
export { internal_BaseAssistantRuntime as BaseAssistantRuntime, internal_MessageRepository as MessageRepository, internal_ProxyConfigProvider as ProxyConfigProvider, internal_TooltipIconButton as TooltipIconButton, internal_useSmooth as useSmooth };
|
1068
|
+
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 };
|
1055
1069
|
}
|
1056
1070
|
|
1057
|
-
export { index$6 as ActionBarPrimitive, type ActionBarPrimitiveCopyProps, type ActionBarPrimitiveEditProps, type ActionBarPrimitiveReloadProps, type ActionBarPrimitiveRootProps, type AddToolResultOptions, type
|
1071
|
+
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, _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, makeAssistantTool, makeAssistantToolUI, toLanguageModelMessages, 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 };
|