@futurity/chat-protocol 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/dist/index.d.ts +2174 -0
- package/dist/index.js +489 -0
- package/package.json +28 -0
- package/src/chat-websocket.ts +219 -0
- package/src/index.ts +2 -0
- package/src/message-parts.ts +326 -0
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
// Canonical wire format for chat WebSocket messages (client ↔ server).
|
|
2
|
+
// Browser-safe — no Node.js imports.
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { Z_MessagePart } from "./message-parts";
|
|
5
|
+
|
|
6
|
+
// ── Supporting schemas ───────────────────────────────────
|
|
7
|
+
|
|
8
|
+
export const wsMessageMetadataSchema = z.object({
|
|
9
|
+
parent_id: z.string().uuid().nullable(),
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export const wsMessageSchema = z.object({
|
|
13
|
+
id: z.string(),
|
|
14
|
+
role: z.enum(["user", "assistant", "system"]),
|
|
15
|
+
parts: z.array(Z_MessagePart),
|
|
16
|
+
metadata: wsMessageMetadataSchema.optional(),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export const wsVaultItemSchema = z.object({
|
|
20
|
+
id: z.string(),
|
|
21
|
+
name: z.string(),
|
|
22
|
+
url: z.string(),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export const wsClarifyOptionSchema = z.object({
|
|
26
|
+
label: z.string(),
|
|
27
|
+
description: z.string(),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export const wsClarifyQuestionSchema = z.object({
|
|
31
|
+
question: z.string(),
|
|
32
|
+
header: z.string(),
|
|
33
|
+
options: z.array(wsClarifyOptionSchema),
|
|
34
|
+
multiSelect: z.boolean(),
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// ── Client → Server commands ─────────────────────────────
|
|
38
|
+
|
|
39
|
+
export const wsRunCommandSchema = z.object({
|
|
40
|
+
type: z.literal("run"),
|
|
41
|
+
data: z.object({
|
|
42
|
+
id: z.string(),
|
|
43
|
+
message: wsMessageSchema,
|
|
44
|
+
vaultItems: z.array(wsVaultItemSchema),
|
|
45
|
+
timezone: z.string(),
|
|
46
|
+
}),
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
export const wsGetChatCommandSchema = z.object({
|
|
50
|
+
type: z.literal("get_chat"),
|
|
51
|
+
data: z.object({
|
|
52
|
+
chat_id: z.string(),
|
|
53
|
+
}),
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
export const wsCancelCommandSchema = z.object({
|
|
57
|
+
type: z.literal("cancel"),
|
|
58
|
+
data: z.object({
|
|
59
|
+
job_id: z.string(),
|
|
60
|
+
}),
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
export const wsClarifyResponseCommandSchema = z.object({
|
|
64
|
+
type: z.literal("clarify_response"),
|
|
65
|
+
data: z.object({
|
|
66
|
+
job_id: z.string(),
|
|
67
|
+
requestId: z.string(),
|
|
68
|
+
answers: z.record(z.string(), z.string()),
|
|
69
|
+
}),
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
export const wsInjectMessageCommandSchema = z.object({
|
|
73
|
+
type: z.literal("inject_message"),
|
|
74
|
+
data: z.object({
|
|
75
|
+
job_id: z.string(),
|
|
76
|
+
text: z.string().max(50000),
|
|
77
|
+
message_id: z.string().uuid(),
|
|
78
|
+
}),
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
export const wsClientCommandSchema = z.discriminatedUnion("type", [
|
|
82
|
+
wsRunCommandSchema,
|
|
83
|
+
wsGetChatCommandSchema,
|
|
84
|
+
wsCancelCommandSchema,
|
|
85
|
+
wsClarifyResponseCommandSchema,
|
|
86
|
+
wsInjectMessageCommandSchema,
|
|
87
|
+
]);
|
|
88
|
+
|
|
89
|
+
// ── Server → Client messages ─────────────────────────────
|
|
90
|
+
|
|
91
|
+
export const wsReadyMessageSchema = z.object({
|
|
92
|
+
type: z.literal("ready"),
|
|
93
|
+
data: z.object({
|
|
94
|
+
success: z.boolean(),
|
|
95
|
+
}),
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
export const wsRunMessageSchema = z.object({
|
|
99
|
+
type: z.literal("run"),
|
|
100
|
+
data: z.object({
|
|
101
|
+
job_id: z.string(),
|
|
102
|
+
message_id: z.string(),
|
|
103
|
+
}),
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
export const wsStreamMessageSchema = z.object({
|
|
107
|
+
type: z.literal("stream"),
|
|
108
|
+
jobId: z.string(),
|
|
109
|
+
chatId: z.string(),
|
|
110
|
+
messageId: z.string(),
|
|
111
|
+
delta: Z_MessagePart,
|
|
112
|
+
index: z.number(),
|
|
113
|
+
consolidated: z.boolean().optional().default(false),
|
|
114
|
+
partsLength: z.number(),
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
export const wsStreamResumeMessageSchema = z.object({
|
|
118
|
+
type: z.literal("stream_resume"),
|
|
119
|
+
jobId: z.string(),
|
|
120
|
+
chatId: z.string(),
|
|
121
|
+
messageId: z.string(),
|
|
122
|
+
parts: z.array(Z_MessagePart),
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
export const wsErrorMessageSchema = z.object({
|
|
126
|
+
type: z.literal("error"),
|
|
127
|
+
error: z.string().optional(),
|
|
128
|
+
message: z.string().optional(),
|
|
129
|
+
data: z.any().optional(),
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
export const wsChatHistoryMessageSchema = z.object({
|
|
133
|
+
type: z.literal("chat_history"),
|
|
134
|
+
data: z.object({
|
|
135
|
+
messages: z.array(z.any()),
|
|
136
|
+
activeMessageId: z.string().optional(),
|
|
137
|
+
}),
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
export const wsCancelMessageSchema = z.object({
|
|
141
|
+
type: z.literal("cancel"),
|
|
142
|
+
data: z.object({
|
|
143
|
+
job_id: z.string(),
|
|
144
|
+
success: z.boolean(),
|
|
145
|
+
reason: z.string().optional(),
|
|
146
|
+
}),
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
export const wsDoneMessageSchema = z.object({
|
|
150
|
+
type: z.literal("done"),
|
|
151
|
+
data: z.object({
|
|
152
|
+
job_id: z.string(),
|
|
153
|
+
}),
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
export const wsClarifyRequestMessageSchema = z.object({
|
|
157
|
+
type: z.literal("clarify_request"),
|
|
158
|
+
data: z.object({
|
|
159
|
+
job_id: z.string(),
|
|
160
|
+
requestId: z.string(),
|
|
161
|
+
questions: z.array(wsClarifyQuestionSchema),
|
|
162
|
+
}),
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
export const wsInjectAckMessageSchema = z.object({
|
|
166
|
+
type: z.literal("inject_ack"),
|
|
167
|
+
data: z.object({
|
|
168
|
+
job_id: z.string(),
|
|
169
|
+
inject_message_id: z.string(),
|
|
170
|
+
new_assistant_id: z.string(),
|
|
171
|
+
}),
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
export const wsInjectSplitMessageSchema = z.object({
|
|
175
|
+
type: z.literal("inject_split"),
|
|
176
|
+
data: z.object({
|
|
177
|
+
job_id: z.string(),
|
|
178
|
+
new_message_id: z.string(),
|
|
179
|
+
}),
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
export const wsServerMessageSchema = z.discriminatedUnion("type", [
|
|
183
|
+
wsReadyMessageSchema,
|
|
184
|
+
wsRunMessageSchema,
|
|
185
|
+
wsStreamMessageSchema,
|
|
186
|
+
wsStreamResumeMessageSchema,
|
|
187
|
+
wsErrorMessageSchema,
|
|
188
|
+
wsChatHistoryMessageSchema,
|
|
189
|
+
wsCancelMessageSchema,
|
|
190
|
+
wsDoneMessageSchema,
|
|
191
|
+
wsClarifyRequestMessageSchema,
|
|
192
|
+
wsInjectAckMessageSchema,
|
|
193
|
+
wsInjectSplitMessageSchema,
|
|
194
|
+
]);
|
|
195
|
+
|
|
196
|
+
// ── Inferred types ───────────────────────────────────────
|
|
197
|
+
|
|
198
|
+
export type WsClientCommand = z.infer<typeof wsClientCommandSchema>;
|
|
199
|
+
export type WsServerMessage = z.infer<typeof wsServerMessageSchema>;
|
|
200
|
+
|
|
201
|
+
export type WsReadyMessage = z.infer<typeof wsReadyMessageSchema>;
|
|
202
|
+
export type WsRunMessage = z.infer<typeof wsRunMessageSchema>;
|
|
203
|
+
export type WsStreamMessage = z.infer<typeof wsStreamMessageSchema>;
|
|
204
|
+
export type WsStreamResumeMessage = z.infer<typeof wsStreamResumeMessageSchema>;
|
|
205
|
+
export type WsErrorMessage = z.infer<typeof wsErrorMessageSchema>;
|
|
206
|
+
export type WsChatHistoryMessage = z.infer<typeof wsChatHistoryMessageSchema>;
|
|
207
|
+
export type WsCancelMessage = z.infer<typeof wsCancelMessageSchema>;
|
|
208
|
+
export type WsDoneMessage = z.infer<typeof wsDoneMessageSchema>;
|
|
209
|
+
export type WsClarifyRequestMessage = z.infer<
|
|
210
|
+
typeof wsClarifyRequestMessageSchema
|
|
211
|
+
>;
|
|
212
|
+
export type WsClarifyQuestion = z.infer<typeof wsClarifyQuestionSchema>;
|
|
213
|
+
export type WsClarifyOption = z.infer<typeof wsClarifyOptionSchema>;
|
|
214
|
+
export type WsInjectAckMessage = z.infer<typeof wsInjectAckMessageSchema>;
|
|
215
|
+
export type WsInjectSplitMessage = z.infer<typeof wsInjectSplitMessageSchema>;
|
|
216
|
+
|
|
217
|
+
export type WsVaultItem = z.infer<typeof wsVaultItemSchema>;
|
|
218
|
+
export type WsMessage = z.infer<typeof wsMessageSchema>;
|
|
219
|
+
export type WsMessageMetadata = z.infer<typeof wsMessageMetadataSchema>;
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
// Canonical Z_MessagePart union used across the monorepo.
|
|
2
|
+
// Browser-safe — no Node.js imports. Keep in sync with packages/db/src/schema/ai.schema.ts.
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
|
|
5
|
+
export const Z_ProviderMetadataSchema = z.record(
|
|
6
|
+
z.string(),
|
|
7
|
+
z.record(z.string(), z.any()),
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
export const Z_TextUIPartSchema = z.object({
|
|
11
|
+
type: z.literal("text"),
|
|
12
|
+
text: z.string(),
|
|
13
|
+
state: z.enum(["streaming", "done"]).optional(),
|
|
14
|
+
providerMetadata: Z_ProviderMetadataSchema.optional(),
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export const Z_ReasoningUIPartSchema = z.object({
|
|
18
|
+
type: z.literal("reasoning"),
|
|
19
|
+
text: z.string(),
|
|
20
|
+
state: z.enum(["streaming", "done"]).optional(),
|
|
21
|
+
providerMetadata: Z_ProviderMetadataSchema.optional(),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export const Z_SourceUrlUIPartSchema = z.object({
|
|
25
|
+
type: z.literal("source-url"),
|
|
26
|
+
sourceId: z.string(),
|
|
27
|
+
url: z.string(),
|
|
28
|
+
title: z.string().optional(),
|
|
29
|
+
providerMetadata: Z_ProviderMetadataSchema.optional(),
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
export const Z_SourceDocumentUIPartSchema = z.object({
|
|
33
|
+
type: z.literal("source-document"),
|
|
34
|
+
sourceId: z.string(),
|
|
35
|
+
mediaType: z.string(),
|
|
36
|
+
title: z.string(),
|
|
37
|
+
filename: z.string().optional(),
|
|
38
|
+
providerMetadata: Z_ProviderMetadataSchema.optional(),
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
export const Z_FileUIPartSchema = z.object({
|
|
42
|
+
type: z.literal("file"),
|
|
43
|
+
mediaType: z.string(),
|
|
44
|
+
filename: z.string().optional(),
|
|
45
|
+
url: z.string(),
|
|
46
|
+
providerMetadata: Z_ProviderMetadataSchema.optional(),
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
export const Z_StepStartUIPartSchema = z.object({
|
|
50
|
+
type: z.literal("step-start"),
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// Data UI Part (generic data with dynamic type names)
|
|
54
|
+
export const Z_DataUIPartSchema = z.object({
|
|
55
|
+
type: z.custom<`data-${string}`>((value) => {
|
|
56
|
+
return typeof value === "string" && value.startsWith("data-");
|
|
57
|
+
}),
|
|
58
|
+
id: z.string().optional(),
|
|
59
|
+
data: z.unknown(),
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// Specific data part schemas for subagent UI markers
|
|
63
|
+
export const Z_DataSplitSchema = z.object({
|
|
64
|
+
type: z.literal("data-split"),
|
|
65
|
+
data: z.object({
|
|
66
|
+
title: z.string(),
|
|
67
|
+
subtitle: z.string().optional(),
|
|
68
|
+
desktopSessionId: z.string().optional(),
|
|
69
|
+
subAgentId: z.string().optional(),
|
|
70
|
+
}),
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
export const Z_DataEndSplitSchema = z.object({
|
|
74
|
+
type: z.literal("data-endsplit"),
|
|
75
|
+
data: z
|
|
76
|
+
.object({
|
|
77
|
+
desktopSessionId: z.string().optional(),
|
|
78
|
+
subAgentId: z.string().optional(),
|
|
79
|
+
})
|
|
80
|
+
.optional(),
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
export const Z_DataSubagentPartSchema = z.object({
|
|
84
|
+
type: z.literal("data-subagent-part"),
|
|
85
|
+
data: z.object({
|
|
86
|
+
subAgentId: z.string(),
|
|
87
|
+
part: z.unknown(),
|
|
88
|
+
}),
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
export const Z_DataStatusSchema = z.object({
|
|
92
|
+
type: z.literal("data-status"),
|
|
93
|
+
id: z.string().optional(),
|
|
94
|
+
data: z.object({
|
|
95
|
+
status: z.enum(["loading", "ready", "error"]),
|
|
96
|
+
text: z.string(),
|
|
97
|
+
}),
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
export const Z_DataClarifyResponseSchema = z.object({
|
|
101
|
+
type: z.literal("data-clarify-response"),
|
|
102
|
+
data: z.object({
|
|
103
|
+
answers: z.record(z.string(), z.string()),
|
|
104
|
+
}),
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
export const Z_DataScreenshotSchema = z.object({
|
|
108
|
+
type: z.literal("data-screenshot"),
|
|
109
|
+
data: z.object({
|
|
110
|
+
src: z.string(),
|
|
111
|
+
toolName: z.string().optional(),
|
|
112
|
+
}),
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
export const Z_DataViewSwitchSchema = z.object({
|
|
116
|
+
type: z.literal("data-view-switch"),
|
|
117
|
+
data: z.object({
|
|
118
|
+
view: z.enum(["browser", "terminal"]),
|
|
119
|
+
}),
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
export const Z_DataFileHighlightSchema = z.object({
|
|
123
|
+
type: z.literal("data-file-highlight"),
|
|
124
|
+
data: z.object({
|
|
125
|
+
path: z.string(),
|
|
126
|
+
label: z.string().optional(),
|
|
127
|
+
}),
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// Tool Invocation schemas
|
|
131
|
+
export const Z_BaseToolInvocationSchema = z.object({
|
|
132
|
+
toolCallId: z.string(),
|
|
133
|
+
title: z.string().optional(),
|
|
134
|
+
providerExecuted: z.boolean().optional(),
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
export const Z_ToolInvocationInputStreamingSchema =
|
|
138
|
+
Z_BaseToolInvocationSchema.extend({
|
|
139
|
+
state: z.literal("input-streaming"),
|
|
140
|
+
input: z.unknown(),
|
|
141
|
+
callProviderMetadata: Z_ProviderMetadataSchema.optional(),
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
export const Z_ToolInvocationInputAvailableSchema =
|
|
145
|
+
Z_BaseToolInvocationSchema.extend({
|
|
146
|
+
state: z.literal("input-available"),
|
|
147
|
+
input: z.unknown(),
|
|
148
|
+
callProviderMetadata: Z_ProviderMetadataSchema.optional(),
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
export const Z_ToolInvocationApprovalRequestedSchema =
|
|
152
|
+
Z_BaseToolInvocationSchema.extend({
|
|
153
|
+
state: z.literal("approval-requested"),
|
|
154
|
+
input: z.unknown(),
|
|
155
|
+
callProviderMetadata: Z_ProviderMetadataSchema.optional(),
|
|
156
|
+
approval: z.object({
|
|
157
|
+
id: z.string(),
|
|
158
|
+
}),
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
export const Z_ToolInvocationApprovalRespondedSchema =
|
|
162
|
+
Z_BaseToolInvocationSchema.extend({
|
|
163
|
+
state: z.literal("approval-responded"),
|
|
164
|
+
input: z.unknown(),
|
|
165
|
+
callProviderMetadata: Z_ProviderMetadataSchema.optional(),
|
|
166
|
+
approval: z.object({
|
|
167
|
+
id: z.string(),
|
|
168
|
+
approved: z.boolean(),
|
|
169
|
+
reason: z.string().optional(),
|
|
170
|
+
}),
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
export const Z_ToolInvocationOutputAvailableSchema =
|
|
174
|
+
Z_BaseToolInvocationSchema.extend({
|
|
175
|
+
state: z.literal("output-available"),
|
|
176
|
+
input: z.unknown(),
|
|
177
|
+
output: z.unknown(),
|
|
178
|
+
callProviderMetadata: Z_ProviderMetadataSchema.optional(),
|
|
179
|
+
preliminary: z.boolean().optional(),
|
|
180
|
+
approval: z
|
|
181
|
+
.object({
|
|
182
|
+
id: z.string(),
|
|
183
|
+
approved: z.literal(true),
|
|
184
|
+
reason: z.string().optional(),
|
|
185
|
+
})
|
|
186
|
+
.optional(),
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
export const Z_ToolInvocationOutputErrorSchema =
|
|
190
|
+
Z_BaseToolInvocationSchema.extend({
|
|
191
|
+
state: z.literal("output-error"),
|
|
192
|
+
input: z.unknown(),
|
|
193
|
+
rawInput: z.unknown().optional(),
|
|
194
|
+
errorText: z.string(),
|
|
195
|
+
callProviderMetadata: Z_ProviderMetadataSchema.optional(),
|
|
196
|
+
approval: z
|
|
197
|
+
.object({
|
|
198
|
+
id: z.string(),
|
|
199
|
+
approved: z.literal(true),
|
|
200
|
+
reason: z.string().optional(),
|
|
201
|
+
})
|
|
202
|
+
.optional(),
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
export const Z_ToolInvocationOutputDeniedSchema =
|
|
206
|
+
Z_BaseToolInvocationSchema.extend({
|
|
207
|
+
state: z.literal("output-denied"),
|
|
208
|
+
input: z.unknown(),
|
|
209
|
+
callProviderMetadata: Z_ProviderMetadataSchema.optional(),
|
|
210
|
+
approval: z.object({
|
|
211
|
+
id: z.string(),
|
|
212
|
+
approved: z.literal(false),
|
|
213
|
+
reason: z.string().optional(),
|
|
214
|
+
}),
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
export const Z_ToolInvocationSchema = z.discriminatedUnion("state", [
|
|
218
|
+
Z_ToolInvocationInputStreamingSchema,
|
|
219
|
+
Z_ToolInvocationInputAvailableSchema,
|
|
220
|
+
Z_ToolInvocationApprovalRequestedSchema,
|
|
221
|
+
Z_ToolInvocationApprovalRespondedSchema,
|
|
222
|
+
Z_ToolInvocationOutputAvailableSchema,
|
|
223
|
+
Z_ToolInvocationOutputErrorSchema,
|
|
224
|
+
Z_ToolInvocationOutputDeniedSchema,
|
|
225
|
+
]);
|
|
226
|
+
|
|
227
|
+
// Tool UI Part (static tool with specific name)
|
|
228
|
+
export const Z_ToolUIPartSchema = z
|
|
229
|
+
.object({
|
|
230
|
+
type: z.custom<`tool-${string}`>((value) => {
|
|
231
|
+
return typeof value === "string" && value.startsWith("tool-");
|
|
232
|
+
}),
|
|
233
|
+
})
|
|
234
|
+
.and(Z_ToolInvocationSchema);
|
|
235
|
+
|
|
236
|
+
export const Z_DynamicToolUIPartSchema = z
|
|
237
|
+
.object({
|
|
238
|
+
type: z.literal("dynamic-tool"),
|
|
239
|
+
toolName: z.string(),
|
|
240
|
+
toolCallId: z.string(),
|
|
241
|
+
title: z.string().optional(),
|
|
242
|
+
providerExecuted: z.boolean().optional(),
|
|
243
|
+
})
|
|
244
|
+
.and(
|
|
245
|
+
z.discriminatedUnion("state", [
|
|
246
|
+
z.object({
|
|
247
|
+
state: z.literal("input-streaming"),
|
|
248
|
+
input: z.unknown(),
|
|
249
|
+
callProviderMetadata: Z_ProviderMetadataSchema.optional(),
|
|
250
|
+
}),
|
|
251
|
+
z.object({
|
|
252
|
+
state: z.literal("input-available"),
|
|
253
|
+
input: z.unknown(),
|
|
254
|
+
callProviderMetadata: Z_ProviderMetadataSchema.optional(),
|
|
255
|
+
}),
|
|
256
|
+
z.object({
|
|
257
|
+
state: z.literal("approval-requested"),
|
|
258
|
+
input: z.unknown(),
|
|
259
|
+
callProviderMetadata: Z_ProviderMetadataSchema.optional(),
|
|
260
|
+
approval: z.object({
|
|
261
|
+
id: z.string(),
|
|
262
|
+
}),
|
|
263
|
+
}),
|
|
264
|
+
z.object({
|
|
265
|
+
state: z.literal("approval-responded"),
|
|
266
|
+
input: z.unknown(),
|
|
267
|
+
callProviderMetadata: Z_ProviderMetadataSchema.optional(),
|
|
268
|
+
approval: z.object({
|
|
269
|
+
id: z.string(),
|
|
270
|
+
approved: z.boolean(),
|
|
271
|
+
reason: z.string().optional(),
|
|
272
|
+
}),
|
|
273
|
+
}),
|
|
274
|
+
z.object({
|
|
275
|
+
state: z.literal("output-available"),
|
|
276
|
+
input: z.unknown(),
|
|
277
|
+
output: z.unknown(),
|
|
278
|
+
callProviderMetadata: Z_ProviderMetadataSchema.optional(),
|
|
279
|
+
preliminary: z.boolean().optional(),
|
|
280
|
+
approval: z
|
|
281
|
+
.object({
|
|
282
|
+
id: z.string(),
|
|
283
|
+
approved: z.literal(true),
|
|
284
|
+
reason: z.string().optional(),
|
|
285
|
+
})
|
|
286
|
+
.optional(),
|
|
287
|
+
}),
|
|
288
|
+
z.object({
|
|
289
|
+
state: z.literal("output-error"),
|
|
290
|
+
input: z.unknown(),
|
|
291
|
+
errorText: z.string(),
|
|
292
|
+
callProviderMetadata: Z_ProviderMetadataSchema.optional(),
|
|
293
|
+
approval: z
|
|
294
|
+
.object({
|
|
295
|
+
id: z.string(),
|
|
296
|
+
approved: z.literal(true),
|
|
297
|
+
reason: z.string().optional(),
|
|
298
|
+
})
|
|
299
|
+
.optional(),
|
|
300
|
+
}),
|
|
301
|
+
z.object({
|
|
302
|
+
state: z.literal("output-denied"),
|
|
303
|
+
input: z.unknown(),
|
|
304
|
+
callProviderMetadata: Z_ProviderMetadataSchema.optional(),
|
|
305
|
+
approval: z.object({
|
|
306
|
+
id: z.string(),
|
|
307
|
+
approved: z.literal(false),
|
|
308
|
+
reason: z.string().optional(),
|
|
309
|
+
}),
|
|
310
|
+
}),
|
|
311
|
+
]),
|
|
312
|
+
);
|
|
313
|
+
|
|
314
|
+
export const Z_MessagePart = z.union([
|
|
315
|
+
Z_TextUIPartSchema,
|
|
316
|
+
Z_ReasoningUIPartSchema,
|
|
317
|
+
Z_SourceUrlUIPartSchema,
|
|
318
|
+
Z_SourceDocumentUIPartSchema,
|
|
319
|
+
Z_FileUIPartSchema,
|
|
320
|
+
Z_StepStartUIPartSchema,
|
|
321
|
+
Z_DataUIPartSchema,
|
|
322
|
+
Z_ToolUIPartSchema,
|
|
323
|
+
Z_DynamicToolUIPartSchema,
|
|
324
|
+
]);
|
|
325
|
+
|
|
326
|
+
export type MessagePart = z.infer<typeof Z_MessagePart>;
|