@assistant-ui/react-ai-sdk 0.6.10 → 0.6.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,9 +1,923 @@
1
- import * as _assistant_ui_react from '@assistant-ui/react';
2
- import { AppendMessage, ThreadMessage } from '@assistant-ui/react';
1
+ import { LanguageModelV1LogProbs } from '@ai-sdk/provider';
3
2
  import { ReactNode } from 'react';
3
+ import { z } from 'zod';
4
+ import { JSONSchema7 } from 'json-schema';
5
+ import { AppendMessage as AppendMessage$1, ThreadMessage as ThreadMessage$1 } from '@assistant-ui/react';
4
6
  import { useChat, useAssistant } from 'ai/react';
5
7
  import { Message } from 'ai';
6
8
 
9
+ type TextContentPart = {
10
+ type: "text";
11
+ text: string;
12
+ };
13
+ type ImageContentPart = {
14
+ type: "image";
15
+ image: string;
16
+ };
17
+ type UIContentPart = {
18
+ type: "ui";
19
+ display: ReactNode;
20
+ };
21
+ type CoreToolCallContentPart<TArgs extends Record<string, unknown> = Record<string | number, unknown>, TResult = unknown> = {
22
+ type: "tool-call";
23
+ toolCallId: string;
24
+ toolName: string;
25
+ args: TArgs;
26
+ result?: TResult | undefined;
27
+ isError?: boolean | undefined;
28
+ };
29
+ type ToolCallContentPart<TArgs extends Record<string, unknown> = Record<string | number, unknown>, TResult = unknown> = CoreToolCallContentPart<TArgs, TResult> & {
30
+ argsText: string;
31
+ };
32
+ type ThreadUserContentPart = TextContentPart | ImageContentPart | UIContentPart;
33
+ type ThreadAssistantContentPart = TextContentPart | ToolCallContentPart | UIContentPart;
34
+ type MessageCommonProps = {
35
+ id: string;
36
+ createdAt: Date;
37
+ };
38
+ type ThreadStep = {
39
+ /**
40
+ * @deprecated This field will be removed in v0.6. Submit feedback if you need this functionality.
41
+ */
42
+ logprobs?: LanguageModelV1LogProbs | undefined;
43
+ usage?: {
44
+ promptTokens: number;
45
+ completionTokens: number;
46
+ } | undefined;
47
+ };
48
+ type ContentPartStatus = {
49
+ type: "running";
50
+ } | {
51
+ type: "complete";
52
+ } | {
53
+ type: "incomplete";
54
+ reason: "cancelled" | "length" | "content-filter" | "other" | "error";
55
+ error?: unknown;
56
+ };
57
+ type ToolCallContentPartStatus = {
58
+ type: "requires-action";
59
+ reason: "tool-calls";
60
+ } | ContentPartStatus;
61
+ type MessageStatus = {
62
+ type: "running";
63
+ } | {
64
+ type: "requires-action";
65
+ reason: "tool-calls";
66
+ } | {
67
+ type: "complete";
68
+ reason: "stop" | "unknown";
69
+ } | {
70
+ type: "incomplete";
71
+ reason: "cancelled" | "tool-calls" | "length" | "content-filter" | "other" | "error";
72
+ error?: unknown;
73
+ };
74
+ type ThreadSystemMessage = MessageCommonProps & {
75
+ role: "system";
76
+ content: [TextContentPart];
77
+ };
78
+ type ThreadUserMessage = MessageCommonProps & {
79
+ role: "user";
80
+ content: ThreadUserContentPart[];
81
+ attachments: readonly CompleteAttachment[];
82
+ };
83
+ type ThreadAssistantMessage = MessageCommonProps & {
84
+ role: "assistant";
85
+ content: ThreadAssistantContentPart[];
86
+ status: MessageStatus;
87
+ /**
88
+ * @deprecated Use `metadata.steps` instead.
89
+ */
90
+ roundtrips?: ThreadStep[] | undefined;
91
+ metadata?: {
92
+ /**
93
+ * @deprecated Use `steps` instead. This field will be removed in v0.6.
94
+ */
95
+ roundtrips?: ThreadStep[] | undefined;
96
+ steps?: ThreadStep[] | undefined;
97
+ custom?: Record<string, unknown> | undefined;
98
+ };
99
+ };
100
+ type AppendMessage = CoreMessage & {
101
+ parentId: string | null;
102
+ attachments?: readonly CompleteAttachment[] | undefined;
103
+ };
104
+ type BaseThreadMessage = {
105
+ status?: ThreadAssistantMessage["status"];
106
+ metadata?: ThreadAssistantMessage["metadata"];
107
+ attachments?: ThreadUserMessage["attachments"];
108
+ };
109
+ type ThreadMessage = BaseThreadMessage & (ThreadSystemMessage | ThreadUserMessage | ThreadAssistantMessage);
110
+ /** Core Message Types (without UI content parts) */
111
+ type CoreUserContentPart = TextContentPart | ImageContentPart;
112
+ type CoreAssistantContentPart = TextContentPart | CoreToolCallContentPart;
113
+ type CoreSystemMessage = {
114
+ role: "system";
115
+ content: [TextContentPart];
116
+ };
117
+ type CoreUserMessage = {
118
+ role: "user";
119
+ content: CoreUserContentPart[];
120
+ };
121
+ type CoreAssistantMessage = {
122
+ role: "assistant";
123
+ content: CoreAssistantContentPart[];
124
+ };
125
+ type CoreMessage = CoreSystemMessage | CoreUserMessage | CoreAssistantMessage;
126
+
127
+ type PendingAttachmentStatus = {
128
+ type: "running";
129
+ reason: "uploading";
130
+ progress: number;
131
+ } | {
132
+ type: "requires-action";
133
+ reason: "composer-send";
134
+ } | {
135
+ type: "incomplete";
136
+ reason: "error" | "upload-paused";
137
+ };
138
+ type CompleteAttachmentStatus = {
139
+ type: "complete";
140
+ };
141
+ type BaseAttachment = {
142
+ id: string;
143
+ type: "image" | "document" | "file";
144
+ name: string;
145
+ contentType?: string;
146
+ file?: File;
147
+ content?: CoreUserContentPart[];
148
+ };
149
+ type PendingAttachment = BaseAttachment & {
150
+ status: PendingAttachmentStatus;
151
+ file: File;
152
+ };
153
+ type CompleteAttachment = BaseAttachment & {
154
+ status: CompleteAttachmentStatus;
155
+ content: CoreUserContentPart[];
156
+ };
157
+ type Attachment = PendingAttachment | CompleteAttachment;
158
+
159
+ declare const LanguageModelV1CallSettingsSchema: z.ZodObject<{
160
+ maxTokens: z.ZodOptional<z.ZodNumber>;
161
+ temperature: z.ZodOptional<z.ZodNumber>;
162
+ topP: z.ZodOptional<z.ZodNumber>;
163
+ presencePenalty: z.ZodOptional<z.ZodNumber>;
164
+ frequencyPenalty: z.ZodOptional<z.ZodNumber>;
165
+ seed: z.ZodOptional<z.ZodNumber>;
166
+ headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodOptional<z.ZodString>>>;
167
+ }, "strip", z.ZodTypeAny, {
168
+ maxTokens?: number | undefined;
169
+ temperature?: number | undefined;
170
+ topP?: number | undefined;
171
+ presencePenalty?: number | undefined;
172
+ frequencyPenalty?: number | undefined;
173
+ seed?: number | undefined;
174
+ headers?: Record<string, string | undefined> | undefined;
175
+ }, {
176
+ maxTokens?: number | undefined;
177
+ temperature?: number | undefined;
178
+ topP?: number | undefined;
179
+ presencePenalty?: number | undefined;
180
+ frequencyPenalty?: number | undefined;
181
+ seed?: number | undefined;
182
+ headers?: Record<string, string | undefined> | undefined;
183
+ }>;
184
+ type LanguageModelV1CallSettings = z.infer<typeof LanguageModelV1CallSettingsSchema>;
185
+ declare const LanguageModelConfigSchema: z.ZodObject<{
186
+ apiKey: z.ZodOptional<z.ZodString>;
187
+ baseUrl: z.ZodOptional<z.ZodString>;
188
+ modelName: z.ZodOptional<z.ZodString>;
189
+ }, "strip", z.ZodTypeAny, {
190
+ apiKey?: string | undefined;
191
+ baseUrl?: string | undefined;
192
+ modelName?: string | undefined;
193
+ }, {
194
+ apiKey?: string | undefined;
195
+ baseUrl?: string | undefined;
196
+ modelName?: string | undefined;
197
+ }>;
198
+ type LanguageModelConfig = z.infer<typeof LanguageModelConfigSchema>;
199
+ type ToolExecuteFunction<TArgs, TResult> = (args: TArgs, context: {
200
+ abortSignal: AbortSignal;
201
+ }) => TResult | Promise<TResult>;
202
+ type Tool<TArgs extends Record<string, unknown> = Record<string | number, unknown>, TResult = unknown> = {
203
+ description?: string | undefined;
204
+ parameters: z.ZodSchema<TArgs> | JSONSchema7;
205
+ execute?: ToolExecuteFunction<TArgs, TResult>;
206
+ };
207
+ type ModelConfig = {
208
+ priority?: number | undefined;
209
+ system?: string | undefined;
210
+ tools?: Record<string, Tool<any, any>> | undefined;
211
+ callSettings?: LanguageModelV1CallSettings | undefined;
212
+ config?: LanguageModelConfig | undefined;
213
+ };
214
+ type ModelConfigProvider = {
215
+ getModelConfig: () => ModelConfig;
216
+ };
217
+
218
+ type Unsubscribe = () => void;
219
+
220
+ type AssistantRuntimeCore = {
221
+ readonly thread: ThreadRuntimeCore;
222
+ switchToNewThread: () => void;
223
+ switchToThread(threadId: string): void;
224
+ /**
225
+ * @deprecated Use `switchToNewThread` instead. This will be removed in 0.6.0.
226
+ */
227
+ switchToThread(threadId: string | null): void;
228
+ registerModelConfigProvider: (provider: ModelConfigProvider) => Unsubscribe;
229
+ subscribe: (callback: () => void) => Unsubscribe;
230
+ };
231
+
232
+ type AssistantRuntime = {
233
+ thread: ThreadRuntime;
234
+ switchToNewThread(): void;
235
+ switchToThread(threadId: string): void;
236
+ /**
237
+ * @deprecated Use `switchToNewThread` instead. This will be removed in 0.6.0.
238
+ */
239
+ switchToThread(threadId: string | null): void;
240
+ registerModelConfigProvider(provider: ModelConfigProvider): Unsubscribe;
241
+ /**
242
+ * @deprecated Thread is now static and never gets updated. This will be removed in 0.6.0.
243
+ */
244
+ subscribe(callback: () => void): Unsubscribe;
245
+ };
246
+ declare class AssistantRuntimeImpl<TThreadRuntime extends ThreadRuntime = ThreadRuntime> implements AssistantRuntimeCore, AssistantRuntime {
247
+ private _core;
248
+ constructor(_core: AssistantRuntimeCore, CustomThreadRuntime: new (binding: ThreadRuntimeCoreBinding) => TThreadRuntime);
249
+ readonly thread: TThreadRuntime;
250
+ switchToNewThread(): void;
251
+ switchToThread(threadId: string): void;
252
+ /**
253
+ * @deprecated Use `switchToNewThread` instead. This will be removed in 0.6.0.
254
+ */
255
+ switchToThread(threadId: string | null): void;
256
+ registerModelConfigProvider(provider: ModelConfigProvider): Unsubscribe;
257
+ /**
258
+ * @deprecated Thread is now static and never gets updated. This will be removed in 0.6.0.
259
+ */
260
+ subscribe(callback: () => void): Unsubscribe;
261
+ }
262
+
263
+ interface ExportedMessageRepository {
264
+ headId?: string | null;
265
+ messages: Array<{
266
+ message: ThreadMessage;
267
+ parentId: string | null;
268
+ }>;
269
+ }
270
+
271
+ type ComposerRuntimeCore = Readonly<{
272
+ attachmentAccept: string;
273
+ attachments: readonly Attachment[];
274
+ addAttachment: (file: File) => Promise<void>;
275
+ removeAttachment: (attachmentId: string) => Promise<void>;
276
+ isEditing: boolean;
277
+ canCancel: boolean;
278
+ isEmpty: boolean;
279
+ text: string;
280
+ setText: (value: string) => void;
281
+ /**
282
+ * @deprecated This method will be removed in 0.6.0. Submit feedback if you need this functionality.
283
+ */
284
+ reset: () => void;
285
+ send: () => void;
286
+ cancel: () => void;
287
+ subscribe: (callback: () => void) => Unsubscribe;
288
+ }>;
289
+ type ThreadComposerRuntimeCore = ComposerRuntimeCore & Readonly<{
290
+ attachments: readonly PendingAttachment[];
291
+ }>;
292
+
293
+ declare namespace SpeechSynthesisAdapter {
294
+ type Status = {
295
+ type: "starting" | "running";
296
+ } | {
297
+ type: "ended";
298
+ reason: "finished" | "cancelled" | "error";
299
+ error?: unknown;
300
+ };
301
+ type Utterance = {
302
+ status: Status;
303
+ cancel: () => void;
304
+ onEnd: (callback: () => void) => Unsubscribe;
305
+ };
306
+ }
307
+ type SpeechSynthesisAdapter = {
308
+ speak: (message: ThreadMessage) => SpeechSynthesisAdapter.Utterance;
309
+ };
310
+
311
+ type Subscribable = {
312
+ subscribe: (callback: () => void) => Unsubscribe;
313
+ };
314
+ type SubscribableWithState<TState> = Subscribable & {
315
+ getState: () => TState;
316
+ };
317
+
318
+ type ThreadComposerRuntimeCoreBinding = SubscribableWithState<ThreadComposerRuntimeCore | undefined>;
319
+ type ComposerRuntimeCoreBinding = SubscribableWithState<ComposerRuntimeCore | undefined>;
320
+ type LegacyEditComposerState = Readonly<{
321
+ type: "edit";
322
+ /** @deprecated Use `text` instead. This will be removed in 0.6.0. */
323
+ value: string;
324
+ /** @deprecated Use `useComposerRuntime().setText()` instead. This will be removed in 0.6.0. */
325
+ setValue: (value: string) => void;
326
+ text: string;
327
+ /**
328
+ * @deprecated Use `useComposerRuntime().setText()` instead. This will be removed in 0.6.0.
329
+ */
330
+ setText: (value: string) => void;
331
+ canCancel: boolean;
332
+ isEditing: boolean;
333
+ isEmpty: boolean;
334
+ /**
335
+ * @deprecated Use useComposerRuntime().beginEdit() instead. This will be removed in 0.6.0.
336
+ */
337
+ edit: () => void;
338
+ /**
339
+ * @deprecated Use `useComposerRuntime().send()` instead. This will be removed in 0.6.0.
340
+ */
341
+ send: () => void;
342
+ /**
343
+ * @deprecated Use `useComposerRuntime().cancel()` instead. This will be removed in 0.6.0.
344
+ */
345
+ cancel: () => void;
346
+ }>;
347
+ type LegacyThreadComposerState = Readonly<{
348
+ type: "thread";
349
+ /** @deprecated Use `text` instead. This will be removed in 0.6.0. */
350
+ value: string;
351
+ /** @deprecated Use `useComposerRuntime().setText` instead. This will be removed in 0.6.0. */
352
+ setValue: (value: string) => void;
353
+ attachmentAccept: string;
354
+ attachments: readonly Attachment[];
355
+ /** @deprecated Use `useComposerRuntime().addAttachment` instead. This will be removed in 0.6.0. */
356
+ addAttachment: (file: File) => Promise<void>;
357
+ /** @deprecated Use `useComposerRuntime().removeAttachment` instead. This will be removed in 0.6.0. */
358
+ removeAttachment: (attachmentId: string) => Promise<void>;
359
+ text: string;
360
+ /** @deprecated Use `useComposerRuntime().setText` instead. This will be removed in 0.6.0. */
361
+ setText: (value: string) => void;
362
+ /** @deprecated Use `useComposerRuntime().reset` instead. This will be removed in 0.6.0. */
363
+ reset: () => void;
364
+ canCancel: boolean;
365
+ isEditing: boolean;
366
+ isEmpty: boolean;
367
+ /**
368
+ * @deprecated Use `useComposerRuntime().send` instead. This will be removed in 0.6.0.
369
+ **/
370
+ send: () => void;
371
+ /** @deprecated Use `useComposerRuntime().cancel` instead. This will be removed in 0.6.0. */
372
+ cancel: () => void;
373
+ /** @deprecated This feature is being removed in 0.6.0. Submit feedback if you need it. */
374
+ focus: () => void;
375
+ /** @deprecated This feature is being removed in 0.6.0. Submit feedback if you need it. */
376
+ onFocus: (listener: () => void) => Unsubscribe;
377
+ }>;
378
+ type BaseComposerState = {
379
+ text: string;
380
+ attachmentAccept: string;
381
+ attachments: readonly Attachment[];
382
+ canCancel: boolean;
383
+ isEditing: boolean;
384
+ isEmpty: boolean;
385
+ };
386
+ type ThreadComposerState = LegacyThreadComposerState & BaseComposerState & {
387
+ type: "thread";
388
+ attachments: readonly PendingAttachment[];
389
+ };
390
+ type EditComposerState = LegacyEditComposerState & BaseComposerState & {
391
+ type: "edit";
392
+ };
393
+ type ComposerState = ThreadComposerState | EditComposerState;
394
+ type ComposerRuntime = {
395
+ readonly type: "edit" | "thread";
396
+ getState(): ComposerState;
397
+ /** @deprecated Use `getState().isEditing` instead. This will be removed in 0.6.0. */
398
+ readonly isEditing: boolean;
399
+ /** @deprecated Use `getState().isEmpty` instead. This will be removed in 0.6.0. */
400
+ readonly isEmpty: boolean;
401
+ /** @deprecated Use `getState().canCancel` instead. This will be removed in 0.6.0. */
402
+ readonly canCancel: boolean;
403
+ /** @deprecated Use `getState().text` instead. This will be removed in 0.6.0. */
404
+ readonly text: string;
405
+ /** @deprecated Use `getState().attachmentAccept` instead. This will be removed in 0.6.0. */
406
+ readonly attachmentAccept: string;
407
+ /** @deprecated Use `getState().attachments` instead. This will be removed in 0.6.0. */
408
+ readonly attachments: readonly Attachment[];
409
+ /** @deprecated Use `getState().text` instead. This will be removed in 0.6.0. */
410
+ readonly value: string;
411
+ setText(text: string): void;
412
+ setValue(text: string): void;
413
+ addAttachment(file: File): Promise<void>;
414
+ /** @deprecated Use `getAttachmentById(id).removeAttachment()` instead. This will be removed in 0.6.0. */
415
+ removeAttachment(attachmentId: string): Promise<void>;
416
+ /** @deprecated This method will be removed in 0.6.0. Submit feedback if you need this functionality. */
417
+ reset(): void;
418
+ send(): void;
419
+ cancel(): void;
420
+ subscribe(callback: () => void): Unsubscribe;
421
+ getAttachmentByIndex(idx: number): AttachmentRuntime;
422
+ };
423
+ declare abstract class ComposerRuntimeImpl implements ComposerRuntimeCore, ComposerRuntime {
424
+ protected _core: ComposerRuntimeCoreBinding;
425
+ abstract get type(): "edit" | "thread";
426
+ constructor(_core: ComposerRuntimeCoreBinding);
427
+ /**
428
+ * @deprecated Use `getState().isEditing` instead. This will be removed in 0.6.0.
429
+ */
430
+ get isEditing(): boolean;
431
+ /**
432
+ * @deprecated Use `getState().isEmpty` instead. This will be removed in 0.6.0.
433
+ */
434
+ get isEmpty(): boolean;
435
+ /**
436
+ * @deprecated Use `getState().canCancel` instead. This will be removed in 0.6.0.
437
+ */
438
+ get canCancel(): boolean;
439
+ /**
440
+ * @deprecated Use `getState().text` instead. This will be removed in 0.6.0.
441
+ */
442
+ get text(): string;
443
+ /**
444
+ * @deprecated Use `getState().attachmentAccept` instead. This will be removed in 0.6.0.
445
+ */
446
+ get attachmentAccept(): string;
447
+ /**
448
+ * @deprecated Use `getState().attachments` instead. This will be removed in 0.6.0.
449
+ */
450
+ get attachments(): readonly Attachment[] | (readonly Attachment[] & readonly PendingAttachment[]);
451
+ /**
452
+ * @deprecated Use `getState().text` instead. This will be removed in 0.6.0.
453
+ */
454
+ get value(): string;
455
+ abstract getState(): ComposerState;
456
+ setText(text: string): void;
457
+ setValue(text: string): void;
458
+ addAttachment(file: File): Promise<void>;
459
+ /**
460
+ * @deprecated Use `getAttachmentById(id).removeAttachment()` instead. This will be removed in 0.6.0.
461
+ */
462
+ removeAttachment(attachmentId: string): Promise<void>;
463
+ /**
464
+ * @deprecated This method will be removed in 0.6.0. Submit feedback if you need this functionality.
465
+ */
466
+ reset(): void;
467
+ send(): void;
468
+ cancel(): void;
469
+ subscribe(callback: () => void): Unsubscribe;
470
+ abstract getAttachmentByIndex(idx: number): AttachmentRuntime;
471
+ }
472
+ type ThreadComposerRuntime = Omit<ComposerRuntime, "getState" | "getAttachmentByIndex"> & {
473
+ readonly type: "thread";
474
+ getState(): ThreadComposerState;
475
+ /**
476
+ * @deprecated Use `getState().attachments` instead. This will be removed in 0.6.0.
477
+ */
478
+ attachments: readonly PendingAttachment[];
479
+ /** @deprecated This feature is being removed in 0.6.0. Submit feedback if you need it. */
480
+ focus(): void;
481
+ /** @deprecated This feature is being removed in 0.6.0. Submit feedback if you need it. */
482
+ onFocus(callback: () => void): Unsubscribe;
483
+ getAttachmentByIndex(idx: number): AttachmentRuntime & {
484
+ source: "thread-composer";
485
+ };
486
+ };
487
+ declare class ThreadComposerRuntimeImpl extends ComposerRuntimeImpl implements ThreadComposerRuntime, ThreadComposerState {
488
+ get type(): "thread";
489
+ private _getState;
490
+ constructor(core: ThreadComposerRuntimeCoreBinding);
491
+ get attachments(): readonly Attachment[] & readonly PendingAttachment[];
492
+ getState(): ThreadComposerState;
493
+ private _focusListeners;
494
+ /**
495
+ * @deprecated This feature is being removed in 0.6.0. Submit feedback if you need it.
496
+ */
497
+ focus(): void;
498
+ /**
499
+ * @deprecated This feature is being removed in 0.6.0. Submit feedback if you need it.
500
+ */
501
+ onFocus(callback: () => void): () => boolean;
502
+ getAttachmentByIndex(idx: number): ThreadComposerAttachmentRuntimeImpl;
503
+ }
504
+ type EditComposerRuntime = Omit<ComposerRuntime, "getState" | "getAttachmentByIndex"> & {
505
+ readonly type: "edit";
506
+ getState(): EditComposerState;
507
+ beginEdit(): void;
508
+ /**
509
+ * @deprecated Use `beginEdit()` instead. This will be removed in 0.6.0.
510
+ */
511
+ edit(): void;
512
+ getAttachmentByIndex(idx: number): AttachmentRuntime & {
513
+ source: "edit-composer";
514
+ };
515
+ };
516
+ declare class EditComposerRuntimeImpl extends ComposerRuntimeImpl implements EditComposerRuntime, EditComposerState {
517
+ private _beginEdit;
518
+ get type(): "edit";
519
+ private _getState;
520
+ constructor(core: ComposerRuntimeCoreBinding, _beginEdit: () => void);
521
+ getState(): EditComposerState;
522
+ beginEdit(): void;
523
+ /**
524
+ * @deprecated Use `beginEdit()` instead. This will be removed in 0.6.0.
525
+ */
526
+ edit(): void;
527
+ getAttachmentByIndex(idx: number): EditComposerAttachmentRuntimeImpl;
528
+ }
529
+
530
+ type MessageAttachmentState = CompleteAttachment & {
531
+ source: "message";
532
+ /**
533
+ * @deprecated You can directly access content part fields in the state. Replace `.attachment.type` with `.type` etc. This will be removed in 0.6.0.
534
+ */
535
+ attachment: CompleteAttachment;
536
+ };
537
+ type ThreadComposerAttachmentState = PendingAttachment & {
538
+ source: "thread-composer";
539
+ /**
540
+ * @deprecated You can directly access content part fields in the state. Replace `.attachment.type` with `.type` etc. This will be removed in 0.6.0.
541
+ */
542
+ attachment: PendingAttachment;
543
+ };
544
+ type EditComposerAttachmentState = Attachment & {
545
+ source: "edit-composer";
546
+ /**
547
+ * @deprecated You can directly access content part fields in the state. Replace `.attachment.type` with `.type` etc. This will be removed in 0.6.0.
548
+ */
549
+ attachment: Attachment;
550
+ };
551
+ type AttachmentState = ThreadComposerAttachmentState | EditComposerAttachmentState | MessageAttachmentState;
552
+ type AttachmentSnapshotBinding<Source extends AttachmentRuntimeSource> = SubscribableWithState<AttachmentState & {
553
+ source: Source;
554
+ }>;
555
+ type AttachmentRuntimeSource = AttachmentState["source"];
556
+ type AttachmentRuntime<TSource extends AttachmentRuntimeSource = AttachmentRuntimeSource> = {
557
+ readonly source: TSource;
558
+ getState(): AttachmentState & {
559
+ source: TSource;
560
+ };
561
+ remove(): Promise<void>;
562
+ subscribe(callback: () => void): Unsubscribe;
563
+ };
564
+ declare abstract class AttachmentRuntimeImpl<Source extends AttachmentRuntimeSource = AttachmentRuntimeSource> implements AttachmentRuntime {
565
+ private _core;
566
+ abstract get source(): Source;
567
+ constructor(_core: AttachmentSnapshotBinding<Source>);
568
+ getState(): AttachmentState & {
569
+ source: Source;
570
+ };
571
+ abstract remove(): Promise<void>;
572
+ subscribe(callback: () => void): Unsubscribe;
573
+ }
574
+ declare abstract class ComposerAttachmentRuntime<Source extends "thread-composer" | "edit-composer"> extends AttachmentRuntimeImpl<Source> {
575
+ private _composerApi;
576
+ constructor(core: AttachmentSnapshotBinding<Source>, _composerApi: ComposerRuntimeCoreBinding);
577
+ remove(): Promise<void>;
578
+ }
579
+ declare class ThreadComposerAttachmentRuntimeImpl extends ComposerAttachmentRuntime<"thread-composer"> {
580
+ get source(): "thread-composer";
581
+ }
582
+ declare class EditComposerAttachmentRuntimeImpl extends ComposerAttachmentRuntime<"edit-composer"> {
583
+ get source(): "edit-composer";
584
+ }
585
+ declare class MessageAttachmentRuntimeImpl extends AttachmentRuntimeImpl<"message"> {
586
+ get source(): "message";
587
+ constructor(core: AttachmentSnapshotBinding<"message">);
588
+ remove(): never;
589
+ }
590
+
591
+ type MessageState = ThreadMessage & {
592
+ /**
593
+ * @deprecated You can directly access message fields in the state. Replace `.message.content` with `.content` etc. This will be removed in 0.6.0.
594
+ */
595
+ message: ThreadMessage;
596
+ parentId: string | null;
597
+ isLast: boolean;
598
+ /**
599
+ * @deprecated Use `branchNumber` and `branchCount` instead. This will be removed in 0.6.0.
600
+ */
601
+ branches: readonly string[];
602
+ branchNumber: number;
603
+ branchCount: number;
604
+ };
605
+ type MessageStateBinding = SubscribableWithState<MessageState>;
606
+ type MessageRuntime = {
607
+ composer: EditComposerRuntime;
608
+ getState(): MessageState;
609
+ reload(): void;
610
+ speak(): SpeechSynthesisAdapter.Utterance;
611
+ submitFeedback({ type }: {
612
+ type: "positive" | "negative";
613
+ }): void;
614
+ switchToBranch({ position, branchId, }: {
615
+ position?: "previous" | "next" | undefined;
616
+ branchId?: string | undefined;
617
+ }): void;
618
+ subscribe(callback: () => void): Unsubscribe;
619
+ getContentPartByIndex(idx: number): ContentPartRuntime;
620
+ getAttachmentByIndex(idx: number): AttachmentRuntime & {
621
+ source: "message";
622
+ };
623
+ };
624
+ declare class MessageRuntimeImpl implements MessageRuntime {
625
+ private _core;
626
+ private _threadBinding;
627
+ constructor(_core: MessageStateBinding, _threadBinding: ThreadRuntimeCoreBinding);
628
+ composer: EditComposerRuntimeImpl;
629
+ getState(): MessageState;
630
+ reload(): void;
631
+ speak(): SpeechSynthesisAdapter.Utterance;
632
+ submitFeedback({ type }: {
633
+ type: "positive" | "negative";
634
+ }): void;
635
+ switchToBranch({ position, branchId, }: {
636
+ position?: "previous" | "next" | undefined;
637
+ branchId?: string | undefined;
638
+ }): void;
639
+ subscribe(callback: () => void): Unsubscribe;
640
+ getContentPartByIndex(idx: number): ContentPartRuntimeImpl;
641
+ getAttachmentByIndex(idx: number): MessageAttachmentRuntimeImpl;
642
+ }
643
+
644
+ type CreateAppendMessage = string | {
645
+ parentId?: string | null | undefined;
646
+ role?: AppendMessage["role"] | undefined;
647
+ content: AppendMessage["content"];
648
+ attachments?: AppendMessage["attachments"] | undefined;
649
+ };
650
+ type ThreadRuntimeCoreBinding = SubscribableWithState<ThreadRuntimeCore>;
651
+ type ThreadState = Readonly<{
652
+ threadId: string;
653
+ isDisabled: boolean;
654
+ isRunning: boolean;
655
+ capabilities: RuntimeCapabilities;
656
+ messages: readonly ThreadMessage[];
657
+ suggestions: readonly ThreadSuggestion[];
658
+ extras: unknown;
659
+ }>;
660
+ type ThreadRuntime = {
661
+ composer: ThreadComposerRuntime;
662
+ getState(): ThreadState;
663
+ /**
664
+ * @deprecated This method will be removed in 0.6.0. Submit feedback if you need this functionality.
665
+ */
666
+ unstable_getCore(): ThreadRuntimeCore;
667
+ append(message: CreateAppendMessage): void;
668
+ startRun(parentId: string | null): void;
669
+ subscribe(callback: () => void): Unsubscribe;
670
+ cancelRun(): void;
671
+ getModelConfig(): ModelConfig;
672
+ export(): ExportedMessageRepository;
673
+ import(repository: ExportedMessageRepository): void;
674
+ getMesssageByIndex(idx: number): MessageRuntime;
675
+ /**
676
+ * @deprecated Use `getState().capabilities` instead. This will be removed in 0.6.0.
677
+ */
678
+ capabilities: Readonly<RuntimeCapabilities>;
679
+ /**
680
+ * @deprecated Use `getState().threadId` instead. This will be removed in 0.6.0.
681
+ */
682
+ threadId: string;
683
+ /**
684
+ * @deprecated Use `getState().isDisabled` instead. This will be removed in 0.6.0.
685
+ */
686
+ isDisabled: boolean;
687
+ /**
688
+ * @deprecated Use `getState().isRunning` instead. This will be removed in 0.6.0.
689
+ */
690
+ isRunning: boolean;
691
+ /**
692
+ * @deprecated Use `getState().messages` instead. This will be removed in 0.6.0.
693
+ */
694
+ messages: readonly ThreadMessage[];
695
+ /**
696
+ * @deprecated Use `getState().followupSuggestions` instead. This will be removed in 0.6.0.
697
+ */
698
+ suggestions: readonly ThreadSuggestion[];
699
+ /**
700
+ * @deprecated Use `getState().extras` instead. This will be removed in 0.6.0.
701
+ */
702
+ extras: unknown;
703
+ /**
704
+ * @deprecated Use `getMesssageById(id).getState().branchNumber` / `getMesssageById(id).getState().branchCount` instead. This will be removed in 0.6.0.
705
+ */
706
+ getBranches: (messageId: string) => readonly string[];
707
+ /**
708
+ * @deprecated Use `getMesssageById(id).switchToBranch({ options })` instead. This will be removed in 0.6.0.
709
+ */
710
+ switchToBranch: (branchId: string) => void;
711
+ /**
712
+ * @deprecated Use `getMesssageById(id).getContentPartByToolCallId(toolCallId).addToolResult({ result })` instead. This will be removed in 0.6.0.
713
+ */
714
+ addToolResult: (options: AddToolResultOptions) => void;
715
+ /**
716
+ * @deprecated Use `getMesssageById(id).speak()` instead. This will be removed in 0.6.0.
717
+ */
718
+ speak: (messageId: string) => SpeechSynthesisAdapter.Utterance;
719
+ /**
720
+ * @deprecated Use `getMesssageById(id).submitFeedback({ type })` instead. This will be removed in 0.6.0.
721
+ */
722
+ submitFeedback: (feedback: SubmitFeedbackOptions) => void;
723
+ /**
724
+ * @deprecated Use `getMesssageById(id).getMessageByIndex(idx).composer` instead. This will be removed in 0.6.0.
725
+ */
726
+ getEditComposer: (messageId: string) => ComposerRuntimeCore | undefined;
727
+ /**
728
+ * @deprecated Use `getMesssageById(id).getMessageByIndex(idx).composer.beginEdit()` instead. This will be removed in 0.6.0.
729
+ */
730
+ beginEdit: (messageId: string) => void;
731
+ };
732
+ declare class ThreadRuntimeImpl implements ThreadRuntimeCore, ThreadRuntime {
733
+ /**
734
+ * @deprecated Use `getState().threadId` instead. This will be removed in 0.6.0.
735
+ */
736
+ get threadId(): string;
737
+ /**
738
+ * @deprecated Use `getState().isDisabled` instead. This will be removed in 0.6.0.
739
+ */
740
+ get isDisabled(): boolean;
741
+ /**
742
+ * @deprecated Use `getState().isRunning` instead. This will be removed in 0.6.0.
743
+ */
744
+ get isRunning(): boolean;
745
+ /**
746
+ * @deprecated Use `getState().capabilities` instead. This will be removed in 0.6.0.
747
+ */
748
+ get capabilities(): Readonly<{
749
+ switchToBranch: boolean;
750
+ edit: boolean;
751
+ reload: boolean;
752
+ cancel: boolean;
753
+ unstable_copy: boolean;
754
+ speak: boolean;
755
+ attachments: boolean;
756
+ feedback: boolean;
757
+ }>;
758
+ /**
759
+ * @deprecated Use `getState().extras` instead. This will be removed in 0.6.0.
760
+ */
761
+ get extras(): unknown;
762
+ /**
763
+ * @deprecated Use `getState().followupSuggestions` instead. This will be removed in 0.6.0.
764
+ */
765
+ get suggestions(): readonly ThreadSuggestion[];
766
+ /**
767
+ * @deprecated Use `getState().messages` instead. This will be removed in 0.6.0.
768
+ */
769
+ get messages(): readonly ThreadMessage[];
770
+ unstable_getCore(): Readonly<{
771
+ getBranches: (messageId: string) => readonly string[];
772
+ switchToBranch: (branchId: string) => void;
773
+ append: (message: AppendMessage) => void;
774
+ startRun: (parentId: string | null) => void;
775
+ cancelRun: () => void;
776
+ addToolResult: (options: AddToolResultOptions) => void;
777
+ speak: (messageId: string) => SpeechSynthesisAdapter.Utterance;
778
+ submitFeedback: (feedback: SubmitFeedbackOptions) => void;
779
+ getModelConfig: () => ModelConfig;
780
+ composer: ThreadComposerRuntimeCore;
781
+ getEditComposer: (messageId: string) => ComposerRuntimeCore | undefined;
782
+ beginEdit: (messageId: string) => void;
783
+ capabilities: Readonly<RuntimeCapabilities>;
784
+ threadId: string;
785
+ isDisabled: boolean;
786
+ messages: readonly ThreadMessage[];
787
+ suggestions: readonly ThreadSuggestion[];
788
+ extras: unknown;
789
+ subscribe: (callback: () => void) => Unsubscribe;
790
+ import(repository: ExportedMessageRepository): void;
791
+ export(): ExportedMessageRepository;
792
+ }>;
793
+ private _threadBinding;
794
+ constructor(threadBinding: ThreadRuntimeCoreBinding);
795
+ readonly composer: ThreadComposerRuntimeImpl;
796
+ getState(): Readonly<{
797
+ threadId: string;
798
+ isDisabled: boolean;
799
+ isRunning: boolean;
800
+ capabilities: RuntimeCapabilities;
801
+ messages: readonly ThreadMessage[];
802
+ suggestions: readonly ThreadSuggestion[];
803
+ extras: unknown;
804
+ }>;
805
+ append(message: CreateAppendMessage): void;
806
+ subscribe(callback: () => void): Unsubscribe;
807
+ /**
808
+ * @derprecated Use `getMesssageById(id).getState().branchNumber` / `getMesssageById(id).getState().branchCount` instead. This will be removed in 0.6.0.
809
+ */
810
+ getBranches(messageId: string): readonly string[];
811
+ getModelConfig(): ModelConfig;
812
+ startRun(parentId: string | null): void;
813
+ cancelRun(): void;
814
+ /**
815
+ * @deprecated Use `getMesssageById(id).getContentPartByToolCallId(toolCallId).addToolResult({ result })` instead. This will be removed in 0.6.0.
816
+ */
817
+ addToolResult(options: AddToolResultOptions): void;
818
+ /**
819
+ * @deprecated Use `getMesssageById(id).switchToBranch({ options })` instead. This will be removed in 0.6.0.
820
+ */
821
+ switchToBranch(branchId: string): void;
822
+ speak(messageId: string): SpeechSynthesisAdapter.Utterance;
823
+ submitFeedback(options: SubmitFeedbackOptions): void;
824
+ /**
825
+ * @deprecated Use `getMesssageById(id).getMessageByIndex(idx).composer` instead. This will be removed in 0.6.0.
826
+ */
827
+ getEditComposer(messageId: string): Readonly<{
828
+ attachmentAccept: string;
829
+ attachments: readonly Attachment[];
830
+ addAttachment: (file: File) => Promise<void>;
831
+ removeAttachment: (attachmentId: string) => Promise<void>;
832
+ isEditing: boolean;
833
+ canCancel: boolean;
834
+ isEmpty: boolean;
835
+ text: string;
836
+ setText: (value: string) => void;
837
+ reset: () => void;
838
+ send: () => void;
839
+ cancel: () => void;
840
+ subscribe: (callback: () => void) => Unsubscribe;
841
+ }> | undefined;
842
+ /**
843
+ * @deprecated Use `getMesssageById(id).getMessageByIndex(idx).composer.beginEdit()` instead. This will be removed in 0.6.0.
844
+ */
845
+ beginEdit(messageId: string): void;
846
+ export(): ExportedMessageRepository;
847
+ import(data: ExportedMessageRepository): void;
848
+ getMesssageByIndex(idx: number): MessageRuntimeImpl;
849
+ }
850
+
851
+ type ContentPartState = (ThreadUserContentPart | ThreadAssistantContentPart) & {
852
+ /**
853
+ * @deprecated You can directly access content part fields in the state. Replace `.part.type` with `.type` etc. This will be removed in 0.6.0.
854
+ */
855
+ part: ThreadUserContentPart | ThreadAssistantContentPart;
856
+ status: ContentPartStatus | ToolCallContentPartStatus;
857
+ };
858
+ type ContentPartSnapshotBinding = SubscribableWithState<ContentPartState>;
859
+ type ContentPartRuntime = {
860
+ getState(): ContentPartState;
861
+ addToolResult(result: any): void;
862
+ subscribe(callback: () => void): Unsubscribe;
863
+ };
864
+ declare class ContentPartRuntimeImpl implements ContentPartRuntime {
865
+ private contentBinding;
866
+ private messageApi;
867
+ private threadApi;
868
+ constructor(contentBinding: ContentPartSnapshotBinding, messageApi: MessageStateBinding, threadApi: ThreadRuntimeCoreBinding);
869
+ getState(): ContentPartState;
870
+ addToolResult(result: any): void;
871
+ subscribe(callback: () => void): Unsubscribe;
872
+ }
873
+
874
+ type RuntimeCapabilities = Readonly<{
875
+ switchToBranch: boolean;
876
+ edit: boolean;
877
+ reload: boolean;
878
+ cancel: boolean;
879
+ unstable_copy: boolean;
880
+ speak: boolean;
881
+ attachments: boolean;
882
+ feedback: boolean;
883
+ }>;
884
+ type AddToolResultOptions = {
885
+ messageId: string;
886
+ toolName: string;
887
+ toolCallId: string;
888
+ result: any;
889
+ };
890
+ type SubmitFeedbackOptions = {
891
+ messageId: string;
892
+ type: "negative" | "positive";
893
+ };
894
+ type ThreadSuggestion = {
895
+ prompt: string;
896
+ };
897
+ type ThreadRuntimeCore = Readonly<{
898
+ getBranches: (messageId: string) => readonly string[];
899
+ switchToBranch: (branchId: string) => void;
900
+ append: (message: AppendMessage) => void;
901
+ startRun: (parentId: string | null) => void;
902
+ cancelRun: () => void;
903
+ addToolResult: (options: AddToolResultOptions) => void;
904
+ speak: (messageId: string) => SpeechSynthesisAdapter.Utterance;
905
+ submitFeedback: (feedback: SubmitFeedbackOptions) => void;
906
+ getModelConfig: () => ModelConfig;
907
+ composer: ThreadComposerRuntimeCore;
908
+ getEditComposer: (messageId: string) => ComposerRuntimeCore | undefined;
909
+ beginEdit: (messageId: string) => void;
910
+ capabilities: Readonly<RuntimeCapabilities>;
911
+ threadId: string;
912
+ isDisabled: boolean;
913
+ messages: readonly ThreadMessage[];
914
+ suggestions: readonly ThreadSuggestion[];
915
+ extras: unknown;
916
+ subscribe: (callback: () => void) => Unsubscribe;
917
+ import(repository: ExportedMessageRepository): void;
918
+ export(): ExportedMessageRepository;
919
+ }>;
920
+
7
921
  type VercelRSCMessage = {
8
922
  id?: string | undefined;
9
923
  role: "user" | "assistant";
@@ -17,18 +931,18 @@ type RSCMessageConverter<T> = {
17
931
  type VercelRSCAdapterBase<T> = {
18
932
  isRunning?: boolean | undefined;
19
933
  messages: T[];
20
- onNew?: (message: AppendMessage) => Promise<void>;
21
- onEdit?: ((message: AppendMessage) => Promise<void>) | undefined;
934
+ onNew?: (message: AppendMessage$1) => Promise<void>;
935
+ onEdit?: ((message: AppendMessage$1) => Promise<void>) | undefined;
22
936
  onReload?: ((parentId: string | null) => Promise<void>) | undefined;
23
937
  convertMessage?: ((message: T) => VercelRSCMessage) | undefined;
24
938
  /**
25
939
  * @deprecated Use `onNew` instead. This will be removed in 0.6.0.
26
940
  */
27
- append?: (message: AppendMessage) => Promise<void>;
941
+ append?: (message: AppendMessage$1) => Promise<void>;
28
942
  /**
29
943
  * @deprecated Use `onEdit` instead. This will be removed in 0.6.0.
30
944
  */
31
- edit?: ((message: AppendMessage) => Promise<void>) | undefined;
945
+ edit?: ((message: AppendMessage$1) => Promise<void>) | undefined;
32
946
  /**
33
947
  * @deprecated Use `onReload` instead. This will be removed in 0.6.0.
34
948
  */
@@ -36,14 +950,14 @@ type VercelRSCAdapterBase<T> = {
36
950
  };
37
951
  type VercelRSCAdapter<T = VercelRSCMessage> = VercelRSCAdapterBase<T> & (T extends VercelRSCMessage ? object : RSCMessageConverter<T>);
38
952
 
39
- declare const useVercelRSCRuntime: <T extends WeakKey>(adapter: VercelRSCAdapter<T>) => _assistant_ui_react.AssistantRuntime<_assistant_ui_react.ThreadRuntime>;
953
+ declare const useVercelRSCRuntime: <T extends WeakKey>(adapter: VercelRSCAdapter<T>) => AssistantRuntimeImpl<ThreadRuntimeImpl>;
40
954
 
41
- declare const getVercelRSCMessage: (message: ThreadMessage) => unknown;
955
+ declare const getVercelRSCMessage: (message: ThreadMessage$1) => unknown;
42
956
 
43
- declare const useVercelUseChatRuntime: (chatHelpers: ReturnType<typeof useChat>) => _assistant_ui_react.AssistantRuntime<_assistant_ui_react.ThreadRuntime>;
957
+ declare const useVercelUseChatRuntime: (chatHelpers: ReturnType<typeof useChat>) => AssistantRuntimeImpl<ThreadRuntimeImpl>;
44
958
 
45
- declare const useVercelUseAssistantRuntime: (assistantHelpers: ReturnType<typeof useAssistant>) => _assistant_ui_react.AssistantRuntime<_assistant_ui_react.ThreadRuntime>;
959
+ declare const useVercelUseAssistantRuntime: (assistantHelpers: ReturnType<typeof useAssistant>) => AssistantRuntimeImpl<ThreadRuntimeImpl>;
46
960
 
47
- declare const getVercelAIMessages: (message: ThreadMessage) => Message[];
961
+ declare const getVercelAIMessages: (message: ThreadMessage$1) => Message[];
48
962
 
49
963
  export { type VercelRSCAdapter, type VercelRSCMessage, getVercelAIMessages as getVercelAIMessage, getVercelAIMessages, getVercelRSCMessage, useVercelRSCRuntime, useVercelUseAssistantRuntime, useVercelUseChatRuntime };