@blazingagents/sdk 0.20.0 → 0.21.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 (83) hide show
  1. package/dist/approvals.d.ts +4 -0
  2. package/dist/approvals.js +4 -0
  3. package/dist/chat-transport.d.ts +18 -1
  4. package/dist/chat-transport.js +16 -0
  5. package/dist/client.d.ts +24 -1
  6. package/dist/client.js +33 -1
  7. package/dist/contracts/api.d.ts +34 -0
  8. package/dist/contracts/api.js +28 -0
  9. package/dist/contracts/entities/agent-tools.d.ts +5 -2
  10. package/dist/contracts/entities/agent-tools.js +5 -2
  11. package/dist/contracts/entities/agents.d.ts +4 -0
  12. package/dist/contracts/entities/agents.js +9 -0
  13. package/dist/contracts/entities/chat.d.ts +3 -0
  14. package/dist/contracts/entities/chat.js +6 -0
  15. package/dist/contracts/entities/mcp-connections.d.ts +3 -1
  16. package/dist/contracts/entities/mcp-connections.js +3 -1
  17. package/dist/contracts/entities/prompts.d.ts +13 -0
  18. package/dist/contracts/entities/prompts.js +13 -0
  19. package/dist/contracts/entities/session-inputs.js +3 -1
  20. package/dist/contracts/entities/sessions.d.ts +11 -0
  21. package/dist/contracts/entities/sessions.js +11 -1
  22. package/dist/contracts/entities/skills.d.ts +3 -0
  23. package/dist/contracts/entities/skills.js +3 -0
  24. package/dist/contracts/entities/tasks.d.ts +1 -0
  25. package/dist/contracts/entities/usage.d.ts +4 -1
  26. package/dist/contracts/entities/usage.js +7 -1
  27. package/dist/contracts/entities/workspaces.d.ts +17 -6
  28. package/dist/contracts/entities/workspaces.js +3 -7
  29. package/dist/contracts/ids.d.ts +31 -0
  30. package/dist/contracts/ids.js +34 -0
  31. package/dist/contracts/index.d.ts +4 -3
  32. package/dist/contracts/index.js +2 -2
  33. package/dist/contracts/utils.d.ts +10 -0
  34. package/dist/contracts/utils.js +10 -0
  35. package/dist/direct-chat-transport.d.ts +27 -1
  36. package/dist/direct-chat-transport.js +26 -0
  37. package/dist/errors.d.ts +9 -0
  38. package/dist/errors.js +9 -0
  39. package/dist/functions.d.ts +35 -2
  40. package/dist/functions.js +60 -4
  41. package/dist/generation.d.ts +32 -0
  42. package/dist/generation.js +83 -0
  43. package/dist/http.d.ts +26 -0
  44. package/dist/http.js +43 -0
  45. package/dist/index.d.ts +2 -2
  46. package/dist/relay.d.ts +23 -0
  47. package/dist/relay.js +16 -0
  48. package/dist/resources/agents.d.ts +5 -0
  49. package/dist/resources/agents.js +38 -0
  50. package/dist/resources/artifacts.d.ts +2 -0
  51. package/dist/resources/artifacts.js +14 -0
  52. package/dist/resources/chat-connections.d.ts +5 -0
  53. package/dist/resources/chat-connections.js +32 -0
  54. package/dist/resources/chat-deliveries.d.ts +2 -0
  55. package/dist/resources/chat-deliveries.js +5 -0
  56. package/dist/resources/mcp-connections.d.ts +5 -0
  57. package/dist/resources/mcp-connections.js +26 -0
  58. package/dist/resources/memories.d.ts +2 -0
  59. package/dist/resources/memories.js +17 -0
  60. package/dist/resources/merchant-bindings.d.ts +2 -0
  61. package/dist/resources/merchant-bindings.js +11 -0
  62. package/dist/resources/merchant-connection.d.ts +2 -0
  63. package/dist/resources/merchant-connection.js +14 -0
  64. package/dist/resources/merchant-usage-events.d.ts +2 -0
  65. package/dist/resources/merchant-usage-events.js +20 -0
  66. package/dist/resources/prompts.d.ts +5 -0
  67. package/dist/resources/prompts.js +20 -0
  68. package/dist/resources/providers.d.ts +2 -0
  69. package/dist/resources/providers.js +23 -0
  70. package/dist/resources/sessions.d.ts +2 -0
  71. package/dist/resources/sessions.js +40 -0
  72. package/dist/resources/skills.d.ts +5 -0
  73. package/dist/resources/skills.js +35 -0
  74. package/dist/resources/tasks.d.ts +2 -0
  75. package/dist/resources/tasks.js +32 -0
  76. package/dist/resources/tenant.d.ts +2 -0
  77. package/dist/resources/tenant.js +8 -0
  78. package/dist/resources/usage.d.ts +2 -0
  79. package/dist/resources/usage.js +14 -0
  80. package/dist/resources/workspaces.d.ts +5 -0
  81. package/dist/resources/workspaces.js +20 -0
  82. package/dist/types.d.ts +679 -10
  83. package/package.json +1 -1
