@langchain/langgraph-sdk 0.0.11 → 0.0.13
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.cjs +35 -6
- package/dist/client.d.ts +19 -3
- package/dist/client.js +35 -6
- package/dist/schema.d.ts +58 -5
- package/dist/types.d.ts +4 -0
- package/package.json +1 -1
package/dist/client.cjs
CHANGED
|
@@ -167,8 +167,10 @@ class AssistantsClient extends BaseClient {
|
|
|
167
167
|
* @param assistantId The ID of the assistant.
|
|
168
168
|
* @returns Serialized graph
|
|
169
169
|
*/
|
|
170
|
-
async getGraph(assistantId) {
|
|
171
|
-
return this.fetch(`/assistants/${assistantId}/graph
|
|
170
|
+
async getGraph(assistantId, options) {
|
|
171
|
+
return this.fetch(`/assistants/${assistantId}/graph`, {
|
|
172
|
+
params: { xray: options?.xray },
|
|
173
|
+
});
|
|
172
174
|
}
|
|
173
175
|
/**
|
|
174
176
|
* Get the state and config schema of the graph assigned to a runnable
|
|
@@ -178,6 +180,21 @@ class AssistantsClient extends BaseClient {
|
|
|
178
180
|
async getSchemas(assistantId) {
|
|
179
181
|
return this.fetch(`/assistants/${assistantId}/schemas`);
|
|
180
182
|
}
|
|
183
|
+
/**
|
|
184
|
+
* Get the schemas of an assistant by ID.
|
|
185
|
+
*
|
|
186
|
+
* @param assistantId The ID of the assistant to get the schema of.
|
|
187
|
+
* @param options Additional options for getting subgraphs, such as namespace or recursion extraction.
|
|
188
|
+
* @returns The subgraphs of the assistant.
|
|
189
|
+
*/
|
|
190
|
+
async getSubgraphs(assistantId, options) {
|
|
191
|
+
if (options?.namespace) {
|
|
192
|
+
return this.fetch(`/assistants/${assistantId}/subgraphs/${options.namespace}`, { params: { recurse: options?.recurse } });
|
|
193
|
+
}
|
|
194
|
+
return this.fetch(`/assistants/${assistantId}/subgraphs`, {
|
|
195
|
+
params: { recurse: options?.recurse },
|
|
196
|
+
});
|
|
197
|
+
}
|
|
181
198
|
/**
|
|
182
199
|
* Create a new assistant.
|
|
183
200
|
* @param payload Payload for creating an assistant.
|
|
@@ -351,10 +368,20 @@ class ThreadsClient extends BaseClient {
|
|
|
351
368
|
* @param threadId ID of the thread.
|
|
352
369
|
* @returns Thread state.
|
|
353
370
|
*/
|
|
354
|
-
async getState(threadId,
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
371
|
+
async getState(threadId, checkpoint, options) {
|
|
372
|
+
if (checkpoint != null) {
|
|
373
|
+
if (typeof checkpoint !== "string") {
|
|
374
|
+
return this.fetch(`/threads/${threadId}/state/checkpoint`, {
|
|
375
|
+
method: "POST",
|
|
376
|
+
json: { checkpoint, subgraphs: options?.subgraphs },
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
// deprecated
|
|
380
|
+
return this.fetch(`/threads/${threadId}/state/${checkpoint}`, { params: { subgraphs: options?.subgraphs } });
|
|
381
|
+
}
|
|
382
|
+
return this.fetch(`/threads/${threadId}/state`, {
|
|
383
|
+
params: { subgraphs: options?.subgraphs },
|
|
384
|
+
});
|
|
358
385
|
}
|
|
359
386
|
/**
|
|
360
387
|
* Add state to a thread.
|
|
@@ -368,6 +395,7 @@ class ThreadsClient extends BaseClient {
|
|
|
368
395
|
json: {
|
|
369
396
|
values: options.values,
|
|
370
397
|
checkpoint_id: options.checkpointId,
|
|
398
|
+
checkpoint: options.checkpoint,
|
|
371
399
|
as_node: options?.asNode,
|
|
372
400
|
},
|
|
373
401
|
});
|
|
@@ -427,6 +455,7 @@ class RunsClient extends BaseClient {
|
|
|
427
455
|
config: payload?.config,
|
|
428
456
|
metadata: payload?.metadata,
|
|
429
457
|
stream_mode: payload?.streamMode,
|
|
458
|
+
stream_subgraphs: payload?.streamSubgraphs,
|
|
430
459
|
feedback_keys: payload?.feedbackKeys,
|
|
431
460
|
assistant_id: assistantId,
|
|
432
461
|
interrupt_before: payload?.interruptBefore,
|
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Assistant, AssistantGraph, Config, DefaultValues, GraphSchema, Metadata, Run, Thread, ThreadState, Cron, AssistantVersion } from "./schema.js";
|
|
1
|
+
import { Assistant, AssistantGraph, Config, DefaultValues, GraphSchema, Metadata, Run, Thread, ThreadState, Cron, AssistantVersion, Subgraphs, Checkpoint } from "./schema.js";
|
|
2
2
|
import { AsyncCaller, AsyncCallerParams } from "./utils/async_caller.js";
|
|
3
3
|
import { RunsCreatePayload, RunsStreamPayload, RunsWaitPayload, StreamEvent, CronsCreatePayload, OnConflictBehavior } from "./types.js";
|
|
4
4
|
interface ClientConfig {
|
|
@@ -69,13 +69,26 @@ export declare class AssistantsClient extends BaseClient {
|
|
|
69
69
|
* @param assistantId The ID of the assistant.
|
|
70
70
|
* @returns Serialized graph
|
|
71
71
|
*/
|
|
72
|
-
getGraph(assistantId: string
|
|
72
|
+
getGraph(assistantId: string, options?: {
|
|
73
|
+
xray?: boolean;
|
|
74
|
+
}): Promise<AssistantGraph>;
|
|
73
75
|
/**
|
|
74
76
|
* Get the state and config schema of the graph assigned to a runnable
|
|
75
77
|
* @param assistantId The ID of the assistant.
|
|
76
78
|
* @returns Graph schema
|
|
77
79
|
*/
|
|
78
80
|
getSchemas(assistantId: string): Promise<GraphSchema>;
|
|
81
|
+
/**
|
|
82
|
+
* Get the schemas of an assistant by ID.
|
|
83
|
+
*
|
|
84
|
+
* @param assistantId The ID of the assistant to get the schema of.
|
|
85
|
+
* @param options Additional options for getting subgraphs, such as namespace or recursion extraction.
|
|
86
|
+
* @returns The subgraphs of the assistant.
|
|
87
|
+
*/
|
|
88
|
+
getSubgraphs(assistantId: string, options?: {
|
|
89
|
+
namespace?: string;
|
|
90
|
+
recurse?: boolean;
|
|
91
|
+
}): Promise<Subgraphs>;
|
|
79
92
|
/**
|
|
80
93
|
* Create a new assistant.
|
|
81
94
|
* @param payload Payload for creating an assistant.
|
|
@@ -212,7 +225,9 @@ export declare class ThreadsClient extends BaseClient {
|
|
|
212
225
|
* @param threadId ID of the thread.
|
|
213
226
|
* @returns Thread state.
|
|
214
227
|
*/
|
|
215
|
-
getState<ValuesType = DefaultValues>(threadId: string,
|
|
228
|
+
getState<ValuesType = DefaultValues>(threadId: string, checkpoint?: Checkpoint | string, options?: {
|
|
229
|
+
subgraphs?: boolean;
|
|
230
|
+
}): Promise<ThreadState<ValuesType>>;
|
|
216
231
|
/**
|
|
217
232
|
* Add state to a thread.
|
|
218
233
|
*
|
|
@@ -221,6 +236,7 @@ export declare class ThreadsClient extends BaseClient {
|
|
|
221
236
|
*/
|
|
222
237
|
updateState<ValuesType = DefaultValues>(threadId: string, options: {
|
|
223
238
|
values: ValuesType;
|
|
239
|
+
checkpoint?: Checkpoint;
|
|
224
240
|
checkpointId?: string;
|
|
225
241
|
asNode?: string;
|
|
226
242
|
}): Promise<Pick<Config, "configurable">>;
|
package/dist/client.js
CHANGED
|
@@ -163,8 +163,10 @@ export class AssistantsClient extends BaseClient {
|
|
|
163
163
|
* @param assistantId The ID of the assistant.
|
|
164
164
|
* @returns Serialized graph
|
|
165
165
|
*/
|
|
166
|
-
async getGraph(assistantId) {
|
|
167
|
-
return this.fetch(`/assistants/${assistantId}/graph
|
|
166
|
+
async getGraph(assistantId, options) {
|
|
167
|
+
return this.fetch(`/assistants/${assistantId}/graph`, {
|
|
168
|
+
params: { xray: options?.xray },
|
|
169
|
+
});
|
|
168
170
|
}
|
|
169
171
|
/**
|
|
170
172
|
* Get the state and config schema of the graph assigned to a runnable
|
|
@@ -174,6 +176,21 @@ export class AssistantsClient extends BaseClient {
|
|
|
174
176
|
async getSchemas(assistantId) {
|
|
175
177
|
return this.fetch(`/assistants/${assistantId}/schemas`);
|
|
176
178
|
}
|
|
179
|
+
/**
|
|
180
|
+
* Get the schemas of an assistant by ID.
|
|
181
|
+
*
|
|
182
|
+
* @param assistantId The ID of the assistant to get the schema of.
|
|
183
|
+
* @param options Additional options for getting subgraphs, such as namespace or recursion extraction.
|
|
184
|
+
* @returns The subgraphs of the assistant.
|
|
185
|
+
*/
|
|
186
|
+
async getSubgraphs(assistantId, options) {
|
|
187
|
+
if (options?.namespace) {
|
|
188
|
+
return this.fetch(`/assistants/${assistantId}/subgraphs/${options.namespace}`, { params: { recurse: options?.recurse } });
|
|
189
|
+
}
|
|
190
|
+
return this.fetch(`/assistants/${assistantId}/subgraphs`, {
|
|
191
|
+
params: { recurse: options?.recurse },
|
|
192
|
+
});
|
|
193
|
+
}
|
|
177
194
|
/**
|
|
178
195
|
* Create a new assistant.
|
|
179
196
|
* @param payload Payload for creating an assistant.
|
|
@@ -346,10 +363,20 @@ export class ThreadsClient extends BaseClient {
|
|
|
346
363
|
* @param threadId ID of the thread.
|
|
347
364
|
* @returns Thread state.
|
|
348
365
|
*/
|
|
349
|
-
async getState(threadId,
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
366
|
+
async getState(threadId, checkpoint, options) {
|
|
367
|
+
if (checkpoint != null) {
|
|
368
|
+
if (typeof checkpoint !== "string") {
|
|
369
|
+
return this.fetch(`/threads/${threadId}/state/checkpoint`, {
|
|
370
|
+
method: "POST",
|
|
371
|
+
json: { checkpoint, subgraphs: options?.subgraphs },
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
// deprecated
|
|
375
|
+
return this.fetch(`/threads/${threadId}/state/${checkpoint}`, { params: { subgraphs: options?.subgraphs } });
|
|
376
|
+
}
|
|
377
|
+
return this.fetch(`/threads/${threadId}/state`, {
|
|
378
|
+
params: { subgraphs: options?.subgraphs },
|
|
379
|
+
});
|
|
353
380
|
}
|
|
354
381
|
/**
|
|
355
382
|
* Add state to a thread.
|
|
@@ -363,6 +390,7 @@ export class ThreadsClient extends BaseClient {
|
|
|
363
390
|
json: {
|
|
364
391
|
values: options.values,
|
|
365
392
|
checkpoint_id: options.checkpointId,
|
|
393
|
+
checkpoint: options.checkpoint,
|
|
366
394
|
as_node: options?.asNode,
|
|
367
395
|
},
|
|
368
396
|
});
|
|
@@ -421,6 +449,7 @@ export class RunsClient extends BaseClient {
|
|
|
421
449
|
config: payload?.config,
|
|
422
450
|
metadata: payload?.metadata,
|
|
423
451
|
stream_mode: payload?.streamMode,
|
|
452
|
+
stream_subgraphs: payload?.streamSubgraphs,
|
|
424
453
|
feedback_keys: payload?.feedbackKeys,
|
|
425
454
|
assistant_id: assistantId,
|
|
426
455
|
interrupt_before: payload?.interruptBefore,
|
package/dist/schema.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { JSONSchema7 } from "json-schema";
|
|
|
2
2
|
type Optional<T> = T | null | undefined;
|
|
3
3
|
type RunStatus = "pending" | "running" | "error" | "success" | "timeout" | "interrupted";
|
|
4
4
|
type ThreadStatus = "idle" | "busy" | "interrupted";
|
|
5
|
+
type MultitaskStrategy = "reject" | "interrupt" | "rollback" | "enqueue";
|
|
5
6
|
export interface Config {
|
|
6
7
|
/**
|
|
7
8
|
* Tags for this call and any sub-calls (eg. a Chain calling an LLM).
|
|
@@ -54,56 +55,108 @@ export interface GraphSchema {
|
|
|
54
55
|
*/
|
|
55
56
|
config_schema?: JSONSchema7;
|
|
56
57
|
}
|
|
58
|
+
export type Subgraphs = Record<string, GraphSchema>;
|
|
57
59
|
export type Metadata = Optional<Record<string, unknown>>;
|
|
58
60
|
export interface AssistantBase {
|
|
61
|
+
/** The ID of the assistant. */
|
|
59
62
|
assistant_id: string;
|
|
63
|
+
/** The ID of the graph. */
|
|
60
64
|
graph_id: string;
|
|
65
|
+
/** The assistant config. */
|
|
61
66
|
config: Config;
|
|
67
|
+
/** The time the assistant was created. */
|
|
62
68
|
created_at: string;
|
|
69
|
+
/** The assistant metadata. */
|
|
63
70
|
metadata: Metadata;
|
|
71
|
+
/** The version of the assistant. */
|
|
64
72
|
version: number;
|
|
65
73
|
}
|
|
66
74
|
export interface AssistantVersion extends AssistantBase {
|
|
67
75
|
}
|
|
68
76
|
export interface Assistant extends AssistantBase {
|
|
77
|
+
/** The last time the assistant was updated. */
|
|
69
78
|
updated_at: string;
|
|
79
|
+
/** The name of the assistant */
|
|
70
80
|
name: string;
|
|
71
81
|
}
|
|
72
82
|
export type AssistantGraph = Record<string, Array<Record<string, unknown>>>;
|
|
73
|
-
export interface Thread {
|
|
83
|
+
export interface Thread<ValuesType = DefaultValues> {
|
|
84
|
+
/** The ID of the thread. */
|
|
74
85
|
thread_id: string;
|
|
86
|
+
/** The time the thread was created. */
|
|
75
87
|
created_at: string;
|
|
88
|
+
/** The last time the thread was updated. */
|
|
76
89
|
updated_at: string;
|
|
90
|
+
/** The thread metadata. */
|
|
77
91
|
metadata: Metadata;
|
|
92
|
+
/** The status of the thread */
|
|
78
93
|
status: ThreadStatus;
|
|
94
|
+
/** The current state of the thread. */
|
|
95
|
+
values: ValuesType;
|
|
79
96
|
}
|
|
80
97
|
export interface Cron {
|
|
98
|
+
/** The ID of the cron */
|
|
81
99
|
cron_id: string;
|
|
100
|
+
/** The ID of the thread */
|
|
82
101
|
thread_id: Optional<string>;
|
|
102
|
+
/** The end date to stop running the cron. */
|
|
83
103
|
end_time: Optional<string>;
|
|
104
|
+
/** The schedule to run, cron format. */
|
|
84
105
|
schedule: string;
|
|
106
|
+
/** The time the cron was created. */
|
|
85
107
|
created_at: string;
|
|
108
|
+
/** The last time the cron was updated. */
|
|
86
109
|
updated_at: string;
|
|
110
|
+
/** The run payload to use for creating new run. */
|
|
87
111
|
payload: Record<string, unknown>;
|
|
88
112
|
}
|
|
89
113
|
export type DefaultValues = Record<string, unknown>[] | Record<string, unknown>;
|
|
90
114
|
export interface ThreadState<ValuesType = DefaultValues> {
|
|
115
|
+
/** The state values */
|
|
91
116
|
values: ValuesType;
|
|
117
|
+
/** The next nodes to execute. If empty, the thread is done until new input is received */
|
|
92
118
|
next: string[];
|
|
93
|
-
|
|
119
|
+
/** Checkpoint of the thread state */
|
|
120
|
+
checkpoint: Checkpoint;
|
|
121
|
+
/** Metadata for this state */
|
|
94
122
|
metadata: Metadata;
|
|
123
|
+
/** Time of state creation */
|
|
95
124
|
created_at: Optional<string>;
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
125
|
+
/** The parent checkpoint. If missing, this is the root checkpoint */
|
|
126
|
+
parent_checkpoint: Optional<Checkpoint>;
|
|
127
|
+
/** Tasks to execute in this step. If already attempted, may contain an error */
|
|
128
|
+
tasks: Array<ThreadTask>;
|
|
129
|
+
}
|
|
130
|
+
export interface ThreadTask {
|
|
131
|
+
id: string;
|
|
132
|
+
name: string;
|
|
133
|
+
error: Optional<string>;
|
|
134
|
+
interrupts: Array<Record<string, unknown>>;
|
|
135
|
+
checkpoint: Optional<Checkpoint>;
|
|
136
|
+
state: Optional<ThreadState>;
|
|
99
137
|
}
|
|
100
138
|
export interface Run {
|
|
139
|
+
/** The ID of the run */
|
|
101
140
|
run_id: string;
|
|
141
|
+
/** The ID of the thread */
|
|
102
142
|
thread_id: string;
|
|
143
|
+
/** The assistant that wwas used for this run */
|
|
103
144
|
assistant_id: string;
|
|
145
|
+
/** The time the run was created */
|
|
104
146
|
created_at: string;
|
|
147
|
+
/** The last time the run was updated */
|
|
105
148
|
updated_at: string;
|
|
149
|
+
/** The status of the run. */
|
|
106
150
|
status: RunStatus;
|
|
151
|
+
/** Run metadata */
|
|
107
152
|
metadata: Metadata;
|
|
153
|
+
/** Strategy to handle concurrent runs on the same thread */
|
|
154
|
+
multitask_strategy: Optional<MultitaskStrategy>;
|
|
155
|
+
}
|
|
156
|
+
export interface Checkpoint {
|
|
157
|
+
thread_id: string;
|
|
158
|
+
checkpoint_ns: string;
|
|
159
|
+
checkpoint_id: Optional<string>;
|
|
160
|
+
checkpoint_map: Optional<Record<string, unknown>>;
|
|
108
161
|
}
|
|
109
162
|
export {};
|
package/dist/types.d.ts
CHANGED
|
@@ -75,6 +75,10 @@ export interface RunsStreamPayload extends RunsInvokePayload {
|
|
|
75
75
|
* afterwards using the `client.runs.listEvents()` method.
|
|
76
76
|
*/
|
|
77
77
|
streamMode?: StreamMode | Array<StreamMode>;
|
|
78
|
+
/**
|
|
79
|
+
* Stream output from subgraphs. By default, streams only the top graph.
|
|
80
|
+
*/
|
|
81
|
+
streamSubgraphs?: boolean;
|
|
78
82
|
/**
|
|
79
83
|
* Pass one or more feedbackKeys if you want to request short-lived signed URLs
|
|
80
84
|
* for submitting feedback to LangSmith with this key for this run.
|