@blazingagents/sdk 0.46.0 → 0.48.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/contracts/api.d.ts +1 -0
- package/dist/contracts/api.js +1 -0
- package/dist/contracts/entities/mcp-connections.js +2 -2
- package/dist/contracts/entities/merchant.js +2 -2
- package/dist/contracts/entities/providers.js +1 -1
- package/dist/contracts/entities/sessions.d.ts +1 -1
- package/dist/functions.js +38 -2
- package/dist/http.js +44 -0
- package/package.json +1 -1
package/dist/contracts/api.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ import type { BlazingAgentsErrorCode } from "../types.ts";
|
|
|
9
9
|
export declare const apiErrorCodeSchema: z.ZodEnum<{
|
|
10
10
|
admin_agent_managed: "admin_agent_managed";
|
|
11
11
|
agent_busy: "agent_busy";
|
|
12
|
+
agent_deleting: "agent_deleting";
|
|
12
13
|
agent_disabled: "agent_disabled";
|
|
13
14
|
agent_mcp_connection_not_found: "agent_mcp_connection_not_found";
|
|
14
15
|
agent_mcp_connections_invalid: "agent_mcp_connections_invalid";
|
package/dist/contracts/api.js
CHANGED
|
@@ -28,7 +28,7 @@ const mcpConnectionNameSchema = z
|
|
|
28
28
|
const mcpConnectionNameInputSchema = mcpConnectionNameSchema.describe("Display name of the connection, unique within your tenant.");
|
|
29
29
|
const bearerTokenSchema = z
|
|
30
30
|
.string()
|
|
31
|
-
.min(
|
|
31
|
+
.min(8)
|
|
32
32
|
.max(MAX_MCP_BEARER_TOKEN_LENGTH)
|
|
33
33
|
.regex(/^[!-~]+$/, "Bearer token must contain visible ASCII characters only")
|
|
34
34
|
.describe("Token sent as `Authorization: Bearer <token>` to the MCP server. Required when `authType` is `bearer`. Never returned.");
|
|
@@ -40,7 +40,7 @@ const oauthClientIdSchema = z
|
|
|
40
40
|
.describe("OAuth client ID. Optional, but send it together with `clientSecret`.");
|
|
41
41
|
const oauthClientSecretSchema = z
|
|
42
42
|
.string()
|
|
43
|
-
.min(
|
|
43
|
+
.min(8)
|
|
44
44
|
.max(MAX_MCP_OAUTH_CLIENT_SECRET_LENGTH)
|
|
45
45
|
.regex(/^[!-~]+$/, "Client secret must contain visible ASCII characters only")
|
|
46
46
|
.describe("OAuth client secret. Optional, but send it together with `clientId`. Never returned.");
|
|
@@ -47,7 +47,7 @@ export const createMerchantConnectionBodySchema = z
|
|
|
47
47
|
environment: merchantEnvironmentSchema.describe("The provider environment to send usage to: `sandbox` or `live`."),
|
|
48
48
|
credential: z
|
|
49
49
|
.string()
|
|
50
|
-
.min(
|
|
50
|
+
.min(8)
|
|
51
51
|
.describe("A credential for your provider account: a Polar Organization Access Token, or a Dodo API key in the mode that matches `environment`. It is never returned."),
|
|
52
52
|
guard: merchantGuardSchema
|
|
53
53
|
.optional()
|
|
@@ -58,7 +58,7 @@ export const updateMerchantConnectionBodySchema = z
|
|
|
58
58
|
.object({
|
|
59
59
|
credential: z
|
|
60
60
|
.string()
|
|
61
|
-
.min(
|
|
61
|
+
.min(8)
|
|
62
62
|
.optional()
|
|
63
63
|
.describe("A replacement credential. It must belong to the same merchant account as the current one."),
|
|
64
64
|
guard: merchantGuardSchema
|
|
@@ -373,7 +373,7 @@ export declare const turnStreamErrorEventSchema: z.ZodObject<{
|
|
|
373
373
|
type: z.ZodLiteral<"data-ba-error">;
|
|
374
374
|
transient: z.ZodLiteral<true>;
|
|
375
375
|
data: z.ZodObject<{
|
|
376
|
-
code: z.ZodCustom<"admin_agent_managed" | "agent_busy" | "agent_disabled" | "agent_mcp_connection_not_found" | "agent_mcp_connections_invalid" | "api_key_limit_reached" | "artifact_session_cap_reached" | "chat_webhook_conflict" | "chat_webhook_registration_failed" | "forbidden" | "function_call_conflict" | "idempotency_conflict" | "input_idempotency_conflict" | "insufficient_scope" | "internal" | "invalid_cursor" | "invalid_request" | "mcp_connection_authentication_failed" | "mcp_connection_discovery_failed" | "mcp_connection_in_use" | "mcp_connection_invalid" | "mcp_connection_limit_reached" | "mcp_connection_name_conflict" | "mcp_connection_stale_credential_version" | "mcp_connection_unreachable" | "merchant_account_mismatch" | "merchant_balance_required" | "merchant_binding_not_found" | "merchant_connection_in_use" | "merchant_connection_not_found" | "merchant_credential_invalid" | "merchant_customer_not_found" | "merchant_customer_unmapped" | "merchant_eligibility_unavailable" | "merchant_event_not_found" | "merchant_event_state_conflict" | "merchant_provider_unavailable" | "merchant_subscription_required" | "message_id_conflict" | "message_not_found" | "model_discovery_unsupported" | "model_not_found" | "model_spending_limit_exceeded" | "model_validation_unavailable" | "not_found" | "prompt_variable_missing" | "prompt_variable_unknown" | "provider_historical_use" | "provider_in_use" | "provider_limit_reached" | "provider_name_conflict" | "provider_not_found" | "provider_required" | "rate_limited" | "service_unavailable" | "session_busy" | "session_fork_deleted" | "session_fork_unavailable" | "session_turn_unresponsive" | "session_version_mismatch" | "skill_invalid_archive" | "skill_invalid_markdown" | "skill_limit_reached" | "skill_name_conflict" | "skill_not_found" | "skill_too_many_files" | "skill_uncompressed_too_large" | "steer_not_available" | "subscription_already_paid" | "subscription_not_cancelled" | "subscription_required" | "task_active_run_exists" | "tenant_deleting" | "tenant_deletion_in_progress" | "tenant_deletion_not_ready" | "tenant_not_deleting" | "tool_approval_continuation_settled" | "tool_approval_decision_conflict" | "turn_interrupted" | "unauthorized" | "usage_credit_required" | "validation_failed" | "workspace_busy" | "workspace_in_use" | "workspace_not_found" | (string & {}), "admin_agent_managed" | "agent_busy" | "agent_disabled" | "agent_mcp_connection_not_found" | "agent_mcp_connections_invalid" | "api_key_limit_reached" | "artifact_session_cap_reached" | "chat_webhook_conflict" | "chat_webhook_registration_failed" | "forbidden" | "function_call_conflict" | "idempotency_conflict" | "input_idempotency_conflict" | "insufficient_scope" | "internal" | "invalid_cursor" | "invalid_request" | "mcp_connection_authentication_failed" | "mcp_connection_discovery_failed" | "mcp_connection_in_use" | "mcp_connection_invalid" | "mcp_connection_limit_reached" | "mcp_connection_name_conflict" | "mcp_connection_stale_credential_version" | "mcp_connection_unreachable" | "merchant_account_mismatch" | "merchant_balance_required" | "merchant_binding_not_found" | "merchant_connection_in_use" | "merchant_connection_not_found" | "merchant_credential_invalid" | "merchant_customer_not_found" | "merchant_customer_unmapped" | "merchant_eligibility_unavailable" | "merchant_event_not_found" | "merchant_event_state_conflict" | "merchant_provider_unavailable" | "merchant_subscription_required" | "message_id_conflict" | "message_not_found" | "model_discovery_unsupported" | "model_not_found" | "model_spending_limit_exceeded" | "model_validation_unavailable" | "not_found" | "prompt_variable_missing" | "prompt_variable_unknown" | "provider_historical_use" | "provider_in_use" | "provider_limit_reached" | "provider_name_conflict" | "provider_not_found" | "provider_required" | "rate_limited" | "service_unavailable" | "session_busy" | "session_fork_deleted" | "session_fork_unavailable" | "session_turn_unresponsive" | "session_version_mismatch" | "skill_invalid_archive" | "skill_invalid_markdown" | "skill_limit_reached" | "skill_name_conflict" | "skill_not_found" | "skill_too_many_files" | "skill_uncompressed_too_large" | "steer_not_available" | "subscription_already_paid" | "subscription_not_cancelled" | "subscription_required" | "task_active_run_exists" | "tenant_deleting" | "tenant_deletion_in_progress" | "tenant_deletion_not_ready" | "tenant_not_deleting" | "tool_approval_continuation_settled" | "tool_approval_decision_conflict" | "turn_interrupted" | "unauthorized" | "usage_credit_required" | "validation_failed" | "workspace_busy" | "workspace_in_use" | "workspace_not_found" | (string & {})>;
|
|
376
|
+
code: z.ZodCustom<"admin_agent_managed" | "agent_busy" | "agent_deleting" | "agent_disabled" | "agent_mcp_connection_not_found" | "agent_mcp_connections_invalid" | "api_key_limit_reached" | "artifact_session_cap_reached" | "chat_webhook_conflict" | "chat_webhook_registration_failed" | "forbidden" | "function_call_conflict" | "idempotency_conflict" | "input_idempotency_conflict" | "insufficient_scope" | "internal" | "invalid_cursor" | "invalid_request" | "mcp_connection_authentication_failed" | "mcp_connection_discovery_failed" | "mcp_connection_in_use" | "mcp_connection_invalid" | "mcp_connection_limit_reached" | "mcp_connection_name_conflict" | "mcp_connection_stale_credential_version" | "mcp_connection_unreachable" | "merchant_account_mismatch" | "merchant_balance_required" | "merchant_binding_not_found" | "merchant_connection_in_use" | "merchant_connection_not_found" | "merchant_credential_invalid" | "merchant_customer_not_found" | "merchant_customer_unmapped" | "merchant_eligibility_unavailable" | "merchant_event_not_found" | "merchant_event_state_conflict" | "merchant_provider_unavailable" | "merchant_subscription_required" | "message_id_conflict" | "message_not_found" | "model_discovery_unsupported" | "model_not_found" | "model_spending_limit_exceeded" | "model_validation_unavailable" | "not_found" | "prompt_variable_missing" | "prompt_variable_unknown" | "provider_historical_use" | "provider_in_use" | "provider_limit_reached" | "provider_name_conflict" | "provider_not_found" | "provider_required" | "rate_limited" | "service_unavailable" | "session_busy" | "session_fork_deleted" | "session_fork_unavailable" | "session_turn_unresponsive" | "session_version_mismatch" | "skill_invalid_archive" | "skill_invalid_markdown" | "skill_limit_reached" | "skill_name_conflict" | "skill_not_found" | "skill_too_many_files" | "skill_uncompressed_too_large" | "steer_not_available" | "subscription_already_paid" | "subscription_not_cancelled" | "subscription_required" | "task_active_run_exists" | "tenant_deleting" | "tenant_deletion_in_progress" | "tenant_deletion_not_ready" | "tenant_not_deleting" | "tool_approval_continuation_settled" | "tool_approval_decision_conflict" | "turn_interrupted" | "unauthorized" | "usage_credit_required" | "validation_failed" | "workspace_busy" | "workspace_in_use" | "workspace_not_found" | (string & {}), "admin_agent_managed" | "agent_busy" | "agent_deleting" | "agent_disabled" | "agent_mcp_connection_not_found" | "agent_mcp_connections_invalid" | "api_key_limit_reached" | "artifact_session_cap_reached" | "chat_webhook_conflict" | "chat_webhook_registration_failed" | "forbidden" | "function_call_conflict" | "idempotency_conflict" | "input_idempotency_conflict" | "insufficient_scope" | "internal" | "invalid_cursor" | "invalid_request" | "mcp_connection_authentication_failed" | "mcp_connection_discovery_failed" | "mcp_connection_in_use" | "mcp_connection_invalid" | "mcp_connection_limit_reached" | "mcp_connection_name_conflict" | "mcp_connection_stale_credential_version" | "mcp_connection_unreachable" | "merchant_account_mismatch" | "merchant_balance_required" | "merchant_binding_not_found" | "merchant_connection_in_use" | "merchant_connection_not_found" | "merchant_credential_invalid" | "merchant_customer_not_found" | "merchant_customer_unmapped" | "merchant_eligibility_unavailable" | "merchant_event_not_found" | "merchant_event_state_conflict" | "merchant_provider_unavailable" | "merchant_subscription_required" | "message_id_conflict" | "message_not_found" | "model_discovery_unsupported" | "model_not_found" | "model_spending_limit_exceeded" | "model_validation_unavailable" | "not_found" | "prompt_variable_missing" | "prompt_variable_unknown" | "provider_historical_use" | "provider_in_use" | "provider_limit_reached" | "provider_name_conflict" | "provider_not_found" | "provider_required" | "rate_limited" | "service_unavailable" | "session_busy" | "session_fork_deleted" | "session_fork_unavailable" | "session_turn_unresponsive" | "session_version_mismatch" | "skill_invalid_archive" | "skill_invalid_markdown" | "skill_limit_reached" | "skill_name_conflict" | "skill_not_found" | "skill_too_many_files" | "skill_uncompressed_too_large" | "steer_not_available" | "subscription_already_paid" | "subscription_not_cancelled" | "subscription_required" | "task_active_run_exists" | "tenant_deleting" | "tenant_deletion_in_progress" | "tenant_deletion_not_ready" | "tenant_not_deleting" | "tool_approval_continuation_settled" | "tool_approval_decision_conflict" | "turn_interrupted" | "unauthorized" | "usage_credit_required" | "validation_failed" | "workspace_busy" | "workspace_in_use" | "workspace_not_found" | (string & {})>;
|
|
377
377
|
details: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
378
378
|
message: z.ZodString;
|
|
379
379
|
}, z.core.$strict>;
|
package/dist/functions.js
CHANGED
|
@@ -10,6 +10,32 @@ import { apiPath, requestJson } from "./http.js";
|
|
|
10
10
|
export function defineFunction(definition) {
|
|
11
11
|
return definition;
|
|
12
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Inlines a root `$ref` to an object `$defs` entry. Zod extracts a schema
|
|
15
|
+
* with an id and leaves that reference, which is not `type: "object"`.
|
|
16
|
+
*/
|
|
17
|
+
function inlineRootObjectDefinition(schema) {
|
|
18
|
+
const { $ref: ref, $defs: defs, ...rest } = schema;
|
|
19
|
+
if (ref === undefined || !ref.startsWith("#/$defs/") || defs === undefined) {
|
|
20
|
+
return schema;
|
|
21
|
+
}
|
|
22
|
+
const name = ref
|
|
23
|
+
.slice("#/$defs/".length)
|
|
24
|
+
.replaceAll("~1", "/")
|
|
25
|
+
.replaceAll("~0", "~");
|
|
26
|
+
const target = defs[name];
|
|
27
|
+
if (target === undefined || target.type !== "object") {
|
|
28
|
+
return schema;
|
|
29
|
+
}
|
|
30
|
+
const inlined = { ...target, ...rest };
|
|
31
|
+
const json = JSON.stringify(inlined);
|
|
32
|
+
if (json.includes('"$ref":"#/$defs/')) {
|
|
33
|
+
const { [name]: _root, ...others } = defs;
|
|
34
|
+
const rootReferenced = `${json}${JSON.stringify(others)}`.includes(JSON.stringify(ref));
|
|
35
|
+
inlined.$defs = rootReferenced ? defs : others;
|
|
36
|
+
}
|
|
37
|
+
return inlined;
|
|
38
|
+
}
|
|
13
39
|
/**
|
|
14
40
|
* Converts caller-local Zod input schemas to validated JSON Schema definitions.
|
|
15
41
|
* @param functions - Caller-local function handlers keyed by name.
|
|
@@ -20,7 +46,13 @@ export function toChatFunctionDefinitions(functions) {
|
|
|
20
46
|
try {
|
|
21
47
|
return chatFunctionDefinitionsSchema.parse(Object.fromEntries(Object.entries(functions).map(([name, fn]) => {
|
|
22
48
|
const { $schema: _, ...inputSchema } = z.toJSONSchema(fn.inputSchema, { io: "input" });
|
|
23
|
-
return [
|
|
49
|
+
return [
|
|
50
|
+
name,
|
|
51
|
+
{
|
|
52
|
+
description: fn.description,
|
|
53
|
+
inputSchema: inlineRootObjectDefinition(inputSchema),
|
|
54
|
+
},
|
|
55
|
+
];
|
|
24
56
|
})));
|
|
25
57
|
}
|
|
26
58
|
catch (cause) {
|
|
@@ -255,7 +287,11 @@ export function stripFunctionEvents(body, { onCall, onCancel, onEnd } = {}) {
|
|
|
255
287
|
buffer = buffer.slice(end);
|
|
256
288
|
}
|
|
257
289
|
}
|
|
258
|
-
|
|
290
|
+
/** An unterminated block is not an SSE event: forward public bytes, never dispatch. */
|
|
291
|
+
const rest = buffer + decoder.decode();
|
|
292
|
+
if (functionCallFrom(rest) === undefined) {
|
|
293
|
+
handleBlock("", rest);
|
|
294
|
+
}
|
|
259
295
|
if (!finished) {
|
|
260
296
|
finished = true;
|
|
261
297
|
output.close();
|
package/dist/http.js
CHANGED
|
@@ -20,6 +20,8 @@ const CREDENTIAL_KEYS = new Set([
|
|
|
20
20
|
"client_secret",
|
|
21
21
|
"credential",
|
|
22
22
|
]);
|
|
23
|
+
/** Submitted secrets at least this long match as a substring; shorter ones only as a whole string. */
|
|
24
|
+
const MIN_SUBSTRING_SECRET_LENGTH = 8;
|
|
23
25
|
const DOT_OR_EMPTY_SEGMENTS = new Set(["", ".", ".."]);
|
|
24
26
|
/**
|
|
25
27
|
* Builds an endpoint path, encoding each interpolated value so it stays inside
|
|
@@ -106,6 +108,16 @@ export async function requestJson(config, path, options = {}, schema) {
|
|
|
106
108
|
status: response.status,
|
|
107
109
|
});
|
|
108
110
|
}
|
|
111
|
+
if (options.credentialBearing &&
|
|
112
|
+
containsSubmittedSecret(json, collectSecrets(options.json))) {
|
|
113
|
+
throw new BlazingAgentsError({
|
|
114
|
+
code: "credential_echo",
|
|
115
|
+
headers,
|
|
116
|
+
message: "The server echoed a submitted secret; the response body was discarded.",
|
|
117
|
+
requestId: headers.get("x-request-id") ?? undefined,
|
|
118
|
+
status: response.status,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
109
121
|
try {
|
|
110
122
|
return schema === undefined ? json : schema.parse(json);
|
|
111
123
|
}
|
|
@@ -139,6 +151,38 @@ function findCredentialKey(value) {
|
|
|
139
151
|
}
|
|
140
152
|
}
|
|
141
153
|
}
|
|
154
|
+
/** Credential values collected from a request body. */
|
|
155
|
+
function collectSecrets(value) {
|
|
156
|
+
if (value === null || typeof value !== "object") {
|
|
157
|
+
return [];
|
|
158
|
+
}
|
|
159
|
+
return Object.entries(value).flatMap(([key, item]) => CREDENTIAL_KEYS.has(key) && typeof item === "string"
|
|
160
|
+
? [item]
|
|
161
|
+
: collectSecrets(item));
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Reports whether `text` holds `secret`: anywhere for a secret of
|
|
165
|
+
* `MIN_SUBSTRING_SECRET_LENGTH` characters or more, else only as the whole
|
|
166
|
+
* string. An empty secret is never found.
|
|
167
|
+
*/
|
|
168
|
+
function secretIn(text, secret) {
|
|
169
|
+
if (secret === "") {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
return secret.length >= MIN_SUBSTRING_SECRET_LENGTH
|
|
173
|
+
? text.includes(secret)
|
|
174
|
+
: text === secret;
|
|
175
|
+
}
|
|
176
|
+
/** Reports whether any string value in a decoded JSON value holds a submitted secret. */
|
|
177
|
+
function containsSubmittedSecret(value, secrets) {
|
|
178
|
+
if (typeof value === "string") {
|
|
179
|
+
return secrets.some((secret) => secretIn(value, secret));
|
|
180
|
+
}
|
|
181
|
+
if (value === null || typeof value !== "object") {
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
return Object.values(value).some((item) => containsSubmittedSecret(item, secrets));
|
|
185
|
+
}
|
|
142
186
|
/**
|
|
143
187
|
* Performs a request and returns the raw `Response` for streaming paths.
|
|
144
188
|
* Non-2xx bodies are decoded before a caller can observe a streaming body.
|