@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
package/dist/cjs/sse.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Tiny SSE parser.
|
|
4
|
+
*
|
|
5
|
+
* Reads a `ReadableStream<Uint8Array>` (the body returned by `fetch`)
|
|
6
|
+
* and yields SSE frames as `{ event, data }`. Spec essentials: lines
|
|
7
|
+
* separated by `\n` (or `\r\n`), blank line terminates a message,
|
|
8
|
+
* `event:` and `data:` fields are accumulated until the terminator,
|
|
9
|
+
* `:` lines are comments and ignored. We don't track ids or retries —
|
|
10
|
+
* not needed for the wait-for-terminal use case.
|
|
11
|
+
*
|
|
12
|
+
* Used by Chat.stream() to turn the backend's SSE response into typed
|
|
13
|
+
* stream events.
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.parseSseStream = parseSseStream;
|
|
17
|
+
async function* parseSseStream(stream) {
|
|
18
|
+
const reader = stream.getReader();
|
|
19
|
+
const decoder = new TextDecoder("utf-8");
|
|
20
|
+
let buffer = "";
|
|
21
|
+
try {
|
|
22
|
+
while (true) {
|
|
23
|
+
const { value, done } = await reader.read();
|
|
24
|
+
if (done)
|
|
25
|
+
break;
|
|
26
|
+
buffer += decoder.decode(value, { stream: true });
|
|
27
|
+
// Split on blank-line terminators (either \n\n or \r\n\r\n). The
|
|
28
|
+
// last chunk in the buffer may be a partial frame; we keep it for
|
|
29
|
+
// the next read.
|
|
30
|
+
let boundary = findBoundary(buffer);
|
|
31
|
+
while (boundary !== -1) {
|
|
32
|
+
const rawFrame = buffer.slice(0, boundary);
|
|
33
|
+
buffer = buffer.slice(boundary).replace(/^(\r?\n)+/, "");
|
|
34
|
+
const frame = parseFrame(rawFrame);
|
|
35
|
+
if (frame)
|
|
36
|
+
yield frame;
|
|
37
|
+
boundary = findBoundary(buffer);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// Flush any trailing complete frame (no blank line, but the stream ended).
|
|
41
|
+
if (buffer.trim().length > 0) {
|
|
42
|
+
const frame = parseFrame(buffer);
|
|
43
|
+
if (frame)
|
|
44
|
+
yield frame;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
finally {
|
|
48
|
+
try {
|
|
49
|
+
reader.releaseLock();
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
/* ignore */
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function findBoundary(s) {
|
|
57
|
+
const a = s.indexOf("\n\n");
|
|
58
|
+
const b = s.indexOf("\r\n\r\n");
|
|
59
|
+
if (a === -1)
|
|
60
|
+
return b;
|
|
61
|
+
if (b === -1)
|
|
62
|
+
return a;
|
|
63
|
+
return Math.min(a, b);
|
|
64
|
+
}
|
|
65
|
+
function parseFrame(raw) {
|
|
66
|
+
let event = "message";
|
|
67
|
+
const dataLines = [];
|
|
68
|
+
for (const line of raw.split(/\r?\n/)) {
|
|
69
|
+
if (line.length === 0)
|
|
70
|
+
continue;
|
|
71
|
+
if (line.startsWith(":"))
|
|
72
|
+
continue; // comment / heartbeat
|
|
73
|
+
const colon = line.indexOf(":");
|
|
74
|
+
const field = colon === -1 ? line : line.slice(0, colon);
|
|
75
|
+
// Spec: a single leading space after the colon is stripped.
|
|
76
|
+
let value = colon === -1 ? "" : line.slice(colon + 1);
|
|
77
|
+
if (value.startsWith(" "))
|
|
78
|
+
value = value.slice(1);
|
|
79
|
+
if (field === "event")
|
|
80
|
+
event = value;
|
|
81
|
+
else if (field === "data")
|
|
82
|
+
dataLines.push(value);
|
|
83
|
+
// ignore id / retry
|
|
84
|
+
}
|
|
85
|
+
if (dataLines.length === 0 && event === "message")
|
|
86
|
+
return null;
|
|
87
|
+
return { event, data: dataLines.join("\n") };
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=sse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sse.js","sourceRoot":"","sources":["../../src/sse.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;AAQH,wCAsCC;AAtCM,KAAK,SAAS,CAAC,CAAC,cAAc,CACnC,MAAkC;IAElC,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,CAAA;IACjC,MAAM,OAAO,GAAG,IAAI,WAAW,CAAC,OAAO,CAAC,CAAA;IACxC,IAAI,MAAM,GAAG,EAAE,CAAA;IAEf,IAAI,CAAC;QACH,OAAO,IAAI,EAAE,CAAC;YACZ,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,I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AAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAA;AAC9C,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stable mapping from SSE frames emitted by `POST /messages?stream=true`
|
|
3
|
+
* to the public `StreamEvent` discriminated union.
|
|
4
|
+
*
|
|
5
|
+
* Extracted from the client so each branch can be unit-tested in
|
|
6
|
+
* isolation — bug-prone because it lives at the contract boundary
|
|
7
|
+
* between backend and SDK and silently mis-mapped fields would surface
|
|
8
|
+
* as confusing UX, not loud errors.
|
|
9
|
+
*/
|
|
10
|
+
import type { SseFrame } from "./sse.js";
|
|
11
|
+
import type { StreamEvent } from "./streamEvents.js";
|
|
12
|
+
export declare function frameToStreamEvent(frame: SseFrame): StreamEvent | null;
|
|
13
|
+
//# sourceMappingURL=streamEventParse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streamEventParse.d.ts","sourceRoot":"","sources":["../../src/streamEventParse.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAEpD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,QAAQ,GAAG,WAAW,GAAG,IAAI,CAkEtE"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Stable mapping from SSE frames emitted by `POST /messages?stream=true`
|
|
4
|
+
* to the public `StreamEvent` discriminated union.
|
|
5
|
+
*
|
|
6
|
+
* Extracted from the client so each branch can be unit-tested in
|
|
7
|
+
* isolation — bug-prone because it lives at the contract boundary
|
|
8
|
+
* between backend and SDK and silently mis-mapped fields would surface
|
|
9
|
+
* as confusing UX, not loud errors.
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.frameToStreamEvent = frameToStreamEvent;
|
|
13
|
+
function frameToStreamEvent(frame) {
|
|
14
|
+
let data;
|
|
15
|
+
try {
|
|
16
|
+
data = frame.data ? JSON.parse(frame.data) : {};
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
switch (frame.event) {
|
|
22
|
+
case "delta":
|
|
23
|
+
return { type: "delta", text: String(data.text ?? "") };
|
|
24
|
+
case "tool_call.started":
|
|
25
|
+
return {
|
|
26
|
+
type: "tool_call.started",
|
|
27
|
+
toolCallId: String(data.tool_call_id),
|
|
28
|
+
toolName: String(data.tool_name),
|
|
29
|
+
capabilityId: String(data.capability_id),
|
|
30
|
+
};
|
|
31
|
+
case "tool_call.completed":
|
|
32
|
+
return {
|
|
33
|
+
type: "tool_call.completed",
|
|
34
|
+
toolCallId: String(data.tool_call_id),
|
|
35
|
+
toolName: String(data.tool_name),
|
|
36
|
+
capabilityId: String(data.capability_id),
|
|
37
|
+
durationMs: Number(data.duration_ms ?? 0),
|
|
38
|
+
};
|
|
39
|
+
case "done": {
|
|
40
|
+
const m = data.message;
|
|
41
|
+
return {
|
|
42
|
+
type: "done",
|
|
43
|
+
runId: String(data.run_id ?? ""),
|
|
44
|
+
conversationId: String(data.conversation_id ?? ""),
|
|
45
|
+
message: m
|
|
46
|
+
? {
|
|
47
|
+
role: "assistant",
|
|
48
|
+
content: String(m.content ?? ""),
|
|
49
|
+
sequence: Number(m.sequence ?? 0),
|
|
50
|
+
stepId: m.step_id ?? null,
|
|
51
|
+
createdAt: String(m.created_at ?? ""),
|
|
52
|
+
runId: String(data.run_id ?? ""),
|
|
53
|
+
conversationId: String(data.conversation_id ?? ""),
|
|
54
|
+
}
|
|
55
|
+
: null,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
case "error":
|
|
59
|
+
return {
|
|
60
|
+
type: "error",
|
|
61
|
+
failureClass: data.failure_class,
|
|
62
|
+
isPermanent: !!data.is_permanent,
|
|
63
|
+
message: String(data.message ?? ""),
|
|
64
|
+
stepId: data.step_id ?? null,
|
|
65
|
+
runId: String(data.run_id ?? ""),
|
|
66
|
+
conversationId: String(data.conversation_id ?? ""),
|
|
67
|
+
};
|
|
68
|
+
case "paused_for_approval":
|
|
69
|
+
return {
|
|
70
|
+
type: "paused_for_approval",
|
|
71
|
+
approval: data.approval,
|
|
72
|
+
runId: String(data.run_id ?? ""),
|
|
73
|
+
conversationId: String(data.conversation_id ?? ""),
|
|
74
|
+
};
|
|
75
|
+
default:
|
|
76
|
+
// Unknown event types are dropped so the SDK stays forward-compatible
|
|
77
|
+
// with future backend additions.
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=streamEventParse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streamEventParse.js","sourceRoot":"","sources":["../../src/streamEventParse.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;AAKH,gDAkEC;AAlED,SAAgB,kBAAkB,CAAC,KAAe;IAChD,IAAI,IAAS,CAAA;IACb,IAAI,CAAC;QACH,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;IACjD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAA;IACb,CAAC;IACD,QAAQ,KAAK,CAAC,KAAK,EAAE,CAAC;QACpB,KAAK,OAAO;YACV,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC,EAAE,CAAA;QACzD,KAAK,mBAAmB;YACtB,OAAO;gBACL,IAAI,EAAE,mBAAmB;gBACzB,UAAU,EAAE,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC;gBACrC,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC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,WAAW,EAAE,CAAC,CAAC,IAAI,CAAC,YAAY;gBAChC,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC;gBACnC,MAAM,EAAE,IAAI,CAAC,OAAO,IAAI,IAAI;gBAC5B,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC;gBAChC,cAAc,EAAE,MAAM,CAAC,IAAI,CAAC,eAAe,IAAI,EAAE,CAAC;aACnD,CAAA;QACH,KAAK,qBAAqB;YACxB,OAAO;gBACL,IAAI,EAAE,qBAAqB;gBAC3B,QAAQ,EAAE,IAAI,CAAC,QAAQ;gBACvB,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC;gBAChC,cAAc,EAAE,MAAM,CAAC,IAAI,CAAC,eAAe,IAAI,EAAE,CAAC;aACnD,CAAA;QACH;YACE,sEAAsE;YACtE,iCAAiC;YACjC,OAAO,IAAI,CAAA;IACf,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK-facing stream event types — what `chat.stream(...)` yields.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors the SSE frames the backend emits on `POST /messages?stream=true`.
|
|
5
|
+
* Stable across backend refactors; the bus-event → stream-event mapping
|
|
6
|
+
* lives on the server.
|
|
7
|
+
*
|
|
8
|
+
* Terminal events (`done`, `error`, `paused_for_approval`) end the
|
|
9
|
+
* iterator. `delta` and `tool_call.*` events arrive incrementally.
|
|
10
|
+
*/
|
|
11
|
+
import type { AgentFailureClass, ApprovalDetails, AssistantMessage } from "./types";
|
|
12
|
+
/** Incremental token delta from the agent. */
|
|
13
|
+
export interface StreamDelta {
|
|
14
|
+
type: "delta";
|
|
15
|
+
text: string;
|
|
16
|
+
}
|
|
17
|
+
/** Agent started a tool call. */
|
|
18
|
+
export interface StreamToolCallStarted {
|
|
19
|
+
type: "tool_call.started";
|
|
20
|
+
toolCallId: string;
|
|
21
|
+
toolName: string;
|
|
22
|
+
capabilityId: string;
|
|
23
|
+
}
|
|
24
|
+
/** Agent finished a tool call. */
|
|
25
|
+
export interface StreamToolCallCompleted {
|
|
26
|
+
type: "tool_call.completed";
|
|
27
|
+
toolCallId: string;
|
|
28
|
+
toolName: string;
|
|
29
|
+
capabilityId: string;
|
|
30
|
+
durationMs: number;
|
|
31
|
+
}
|
|
32
|
+
/** Terminal: assistant finished, no more tokens. */
|
|
33
|
+
export interface StreamDone {
|
|
34
|
+
type: "done";
|
|
35
|
+
message: AssistantMessage | null;
|
|
36
|
+
runId: string;
|
|
37
|
+
conversationId: string;
|
|
38
|
+
}
|
|
39
|
+
/** Terminal: agent failed. */
|
|
40
|
+
export interface StreamError {
|
|
41
|
+
type: "error";
|
|
42
|
+
failureClass: AgentFailureClass;
|
|
43
|
+
isPermanent: boolean;
|
|
44
|
+
message: string;
|
|
45
|
+
stepId: string | null;
|
|
46
|
+
runId: string;
|
|
47
|
+
conversationId: string;
|
|
48
|
+
}
|
|
49
|
+
/** Terminal: run paused waiting for HITL approval. */
|
|
50
|
+
export interface StreamPausedForApproval {
|
|
51
|
+
type: "paused_for_approval";
|
|
52
|
+
approval: ApprovalDetails;
|
|
53
|
+
runId: string;
|
|
54
|
+
conversationId: string;
|
|
55
|
+
}
|
|
56
|
+
export type StreamEvent = StreamDelta | StreamToolCallStarted | StreamToolCallCompleted | StreamDone | StreamError | StreamPausedForApproval;
|
|
57
|
+
export declare function isTerminalStreamEvent(e: StreamEvent): boolean;
|
|
58
|
+
//# sourceMappingURL=streamEvents.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streamEvents.d.ts","sourceRoot":"","sources":["../../src/streamEvents.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAEnF,8CAA8C;AAC9C,MAA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AE7D"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* SDK-facing stream event types — what `chat.stream(...)` yields.
|
|
4
|
+
*
|
|
5
|
+
* Mirrors the SSE frames the backend emits on `POST /messages?stream=true`.
|
|
6
|
+
* Stable across backend refactors; the bus-event → stream-event mapping
|
|
7
|
+
* lives on the server.
|
|
8
|
+
*
|
|
9
|
+
* Terminal events (`done`, `error`, `paused_for_approval`) end the
|
|
10
|
+
* iterator. `delta` and `tool_call.*` events arrive incrementally.
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.isTerminalStreamEvent = isTerminalStreamEvent;
|
|
14
|
+
const TERMINAL_TYPES = new Set([
|
|
15
|
+
"done",
|
|
16
|
+
"error",
|
|
17
|
+
"paused_for_approval",
|
|
18
|
+
]);
|
|
19
|
+
function isTerminalStreamEvent(e) {
|
|
20
|
+
return TERMINAL_TYPES.has(e.type);
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=streamEvents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streamEvents.js","sourceRoot":"","sources":["../../src/streamEvents.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;AAoEH,sDAEC;AARD,MAAM,cAAc,GAAqC,IAAI,GAAG,CAAC;IAC/D,MAAM;IACN,OAAO;IACP,qBAAqB;CACtB,CAAC,CAAA;AAEF,SAAgB,qBAAqB,CAAC,CAAc;IAClD,OAAO,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;AACnC,CAAC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shapes exposed by the SDK.
|
|
3
|
+
*
|
|
4
|
+
* These mirror the backend response shapes but are intentionally
|
|
5
|
+
* decoupled from `@darq/shared-types` so the SDK can be published
|
|
6
|
+
* without dragging the entire internal type surface along with it.
|
|
7
|
+
*/
|
|
8
|
+
export type Environment = "production" | "staging" | "development";
|
|
9
|
+
export interface AssistantMessage {
|
|
10
|
+
role: "assistant";
|
|
11
|
+
content: string;
|
|
12
|
+
/** Monotonic per-conversation sequence number. */
|
|
13
|
+
sequence: number;
|
|
14
|
+
/** The agent step that produced this message, if known. */
|
|
15
|
+
stepId: string | null;
|
|
16
|
+
/** ISO-8601 timestamp. */
|
|
17
|
+
createdAt: string;
|
|
18
|
+
/** Run that produced this message. */
|
|
19
|
+
runId: string;
|
|
20
|
+
conversationId: string;
|
|
21
|
+
}
|
|
22
|
+
export interface UserMessage {
|
|
23
|
+
role: "user";
|
|
24
|
+
content: string;
|
|
25
|
+
sequence: number;
|
|
26
|
+
createdAt: string;
|
|
27
|
+
}
|
|
28
|
+
export interface ToolMessage {
|
|
29
|
+
role: "tool";
|
|
30
|
+
content: string;
|
|
31
|
+
sequence: number;
|
|
32
|
+
toolCallId: string | null;
|
|
33
|
+
createdAt: string;
|
|
34
|
+
}
|
|
35
|
+
export type ConversationMessage = AssistantMessage | UserMessage | ToolMessage;
|
|
36
|
+
export interface FileAttachment {
|
|
37
|
+
/** Path of the artifact in object storage. */
|
|
38
|
+
storageKey: string;
|
|
39
|
+
mimeType: string;
|
|
40
|
+
filename: string;
|
|
41
|
+
size: number;
|
|
42
|
+
/** Artifact id, when one has been recorded. */
|
|
43
|
+
artifactId?: string;
|
|
44
|
+
}
|
|
45
|
+
export type AgentFailureClass = "provider_quota_exhausted" | "provider_auth" | "provider_bad_request" | "provider_rate_limited" | "provider_unavailable" | "internal" | "unknown";
|
|
46
|
+
export interface ApprovalDetails {
|
|
47
|
+
approval_id: string;
|
|
48
|
+
tool_call_id: string;
|
|
49
|
+
capability_id: string;
|
|
50
|
+
tool_name: string;
|
|
51
|
+
arguments: Record<string, unknown>;
|
|
52
|
+
nested_approval?: {
|
|
53
|
+
agent_id: string;
|
|
54
|
+
agent_name: string;
|
|
55
|
+
tool_name: string;
|
|
56
|
+
capability_id: string;
|
|
57
|
+
arguments?: Record<string, unknown>;
|
|
58
|
+
depth: number;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
export interface SendOptions {
|
|
62
|
+
/** Optional file attachments. */
|
|
63
|
+
files?: FileAttachment[];
|
|
64
|
+
/** Override the SDK-default wait timeout for this call. */
|
|
65
|
+
timeoutMs?: number;
|
|
66
|
+
}
|
|
67
|
+
export interface HistoryOptions {
|
|
68
|
+
/** Max messages to return (server-capped at 500). */
|
|
69
|
+
limit?: number;
|
|
70
|
+
/** Pagination cursor — pass the oldest sequence returned previously. */
|
|
71
|
+
beforeSequence?: number;
|
|
72
|
+
}
|
|
73
|
+
export interface HistoryPage {
|
|
74
|
+
messages: ConversationMessage[];
|
|
75
|
+
hasMore: boolean;
|
|
76
|
+
oldestSequence: number | null;
|
|
77
|
+
totalMessageCount: number;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Read-only, per-deployment client config. Resolved server-side from the
|
|
81
|
+
* owning org's subscription — the SDK never decides these itself. Fetched
|
|
82
|
+
* once on widget mount via `agent(...).config()`.
|
|
83
|
+
*/
|
|
84
|
+
export interface DeploymentConfig {
|
|
85
|
+
branding: {
|
|
86
|
+
/**
|
|
87
|
+
* When true, the org's tier entitles it to run the widget without the
|
|
88
|
+
* "Powered by Curator" footer. `false` for tiers without white-label.
|
|
89
|
+
*/
|
|
90
|
+
hidePoweredBy: boolean;
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,MAAM,WAAW,GAAG,YAAY,GAAG,SAAS,GAAG,aAAa,CAAA;AAElE,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,WAAW,CAAA;IACjB,OAAO,EAAE,MAAM,CAAA;IACf,kDAAkD;IA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QAChB,UAAU,EAAE,MAAM,CAAA;QAClB,SAAS,EAAE,MAAM,CAAA;QACjB,aAAa,EAAE,MAAM,CAAA;QACrB,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QACnC,KAAK,EAAE,MAAM,CAAA;KACd,CAAA;CACF;AAED,MAAM,WAAW,WAAW;IAC1B,iCAAiC;IACjC,KAAK,CAAC,EAAE,cAAc,EAAE,CAAA;IACxB,2DAA2D;IAC3D,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,cAAc;IAC7B,qDAAqD;IACrD,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,wEAAwE;IACxE,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,mBAAmB,EAAE,CAAA;IAC/B,OAAO,EAAE,OAAO,CAAA;IAChB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAA;IAC7B,iBAAiB,EAAE,MAAM,CAAA;CAC1B;AAED;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE;QACR;;;WAGG;QACH,aAAa,EAAE,OAAO,CAAA;KACvB,CAAA;CACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Shapes exposed by the SDK.
|
|
4
|
+
*
|
|
5
|
+
* These mirror the backend response shapes but are intentionally
|
|
6
|
+
* decoupled from `@darq/shared-types` so the SDK can be published
|
|
7
|
+
* without dragging the entire internal type surface along with it.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG"}
|
|
@@ -0,0 +1,174 @@
|
|
|
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 { Files } from "./files.js";
|
|
22
|
+
import { HttpClient, type DeploymentRoute, type EndUserJwtProvider } from "./http.js";
|
|
23
|
+
import type { StreamEvent } from "./streamEvents.js";
|
|
24
|
+
import type { AssistantMessage, DeploymentConfig, Environment, HistoryOptions, HistoryPage, SendOptions } from "./types.js";
|
|
25
|
+
export interface CuratorOptions {
|
|
26
|
+
/** Org-scoped API key from Settings → Developer. `curator_live_*` for production, `curator_test_*` for staging / development. */
|
|
27
|
+
apiKey: string;
|
|
28
|
+
/**
|
|
29
|
+
* Base URL of the Curator deployment. Defaults to the public host.
|
|
30
|
+
* Override for self-hosted or staging environments.
|
|
31
|
+
*/
|
|
32
|
+
baseUrl?: string;
|
|
33
|
+
/** Default project slug. Can be overridden per-call via `agent(slug, { project })`. */
|
|
34
|
+
project?: string;
|
|
35
|
+
/** Default environment. Can be overridden per-call via `agent(slug, { environment })`. */
|
|
36
|
+
environment?: Environment;
|
|
37
|
+
/** Default sync-wait timeout, in ms. The server caps this at 300s. */
|
|
38
|
+
defaultTimeoutMs?: number;
|
|
39
|
+
/** Custom fetch implementation (test stubs, older Node, etc.). */
|
|
40
|
+
fetch?: typeof fetch;
|
|
41
|
+
/** Extra headers attached to every request. */
|
|
42
|
+
defaultHeaders?: Record<string, string>;
|
|
43
|
+
/**
|
|
44
|
+
* End-user JWT — proves which user on the customer's platform is driving
|
|
45
|
+
* the agent. Required when the org has opted into verified end-user
|
|
46
|
+
* identity. Accepts either a static string or a sync/async function the
|
|
47
|
+
* SDK calls per-request (typical for browsers refreshing short-lived
|
|
48
|
+
* tokens via their backend). See {@link EndUserJwtProvider}.
|
|
49
|
+
*/
|
|
50
|
+
endUserJwt?: EndUserJwtProvider;
|
|
51
|
+
}
|
|
52
|
+
export interface AgentLocator {
|
|
53
|
+
/** Project slug. Defaults to the value passed to `new Curator({ project })`. */
|
|
54
|
+
project?: string;
|
|
55
|
+
/** Environment. Defaults to the value passed to `new Curator({ environment })`. */
|
|
56
|
+
environment?: Environment;
|
|
57
|
+
/**
|
|
58
|
+
* Set to true to address a system-scoped deployment (no project /
|
|
59
|
+
* environment in the path). Mutually exclusive with `project`.
|
|
60
|
+
*/
|
|
61
|
+
system?: boolean;
|
|
62
|
+
}
|
|
63
|
+
export declare class Curator {
|
|
64
|
+
private readonly http;
|
|
65
|
+
private readonly defaultProject?;
|
|
66
|
+
private readonly defaultEnvironment;
|
|
67
|
+
private readonly defaultTimeoutMs;
|
|
68
|
+
/** File-upload surface — see {@link Files}. */
|
|
69
|
+
readonly files: Files;
|
|
70
|
+
constructor(opts: CuratorOptions);
|
|
71
|
+
/**
|
|
72
|
+
* Address an agent deployment by its slug. Project / environment fall
|
|
73
|
+
* back to the constructor defaults; pass overrides via the second arg.
|
|
74
|
+
*/
|
|
75
|
+
agent(slug: string, locator?: AgentLocator): Agent;
|
|
76
|
+
private resolveRoute;
|
|
77
|
+
}
|
|
78
|
+
export declare class Agent {
|
|
79
|
+
private readonly http;
|
|
80
|
+
private readonly defaultTimeoutMs;
|
|
81
|
+
private readonly route;
|
|
82
|
+
/** @internal */
|
|
83
|
+
constructor(http: HttpClient, defaultTimeoutMs: number, route: DeploymentRoute);
|
|
84
|
+
/**
|
|
85
|
+
* Open a fresh conversation, send `content`, await the reply, and
|
|
86
|
+
* return it. Equivalent to `agent.chat().send(content)` but one line.
|
|
87
|
+
*/
|
|
88
|
+
run(content: string, opts?: SendOptions): Promise<AssistantMessage>;
|
|
89
|
+
/**
|
|
90
|
+
* Open a fresh conversation and stream the reply as it's generated.
|
|
91
|
+
* Equivalent to `agent.chat().stream(content)`.
|
|
92
|
+
*/
|
|
93
|
+
stream(content: string, opts?: SendOptions): AsyncIterable<StreamEvent>;
|
|
94
|
+
/**
|
|
95
|
+
* Return a Chat handle whose conversation is created lazily on the
|
|
96
|
+
* first `send(...)`. Subsequent sends reuse the same conversation.
|
|
97
|
+
*/
|
|
98
|
+
chat(): Chat;
|
|
99
|
+
/**
|
|
100
|
+
* Reattach to an existing conversation by id (e.g. resuming a chat
|
|
101
|
+
* across processes or restoring from durable state).
|
|
102
|
+
*/
|
|
103
|
+
conversation(conversationId: string): Chat;
|
|
104
|
+
/**
|
|
105
|
+
* Fetch this deployment's read-only client config (branding entitlements,
|
|
106
|
+
* etc.). Resolved server-side from the org's subscription tier. No side
|
|
107
|
+
* effects — safe to call on widget mount. `<CuratorChat />` uses this to
|
|
108
|
+
* decide whether to render the "Powered by Curator" footer.
|
|
109
|
+
*/
|
|
110
|
+
config(): Promise<DeploymentConfig>;
|
|
111
|
+
}
|
|
112
|
+
export declare class Chat {
|
|
113
|
+
private readonly http;
|
|
114
|
+
private readonly defaultTimeoutMs;
|
|
115
|
+
private readonly route;
|
|
116
|
+
private conversationId;
|
|
117
|
+
/** Cached promise for an in-flight `POST /conversations`. */
|
|
118
|
+
private pendingCreate;
|
|
119
|
+
/** @internal */
|
|
120
|
+
constructor(http: HttpClient, defaultTimeoutMs: number, route: DeploymentRoute, initialConversationId: string | null);
|
|
121
|
+
/**
|
|
122
|
+
* Conversation id, or `null` until the first send creates one.
|
|
123
|
+
* Use `.ensureId()` if you need to materialize the conversation
|
|
124
|
+
* eagerly without sending a message.
|
|
125
|
+
*/
|
|
126
|
+
get id(): string | null;
|
|
127
|
+
/** Force conversation creation now and return its id. */
|
|
128
|
+
ensureId(): Promise<string>;
|
|
129
|
+
/**
|
|
130
|
+
* Send a user message and await the assistant's reply. Lazily creates
|
|
131
|
+
* the conversation if needed. Returns the final assistant message.
|
|
132
|
+
*
|
|
133
|
+
* Throws:
|
|
134
|
+
* - CuratorApprovalRequiredError if the run pauses for HITL (an
|
|
135
|
+
* administrator must resolve it in the dashboard)
|
|
136
|
+
* - CuratorAgentError on terminal agent failure
|
|
137
|
+
* - CuratorTimeoutError if the wait expires (the run keeps running)
|
|
138
|
+
*/
|
|
139
|
+
send(content: string, opts?: SendOptions): Promise<AssistantMessage>;
|
|
140
|
+
/**
|
|
141
|
+
* Send a user message and stream the agent's response back as it's
|
|
142
|
+
* generated. Each yielded event is one of `delta` / `tool_call.*` /
|
|
143
|
+
* `done` / `error` / `paused_for_approval`. The iterator ends on the
|
|
144
|
+
* first terminal event.
|
|
145
|
+
*
|
|
146
|
+
* for await (const e of chat.stream("hello")) {
|
|
147
|
+
* if (e.type === "delta") process.stdout.write(e.text)
|
|
148
|
+
* if (e.type === "done") console.log("\nfinal:", e.message?.content)
|
|
149
|
+
* }
|
|
150
|
+
*
|
|
151
|
+
* Aborting the iteration (breaking out of the loop, or calling
|
|
152
|
+
* `.return()`) closes the underlying HTTP connection — the server-
|
|
153
|
+
* side run keeps going independently. Use `chat.history()` later to
|
|
154
|
+
* fetch what landed.
|
|
155
|
+
*/
|
|
156
|
+
stream(content: string, opts?: SendOptions): AsyncGenerator<StreamEvent, void, void>;
|
|
157
|
+
/** Fetch (paginated) conversation history. */
|
|
158
|
+
history(opts?: HistoryOptions): Promise<HistoryPage>;
|
|
159
|
+
private createConversation;
|
|
160
|
+
/**
|
|
161
|
+
* Continue waiting for the next terminal state on an already-running
|
|
162
|
+
* conversation. Used to back `CuratorTimeoutError.continueWaiting()`.
|
|
163
|
+
*
|
|
164
|
+
* The server-side wait endpoint hangs off `POST /messages`, so to
|
|
165
|
+
* re-wait without sending a new user message we poll history for an
|
|
166
|
+
* assistant message whose `sequence` exceeds the baseline established
|
|
167
|
+
* before the wait began. For a still-in-flight run, the assistant
|
|
168
|
+
* reply typically lands within seconds.
|
|
169
|
+
*/
|
|
170
|
+
private waitForNextReply;
|
|
171
|
+
private latestSequence;
|
|
172
|
+
private unwrapWaitOutcome;
|
|
173
|
+
}
|
|
174
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAQH,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,UAAU,EAAE,KAAK,eAAe,EAAE,KAAK,kBAAkB,EAAE,MAAM,WAAW,CAAA;AAGrF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAEpD,OAAO,KAAK,EAEV,gBAAgB,EAEhB,gBAAgB,EAChB,WAAW,EAEX,cAAc,EACd,WAAW,EACX,WAAW,EACZ,MAAM,YAAY,CAAA;AAEnB,MAAM,WAAW,cAAc;IAC7B,iIAAiI;IACjI,MAAM,EAAE,MAAM,CAAA;IACd;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,uFAAuF;IACvF,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,0FAA0F;IAC1F,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,sEAAsE;IACtE,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,kEAAkE;IAClE,KAAK,CAAC,EAAE,OAAO,KAAK,CAAA;IACpB,+CAA+C;IAC/C,cAAc,CAAC,EAAE,MAAM,CAAC,MAA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