js-bao-wss-client 3.4.0 → 3.4.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/dist/agents/uiMessageTypes.d.ts +360 -0
- package/dist/agents/uiMessageTypes.js +15 -0
- package/dist/agents/uiMessages.d.ts +105 -0
- package/dist/agents/uiMessages.js +467 -0
- package/dist/browser.umd.js +468 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/package.json +2 -2
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
/** A JSON value, as AI SDK providers exchange it. */
|
|
2
|
+
export type JSONValue = null | string | number | boolean | Readonly<JSONObject> | readonly JSONValue[];
|
|
3
|
+
/** A JSON object, as AI SDK providers exchange it. */
|
|
4
|
+
export type JSONObject = {
|
|
5
|
+
[key: string]: JSONValue | undefined;
|
|
6
|
+
};
|
|
7
|
+
/** Provider-specific metadata, keyed by provider name. */
|
|
8
|
+
export type ProviderMetadata = Record<string, JSONObject>;
|
|
9
|
+
/** Provider file identifiers for a file uploaded to a provider, keyed by provider name. */
|
|
10
|
+
export type ProviderReference = Record<string, string> & {
|
|
11
|
+
type?: never;
|
|
12
|
+
};
|
|
13
|
+
/** A type with every key, nested keys included, made optional. */
|
|
14
|
+
export type DeepPartial<T> = T extends null | undefined | string | number | boolean | symbol | bigint | void | Date | RegExp | ((...arguments_: any[]) => unknown) | (new (...arguments_: any[]) => unknown) ? T : T extends Map<infer KeyType, infer ValueType> ? PartialMap<KeyType, ValueType> : T extends Set<infer ItemType> ? PartialSet<ItemType> : T extends ReadonlyMap<infer KeyType, infer ValueType> ? PartialReadonlyMap<KeyType, ValueType> : T extends ReadonlySet<infer ItemType> ? PartialReadonlySet<ItemType> : T extends object ? T extends ReadonlyArray<infer ItemType> ? ItemType[] extends T ? readonly ItemType[] extends T ? ReadonlyArray<DeepPartial<ItemType | undefined>> : Array<DeepPartial<ItemType | undefined>> : PartialObject<T> : PartialObject<T> : unknown;
|
|
15
|
+
/** A `Map` whose keys and values are `DeepPartial`. */
|
|
16
|
+
export type PartialMap<KeyType, ValueType> = {} & Map<DeepPartial<KeyType>, DeepPartial<ValueType>>;
|
|
17
|
+
/** A `Set` whose members are `DeepPartial`. */
|
|
18
|
+
export type PartialSet<T> = {} & Set<DeepPartial<T>>;
|
|
19
|
+
/** A `ReadonlyMap` whose keys and values are `DeepPartial`. */
|
|
20
|
+
export type PartialReadonlyMap<KeyType, ValueType> = {} & ReadonlyMap<DeepPartial<KeyType>, DeepPartial<ValueType>>;
|
|
21
|
+
/** A `ReadonlySet` whose members are `DeepPartial`. */
|
|
22
|
+
export type PartialReadonlySet<T> = {} & ReadonlySet<DeepPartial<T>>;
|
|
23
|
+
/** An object whose keys are optional and whose values are `DeepPartial`. */
|
|
24
|
+
export type PartialObject<ObjectType extends object> = {
|
|
25
|
+
[KeyType in keyof ObjectType]?: DeepPartial<ObjectType[KeyType]>;
|
|
26
|
+
};
|
|
27
|
+
/** The union of an object type's property types. */
|
|
28
|
+
export type ValueOf<ObjectType, ValueType extends keyof ObjectType = keyof ObjectType> = ObjectType[ValueType];
|
|
29
|
+
/** The data types a message's data parts can carry, keyed by data part name. */
|
|
30
|
+
export type UIDataTypes = Record<string, unknown>;
|
|
31
|
+
/** The input and output types of one tool, as a UI message sees them. */
|
|
32
|
+
export type UITool = {
|
|
33
|
+
input: unknown;
|
|
34
|
+
output: unknown | undefined;
|
|
35
|
+
};
|
|
36
|
+
/** The tools a message's tool parts can name, keyed by tool name. */
|
|
37
|
+
export type UITools = Record<string, UITool>;
|
|
38
|
+
/** An AI SDK UI message: the unit AI SDK UI components render. */
|
|
39
|
+
export interface UIMessage<METADATA = unknown, DATA_PARTS extends UIDataTypes = UIDataTypes, TOOLS extends UITools = UITools> {
|
|
40
|
+
/** A unique identifier for the message. */
|
|
41
|
+
id: string;
|
|
42
|
+
/** The role of the message. */
|
|
43
|
+
role: "system" | "user" | "assistant";
|
|
44
|
+
/** The metadata of the message. */
|
|
45
|
+
metadata?: METADATA;
|
|
46
|
+
/** The parts of the message, in the order they are rendered. */
|
|
47
|
+
parts: Array<UIMessagePart<DATA_PARTS, TOOLS>>;
|
|
48
|
+
}
|
|
49
|
+
/** One part of a UI message. */
|
|
50
|
+
export type UIMessagePart<DATA_TYPES extends UIDataTypes, TOOLS extends UITools> = TextUIPart | CustomContentUIPart | ReasoningUIPart | ToolUIPart<TOOLS> | DynamicToolUIPart | SourceUrlUIPart | SourceDocumentUIPart | FileUIPart | ReasoningFileUIPart | DataUIPart<DATA_TYPES> | StepStartUIPart;
|
|
51
|
+
/** A text part of a message. */
|
|
52
|
+
export type TextUIPart = {
|
|
53
|
+
type: "text";
|
|
54
|
+
/** The text content. */
|
|
55
|
+
text: string;
|
|
56
|
+
/** The state of the text part. */
|
|
57
|
+
state?: "streaming" | "done";
|
|
58
|
+
/** The provider metadata. */
|
|
59
|
+
providerMetadata?: ProviderMetadata;
|
|
60
|
+
};
|
|
61
|
+
/** A provider-specific part of a message. */
|
|
62
|
+
export type CustomContentUIPart = {
|
|
63
|
+
type: "custom";
|
|
64
|
+
/** The kind of custom content, in the format `{provider}.{provider-type}`. */
|
|
65
|
+
kind: `${string}.${string}`;
|
|
66
|
+
/** The provider metadata. */
|
|
67
|
+
providerMetadata?: ProviderMetadata;
|
|
68
|
+
};
|
|
69
|
+
/** A reasoning part of a message. */
|
|
70
|
+
export type ReasoningUIPart = {
|
|
71
|
+
type: "reasoning";
|
|
72
|
+
/** The reasoning part ID. */
|
|
73
|
+
id?: string;
|
|
74
|
+
/** The reasoning text. */
|
|
75
|
+
text: string;
|
|
76
|
+
/** The state of the reasoning part. */
|
|
77
|
+
state?: "streaming" | "done";
|
|
78
|
+
/** The provider metadata. */
|
|
79
|
+
providerMetadata?: ProviderMetadata;
|
|
80
|
+
};
|
|
81
|
+
/** A source part of a message. */
|
|
82
|
+
export type SourceUrlUIPart = {
|
|
83
|
+
type: "source-url";
|
|
84
|
+
sourceId: string;
|
|
85
|
+
url: string;
|
|
86
|
+
title?: string;
|
|
87
|
+
providerMetadata?: ProviderMetadata;
|
|
88
|
+
};
|
|
89
|
+
/** A document source part of a message. */
|
|
90
|
+
export type SourceDocumentUIPart = {
|
|
91
|
+
type: "source-document";
|
|
92
|
+
sourceId: string;
|
|
93
|
+
mediaType: string;
|
|
94
|
+
title: string;
|
|
95
|
+
filename?: string;
|
|
96
|
+
providerMetadata?: ProviderMetadata;
|
|
97
|
+
};
|
|
98
|
+
/** A file part of a message. */
|
|
99
|
+
export type FileUIPart = {
|
|
100
|
+
type: "file";
|
|
101
|
+
/** An IANA media type (`image/png`) or its top-level segment (`image`). */
|
|
102
|
+
mediaType: string;
|
|
103
|
+
/** Optional filename of the file. */
|
|
104
|
+
filename?: string;
|
|
105
|
+
/** The URL of the file: a hosted file or a data URL. */
|
|
106
|
+
url: string;
|
|
107
|
+
/** Provider file identifiers, keyed by provider name. */
|
|
108
|
+
providerReference?: ProviderReference;
|
|
109
|
+
/** The provider metadata. */
|
|
110
|
+
providerMetadata?: ProviderMetadata;
|
|
111
|
+
};
|
|
112
|
+
/** A reasoning file part of a message. */
|
|
113
|
+
export type ReasoningFileUIPart = {
|
|
114
|
+
type: "reasoning-file";
|
|
115
|
+
/** IANA media type of the file. */
|
|
116
|
+
mediaType: string;
|
|
117
|
+
/** The URL of the file: a hosted file or a data URL. */
|
|
118
|
+
url: string;
|
|
119
|
+
/** The provider metadata. */
|
|
120
|
+
providerMetadata?: ProviderMetadata;
|
|
121
|
+
};
|
|
122
|
+
/** A step boundary part of a message. */
|
|
123
|
+
export type StepStartUIPart = {
|
|
124
|
+
type: "step-start";
|
|
125
|
+
};
|
|
126
|
+
/** A data part of a message: `data-<name>` carrying that name's data type. */
|
|
127
|
+
export type DataUIPart<DATA_TYPES extends UIDataTypes> = ValueOf<{
|
|
128
|
+
[NAME in keyof DATA_TYPES & string]: {
|
|
129
|
+
type: `data-${NAME}`;
|
|
130
|
+
id?: string;
|
|
131
|
+
data: DATA_TYPES[NAME];
|
|
132
|
+
};
|
|
133
|
+
}>;
|
|
134
|
+
/**
|
|
135
|
+
* Everything needed to render one tool call, by state. Each state admits its
|
|
136
|
+
* own fields: `output` only under `output-available`, `errorText` only under
|
|
137
|
+
* `output-error`, `approval` from `approval-requested` on.
|
|
138
|
+
*/
|
|
139
|
+
export type UIToolInvocation<TOOL extends UITool> = {
|
|
140
|
+
/** ID of the tool call. */
|
|
141
|
+
toolCallId: string;
|
|
142
|
+
title?: string;
|
|
143
|
+
toolMetadata?: JSONObject;
|
|
144
|
+
/** Whether the tool call was executed by the provider. */
|
|
145
|
+
providerExecuted?: boolean;
|
|
146
|
+
} & ({
|
|
147
|
+
state: "input-streaming";
|
|
148
|
+
input?: DeepPartial<TOOL["input"]> | undefined;
|
|
149
|
+
output?: never;
|
|
150
|
+
errorText?: never;
|
|
151
|
+
callProviderMetadata?: ProviderMetadata;
|
|
152
|
+
approval?: never;
|
|
153
|
+
} | {
|
|
154
|
+
state: "input-available";
|
|
155
|
+
input: TOOL["input"];
|
|
156
|
+
output?: never;
|
|
157
|
+
errorText?: never;
|
|
158
|
+
callProviderMetadata?: ProviderMetadata;
|
|
159
|
+
approval?: never;
|
|
160
|
+
} | {
|
|
161
|
+
state: "approval-requested";
|
|
162
|
+
input: TOOL["input"];
|
|
163
|
+
output?: never;
|
|
164
|
+
errorText?: never;
|
|
165
|
+
callProviderMetadata?: ProviderMetadata;
|
|
166
|
+
approval: {
|
|
167
|
+
id: string;
|
|
168
|
+
approved?: never;
|
|
169
|
+
descriptor?: unknown;
|
|
170
|
+
requestReason?: string;
|
|
171
|
+
reason?: never;
|
|
172
|
+
isAutomatic?: boolean;
|
|
173
|
+
signature?: string;
|
|
174
|
+
inputSchemaInput?: unknown;
|
|
175
|
+
};
|
|
176
|
+
} | {
|
|
177
|
+
state: "approval-responded";
|
|
178
|
+
input: TOOL["input"];
|
|
179
|
+
output?: never;
|
|
180
|
+
errorText?: never;
|
|
181
|
+
callProviderMetadata?: ProviderMetadata;
|
|
182
|
+
approval: {
|
|
183
|
+
id: string;
|
|
184
|
+
approved: boolean;
|
|
185
|
+
descriptor?: unknown;
|
|
186
|
+
requestReason?: string;
|
|
187
|
+
reason?: string;
|
|
188
|
+
isAutomatic?: boolean;
|
|
189
|
+
signature?: string;
|
|
190
|
+
inputSchemaInput?: unknown;
|
|
191
|
+
};
|
|
192
|
+
} | {
|
|
193
|
+
state: "output-available";
|
|
194
|
+
input: TOOL["input"];
|
|
195
|
+
output: TOOL["output"];
|
|
196
|
+
errorText?: never;
|
|
197
|
+
callProviderMetadata?: ProviderMetadata;
|
|
198
|
+
resultProviderMetadata?: ProviderMetadata;
|
|
199
|
+
preliminary?: boolean;
|
|
200
|
+
approval?: {
|
|
201
|
+
id: string;
|
|
202
|
+
approved: true;
|
|
203
|
+
descriptor?: unknown;
|
|
204
|
+
requestReason?: string;
|
|
205
|
+
reason?: string;
|
|
206
|
+
isAutomatic?: boolean;
|
|
207
|
+
signature?: string;
|
|
208
|
+
inputSchemaInput?: unknown;
|
|
209
|
+
};
|
|
210
|
+
} | {
|
|
211
|
+
state: "output-error";
|
|
212
|
+
input: TOOL["input"] | undefined;
|
|
213
|
+
/** @deprecated Use `input` instead. */
|
|
214
|
+
rawInput?: unknown;
|
|
215
|
+
output?: never;
|
|
216
|
+
errorText: string;
|
|
217
|
+
callProviderMetadata?: ProviderMetadata;
|
|
218
|
+
resultProviderMetadata?: ProviderMetadata;
|
|
219
|
+
approval?: {
|
|
220
|
+
id: string;
|
|
221
|
+
approved: true;
|
|
222
|
+
descriptor?: unknown;
|
|
223
|
+
requestReason?: string;
|
|
224
|
+
reason?: string;
|
|
225
|
+
isAutomatic?: boolean;
|
|
226
|
+
signature?: string;
|
|
227
|
+
inputSchemaInput?: unknown;
|
|
228
|
+
};
|
|
229
|
+
} | {
|
|
230
|
+
state: "output-denied";
|
|
231
|
+
input: TOOL["input"];
|
|
232
|
+
output?: never;
|
|
233
|
+
errorText?: never;
|
|
234
|
+
callProviderMetadata?: ProviderMetadata;
|
|
235
|
+
approval: {
|
|
236
|
+
id: string;
|
|
237
|
+
approved: false;
|
|
238
|
+
descriptor?: unknown;
|
|
239
|
+
requestReason?: string;
|
|
240
|
+
reason?: string;
|
|
241
|
+
isAutomatic?: boolean;
|
|
242
|
+
signature?: string;
|
|
243
|
+
inputSchemaInput?: unknown;
|
|
244
|
+
};
|
|
245
|
+
});
|
|
246
|
+
/** A tool call part of a message: `tool-<name>` for a tool of `TOOLS`. */
|
|
247
|
+
export type ToolUIPart<TOOLS extends UITools = UITools> = ValueOf<{
|
|
248
|
+
[NAME in keyof TOOLS & string]: {
|
|
249
|
+
type: `tool-${NAME}`;
|
|
250
|
+
} & UIToolInvocation<TOOLS[NAME]>;
|
|
251
|
+
}>;
|
|
252
|
+
/** A tool call part for a tool the message's `TOOLS` do not declare. */
|
|
253
|
+
export type DynamicToolUIPart = {
|
|
254
|
+
type: "dynamic-tool";
|
|
255
|
+
/** Name of the tool that is being called. */
|
|
256
|
+
toolName: string;
|
|
257
|
+
/** ID of the tool call. */
|
|
258
|
+
toolCallId: string;
|
|
259
|
+
title?: string;
|
|
260
|
+
toolMetadata?: JSONObject;
|
|
261
|
+
/** Whether the tool call was executed by the provider. */
|
|
262
|
+
providerExecuted?: boolean;
|
|
263
|
+
} & ({
|
|
264
|
+
state: "input-streaming";
|
|
265
|
+
input?: unknown;
|
|
266
|
+
output?: never;
|
|
267
|
+
errorText?: never;
|
|
268
|
+
callProviderMetadata?: ProviderMetadata;
|
|
269
|
+
approval?: never;
|
|
270
|
+
} | {
|
|
271
|
+
state: "input-available";
|
|
272
|
+
input: unknown;
|
|
273
|
+
output?: never;
|
|
274
|
+
errorText?: never;
|
|
275
|
+
callProviderMetadata?: ProviderMetadata;
|
|
276
|
+
approval?: never;
|
|
277
|
+
} | {
|
|
278
|
+
state: "approval-requested";
|
|
279
|
+
input: unknown;
|
|
280
|
+
output?: never;
|
|
281
|
+
errorText?: never;
|
|
282
|
+
callProviderMetadata?: ProviderMetadata;
|
|
283
|
+
approval: {
|
|
284
|
+
id: string;
|
|
285
|
+
approved?: never;
|
|
286
|
+
descriptor?: unknown;
|
|
287
|
+
requestReason?: string;
|
|
288
|
+
reason?: never;
|
|
289
|
+
isAutomatic?: boolean;
|
|
290
|
+
signature?: string;
|
|
291
|
+
inputSchemaInput?: unknown;
|
|
292
|
+
};
|
|
293
|
+
} | {
|
|
294
|
+
state: "approval-responded";
|
|
295
|
+
input: unknown;
|
|
296
|
+
output?: never;
|
|
297
|
+
errorText?: never;
|
|
298
|
+
callProviderMetadata?: ProviderMetadata;
|
|
299
|
+
approval: {
|
|
300
|
+
id: string;
|
|
301
|
+
approved: boolean;
|
|
302
|
+
descriptor?: unknown;
|
|
303
|
+
requestReason?: string;
|
|
304
|
+
reason?: string;
|
|
305
|
+
isAutomatic?: boolean;
|
|
306
|
+
signature?: string;
|
|
307
|
+
inputSchemaInput?: unknown;
|
|
308
|
+
};
|
|
309
|
+
} | {
|
|
310
|
+
state: "output-available";
|
|
311
|
+
input: unknown;
|
|
312
|
+
output: unknown;
|
|
313
|
+
errorText?: never;
|
|
314
|
+
callProviderMetadata?: ProviderMetadata;
|
|
315
|
+
resultProviderMetadata?: ProviderMetadata;
|
|
316
|
+
preliminary?: boolean;
|
|
317
|
+
approval?: {
|
|
318
|
+
id: string;
|
|
319
|
+
approved: true;
|
|
320
|
+
descriptor?: unknown;
|
|
321
|
+
requestReason?: string;
|
|
322
|
+
reason?: string;
|
|
323
|
+
isAutomatic?: boolean;
|
|
324
|
+
signature?: string;
|
|
325
|
+
inputSchemaInput?: unknown;
|
|
326
|
+
};
|
|
327
|
+
} | {
|
|
328
|
+
state: "output-error";
|
|
329
|
+
input: unknown;
|
|
330
|
+
output?: never;
|
|
331
|
+
errorText: string;
|
|
332
|
+
callProviderMetadata?: ProviderMetadata;
|
|
333
|
+
resultProviderMetadata?: ProviderMetadata;
|
|
334
|
+
approval?: {
|
|
335
|
+
id: string;
|
|
336
|
+
approved: true;
|
|
337
|
+
descriptor?: unknown;
|
|
338
|
+
requestReason?: string;
|
|
339
|
+
reason?: string;
|
|
340
|
+
isAutomatic?: boolean;
|
|
341
|
+
signature?: string;
|
|
342
|
+
inputSchemaInput?: unknown;
|
|
343
|
+
};
|
|
344
|
+
} | {
|
|
345
|
+
state: "output-denied";
|
|
346
|
+
input: unknown;
|
|
347
|
+
output?: never;
|
|
348
|
+
errorText?: never;
|
|
349
|
+
callProviderMetadata?: ProviderMetadata;
|
|
350
|
+
approval: {
|
|
351
|
+
id: string;
|
|
352
|
+
approved: false;
|
|
353
|
+
descriptor?: unknown;
|
|
354
|
+
requestReason?: string;
|
|
355
|
+
reason?: string;
|
|
356
|
+
isAutomatic?: boolean;
|
|
357
|
+
signature?: string;
|
|
358
|
+
inputSchemaInput?: unknown;
|
|
359
|
+
};
|
|
360
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// The AI SDK `UIMessage` family as structural types.
|
|
2
|
+
//
|
|
3
|
+
// Transcribed from the published `ai` package, version 7.0.119
|
|
4
|
+
// (`ai/dist/index.d.ts`; `ProviderMetadata`, `ProviderReference` and the JSON
|
|
5
|
+
// value types from `@ai-sdk/provider` 4.0.19, which that version depends on),
|
|
6
|
+
// so the client ships AI SDK shapes with no dependency on `ai`. The names are
|
|
7
|
+
// the ones `ai` uses. `ToolUIPart` is the per-state union it is in `ai`: each
|
|
8
|
+
// state admits its own fields. Only `FlexibleSchema` is left out of
|
|
9
|
+
// `DeepPartial`, because the `TOOLS` here are UI tools, never schemas.
|
|
10
|
+
//
|
|
11
|
+
// `tests/unit/workflows/agent-ui-message-types-3804.test.ts` compiles these
|
|
12
|
+
// against the published declarations in both directions.
|
|
13
|
+
//
|
|
14
|
+
// Types only: no imports, no emitted code.
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { type PrimitiveFilePartRecord, type PrimitiveMessageRecord, type PrimitiveMessageRow, type PrimitivePartRecord, type PrimitivePartRow, type PrimitiveStepRecord } from "./sessionModels.generated";
|
|
2
|
+
import type { UIMessage, UITools } from "./uiMessageTypes";
|
|
3
|
+
/** The decoded rows of one session document (from the `decodePrimitive*` functions). */
|
|
4
|
+
export interface PrimitiveSessionContent {
|
|
5
|
+
messages: readonly PrimitiveMessageRecord[];
|
|
6
|
+
parts: readonly PrimitivePartRecord[];
|
|
7
|
+
steps?: readonly PrimitiveStepRecord[];
|
|
8
|
+
}
|
|
9
|
+
/** Options for `toUIMessages`. */
|
|
10
|
+
export interface ToUIMessagesOptions {
|
|
11
|
+
/**
|
|
12
|
+
* The `url` of a file part. Default: `primitive-blob:<blobId>`, which an app
|
|
13
|
+
* resolves itself (for example with the document's `blobs.proxyUrl`), or
|
|
14
|
+
* `""` for a file part with no blob.
|
|
15
|
+
*/
|
|
16
|
+
fileUrl?: (part: PrimitiveFilePartRecord) => string;
|
|
17
|
+
}
|
|
18
|
+
/** The platform-only fields of one part, in `metadata.parts` at the part's index. */
|
|
19
|
+
export interface PrimitiveUIPartMetadata {
|
|
20
|
+
id: string;
|
|
21
|
+
seq: number;
|
|
22
|
+
createdAt: string;
|
|
23
|
+
modifiedAt?: string;
|
|
24
|
+
/** Tool call parts. */
|
|
25
|
+
statusText?: string;
|
|
26
|
+
errorCode?: string;
|
|
27
|
+
approvalUserId?: string;
|
|
28
|
+
approvalRespondedAt?: string;
|
|
29
|
+
resolvedByUserId?: string;
|
|
30
|
+
artifact?: unknown;
|
|
31
|
+
artifactBlobId?: string;
|
|
32
|
+
/** File parts. */
|
|
33
|
+
blobId?: string;
|
|
34
|
+
sizeBytes?: number;
|
|
35
|
+
/** The part row as read, present only when the mapping alone would not reproduce it. */
|
|
36
|
+
source?: PrimitivePartRow;
|
|
37
|
+
}
|
|
38
|
+
/** The platform-only fields of one message, in its `metadata`. */
|
|
39
|
+
export interface PrimitiveUIMessageMetadata {
|
|
40
|
+
seq: number;
|
|
41
|
+
turnId?: string;
|
|
42
|
+
authorUserId?: string;
|
|
43
|
+
clientMessageId?: string;
|
|
44
|
+
createdAt: string;
|
|
45
|
+
/** One entry per element of `parts`, in the same order. */
|
|
46
|
+
parts: PrimitiveUIPartMetadata[];
|
|
47
|
+
/** The step rows of this message's turn, by step `seq`; present only when there are any. */
|
|
48
|
+
steps?: PrimitiveStepRecord[];
|
|
49
|
+
/** The message row as read, present only when the mapping alone would not reproduce it. */
|
|
50
|
+
source?: PrimitiveMessageRow;
|
|
51
|
+
}
|
|
52
|
+
/** The data of a `data-primitive-event` part: an event part's columns. */
|
|
53
|
+
export interface PrimitiveUIEventData {
|
|
54
|
+
eventKind?: string;
|
|
55
|
+
eventId?: string;
|
|
56
|
+
refersTo?: string;
|
|
57
|
+
data?: unknown;
|
|
58
|
+
}
|
|
59
|
+
/** The data part types a session's `UIMessage`s carry. */
|
|
60
|
+
export type PrimitiveUIDataTypes = {
|
|
61
|
+
"primitive-event": PrimitiveUIEventData;
|
|
62
|
+
};
|
|
63
|
+
/** A session message as an AI SDK `UIMessage`, typed by the app's tools. */
|
|
64
|
+
export type PrimitiveUIMessage<TOOLS extends UITools = UITools> = UIMessage<PrimitiveUIMessageMetadata, PrimitiveUIDataTypes, TOOLS>;
|
|
65
|
+
/**
|
|
66
|
+
* The error `toUIMessages` and `fromUIMessages` throw for input they cannot
|
|
67
|
+
* map. `AGENT_UI_MESSAGE_ORPHAN` is a part or step with no message to ride
|
|
68
|
+
* on; `AGENT_UI_MESSAGE_UNMAPPABLE` is everything else.
|
|
69
|
+
*/
|
|
70
|
+
export interface AgentUIMessageError extends Error {
|
|
71
|
+
code: "AGENT_UI_MESSAGE_UNMAPPABLE" | "AGENT_UI_MESSAGE_ORPHAN";
|
|
72
|
+
messageId?: string;
|
|
73
|
+
partId?: string;
|
|
74
|
+
stepId?: string;
|
|
75
|
+
/** What could not be mapped, e.g. `part kind "sticker"` or `tool state "queued"`. */
|
|
76
|
+
reason: string;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The session's messages as AI SDK `UIMessage`s, one per `PrimitiveMessage`
|
|
80
|
+
* by `seq` (then id), each with its parts by `seq` (then id). Platform-only
|
|
81
|
+
* fields ride in `metadata`; a turn's steps ride on the turn's last message,
|
|
82
|
+
* or on the session's last message when the turn has none. A row the mapping
|
|
83
|
+
* alone would not reproduce carries itself as `source`, so `fromUIMessages`
|
|
84
|
+
* returns it exactly. Throws an `AgentUIMessageError` for a row it cannot map:
|
|
85
|
+
* an unknown author, part kind, tool state or text state, a tool part missing
|
|
86
|
+
* a column its state requires, a part with no message, or a step when there is
|
|
87
|
+
* no message at all.
|
|
88
|
+
*/
|
|
89
|
+
export declare function toUIMessages<TOOLS extends UITools = UITools>(content: PrimitiveSessionContent, options?: ToUIMessagesOptions): PrimitiveUIMessage<TOOLS>[];
|
|
90
|
+
/**
|
|
91
|
+
* The records `UIMessage`s from `toUIMessages` map back to, in the order they
|
|
92
|
+
* appear; `encodePrimitiveMessage`, `encodePrimitivePart` and
|
|
93
|
+
* `encodePrimitiveStep` turn them into the rows that went in. A message or
|
|
94
|
+
* part carrying `source` is rebuilt from it, with only the fields the app
|
|
95
|
+
* changed overwritten, and its record carries `row`; the rest carry none. A
|
|
96
|
+
* file part's `url` is never read (its blob is `metadata.parts[i].blobId`).
|
|
97
|
+
* Throws an `AgentUIMessageError` for a message without the adapter's
|
|
98
|
+
* metadata, a `parts`/`metadata.parts` length mismatch, a part type the
|
|
99
|
+
* adapter never produces, or a tool part whose fields do not fit its state.
|
|
100
|
+
*/
|
|
101
|
+
export declare function fromUIMessages(messages: readonly PrimitiveUIMessage<any>[]): {
|
|
102
|
+
messages: PrimitiveMessageRecord[];
|
|
103
|
+
parts: PrimitivePartRecord[];
|
|
104
|
+
steps: PrimitiveStepRecord[];
|
|
105
|
+
};
|