@blazingagents/sdk 0.1.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/LICENSE +21 -0
- package/README.md +366 -0
- package/dist/chat-transport.d.ts +17 -0
- package/dist/chat-transport.js +58 -0
- package/dist/client.d.ts +38 -0
- package/dist/client.js +86 -0
- package/dist/contracts/api.d.ts +256 -0
- package/dist/contracts/api.js +189 -0
- package/dist/contracts/entities/agent-tools.d.ts +26 -0
- package/dist/contracts/entities/agent-tools.js +52 -0
- package/dist/contracts/entities/agents.d.ts +183 -0
- package/dist/contracts/entities/agents.js +153 -0
- package/dist/contracts/entities/artifacts.d.ts +71 -0
- package/dist/contracts/entities/artifacts.js +71 -0
- package/dist/contracts/entities/attribution.d.ts +27 -0
- package/dist/contracts/entities/attribution.js +27 -0
- package/dist/contracts/entities/chat.d.ts +269 -0
- package/dist/contracts/entities/chat.js +198 -0
- package/dist/contracts/entities/mcp-connections.d.ts +421 -0
- package/dist/contracts/entities/mcp-connections.js +473 -0
- package/dist/contracts/entities/memories.d.ts +56 -0
- package/dist/contracts/entities/memories.js +62 -0
- package/dist/contracts/entities/prompts.d.ts +61 -0
- package/dist/contracts/entities/prompts.js +96 -0
- package/dist/contracts/entities/providers.d.ts +123 -0
- package/dist/contracts/entities/providers.js +111 -0
- package/dist/contracts/entities/sessions.d.ts +156 -0
- package/dist/contracts/entities/sessions.js +120 -0
- package/dist/contracts/entities/skills.d.ts +167 -0
- package/dist/contracts/entities/skills.js +153 -0
- package/dist/contracts/entities/tasks.d.ts +457 -0
- package/dist/contracts/entities/tasks.js +252 -0
- package/dist/contracts/entities/tenants.d.ts +69 -0
- package/dist/contracts/entities/tenants.js +54 -0
- package/dist/contracts/entities/usage.d.ts +95 -0
- package/dist/contracts/entities/usage.js +117 -0
- package/dist/contracts/entities/workspaces.d.ts +89 -0
- package/dist/contracts/entities/workspaces.js +71 -0
- package/dist/contracts/ids.d.ts +57 -0
- package/dist/contracts/ids.js +79 -0
- package/dist/contracts/index.d.ts +15 -0
- package/dist/contracts/index.js +16 -0
- package/dist/contracts/limitations.d.ts +138 -0
- package/dist/contracts/limitations.js +140 -0
- package/dist/contracts/utils.d.ts +3 -0
- package/dist/contracts/utils.js +7 -0
- package/dist/errors.d.ts +33 -0
- package/dist/errors.js +48 -0
- package/dist/generation.d.ts +5 -0
- package/dist/generation.js +422 -0
- package/dist/http.d.ts +21 -0
- package/dist/http.js +307 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +13 -0
- package/dist/relay.d.ts +20 -0
- package/dist/relay.js +113 -0
- package/dist/resources/agents.d.ts +8 -0
- package/dist/resources/agents.js +82 -0
- package/dist/resources/artifacts.d.ts +5 -0
- package/dist/resources/artifacts.js +29 -0
- package/dist/resources/mcp-connections.d.ts +2 -0
- package/dist/resources/mcp-connections.js +40 -0
- package/dist/resources/memories.d.ts +7 -0
- package/dist/resources/memories.js +33 -0
- package/dist/resources/prompts.d.ts +6 -0
- package/dist/resources/prompts.js +36 -0
- package/dist/resources/providers.d.ts +5 -0
- package/dist/resources/providers.js +38 -0
- package/dist/resources/sessions.d.ts +8 -0
- package/dist/resources/sessions.js +49 -0
- package/dist/resources/skills.d.ts +2 -0
- package/dist/resources/skills.js +49 -0
- package/dist/resources/tasks.d.ts +7 -0
- package/dist/resources/tasks.js +63 -0
- package/dist/resources/tenant.d.ts +6 -0
- package/dist/resources/tenant.js +19 -0
- package/dist/resources/usage.d.ts +7 -0
- package/dist/resources/usage.js +19 -0
- package/dist/resources/workspaces.d.ts +2 -0
- package/dist/resources/workspaces.js +31 -0
- package/dist/types.d.ts +381 -0
- package/dist/types.js +1 -0
- package/package.json +65 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Blazing Agents
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
# `@blazingagents/sdk`
|
|
2
|
+
|
|
3
|
+
The resource-style client SDK for the Blazing Agents `/v1` API.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The SDK wraps the Blazing Agents REST API with a thin, typed client in the
|
|
8
|
+
stripe/openai-node shape. It provides:
|
|
9
|
+
|
|
10
|
+
- **Resource namespaces** for management CRUD (`agents`, `workspaces`,
|
|
11
|
+
`prompts`, `providers`, `tasks`, `sessions`, `artifacts`, `tenant`, `usage`),
|
|
12
|
+
plus Agent-scoped Skills through `client.agent(agentId).skills`.
|
|
13
|
+
- **Generation methods** with a raw `useChat` SSE relay and AI SDK–shaped
|
|
14
|
+
completion/object results.
|
|
15
|
+
- **A single error class** (`BlazingAgentsError`) with known-code completion
|
|
16
|
+
and forward-compatible server codes.
|
|
17
|
+
|
|
18
|
+
`ai` is a peer dependency (`^7`). The SDK re-exports `UIMessage` from `ai` —
|
|
19
|
+
it never redeclares it.
|
|
20
|
+
|
|
21
|
+
## Quick start
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { BlazingAgents } from "@blazingagents/sdk";
|
|
25
|
+
|
|
26
|
+
const client = new BlazingAgents({
|
|
27
|
+
apiKey: "ba_your_api_key",
|
|
28
|
+
// baseUrl defaults to https://api.blazingagents.com.
|
|
29
|
+
onResponse(response) {
|
|
30
|
+
// Store response.requestId with your logs for support correlation.
|
|
31
|
+
console.log(response.requestId, response.status);
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// --- Management ---
|
|
36
|
+
|
|
37
|
+
// Agents
|
|
38
|
+
const agent = await client.agents.create({
|
|
39
|
+
name: "My Agent",
|
|
40
|
+
model: "openrouter/auto",
|
|
41
|
+
instructions: "Be helpful.",
|
|
42
|
+
tools: ["write_todos"],
|
|
43
|
+
});
|
|
44
|
+
// Every Agent receives a Workspace. Its runtime stays lazy until first use.
|
|
45
|
+
const defaultWorkspace = await client.workspaces.get({
|
|
46
|
+
workspaceId: agent.workspaceId,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const list = await client.agents.list();
|
|
50
|
+
const fetched = await client.agents.get(agent.id);
|
|
51
|
+
const updated = await client.agents.update(agent.id, { name: "Renamed" });
|
|
52
|
+
|
|
53
|
+
// Pass an existing Workspace to share it, or switch to one later.
|
|
54
|
+
const sharedWorkspace = await client.workspaces.create({ name: "Team files" });
|
|
55
|
+
const teammate = await client.agents.create({
|
|
56
|
+
name: "Teammate",
|
|
57
|
+
model: "openrouter/auto",
|
|
58
|
+
workspaceId: sharedWorkspace.id,
|
|
59
|
+
});
|
|
60
|
+
await client.agents.update(agent.id, { workspaceId: sharedWorkspace.id });
|
|
61
|
+
|
|
62
|
+
// Agent-owned Skills
|
|
63
|
+
const skills = client.agent(teammate.id).skills;
|
|
64
|
+
const skill = await skills.create({
|
|
65
|
+
path: "SKILL.md",
|
|
66
|
+
content: "---\nname: release-notes\ndescription: Draft release notes.\n---\n",
|
|
67
|
+
});
|
|
68
|
+
await skills.putFile({
|
|
69
|
+
skillId: skill.id,
|
|
70
|
+
path: "references/style.md",
|
|
71
|
+
content: "Use sentence case.",
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// Deleting an Agent preserves its Workspace for explicit cleanup or reuse.
|
|
75
|
+
await client.agents.delete(agent.id, false);
|
|
76
|
+
await client.workspaces.get({ workspaceId: sharedWorkspace.id });
|
|
77
|
+
|
|
78
|
+
// Prompts
|
|
79
|
+
const prompt = await client.prompts.create({
|
|
80
|
+
name: "Greeting",
|
|
81
|
+
template: "Hello {{name}}!",
|
|
82
|
+
});
|
|
83
|
+
const promptList = await client.prompts.list();
|
|
84
|
+
|
|
85
|
+
// Providers
|
|
86
|
+
const provider = await client.providers.create({
|
|
87
|
+
name: "My OpenRouter",
|
|
88
|
+
providerType: "openrouter",
|
|
89
|
+
apiKey: "sk-or-...",
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// Tenant settings
|
|
93
|
+
const settings = await client.tenant.get();
|
|
94
|
+
await client.tenant.patch({
|
|
95
|
+
quota: { monthlyTokenLimit: 100_000, monthlyRequestLimit: null, resetDay: 1 },
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// Usage
|
|
99
|
+
const usage = await client.usage.get({ groupBy: "agent" });
|
|
100
|
+
const agentUsage = await client.usage.getForAgent(agent.id);
|
|
101
|
+
|
|
102
|
+
// Tasks
|
|
103
|
+
const task = await client.tasks.create({
|
|
104
|
+
agentId: agent.id,
|
|
105
|
+
name: "Daily Report",
|
|
106
|
+
prompt: "Generate the daily report",
|
|
107
|
+
});
|
|
108
|
+
const run = await client.tasks.createRun(task.task.id);
|
|
109
|
+
|
|
110
|
+
// Persist task.task.id and run.runId, then return to the caller.
|
|
111
|
+
|
|
112
|
+
// In a later request, scheduled job, or worker invocation:
|
|
113
|
+
const outcome = await client.tasks.getRun(task.task.id, run.runId);
|
|
114
|
+
if (outcome.status !== "queued" && outcome.status !== "running") {
|
|
115
|
+
const transcript = await client.tasks.runMessages(task.task.id, run.runId);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Sessions
|
|
119
|
+
const sessions = await client.sessions.list(agent.id);
|
|
120
|
+
const messages = await client.sessions.messages(agent.id, sessionId);
|
|
121
|
+
|
|
122
|
+
// Artifacts
|
|
123
|
+
const artifacts = await client.artifacts.list({ agentId: agent.id });
|
|
124
|
+
const artifact = artifacts.data[0];
|
|
125
|
+
if (artifact) {
|
|
126
|
+
const { url } = await client.artifacts.createDownloadUrl(artifact.artifactId);
|
|
127
|
+
const bytes = await (await fetch(url)).arrayBuffer();
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Generation request inputs accept `clientRequestId` for caller-owned
|
|
132
|
+
correlation without raw headers. For any resource or generation request, use
|
|
133
|
+
`client.withOptions({ clientRequestId })` to create a scoped client view. The
|
|
134
|
+
callback receives the method, path
|
|
135
|
+
without query, status, duration, server `requestId`, and the same optional
|
|
136
|
+
`clientRequestId` once for every received response, including errors and
|
|
137
|
+
streaming handshakes. Callback failures are ignored and transport failures
|
|
138
|
+
with no response do not invoke it. The server-owned `requestId` identifies one
|
|
139
|
+
HTTP attempt and should be retained when contacting support.
|
|
140
|
+
Successful generated message metadata separately exposes `usage.turnId` for
|
|
141
|
+
the admitted, metered Turn. It is not the HTTP `requestId` or message ID.
|
|
142
|
+
|
|
143
|
+
## Generation methods
|
|
144
|
+
|
|
145
|
+
### `client.chat(input)` — stateful UI message stream
|
|
146
|
+
|
|
147
|
+
The server mints the `ss_` session id. Start a new chat with a single
|
|
148
|
+
`client.chat({ agentId, message })` call — no `sessionId`, no `mode` —
|
|
149
|
+
and read the minted id from `await result.sessionId` (resolved from the
|
|
150
|
+
create response's `Location` header):
|
|
151
|
+
|
|
152
|
+
```ts
|
|
153
|
+
// Create — the server mints the ss_ id and returns it via Location.
|
|
154
|
+
const created = await client.chat({
|
|
155
|
+
agentId: agent.id,
|
|
156
|
+
message: {
|
|
157
|
+
id: "msg_user_1",
|
|
158
|
+
role: "user",
|
|
159
|
+
parts: [{ type: "text", text: "Hello!" }],
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
const sessionId = await created.sessionId;
|
|
163
|
+
return created.toResponse();
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
`toResponse()` exposes the server's AI SDK UI-message SSE response unchanged
|
|
167
|
+
for relay to the browser. It is one-shot; a repeated call throws a
|
|
168
|
+
`BlazingAgentsError` with `code: "stream_error"`. `result.sessionId` remains
|
|
169
|
+
independently awaitable before or after selecting the response.
|
|
170
|
+
|
|
171
|
+
After `useChat` successfully consumes that response, pass the same `sessionId`
|
|
172
|
+
on a later request to continue the chat:
|
|
173
|
+
|
|
174
|
+
```ts
|
|
175
|
+
const result = await client.chat({
|
|
176
|
+
agentId: agent.id,
|
|
177
|
+
sessionId,
|
|
178
|
+
message: {
|
|
179
|
+
id: "msg_user_2",
|
|
180
|
+
role: "user",
|
|
181
|
+
parts: [{ type: "text", text: "Follow up" }],
|
|
182
|
+
},
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
return result.toResponse();
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
`trigger: "regenerate-message"` is valid only when `sessionId` is present.
|
|
189
|
+
`messageId` remains optional when regenerating an existing Session.
|
|
190
|
+
|
|
191
|
+
Prompt-invocation variant (server resolves + renders the template):
|
|
192
|
+
|
|
193
|
+
```ts
|
|
194
|
+
const result = await client.chat({
|
|
195
|
+
agentId: agent.id,
|
|
196
|
+
promptId: "prompt_...",
|
|
197
|
+
variables: { name: "Alice" },
|
|
198
|
+
});
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### `client.completion(input)` — stateless text stream
|
|
202
|
+
|
|
203
|
+
`POST /v1/agents/:agentId/generation` with text output. Returns a text-stream result:
|
|
204
|
+
|
|
205
|
+
```ts
|
|
206
|
+
const result = await client.completion({
|
|
207
|
+
agentId: agent.id,
|
|
208
|
+
prompt: "Write a haiku about the sea.",
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
for await (const delta of result.textStream) {
|
|
212
|
+
process.stdout.write(delta);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const fullText = await result.text;
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### `client.object(input)` — stateless structured output
|
|
219
|
+
|
|
220
|
+
`POST /v1/agents/:agentId/generation` with structured output. Returns a partial-object stream:
|
|
221
|
+
|
|
222
|
+
```ts
|
|
223
|
+
const result = await client.object({
|
|
224
|
+
agentId: agent.id,
|
|
225
|
+
prompt: "Give me a person",
|
|
226
|
+
schema: {
|
|
227
|
+
type: "object",
|
|
228
|
+
properties: {
|
|
229
|
+
name: { type: "string" },
|
|
230
|
+
age: { type: "number" },
|
|
231
|
+
},
|
|
232
|
+
required: ["name"],
|
|
233
|
+
},
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
for await (const partial of result.partialObjectStream) {
|
|
237
|
+
console.log(partial);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const finalObject = await result.object;
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
## React `useChat` transport
|
|
244
|
+
|
|
245
|
+
Keep `BlazingAgents` and its API key on your backend. The browser-safe
|
|
246
|
+
`BlazingAgentsChatTransport` sends the latest user message, forwards
|
|
247
|
+
regeneration metadata, captures the Session ID from the first response's
|
|
248
|
+
`Location` header, and includes that ID on later sends.
|
|
249
|
+
|
|
250
|
+
### Tenant backend
|
|
251
|
+
|
|
252
|
+
```ts
|
|
253
|
+
import {
|
|
254
|
+
BlazingAgents,
|
|
255
|
+
createChatRelay,
|
|
256
|
+
createCompletionRelay,
|
|
257
|
+
} from "@blazingagents/sdk";
|
|
258
|
+
|
|
259
|
+
const client = new BlazingAgents({ apiKey: process.env.BLAZING_AGENTS_API_KEY });
|
|
260
|
+
|
|
261
|
+
const resolveContext = async (request: Request) => {
|
|
262
|
+
const user = await authenticateApplicationRequest(request);
|
|
263
|
+
return user ? { agentId: "ag_...", userId: user.id } : null;
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
export const POST = createChatRelay({
|
|
267
|
+
client,
|
|
268
|
+
resolveContext,
|
|
269
|
+
sessions: {
|
|
270
|
+
ownerOf: (sessionId) => chatSessions.ownerOf(sessionId),
|
|
271
|
+
recordOwner: (sessionId, userId) =>
|
|
272
|
+
chatSessions.recordOwner(sessionId, userId),
|
|
273
|
+
},
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
export const POST_COMPLETION = createCompletionRelay({ client, resolveContext });
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
Both factories accept standard Web `Request` objects and return standard Web
|
|
280
|
+
`Response` objects. They validate AI SDK input, ignore browser attempts to set
|
|
281
|
+
reserved agent/attribution fields, authorize Session resumes, record ownership
|
|
282
|
+
before returning a created stream, preserve safe status and correlation
|
|
283
|
+
headers, and propagate request cancellation. Framework adapters only need to
|
|
284
|
+
pass their request to the returned function.
|
|
285
|
+
|
|
286
|
+
### Browser
|
|
287
|
+
|
|
288
|
+
```tsx
|
|
289
|
+
import { useChat } from "@ai-sdk/react";
|
|
290
|
+
import { BlazingAgentsChatTransport } from "@blazingagents/sdk";
|
|
291
|
+
import { useState } from "react";
|
|
292
|
+
|
|
293
|
+
function useBlazingChat({
|
|
294
|
+
initialSessionId,
|
|
295
|
+
rememberSessionId,
|
|
296
|
+
}: {
|
|
297
|
+
initialSessionId?: string;
|
|
298
|
+
rememberSessionId: (sessionId: string) => void;
|
|
299
|
+
}) {
|
|
300
|
+
const [transport] = useState(
|
|
301
|
+
() =>
|
|
302
|
+
new BlazingAgentsChatTransport({
|
|
303
|
+
api: "/api/chat",
|
|
304
|
+
onSessionId: rememberSessionId,
|
|
305
|
+
sessionId: initialSessionId,
|
|
306
|
+
}),
|
|
307
|
+
);
|
|
308
|
+
return useChat({ transport });
|
|
309
|
+
}
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
The backend should derive `userId` from its authenticated session, never from
|
|
313
|
+
an untrusted browser field. The Session store is a durable server-owned mapping;
|
|
314
|
+
the opaque browser `sessionId` and End-user Attribution are not authorization.
|
|
315
|
+
Use one stable transport instance per chat. Persist the ID received by
|
|
316
|
+
`onSessionId`, and restore it through `sessionId` only after the backend has
|
|
317
|
+
authorized that Session for the current application user.
|
|
318
|
+
|
|
319
|
+
## Error model
|
|
320
|
+
|
|
321
|
+
All SDK failures use `BlazingAgentsError`. The server's lower-snake-case code
|
|
322
|
+
is preserved exactly, including a future code unknown to the installed SDK.
|
|
323
|
+
`KnownBlazingAgentsErrorCode` provides editor completion for the current API
|
|
324
|
+
catalog and four SDK-local codes:
|
|
325
|
+
|
|
326
|
+
| Local code | Meaning |
|
|
327
|
+
| --- | --- |
|
|
328
|
+
| `invalid_response` | A response is not a valid API envelope or successful JSON result. |
|
|
329
|
+
| `network_error` | Fetch failed before an HTTP exchange for a reason other than caller abort. |
|
|
330
|
+
| `request_aborted` | The caller's `AbortSignal` aborted the request. |
|
|
331
|
+
| `stream_error` | A stream failed after its response started or violated its stream contract. |
|
|
332
|
+
|
|
333
|
+
`BlazingAgentsError` exposes `code`, `message`, and optional `status`,
|
|
334
|
+
`details`, `param`, `headers`, `requestId`, `responseBody`,
|
|
335
|
+
`responseBodyTruncated`, and `cause`. A malformed response uses the stable
|
|
336
|
+
`invalid_response` message and retains a size-bounded body separately.
|
|
337
|
+
Response-backed failures copy `X-Request-Id` into `requestId`.
|
|
338
|
+
|
|
339
|
+
```ts
|
|
340
|
+
import { BlazingAgentsError } from "@blazingagents/sdk";
|
|
341
|
+
|
|
342
|
+
try {
|
|
343
|
+
await client.agents.get("ag_nonexistent...");
|
|
344
|
+
} catch (error) {
|
|
345
|
+
if (BlazingAgentsError.isInstance(error)) {
|
|
346
|
+
console.log(error.code);
|
|
347
|
+
console.log(error.status);
|
|
348
|
+
console.log(error.requestId);
|
|
349
|
+
console.log(error.message);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
Use `BlazingAgentsError.isInstance()` instead of `instanceof` when package
|
|
355
|
+
copies may cross realms or bundlers. See the public
|
|
356
|
+
[error catalog and stream boundary](https://docs.blazingagents.com/api-reference/protocols/errors).
|
|
357
|
+
|
|
358
|
+
## Development
|
|
359
|
+
|
|
360
|
+
Install dependencies and run the complete standalone check:
|
|
361
|
+
|
|
362
|
+
```bash
|
|
363
|
+
npm ci
|
|
364
|
+
npm run check
|
|
365
|
+
npm run test:consumer
|
|
366
|
+
```
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type ChatTransport, type HttpChatTransportInitOptions, type UIMessage } from "ai";
|
|
2
|
+
export type BlazingAgentsChatTransportOptions<UI_MESSAGE extends UIMessage = UIMessage> = Omit<HttpChatTransportInitOptions<UI_MESSAGE>, "prepareReconnectToStreamRequest" | "prepareSendMessagesRequest"> & {
|
|
3
|
+
/** Receives the Session ID minted by the first successful response. */
|
|
4
|
+
onSessionId?: (sessionId: string) => Promise<void> | void;
|
|
5
|
+
/** An authorized Session ID used to resume after a remount or reload. */
|
|
6
|
+
sessionId?: string;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Adapts AI SDK chat requests to the Blazing Agents backend-relay shape and
|
|
10
|
+
* resumes with the server-minted Session ID returned in `Location`.
|
|
11
|
+
*/
|
|
12
|
+
export declare class BlazingAgentsChatTransport<UI_MESSAGE extends UIMessage = UIMessage> implements ChatTransport<UI_MESSAGE> {
|
|
13
|
+
#private;
|
|
14
|
+
constructor(options?: BlazingAgentsChatTransportOptions<UI_MESSAGE>);
|
|
15
|
+
sendMessages(input: Parameters<ChatTransport<UI_MESSAGE>["sendMessages"]>[0]): Promise<ReadableStream<import("ai").UIMessageChunk>>;
|
|
16
|
+
reconnectToStream(_input: Parameters<ChatTransport<UI_MESSAGE>["reconnectToStream"]>[0]): Promise<null>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { DefaultChatTransport, } from "ai";
|
|
2
|
+
import { sessionIdSchema } from "./contracts/ids.js";
|
|
3
|
+
/**
|
|
4
|
+
* Adapts AI SDK chat requests to the Blazing Agents backend-relay shape and
|
|
5
|
+
* resumes with the server-minted Session ID returned in `Location`.
|
|
6
|
+
*/
|
|
7
|
+
export class BlazingAgentsChatTransport {
|
|
8
|
+
#transport;
|
|
9
|
+
#sessionId;
|
|
10
|
+
constructor(options = {}) {
|
|
11
|
+
const { onSessionId, sessionId, ...transportOptions } = options;
|
|
12
|
+
const transportFetch = transportOptions.fetch ?? globalThis.fetch;
|
|
13
|
+
this.#sessionId =
|
|
14
|
+
sessionId === undefined ? undefined : sessionIdSchema.parse(sessionId);
|
|
15
|
+
this.#transport = new DefaultChatTransport({
|
|
16
|
+
...transportOptions,
|
|
17
|
+
fetch: async (input, init) => {
|
|
18
|
+
const response = await transportFetch(input, init);
|
|
19
|
+
if (response.ok && this.#sessionId === undefined) {
|
|
20
|
+
try {
|
|
21
|
+
const location = response.headers.get("location");
|
|
22
|
+
const candidate = location?.split("/").pop();
|
|
23
|
+
this.#sessionId = sessionIdSchema.parse(candidate);
|
|
24
|
+
await onSessionId?.(this.#sessionId);
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
await response.body?.cancel(error).catch(() => undefined);
|
|
28
|
+
throw error;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return response;
|
|
32
|
+
},
|
|
33
|
+
prepareSendMessagesRequest: ({ body, messageId, messages, trigger }) => {
|
|
34
|
+
const message = messages.findLast((candidate) => candidate.role === "user");
|
|
35
|
+
if (!message) {
|
|
36
|
+
throw new Error("Chat submission requires a user message.");
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
body: {
|
|
40
|
+
...body,
|
|
41
|
+
message,
|
|
42
|
+
messageId,
|
|
43
|
+
...(this.#sessionId === undefined
|
|
44
|
+
? { sessionId: undefined }
|
|
45
|
+
: { sessionId: this.#sessionId }),
|
|
46
|
+
trigger,
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
sendMessages(input) {
|
|
53
|
+
return this.#transport.sendMessages(input);
|
|
54
|
+
}
|
|
55
|
+
reconnectToStream(_input) {
|
|
56
|
+
return Promise.resolve(null);
|
|
57
|
+
}
|
|
58
|
+
}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { AgentClient, AgentsResource, ArtifactsResource, BlazingAgentsOptions, BlazingAgentsRequestOptions, ChatInput, ChatResult, CompletionInput, CompletionResult, McpConnectionsResource, MemoriesResource, ObjectInput, ObjectResult, PromptsResource, ProvidersResource, SessionsResource, TasksResource, TenantResource, UsageResource, WorkspacesResource } from "./types.ts";
|
|
2
|
+
export declare class BlazingAgents {
|
|
3
|
+
private readonly config;
|
|
4
|
+
readonly agents: AgentsResource;
|
|
5
|
+
readonly sessions: SessionsResource;
|
|
6
|
+
readonly providers: ProvidersResource;
|
|
7
|
+
readonly mcpConnections: McpConnectionsResource;
|
|
8
|
+
readonly memories: MemoriesResource;
|
|
9
|
+
readonly prompts: PromptsResource;
|
|
10
|
+
readonly usage: UsageResource;
|
|
11
|
+
readonly artifacts: ArtifactsResource;
|
|
12
|
+
readonly tasks: TasksResource;
|
|
13
|
+
readonly tenant: TenantResource;
|
|
14
|
+
readonly workspaces: WorkspacesResource;
|
|
15
|
+
constructor(options: BlazingAgentsOptions);
|
|
16
|
+
agent(agentId: string): AgentClient;
|
|
17
|
+
/**
|
|
18
|
+
* `POST /v1/agents/:agentId/sessions` (create, no `sessionId`) or
|
|
19
|
+
* `POST /v1/agents/:agentId/sessions/:sessionId` (resume). Returns the
|
|
20
|
+
* session id and a byte-compatible SSE relay for `useChat`.
|
|
21
|
+
*/
|
|
22
|
+
chat(input: ChatInput): Promise<ChatResult>;
|
|
23
|
+
/**
|
|
24
|
+
* `POST /v1/agents/:agentId/generation` — stateless one-shot text
|
|
25
|
+
* stream. Returns `textStream` + `await result.text` + `toResponse()`.
|
|
26
|
+
*/
|
|
27
|
+
completion(input: CompletionInput): Promise<CompletionResult>;
|
|
28
|
+
/**
|
|
29
|
+
* `POST /v1/agents/:agentId/generation` — stateless structured output.
|
|
30
|
+
* Returns `partialObjectStream` + `await result.object` + `toResponse()`.
|
|
31
|
+
*/
|
|
32
|
+
object(input: ObjectInput): Promise<ObjectResult>;
|
|
33
|
+
/**
|
|
34
|
+
* Returns a lightweight client view whose resource and generation calls
|
|
35
|
+
* carry caller-owned correlation without raw header manipulation.
|
|
36
|
+
*/
|
|
37
|
+
withOptions(options: BlazingAgentsRequestOptions): BlazingAgents;
|
|
38
|
+
}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { chat, completion, objectGeneration } from "./generation.js";
|
|
2
|
+
import { createAgentsResource } from "./resources/agents.js";
|
|
3
|
+
import { createArtifactsResource } from "./resources/artifacts.js";
|
|
4
|
+
import { createMcpConnectionsResource } from "./resources/mcp-connections.js";
|
|
5
|
+
import { createMemoriesResource } from "./resources/memories.js";
|
|
6
|
+
import { createPromptsResource } from "./resources/prompts.js";
|
|
7
|
+
import { createProvidersResource } from "./resources/providers.js";
|
|
8
|
+
import { createSessionsResource } from "./resources/sessions.js";
|
|
9
|
+
import { createAgentSkillsResource } from "./resources/skills.js";
|
|
10
|
+
import { createTasksResource } from "./resources/tasks.js";
|
|
11
|
+
import { createTenantResource } from "./resources/tenant.js";
|
|
12
|
+
import { createUsageResource } from "./resources/usage.js";
|
|
13
|
+
import { createWorkspacesResource } from "./resources/workspaces.js";
|
|
14
|
+
const DEFAULT_BASE_URL = "https://api.blazingagents.com";
|
|
15
|
+
const TRAILING_SLASH_RE = /\/+$/;
|
|
16
|
+
export class BlazingAgents {
|
|
17
|
+
config;
|
|
18
|
+
agents;
|
|
19
|
+
sessions;
|
|
20
|
+
providers;
|
|
21
|
+
mcpConnections;
|
|
22
|
+
memories;
|
|
23
|
+
prompts;
|
|
24
|
+
usage;
|
|
25
|
+
artifacts;
|
|
26
|
+
tasks;
|
|
27
|
+
tenant;
|
|
28
|
+
workspaces;
|
|
29
|
+
constructor(options) {
|
|
30
|
+
this.config = {
|
|
31
|
+
apiKey: options.apiKey,
|
|
32
|
+
baseUrl: (options.baseUrl ?? DEFAULT_BASE_URL).replace(TRAILING_SLASH_RE, ""),
|
|
33
|
+
...(options.fetch ? { fetch: options.fetch } : {}),
|
|
34
|
+
...(options.clientRequestId === undefined
|
|
35
|
+
? {}
|
|
36
|
+
: { clientRequestId: options.clientRequestId }),
|
|
37
|
+
onResponse: options.onResponse,
|
|
38
|
+
};
|
|
39
|
+
this.agents = createAgentsResource(this.config);
|
|
40
|
+
this.sessions = createSessionsResource(this.config);
|
|
41
|
+
this.providers = createProvidersResource(this.config);
|
|
42
|
+
this.mcpConnections = createMcpConnectionsResource(this.config);
|
|
43
|
+
this.memories = createMemoriesResource(this.config);
|
|
44
|
+
this.prompts = createPromptsResource(this.config);
|
|
45
|
+
this.usage = createUsageResource(this.config);
|
|
46
|
+
this.artifacts = createArtifactsResource(this.config);
|
|
47
|
+
this.tasks = createTasksResource(this.config);
|
|
48
|
+
this.tenant = createTenantResource(this.config);
|
|
49
|
+
this.workspaces = createWorkspacesResource(this.config);
|
|
50
|
+
}
|
|
51
|
+
agent(agentId) {
|
|
52
|
+
return { skills: createAgentSkillsResource(this.config, agentId) };
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* `POST /v1/agents/:agentId/sessions` (create, no `sessionId`) or
|
|
56
|
+
* `POST /v1/agents/:agentId/sessions/:sessionId` (resume). Returns the
|
|
57
|
+
* session id and a byte-compatible SSE relay for `useChat`.
|
|
58
|
+
*/
|
|
59
|
+
chat(input) {
|
|
60
|
+
return chat(this.config, input);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* `POST /v1/agents/:agentId/generation` — stateless one-shot text
|
|
64
|
+
* stream. Returns `textStream` + `await result.text` + `toResponse()`.
|
|
65
|
+
*/
|
|
66
|
+
completion(input) {
|
|
67
|
+
return completion(this.config, input);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* `POST /v1/agents/:agentId/generation` — stateless structured output.
|
|
71
|
+
* Returns `partialObjectStream` + `await result.object` + `toResponse()`.
|
|
72
|
+
*/
|
|
73
|
+
object(input) {
|
|
74
|
+
return objectGeneration(this.config, input);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Returns a lightweight client view whose resource and generation calls
|
|
78
|
+
* carry caller-owned correlation without raw header manipulation.
|
|
79
|
+
*/
|
|
80
|
+
withOptions(options) {
|
|
81
|
+
return new BlazingAgents({
|
|
82
|
+
...this.config,
|
|
83
|
+
clientRequestId: options.clientRequestId,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|