@assistant-ui/react-statewire 0.0.1

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/src/types.ts ADDED
@@ -0,0 +1,140 @@
1
+ import type { ToolModelContentPart } from "assistant-stream";
2
+ import type { ReadonlyJSONValue } from "assistant-stream/utils";
3
+ import type {
4
+ AttachmentAdapter,
5
+ ThreadMessage,
6
+ ToolExecutionStatus,
7
+ LanguageModelV1CallSettings,
8
+ LanguageModelConfig,
9
+ } from "@assistant-ui/core";
10
+ import type { Assistant } from "@assistant-ui/react";
11
+
12
+ export type UserCommands = Assistant.Commands[keyof Assistant.Commands];
13
+ export type UserExternalState = keyof Assistant.ExternalState extends never
14
+ ? Record<string, unknown>
15
+ : Assistant.ExternalState[keyof Assistant.ExternalState];
16
+
17
+ export type TextPart = {
18
+ readonly type: "text";
19
+ readonly text: string;
20
+ };
21
+
22
+ export type ImagePart = {
23
+ readonly type: "image";
24
+ readonly image: string;
25
+ };
26
+
27
+ export type UserMessagePart = TextPart | ImagePart;
28
+
29
+ export type UserMessage = {
30
+ readonly role: "user";
31
+ readonly parts: readonly UserMessagePart[];
32
+ };
33
+
34
+ export type AssistantMessage = {
35
+ readonly role: "assistant";
36
+ readonly parts: readonly TextPart[];
37
+ };
38
+
39
+ export type AddMessageCommand = {
40
+ readonly type: "add-message";
41
+ readonly message: UserMessage | AssistantMessage;
42
+ readonly parentId: string | null;
43
+ readonly sourceId: string | null;
44
+ };
45
+
46
+ export type AddToolResultCommand = {
47
+ readonly type: "add-tool-result";
48
+ readonly toolCallId: string;
49
+ readonly toolName: string;
50
+ readonly result: ReadonlyJSONValue;
51
+ readonly isError: boolean;
52
+ readonly artifact?: ReadonlyJSONValue;
53
+ readonly modelContent?: readonly ToolModelContentPart[];
54
+ };
55
+
56
+ export type AssistantTransportCommand =
57
+ | AddMessageCommand
58
+ | AddToolResultCommand
59
+ | UserCommands;
60
+
61
+ export type AssistantTransportState = {
62
+ readonly messages: readonly ThreadMessage[];
63
+ readonly state?: ReadonlyJSONValue;
64
+ readonly isRunning: boolean;
65
+ };
66
+
67
+ export type AssistantTransportConnectionMetadata = {
68
+ pendingCommands: AssistantTransportCommand[];
69
+ isSending: boolean;
70
+ toolStatuses: Record<string, ToolExecutionStatus>;
71
+ };
72
+
73
+ export type AssistantTransportStateConverter<T> = (
74
+ state: T,
75
+ connectionMetadata: AssistantTransportConnectionMetadata,
76
+ ) => AssistantTransportState;
77
+
78
+ export type HeadersValue = Record<string, string> | Headers;
79
+
80
+ export type AssistantTransportProtocol = "data-stream" | "assistant-transport";
81
+
82
+ export type SendCommandsRequestBody = {
83
+ commands: AssistantTransportCommand[];
84
+ state: unknown;
85
+ system: string | undefined;
86
+ tools: Record<string, unknown> | undefined;
87
+ callSettings: LanguageModelV1CallSettings | undefined;
88
+ config: LanguageModelConfig | undefined;
89
+ threadId: string | null;
90
+ parentId?: string | null;
91
+ [key: string]: unknown;
92
+ };
93
+
94
+ export type AssistantTransportOptions<T> = {
95
+ initialState: T;
96
+ converter: AssistantTransportStateConverter<T>;
97
+ api: string;
98
+ resumeApi?: string | undefined;
99
+ protocol?: AssistantTransportProtocol | undefined;
100
+ headers: HeadersValue | (() => Promise<HeadersValue>);
101
+ body?: object | (() => Promise<object | undefined>) | undefined;
102
+ /** Transform the fully assembled request body before it is sent. */
103
+ prepareSendCommandsRequest?:
104
+ | ((
105
+ body: SendCommandsRequestBody,
106
+ ) => Record<string, unknown> | Promise<Record<string, unknown>>)
107
+ | undefined;
108
+ onResponse?: ((response: Response) => void) | undefined;
109
+ onFinish?: (() => void) | undefined;
110
+ onError?:
111
+ | ((
112
+ error: Error,
113
+ params: {
114
+ commands: AssistantTransportCommand[];
115
+ updateState: (updater: (state: T) => T) => void;
116
+ },
117
+ ) => void | Promise<void>)
118
+ | undefined;
119
+ /**
120
+ * Called when commands are cancelled. After an error, queued commands are
121
+ * cancelled once `onError` settles; `error` then carries the cause.
122
+ */
123
+ onCancel?:
124
+ | ((params: {
125
+ commands: AssistantTransportCommand[];
126
+ updateState: (updater: (state: T) => T) => void;
127
+ error?: Error;
128
+ }) => void)
129
+ | undefined;
130
+ capabilities?:
131
+ | {
132
+ edit?: boolean | undefined;
133
+ }
134
+ | undefined;
135
+ adapters?:
136
+ | {
137
+ attachments?: AttachmentAdapter | undefined;
138
+ }
139
+ | undefined;
140
+ };