@langchain/langgraph-sdk 0.0.84 → 0.0.85

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
@@ -6,6 +6,61 @@ const env_js_1 = require("./utils/env.cjs");
6
6
  const signals_js_1 = require("./utils/signals.cjs");
7
7
  const sse_js_1 = require("./utils/sse.cjs");
8
8
  const stream_js_1 = require("./utils/stream.cjs");
9
+ function* iterateHeaders(headers) {
10
+ let iter;
11
+ let shouldClear = false;
12
+ if (headers instanceof Headers) {
13
+ const entries = [];
14
+ headers.forEach((value, name) => {
15
+ entries.push([name, value]);
16
+ });
17
+ iter = entries;
18
+ }
19
+ else if (Array.isArray(headers)) {
20
+ iter = headers;
21
+ }
22
+ else {
23
+ shouldClear = true;
24
+ iter = Object.entries(headers ?? {});
25
+ }
26
+ for (let item of iter) {
27
+ const name = item[0];
28
+ if (typeof name !== "string")
29
+ throw new TypeError(`Expected header name to be a string, got ${typeof name}`);
30
+ const values = Array.isArray(item[1]) ? item[1] : [item[1]];
31
+ let didClear = false;
32
+ for (const value of values) {
33
+ if (value === undefined)
34
+ continue;
35
+ // New object keys should always overwrite older headers
36
+ // Yield a null to clear the header in the headers object
37
+ // before adding the new value
38
+ if (shouldClear && !didClear) {
39
+ didClear = true;
40
+ yield [name, null];
41
+ }
42
+ yield [name, value];
43
+ }
44
+ }
45
+ }
46
+ function mergeHeaders(...headerObjects) {
47
+ const outputHeaders = new Headers();
48
+ for (const headers of headerObjects) {
49
+ if (!headers)
50
+ continue;
51
+ for (const [name, value] of iterateHeaders(headers)) {
52
+ if (value === null)
53
+ outputHeaders.delete(name);
54
+ else
55
+ outputHeaders.append(name, value);
56
+ }
57
+ }
58
+ const headerEntries = [];
59
+ outputHeaders.forEach((value, name) => {
60
+ headerEntries.push([name, value]);
61
+ });
62
+ return Object.fromEntries(headerEntries);
63
+ }
9
64
  /**
10
65
  * Get the API key from the environment.
11
66
  * Precedence:
@@ -104,20 +159,19 @@ class BaseClient {
104
159
  this.onRequest = config?.onRequest;
105
160
  const apiKey = getApiKey(config?.apiKey);
106
161
  if (apiKey) {
107
- this.defaultHeaders["X-Api-Key"] = apiKey;
162
+ this.defaultHeaders["x-api-key"] = apiKey;
108
163
  }
109
164
  }
110
165
  prepareFetchOptions(path, options) {
111
166
  const mutatedOptions = {
112
167
  ...options,
113
- headers: { ...this.defaultHeaders, ...options?.headers },
168
+ headers: mergeHeaders(this.defaultHeaders, options?.headers),
114
169
  };
115
170
  if (mutatedOptions.json) {
116
171
  mutatedOptions.body = JSON.stringify(mutatedOptions.json);
117
- mutatedOptions.headers = {
118
- ...mutatedOptions.headers,
119
- "Content-Type": "application/json",
120
- };
172
+ mutatedOptions.headers = mergeHeaders(mutatedOptions.headers, {
173
+ "content-type": "application/json",
174
+ });
121
175
  delete mutatedOptions.json;
122
176
  }
123
177
  if (mutatedOptions.withResponse) {
@@ -240,6 +294,8 @@ class CronsClient extends BaseClient {
240
294
  thread_id: query?.threadId ?? undefined,
241
295
  limit: query?.limit ?? 10,
242
296
  offset: query?.offset ?? 0,
297
+ sort_by: query?.sortBy ?? undefined,
298
+ sort_order: query?.sortOrder ?? undefined,
243
299
  },
244
300
  });
245
301
  }
package/dist/client.d.ts CHANGED
@@ -1,7 +1,8 @@
1
- import { Assistant, AssistantGraph, AssistantSortBy, AssistantVersion, CancelAction, Checkpoint, Config, Cron, CronCreateForThreadResponse, CronCreateResponse, DefaultValues, GraphSchema, Item, ListNamespaceResponse, Metadata, Run, RunStatus, SearchItemsResponse, SortOrder, Subgraphs, Thread, ThreadSortBy, ThreadState, ThreadStatus } from "./schema.js";
1
+ import { Assistant, AssistantGraph, AssistantSortBy, AssistantVersion, CancelAction, Checkpoint, Config, Cron, CronCreateForThreadResponse, CronCreateResponse, CronSortBy, DefaultValues, GraphSchema, Item, ListNamespaceResponse, Metadata, Run, RunStatus, SearchItemsResponse, SortOrder, Subgraphs, Thread, ThreadSortBy, ThreadState, ThreadStatus } from "./schema.js";
2
2
  import type { Command, CronsCreatePayload, OnConflictBehavior, RunsCreatePayload, RunsStreamPayload, RunsWaitPayload, StreamEvent } from "./types.js";
3
3
  import type { StreamMode, TypedAsyncGenerator } from "./types.stream.js";
4
4
  import { AsyncCaller, AsyncCallerParams } from "./utils/async_caller.js";
5
+ type HeaderValue = string | undefined | null;
5
6
  /**
6
7
  * Get the API key from the environment.
7
8
  * Precedence:
@@ -20,14 +21,14 @@ export interface ClientConfig {
20
21
  apiKey?: string;
21
22
  callerOptions?: AsyncCallerParams;
22
23
  timeoutMs?: number;
23
- defaultHeaders?: Record<string, string | null | undefined>;
24
+ defaultHeaders?: Record<string, HeaderValue>;
24
25
  onRequest?: RequestHook;
25
26
  }
26
27
  declare class BaseClient {
27
28
  protected asyncCaller: AsyncCaller;
28
29
  protected timeoutMs: number | undefined;
29
30
  protected apiUrl: string;
30
- protected defaultHeaders: Record<string, string | null | undefined>;
31
+ protected defaultHeaders: Record<string, HeaderValue>;
31
32
  protected onRequest?: RequestHook;
32
33
  constructor(config?: ClientConfig);
33
34
  protected prepareFetchOptions(path: string, options?: RequestInit & {
@@ -82,6 +83,8 @@ export declare class CronsClient extends BaseClient {
82
83
  threadId?: string;
83
84
  limit?: number;
84
85
  offset?: number;
86
+ sortBy?: CronSortBy;
87
+ sortOrder?: SortOrder;
85
88
  }): Promise<Cron[]>;
86
89
  }
87
90
  export declare class AssistantsClient extends BaseClient {
@@ -279,7 +282,6 @@ export declare class ThreadsClient<TStateType = DefaultValues, TUpdateType = TSt
279
282
  offset?: number;
280
283
  /**
281
284
  * Thread status to filter on.
282
- * Must be one of 'idle', 'busy', 'interrupted' or 'error'.
283
285
  */
