@blazingagents/sdk 0.8.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -16,7 +16,7 @@ requires Node.js 24 or newer.
16
16
  ## Features
17
17
 
18
18
  - Typed clients for Agents, Workspaces, Skills, Providers, Prompts, Tasks,
19
- Sessions, Artifacts, usage, and Tenant settings.
19
+ Sessions, Artifacts, Slack and Telegram Chat Connections, usage, and Tenant settings.
20
20
  - Stateful chat and stateless text or structured-object generation.
21
21
  - Public Zod contracts for validating API requests and responses.
22
22
  - Cursor pagination and binary transfers.
@@ -232,3 +232,9 @@ ordinary-policy reference). Persisted approval decisions remain
232
232
  The root package exports `ApprovalDecision`, `ApprovalPolicy`, `ToolReference`,
233
233
  and `ToolApprovalState`; runtime policy schemas are exported from
234
234
  `@blazingagents/sdk/contracts`.
235
+
236
+ ## Slack and Telegram
237
+
238
+ Use the [connection example](https://github.com/blazingagents/typescript-sdk/blob/main/examples/chat-integrations.md) to connect an existing
239
+ Agent through REST. BA hosts the Chat SDK runtime, conversation history, and
240
+ approval cards; no additional SDK resource is required.
package/dist/client.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import type { AgentClient, AgentsResource, ArtifactsResource, BlazingAgentsOptions, BlazingAgentsRequestOptions, ChatInput, ChatResult, CompletionInput, CompletionResult, McpConnectionsResource, MemoriesResource, ObjectInput, ObjectResult, PromptsResource, ProvidersResource, SessionsResource, TasksResource, TenantResource, UsageResource, WorkspacesResource } from "./types.ts";
1
+ import type { AgentClient, AgentsResource, ArtifactsResource, BlazingAgentsOptions, BlazingAgentsRequestOptions, ChatConnectionsResource, ChatInput, ChatResult, CompletionInput, CompletionResult, McpConnectionsResource, MemoriesResource, ObjectInput, ObjectResult, PromptsResource, ProvidersResource, SessionsResource, TasksResource, TenantResource, UsageResource, WorkspacesResource } from "./types.ts";
2
2
  export declare class BlazingAgents {
3
3
  private readonly config;
4
+ readonly chatConnections: ChatConnectionsResource;
4
5
  readonly agents: AgentsResource;
5
6
  readonly sessions: SessionsResource;
6
7
  readonly providers: ProvidersResource;
package/dist/client.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { chat, completion, objectGeneration } from "./generation.js";
2
2
  import { createAgentsResource } from "./resources/agents.js";
3
3
  import { createArtifactsResource } from "./resources/artifacts.js";
4
+ import { createChatConnectionsResource } from "./resources/chat-connections.js";
4
5
  import { createMcpConnectionsResource } from "./resources/mcp-connections.js";
5
6
  import { createMemoriesResource } from "./resources/memories.js";
6
7
  import { createPromptsResource } from "./resources/prompts.js";
@@ -15,6 +16,7 @@ const DEFAULT_BASE_URL = "https://api.blazingagents.com";
15
16
  const TRAILING_SLASH_RE = /\/+$/;
16
17
  export class BlazingAgents {
17
18
  config;
19
+ chatConnections;
18
20
  agents;
19
21
  sessions;
20
22
  providers;
@@ -36,6 +38,7 @@ export class BlazingAgents {
36
38
  : { clientRequestId: options.clientRequestId }),
37
39
  onResponse: options.onResponse,
38
40
  };
41
+ this.chatConnections = createChatConnectionsResource(this.config);
39
42
  this.agents = createAgentsResource(this.config);
40
43
  this.sessions = createSessionsResource(this.config);
41
44
  this.providers = createProvidersResource(this.config);
@@ -0,0 +1,202 @@
1
+ import { z } from "zod";
2
+ export declare const chatCredentialsSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
3
+ platform: z.ZodLiteral<"slack">;
4
+ botToken: z.ZodString;
5
+ signingSecret: z.ZodString;
6
+ }, z.core.$strict>, z.ZodObject<{
7
+ platform: z.ZodLiteral<"telegram">;
8
+ botToken: z.ZodString;
9
+ webhookSecret: z.ZodString;
10
+ }, z.core.$strict>], "platform">;
11
+ export declare const chatConfigurationSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
12
+ teamId: z.ZodString;
13
+ appId: z.ZodString;
14
+ webhookUrl: z.ZodURL;
15
+ channelIds: z.ZodDefault<z.ZodArray<z.ZodString>>;
16
+ platform: z.ZodLiteral<"slack">;
17
+ }, z.core.$strict>, z.ZodObject<{
18
+ botId: z.ZodString;
19
+ webhookUrl: z.ZodURL;
20
+ chatIds: z.ZodDefault<z.ZodArray<z.ZodString>>;
21
+ platform: z.ZodLiteral<"telegram">;
22
+ }, z.core.$strict>], "platform">;
23
+ export declare const createChatConnectionBodySchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
24
+ agentId: z.ZodString;
25
+ name: z.ZodString;
26
+ enabled: z.ZodDefault<z.ZodBoolean>;
27
+ platform: z.ZodLiteral<"slack">;
28
+ configuration: z.ZodObject<{
29
+ teamId: z.ZodString;
30
+ appId: z.ZodString;
31
+ webhookUrl: z.ZodURL;
32
+ channelIds: z.ZodDefault<z.ZodArray<z.ZodString>>;
33
+ }, z.core.$strict>;
34
+ credentials: z.ZodObject<{
35
+ botToken: z.ZodString;
36
+ signingSecret: z.ZodString;
37
+ }, z.core.$strict>;
38
+ }, z.core.$strict>, z.ZodObject<{
39
+ agentId: z.ZodString;
40
+ name: z.ZodString;
41
+ enabled: z.ZodDefault<z.ZodBoolean>;
42
+ platform: z.ZodLiteral<"telegram">;
43
+ configuration: z.ZodObject<{
44
+ botId: z.ZodString;
45
+ webhookUrl: z.ZodURL;
46
+ chatIds: z.ZodDefault<z.ZodArray<z.ZodString>>;
47
+ }, z.core.$strict>;
48
+ credentials: z.ZodObject<{
49
+ botToken: z.ZodString;
50
+ webhookSecret: z.ZodString;
51
+ }, z.core.$strict>;
52
+ }, z.core.$strict>], "platform">;
53
+ export declare const rotateChatConnectionBodySchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
54
+ platform: z.ZodLiteral<"slack">;
55
+ botToken: z.ZodString;
56
+ signingSecret: z.ZodString;
57
+ }, z.core.$strict>, z.ZodObject<{
58
+ platform: z.ZodLiteral<"telegram">;
59
+ botToken: z.ZodString;
60
+ webhookSecret: z.ZodString;
61
+ }, z.core.$strict>], "platform">;
62
+ export declare const updateChatConnectionBodySchema: z.ZodObject<{
63
+ name: z.ZodOptional<z.ZodString>;
64
+ webhookUrl: z.ZodOptional<z.ZodURL>;
65
+ }, z.core.$strict>;
66
+ export declare const chatConnectionParamsSchema: z.ZodObject<{
67
+ id: z.ZodString;
68
+ }, z.core.$strip>;
69
+ export declare const chatHealthCheckSchema: z.ZodObject<{
70
+ code: z.ZodString;
71
+ status: z.ZodEnum<{
72
+ fail: "fail";
73
+ pass: "pass";
74
+ unknown: "unknown";
75
+ }>;
76
+ subject: z.ZodOptional<z.ZodString>;
77
+ }, z.core.$strip>;
78
+ export declare const chatHealthSchema: z.ZodObject<{
79
+ checkedAt: z.ZodString;
80
+ tokenValid: z.ZodBoolean;
81
+ identityVerified: z.ZodBoolean;
82
+ checks: z.ZodArray<z.ZodObject<{
83
+ code: z.ZodString;
84
+ status: z.ZodEnum<{
85
+ fail: "fail";
86
+ pass: "pass";
87
+ unknown: "unknown";
88
+ }>;
89
+ subject: z.ZodOptional<z.ZodString>;
90
+ }, z.core.$strip>>;
91
+ }, z.core.$strip>;
92
+ export declare const chatIdentitySchema: z.ZodObject<{
93
+ botId: z.ZodString;
94
+ botUserId: z.ZodString;
95
+ teamId: z.ZodNullable<z.ZodString>;
96
+ appId: z.ZodNullable<z.ZodString>;
97
+ }, z.core.$strip>;
98
+ export declare const chatConnectionSchema: z.ZodObject<{
99
+ id: z.ZodString;
100
+ tenantId: z.ZodString;
101
+ agentId: z.ZodString;
102
+ name: z.ZodString;
103
+ platform: z.ZodEnum<{
104
+ slack: "slack";
105
+ telegram: "telegram";
106
+ }>;
107
+ enabled: z.ZodBoolean;
108
+ configuration: z.ZodDiscriminatedUnion<[z.ZodObject<{
109
+ teamId: z.ZodString;
110
+ appId: z.ZodString;
111
+ webhookUrl: z.ZodURL;
112
+ channelIds: z.ZodDefault<z.ZodArray<z.ZodString>>;
113
+ platform: z.ZodLiteral<"slack">;
114
+ }, z.core.$strip>, z.ZodObject<{
115
+ botId: z.ZodString;
116
+ webhookUrl: z.ZodURL;
117
+ chatIds: z.ZodDefault<z.ZodArray<z.ZodString>>;
118
+ platform: z.ZodLiteral<"telegram">;
119
+ }, z.core.$strip>], "platform">;
120
+ identity: z.ZodObject<{
121
+ botId: z.ZodString;
122
+ botUserId: z.ZodString;
123
+ teamId: z.ZodNullable<z.ZodString>;
124
+ appId: z.ZodNullable<z.ZodString>;
125
+ }, z.core.$strip>;
126
+ health: z.ZodObject<{
127
+ checkedAt: z.ZodString;
128
+ tokenValid: z.ZodBoolean;
129
+ identityVerified: z.ZodBoolean;
130
+ checks: z.ZodArray<z.ZodObject<{
131
+ code: z.ZodString;
132
+ status: z.ZodEnum<{
133
+ fail: "fail";
134
+ pass: "pass";
135
+ unknown: "unknown";
136
+ }>;
137
+ subject: z.ZodOptional<z.ZodString>;
138
+ }, z.core.$strip>>;
139
+ }, z.core.$strip>;
140
+ credentialFragment: z.ZodString;
141
+ credentialVersion: z.ZodNumber;
142
+ createdAt: z.ZodString;
143
+ updatedAt: z.ZodString;
144
+ }, z.core.$strip>;
145
+ export type CreateChatConnectionBody = z.input<typeof createChatConnectionBodySchema>;
146
+ export type ChatCredentials = z.output<typeof chatCredentialsSchema>;
147
+ export type ChatConfiguration = z.output<typeof chatConfigurationSchema>;
148
+ export type ChatHealth = z.output<typeof chatHealthSchema>;
149
+ export type ChatIdentity = z.output<typeof chatIdentitySchema>;
150
+ export type ChatConnection = z.output<typeof chatConnectionSchema>;
151
+ export type UpdateChatConnectionBody = z.output<typeof updateChatConnectionBodySchema>;
152
+ export declare const chatConnectionsResponseSchema: z.ZodObject<{
153
+ chatConnections: z.ZodArray<z.ZodObject<{
154
+ id: z.ZodString;
155
+ tenantId: z.ZodString;
156
+ agentId: z.ZodString;
157
+ name: z.ZodString;
158
+ platform: z.ZodEnum<{
159
+ slack: "slack";
160
+ telegram: "telegram";
161
+ }>;
162
+ enabled: z.ZodBoolean;
163
+ configuration: z.ZodDiscriminatedUnion<[z.ZodObject<{
164
+ teamId: z.ZodString;
165
+ appId: z.ZodString;
166
+ webhookUrl: z.ZodURL;
167
+ channelIds: z.ZodDefault<z.ZodArray<z.ZodString>>;
168
+ platform: z.ZodLiteral<"slack">;
169
+ }, z.core.$strip>, z.ZodObject<{
170
+ botId: z.ZodString;
171
+ webhookUrl: z.ZodURL;
172
+ chatIds: z.ZodDefault<z.ZodArray<z.ZodString>>;
173
+ platform: z.ZodLiteral<"telegram">;
174
+ }, z.core.$strip>], "platform">;
175
+ identity: z.ZodObject<{
176
+ botId: z.ZodString;
177
+ botUserId: z.ZodString;
178
+ teamId: z.ZodNullable<z.ZodString>;
179
+ appId: z.ZodNullable<z.ZodString>;
180
+ }, z.core.$strip>;
181
+ health: z.ZodObject<{
182
+ checkedAt: z.ZodString;
183
+ tokenValid: z.ZodBoolean;
184
+ identityVerified: z.ZodBoolean;
185
+ checks: z.ZodArray<z.ZodObject<{
186
+ code: z.ZodString;
187
+ status: z.ZodEnum<{
188
+ fail: "fail";
189
+ pass: "pass";
190
+ unknown: "unknown";
191
+ }>;
192
+ subject: z.ZodOptional<z.ZodString>;
193
+ }, z.core.$strip>>;
194
+ }, z.core.$strip>;
195
+ credentialFragment: z.ZodString;
196
+ credentialVersion: z.ZodNumber;
197
+ createdAt: z.ZodString;
198
+ updatedAt: z.ZodString;
199
+ }, z.core.$strip>>;
200
+ }, z.core.$strip>;
201
+ export type ChatConnectionsResponse = z.output<typeof chatConnectionsResponseSchema>;
202
+ export type RotateChatConnectionBody = z.input<typeof rotateChatConnectionBodySchema>;
@@ -0,0 +1,142 @@
1
+ import { z } from "zod";
2
+ import { agentIdSchema, chatConnectionIdSchema, tenantIdSchema, } from "../ids.js";
3
+ const webhookUrl = z
4
+ .url()
5
+ .max(2048)
6
+ .refine((value) => {
7
+ const url = new URL(value);
8
+ return (url.protocol === "https:" &&
9
+ !url.username &&
10
+ !url.password &&
11
+ !url.search &&
12
+ !url.hash);
13
+ }, "Use an HTTPS callback URL without credentials, query or fragment");
14
+ const secret = z
15
+ .string()
16
+ .min(8)
17
+ .max(8192)
18
+ .regex(/^[!-~]+$/);
19
+ export const chatCredentialsSchema = z.discriminatedUnion("platform", [
20
+ z
21
+ .object({
22
+ platform: z.literal("slack"),
23
+ botToken: secret,
24
+ signingSecret: z.string().regex(/^[0-9a-f]{32}$/),
25
+ })
26
+ .strict(),
27
+ z
28
+ .object({
29
+ platform: z.literal("telegram"),
30
+ botToken: z.string().regex(/^\d+:[A-Za-z0-9_-]+$/),
31
+ webhookSecret: z
32
+ .string()
33
+ .min(1)
34
+ .max(256)
35
+ .regex(/^[A-Za-z0-9_-]+$/),
36
+ })
37
+ .strict(),
38
+ ]);
39
+ const slackConfiguration = z
40
+ .object({
41
+ teamId: z.string().regex(/^T[A-Z0-9]+$/),
42
+ appId: z.string().regex(/^A[A-Z0-9]+$/),
43
+ webhookUrl,
44
+ channelIds: z
45
+ .array(z.string().regex(/^[CG][A-Z0-9]+$/))
46
+ .max(20)
47
+ .default([]),
48
+ })
49
+ .strict();
50
+ const telegramConfiguration = z
51
+ .object({
52
+ botId: z.string().regex(/^\d+$/),
53
+ webhookUrl,
54
+ chatIds: z
55
+ .array(z.string().regex(/^-?\d+$/))
56
+ .max(20)
57
+ .default([]),
58
+ })
59
+ .strict();
60
+ export const chatConfigurationSchema = z.discriminatedUnion("platform", [
61
+ slackConfiguration.extend({ platform: z.literal("slack") }),
62
+ telegramConfiguration.extend({ platform: z.literal("telegram") }),
63
+ ]);
64
+ const common = {
65
+ agentId: agentIdSchema,
66
+ name: z.string().trim().min(1).max(80),
67
+ enabled: z.boolean().default(true),
68
+ };
69
+ export const createChatConnectionBodySchema = z.discriminatedUnion("platform", [
70
+ z
71
+ .object({
72
+ ...common,
73
+ platform: z.literal("slack"),
74
+ configuration: slackConfiguration,
75
+ credentials: chatCredentialsSchema.options[0].omit({ platform: true }),
76
+ })
77
+ .strict(),
78
+ z
79
+ .object({
80
+ ...common,
81
+ platform: z.literal("telegram"),
82
+ configuration: telegramConfiguration,
83
+ credentials: chatCredentialsSchema.options[1].omit({ platform: true }),
84
+ })
85
+ .strict(),
86
+ ]);
87
+ export const rotateChatConnectionBodySchema = chatCredentialsSchema;
88
+ export const updateChatConnectionBodySchema = z
89
+ .object({ name: common.name.optional(), webhookUrl: webhookUrl.optional() })
90
+ .strict()
91
+ .refine((body) => body.name !== undefined || body.webhookUrl !== undefined, {
92
+ message: "Provide a name or webhook URL",
93
+ });
94
+ export const chatConnectionParamsSchema = z.object({
95
+ id: chatConnectionIdSchema,
96
+ });
97
+ export const chatHealthCheckSchema = z
98
+ .object({
99
+ code: z.string(),
100
+ status: z.enum(["pass", "fail", "unknown"]),
101
+ subject: z.string().optional(),
102
+ })
103
+ .strip();
104
+ export const chatHealthSchema = z
105
+ .object({
106
+ checkedAt: z.string(),
107
+ tokenValid: z.boolean(),
108
+ identityVerified: z.boolean(),
109
+ checks: z.array(chatHealthCheckSchema),
110
+ })
111
+ .strip();
112
+ export const chatIdentitySchema = z
113
+ .object({
114
+ botId: z.string(),
115
+ botUserId: z.string(),
116
+ teamId: z.string().nullable(),
117
+ appId: z.string().nullable(),
118
+ })
119
+ .strip();
120
+ export const chatConnectionSchema = z
121
+ .object({
122
+ id: chatConnectionIdSchema,
123
+ tenantId: tenantIdSchema,
124
+ agentId: agentIdSchema,
125
+ name: common.name,
126
+ platform: z.enum(["slack", "telegram"]),
127
+ enabled: z.boolean(),
128
+ configuration: z.discriminatedUnion("platform", [
129
+ chatConfigurationSchema.options[0].strip(),
130
+ chatConfigurationSchema.options[1].strip(),
131
+ ]),
132
+ identity: chatIdentitySchema,
133
+ health: chatHealthSchema,
134
+ credentialFragment: z.string().max(4),
135
+ credentialVersion: z.number().int().nonnegative(),
136
+ createdAt: z.string(),
137
+ updatedAt: z.string(),
138
+ })
139
+ .strip();
140
+ export const chatConnectionsResponseSchema = z
141
+ .object({ chatConnections: z.array(chatConnectionSchema) })
142
+ .strip();
@@ -42,6 +42,15 @@ export declare const usageQuerySchema: z.ZodObject<{
42
42
  }>>;
