@blazingagents/sdk 0.21.0 → 0.23.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.
@@ -0,0 +1,5 @@
1
+ import { DefaultChatTransport, type UIMessage } from "ai";
2
+ export declare class ChatStreamTransport<UI_MESSAGE extends UIMessage = UIMessage> extends DefaultChatTransport<UI_MESSAGE> {
3
+ /** Native Chat rejects an update job for error chunks, so fail the stream before that job runs. */
4
+ protected processResponseStream(stream: ReadableStream<Uint8Array>): ReadableStream<any>;
5
+ }
@@ -0,0 +1,15 @@
1
+ import { DefaultChatTransport } from "ai";
2
+ export class ChatStreamTransport extends DefaultChatTransport {
3
+ /** Native Chat rejects an update job for error chunks, so fail the stream before that job runs. */
4
+ processResponseStream(stream) {
5
+ return super.processResponseStream(stream).pipeThrough(new TransformStream({
6
+ transform(chunk, controller) {
7
+ if (chunk.type === "error") {
8
+ controller.error(new Error(chunk.errorText));
9
+ return;
10
+ }
11
+ controller.enqueue(chunk);
12
+ },
13
+ }));
14
+ }
15
+ }
@@ -1,4 +1,5 @@
1
- import { DefaultChatTransport, lastAssistantMessageIsCompleteWithApprovalResponses, } from "ai";
1
+ import { lastAssistantMessageIsCompleteWithApprovalResponses, } from "ai";
2
+ import { ChatStreamTransport } from "./chat-stream-transport.js";
2
3
  import { sessionIdSchema } from "./contracts/ids.js";
3
4
  /**
4
5
  * Adapts AI SDK chat requests to the Blazing Agents backend-relay shape and
@@ -16,7 +17,7 @@ export class BlazingAgentsChatTransport {
16
17
  const transportFetch = transportOptions.fetch ?? globalThis.fetch;
17
18
  this.#sessionId =
18
19
  sessionId === undefined ? undefined : sessionIdSchema.parse(sessionId);
19
- this.#transport = new DefaultChatTransport({
20
+ this.#transport = new ChatStreamTransport({
20
21
  ...transportOptions,
21
22
  /** Reads the first Session ID from Location before returning the response. */
