@langchain/langgraph-sdk 0.0.1-rc.10 → 0.0.1-rc.12
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 +34 -33
- package/dist/client.mjs +85 -36
- package/dist/index.d.mts +1 -1
- package/dist/schema.d.ts +0 -11
- package/dist/types.d.mts +13 -0
- package/package.json +1 -1
package/dist/client.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Assistant, AssistantGraph, Config, DefaultValues, GraphSchema, Metadata, Run,
|
|
1
|
+
import { Assistant, AssistantGraph, Config, DefaultValues, GraphSchema, Metadata, Run, 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.
|
|
@@ -230,25 +226,30 @@ declare class RunsClient extends BaseClient {
|
|
|
230
226
|
*/
|
|
231
227
|
get(threadId: string, runId: string): Promise<Run>;
|
|
232
228
|
/**
|
|
233
|
-
*
|
|
229
|
+
* Cancel a run.
|
|
234
230
|
*
|
|
235
231
|
* @param threadId The ID of the thread.
|
|
236
232
|
* @param runId The ID of the run.
|
|
237
|
-
* @param
|
|
238
|
-
* @returns
|
|
233
|
+
* @param wait Whether to block when canceling
|
|
234
|
+
* @returns
|
|
239
235
|
*/
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
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>;
|
|
245
|
+
/**
|
|
246
|
+
* Delete a run.
|
|
247
|
+
*
|
|
248
|
+
* @param threadId The ID of the thread.
|
|
249
|
+
* @param runId The ID of the run.
|
|
250
|
+
* @returns
|
|
251
|
+
*/
|
|
252
|
+
delete(threadId: string, runId: string): Promise<void>;
|
|
252
253
|
}
|
|
253
254
|
export declare class Client {
|
|
254
255
|
/**
|
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 || response.status === 204) {
|
|
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
|
}
|
|
@@ -387,21 +414,43 @@ class RunsClient extends BaseClient {
|
|
|
387
414
|
return this.fetch(`/threads/${threadId}/runs/${runId}`);
|
|
388
415
|
}
|
|
389
416
|
/**
|
|
390
|
-
*
|
|
417
|
+
* Cancel a run.
|
|
391
418
|
*
|
|
392
419
|
* @param threadId The ID of the thread.
|
|
393
420
|
* @param runId The ID of the run.
|
|
394
|
-
* @param
|
|
395
|
-
* @returns
|
|
421
|
+
* @param wait Whether to block when canceling
|
|
422
|
+
* @returns
|
|
396
423
|
*/
|
|
397
|
-
async
|
|
398
|
-
return this.fetch(`/threads/${threadId}/runs/${runId}/
|
|
424
|
+
async cancel(threadId, runId, wait = false) {
|
|
425
|
+
return this.fetch(`/threads/${threadId}/runs/${runId}/cancel`, {
|
|
426
|
+
method: "POST",
|
|
399
427
|
params: {
|
|
400
|
-
|
|
401
|
-
offset: options?.offset ?? 0,
|
|
428
|
+
wait: wait ? "1" : "0",
|
|
402
429
|
},
|
|
403
430
|
});
|
|
404
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
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Delete a run.
|
|
444
|
+
*
|
|
445
|
+
* @param threadId The ID of the thread.
|
|
446
|
+
* @param runId The ID of the run.
|
|
447
|
+
* @returns
|
|
448
|
+
*/
|
|
449
|
+
async delete(threadId, runId) {
|
|
450
|
+
return this.fetch(`/threads/${threadId}/runs/${runId}`, {
|
|
451
|
+
method: "DELETE",
|
|
452
|
+
});
|
|
453
|
+
}
|
|
405
454
|
}
|
|
406
455
|
export class Client {
|
|
407
456
|
constructor(config) {
|
package/dist/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { Client } from "./client.mjs";
|
|
2
|
-
export type { Assistant, AssistantGraph, Config, DefaultValues, GraphSchema, Metadata, Run,
|
|
2
|
+
export type { Assistant, AssistantGraph, Config, DefaultValues, GraphSchema, Metadata, Run, Thread, ThreadState, } from "./schema.js";
|
package/dist/schema.d.ts
CHANGED
|
@@ -74,15 +74,4 @@ export interface Run {
|
|
|
74
74
|
status: "pending" | "running" | "error" | "success" | "timeout" | "interrupted";
|
|
75
75
|
metadata: Metadata;
|
|
76
76
|
}
|
|
77
|
-
export interface RunEvent {
|
|
78
|
-
event_id: string;
|
|
79
|
-
run_id: string;
|
|
80
|
-
received_at: string;
|
|
81
|
-
span_id: string;
|
|
82
|
-
event: string;
|
|
83
|
-
name: string;
|
|
84
|
-
data: Record<string, unknown>;
|
|
85
|
-
metadata: Record<string, unknown>;
|
|
86
|
-
tags: string[];
|
|
87
|
-
}
|
|
88
77
|
export {};
|
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
|
*/
|