43
43
  limit: z.ZodDefault<z.ZodNumber>;
44
44
  }, z.core.$strict>;
45
+ /**
46
+ * Query for the bounded dashboard-oriented usage overview. The date range has
47
+ * the same semantics as `usageQuerySchema`; `limit` bounds each ranking.
48
+ */
49
+ export declare const usageOverviewQuerySchema: z.ZodObject<{
50
+ from: z.ZodOptional<z.ZodISODate>;
51
+ to: z.ZodOptional<z.ZodISODate>;
52
+ limit: z.ZodDefault<z.ZodNumber>;
53
+ }, z.core.$strict>;
45
54
  /**
46
55
  * Usage bucket — one row per group. `sessionId` is the platform session id
47
56
  * (`ss_…`) or `null` for the `''` stateless sentinel (mapped at the read
@@ -88,8 +97,130 @@ export declare const usageResponseSchema: z.ZodObject<{
88
97
  durationMs: z.ZodNumber;
89
98
  }, z.core.$strip>;
90
99
  }, z.core.$strip>;
100
+ /**
101
+ * Dashboard usage data from one bounded aggregation. `byModel` may contain
102
+ * one final `{ provider: null, model: null }` bucket for usage outside the
103
+ * top-N models.
104
+ */
105
+ export declare const usageOverviewResponseSchema: z.ZodObject<{
106
+ totals: z.ZodObject<{
107
+ inputTokens: z.ZodNumber;
108
+ outputTokens: z.ZodNumber;
109
+ requestCount: z.ZodNumber;
110
+ durationMs: z.ZodNumber;
111
+ }, z.core.$strip>;
112
+ daily: z.ZodArray<z.ZodObject<{
113
+ day: z.ZodNullable<z.ZodString>;
114
+ agentId: z.ZodNullable<z.ZodString>;
115
+ sessionId: z.ZodNullable<z.ZodString>;
116
+ userId: z.ZodNullable<z.ZodString>;
117
+ provider: z.ZodNullable<z.ZodString>;
118
+ model: z.ZodNullable<z.ZodString>;
119
+ inputTokens: z.ZodNumber;
120
+ outputTokens: z.ZodNumber;
121
+ requestCount: z.ZodNumber;
122
+ durationMs: z.ZodNumber;
123
+ }, z.core.$strip>>;
124
+ byAgent: z.ZodArray<z.ZodObject<{
125
+ day: z.ZodNullable<z.ZodString>;
126
+ agentId: z.ZodNullable<z.ZodString>;
127
+ sessionId: z.ZodNullable<z.ZodString>;
128
+ userId: z.ZodNullable<z.ZodString>;
129
+ provider: z.ZodNullable<z.ZodString>;
130
+ model: z.ZodNullable<z.ZodString>;
131
+ inputTokens: z.ZodNumber;
132
+ outputTokens: z.ZodNumber;
133
+ requestCount: z.ZodNumber;
134
+ durationMs: z.ZodNumber;
135
+ }, z.core.$strip>>;
136
+ byUser: z.ZodArray<z.ZodObject<{
137
+ day: z.ZodNullable<z.ZodString>;
138
+ agentId: z.ZodNullable<z.ZodString>;
139
+ sessionId: z.ZodNullable<z.ZodString>;
140
+ userId: z.ZodNullable<z.ZodString>;
141
+ provider: z.ZodNullable<z.ZodString>;
142
+ model: z.ZodNullable<z.ZodString>;
143
+ inputTokens: z.ZodNumber;
144
+ outputTokens: z.ZodNumber;
145
+ requestCount: z.ZodNumber;
146
+ durationMs: z.ZodNumber;
147
+ }, z.core.$strip>>;
148
+ byModel: z.ZodArray<z.ZodObject<{
149
+ day: z.ZodNullable<z.ZodString>;
150
+ agentId: z.ZodNullable<z.ZodString>;
151
+ sessionId: z.ZodNullable<z.ZodString>;
152
+ userId: z.ZodNullable<z.ZodString>;
153
+ provider: z.ZodNullable<z.ZodString>;
154
+ model: z.ZodNullable<z.ZodString>;
155
+ inputTokens: z.ZodNumber;
156
+ outputTokens: z.ZodNumber;
157
+ requestCount: z.ZodNumber;
158
+ durationMs: z.ZodNumber;
159
+ }, z.core.$strip>>;
160
+ activeAgentCount: z.ZodNumber;
161
+ }, z.core.$strip>;
162
+ /** Applies the request-dependent ranking and daily-series guarantees. */
163
+ export declare function usageOverviewResponseSchemaForQuery(query?: Partial<UsageOverviewQuery>): z.ZodObject<{
164
+ totals: z.ZodObject<{
165
+ inputTokens: z.ZodNumber;
166
+ outputTokens: z.ZodNumber;
167
+ requestCount: z.ZodNumber;
168
+ durationMs: z.ZodNumber;
169
+ }, z.core.$strip>;
170
+ daily: z.ZodArray<z.ZodObject<{
171
+ day: z.ZodNullable<z.ZodString>;
172
+ agentId: z.ZodNullable<z.ZodString>;
173
+ sessionId: z.ZodNullable<z.ZodString>;
174
+ userId: z.ZodNullable<z.ZodString>;
175
+ provider: z.ZodNullable<z.ZodString>;
176
+ model: z.ZodNullable<z.ZodString>;
177
+ inputTokens: z.ZodNumber;
178
+ outputTokens: z.ZodNumber;
179
+ requestCount: z.ZodNumber;
180
+ durationMs: z.ZodNumber;
181
+ }, z.core.$strip>>;
182
+ byAgent: z.ZodArray<z.ZodObject<{
183
+ day: z.ZodNullable<z.ZodString>;
184
+ agentId: z.ZodNullable<z.ZodString>;
185
+ sessionId: z.ZodNullable<z.ZodString>;
186
+ userId: z.ZodNullable<z.ZodString>;
187
+ provider: z.ZodNullable<z.ZodString>;
188
+ model: z.ZodNullable<z.ZodString>;
189
+ inputTokens: z.ZodNumber;
190
+ outputTokens: z.ZodNumber;
191
+ requestCount: z.ZodNumber;
192
+ durationMs: z.ZodNumber;
193
+ }, z.core.$strip>>;
194
+ byUser: z.ZodArray<z.ZodObject<{
195
+ day: z.ZodNullable<z.ZodString>;
196
+ agentId: z.ZodNullable<z.ZodString>;
197
+ sessionId: z.ZodNullable<z.ZodString>;
198
+ userId: z.ZodNullable<z.ZodString>;
199
+ provider: z.ZodNullable<z.ZodString>;
200
+ model: z.ZodNullable<z.ZodString>;
201
+ inputTokens: z.ZodNumber;
202
+ outputTokens: z.ZodNumber;
203
+ requestCount: z.ZodNumber;
204
+ durationMs: z.ZodNumber;
205
+ }, z.core.$strip>>;
206
+ byModel: z.ZodArray<z.ZodObject<{
207
+ day: z.ZodNullable<z.ZodString>;
208
+ agentId: z.ZodNullable<z.ZodString>;
209
+ sessionId: z.ZodNullable<z.ZodString>;
210
+ userId: z.ZodNullable<z.ZodString>;
211
+ provider: z.ZodNullable<z.ZodString>;
212
+ model: z.ZodNullable<z.ZodString>;
213
+ inputTokens: z.ZodNumber;
214
+ outputTokens: z.ZodNumber;
215
+ requestCount: z.ZodNumber;
216
+ durationMs: z.ZodNumber;
217
+ }, z.core.$strip>>;
218
+ activeAgentCount: z.ZodNumber;
219
+ }, z.core.$strip>;
91
220
  export type UsageGroupBy = z.infer<typeof usageGroupBySchema>;
