@langchain/langgraph-sdk 0.0.1-rc.10 → 0.0.1-rc.11
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 +38 -17
- package/dist/client.mjs +94 -29
- package/dist/types.d.mts +13 -0
- package/package.json +1 -1
package/dist/client.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Assistant, AssistantGraph, Config, DefaultValues, GraphSchema, Metadata, Run, RunEvent, Thread, ThreadState } from "./schema.js";
|
|
2
2
|
import { AsyncCaller, AsyncCallerParams } from "./utils/async_caller.mjs";
|
|
3
|
-
import { RunsCreatePayload, RunsStreamPayload, RunsWaitPayload } from "./types.mjs";
|
|
3
|
+
import { RunsCreatePayload, RunsStreamPayload, RunsWaitPayload, StreamEvent } from "./types.mjs";
|
|
4
4
|
interface ClientConfig {
|
|
5
5
|
apiUrl?: string;
|
|
6
6
|
callerOptions?: AsyncCallerParams;
|
|
@@ -63,6 +63,12 @@ declare class AssistantsClient extends BaseClient {
|
|
|
63
63
|
config?: Config;
|
|
64
64
|
metadata?: Metadata;
|
|
65
65
|
}): Promise<Assistant>;
|
|
66
|
+
/**
|
|
67
|
+
* Delete an assistant.
|
|
68
|
+
*
|
|
69
|
+
* @param assistantId ID of the assistant.
|
|
70
|
+
*/
|
|
71
|
+
delete(assistantId: string): Promise<void>;
|
|
66
72
|
/**
|
|
67
73
|
* List assistants.
|
|
68
74
|
* @param query Query options.
|
|
@@ -173,15 +179,12 @@ declare class ThreadsClient extends BaseClient {
|
|
|
173
179
|
}): Promise<ThreadState<ValuesType>[]>;
|
|
174
180
|
}
|
|
175
181
|
declare class RunsClient extends BaseClient {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
* @param assistantId Assistant ID to use for this run.
|
|
181
|
-
* @param payload Payload for creating a run.
|
|
182
|
-
*/
|
|
182
|
+
stream(threadId: null, assistantId: string, payload?: Omit<RunsStreamPayload, "multitaskStrategy">): AsyncGenerator<{
|
|
183
|
+
event: StreamEvent;
|
|
184
|
+
data: any;
|
|
185
|
+
}>;
|
|
183
186
|
stream(threadId: string, assistantId: string, payload?: RunsStreamPayload): AsyncGenerator<{
|
|
184
|
-
event:
|
|
187
|
+
event: StreamEvent;
|
|
185
188
|
data: any;
|
|
186
189
|
}>;
|
|
187
190
|
/**
|
|
@@ -193,14 +196,7 @@ declare class RunsClient extends BaseClient {
|
|
|
193
196
|
* @returns The created run.
|
|
194
197
|
*/
|
|
195
198
|
create(threadId: string, assistantId: string, payload?: RunsCreatePayload): Promise<Run>;
|
|
196
|
-
|
|
197
|
-
* Create a run and wait for it to complete.
|
|
198
|
-
*
|
|
199
|
-
* @param threadId The ID of the thread.
|
|
200
|
-
* @param assistantId Assistant ID to use for this run.
|
|
201
|
-
* @param payload Payload for creating a run.
|
|
202
|
-
* @returns The last values chunk of the thread.
|
|
203
|
-
*/
|
|
199
|
+
wait(threadId: null, assistantId: string, payload?: Omit<RunsWaitPayload, "multitaskStrategy">): Promise<ThreadState["values"]>;
|
|
204
200
|
wait(threadId: string, assistantId: string, payload?: RunsWaitPayload): Promise<ThreadState["values"]>;
|
|
205
201
|
/**
|
|
206
202
|
* List all runs for a thread.
|
|
@@ -229,6 +225,23 @@ declare class RunsClient extends BaseClient {
|
|
|
229
225
|
* @returns The run.
|
|
230
226
|
*/
|
|
231
227
|
get(threadId: string, runId: string): Promise<Run>;
|
|
228
|
+
/**
|
|
229
|
+
* Cancel a run.
|
|
230
|
+
*
|
|
231
|
+
* @param threadId The ID of the thread.
|
|
232
|
+
* @param runId The ID of the run.
|
|
233
|
+
* @param wait Whether to block when canceling
|
|
234
|
+
* @returns
|
|
235
|
+
*/
|
|
236
|
+
cancel(threadId: string, runId: string, wait?: boolean): Promise<void>;
|
|
237
|
+
/**
|
|
238
|
+
* Block until a run is done.
|
|
239
|
+
*
|
|
240
|
+
* @param threadId The ID of the thread.
|
|
241
|
+
* @param runId The ID of the run.
|
|
242
|
+
* @returns
|
|
243
|
+
*/
|
|
244
|
+
join(threadId: string, runId: string): Promise<void>;
|
|
232
245
|
/**
|
|
233
246
|
* List all events for a run.
|
|
234
247
|
*
|
|
@@ -249,6 +262,14 @@ declare class RunsClient extends BaseClient {
|
|
|
249
262
|
*/
|
|
250
263
|
offset?: number;
|
|
251
264
|
}): Promise<RunEvent[]>;
|
|
265
|
+
/**
|
|
266
|
+
* Delete a run.
|
|
267
|
+
*
|
|
268
|
+
* @param threadId The ID of the thread.
|
|
269
|
+
* @param runId The ID of the run.
|
|
270
|
+
* @returns
|
|
271
|
+
*/
|
|
272
|
+
delete(threadId: string, runId: string): Promise<void>;
|
|
252
273
|
}
|
|
253
274
|
export declare class Client {
|
|
254
275
|
/**
|
package/dist/client.mjs
CHANGED
|
@@ -65,6 +65,9 @@ class BaseClient {
|
|
|
65
65
|
}
|
|
66
66
|
async fetch(path, options) {
|
|
67
67
|
const response = await this.asyncCaller.fetch(...this.prepareFetchOptions(path, options));
|
|
68
|
+
if (response.status == 202) {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
68
71
|
return response.json();
|
|
69
72
|
}
|
|
70
73
|
}
|
|
@@ -125,6 +128,16 @@ class AssistantsClient extends BaseClient {
|
|
|
125
128
|
},
|
|
126
129
|
});
|
|
127
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Delete an assistant.
|
|
133
|
+
*
|
|
134
|
+
* @param assistantId ID of the assistant.
|
|
135
|
+
*/
|
|
136
|
+
async delete(assistantId) {
|
|
137
|
+
return this.fetch(`/assistants/${assistantId}`, {
|
|
138
|
+
method: "DELETE",
|
|
139
|
+
});
|
|
140
|
+
}
|
|
128
141
|
/**
|
|
129
142
|
* List assistants.
|
|
130
143
|
* @param query Query options.
|
|
@@ -278,18 +291,23 @@ class RunsClient extends BaseClient {
|
|
|
278
291
|
* @param payload Payload for creating a run.
|
|
279
292
|
*/
|
|
280
293
|
async *stream(threadId, assistantId, payload) {
|
|
281
|
-
const
|
|
294
|
+
const json = {
|
|
295
|
+
input: payload?.input,
|
|
296
|
+
config: payload?.config,
|
|
297
|
+
metadata: payload?.metadata,
|
|
298
|
+
stream_mode: payload?.streamMode,
|
|
299
|
+
feedback_keys: payload?.feedbackKeys,
|
|
300
|
+
assistant_id: assistantId,
|
|
301
|
+
interrupt_before: payload?.interruptBefore,
|
|
302
|
+
interrupt_after: payload?.interruptAfter,
|
|
303
|
+
};
|
|
304
|
+
if (payload?.multitaskStrategy != null) {
|
|
305
|
+
json["multitask_strategy"] = payload?.multitaskStrategy;
|
|
306
|
+
}
|
|
307
|
+
const endpoint = threadId == null ? `/runs/stream` : `/threads/${threadId}/runs/stream`;
|
|
308
|
+
const response = await this.asyncCaller.fetch(...this.prepareFetchOptions(endpoint, {
|
|
282
309
|
method: "POST",
|
|
283
|
-
json
|
|
284
|
-
input: payload?.input,
|
|
285
|
-
config: payload?.config,
|
|
286
|
-
metadata: payload?.metadata,
|
|
287
|
-
stream_mode: payload?.streamMode,
|
|
288
|
-
feedback_keys: payload?.feedbackKeys,
|
|
289
|
-
assistant_id: assistantId,
|
|
290
|
-
interrupt_before: payload?.interruptBefore,
|
|
291
|
-
interrupt_after: payload?.interruptAfter,
|
|
292
|
-
},
|
|
310
|
+
json,
|
|
293
311
|
signal: payload?.signal,
|
|
294
312
|
}));
|
|
295
313
|
let parser;
|
|
@@ -325,17 +343,21 @@ class RunsClient extends BaseClient {
|
|
|
325
343
|
* @returns The created run.
|
|
326
344
|
*/
|
|
327
345
|
async create(threadId, assistantId, payload) {
|
|
346
|
+
const json = {
|
|
347
|
+
input: payload?.input,
|
|
348
|
+
config: payload?.config,
|
|
349
|
+
metadata: payload?.metadata,
|
|
350
|
+
assistant_id: assistantId,
|
|
351
|
+
interrupt_before: payload?.interruptBefore,
|
|
352
|
+
interrupt_after: payload?.interruptAfter,
|
|
353
|
+
webhook: payload?.webhook,
|
|
354
|
+
};
|
|
355
|
+
if (payload?.multitaskStrategy != null) {
|
|
356
|
+
json["multitask_strategy"] = payload?.multitaskStrategy;
|
|
357
|
+
}
|
|
328
358
|
return this.fetch(`/threads/${threadId}/runs`, {
|
|
329
359
|
method: "POST",
|
|
330
|
-
json
|
|
331
|
-
input: payload?.input,
|
|
332
|
-
config: payload?.config,
|
|
333
|
-
metadata: payload?.metadata,
|
|
334
|
-
assistant_id: assistantId,
|
|
335
|
-
interrupt_before: payload?.interruptBefore,
|
|
336
|
-
interrupt_after: payload?.interruptAfter,
|
|
337
|
-
webhook: payload?.webhook,
|
|
338
|
-
},
|
|
360
|
+
json,
|
|
339
361
|
signal: payload?.signal,
|
|
340
362
|
});
|
|
341
363
|
}
|
|
@@ -348,16 +370,21 @@ class RunsClient extends BaseClient {
|
|
|
348
370
|
* @returns The last values chunk of the thread.
|
|
349
371
|
*/
|
|
350
372
|
async wait(threadId, assistantId, payload) {
|
|
351
|
-
|
|
373
|
+
const json = {
|
|
374
|
+
input: payload?.input,
|
|
375
|
+
config: payload?.config,
|
|
376
|
+
metadata: payload?.metadata,
|
|
377
|
+
assistant_id: assistantId,
|
|
378
|
+
interrupt_before: payload?.interruptBefore,
|
|
379
|
+
interrupt_after: payload?.interruptAfter,
|
|
380
|
+
};
|
|
381
|
+
if (payload?.multitaskStrategy != null) {
|
|
382
|
+
json["multitask_strategy"] = payload?.multitaskStrategy;
|
|
383
|
+
}
|
|
384
|
+
const endpoint = threadId == null ? `/runs/wait` : `/threads/${threadId}/runs/wait`;
|
|
385
|
+
return this.fetch(endpoint, {
|
|
352
386
|
method: "POST",
|
|
353
|
-
json
|
|
354
|
-
input: payload?.input,
|
|
355
|
-
config: payload?.config,
|
|
356
|
-
metadata: payload?.metadata,
|
|
357
|
-
assistant_id: assistantId,
|
|
358
|
-
interrupt_before: payload?.interruptBefore,
|
|
359
|
-
interrupt_after: payload?.interruptAfter,
|
|
360
|
-
},
|
|
387
|
+
json,
|
|
361
388
|
signal: payload?.signal,
|
|
362
389
|
});
|
|
363
390
|
}
|
|
@@ -386,6 +413,32 @@ class RunsClient extends BaseClient {
|
|
|
386
413
|
async get(threadId, runId) {
|
|
387
414
|
return this.fetch(`/threads/${threadId}/runs/${runId}`);
|
|
388
415
|
}
|
|
416
|
+
/**
|
|
417
|
+
* Cancel a run.
|
|
418
|
+
*
|
|
419
|
+
* @param threadId The ID of the thread.
|
|
420
|
+
* @param runId The ID of the run.
|
|
421
|
+
* @param wait Whether to block when canceling
|
|
422
|
+
* @returns
|
|
423
|
+
*/
|
|
424
|
+
async cancel(threadId, runId, wait = false) {
|
|
425
|
+
return this.fetch(`/threads/${threadId}/runs/${runId}/cancel`, {
|
|
426
|
+
method: "POST",
|
|
427
|
+
params: {
|
|
428
|
+
wait: wait ? "1" : "0",
|
|
429
|
+
},
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Block until a run is done.
|
|
434
|
+
*
|
|
435
|
+
* @param threadId The ID of the thread.
|
|
436
|
+
* @param runId The ID of the run.
|
|
437
|
+
* @returns
|
|
438
|
+
*/
|
|
439
|
+
async join(threadId, runId) {
|
|
440
|
+
return this.fetch(`/threads/${threadId}/runs/${runId}/join`);
|
|
441
|
+
}
|
|
389
442
|
/**
|
|
390
443
|
* List all events for a run.
|
|
391
444
|
*
|
|
@@ -402,6 +455,18 @@ class RunsClient extends BaseClient {
|
|
|
402
455
|
},
|
|
403
456
|
});
|
|
404
457
|
}
|
|
458
|
+
/**
|
|
459
|
+
* Delete a run.
|
|
460
|
+
*
|
|
461
|
+
* @param threadId The ID of the thread.
|
|
462
|
+
* @param runId The ID of the run.
|
|
463
|
+
* @returns
|
|
464
|
+
*/
|
|
465
|
+
async delete(threadId, runId) {
|
|
466
|
+
return this.fetch(`/threads/${threadId}/runs/${runId}`, {
|
|
467
|
+
method: "DELETE",
|
|
468
|
+
});
|
|
469
|
+
}
|
|
405
470
|
}
|
|
406
471
|
export class Client {
|
|
407
472
|
constructor(config) {
|
package/dist/types.d.mts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Config, Metadata } from "./schema.js";
|
|
2
2
|
export type StreamMode = "values" | "messages" | "updates" | "events" | "debug";
|
|
3
|
+
export type MultitaskStrategy = "reject" | "interrupt" | "rollback" | "enqueue";
|
|
4
|
+
export type StreamEvent = "events" | "metadata" | "debug" | "updates" | "values" | "messages/partial" | "messages/metadata" | "messages/complete" | (string & {});
|
|
3
5
|
interface RunsInvokePayload {
|
|
4
6
|
/**
|
|
5
7
|
* Input to the run. Pass `null` to resume from the current state of the thread.
|
|
@@ -21,6 +23,17 @@ interface RunsInvokePayload {
|
|
|
21
23
|
* Interrupt execution after leaving these nodes.
|
|
22
24
|
*/
|
|
23
25
|
interruptAfter?: string[];
|
|
26
|
+
/**
|
|
27
|
+
* Strategy to handle concurrent runs on the same thread. Only relevant if
|
|
28
|
+
* there is a pending/inflight run on the same thread. One of:
|
|
29
|
+
* - "reject": Reject the new run.
|
|
30
|
+
* - "interrupt": Interrupt the current run, keeping steps completed until now,
|
|
31
|
+
and start a new one.
|
|
32
|
+
* - "rollback": Cancel and delete the existing run, rolling back the thread to
|
|
33
|
+
the state before it had started, then start the new run.
|
|
34
|
+
* - "enqueue": Queue up the new run to start after the current run finishes.
|
|
35
|
+
*/
|
|
36
|
+
multitaskStrategy?: MultitaskStrategy;
|
|
24
37
|
/**
|
|
25
38
|
* Abort controller signal to cancel the run.
|
|
26
39
|
*/
|