@agent-os-sdk/client 0.3.15 → 0.4.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.
- package/dist/client/config.d.ts +49 -0
- package/dist/client/config.d.ts.map +1 -0
- package/dist/client/config.js +62 -0
- package/dist/client/pagination.d.ts +105 -0
- package/dist/client/pagination.d.ts.map +1 -0
- package/dist/client/pagination.js +117 -0
- package/dist/client/raw.d.ts +67 -2
- package/dist/client/raw.d.ts.map +1 -1
- package/dist/client/raw.js +78 -17
- package/dist/client/retry.d.ts +37 -0
- package/dist/client/retry.d.ts.map +1 -0
- package/dist/client/retry.js +108 -0
- package/dist/client/timeout.d.ts +26 -0
- package/dist/client/timeout.d.ts.map +1 -0
- package/dist/client/timeout.js +51 -0
- package/dist/errors/factory.d.ts +20 -0
- package/dist/errors/factory.d.ts.map +1 -0
- package/dist/errors/factory.js +97 -0
- package/dist/errors/index.d.ts +210 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +283 -0
- package/dist/index.d.ts +37 -29
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +48 -22
- package/dist/modules/audit.d.ts +27 -4
- package/dist/modules/audit.d.ts.map +1 -1
- package/dist/modules/audit.js +58 -2
- package/dist/modules/builder.d.ts +6 -0
- package/dist/modules/builder.d.ts.map +1 -1
- package/dist/modules/checkpoints.d.ts +1 -1
- package/dist/modules/checkpoints.d.ts.map +1 -1
- package/dist/modules/info.d.ts +49 -0
- package/dist/modules/info.d.ts.map +1 -1
- package/dist/modules/info.js +66 -0
- package/dist/modules/members.d.ts +50 -2
- package/dist/modules/members.d.ts.map +1 -1
- package/dist/modules/members.js +61 -0
- package/dist/modules/runs.d.ts +103 -0
- package/dist/modules/runs.d.ts.map +1 -1
- package/dist/modules/runs.js +258 -0
- package/dist/modules/tenants.d.ts +4 -1
- package/dist/modules/tenants.d.ts.map +1 -1
- package/dist/modules/tenants.js +3 -0
- package/dist/modules/threads.d.ts +24 -0
- package/dist/modules/threads.d.ts.map +1 -1
- package/dist/modules/threads.js +48 -1
- package/dist/sse/client.d.ts.map +1 -1
- package/dist/sse/client.js +17 -5
- package/package.json +49 -50
- package/src/client/config.ts +100 -0
- package/src/client/pagination.ts +218 -0
- package/src/client/raw.ts +141 -20
- package/src/client/retry.ts +150 -0
- package/src/client/timeout.ts +59 -0
- package/src/errors/factory.ts +135 -0
- package/src/errors/index.ts +365 -0
- package/src/index.ts +97 -76
- package/src/modules/audit.ts +77 -6
- package/src/modules/builder.ts +7 -0
- package/src/modules/checkpoints.ts +1 -1
- package/src/modules/info.ts +108 -0
- package/src/modules/members.ts +80 -2
- package/src/modules/runs.ts +333 -0
- package/src/modules/tenants.ts +5 -2
- package/src/modules/threads.ts +57 -1
- package/src/sse/client.ts +21 -5
package/dist/modules/runs.js
CHANGED
|
@@ -21,11 +21,24 @@ export class RunsModule {
|
|
|
21
21
|
* agent_id: "agent-uuid",
|
|
22
22
|
* input: { message: "Hello" }
|
|
23
23
|
* });
|
|
24
|
+
*
|
|
25
|
+
* // With idempotency (safe to retry)
|
|
26
|
+
* const { data } = await client.runs.create({
|
|
27
|
+
* agent_id: "agent-uuid",
|
|
28
|
+
* input: { message: "Hello" },
|
|
29
|
+
* idempotency_key: "my-unique-key"
|
|
30
|
+
* });
|
|
24
31
|
* ```
|
|
25
32
|
*/
|
|
26
33
|
async create(body) {
|
|
34
|
+
// Send Idempotency-Key in HEADER (enterprise standard) + body (backend compat)
|
|
35
|
+
const headers = {};
|
|
36
|
+
if (body.idempotency_key) {
|
|
37
|
+
headers["Idempotency-Key"] = body.idempotency_key;
|
|
38
|
+
}
|
|
27
39
|
return this.client.POST("/v1/api/runs", {
|
|
28
40
|
body,
|
|
41
|
+
headers,
|
|
29
42
|
});
|
|
30
43
|
}
|
|
31
44
|
/**
|
|
@@ -44,6 +57,49 @@ export class RunsModule {
|
|
|
44
57
|
params: { query: params },
|
|
45
58
|
});
|
|
46
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Iterate through all runs with automatic pagination.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* // Stream all completed runs
|
|
66
|
+
* for await (const run of client.runs.iterate({ status: "completed" })) {
|
|
67
|
+
* console.log(run.run_id, run.status);
|
|
68
|
+
* }
|
|
69
|
+
*
|
|
70
|
+
* // With limit
|
|
71
|
+
* for await (const run of client.runs.iterate({ agent_id: "..." }, { maxItems: 100 })) {
|
|
72
|
+
* processRun(run);
|
|
73
|
+
* }
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
async *iterate(filters, options) {
|
|
77
|
+
const pageSize = options?.pageSize ?? 100;
|
|
78
|
+
const maxItems = options?.maxItems ?? Infinity;
|
|
79
|
+
let offset = 0;
|
|
80
|
+
let yielded = 0;
|
|
81
|
+
let hasMore = true;
|
|
82
|
+
while (hasMore && yielded < maxItems) {
|
|
83
|
+
if (options?.signal?.aborted)
|
|
84
|
+
return;
|
|
85
|
+
const response = await this.list({
|
|
86
|
+
...filters,
|
|
87
|
+
limit: Math.min(pageSize, maxItems - yielded),
|
|
88
|
+
offset,
|
|
89
|
+
});
|
|
90
|
+
if (response.error)
|
|
91
|
+
throw response.error;
|
|
92
|
+
const data = response.data;
|
|
93
|
+
for (const run of data.items) {
|
|
94
|
+
if (yielded >= maxItems)
|
|
95
|
+
return;
|
|
96
|
+
yield run;
|
|
97
|
+
yielded++;
|
|
98
|
+
}
|
|
99
|
+
offset += data.items.length;
|
|
100
|
+
hasMore = offset < data.total && data.items.length > 0;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
47
103
|
// ======================== Execution ========================
|
|
48
104
|
/**
|
|
49
105
|
* Wait for run completion synchronously.
|
|
@@ -239,4 +295,206 @@ export class RunsModule {
|
|
|
239
295
|
});
|
|
240
296
|
yield* parseSSE(response, { onOpen: options?.onOpen });
|
|
241
297
|
}
|
|
298
|
+
// ======================== FOLLOW (Enterprise SSE) ========================
|
|
299
|
+
/**
|
|
300
|
+
* Follow a run's event stream with automatic reconnection and resume.
|
|
301
|
+
*
|
|
302
|
+
* This is the enterprise-grade streaming method that:
|
|
303
|
+
* - Reconnects automatically on connection drops
|
|
304
|
+
* - Resumes from last received event using Last-Event-ID
|
|
305
|
+
* - Never duplicates or loses events
|
|
306
|
+
* - Terminates cleanly on 'close' event
|
|
307
|
+
*
|
|
308
|
+
* @example
|
|
309
|
+
* ```ts
|
|
310
|
+
* for await (const event of client.runs.follow(runId)) {
|
|
311
|
+
* if (event.type === "run_event") {
|
|
312
|
+
* console.log(event.payload);
|
|
313
|
+
* } else if (event.type === "close") {
|
|
314
|
+
* console.log("Run completed");
|
|
315
|
+
* }
|
|
316
|
+
* }
|
|
317
|
+
* ```
|
|
318
|
+
*/
|
|
319
|
+
async *follow(runId, options) {
|
|
320
|
+
const signal = options?.signal;
|
|
321
|
+
const maxReconnects = options?.maxReconnects ?? 10;
|
|
322
|
+
const baseDelayMs = options?.baseDelayMs ?? 1000;
|
|
323
|
+
const maxDelayMs = options?.maxDelayMs ?? 30000;
|
|
324
|
+
// nextSeq = next seq we expect to receive (or 0 at start)
|
|
325
|
+
let nextSeq = options?.startSeq ?? 0;
|
|
326
|
+
let reconnectCount = 0;
|
|
327
|
+
let receivedTerminal = false;
|
|
328
|
+
options?.onConnect?.();
|
|
329
|
+
while (!receivedTerminal && reconnectCount <= maxReconnects) {
|
|
330
|
+
if (signal?.aborted)
|
|
331
|
+
return;
|
|
332
|
+
try {
|
|
333
|
+
// Build headers - Last-Event-ID is the LAST seq we received (nextSeq - 1)
|
|
334
|
+
const headers = {};
|
|
335
|
+
if (nextSeq > 0) {
|
|
336
|
+
headers["Last-Event-ID"] = String(nextSeq - 1);
|
|
337
|
+
}
|
|
338
|
+
const response = await this.client.streamGet("/v1/api/runs/{runId}/stream", {
|
|
339
|
+
params: {
|
|
340
|
+
path: { runId },
|
|
341
|
+
query: nextSeq > 0 ? { seq: nextSeq } : undefined // Also send as query for backends that support it
|
|
342
|
+
},
|
|
343
|
+
headers,
|
|
344
|
+
});
|
|
345
|
+
// Check for auth errors - don't reconnect on these
|
|
346
|
+
if (response.status === 401 || response.status === 403) {
|
|
347
|
+
const errorEvent = {
|
|
348
|
+
type: "error",
|
|
349
|
+
payload: { code: `HTTP_${response.status}`, message: response.statusText },
|
|
350
|
+
seq: -1,
|
|
351
|
+
timestamp: new Date().toISOString(),
|
|
352
|
+
};
|
|
353
|
+
yield errorEvent;
|
|
354
|
+
return; // Don't reconnect on auth errors
|
|
355
|
+
}
|
|
356
|
+
if (!response.ok) {
|
|
357
|
+
throw new Error(`SSE connection failed: ${response.status}`);
|
|
358
|
+
}
|
|
359
|
+
// Reset reconnect count on successful connection
|
|
360
|
+
if (reconnectCount > 0) {
|
|
361
|
+
options?.onReconnect?.(reconnectCount);
|
|
362
|
+
}
|
|
363
|
+
reconnectCount = 0;
|
|
364
|
+
// Parse SSE stream
|
|
365
|
+
for await (const rawEvent of parseSSE(response)) {
|
|
366
|
+
if (signal?.aborted)
|
|
367
|
+
return;
|
|
368
|
+
// Narrow to known event types
|
|
369
|
+
const event = narrowFollowEvent(rawEvent);
|
|
370
|
+
if (!event)
|
|
371
|
+
continue; // Skip unknown event types
|
|
372
|
+
// Update seq tracking if event has seq
|
|
373
|
+
if (typeof event.seq === "number" && event.seq >= 0) {
|
|
374
|
+
nextSeq = event.seq + 1;
|
|
375
|
+
}
|
|
376
|
+
// Check for terminal events
|
|
377
|
+
if (event.type === "close") {
|
|
378
|
+
receivedTerminal = true;
|
|
379
|
+
yield event;
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
if (event.type === "error") {
|
|
383
|
+
// Error event from server - yield but continue (might reconnect)
|
|
384
|
+
yield event;
|
|
385
|
+
// If it's a fatal error, break and try reconnect
|
|
386
|
+
break;
|
|
387
|
+
}
|
|
388
|
+
yield event;
|
|
389
|
+
}
|
|
390
|
+
// Stream ended without close event - this is unexpected EOF
|
|
391
|
+
// Reconnect unless we already received terminal
|
|
392
|
+
if (!receivedTerminal && !signal?.aborted) {
|
|
393
|
+
options?.onDisconnect?.("eof");
|
|
394
|
+
reconnectCount++;
|
|
395
|
+
if (reconnectCount <= maxReconnects) {
|
|
396
|
+
await sleep(calculateBackoff(reconnectCount, baseDelayMs, maxDelayMs));
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
catch (err) {
|
|
401
|
+
if (signal?.aborted)
|
|
402
|
+
return;
|
|
403
|
+
options?.onDisconnect?.("error");
|
|
404
|
+
reconnectCount++;
|
|
405
|
+
if (reconnectCount <= maxReconnects) {
|
|
406
|
+
await sleep(calculateBackoff(reconnectCount, baseDelayMs, maxDelayMs));
|
|
407
|
+
}
|
|
408
|
+
else {
|
|
409
|
+
// Max reconnects exceeded - yield error and stop
|
|
410
|
+
yield {
|
|
411
|
+
type: "error",
|
|
412
|
+
payload: { code: "MAX_RECONNECTS", message: `Max reconnects (${maxReconnects}) exceeded` },
|
|
413
|
+
seq: -1,
|
|
414
|
+
timestamp: new Date().toISOString(),
|
|
415
|
+
};
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Wait for a specific event that matches a predicate.
|
|
423
|
+
*
|
|
424
|
+
* @example
|
|
425
|
+
* ```ts
|
|
426
|
+
* // Wait for run completion
|
|
427
|
+
* const event = await client.runs.waitFor(runId, (e) => e.type === "close", {
|
|
428
|
+
* timeoutMs: 60000
|
|
429
|
+
* });
|
|
430
|
+
*
|
|
431
|
+
* // Wait for specific node execution
|
|
432
|
+
* const nodeEvent = await client.runs.waitFor(runId, (e) =>
|
|
433
|
+
* e.type === "run_event" && e.payload?.node === "my_node"
|
|
434
|
+
* );
|
|
435
|
+
* ```
|
|
436
|
+
*/
|
|
437
|
+
async waitFor(runId, predicate, options) {
|
|
438
|
+
const timeoutMs = options?.timeoutMs ?? 300_000; // 5 min default
|
|
439
|
+
const controller = new AbortController();
|
|
440
|
+
// Combine parent signal with our timeout
|
|
441
|
+
const onAbort = () => controller.abort();
|
|
442
|
+
options?.signal?.addEventListener("abort", onAbort, { once: true });
|
|
443
|
+
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
|
|
444
|
+
try {
|
|
445
|
+
for await (const event of this.follow(runId, {
|
|
446
|
+
signal: controller.signal,
|
|
447
|
+
startSeq: options?.startSeq,
|
|
448
|
+
})) {
|
|
449
|
+
if (predicate(event)) {
|
|
450
|
+
return event;
|
|
451
|
+
}
|
|
452
|
+
// If we got close without matching predicate, error
|
|
453
|
+
if (event.type === "close") {
|
|
454
|
+
throw new Error("Run completed without matching event");
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
// Stream ended without match or terminal
|
|
458
|
+
throw new Error("Stream ended without matching event");
|
|
459
|
+
}
|
|
460
|
+
catch (err) {
|
|
461
|
+
if (controller.signal.aborted && !options?.signal?.aborted) {
|
|
462
|
+
// Our timeout triggered the abort
|
|
463
|
+
const { TimeoutError } = await import("../errors/index.js");
|
|
464
|
+
throw new TimeoutError(timeoutMs);
|
|
465
|
+
}
|
|
466
|
+
throw err;
|
|
467
|
+
}
|
|
468
|
+
finally {
|
|
469
|
+
clearTimeout(timeoutId);
|
|
470
|
+
options?.signal?.removeEventListener("abort", onAbort);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
/** Narrow raw SSE event to FollowEvent */
|
|
475
|
+
function narrowFollowEvent(raw) {
|
|
476
|
+
const eventType = raw.event ?? "message";
|
|
477
|
+
const validTypes = ["run_event", "heartbeat", "close", "error"];
|
|
478
|
+
if (!validTypes.includes(eventType)) {
|
|
479
|
+
return null;
|
|
480
|
+
}
|
|
481
|
+
const data = raw.data;
|
|
482
|
+
return {
|
|
483
|
+
type: eventType,
|
|
484
|
+
seq: typeof data?.seq === "number" ? data.seq : (raw.id ? parseInt(raw.id, 10) : -1),
|
|
485
|
+
timestamp: typeof data?.timestamp === "string" ? data.timestamp : new Date().toISOString(),
|
|
486
|
+
payload: data,
|
|
487
|
+
node: typeof data?.node === "string" ? data.node : undefined,
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
/** Calculate exponential backoff with jitter */
|
|
491
|
+
function calculateBackoff(attempt, baseMs, maxMs) {
|
|
492
|
+
const exponential = baseMs * Math.pow(2, attempt - 1);
|
|
493
|
+
const capped = Math.min(exponential, maxMs);
|
|
494
|
+
const jitter = capped * 0.2 * Math.random();
|
|
495
|
+
return Math.floor(capped + jitter);
|
|
496
|
+
}
|
|
497
|
+
/** Sleep utility */
|
|
498
|
+
function sleep(ms) {
|
|
499
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
242
500
|
}
|
|
@@ -22,7 +22,10 @@ export declare class TenantsModule {
|
|
|
22
22
|
/**
|
|
23
23
|
* List all tenants the user has access to.
|
|
24
24
|
*/
|
|
25
|
-
|
|
25
|
+
/**
|
|
26
|
+
* List all tenants the user has access to.
|
|
27
|
+
*/
|
|
28
|
+
list(): Promise<APIResponse<TenantListResponse>>;
|
|
26
29
|
/**
|
|
27
30
|
* Get the current tenant.
|
|
28
31
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tenants.d.ts","sourceRoot":"","sources":["../../src/modules/tenants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAc,MAAM,kBAAkB,CAAC;AAI3E,MAAM,WAAW,MAAM;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,kBAAkB;IAC/B,KAA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AM,CAAC;KACjB,GAAG,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IAOhC;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAMlE;;OAEG;IACG,cAAc,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;CAMtF"}
|
package/dist/modules/tenants.js
CHANGED
|
@@ -67,12 +67,19 @@ export declare class ThreadsModule {
|
|
|
67
67
|
* @example
|
|
68
68
|
* ```ts
|
|
69
69
|
* const { data: thread } = await client.threads.create();
|
|
70
|
+
*
|
|
71
|
+
* // With idempotency (safe to retry)
|
|
72
|
+
* const { data: thread } = await client.threads.create({
|
|
73
|
+
* idempotency_key: "my-unique-key"
|
|
74
|
+
* });
|
|
70
75
|
* ```
|
|
71
76
|
*/
|
|
72
77
|
create(body?: {
|
|
73
78
|
channel?: string;
|
|
74
79
|
external_conversation_id?: string;
|
|
75
80
|
metadata?: Record<string, unknown>;
|
|
81
|
+
/** Idempotency key for safe retries. When set, duplicate requests with the same key return the original response. */
|
|
82
|
+
idempotency_key?: string;
|
|
76
83
|
}): Promise<APIResponse<Thread>>;
|
|
77
84
|
/**
|
|
78
85
|
* Get a thread by ID.
|
|
@@ -92,6 +99,23 @@ export declare class ThreadsModule {
|
|
|
92
99
|
list(params?: PaginationParams & {
|
|
93
100
|
workspace_id?: string;
|
|
94
101
|
}): Promise<APIResponse<ThreadListResponse>>;
|
|
102
|
+
/**
|
|
103
|
+
* Iterate through all threads with automatic pagination.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts
|
|
107
|
+
* for await (const thread of client.threads.iterate()) {
|
|
108
|
+
* console.log(thread.id);
|
|
109
|
+
* }
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
iterate(filters?: {
|
|
113
|
+
workspace_id?: string;
|
|
114
|
+
}, options?: {
|
|
115
|
+
pageSize?: number;
|
|
116
|
+
maxItems?: number;
|
|
117
|
+
signal?: AbortSignal;
|
|
118
|
+
}): AsyncGenerator<Thread, void, unknown>;
|
|
95
119
|
/**
|
|
96
120
|
* Delete a thread.
|
|
97
121
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"threads.d.ts","sourceRoot":"","sources":["../../src/modules/threads.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAGhF,MAAM,WAAW,MAAM;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,WAAW;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACtC;AAED,MAAM,WAAW,aAAa;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,OAAO,EAAE,CAAC;CAC1B;AAED,MAAM,WAAW,aAAa;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM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AI,UAAU,MAAM,EAAE,SAAS,gBAAgB,kDAAwC;IAE/F;;OAEG;IACG,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE;QACrC,IAAI,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,WAAW,CAAC;QACxC,OAAO,EAAE,MAAM,CAAC;QAChB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACtC,GAAG,OAAO,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;IAUvC;;OAEG;IACG,MAAM,CAAC,IAAI,EAAE;QACf,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,SAAS,CAAC,EAAE,OAAO,CAAC;KACvB,GAAG,gBAAgB,GAAG,OAAO,CAAC,WAAW,CAAC,oBAAoB,CAAC,CAAC;IASjE;;OAEG;IACG,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,YAAY,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IAUhG;;OAEG;IACG,KAAK,CAAC,IAAI,EAAE;QACd,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,OAAO,CAAC,EAAE,OAAO,CAAC;KACrB,GAAG,gBAAgB,GAAG,OAAO,CAAC,WAAW,CAAC,mBAAmB,CAAC,CAAC;CAMnE"}
|
package/dist/modules/threads.js
CHANGED
|
@@ -21,12 +21,22 @@ export class ThreadsModule {
|
|
|
21
21
|
* @example
|
|
22
22
|
* ```ts
|
|
23
23
|
* const { data: thread } = await client.threads.create();
|
|
24
|
+
*
|
|
25
|
+
* // With idempotency (safe to retry)
|
|
26
|
+
* const { data: thread } = await client.threads.create({
|
|
27
|
+
* idempotency_key: "my-unique-key"
|
|
28
|
+
* });
|
|
24
29
|
* ```
|
|
25
30
|
*/
|
|
26
31
|
async create(body) {
|
|
32
|
+
// Send Idempotency-Key in HEADER (enterprise standard) + body (backend compat)
|
|
33
|
+
const headers = { ...this.headers() };
|
|
34
|
+
if (body?.idempotency_key) {
|
|
35
|
+
headers["Idempotency-Key"] = body.idempotency_key;
|
|
36
|
+
}
|
|
27
37
|
return this.client.POST("/v1/api/threads", {
|
|
28
38
|
body: body ?? {},
|
|
29
|
-
headers
|
|
39
|
+
headers,
|
|
30
40
|
});
|
|
31
41
|
}
|
|
32
42
|
/**
|
|
@@ -55,6 +65,43 @@ export class ThreadsModule {
|
|
|
55
65
|
headers: this.headers(),
|
|
56
66
|
});
|
|
57
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Iterate through all threads with automatic pagination.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* for await (const thread of client.threads.iterate()) {
|
|
74
|
+
* console.log(thread.id);
|
|
75
|
+
* }
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
async *iterate(filters, options) {
|
|
79
|
+
const pageSize = options?.pageSize ?? 100;
|
|
80
|
+
const maxItems = options?.maxItems ?? Infinity;
|
|
81
|
+
let offset = 0;
|
|
82
|
+
let yielded = 0;
|
|
83
|
+
let hasMore = true;
|
|
84
|
+
while (hasMore && yielded < maxItems) {
|
|
85
|
+
if (options?.signal?.aborted)
|
|
86
|
+
return;
|
|
87
|
+
const response = await this.list({
|
|
88
|
+
...filters,
|
|
89
|
+
limit: Math.min(pageSize, maxItems - yielded),
|
|
90
|
+
offset,
|
|
91
|
+
});
|
|
92
|
+
if (response.error)
|
|
93
|
+
throw response.error;
|
|
94
|
+
const data = response.data;
|
|
95
|
+
for (const thread of data.items) {
|
|
96
|
+
if (yielded >= maxItems)
|
|
97
|
+
return;
|
|
98
|
+
yield thread;
|
|
99
|
+
yielded++;
|
|
100
|
+
}
|
|
101
|
+
offset += data.items.length;
|
|
102
|
+
hasMore = offset < data.total && data.items.length > 0;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
58
105
|
/**
|
|
59
106
|
* Delete a thread.
|
|
60
107
|
*/
|
package/dist/sse/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/sse/client.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,MAAM,QAAQ,CAAC,CAAC,GAAG,OAAO,IAAI;IAChC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,CAAC,CAAC;IACR,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,MAAM,CAAC,EAAE,WAAW,CAAC;CACxB,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,wBAAuB,QAAQ,CAAC,CAAC,EAC7B,QAAQ,EAAE,QAAQ,EAClB,OAAO,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,IAAI,CAAA;CAAE,GAClC,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/sse/client.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,MAAM,QAAQ,CAAC,CAAC,GAAG,OAAO,IAAI;IAChC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,C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EAAE,OAAO,CAAA;CAAE,GACtC;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC"}
|
package/dist/sse/client.js
CHANGED
|
@@ -31,6 +31,8 @@ export async function* parseSSE(response, options) {
|
|
|
31
31
|
const reader = response.body.getReader();
|
|
32
32
|
const decoder = new TextDecoder();
|
|
33
33
|
let buffer = "";
|
|
34
|
+
// State must be maintained across chunks
|
|
35
|
+
let currentEvent = { event: "message" };
|
|
34
36
|
try {
|
|
35
37
|
while (true) {
|
|
36
38
|
const { done, value } = await reader.read();
|
|
@@ -38,15 +40,29 @@ export async function* parseSSE(response, options) {
|
|
|
38
40
|
break;
|
|
39
41
|
buffer += decoder.decode(value, { stream: true });
|
|
40
42
|
const lines = buffer.split("\n");
|
|
43
|
+
// Keep the last partial line in the buffer
|
|
41
44
|
buffer = lines.pop() ?? "";
|
|
42
|
-
let currentEvent = { event: "message" };
|
|
43
45
|
for (const line of lines) {
|
|
46
|
+
const trimmed = line.trim();
|
|
47
|
+
if (trimmed === "") {
|
|
48
|
+
// Empty line triggers event dispatch if we have data
|
|
49
|
+
if (currentEvent.data !== undefined) {
|
|
50
|
+
yield currentEvent;
|
|
51
|
+
}
|
|
52
|
+
// Reset for next event
|
|
53
|
+
currentEvent = { event: "message" };
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
44
56
|
if (line.startsWith("event:")) {
|
|
45
57
|
currentEvent.event = line.slice(6).trim();
|
|
46
58
|
}
|
|
47
59
|
else if (line.startsWith("data:")) {
|
|
48
60
|
const dataStr = line.slice(5).trim();
|
|
49
61
|
try {
|
|
62
|
+
// Accumulate data if meaningful (though standard SSE usually has one data line per event,
|
|
63
|
+
// multiline data is possible but rare in this specific protocol.
|
|
64
|
+
// For simplicity and matching current backend, we overwrite or concatenation check could be stricter).
|
|
65
|
+
// Given strict JSON protocol, we assume valid info per data line or single data line.
|
|
50
66
|
currentEvent.data = JSON.parse(dataStr);
|
|
51
67
|
}
|
|
52
68
|
catch {
|
|
@@ -59,10 +75,6 @@ export async function* parseSSE(response, options) {
|
|
|
59
75
|
else if (line.startsWith("retry:")) {
|
|
60
76
|
currentEvent.retry = parseInt(line.slice(6).trim(), 10);
|
|
61
77
|
}
|
|
62
|
-
else if (line === "" && currentEvent.data !== undefined) {
|
|
63
|
-
yield currentEvent;
|
|
64
|
-
currentEvent = { event: "message" };
|
|
65
|
-
}
|
|
66
78
|
}
|
|
67
79
|
}
|
|
68
80
|
}
|
package/package.json
CHANGED
|
@@ -1,52 +1,51 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
"
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
"
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
]
|
|
2
|
+
"name": "@agent-os-sdk/client",
|
|
3
|
+
"version": "0.4.1",
|
|
4
|
+
"description": "Official TypeScript SDK for Agent OS platform",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"agent-os",
|
|
17
|
+
"sdk",
|
|
18
|
+
"ai",
|
|
19
|
+
"agents",
|
|
20
|
+
"typescript"
|
|
21
|
+
],
|
|
22
|
+
"author": "Agent OS Team",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "https://github.com/yuri12344/agent-os.git"
|
|
27
|
+
},
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"openapi-fetch": "^0.13.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"openapi-typescript": "^7.4.0",
|
|
36
|
+
"tsx": "^4.19.0",
|
|
37
|
+
"typescript": "^5.5.0",
|
|
38
|
+
"vitest": "^4.0.18"
|
|
39
|
+
},
|
|
40
|
+
"files": [
|
|
41
|
+
"dist",
|
|
42
|
+
"src"
|
|
43
|
+
],
|
|
44
|
+
"scripts": {
|
|
45
|
+
"generate": "tsx scripts/generate.ts",
|
|
46
|
+
"build": "tsc",
|
|
47
|
+
"dev": "tsc --watch",
|
|
48
|
+
"test": "vitest run",
|
|
49
|
+
"typecheck": "tsc --noEmit"
|
|
50
|
+
}
|
|
52
51
|
}
|