92
221
  export type UsageQuery = z.infer<typeof usageQuerySchema>;
93
222
  export type UsageBucket = z.infer<typeof usageBucketSchema>;
94
223
  export type UsageTotals = z.infer<typeof usageTotalsSchema>;
95
224
  export type UsageResponse = z.infer<typeof usageResponseSchema>;
225
+ export type UsageOverviewQuery = z.infer<typeof usageOverviewQuerySchema>;
226
+ export type UsageOverviewResponse = z.infer<typeof usageOverviewResponseSchema>;
@@ -1,7 +1,35 @@
1
1
  import { z } from "zod";
2
2
  import { agentIdSchema, sessionIdSchema } from "../ids.js";
3
- import { DEFAULT_USAGE_SESSION_TOP_N, MAX_USAGE_RANGE_DAYS, MAX_USAGE_SESSION_TOP_N, } from "../limitations.js";
3
+ import { DEFAULT_USAGE_OVERVIEW_TOP_N, DEFAULT_USAGE_RANGE_DAYS, DEFAULT_USAGE_SESSION_TOP_N, MAX_USAGE_OVERVIEW_TOP_N, MAX_USAGE_RANGE_DAYS, MAX_USAGE_SESSION_TOP_N, } from "../limitations.js";
4
4
  import { userIdSchema } from "./attribution.js";
