@langchain/langgraph-sdk 0.0.10 → 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 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.
@@ -192,6 +209,7 @@ class AssistantsClient extends BaseClient {
192
209
  metadata: payload.metadata,
193
210
  assistant_id: payload.assistantId,
194
211
  if_exists: payload.ifExists,
212
+ name: payload.name,
195
213
  },
196
214
  });
197
215
  }
@@ -208,6 +226,7 @@ class AssistantsClient extends BaseClient {
208
226
  graph_id: payload.graphId,
209
227
  config: payload.config,
210
228
  metadata: payload.metadata,
229
+ name: payload.name,
211
230
  },
212
231
  });
213
232
  }
@@ -237,6 +256,35 @@ class AssistantsClient extends BaseClient {
237
256
  },
238
257
  });
239
258
  }
259
+ /**
260
+ * List all versions of an assistant.
261
+ *
262
+ * @param assistantId ID of the assistant.
263
+ * @returns List of assistant versions.
264
+ */
265
+ async getVersions(assistantId, payload) {
266
+ return this.fetch(`/assistants/${assistantId}/versions`, {
267
+ method: "POST",
268
+ json: {
269
+ metadata: payload?.metadata ?? undefined,
270
+ limit: payload?.limit ?? 10,
271
+ offset: payload?.offset ?? 0,
272
+ },
273
+ });
274
+ }
275
+ /**
276
+ * Change the version of an assistant.
277
+ *
278
+ * @param assistantId ID of the assistant.
279
+ * @param version The version to change to.
280
+ * @returns The updated assistant.
281
+ */
282
+ async setLatest(assistantId, version) {
283
+ return this.fetch(`/assistants/${assistantId}/latest`, {
284
+ method: "POST",
285
+ json: { version },
286
+ });
287
+ }
240
288
  }
241
289
  exports.AssistantsClient = AssistantsClient;
242
290
  class ThreadsClient extends BaseClient {
@@ -320,10 +368,20 @@ class ThreadsClient extends BaseClient {
320
368
  * @param threadId ID of the thread.
321
369
  * @returns Thread state.
322
370
  */
323
- async getState(threadId, checkpointId) {
324
- return this.fetch(checkpointId != null
325
- ? `/threads/${threadId}/state/${checkpointId}`
326
- : `/threads/${threadId}/state`);
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
+ });
327
385
  }
328
386
  /**
329
387
  * Add state to a thread.
@@ -337,6 +395,7 @@ class ThreadsClient extends BaseClient {
337
395
  json: {
338
396
  values: options.values,
339
397
  checkpoint_id: options.checkpointId,
398
+ checkpoint: options.checkpoint,
340
399
  as_node: options?.asNode,
341
400
  },
342
401
  });
@@ -396,6 +455,7 @@ class RunsClient extends BaseClient {
396
455
  config: payload?.config,
397
456
  metadata: payload?.metadata,
398
457
  stream_mode: payload?.streamMode,
458
+ stream_subgraphs: payload?.streamSubgraphs,
399
459
  feedback_keys: payload?.feedbackKeys,
400
460
  assistant_id: assistantId,
401
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 } 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): Promise<AssistantGraph>;
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.
@@ -87,6 +100,7 @@ export declare class AssistantsClient extends BaseClient {
87
100
  metadata?: Metadata;
88
101
  assistantId?: string;
89
102
  ifExists?: OnConflictBehavior;
103
+ name?: string;
90
104
  }): Promise<Assistant>;
91
105
  /**
92
106
  * Update an assistant.
@@ -98,6 +112,7 @@ export declare class AssistantsClient extends BaseClient {
98
112
  graphId?: string;
99
113
  config?: Config;
100
114
  metadata?: Metadata;
115
+ name?: string;
101
116
  }): Promise<Assistant>;
102
117
  /**
103
118
  * Delete an assistant.
@@ -116,6 +131,25 @@ export declare class AssistantsClient extends BaseClient {
116
131
  limit?: number;
117
132
  offset?: number;
118
133
  }): Promise<Assistant[]>;
134
+ /**
135
+ * List all versions of an assistant.
136
+ *
137
+ * @param assistantId ID of the assistant.
138
+ * @returns List of assistant versions.
139
+ */
140
+ getVersions(assistantId: string, payload?: {
141
+ metadata?: Metadata;
142
+ limit?: number;
143
+ offset?: number;
144
+ }): Promise<AssistantVersion[]>;
145
+ /**
146
+ * Change the version of an assistant.
147
+ *
148
+ * @param assistantId ID of the assistant.
149
+ * @param version The version to change to.
150
+ * @returns The updated assistant.
151
+ */
152
+ setLatest(assistantId: string, version: number): Promise<Assistant>;
119
153
  }
