ql-agent-sdk 0.0.0-stage → 1.0.1

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.
@@ -0,0 +1,416 @@
1
+ interface JsonRequestOptions {
2
+ body?: unknown;
3
+ query?: Record<string, string | number | undefined>;
4
+ signal?: AbortSignal;
5
+ headers?: Record<string, string>;
6
+ }
7
+ /**
8
+ * Internal transport used by the API namespaces. Keeps the API key inside a
9
+ * closure (never exposed) and normalizes responses/errors for the caller.
10
+ */
11
+ interface Transport {
12
+ /** Perform a JSON request and return the unwrapped `data` payload. */
13
+ json<T>(method: string, path: string, opts?: JsonRequestOptions): Promise<T>;
14
+ /**
15
+ * Perform a request expected to stream SSE. Returns the response body stream
16
+ * after verifying a 2xx + text/event-stream; throws QLError otherwise.
17
+ */
18
+ stream(method: string, path: string, opts?: JsonRequestOptions & {
19
+ acceptStream?: boolean;
20
+ }): Promise<ReadableStream<Uint8Array>>;
21
+ }
22
+
23
+ /**
24
+ * Public request/response types for the Quanton Labs agent platform API (v1).
25
+ *
26
+ * These mirror the verified Phase 1 endpoints. The public surface is enveloped:
27
+ * success -> { ok: true, data }
28
+ * error -> { ok: false, error: { code, message } }
29
+ * The SDK unwraps `data` for you and surfaces errors as a typed QLError.
30
+ */
31
+ /** Stable API error codes emitted by the backend. */
32
+ declare const API_ERROR_CODES: {
33
+ readonly unauthorized: "unauthorized";
34
+ readonly forbidden: "forbidden";
35
+ readonly notFound: "not_found";
36
+ readonly validationError: "validation_error";
37
+ readonly conflict: "conflict";
38
+ readonly internalError: "internal_error";
39
+ };
40
+ type ApiErrorCode = (typeof API_ERROR_CODES)[keyof typeof API_ERROR_CODES];
41
+ /** A single message in a chat conversation. */
42
+ interface ChatMessage {
43
+ role: "system" | "user" | "assistant";
44
+ content: string;
45
+ }
46
+ /** Input for `agents.chat` and `agents.chatStream`. */
47
+ interface ChatInput {
48
+ agentId: string;
49
+ messages: ChatMessage[];
50
+ /** Optional internal user id; defaults to the key's workspace when omitted. */
51
+ userId?: string;
52
+ /** Optional OpenRouter response-format hint (e.g. `{ type: "json_object" }`). */
53
+ response_format?: Record<string, unknown>;
54
+ }
55
+ /** Result of a non-streaming chat call. */
56
+ interface ChatResult {
57
+ content: string;
58
+ toolCalls: number;
59
+ iterations: number;
60
+ /** Human-readable duration string, e.g. "2.91s". */
61
+ duration: string;
62
+ }
63
+ /**
64
+ * A single event yielded by `agents.chatStream`.
65
+ * - `delta`: an incremental piece of the streamed response (text and/or reasoning).
66
+ * - `done`: emitted once at the end with the fully accumulated text.
67
+ */
68
+ type ChatStreamEvent = {
69
+ type: "delta";
70
+ content?: string;
71
+ reasoning?: string;
72
+ } | {
73
+ type: "done";
74
+ content: string;
75
+ reasoning?: string;
76
+ };
77
+ /** Options accepted by streaming methods. */
78
+ interface StreamOptions {
79
+ /** Abort the in-flight request/stream at any time. */
80
+ signal?: AbortSignal;
81
+ }
82
+ /** A conversation-history page (newest first). */
83
+ interface MessageItem {
84
+ id: string;
85
+ role: string;
86
+ content: string | null;
87
+ reasoning?: string;
88
+ toolCalls: unknown[];
89
+ status: string;
90
+ timestamp: string | Date;
91
+ }
92
+ interface HistoryPage {
93
+ agentId: string;
94
+ limit: number;
95
+ /** Cursor for the next page (pass as `before`); null when exhausted. */
96
+ nextBefore: string | null;
97
+ items: MessageItem[];
98
+ }
99
+ /** Query params for `agents.history`. */
100
+ interface HistoryParams {
101
+ /** Page size, 1..100 (default 20 server-side). */
102
+ limit?: number;
103
+ /** Cursor = id of the last item on the previous page. */
104
+ before?: string;
105
+ /** Optional internal user id filter. */
106
+ userId?: string;
107
+ }
108
+ /** Agent summary as returned by `agents.list`. */
109
+ interface AgentSummary {
110
+ id: string;
111
+ name: string;
112
+ domain: string;
113
+ description: string;
114
+ icon: string;
115
+ tags: string[];
116
+ capabilityCount: number;
117
+ }
118
+ interface AgentListResult {
119
+ agents: AgentSummary[];
120
+ }
121
+ /** A schema-driven capability parameter (rendered as a form field in the UI). */
122
+ type CapParamKind = "text" | "textarea" | "number" | "select" | "boolean" | "json";
123
+ interface CapabilityParam {
124
+ key: string;
125
+ label: string;
126
+ kind: CapParamKind;
127
+ placeholder?: string;
128
+ options?: {
129
+ value: string;
130
+ label: string;
131
+ }[];
132
+ required?: boolean;
133
+ hint?: string;
134
+ rows?: number;
135
+ [key: string]: unknown;
136
+ }
137
+ /** A pre-filled example input set (suggestion chip). */
138
+ interface CapabilityTemplate {
139
+ label: string;
140
+ values: Record<string, unknown>;
141
+ }
142
+ /** A client-safe capability descriptor (the server-side `run` is stripped). */
143
+ interface CapabilityInfo {
144
+ id: string;
145
+ name: string;
146
+ description: string;
147
+ category: string;
148
+ icon?: string;
149
+ badge?: string;
150
+ params: CapabilityParam[];
151
+ templates?: CapabilityTemplate[];
152
+ metrics?: string[];
153
+ tableKey?: string;
154
+ outputHint?: string;
155
+ [key: string]: unknown;
156
+ }
157
+ /** Agent detail + its capabilities, as returned by `agents.get`. */
158
+ interface AgentDetail {
159
+ agent: {
160
+ id: string;
161
+ name: string;
162
+ domain: string;
163
+ description: string;
164
+ icon: string;
165
+ tags: string[];
166
+ };
167
+ capabilities: CapabilityInfo[];
168
+ }
169
+ /** Result of `agents.capabilities`. */
170
+ interface CapabilitiesResult {
171
+ agentId: string;
172
+ capabilities: CapabilityInfo[];
173
+ }
174
+ /** Input for `agents.runCapability`. */
175
+ interface RunCapabilityInput {
176
+ capId: string;
177
+ /** Capability-specific parameters (see the capability's `params`). */
178
+ params?: Record<string, unknown>;
179
+ }
180
+ /**
181
+ * The result of running a capability. A discriminated union matching the
182
+ * backend — a feature can return text, structured JSON, HTML, or a file URL.
183
+ */
184
+ type CapabilityResult = {
185
+ type: "text";
186
+ content: string;
187
+ } | {
188
+ type: "json";
189
+ data: unknown;
190
+ } | {
191
+ type: "html";
192
+ html: string;
193
+ } | {
194
+ type: "file";
195
+ url: string;
196
+ filename: string;
197
+ mime: string;
198
+ };
199
+ /** Result envelope for `agents.runCapability`. */
200
+ interface RunCapabilityResult {
201
+ result: CapabilityResult;
202
+ }
203
+ /** The workspace object as returned by the public API (redacted). */
204
+ interface Workspace {
205
+ _id: string;
206
+ name: string;
207
+ plan?: string;
208
+ createdAt?: string | Date;
209
+ updatedAt?: string | Date;
210
+ }
211
+ /** Input for `workflows.run`. */
212
+ interface WorkflowRunInput {
213
+ /** Optional workflow input payload. */
214
+ input?: Record<string, unknown>;
215
+ }
216
+ /** Returned immediately when a workflow run is started (HTTP 202). */
217
+ interface WorkflowRunStart {
218
+ runId: string;
219
+ status: "running";
220
+ }
221
+ type WorkflowRunStatus = "queued" | "running" | "completed" | "failed" | "cancelled" | (string & {});
222
+ /** A workflow run snapshot, as returned by `workflows.getRun`. */
223
+ interface WorkflowRun {
224
+ runId: string;
225
+ status: WorkflowRunStatus;
226
+ output: unknown | null;
227
+ error?: string;
228
+ durationMs?: number;
229
+ startedAt: string | Date;
230
+ finishedAt: string | Date | null;
231
+ }
232
+ type TaskPriority = "low" | "medium" | "high" | "urgent";
233
+ /** Input for `tasks.create`. */
234
+ interface TaskCreateInput {
235
+ agentId: string;
236
+ title: string;
237
+ description?: string;
238
+ /** Arbitrary payload handed to the agent. */
239
+ input?: unknown;
240
+ priority?: TaskPriority;
241
+ }
242
+ /** Returned when a task is created (HTTP 201). */
243
+ interface TaskCreated {
244
+ taskId: string;
245
+ status: TaskStatus;
246
+ }
247
+ type TaskStatus = "queued" | "running" | "completed" | "failed" | "cancelled" | "retrying" | (string & {});
248
+ /** A task snapshot, as returned by `tasks.get`. */
249
+ interface Task {
250
+ taskId: string;
251
+ status: TaskStatus;
252
+ title: string;
253
+ progress?: unknown;
254
+ result?: unknown;
255
+ output?: unknown;
256
+ error?: string;
257
+ createdAt: string | Date;
258
+ completedAt: string | Date | null;
259
+ }
260
+ /** Options for polling / waiting on a task. */
261
+ interface WaitOptions {
262
+ /** Base delay between polls in ms (default 2000). Grows with backoff up to `maxIntervalMs`. */
263
+ intervalMs?: number;
264
+ /** Upper bound for the backoff delay in ms (default 15000). */
265
+ maxIntervalMs?: number;
266
+ /** Stop waiting after this many ms and throw a timeout error. Omit to wait until terminal or abort. */
267
+ timeoutMs?: number;
268
+ /** Abort polling at any time. */
269
+ signal?: AbortSignal;
270
+ /** Called after each poll with the latest task snapshot. */
271
+ onTick?: (task: Task) => void;
272
+ }
273
+
274
+ declare function isTerminalTaskStatus(status: string): boolean;
275
+ /**
276
+ * A handle to a background task created via `tasks.create`.
277
+ *
278
+ * NOTE on execution: creating a task only enqueues it. It may stay in the
279
+ * `queued` state until an existing worker/execution mechanism processes it —
280
+ * this SDK does not trigger execution. `wait()` simply polls until the task
281
+ * reaches a terminal status (or you time out / abort).
282
+ */
283
+ declare class TaskHandle {
284
+ private readonly transport;
285
+ readonly taskId: string;
286
+ constructor(transport: Transport, taskId: string);
287
+ /** Fetch the current task snapshot (single request). */
288
+ get(signal?: AbortSignal): Promise<Task>;
289
+ /** Alias of `get()` — perform one poll and return the latest snapshot. */
290
+ poll(signal?: AbortSignal): Promise<Task>;
291
+ /**
292
+ * Poll until the task reaches a terminal status.
293
+ *
294
+ * - Uses exponential-ish backoff from `intervalMs` up to `maxIntervalMs`.
295
+ * - Throws a QLError with code "timeout" if `timeoutMs` elapses first.
296
+ * - Throws a QLError with code "aborted" if `signal` aborts.
297
+ */
298
+ wait(opts?: WaitOptions): Promise<Task>;
299
+ }
300
+
301
+ declare const DEFAULT_BASE_URL = "https://app.quantonlabs.com";
302
+ interface QLClientOptions {
303
+ /** Your Quanton Labs API key (Bearer). Never logged or exposed. */
304
+ apiKey: string;
305
+ /** API base URL. Defaults to `QL_BASE_URL` if set, else https://app.quantonlabs.com. */
306
+ baseUrl?: string;
307
+ /** Override the global fetch (for tests, proxies, or custom runtimes). */
308
+ fetch?: typeof fetch;
309
+ }
310
+ /** Workspace namespace. */
311
+ declare class WorkspaceApi {
312
+ private readonly t;
313
+ constructor(t: Transport);
314
+ /** GET /api/v1/workspace */
315
+ get(): Promise<Workspace>;
316
+ }
317
+ /** Agents namespace. */
318
+ declare class AgentsApi {
319
+ private readonly t;
320
+ constructor(t: Transport);
321
+ /** GET /api/v1/agents — list the global agent registry. */
322
+ list(): Promise<AgentListResult>;
323
+ /** GET /api/v1/agents/:agentId — agent detail + capabilities. */
324
+ get(agentId: string): Promise<AgentDetail>;
325
+ /** GET /api/v1/agents/:agentId/capabilities */
326
+ capabilities(agentId: string): Promise<CapabilitiesResult>;
327
+ /** POST /api/v1/agents/:agentId/capabilities/run — run a feature. */
328
+ runCapability(agentId: string, input: RunCapabilityInput): Promise<RunCapabilityResult>;
329
+ /** POST /api/v1/agents/chat — non-streaming chat. */
330
+ chat(input: ChatInput): Promise<ChatResult>;
331
+ /**
332
+ * POST /api/v1/agents/chat/stream — streaming chat as an async iterable.
333
+ *
334
+ * Yields incremental `delta` events (text and/or reasoning) followed by a
335
+ * single `done` event with the fully accumulated text. Stop early by passing
336
+ * an `AbortSignal` (see StreamOptions) or breaking out of the loop.
337
+ */
338
+ chatStream(input: ChatInput, opts?: StreamOptions): AsyncIterable<ChatStreamEvent>;
339
+ /** GET /api/v1/agents/:agentId/messages — paginated history (newest first). */
340
+ history(agentId: string, params?: HistoryParams): Promise<HistoryPage>;
341
+ private chatStreamImpl;
342
+ }
343
+ /** Workflows namespace. */
344
+ declare class WorkflowsApi {
345
+ private readonly t;
346
+ constructor(t: Transport);
347
+ /** POST /api/v1/workflows/:id/run — start a run (returns immediately, HTTP 202). */
348
+ run(workflowId: string, input?: WorkflowRunInput): Promise<WorkflowRunStart>;
349
+ /** GET /api/v1/workflow-runs/:runId — poll a run. */
350
+ getRun(runId: string): Promise<WorkflowRun>;
351
+ }
352
+ /** Tasks namespace. */
353
+ declare class TasksApi {
354
+ private readonly t;
355
+ constructor(t: Transport);
356
+ /** POST /api/v1/tasks — create (enqueue) a background task. Does NOT trigger execution. */
357
+ create(input: TaskCreateInput): Promise<TaskCreated>;
358
+ /** GET /api/v1/tasks/:taskId — fetch the current snapshot. */
359
+ get(taskId: string, signal?: AbortSignal): Promise<Task>;
360
+ /** Get a handle for polling / waiting on a task (poll(), wait()). */
361
+ handle(taskId: string): TaskHandle;
362
+ }
363
+ /**
364
+ * The public client. Example:
365
+ * const ql = new QLClient({ apiKey: process.env.QL_API_KEY });
366
+ * const agents = await ql.agents.list();
367
+ */
368
+ declare class QLClient {
369
+ readonly workspace: WorkspaceApi;
370
+ readonly agents: AgentsApi;
371
+ readonly workflows: WorkflowsApi;
372
+ readonly tasks: TasksApi;
373
+ private readonly transport;
374
+ private readonly base;
375
+ constructor(opts: QLClientOptions);
376
+ /** The normalized base URL in use (not secret). */
377
+ get baseUrl(): string;
378
+ }
379
+
380
+ interface QLErrorContext {
381
+ method?: string;
382
+ url?: string;
383
+ }
384
+ /**
385
+ * Error thrown by the SDK for any failed API interaction.
386
+ *
387
+ * - `status`: HTTP status code (when the failure came from an HTTP response).
388
+ * - `code`: stable API error code when provided by the backend, otherwise a
389
+ * synthesized one derived from the status, or a synthetic transport
390
+ * code such as "aborted" / "timeout" / "network".
391
+ * - `message`: human-readable description. The API key is never included.
392
+ */
393
+ declare class QLError extends Error {
394
+ readonly status?: number;
395
+ readonly code: string;
396
+ readonly method?: string;
397
+ readonly url?: string;
398
+ /** The raw parsed error body (if any), for advanced inspection. */
399
+ readonly details?: unknown;
400
+ constructor(message: string, opts?: {
401
+ status?: number;
402
+ code: string;
403
+ context?: QLErrorContext;
404
+ details?: unknown;
405
+ });
406
+ /** True for 401/403 or unauthorized/forbidden codes. */
407
+ get isAuthError(): boolean;
408
+ /** True when the request was aborted by the caller. */
409
+ get isAborted(): boolean;
410
+ /** True when a wait() call exceeded its timeout. */
411
+ get isTimeout(): boolean;
412
+ /** True for transient network failures (no HTTP response received). */
413
+ get isNetworkError(): boolean;
414
+ }
415
+
416
+ export { API_ERROR_CODES, type AgentDetail, type AgentListResult, type AgentSummary, AgentsApi, type ApiErrorCode, type CapParamKind, type CapabilitiesResult, type CapabilityInfo, type CapabilityParam, type CapabilityResult, type CapabilityTemplate, type ChatInput, type ChatMessage, type ChatResult, type ChatStreamEvent, DEFAULT_BASE_URL, type HistoryPage, type HistoryParams, type MessageItem, QLClient, type QLClientOptions, QLError, type QLErrorContext, type RunCapabilityInput, type RunCapabilityResult, type StreamOptions, type Task, type TaskCreateInput, type TaskCreated, TaskHandle, type TaskPriority, type TaskStatus, TasksApi, type WaitOptions, type WorkflowRun, type WorkflowRunInput, type WorkflowRunStart, type WorkflowRunStatus, WorkflowsApi, type Workspace, WorkspaceApi, isTerminalTaskStatus };