@blazingagents/sdk 0.34.0 → 0.36.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.
Files changed (74) hide show
  1. package/dist/chat-transport.js +4 -1
  2. package/dist/client.d.ts +18 -2
  3. package/dist/client.js +16 -15
  4. package/dist/contracts/entities/agents.d.ts +7 -6
  5. package/dist/contracts/entities/agents.js +129 -36
  6. package/dist/contracts/entities/chat-connections.d.ts +9 -8
  7. package/dist/contracts/entities/chat-connections.js +70 -40
  8. package/dist/contracts/entities/chat.d.ts +8 -4
  9. package/dist/contracts/entities/chat.js +102 -28
  10. package/dist/contracts/entities/mcp-connections.d.ts +2 -0
  11. package/dist/contracts/entities/mcp-connections.js +36 -23
  12. package/dist/contracts/entities/memories.d.ts +1 -0
  13. package/dist/contracts/entities/memories.js +5 -3
  14. package/dist/contracts/entities/merchant.js +28 -9
  15. package/dist/contracts/entities/prompts.d.ts +2 -2
  16. package/dist/contracts/entities/prompts.js +42 -15
  17. package/dist/contracts/entities/providers.js +14 -6
  18. package/dist/contracts/entities/sessions.d.ts +10 -4
  19. package/dist/contracts/entities/sessions.js +5 -4
  20. package/dist/contracts/entities/skills.js +6 -3
  21. package/dist/contracts/entities/tasks.d.ts +4 -7
  22. package/dist/contracts/entities/tasks.js +45 -15
  23. package/dist/contracts/entities/tenants.d.ts +2 -28
  24. package/dist/contracts/entities/tenants.js +15 -22
  25. package/dist/contracts/entities/usage.d.ts +1 -1
  26. package/dist/contracts/entities/usage.js +16 -6
  27. package/dist/contracts/entities/workspaces.d.ts +1 -1
  28. package/dist/contracts/entities/workspaces.js +26 -10
  29. package/dist/contracts/index.d.ts +18 -13
  30. package/dist/contracts/index.js +12 -12
  31. package/dist/contracts/limitations.d.ts +2 -4
  32. package/dist/contracts/limitations.js +2 -4
  33. package/dist/direct-chat-transport.js +2 -1
  34. package/dist/errors.d.ts +11 -0
  35. package/dist/errors.js +21 -0
  36. package/dist/http.d.ts +3 -1
  37. package/dist/http.js +74 -2
  38. package/dist/index.d.ts +18 -1
  39. package/dist/resources/agents.d.ts +120 -1
  40. package/dist/resources/agents.js +1 -33
  41. package/dist/resources/artifacts.d.ts +42 -1
  42. package/dist/resources/artifacts.js +0 -12
  43. package/dist/resources/chat-connections.d.ts +110 -1
  44. package/dist/resources/chat-connections.js +31 -44
  45. package/dist/resources/chat-deliveries.d.ts +23 -1
  46. package/dist/resources/chat-deliveries.js +2 -4
  47. package/dist/resources/mcp-connections.d.ts +63 -1
  48. package/dist/resources/mcp-connections.js +10 -24
  49. package/dist/resources/memories.d.ts +58 -1
  50. package/dist/resources/memories.js +0 -15
  51. package/dist/resources/merchant-bindings.d.ts +39 -1
  52. package/dist/resources/merchant-bindings.js +0 -9
  53. package/dist/resources/merchant-connection.d.ts +37 -1
  54. package/dist/resources/merchant-connection.js +15 -16
  55. package/dist/resources/merchant-usage-events.d.ts +66 -1
  56. package/dist/resources/merchant-usage-events.js +0 -18
  57. package/dist/resources/prompts.d.ts +50 -1
  58. package/dist/resources/prompts.js +0 -15
  59. package/dist/resources/providers.d.ts +64 -1
  60. package/dist/resources/providers.js +7 -25
  61. package/dist/resources/sessions.d.ts +124 -1
  62. package/dist/resources/sessions.js +5 -36
  63. package/dist/resources/skills.d.ts +95 -1
  64. package/dist/resources/skills.js +0 -27
  65. package/dist/resources/tasks.d.ts +107 -1
  66. package/dist/resources/tasks.js +0 -30
  67. package/dist/resources/tenant.d.ts +23 -1
  68. package/dist/resources/tenant.js +2 -10
  69. package/dist/resources/usage.d.ts +34 -1
  70. package/dist/resources/usage.js +2 -15
  71. package/dist/resources/workspaces.d.ts +50 -1
  72. package/dist/resources/workspaces.js +0 -15
  73. package/dist/types.d.ts +17 -1083
  74. package/package.json +1 -2
@@ -1,6 +1,7 @@
1
1
  import { lastAssistantMessageIsCompleteWithApprovalResponses, } from "ai";
2
2
  import { ChatStreamTransport } from "./chat-stream-transport.js";
3
3
  import { sessionIdSchema, turnIdSchema } from "./contracts/ids.js";