120
154
  export declare class ThreadsClient extends BaseClient {
121
155
  /**
@@ -191,7 +225,9 @@ export declare class ThreadsClient extends BaseClient {
191
225
  * @param threadId ID of the thread.
192
226
  * @returns Thread state.
193
227
  */
194
- getState<ValuesType = DefaultValues>(threadId: string, checkpointId?: string): Promise<ThreadState<ValuesType>>;
228
+ getState<ValuesType = DefaultValues>(threadId: string, checkpoint?: Checkpoint | string, options?: {
229
+ subgraphs?: boolean;
230
+ }): Promise<ThreadState<ValuesType>>;
195
231
  /**
196
232
  * Add state to a thread.
197
233
  *
@@ -200,6 +236,7 @@ export declare class ThreadsClient extends BaseClient {
200
236
  */
201
237
  updateState<ValuesType = DefaultValues>(threadId: string, options: {
202
238
  values: ValuesType;
239
+ checkpoint?: Checkpoint;
203
240
  checkpointId?: string;
204
241
  asNode?: string;
205
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.
@@ -188,6 +205,7 @@ export class AssistantsClient extends BaseClient {
188
205
  metadata: payload.metadata,
189
206
  assistant_id: payload.assistantId,
190
207
  if_exists: payload.ifExists,
208
+ name: payload.name,
191
209
  },
192
210
  });
193
211
  }
@@ -204,6 +222,7 @@ export class AssistantsClient extends BaseClient {
204
222
  graph_id: payload.graphId,
205
223
  config: payload.config,
206
224
  metadata: payload.metadata,
225
+ name: payload.name,
207
226
  },
208
227
  });
209
228
  }
@@ -233,6 +252,35 @@ export class AssistantsClient extends BaseClient {
233
252
  },
234
253
  });
235
254
  }
255
+ /**
256
+ * List all versions of an assistant.
257
+ *
258
+ * @param assistantId ID of the assistant.
259
+ * @returns List of assistant versions.
260
+ */
261
+ async getVersions(assistantId, payload) {
262
+ return this.fetch(`/assistants/${assistantId}/versions`, {
263
+ method: "POST",
264
+ json: {
265
+ metadata: payload?.metadata ?? undefined,
266
+ limit: payload?.limit ?? 10,
267
+ offset: payload?.offset ?? 0,
268
+ },
269
+ });
270
+ }
271
+ /**
272
+ * Change the version of an assistant.
273
+ *
274
+ * @param assistantId ID of the assistant.
275
+ * @param version The version to change to.
276
+ * @returns The updated assistant.
277
+ */
278
+ async setLatest(assistantId, version) {
279
+ return this.fetch(`/assistants/${assistantId}/latest`, {
280
+ method: "POST",
281
+ json: { version },
282
+ });
283
+ }
236
284
  }
237
285
  export class ThreadsClient extends BaseClient {
238
286
  /**
@@ -315,10 +363,20 @@ export class ThreadsClient extends BaseClient {
315
363
  * @param threadId ID of the thread.
316
364
  * @returns Thread state.
317
365
  */
318
- async getState(threadId, checkpointId) {
319
- return this.fetch(checkpointId != null
320
- ? `/threads/${threadId}/state/${checkpointId}`
321
- : `/threads/${threadId}/state`);
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
+ });
322
380
  }