22
23
  fetch: async (input, init) => {
@@ -60,6 +60,7 @@ export declare const apiErrorCodeSchema: z.ZodEnum<{
60
60
  message_not_found: "message_not_found";
61
61
  model_discovery_unsupported: "model_discovery_unsupported";
62
62
  model_not_found: "model_not_found";
63
+ model_spending_limit_exceeded: "model_spending_limit_exceeded";
63
64
  model_validation_unavailable: "model_validation_unavailable";
64
65
  not_found: "not_found";
65
66
  prompt_variable_missing: "prompt_variable_missing";
@@ -143,6 +144,7 @@ export declare const apiErrorSchema: z.ZodObject<{
143
144
  message_not_found: "message_not_found";
144
145
  model_discovery_unsupported: "model_discovery_unsupported";
145
146
  model_not_found: "model_not_found";
147
+ model_spending_limit_exceeded: "model_spending_limit_exceeded";
146
148
  model_validation_unavailable: "model_validation_unavailable";
147
149
  not_found: "not_found";
148
150
  prompt_variable_missing: "prompt_variable_missing";
@@ -231,6 +233,7 @@ export declare const apiErrorResponseSchema: z.ZodObject<{
231
233
  message_not_found: "message_not_found";
232
234
  model_discovery_unsupported: "model_discovery_unsupported";
233
235
  model_not_found: "model_not_found";
236
+ model_spending_limit_exceeded: "model_spending_limit_exceeded";
234
237
  model_validation_unavailable: "model_validation_unavailable";
235
238
  not_found: "not_found";
236
239
  prompt_variable_missing: "prompt_variable_missing";
@@ -28,6 +28,7 @@ export const apiErrorCodeSchema = z.enum([
28
28
  "forbidden",
29
29
  "not_found",
30
30
  "quota_exceeded",
31
+ "model_spending_limit_exceeded",
31
32
  "subscription_required",
32
33
  "usage_credit_required",
33
34
  "rate_limited",
@@ -0,0 +1,101 @@
1
+ import { z } from "zod";
2
+ export declare const spendingLimitResetIntervalSchema: z.ZodEnum<{
3
+ biweekly: "biweekly";
4
+ daily: "daily";
5
+ monthly: "monthly";
6
+ weekly: "weekly";
7
+ }>;
8
+ export declare const spendingLimitSchema: z.ZodObject<{
9
+ amountUsd: z.ZodNumber;
10
+ resetStartDate: z.ZodISODate;
11
+ resetInterval: z.ZodEnum<{
12
+ biweekly: "biweekly";
13
+ daily: "daily";
14
+ monthly: "monthly";
15
+ weekly: "weekly";
16
+ }>;
17
+ }, z.core.$strict>;
18
+ export declare const updateSpendingLimitBodySchema: z.ZodObject<{
19
+ spendingLimit: z.ZodNullable<z.ZodObject<{
20
+ amountUsd: z.ZodNumber;
21
+ resetStartDate: z.ZodISODate;
22
+ resetInterval: z.ZodEnum<{
23
+ biweekly: "biweekly";
24
+ daily: "daily";
25
+ monthly: "monthly";
26
+ weekly: "weekly";
27
+ }>;
28
+ }, z.core.$strict>>;
29
+ }, z.core.$strict>;
30
+ export declare const spendingLimitPeriodSchema: z.ZodObject<{
31
+ startsAt: z.ZodISODateTime;
32
+ endsAt: z.ZodISODateTime;
33
+ spentUsd: z.ZodNumber;
34
+ reservedUsd: z.ZodNumber;
35
+ availableUsd: z.ZodNumber;
36
+ }, z.core.$strict>;
37
+ export declare const spendingLimitResponseSchema: z.ZodObject<{
38
+ spendingLimit: z.ZodNullable<z.ZodObject<{
39
+ amountUsd: z.ZodNumber;
40
+ resetStartDate: z.ZodISODate;
41
+ resetInterval: z.ZodEnum<{
42
+ biweekly: "biweekly";
43
+ daily: "daily";
44
+ monthly: "monthly";
45
+ weekly: "weekly";
46
+ }>;
47
+ }, z.core.$strict>>;
48
+ period: z.ZodNullable<z.ZodObject<{
49
+ startsAt: z.ZodISODateTime;
50
+ endsAt: z.ZodISODateTime;
51
+ spentUsd: z.ZodNumber;
52
+ reservedUsd: z.ZodNumber;
53
+ availableUsd: z.ZodNumber;
54
+ }, z.core.$strict>>;
55
+ nextResetAt: z.ZodNullable<z.ZodISODateTime>;
56
+ }, z.core.$strict>;
57
+ export declare const spendingLimitStopDetailsSchema: z.ZodObject<{
58
+ scope: z.ZodEnum<{
59
+ agent: "agent";
60
+ both: "both";
61
+ tenant: "tenant";
62
+ }>;
63
+ reason: z.ZodEnum<{
64
+ exhausted: "exhausted";
65
+ reserved: "reserved";
66
+ unknown_usage: "unknown_usage";
67
+ unpriced: "unpriced";
68
+ }>;
69
+ spentUsd: z.ZodNumber;
70
+ reservedUsd: z.ZodNumber;
71
+ availableUsd: z.ZodNumber;
72
+ nextResetAt: z.ZodNullable<z.ZodISODateTime>;
73
+ }, z.core.$strict>;
74
+ export type SpendingLimit = z.infer<typeof spendingLimitSchema>;
75
+ export type SpendingLimitResponse = z.infer<typeof spendingLimitResponseSchema>;
76
+ export type SpendingLimitStopDetails = z.infer<typeof spendingLimitStopDetailsSchema>;
77
+ export type UpdateSpendingLimitBody = z.infer<typeof updateSpendingLimitBodySchema>;
78
+ export declare function nextSpendingLimitReset(schedule: Pick<SpendingLimit, "resetStartDate" | "resetInterval">, after: string | Date): string;
79
+ export declare const spendingLimitStopEventSchema: z.ZodObject<{
80
+ type: z.ZodLiteral<"data-model-spending-limit">;
81
+ data: z.ZodObject<{
82
+ scope: z.ZodEnum<{
83
+ agent: "agent";
84
+ both: "both";
85
+ tenant: "tenant";
86
+ }>;
87
+ reason: z.ZodEnum<{
88
+ exhausted: "exhausted";
89
+ reserved: "reserved";
90
+ unknown_usage: "unknown_usage";
91
+ unpriced: "unpriced";
92
+ }>;
93
+ spentUsd: z.ZodNumber;
94
+ reservedUsd: z.ZodNumber;
95
+ availableUsd: z.ZodNumber;
96
+ nextResetAt: z.ZodNullable<z.ZodISODateTime>;
97
+ code: z.ZodLiteral<"model_spending_limit_exceeded">;
98
+ }, z.core.$strict>;
99
+ transient: z.ZodLiteral<true>;
100
+ }, z.core.$strict>;
101
+ export type SpendingLimitStopEvent = z.infer<typeof spendingLimitStopEventSchema>;
@@ -0,0 +1,79 @@
1
+ import { z } from "zod";
2
+ export const spendingLimitResetIntervalSchema = z.enum([
3
+ "daily",
4
+ "weekly",
5
+ "biweekly",
6
+ "monthly",
7
+ ]);
8
+ export const spendingLimitSchema = z
9
+ .object({
10
+ amountUsd: z.number().positive().max(1_000_000_000).multipleOf(0.000_001),
11
+ resetStartDate: z.iso.date(),
12
+ resetInterval: spendingLimitResetIntervalSchema,
13
+ })
14
+ .strict()
15
+ .meta({ id: "ModelSpendingLimit" });
16
+ export const updateSpendingLimitBodySchema = z
17
+ .object({
18
+ spendingLimit: spendingLimitSchema
19
+ .nullable()
20
+ .describe("Model-only USD allowance and UTC reset schedule. Set null to disable the limit."),
21
+ })
22
+ .strict();
23
+ export const spendingLimitPeriodSchema = z
24
+ .object({
25
+ startsAt: z.iso.datetime({ offset: true }),
26
+ endsAt: z.iso.datetime({ offset: true }),
27
+ spentUsd: z.number().nonnegative(),
28
+ reservedUsd: z.number().nonnegative(),
29
+ availableUsd: z.number().nonnegative(),
30
+ })
31
+ .strict();
32
+ export const spendingLimitResponseSchema = z
33
+ .object({
34
+ spendingLimit: spendingLimitSchema.nullable(),
35
+ period: spendingLimitPeriodSchema.nullable(),
36
+ nextResetAt: z.iso.datetime({ offset: true }).nullable(),
37
+ })
38
+ .strict()
39
+ .meta({ id: "ModelSpendingLimitStatus" });
40
+ export const spendingLimitStopDetailsSchema = z
41
+ .object({
42
+ scope: z.enum(["agent", "tenant", "both"]),
43
+ reason: z.enum(["exhausted", "reserved", "unpriced", "unknown_usage"]),
44
+ spentUsd: z.number().nonnegative(),
45
+ reservedUsd: z.number().nonnegative(),
46
+ availableUsd: z.number().nonnegative(),
47
+ nextResetAt: z.iso.datetime({ offset: true }).nullable(),
48
+ })
49
+ .strict();
50
+ export function nextSpendingLimitReset(schedule, after) {
51
+ const anchor = new Date(`${schedule.resetStartDate}T00:00:00.000Z`);
52
+ const instant = new Date(after).getTime();
53
+ if (anchor.getTime() > instant) {
54
+ return anchor.toISOString();
55
+ }
56
+ if (schedule.resetInterval !== "monthly") {
57
+ const days = { daily: 1, weekly: 7, biweekly: 14 }[schedule.resetInterval];
58
+ const interval = days * 86_400_000;
59
+ return new Date(anchor.getTime() +
60
+ (Math.floor((instant - anchor.getTime()) / interval) + 1) * interval).toISOString();
61
+ }
62
+ const current = new Date(instant);
63
+ let month = current.getUTCMonth();
64
+ const year = current.getUTCFullYear();
65
+ const boundary = () => new Date(Date.UTC(year, month, Math.min(anchor.getUTCDate(), new Date(Date.UTC(year, month + 1, 0)).getUTCDate())));
66
+ if (boundary().getTime() <= instant) {
67
+ month += 1;
68
+ }
69
+ return boundary().toISOString();
70
+ }
71
+ export const spendingLimitStopEventSchema = z
72
+ .object({
73
+ type: z.literal("data-model-spending-limit"),
74
+ data: spendingLimitStopDetailsSchema.extend({
75
+ code: z.literal("model_spending_limit_exceeded"),
76
+ }),
77
+ transient: z.literal(true),
78
+ })
79
+ .strict();
@@ -19,6 +19,8 @@ export { chatSteerConsumedEventSchema, sessionActivitySchema, sessionInputReques
19
19
  export type { ContinueToolApprovalsBody, SessionForkedFrom, ToolApprovalContinuationState, ToolApprovalDecision, ToolApprovalsResponse, } from "./entities/sessions.ts";
20
20
  export { continueToolApprovalsBodySchema, latestSessionListItemSchema, latestSessionsListResponseSchema, sessionForkedFromSchema, sessionListItemSchema, sessionMessageSchema, sessionMessagesResponseSchema, sessionResponseSchema, sessionsListResponseSchema, toolApprovalContinuationStateSchema, toolApprovalDecisionSchema, toolApprovalStateSchema, toolApprovalsResponseSchema, } from "./entities/sessions.ts";
21
21
  export { copySkillBodySchema, createSkillBodySchema, skillCopyResultsSchema, skillDetailSchema, skillsListResponseSchema, } from "./entities/skills.ts";
22
+ export type { SpendingLimit, SpendingLimitResponse, SpendingLimitStopDetails, SpendingLimitStopEvent, UpdateSpendingLimitBody, } from "./entities/spending-limits.ts";
23
+ export { nextSpendingLimitReset, spendingLimitPeriodSchema, spendingLimitResetIntervalSchema, spendingLimitResponseSchema, spendingLimitSchema, spendingLimitStopDetailsSchema, spendingLimitStopEventSchema, updateSpendingLimitBodySchema, } from "./entities/spending-limits.ts";
22
24
  export { createTaskBodySchema, createTaskResponseSchema, createTaskRunBodySchema, createTaskRunResponseSchema, taskCronConfigSchema, taskIntervalConfigSchema, taskListItemSchema, taskOnceConfigSchema, taskResponseSchema, taskRunMessagesResponseSchema, taskRunResponseSchema, taskRunSchema, taskRunStatusSchema, taskRunsListResponseSchema, taskScheduleInputSchema, taskScheduleKindSchema, taskSchema, tasksListResponseSchema, updateTaskBodySchema, } from "./entities/tasks.ts";
23
25
  export { quotaSchema, subscriptionStatusSchema, tenantDeletionSchema, tenantResponseSchema, tenantSchema, tenantSettingsResponseSchema, updateTenantSettingsBodySchema, } from "./entities/tenants.ts";
24
26
  export type { SessionUsageQuery, SessionUsageResponse, UsageBucket, UsageOverviewQuery, UsageOverviewResponse, UsageResponse, UsageTotals, } from "./entities/usage.ts";
@@ -16,6 +16,7 @@ export { createProviderBodySchema, providerListItemSchema, providerModelsRespons
16
16
  export { chatSteerConsumedEventSchema, sessionActivitySchema, sessionInputRequestIdSchema, sessionInputResponseSchema, sessionInputSchema, sessionInputStateSchema, sessionInputsQuerySchema, sessionInputsResponseSchema, stopSessionBodySchema, stopSessionResponseSchema, submitSessionInputBodySchema, } from "./entities/session-inputs.js";
17
17
  export { continueToolApprovalsBodySchema, latestSessionListItemSchema, latestSessionsListResponseSchema, sessionForkedFromSchema, sessionListItemSchema, sessionMessageSchema, sessionMessagesResponseSchema, sessionResponseSchema, sessionsListResponseSchema, toolApprovalContinuationStateSchema, toolApprovalDecisionSchema, toolApprovalStateSchema, toolApprovalsResponseSchema, } from "./entities/sessions.js";
18
18
  export { copySkillBodySchema, createSkillBodySchema, skillCopyResultsSchema, skillDetailSchema, skillsListResponseSchema, } from "./entities/skills.js";
19
+ export { nextSpendingLimitReset, spendingLimitPeriodSchema, spendingLimitResetIntervalSchema, spendingLimitResponseSchema, spendingLimitSchema, spendingLimitStopDetailsSchema, spendingLimitStopEventSchema, updateSpendingLimitBodySchema, } from "./entities/spending-limits.js";
19
20
  export { createTaskBodySchema, createTaskResponseSchema, createTaskRunBodySchema, createTaskRunResponseSchema, taskCronConfigSchema, taskIntervalConfigSchema, taskListItemSchema, taskOnceConfigSchema, taskResponseSchema, taskRunMessagesResponseSchema, taskRunResponseSchema, taskRunSchema, taskRunStatusSchema, taskRunsListResponseSchema, taskScheduleInputSchema, taskScheduleKindSchema, taskSchema, tasksListResponseSchema, updateTaskBodySchema, } from "./entities/tasks.js";
20
21
  export { quotaSchema, subscriptionStatusSchema, tenantDeletionSchema, tenantResponseSchema, tenantSchema, tenantSettingsResponseSchema, updateTenantSettingsBodySchema, } from "./entities/tenants.js";
21
22
  export { sessionUsageQuerySchema, sessionUsageResponseSchema, usageOverviewQuerySchema, usageOverviewResponseSchema, usageResponseSchema, } from "./entities/usage.js";
@@ -1,4 +1,5 @@
1
- import { type ChatTransport, DefaultChatTransport, type UIMessage } from "ai";
1
+ import { type ChatTransport, type UIMessage } from "ai";
2
+ import { ChatStreamTransport } from "./chat-stream-transport.ts";
2
3
  import type { BlazingAgents } from "./client.ts";
3
4
  import type { ChatFunctions } from "./functions.ts";
4
5
  export type BlazingAgentsDirectChatTransportOptions = {
@@ -26,7 +27,7 @@ export type BlazingAgentsDirectChatTransportOptions = {
26
27
  variables?: never;
27
28
  });
28
29
  /** Connects useChat directly to the SDK, including native streaming fetch clients. */
29
- export declare class BlazingAgentsDirectChatTransport<UI_MESSAGE extends UIMessage = UIMessage> extends DefaultChatTransport<UI_MESSAGE> {
30
+ export declare class BlazingAgentsDirectChatTransport<UI_MESSAGE extends UIMessage = UIMessage> extends ChatStreamTransport<UI_MESSAGE> {
30
31
  #private;
31
32
  /**
32
33
  * Creates a chat transport and validates any supplied Session ID.
@@ -41,13 +42,13 @@ export declare class BlazingAgentsDirectChatTransport<UI_MESSAGE extends UIMessa
41
42
  sendUserMessages(input: {
42
43
  messages: UI_MESSAGE[];
43
44
  abortSignal?: AbortSignal;
44
- }): Promise<ReadableStream<import("ai").UIMessageChunk<unknown, import("ai").UIDataTypes>>>;
45
+ }): Promise<ReadableStream<any>>;
45
46
  /**
46
47
  * Submits the latest user message or complete assistant approval round to the chat.
47
48
  * @param input - Operation input and optional cancellation signal.
48
49
  * @returns The decoded AI SDK message-chunk stream.
49
50
  */
50
- sendMessages(input: Parameters<ChatTransport<UI_MESSAGE>["sendMessages"]>[0]): Promise<ReadableStream<import("ai").UIMessageChunk<unknown, import("ai").UIDataTypes>>>;
51
+ sendMessages(input: Parameters<ChatTransport<UI_MESSAGE>["sendMessages"]>[0]): Promise<ReadableStream<any>>;
51
52
  /**
52
53
  * Returns null because reconnecting to an existing stream is unsupported.
53
54
  * @param _input - Unused reconnect request.
@@ -1,8 +1,9 @@
1
- import { DefaultChatTransport, lastAssistantMessageIsCompleteWithApprovalResponses, } from "ai";
1
+ import { lastAssistantMessageIsCompleteWithApprovalResponses, } from "ai";
2
2
  import { extractApprovalDecisions } from "./approvals.js";
3
+ import { ChatStreamTransport } from "./chat-stream-transport.js";
3
4
  import { sessionIdSchema } from "./contracts/ids.js";
4
5
  /** Connects useChat directly to the SDK, including native streaming fetch clients. */
5
- export class BlazingAgentsDirectChatTransport extends DefaultChatTransport {
6
+ export class BlazingAgentsDirectChatTransport extends ChatStreamTransport {
6
7
  #options;
7
8
  #sessionId;
8
9
  /**
package/dist/index.d.ts CHANGED
@@ -19,10 +19,12 @@ export type { ChatSteerConsumedEvent, SessionActivity, SessionInput, SessionInpu
19
19
  export type { ContinueToolApprovalsBody, SessionForkedFrom, SessionResponse, ToolApprovalDecision, ToolApprovalState, ToolApprovalsResponse, } from "./contracts/entities/sessions.ts";
20
20
  export { sessionResponseSchema } from "./contracts/entities/sessions.ts";
21
21
  export type { CreateSkillBody, Skill, SkillArchiveType, SkillCopyResult, SkillCopyResults, SkillDetail, SkillFile, SkillsListResponse, } from "./contracts/entities/skills.ts";
22
+ export type { SpendingLimit, SpendingLimitResponse, SpendingLimitStopDetails, SpendingLimitStopEvent, UpdateSpendingLimitBody, } from "./contracts/entities/spending-limits.ts";
23
+ export { nextSpendingLimitReset } from "./contracts/entities/spending-limits.ts";
22
24
  export type { SessionUsageQuery, SessionUsageResponse, UsageBucket, UsageOverviewQuery, UsageOverviewResponse, UsageTotals, } from "./contracts/entities/usage.ts";
23
25
  export type { CreateWorkspaceBody, UpdateWorkspaceBody, Workspace, WorkspaceNetworkPolicy, WorkspacesListResponse, WorkspaceTier, } from "./contracts/entities/workspaces.ts";
24
26
  export { BlazingAgentsDirectChatTransport, type BlazingAgentsDirectChatTransportOptions, } from "./direct-chat-transport.ts";
25
27
  export { BlazingAgentsError } from "./errors.ts";
26
28
  export { type ChatFunction, type ChatFunctionContext, type ChatFunctions, defineFunction, } from "./functions.ts";
27
29
  export { createChatRelay, createCompletionRelay, type RelayContext, type SessionOwnershipStore, } from "./relay.ts";
28
- export type { AgentClient, AgentSkillsResource, AgentsListOptions, AgentsResource, ArtifactsResource, AttributionInput, BlazingAgentsErrorCode, BlazingAgentsOptions, BlazingAgentsRequestOptions, BlazingAgentsUIMessage, BlazingAgentsUIMessageChunk, ChatConnectionsResource, ChatDeliveriesListOptions, ChatDeliveriesResource, ChatInput, ChatMessageInput, ChatMessagesInput, ChatPromptInput, ChatResult, ChatTrigger, CompletionInput, CompletionPromptIdInput, CompletionPromptInput, CompletionResult, ContinueChatInput, KnownBlazingAgentsErrorCode, LatestSessionsListOptions, McpConnectionsResource, MemoriesListOptions, MemoriesResource, MerchantBindingsListOptions, MerchantBindingsResource, MerchantConnectionResource, MerchantUsageEventsListOptions, MerchantUsageEventsResource, ObjectInput, ObjectPromptIdInput, ObjectPromptInput, ObjectResult, PromptsResource, ProvidersResource, ResourceRequestOptions, ResponseObservation, SessionsResource, SkillsListOptions, TasksResource, TenantResource, TerminalStreamResult, UsageResource, UserClient, WorkspacesListOptions, WorkspacesResource, } from "./types.ts";
30
+ export type { AgentClient, AgentSkillsResource, AgentsListOptions, AgentsResource, ArtifactsResource, AttributionInput, BlazingAgentsErrorCode, BlazingAgentsOptions, BlazingAgentsRequestOptions, BlazingAgentsUIMessage, BlazingAgentsUIMessageChunk, BlazingAgentsUIMessageData, ChatConnectionsResource, ChatDeliveriesListOptions, ChatDeliveriesResource, ChatInput, ChatMessageInput, ChatMessagesInput, ChatPromptInput, ChatResult, ChatTrigger, CompletionInput, CompletionPromptIdInput, CompletionPromptInput, CompletionResult, ContinueChatInput, KnownBlazingAgentsErrorCode, LatestSessionsListOptions, McpConnectionsResource, MemoriesListOptions, MemoriesResource, MerchantBindingsListOptions, MerchantBindingsResource, MerchantConnectionResource, MerchantUsageEventsListOptions, MerchantUsageEventsResource, ObjectInput, ObjectPromptIdInput, ObjectPromptInput, ObjectResult, PromptsResource, ProvidersResource, ResourceRequestOptions, ResponseObservation, SessionsResource, SkillsListOptions, TasksResource, TenantResource, TerminalStreamResult, UsageResource, UserClient, WorkspacesListOptions, WorkspacesResource, } from "./types.ts";
package/dist/index.js CHANGED
@@ -8,6 +8,7 @@ export { BlazingAgentsChatTransport, } from "./chat-transport.js";
8
8
  export { BlazingAgents } from "./client.js";
9
9
  export { agentConfigSchema } from "./contracts/entities/agents.js";
10
10
  export { sessionResponseSchema } from "./contracts/entities/sessions.js";
11
+ export { nextSpendingLimitReset } from "./contracts/entities/spending-limits.js";
11
12
  export { BlazingAgentsDirectChatTransport, } from "./direct-chat-transport.js";
12
13
  export { BlazingAgentsError } from "./errors.js";
13
14
  export { defineFunction, } from "./functions.js";
@@ -1,5 +1,6 @@
1
1
  import { agentResponseSchema, agentsResponseSchema, } from "../contracts/entities/agents.js";
2
2
  import { mcpAttachmentResponseSchema, mcpAttachmentsResponseSchema, } from "../contracts/entities/mcp-connections.js";
3
+ import { spendingLimitResponseSchema } from "../contracts/entities/spending-limits.js";
3
4
  import { requestJson } from "../http.js";
4
5
  /**
5
6
  * Builds the Agents operations using the shared HTTP configuration.
@@ -16,6 +17,14 @@ export function createAgentsResource(config) {
16
17
  method: "PUT",
17
18
  }, agentResponseSchema);
18
19
  return {
20
+ /** Retrieves the model spending limit using tenant authority. */
21
+ async getSpendingLimit({ agentId, abortSignal }) {
22
+ return await requestJson(config, `/v1/agents/${agentId}/spending-limit`, { signal: abortSignal }, spendingLimitResponseSchema);
23
+ },
24
+ /** Sets the model spending limit. Null disables it. Requires tenant authority. */
25
+ async updateSpendingLimit({ agentId, abortSignal, ...body }) {
26
+ return await requestJson(config, `/v1/agents/${agentId}/spending-limit`, { method: "PUT", json: body, signal: abortSignal }, spendingLimitResponseSchema);
27
+ },
19
28
  /**
20
29
  * Creates agents.
21
30
  */
@@ -1,3 +1,4 @@
1
+ import { spendingLimitResponseSchema } from "../contracts/entities/spending-limits.js";
1
2
  import { tenantSettingsResponseSchema } from "../contracts/entities/tenants.js";
2
3
  import { requestJson } from "../http.js";
3
4
  /**
@@ -8,6 +9,14 @@ import { requestJson } from "../http.js";
8
9
  */
9
10
  export function createTenantResource(config) {
10
11
  return {
12
+ /** Retrieves the model spending limit using tenant authority. */
13
+ async getSpendingLimit({ abortSignal } = {}) {
14
+ return await requestJson(config, "/v1/tenant/spending-limit", { signal: abortSignal }, spendingLimitResponseSchema);
15
+ },
16
+ /** Sets the model spending limit. Null disables it. Requires tenant authority. */
17
+ async updateSpendingLimit({ abortSignal, ...body }) {
18
+ return await requestJson(config, "/v1/tenant/spending-limit", { method: "PUT", json: body, signal: abortSignal }, spendingLimitResponseSchema);
19
+ },
11
20
  /**
12
21
  * Retrieves tenant.
13
22
  */
package/dist/types.d.ts CHANGED
@@ -9,9 +9,10 @@ import type { CreateMemoryBody, MemoriesListResponse, MemoryResponse, UpdateMemo
9
9
  import type { CreateMerchantConnectionBody, MerchantBindingResponse, MerchantBindingsResponse, MerchantConnectionResponse, MerchantUsageEventResponse, MerchantUsageEventStatus, MerchantUsageEventsResponse, MerchantUsageSummaryResponse, UpdateMerchantConnectionBody, UpsertMerchantBindingBody } from "./contracts/entities/merchant.ts";
10
10
  import type { CreatePromptBody, PromptResponse, PromptsResponse, UpdatePromptBody } from "./contracts/entities/prompts.ts";
11
11
  import type { CreateProviderBody, DeleteProviderOptions, ProviderModelsResponse, ProviderResponse, ProvidersResponse, ThinkingLevelsResponse, UpdateProviderBody } from "./contracts/entities/providers.ts";
12
- import type { SessionInputResponse, SessionInputsQuery, SessionInputsResponse, StopSessionBody, StopSessionResponse, SubmitSessionInputBody } from "./contracts/entities/session-inputs.ts";
12
+ import type { ChatSteerConsumedEvent, SessionInputResponse, SessionInputsQuery, SessionInputsResponse, StopSessionBody, StopSessionResponse, SubmitSessionInputBody } from "./contracts/entities/session-inputs.ts";
13
13
  import type { LatestSessionsListResponse, SessionMessagesResponse, SessionResponse, SessionsListResponse, ToolApprovalDecision, ToolApprovalsResponse } from "./contracts/entities/sessions.ts";
14
14
  import type { CreateSkillBody, SkillArchiveType, SkillCopyResults, SkillDetail, SkillsListResponse } from "./contracts/entities/skills.ts";
15
+ import type { SpendingLimitResponse, SpendingLimitStopEvent, UpdateSpendingLimitBody } from "./contracts/entities/spending-limits.ts";
15
16
  import type { CreateTaskBody, CreateTaskResponse, CreateTaskRunBody, CreateTaskRunResponse, TaskResponse, TaskRunMessagesResponse, TaskRunResponse, TaskRunsListResponse, TasksListResponse, UpdateTaskBody } from "./contracts/entities/tasks.ts";
16
17
  import type { TenantSettingsResponse, UpdateTenantSettingsBody } from "./contracts/entities/tenants.ts";
17
18
  import type { SessionUsageQuery, SessionUsageResponse, UsageOverviewQuery, UsageOverviewResponse, UsageQuery, UsageResponse } from "./contracts/entities/usage.ts";
@@ -117,8 +118,9 @@ export interface ResponseObservation {
117
118
  status: number;
118
119
  }
119
120
  export type ChatTrigger = "submit-message" | "regenerate-message";
120
- export type BlazingAgentsUIMessage = UIMessage<BlazingAgentsChatMessageMetadata>;
121
- export type BlazingAgentsUIMessageChunk = UIMessageChunk<BlazingAgentsChatMessageMetadata>;
121
+ export type BlazingAgentsUIMessageData = Record<"ba-steer-consumed", ChatSteerConsumedEvent["data"]> & Record<"model-spending-limit", SpendingLimitStopEvent["data"]>;
122
+ export type BlazingAgentsUIMessage = UIMessage<BlazingAgentsChatMessageMetadata, BlazingAgentsUIMessageData>;
123
+ export type BlazingAgentsUIMessageChunk = UIMessageChunk<BlazingAgentsChatMessageMetadata, BlazingAgentsUIMessageData>;
122
124
  /**
123
125
  * End-user attribution (ADR-0001) carried on every generation request.
124
126
  * `userId` defaults to `''` (tenant-level) server-side; `metadata` is an
@@ -319,6 +321,10 @@ export interface AgentsResource {
319
321
  get(input: {
320
322
  agentId: string;
321
323
  } & ResourceRequestOptions): Promise<Agent>;
324
+ /** Retrieves the Agent model spending limit. Requires tenant authority. */
325
+ getSpendingLimit(input: {
326
+ agentId: string;
327
+ } & ResourceRequestOptions): Promise<SpendingLimitResponse>;
322
328
  /**
323
329
  * Lists available Agent records.
324
330
  * @param input - filters and pagination options.
@@ -363,6 +369,10 @@ export interface AgentsResource {
363
369
  agentId: string;
364
370
  mcpConnectionId: string;
365
371
  } & ResourceRequestOptions): Promise<McpAttachmentResponse>;
372
+ /** Sets the Agent model spending limit. Pass null to disable it. Requires tenant authority. */
373
+ updateSpendingLimit(input: UpdateSpendingLimitBody & {
374
+ agentId: string;
375
+ } & ResourceRequestOptions): Promise<SpendingLimitResponse>;
366
376
  /**
367
377
  * Uploads an Agent avatar as multipart form data.
368
378
  * @param input - Target `agentId`, image `file`, and optional abortSignal.
@@ -1033,6 +1043,8 @@ export interface TenantResource {
1033
1043
  * @throws BlazingAgentsError - If the request fails, is aborted, or returns an invalid response.
1034
1044
  */
1035
1045
  get(input?: ResourceRequestOptions): Promise<TenantSettingsResponse>;
1046
+ /** Retrieves the tenant model spending limit. Requires tenant authority. */
1047
+ getSpendingLimit(input?: ResourceRequestOptions): Promise<SpendingLimitResponse>;
1036
1048
  /**
1037
1049
  * Updates Tenant settings.
1038
1050
  * @param input - fields to change; optional abortSignal.
@@ -1040,6 +1052,8 @@ export interface TenantResource {
1040
1052
  * @throws BlazingAgentsError - If the request fails, is aborted, or returns an invalid response.
1041
1053
  */
1042
1054
  patch(input: UpdateTenantSettingsBody & ResourceRequestOptions): Promise<TenantSettingsResponse>;
1055
+ /** Sets the tenant model spending limit. Pass null to disable it. Requires tenant authority. */
1056
+ updateSpendingLimit(input: UpdateSpendingLimitBody & ResourceRequestOptions): Promise<SpendingLimitResponse>;
1043
1057
  }
1044
1058
  export interface UsageResource {
1045
1059
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blazingagents/sdk",
3
- "version": "0.21.0",
3
+ "version": "0.23.0",
4
4
  "description": "TypeScript SDK for the Blazing Agents API",
5
5
  "homepage": "https://docs.blazingagents.com",
6
6
  "bugs": {