@assistant-ui/react 0.1.3 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,334 @@
1
+ import * as react from 'react';
2
+ import { FC, ReactNode, PropsWithChildren, ComponentType } from 'react';
3
+ import { TextareaAutosizeProps } from 'react-textarea-autosize';
4
+ import { T as TextContentPart, I as ImageContentPart, U as UIContentPart, a as ToolCallContentPart, b as ThreadState, c as Unsubscribe, M as ModelConfigProvider, d as ThreadMessage, e as ModelConfig, A as AssistantContentPart, f as AppendMessage } from './Thread-DcmnmkmV.js';
5
+ export { j as AppendContentPart, g as AssistantMessage, i as UserContentPart, h as UserMessage } from './Thread-DcmnmkmV.js';
6
+ import { ComponentPropsWithoutRef, Primitive } from '@radix-ui/react-primitive';
7
+ import 'zod';
8
+
9
+ declare const useCopyMessage: ({ copiedDuration }: {
10
+ copiedDuration?: number | undefined;
11
+ }) => (() => void) | null;
12
+
13
+ declare const useReloadMessage: () => (() => void) | null;
14
+
15
+ declare const useBeginMessageEdit: () => (() => void) | null;
16
+
17
+ declare const useGoToNextBranch: () => (() => void) | null;
18
+
19
+ declare const useGoToPreviousBranch: () => (() => void) | null;
20
+
21
+ declare const ThreadRoot: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
22
+ ref?: ((instance: HTMLDivElement | null) => void) | react.RefObject<HTMLDivElement> | null | undefined;
23
+ } & {
24
+ asChild?: boolean;
25
+ }, "key" | keyof react.HTMLAttributes<HTMLDivElement> | "asChild"> & react.RefAttributes<HTMLDivElement>>;
26
+
27
+ type ThreadEmptyProps = {
28
+ children: ReactNode;
29
+ };
30
+ declare const ThreadEmpty: FC<ThreadEmptyProps>;
31
+
32
+ type RequireAtLeastOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> & {
33
+ [K in Keys]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>>;
34
+ }[Keys];
35
+
36
+ type ThreadIfFilters = {
37
+ empty: boolean | undefined;
38
+ running: boolean | undefined;
39
+ };
40
+ type ThreadIfProps = PropsWithChildren<RequireAtLeastOne<ThreadIfFilters>>;
41
+ declare const ThreadIf: FC<ThreadIfProps>;
42
+
43
+ declare const ThreadViewport: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
44
+ ref?: ((instance: HTMLDivElement | null) => void) | react.RefObject<HTMLDivElement> | null | undefined;
45
+ } & {
46
+ asChild?: boolean;
47
+ }, "key" | keyof react.HTMLAttributes<HTMLDivElement> | "asChild"> & {
48
+ autoScroll?: boolean;
49
+ } & react.RefAttributes<HTMLDivElement>>;
50
+
51
+ type ThreadMessagesProps = {
52
+ components: {
53
+ Message: ComponentType;
54
+ UserMessage?: ComponentType;
55
+ EditComposer?: ComponentType;
56
+ AssistantMessage?: ComponentType;
57
+ } | {
58
+ Message?: ComponentType;
59
+ UserMessage: ComponentType;
60
+ EditComposer?: ComponentType;
61
+ AssistantMessage: ComponentType;
62
+ };
63
+ };
64
+ declare const ThreadMessages: FC<ThreadMessagesProps>;
65
+
66
+ declare const ThreadScrollToBottom: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & {
67
+ ref?: ((instance: HTMLButtonElement | null) => void) | react.RefObject<HTMLButtonElement> | null | undefined;
68
+ } & {
69
+ asChild?: boolean;
70
+ }, "key" | "asChild" | keyof react.ButtonHTMLAttributes<HTMLButtonElement>> & react.RefAttributes<HTMLButtonElement>>;
71
+
72
+ declare const ThreadSuggestion: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & {
73
+ ref?: ((instance: HTMLButtonElement | null) => void) | react.RefObject<HTMLButtonElement> | null | undefined;
74
+ } & {
75
+ asChild?: boolean;
76
+ }, "key" | "asChild" | keyof react.ButtonHTMLAttributes<HTMLButtonElement>> & {
77
+ prompt: string;
78
+ method: "replace";
79
+ autoSend?: boolean;
80
+ } & react.RefAttributes<HTMLButtonElement>>;
81
+
82
+ declare namespace index$5 {
83
+ export { ThreadEmpty as Empty, ThreadIf as If, ThreadMessages as Messages, ThreadRoot as Root, ThreadScrollToBottom as ScrollToBottom, ThreadSuggestion as Suggestion, ThreadViewport as Viewport };
84
+ }
85
+
86
+ declare const ComposerRoot: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.FormHTMLAttributes<HTMLFormElement>, HTMLFormElement>, "ref"> & {
87
+ ref?: ((instance: HTMLFormElement | null) => void) | react.RefObject<HTMLFormElement> | null | undefined;
88
+ } & {
89
+ asChild?: boolean;
90
+ }, "key" | "asChild" | keyof react.FormHTMLAttributes<HTMLFormElement>> & react.RefAttributes<HTMLFormElement>>;
91
+
92
+ declare const ComposerInput: react.ForwardRefExoticComponent<TextareaAutosizeProps & {
93
+ asChild?: boolean;
94
+ } & react.RefAttributes<HTMLTextAreaElement>>;
95
+
96
+ declare const ComposerSend: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & {
97
+ ref?: ((instance: HTMLButtonElement | null) => void) | react.RefObject<HTMLButtonElement> | null | undefined;
98
+ } & {
99
+ asChild?: boolean;
100
+ }, "key" | "asChild" | keyof react.ButtonHTMLAttributes<HTMLButtonElement>> & react.RefAttributes<HTMLButtonElement>>;
101
+
102
+ declare const ComposerCancel: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & {
103
+ ref?: ((instance: HTMLButtonElement | null) => void) | react.RefObject<HTMLButtonElement> | null | undefined;
104
+ } & {
105
+ asChild?: boolean;
106
+ }, "key" | "asChild" | keyof react.ButtonHTMLAttributes<HTMLButtonElement>> & react.RefAttributes<HTMLButtonElement>>;
107
+
108
+ type ComposerIfFilters = {
109
+ editing: boolean | undefined;
110
+ };
111
+ type ComposerIfProps = PropsWithChildren<RequireAtLeastOne<ComposerIfFilters>>;
112
+ declare const ComposerIf: FC<ComposerIfProps>;
113
+
114
+ declare namespace index$4 {
115
+ export { ComposerCancel as Cancel, ComposerIf as If, ComposerInput as Input, ComposerRoot as Root, ComposerSend as Send };
116
+ }
117
+
118
+ declare const MessageRoot: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
119
+ ref?: ((instance: HTMLDivElement | null) => void) | react.RefObject<HTMLDivElement> | null | undefined;
120
+ } & {
121
+ asChild?: boolean;
122
+ }, "key" | keyof react.HTMLAttributes<HTMLDivElement> | "asChild"> & react.RefAttributes<HTMLDivElement>>;
123
+
124
+ type MessageIfFilters = {
125
+ user: boolean | undefined;
126
+ assistant: boolean | undefined;
127
+ hasBranches: boolean | undefined;
128
+ copied: boolean | undefined;
129
+ lastOrHover: boolean | undefined;
130
+ };
131
+ type MessageIfProps = RequireAtLeastOne<MessageIfFilters> & {
132
+ children: ReactNode;
133
+ };
134
+ declare const MessageIf: FC<MessageIfProps>;
135
+
136
+ type MessageContentProps = {
137
+ components?: {
138
+ Text?: ComponentType<{
139
+ part: TextContentPart;
140
+ status: "done" | "in_progress" | "error";
141
+ }>;
142
+ Image?: ComponentType<{
143
+ part: ImageContentPart;
144
+ status: "done" | "in_progress" | "error";
145
+ }>;
146
+ UI?: ComponentType<{
147
+ part: UIContentPart;
148
+ status: "done" | "in_progress" | "error";
149
+ }>;
150
+ tools?: {
151
+ by_name?: Record<string, ComponentType<{
152
+ part: ToolCallContentPart;
153
+ status: "done" | "in_progress" | "error";
154
+ }>>;
155
+ Fallback?: ComponentType<{
156
+ part: ToolCallContentPart;
157
+ status: "done" | "in_progress" | "error";
158
+ }>;
159
+ };
160
+ };
161
+ };
162
+ declare const MessageContent: FC<MessageContentProps>;
163
+
164
+ declare const MessageInProgress: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "ref"> & {
165
+ ref?: ((instance: HTMLSpanElement | null) => void) | react.RefObject<HTMLSpanElement> | null | undefined;
166
+ } & {
167
+ asChild?: boolean;
168
+ }, "key" | "asChild" | keyof react.HTMLAttributes<HTMLSpanElement>> & react.RefAttributes<HTMLSpanElement>>;
169
+
170
+ declare namespace index$3 {
171
+ export { MessageContent as Content, MessageIf as If, MessageInProgress as InProgress, MessageRoot as Root };
172
+ }
173
+
174
+ declare const BranchPickerNext: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & {
175
+ ref?: ((instance: HTMLButtonElement | null) => void) | react.RefObject<HTMLButtonElement> | null | undefined;
176
+ } & {
177
+ asChild?: boolean;
178
+ }, "key" | "asChild" | keyof react.ButtonHTMLAttributes<HTMLButtonElement>> & react.RefAttributes<HTMLButtonElement>>;
179
+
180
+ declare const BranchPickerPrevious: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & {
181
+ ref?: ((instance: HTMLButtonElement | null) => void) | react.RefObject<HTMLButtonElement> | null | undefined;
182
+ } & {
183
+ asChild?: boolean;
184
+ }, "key" | "asChild" | keyof react.ButtonHTMLAttributes<HTMLButtonElement>> & react.RefAttributes<HTMLButtonElement>>;
185
+
186
+ declare const BranchPickerCount: FC;
187
+
188
+ declare const BranchPickerNumber: FC;
189
+
190
+ declare const BranchPickerRoot: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
191
+ ref?: ((instance: HTMLDivElement | null) => void) | react.RefObject<HTMLDivElement> | null | undefined;
192
+ } & {
193
+ asChild?: boolean;
194
+ }, "key" | keyof react.HTMLAttributes<HTMLDivElement> | "asChild"> & {
195
+ hideWhenSingleBranch?: boolean;
196
+ } & react.RefAttributes<HTMLDivElement>>;
197
+
198
+ declare namespace index$2 {
199
+ export { BranchPickerCount as Count, BranchPickerNext as Next, BranchPickerNumber as Number, BranchPickerPrevious as Previous, BranchPickerRoot as Root };
200
+ }
201
+
202
+ declare const ActionBarRoot: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
203
+ ref?: ((instance: HTMLDivElement | null) => void) | react.RefObject<HTMLDivElement> | null | undefined;
204
+ } & {
205
+ asChild?: boolean;
206
+ }, "key" | keyof react.HTMLAttributes<HTMLDivElement> | "asChild"> & {
207
+ hideWhenRunning?: boolean;
208
+ autohide?: "always" | "not-last" | "never";
209
+ autohideFloat?: "always" | "single-branch" | "never";
210
+ } & react.RefAttributes<HTMLDivElement>>;
211
+
212
+ type ActionBarCopyProps = {
213
+ copiedDuration?: number;
214
+ };
215
+ declare const ActionBarCopy: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & {
216
+ ref?: ((instance: HTMLButtonElement | null) => void) | react.RefObject<HTMLButtonElement> | null | undefined;
217
+ } & {
218
+ asChild?: boolean;
219
+ }, "key" | "asChild" | keyof react.ButtonHTMLAttributes<HTMLButtonElement>> & ActionBarCopyProps & react.RefAttributes<HTMLButtonElement>>;
220
+
221
+ declare const ActionBarReload: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & {
222
+ ref?: ((instance: HTMLButtonElement | null) => void) | react.RefObject<HTMLButtonElement> | null | undefined;
223
+ } & {
224
+ asChild?: boolean;
225
+ }, "key" | "asChild" | keyof react.ButtonHTMLAttributes<HTMLButtonElement>> & react.RefAttributes<HTMLButtonElement>>;
226
+
227
+ declare const ActionBarEdit: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & {
228
+ ref?: ((instance: HTMLButtonElement | null) => void) | react.RefObject<HTMLButtonElement> | null | undefined;
229
+ } & {
230
+ asChild?: boolean;
231
+ }, "key" | "asChild" | keyof react.ButtonHTMLAttributes<HTMLButtonElement>> & react.RefAttributes<HTMLButtonElement>>;
232
+
233
+ declare namespace index$1 {
234
+ export { ActionBarCopy as Copy, ActionBarEdit as Edit, ActionBarReload as Reload, ActionBarRoot as Root };
235
+ }
236
+
237
+ declare const ContentPartInProgressIndicator: FC;
238
+
239
+ type PrimitiveSpanProps = ComponentPropsWithoutRef<typeof Primitive.span>;
240
+ type ContentPartTextProps = Omit<PrimitiveSpanProps, "children">;
241
+ declare const ContentPartText: react.ForwardRefExoticComponent<ContentPartTextProps & react.RefAttributes<HTMLSpanElement>>;
242
+
243
+ declare const ContentPartImage: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, "ref"> & {
244
+ ref?: ((instance: HTMLImageElement | null) => void) | react.RefObject<HTMLImageElement> | null | undefined;
245
+ } & {
246
+ asChild?: boolean;
247
+ }, "key" | "asChild" | keyof react.ImgHTMLAttributes<HTMLImageElement>> & react.RefAttributes<HTMLImageElement>>;
248
+
249
+ declare const ContentPartDisplay: FC;
250
+
251
+ declare namespace index {
252
+ export { ContentPartDisplay as Display, ContentPartImage as Image, ContentPartInProgressIndicator as InProgressIndicator, ContentPartText as Text };
253
+ }
254
+
255
+ type ThreadRuntime = Readonly<ThreadState & {
256
+ subscribe: (callback: () => void) => Unsubscribe;
257
+ }>;
258
+
259
+ type AssistantRuntime = ThreadRuntime & {
260
+ registerModelConfigProvider: (provider: ModelConfigProvider) => Unsubscribe;
261
+ };
262
+
263
+ type ReactThreadRuntime = ThreadRuntime & {
264
+ unstable_synchronizer?: ComponentType;
265
+ };
266
+
267
+ type ChatModelRunResult = {
268
+ content: AssistantContentPart[];
269
+ };
270
+ type ChatModelRunOptions = {
271
+ messages: ThreadMessage[];
272
+ abortSignal: AbortSignal;
273
+ config: ModelConfig;
274
+ onUpdate: (result: ChatModelRunResult) => void;
275
+ };
276
+ type ChatModelAdapter = {
277
+ run: (options: ChatModelRunOptions) => Promise<ChatModelRunResult>;
278
+ };
279
+
280
+ declare class LocalRuntime implements AssistantRuntime {
281
+ adapter: ChatModelAdapter;
282
+ private _subscriptions;
283
+ private _configProviders;
284
+ private abortController;
285
+ private repository;
286
+ get messages(): ThreadMessage[];
287
+ get isRunning(): boolean;
288
+ constructor(adapter: ChatModelAdapter);
289
+ getBranches(messageId: string): string[];
290
+ switchToBranch(branchId: string): void;
291
+ append(message: AppendMessage): Promise<void>;
292
+ startRun(parentId: string | null): Promise<void>;
293
+ cancelRun(): void;
294
+ private notifySubscribers;
295
+ subscribe(callback: () => void): Unsubscribe;
296
+ registerModelConfigProvider(provider: ModelConfigProvider): () => boolean;
297
+ }
298
+
299
+ declare const useLocalRuntime: (adapter: ChatModelAdapter) => LocalRuntime;
300
+
301
+ type AssistantRuntimeProviderProps = {
302
+ runtime: AssistantRuntime;
303
+ };
304
+ declare const AssistantRuntimeProvider: react.NamedExoticComponent<PropsWithChildren<AssistantRuntimeProviderProps>>;
305
+
306
+ declare class ProxyConfigProvider {
307
+ private _providers;
308
+ getModelConfig(): ModelConfig;
309
+ registerModelConfigProvider(provider: ModelConfigProvider): () => void;
310
+ }
311
+
312
+ declare class MessageRepository {
313
+ private messages;
314
+ private head;
315
+ private root;
316
+ private performOp;
317
+ getMessages(): ThreadMessage[];
318
+ addOrUpdateMessage(parentId: string | null, message: ThreadMessage): void;
319
+ appendOptimisticMessage(parentId: string | null, message: Omit<ThreadMessage, "id" | "createdAt">): string;
320
+ deleteMessage(messageId: string, replacementId?: string | null | undefined): void;
321
+ getBranches(messageId: string): string[];
322
+ switchToBranch(messageId: string): void;
323
+ resetHead(messageId: string | null): void;
324
+ }
325
+
326
+ type internal_MessageRepository = MessageRepository;
327
+ declare const internal_MessageRepository: typeof MessageRepository;
328
+ type internal_ProxyConfigProvider = ProxyConfigProvider;
329
+ declare const internal_ProxyConfigProvider: typeof ProxyConfigProvider;
330
+ declare namespace internal {
331
+ export { internal_MessageRepository as MessageRepository, internal_ProxyConfigProvider as ProxyConfigProvider };
332
+ }
333
+
334
+ export { index$1 as ActionBarPrimitive, AppendMessage, AssistantContentPart, type AssistantRuntime, AssistantRuntimeProvider, index$2 as BranchPickerPrimitive, type ChatModelAdapter, type ChatModelRunOptions, index$4 as ComposerPrimitive, index as ContentPartPrimitive, internal as INTERNAL, index$3 as MessagePrimitive, type ReactThreadRuntime, TextContentPart, ThreadMessage, index$5 as ThreadPrimitive, type ThreadRuntime, Unsubscribe, useBeginMessageEdit, useCopyMessage, useGoToNextBranch, useGoToPreviousBranch, useLocalRuntime, useReloadMessage };