@langchain/langgraph-sdk 0.0.7 → 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 +81 -9
- package/dist/types.d.mts +24 -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
|
}
|
|
@@ -390,10 +394,12 @@ export class RunsClient extends BaseClient {
|
|
|
390
394
|
assistant_id: assistantId,
|
|
391
395
|
interrupt_before: payload?.interruptBefore,
|
|
392
396
|
interrupt_after: payload?.interruptAfter,
|
|
397
|
+
checkpoint_id: payload?.checkpointId,
|
|
398
|
+
webhook: payload?.webhook,
|
|
399
|
+
multitask_strategy: payload?.multitaskStrategy,
|
|
400
|
+
on_completion: payload?.onCompletion,
|
|
401
|
+
on_disconnect: payload?.onDisconnect,
|
|
393
402
|
};
|
|
394
|
-
if (payload?.multitaskStrategy != null) {
|
|
395
|
-
json["multitask_strategy"] = payload?.multitaskStrategy;
|
|
396
|
-
}
|
|
397
403
|
const endpoint = threadId == null ? `/runs/stream` : `/threads/${threadId}/runs/stream`;
|
|
398
404
|
const response = await this.asyncCaller.fetch(...this.prepareFetchOptions(endpoint, {
|
|
399
405
|
method: "POST",
|
|
@@ -450,16 +456,32 @@ export class RunsClient extends BaseClient {
|
|
|
450
456
|
interrupt_before: payload?.interruptBefore,
|
|
451
457
|
interrupt_after: payload?.interruptAfter,
|
|
452
458
|
webhook: payload?.webhook,
|
|
459
|
+
checkpoint_id: payload?.checkpointId,
|
|
460
|
+
multitask_strategy: payload?.multitaskStrategy,
|
|
453
461
|
};
|
|
454
|
-
if (payload?.multitaskStrategy != null) {
|
|
455
|
-
json["multitask_strategy"] = payload?.multitaskStrategy;
|
|
456
|
-
}
|
|
457
462
|
return this.fetch(`/threads/${threadId}/runs`, {
|
|
458
463
|
method: "POST",
|
|
459
464
|
json,
|
|
460
465
|
signal: payload?.signal,
|
|
461
466
|
});
|
|
462
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
|
+
}
|
|
463
485
|
/**
|
|
464
486
|
* Create a run and wait for it to complete.
|
|
465
487
|
*
|
|
@@ -476,10 +498,12 @@ export class RunsClient extends BaseClient {
|
|
|
476
498
|
assistant_id: assistantId,
|
|
477
499
|
interrupt_before: payload?.interruptBefore,
|
|
478
500
|
interrupt_after: payload?.interruptAfter,
|
|
501
|
+
checkpoint_id: payload?.checkpointId,
|
|
502
|
+
webhook: payload?.webhook,
|
|
503
|
+
multitask_strategy: payload?.multitaskStrategy,
|
|
504
|
+
on_completion: payload?.onCompletion,
|
|
505
|
+
on_disconnect: payload?.onDisconnect,
|
|
479
506
|
};
|
|
480
|
-
if (payload?.multitaskStrategy != null) {
|
|
481
|
-
json["multitask_strategy"] = payload?.multitaskStrategy;
|
|
482
|
-
}
|
|
483
507
|
const endpoint = threadId == null ? `/runs/wait` : `/threads/${threadId}/runs/wait`;
|
|
484
508
|
return this.fetch(endpoint, {
|
|
485
509
|
method: "POST",
|
|
@@ -538,6 +562,54 @@ export class RunsClient extends BaseClient {
|
|
|
538
562
|
async join(threadId, runId) {
|
|
539
563
|
return this.fetch(`/threads/${threadId}/runs/${runId}/join`);
|
|
540
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
|
+
}
|
|
541
613
|
/**
|
|
542
614
|
* Delete a run.
|
|
543
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
|
/**
|
|
@@ -16,6 +18,10 @@ interface RunsInvokePayload {
|
|
|
16
18
|
* Additional configuration for the run.
|
|
17
19
|
*/
|
|
18
20
|
config?: Config;
|
|
21
|
+
/**
|
|
22
|
+
* Checkpoint ID for when creating a new run.
|
|
23
|
+
*/
|
|
24
|
+
checkpointId?: string;
|
|
19
25
|
/**
|
|
20
26
|
* Interrupt execution before entering these nodes.
|
|
21
27
|
*/
|
|
@@ -39,6 +45,24 @@ interface RunsInvokePayload {
|
|
|
39
45
|
* Abort controller signal to cancel the run.
|
|
40
46
|
*/
|
|
41
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;
|
|
42
66
|
}
|
|
43
67
|
export interface RunsStreamPayload extends RunsInvokePayload {
|
|
44
68
|
/**
|
|
@@ -58,10 +82,6 @@ export interface RunsStreamPayload extends RunsInvokePayload {
|
|
|
58
82
|
feedbackKeys?: string[];
|
|
59
83
|
}
|
|
60
84
|
export interface RunsCreatePayload extends RunsInvokePayload {
|
|
61
|
-
/**
|
|
62
|
-
* Webhook to call when the run is complete.
|
|
63
|
-
*/
|
|
64
|
-
webhook?: string;
|
|
65
85
|
}
|
|
66
86
|
export interface CronsCreatePayload extends RunsCreatePayload {
|
|
67
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;
|