5
+ function validateUsageRange(value, ctx) {
6
+ if ((value.from === undefined) !== (value.to === undefined)) {
7
+ ctx.addIssue({
8
+ code: "custom",
9
+ message: "`from` and `to` must both be present or both be absent.",
10
+ path: value.from === undefined ? ["from"] : ["to"],
11
+ });
12
+ }
13
+ if (value.from && value.to) {
14
+ const fromMs = new Date(`${value.from}T00:00:00Z`).getTime();
15
+ const toMs = new Date(`${value.to}T00:00:00Z`).getTime();
16
+ const spanDays = (toMs - fromMs) / (1000 * 60 * 60 * 24);
17
+ if (spanDays > MAX_USAGE_RANGE_DAYS) {
18
+ ctx.addIssue({
19
+ code: "custom",
20
+ message: `Usage range must be at most ${MAX_USAGE_RANGE_DAYS} days.`,
21
+ path: ["to"],
22
+ });
23
+ }
24
+ if (toMs < fromMs) {
25
+ ctx.addIssue({
26
+ code: "custom",
27
+ message: "`to` must be after `from`.",
28
+ path: ["to"],
29
+ });
30
+ }
31
+ }
32
+ }
5
33
  /**
6
34
  * `GET /v1/usage` groupBy — `day|agent|model|session|user`. `session` is
7
35
  * top-N by tokens; the others are exhaustive and bounded. `user` is the
@@ -46,39 +74,24 @@ export const usageQuerySchema = z
46
74
  .default(DEFAULT_USAGE_SESSION_TOP_N),
47
75
  })
48
76
  .strict()
49
- .superRefine((value, ctx) => {
50
- /**
51
- * Require either both `from` and `to` or neither — a partial range
52
- * (only one bound) is rejected so the caller doesn't silently get the
53
- * default window when they meant to specify a custom range.
54
- */
55
- if ((value.from === undefined) !== (value.to === undefined)) {
56
- ctx.addIssue({
57
- code: "custom",
58
- message: "`from` and `to` must both be present or both be absent.",
59
- path: value.from === undefined ? ["from"] : ["to"],
60
- });
61
- }
62
- if (value.from && value.to) {
63
- const fromMs = new Date(`${value.from}T00:00:00Z`).getTime();
64
- const toMs = new Date(`${value.to}T00:00:00Z`).getTime();
65
- const spanDays = (toMs - fromMs) / (1000 * 60 * 60 * 24);
66
- if (spanDays > MAX_USAGE_RANGE_DAYS) {
67
- ctx.addIssue({
68
- code: "custom",
69
- message: `Usage range must be at most ${MAX_USAGE_RANGE_DAYS} days.`,
70
- path: ["to"],
71
- });
72
- }
73
- if (toMs < fromMs) {
74
- ctx.addIssue({
75
- code: "custom",
76
- message: "`to` must be after `from`.",
77
- path: ["to"],
78
- });
79
- }
80
- }
81
- });
77
+ .superRefine(validateUsageRange);
78
+ /**
79
+ * Query for the bounded dashboard-oriented usage overview. The date range has
80
+ * the same semantics as `usageQuerySchema`; `limit` bounds each ranking.
81
+ */
82
+ export const usageOverviewQuerySchema = z
83
+ .object({
84
+ from: z.iso.date().optional(),
85
+ to: z.iso.date().optional(),
86
+ limit: z
87
+ .number()
88
+ .int()
89
+ .min(1)
90
+ .max(MAX_USAGE_OVERVIEW_TOP_N)
91
+ .default(DEFAULT_USAGE_OVERVIEW_TOP_N),
92
+ })
93
+ .strict()
94
+ .superRefine(validateUsageRange);
82
95
  /**
83
96
  * Usage bucket — one row per group. `sessionId` is the platform session id
84
97
  * (`ss_…`) or `null` for the `''` stateless sentinel (mapped at the read
@@ -115,3 +128,73 @@ export const usageResponseSchema = z
115
128
  totals: usageTotalsSchema,
116
129
  })
117
130
  .strip();
131
+ /**
132
+ * Dashboard usage data from one bounded aggregation. `byModel` may contain
133
+ * one final `{ provider: null, model: null }` bucket for usage outside the
134
+ * top-N models.
135
+ */
136
+ export const usageOverviewResponseSchema = z
137
+ .object({
138
+ totals: usageTotalsSchema,
139
+ daily: z.array(usageBucketSchema).max(MAX_USAGE_RANGE_DAYS + 1),
140
+ byAgent: z.array(usageBucketSchema).max(MAX_USAGE_OVERVIEW_TOP_N),
141
+ byUser: z.array(usageBucketSchema).max(MAX_USAGE_OVERVIEW_TOP_N),
142
+ byModel: z.array(usageBucketSchema).max(MAX_USAGE_OVERVIEW_TOP_N + 1),
143
+ activeAgentCount: z.number().int().nonnegative(),
144
+ })
145
+ .strip()
146
+ .superRefine((value, ctx) => {
147
+ const remainderCount = value.byModel.filter(({ model, provider }) => model === null && provider === null).length;
148
+ const normalCount = value.byModel.length - remainderCount;
149
+ const hasIncompleteModel = value.byModel.some(({ model, provider }) => (model === null) !== (provider === null));
150
+ if (remainderCount > 1 ||
151
+ normalCount > MAX_USAGE_OVERVIEW_TOP_N ||
152
+ hasIncompleteModel) {
153
+ ctx.addIssue({
154
+ code: "custom",
155
+ message: "Model usage must contain at most 20 models and one remainder.",
156
+ path: ["byModel"],
157
+ });
158
+ }
159
+ });
160
+ /** Applies the request-dependent ranking and daily-series guarantees. */
161
+ export function usageOverviewResponseSchemaForQuery(query = {}) {
162
+ const limit = query.limit ?? DEFAULT_USAGE_OVERVIEW_TOP_N;
163
+ const expectedDays = query.from && query.to
164
+ ? (new Date(`${query.to}T00:00:00Z`).getTime() -
165
+ new Date(`${query.from}T00:00:00Z`).getTime()) /
166
+ (1000 * 60 * 60 * 24) +
167
+ 1
168
+ : DEFAULT_USAGE_RANGE_DAYS;
169
+ return usageOverviewResponseSchema.superRefine((value, ctx) => {
170
+ const normalModelCount = value.byModel.filter(({ model, provider }) => model !== null || provider !== null).length;
171
+ if (value.byAgent.length > limit ||
172
+ value.byUser.length > limit ||
173
+ normalModelCount > limit) {
174
+ ctx.addIssue({
175
+ code: "custom",
176
+ message: "Usage rankings exceed the requested limit.",
177
+ path: ["byAgent"],
178
+ });
179
+ }
180
+ const days = value.daily.map(({ day }) => day);
181
+ const firstDay = query.from ?? days[0];
182
+ const completeDailyRange = days.length === expectedDays &&
183
+ firstDay !== null &&
184
+ firstDay !== undefined &&
185
+ days.every((day, index) => {
186
+ const expected = new Date(new Date(`${firstDay}T00:00:00Z`).getTime() +
187
+ index * 24 * 60 * 60 * 1000)
188
+ .toISOString()
189
+ .slice(0, 10);
190
+ return day === expected;
191
+ });
192
+ if (!completeDailyRange) {
193
+ ctx.addIssue({
194
+ code: "custom",
195
+ message: "Daily usage must cover the complete selected range.",
196
+ path: ["daily"],
197
+ });
198
+ }
199
+ });
200
+ }
@@ -55,3 +55,4 @@ export declare const apiKeyDigestSchema: z.ZodString;
55
55
  export declare const apiKeyFragmentSchema: z.ZodString;