323
381
  /**
324
382
  * Add state to a thread.
@@ -332,6 +390,7 @@ export class ThreadsClient extends BaseClient {
332
390
  json: {
333
391
  values: options.values,
334
392
  checkpoint_id: options.checkpointId,
393
+ checkpoint: options.checkpoint,
335
394
  as_node: options?.asNode,
336
395
  },
337
396
  });
@@ -390,6 +449,7 @@ export class RunsClient extends BaseClient {
390
449
  config: payload?.config,
391
450
  metadata: payload?.metadata,
392
451
  stream_mode: payload?.streamMode,
452
+ stream_subgraphs: payload?.streamSubgraphs,
393
453
  feedback_keys: payload?.feedbackKeys,
394
454
  assistant_id: assistantId,
395
455
  interrupt_before: payload?.interruptBefore,
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export { Client } from "./client.js";
2
- export type { Assistant, AssistantGraph, Config, DefaultValues, GraphSchema, Metadata, Run, Thread, ThreadState, Cron, } from "./schema.js";
2
+ export type { Assistant, AssistantVersion, AssistantGraph, Config, DefaultValues, GraphSchema, Metadata, Run, Thread, ThreadState, Cron, } from "./schema.js";
3
+ export type { OnConflictBehavior } from "./types.js";
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,50 +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
- export interface Assistant {
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;
63
- updated_at: string;
69
+ /** The assistant metadata. */
64
70
  metadata: Metadata;
71
+ /** The version of the assistant. */
72
+ version: number;
73
+ }
74
+ export interface AssistantVersion extends AssistantBase {
75
+ }
76
+ export interface Assistant extends AssistantBase {
77
+ /** The last time the assistant was updated. */
78
+ updated_at: string;
79
+ /** The name of the assistant */
80
+ name: string;
65
81
  }
66
82
  export type AssistantGraph = Record<string, Array<Record<string, unknown>>>;
67
- export interface Thread {
83
+ export interface Thread<ValuesType = DefaultValues> {
84
+ /** The ID of the thread. */
68
85
  thread_id: string;
86
+ /** The time the thread was created. */
69
87
  created_at: string;
88
+ /** The last time the thread was updated. */
70
89
  updated_at: string;
90
+ /** The thread metadata. */
71
91
  metadata: Metadata;
92
+ /** The status of the thread */
72
93
  status: ThreadStatus;
94
+ /** The current state of the thread. */
95
+ values: ValuesType;
73
96
  }
74
97
  export interface Cron {
98
+ /** The ID of the cron */
75
99
  cron_id: string;
100
+ /** The ID of the thread */
76
101
  thread_id: Optional<string>;
102
+ /** The end date to stop running the cron. */
77
103
  end_time: Optional<string>;
104
+ /** The schedule to run, cron format. */
78
105
  schedule: string;
106
+ /** The time the cron was created. */
79
107
  created_at: string;
108
+ /** The last time the cron was updated. */
80
109
  updated_at: string;
110
+ /** The run payload to use for creating new run. */
81
111
  payload: Record<string, unknown>;
82
112
  }
83
113
  export type DefaultValues = Record<string, unknown>[] | Record<string, unknown>;
84
114
  export interface ThreadState<ValuesType = DefaultValues> {
115
+ /** The state values */
85
116
  values: ValuesType;
117
+ /** The next nodes to execute. If empty, the thread is done until new input is received */
86
118
  next: string[];
87
- checkpoint_id: string;
119
+ /** Checkpoint of the thread state */
120
+ checkpoint: Checkpoint;
121
+ /** Metadata for this state */
88
122
  metadata: Metadata;
123
+ /** Time of state creation */
89
124
  created_at: Optional<string>;
90
- parent_checkpoint_id: Optional<string>;
91
- config: Config;
92
- parent_config?: Config;
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>;
93
137
  }
94
138
  export interface Run {
139
+ /** The ID of the run */
95
140
  run_id: string;
141
+ /** The ID of the thread */
96
142
  thread_id: string;
143
+ /** The assistant that wwas used for this run */
97
144
  assistant_id: string;
145
+ /** The time the run was created */
98
146
  created_at: string;
147
+ /** The last time the run was updated */
99
148
  updated_at: string;
149
+ /** The status of the run. */
100
150
  status: RunStatus;
151
+ /** Run metadata */
101
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>>;
102
161
  }
103
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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/langgraph-sdk",
3
- "version": "0.0.10",
3
+ "version": "0.0.13",
4
4
  "description": "Client library for interacting with the LangGraph API",
5
5
  "type": "module",
6
6
  "packageManager": "yarn@1.22.19",