@darqlabs/curator-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 +313 -0
- package/dist/cjs/client.d.ts +174 -0
- package/dist/cjs/client.d.ts.map +1 -0
- package/dist/cjs/client.js +417 -0
- package/dist/cjs/client.js.map +1 -0
- package/dist/cjs/errors.d.ts +91 -0
- package/dist/cjs/errors.d.ts.map +1 -0
- package/dist/cjs/errors.js +131 -0
- package/dist/cjs/errors.js.map +1 -0
- package/dist/cjs/files.d.ts +66 -0
- package/dist/cjs/files.d.ts.map +1 -0
- package/dist/cjs/files.js +86 -0
- package/dist/cjs/files.js.map +1 -0
- package/dist/cjs/http.d.ts +92 -0
- package/dist/cjs/http.d.ts.map +1 -0
- package/dist/cjs/http.js +232 -0
- package/dist/cjs/http.js.map +1 -0
- package/dist/cjs/index.d.ts +10 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +22 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/sse.d.ts +20 -0
- package/dist/cjs/sse.d.ts.map +1 -0
- package/dist/cjs/sse.js +89 -0
- package/dist/cjs/sse.js.map +1 -0
- package/dist/cjs/streamEventParse.d.ts +13 -0
- package/dist/cjs/streamEventParse.d.ts.map +1 -0
- package/dist/cjs/streamEventParse.js +81 -0
- package/dist/cjs/streamEventParse.js.map +1 -0
- package/dist/cjs/streamEvents.d.ts +58 -0
- package/dist/cjs/streamEvents.d.ts.map +1 -0
- package/dist/cjs/streamEvents.js +22 -0
- package/dist/cjs/streamEvents.js.map +1 -0
- package/dist/cjs/types.d.ts +93 -0
- package/dist/cjs/types.d.ts.map +1 -0
- package/dist/cjs/types.js +10 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/esm/client.d.ts +174 -0
- package/dist/esm/client.d.ts.map +1 -0
- package/dist/esm/client.js +411 -0
- package/dist/esm/client.js.map +1 -0
- package/dist/esm/errors.d.ts +91 -0
- package/dist/esm/errors.d.ts.map +1 -0
- package/dist/esm/errors.js +119 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/files.d.ts +66 -0
- package/dist/esm/files.d.ts.map +1 -0
- package/dist/esm/files.js +82 -0
- package/dist/esm/files.js.map +1 -0
- package/dist/esm/http.d.ts +92 -0
- package/dist/esm/http.d.ts.map +1 -0
- package/dist/esm/http.js +228 -0
- package/dist/esm/http.js.map +1 -0
- package/dist/esm/index.d.ts +10 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/sse.d.ts +20 -0
- package/dist/esm/sse.d.ts.map +1 -0
- package/dist/esm/sse.js +86 -0
- package/dist/esm/sse.js.map +1 -0
- package/dist/esm/streamEventParse.d.ts +13 -0
- package/dist/esm/streamEventParse.d.ts.map +1 -0
- package/dist/esm/streamEventParse.js +78 -0
- package/dist/esm/streamEventParse.js.map +1 -0
- package/dist/esm/streamEvents.d.ts +58 -0
- package/dist/esm/streamEvents.d.ts.map +1 -0
- package/dist/esm/streamEvents.js +19 -0
- package/dist/esm/streamEvents.js.map +1 -0
- package/dist/esm/types.d.ts +93 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +9 -0
- package/dist/esm/types.js.map +1 -0
- package/package.json +48 -0
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public surface of the Curator SDK.
|
|
3
|
+
*
|
|
4
|
+
* const curator = new Curator({ apiKey, project, environment })
|
|
5
|
+
* const reply = await curator.agent("support-bot").run("hello")
|
|
6
|
+
*
|
|
7
|
+
* const chat = curator.agent("support-bot").chat()
|
|
8
|
+
* const r1 = await chat.send("first")
|
|
9
|
+
* const r2 = await chat.send("follow up")
|
|
10
|
+
*
|
|
11
|
+
* const chat = curator.agent("support-bot").conversation("conv_xxx")
|
|
12
|
+
* const r = await chat.send("continuing later")
|
|
13
|
+
*
|
|
14
|
+
* Both helpers route through `?wait=true` under the hood — the caller
|
|
15
|
+
* never sees `run_id` or has to poll. Non-completion states (HITL
|
|
16
|
+
* pause, terminal agent error, timeout) surface as typed errors from
|
|
17
|
+
* `./errors`. HITL approvals are NOT resolved through the SDK — the
|
|
18
|
+
* pause is surfaced as an error so the calling app can tell its user
|
|
19
|
+
* to contact an administrator, who handles it in the dashboard.
|
|
20
|
+
*/
|
|
21
|
+
import { CuratorAgentError, CuratorApprovalRequiredError, CuratorError, CuratorTimeoutError, } from "./errors.js";
|
|
22
|
+
import { Files } from "./files.js";
|
|
23
|
+
import { HttpClient } from "./http.js";
|
|
24
|
+
import { parseSseStream } from "./sse.js";
|
|
25
|
+
import { frameToStreamEvent } from "./streamEventParse.js";
|
|
26
|
+
import { isTerminalStreamEvent } from "./streamEvents.js";
|
|
27
|
+
const DEFAULT_BASE_URL = "https://app.darqlabs.ai";
|
|
28
|
+
const DEFAULT_TIMEOUT_MS = 120_000;
|
|
29
|
+
export class Curator {
|
|
30
|
+
http;
|
|
31
|
+
defaultProject;
|
|
32
|
+
defaultEnvironment;
|
|
33
|
+
defaultTimeoutMs;
|
|
34
|
+
/** File-upload surface — see {@link Files}. */
|
|
35
|
+
files;
|
|
36
|
+
constructor(opts) {
|
|
37
|
+
const baseUrl = opts.baseUrl ?? DEFAULT_BASE_URL;
|
|
38
|
+
// Same bind-to-host dance as HttpClient — needed because the bare
|
|
39
|
+
// `globalThis.fetch` reference loses its `this` when invoked through
|
|
40
|
+
// a stashed variable, and browsers reject that with "Illegal invocation".
|
|
41
|
+
const globalFetch = globalThis.fetch;
|
|
42
|
+
const fetchImpl = opts.fetch ?? (globalFetch ? globalFetch.bind(globalThis) : undefined);
|
|
43
|
+
this.http = new HttpClient({
|
|
44
|
+
apiKey: opts.apiKey,
|
|
45
|
+
baseUrl,
|
|
46
|
+
fetch: opts.fetch,
|
|
47
|
+
defaultHeaders: opts.defaultHeaders,
|
|
48
|
+
endUserJwt: opts.endUserJwt,
|
|
49
|
+
});
|
|
50
|
+
this.defaultProject = opts.project;
|
|
51
|
+
this.defaultEnvironment = opts.environment ?? "production";
|
|
52
|
+
this.defaultTimeoutMs = opts.defaultTimeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
53
|
+
this.files = new Files(this.http, stripTrailingSlash(baseUrl), fetchImpl);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Address an agent deployment by its slug. Project / environment fall
|
|
57
|
+
* back to the constructor defaults; pass overrides via the second arg.
|
|
58
|
+
*/
|
|
59
|
+
agent(slug, locator = {}) {
|
|
60
|
+
return new Agent(this.http, this.defaultTimeoutMs, this.resolveRoute(slug, locator));
|
|
61
|
+
}
|
|
62
|
+
resolveRoute(deployment, locator) {
|
|
63
|
+
if (locator.system) {
|
|
64
|
+
if (locator.project) {
|
|
65
|
+
throw new CuratorError("Cannot combine `system: true` with `project`.");
|
|
66
|
+
}
|
|
67
|
+
return { kind: "system", deployment };
|
|
68
|
+
}
|
|
69
|
+
const project = locator.project ?? this.defaultProject;
|
|
70
|
+
const environment = locator.environment ?? this.defaultEnvironment;
|
|
71
|
+
if (!project) {
|
|
72
|
+
throw new CuratorError("No project specified. Set `project` on `new Curator({ ... })` or pass it as the second arg to `agent(slug, { project })`. " +
|
|
73
|
+
"If the deployment is system-scoped, pass `{ system: true }`.");
|
|
74
|
+
}
|
|
75
|
+
return { kind: "project", project, environment, deployment };
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
export class Agent {
|
|
79
|
+
http;
|
|
80
|
+
defaultTimeoutMs;
|
|
81
|
+
route;
|
|
82
|
+
/** @internal */
|
|
83
|
+
constructor(http, defaultTimeoutMs, route) {
|
|
84
|
+
this.http = http;
|
|
85
|
+
this.defaultTimeoutMs = defaultTimeoutMs;
|
|
86
|
+
this.route = route;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Open a fresh conversation, send `content`, await the reply, and
|
|
90
|
+
* return it. Equivalent to `agent.chat().send(content)` but one line.
|
|
91
|
+
*/
|
|
92
|
+
async run(content, opts = {}) {
|
|
93
|
+
return this.chat().send(content, opts);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Open a fresh conversation and stream the reply as it's generated.
|
|
97
|
+
* Equivalent to `agent.chat().stream(content)`.
|
|
98
|
+
*/
|
|
99
|
+
stream(content, opts = {}) {
|
|
100
|
+
return this.chat().stream(content, opts);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Return a Chat handle whose conversation is created lazily on the
|
|
104
|
+
* first `send(...)`. Subsequent sends reuse the same conversation.
|
|
105
|
+
*/
|
|
106
|
+
chat() {
|
|
107
|
+
return new Chat(this.http, this.defaultTimeoutMs, this.route, null);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Reattach to an existing conversation by id (e.g. resuming a chat
|
|
111
|
+
* across processes or restoring from durable state).
|
|
112
|
+
*/
|
|
113
|
+
conversation(conversationId) {
|
|
114
|
+
return new Chat(this.http, this.defaultTimeoutMs, this.route, conversationId);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Fetch this deployment's read-only client config (branding entitlements,
|
|
118
|
+
* etc.). Resolved server-side from the org's subscription tier. No side
|
|
119
|
+
* effects — safe to call on widget mount. `<CuratorChat />` uses this to
|
|
120
|
+
* decide whether to render the "Powered by Curator" footer.
|
|
121
|
+
*/
|
|
122
|
+
async config() {
|
|
123
|
+
const envelope = await this.http.request(`${this.http.deploymentBase(this.route)}/config`, { method: "GET" });
|
|
124
|
+
return {
|
|
125
|
+
branding: {
|
|
126
|
+
hidePoweredBy: envelope.data.branding?.hide_powered_by === true,
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
export class Chat {
|
|
132
|
+
http;
|
|
133
|
+
defaultTimeoutMs;
|
|
134
|
+
route;
|
|
135
|
+
conversationId;
|
|
136
|
+
/** Cached promise for an in-flight `POST /conversations`. */
|
|
137
|
+
pendingCreate = null;
|
|
138
|
+
/** @internal */
|
|
139
|
+
constructor(http, defaultTimeoutMs, route, initialConversationId) {
|
|
140
|
+
this.http = http;
|
|
141
|
+
this.defaultTimeoutMs = defaultTimeoutMs;
|
|
142
|
+
this.route = route;
|
|
143
|
+
this.conversationId = initialConversationId;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Conversation id, or `null` until the first send creates one.
|
|
147
|
+
* Use `.ensureId()` if you need to materialize the conversation
|
|
148
|
+
* eagerly without sending a message.
|
|
149
|
+
*/
|
|
150
|
+
get id() {
|
|
151
|
+
return this.conversationId;
|
|
152
|
+
}
|
|
153
|
+
/** Force conversation creation now and return its id. */
|
|
154
|
+
async ensureId() {
|
|
155
|
+
if (this.conversationId)
|
|
156
|
+
return this.conversationId;
|
|
157
|
+
if (this.pendingCreate)
|
|
158
|
+
return this.pendingCreate;
|
|
159
|
+
this.pendingCreate = this.createConversation().finally(() => {
|
|
160
|
+
this.pendingCreate = null;
|
|
161
|
+
});
|
|
162
|
+
return this.pendingCreate;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Send a user message and await the assistant's reply. Lazily creates
|
|
166
|
+
* the conversation if needed. Returns the final assistant message.
|
|
167
|
+
*
|
|
168
|
+
* Throws:
|
|
169
|
+
* - CuratorApprovalRequiredError if the run pauses for HITL (an
|
|
170
|
+
* administrator must resolve it in the dashboard)
|
|
171
|
+
* - CuratorAgentError on terminal agent failure
|
|
172
|
+
* - CuratorTimeoutError if the wait expires (the run keeps running)
|
|
173
|
+
*/
|
|
174
|
+
async send(content, opts = {}) {
|
|
175
|
+
if (!content && !opts.files?.length) {
|
|
176
|
+
throw new CuratorError("Either `content` or `files` must be provided.");
|
|
177
|
+
}
|
|
178
|
+
const conversationId = await this.ensureId();
|
|
179
|
+
const timeoutMs = opts.timeoutMs ?? this.defaultTimeoutMs;
|
|
180
|
+
const body = { content };
|
|
181
|
+
if (opts.files?.length) {
|
|
182
|
+
body.files = opts.files.map(toServerFile);
|
|
183
|
+
}
|
|
184
|
+
const envelope = await this.http.request(`${this.http.deploymentBase(this.route)}/conversations/${encodeURIComponent(conversationId)}/messages`, {
|
|
185
|
+
method: "POST",
|
|
186
|
+
query: { wait: "true", timeout_ms: timeoutMs },
|
|
187
|
+
body,
|
|
188
|
+
// Give the underlying fetch a small slack window over the server
|
|
189
|
+
// timeout — the server returns a structured `status: 'timeout'`
|
|
190
|
+
// payload that we want to surface as CuratorTimeoutError rather
|
|
191
|
+
// than an aborted fetch.
|
|
192
|
+
signalTimeoutMs: timeoutMs + 10_000,
|
|
193
|
+
});
|
|
194
|
+
return this.unwrapWaitOutcome(envelope.data);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Send a user message and stream the agent's response back as it's
|
|
198
|
+
* generated. Each yielded event is one of `delta` / `tool_call.*` /
|
|
199
|
+
* `done` / `error` / `paused_for_approval`. The iterator ends on the
|
|
200
|
+
* first terminal event.
|
|
201
|
+
*
|
|
202
|
+
* for await (const e of chat.stream("hello")) {
|
|
203
|
+
* if (e.type === "delta") process.stdout.write(e.text)
|
|
204
|
+
* if (e.type === "done") console.log("\nfinal:", e.message?.content)
|
|
205
|
+
* }
|
|
206
|
+
*
|
|
207
|
+
* Aborting the iteration (breaking out of the loop, or calling
|
|
208
|
+
* `.return()`) closes the underlying HTTP connection — the server-
|
|
209
|
+
* side run keeps going independently. Use `chat.history()` later to
|
|
210
|
+
* fetch what landed.
|
|
211
|
+
*/
|
|
212
|
+
async *stream(content, opts = {}) {
|
|
213
|
+
if (!content && !opts.files?.length) {
|
|
214
|
+
throw new CuratorError("Either `content` or `files` must be provided.");
|
|
215
|
+
}
|
|
216
|
+
const conversationId = await this.ensureId();
|
|
217
|
+
const body = { content };
|
|
218
|
+
if (opts.files?.length) {
|
|
219
|
+
body.files = opts.files.map(toServerFile);
|
|
220
|
+
}
|
|
221
|
+
const controller = new AbortController();
|
|
222
|
+
const response = await this.http.streamPost(`${this.http.deploymentBase(this.route)}/conversations/${encodeURIComponent(conversationId)}/messages`, {
|
|
223
|
+
body,
|
|
224
|
+
query: { stream: "true" },
|
|
225
|
+
signal: controller.signal,
|
|
226
|
+
});
|
|
227
|
+
try {
|
|
228
|
+
for await (const frame of parseSseStream(response.body)) {
|
|
229
|
+
const event = frameToStreamEvent(frame);
|
|
230
|
+
if (!event)
|
|
231
|
+
continue;
|
|
232
|
+
yield event;
|
|
233
|
+
if (isTerminalStreamEvent(event))
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
finally {
|
|
238
|
+
try {
|
|
239
|
+
controller.abort();
|
|
240
|
+
}
|
|
241
|
+
catch {
|
|
242
|
+
/* ignore */
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
/** Fetch (paginated) conversation history. */
|
|
247
|
+
async history(opts = {}) {
|
|
248
|
+
const conversationId = await this.ensureId();
|
|
249
|
+
const envelope = await this.http.request(`${this.http.deploymentBase(this.route)}/conversations/${encodeURIComponent(conversationId)}`, {
|
|
250
|
+
query: {
|
|
251
|
+
limit: opts.limit,
|
|
252
|
+
before_sequence: opts.beforeSequence,
|
|
253
|
+
},
|
|
254
|
+
});
|
|
255
|
+
const messages = envelope.data.messages.map((m) => adaptHistoryMessage(m));
|
|
256
|
+
return {
|
|
257
|
+
messages,
|
|
258
|
+
hasMore: envelope.data.has_more_messages,
|
|
259
|
+
oldestSequence: envelope.data.oldest_loaded_sequence,
|
|
260
|
+
totalMessageCount: envelope.data.message_count,
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
// ── internals ────────────────────────────────────────────────────
|
|
264
|
+
async createConversation() {
|
|
265
|
+
const envelope = await this.http.request(`${this.http.deploymentBase(this.route)}/conversations`, {
|
|
266
|
+
method: "POST",
|
|
267
|
+
});
|
|
268
|
+
this.conversationId = envelope.data.conversation_id;
|
|
269
|
+
return this.conversationId;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Continue waiting for the next terminal state on an already-running
|
|
273
|
+
* conversation. Used to back `CuratorTimeoutError.continueWaiting()`.
|
|
274
|
+
*
|
|
275
|
+
* The server-side wait endpoint hangs off `POST /messages`, so to
|
|
276
|
+
* re-wait without sending a new user message we poll history for an
|
|
277
|
+
* assistant message whose `sequence` exceeds the baseline established
|
|
278
|
+
* before the wait began. For a still-in-flight run, the assistant
|
|
279
|
+
* reply typically lands within seconds.
|
|
280
|
+
*/
|
|
281
|
+
async waitForNextReply(timeoutMs) {
|
|
282
|
+
const conversationId = await this.ensureId();
|
|
283
|
+
const deadline = Date.now() + timeoutMs;
|
|
284
|
+
let baseline = await this.latestSequence(conversationId);
|
|
285
|
+
while (Date.now() < deadline) {
|
|
286
|
+
await sleep(1_500);
|
|
287
|
+
const latest = await this.latestSequence(conversationId);
|
|
288
|
+
if (latest <= baseline)
|
|
289
|
+
continue;
|
|
290
|
+
const page = await this.history({ limit: 50 });
|
|
291
|
+
for (let i = page.messages.length - 1; i >= 0; i--) {
|
|
292
|
+
const m = page.messages[i];
|
|
293
|
+
if (m.role === "assistant" && m.sequence > baseline) {
|
|
294
|
+
return {
|
|
295
|
+
...m,
|
|
296
|
+
runId: "<resumed>",
|
|
297
|
+
conversationId,
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
baseline = latest;
|
|
302
|
+
}
|
|
303
|
+
throw new CuratorTimeoutError({
|
|
304
|
+
conversationId,
|
|
305
|
+
runId: "<resumed>",
|
|
306
|
+
continueWaiting: (next) => this.waitForNextReply(next ?? this.defaultTimeoutMs),
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
async latestSequence(conversationId) {
|
|
310
|
+
const envelope = await this.http.request(`${this.http.deploymentBase(this.route)}/conversations/${encodeURIComponent(conversationId)}`, { query: { limit: 1 } });
|
|
311
|
+
const list = envelope.data.messages;
|
|
312
|
+
return list.length > 0 ? list[list.length - 1].sequence : 0;
|
|
313
|
+
}
|
|
314
|
+
unwrapWaitOutcome(data) {
|
|
315
|
+
const { run_id, conversation_id, status } = data;
|
|
316
|
+
switch (status) {
|
|
317
|
+
case "completed": {
|
|
318
|
+
const msg = data.message;
|
|
319
|
+
if (!msg) {
|
|
320
|
+
throw new CuratorError("Server returned `completed` without a message payload.");
|
|
321
|
+
}
|
|
322
|
+
return {
|
|
323
|
+
role: "assistant",
|
|
324
|
+
content: msg.content,
|
|
325
|
+
sequence: msg.sequence,
|
|
326
|
+
stepId: msg.step_id,
|
|
327
|
+
createdAt: msg.created_at,
|
|
328
|
+
runId: run_id,
|
|
329
|
+
conversationId: conversation_id,
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
case "paused_for_approval": {
|
|
333
|
+
const approval = data.approval;
|
|
334
|
+
if (!approval) {
|
|
335
|
+
throw new CuratorError("Server returned `paused_for_approval` without approval payload.");
|
|
336
|
+
}
|
|
337
|
+
throw new CuratorApprovalRequiredError({
|
|
338
|
+
approval,
|
|
339
|
+
conversationId: conversation_id,
|
|
340
|
+
runId: run_id,
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
case "errored": {
|
|
344
|
+
const err = data.error;
|
|
345
|
+
if (!err) {
|
|
346
|
+
throw new CuratorError("Server returned `errored` without error payload.");
|
|
347
|
+
}
|
|
348
|
+
throw new CuratorAgentError({
|
|
349
|
+
message: err.message,
|
|
350
|
+
failureClass: err.failure_class,
|
|
351
|
+
isPermanent: err.is_permanent,
|
|
352
|
+
stepId: err.step_id ?? null,
|
|
353
|
+
conversationId: conversation_id,
|
|
354
|
+
runId: run_id,
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
case "timeout":
|
|
358
|
+
throw new CuratorTimeoutError({
|
|
359
|
+
conversationId: conversation_id,
|
|
360
|
+
runId: run_id,
|
|
361
|
+
continueWaiting: (next) => this.waitForNextReply(next ?? this.defaultTimeoutMs),
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
function adaptHistoryMessage(m) {
|
|
367
|
+
if (m.role === "assistant") {
|
|
368
|
+
return {
|
|
369
|
+
role: "assistant",
|
|
370
|
+
content: m.content,
|
|
371
|
+
sequence: m.sequence,
|
|
372
|
+
stepId: m.step_id,
|
|
373
|
+
createdAt: m.created_at,
|
|
374
|
+
// History endpoint doesn't return run_id / conversation_id per
|
|
375
|
+
// row — callers that need them should track separately.
|
|
376
|
+
runId: "<historical>",
|
|
377
|
+
conversationId: "<historical>",
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
if (m.role === "tool") {
|
|
381
|
+
return {
|
|
382
|
+
role: "tool",
|
|
383
|
+
content: m.content,
|
|
384
|
+
sequence: m.sequence,
|
|
385
|
+
toolCallId: m.tool_call_id,
|
|
386
|
+
createdAt: m.created_at,
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
return {
|
|
390
|
+
role: "user",
|
|
391
|
+
content: m.content,
|
|
392
|
+
sequence: m.sequence,
|
|
393
|
+
createdAt: m.created_at,
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
function toServerFile(f) {
|
|
397
|
+
return {
|
|
398
|
+
storageKey: f.storageKey,
|
|
399
|
+
mimeType: f.mimeType,
|
|
400
|
+
filename: f.filename,
|
|
401
|
+
size: f.size,
|
|
402
|
+
artifactId: f.artifactId,
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
function sleep(ms) {
|
|
406
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
407
|
+
}
|
|
408
|
+
function stripTrailingSlash(s) {
|
|
409
|
+
return s.replace(/\/+$/, "");
|
|
410
|
+
}
|
|
411
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EACL,iBAAiB,EACjB,4BAA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SAAS,kBAAkB,CAAC,CAAS;IACnC,OAAO,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;AAC9B,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed errors the SDK throws.
|
|
3
|
+
*
|
|
4
|
+
* Happy-path code reads the return value of `agent.run(...)` or
|
|
5
|
+
* `chat.send(...)`. Anything else — HITL pauses, agent-side errors,
|
|
6
|
+
* timeouts, HTTP failures — surfaces as one of these. Catch the
|
|
7
|
+
* specific class you care about; everything inherits from
|
|
8
|
+
* `CuratorError` so a single `catch (err: CuratorError)` works as a
|
|
9
|
+
* backstop.
|
|
10
|
+
*/
|
|
11
|
+
import type { AssistantMessage, ApprovalDetails, AgentFailureClass } from "./types.js";
|
|
12
|
+
export declare class CuratorError extends Error {
|
|
13
|
+
constructor(message: string, options?: {
|
|
14
|
+
cause?: unknown;
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
/** HTTP 401 from the API — your API key is missing, invalid, or revoked. */
|
|
18
|
+
export declare class CuratorAuthError extends CuratorError {
|
|
19
|
+
constructor(message?: string);
|
|
20
|
+
}
|
|
21
|
+
/** HTTP 403 from the API — your API key doesn't have permission for this action. */
|
|
22
|
+
export declare class CuratorForbiddenError extends CuratorError {
|
|
23
|
+
constructor(message?: string);
|
|
24
|
+
}
|
|
25
|
+
/** HTTP 404 from the API — the deployment slug or conversation id wasn't found. */
|
|
26
|
+
export declare class CuratorNotFoundError extends CuratorError {
|
|
27
|
+
constructor(message?: string);
|
|
28
|
+
}
|
|
29
|
+
/** HTTP 410 from the API — the deployment was retired. */
|
|
30
|
+
export declare class CuratorDeploymentRetiredError extends CuratorError {
|
|
31
|
+
readonly retiredAt: string | null;
|
|
32
|
+
constructor(message: string, retiredAt: string | null);
|
|
33
|
+
}
|
|
34
|
+
/** HTTP 429 from the API — back off. */
|
|
35
|
+
export declare class CuratorRateLimitError extends CuratorError {
|
|
36
|
+
readonly retryAfterSeconds: number | null;
|
|
37
|
+
constructor(message?: string, retryAfterSeconds?: number | null);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Run paused waiting for human approval. Approval resolution is not
|
|
41
|
+
* exposed to API consumers — pauses are routed through the dashboard
|
|
42
|
+
* by an org administrator. The error carries the approval payload so
|
|
43
|
+
* the caller can surface a friendly "contact your administrator"
|
|
44
|
+
* message that mentions the specific tool.
|
|
45
|
+
*/
|
|
46
|
+
export declare class CuratorApprovalRequiredError extends CuratorError {
|
|
47
|
+
readonly approval: ApprovalDetails;
|
|
48
|
+
readonly conversationId: string;
|
|
49
|
+
readonly runId: string;
|
|
50
|
+
constructor(args: {
|
|
51
|
+
approval: ApprovalDetails;
|
|
52
|
+
conversationId: string;
|
|
53
|
+
runId: string;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The agent run reached a terminal error state (LLM quota, auth, 5xx
|
|
58
|
+
* exhausted retries, etc.). `failureClass` and `isPermanent` mirror the
|
|
59
|
+
* server's classification so callers can decide whether to retry.
|
|
60
|
+
*/
|
|
61
|
+
export declare class CuratorAgentError extends CuratorError {
|
|
62
|
+
readonly failureClass: AgentFailureClass;
|
|
63
|
+
readonly isPermanent: boolean;
|
|
64
|
+
readonly conversationId: string;
|
|
65
|
+
readonly runId: string;
|
|
66
|
+
readonly stepId: string | null;
|
|
67
|
+
constructor(args: {
|
|
68
|
+
message: string;
|
|
69
|
+
failureClass: AgentFailureClass;
|
|
70
|
+
isPermanent: boolean;
|
|
71
|
+
conversationId: string;
|
|
72
|
+
runId: string;
|
|
73
|
+
stepId?: string | null;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The synchronous wait expired. The agent run keeps running on the
|
|
78
|
+
* server; call `.continueWaiting()` to resume listening, or fetch
|
|
79
|
+
* history later via `chat.history()`.
|
|
80
|
+
*/
|
|
81
|
+
export declare class CuratorTimeoutError extends CuratorError {
|
|
82
|
+
readonly conversationId: string;
|
|
83
|
+
readonly runId: string;
|
|
84
|
+
readonly continueWaiting: (timeoutMs?: number) => Promise<AssistantMessage>;
|
|
85
|
+
constructor(args: {
|
|
86
|
+
conversationId: string;
|
|
87
|
+
runId: string;
|
|
88
|
+
continueWaiting: (timeoutMs?: number) => Promise<AssistantMessage>;
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAEtF,qBAAa,YAAa,SAAQ,KAAK;gBACzB,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAQ3D;AAED,4EAA4E;AAC5E,qBAAa,gBAAiB,SAAQ,YAAY;gBACpC,OAAO,SAA+B;CAInD;AAED,oFAAoF;AACpF,qBAAa,qBAAsB,SAAQ,YAAY;gBACzC,OAAO,SAAsB;CAI1C;AAED,mFAAmF;AACnF,qBAAa,oBAAqB,SAAQ,YAAY;gBACxC,OAAO,SAAuB;CAI3C;AAED,0DAA0D;AAC1D,qBAAa,6BAA8B,SAAQ,YAAY;IAC7D,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;gBACrB,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI;CAKtD;AAED,wCAAwC;AACxC,qBAAa,qBAAsB,SAAQ,YAAY;IACrD,QAAQ,CAAC,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAA;gBAC7B,OAAO,SAAwB,EAAE,iBAAiB,GAAE,MAAM,GAAG,IAAW;CAKrF;AAED;;;;;;GAMG;AACH,qBAAa,4BAA6B,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+
/**
|
|
2
|
+
* Typed errors the SDK throws.
|
|
3
|
+
*
|
|
4
|
+
* Happy-path code reads the return value of `agent.run(...)` or
|
|
5
|
+
* `chat.send(...)`. Anything else — HITL pauses, agent-side errors,
|
|
6
|
+
* timeouts, HTTP failures — surfaces as one of these. Catch the
|
|
7
|
+
* specific class you care about; everything inherits from
|
|
8
|
+
* `CuratorError` so a single `catch (err: CuratorError)` works as a
|
|
9
|
+
* backstop.
|
|
10
|
+
*/
|
|
11
|
+
export class CuratorError extends Error {
|
|
12
|
+
constructor(message, options) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.name = "CuratorError";
|
|
15
|
+
// Preserve the underlying error if the runtime supports it.
|
|
16
|
+
if (options?.cause !== undefined) {
|
|
17
|
+
;
|
|
18
|
+
this.cause = options.cause;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/** HTTP 401 from the API — your API key is missing, invalid, or revoked. */
|
|
23
|
+
export class CuratorAuthError extends CuratorError {
|
|
24
|
+
constructor(message = "Invalid or revoked API key") {
|
|
25
|
+
super(message);
|
|
26
|
+
this.name = "CuratorAuthError";
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/** HTTP 403 from the API — your API key doesn't have permission for this action. */
|
|
30
|
+
export class CuratorForbiddenError extends CuratorError {
|
|
31
|
+
constructor(message = "Permission denied") {
|
|
32
|
+
super(message);
|
|
33
|
+
this.name = "CuratorForbiddenError";
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** HTTP 404 from the API — the deployment slug or conversation id wasn't found. */
|
|
37
|
+
export class CuratorNotFoundError extends CuratorError {
|
|
38
|
+
constructor(message = "Resource not found") {
|
|
39
|
+
super(message);
|
|
40
|
+
this.name = "CuratorNotFoundError";
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/** HTTP 410 from the API — the deployment was retired. */
|
|
44
|
+
export class CuratorDeploymentRetiredError extends CuratorError {
|
|
45
|
+
retiredAt;
|
|
46
|
+
constructor(message, retiredAt) {
|
|
47
|
+
super(message);
|
|
48
|
+
this.name = "CuratorDeploymentRetiredError";
|
|
49
|
+
this.retiredAt = retiredAt;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/** HTTP 429 from the API — back off. */
|
|
53
|
+
export class CuratorRateLimitError extends CuratorError {
|
|
54
|
+
retryAfterSeconds;
|
|
55
|
+
constructor(message = "Rate limit exceeded", retryAfterSeconds = null) {
|
|
56
|
+
super(message);
|
|
57
|
+
this.name = "CuratorRateLimitError";
|
|
58
|
+
this.retryAfterSeconds = retryAfterSeconds;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Run paused waiting for human approval. Approval resolution is not
|
|
63
|
+
* exposed to API consumers — pauses are routed through the dashboard
|
|
64
|
+
* by an org administrator. The error carries the approval payload so
|
|
65
|
+
* the caller can surface a friendly "contact your administrator"
|
|
66
|
+
* message that mentions the specific tool.
|
|
67
|
+
*/
|
|
68
|
+
export class CuratorApprovalRequiredError extends CuratorError {
|
|
69
|
+
approval;
|
|
70
|
+
conversationId;
|
|
71
|
+
runId;
|
|
72
|
+
constructor(args) {
|
|
73
|
+
super(`Run paused for approval — the '${args.approval.tool_name}' tool needs an administrator to review it. ` +
|
|
74
|
+
"Contact your administrator to resolve this in the Curator dashboard.");
|
|
75
|
+
this.name = "CuratorApprovalRequiredError";
|
|
76
|
+
this.approval = args.approval;
|
|
77
|
+
this.conversationId = args.conversationId;
|
|
78
|
+
this.runId = args.runId;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The agent run reached a terminal error state (LLM quota, auth, 5xx
|
|
83
|
+
* exhausted retries, etc.). `failureClass` and `isPermanent` mirror the
|
|
84
|
+
* server's classification so callers can decide whether to retry.
|
|
85
|
+
*/
|
|
86
|
+
export class CuratorAgentError extends CuratorError {
|
|
87
|
+
failureClass;
|
|
88
|
+
isPermanent;
|
|
89
|
+
conversationId;
|
|
90
|
+
runId;
|
|
91
|
+
stepId;
|
|
92
|
+
constructor(args) {
|
|
93
|
+
super(args.message);
|
|
94
|
+
this.name = "CuratorAgentError";
|
|
95
|
+
this.failureClass = args.failureClass;
|
|
96
|
+
this.isPermanent = args.isPermanent;
|
|
97
|
+
this.conversationId = args.conversationId;
|
|
98
|
+
this.runId = args.runId;
|
|
99
|
+
this.stepId = args.stepId ?? null;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* The synchronous wait expired. The agent run keeps running on the
|
|
104
|
+
* server; call `.continueWaiting()` to resume listening, or fetch
|
|
105
|
+
* history later via `chat.history()`.
|
|
106
|
+
*/
|
|
107
|
+
export class CuratorTimeoutError extends CuratorError {
|
|
108
|
+
conversationId;
|
|
109
|
+
runId;
|
|
110
|
+
continueWaiting;
|
|
111
|
+
constructor(args) {
|
|
112
|
+
super("Timed out waiting for the agent to reply — the run is still in progress.");
|
|
113
|
+
this.name = "CuratorTimeoutError";
|
|
114
|
+
this.conversationId = args.conversationId;
|
|
115
|
+
this.runId = args.runId;
|
|
116
|
+
this.continueWaiting = args.continueWaiting;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC,YAAY,OAAe,EAAE,OAA6B;QACxD,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,cAAc,CAAA;QAC1B,4DAA4D;QAC5D,IAAI,OAAO,EAAE,KAAK,KAAK,SAAS,EAAE,CAAC;YACjC,CAAC;YAAC,IAA4B,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAA;QACtD,CAAC;IACH,CAAC;CACF;AAED,4EAA4E;AAC5E,MAAM,OAA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