56
56
  export declare const providerKeyFragmentSchema: z.ZodString;
57
57
  export type TurnId = z.infer<typeof turnIdSchema>;
58
+ export declare const chatConnectionIdSchema: z.ZodString;
@@ -77,3 +77,4 @@ export const apiKeyDigestSchema = z.string().regex(/^[0-9a-f]{64}$/);
77
77
  export const apiKeyFragmentSchema = z.string().regex(/^ba_[0-9A-Za-z]{2}$/);
78
78
  // Provider key fragment — last 4 chars of the secret, display-only.
79
79
  export const providerKeyFragmentSchema = z.string().min(1).max(4);
80
+ export const chatConnectionIdSchema = z.string().regex(/^cc_[0-9A-Za-z]{16}$/);
@@ -7,6 +7,7 @@ export { artifactDownloadUrlResponseSchema, artifactListItemSchema, artifactsLis
7
7
  export { attributionCreateInputSchema, metadataSchema, } from "./entities/attribution.ts";
8
8
  export type { PromptVariables, UsageSummary } from "./entities/chat.ts";
9
9
  export { blazingAgentsChatMessageMetadataSchema, chatModeSchema, chatRequestBodySchema, chatTriggerSchema, generationRequestBodySchema, jsonSchemaShapeSchema, promptVariablesSchema, usageSummarySchema, } from "./entities/chat.ts";
10
+ export { chatConfigurationSchema, chatConnectionSchema, chatConnectionsResponseSchema, chatCredentialsSchema, chatHealthCheckSchema, chatHealthSchema, chatIdentitySchema, createChatConnectionBodySchema, rotateChatConnectionBodySchema, updateChatConnectionBodySchema, } from "./entities/chat-connections.ts";
10
11
  export { approveMcpOauthAuthorizationBodySchema, createMcpConnectionBodySchema, mcpAttachmentResponseSchema, mcpAttachmentsResponseSchema, mcpConnectionAuthTypeSchema, mcpConnectionOauthConnectResponseSchema, mcpConnectionReconnectResultSchema, mcpConnectionResponseSchema, mcpConnectionStatusSchema, mcpConnectionsResponseSchema, mcpConnectionTestErrorCodeSchema, mcpConnectionTestResponseSchema, mcpOauthAuthorizationLaunchResponseSchema, reconnectMcpConnectionBodySchema, updateMcpAttachmentBodySchema, updateMcpConnectionBodySchema, } from "./entities/mcp-connections.ts";
11
12
  export { createMemoryBodySchema, memoriesListResponseSchema, memoryResponseSchema, memorySchema, updateMemoryBodySchema, } from "./entities/memories.ts";
12
13
  export { createPromptBodySchema, promptResponseSchema, promptSchema, promptsResponseSchema, updatePromptBodySchema, } from "./entities/prompts.ts";
@@ -16,6 +17,7 @@ export { decideToolApprovalBodySchema, latestSessionListItemSchema, latestSessio
16
17
  export { copySkillBodySchema, createSkillBodySchema, skillCopyResultsSchema, skillDetailSchema, skillsListResponseSchema, } from "./entities/skills.ts";
17
18
  export { createTaskBodySchema, createTaskResponseSchema, createTaskRunBodySchema, createTaskRunResponseSchema, taskListItemSchema, taskResponseSchema, taskRunMessagesResponseSchema, taskRunResponseSchema, taskRunSchema, taskRunStatusSchema, taskRunsListResponseSchema, taskScheduleKindSchema, taskSchema, tasksListResponseSchema, updateTaskBodySchema, } from "./entities/tasks.ts";
18
19
  export { quotaSchema, subscriptionStatusSchema, tenantResponseSchema, tenantSchema, tenantSettingsResponseSchema, updateTenantSettingsBodySchema, } from "./entities/tenants.ts";
19
- export { usageResponseSchema } from "./entities/usage.ts";
20
+ export type { UsageBucket, UsageOverviewQuery, UsageOverviewResponse, UsageResponse, UsageTotals, } from "./entities/usage.ts";
21
+ export { usageOverviewQuerySchema, usageOverviewResponseSchema, usageResponseSchema, } from "./entities/usage.ts";
20
22
  export { createWorkspaceBodySchema, updateWorkspaceBodySchema, workspaceSchema, workspacesListResponseSchema, } from "./entities/workspaces.ts";
21
23
  export { agentIdSchema, apiKeyTokenSchema, isAdminAgentId, promptIdSchema, sessionIdSchema, } from "./ids.ts";
@@ -6,6 +6,7 @@ export { agentResponseSchema, agentSchema, agentStatusSchema, agentsResponseSche
6
6
  export { artifactDownloadUrlResponseSchema, artifactListItemSchema, artifactsListResponseSchema, } from "./entities/artifacts.js";
7
7
  export { attributionCreateInputSchema, metadataSchema, } from "./entities/attribution.js";
8
8
  export { blazingAgentsChatMessageMetadataSchema, chatModeSchema, chatRequestBodySchema, chatTriggerSchema, generationRequestBodySchema, jsonSchemaShapeSchema, promptVariablesSchema, usageSummarySchema, } from "./entities/chat.js";
9
+ export { chatConfigurationSchema, chatConnectionSchema, chatConnectionsResponseSchema, chatCredentialsSchema, chatHealthCheckSchema, chatHealthSchema, chatIdentitySchema, createChatConnectionBodySchema, rotateChatConnectionBodySchema, updateChatConnectionBodySchema, } from "./entities/chat-connections.js";
9
10
  export { approveMcpOauthAuthorizationBodySchema, createMcpConnectionBodySchema, mcpAttachmentResponseSchema, mcpAttachmentsResponseSchema, mcpConnectionAuthTypeSchema, mcpConnectionOauthConnectResponseSchema, mcpConnectionReconnectResultSchema, mcpConnectionResponseSchema, mcpConnectionStatusSchema, mcpConnectionsResponseSchema, mcpConnectionTestErrorCodeSchema, mcpConnectionTestResponseSchema, mcpOauthAuthorizationLaunchResponseSchema, reconnectMcpConnectionBodySchema, updateMcpAttachmentBodySchema, updateMcpConnectionBodySchema, } from "./entities/mcp-connections.js";
10
11
  export { createMemoryBodySchema, memoriesListResponseSchema, memoryResponseSchema, memorySchema, updateMemoryBodySchema, } from "./entities/memories.js";
11
12
  export { createPromptBodySchema, promptResponseSchema, promptSchema, promptsResponseSchema, updatePromptBodySchema, } from "./entities/prompts.js";
@@ -14,6 +15,6 @@ export { decideToolApprovalBodySchema, latestSessionListItemSchema, latestSessio
14
15
  export { copySkillBodySchema, createSkillBodySchema, skillCopyResultsSchema, skillDetailSchema, skillsListResponseSchema, } from "./entities/skills.js";
15
16
  export { createTaskBodySchema, createTaskResponseSchema, createTaskRunBodySchema, createTaskRunResponseSchema, taskListItemSchema, taskResponseSchema, taskRunMessagesResponseSchema, taskRunResponseSchema, taskRunSchema, taskRunStatusSchema, taskRunsListResponseSchema, taskScheduleKindSchema, taskSchema, tasksListResponseSchema, updateTaskBodySchema, } from "./entities/tasks.js";
16
17
  export { quotaSchema, subscriptionStatusSchema, tenantResponseSchema, tenantSchema, tenantSettingsResponseSchema, updateTenantSettingsBodySchema, } from "./entities/tenants.js";
17
- export { usageResponseSchema } from "./entities/usage.js";
18
+ export { usageOverviewQuerySchema, usageOverviewResponseSchema, usageResponseSchema, } from "./entities/usage.js";
18
19
  export { createWorkspaceBodySchema, updateWorkspaceBodySchema, workspaceSchema, workspacesListResponseSchema, } from "./entities/workspaces.js";
19
20
  export { agentIdSchema, apiKeyTokenSchema, isAdminAgentId, promptIdSchema, sessionIdSchema, } from "./ids.js";
@@ -122,6 +122,8 @@ export declare const MAX_USAGE_RANGE_DAYS = 31;
122
122
  export declare const DEFAULT_USAGE_RANGE_DAYS = 30;
123
123
  export declare const DEFAULT_USAGE_SESSION_TOP_N = 50;
124
124
  export declare const MAX_USAGE_SESSION_TOP_N = 200;
125
+ export declare const DEFAULT_USAGE_OVERVIEW_TOP_N = 5;
126
+ export declare const MAX_USAGE_OVERVIEW_TOP_N = 20;
125
127
  export declare const MIN_QUOTA_RESET_DAY = 1;
126
128
  export declare const MAX_QUOTA_RESET_DAY = 28;
127
129
  /**
@@ -123,6 +123,8 @@ export const MAX_USAGE_RANGE_DAYS = 31;
123
123
  export const DEFAULT_USAGE_RANGE_DAYS = 30;
124
124
  export const DEFAULT_USAGE_SESSION_TOP_N = 50;
125
125
  export const MAX_USAGE_SESSION_TOP_N = 200;
126
+ export const DEFAULT_USAGE_OVERVIEW_TOP_N = 5;
127
+ export const MAX_USAGE_OVERVIEW_TOP_N = 20;
126
128
  // Quota — reset day between 1 and 28.
127
129
  export const MIN_QUOTA_RESET_DAY = 1;
128
130
  export const MAX_QUOTA_RESET_DAY = 28;
package/dist/index.d.ts CHANGED
@@ -12,12 +12,14 @@ export { BlazingAgents } from "./client.ts";
12
12
  export type { ApprovalDecision, ApprovalPolicy, ToolReference, } from "./contracts/entities/agent-approval.ts";
13
13
  export type { Agent, AgentResponse, AgentsResponse, AgentVersion, AgentVersionsListQuery, AgentVersionsResponse, CreateAgentBody, UpdateAgentBody, } from "./contracts/entities/agents.ts";
14
14
  export type { ArtifactDownloadUrlResponse, ArtifactListItem, ArtifactsListResponse, } from "./contracts/entities/artifacts.ts";
15
+ export type { ChatConfiguration, ChatConnection, ChatConnectionsResponse, ChatCredentials, ChatHealth, ChatIdentity, CreateChatConnectionBody, RotateChatConnectionBody, UpdateChatConnectionBody, } from "./contracts/entities/chat-connections.ts";
15
16
  export type { CreateMcpConnectionBody, McpAttachmentResponse, McpAttachmentsResponse, McpConnectionAuthType, McpConnectionOauthConnectResponse, McpConnectionReconnectResult, McpConnectionResponse, McpConnectionStatus, McpConnectionTestResponse, ReconnectMcpConnectionBody, UpdateMcpAttachmentBody, UpdateMcpConnectionBody, } from "./contracts/entities/mcp-connections.ts";
16
17
  export type { CreateProviderBody, ProviderListItem, ProviderModel, ProviderModelsResponse, ProviderResponse, ProvidersResponse, ProviderType, ThinkingLevelsResponse, UpdateProviderBody, } from "./contracts/entities/providers.ts";
17
18
  export type { ToolApprovalDecisionResponse, ToolApprovalState, ToolApprovalsResponse, } from "./contracts/entities/sessions.ts";
18
19
  export type { CreateSkillBody, Skill, SkillArchiveType, SkillCopyResult, SkillCopyResults, SkillDetail, SkillFile, SkillsListResponse, } from "./contracts/entities/skills.ts";
20
+ export type { UsageBucket, UsageOverviewQuery, UsageOverviewResponse, UsageTotals, } from "./contracts/entities/usage.ts";
19
21
  export type { CreateWorkspaceBody, UpdateWorkspaceBody, Workspace, WorkspaceNetworkPolicy, WorkspacesListResponse, } from "./contracts/entities/workspaces.ts";
20
22
  export { BlazingAgentsDirectChatTransport, type BlazingAgentsDirectChatTransportOptions, } from "./direct-chat-transport.ts";
21
23
  export { BlazingAgentsError } from "./errors.ts";
22
24
  export { createChatRelay, createCompletionRelay, type RelayContext, type SessionOwnershipStore, } from "./relay.ts";
23
- export type { AgentClient, AgentSkillsResource, AgentsListOptions, AgentsResource, AgentVersionsListOptions, ArtifactsResource, AttributionInput, BlazingAgentsErrorCode, BlazingAgentsOptions, BlazingAgentsRequestOptions, BlazingAgentsUIMessage, BlazingAgentsUIMessageChunk, ChatInput, ChatMessageInput, ChatPromptInput, ChatResult, ChatTrigger, CompletionInput, CompletionPromptIdInput, CompletionPromptInput, CompletionResult, KnownBlazingAgentsErrorCode, LatestSessionsListOptions, McpConnectionsResource, MemoriesListOptions, MemoriesResource, ObjectInput, ObjectPromptIdInput, ObjectPromptInput, ObjectResult, PromptsResource, ProvidersResource, ResourceRequestOptions, ResponseObservation, SessionsResource, SkillsListOptions, TasksResource, TenantResource, TerminalStreamResult, UsageResource, WorkspacesListOptions, WorkspacesResource, } from "./types.ts";
25
+ export type { AgentClient, AgentSkillsResource, AgentsListOptions, AgentsResource, AgentVersionsListOptions, ArtifactsResource, AttributionInput, BlazingAgentsErrorCode, BlazingAgentsOptions, BlazingAgentsRequestOptions, BlazingAgentsUIMessage, BlazingAgentsUIMessageChunk, ChatConnectionsResource, ChatInput, ChatMessageInput, ChatPromptInput, ChatResult, ChatTrigger, CompletionInput, CompletionPromptIdInput, CompletionPromptInput, CompletionResult, KnownBlazingAgentsErrorCode, LatestSessionsListOptions, McpConnectionsResource, MemoriesListOptions, MemoriesResource, ObjectInput, ObjectPromptIdInput, ObjectPromptInput, ObjectResult, PromptsResource, ProvidersResource, ResourceRequestOptions, ResponseObservation, SessionsResource, SkillsListOptions, TasksResource, TenantResource, TerminalStreamResult, UsageResource, WorkspacesListOptions, WorkspacesResource, } from "./types.ts";
@@ -0,0 +1,2 @@
1
+ import type { ChatConnectionsResource, HttpConfig } from "../types.ts";
2
+ export declare function createChatConnectionsResource(config: HttpConfig): ChatConnectionsResource;
@@ -0,0 +1,33 @@
1
+ import { chatConnectionSchema, chatConnectionsResponseSchema, } from "../contracts/entities/chat-connections.js";
2
+ import { requestJson } from "../http.js";
3
+ export function createChatConnectionsResource(config) {
4
+ return {
5
+ async list({ abortSignal } = {}) {
6
+ return await requestJson(config, "/v1/chat-connections", { signal: abortSignal }, chatConnectionsResponseSchema);
7
+ },
8
+ async create({ abortSignal, ...body }) {
9
+ return await requestJson(config, "/v1/chat-connections", { signal: abortSignal, method: "POST", json: body }, chatConnectionSchema);
10
+ },
11
+ async get({ chatConnectionId, abortSignal }) {
12
+ return await requestJson(config, `/v1/chat-connections/${encodeURIComponent(chatConnectionId)}`, { signal: abortSignal, method: "GET" }, chatConnectionSchema);
13
+ },
14
+ async update({ chatConnectionId, abortSignal, ...body }) {
15
+ return await requestJson(config, `/v1/chat-connections/${encodeURIComponent(chatConnectionId)}`, { signal: abortSignal, method: "PATCH", json: body }, chatConnectionSchema);
16
+ },
17
+ async rotateCredentials({ chatConnectionId, abortSignal, ...body }) {
18
+ return await requestJson(config, `/v1/chat-connections/${encodeURIComponent(chatConnectionId)}/credentials`, { signal: abortSignal, method: "POST", json: body }, chatConnectionSchema);
19
+ },
20
+ async checkHealth({ chatConnectionId, abortSignal }) {
21
+ return await requestJson(config, `/v1/chat-connections/${encodeURIComponent(chatConnectionId)}/health`, { signal: abortSignal, method: "POST" }, chatConnectionSchema);
22
+ },
23
+ async enable({ chatConnectionId, abortSignal }) {
24
+ return await requestJson(config, `/v1/chat-connections/${encodeURIComponent(chatConnectionId)}/enable`, { signal: abortSignal, method: "POST" }, chatConnectionSchema);
25
+ },
26
+ async disable({ chatConnectionId, abortSignal }) {
27
+ return await requestJson(config, `/v1/chat-connections/${encodeURIComponent(chatConnectionId)}/disable`, { signal: abortSignal, method: "POST" }, chatConnectionSchema);
28
+ },
29
+ async delete({ chatConnectionId, abortSignal }) {
30
+ await requestJson(config, `/v1/chat-connections/${encodeURIComponent(chatConnectionId)}`, { signal: abortSignal, method: "DELETE" });
31
+ },
32
+ };
33
+ }
@@ -35,6 +35,9 @@ export function createSessionsResource(config) {
35
35
  limit: options.limit,
36
36
  // Stryker disable next-line ConditionalExpression: URL serialization omits an undefined query value.
37
37
  ...(options.userId === undefined ? {} : { userId: options.userId }),
38
+ ...(options.byAgent === undefined
39
+ ? {}
40
+ : { byAgent: options.byAgent }),
38
41
  },
39
42
  }, latestSessionsListResponseSchema);
40
43
  },
@@ -1,4 +1,4 @@
1
- import { usageResponseSchema } from "../contracts/entities/usage.js";
1
+ import { usageOverviewResponseSchemaForQuery, usageResponseSchema, } from "../contracts/entities/usage.js";
2
2
  import { requestJson } from "../http.js";
3
3
  /**
4
4
  * `client.usage` — get over `/v1/usage` (tenant-wide) and
@@ -16,5 +16,8 @@ export function createUsageResource(config) {
16
16
  async getForAgent({ agentId, abortSignal, ...query }) {
17
17
  return await requestJson(config, `/v1/agents/${agentId}/usage`, { query, signal: abortSignal }, usageResponseSchema);
18
18
  },
19
+ async overview({ abortSignal, ...query } = {}) {
20
+ return await requestJson(config, "/v1/usage/overview", { query, signal: abortSignal }, usageOverviewResponseSchemaForQuery(query));
21
+ },
19
22
  };
20
23
  }
package/dist/types.d.ts CHANGED
@@ -3,6 +3,7 @@ import type { ApiErrorCode } from "./contracts/api.ts";
3
3
  import type { Agent, AgentsResponse, AgentVersion, AgentVersionsResponse, CreateAgentBody, UpdateAgentBody } from "./contracts/entities/agents.ts";
4
4
  import type { ArtifactDownloadUrlResponse, ArtifactListItem, ArtifactsListResponse } from "./contracts/entities/artifacts.ts";
5
5
  import type { BlazingAgentsChatMessageMetadata } from "./contracts/entities/chat.ts";
6
+ import type { ChatConnection, ChatConnectionsResponse, CreateChatConnectionBody, RotateChatConnectionBody, UpdateChatConnectionBody } from "./contracts/entities/chat-connections.ts";
6
7
  import type { CreateMcpConnectionBody, McpAttachmentResponse, McpAttachmentsResponse, McpConnectionOauthConnectResponse, McpConnectionReconnectResult, McpConnectionResponse, McpConnectionsResponse, McpConnectionTestResponse, ReconnectMcpConnectionBody, UpdateMcpAttachmentBody, UpdateMcpConnectionBody } from "./contracts/entities/mcp-connections.ts";
7
8
  import type { CreateMemoryBody, MemoriesListResponse, MemoryResponse, UpdateMemoryBody } from "./contracts/entities/memories.ts";
8
9
  import type { CreatePromptBody, PromptResponse, PromptsResponse, UpdatePromptBody } from "./contracts/entities/prompts.ts";
@@ -11,7 +12,7 @@ import type { DecideToolApprovalBody, LatestSessionsListResponse, SessionMessage
11
12
  import type { CreateSkillBody, SkillArchiveType, SkillCopyResults, SkillDetail, SkillsListResponse } from "./contracts/entities/skills.ts";
12
13
  import type { CreateTaskBody, CreateTaskResponse, CreateTaskRunBody, CreateTaskRunResponse, TaskResponse, TaskRunMessagesResponse, TaskRunResponse, TaskRunsListResponse, TasksListResponse, UpdateTaskBody } from "./contracts/entities/tasks.ts";
13
14
  import type { TenantSettingsResponse, UpdateTenantSettingsBody } from "./contracts/entities/tenants.ts";
14
- import type { UsageQuery, UsageResponse } from "./contracts/entities/usage.ts";
15
+ import type { UsageOverviewQuery, UsageOverviewResponse, UsageQuery, UsageResponse } from "./contracts/entities/usage.ts";
15
16
  import type { CreateWorkspaceBody, UpdateWorkspaceBody, Workspace, WorkspacesListResponse } from "./contracts/entities/workspaces.ts";
16
17
  export type KnownBlazingAgentsErrorCode = ApiErrorCode | "invalid_response" | "network_error" | "request_aborted" | "stream_error";
17
18
  export type BlazingAgentsErrorCode = KnownBlazingAgentsErrorCode | (string & {});
@@ -373,6 +374,7 @@ export interface SessionsListOptions extends ResourceRequestOptions {
373
374
  userId?: string;
374
375
  }
375
376
  export interface LatestSessionsListOptions extends ResourceRequestOptions {
377
+ byAgent?: boolean;
376
378
  cursor?: string;
377
379
  limit?: number;
378
380
  userId?: string;
@@ -402,9 +404,9 @@ export interface SessionsResource {
402
404
  agentId: string;
403
405
  } & SessionsListOptions): Promise<SessionsListResponse>;
404
406
  /**
405
- * `GET /v1/sessions/latest` — each Agent's most recently updated Session
406
- * across the Tenant, one item per Agent, newest first. `userId` narrows
407
- * the candidate Sessions to one end user's before picking the latest.
407
+ * `GET /v1/sessions/latest` — the Tenant's most recently updated Sessions,
408
+ * newest first. Set `byAgent` to return at most one Session per Agent.
409
+ * `userId` narrows the candidate Sessions to one end user's.
408
410
  */
409
411
  listLatest(input?: LatestSessionsListOptions): Promise<LatestSessionsListResponse>;
410
412
  messages(input: {
@@ -510,5 +512,32 @@ export interface UsageResource {
510
512
  getForAgent(input: Partial<UsageQuery> & {
511
513
  agentId: string;
512
514
  } & ResourceRequestOptions): Promise<UsageResponse>;
515
+ /** Returns totals, daily usage, and bounded Agent, user, and model rankings. */
516
+ overview(input?: Partial<UsageOverviewQuery> & ResourceRequestOptions): Promise<UsageOverviewResponse>;
517
+ }
518
+ export interface ChatConnectionsResource {
519
+ checkHealth(input: {
520
+ chatConnectionId: string;
521
+ } & ResourceRequestOptions): Promise<ChatConnection>;
522
+ create(input: CreateChatConnectionBody & ResourceRequestOptions): Promise<ChatConnection>;
523
+ delete(input: {
524
+ chatConnectionId: string;
525
+ } & ResourceRequestOptions): Promise<void>;
526
+ disable(input: {
527
+ chatConnectionId: string;
528
+ } & ResourceRequestOptions): Promise<ChatConnection>;
529
+ enable(input: {
530
+ chatConnectionId: string;
531
+ } & ResourceRequestOptions): Promise<ChatConnection>;
532
+ get(input: {
533
+ chatConnectionId: string;
534
+ } & ResourceRequestOptions): Promise<ChatConnection>;
535
+ list(input?: ResourceRequestOptions): Promise<ChatConnectionsResponse>;
536
+ rotateCredentials(input: RotateChatConnectionBody & {
537
+ chatConnectionId: string;
538
+ } & ResourceRequestOptions): Promise<ChatConnection>;
539
+ update(input: UpdateChatConnectionBody & {
540
+ chatConnectionId: string;
541
+ } & ResourceRequestOptions): Promise<ChatConnection>;
513
542
  }
514
543
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blazingagents/sdk",
3
- "version": "0.8.0",
3
+ "version": "0.9.1",
4
4
  "description": "TypeScript SDK for the Blazing Agents API",
5
5
  "homepage": "https://docs.blazingagents.com",
6
6
  "bugs": {