@blazingagents/sdk 0.35.0 → 0.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/http.js +62 -1
- package/dist/resources/chat-connections.js +31 -11
- package/dist/resources/chat-deliveries.js +1 -0
- package/dist/resources/mcp-connections.js +7 -3
- package/dist/resources/merchant-connection.js +14 -3
- package/dist/resources/providers.js +7 -4
- package/dist/types.d.ts +6 -1
- package/package.json +1 -2
package/dist/http.js
CHANGED
|
@@ -4,6 +4,22 @@ const DIAGNOSTIC_BODY_LIMIT_BYTES = 64 * 1024;
|
|
|
4
4
|
const INVALID_RESPONSE_MESSAGE = "The server returned an invalid response.";
|
|
5
5
|
const NETWORK_ERROR_MESSAGE = "Network request failed (fetch threw before any HTTP exchange).";
|
|
6
6
|
const REQUEST_ABORTED_MESSAGE = "The request was aborted before any HTTP response.";
|
|
7
|
+
/** Fields no credential-bearing operation's response may contain. */
|
|
8
|
+
const CREDENTIAL_KEYS = new Set([
|
|
9
|
+
"apiKey",
|
|
10
|
+
"api_key",
|
|
11
|
+
"botToken",
|
|
12
|
+
"bot_token",
|
|
13
|
+
"signingSecret",
|
|
14
|
+
"signing_secret",
|
|
15
|
+
"webhookSecret",
|
|
16
|
+
"webhook_secret",
|
|
17
|
+
"bearerToken",
|
|
18
|
+
"bearer_token",
|
|
19
|
+
"clientSecret",
|
|
20
|
+
"client_secret",
|
|
21
|
+
"credential",
|
|
22
|
+
]);
|
|
7
23
|
const DOT_OR_EMPTY_SEGMENTS = new Set(["", ".", ".."]);
|
|
8
24
|
/**
|
|
9
25
|
* Builds an endpoint path, encoding each interpolated value so it stays inside
|
|
@@ -70,14 +86,59 @@ export async function requestJson(config, path, options = {}, schema) {
|
|
|
70
86
|
}
|
|
71
87
|
throw invalidResponseError(headers, response.status, read.diagnosticBody, true, read.cause);
|
|
72
88
|
}
|
|
89
|
+
let json;
|
|
90
|
+
try {
|
|
91
|
+
json = JSON.parse(read.bodyText);
|
|
92
|
+
}
|
|
93
|
+
catch (cause) {
|
|
94
|
+
throw invalidResponseError(headers, response.status, read.diagnosticBody, read.diagnosticBodyTruncated, cause);
|
|
95
|
+
}
|
|
96
|
+
const echoed = options.credentialBearing
|
|
97
|
+
? findCredentialKey(json)
|
|
98
|
+
: undefined;
|
|
99
|
+
if (echoed !== undefined) {
|
|
100
|
+
throw new BlazingAgentsError({
|
|
101
|
+
code: "credential_echo",
|
|
102
|
+
details: { field: echoed },
|
|
103
|
+
headers,
|
|
104
|
+
message: `The server echoed credential field ${JSON.stringify(echoed)}; the response body was discarded.`,
|
|
105
|
+
requestId: headers.get("x-request-id") ?? undefined,
|
|
106
|
+
status: response.status,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
73
109
|
try {
|
|
74
|
-
const json = JSON.parse(read.bodyText);
|
|
75
110
|
return schema === undefined ? json : schema.parse(json);
|
|
76
111
|
}
|
|
77
112
|
catch (cause) {
|
|
78
113
|
throw invalidResponseError(headers, response.status, read.diagnosticBody, read.diagnosticBodyTruncated, cause);
|
|
79
114
|
}
|
|
80
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* Returns the first credential field found anywhere in a decoded JSON value.
|
|
118
|
+
*/
|
|
119
|
+
function findCredentialKey(value) {
|
|
120
|
+
if (Array.isArray(value)) {
|
|
121
|
+
for (const item of value) {
|
|
122
|
+
const key = findCredentialKey(item);
|
|
123
|
+
if (key !== undefined) {
|
|
124
|
+
return key;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
if (value === null || typeof value !== "object") {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
for (const [key, item] of Object.entries(value)) {
|
|
133
|
+
if (CREDENTIAL_KEYS.has(key)) {
|
|
134
|
+
return key;
|
|
135
|
+
}
|
|
136
|
+
const nested = findCredentialKey(item);
|
|
137
|
+
if (nested !== undefined) {
|
|
138
|
+
return nested;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
81
142
|
/**
|
|
82
143
|
* Performs a request and returns the raw `Response` for streaming paths.
|
|
83
144
|
* Non-2xx bodies are decoded before a caller can observe a streaming body.
|
|
@@ -8,37 +8,57 @@ import { apiPath, requestJson } from "../http.js";
|
|
|
8
8
|
export function createChatConnectionsResource(config) {
|
|
9
9
|
return {
|
|
10
10
|
async list({ abortSignal } = {}) {
|
|
11
|
-
return await requestJson(config, "/v1/chat-connections", { signal: abortSignal }, chatConnectionsResponseSchema);
|
|
11
|
+
return await requestJson(config, "/v1/chat-connections", { credentialBearing: true, signal: abortSignal }, chatConnectionsResponseSchema);
|
|
12
12
|
},
|
|
13
13
|
async create({ abortSignal, ...body }) {
|
|
14
|
-
return await requestJson(config, "/v1/chat-connections", {
|
|
14
|
+
return await requestJson(config, "/v1/chat-connections", {
|
|
15
|
+
credentialBearing: true,
|
|
16
|
+
signal: abortSignal,
|
|
17
|
+
method: "POST",
|
|
18
|
+
json: body,
|
|
19
|
+
}, chatConnectionSchema);
|
|
15
20
|
},
|
|
16
21
|
async get({ chatConnectionId, abortSignal }) {
|
|
17
|
-
return await requestJson(config, apiPath `/v1/chat-connections/${chatConnectionId}`, { signal: abortSignal, method: "GET" }, chatConnectionSchema);
|
|
22
|
+
return await requestJson(config, apiPath `/v1/chat-connections/${chatConnectionId}`, { credentialBearing: true, signal: abortSignal, method: "GET" }, chatConnectionSchema);
|
|
18
23
|
},
|
|
19
24
|
async update({ chatConnectionId, abortSignal, ...body }) {
|
|
20
|
-
return await requestJson(config, apiPath `/v1/chat-connections/${chatConnectionId}`, {
|
|
25
|
+
return await requestJson(config, apiPath `/v1/chat-connections/${chatConnectionId}`, {
|
|
26
|
+
credentialBearing: true,
|
|
27
|
+
signal: abortSignal,
|
|
28
|
+
method: "PATCH",
|
|
29
|
+
json: body,
|
|
30
|
+
}, chatConnectionSchema);
|
|
21
31
|
},
|
|
22
32
|
async rotateCredentials({ chatConnectionId, abortSignal, ...body }) {
|
|
23
|
-
return await requestJson(config, apiPath `/v1/chat-connections/${chatConnectionId}/credentials`, {
|
|
33
|
+
return await requestJson(config, apiPath `/v1/chat-connections/${chatConnectionId}/credentials`, {
|
|
34
|
+
credentialBearing: true,
|
|
35
|
+
signal: abortSignal,
|
|
36
|
+
method: "POST",
|
|
37
|
+
json: body,
|
|
38
|
+
}, chatConnectionSchema);
|
|
24
39
|
},
|
|
25
40
|
async checkHealth({ chatConnectionId, abortSignal }) {
|
|
26
|
-
return await requestJson(config, apiPath `/v1/chat-connections/${chatConnectionId}/health`, { signal: abortSignal, method: "POST" }, chatConnectionSchema);
|
|
41
|
+
return await requestJson(config, apiPath `/v1/chat-connections/${chatConnectionId}/health`, { credentialBearing: true, signal: abortSignal, method: "POST" }, chatConnectionSchema);
|
|
27
42
|
},
|
|
28
43
|
async listDeliveries({ chatConnectionId, abortSignal, ...query }) {
|
|
29
|
-
return await requestJson(config, apiPath `/v1/chat-connections/${chatConnectionId}/deliveries`, { signal: abortSignal, query }, chatDeliveryListSchema);
|
|
44
|
+
return await requestJson(config, apiPath `/v1/chat-connections/${chatConnectionId}/deliveries`, { credentialBearing: true, signal: abortSignal, query }, chatDeliveryListSchema);
|
|
30
45
|
},
|
|
31
46
|
async repairDelivery({ chatConnectionId, deliveryId, abortSignal, ...body }) {
|
|
32
|
-
return await requestJson(config, apiPath `/v1/chat-connections/${chatConnectionId}/deliveries/${deliveryId}/repair`, {
|
|
47
|
+
return await requestJson(config, apiPath `/v1/chat-connections/${chatConnectionId}/deliveries/${deliveryId}/repair`, {
|
|
48
|
+
credentialBearing: true,
|
|
49
|
+
signal: abortSignal,
|
|
50
|
+
method: "POST",
|
|
51
|
+
json: body,
|
|
52
|
+
}, chatDeliveryResultSchema);
|
|
33
53
|
},
|
|
34
54
|
async enable({ chatConnectionId, abortSignal }) {
|
|
35
|
-
return await requestJson(config, apiPath `/v1/chat-connections/${chatConnectionId}/enable`, { signal: abortSignal, method: "POST" }, chatConnectionSchema);
|
|
55
|
+
return await requestJson(config, apiPath `/v1/chat-connections/${chatConnectionId}/enable`, { credentialBearing: true, signal: abortSignal, method: "POST" }, chatConnectionSchema);
|
|
36
56
|
},
|
|
37
57
|
async disable({ chatConnectionId, abortSignal }) {
|
|
38
|
-
return await requestJson(config, apiPath `/v1/chat-connections/${chatConnectionId}/disable`, { signal: abortSignal, method: "POST" }, chatConnectionSchema);
|
|
58
|
+
return await requestJson(config, apiPath `/v1/chat-connections/${chatConnectionId}/disable`, { credentialBearing: true, signal: abortSignal, method: "POST" }, chatConnectionSchema);
|
|
39
59
|
},
|
|
40
60
|
async delete({ chatConnectionId, abortSignal }) {
|
|
41
|
-
await requestJson(config, apiPath `/v1/chat-connections/${chatConnectionId}`, { signal: abortSignal, method: "DELETE" });
|
|
61
|
+
await requestJson(config, apiPath `/v1/chat-connections/${chatConnectionId}`, { credentialBearing: true, signal: abortSignal, method: "DELETE" });
|
|
42
62
|
},
|
|
43
63
|
};
|
|
44
64
|
}
|
|
@@ -15,6 +15,7 @@ export function createChatDeliveriesResource(config) {
|
|
|
15
15
|
// Multi-value filters serialize as one comma-separated parameter.
|
|
16
16
|
status: status?.length ? status.join(",") : undefined,
|
|
17
17
|
},
|
|
18
|
+
credentialBearing: true,
|
|
18
19
|
signal: abortSignal,
|
|
19
20
|
}, chatDeliveriesResponseSchema);
|
|
20
21
|
},
|
|
@@ -8,20 +8,22 @@ import { apiPath, requestJson } from "../http.js";
|
|
|
8
8
|
export function createMcpConnectionsResource(config) {
|
|
9
9
|
const create = (async ({ abortSignal, ...body }) => requestJson(config, "/v1/mcp-connections", {
|
|
10
10
|
json: body,
|
|
11
|
+
credentialBearing: true,
|
|
11
12
|
signal: abortSignal,
|
|
12
13
|
method: "POST",
|
|
13
14
|
}, mcpConnectionResponseSchema));
|
|
14
15
|
return {
|
|
15
16
|
create,
|
|
16
17
|
async list({ abortSignal } = {}) {
|
|
17
|
-
return await requestJson(config, "/v1/mcp-connections", { signal: abortSignal }, mcpConnectionsResponseSchema);
|
|
18
|
+
return await requestJson(config, "/v1/mcp-connections", { credentialBearing: true, signal: abortSignal }, mcpConnectionsResponseSchema);
|
|
18
19
|
},
|
|
19
20
|
async get({ mcpConnectionId, abortSignal }) {
|
|
20
|
-
return await requestJson(config, apiPath `/v1/mcp-connections/${mcpConnectionId}`, { signal: abortSignal }, mcpConnectionResponseSchema);
|
|
21
|
+
return await requestJson(config, apiPath `/v1/mcp-connections/${mcpConnectionId}`, { credentialBearing: true, signal: abortSignal }, mcpConnectionResponseSchema);
|
|
21
22
|
},
|
|
22
23
|
async update({ mcpConnectionId, abortSignal, ...body }) {
|
|
23
24
|
return await requestJson(config, apiPath `/v1/mcp-connections/${mcpConnectionId}`, {
|
|
24
25
|
json: body,
|
|
26
|
+
credentialBearing: true,
|
|
25
27
|
signal: abortSignal,
|
|
26
28
|
method: "PATCH",
|
|
27
29
|
}, mcpConnectionResponseSchema);
|
|
@@ -29,15 +31,17 @@ export function createMcpConnectionsResource(config) {
|
|
|
29
31
|
async delete({ mcpConnectionId, abortSignal }) {
|
|
30
32
|
await requestJson(config, apiPath `/v1/mcp-connections/${mcpConnectionId}`, {
|
|
31
33
|
method: "DELETE",
|
|
34
|
+
credentialBearing: true,
|
|
32
35
|
signal: abortSignal,
|
|
33
36
|
});
|
|
34
37
|
},
|
|
35
38
|
async test({ mcpConnectionId, abortSignal }) {
|
|
36
|
-
return await requestJson(config, apiPath `/v1/mcp-connections/${mcpConnectionId}/test`, { method: "POST", signal: abortSignal }, mcpConnectionTestResponseSchema);
|
|
39
|
+
return await requestJson(config, apiPath `/v1/mcp-connections/${mcpConnectionId}/test`, { method: "POST", credentialBearing: true, signal: abortSignal }, mcpConnectionTestResponseSchema);
|
|
37
40
|
},
|
|
38
41
|
async reconnect({ mcpConnectionId, abortSignal, ...body }) {
|
|
39
42
|
return await requestJson(config, apiPath `/v1/mcp-connections/${mcpConnectionId}/reconnect`, {
|
|
40
43
|
json: body,
|
|
44
|
+
credentialBearing: true,
|
|
41
45
|
signal: abortSignal,
|
|
42
46
|
method: "POST",
|
|
43
47
|
}, mcpConnectionReconnectResultSchema);
|
|
@@ -10,17 +10,28 @@ import { requestJson } from "../http.js";
|
|
|
10
10
|
export function createMerchantConnectionResource(config) {
|
|
11
11
|
return {
|
|
12
12
|
async get({ abortSignal } = {}) {
|
|
13
|
-
return await requestJson(config, "/v1/merchant-connection", { signal: abortSignal }, merchantConnectionResponseSchema);
|
|
13
|
+
return await requestJson(config, "/v1/merchant-connection", { credentialBearing: true, signal: abortSignal }, merchantConnectionResponseSchema);
|
|
14
14
|
},
|
|
15
15
|
async create({ abortSignal, ...body }) {
|
|
16
|
-
return await requestJson(config, "/v1/merchant-connection", {
|
|
16
|
+
return await requestJson(config, "/v1/merchant-connection", {
|
|
17
|
+
json: body,
|
|
18
|
+
method: "POST",
|
|
19
|
+
credentialBearing: true,
|
|
20
|
+
signal: abortSignal,
|
|
21
|
+
}, merchantConnectionResponseSchema);
|
|
17
22
|
},
|
|
18
23
|
async update({ abortSignal, ...body }) {
|
|
19
|
-
return await requestJson(config, "/v1/merchant-connection", {
|
|
24
|
+
return await requestJson(config, "/v1/merchant-connection", {
|
|
25
|
+
json: body,
|
|
26
|
+
method: "PATCH",
|
|
27
|
+
credentialBearing: true,
|
|
28
|
+
signal: abortSignal,
|
|
29
|
+
}, merchantConnectionResponseSchema);
|
|
20
30
|
},
|
|
21
31
|
async retire({ abortSignal } = {}) {
|
|
22
32
|
await requestJson(config, "/v1/merchant-connection", {
|
|
23
33
|
method: "DELETE",
|
|
34
|
+
credentialBearing: true,
|
|
24
35
|
signal: abortSignal,
|
|
25
36
|
});
|
|
26
37
|
},
|
|
@@ -10,25 +10,27 @@ export function createProvidersResource(config) {
|
|
|
10
10
|
async create({ abortSignal, ...body }) {
|
|
11
11
|
return await requestJson(config, "/v1/providers", {
|
|
12
12
|
json: body,
|
|
13
|
+
credentialBearing: true,
|
|
13
14
|
signal: abortSignal,
|
|
14
15
|
method: "POST",
|
|
15
16
|
}, providerResponseSchema);
|
|
16
17
|
},
|
|
17
18
|
async list({ abortSignal } = {}) {
|
|
18
|
-
return await requestJson(config, "/v1/providers", { signal: abortSignal }, providersResponseSchema);
|
|
19
|
+
return await requestJson(config, "/v1/providers", { credentialBearing: true, signal: abortSignal }, providersResponseSchema);
|
|
19
20
|
},
|
|
20
21
|
async get({ providerId, abortSignal }) {
|
|
21
|
-
return await requestJson(config, apiPath `/v1/providers/${providerId}`, { signal: abortSignal }, providerResponseSchema);
|
|
22
|
+
return await requestJson(config, apiPath `/v1/providers/${providerId}`, { credentialBearing: true, signal: abortSignal }, providerResponseSchema);
|
|
22
23
|
},
|
|
23
24
|
async listModels({ providerId, abortSignal }) {
|
|
24
|
-
return await requestJson(config, apiPath `/v1/providers/${providerId}/models`, { signal: abortSignal }, providerModelsResponseSchema);
|
|
25
|
+
return await requestJson(config, apiPath `/v1/providers/${providerId}/models`, { credentialBearing: true, signal: abortSignal }, providerModelsResponseSchema);
|
|
25
26
|
},
|
|
26
27
|
async getThinkingLevels({ providerId, model, abortSignal }) {
|
|
27
|
-
return await requestJson(config, apiPath `/v1/providers/${providerId}/thinking-levels`, { signal: abortSignal, query: { model } }, thinkingLevelsResponseSchema);
|
|
28
|
+
return await requestJson(config, apiPath `/v1/providers/${providerId}/thinking-levels`, { credentialBearing: true, signal: abortSignal, query: { model } }, thinkingLevelsResponseSchema);
|
|
28
29
|
},
|
|
29
30
|
async update({ providerId, abortSignal, ...body }) {
|
|
30
31
|
return await requestJson(config, apiPath `/v1/providers/${providerId}`, {
|
|
31
32
|
json: body,
|
|
33
|
+
credentialBearing: true,
|
|
32
34
|
signal: abortSignal,
|
|
33
35
|
method: "PATCH",
|
|
34
36
|
}, providerResponseSchema);
|
|
@@ -36,6 +38,7 @@ export function createProvidersResource(config) {
|
|
|
36
38
|
async delete({ providerId, abortSignal, ...options }) {
|
|
37
39
|
await requestJson(config, apiPath `/v1/providers/${providerId}`, {
|
|
38
40
|
method: "DELETE",
|
|
41
|
+
credentialBearing: true,
|
|
39
42
|
signal: abortSignal,
|
|
40
43
|
query: {
|
|
41
44
|
confirmSnapshotInvalidation: options.confirmSnapshotInvalidation,
|
package/dist/types.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ import type { AgentSkillsResource } from "./resources/skills.ts";
|
|
|
13
13
|
import type { TasksResource } from "./resources/tasks.ts";
|
|
14
14
|
import type { UsageResource } from "./resources/usage.ts";
|
|
15
15
|
import type { WorkspacesResource } from "./resources/workspaces.ts";
|
|
16
|
-
export type KnownBlazingAgentsErrorCode = ApiErrorCode | "invalid_response" | "network_error" | "request_aborted" | "stream_error";
|
|
16
|
+
export type KnownBlazingAgentsErrorCode = ApiErrorCode | "credential_echo" | "invalid_response" | "network_error" | "request_aborted" | "stream_error";
|
|
17
17
|
export type BlazingAgentsErrorCode = KnownBlazingAgentsErrorCode | (string & {});
|
|
18
18
|
export type BlazingAgentsFetch = (input: string, init?: BlazingAgentsRequestInit) => Promise<Response>;
|
|
19
19
|
export interface BlazingAgentsRequestInit extends RequestInit {
|
|
@@ -23,6 +23,11 @@ export interface BlazingAgentsRequestInit extends RequestInit {
|
|
|
23
23
|
export interface RequestOptions {
|
|
24
24
|
body?: BodyInit | FormData | null;
|
|
25
25
|
clientRequestId?: string | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Set on operations the contract marks `x-credential-bearing`: a 2xx JSON
|
|
28
|
+
* body that contains a credential field is discarded and rejected.
|
|
29
|
+
*/
|
|
30
|
+
credentialBearing?: true;
|
|
26
31
|
/**
|
|
27
32
|
* Extra headers (e.g. `Content-Type: multipart/form-data` is set
|
|
28
33
|
* automatically by `fetch` when given a `FormData` body).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blazingagents/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.36.0",
|
|
4
4
|
"description": "TypeScript SDK for the Blazing Agents API",
|
|
5
5
|
"homepage": "https://docs.blazingagents.com",
|
|
6
6
|
"bugs": {
|
|
@@ -29,7 +29,6 @@
|
|
|
29
29
|
"README.md"
|
|
30
30
|
],
|
|
31
31
|
"scripts": {
|
|
32
|
-
"agent-tools:json": "node scripts/write-agent-tools-json.ts",
|
|
33
32
|
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
|
34
33
|
"check": "npm run typecheck && npm run test && npm run lint && npm run unused",
|
|
35
34
|
"fix": "ultracite fix",
|