@agents24/node 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 +42 -0
- package/compatibility.json +54 -0
- package/dist/artifacts.cjs +138 -0
- package/dist/artifacts.cjs.map +1 -0
- package/dist/artifacts.d.cts +76 -0
- package/dist/artifacts.d.ts +76 -0
- package/dist/artifacts.js +130 -0
- package/dist/artifacts.js.map +1 -0
- package/dist/index.cjs +733 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +564 -0
- package/dist/index.d.ts +564 -0
- package/dist/index.js +667 -0
- package/dist/index.js.map +1 -0
- package/dist/server.cjs +275 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.cts +47 -0
- package/dist/server.d.ts +47 -0
- package/dist/server.js +271 -0
- package/dist/server.js.map +1 -0
- package/dist/types/agents.d.ts +28 -0
- package/dist/types/agents.d.ts.map +1 -0
- package/dist/types/artifacts.d.ts +75 -0
- package/dist/types/artifacts.d.ts.map +1 -0
- package/dist/types/builders.d.ts +27 -0
- package/dist/types/builders.d.ts.map +1 -0
- package/dist/types/client-runtime-admin.d.ts +17 -0
- package/dist/types/client-runtime-admin.d.ts.map +1 -0
- package/dist/types/client.d.ts +17 -0
- package/dist/types/client.d.ts.map +1 -0
- package/dist/types/embed.d.ts +22 -0
- package/dist/types/embed.d.ts.map +1 -0
- package/dist/types/errors.d.ts +17 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/generated/manifest.d.ts +3 -0
- package/dist/types/generated/manifest.d.ts.map +1 -0
- package/dist/types/http.d.ts +25 -0
- package/dist/types/http.d.ts.map +1 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/runs.d.ts +17 -0
- package/dist/types/runs.d.ts.map +1 -0
- package/dist/types/server.d.ts +45 -0
- package/dist/types/server.d.ts.map +1 -0
- package/dist/types/streams.d.ts +4 -0
- package/dist/types/streams.d.ts.map +1 -0
- package/dist/types/types.d.ts +409 -0
- package/dist/types/types.d.ts.map +1 -0
- package/package.json +85 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,667 @@
|
|
|
1
|
+
import { randomUUID } from 'crypto';
|
|
2
|
+
import { createSseParser, parseRuntimeSsePayload, parseThreadSummarySsePayload } from '@agents24/client/protocol';
|
|
3
|
+
export { CONTRACT_HASH, RUNTIME_PROTOCOL_VERSION, THREAD_SUMMARY_PROTOCOL_VERSION, compressionFromContextWindow, createContextWindowTracker, mergeContextWindow, mergeContextWindowUpdate, normalizeContextCompression, normalizeContextWindow, parseRuntimeEvent, parseRuntimeSsePayload, parseThreadSummarySsePayload, validateResponseBlock, validateRuntimeEvent, validateThreadSummaryEvent } from '@agents24/client/protocol';
|
|
4
|
+
|
|
5
|
+
// src/http.ts
|
|
6
|
+
|
|
7
|
+
// src/errors.ts
|
|
8
|
+
var Agents24SDKError = class extends Error {
|
|
9
|
+
kind;
|
|
10
|
+
status;
|
|
11
|
+
details;
|
|
12
|
+
responseHeaders;
|
|
13
|
+
constructor(message, options) {
|
|
14
|
+
super(message, { cause: options.cause });
|
|
15
|
+
this.name = "Agents24SDKError";
|
|
16
|
+
this.kind = options.kind;
|
|
17
|
+
this.status = options.status;
|
|
18
|
+
this.details = options.details;
|
|
19
|
+
this.responseHeaders = options.responseHeaders;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// src/http.ts
|
|
24
|
+
function required(value, name) {
|
|
25
|
+
const normalized = String(value || "").trim();
|
|
26
|
+
if (!normalized) throw new Agents24SDKError(`Agents24 requires ${name}.`, { kind: "protocol" });
|
|
27
|
+
return normalized;
|
|
28
|
+
}
|
|
29
|
+
function normalizeBaseUrl(value) {
|
|
30
|
+
try {
|
|
31
|
+
return new URL(required(value, "baseUrl")).toString().replace(/\/+$/, "");
|
|
32
|
+
} catch (cause) {
|
|
33
|
+
if (cause instanceof Agents24SDKError) throw cause;
|
|
34
|
+
throw new Agents24SDKError("Agents24 received an invalid baseUrl.", { kind: "protocol", cause });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
async function errorDetails(response) {
|
|
38
|
+
const text = await response.text().catch(() => "");
|
|
39
|
+
if (!text) return null;
|
|
40
|
+
try {
|
|
41
|
+
return JSON.parse(text);
|
|
42
|
+
} catch {
|
|
43
|
+
return text;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function detailMessage(details) {
|
|
47
|
+
if (typeof details === "string" && details.trim()) return details.trim();
|
|
48
|
+
if (!details || typeof details !== "object" || Array.isArray(details)) return void 0;
|
|
49
|
+
const detail = details.detail;
|
|
50
|
+
if (typeof detail === "string" && detail.trim()) return detail.trim();
|
|
51
|
+
if (detail && typeof detail === "object" && !Array.isArray(detail)) {
|
|
52
|
+
const message2 = detail.message;
|
|
53
|
+
if (typeof message2 === "string" && message2.trim()) return message2.trim();
|
|
54
|
+
}
|
|
55
|
+
const message = details.message;
|
|
56
|
+
return typeof message === "string" && message.trim() ? message.trim() : void 0;
|
|
57
|
+
}
|
|
58
|
+
function responseHeaders(response) {
|
|
59
|
+
const headers = {};
|
|
60
|
+
for (const name of ["dpop-nonce", "retry-after", "www-authenticate", "x-request-id"]) {
|
|
61
|
+
const value = response.headers.get(name);
|
|
62
|
+
if (value) headers[name] = value;
|
|
63
|
+
}
|
|
64
|
+
return headers;
|
|
65
|
+
}
|
|
66
|
+
async function assertOk(response) {
|
|
67
|
+
if (response.ok) return;
|
|
68
|
+
const details = await errorDetails(response);
|
|
69
|
+
throw new Agents24SDKError(detailMessage(details) || response.statusText || "Agents24 request failed.", {
|
|
70
|
+
kind: "http",
|
|
71
|
+
status: response.status,
|
|
72
|
+
details,
|
|
73
|
+
responseHeaders: responseHeaders(response)
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
var Agents24HttpClient = class {
|
|
77
|
+
base;
|
|
78
|
+
apiKey;
|
|
79
|
+
organizationId;
|
|
80
|
+
projectId;
|
|
81
|
+
fetchImpl;
|
|
82
|
+
constructor(options) {
|
|
83
|
+
if (typeof process === "undefined" || process.release?.name !== "node") {
|
|
84
|
+
throw new Agents24SDKError("@agents24/node is for trusted server runtimes only.", { kind: "protocol" });
|
|
85
|
+
}
|
|
86
|
+
this.base = normalizeBaseUrl(options.baseUrl);
|
|
87
|
+
this.apiKey = required(options.apiKey, "apiKey");
|
|
88
|
+
this.organizationId = required(options.organizationId, "organizationId");
|
|
89
|
+
this.projectId = required(options.projectId, "projectId");
|
|
90
|
+
if (typeof options.fetchImpl !== "function" && typeof fetch !== "function") {
|
|
91
|
+
throw new Agents24SDKError("No fetch implementation is available. Use Node 22 or 24.", { kind: "protocol" });
|
|
92
|
+
}
|
|
93
|
+
this.fetchImpl = options.fetchImpl || fetch;
|
|
94
|
+
}
|
|
95
|
+
url(requestPath, query) {
|
|
96
|
+
const url = new URL(`${this.base}${requestPath}`);
|
|
97
|
+
for (const [key, value] of Object.entries(query || {})) {
|
|
98
|
+
if (value === void 0 || value === null || value === "") continue;
|
|
99
|
+
if (Array.isArray(value)) {
|
|
100
|
+
for (const item of value) {
|
|
101
|
+
if (item !== void 0 && item !== null && item !== "") url.searchParams.append(key, String(item));
|
|
102
|
+
}
|
|
103
|
+
} else {
|
|
104
|
+
url.searchParams.set(key, String(value));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return url.toString();
|
|
108
|
+
}
|
|
109
|
+
jsonHeaders(extra, options, mutation = false) {
|
|
110
|
+
return {
|
|
111
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
112
|
+
Accept: "application/json",
|
|
113
|
+
"Content-Type": "application/json",
|
|
114
|
+
"X-Organization-ID": this.organizationId,
|
|
115
|
+
"X-Project-ID": this.projectId,
|
|
116
|
+
"X-SDK-Contract": "1",
|
|
117
|
+
...mutation ? { "Idempotency-Key": options?.idempotencyKey || randomUUID() } : {},
|
|
118
|
+
...options?.requestMetadata ? { "X-Request-Metadata": JSON.stringify(options.requestMetadata) } : {},
|
|
119
|
+
...extra || {}
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
streamHeaders(extra, options, mutation = false) {
|
|
123
|
+
return this.jsonHeaders({ Accept: "text/event-stream", ...extra || {} }, options, mutation);
|
|
124
|
+
}
|
|
125
|
+
multipartHeaders(extra, options, mutation = false) {
|
|
126
|
+
return {
|
|
127
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
128
|
+
Accept: "application/json",
|
|
129
|
+
"X-Organization-ID": this.organizationId,
|
|
130
|
+
"X-Project-ID": this.projectId,
|
|
131
|
+
"X-SDK-Contract": "1",
|
|
132
|
+
...mutation ? { "Idempotency-Key": options?.idempotencyKey || randomUUID() } : {},
|
|
133
|
+
...extra || {}
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
async requestJson(requestPath, config = {}) {
|
|
137
|
+
const query = { ...config.query || {} };
|
|
138
|
+
if (config.options?.dryRun !== void 0) query.dry_run = config.options.dryRun;
|
|
139
|
+
if (config.options?.validateOnly !== void 0) query.validate_only = config.options.validateOnly;
|
|
140
|
+
const response = await this.fetchOrThrow(this.url(requestPath, query), {
|
|
141
|
+
method: config.method || "GET",
|
|
142
|
+
headers: this.jsonHeaders(config.headers, config.options, Boolean(config.mutation)),
|
|
143
|
+
...config.body === void 0 ? {} : { body: JSON.stringify(config.body) }
|
|
144
|
+
}, "Failed to connect to the Agents24 API.");
|
|
145
|
+
await assertOk(response);
|
|
146
|
+
return await response.json();
|
|
147
|
+
}
|
|
148
|
+
async fetchOrThrow(url, init, message) {
|
|
149
|
+
try {
|
|
150
|
+
return await this.fetchImpl(url, init);
|
|
151
|
+
} catch (cause) {
|
|
152
|
+
if (cause instanceof Agents24SDKError) throw cause;
|
|
153
|
+
throw new Agents24SDKError(message, { kind: "network", cause });
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
async function consumePayloads(response, onPayload, signal) {
|
|
158
|
+
if (!response.body) {
|
|
159
|
+
throw new Agents24SDKError("Stream response did not include a readable body.", { kind: "protocol" });
|
|
160
|
+
}
|
|
161
|
+
const reader = response.body.getReader();
|
|
162
|
+
const parser = createSseParser({ decoder: new TextDecoder(), onPayload, signal });
|
|
163
|
+
const abort = () => {
|
|
164
|
+
void reader.cancel(signal?.reason).catch(() => void 0);
|
|
165
|
+
};
|
|
166
|
+
if (signal?.aborted) return abort();
|
|
167
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
168
|
+
try {
|
|
169
|
+
while (!signal?.aborted) {
|
|
170
|
+
const { done, value } = await reader.read();
|
|
171
|
+
if (value) await parser.push(value);
|
|
172
|
+
if (done) break;
|
|
173
|
+
}
|
|
174
|
+
if (!signal?.aborted) await parser.finish();
|
|
175
|
+
} finally {
|
|
176
|
+
signal?.removeEventListener("abort", abort);
|
|
177
|
+
reader.releaseLock();
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
async function consumeRuntimeEventStream(response, onEvent, signal) {
|
|
181
|
+
await consumePayloads(response, async (payload) => {
|
|
182
|
+
const event = parseRuntimeSsePayload(payload);
|
|
183
|
+
if (onEvent) await onEvent(event);
|
|
184
|
+
}, signal);
|
|
185
|
+
}
|
|
186
|
+
async function consumeThreadSummaryEventStream(response, onEvent, signal) {
|
|
187
|
+
await consumePayloads(response, async (payload) => {
|
|
188
|
+
await onEvent(parseThreadSummarySsePayload(payload));
|
|
189
|
+
}, signal);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// src/agents.ts
|
|
193
|
+
var AgentsNamespace = class {
|
|
194
|
+
constructor(http) {
|
|
195
|
+
this.http = http;
|
|
196
|
+
}
|
|
197
|
+
http;
|
|
198
|
+
list(options = {}) {
|
|
199
|
+
return this.http.requestJson("/agents", { query: { status: options.status, skip: options.skip ?? 0, limit: options.limit ?? 20, view: options.view ?? "summary" } });
|
|
200
|
+
}
|
|
201
|
+
get(agentId) {
|
|
202
|
+
return this.http.requestJson(`/agents/${agentId}`);
|
|
203
|
+
}
|
|
204
|
+
create(request, options) {
|
|
205
|
+
return this.http.requestJson("/agents", { method: "POST", body: request, options, mutation: true });
|
|
206
|
+
}
|
|
207
|
+
update(agentId, request, options) {
|
|
208
|
+
return this.http.requestJson(`/agents/${agentId}`, { method: "PATCH", body: request, options, mutation: true });
|
|
209
|
+
}
|
|
210
|
+
updateGraph(agentId, graph, options) {
|
|
211
|
+
return this.http.requestJson(`/agents/${agentId}/graph`, { method: "PUT", body: graph, options, mutation: true });
|
|
212
|
+
}
|
|
213
|
+
delete(agentId, options) {
|
|
214
|
+
return this.http.requestJson(`/agents/${agentId}`, { method: "DELETE", options, mutation: true });
|
|
215
|
+
}
|
|
216
|
+
catalog() {
|
|
217
|
+
return this.http.requestJson("/agents/nodes/catalog");
|
|
218
|
+
}
|
|
219
|
+
schema(nodeTypes) {
|
|
220
|
+
return this.http.requestJson("/agents/nodes/schema", { method: "POST", body: { node_types: nodeTypes } });
|
|
221
|
+
}
|
|
222
|
+
validate(agentId) {
|
|
223
|
+
return this.http.requestJson(`/agents/${agentId}/validate`, { method: "POST", body: {} });
|
|
224
|
+
}
|
|
225
|
+
publish(agentId, options) {
|
|
226
|
+
return this.http.requestJson(`/agents/${agentId}/publish`, { method: "POST", body: {}, options, mutation: true });
|
|
227
|
+
}
|
|
228
|
+
startRun(agentId, payload, options) {
|
|
229
|
+
return this.http.requestJson(`/agents/${agentId}/run`, { method: "POST", body: payload, options, mutation: true });
|
|
230
|
+
}
|
|
231
|
+
async stream(agentId, payload, onEvent, mode, options = {}) {
|
|
232
|
+
const response = await this.http.fetchOrThrow(this.http.url(`/agents/${agentId}/stream`, { mode }), {
|
|
233
|
+
method: "POST",
|
|
234
|
+
headers: this.http.streamHeaders(),
|
|
235
|
+
body: JSON.stringify(payload),
|
|
236
|
+
signal: options.signal
|
|
237
|
+
}, "Failed to connect to the agent stream endpoint.");
|
|
238
|
+
await assertOk(response);
|
|
239
|
+
let runId = response.headers.get("X-Run-ID");
|
|
240
|
+
await consumeRuntimeEventStream(response, async (event) => {
|
|
241
|
+
runId ||= event.run_id;
|
|
242
|
+
if (onEvent) await onEvent(event);
|
|
243
|
+
}, options.signal);
|
|
244
|
+
return { threadId: response.headers.get("X-Thread-ID"), runId };
|
|
245
|
+
}
|
|
246
|
+
resumeRun(runId, payload, options) {
|
|
247
|
+
return this.http.requestJson(`/agents/runs/${runId}/resume`, { method: "POST", body: payload, options, mutation: true });
|
|
248
|
+
}
|
|
249
|
+
cancelRun(runId, options = {}) {
|
|
250
|
+
return this.http.requestJson(`/agents/runs/${runId}/cancel`, { method: "POST", body: { assistant_output_text: options.assistantOutputText }, mutation: true });
|
|
251
|
+
}
|
|
252
|
+
async uploadAttachments(agentId, options) {
|
|
253
|
+
const form = new FormData();
|
|
254
|
+
if (options.threadId) form.set("thread_id", options.threadId);
|
|
255
|
+
for (const file of options.files) form.append("files", file, file.name);
|
|
256
|
+
const response = await this.http.fetchOrThrow(this.http.url(`/agents/${agentId}/attachments/upload`), {
|
|
257
|
+
method: "POST",
|
|
258
|
+
headers: this.http.multipartHeaders(),
|
|
259
|
+
body: form
|
|
260
|
+
}, "Failed to connect to the agent attachment endpoint.");
|
|
261
|
+
await assertOk(response);
|
|
262
|
+
return await response.json();
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
// src/builders.ts
|
|
267
|
+
function refId(ref) {
|
|
268
|
+
return typeof ref === "string" ? ref : ref.id;
|
|
269
|
+
}
|
|
270
|
+
function refs(values) {
|
|
271
|
+
return [...new Set((values || []).map(refId).filter(Boolean))];
|
|
272
|
+
}
|
|
273
|
+
function graphNode(id, type, x, y, config = {}) {
|
|
274
|
+
return { id, type, position: { x, y }, config };
|
|
275
|
+
}
|
|
276
|
+
function toolsetAttachments(options) {
|
|
277
|
+
const seen = /* @__PURE__ */ new Set();
|
|
278
|
+
return (options.toolsetAttachments || []).flatMap((attachment) => {
|
|
279
|
+
const id = refId(attachment.toolset);
|
|
280
|
+
if (!id || seen.has(id)) return [];
|
|
281
|
+
seen.add(id);
|
|
282
|
+
const policy = attachment.versionPolicy || { mode: "latest" };
|
|
283
|
+
return [{
|
|
284
|
+
toolset_id: id,
|
|
285
|
+
loading_mode: attachment.loadingMode || "static",
|
|
286
|
+
version_policy: policy.mode === "pinned" ? { mode: "pinned", version_id: policy.versionId } : { mode: "latest" }
|
|
287
|
+
}];
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
var AgentDefinitionBuilder = class {
|
|
291
|
+
constructor(agents, options) {
|
|
292
|
+
this.agents = agents;
|
|
293
|
+
this.options = options;
|
|
294
|
+
}
|
|
295
|
+
agents;
|
|
296
|
+
options;
|
|
297
|
+
toGraph() {
|
|
298
|
+
const agentConfig = {
|
|
299
|
+
instructions: this.options.instructions || "",
|
|
300
|
+
tools: refs(this.options.tools),
|
|
301
|
+
toolset_attachments: toolsetAttachments(this.options),
|
|
302
|
+
input_sources: [{ id: "workflow-text", value_ref: { namespace: "workflow_input", key: "text", label: "Workflow input / Text" } }]
|
|
303
|
+
};
|
|
304
|
+
if (this.options.model) agentConfig.model_id = refId(this.options.model);
|
|
305
|
+
return {
|
|
306
|
+
spec_version: "4.0",
|
|
307
|
+
graph_type: "agent",
|
|
308
|
+
workflow_contract: { inputs: [] },
|
|
309
|
+
state_contract: { variables: [] },
|
|
310
|
+
nodes: [
|
|
311
|
+
graphNode("start", "start", 0, 0),
|
|
312
|
+
graphNode("agent", "agent", 260, 0, agentConfig),
|
|
313
|
+
graphNode("end", "end", 520, 0, {
|
|
314
|
+
output_schema: {
|
|
315
|
+
name: "workflow_result",
|
|
316
|
+
mode: "simple",
|
|
317
|
+
schema: { type: "object", additionalProperties: false, properties: { response: { type: "string" } }, required: ["response"] }
|
|
318
|
+
},
|
|
319
|
+
output_bindings: [{ json_pointer: "/response", value_ref: { namespace: "node_output", node_id: "agent", key: "output_text", label: "Agent response" } }]
|
|
320
|
+
})
|
|
321
|
+
],
|
|
322
|
+
edges: [
|
|
323
|
+
{ id: "start-agent", source: "start", target: "agent", type: "control" },
|
|
324
|
+
{ id: "agent-end", source: "agent", target: "end", type: "control" }
|
|
325
|
+
]
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
toCreateRequest() {
|
|
329
|
+
const knowledge = refs(this.options.knowledge);
|
|
330
|
+
return {
|
|
331
|
+
name: this.options.name,
|
|
332
|
+
description: this.options.description ?? null,
|
|
333
|
+
graph_definition: this.toGraph(),
|
|
334
|
+
memory_config: {
|
|
335
|
+
...this.options.memory || {},
|
|
336
|
+
...knowledge.length ? { long_term_enabled: true, long_term_index_id: knowledge[0], knowledge_refs: knowledge } : {}
|
|
337
|
+
},
|
|
338
|
+
execution_constraints: this.options.execution || {}
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
create(options) {
|
|
342
|
+
return this.agents.create(this.toCreateRequest(), options);
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
var GraphBuilder = class {
|
|
346
|
+
nodes = /* @__PURE__ */ new Map();
|
|
347
|
+
edges = [];
|
|
348
|
+
node(type, config = {}, options = {}) {
|
|
349
|
+
const id = options.id || `${type}_${this.nodes.size + 1}`;
|
|
350
|
+
if (this.nodes.has(id)) throw new Error(`Duplicate graph node id: ${id}`);
|
|
351
|
+
const value = graphNode(id, type, options.x ?? this.nodes.size * 260, options.y ?? 0, config);
|
|
352
|
+
if (options.label) value.label = options.label;
|
|
353
|
+
this.nodes.set(id, value);
|
|
354
|
+
return value;
|
|
355
|
+
}
|
|
356
|
+
connect(source, target, options = {}) {
|
|
357
|
+
const sourceId = typeof source === "string" ? source : source.id;
|
|
358
|
+
const targetId = typeof target === "string" ? target : target.id;
|
|
359
|
+
if (!this.nodes.has(sourceId)) throw new Error(`Unknown source node id: ${sourceId}`);
|
|
360
|
+
if (!this.nodes.has(targetId)) throw new Error(`Unknown target node id: ${targetId}`);
|
|
361
|
+
this.edges.push({
|
|
362
|
+
id: options.id || `${sourceId}-${targetId}`,
|
|
363
|
+
source: sourceId,
|
|
364
|
+
target: targetId,
|
|
365
|
+
type: "control",
|
|
366
|
+
source_handle: options.sourceHandle,
|
|
367
|
+
target_handle: options.targetHandle
|
|
368
|
+
});
|
|
369
|
+
return this;
|
|
370
|
+
}
|
|
371
|
+
toGraph() {
|
|
372
|
+
return {
|
|
373
|
+
spec_version: "4.0",
|
|
374
|
+
graph_type: "agent",
|
|
375
|
+
workflow_contract: { inputs: [] },
|
|
376
|
+
state_contract: { variables: [] },
|
|
377
|
+
nodes: [...this.nodes.values()],
|
|
378
|
+
edges: [...this.edges]
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
// src/client-runtime-admin.ts
|
|
384
|
+
var ClientDeploymentsNamespace = class {
|
|
385
|
+
constructor(http) {
|
|
386
|
+
this.http = http;
|
|
387
|
+
}
|
|
388
|
+
http;
|
|
389
|
+
create(request, options) {
|
|
390
|
+
return this.http.requestJson("/client-runtime/deployments", {
|
|
391
|
+
method: "POST",
|
|
392
|
+
body: request,
|
|
393
|
+
options,
|
|
394
|
+
mutation: true
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
get(deploymentId) {
|
|
398
|
+
return this.http.requestJson(`/client-runtime/deployments/${deploymentId}`);
|
|
399
|
+
}
|
|
400
|
+
update(deploymentId, request, options) {
|
|
401
|
+
return this.http.requestJson(`/client-runtime/deployments/${deploymentId}`, {
|
|
402
|
+
method: "PATCH",
|
|
403
|
+
body: request,
|
|
404
|
+
options,
|
|
405
|
+
mutation: true
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
promote(deploymentId, request, options) {
|
|
409
|
+
return this.http.requestJson(`/client-runtime/deployments/${deploymentId}/promote`, {
|
|
410
|
+
method: "POST",
|
|
411
|
+
body: request,
|
|
412
|
+
options,
|
|
413
|
+
mutation: true
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
revoke(deploymentId, options) {
|
|
417
|
+
return this.http.requestJson(`/client-runtime/deployments/${deploymentId}`, {
|
|
418
|
+
method: "DELETE",
|
|
419
|
+
options,
|
|
420
|
+
mutation: true
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
var ClientSessionsNamespace = class {
|
|
425
|
+
constructor(http) {
|
|
426
|
+
this.http = http;
|
|
427
|
+
}
|
|
428
|
+
http;
|
|
429
|
+
createBackendSession(deploymentId, request, options) {
|
|
430
|
+
return this.http.requestJson(
|
|
431
|
+
`/client-runtime/deployments/${deploymentId}/session-tokens`,
|
|
432
|
+
{
|
|
433
|
+
method: "POST",
|
|
434
|
+
body: request,
|
|
435
|
+
options,
|
|
436
|
+
mutation: true,
|
|
437
|
+
headers: options?.dpopProof ? { DPoP: options.dpopProof } : void 0
|
|
438
|
+
}
|
|
439
|
+
);
|
|
440
|
+
}
|
|
441
|
+
};
|
|
442
|
+
|
|
443
|
+
// src/embed.ts
|
|
444
|
+
var EmbedNamespace = class {
|
|
445
|
+
constructor(http) {
|
|
446
|
+
this.http = http;
|
|
447
|
+
}
|
|
448
|
+
http;
|
|
449
|
+
async streamAgent(agentId, payload, onEvent, options = {}) {
|
|
450
|
+
return this.stream(`/public/embed/agents/${agentId}/chat/stream`, payload, onEvent, options);
|
|
451
|
+
}
|
|
452
|
+
async attachAgentRun(agentId, runId, payload, onEvent, options = {}) {
|
|
453
|
+
return this.stream(`/public/embed/agents/${agentId}/runs/${runId}/stream`, payload, onEvent, options);
|
|
454
|
+
}
|
|
455
|
+
async stream(path, payload, onEvent, options) {
|
|
456
|
+
const response = await this.http.fetchOrThrow(this.http.url(path), {
|
|
457
|
+
method: "POST",
|
|
458
|
+
headers: this.http.streamHeaders(void 0, options, true),
|
|
459
|
+
body: JSON.stringify(payload),
|
|
460
|
+
signal: options.signal
|
|
461
|
+
}, "Failed to connect to the embedded-agent stream endpoint.");
|
|
462
|
+
await assertOk(response);
|
|
463
|
+
let runId = response.headers.get("X-Run-ID");
|
|
464
|
+
await consumeRuntimeEventStream(response, async (event) => {
|
|
465
|
+
runId ||= event.run_id;
|
|
466
|
+
if (onEvent) await onEvent(event);
|
|
467
|
+
}, options.signal);
|
|
468
|
+
return { threadId: response.headers.get("X-Thread-ID"), runId };
|
|
469
|
+
}
|
|
470
|
+
resumeAgentRun(agentId, runId, payload, options) {
|
|
471
|
+
return this.http.requestJson(`/public/embed/agents/${agentId}/runs/${runId}/resume`, { method: "POST", body: payload, options, mutation: true });
|
|
472
|
+
}
|
|
473
|
+
startAgentRunMcpAuth(agentId, runId, serverId, payload, options) {
|
|
474
|
+
return this.http.requestJson(`/public/embed/agents/${agentId}/runs/${runId}/mcp/servers/${serverId}/auth/start`, { method: "POST", body: payload, options, mutation: true });
|
|
475
|
+
}
|
|
476
|
+
getRuntimeBootstrap(agentId) {
|
|
477
|
+
return this.http.requestJson(`/public/embed/agents/${agentId}/runtime/bootstrap`);
|
|
478
|
+
}
|
|
479
|
+
listAgentThreads(agentId, options) {
|
|
480
|
+
return this.http.requestJson(`/public/embed/agents/${agentId}/threads`, { query: {
|
|
481
|
+
external_user_id: options.externalUserId,
|
|
482
|
+
external_session_id: options.externalSessionId,
|
|
483
|
+
skip: options.skip ?? 0,
|
|
484
|
+
limit: options.limit ?? 20
|
|
485
|
+
} });
|
|
486
|
+
}
|
|
487
|
+
listAgentThreadsMulti(options) {
|
|
488
|
+
return this.http.requestJson("/public/embed/threads/query", { method: "POST", body: options });
|
|
489
|
+
}
|
|
490
|
+
async subscribeAgentThreadEvents(agentId, options, onEvent) {
|
|
491
|
+
const response = await this.http.fetchOrThrow(this.http.url(`/public/embed/agents/${agentId}/threads/events`, {
|
|
492
|
+
external_user_id: options.externalUserId,
|
|
493
|
+
external_session_id: options.externalSessionId,
|
|
494
|
+
cursor: options.cursor
|
|
495
|
+
}), { method: "GET", headers: this.http.streamHeaders(), signal: options.signal }, "Failed to connect to the embedded-agent thread event endpoint.");
|
|
496
|
+
await assertOk(response);
|
|
497
|
+
await consumeThreadSummaryEventStream(response, onEvent, options.signal);
|
|
498
|
+
}
|
|
499
|
+
async subscribeAgentThreadEventsMulti(options, onEvent) {
|
|
500
|
+
const response = await this.http.fetchOrThrow(this.http.url("/public/embed/threads/events", {
|
|
501
|
+
agent_ids: options.agentIds,
|
|
502
|
+
external_user_id: options.externalUserId,
|
|
503
|
+
external_session_id: options.externalSessionId,
|
|
504
|
+
cursor: options.cursor
|
|
505
|
+
}), { method: "GET", headers: this.http.streamHeaders(), signal: options.signal }, "Failed to connect to the embedded-agent thread event endpoint.");
|
|
506
|
+
await assertOk(response);
|
|
507
|
+
await consumeThreadSummaryEventStream(response, onEvent, options.signal);
|
|
508
|
+
}
|
|
509
|
+
getAgentThread(agentId, threadId, options) {
|
|
510
|
+
return this.http.requestJson(`/public/embed/agents/${agentId}/threads/${threadId}`, { query: {
|
|
511
|
+
external_user_id: options.externalUserId,
|
|
512
|
+
external_session_id: options.externalSessionId,
|
|
513
|
+
before_turn_index: options.beforeTurnIndex,
|
|
514
|
+
limit: options.limit,
|
|
515
|
+
include_run_events: options.includeRunEvents,
|
|
516
|
+
include_subthreads: options.includeSubthreads,
|
|
517
|
+
subthread_depth: options.subthreadDepth,
|
|
518
|
+
subthread_turn_limit: options.subthreadTurnLimit,
|
|
519
|
+
subthread_child_limit: options.subthreadChildLimit
|
|
520
|
+
} });
|
|
521
|
+
}
|
|
522
|
+
deleteAgentThread(agentId, threadId, options) {
|
|
523
|
+
return this.http.requestJson(`/public/embed/agents/${agentId}/threads/${threadId}`, { method: "DELETE", query: {
|
|
524
|
+
external_user_id: options.externalUserId,
|
|
525
|
+
external_session_id: options.externalSessionId
|
|
526
|
+
}, mutation: true });
|
|
527
|
+
}
|
|
528
|
+
getAgentRunContext(agentId, runId, options) {
|
|
529
|
+
return this.http.requestJson(`/public/embed/agents/${agentId}/runs/${runId}/context`, { query: {
|
|
530
|
+
external_user_id: options.externalUserId,
|
|
531
|
+
external_session_id: options.externalSessionId
|
|
532
|
+
} });
|
|
533
|
+
}
|
|
534
|
+
cancelAgentRun(agentId, runId, options) {
|
|
535
|
+
return this.http.requestJson(`/public/embed/agents/${agentId}/runs/${runId}/cancel`, { method: "POST", query: {
|
|
536
|
+
external_user_id: options.externalUserId,
|
|
537
|
+
external_session_id: options.externalSessionId
|
|
538
|
+
}, body: {}, mutation: true });
|
|
539
|
+
}
|
|
540
|
+
async uploadAgentAttachments(agentId, options) {
|
|
541
|
+
const form = new FormData();
|
|
542
|
+
form.set("external_user_id", options.externalUserId);
|
|
543
|
+
if (options.externalSessionId) form.set("external_session_id", options.externalSessionId);
|
|
544
|
+
if (options.threadId) form.set("thread_id", options.threadId);
|
|
545
|
+
for (const file of options.files) form.append("files", file, file.name);
|
|
546
|
+
const response = await this.http.fetchOrThrow(this.http.url(`/public/embed/agents/${agentId}/attachments/upload`), {
|
|
547
|
+
method: "POST",
|
|
548
|
+
headers: this.http.multipartHeaders(void 0, { idempotencyKey: options.idempotencyKey }, true),
|
|
549
|
+
body: form
|
|
550
|
+
}, "Failed to connect to the embedded-agent attachment endpoint.");
|
|
551
|
+
await assertOk(response);
|
|
552
|
+
return await response.json();
|
|
553
|
+
}
|
|
554
|
+
};
|
|
555
|
+
|
|
556
|
+
// src/runs.ts
|
|
557
|
+
var RunsNamespace = class {
|
|
558
|
+
constructor(http) {
|
|
559
|
+
this.http = http;
|
|
560
|
+
}
|
|
561
|
+
http;
|
|
562
|
+
get(runId, options = {}) {
|
|
563
|
+
return this.http.requestJson(`/agents/runs/${runId}`, { query: { include_tree: options.includeTree } });
|
|
564
|
+
}
|
|
565
|
+
getTree(runId) {
|
|
566
|
+
return this.http.requestJson(`/agents/runs/${runId}/tree`);
|
|
567
|
+
}
|
|
568
|
+
getEvents(runId, options = {}) {
|
|
569
|
+
return this.http.requestJson(`/agents/runs/${runId}/events`, { query: { after_sequence: options.afterSequence, limit: options.limit } });
|
|
570
|
+
}
|
|
571
|
+
getContext(runId) {
|
|
572
|
+
return this.http.requestJson(`/agents/runs/${runId}/context`);
|
|
573
|
+
}
|
|
574
|
+
async getTrace(runId) {
|
|
575
|
+
const run = await this.get(runId);
|
|
576
|
+
const tree = await this.getTree(runId);
|
|
577
|
+
const events = await this.getEvents(runId);
|
|
578
|
+
const context = await this.getContext(runId);
|
|
579
|
+
return { run, tree, events, context };
|
|
580
|
+
}
|
|
581
|
+
};
|
|
582
|
+
|
|
583
|
+
// src/client.ts
|
|
584
|
+
var Agents24 = class {
|
|
585
|
+
agents;
|
|
586
|
+
embed;
|
|
587
|
+
runs;
|
|
588
|
+
clientDeployments;
|
|
589
|
+
clientSessions;
|
|
590
|
+
constructor(options) {
|
|
591
|
+
const http = new Agents24HttpClient(options);
|
|
592
|
+
this.agents = new AgentsNamespace(http);
|
|
593
|
+
this.embed = new EmbedNamespace(http);
|
|
594
|
+
this.runs = new RunsNamespace(http);
|
|
595
|
+
this.clientDeployments = new ClientDeploymentsNamespace(http);
|
|
596
|
+
this.clientSessions = new ClientSessionsNamespace(http);
|
|
597
|
+
}
|
|
598
|
+
agent(options) {
|
|
599
|
+
return new AgentDefinitionBuilder(this.agents, options);
|
|
600
|
+
}
|
|
601
|
+
graph() {
|
|
602
|
+
return new GraphBuilder();
|
|
603
|
+
}
|
|
604
|
+
};
|
|
605
|
+
|
|
606
|
+
// src/generated/manifest.ts
|
|
607
|
+
var SDK_OPERATION_IDS = [
|
|
608
|
+
"agents.cancel_run",
|
|
609
|
+
"agents.catalog",
|
|
610
|
+
"agents.create",
|
|
611
|
+
"agents.delete",
|
|
612
|
+
"agents.get",
|
|
613
|
+
"agents.list",
|
|
614
|
+
"agents.publish",
|
|
615
|
+
"agents.resume_run",
|
|
616
|
+
"agents.schema",
|
|
617
|
+
"agents.start_run",
|
|
618
|
+
"agents.stream",
|
|
619
|
+
"agents.update",
|
|
620
|
+
"agents.update_graph",
|
|
621
|
+
"agents.upload_attachments",
|
|
622
|
+
"agents.validate",
|
|
623
|
+
"client.attachments.upload",
|
|
624
|
+
"client.bootstrap",
|
|
625
|
+
"client.chat.stream",
|
|
626
|
+
"client.deployments.create",
|
|
627
|
+
"client.deployments.get",
|
|
628
|
+
"client.deployments.promote",
|
|
629
|
+
"client.deployments.revoke",
|
|
630
|
+
"client.deployments.update",
|
|
631
|
+
"client.hitl.resume",
|
|
632
|
+
"client.jwks",
|
|
633
|
+
"client.mcp.redeem",
|
|
634
|
+
"client.mcp.start",
|
|
635
|
+
"client.runs.attach",
|
|
636
|
+
"client.runs.cancel",
|
|
637
|
+
"client.sessions.anonymous",
|
|
638
|
+
"client.sessions.backendExchange",
|
|
639
|
+
"client.sessions.refresh",
|
|
640
|
+
"client.sessions.revoke",
|
|
641
|
+
"client.threads.delete",
|
|
642
|
+
"client.threads.events",
|
|
643
|
+
"client.threads.get",
|
|
644
|
+
"client.threads.list",
|
|
645
|
+
"embed.attach_agent_run",
|
|
646
|
+
"embed.cancel_agent_run",
|
|
647
|
+
"embed.delete_agent_thread",
|
|
648
|
+
"embed.get_agent_run_context",
|
|
649
|
+
"embed.get_agent_thread",
|
|
650
|
+
"embed.get_runtime_bootstrap",
|
|
651
|
+
"embed.list_agent_threads",
|
|
652
|
+
"embed.list_agent_threads_multi",
|
|
653
|
+
"embed.resume_agent_run",
|
|
654
|
+
"embed.start_agent_run_mcp_auth",
|
|
655
|
+
"embed.stream_agent",
|
|
656
|
+
"embed.stream_agent_thread_events",
|
|
657
|
+
"embed.stream_agent_thread_events_multi",
|
|
658
|
+
"embed.upload_agent_attachments",
|
|
659
|
+
"runs.get",
|
|
660
|
+
"runs.get_context",
|
|
661
|
+
"runs.get_events",
|
|
662
|
+
"runs.get_tree"
|
|
663
|
+
];
|
|
664
|
+
|
|
665
|
+
export { AgentDefinitionBuilder, Agents24, Agents24SDKError as Agents24NodeError, Agents24SDKError, GraphBuilder, SDK_OPERATION_IDS };
|
|
666
|
+
//# sourceMappingURL=index.js.map
|
|
667
|
+
//# sourceMappingURL=index.js.map
|