@assistant-ui/react 0.1.4 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,319 @@
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 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-ZUDFhMtm.js';
5
+ export { k as AppendContentPart, h as AssistantMessage, l as TextContentPart, j as UserContentPart, i as UserMessage } from './Thread-ZUDFhMtm.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?: TextContentPartComponent;
139
+ Image?: ImageContentPartComponent;
140
+ UI?: UIContentPartComponent;
141
+ tools?: {
142
+ by_name?: Record<string, ToolCallContentPartComponent>;
143
+ Fallback?: ComponentType<ToolCallContentPartProps>;
144
+ };
145
+ };
146
+ };
147
+ declare const MessageContent: FC<MessageContentProps>;
148
+
149
+ declare const MessageInProgress: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "ref"> & {
150
+ ref?: ((instance: HTMLSpanElement | null) => void) | react.RefObject<HTMLSpanElement> | null | undefined;
151
+ } & {
152
+ asChild?: boolean;
153
+ }, "key" | "asChild" | keyof react.HTMLAttributes<HTMLSpanElement>> & react.RefAttributes<HTMLSpanElement>>;
154
+
155
+ declare namespace index$3 {
156
+ export { MessageContent as Content, MessageIf as If, MessageInProgress as InProgress, MessageRoot as Root };
157
+ }
158
+
159
+ declare const BranchPickerNext: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & {
160
+ ref?: ((instance: HTMLButtonElement | null) => void) | react.RefObject<HTMLButtonElement> | null | undefined;
161
+ } & {
162
+ asChild?: boolean;
163
+ }, "key" | "asChild" | keyof react.ButtonHTMLAttributes<HTMLButtonElement>> & react.RefAttributes<HTMLButtonElement>>;
164
+
165
+ declare const BranchPickerPrevious: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & {
166
+ ref?: ((instance: HTMLButtonElement | null) => void) | react.RefObject<HTMLButtonElement> | null | undefined;
167
+ } & {
168
+ asChild?: boolean;
169
+ }, "key" | "asChild" | keyof react.ButtonHTMLAttributes<HTMLButtonElement>> & react.RefAttributes<HTMLButtonElement>>;
170
+
171
+ declare const BranchPickerCount: FC;
172
+
173
+ declare const BranchPickerNumber: FC;
174
+
175
+ declare const BranchPickerRoot: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
176
+ ref?: ((instance: HTMLDivElement | null) => void) | react.RefObject<HTMLDivElement> | null | undefined;
177
+ } & {
178
+ asChild?: boolean;
179
+ }, "key" | keyof react.HTMLAttributes<HTMLDivElement> | "asChild"> & {
180
+ hideWhenSingleBranch?: boolean;
181
+ } & react.RefAttributes<HTMLDivElement>>;
182
+
183
+ declare namespace index$2 {
184
+ export { BranchPickerCount as Count, BranchPickerNext as Next, BranchPickerNumber as Number, BranchPickerPrevious as Previous, BranchPickerRoot as Root };
185
+ }
186
+
187
+ declare const ActionBarRoot: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
188
+ ref?: ((instance: HTMLDivElement | null) => void) | react.RefObject<HTMLDivElement> | null | undefined;
189
+ } & {
190
+ asChild?: boolean;
191
+ }, "key" | keyof react.HTMLAttributes<HTMLDivElement> | "asChild"> & {
192
+ hideWhenRunning?: boolean;
193
+ autohide?: "always" | "not-last" | "never";
194
+ autohideFloat?: "always" | "single-branch" | "never";
195
+ } & react.RefAttributes<HTMLDivElement>>;
196
+
197
+ type ActionBarCopyProps = {
198
+ copiedDuration?: number;
199
+ };
200
+ declare const ActionBarCopy: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & {
201
+ ref?: ((instance: HTMLButtonElement | null) => void) | react.RefObject<HTMLButtonElement> | null | undefined;
202
+ } & {
203
+ asChild?: boolean;
204
+ }, "key" | "asChild" | keyof react.ButtonHTMLAttributes<HTMLButtonElement>> & ActionBarCopyProps & react.RefAttributes<HTMLButtonElement>>;
205
+
206
+ declare const ActionBarReload: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & {
207
+ ref?: ((instance: HTMLButtonElement | null) => void) | react.RefObject<HTMLButtonElement> | null | undefined;
208
+ } & {
209
+ asChild?: boolean;
210
+ }, "key" | "asChild" | keyof react.ButtonHTMLAttributes<HTMLButtonElement>> & react.RefAttributes<HTMLButtonElement>>;
211
+
212
+ declare const ActionBarEdit: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & {
213
+ ref?: ((instance: HTMLButtonElement | null) => void) | react.RefObject<HTMLButtonElement> | null | undefined;
214
+ } & {
215
+ asChild?: boolean;
216
+ }, "key" | "asChild" | keyof react.ButtonHTMLAttributes<HTMLButtonElement>> & react.RefAttributes<HTMLButtonElement>>;
217
+
218
+ declare namespace index$1 {
219
+ export { ActionBarCopy as Copy, ActionBarEdit as Edit, ActionBarReload as Reload, ActionBarRoot as Root };
220
+ }
221
+
222
+ declare const ContentPartInProgressIndicator: FC;
223
+
224
+ type PrimitiveSpanProps = ComponentPropsWithoutRef<typeof Primitive.span>;
225
+ type ContentPartTextProps = Omit<PrimitiveSpanProps, "children">;
226
+ declare const ContentPartText: react.ForwardRefExoticComponent<ContentPartTextProps & react.RefAttributes<HTMLSpanElement>>;
227
+
228
+ declare const ContentPartImage: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, "ref"> & {
229
+ ref?: ((instance: HTMLImageElement | null) => void) | react.RefObject<HTMLImageElement> | null | undefined;
230
+ } & {
231
+ asChild?: boolean;
232
+ }, "key" | "asChild" | keyof react.ImgHTMLAttributes<HTMLImageElement>> & react.RefAttributes<HTMLImageElement>>;
233
+
234
+ declare const ContentPartDisplay: FC;
235
+
236
+ declare namespace index {
237
+ export { ContentPartDisplay as Display, ContentPartImage as Image, ContentPartInProgressIndicator as InProgressIndicator, ContentPartText as Text };
238
+ }
239
+
240
+ type ThreadRuntime = Readonly<ThreadState & {
241
+ subscribe: (callback: () => void) => Unsubscribe;
242
+ }>;
243
+
244
+ type AssistantRuntime = ThreadRuntime & {
245
+ registerModelConfigProvider: (provider: ModelConfigProvider) => Unsubscribe;
246
+ };
247
+
248
+ type ReactThreadRuntime = ThreadRuntime & {
249
+ unstable_synchronizer?: ComponentType;
250
+ };
251
+
252
+ type ChatModelRunResult = {
253
+ content: AssistantContentPart[];
254
+ };
255
+ type ChatModelRunOptions = {
256
+ messages: ThreadMessage[];
257
+ abortSignal: AbortSignal;
258
+ config: ModelConfig;
259
+ onUpdate: (result: ChatModelRunResult) => void;
260
+ };
261
+ type ChatModelAdapter = {
262
+ run: (options: ChatModelRunOptions) => Promise<ChatModelRunResult>;
263
+ };
264
+
265
+ declare class LocalRuntime implements AssistantRuntime {
266
+ adapter: ChatModelAdapter;
267
+ private _subscriptions;
268
+ private _configProviders;
269
+ private abortController;
270
+ private repository;
271
+ get messages(): ThreadMessage[];
272
+ get isRunning(): boolean;
273
+ constructor(adapter: ChatModelAdapter);
274
+ getBranches(messageId: string): string[];
275
+ switchToBranch(branchId: string): void;
276
+ append(message: AppendMessage): Promise<void>;
277
+ startRun(parentId: string | null): Promise<void>;
278
+ cancelRun(): void;
279
+ private notifySubscribers;
280
+ subscribe(callback: () => void): Unsubscribe;
281
+ registerModelConfigProvider(provider: ModelConfigProvider): () => boolean;
282
+ }
283
+
284
+ declare const useLocalRuntime: (adapter: ChatModelAdapter) => LocalRuntime;
285
+
286
+ type AssistantRuntimeProviderProps = {
287
+ runtime: AssistantRuntime;
288
+ };
289
+ declare const AssistantRuntimeProvider: react.NamedExoticComponent<PropsWithChildren<AssistantRuntimeProviderProps>>;
290
+
291
+ declare class ProxyConfigProvider {
292
+ private _providers;
293
+ getModelConfig(): ModelConfig;
294
+ registerModelConfigProvider(provider: ModelConfigProvider): () => void;
295
+ }
296
+
297
+ declare class MessageRepository {
298
+ private messages;
299
+ private head;
300
+ private root;
301
+ private performOp;
302
+ getMessages(): ThreadMessage[];
303
+ addOrUpdateMessage(parentId: string | null, message: ThreadMessage): void;
304
+ appendOptimisticMessage(parentId: string | null, message: Omit<ThreadMessage, "id" | "createdAt">): string;
305
+ deleteMessage(messageId: string, replacementId?: string | null | undefined): void;
306
+ getBranches(messageId: string): string[];
307
+ switchToBranch(messageId: string): void;
308
+ resetHead(messageId: string | null): void;
309
+ }
310
+
311
+ type internal_MessageRepository = MessageRepository;
312
+ declare const internal_MessageRepository: typeof MessageRepository;
313
+ type internal_ProxyConfigProvider = ProxyConfigProvider;
314
+ declare const internal_ProxyConfigProvider: typeof ProxyConfigProvider;
315
+ declare namespace internal {
316
+ export { internal_MessageRepository as MessageRepository, internal_ProxyConfigProvider as ProxyConfigProvider };
317
+ }
318
+
319
+ 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, ThreadMessage, index$5 as ThreadPrimitive, type ThreadRuntime, Unsubscribe, useBeginMessageEdit, useCopyMessage, useGoToNextBranch, useGoToPreviousBranch, useLocalRuntime, useReloadMessage };