@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,96 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { promptIdSchema, tenantIdSchema } from "../ids.js";
|
|
3
|
+
import { MAX_PROMPT_NAME_LENGTH, MAX_PROMPT_TEMPLATE_BYTES, MAX_PROMPT_VARIABLES, } from "../limitations.js";
|
|
4
|
+
import { atLeastOneFieldMessage, hasObjectKeys } from "../utils.js";
|
|
5
|
+
import { metadataSchema, userIdSchema } from "./attribution.js";
|
|
6
|
+
export const promptVariableTokenPattern = /{{([\s\S]*?)}}/g;
|
|
7
|
+
export const promptVariableNamePattern = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
8
|
+
const promptNameSchema = z.string().trim().min(1).max(MAX_PROMPT_NAME_LENGTH);
|
|
9
|
+
export function parsePromptVariables(template) {
|
|
10
|
+
const invalidVariableNames = [];
|
|
11
|
+
const seenVariables = new Set();
|
|
12
|
+
const variables = [];
|
|
13
|
+
for (const match of template.matchAll(promptVariableTokenPattern)) {
|
|
14
|
+
const variableName = match[1].trim();
|
|
15
|
+
if (!promptVariableNamePattern.test(variableName)) {
|
|
16
|
+
invalidVariableNames.push(variableName);
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
if (!seenVariables.has(variableName)) {
|
|
20
|
+
seenVariables.add(variableName);
|
|
21
|
+
variables.push(variableName);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return { invalidVariableNames, variables };
|
|
25
|
+
}
|
|
26
|
+
export const promptTemplateSchema = z
|
|
27
|
+
.string()
|
|
28
|
+
.trim()
|
|
29
|
+
.min(1, { message: "Prompt template is required." })
|
|
30
|
+
.max(MAX_PROMPT_TEMPLATE_BYTES, {
|
|
31
|
+
message: `Prompt template must be at most ${MAX_PROMPT_TEMPLATE_BYTES} bytes.`,
|
|
32
|
+
})
|
|
33
|
+
.superRefine((template, ctx) => {
|
|
34
|
+
const { invalidVariableNames, variables } = parsePromptVariables(template);
|
|
35
|
+
if (invalidVariableNames.length > 0) {
|
|
36
|
+
ctx.addIssue({
|
|
37
|
+
code: "custom",
|
|
38
|
+
message: "Prompt variables must match [A-Za-z_][A-Za-z0-9_]*.",
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
if (variables.length > MAX_PROMPT_VARIABLES) {
|
|
42
|
+
ctx.addIssue({
|
|
43
|
+
code: "custom",
|
|
44
|
+
message: `Prompts can include at most ${MAX_PROMPT_VARIABLES} variables.`,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
export const promptSchema = z
|
|
49
|
+
.object({
|
|
50
|
+
id: promptIdSchema,
|
|
51
|
+
tenantId: tenantIdSchema,
|
|
52
|
+
name: promptNameSchema,
|
|
53
|
+
template: promptTemplateSchema,
|
|
54
|
+
variables: z.array(z.string().min(1)),
|
|
55
|
+
userId: userIdSchema,
|
|
56
|
+
metadata: metadataSchema,
|
|
57
|
+
createdAt: z.iso.datetime({ offset: true }),
|
|
58
|
+
updatedAt: z.iso.datetime({ offset: true }),
|
|
59
|
+
})
|
|
60
|
+
.strict();
|
|
61
|
+
export const promptsResponseSchema = z
|
|
62
|
+
.object({
|
|
63
|
+
prompts: z.array(promptSchema),
|
|
64
|
+
})
|
|
65
|
+
.strict();
|
|
66
|
+
export const promptResponseSchema = promptSchema;
|
|
67
|
+
export const createPromptBodySchema = z
|
|
68
|
+
.object({
|
|
69
|
+
name: promptNameSchema,
|
|
70
|
+
template: promptTemplateSchema,
|
|
71
|
+
userId: userIdSchema.default(""),
|
|
72
|
+
metadata: metadataSchema.default({}),
|
|
73
|
+
})
|
|
74
|
+
.strict();
|
|
75
|
+
export const updatePromptBodySchema = z
|
|
76
|
+
.object({
|
|
77
|
+
name: promptNameSchema.optional(),
|
|
78
|
+
template: promptTemplateSchema.optional(),
|
|
79
|
+
metadata: metadataSchema.optional(),
|
|
80
|
+
})
|
|
81
|
+
.strict()
|
|
82
|
+
.refine(hasObjectKeys, {
|
|
83
|
+
message: atLeastOneFieldMessage,
|
|
84
|
+
});
|
|
85
|
+
export function renderPromptTemplate(template, values) {
|
|
86
|
+
return promptTemplateSchema
|
|
87
|
+
.parse(template)
|
|
88
|
+
.replace(promptVariableTokenPattern, (_token, rawVariableName) => {
|
|
89
|
+
const variableName = rawVariableName.trim();
|
|
90
|
+
const value = values[variableName];
|
|
91
|
+
if (typeof value !== "string") {
|
|
92
|
+
throw new Error(`Missing prompt variable value: ${variableName}`);
|
|
93
|
+
}
|
|
94
|
+
return value;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Provider type — the enum of model providers we support. Selects catalog
|
|
4
|
+
* discovery and AI SDK model behavior.
|
|
5
|
+
* (docs/adr/0039-explicit-provider-model-pairs.md)
|
|
6
|
+
*/
|
|
7
|
+
export declare const providerTypeSchema: z.ZodEnum<{
|
|
8
|
+
anthropic: "anthropic";
|
|
9
|
+
custom: "custom";
|
|
10
|
+
google: "google";
|
|
11
|
+
openai: "openai";
|
|
12
|
+
openrouter: "openrouter";
|
|
13
|
+
vercel_ai_gateway: "vercel_ai_gateway";
|
|
14
|
+
}>;
|
|
15
|
+
export type ProviderType = z.infer<typeof providerTypeSchema>;
|
|
16
|
+
/**
|
|
17
|
+
* Stored row — the full persisted record, including the Vault pointer and
|
|
18
|
+
* tenant id. Used internally by services; never sent on the wire.
|
|
19
|
+
*/
|
|
20
|
+
export declare const providerSchema: z.ZodObject<{
|
|
21
|
+
id: z.ZodString;
|
|
22
|
+
tenantId: z.ZodString;
|
|
23
|
+
name: z.ZodString;
|
|
24
|
+
providerType: z.ZodEnum<{
|
|
25
|
+
anthropic: "anthropic";
|
|
26
|
+
custom: "custom";
|
|
27
|
+
google: "google";
|
|
28
|
+
openai: "openai";
|
|
29
|
+
openrouter: "openrouter";
|
|
30
|
+
vercel_ai_gateway: "vercel_ai_gateway";
|
|
31
|
+
}>;
|
|
32
|
+
baseUrl: z.ZodNullable<z.ZodString>;
|
|
33
|
+
keyFragment: z.ZodString;
|
|
34
|
+
vaultSecretId: z.ZodString;
|
|
35
|
+
createdAt: z.ZodISODateTime;
|
|
36
|
+
updatedAt: z.ZodISODateTime;
|
|
37
|
+
}, z.core.$strict>;
|
|
38
|
+
/**
|
|
39
|
+
* Wire response — `GET /v1/providers` and `GET /v1/providers/{id}` shape per
|
|
40
|
+
* ticket 12: `{ id, name, providerType, baseUrl, keyFragment, createdAt,
|
|
41
|
+
* updatedAt }`. The Vault pointer and tenant id are write-only/internal.
|
|
42
|
+
*/
|
|
43
|
+
export declare const providerResponseSchema: z.ZodObject<{
|
|
44
|
+
id: z.ZodString;
|
|
45
|
+
name: z.ZodString;
|
|
46
|
+
providerType: z.ZodEnum<{
|
|
47
|
+
anthropic: "anthropic";
|
|
48
|
+
custom: "custom";
|
|
49
|
+
google: "google";
|
|
50
|
+
openai: "openai";
|
|
51
|
+
openrouter: "openrouter";
|
|
52
|
+
vercel_ai_gateway: "vercel_ai_gateway";
|
|
53
|
+
}>;
|
|
54
|
+
baseUrl: z.ZodNullable<z.ZodString>;
|
|
55
|
+
keyFragment: z.ZodString;
|
|
56
|
+
createdAt: z.ZodISODateTime;
|
|
57
|
+
updatedAt: z.ZodISODateTime;
|
|
58
|
+
}, z.core.$strict>;
|
|
59
|
+
export declare const providersResponseSchema: z.ZodObject<{
|
|
60
|
+
providers: z.ZodArray<z.ZodObject<{
|
|
61
|
+
id: z.ZodString;
|
|
62
|
+
name: z.ZodString;
|
|
63
|
+
providerType: z.ZodEnum<{
|
|
64
|
+
anthropic: "anthropic";
|
|
65
|
+
custom: "custom";
|
|
66
|
+
google: "google";
|
|
67
|
+
openai: "openai";
|
|
68
|
+
openrouter: "openrouter";
|
|
69
|
+
vercel_ai_gateway: "vercel_ai_gateway";
|
|
70
|
+
}>;
|
|
71
|
+
baseUrl: z.ZodNullable<z.ZodString>;
|
|
72
|
+
keyFragment: z.ZodString;
|
|
73
|
+
createdAt: z.ZodISODateTime;
|
|
74
|
+
updatedAt: z.ZodISODateTime;
|
|
75
|
+
}, z.core.$strict>>;
|
|
76
|
+
}, z.core.$strict>;
|
|
77
|
+
export declare const providerModelsResponseSchema: z.ZodObject<{
|
|
78
|
+
models: z.ZodArray<z.ZodObject<{
|
|
79
|
+
id: z.ZodString;
|
|
80
|
+
}, z.core.$strict>>;
|
|
81
|
+
}, z.core.$strict>;
|
|
82
|
+
export declare const providerHistoricalUseDetailsSchema: z.ZodObject<{
|
|
83
|
+
agentVersions: z.ZodArray<z.ZodObject<{
|
|
84
|
+
agentId: z.ZodString;
|
|
85
|
+
version: z.ZodNumber;
|
|
86
|
+
}, z.core.$strict>>;
|
|
87
|
+
sessionIds: z.ZodArray<z.ZodString>;
|
|
88
|
+
taskIds: z.ZodArray<z.ZodString>;
|
|
89
|
+
}, z.core.$strict>;
|
|
90
|
+
/**
|
|
91
|
+
* `POST /v1/providers` — name, type, optional base URL, and the API key
|
|
92
|
+
* (plaintext, never stored — goes to Vault). `custom` providers require a
|
|
93
|
+
* non-empty baseUrl. Vercel AI Gateway accepts no base URL because it always
|
|
94
|
+
* uses the first-party Gateway endpoint.
|
|
95
|
+
*/
|
|
96
|
+
export declare const createProviderBodySchema: z.ZodObject<{
|
|
97
|
+
name: z.ZodString;
|
|
98
|
+
providerType: z.ZodEnum<{
|
|
99
|
+
anthropic: "anthropic";
|
|
100
|
+
custom: "custom";
|
|
101
|
+
google: "google";
|
|
102
|
+
openai: "openai";
|
|
103
|
+
openrouter: "openrouter";
|
|
104
|
+
vercel_ai_gateway: "vercel_ai_gateway";
|
|
105
|
+
}>;
|
|
106
|
+
baseUrl: z.ZodDefault<z.ZodNullable<z.ZodUnion<[z.ZodString, z.ZodLiteral<"">]>>>;
|
|
107
|
+
apiKey: z.ZodString;
|
|
108
|
+
}, z.core.$strict>;
|
|
109
|
+
/** `PATCH /v1/providers/{id}` — only the display name is mutable. */
|
|
110
|
+
export declare const updateProviderBodySchema: z.ZodObject<{
|
|
111
|
+
name: z.ZodString;
|
|
112
|
+
}, z.core.$strict>;
|
|
113
|
+
export type Provider = z.infer<typeof providerSchema>;
|
|
114
|
+
export type ProvidersResponse = z.infer<typeof providersResponseSchema>;
|
|
115
|
+
export type ProviderModelsResponse = z.infer<typeof providerModelsResponseSchema>;
|
|
116
|
+
export type ProviderModel = ProviderModelsResponse["models"][number];
|
|
117
|
+
export type ProviderHistoricalUseDetails = z.infer<typeof providerHistoricalUseDetailsSchema>;
|
|
118
|
+
export interface DeleteProviderOptions {
|
|
119
|
+
confirmVersionInvalidation?: boolean;
|
|
120
|
+
}
|
|
121
|
+
export type ProviderResponse = z.infer<typeof providerResponseSchema>;
|
|
122
|
+
export type CreateProviderBody = z.infer<typeof createProviderBodySchema>;
|
|
123
|
+
export type UpdateProviderBody = z.infer<typeof updateProviderBodySchema>;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { agentIdSchema, providerIdSchema, providerKeyFragmentSchema, sessionIdSchema, taskIdSchema, tenantIdSchema, } from "../ids.js";
|
|
3
|
+
import { MAX_PROVIDER_NAME_LENGTH } from "../limitations.js";
|
|
4
|
+
import { agentVersionNumberSchema } from "./agents.js";
|
|
5
|
+
/**
|
|
6
|
+
* Provider type — the enum of model providers we support. Selects catalog
|
|
7
|
+
* discovery and AI SDK model behavior.
|
|
8
|
+
* (docs/adr/0039-explicit-provider-model-pairs.md)
|
|
9
|
+
*/
|
|
10
|
+
export const providerTypeSchema = z.enum([
|
|
11
|
+
"openai",
|
|
12
|
+
"anthropic",
|
|
13
|
+
"openrouter",
|
|
14
|
+
"google",
|
|
15
|
+
"vercel_ai_gateway",
|
|
16
|
+
"custom",
|
|
17
|
+
]);
|
|
18
|
+
const providerNameSchema = z
|
|
19
|
+
.string()
|
|
20
|
+
.trim()
|
|
21
|
+
.min(1)
|
|
22
|
+
.max(MAX_PROVIDER_NAME_LENGTH);
|
|
23
|
+
const providerBaseUrlSchema = z.string().trim().min(1).url().or(z.literal(""));
|
|
24
|
+
/**
|
|
25
|
+
* Stored row — the full persisted record, including the Vault pointer and
|
|
26
|
+
* tenant id. Used internally by services; never sent on the wire.
|
|
27
|
+
*/
|
|
28
|
+
export const providerSchema = z
|
|
29
|
+
.object({
|
|
30
|
+
id: providerIdSchema,
|
|
31
|
+
tenantId: tenantIdSchema,
|
|
32
|
+
name: providerNameSchema,
|
|
33
|
+
providerType: providerTypeSchema,
|
|
34
|
+
baseUrl: z.string().nullable(),
|
|
35
|
+
keyFragment: providerKeyFragmentSchema,
|
|
36
|
+
vaultSecretId: z.string().min(1),
|
|
37
|
+
createdAt: z.iso.datetime({ offset: true }),
|
|
38
|
+
updatedAt: z.iso.datetime({ offset: true }),
|
|
39
|
+
})
|
|
40
|
+
.strict();
|
|
41
|
+
/**
|
|
42
|
+
* Wire response — `GET /v1/providers` and `GET /v1/providers/{id}` shape per
|
|
43
|
+
* ticket 12: `{ id, name, providerType, baseUrl, keyFragment, createdAt,
|
|
44
|
+
* updatedAt }`. The Vault pointer and tenant id are write-only/internal.
|
|
45
|
+
*/
|
|
46
|
+
export const providerResponseSchema = z
|
|
47
|
+
.object({
|
|
48
|
+
id: providerIdSchema,
|
|
49
|
+
name: providerNameSchema,
|
|
50
|
+
providerType: providerTypeSchema,
|
|
51
|
+
baseUrl: z.string().nullable(),
|
|
52
|
+
keyFragment: providerKeyFragmentSchema,
|
|
53
|
+
createdAt: z.iso.datetime({ offset: true }),
|
|
54
|
+
updatedAt: z.iso.datetime({ offset: true }),
|
|
55
|
+
})
|
|
56
|
+
.strict();
|
|
57
|
+
export const providersResponseSchema = z
|
|
58
|
+
.object({
|
|
59
|
+
providers: z.array(providerResponseSchema),
|
|
60
|
+
})
|
|
61
|
+
.strict();
|
|
62
|
+
export const providerModelsResponseSchema = z
|
|
63
|
+
.object({
|
|
64
|
+
models: z.array(z
|
|
65
|
+
.object({
|
|
66
|
+
id: z.string().trim().min(1),
|
|
67
|
+
})
|
|
68
|
+
.strict()),
|
|
69
|
+
})
|
|
70
|
+
.strict();
|
|
71
|
+
export const providerHistoricalUseDetailsSchema = z
|
|
72
|
+
.object({
|
|
73
|
+
agentVersions: z.array(z
|
|
74
|
+
.object({
|
|
75
|
+
agentId: agentIdSchema,
|
|
76
|
+
version: agentVersionNumberSchema,
|
|
77
|
+
})
|
|
78
|
+
.strict()),
|
|
79
|
+
sessionIds: z.array(sessionIdSchema),
|
|
80
|
+
taskIds: z.array(taskIdSchema),
|
|
81
|
+
})
|
|
82
|
+
.strict();
|
|
83
|
+
/**
|
|
84
|
+
* `POST /v1/providers` — name, type, optional base URL, and the API key
|
|
85
|
+
* (plaintext, never stored — goes to Vault). `custom` providers require a
|
|
86
|
+
* non-empty baseUrl. Vercel AI Gateway accepts no base URL because it always
|
|
87
|
+
* uses the first-party Gateway endpoint.
|
|
88
|
+
*/
|
|
89
|
+
export const createProviderBodySchema = z
|
|
90
|
+
.object({
|
|
91
|
+
name: providerNameSchema,
|
|
92
|
+
providerType: providerTypeSchema,
|
|
93
|
+
baseUrl: providerBaseUrlSchema.nullable().default(null),
|
|
94
|
+
apiKey: z.string().trim().min(1),
|
|
95
|
+
})
|
|
96
|
+
.strict()
|
|
97
|
+
.refine((body) => body.providerType !== "custom" ||
|
|
98
|
+
(body.baseUrl !== null && body.baseUrl.length > 0), {
|
|
99
|
+
message: "baseUrl is required for custom providers",
|
|
100
|
+
path: ["baseUrl"],
|
|
101
|
+
})
|
|
102
|
+
.refine((body) => body.providerType !== "vercel_ai_gateway" || body.baseUrl === null, {
|
|
103
|
+
message: "baseUrl is not accepted for Vercel AI Gateway providers",
|
|
104
|
+
path: ["baseUrl"],
|
|
105
|
+
});
|
|
106
|
+
/** `PATCH /v1/providers/{id}` — only the display name is mutable. */
|
|
107
|
+
export const updateProviderBodySchema = z
|
|
108
|
+
.object({
|
|
109
|
+
name: providerNameSchema,
|
|
110
|
+
})
|
|
111
|
+
.strict();
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* `GET /v1/agents/{agentId}/sessions` list item — the public wire shape:
|
|
4
|
+
* `{ id, agentVersion, createdAt, updatedAt, messageCount,
|
|
5
|
+
* lastMessagePreview, userId, metadata }`. `agentId`/`tenantId` are internal
|
|
6
|
+
* (used for filtering) and never leak to the wire. `userId`/`metadata` are
|
|
7
|
+
* stamped at lazy materialization (the first successful turn's attribution).
|
|
8
|
+
*/
|
|
9
|
+
export declare const sessionListItemSchema: z.ZodObject<{
|
|
10
|
+
agentVersion: z.ZodNullable<z.ZodNumber>;
|
|
11
|
+
id: z.ZodString;
|
|
12
|
+
messageCount: z.ZodNumber;
|
|
13
|
+
lastMessagePreview: z.ZodNullable<z.ZodString>;
|
|
14
|
+
userId: z.ZodString;
|
|
15
|
+
metadata: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
16
|
+
createdAt: z.ZodISODateTime;
|
|
17
|
+
updatedAt: z.ZodISODateTime;
|
|
18
|
+
}, z.core.$strict>;
|
|
19
|
+
export declare const sessionsListResponseSchema: z.ZodObject<{
|
|
20
|
+
data: z.ZodArray<z.ZodObject<{
|
|
21
|
+
agentVersion: z.ZodNullable<z.ZodNumber>;
|
|
22
|
+
id: z.ZodString;
|
|
23
|
+
messageCount: z.ZodNumber;
|
|
24
|
+
lastMessagePreview: z.ZodNullable<z.ZodString>;
|
|
25
|
+
userId: z.ZodString;
|
|
26
|
+
metadata: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
27
|
+
createdAt: z.ZodISODateTime;
|
|
28
|
+
updatedAt: z.ZodISODateTime;
|
|
29
|
+
}, z.core.$strict>>;
|
|
30
|
+
nextCursor: z.ZodNullable<z.ZodString>;
|
|
31
|
+
}, z.core.$strict>;
|
|
32
|
+
/**
|
|
33
|
+
* `GET /v1/agents/{agentId}/sessions/{sessionId}/messages` — transcript as
|
|
34
|
+
* `UIMessage[]` verbatim, paginated backwards (newest page first) with an
|
|
35
|
+
* optional forward `?after={cursor}` for the poll loop.
|
|
36
|
+
*/
|
|
37
|
+
export declare const sessionMessageSchema: z.ZodObject<{
|
|
38
|
+
id: z.ZodString;
|
|
39
|
+
role: z.ZodEnum<{
|
|
40
|
+
assistant: "assistant";
|
|
41
|
+
system: "system";
|
|
42
|
+
user: "user";
|
|
43
|
+
}>;
|
|
44
|
+
parts: z.ZodArray<z.ZodObject<{
|
|
45
|
+
type: z.ZodString;
|
|
46
|
+
}, z.core.$loose>>;
|
|
47
|
+
metadata: z.ZodOptional<z.ZodUnknown>;
|
|
48
|
+
}, z.core.$loose>;
|
|
49
|
+
/**
|
|
50
|
+
* The messages endpoint carries two cursors: `nextCursor` for continuing
|
|
51
|
+
* pagination in the requested direction (backward `?cursor=` walks older
|
|
52
|
+
* pages; forward `?after=` walks the next forward page), and `latestCursor`
|
|
53
|
+
* — the tail position (the seq of the newest message in the page) for the
|
|
54
|
+
* cron/task poll loop to pass back as `?after=`. `latestCursor` is always
|
|
55
|
+
* present when `data` is non-empty, even on the last page, so the poll loop
|
|
56
|
+
* has a cursor to watch a transcript grow.
|
|
57
|
+
*/
|
|
58
|
+
export declare const sessionMessagesResponseSchema: z.ZodObject<{
|
|
59
|
+
data: z.ZodArray<z.ZodObject<{
|
|
60
|
+
id: z.ZodString;
|
|
61
|
+
role: z.ZodEnum<{
|
|
62
|
+
assistant: "assistant";
|
|
63
|
+
system: "system";
|
|
64
|
+
user: "user";
|
|
65
|
+
}>;
|
|
66
|
+
parts: z.ZodArray<z.ZodObject<{
|
|
67
|
+
type: z.ZodString;
|
|
68
|
+
}, z.core.$loose>>;
|
|
69
|
+
metadata: z.ZodOptional<z.ZodUnknown>;
|
|
70
|
+
}, z.core.$loose>>;
|
|
71
|
+
nextCursor: z.ZodNullable<z.ZodString>;
|
|
72
|
+
latestCursor: z.ZodNullable<z.ZodString>;
|
|
73
|
+
}, z.core.$strict>;
|
|
74
|
+
export declare const sessionMessagesQuerySchema: z.ZodObject<{
|
|
75
|
+
limit: z.ZodDefault<z.ZodNumber>;
|
|
76
|
+
cursor: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
77
|
+
after: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
78
|
+
}, z.core.$strict>;
|
|
79
|
+
/** Decision-only input for one server-owned Tool approval. */
|
|
80
|
+
export declare const decideToolApprovalBodySchema: z.ZodObject<{
|
|
81
|
+
approved: z.ZodBoolean;
|
|
82
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
83
|
+
}, z.core.$strict>;
|
|
84
|
+
export declare const toolApprovalContinuationStateSchema: z.ZodEnum<{
|
|
85
|
+
failed: "failed";
|
|
86
|
+
queued: "queued";
|
|
87
|
+
running: "running";
|
|
88
|
+
succeeded: "succeeded";
|
|
89
|
+
waiting: "waiting";
|
|
90
|
+
}>;
|
|
91
|
+
export declare const toolApprovalStateSchema: z.ZodObject<{
|
|
92
|
+
approvalId: z.ZodString;
|
|
93
|
+
decision: z.ZodEnum<{
|
|
94
|
+
approved: "approved";
|
|
95
|
+
denied: "denied";
|
|
96
|
+
pending: "pending";
|
|
97
|
+
}>;
|
|
98
|
+
input: z.ZodJSONSchema;
|
|
99
|
+
reason: z.ZodNullable<z.ZodString>;
|
|
100
|
+
toolCallId: z.ZodString;
|
|
101
|
+
toolName: z.ZodString;
|
|
102
|
+
}, z.core.$strict>;
|
|
103
|
+
export declare const toolApprovalContinuationSchema: z.ZodObject<{
|
|
104
|
+
id: z.ZodString;
|
|
105
|
+
state: z.ZodEnum<{
|
|
106
|
+
failed: "failed";
|
|
107
|
+
queued: "queued";
|
|
108
|
+
running: "running";
|
|
109
|
+
succeeded: "succeeded";
|
|
110
|
+
waiting: "waiting";
|
|
111
|
+
}>;
|
|
112
|
+
}, z.core.$strict>;
|
|
113
|
+
export declare const toolApprovalsResponseSchema: z.ZodObject<{
|
|
114
|
+
data: z.ZodArray<z.ZodObject<{
|
|
115
|
+
approvalId: z.ZodString;
|
|
116
|
+
decision: z.ZodEnum<{
|
|
117
|
+
approved: "approved";
|
|
118
|
+
denied: "denied";
|
|
119
|
+
pending: "pending";
|
|
120
|
+
}>;
|
|
121
|
+
input: z.ZodJSONSchema;
|
|
122
|
+
reason: z.ZodNullable<z.ZodString>;
|
|
123
|
+
toolCallId: z.ZodString;
|
|
124
|
+
toolName: z.ZodString;
|
|
125
|
+
}, z.core.$strict>>;
|
|
126
|
+
continuation: z.ZodNullable<z.ZodObject<{
|
|
127
|
+
id: z.ZodString;
|
|
128
|
+
state: z.ZodEnum<{
|
|
129
|
+
failed: "failed";
|
|
130
|
+
queued: "queued";
|
|
131
|
+
running: "running";
|
|
132
|
+
succeeded: "succeeded";
|
|
133
|
+
waiting: "waiting";
|
|
134
|
+
}>;
|
|
135
|
+
}, z.core.$strict>>;
|
|
136
|
+
}, z.core.$strict>;
|
|
137
|
+
export declare const toolApprovalDecisionResponseSchema: z.ZodObject<{
|
|
138
|
+
continuationId: z.ZodString;
|
|
139
|
+
state: z.ZodEnum<{
|
|
140
|
+
failed: "failed";
|
|
141
|
+
queued: "queued";
|
|
142
|
+
running: "running";
|
|
143
|
+
succeeded: "succeeded";
|
|
144
|
+
waiting: "waiting";
|
|
145
|
+
}>;
|
|
146
|
+
}, z.core.$strict>;
|
|
147
|
+
export type SessionListItem = z.infer<typeof sessionListItemSchema>;
|
|
148
|
+
export type SessionsListResponse = z.infer<typeof sessionsListResponseSchema>;
|
|
149
|
+
export type SessionMessage = z.infer<typeof sessionMessageSchema>;
|
|
150
|
+
export type SessionMessagesResponse = z.infer<typeof sessionMessagesResponseSchema>;
|
|
151
|
+
export type SessionMessagesQuery = z.infer<typeof sessionMessagesQuerySchema>;
|
|
152
|
+
export type DecideToolApprovalBody = z.infer<typeof decideToolApprovalBodySchema>;
|
|
153
|
+
export type ToolApprovalContinuationState = z.infer<typeof toolApprovalContinuationStateSchema>;
|
|
154
|
+
export type ToolApprovalState = z.infer<typeof toolApprovalStateSchema>;
|
|
155
|
+
export type ToolApprovalsResponse = z.infer<typeof toolApprovalsResponseSchema>;
|
|
156
|
+
export type ToolApprovalDecisionResponse = z.infer<typeof toolApprovalDecisionResponseSchema>;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { paginatedResponseSchema } from "../api.js";
|
|
3
|
+
import { sessionIdSchema } from "../ids.js";
|
|
4
|
+
import { DEFAULT_SESSION_MESSAGES_LIMIT, MAX_SESSION_MESSAGES_LIMIT, } from "../limitations.js";
|
|
5
|
+
import { agentVersionNumberSchema } from "./agents.js";
|
|
6
|
+
import { metadataSchema, userIdSchema } from "./attribution.js";
|
|
7
|
+
/**
|
|
8
|
+
* `GET /v1/agents/{agentId}/sessions` list item — the public wire shape:
|
|
9
|
+
* `{ id, agentVersion, createdAt, updatedAt, messageCount,
|
|
10
|
+
* lastMessagePreview, userId, metadata }`. `agentId`/`tenantId` are internal
|
|
11
|
+
* (used for filtering) and never leak to the wire. `userId`/`metadata` are
|
|
12
|
+
* stamped at lazy materialization (the first successful turn's attribution).
|
|
13
|
+
*/
|
|
14
|
+
export const sessionListItemSchema = z
|
|
15
|
+
.object({
|
|
16
|
+
agentVersion: agentVersionNumberSchema.nullable(),
|
|
17
|
+
id: sessionIdSchema,
|
|
18
|
+
messageCount: z.number().int().nonnegative(),
|
|
19
|
+
lastMessagePreview: z.string().nullable(),
|
|
20
|
+
userId: userIdSchema,
|
|
21
|
+
metadata: metadataSchema,
|
|
22
|
+
createdAt: z.iso.datetime({ offset: true }),
|
|
23
|
+
updatedAt: z.iso.datetime({ offset: true }),
|
|
24
|
+
})
|
|
25
|
+
.strict();
|
|
26
|
+
export const sessionsListResponseSchema = paginatedResponseSchema(sessionListItemSchema);
|
|
27
|
+
/**
|
|
28
|
+
* `GET /v1/agents/{agentId}/sessions/{sessionId}/messages` — transcript as
|
|
29
|
+
* `UIMessage[]` verbatim, paginated backwards (newest page first) with an
|
|
30
|
+
* optional forward `?after={cursor}` for the poll loop.
|
|
31
|
+
*/
|
|
32
|
+
export const sessionMessageSchema = z
|
|
33
|
+
.object({
|
|
34
|
+
id: z.string().min(1),
|
|
35
|
+
role: z.enum(["system", "user", "assistant"]),
|
|
36
|
+
parts: z
|
|
37
|
+
.array(z
|
|
38
|
+
.object({
|
|
39
|
+
type: z.string().min(1),
|
|
40
|
+
})
|
|
41
|
+
.passthrough())
|
|
42
|
+
.min(1),
|
|
43
|
+
metadata: z.unknown().optional(),
|
|
44
|
+
})
|
|
45
|
+
.passthrough();
|
|
46
|
+
/**
|
|
47
|
+
* The messages endpoint carries two cursors: `nextCursor` for continuing
|
|
48
|
+
* pagination in the requested direction (backward `?cursor=` walks older
|
|
49
|
+
* pages; forward `?after=` walks the next forward page), and `latestCursor`
|
|
50
|
+
* — the tail position (the seq of the newest message in the page) for the
|
|
51
|
+
* cron/task poll loop to pass back as `?after=`. `latestCursor` is always
|
|
52
|
+
* present when `data` is non-empty, even on the last page, so the poll loop
|
|
53
|
+
* has a cursor to watch a transcript grow.
|
|
54
|
+
*/
|
|
55
|
+
export const sessionMessagesResponseSchema = z
|
|
56
|
+
.object({
|
|
57
|
+
data: z.array(sessionMessageSchema),
|
|
58
|
+
nextCursor: z.string().nullable(),
|
|
59
|
+
latestCursor: z.string().nullable(),
|
|
60
|
+
})
|
|
61
|
+
.strict();
|
|
62
|
+
// Query params for the messages endpoint.
|
|
63
|
+
export const sessionMessagesQuerySchema = z
|
|
64
|
+
.object({
|
|
65
|
+
limit: z
|
|
66
|
+
.number()
|
|
67
|
+
.int()
|
|
68
|
+
.min(1)
|
|
69
|
+
.max(MAX_SESSION_MESSAGES_LIMIT)
|
|
70
|
+
.default(DEFAULT_SESSION_MESSAGES_LIMIT),
|
|
71
|
+
cursor: z.string().nullable().optional(),
|
|
72
|
+
after: z.string().nullable().optional(),
|
|
73
|
+
})
|
|
74
|
+
.strict()
|
|
75
|
+
.refine((value) => !(value.cursor && value.after), {
|
|
76
|
+
message: "cursor and after are mutually exclusive.",
|
|
77
|
+
path: ["after"],
|
|
78
|
+
});
|
|
79
|
+
/** Decision-only input for one server-owned Tool approval. */
|
|
80
|
+
export const decideToolApprovalBodySchema = z
|
|
81
|
+
.object({
|
|
82
|
+
approved: z.boolean(),
|
|
83
|
+
reason: z.string().trim().min(1).max(1000).optional(),
|
|
84
|
+
})
|
|
85
|
+
.strict();
|
|
86
|
+
export const toolApprovalContinuationStateSchema = z.enum([
|
|
87
|
+
"waiting",
|
|
88
|
+
"queued",
|
|
89
|
+
"running",
|
|
90
|
+
"succeeded",
|
|
91
|
+
"failed",
|
|
92
|
+
]);
|
|
93
|
+
export const toolApprovalStateSchema = z
|
|
94
|
+
.object({
|
|
95
|
+
approvalId: z.string().min(1),
|
|
96
|
+
decision: z.enum(["pending", "approved", "denied"]),
|
|
97
|
+
input: z.json(),
|
|
98
|
+
reason: z.string().nullable(),
|
|
99
|
+
toolCallId: z.string().min(1),
|
|
100
|
+
toolName: z.string().min(1),
|
|
101
|
+
})
|
|
102
|
+
.strict();
|
|
103
|
+
export const toolApprovalContinuationSchema = z
|
|
104
|
+
.object({
|
|
105
|
+
id: z.string().min(1),
|
|
106
|
+
state: toolApprovalContinuationStateSchema,
|
|
107
|
+
})
|
|
108
|
+
.strict();
|
|
109
|
+
export const toolApprovalsResponseSchema = z
|
|
110
|
+
.object({
|
|
111
|
+
data: z.array(toolApprovalStateSchema),
|
|
112
|
+
continuation: toolApprovalContinuationSchema.nullable(),
|
|
113
|
+
})
|
|
114
|
+
.strict();
|
|
115
|
+
export const toolApprovalDecisionResponseSchema = z
|
|
116
|
+
.object({
|
|
117
|
+
continuationId: z.string().min(1),
|
|
118
|
+
state: toolApprovalContinuationStateSchema,
|
|
119
|
+
})
|
|
120
|
+
.strict();
|