@blazingagents/sdk 0.14.0 → 0.16.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/README.md +5 -231
- package/dist/approvals.d.ts +15 -0
- package/dist/approvals.js +20 -0
- package/dist/chat-transport.js +9 -2
- package/dist/client.d.ts +8 -1
- package/dist/client.js +41 -1
- package/dist/contracts/api.d.ts +9 -9
- package/dist/contracts/api.js +3 -3
- package/dist/contracts/entities/agent-approval.d.ts +32 -0
- package/dist/contracts/entities/agent-approval.js +12 -1
- package/dist/contracts/entities/agent-tools.d.ts +6 -0
- package/dist/contracts/entities/agent-tools.js +13 -0
- package/dist/contracts/entities/agents.d.ts +4 -1
- package/dist/contracts/entities/agents.js +9 -6
- package/dist/contracts/entities/chat.d.ts +95 -12
- package/dist/contracts/entities/chat.js +105 -36
- package/dist/contracts/entities/prompts.d.ts +9 -1
- package/dist/contracts/entities/prompts.js +14 -4
- package/dist/contracts/entities/sessions.d.ts +6 -0
- package/dist/contracts/entities/sessions.js +2 -2
- package/dist/contracts/entities/tasks.d.ts +4 -6
- package/dist/contracts/entities/tasks.js +4 -6
- package/dist/contracts/entities/usage.d.ts +18 -0
- package/dist/contracts/entities/usage.js +28 -0
- package/dist/contracts/ids.d.ts +1 -0
- package/dist/contracts/ids.js +1 -0
- package/dist/contracts/index.d.ts +11 -10
- package/dist/contracts/index.js +8 -7
- package/dist/contracts/limitations.d.ts +4 -4
- package/dist/contracts/limitations.js +4 -4
- package/dist/direct-chat-transport.d.ts +3 -0
- package/dist/direct-chat-transport.js +20 -22
- package/dist/functions.d.ts +38 -0
- package/dist/functions.js +299 -0
- package/dist/generation.d.ts +7 -1
- package/dist/generation.js +64 -12
- package/dist/http.js +3 -0
- package/dist/index.d.ts +6 -4
- package/dist/index.js +1 -0
- package/dist/relay.d.ts +11 -4
- package/dist/relay.js +41 -1
- package/dist/resources/agents.d.ts +0 -6
- package/dist/resources/agents.js +2 -6
- package/dist/resources/prompts.d.ts +0 -4
- package/dist/resources/prompts.js +2 -6
- package/dist/resources/sessions.js +4 -2
- package/dist/resources/usage.js +9 -1
- package/dist/types.d.ts +39 -1
- package/package.json +8 -6
package/README.md
CHANGED
|
@@ -21,14 +21,17 @@ requires Node.js 24 or newer.
|
|
|
21
21
|
- Public Zod contracts for validating API requests and responses.
|
|
22
22
|
- Cursor pagination and binary transfers.
|
|
23
23
|
- Request correlation and a typed, forward-compatible error model.
|
|
24
|
+
- End-user scoped clients for user-owned resources and generation.
|
|
24
25
|
|
|
25
26
|
## Installation
|
|
26
27
|
|
|
27
28
|
```console
|
|
28
|
-
npm install @blazingagents/sdk ai
|
|
29
|
+
npm install @blazingagents/sdk ai@^7.0.84 zod@^4.5.4
|
|
29
30
|
```
|
|
30
31
|
|
|
31
|
-
`ai`
|
|
32
|
+
`ai` (`^7.0.84`) and `zod` (`^4.5.4`) are peer dependencies. The SDK
|
|
33
|
+
re-exports AI SDK message types and Zod schemas, so consumers share these
|
|
34
|
+
dependencies with the SDK.
|
|
32
35
|
|
|
33
36
|
## Quick start
|
|
34
37
|
|
|
@@ -70,232 +73,3 @@ npm run test:consumer
|
|
|
70
73
|
## License
|
|
71
74
|
|
|
72
75
|
[MIT](LICENSE)
|
|
73
|
-
|
|
74
|
-
### Thinking level
|
|
75
|
-
|
|
76
|
-
Agent create/update accepts `thinkingLevel: "high"`, `"off"`, `"max"`, or
|
|
77
|
-
another nonempty string supported by the selected Model. Omission on creation
|
|
78
|
-
means Provider default; omission on update preserves the saved value, while
|
|
79
|
-
`thinkingLevel: null` clears it. Agent and Version responses include the
|
|
80
|
-
selection, and `restoreVersion` restores it through ordinary validation.
|
|
81
|
-
Use `client.providers.getThinkingLevels({ providerId, model })` to read
|
|
82
|
-
`{ known, levels }`. Unknown capabilities permit custom values that can still
|
|
83
|
-
be rejected during execution. Levels control reasoning, not a token/cost cap.
|
|
84
|
-
|
|
85
|
-
For native clients whose `Response` constructor does not support streaming bodies,
|
|
86
|
-
use `result.toStream()` on chat or terminal continuation results to read the
|
|
87
|
-
original SSE bytes. It shares one-shot ownership with `toResponse()`; choose one
|
|
88
|
-
accessor per result. Stream errors and cancellation retain the same behavior.
|
|
89
|
-
|
|
90
|
-
### Relay browser chat
|
|
91
|
-
|
|
92
|
-
Tenant browser apps use `BlazingAgentsChatTransport` with their own backend.
|
|
93
|
-
The backend holds the Tenant API key and authorizes each Session. The transport
|
|
94
|
-
sends the newest user message and resumes with the server-minted Session ID.
|
|
95
|
-
|
|
96
|
-
### Direct chat with the SDK
|
|
97
|
-
|
|
98
|
-
For the platform dashboard or another runtime with an authorized credential,
|
|
99
|
-
use `BlazingAgentsDirectChatTransport` with AI SDK `useChat`. It sends through
|
|
100
|
-
`client.chat()` and decodes the stream without constructing a streaming
|
|
101
|
-
`Response`. Inject a native streaming fetch implementation into `BlazingAgents`
|
|
102
|
-
when the runtime requires one.
|
|
103
|
-
|
|
104
|
-
```tsx
|
|
105
|
-
import { useMemo } from "react";
|
|
106
|
-
import { useChat } from "@ai-sdk/react";
|
|
107
|
-
import { BlazingAgents, BlazingAgentsDirectChatTransport } from "@blazingagents/sdk";
|
|
108
|
-
|
|
109
|
-
function Chat({ getCredential, agentId, initialSessionId, saveSessionId }) {
|
|
110
|
-
const transport = useMemo(
|
|
111
|
-
() => new BlazingAgentsDirectChatTransport({
|
|
112
|
-
getClient: async () => new BlazingAgents({ apiKey: await getCredential() }),
|
|
113
|
-
agentId,
|
|
114
|
-
sessionId: initialSessionId,
|
|
115
|
-
onSessionId: saveSessionId,
|
|
116
|
-
}),
|
|
117
|
-
[getCredential, agentId, initialSessionId, saveSessionId],
|
|
118
|
-
);
|
|
119
|
-
const chat = useChat({ transport });
|
|
120
|
-
// Render chat.messages and submit using chat.sendMessage({ text }).
|
|
121
|
-
}
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
Install `@ai-sdk/react` for the React hook. Keep the transport stable for one
|
|
125
|
-
Session; remount the chat with a new transport when switching Agents or
|
|
126
|
-
Sessions. `getClient` runs before each request, so it can read a current
|
|
127
|
-
dashboard credential. Return a `BlazingAgents` client with that credential.
|
|
128
|
-
|
|
129
|
-
On Session creation, `version` pins the Agent Version, and `userId` and
|
|
130
|
-
`metadata` set attribution. To invoke a stored Prompt, pass `promptId` and
|
|
131
|
-
optional `variables` to the transport. Its first Turn sends those fields in
|
|
132
|
-
place of the `useChat` user message. Later Turns send user messages and omit
|
|
133
|
-
the create options, including `version`.
|
|
134
|
-
|
|
135
|
-
`onSessionId` runs once for a newly created Session before stream consumption,
|
|
136
|
-
so it can be saved even if streaming later fails. The transport preserves user
|
|
137
|
-
message IDs, regeneration targets, and `useChat` cancellation. Regeneration
|
|
138
|
-
requires an existing Session. When `useChat` submits tool approval responses,
|
|
139
|
-
the transport sends each decision in order and streams the continuation. After
|
|
140
|
-
reload, `reconnectToStream` joins a queued or running continuation for the
|
|
141
|
-
supplied `sessionId`. It returns `null` when there is no active continuation.
|
|
142
|
-
It does not retry an interrupted ordinary Turn.
|
|
143
|
-
|
|
144
|
-
### Cancel requests
|
|
145
|
-
|
|
146
|
-
Pass an optional `abortSignal` in the request object for reads, writes, uploads,
|
|
147
|
-
and generation:
|
|
148
|
-
|
|
149
|
-
```ts
|
|
150
|
-
const controller = new AbortController();
|
|
151
|
-
const agents = client.agents.list({ abortSignal: controller.signal });
|
|
152
|
-
controller.abort();
|
|
153
|
-
await agents; // Rejects with the SDK's typed cancellation error.
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
SDK response parsing strips unknown object fields while validating required
|
|
157
|
-
fields and known field types. Request validation remains strict.
|
|
158
|
-
|
|
159
|
-
### Migrating from 0.2.x to 0.3.0
|
|
160
|
-
|
|
161
|
-
Resource and generation methods take a single request object, optional when no
|
|
162
|
-
fields are required. Move positional identifiers, body fields, and request
|
|
163
|
-
options into that object. Use `abortSignal` instead of
|
|
164
|
-
`signal`; custom fetch implementations still receive the native `signal`.
|
|
165
|
-
|
|
166
|
-
```ts
|
|
167
|
-
// Before (0.2.x)
|
|
168
|
-
client.agents.update(agentId, { name: "Builder" });
|
|
169
|
-
client.sessions.messages(agentId, sessionId, { signal });
|
|
170
|
-
client.agent(agentId).skills.list();
|
|
171
|
-
|
|
172
|
-
// After (0.3.0)
|
|
173
|
-
client.agents.update({ agentId, name: "Builder", abortSignal: signal });
|
|
174
|
-
client.sessions.messages({ agentId, sessionId, abortSignal: signal });
|
|
175
|
-
client.agent({ agentId }).skills.list({ abortSignal: signal });
|
|
176
|
-
```
|
|
177
|
-
|
|
178
|
-
`ResourceRequestOptions` replaces `ResourceReadOptions`. Cancellation stops the
|
|
179
|
-
request; it does not roll back a mutation already accepted by the server.
|
|
180
|
-
|
|
181
|
-
## Interactive resend
|
|
182
|
-
|
|
183
|
-
Successful interactive exchanges are saved together. Failed or canceled execution
|
|
184
|
-
leaves saved history unchanged, including the previous answer during regeneration;
|
|
185
|
-
executed usage and Tool effects remain. Retain submitted text/images until success
|
|
186
|
-
and resend edited or unchanged input through ordinary chat with a fresh message ID.
|
|
187
|
-
Stop requests cancellation; a lost response can hide a saved exchange. Reuse the
|
|
188
|
-
returned Session ID and load history normally on return. No outcome polling or
|
|
189
|
-
automatic generation retry is needed. See the [chatbot guide](https://docs.blazingagents.com/getting-started/chatbot)
|
|
190
|
-
and [working examples](https://github.com/blazingagents/examples).
|
|
191
|
-
|
|
192
|
-
## Automatic context compaction
|
|
193
|
-
|
|
194
|
-
Agents enable automatic compaction by default with a 16,384-token reserve.
|
|
195
|
-
A larger reserve compacts earlier. Settings are included in Agent Versions.
|
|
196
|
-
Compaction summarizes older history for the model while retaining the full
|
|
197
|
-
Session transcript; summarization calls contribute to token usage.
|
|
198
|
-
|
|
199
|
-
```ts
|
|
200
|
-
await client.agents.update({
|
|
201
|
-
agentId: "ag_...",
|
|
202
|
-
autoCompaction: true,
|
|
203
|
-
compactionReserveTokens: 32768,
|
|
204
|
-
});
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
### Tool approval policies (0.8.0)
|
|
208
|
-
|
|
209
|
-
Agents and immutable Agent Versions expose separate `approvalInChat` and
|
|
210
|
-
`approvalInTasks` policies. Create and update them through the ordinary Agent API:
|
|
211
|
-
|
|
212
|
-
```ts
|
|
213
|
-
await client.agents.update({
|
|
214
|
-
agentId,
|
|
215
|
-
approvalInChat: {
|
|
216
|
-
default: "full",
|
|
217
|
-
overrides: [
|
|
218
|
-
{ tool: { type: "builtin", name: "bash" }, decision: "manual" },
|
|
219
|
-
{
|
|
220
|
-
tool: { type: "mcp", connectionId: "mcp_0123456789abcdef", name: "send_mail" },
|
|
221
|
-
decision: "auto",
|
|
222
|
-
},
|
|
223
|
-
],
|
|
224
|
-
},
|
|
225
|
-
approvalInTasks: { default: "deny", overrides: [] },
|
|
226
|
-
});
|
|
227
|
-
```
|
|
228
|
-
|
|
229
|
-
An exact tool override wins over the default. Both policies default to `full`
|
|
230
|
-
with no overrides. `full` allows available tools, `deny` blocks execution,
|
|
231
|
-
`manual` requires human review, and `auto` uses backend LLM review. Review errors
|
|
232
|
-
block execution; escalation without an available human also blocks execution.
|
|
233
|
-
Policies do not grant tool access. MCP references use the original remote tool
|
|
234
|
-
name and connection ID; the backend validates attachment and discovery.
|
|
235
|
-
|
|
236
|
-
Omitting a policy from an update preserves it. Supplying one replaces that whole
|
|
237
|
-
policy; omitted or empty `overrides` clears its overrides. `restoreVersion`
|
|
238
|
-
restores both policies alongside the other versioned fields.
|
|
239
|
-
|
|
240
|
-
Interactive Sessions reuse `client.sessions.toolApprovals`,
|
|
241
|
-
`client.sessions.decideToolApproval`, and
|
|
242
|
-
`client.sessions.joinToolApprovalContinuation`. A configured backend human
|
|
243
|
-
reviewer path is required. Tasks and stateless generations have no human
|
|
244
|
-
continuation path and block manual or escalated calls; stateless generation uses
|
|
245
|
-
`approvalInChat`. The SDK does not run an approval reviewer.
|
|
246
|
-
|
|
247
|
-
Approval rows retain optional `tool`, `assistantMessageId`, `createdAt`, and
|
|
248
|
-
`decidedAt` metadata. `tool` and `decidedAt` may be null (admin tools have no
|
|
249
|
-
ordinary-policy reference). Persisted approval decisions remain
|
|
250
|
-
`pending | approved | denied`; policy modes are `full | deny | manual | auto`.
|
|
251
|
-
The root package exports `ApprovalDecision`, `ApprovalPolicy`, `ToolReference`,
|
|
252
|
-
and `ToolApprovalState`; runtime policy schemas are exported from
|
|
253
|
-
`@blazingagents/sdk/contracts`.
|
|
254
|
-
|
|
255
|
-
## Slack and Telegram
|
|
256
|
-
|
|
257
|
-
Use the [connection example](https://github.com/blazingagents/typescript-sdk/blob/main/examples/chat-integrations.md) to connect an existing
|
|
258
|
-
Agent through REST. BA hosts the Chat SDK runtime, conversation history, and
|
|
259
|
-
approval cards; no additional SDK resource is required.
|
|
260
|
-
|
|
261
|
-
`client.chatDeliveries.list` reads the Tenant-wide delivery feed across all
|
|
262
|
-
Chat Connections, newest first. `status` accepts `failed` and/or `ambiguous`;
|
|
263
|
-
omitting it returns both. For example, the failed and ambiguous deliveries
|
|
264
|
-
since a timestamp:
|
|
265
|
-
|
|
266
|
-
```ts
|
|
267
|
-
const page = await client.chatDeliveries.list({
|
|
268
|
-
status: ["failed", "ambiguous"],
|
|
269
|
-
since: "2026-09-01T00:00:00.000Z",
|
|
270
|
-
});
|
|
271
|
-
```
|
|
272
|
-
|
|
273
|
-
## Merchant monetization
|
|
274
|
-
|
|
275
|
-
Bill your own customers for model-token usage through your Polar or Dodo
|
|
276
|
-
merchant account. Blazing Agents records usage per Turn and delivers it to
|
|
277
|
-
your provider; your provider owns billing.
|
|
278
|
-
|
|
279
|
-
```ts
|
|
280
|
-
const client = new BlazingAgents({ apiKey: "ba_..." });
|
|
281
|
-
|
|
282
|
-
// One-time: connect your merchant account (dashboard or API).
|
|
283
|
-
await client.merchantConnection.create({
|
|
284
|
-
provider: "polar",
|
|
285
|
-
environment: "sandbox",
|
|
286
|
-
credential: "polar_oat_...", // organization access token
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
// On user onboarding in your backend: bind your user id to the
|
|
290
|
-
// provider-side customer so usage is attributed correctly.
|
|
291
|
-
await client.merchantBindings.put({
|
|
292
|
-
userId: "user_123",
|
|
293
|
-
customerId: "cust_polar_...",
|
|
294
|
-
});
|
|
295
|
-
```
|
|
296
|
-
|
|
297
|
-
`client.merchantUsageEvents` exposes the delivery ledger (`list`, `get`,
|
|
298
|
-
`summary`) and the operator actions `retry`, `release`, and `discard`. The
|
|
299
|
-
optional eligibility guard (`guard` on the connection) refuses new
|
|
300
|
-
executions when the bound customer lacks the required subscription or
|
|
301
|
-
balance; it is a provider-reported check, not a spending lock.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type UIMessage } from "ai";
|
|
2
|
+
import type { BlazingAgents } from "./client.ts";
|
|
3
|
+
interface ApprovalTarget {
|
|
4
|
+
abortSignal?: AbortSignal;
|
|
5
|
+
agentId: string;
|
|
6
|
+
sessionId: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Records each approval response in the assistant message's last step and
|
|
10
|
+
* returns the continuation they decide, or `undefined` when there are none.
|
|
11
|
+
*/
|
|
12
|
+
export declare function decideApprovalResponses(client: Pick<BlazingAgents, "sessions">, { message, ...target }: ApprovalTarget & {
|
|
13
|
+
message: UIMessage;
|
|
14
|
+
}): Promise<string | undefined>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { isToolUIPart } from "ai";
|
|
2
|
+
/**
|
|
3
|
+
* Records each approval response in the assistant message's last step and
|
|
4
|
+
* returns the continuation they decide, or `undefined` when there are none.
|
|
5
|
+
*/
|
|
6
|
+
export async function decideApprovalResponses(client, { message, ...target }) {
|
|
7
|
+
const lastStep = message.parts.findLastIndex((part) => part.type === "step-start");
|
|
8
|
+
let continuationId;
|
|
9
|
+
for (const part of message.parts.slice(lastStep + 1)) {
|
|
10
|
+
if (isToolUIPart(part) && part.state === "approval-responded") {
|
|
11
|
+
({ continuationId } = await client.sessions.decideToolApproval({
|
|
12
|
+
...target,
|
|
13
|
+
approvalId: part.approval.id,
|
|
14
|
+
approved: part.approval.approved,
|
|
15
|
+
reason: part.approval.reason,
|
|
16
|
+
}));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return continuationId;
|
|
20
|
+
}
|
package/dist/chat-transport.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DefaultChatTransport, } from "ai";
|
|
1
|
+
import { DefaultChatTransport, lastAssistantMessageIsCompleteWithApprovalResponses, } from "ai";
|
|
2
2
|
import { sessionIdSchema } from "./contracts/ids.js";
|
|
3
3
|
/**
|
|
4
4
|
* Adapts AI SDK chat requests to the Blazing Agents backend-relay shape and
|
|
@@ -31,7 +31,14 @@ export class BlazingAgentsChatTransport {
|
|
|
31
31
|
return response;
|
|
32
32
|
},
|
|
33
33
|
prepareSendMessagesRequest: ({ body, messageId, messages, trigger }) => {
|
|
34
|
-
const
|
|
34
|
+
const approvals = messages.at(-1)?.role === "assistant" &&
|
|
35
|
+
lastAssistantMessageIsCompleteWithApprovalResponses({ messages });
|
|
36
|
+
if (approvals && this.#sessionId === undefined) {
|
|
37
|
+
throw new Error("Tool approval requires an existing Session.");
|
|
38
|
+
}
|
|
39
|
+
const message = approvals
|
|
40
|
+
? messages.at(-1)
|
|
41
|
+
: messages.findLast((candidate) => candidate.role === "user");
|
|
35
42
|
if (!message) {
|
|
36
43
|
throw new Error("Chat submission requires a user message.");
|
|
37
44
|
}
|
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AgentClient, AgentsResource, ArtifactsResource, BlazingAgentsOptions, BlazingAgentsRequestOptions, ChatConnectionsResource, ChatDeliveriesResource, ChatInput, ChatResult, CompletionInput, CompletionResult, McpConnectionsResource, MemoriesResource, MerchantBindingsResource, MerchantConnectionResource, MerchantUsageEventsResource, ObjectInput, ObjectResult, PromptsResource, ProvidersResource, SessionsResource, TasksResource, TenantResource, UsageResource, WorkspacesResource } from "./types.ts";
|
|
1
|
+
import type { AgentClient, AgentsResource, ArtifactsResource, BlazingAgentsOptions, BlazingAgentsRequestOptions, ChatConnectionsResource, ChatDeliveriesResource, ChatInput, ChatResult, CompletionInput, CompletionResult, McpConnectionsResource, MemoriesResource, MerchantBindingsResource, MerchantConnectionResource, MerchantUsageEventsResource, ObjectInput, ObjectResult, PromptsResource, ProvidersResource, ResumeChatInput, SessionsResource, TasksResource, TenantResource, UsageResource, UserClient, WorkspacesResource } from "./types.ts";
|
|
2
2
|
export declare class BlazingAgents {
|
|
3
3
|
private readonly config;
|
|
4
4
|
readonly chatConnections: ChatConnectionsResource;
|
|
@@ -21,12 +21,19 @@ export declare class BlazingAgents {
|
|
|
21
21
|
agent({ agentId }: {
|
|
22
22
|
agentId: string;
|
|
23
23
|
}): AgentClient;
|
|
24
|
+
/** Scope requests to one end user. IDs use printable ASCII, at most 256 characters, without leading or trailing spaces. */
|
|
25
|
+
forUser(userId: string): UserClient;
|
|
24
26
|
/**
|
|
25
27
|
* `POST /v1/agents/:agentId/sessions` (create, no `sessionId`) or
|
|
26
28
|
* `POST /v1/agents/:agentId/sessions/:sessionId` (resume). Returns the
|
|
27
29
|
* session id and a byte-compatible SSE relay for `useChat`.
|
|
28
30
|
*/
|
|
29
31
|
chat(input: ChatInput): Promise<ChatResult>;
|
|
32
|
+
/**
|
|
33
|
+
* Reattaches function handlers after human tool approval and starts or
|
|
34
|
+
* joins the Session's continuation. Returns the continuation SSE relay.
|
|
35
|
+
*/
|
|
36
|
+
resumeChat(input: ResumeChatInput): Promise<ChatResult>;
|
|
30
37
|
/**
|
|
31
38
|
* `POST /v1/agents/:agentId/generation` — stateless one-shot text
|
|
32
39
|
* stream. Returns `textStream` + `await result.text` + `toResponse()`.
|
package/dist/client.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { chat, completion, objectGeneration, resumeChat, } from "./generation.js";
|
|
2
3
|
import { createAgentsResource } from "./resources/agents.js";
|
|
3
4
|
import { createArtifactsResource } from "./resources/artifacts.js";
|
|
4
5
|
import { createChatConnectionsResource } from "./resources/chat-connections.js";
|
|
@@ -18,6 +19,31 @@ import { createUsageResource } from "./resources/usage.js";
|
|
|
18
19
|
import { createWorkspacesResource } from "./resources/workspaces.js";
|
|
19
20
|
const DEFAULT_BASE_URL = "https://api.blazingagents.com";
|
|
20
21
|
const TRAILING_SLASH_RE = /\/+$/;
|
|
22
|
+
const scopedUserIdSchema = z
|
|
23
|
+
.string()
|
|
24
|
+
.max(256)
|
|
25
|
+
.regex(/^[\x21-\x7E](?:[\x20-\x7E]*[\x21-\x7E])?$/);
|
|
26
|
+
function createUserClient(config) {
|
|
27
|
+
const usage = createUsageResource(config);
|
|
28
|
+
return {
|
|
29
|
+
agents: createAgentsResource(config),
|
|
30
|
+
sessions: createSessionsResource(config),
|
|
31
|
+
prompts: createPromptsResource(config),
|
|
32
|
+
tasks: createTasksResource(config),
|
|
33
|
+
artifacts: createArtifactsResource(config),
|
|
34
|
+
workspaces: createWorkspacesResource(config),
|
|
35
|
+
memories: createMemoriesResource(config),
|
|
36
|
+
usage: { get: usage.get, sessions: usage.sessions },
|
|
37
|
+
agent: ({ agentId }) => ({
|
|
38
|
+
skills: createAgentSkillsResource(config, agentId),
|
|
39
|
+
}),
|
|
40
|
+
chat: (input) => chat(config, input),
|
|
41
|
+
completion: (input) => completion(config, input),
|
|
42
|
+
object: (input) => objectGeneration(config, input),
|
|
43
|
+
resumeChat: (input) => resumeChat(config, input),
|
|
44
|
+
withOptions: (options) => createUserClient({ ...config, clientRequestId: options.clientRequestId }),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
21
47
|
export class BlazingAgents {
|
|
22
48
|
config;
|
|
23
49
|
chatConnections;
|
|
@@ -66,6 +92,13 @@ export class BlazingAgents {
|
|
|
66
92
|
agent({ agentId }) {
|
|
67
93
|
return { skills: createAgentSkillsResource(this.config, agentId) };
|
|
68
94
|
}
|
|
95
|
+
/** Scope requests to one end user. IDs use printable ASCII, at most 256 characters, without leading or trailing spaces. */
|
|
96
|
+
forUser(userId) {
|
|
97
|
+
return createUserClient({
|
|
98
|
+
...this.config,
|
|
99
|
+
scopeUserId: scopedUserIdSchema.parse(userId),
|
|
100
|
+
});
|
|
101
|
+
}
|
|
69
102
|
/**
|
|
70
103
|
* `POST /v1/agents/:agentId/sessions` (create, no `sessionId`) or
|
|
71
104
|
* `POST /v1/agents/:agentId/sessions/:sessionId` (resume). Returns the
|
|
@@ -74,6 +107,13 @@ export class BlazingAgents {
|
|
|
74
107
|
chat(input) {
|
|
75
108
|
return chat(this.config, input);
|
|
76
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* Reattaches function handlers after human tool approval and starts or
|
|
112
|
+
* joins the Session's continuation. Returns the continuation SSE relay.
|
|
113
|
+
*/
|
|
114
|
+
resumeChat(input) {
|
|
115
|
+
return resumeChat(this.config, input);
|
|
116
|
+
}
|
|
77
117
|
/**
|
|
78
118
|
* `POST /v1/agents/:agentId/generation` — stateless one-shot text
|
|
79
119
|
* stream. Returns `textStream` + `await result.text` + `toResponse()`.
|
package/dist/contracts/api.d.ts
CHANGED
|
@@ -23,13 +23,15 @@ export declare const apiErrorCodeSchema: z.ZodEnum<{
|
|
|
23
23
|
agent_disabled: "agent_disabled";
|
|
24
24
|
agent_mcp_connection_not_found: "agent_mcp_connection_not_found";
|
|
25
25
|
agent_mcp_connections_invalid: "agent_mcp_connections_invalid";
|
|
26
|
-
agent_name_conflict: "agent_name_conflict";
|
|
27
26
|
agent_version_not_found: "agent_version_not_found";
|
|
28
27
|
api_key_limit_reached: "api_key_limit_reached";
|
|
29
28
|
artifact_session_cap_reached: "artifact_session_cap_reached";
|
|
30
29
|
chat_webhook_conflict: "chat_webhook_conflict";
|
|
31
30
|
chat_webhook_registration_failed: "chat_webhook_registration_failed";
|
|
32
31
|
checkout_evidence_mismatch: "checkout_evidence_mismatch";
|
|
32
|
+
forbidden: "forbidden";
|
|
33
|
+
function_call_conflict: "function_call_conflict";
|
|
34
|
+
idempotency_conflict: "idempotency_conflict";
|
|
33
35
|
internal: "internal";
|
|
34
36
|
invalid_cursor: "invalid_cursor";
|
|
35
37
|
invalid_request: "invalid_request";
|
|
@@ -59,8 +61,6 @@ export declare const apiErrorCodeSchema: z.ZodEnum<{
|
|
|
59
61
|
model_not_found: "model_not_found";
|
|
60
62
|
model_validation_unavailable: "model_validation_unavailable";
|
|
61
63
|
not_found: "not_found";
|
|
62
|
-
prompt_limit_reached: "prompt_limit_reached";
|
|
63
|
-
prompt_name_conflict: "prompt_name_conflict";
|
|
64
64
|
prompt_variable_missing: "prompt_variable_missing";
|
|
65
65
|
prompt_variable_unknown: "prompt_variable_unknown";
|
|
66
66
|
provider_historical_use: "provider_historical_use";
|
|
@@ -102,13 +102,15 @@ export declare const apiErrorSchema: z.ZodObject<{
|
|
|
102
102
|
agent_disabled: "agent_disabled";
|
|
103
103
|
agent_mcp_connection_not_found: "agent_mcp_connection_not_found";
|
|
104
104
|
agent_mcp_connections_invalid: "agent_mcp_connections_invalid";
|
|
105
|
-
agent_name_conflict: "agent_name_conflict";
|
|
106
105
|
agent_version_not_found: "agent_version_not_found";
|
|
107
106
|
api_key_limit_reached: "api_key_limit_reached";
|
|
108
107
|
artifact_session_cap_reached: "artifact_session_cap_reached";
|
|
109
108
|
chat_webhook_conflict: "chat_webhook_conflict";
|
|
110
109
|
chat_webhook_registration_failed: "chat_webhook_registration_failed";
|
|
111
110
|
checkout_evidence_mismatch: "checkout_evidence_mismatch";
|
|
111
|
+
forbidden: "forbidden";
|
|
112
|
+
function_call_conflict: "function_call_conflict";
|
|
113
|
+
idempotency_conflict: "idempotency_conflict";
|
|
112
114
|
internal: "internal";
|
|
113
115
|
invalid_cursor: "invalid_cursor";
|
|
114
116
|
invalid_request: "invalid_request";
|
|
@@ -138,8 +140,6 @@ export declare const apiErrorSchema: z.ZodObject<{
|
|
|
138
140
|
model_not_found: "model_not_found";
|
|
139
141
|
model_validation_unavailable: "model_validation_unavailable";
|
|
140
142
|
not_found: "not_found";
|
|
141
|
-
prompt_limit_reached: "prompt_limit_reached";
|
|
142
|
-
prompt_name_conflict: "prompt_name_conflict";
|
|
143
143
|
prompt_variable_missing: "prompt_variable_missing";
|
|
144
144
|
prompt_variable_unknown: "prompt_variable_unknown";
|
|
145
145
|
provider_historical_use: "provider_historical_use";
|
|
@@ -186,13 +186,15 @@ export declare const apiErrorResponseSchema: z.ZodObject<{
|
|
|
186
186
|
agent_disabled: "agent_disabled";
|
|
187
187
|
agent_mcp_connection_not_found: "agent_mcp_connection_not_found";
|
|
188
188
|
agent_mcp_connections_invalid: "agent_mcp_connections_invalid";
|
|
189
|
-
agent_name_conflict: "agent_name_conflict";
|
|
190
189
|
agent_version_not_found: "agent_version_not_found";
|
|
191
190
|
api_key_limit_reached: "api_key_limit_reached";
|
|
192
191
|
artifact_session_cap_reached: "artifact_session_cap_reached";
|
|
193
192
|
chat_webhook_conflict: "chat_webhook_conflict";
|
|
194
193
|
chat_webhook_registration_failed: "chat_webhook_registration_failed";
|
|
195
194
|
checkout_evidence_mismatch: "checkout_evidence_mismatch";
|
|
195
|
+
forbidden: "forbidden";
|
|
196
|
+
function_call_conflict: "function_call_conflict";
|
|
197
|
+
idempotency_conflict: "idempotency_conflict";
|
|
196
198
|
internal: "internal";
|
|
197
199
|
invalid_cursor: "invalid_cursor";
|
|
198
200
|
invalid_request: "invalid_request";
|
|
@@ -222,8 +224,6 @@ export declare const apiErrorResponseSchema: z.ZodObject<{
|
|
|
222
224
|
model_not_found: "model_not_found";
|
|
223
225
|
model_validation_unavailable: "model_validation_unavailable";
|
|
224
226
|
not_found: "not_found";
|
|
225
|
-
prompt_limit_reached: "prompt_limit_reached";
|
|
226
|
-
prompt_name_conflict: "prompt_name_conflict";
|
|
227
227
|
prompt_variable_missing: "prompt_variable_missing";
|
|
228
228
|
prompt_variable_unknown: "prompt_variable_unknown";
|
|
229
229
|
provider_historical_use: "provider_historical_use";
|
package/dist/contracts/api.js
CHANGED
|
@@ -18,8 +18,10 @@ export const apiErrorIssueSchema = z
|
|
|
18
18
|
*/
|
|
19
19
|
export const apiErrorCodeSchema = z.enum([
|
|
20
20
|
"invalid_request",
|
|
21
|
+
"idempotency_conflict",
|
|
21
22
|
"validation_failed",
|
|
22
23
|
"unauthorized",
|
|
24
|
+
"forbidden",
|
|
23
25
|
"not_found",
|
|
24
26
|
"quota_exceeded",
|
|
25
27
|
"subscription_required",
|
|
@@ -33,14 +35,11 @@ export const apiErrorCodeSchema = z.enum([
|
|
|
33
35
|
"agent_version_not_found",
|
|
34
36
|
"agent_mcp_connection_not_found",
|
|
35
37
|
"agent_mcp_connections_invalid",
|
|
36
|
-
"agent_name_conflict",
|
|
37
38
|
"provider_required",
|
|
38
39
|
"api_key_limit_reached",
|
|
39
40
|
"artifact_session_cap_reached",
|
|
40
41
|
"invalid_cursor",
|
|
41
42
|
"message_not_found",
|
|
42
|
-
"prompt_limit_reached",
|
|
43
|
-
"prompt_name_conflict",
|
|
44
43
|
"prompt_variable_missing",
|
|
45
44
|
"prompt_variable_unknown",
|
|
46
45
|
"provider_in_use",
|
|
@@ -66,6 +65,7 @@ export const apiErrorCodeSchema = z.enum([
|
|
|
66
65
|
"session_version_mismatch",
|
|
67
66
|
"tool_approval_continuation_not_found",
|
|
68
67
|
"tool_approval_decision_conflict",
|
|
68
|
+
"function_call_conflict",
|
|
69
69
|
"skill_invalid_archive",
|
|
70
70
|
"skill_invalid_markdown",
|
|
71
71
|
"skill_limit_reached",
|
|
@@ -28,6 +28,37 @@ export declare const toolReferenceSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
28
28
|
connectionId: z.ZodString;
|
|
29
29
|
name: z.ZodString;
|
|
30
30
|
}, z.core.$strict>], "type">;
|
|
31
|
+
/**
|
|
32
|
+
* Identifies the tool behind one execution or approval record. Caller-local
|
|
33
|
+
* functions appear here for display and audit only; approval policies keep
|
|
34
|
+
* `toolReferenceSchema`, so function names never become Agent configuration.
|
|
35
|
+
*/
|
|
36
|
+
export declare const toolExecutionReferenceSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
37
|
+
type: z.ZodLiteral<"builtin">;
|
|
38
|
+
name: z.ZodEnum<{
|
|
39
|
+
activate_skill: "activate_skill";
|
|
40
|
+
bash: "bash";
|
|
41
|
+
delete_memory: "delete_memory";
|
|
42
|
+
edit: "edit";
|
|
43
|
+
get_memory: "get_memory";
|
|
44
|
+
glob: "glob";
|
|
45
|
+
grep: "grep";
|
|
46
|
+
publish_artifacts: "publish_artifacts";
|
|
47
|
+
read: "read";
|
|
48
|
+
save_memory: "save_memory";
|
|
49
|
+
search_memories: "search_memories";
|
|
50
|
+
update_memory: "update_memory";
|
|
51
|
+
write: "write";
|
|
52
|
+
write_todos: "write_todos";
|
|
53
|
+
}>;
|
|
54
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
55
|
+
type: z.ZodLiteral<"mcp">;
|
|
56
|
+
connectionId: z.ZodString;
|
|
57
|
+
name: z.ZodString;
|
|
58
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
59
|
+
type: z.ZodLiteral<"function">;
|
|
60
|
+
name: z.ZodString;
|
|
61
|
+
}, z.core.$strict>], "type">;
|
|
31
62
|
export declare const approvalPolicySchema: z.ZodObject<{
|
|
32
63
|
default: z.ZodEnum<{
|
|
33
64
|
auto: "auto";
|
|
@@ -69,4 +100,5 @@ export declare const approvalPolicySchema: z.ZodObject<{
|
|
|
69
100
|
}, z.core.$strict>;
|
|
70
101
|
export type ApprovalPolicy = z.infer<typeof approvalPolicySchema>;
|
|
71
102
|
export type ToolReference = z.infer<typeof toolReferenceSchema>;
|
|
103
|
+
export type ToolExecutionReference = z.infer<typeof toolExecutionReferenceSchema>;
|
|
72
104
|
export type ApprovalDecision = z.infer<typeof approvalDecisionSchema>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { mcpConnectionIdSchema } from "../ids.js";
|
|
3
|
-
import { AGENT_TOOL_CATALOG } from "./agent-tools.js";
|
|
3
|
+
import { AGENT_TOOL_CATALOG, chatFunctionNameSchema } from "./agent-tools.js";
|
|
4
4
|
export const approvalDecisionSchema = z.enum([
|
|
5
5
|
"full",
|
|
6
6
|
"deny",
|
|
@@ -25,6 +25,17 @@ export const toolReferenceSchema = z.discriminatedUnion("type", [
|
|
|
25
25
|
})
|
|
26
26
|
.strict(),
|
|
27
27
|
]);
|
|
28
|
+
/**
|
|
29
|
+
* Identifies the tool behind one execution or approval record. Caller-local
|
|
30
|
+
* functions appear here for display and audit only; approval policies keep
|
|
31
|
+
* `toolReferenceSchema`, so function names never become Agent configuration.
|
|
32
|
+
*/
|
|
33
|
+
export const toolExecutionReferenceSchema = z.discriminatedUnion("type", [
|
|
34
|
+
...toolReferenceSchema.options,
|
|
35
|
+
z
|
|
36
|
+
.object({ type: z.literal("function"), name: chatFunctionNameSchema })
|
|
37
|
+
.strict(),
|
|
38
|
+
]);
|
|
28
39
|
export const approvalPolicySchema = z
|
|
29
40
|
.object({
|
|
30
41
|
default: approvalDecisionSchema,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
1
2
|
/** Tool groups an Agent can attach. File operations use its durable Workspace. */
|
|
2
3
|
export declare const agentToolGroupIds: readonly ["workspace", "write_todos", "memory"];
|
|
3
4
|
export type AgentToolGroupId = (typeof agentToolGroupIds)[number];
|
|
@@ -24,3 +25,8 @@ export declare const AGENT_TOOL_CATALOG: readonly [{
|
|
|
24
25
|
readonly tools: readonly ["save_memory", "get_memory", "search_memories", "update_memory", "delete_memory"];
|
|
25
26
|
}];
|
|
26
27
|
export declare function expandToolGroups(ids: Iterable<string>): Set<string>;
|
|
28
|
+
/**
|
|
29
|
+
* A model-facing tool name. Built-in tool names and the `mcp__` prefix used
|
|
30
|
+
* for MCP tools are reserved so a caller function never shadows them.
|
|
31
|
+
*/
|
|
32
|
+
export declare const chatFunctionNameSchema: z.ZodString;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
1
2
|
/** Tool groups an Agent can attach. File operations use its durable Workspace. */
|
|
2
3
|
export const agentToolGroupIds = [
|
|
3
4
|
"workspace",
|
|
@@ -50,3 +51,15 @@ export function expandToolGroups(ids) {
|
|
|
50
51
|
}
|
|
51
52
|
return result;
|
|
52
53
|
}
|
|
54
|
+
const RESERVED_CHAT_FUNCTION_NAMES = new Set([
|
|
55
|
+
...AGENT_TOOL_CATALOG.flatMap((group) => group.tools),
|
|
56
|
+
"activate_skill",
|
|
57
|
+
]);
|
|
58
|
+
/**
|
|
59
|
+
* A model-facing tool name. Built-in tool names and the `mcp__` prefix used
|
|
60
|
+
* for MCP tools are reserved so a caller function never shadows them.
|
|
61
|
+
*/
|
|
62
|
+
export const chatFunctionNameSchema = z
|
|
63
|
+
.string()
|
|
64
|
+
.regex(/^[A-Za-z][A-Za-z0-9_-]{0,63}$/)
|
|
65
|
+
.refine((name) => !(RESERVED_CHAT_FUNCTION_NAMES.has(name) || name.startsWith("mcp__")), { message: "Function name is reserved for a built-in or MCP tool." });
|
|
@@ -121,7 +121,7 @@ export declare const agentSchema: z.ZodObject<{
|
|
|
121
121
|
}>;
|
|
122
122
|
}, z.core.$strip>;
|
|
123
123
|
export declare const agentsResponseSchema: z.ZodObject<{
|
|
124
|
-
|
|
124
|
+
data: z.ZodArray<z.ZodObject<{
|
|
125
125
|
approvalInChat: z.ZodDefault<z.ZodObject<{
|
|
126
126
|
default: z.ZodEnum<{
|
|
127
127
|
auto: "auto";
|
|
@@ -228,6 +228,7 @@ export declare const agentsResponseSchema: z.ZodObject<{
|
|
|
228
228
|
disabled: "disabled";
|
|
229
229
|
}>;
|
|
230
230
|
}, z.core.$strip>>;
|
|
231
|
+
nextCursor: z.ZodNullable<z.ZodString>;
|
|
231
232
|
}, z.core.$strip>;
|
|
232
233
|
export declare const agentResponseSchema: z.ZodObject<{
|
|
233
234
|
approvalInChat: z.ZodDefault<z.ZodObject<{
|
|
@@ -337,6 +338,8 @@ export declare const agentResponseSchema: z.ZodObject<{
|
|
|
337
338
|
}>;
|
|
338
339
|
}, z.core.$strip>;
|
|
339
340
|
export declare const agentsListQuerySchema: z.ZodObject<{
|
|
341
|
+
cursor: z.ZodOptional<z.ZodString>;
|
|
342
|
+
limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
340
343
|
userId: z.ZodOptional<z.ZodString>;
|
|
341
344
|
workspaceId: z.ZodOptional<z.ZodString>;
|
|
342
345
|
}, z.core.$strict>;
|