@blazingagents/sdk 0.1.0
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/LICENSE +21 -0
- package/README.md +366 -0
- package/dist/chat-transport.d.ts +17 -0
- package/dist/chat-transport.js +58 -0
- package/dist/client.d.ts +38 -0
- package/dist/client.js +86 -0
- package/dist/contracts/api.d.ts +256 -0
- package/dist/contracts/api.js +189 -0
- package/dist/contracts/entities/agent-tools.d.ts +26 -0
- package/dist/contracts/entities/agent-tools.js +52 -0
- package/dist/contracts/entities/agents.d.ts +183 -0
- package/dist/contracts/entities/agents.js +153 -0
- package/dist/contracts/entities/artifacts.d.ts +71 -0
- package/dist/contracts/entities/artifacts.js +71 -0
- package/dist/contracts/entities/attribution.d.ts +27 -0
- package/dist/contracts/entities/attribution.js +27 -0
- package/dist/contracts/entities/chat.d.ts +269 -0
- package/dist/contracts/entities/chat.js +198 -0
- package/dist/contracts/entities/mcp-connections.d.ts +421 -0
- package/dist/contracts/entities/mcp-connections.js +473 -0
- package/dist/contracts/entities/memories.d.ts +56 -0
- package/dist/contracts/entities/memories.js +62 -0
- package/dist/contracts/entities/prompts.d.ts +61 -0
- package/dist/contracts/entities/prompts.js +96 -0
- package/dist/contracts/entities/providers.d.ts +123 -0
- package/dist/contracts/entities/providers.js +111 -0
- package/dist/contracts/entities/sessions.d.ts +156 -0
- package/dist/contracts/entities/sessions.js +120 -0
- package/dist/contracts/entities/skills.d.ts +167 -0
- package/dist/contracts/entities/skills.js +153 -0
- package/dist/contracts/entities/tasks.d.ts +457 -0
- package/dist/contracts/entities/tasks.js +252 -0
- package/dist/contracts/entities/tenants.d.ts +69 -0
- package/dist/contracts/entities/tenants.js +54 -0
- package/dist/contracts/entities/usage.d.ts +95 -0
- package/dist/contracts/entities/usage.js +117 -0
- package/dist/contracts/entities/workspaces.d.ts +89 -0
- package/dist/contracts/entities/workspaces.js +71 -0
- package/dist/contracts/ids.d.ts +57 -0
- package/dist/contracts/ids.js +79 -0
- package/dist/contracts/index.d.ts +15 -0
- package/dist/contracts/index.js +16 -0
- package/dist/contracts/limitations.d.ts +138 -0
- package/dist/contracts/limitations.js +140 -0
- package/dist/contracts/utils.d.ts +3 -0
- package/dist/contracts/utils.js +7 -0
- package/dist/errors.d.ts +33 -0
- package/dist/errors.js +48 -0
- package/dist/generation.d.ts +5 -0
- package/dist/generation.js +422 -0
- package/dist/http.d.ts +21 -0
- package/dist/http.js +307 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +13 -0
- package/dist/relay.d.ts +20 -0
- package/dist/relay.js +113 -0
- package/dist/resources/agents.d.ts +8 -0
- package/dist/resources/agents.js +82 -0
- package/dist/resources/artifacts.d.ts +5 -0
- package/dist/resources/artifacts.js +29 -0
- package/dist/resources/mcp-connections.d.ts +2 -0
- package/dist/resources/mcp-connections.js +40 -0
- package/dist/resources/memories.d.ts +7 -0
- package/dist/resources/memories.js +33 -0
- package/dist/resources/prompts.d.ts +6 -0
- package/dist/resources/prompts.js +36 -0
- package/dist/resources/providers.d.ts +5 -0
- package/dist/resources/providers.js +38 -0
- package/dist/resources/sessions.d.ts +8 -0
- package/dist/resources/sessions.js +49 -0
- package/dist/resources/skills.d.ts +2 -0
- package/dist/resources/skills.js +49 -0
- package/dist/resources/tasks.d.ts +7 -0
- package/dist/resources/tasks.js +63 -0
- package/dist/resources/tenant.d.ts +6 -0
- package/dist/resources/tenant.js +19 -0
- package/dist/resources/usage.d.ts +7 -0
- package/dist/resources/usage.js +19 -0
- package/dist/resources/workspaces.d.ts +2 -0
- package/dist/resources/workspaces.js +31 -0
- package/dist/types.d.ts +381 -0
- package/dist/types.js +1 -0
- package/package.json +65 -0
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Re-exported AI SDK types — every service, the SDK, and the dashboard
|
|
4
|
+
* consume these from one place.
|
|
5
|
+
*/
|
|
6
|
+
export type { UIMessage, UIMessageChunk } from "ai";
|
|
7
|
+
export declare const chatModeSchema: z.ZodEnum<{
|
|
8
|
+
create: "create";
|
|
9
|
+
resume: "resume";
|
|
10
|
+
}>;
|
|
11
|
+
export declare const chatTriggerSchema: z.ZodEnum<{
|
|
12
|
+
"regenerate-message": "regenerate-message";
|
|
13
|
+
"submit-message": "submit-message";
|
|
14
|
+
}>;
|
|
15
|
+
/**
|
|
16
|
+
* Per-Turn usage summary stamped into the assistant message's
|
|
17
|
+
* `metadata.blazingAgents.usage` and persisted by the server. Session Turns
|
|
18
|
+
* carry an `ss_` id; stateless generation uses the empty-string sentinel.
|
|
19
|
+
*/
|
|
20
|
+
export declare const usageSummarySchema: z.ZodObject<{
|
|
21
|
+
agentId: z.ZodString;
|
|
22
|
+
agentVersion: z.ZodNumber;
|
|
23
|
+
commitId: z.ZodString;
|
|
24
|
+
completedAt: z.ZodISODateTime;
|
|
25
|
+
durationMs: z.ZodNumber;
|
|
26
|
+
errorMessage: z.ZodNullable<z.ZodString>;
|
|
27
|
+
inputTokens: z.ZodNumber;
|
|
28
|
+
modelDurationMs: z.ZodNumber;
|
|
29
|
+
metadata: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
30
|
+
modelId: z.ZodString;
|
|
31
|
+
outputTokens: z.ZodNumber;
|
|
32
|
+
turnId: z.ZodString;
|
|
33
|
+
sessionId: z.ZodUnion<readonly [z.ZodString, z.ZodLiteral<"">]>;
|
|
34
|
+
stepUsages: z.ZodArray<z.ZodObject<{
|
|
35
|
+
inputTokens: z.ZodNumber;
|
|
36
|
+
outputTokens: z.ZodNumber;
|
|
37
|
+
stepNumber: z.ZodNumber;
|
|
38
|
+
}, z.core.$strict>>;
|
|
39
|
+
startedAt: z.ZodISODateTime;
|
|
40
|
+
status: z.ZodEnum<{
|
|
41
|
+
cancelled: "cancelled";
|
|
42
|
+
failed: "failed";
|
|
43
|
+
succeeded: "succeeded";
|
|
44
|
+
}>;
|
|
45
|
+
tenantId: z.ZodString;
|
|
46
|
+
userId: z.ZodString;
|
|
47
|
+
}, z.core.$strict>;
|
|
48
|
+
export declare const blazingAgentsChatMessageMetadataSchema: z.ZodObject<{
|
|
49
|
+
blazingAgents: z.ZodObject<{
|
|
50
|
+
usage: z.ZodObject<{
|
|
51
|
+
agentId: z.ZodString;
|
|
52
|
+
agentVersion: z.ZodNumber;
|
|
53
|
+
commitId: z.ZodString;
|
|
54
|
+
completedAt: z.ZodISODateTime;
|
|
55
|
+
durationMs: z.ZodNumber;
|
|
56
|
+
errorMessage: z.ZodNullable<z.ZodString>;
|
|
57
|
+
inputTokens: z.ZodNumber;
|
|
58
|
+
modelDurationMs: z.ZodNumber;
|
|
59
|
+
metadata: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
60
|
+
modelId: z.ZodString;
|
|
61
|
+
outputTokens: z.ZodNumber;
|
|
62
|
+
turnId: z.ZodString;
|
|
63
|
+
sessionId: z.ZodUnion<readonly [z.ZodString, z.ZodLiteral<"">]>;
|
|
64
|
+
stepUsages: z.ZodArray<z.ZodObject<{
|
|
65
|
+
inputTokens: z.ZodNumber;
|
|
66
|
+
outputTokens: z.ZodNumber;
|
|
67
|
+
stepNumber: z.ZodNumber;
|
|
68
|
+
}, z.core.$strict>>;
|
|
69
|
+
startedAt: z.ZodISODateTime;
|
|
70
|
+
status: z.ZodEnum<{
|
|
71
|
+
cancelled: "cancelled";
|
|
72
|
+
failed: "failed";
|
|
73
|
+
succeeded: "succeeded";
|
|
74
|
+
}>;
|
|
75
|
+
tenantId: z.ZodString;
|
|
76
|
+
userId: z.ZodString;
|
|
77
|
+
}, z.core.$strict>;
|
|
78
|
+
}, z.core.$strict>;
|
|
79
|
+
}, z.core.$strict>;
|
|
80
|
+
/**
|
|
81
|
+
* `variables` for the prompt-invocation path — a flat map of string→string.
|
|
82
|
+
* The prompt template's derived variables are the required keys; this is
|
|
83
|
+
* the wire shape only, the route layer enforces strict both-ways matching
|
|
84
|
+
* against the template (missing or unknown variable → 400 invalid_request).
|
|
85
|
+
*/
|
|
86
|
+
export declare const promptVariablesSchema: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
87
|
+
type ExclusivePromptInput<Literal extends object> = (Literal & {
|
|
88
|
+
promptId?: never;
|
|
89
|
+
variables?: never;
|
|
90
|
+
}) | (Partial<Record<keyof Literal, never>> & {
|
|
91
|
+
promptId: string;
|
|
92
|
+
variables?: z.infer<typeof promptVariablesSchema>;
|
|
93
|
+
});
|
|
94
|
+
/**
|
|
95
|
+
* `POST /v1/agents/{agentId}/sessions` (create) and
|
|
96
|
+
* `POST /v1/agents/{agentId}/sessions/{sessionId}` (resume) request body.
|
|
97
|
+
* The platform mints the `ss_` session id on the create path and returns
|
|
98
|
+
* it via the `Location` header; the URL presence (no id → create, id
|
|
99
|
+
* present → resume) is the mode — there is no `id` or `mode` field here.
|
|
100
|
+
* `message` is the literal input; the prompt-invocation alternative
|
|
101
|
+
* (`promptId` + `variables`) is mutually exclusive with `message` — both
|
|
102
|
+
* present or neither → 400 invalid_request. `variables` is only allowed
|
|
103
|
+
* on the prompt-invocation path: a request carrying both `message` and
|
|
104
|
+
* `variables` (without `promptId`) is a mixed shape and is rejected
|
|
105
|
+
* (strict both ways). The route layer resolves the prompt template,
|
|
106
|
+
* renders, and substitutes a server-constructed user `UIMessage` with a
|
|
107
|
+
* single text part carrying the rendered string. `trigger` /
|
|
108
|
+
* `messageId` are turn-level concerns (regenerate rides on the resume
|
|
109
|
+
* route only — enforced by the route layer, not the schema).
|
|
110
|
+
*/
|
|
111
|
+
export declare const chatRequestBodySchema: z.ZodObject<{
|
|
112
|
+
message: z.ZodOptional<z.ZodUnknown>;
|
|
113
|
+
promptId: z.ZodOptional<z.ZodString>;
|
|
114
|
+
variables: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
115
|
+
trigger: z.ZodDefault<z.ZodEnum<{
|
|
116
|
+
"regenerate-message": "regenerate-message";
|
|
117
|
+
"submit-message": "submit-message";
|
|
118
|
+
}>>;
|
|
119
|
+
messageId: z.ZodOptional<z.ZodString>;
|
|
120
|
+
version: z.ZodOptional<z.ZodNumber>;
|
|
121
|
+
userId: z.ZodDefault<z.ZodString>;
|
|
122
|
+
metadata: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
123
|
+
}, z.core.$strict> & z.ZodType<{
|
|
124
|
+
message?: unknown;
|
|
125
|
+
promptId?: string | undefined;
|
|
126
|
+
variables?: Record<string, string> | undefined;
|
|
127
|
+
trigger: "regenerate-message" | "submit-message";
|
|
128
|
+
messageId?: string | undefined;
|
|
129
|
+
version?: number | undefined;
|
|
130
|
+
userId: string;
|
|
131
|
+
metadata: Record<string, unknown>;
|
|
132
|
+
} & ExclusivePromptInput<{
|
|
133
|
+
message: null | NonNullable<unknown>;
|
|
134
|
+
}>, {
|
|
135
|
+
message?: unknown;
|
|
136
|
+
promptId?: string | undefined;
|
|
137
|
+
variables?: Record<string, string> | undefined;
|
|
138
|
+
trigger?: "regenerate-message" | "submit-message" | undefined;
|
|
139
|
+
messageId?: string | undefined;
|
|
140
|
+
version?: number | undefined;
|
|
141
|
+
userId?: string | undefined;
|
|
142
|
+
metadata?: Record<string, unknown> | undefined;
|
|
143
|
+
}, z.core.$ZodTypeInternals<{
|
|
144
|
+
message?: unknown;
|
|
145
|
+
promptId?: string | undefined;
|
|
146
|
+
variables?: Record<string, string> | undefined;
|
|
147
|
+
trigger: "regenerate-message" | "submit-message";
|
|
148
|
+
messageId?: string | undefined;
|
|
149
|
+
version?: number | undefined;
|
|
150
|
+
userId: string;
|
|
151
|
+
metadata: Record<string, unknown>;
|
|
152
|
+
} & ExclusivePromptInput<{
|
|
153
|
+
message: null | NonNullable<unknown>;
|
|
154
|
+
}>, {
|
|
155
|
+
message?: unknown;
|
|
156
|
+
promptId?: string | undefined;
|
|
157
|
+
variables?: Record<string, string> | undefined;
|
|
158
|
+
trigger?: "regenerate-message" | "submit-message" | undefined;
|
|
159
|
+
messageId?: string | undefined;
|
|
160
|
+
version?: number | undefined;
|
|
161
|
+
userId?: string | undefined;
|
|
162
|
+
metadata?: Record<string, unknown> | undefined;
|
|
163
|
+
}>>;
|
|
164
|
+
/**
|
|
165
|
+
* The JSON Schema accepted by structured generation. Zod's JSON Schema
|
|
166
|
+
* compiler (`z.fromJSONSchema`) is the single authority for the supported
|
|
167
|
+
* feature set: anything it can convert is accepted, anything it cannot
|
|
168
|
+
* (unresolvable references, unsupported keywords, …) is rejected at this
|
|
169
|
+
* untrusted boundary. The only product restriction on top is the documented
|
|
170
|
+
* "at least a schema root" rule, which keeps the empty match-anything schema
|
|
171
|
+
* out of object mode. Composition roots are needed for schemas derived from
|
|
172
|
+
* unions (for example, Pydantic's `int | None` TypeAdapter schema), and local
|
|
173
|
+
* `$ref` roots are needed for recursive Pydantic models.
|
|
174
|
+
*/
|
|
175
|
+
export declare const jsonSchemaShapeSchema: z.ZodCustom<z.core.JSONSchema.JSONSchema, z.core.JSONSchema.JSONSchema>;
|
|
176
|
+
/**
|
|
177
|
+
* `POST /v1/agents/{agentId}/generation` — the single stateless generation
|
|
178
|
+
* boundary. Output selection is explicit on the wire while prompt selection
|
|
179
|
+
* remains the existing exclusive literal-or-stored-Prompt choice.
|
|
180
|
+
*/
|
|
181
|
+
export declare const generationRequestBodySchema: z.ZodObject<{
|
|
182
|
+
prompt: z.ZodOptional<z.ZodString>;
|
|
183
|
+
promptId: z.ZodOptional<z.ZodString>;
|
|
184
|
+
variables: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
185
|
+
output: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
186
|
+
type: z.ZodLiteral<"text">;
|
|
187
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
188
|
+
type: z.ZodLiteral<"object">;
|
|
189
|
+
schema: z.ZodCustom<z.core.JSONSchema.JSONSchema, z.core.JSONSchema.JSONSchema>;
|
|
190
|
+
}, z.core.$strict>], "type">;
|
|
191
|
+
version: z.ZodOptional<z.ZodNumber>;
|
|
192
|
+
userId: z.ZodDefault<z.ZodString>;
|
|
193
|
+
metadata: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
194
|
+
}, z.core.$strict> & z.ZodType<{
|
|
195
|
+
prompt?: string | undefined;
|
|
196
|
+
promptId?: string | undefined;
|
|
197
|
+
variables?: Record<string, string> | undefined;
|
|
198
|
+
output: {
|
|
199
|
+
type: "text";
|
|
200
|
+
} | {
|
|
201
|
+
type: "object";
|
|
202
|
+
schema: z.core.JSONSchema.JSONSchema;
|
|
203
|
+
};
|
|
204
|
+
version?: number | undefined;
|
|
205
|
+
userId: string;
|
|
206
|
+
metadata: Record<string, unknown>;
|
|
207
|
+
} & ExclusivePromptInput<{
|
|
208
|
+
prompt: string;
|
|
209
|
+
}>, {
|
|
210
|
+
prompt?: string | undefined;
|
|
211
|
+
promptId?: string | undefined;
|
|
212
|
+
variables?: Record<string, string> | undefined;
|
|
213
|
+
output: {
|
|
214
|
+
type: "text";
|
|
215
|
+
} | {
|
|
216
|
+
type: "object";
|
|
217
|
+
schema: z.core.JSONSchema.JSONSchema;
|
|
218
|
+
};
|
|
219
|
+
version?: number | undefined;
|
|
220
|
+
userId?: string | undefined;
|
|
221
|
+
metadata?: Record<string, unknown> | undefined;
|
|
222
|
+
}, z.core.$ZodTypeInternals<{
|
|
223
|
+
prompt?: string | undefined;
|
|
224
|
+
promptId?: string | undefined;
|
|
225
|
+
variables?: Record<string, string> | undefined;
|
|
226
|
+
output: {
|
|
227
|
+
type: "text";
|
|
228
|
+
} | {
|
|
229
|
+
type: "object";
|
|
230
|
+
schema: z.core.JSONSchema.JSONSchema;
|
|
231
|
+
};
|
|
232
|
+
version?: number | undefined;
|
|
233
|
+
userId: string;
|
|
234
|
+
metadata: Record<string, unknown>;
|
|
235
|
+
} & ExclusivePromptInput<{
|
|
236
|
+
prompt: string;
|
|
237
|
+
}>, {
|
|
238
|
+
prompt?: string | undefined;
|
|
239
|
+
promptId?: string | undefined;
|
|
240
|
+
variables?: Record<string, string> | undefined;
|
|
241
|
+
output: {
|
|
242
|
+
type: "text";
|
|
243
|
+
} | {
|
|
244
|
+
type: "object";
|
|
245
|
+
schema: z.core.JSONSchema.JSONSchema;
|
|
246
|
+
};
|
|
247
|
+
version?: number | undefined;
|
|
248
|
+
userId?: string | undefined;
|
|
249
|
+
metadata?: Record<string, unknown> | undefined;
|
|
250
|
+
}>>;
|
|
251
|
+
/**
|
|
252
|
+
* Mid-stream error chunk — the AI SDK native `{ type: 'error', errorText }`
|
|
253
|
+
* shape (docs/adr/0003-ai-sdk-native-wire-protocol.md). `errorText` is a plain string:
|
|
254
|
+
* safe human-readable prose produced by our server-side `onError` mapping —
|
|
255
|
+
* no JSON stuffed in the string, no client-side parsing. `useChat` routes it
|
|
256
|
+
* to `onError`, never into the transcript.
|
|
257
|
+
*/
|
|
258
|
+
export declare const chatStreamErrorChunkSchema: z.ZodObject<{
|
|
259
|
+
type: z.ZodLiteral<"error">;
|
|
260
|
+
errorText: z.ZodString;
|
|
261
|
+
}, z.core.$strict>;
|
|
262
|
+
export type ChatMode = z.infer<typeof chatModeSchema>;
|
|
263
|
+
export type ChatTrigger = z.infer<typeof chatTriggerSchema>;
|
|
264
|
+
export type UsageSummary = z.infer<typeof usageSummarySchema>;
|
|
265
|
+
export type BlazingAgentsChatMessageMetadata = z.infer<typeof blazingAgentsChatMessageMetadataSchema>;
|
|
266
|
+
export type ChatRequestBody = z.infer<typeof chatRequestBodySchema>;
|
|
267
|
+
export type GenerationRequestBody = z.infer<typeof generationRequestBodySchema>;
|
|
268
|
+
export type ChatStreamErrorChunk = z.infer<typeof chatStreamErrorChunkSchema>;
|
|
269
|
+
export type PromptVariables = z.infer<typeof promptVariablesSchema>;
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { agentIdSchema, promptIdSchema, sessionIdSchema, tenantIdSchema, turnIdSchema, } from "../ids.js";
|
|
3
|
+
import { agentModelIdSchema, agentVersionNumberSchema } from "./agents.js";
|
|
4
|
+
import { metadataSchema, userIdSchema } from "./attribution.js";
|
|
5
|
+
export const chatModeSchema = z.enum(["create", "resume"]);
|
|
6
|
+
export const chatTriggerSchema = z.enum([
|
|
7
|
+
"submit-message",
|
|
8
|
+
"regenerate-message",
|
|
9
|
+
]);
|
|
10
|
+
/**
|
|
11
|
+
* Per-Turn usage summary stamped into the assistant message's
|
|
12
|
+
* `metadata.blazingAgents.usage` and persisted by the server. Session Turns
|
|
13
|
+
* carry an `ss_` id; stateless generation uses the empty-string sentinel.
|
|
14
|
+
*/
|
|
15
|
+
export const usageSummarySchema = z
|
|
16
|
+
.object({
|
|
17
|
+
agentId: agentIdSchema,
|
|
18
|
+
agentVersion: agentVersionNumberSchema,
|
|
19
|
+
commitId: z.string().trim().min(1),
|
|
20
|
+
completedAt: z.iso.datetime({ offset: true }),
|
|
21
|
+
durationMs: z.number().int().min(0),
|
|
22
|
+
errorMessage: z.string().nullable(),
|
|
23
|
+
inputTokens: z.number().int().min(0),
|
|
24
|
+
modelDurationMs: z.number().int().min(0),
|
|
25
|
+
metadata: z.record(z.string(), z.unknown()),
|
|
26
|
+
modelId: agentModelIdSchema,
|
|
27
|
+
outputTokens: z.number().int().min(0),
|
|
28
|
+
turnId: turnIdSchema,
|
|
29
|
+
sessionId: z.union([sessionIdSchema, z.literal("")]),
|
|
30
|
+
stepUsages: z.array(z
|
|
31
|
+
.object({
|
|
32
|
+
inputTokens: z.number().int().min(0),
|
|
33
|
+
outputTokens: z.number().int().min(0),
|
|
34
|
+
stepNumber: z.number().int().min(0),
|
|
35
|
+
})
|
|
36
|
+
.strict()),
|
|
37
|
+
startedAt: z.iso.datetime({ offset: true }),
|
|
38
|
+
status: z.enum(["succeeded", "cancelled", "failed"]),
|
|
39
|
+
tenantId: tenantIdSchema,
|
|
40
|
+
userId: z.string(),
|
|
41
|
+
})
|
|
42
|
+
.strict();
|
|
43
|
+
export const blazingAgentsChatMessageMetadataSchema = z
|
|
44
|
+
.object({
|
|
45
|
+
blazingAgents: z.object({ usage: usageSummarySchema }).strict(),
|
|
46
|
+
})
|
|
47
|
+
.strict();
|
|
48
|
+
/**
|
|
49
|
+
* `variables` for the prompt-invocation path — a flat map of string→string.
|
|
50
|
+
* The prompt template's derived variables are the required keys; this is
|
|
51
|
+
* the wire shape only, the route layer enforces strict both-ways matching
|
|
52
|
+
* against the template (missing or unknown variable → 400 invalid_request).
|
|
53
|
+
*/
|
|
54
|
+
export const promptVariablesSchema = z.record(z.string(), z.string());
|
|
55
|
+
/**
|
|
56
|
+
* `POST /v1/agents/{agentId}/sessions` (create) and
|
|
57
|
+
* `POST /v1/agents/{agentId}/sessions/{sessionId}` (resume) request body.
|
|
58
|
+
* The platform mints the `ss_` session id on the create path and returns
|
|
59
|
+
* it via the `Location` header; the URL presence (no id → create, id
|
|
60
|
+
* present → resume) is the mode — there is no `id` or `mode` field here.
|
|
61
|
+
* `message` is the literal input; the prompt-invocation alternative
|
|
62
|
+
* (`promptId` + `variables`) is mutually exclusive with `message` — both
|
|
63
|
+
* present or neither → 400 invalid_request. `variables` is only allowed
|
|
64
|
+
* on the prompt-invocation path: a request carrying both `message` and
|
|
65
|
+
* `variables` (without `promptId`) is a mixed shape and is rejected
|
|
66
|
+
* (strict both ways). The route layer resolves the prompt template,
|
|
67
|
+
* renders, and substitutes a server-constructed user `UIMessage` with a
|
|
68
|
+
* single text part carrying the rendered string. `trigger` /
|
|
69
|
+
* `messageId` are turn-level concerns (regenerate rides on the resume
|
|
70
|
+
* route only — enforced by the route layer, not the schema).
|
|
71
|
+
*/
|
|
72
|
+
export const chatRequestBodySchema = z
|
|
73
|
+
.object({
|
|
74
|
+
/**
|
|
75
|
+
* AI SDK owns the runtime UIMessage schema. Core keeps this wire field
|
|
76
|
+
* unknown; the HTTP boundary validates it with `safeValidateUIMessages`
|
|
77
|
+
* before treating it as a UIMessage.
|
|
78
|
+
*/
|
|
79
|
+
message: z.unknown().optional(),
|
|
80
|
+
promptId: promptIdSchema.optional(),
|
|
81
|
+
variables: promptVariablesSchema.optional(),
|
|
82
|
+
trigger: chatTriggerSchema.default("submit-message"),
|
|
83
|
+
messageId: z.string().min(1).optional(),
|
|
84
|
+
version: agentVersionNumberSchema.optional(),
|
|
85
|
+
/**
|
|
86
|
+
* End-user attribution for the session + this turn's usage
|
|
87
|
+
* (ADR-0001). `userId` is opaque text (`''` = tenant-level); it stamps
|
|
88
|
+
* the session row at lazy materialization (create path) and every
|
|
89
|
+
* `token_usage_*` row this turn records. `metadata` is a mutable jsonb
|
|
90
|
+
* object carried onto the same rows. Both default to tenant-level.
|
|
91
|
+
*/
|
|
92
|
+
userId: userIdSchema.default(""),
|
|
93
|
+
metadata: metadataSchema.default({}),
|
|
94
|
+
})
|
|
95
|
+
.strict()
|
|
96
|
+
.refine((body) => body.message === undefined
|
|
97
|
+
? body.promptId !== undefined
|
|
98
|
+
: body.promptId === undefined && body.variables === undefined, {
|
|
99
|
+
message: "Provide either `message` or `promptId` (+`variables`); they are mutually exclusive, and `variables` is only allowed with `promptId`.",
|
|
100
|
+
path: ["message"],
|
|
101
|
+
});
|
|
102
|
+
const JSON_SCHEMA_COMPOSITION_KEYS = ["allOf", "anyOf", "oneOf"];
|
|
103
|
+
function hasMeaningfulSchemaRoot(value, definitions, seenReferences) {
|
|
104
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
const schema = value;
|
|
108
|
+
if ("type" in schema || "properties" in schema) {
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
const reference = schema.$ref;
|
|
112
|
+
if (typeof reference === "string" && reference.startsWith("#/$defs/")) {
|
|
113
|
+
const name = reference.slice("#/$defs/".length);
|
|
114
|
+
if (!name || seenReferences.has(name) || !(name in definitions)) {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
return hasMeaningfulSchemaRoot(definitions[name], definitions, new Set([...seenReferences, name]));
|
|
118
|
+
}
|
|
119
|
+
return JSON_SCHEMA_COMPOSITION_KEYS.some((keyword) => {
|
|
120
|
+
const branches = schema[keyword];
|
|
121
|
+
return (Array.isArray(branches) &&
|
|
122
|
+
branches.length > 0 &&
|
|
123
|
+
branches.every((branch) => hasMeaningfulSchemaRoot(branch, definitions, seenReferences)));
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* The JSON Schema accepted by structured generation. Zod's JSON Schema
|
|
128
|
+
* compiler (`z.fromJSONSchema`) is the single authority for the supported
|
|
129
|
+
* feature set: anything it can convert is accepted, anything it cannot
|
|
130
|
+
* (unresolvable references, unsupported keywords, …) is rejected at this
|
|
131
|
+
* untrusted boundary. The only product restriction on top is the documented
|
|
132
|
+
* "at least a schema root" rule, which keeps the empty match-anything schema
|
|
133
|
+
* out of object mode. Composition roots are needed for schemas derived from
|
|
134
|
+
* unions (for example, Pydantic's `int | None` TypeAdapter schema), and local
|
|
135
|
+
* `$ref` roots are needed for recursive Pydantic models.
|
|
136
|
+
*/
|
|
137
|
+
export const jsonSchemaShapeSchema = z.custom((value) => {
|
|
138
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
const schema = value;
|
|
142
|
+
const rawDefinitions = schema.$defs;
|
|
143
|
+
const definitions = typeof rawDefinitions === "object" &&
|
|
144
|
+
rawDefinitions !== null &&
|
|
145
|
+
!Array.isArray(rawDefinitions)
|
|
146
|
+
? rawDefinitions
|
|
147
|
+
: {};
|
|
148
|
+
if (!hasMeaningfulSchemaRoot(value, definitions, new Set())) {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
try {
|
|
152
|
+
z.fromJSONSchema(value);
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
catch {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
}, { message: "schema contains an unsupported or invalid JSON Schema feature" });
|
|
159
|
+
/**
|
|
160
|
+
* `POST /v1/agents/{agentId}/generation` — the single stateless generation
|
|
161
|
+
* boundary. Output selection is explicit on the wire while prompt selection
|
|
162
|
+
* remains the existing exclusive literal-or-stored-Prompt choice.
|
|
163
|
+
*/
|
|
164
|
+
export const generationRequestBodySchema = z
|
|
165
|
+
.object({
|
|
166
|
+
prompt: z.string().trim().min(1).optional(),
|
|
167
|
+
promptId: promptIdSchema.optional(),
|
|
168
|
+
variables: promptVariablesSchema.optional(),
|
|
169
|
+
output: z.discriminatedUnion("type", [
|
|
170
|
+
z.object({ type: z.literal("text") }).strict(),
|
|
171
|
+
z
|
|
172
|
+
.object({ type: z.literal("object"), schema: jsonSchemaShapeSchema })
|
|
173
|
+
.strict(),
|
|
174
|
+
]),
|
|
175
|
+
version: agentVersionNumberSchema.optional(),
|
|
176
|
+
userId: userIdSchema.default(""),
|
|
177
|
+
metadata: metadataSchema.default({}),
|
|
178
|
+
})
|
|
179
|
+
.strict()
|
|
180
|
+
.refine((body) => body.prompt === undefined
|
|
181
|
+
? body.promptId !== undefined
|
|
182
|
+
: body.promptId === undefined && body.variables === undefined, {
|
|
183
|
+
message: "Provide either `prompt` or `promptId` (+`variables`); they are mutually exclusive, and `variables` is only allowed with `promptId`.",
|
|
184
|
+
path: ["prompt"],
|
|
185
|
+
});
|
|
186
|
+
/**
|
|
187
|
+
* Mid-stream error chunk — the AI SDK native `{ type: 'error', errorText }`
|
|
188
|
+
* shape (docs/adr/0003-ai-sdk-native-wire-protocol.md). `errorText` is a plain string:
|
|
189
|
+
* safe human-readable prose produced by our server-side `onError` mapping —
|
|
190
|
+
* no JSON stuffed in the string, no client-side parsing. `useChat` routes it
|
|
191
|
+
* to `onError`, never into the transcript.
|
|
192
|
+
*/
|
|
193
|
+
export const chatStreamErrorChunkSchema = z
|
|
194
|
+
.object({
|
|
195
|
+
type: z.literal("error"),
|
|
196
|
+
errorText: z.string(),
|
|
197
|
+
})
|
|
198
|
+
.strict();
|