@langchain/langgraph-sdk 0.0.8 → 0.0.9
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.d.mts +28 -3
- package/dist/client.mjs +78 -9
- package/dist/types.d.mts +20 -4
- package/dist/utils/async_caller.d.mts +1 -1
- package/package.json +1 -1
package/dist/client.d.mts
CHANGED
|
@@ -85,6 +85,8 @@ export declare class AssistantsClient extends BaseClient {
|
|
|
85
85
|
graphId: string;
|
|
86
86
|
config?: Config;
|
|
87
87
|
metadata?: Metadata;
|
|
88
|
+
assistantId?: string;
|
|
89
|
+
ifExists?: OnConflictBehavior;
|
|
88
90
|
}): Promise<Assistant>;
|
|
89
91
|
/**
|
|
90
92
|
* Update an assistant.
|
|
@@ -93,7 +95,7 @@ export declare class AssistantsClient extends BaseClient {
|
|
|
93
95
|
* @returns The updated assistant.
|
|
94
96
|
*/
|
|
95
97
|
update(assistantId: string, payload: {
|
|
96
|
-
graphId
|
|
98
|
+
graphId?: string;
|
|
97
99
|
config?: Config;
|
|
98
100
|
metadata?: Metadata;
|
|
99
101
|
}): Promise<Assistant>;
|
|
@@ -222,7 +224,7 @@ export declare class ThreadsClient extends BaseClient {
|
|
|
222
224
|
}): Promise<ThreadState<ValuesType>[]>;
|
|
223
225
|
}
|
|
224
226
|
export declare class RunsClient extends BaseClient {
|
|
225
|
-
stream(threadId: null, assistantId: string, payload?: Omit<RunsStreamPayload, "multitaskStrategy">): AsyncGenerator<{
|
|
227
|
+
stream(threadId: null, assistantId: string, payload?: Omit<RunsStreamPayload, "multitaskStrategy" | "onCompletion">): AsyncGenerator<{
|
|
226
228
|
event: StreamEvent;
|
|
227
229
|
data: any;
|
|
228
230
|
}>;
|
|
@@ -239,7 +241,16 @@ export declare class RunsClient extends BaseClient {
|
|
|
239
241
|
* @returns The created run.
|
|
240
242
|
*/
|
|
241
243
|
create(threadId: string, assistantId: string, payload?: RunsCreatePayload): Promise<Run>;
|
|
242
|
-
|
|
244
|
+
/**
|
|
245
|
+
* Create a batch of stateless background runs.
|
|
246
|
+
*
|
|
247
|
+
* @param payloads An array of payloads for creating runs.
|
|
248
|
+
* @returns An array of created runs.
|
|
249
|
+
*/
|
|
250
|
+
createBatch(payloads: (RunsCreatePayload & {
|
|
251
|
+
assistantId: string;
|
|
252
|
+
})[]): Promise<Run[]>;
|
|
253
|
+
wait(threadId: null, assistantId: string, payload?: Omit<RunsWaitPayload, "multitaskStrategy" | "onCompletion">): Promise<ThreadState["values"]>;
|
|
243
254
|
wait(threadId: string, assistantId: string, payload?: RunsWaitPayload): Promise<ThreadState["values"]>;
|
|
244
255
|
/**
|
|
245
256
|
* List all runs for a thread.
|
|
@@ -285,6 +296,20 @@ export declare class RunsClient extends BaseClient {
|
|
|
285
296
|
* @returns
|
|
286
297
|
*/
|
|
287
298
|
join(threadId: string, runId: string): Promise<void>;
|
|
299
|
+
/**
|
|
300
|
+
* Stream output from a run in real-time, until the run is done.
|
|
301
|
+
* Output is not buffered, so any output produced before this call will
|
|
302
|
+
* not be received here.
|
|
303
|
+
*
|
|
304
|
+
* @param threadId The ID of the thread.
|
|
305
|
+
* @param runId The ID of the run.
|
|
306
|
+
* @param signal An optional abort signal.
|
|
307
|
+
* @returns An async generator yielding stream parts.
|
|
308
|
+
*/
|
|
309
|
+
joinStream(threadId: string, runId: string, signal?: AbortSignal): AsyncGenerator<{
|
|
310
|
+
event: StreamEvent;
|
|
311
|
+
data: any;
|
|
312
|
+
}>;
|
|
288
313
|
/**
|
|
289
314
|
* Delete a run.
|
|
290
315
|
*
|
package/dist/client.mjs
CHANGED
|
@@ -92,6 +92,7 @@ export class CronsClient extends BaseClient {
|
|
|
92
92
|
interrupt_before: payload?.interruptBefore,
|
|
93
93
|
interrupt_after: payload?.interruptAfter,
|
|
94
94
|
webhook: payload?.webhook,
|
|
95
|
+
multitask_strategy: payload?.multitaskStrategy,
|
|
95
96
|
};
|
|
96
97
|
return this.fetch(`/threads/${threadId}/runs/crons`, {
|
|
97
98
|
method: "POST",
|
|
@@ -114,6 +115,7 @@ export class CronsClient extends BaseClient {
|
|
|
114
115
|
interrupt_before: payload?.interruptBefore,
|
|
115
116
|
interrupt_after: payload?.interruptAfter,
|
|
116
117
|
webhook: payload?.webhook,
|
|
118
|
+
multitask_strategy: payload?.multitaskStrategy,
|
|
117
119
|
};
|
|
118
120
|
return this.fetch(`/runs/crons`, {
|
|
119
121
|
method: "POST",
|
|
@@ -184,6 +186,8 @@ export class AssistantsClient extends BaseClient {
|
|
|
184
186
|
graph_id: payload.graphId,
|
|
185
187
|
config: payload.config,
|
|
186
188
|
metadata: payload.metadata,
|
|
189
|
+
assistant_id: payload.assistantId,
|
|
190
|
+
if_exists: payload.ifExists,
|
|
187
191
|
},
|
|
188
192
|
});
|
|
189
193
|
}
|
|
@@ -391,10 +395,11 @@ export class RunsClient extends BaseClient {
|
|
|
391
395
|
interrupt_before: payload?.interruptBefore,
|
|
392
396
|
interrupt_after: payload?.interruptAfter,
|
|
393
397
|
checkpoint_id: payload?.checkpointId,
|
|
398
|
+
webhook: payload?.webhook,
|
|
399
|
+
multitask_strategy: payload?.multitaskStrategy,
|
|
400
|
+
on_completion: payload?.onCompletion,
|
|
401
|
+
on_disconnect: payload?.onDisconnect,
|
|
394
402
|
};
|
|
395
|
-
if (payload?.multitaskStrategy != null) {
|
|
396
|
-
json["multitask_strategy"] = payload?.multitaskStrategy;
|
|
397
|
-
}
|
|
398
403
|
const endpoint = threadId == null ? `/runs/stream` : `/threads/${threadId}/runs/stream`;
|
|
399
404
|
const response = await this.asyncCaller.fetch(...this.prepareFetchOptions(endpoint, {
|
|
400
405
|
method: "POST",
|
|
@@ -452,16 +457,31 @@ export class RunsClient extends BaseClient {
|
|
|
452
457
|
interrupt_after: payload?.interruptAfter,
|
|
453
458
|
webhook: payload?.webhook,
|
|
454
459
|
checkpoint_id: payload?.checkpointId,
|
|
460
|
+
multitask_strategy: payload?.multitaskStrategy,
|
|
455
461
|
};
|
|
456
|
-
if (payload?.multitaskStrategy != null) {
|
|
457
|
-
json["multitask_strategy"] = payload?.multitaskStrategy;
|
|
458
|
-
}
|
|
459
462
|
return this.fetch(`/threads/${threadId}/runs`, {
|
|
460
463
|
method: "POST",
|
|
461
464
|
json,
|
|
462
465
|
signal: payload?.signal,
|
|
463
466
|
});
|
|
464
467
|
}
|
|
468
|
+
/**
|
|
469
|
+
* Create a batch of stateless background runs.
|
|
470
|
+
*
|
|
471
|
+
* @param payloads An array of payloads for creating runs.
|
|
472
|
+
* @returns An array of created runs.
|
|
473
|
+
*/
|
|
474
|
+
async createBatch(payloads) {
|
|
475
|
+
const filteredPayloads = payloads
|
|
476
|
+
.map((payload) => ({ ...payload, assistant_id: payload.assistantId }))
|
|
477
|
+
.map((payload) => {
|
|
478
|
+
return Object.fromEntries(Object.entries(payload).filter(([_, v]) => v !== undefined));
|
|
479
|
+
});
|
|
480
|
+
return this.fetch("/runs/batch", {
|
|
481
|
+
method: "POST",
|
|
482
|
+
json: filteredPayloads,
|
|
483
|
+
});
|
|
484
|
+
}
|
|
465
485
|
/**
|
|
466
486
|
* Create a run and wait for it to complete.
|
|
467
487
|
*
|
|
@@ -479,10 +499,11 @@ export class RunsClient extends BaseClient {
|
|
|
479
499
|
interrupt_before: payload?.interruptBefore,
|
|
480
500
|
interrupt_after: payload?.interruptAfter,
|
|
481
501
|
checkpoint_id: payload?.checkpointId,
|
|
502
|
+
webhook: payload?.webhook,
|
|
503
|
+
multitask_strategy: payload?.multitaskStrategy,
|
|
504
|
+
on_completion: payload?.onCompletion,
|
|
505
|
+
on_disconnect: payload?.onDisconnect,
|
|
482
506
|
};
|
|
483
|
-
if (payload?.multitaskStrategy != null) {
|
|
484
|
-
json["multitask_strategy"] = payload?.multitaskStrategy;
|
|
485
|
-
}
|
|
486
507
|
const endpoint = threadId == null ? `/runs/wait` : `/threads/${threadId}/runs/wait`;
|
|
487
508
|
return this.fetch(endpoint, {
|
|
488
509
|
method: "POST",
|
|
@@ -541,6 +562,54 @@ export class RunsClient extends BaseClient {
|
|
|
541
562
|
async join(threadId, runId) {
|
|
542
563
|
return this.fetch(`/threads/${threadId}/runs/${runId}/join`);
|
|
543
564
|
}
|
|
565
|
+
/**
|
|
566
|
+
* Stream output from a run in real-time, until the run is done.
|
|
567
|
+
* Output is not buffered, so any output produced before this call will
|
|
568
|
+
* not be received here.
|
|
569
|
+
*
|
|
570
|
+
* @param threadId The ID of the thread.
|
|
571
|
+
* @param runId The ID of the run.
|
|
572
|
+
* @param signal An optional abort signal.
|
|
573
|
+
* @returns An async generator yielding stream parts.
|
|
574
|
+
*/
|
|
575
|
+
async *joinStream(threadId, runId, signal) {
|
|
576
|
+
const response = await this.asyncCaller.fetch(...this.prepareFetchOptions(`/threads/${threadId}/runs/${runId}/stream`, {
|
|
577
|
+
method: "GET",
|
|
578
|
+
signal,
|
|
579
|
+
}));
|
|
580
|
+
let parser;
|
|
581
|
+
let onEndEvent;
|
|
582
|
+
const textDecoder = new TextDecoder();
|
|
583
|
+
const stream = (response.body || new ReadableStream({ start: (ctrl) => ctrl.close() })).pipeThrough(new TransformStream({
|
|
584
|
+
async start(ctrl) {
|
|
585
|
+
parser = createParser((event) => {
|
|
586
|
+
if ((signal && signal.aborted) ||
|
|
587
|
+
(event.type === "event" && event.data === "[DONE]")) {
|
|
588
|
+
ctrl.terminate();
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
591
|
+
if ("data" in event) {
|
|
592
|
+
ctrl.enqueue({
|
|
593
|
+
event: event.event ?? "message",
|
|
594
|
+
data: JSON.parse(event.data),
|
|
595
|
+
});
|
|
596
|
+
}
|
|
597
|
+
});
|
|
598
|
+
onEndEvent = () => {
|
|
599
|
+
ctrl.enqueue({ event: "end", data: undefined });
|
|
600
|
+
};
|
|
601
|
+
},
|
|
602
|
+
async transform(chunk) {
|
|
603
|
+
const payload = textDecoder.decode(chunk);
|
|
604
|
+
parser.feed(payload);
|
|
605
|
+
// eventsource-parser will ignore events
|
|
606
|
+
// that are not terminated by a newline
|
|
607
|
+
if (payload.trim() === "event: end")
|
|
608
|
+
onEndEvent();
|
|
609
|
+
},
|
|
610
|
+
}));
|
|
611
|
+
yield* IterableReadableStream.fromReadableStream(stream);
|
|
612
|
+
}
|
|
544
613
|
/**
|
|
545
614
|
* Delete a run.
|
|
546
615
|
*
|
package/dist/types.d.mts
CHANGED
|
@@ -2,6 +2,8 @@ import { Config, Metadata } from "./schema.js";
|
|
|
2
2
|
export type StreamMode = "values" | "messages" | "updates" | "events" | "debug";
|
|
3
3
|
export type MultitaskStrategy = "reject" | "interrupt" | "rollback" | "enqueue";
|
|
4
4
|
export type OnConflictBehavior = "raise" | "do_nothing";
|
|
5
|
+
export type OnCompletionBehavior = "complete" | "continue";
|
|
6
|
+
export type DisconnectMode = "cancel" | "continue";
|
|
5
7
|
export type StreamEvent = "events" | "metadata" | "debug" | "updates" | "values" | "messages/partial" | "messages/metadata" | "messages/complete" | (string & {});
|
|
6
8
|
interface RunsInvokePayload {
|
|
7
9
|
/**
|
|
@@ -43,6 +45,24 @@ interface RunsInvokePayload {
|
|
|
43
45
|
* Abort controller signal to cancel the run.
|
|
44
46
|
*/
|
|
45
47
|
signal?: AbortController["signal"];
|
|
48
|
+
/**
|
|
49
|
+
* Behavior to handle run completion. Only relevant if
|
|
50
|
+
* there is a pending/inflight run on the same thread. One of:
|
|
51
|
+
* - "complete": Complete the run.
|
|
52
|
+
* - "continue": Continue the run.
|
|
53
|
+
*/
|
|
54
|
+
onCompletion?: OnCompletionBehavior;
|
|
55
|
+
/**
|
|
56
|
+
* Webhook to call when the run is complete.
|
|
57
|
+
*/
|
|
58
|
+
webhook?: string;
|
|
59
|
+
/**
|
|
60
|
+
* Behavior to handle disconnection. Only relevant if
|
|
61
|
+
* there is a pending/inflight run on the same thread. One of:
|
|
62
|
+
* - "cancel": Cancel the run.
|
|
63
|
+
* - "continue": Continue the run.
|
|
64
|
+
*/
|
|
65
|
+
onDisconnect?: DisconnectMode;
|
|
46
66
|
}
|
|
47
67
|
export interface RunsStreamPayload extends RunsInvokePayload {
|
|
48
68
|
/**
|
|
@@ -62,10 +82,6 @@ export interface RunsStreamPayload extends RunsInvokePayload {
|
|
|
62
82
|
feedbackKeys?: string[];
|
|
63
83
|
}
|
|
64
84
|
export interface RunsCreatePayload extends RunsInvokePayload {
|
|
65
|
-
/**
|
|
66
|
-
* Webhook to call when the run is complete.
|
|
67
|
-
*/
|
|
68
|
-
webhook?: string;
|
|
69
85
|
}
|
|
70
86
|
export interface CronsCreatePayload extends RunsCreatePayload {
|
|
71
87
|
/**
|
|
@@ -16,7 +16,7 @@ export interface AsyncCallerParams {
|
|
|
16
16
|
*
|
|
17
17
|
* By default we expect the `fetch` is available in the global scope.
|
|
18
18
|
*/
|
|
19
|
-
fetch?: typeof fetch;
|
|
19
|
+
fetch?: typeof fetch | ((...args: any[]) => any);
|
|
20
20
|
}
|
|
21
21
|
export interface AsyncCallerCallOptions {
|
|
22
22
|
signal?: AbortSignal;
|