284
286
  status?: ThreadStatus;
285
287
  /**
package/dist/client.js CHANGED
@@ -3,6 +3,61 @@ import { getEnvironmentVariable } from "./utils/env.js";
3
3
  import { mergeSignals } from "./utils/signals.js";
4
4
  import { BytesLineDecoder, SSEDecoder } from "./utils/sse.js";
5
5
  import { IterableReadableStream } from "./utils/stream.js";
6
+ function* iterateHeaders(headers) {
7
+ let iter;
8
+ let shouldClear = false;
9
+ if (headers instanceof Headers) {
10
+ const entries = [];
11
+ headers.forEach((value, name) => {
12
+ entries.push([name, value]);
13
+ });
14
+ iter = entries;
15
+ }
16
+ else if (Array.isArray(headers)) {
17
+ iter = headers;
18
+ }
19
+ else {
20
+ shouldClear = true;
21
+ iter = Object.entries(headers ?? {});
22
+ }
23
+ for (let item of iter) {
24
+ const name = item[0];
25
+ if (typeof name !== "string")
26
+ throw new TypeError(`Expected header name to be a string, got ${typeof name}`);
27
+ const values = Array.isArray(item[1]) ? item[1] : [item[1]];
28
+ let didClear = false;
29
+ for (const value of values) {
30
+ if (value === undefined)
31
+ continue;
32
+ // New object keys should always overwrite older headers
33
+ // Yield a null to clear the header in the headers object
34
+ // before adding the new value
35
+ if (shouldClear && !didClear) {
36
+ didClear = true;
37
+ yield [name, null];
38
+ }
39
+ yield [name, value];
40
+ }
41
+ }
42
+ }
43
+ function mergeHeaders(...headerObjects) {
44
+ const outputHeaders = new Headers();
45
+ for (const headers of headerObjects) {
46
+ if (!headers)
47
+ continue;
48
+ for (const [name, value] of iterateHeaders(headers)) {
49
+ if (value === null)
50
+ outputHeaders.delete(name);
51
+ else
52
+ outputHeaders.append(name, value);
53
+ }
54
+ }
55
+ const headerEntries = [];
56
+ outputHeaders.forEach((value, name) => {
57
+ headerEntries.push([name, value]);
58
+ });
59
+ return Object.fromEntries(headerEntries);
60
+ }
6
61
  /**
7
62
  * Get the API key from the environment.
8
63
  * Precedence:
@@ -100,20 +155,19 @@ class BaseClient {
100
155
  this.onRequest = config?.onRequest;
101
156
  const apiKey = getApiKey(config?.apiKey);
102
157
  if (apiKey) {
103
- this.defaultHeaders["X-Api-Key"] = apiKey;
158
+ this.defaultHeaders["x-api-key"] = apiKey;
104
159
  }
105
160
  }
106
161
  prepareFetchOptions(path, options) {
107
162
  const mutatedOptions = {
108
163
  ...options,
109
- headers: { ...this.defaultHeaders, ...options?.headers },
164
+ headers: mergeHeaders(this.defaultHeaders, options?.headers),
110
165
  };
111
166
  if (mutatedOptions.json) {
112
167
  mutatedOptions.body = JSON.stringify(mutatedOptions.json);
113
- mutatedOptions.headers = {
114
- ...mutatedOptions.headers,
115
- "Content-Type": "application/json",
116
- };
168
+ mutatedOptions.headers = mergeHeaders(mutatedOptions.headers, {
169
+ "content-type": "application/json",
170
+ });
117
171
  delete mutatedOptions.json;
118
172
  }
119
173
  if (mutatedOptions.withResponse) {
@@ -236,6 +290,8 @@ export class CronsClient extends BaseClient {
236
290
  thread_id: query?.threadId ?? undefined,
237
291
  limit: query?.limit ?? 10,
238
292
  offset: query?.offset ?? 0,
293
+ sort_by: query?.sortBy ?? undefined,
294
+ sort_order: query?.sortOrder ?? undefined,
239
295
  },
240
296
  });
241
297
  }
@@ -380,8 +380,13 @@ function useStream(options) {
380
380
  options.onLangChainEvent?.(data);
381
381
  if (event === "debug")
382
382
  options.onDebugEvent?.(data);
383
- if (event === "values")
383
+ if (event === "values") {
384
+ if ("__interrupt__" in data) {
385
+ // don't update values on interrupt values event
386
+ continue;
387
+ }
384
388
  setStreamValues(data);
389
+ }
385
390
  if (event === "messages") {
386
391
  const [serialized] = data;
387
392
  const messageId = messageManagerRef.current.add(serialized);
@@ -377,8 +377,13 @@ export function useStream(options) {
377
377
  options.onLangChainEvent?.(data);
378
378
  if (event === "debug")
379
379
  options.onDebugEvent?.(data);
380
- if (event === "values")
380
+ if (event === "values") {
381
+ if ("__interrupt__" in data) {
382
+ // don't update values on interrupt values event
383
+ continue;
384
+ }
381
385
  setStreamValues(data);
386
+ }
382
387
  if (event === "messages") {
383
388
  const [serialized] = data;
384
389
  const messageId = messageManagerRef.current.add(serialized);
package/dist/schema.d.ts CHANGED
@@ -227,5 +227,6 @@ export interface CronCreateForThreadResponse extends Omit<CronCreateResponse, "t
227
227
  }
228
228
  export type AssistantSortBy = "assistant_id" | "graph_id" | "name" | "created_at" | "updated_at";
229
229
  export type ThreadSortBy = "thread_id" | "status" | "created_at" | "updated_at";
230
+ export type CronSortBy = "cron_id" | "assistant_id" | "thread_id" | "created_at" | "updated_at" | "next_run_date";
230
231
  export type SortOrder = "asc" | "desc";
231
232
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/langgraph-sdk",
3
- "version": "0.0.84",
3
+ "version": "0.0.85",
4
4
  "description": "Client library for interacting with the LangGraph API",
5
5
  "type": "module",
6
6
  "packageManager": "yarn@1.22.19",