@@ -19,7 +19,9 @@ export const sessionInputSchema = z
19
19
  .object({
20
20
  requestId: sessionInputRequestIdSchema,
21
21
  sequence: z.number().int().positive(),
22
- message: sessionMessageSchema.extend({ role: z.literal("user") }),
22
+ message: sessionMessageSchema
23
+ .omit({ branchable: true })
24
+ .extend({ role: z.literal("user") }),
23
25
  state: sessionInputStateSchema,
24
26
  turnId: turnIdSchema,
25
27
  createdAt: z.iso.datetime({ offset: true }),
@@ -24,6 +24,10 @@ export declare const sessionsListResponseSchema: z.ZodObject<{
24
24
  }, z.core.$strip>>;
25
25
  nextCursor: z.ZodNullable<z.ZodString>;
26
26
  }, z.core.$strip>;
27
+ export declare const sessionForkedFromSchema: z.ZodObject<{
28
+ sessionId: z.ZodString;
29
+ messageId: z.ZodString;
30
+ }, z.core.$strip>;
27
31
  export declare const sessionResponseSchema: z.ZodObject<{
28
32
  id: z.ZodString;
29
33
  messageCount: z.ZodNumber;
@@ -127,6 +131,10 @@ export declare const sessionResponseSchema: z.ZodObject<{
127
131
  metadata: z.ZodRecord<z.ZodString, z.ZodUnknown>;
128
132
  mcpConnectionIds: z.ZodArray<z.ZodString>;
129
133
  }, z.core.$strip>;
134
+ forkedFrom: z.ZodNullable<z.ZodObject<{
135
+ sessionId: z.ZodString;
136
+ messageId: z.ZodString;
137
+ }, z.core.$strip>>;
130
138
  }, z.core.$strip>;
131
139
  /**
132
140
  * `GET /v1/sessions/latest` list item — one per Agent: the Agent's most
@@ -181,6 +189,7 @@ export declare const sessionMessageSchema: z.ZodObject<{
181
189
  system: "system";
182
190
  user: "user";
183
191
  }>;
192
+ branchable: z.ZodBoolean;
184
193
  parts: z.ZodArray<z.ZodObject<{
185
194
  type: z.ZodString;
186
195
  }, z.core.$loose>>;
@@ -203,6 +212,7 @@ export declare const sessionMessagesResponseSchema: z.ZodObject<{
203
212
  system: "system";
204
213
  user: "user";
205
214
  }>;
215
+ branchable: z.ZodBoolean;
206
216
  parts: z.ZodArray<z.ZodObject<{
207
217
  type: z.ZodString;
208
218
  }, z.core.$loose>>;
@@ -342,6 +352,7 @@ export declare const continueToolApprovalsBodySchema: z.ZodObject<{
342
352
  }, z.core.$strict>>>;
343
353
  }, z.core.$strict>;
344
354
  export type SessionListItem = z.infer<typeof sessionListItemSchema>;
355
+ export type SessionForkedFrom = z.infer<typeof sessionForkedFromSchema>;
345
356
  export type SessionResponse = z.infer<typeof sessionResponseSchema>;
346
357
  export type SessionsListResponse = z.infer<typeof sessionsListResponseSchema>;
347
358
  export type LatestSessionListItem = z.infer<typeof latestSessionListItemSchema>;
@@ -22,8 +22,17 @@ export const sessionListItemSchema = z
22
22
  })
23
23
  .strip();
24
24
  export const sessionsListResponseSchema = paginatedResponseSchema(sessionListItemSchema);
25
+ export const sessionForkedFromSchema = z
26
+ .object({
27
+ sessionId: sessionIdSchema,
28
+ messageId: z.string().min(1),
29
+ })
30
+ .strip();
25
31
  export const sessionResponseSchema = sessionListItemSchema
26
- .extend({ agentConfig: agentConfigSchema })
32
+ .extend({
33
+ agentConfig: agentConfigSchema,
34
+ forkedFrom: sessionForkedFromSchema.nullable(),
35
+ })
27
36
  .strip();
28
37
  /**
29
38
  * `GET /v1/sessions/latest` list item — one per Agent: the Agent's most
@@ -49,6 +58,7 @@ export const sessionMessageSchema = z
49
58
  .object({
50
59
  id: z.string().min(1),
51
60
  role: z.enum(["system", "user", "assistant"]),
61
+ branchable: z.boolean(),
52
62
  parts: z
53
63
  .array(z
54
64
  .object({
@@ -151,6 +151,9 @@ export interface SkillMarkdownFrontmatterParseFailure {
151
151
  success: false;
152
152
  }
153
153
  export type SkillMarkdownFrontmatterParseResult = SkillMarkdownFrontmatterParseSuccess | SkillMarkdownFrontmatterParseFailure;
154
+ /**
155
+ * Parses and validates YAML frontmatter from Skill Markdown.
156
+ */
154
157
  export declare function parseSkillMarkdownFrontmatter(content: string): SkillMarkdownFrontmatterParseResult;
155
158
  export type Skill = z.infer<typeof skillSchema>;
156
159
  export type SkillDetail = z.infer<typeof skillDetailSchema>;
@@ -126,6 +126,9 @@ export const skillCopyResultSchema = z.discriminatedUnion("status", [
126
126
  ]);
127
127
  export const skillCopyResultsSchema = z.array(skillCopyResultSchema);
128
128
  const frontmatterPattern = /^---\n([\s\S]*?)\n---(?:\n|$)/;
129
+ /**
130
+ * Parses and validates YAML frontmatter from Skill Markdown.
131
+ */
129
132
  export function parseSkillMarkdownFrontmatter(content) {
130
133
  const normalized = content.replaceAll("\r\n", "\n");
131
134
  const match = frontmatterPattern.exec(normalized);
@@ -716,6 +716,7 @@ export declare const taskRunMessagesResponseSchema: z.ZodObject<{
716
716
  system: "system";
717
717
  user: "user";
718
718
  }>;
719
+ branchable: z.ZodBoolean;
719
720
  parts: z.ZodArray<z.ZodObject<{
720
721
  type: z.ZodString;
721
722
  }, z.core.$loose>>;
@@ -175,7 +175,10 @@ export declare const usageOverviewResponseSchema: z.ZodObject<{
175
175
  }, z.core.$strip>>;
176
176
  activeAgentCount: z.ZodNumber;
177
177
  }, z.core.$strip>;
178
- /** Applies the request-dependent ranking and daily-series guarantees. */
178
+ /**
179
+ * Applies the request-dependent ranking and daily-series guarantees.
180
+ * @param query - Ranking limit and date range used to validate the response.
181
+ */
179
182
  export declare function usageOverviewResponseSchemaForQuery(query?: Partial<UsageOverviewQuery>): z.ZodObject<{
180
183
  totals: z.ZodObject<{
181
184
  inputTokens: z.ZodNumber;
@@ -3,6 +3,9 @@ import { agentIdSchema, sessionIdSchema } from "../ids.js";
3
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 { hasUniqueValues } from "../utils.js";
5
5
  import { userIdSchema } from "./attribution.js";
6
+ /**
7
+ * Adds a validation issue when the usage date range is invalid.
8
+ */
6
9
  function validateUsageRange(value, ctx) {
7
10
  if ((value.from === undefined) !== (value.to === undefined)) {
8
11
  ctx.addIssue({
@@ -185,7 +188,10 @@ export const usageOverviewResponseSchema = z
185
188
  });
186
189
  }
187
190
  });
188
- /** Applies the request-dependent ranking and daily-series guarantees. */
191
+ /**
192
+ * Applies the request-dependent ranking and daily-series guarantees.
193
+ * @param query - Ranking limit and date range used to validate the response.
194
+ */
189
195
  export function usageOverviewResponseSchemaForQuery(query = {}) {
190
196
  const limit = query.limit ?? DEFAULT_USAGE_OVERVIEW_TOP_N;
191
197
  const expectedDays = query.from && query.to
@@ -1,10 +1,9 @@
1
1
  import { z } from "zod";
2
2
  export declare const workspaceNameSchema: z.ZodString;
3
- export declare const workspaceBackupSchema: z.ZodObject<{
4
- dir: z.ZodLiteral<"/workspace">;
5
- id: z.ZodUUID;
6
- localBucket: z.ZodOptional<z.ZodBoolean>;
7
- }, z.core.$strict>;
3
+ export declare const workspaceTierSchema: z.ZodEnum<{
4
+ core: "core";
5
+ plus: "plus";
6
+ }>;
8
7
  export declare const workspaceNetworkPolicySchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
9
8
  mode: z.ZodLiteral<"unrestricted">;
10
9
  }, z.core.$strict>, z.ZodObject<{
@@ -16,6 +15,10 @@ export declare const workspaceNetworkPolicySchema: z.ZodDiscriminatedUnion<[z.Zo
16
15
  export declare const workspaceSchema: z.ZodObject<{
17
16
  id: z.ZodString;
18
17
  tenantId: z.ZodString;
18
+ tier: z.ZodEnum<{
19
+ core: "core";
20
+ plus: "plus";
21
+ }>;
19
22
  name: z.ZodNullable<z.ZodString>;
20
23
  userId: z.ZodString;
21
24
  metadata: z.ZodRecord<z.ZodString, z.ZodUnknown>;
@@ -32,6 +35,10 @@ export declare const workspaceSchema: z.ZodObject<{
32
35
  }, z.core.$strip>;
33
36
  export declare const createWorkspaceBodySchema: z.ZodObject<{
34
37
  name: z.ZodOptional<z.ZodString>;
38
+ tier: z.ZodDefault<z.ZodEnum<{
39
+ core: "core";
40
+ plus: "plus";
41
+ }>>;
35
42
  userId: z.ZodDefault<z.ZodString>;
36
43
  metadata: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
37
44
  networkPolicy: z.ZodDefault<z.ZodDiscriminatedUnion<[z.ZodObject<{
@@ -64,6 +71,10 @@ export declare const workspacesListResponseSchema: z.ZodObject<{
64
71
  data: z.ZodArray<z.ZodObject<{
65
72
  id: z.ZodString;
66
73
  tenantId: z.ZodString;
74
+ tier: z.ZodEnum<{
75
+ core: "core";
76
+ plus: "plus";
77
+ }>;
67
78
  name: z.ZodNullable<z.ZodString>;
68
79
  userId: z.ZodString;
69
80
  metadata: z.ZodRecord<z.ZodString, z.ZodUnknown>;
@@ -81,7 +92,7 @@ export declare const workspacesListResponseSchema: z.ZodObject<{
81
92
  nextCursor: z.ZodNullable<z.ZodString>;
82
93
  }, z.core.$strip>;
83
94
  export type Workspace = z.infer<typeof workspaceSchema>;
84
- export type WorkspaceBackup = z.infer<typeof workspaceBackupSchema>;
95
+ export type WorkspaceTier = z.infer<typeof workspaceTierSchema>;
85
96
  export type WorkspaceNetworkPolicy = z.infer<typeof workspaceNetworkPolicySchema>;
86
97
  export type CreateWorkspaceBody = z.input<typeof createWorkspaceBodySchema>;
87
98
  export type UpdateWorkspaceBody = z.infer<typeof updateWorkspaceBodySchema>;
@@ -9,13 +9,7 @@ export const workspaceNameSchema = z
9
9
  .trim()
10
10
  .min(1)
11
11
  .max(MAX_WORKSPACE_NAME_LENGTH);
12
- export const workspaceBackupSchema = z
13
- .object({
14
- dir: z.literal("/workspace"),
15
- id: z.uuid(),
16
- localBucket: z.boolean().optional(),
17
- })
18
- .strict();
12
+ export const workspaceTierSchema = z.enum(["core", "plus"]);
19
13
  export const workspaceNetworkPolicySchema = z.discriminatedUnion("mode", [
20
14
  z.object({ mode: z.literal("unrestricted") }).strict(),
21
15
  z
@@ -35,6 +29,7 @@ export const workspaceSchema = z
35
29
  .object({
36
30
  id: workspaceIdSchema,
37
31
  tenantId: tenantIdSchema,
32
+ tier: workspaceTierSchema,
38
33
  name: workspaceNameSchema.nullable(),
39
34
  userId: userIdSchema,
40
35
  metadata: metadataSchema,
@@ -46,6 +41,7 @@ export const workspaceSchema = z
46
41
  export const createWorkspaceBodySchema = z
47
42
  .object({
48
43
  name: workspaceNameSchema.optional(),
44
+ tier: workspaceTierSchema.default("core"),
49
45
  userId: userIdSchema.default(""),
50
46
  metadata: metadataSchema.default({}),
51
47
  networkPolicy: workspaceNetworkPolicySchema.default({
@@ -1,20 +1,42 @@
1
1
  import { z } from "zod";
2
2
  export declare const ADMIN_AGENT_ID_PREFIX = "ag_adm";
3
+ /** Creates a Tenant ID with a 16-character base62 body. */
3
4
  export declare const createTenantId: () => string;
5
+ /**
6
+ * Creates an Agent ID outside the reserved administrator prefix.
7
+ */
4
8
  export declare const createAgentId: () => string;
9
+ /**
10
+ * Creates an Agent ID with the reserved administrator prefix.
11
+ */
5
12
  export declare const mintAdminAgentId: () => string;
13
+ /** Creates a Session ID with a 16-character base62 body. */
6
14
  export declare const createSessionId: () => string;
15
+ /** Creates a Api Key ID with a 16-character base62 body. */
7
16
  export declare const createApiKeyId: () => string;
17
+ /** Creates a Provider ID with a 16-character base62 body. */
8
18
  export declare const createProviderId: () => string;
19
+ /** Creates a Mcp Connection ID with a 16-character base62 body. */
9
20
  export declare const createMcpConnectionId: () => string;
21
+ /** Creates a Workspace ID with a 16-character base62 body. */
10
22
  export declare const createWorkspaceId: () => string;
23
+ /** Creates a Artifact ID with a 16-character base62 body. */
11
24
  export declare const createArtifactId: () => string;
25
+ /** Creates a Task ID with a 16-character base62 body. */
12
26
  export declare const createTaskId: () => string;
27
+ /** Creates a Task Run ID with a 16-character base62 body. */
13
28
  export declare const createTaskRunId: () => string;
29
+ /** Creates a Memory ID with a 16-character base62 body. */
14
30
  export declare const createMemoryId: () => string;
31
+ /** Creates a Prompt ID with a 16-character base62 body. */
15
32
  export declare const createPromptId: () => string;
33
+ /** Creates a Request ID with a 16-character base62 body. */
16
34
  export declare const createRequestId: () => string;
35
+ /** Creates a Checkout Attempt ID with a 16-character base62 body. */
17
36
  export declare const createCheckoutAttemptId: () => string;
37
+ /**
38
+ * Creates a Skill ID with a 16-character base62 body.
39
+ */
18
40
  export declare const createSkillId: () => string;
19
41
  /**
20
42
  * API keys — `ba_` + 40 base62 chars (~230 bits entropy). The full token is
@@ -22,14 +44,23 @@ export declare const createSkillId: () => string;
22
44
  * are stored. (docs/adr/0004-unified-v1-dual-credential-auth.md)
23
45
  */
24
46
  export declare const API_KEY_TOKEN_PREFIX = "ba_";
47
+ /**
48
+ * Creates an API key token with a 40-character random base62 body.
49
+ * @returns A ba_ token with 40 random base62 characters.
50
+ */
25
51
  export declare function createApiKeyToken(): string;
26
52
  /**
27
53
  * The display fragment is `ba_` + the first 2 chars of the random body —
28
54
  * safe to store (~12 of ~230 bits revealed).
55
+ * @param token - API key token with the ba_ prefix.
56
+ * @returns The prefix and first two characters of the token body.
29
57
  */
30
58
  export declare function apiKeyFragmentFromToken(token: string): string;
31
59
  export declare const tenantIdSchema: z.ZodString;
32
60
  export declare const agentIdSchema: z.ZodString;
61
+ /**
62
+ * Checks the administrator prefix and validates the complete Agent ID.
63
+ */
33
64
  export declare const isAdminAgentId: (id: string) => boolean;
34
65
  export declare const sessionIdSchema: z.ZodString;
35
66
  export declare const apiKeyIdSchema: z.ZodString;
@@ -12,22 +12,47 @@ const createNanoId13 = customAlphabet(BASE62, 13);
12
12
  const createAgentIdFirstChar = customAlphabet(BASE62.replace("a", ""), 1);
13
13
  const createNanoId15 = customAlphabet(BASE62, 15);
14
14
  const createNanoId40 = customAlphabet(BASE62, 40);
15
+ /**
16
+ * Creates a generator for prefixed IDs with a 16-character base62 body.
17
+ */
15
18
  const platformId = (prefix) => () => `${prefix}_${createNanoId16()}`;
19
+ /** Creates a Tenant ID with a 16-character base62 body. */
16
20
  export const createTenantId = platformId("ten");
21
+ /**
22
+ * Creates an Agent ID outside the reserved administrator prefix.
23
+ */
17
24
  export const createAgentId = () => `ag_${createAgentIdFirstChar()}${createNanoId15()}`;
25
+ /**
26
+ * Creates an Agent ID with the reserved administrator prefix.
27
+ */
18
28
  export const mintAdminAgentId = () => `${ADMIN_AGENT_ID_PREFIX}${createNanoId13()}`;
29
+ /** Creates a Session ID with a 16-character base62 body. */
19
30
  export const createSessionId = platformId("ss");
31
+ /** Creates a Api Key ID with a 16-character base62 body. */
20
32
  export const createApiKeyId = platformId("ak");
33
+ /** Creates a Provider ID with a 16-character base62 body. */
21
34
  export const createProviderId = platformId("prv");
35
+ /** Creates a Mcp Connection ID with a 16-character base62 body. */
22
36
  export const createMcpConnectionId = platformId("mcp");
37
+ /** Creates a Workspace ID with a 16-character base62 body. */
23
38
  export const createWorkspaceId = platformId("ws");
39
+ /** Creates a Artifact ID with a 16-character base62 body. */
24
40
  export const createArtifactId = platformId("at");
41
+ /** Creates a Task ID with a 16-character base62 body. */
25
42
  export const createTaskId = platformId("tk");
43
+ /** Creates a Task Run ID with a 16-character base62 body. */
26
44
  export const createTaskRunId = platformId("tr");
45
+ /** Creates a Memory ID with a 16-character base62 body. */
27
46
  export const createMemoryId = platformId("mem");
47
+ /** Creates a Prompt ID with a 16-character base62 body. */
28
48
  export const createPromptId = platformId("prompt");
49
+ /** Creates a Request ID with a 16-character base62 body. */
29
50
  export const createRequestId = platformId("req");
51
+ /** Creates a Checkout Attempt ID with a 16-character base62 body. */
30
52
  export const createCheckoutAttemptId = platformId("ca");
53
+ /**
54
+ * Creates a Skill ID with a 16-character base62 body.
55
+ */
31
56
  export const createSkillId = () => `skill_${createNanoId16()}`;
32
57
  /**
33
58
  * API keys — `ba_` + 40 base62 chars (~230 bits entropy). The full token is
@@ -35,12 +60,18 @@ export const createSkillId = () => `skill_${createNanoId16()}`;
35
60
  * are stored. (docs/adr/0004-unified-v1-dual-credential-auth.md)
36
61
  */
37
62
  export const API_KEY_TOKEN_PREFIX = "ba_";
63
+ /**
64
+ * Creates an API key token with a 40-character random base62 body.
65
+ * @returns A ba_ token with 40 random base62 characters.
66
+ */
38
67
  export function createApiKeyToken() {
39
68
  return `${API_KEY_TOKEN_PREFIX}${createNanoId40()}`;
40
69
  }
41
70
  /**
42
71
  * The display fragment is `ba_` + the first 2 chars of the random body —
43
72
  * safe to store (~12 of ~230 bits revealed).
73
+ * @param token - API key token with the ba_ prefix.
74
+ * @returns The prefix and first two characters of the token body.
44
75
  */
45
76
  export function apiKeyFragmentFromToken(token) {
46
77
  if (!token.startsWith(API_KEY_TOKEN_PREFIX)) {
@@ -52,6 +83,9 @@ export function apiKeyFragmentFromToken(token) {
52
83
  // Schemas — one per id prefix, mirroring the migration check constraints.
53
84
  export const tenantIdSchema = z.string().regex(/^ten_[0-9A-Za-z]{16}$/);
54
85
  export const agentIdSchema = z.string().regex(/^ag_[0-9A-Za-z]{16}$/);
86
+ /**
87
+ * Checks the administrator prefix and validates the complete Agent ID.
88
+ */
55
89
  export const isAdminAgentId = (id) => id.startsWith(ADMIN_AGENT_ID_PREFIX) && z.validate(agentIdSchema, id);
56
90
  export const sessionIdSchema = z.string().regex(/^ss_[0-9A-Za-z]{16}$/);
57
91
  export const apiKeyIdSchema = z.string().regex(/^ak_[0-9A-Za-z]{16}$/);
@@ -16,12 +16,13 @@ export { createPromptBodySchema, parsePromptVariables, promptResponseSchema, pro
16
16
  export { createProviderBodySchema, providerListItemSchema, providerModelsResponseSchema, providerResponseSchema, providersResponseSchema, providerTypeSchema, thinkingLevelsResponseSchema, updateProviderBodySchema, } from "./entities/providers.ts";
17
17
  export type { ChatSteerConsumedEvent, SessionActivity, SessionInput, SessionInputResponse, SessionInputState, SessionInputsQuery, SessionInputsResponse, StopSessionBody, StopSessionResponse, SubmitSessionInputBody, } from "./entities/session-inputs.ts";
18
18
  export { chatSteerConsumedEventSchema, sessionActivitySchema, sessionInputRequestIdSchema, sessionInputResponseSchema, sessionInputSchema, sessionInputStateSchema, sessionInputsQuerySchema, sessionInputsResponseSchema, stopSessionBodySchema, stopSessionResponseSchema, submitSessionInputBodySchema, } from "./entities/session-inputs.ts";
19
- export type { ContinueToolApprovalsBody, ToolApprovalContinuationState, ToolApprovalDecision, ToolApprovalsResponse, } from "./entities/sessions.ts";
20
- export { continueToolApprovalsBodySchema, latestSessionListItemSchema, latestSessionsListResponseSchema, sessionListItemSchema, sessionMessageSchema, sessionMessagesResponseSchema, sessionResponseSchema, sessionsListResponseSchema, toolApprovalContinuationStateSchema, toolApprovalDecisionSchema, toolApprovalStateSchema, toolApprovalsResponseSchema, } from "./entities/sessions.ts";
19
+ export type { ContinueToolApprovalsBody, SessionForkedFrom, ToolApprovalContinuationState, ToolApprovalDecision, ToolApprovalsResponse, } from "./entities/sessions.ts";
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
22
  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
23
  export { quotaSchema, subscriptionStatusSchema, tenantDeletionSchema, tenantResponseSchema, tenantSchema, tenantSettingsResponseSchema, updateTenantSettingsBodySchema, } from "./entities/tenants.ts";
24
24
  export type { SessionUsageQuery, SessionUsageResponse, UsageBucket, UsageOverviewQuery, UsageOverviewResponse, UsageResponse, UsageTotals, } from "./entities/usage.ts";
25
25
  export { sessionUsageQuerySchema, sessionUsageResponseSchema, usageOverviewQuerySchema, usageOverviewResponseSchema, usageResponseSchema, } from "./entities/usage.ts";
26
- export { createWorkspaceBodySchema, updateWorkspaceBodySchema, workspaceSchema, workspacesListResponseSchema, } from "./entities/workspaces.ts";
26
+ export type { WorkspaceTier } from "./entities/workspaces.ts";
27
+ export { createWorkspaceBodySchema, updateWorkspaceBodySchema, workspaceSchema, workspacesListResponseSchema, workspaceTierSchema, } from "./entities/workspaces.ts";
27
28
  export { agentIdSchema, apiKeyTokenSchema, functionCallIdSchema, isAdminAgentId, promptIdSchema, sessionIdSchema, } from "./ids.ts";
@@ -14,10 +14,10 @@ export { createMerchantConnectionBodySchema, merchantBindingResponseSchema, merc
14
14
  export { createPromptBodySchema, parsePromptVariables, promptResponseSchema, promptSchema, promptsListQuerySchema, promptsResponseSchema, promptTemplateSchema, renderPromptTemplate, updatePromptBodySchema, } from "./entities/prompts.js";
15
15
  export { createProviderBodySchema, providerListItemSchema, providerModelsResponseSchema, providerResponseSchema, providersResponseSchema, providerTypeSchema, thinkingLevelsResponseSchema, updateProviderBodySchema, } from "./entities/providers.js";
16
16
  export { chatSteerConsumedEventSchema, sessionActivitySchema, sessionInputRequestIdSchema, sessionInputResponseSchema, sessionInputSchema, sessionInputStateSchema, sessionInputsQuerySchema, sessionInputsResponseSchema, stopSessionBodySchema, stopSessionResponseSchema, submitSessionInputBodySchema, } from "./entities/session-inputs.js";
17
- export { continueToolApprovalsBodySchema, latestSessionListItemSchema, latestSessionsListResponseSchema, sessionListItemSchema, sessionMessageSchema, sessionMessagesResponseSchema, sessionResponseSchema, sessionsListResponseSchema, toolApprovalContinuationStateSchema, toolApprovalDecisionSchema, toolApprovalStateSchema, toolApprovalsResponseSchema, } from "./entities/sessions.js";
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
19
  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
20
  export { quotaSchema, subscriptionStatusSchema, tenantDeletionSchema, tenantResponseSchema, tenantSchema, tenantSettingsResponseSchema, updateTenantSettingsBodySchema, } from "./entities/tenants.js";
21
21
  export { sessionUsageQuerySchema, sessionUsageResponseSchema, usageOverviewQuerySchema, usageOverviewResponseSchema, usageResponseSchema, } from "./entities/usage.js";
22
- export { createWorkspaceBodySchema, updateWorkspaceBodySchema, workspaceSchema, workspacesListResponseSchema, } from "./entities/workspaces.js";
22
+ export { createWorkspaceBodySchema, updateWorkspaceBodySchema, workspaceSchema, workspacesListResponseSchema, workspaceTierSchema, } from "./entities/workspaces.js";
23
23
  export { agentIdSchema, apiKeyTokenSchema, functionCallIdSchema, isAdminAgentId, promptIdSchema, sessionIdSchema, } from "./ids.js";
@@ -1,3 +1,13 @@
1
1
  export declare const atLeastOneFieldMessage = "At least one field must be provided.";
2
+ /**
3
+ * Checks whether the object has at least one own enumerable key.
4
+ * @param value - Value to inspect.
5
+ * @returns Whether at least one own enumerable key exists.
6
+ */
2
7
  export declare function hasObjectKeys(value: object): boolean;
8
+ /**
9
+ * Checks whether every string in the array is unique.
10
+ * @param values - Values to inspect or substitute.
11
+ * @returns Whether no string occurs more than once.
12
+ */
3
13
  export declare function hasUniqueValues(values: string[]): boolean;
@@ -1,7 +1,17 @@
1
1
  export const atLeastOneFieldMessage = "At least one field must be provided.";
2
+ /**
3
+ * Checks whether the object has at least one own enumerable key.
4
+ * @param value - Value to inspect.
5
+ * @returns Whether at least one own enumerable key exists.
6
+ */
2
7
  export function hasObjectKeys(value) {
3
8
  return Object.keys(value).length > 0;
4
9
  }
10
+ /**
11
+ * Checks whether every string in the array is unique.
12
+ * @param values - Values to inspect or substitute.
13
+ * @returns Whether no string occurs more than once.
14
+ */
5
15
  export function hasUniqueValues(values) {
6
16
  return new Set(values).size === values.length;
7
17
  }
@@ -5,9 +5,16 @@ export type BlazingAgentsDirectChatTransportOptions = {
5
5
  agentId: string;
6
6
  /** Caller-local functions for every Turn and approved continuation of this chat. */
7
7
  functions?: ChatFunctions;
8
+ /**
9
+ * Returns the authenticated SDK client for the current request.
10
+ * @returns The SDK client for this request.
11
+ */
8
12
  getClient: () => BlazingAgents | Promise<BlazingAgents>;
9
13
  metadata?: Record<string, unknown>;
10
- /** Receives the Session ID before the response stream is consumed. */
14
+ /**
15
+ * Receives the Session ID before the response stream is consumed.
16
+ * @param sessionId - Session to look up or record.
17
+ */
11
18
  onSessionId?: (sessionId: string) => Promise<void> | void;
12
19
  sessionId?: string;
13
20
  userId?: string;
@@ -21,11 +28,30 @@ export type BlazingAgentsDirectChatTransportOptions = {
21
28
  /** Connects useChat directly to the SDK, including native streaming fetch clients. */
22
29
  export declare class BlazingAgentsDirectChatTransport<UI_MESSAGE extends UIMessage = UIMessage> extends DefaultChatTransport<UI_MESSAGE> {
23
30
  #private;
31
+ /**
32
+ * Creates a chat transport and validates any supplied Session ID.
33
+ * @param options - Configuration for this operation.
34
+ */
24
35
  constructor(options: BlazingAgentsDirectChatTransportOptions);
36
+ /**
37
+ * Submits the supplied user messages directly to the SDK chat endpoint.
38
+ * @param input - Operation input and optional cancellation signal.
39
+ * @returns The decoded AI SDK message-chunk stream.
40
+ */
25
41
  sendUserMessages(input: {
26
42
  messages: UI_MESSAGE[];
27
43
  abortSignal?: AbortSignal;
28
44
  }): Promise<ReadableStream<import("ai").UIMessageChunk<unknown, import("ai").UIDataTypes>>>;
45
+ /**
46
+ * Submits the latest user message or complete assistant approval round to the chat.
47
+ * @param input - Operation input and optional cancellation signal.
48
+ * @returns The decoded AI SDK message-chunk stream.
49
+ */
29
50
  sendMessages(input: Parameters<ChatTransport<UI_MESSAGE>["sendMessages"]>[0]): Promise<ReadableStream<import("ai").UIMessageChunk<unknown, import("ai").UIDataTypes>>>;
51
+ /**
52
+ * Returns null because reconnecting to an existing stream is unsupported.
53
+ * @param _input - Unused reconnect request.
54
+ * @returns A promise resolving to null.
55
+ */
30
56
  reconnectToStream(_input: Parameters<ChatTransport<UI_MESSAGE>["reconnectToStream"]>[0]): Promise<null>;
31
57
  }
@@ -5,6 +5,10 @@ import { sessionIdSchema } from "./contracts/ids.js";
5
5
  export class BlazingAgentsDirectChatTransport extends DefaultChatTransport {
6
6
  #options;
7
7
  #sessionId;
8
+ /**
9
+ * Creates a chat transport and validates any supplied Session ID.
10
+ * @param options - Configuration for this operation.
11
+ */
8
12
  constructor(options) {
9
13
  super();
10
14
  this.#options = options;
@@ -13,6 +17,11 @@ export class BlazingAgentsDirectChatTransport extends DefaultChatTransport {
13
17
  ? undefined
14
18
  : sessionIdSchema.parse(options.sessionId);
15
19
  }
20
+ /**
21
+ * Submits the supplied user messages directly to the SDK chat endpoint.
22
+ * @param input - Operation input and optional cancellation signal.
23
+ * @returns The decoded AI SDK message-chunk stream.
24
+ */
16
25
  async sendUserMessages(input) {
17
26
  const client = await this.#options.getClient();
18
27
  const result = await client.chat({
@@ -25,6 +34,11 @@ export class BlazingAgentsDirectChatTransport extends DefaultChatTransport {
25
34
  });
26
35
  return this.#processChatResult(result);
27
36
  }
37
+ /**
38
+ * Submits the latest user message or complete assistant approval round to the chat.
39
+ * @param input - Operation input and optional cancellation signal.
40
+ * @returns The decoded AI SDK message-chunk stream.
41
+ */
28
42
  async sendMessages(input) {
29
43
  if (input.trigger === "regenerate-message" && !this.#sessionId) {
30
44
  throw new Error("Regeneration requires an existing Session.");
@@ -80,6 +94,9 @@ export class BlazingAgentsDirectChatTransport extends DefaultChatTransport {
80
94
  }
81
95
  return this.#processChatResult(result);
82
96
  }
97
+ /**
98
+ * Claims the chat stream and records the first Session ID before decoding chunks.
99
+ */
83
100
  async #processChatResult(result) {
84
101
  const stream = result.toStream();
85
102
  try {
@@ -95,9 +112,18 @@ export class BlazingAgentsDirectChatTransport extends DefaultChatTransport {
95
112
  }
96
113
  return this.processResponseStream(stream);
97
114
  }
115
+ /**
116
+ * Returns null because reconnecting to an existing stream is unsupported.
117
+ * @param _input - Unused reconnect request.
118
+ * @returns A promise resolving to null.
119
+ */
98
120
  reconnectToStream(_input) {
99
121
  return Promise.resolve(null);
100
122
  }
123
+ /**
124
+ * Submits the last assistant approval round for the existing Session.
125
+ * @param input - Operation input and optional cancellation signal.
126
+ */
101
127
  async #sendApprovalContinuation(input, last) {
102
128
  if (this.#sessionId === undefined) {
103
129
  throw new Error("Tool approval requires an existing Session.");
package/dist/errors.d.ts CHANGED
@@ -17,6 +17,10 @@ export declare class BlazingAgentsError extends Error {
17
17
  * biome-ignore lint/correctness/noUnusedPrivateClassMembers: marker pattern
18
18
  */
19
19
  private readonly [BLAZING_AGENTS_ERROR_SYMBOL];
20
+ /**
21
+ * Creates an SDK error with its code, diagnostics, and optional cause.
22
+ * @param options - Configuration for this operation.
23
+ */
20
24
  constructor({ code, details, headers, message, param, requestId, responseBody, responseBodyTruncated, status, }: {
21
25
  code: BlazingAgentsErrorCode;
22
26
  details?: Record<string, unknown>;
@@ -28,6 +32,11 @@ export declare class BlazingAgentsError extends Error {
28
32
  responseBodyTruncated?: boolean;
29
33
  status?: number;
30
34
  }, options?: ErrorOptions);
35
+ /**
36
+ * Checks the shared symbol marker, including errors from duplicated SDK packages.
37
+ * @param error - Value to inspect or handle.
38
+ * @returns Whether the value carries the SDK error marker.
39
+ */
31
40
  static isInstance(error: unknown): error is BlazingAgentsError;
32
41
  }
33
42
  export {};
package/dist/errors.js CHANGED
@@ -27,6 +27,10 @@ export class BlazingAgentsError extends Error {
27
27
  */
28
28
  [BLAZING_AGENTS_ERROR_SYMBOL] = true;
29
29
  // Stryker restore BooleanLiteral
30
+ /**
31
+ * Creates an SDK error with its code, diagnostics, and optional cause.
32
+ * @param options - Configuration for this operation.
33
+ */
30
34
  constructor({ code, details, headers, message, param, requestId, responseBody, responseBodyTruncated, status, }, options) {
31
35
  super(`[${code}] ${message}`, options);
32
36
  this.name = BLAZING_AGENTS_ERROR_NAME;
@@ -39,6 +43,11 @@ export class BlazingAgentsError extends Error {
39
43
  this.responseBodyTruncated = responseBodyTruncated;
40
44
  this.status = status;
41
45
  }
46
+ /**
47
+ * Checks the shared symbol marker, including errors from duplicated SDK packages.
48
+ * @param error - Value to inspect or handle.
49
+ * @returns Whether the value carries the SDK error marker.
50
+ */
42
51
  static isInstance(error) {
43
52
  if (error === null || typeof error !== "object") {
44
53
  return false;