4
+ import { parseClientInput } from "./errors.js";
4
5
  /**
5
6
  * Adapts AI SDK chat requests to the Blazing Agents backend-relay shape and
6
7
  * resumes with the server-minted Session ID returned in `Location`.
@@ -16,7 +17,9 @@ export class BlazingAgentsChatTransport {
16
17
  const { onSessionId, onTurnId, sessionId, ...transportOptions } = options;
17
18
  const transportFetch = transportOptions.fetch ?? globalThis.fetch;
18
19
  this.#sessionId =
19
- sessionId === undefined ? undefined : sessionIdSchema.parse(sessionId);
20
+ sessionId === undefined
21
+ ? undefined
22
+ : parseClientInput(sessionIdSchema, sessionId, "sessionId");
20
23
  this.#transport = new ChatStreamTransport({
21
24
  ...transportOptions,
22
25
  /** Reads the first Session ID and each Turn ID before returning the response. */
package/dist/client.d.ts CHANGED
@@ -1,4 +1,20 @@
1
- import type { AgentClient, AgentsResource, ArtifactsResource, BlazingAgentsOptions, BlazingAgentsRequestOptions, ChatConnectionsResource, ChatDeliveriesResource, ChatInput, ChatResult, CompletionInput, CompletionResult, ContinueChatInput, McpConnectionsResource, MemoriesResource, MerchantBindingsResource, MerchantConnectionResource, MerchantUsageEventsResource, ObjectInput, ObjectResult, PromptsResource, ProvidersResource, SessionsResource, TasksResource, TenantResource, UsageResource, UserClient, WorkspacesResource } from "./types.ts";
1
+ import { type AgentsResource } from "./resources/agents.ts";
2
+ import { type ArtifactsResource } from "./resources/artifacts.ts";
3
+ import { type ChatConnectionsResource } from "./resources/chat-connections.ts";
4
+ import { type ChatDeliveriesResource } from "./resources/chat-deliveries.ts";
5
+ import { type McpConnectionsResource } from "./resources/mcp-connections.ts";
6
+ import { type MemoriesResource } from "./resources/memories.ts";
7
+ import { type MerchantBindingsResource } from "./resources/merchant-bindings.ts";
8
+ import { type MerchantConnectionResource } from "./resources/merchant-connection.ts";
9
+ import { type MerchantUsageEventsResource } from "./resources/merchant-usage-events.ts";
10
+ import { type PromptsResource } from "./resources/prompts.ts";
11
+ import { type ProvidersResource } from "./resources/providers.ts";
12
+ import { type SessionsResource } from "./resources/sessions.ts";
13
+ import { type TasksResource } from "./resources/tasks.ts";
14
+ import { type TenantResource } from "./resources/tenant.ts";
15
+ import { type UsageResource } from "./resources/usage.ts";
16
+ import { type WorkspacesResource } from "./resources/workspaces.ts";
17
+ import type { AgentClient, BlazingAgentsOptions, BlazingAgentsRequestOptions, ChatInput, ChatResult, CompletionInput, CompletionResult, ContinueChatInput, ObjectInput, ObjectResult, UserClient } from "./types.ts";
2
18
  export declare class BlazingAgents {
3
19
  #private;
4
20
  readonly chatConnections: ChatConnectionsResource;
@@ -33,7 +49,7 @@ export declare class BlazingAgents {
33
49
  * Scope requests to one end user. IDs use printable ASCII, at most 256 characters, without leading or trailing spaces.
34
50
  * @param userId - Printable ASCII end-user ID, at most 256 characters with no surrounding spaces.
35
51
  * @returns A client scoped to the validated end-user ID.
36
- * @throws ZodError - If the user ID is invalid.
52
+ * @throws BlazingAgentsError - With code `invalid_request` if the user ID is invalid.
37
53
  */
38
54
  forUser(userId: string): UserClient;
39
55
  /**
package/dist/client.js CHANGED
@@ -1,22 +1,23 @@
1
1
  import { z } from "zod";
2
+ import { parseClientInput } from "./errors.js";
2
3
  import { chat, completion, continueChat, objectGeneration, } from "./generation.js";
3
4
  import { createAgentsResource, createUserAgentsResource, } from "./resources/agents.js";
4
- import { createArtifactsResource } from "./resources/artifacts.js";
5
- import { createChatConnectionsResource } from "./resources/chat-connections.js";
6
- import { createChatDeliveriesResource } from "./resources/chat-deliveries.js";
7
- import { createMcpConnectionsResource } from "./resources/mcp-connections.js";
8
- import { createMemoriesResource } from "./resources/memories.js";
9
- import { createMerchantBindingsResource } from "./resources/merchant-bindings.js";
10
- import { createMerchantConnectionResource } from "./resources/merchant-connection.js";
11
- import { createMerchantUsageEventsResource } from "./resources/merchant-usage-events.js";
12
- import { createPromptsResource } from "./resources/prompts.js";
13
- import { createProvidersResource } from "./resources/providers.js";
14
- import { createSessionsResource } from "./resources/sessions.js";
5
+ import { createArtifactsResource, } from "./resources/artifacts.js";
6
+ import { createChatConnectionsResource, } from "./resources/chat-connections.js";
7
+ import { createChatDeliveriesResource, } from "./resources/chat-deliveries.js";
8
+ import { createMcpConnectionsResource, } from "./resources/mcp-connections.js";
9
+ import { createMemoriesResource, } from "./resources/memories.js";
10
+ import { createMerchantBindingsResource, } from "./resources/merchant-bindings.js";
11
+ import { createMerchantConnectionResource, } from "./resources/merchant-connection.js";
12
+ import { createMerchantUsageEventsResource, } from "./resources/merchant-usage-events.js";
13
+ import { createPromptsResource, } from "./resources/prompts.js";
14
+ import { createProvidersResource, } from "./resources/providers.js";
15
+ import { createSessionsResource, } from "./resources/sessions.js";
15
16
  import { createAgentSkillsResource } from "./resources/skills.js";
16
17
  import { createTasksResource } from "./resources/tasks.js";
17
- import { createTenantResource } from "./resources/tenant.js";
18
+ import { createTenantResource, } from "./resources/tenant.js";
18
19
  import { createUsageResource } from "./resources/usage.js";
19
- import { createWorkspacesResource } from "./resources/workspaces.js";
20
+ import { createWorkspacesResource, } from "./resources/workspaces.js";
20
21
  const DEFAULT_BASE_URL = "https://api.blazingagents.com";
21
22
  const TRAILING_SLASH_RE = /\/+$/;
22
23
  const scopedUserIdSchema = z
@@ -117,12 +118,12 @@ export class BlazingAgents {
117
118
  * Scope requests to one end user. IDs use printable ASCII, at most 256 characters, without leading or trailing spaces.
118
119
  * @param userId - Printable ASCII end-user ID, at most 256 characters with no surrounding spaces.
119
120
  * @returns A client scoped to the validated end-user ID.
120
- * @throws ZodError - If the user ID is invalid.
121
+ * @throws BlazingAgentsError - With code `invalid_request` if the user ID is invalid.
121
122
  */
122
123
  forUser(userId) {
123
124
  return createUserClient({
124
125
  ...this.#config,
125
- scopeUserId: scopedUserIdSchema.parse(userId),
126
+ scopeUserId: parseClientInput(scopedUserIdSchema, userId, "userId"),
126
127
  });
127
128
  }
128
129
  /**
@@ -265,10 +265,10 @@ export declare const agentsResponseSchema: z.ZodObject<{
265
265
  nextCursor: z.ZodNullable<z.ZodString>;
266
266
  }, z.core.$strip>;
267
267
  export declare const agentsListQuerySchema: z.ZodObject<{
268
- cursor: z.ZodOptional<z.ZodString>;
269
- limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
270
268
  userId: z.ZodOptional<z.ZodString>;
271
269
  workspaceId: z.ZodOptional<z.ZodString>;
270
+ cursor: z.ZodOptional<z.ZodString>;
271
+ limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
272
272
  }, z.core.$strict>;
273
273
  export declare const agentConfigSchema: z.ZodObject<{
274
274
  approvalInChat: z.ZodDefault<z.ZodObject<{
@@ -379,6 +379,10 @@ export declare const agentConfigSchema: z.ZodObject<{
379
379
  mcpConnectionIds: z.ZodArray<z.ZodString>;
380
380
  }, z.core.$strip>;
381
381
  export declare const createAgentBodySchema: z.ZodObject<{
382
+ workspaceTier: z.ZodOptional<z.ZodEnum<{
383
+ core: "core";
384
+ plus: "plus";
385
+ }>>;
382
386
  approvalInChat: z.ZodDefault<z.ZodObject<{
383
387
  default: z.ZodEnum<{
384
388
  auto: "auto";
@@ -464,10 +468,6 @@ export declare const createAgentBodySchema: z.ZodObject<{
464
468
  thinkingLevel: z.ZodDefault<z.ZodNullable<z.ZodString>>;
465
469
  providerId: z.ZodDefault<z.ZodNullable<z.ZodString>>;
466
470
  workspaceId: z.ZodOptional<z.ZodString>;
467
- workspaceTier: z.ZodOptional<z.ZodEnum<{
468
- core: "core";
469
- plus: "plus";
470
- }>>;
471
471
  autoCompaction: z.ZodDefault<z.ZodBoolean>;
472
472
  compactionReserveTokens: z.ZodDefault<z.ZodNumber>;
473
473
  memoryInjectionEnabled: z.ZodDefault<z.ZodBoolean>;
@@ -605,6 +605,7 @@ export type Agent = z.infer<typeof agentResponseSchema>;
605
605
  export type AgentsResponse = z.infer<typeof agentsResponseSchema>;
606
606
  export type AgentResponse = z.infer<typeof agentResponseSchema>;
607
607
  export type AgentsListQuery = z.infer<typeof agentsListQuerySchema>;
608
+ export type AgentStatus = z.infer<typeof agentStatusSchema>;
608
609
  export type AgentConfig = z.infer<typeof agentConfigSchema>;
609
610
  export type CreateAgentBody = z.input<typeof createAgentBodySchema>;
610
611
  export type UpdateAgentBody = z.input<typeof updateAgentBodySchema>;
@@ -1,7 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { cursorSchema, paginatedResponseSchema } from "../api.js";
3
3
  import { agentIdSchema, mcpConnectionIdSchema, providerIdSchema, tenantIdSchema, workspaceIdSchema, } from "../ids.js";
4
- import { DEFAULT_AGENTS_LIST_LIMIT, MAX_AGENT_INSTRUCTIONS_LENGTH, MAX_AGENT_NAME_LENGTH, MAX_AGENTS_LIST_LIMIT, MAX_MCP_CONNECTIONS_PER_AGENT, } from "../limitations.js";
4
+ import { DEFAULT_RESOURCES_LIST_LIMIT, MAX_AGENT_INSTRUCTIONS_LENGTH, MAX_AGENT_NAME_LENGTH, MAX_MCP_CONNECTIONS_PER_AGENT, MAX_RESOURCES_LIST_LIMIT, } from "../limitations.js";
5
5
  import { atLeastOneFieldMessage, hasObjectKeys, hasUniqueValues, } from "../utils.js";
6
6
  import { approvalPolicySchema } from "./agent-approval.js";
7
7
  import { agentToolNames } from "./agent-tools.js";
@@ -78,15 +78,22 @@ export const agentResponseSchema = z
78
78
  export const agentsResponseSchema = paginatedResponseSchema(agentResponseSchema);
79
79
  export const agentsListQuerySchema = z
80
80
  .object({
81
- cursor: cursorSchema.optional(),
81
+ userId: userIdSchema
82
+ .optional()
83
+ .describe("Return only agents for this end user. Send an empty string for tenant-level agents, or leave it out for all agents."),
84
+ workspaceId: workspaceIdSchema
85
+ .optional()
86
+ .describe("Return only agents that use this workspace."),
87
+ cursor: cursorSchema
88
+ .optional()
89
+ .describe("`nextCursor` from the previous page."),
82
90
  limit: z.coerce
83
91
  .number()
84
92
  .int()
85
93
  .min(1)
86
- .max(MAX_AGENTS_LIST_LIMIT)
87
- .default(DEFAULT_AGENTS_LIST_LIMIT),
88
- userId: userIdSchema.optional(),
89
- workspaceId: workspaceIdSchema.optional(),
94
+ .max(MAX_RESOURCES_LIST_LIMIT)
95
+ .default(DEFAULT_RESOURCES_LIST_LIMIT)
96
+ .describe("Maximum number of agents to return."),
90
97
  })
91
98
  .strict();
92
99
  export const agentConfigSchema = z
@@ -109,27 +116,78 @@ export const agentConfigSchema = z
109
116
  message: providerModelPairMessage,
110
117
  path: ["providerId"],
111
118
  });
119
+ const agentFieldDescriptions = {
120
+ approvalInChat: "Which tool calls need approval in sessions and stateless generation.",
121
+ approvalInTasks: "Which tool calls need approval in task runs.",
122
+ name: "Display name.",
123
+ model: "The provider's own model ID, such as `openai/gpt-6-luna`. Send it together with `providerId`.",
124
+ thinkingLevel: "How much reasoning to request from the model, such as `high`. Needs a provider and model, and must be a level the model supports.",
125
+ providerId: "ID of the provider whose key runs the model. Send it together with `model`.",
126
+ workspaceId: "ID of the workspace the agent reads and writes files in.",
127
+ autoCompaction: "Summarize older context automatically when a conversation nears the model's context limit.",
128
+ compactionReserveTokens: "Tokens to keep free for the model's reply when deciding whether to compact.",
129
+ memoryInjectionEnabled: "Add the agent's saved memories to every turn automatically.",
130
+ tools: "Built-in tools the agent can use. Each tool is enabled individually and is off until listed. File tools such as `read` and `bash` run in the attached workspace.",
131
+ instructions: "Instructions the agent follows on every turn.",
132
+ userId: "Your end user's ID, used for attribution. An empty string means a tenant-level agent. It cannot change after creation.",
133
+ metadata: "Your own key-value data, returned unchanged.",
134
+ mcpConnectionIds: "IDs of the MCP connections attached to the agent.",
135
+ };
112
136
  export const createAgentBodySchema = z
113
137
  .object({
114
- ...approvalFields,
115
- name: agentNameSchema,
116
- model: agentModelIdSchema.nullable().default(null),
117
- thinkingLevel: z.string().min(1).nullable().default(null),
118
- providerId: providerIdSchema.nullable().default(null),
119
- workspaceId: workspaceIdSchema.optional(),
120
- workspaceTier: workspaceTierSchema.optional(),
121
- autoCompaction: z.boolean().default(true),
122
- compactionReserveTokens: agentResponseSchema.shape.compactionReserveTokens.default(16_384),
123
- memoryInjectionEnabled: z.boolean().default(false),
124
- tools: agentToolsSchema.default([]),
125
- instructions: agentInstructionsSchema.default(""),
126
- userId: userIdSchema.default(""),
127
- metadata: metadataSchema.default({}),
128
- mcpConnectionIds: agentMcpConnectionIdsSchema.default([]),
138
+ workspaceTier: workspaceTierSchema
139
+ .optional()
140
+ .describe("Tier for a new Workspace. Defaults to Core. Cannot be combined with workspaceId."),
141
+ approvalInChat: approvalFields.approvalInChat.describe(agentFieldDescriptions.approvalInChat),
142
+ approvalInTasks: approvalFields.approvalInTasks.describe(agentFieldDescriptions.approvalInTasks),
143
+ name: agentNameSchema.describe(agentFieldDescriptions.name),
144
+ model: agentModelIdSchema
145
+ .nullable()
146
+ .default(null)
147
+ .describe(agentFieldDescriptions.model),
148
+ thinkingLevel: z
149
+ .string()
150
+ .min(1)
151
+ .nullable()
152
+ .default(null)
153
+ .describe(agentFieldDescriptions.thinkingLevel),
154
+ providerId: providerIdSchema
155
+ .nullable()
156
+ .default(null)
157
+ .describe(agentFieldDescriptions.providerId),
158
+ workspaceId: workspaceIdSchema
159
+ .optional()
160
+ .describe(`${agentFieldDescriptions.workspaceId} Leave it out to create a new workspace for the agent, or send an existing one to share it.`),
161
+ autoCompaction: z
162
+ .boolean()
163
+ .default(true)
164
+ .describe(agentFieldDescriptions.autoCompaction),
165
+ compactionReserveTokens: z
166
+ .number()
167
+ .int()
168
+ .nonnegative()
169
+ .max(Number.MAX_SAFE_INTEGER)
170
+ .default(16_384)
171
+ .describe(agentFieldDescriptions.compactionReserveTokens),
172
+ memoryInjectionEnabled: z
173
+ .boolean()
174
+ .default(false)
175
+ .describe(agentFieldDescriptions.memoryInjectionEnabled),
176
+ tools: agentToolsSchema.default([]).describe(agentFieldDescriptions.tools),
177
+ instructions: agentInstructionsSchema
178
+ .default("")
179
+ .describe(agentFieldDescriptions.instructions),
180
+ userId: userIdSchema.default("").describe(agentFieldDescriptions.userId),
181
+ metadata: metadataSchema
182
+ .default({})
183
+ .describe(agentFieldDescriptions.metadata),
184
+ mcpConnectionIds: agentMcpConnectionIdsSchema
185
+ .default([])
186
+ .describe(agentFieldDescriptions.mcpConnectionIds),
129
187
  })
130
188
  .strict()
131
189
  .refine((input) => input.workspaceId === undefined || input.workspaceTier === undefined, {
132
- message: "workspaceId and workspaceTier are mutually exclusive.",
190
+ message: "workspaceTier cannot be combined with workspaceId",
133
191
  path: ["workspaceTier"],
134
192
  })
135
193
  .refine(hasProviderModelPair, {
@@ -138,20 +196,55 @@ export const createAgentBodySchema = z
138
196
  });
139
197
  export const updateAgentBodySchema = z
140
198
  .object({
141
- approvalInChat: approvalPolicySchema.optional(),
142
- approvalInTasks: approvalPolicySchema.optional(),
143
- name: agentNameSchema.optional(),
144
- model: agentModelIdSchema.nullable().optional(),
145
- thinkingLevel: z.string().min(1).nullable().optional(),
146
- providerId: providerIdSchema.nullable().optional(),
147
- workspaceId: workspaceIdSchema.optional(),
148
- autoCompaction: z.boolean().optional(),
149
- compactionReserveTokens: agentResponseSchema.shape.compactionReserveTokens.optional(),
150
- memoryInjectionEnabled: z.boolean().optional(),
151
- tools: agentToolsSchema.optional(),
152
- instructions: agentInstructionsSchema.optional(),
153
- metadata: metadataSchema.optional(),
154
- mcpConnectionIds: agentMcpConnectionIdsSchema.optional(),
199
+ approvalInChat: approvalPolicySchema
200
+ .optional()
201
+ .describe(agentFieldDescriptions.approvalInChat),
202
+ approvalInTasks: approvalPolicySchema
203
+ .optional()
204
+ .describe(agentFieldDescriptions.approvalInTasks),
205
+ name: agentNameSchema.optional().describe(agentFieldDescriptions.name),
206
+ model: agentModelIdSchema
207
+ .nullable()
208
+ .optional()
209
+ .describe(agentFieldDescriptions.model),
210
+ thinkingLevel: z
211
+ .string()
212
+ .min(1)
213
+ .nullable()
214
+ .optional()
215
+ .describe(agentFieldDescriptions.thinkingLevel),
216
+ providerId: providerIdSchema
217
+ .nullable()
218
+ .optional()
219
+ .describe(agentFieldDescriptions.providerId),
220
+ workspaceId: workspaceIdSchema
221
+ .optional()
222
+ .describe(agentFieldDescriptions.workspaceId),
223
+ autoCompaction: z
224
+ .boolean()
225
+ .optional()
226
+ .describe(agentFieldDescriptions.autoCompaction),
227
+ compactionReserveTokens: z
228
+ .number()
229
+ .int()
230
+ .nonnegative()
231
+ .max(Number.MAX_SAFE_INTEGER)
232
+ .optional()
233
+ .describe(agentFieldDescriptions.compactionReserveTokens),
234
+ memoryInjectionEnabled: z
235
+ .boolean()
236
+ .optional()
237
+ .describe(agentFieldDescriptions.memoryInjectionEnabled),
238
+ tools: agentToolsSchema.optional().describe(agentFieldDescriptions.tools),
239
+ instructions: agentInstructionsSchema
240
+ .optional()
241
+ .describe(agentFieldDescriptions.instructions),
242
+ metadata: metadataSchema
243
+ .optional()
244
+ .describe(agentFieldDescriptions.metadata),
245
+ mcpConnectionIds: agentMcpConnectionIdsSchema
246
+ .optional()
247
+ .describe(agentFieldDescriptions.mcpConnectionIds),
155
248
  })
156
249
  .strict()
157
250
  .refine(hasObjectKeys, {
@@ -1,4 +1,5 @@
1
1
  import { z } from "zod";
2
+ /** The credentials a client sends; the server never returns them. */
2
3
  export declare const chatCredentialsSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
3
4
  platform: z.ZodLiteral<"slack">;
4
5
  botToken: z.ZodString;
@@ -103,7 +104,6 @@ export declare const chatConnectionSchema: z.ZodObject<{
103
104
  chatIds: z.ZodDefault<z.ZodArray<z.ZodString>>;
104
105
  platform: z.ZodLiteral<"telegram">;
105
106
  }, z.core.$strip>], "platform">;
106
- webhookUrl: z.ZodURL;
107
107
  identity: z.ZodObject<{
108
108
  botId: z.ZodString;
109
109
  botUserId: z.ZodString;
@@ -128,6 +128,7 @@ export declare const chatConnectionSchema: z.ZodObject<{
128
128
  credentialVersion: z.ZodNumber;
129
129
  createdAt: z.ZodString;
130
130
  updatedAt: z.ZodString;
131
+ webhookUrl: z.ZodURL;
131
132
  }, z.core.$strip>;
132
133
  export type CreateChatConnectionBody = z.input<typeof createChatConnectionBodySchema>;
133
134
  export type ChatCredentials = z.output<typeof chatCredentialsSchema>;
@@ -155,7 +156,6 @@ export declare const chatConnectionsResponseSchema: z.ZodObject<{
155
156
  chatIds: z.ZodDefault<z.ZodArray<z.ZodString>>;
156
157
  platform: z.ZodLiteral<"telegram">;
157
158
  }, z.core.$strip>], "platform">;
158
- webhookUrl: z.ZodURL;
159
159
  identity: z.ZodObject<{
160
160
  botId: z.ZodString;
161
161
  botUserId: z.ZodString;
@@ -180,6 +180,7 @@ export declare const chatConnectionsResponseSchema: z.ZodObject<{
180
180
  credentialVersion: z.ZodNumber;
181
181
  createdAt: z.ZodString;
182
182
  updatedAt: z.ZodString;
183
+ webhookUrl: z.ZodURL;
183
184
  }, z.core.$strip>>;
184
185
  }, z.core.$strip>;
185
186
  export type ChatConnectionsResponse = z.output<typeof chatConnectionsResponseSchema>;
@@ -212,7 +213,7 @@ export declare const chatDeliverySchema: z.ZodObject<{
212
213
  credentialVersion: z.ZodNumber;
213
214
  representation: z.ZodString;
214
215
  diagnostic: z.ZodNullable<z.ZodString>;
215
- receipts: z.ZodOptional<z.ZodUnknown>;
216
+ receipts: z.ZodUnknown;
216
217
  sessionId: z.ZodString;
217
218
  messageId: z.ZodNullable<z.ZodString>;
218
219
  approvalId: z.ZodNullable<z.ZodString>;
@@ -237,7 +238,7 @@ export declare const tenantChatDeliverySchema: z.ZodObject<{
237
238
  credentialVersion: z.ZodNumber;
238
239
  representation: z.ZodString;
239
240
  diagnostic: z.ZodNullable<z.ZodString>;
240
- receipts: z.ZodOptional<z.ZodUnknown>;
241
+ receipts: z.ZodUnknown;
241
242
  sessionId: z.ZodString;
242
243
  messageId: z.ZodNullable<z.ZodString>;
243
244
  approvalId: z.ZodNullable<z.ZodString>;
@@ -250,7 +251,7 @@ export declare const tenantChatDeliverySchema: z.ZodObject<{
250
251
  slack: "slack";
251
252
  telegram: "telegram";
252
253
  }>;
253
- }, z.core.$strip>;
254
+ }, z.core.$strict>;
254
255
  export type TenantChatDelivery = z.infer<typeof tenantChatDeliverySchema>;
255
256
  export declare const chatDeliveriesResponseSchema: z.ZodObject<{
256
257
  data: z.ZodArray<z.ZodObject<{
@@ -269,7 +270,7 @@ export declare const chatDeliveriesResponseSchema: z.ZodObject<{
269
270
  credentialVersion: z.ZodNumber;
270
271
  representation: z.ZodString;
271
272
  diagnostic: z.ZodNullable<z.ZodString>;
272
- receipts: z.ZodOptional<z.ZodUnknown>;
273
+ receipts: z.ZodUnknown;
273
274
  sessionId: z.ZodString;
274
275
  messageId: z.ZodNullable<z.ZodString>;
275
276
  approvalId: z.ZodNullable<z.ZodString>;
@@ -282,7 +283,7 @@ export declare const chatDeliveriesResponseSchema: z.ZodObject<{
282
283
  slack: "slack";
283
284
  telegram: "telegram";
284
285
  }>;
285
- }, z.core.$strip>>;
286
+ }, z.core.$strict>>;
286
287
  nextCursor: z.ZodNullable<z.ZodString>;
287
288
  }, z.core.$strip>;
288
289
  export type ChatDeliveriesResponse = z.infer<typeof chatDeliveriesResponseSchema>;
@@ -303,7 +304,7 @@ export declare const chatDeliveryListSchema: z.ZodObject<{
303
304
  credentialVersion: z.ZodNumber;
304
305
  representation: z.ZodString;
305
306
  diagnostic: z.ZodNullable<z.ZodString>;
306
- receipts: z.ZodOptional<z.ZodUnknown>;
307
+ receipts: z.ZodUnknown;
307
308
  sessionId: z.ZodString;
308
309
  messageId: z.ZodNullable<z.ZodString>;
309
310
  approvalId: z.ZodNullable<z.ZodString>;
@@ -1,90 +1,118 @@
1
1
  import { z } from "zod";
2
2
  import { agentIdSchema, chatConnectionIdSchema, chatDeliveryIdSchema, tenantIdSchema, } from "../ids.js";
3
- const secret = z
3
+ const slackBotToken = z
4
4
  .string()
5
5
  .min(8)
6
6
  .max(8192)
7
7
  .regex(/^[!-~]+$/);
8
+ const slackSigningSecret = z.string().regex(/^[0-9a-f]{32}$/);
9
+ const telegramBotToken = z.string().regex(/^\d+:[A-Za-z0-9_-]+$/);
10
+ const slackChannelIds = z.array(z.string().regex(/^[CG][A-Z0-9]+$/)).max(20);
11
+ const telegramChatIds = z.array(z.string().regex(/^-?\d+$/)).max(20);
12
+ /** The credentials a client sends; the server never returns them. */
8
13
  export const chatCredentialsSchema = z.discriminatedUnion("platform", [
9
14
  z
10
15
  .object({
11
16
  platform: z.literal("slack"),
12
- botToken: secret,
13
- signingSecret: z.string().regex(/^[0-9a-f]{32}$/),
17
+ botToken: slackBotToken,
18
+ signingSecret: slackSigningSecret,
14
19
  })
15
20
  .strict(),
16
21
  z
17
22
  .object({
18
23
  platform: z.literal("telegram"),
19
- botToken: z.string().regex(/^\d+:[A-Za-z0-9_-]+$/),
24
+ botToken: telegramBotToken,
20
25
  })
21
26
  .strict(),
22
27
  ]);
23
28
  const slackConfiguration = z
24
29
  .object({
25
- channelIds: z
26
- .array(z.string().regex(/^[CG][A-Z0-9]+$/))
27
- .max(20)
28
- .default([]),
30
+ channelIds: slackChannelIds.default([]),
29
31
  })
30
32
  .strict();
31
33
  const telegramConfiguration = z
32
34
  .object({
33
35
  businessMode: z.boolean().default(false),
34
- chatIds: z
35
- .array(z.string().regex(/^-?\d+$/))
36
- .max(20)
37
- .default([]),
36
+ chatIds: telegramChatIds.default([]),
38
37
  })
39
38
  .strict();
40
39
  export const chatConfigurationSchema = z.discriminatedUnion("platform", [
41
40
  slackConfiguration.extend({ platform: z.literal("slack") }),
42
41
  telegramConfiguration.extend({ platform: z.literal("telegram") }),
43
42
  ]);
43
+ const connectionName = z.string().trim().min(1).max(80);
44
44
  const common = {
45
- agentId: agentIdSchema,
46
- name: z.string().trim().min(1).max(80),
47
- enabled: z.boolean().default(true),
45
+ agentId: agentIdSchema.describe("ID of the agent that answers messages on this connection. You cannot change it later."),
46
+ name: connectionName.describe("Display name, 1 to 80 characters."),
47
+ enabled: z
48
+ .boolean()
49
+ .default(true)
50
+ .describe("Whether the connection accepts messages. Defaults to `true`."),
48
51
  };
52
+ const configurationDescription = "Optional platform settings. Destination IDs choose where health checks look; they do not restrict who can talk to the agent.";
53
+ const platformDescription = "Chat platform: `slack` or `telegram`.";
49
54
  export const createChatConnectionBodySchema = z.discriminatedUnion("platform", [
50
55
  z
51
56
  .object({
52
57
  ...common,
53
- platform: z.literal("slack"),
54
- configuration: slackConfiguration.prefault({}),
55
- credentials: chatCredentialsSchema.options[0].omit({ platform: true }),
58
+ platform: z.literal("slack").describe(platformDescription),
59
+ configuration: slackConfiguration
60
+ .prefault({})
61
+ .describe(configurationDescription),
62
+ credentials: z
63
+ .object({
64
+ botToken: slackBotToken,
65
+ signingSecret: slackSigningSecret,
66
+ })
67
+ .strict()
68
+ .describe("The Slack app's bot token and signing secret."),
56
69
  })
57
70
  .strict(),
58
71
  z
59
72
  .object({
60
73
  ...common,
61
- platform: z.literal("telegram"),
62
- configuration: telegramConfiguration.prefault({}),
63
- credentials: chatCredentialsSchema.options[1].omit({ platform: true }),
74
+ platform: z.literal("telegram").describe(platformDescription),
75
+ configuration: telegramConfiguration
76
+ .prefault({})
77
+ .describe(configurationDescription),
78
+ credentials: z
79
+ .object({ botToken: telegramBotToken })
80
+ .strict()
81
+ .describe("The Telegram bot token from BotFather."),
64
82
  })
65
83
  .strict(),
66
84
  ]);
67
85
  export const rotateChatConnectionBodySchema = z.discriminatedUnion("platform", [
68
- chatCredentialsSchema.options[0],
69
- chatCredentialsSchema.options[1],
86
+ z
87
+ .object({
88
+ platform: z
89
+ .literal("slack")
90
+ .describe("Must match the connection's platform."),
91
+ botToken: slackBotToken.describe("The new Slack bot token."),
92
+ signingSecret: slackSigningSecret.describe("The Slack app's signing secret."),
93
+ })
94
+ .strict(),
95
+ z
96
+ .object({
97
+ platform: z
98
+ .literal("telegram")
99
+ .describe("Must match the connection's platform."),
100
+ botToken: telegramBotToken.describe("The new Telegram bot token."),
101
+ })
102
+ .strict(),
70
103
  ]);
71
104
  export const updateChatConnectionBodySchema = z
72
105
  .object({
73
- name: common.name.optional(),
106
+ name: connectionName.optional().describe("New display name."),
74
107
  configuration: z
75
108
  .object({
76
109
  businessMode: z.boolean().optional(),
77
- chatIds: z
78
- .array(z.string().regex(/^-?\d+$/))
79
- .max(20)
80
- .optional(),
81
- channelIds: z
82
- .array(z.string().regex(/^[CG][A-Z0-9]+$/))
83
- .max(20)
84
- .optional(),
110
+ chatIds: telegramChatIds.optional(),
111
+ channelIds: slackChannelIds.optional(),
85
112
  })
86
113
  .strict()
87
- .optional(),
114
+ .optional()
115
+ .describe("Fields to change. Slack connections accept `channelIds`; Telegram connections accept `chatIds` and `businessMode`. Fields you leave out keep their values."),
88
116
  })
89
117
  .strict()
90
118
  .refine((body) => body.name !== undefined ||
@@ -118,24 +146,24 @@ export const chatConnectionSchema = z
118
146
  id: chatConnectionIdSchema,
119
147
  tenantId: tenantIdSchema,
120
148
  agentId: agentIdSchema,
121
- name: common.name,
149
+ name: connectionName,
122
150
  platform: z.enum(["slack", "telegram"]),
123
151
  enabled: z.boolean(),
124
152
  configuration: z.discriminatedUnion("platform", [
125
153
  chatConfigurationSchema.options[0].strip(),
126
154
  chatConfigurationSchema.options[1].strip(),
127
155
  ]),
128
- webhookUrl: z.url(),
129
156
  identity: chatIdentitySchema,
130
157
  health: chatHealthSchema,
131
158
  credentialFragment: z.string().max(4),
132
159
  credentialVersion: z.number().int().nonnegative(),
133
160
  createdAt: z.string(),
134
161
  updatedAt: z.string(),
162
+ webhookUrl: z.url(),
135
163
  })
136
164
  .strip();
137
165
  export const chatConnectionsResponseSchema = z
138
- .object({ chatConnections: z.array(chatConnectionSchema) })
166
+ .object({ chatConnections: chatConnectionSchema.array() })
139
167
  .strip();
140
168
  export const chatDeliveryStatusSchema = z.enum([
141
169
  "pending",
@@ -148,12 +176,12 @@ export const chatDeliverySchema = z
148
176
  .object({
149
177
  id: chatDeliveryIdSchema,
150
178
  kind: z.enum(["reply", "card"]),
151
- status: chatDeliveryStatusSchema,
179
+ status: z.enum(["pending", "confirmed", "failed", "ambiguous"]),
152
180
  attempt: z.number().int().nonnegative(),
153
181
  credentialVersion: z.number().int().nonnegative(),
154
182
  representation: z.string(),
155
183
  diagnostic: z.string().nullable(),
156
- receipts: z.unknown().optional(),
184
+ receipts: z.unknown(),
157
185
  sessionId: z.string(),
158
186
  messageId: z.string().nullable(),
159
187
  approvalId: z.string().nullable(),
@@ -162,11 +190,13 @@ export const chatDeliverySchema = z
162
190
  updatedAt: z.string(),
163
191
  })
164
192
  .strip();
165
- export const tenantChatDeliverySchema = chatDeliverySchema.extend({
193
+ export const tenantChatDeliverySchema = chatDeliverySchema
194
+ .extend({
166
195
  connectionId: chatConnectionIdSchema,
167
196
  agentId: agentIdSchema,
168
197
  platform: z.enum(["slack", "telegram"]),
169
- });
198
+ })
199
+ .strict();
170
200
  export const chatDeliveriesResponseSchema = z
171
201
  .object({
172
202
  data: z.array(tenantChatDeliverySchema),