@langchain/langgraph-sdk 0.0.79 → 0.0.81

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
@@ -71,6 +71,12 @@ class BaseClient {
71
71
  writable: true,
72
72
  value: void 0
73
73
  });
74
+ Object.defineProperty(this, "onRequest", {
75
+ enumerable: true,
76
+ configurable: true,
77
+ writable: true,
78
+ value: void 0
79
+ });
74
80
  const callerOptions = {
75
81
  maxRetries: 4,
76
82
  maxConcurrency: 4,
@@ -95,6 +101,7 @@ class BaseClient {
95
101
  // Regex to remove trailing slash, if present
96
102
  this.apiUrl = config?.apiUrl?.replace(/\/$/, "") || defaultApiUrl;
97
103
  this.defaultHeaders = config?.defaultHeaders || {};
104
+ this.onRequest = config?.onRequest;
98
105
  const apiKey = getApiKey(config?.apiKey);
99
106
  if (apiKey) {
100
107
  this.defaultHeaders["X-Api-Key"] = apiKey;
@@ -141,7 +148,12 @@ class BaseClient {
141
148
  return [targetUrl, mutatedOptions];
142
149
  }
143
150
  async fetch(path, options) {
144
- const response = await this.asyncCaller.fetch(...this.prepareFetchOptions(path, options));
151
+ const [url, init] = this.prepareFetchOptions(path, options);
152
+ let finalInit = init;
153
+ if (this.onRequest) {
154
+ finalInit = await this.onRequest(url, init);
155
+ }
156
+ const response = await this.asyncCaller.fetch(url, finalInit);
145
157
  const body = (() => {
146
158
  if (response.status === 202 || response.status === 204) {
147
159
  return undefined;
@@ -614,6 +626,7 @@ class RunsClient extends BaseClient {
614
626
  after_seconds: payload?.afterSeconds,
615
627
  if_not_exists: payload?.ifNotExists,
616
628
  checkpoint_during: payload?.checkpointDuring,
629
+ langsmith_tracer: payload?._langsmithTracer,
617
630
  };
618
631
  const [run, response] = await this.fetch(`/threads/${threadId}/runs`, {
619
632
  method: "POST",
@@ -669,6 +682,12 @@ class RunsClient extends BaseClient {
669
682
  after_seconds: payload?.afterSeconds,
670
683
  if_not_exists: payload?.ifNotExists,
671
684
  checkpoint_during: payload?.checkpointDuring,
685
+ langsmith_tracer: payload?._langsmithTracer
686
+ ? {
687
+ project_name: payload?._langsmithTracer?.projectName,
688
+ example_id: payload?._langsmithTracer?.exampleId,
689
+ }
690
+ : undefined,
672
691
  };
673
692
  const endpoint = threadId == null ? `/runs/wait` : `/threads/${threadId}/runs/wait`;
674
693
  const [run, response] = await this.fetch(endpoint, {
package/dist/client.d.ts CHANGED
@@ -14,18 +14,21 @@ import { AsyncCaller, AsyncCallerParams } from "./utils/async_caller.js";
14
14
  * @returns The API key if found, otherwise undefined
15
15
  */
16
16
  export declare function getApiKey(apiKey?: string): string | undefined;
17
+ export type RequestHook = (url: URL, init: RequestInit) => Promise<RequestInit> | RequestInit;
17
18
  export interface ClientConfig {
18
19
  apiUrl?: string;
19
20
  apiKey?: string;
20
21
  callerOptions?: AsyncCallerParams;
21
22
  timeoutMs?: number;
22
23
  defaultHeaders?: Record<string, string | null | undefined>;
24
+ onRequest?: RequestHook;
23
25
  }
24
26
  declare class BaseClient {
25
27
  protected asyncCaller: AsyncCaller;
26
28
  protected timeoutMs: number | undefined;
27
29
  protected apiUrl: string;
28
30
  protected defaultHeaders: Record<string, string | null | undefined>;
31
+ protected onRequest?: RequestHook;
29
32
  constructor(config?: ClientConfig);
30
33
  protected prepareFetchOptions(path: string, options?: RequestInit & {
31
34
  json?: unknown;
package/dist/client.js CHANGED
@@ -67,6 +67,12 @@ class BaseClient {
67
67
  writable: true,
68
68
  value: void 0
69
69
  });
70
+ Object.defineProperty(this, "onRequest", {
71
+ enumerable: true,
72
+ configurable: true,
73
+ writable: true,
74
+ value: void 0
75
+ });
70
76
  const callerOptions = {
71
77
  maxRetries: 4,
72
78
  maxConcurrency: 4,
@@ -91,6 +97,7 @@ class BaseClient {
91
97
  // Regex to remove trailing slash, if present
92
98
  this.apiUrl = config?.apiUrl?.replace(/\/$/, "") || defaultApiUrl;
93
99
  this.defaultHeaders = config?.defaultHeaders || {};
100
+ this.onRequest = config?.onRequest;
94
101
  const apiKey = getApiKey(config?.apiKey);
95
102
  if (apiKey) {
96
103
  this.defaultHeaders["X-Api-Key"] = apiKey;
@@ -137,7 +144,12 @@ class BaseClient {
137
144
  return [targetUrl, mutatedOptions];
138
145
  }
139
146
  async fetch(path, options) {
140
- const response = await this.asyncCaller.fetch(...this.prepareFetchOptions(path, options));
147
+ const [url, init] = this.prepareFetchOptions(path, options);
148
+ let finalInit = init;
149
+ if (this.onRequest) {
150
+ finalInit = await this.onRequest(url, init);
151
+ }
152
+ const response = await this.asyncCaller.fetch(url, finalInit);
141
153
  const body = (() => {
142
154
  if (response.status === 202 || response.status === 204) {
143
155
  return undefined;
@@ -607,6 +619,7 @@ export class RunsClient extends BaseClient {
607
619
  after_seconds: payload?.afterSeconds,
608
620
  if_not_exists: payload?.ifNotExists,
609
621
  checkpoint_during: payload?.checkpointDuring,
622
+ langsmith_tracer: payload?._langsmithTracer,
610
623
  };
611
624
  const [run, response] = await this.fetch(`/threads/${threadId}/runs`, {
612
625
  method: "POST",
@@ -662,6 +675,12 @@ export class RunsClient extends BaseClient {
662
675
  after_seconds: payload?.afterSeconds,
663
676
  if_not_exists: payload?.ifNotExists,
664
677
  checkpoint_during: payload?.checkpointDuring,
678
+ langsmith_tracer: payload?._langsmithTracer
679
+ ? {
680
+ project_name: payload?._langsmithTracer?.projectName,
681
+ example_id: payload?._langsmithTracer?.exampleId,
682
+ }
683
+ : undefined,
665
684
  };
666
685
  const endpoint = threadId == null ? `/runs/wait` : `/threads/${threadId}/runs/wait`;
667
686
  const [run, response] = await this.fetch(endpoint, {
package/dist/index.cjs CHANGED
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.overrideFetchImplementation = exports.Client = void 0;
3
+ exports.overrideFetchImplementation = exports.getApiKey = exports.Client = void 0;
4
4
  var client_js_1 = require("./client.cjs");
5
5
  Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return client_js_1.Client; } });
6
+ Object.defineProperty(exports, "getApiKey", { enumerable: true, get: function () { return client_js_1.getApiKey; } });
6
7
  var fetch_js_1 = require("./singletons/fetch.cjs");
7
8
  Object.defineProperty(exports, "overrideFetchImplementation", { enumerable: true, get: function () { return fetch_js_1.overrideFetchImplementation; } });
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- export { Client } from "./client.js";
2
- export type { AssistantBase, Assistant, AssistantVersion, AssistantGraph, Config, DefaultValues, GraphSchema, Metadata, Run, Thread, ThreadTask, ThreadState, ThreadStatus, Cron, Checkpoint, Interrupt, ListNamespaceResponse, Item, SearchItem, SearchItemsResponse, CronCreateResponse, CronCreateForThreadResponse, } from "./schema.js";
1
+ export { Client, getApiKey } from "./client.js";
2
+ export type { ClientConfig, RequestHook } from "./client.js";
3
+ export type { Assistant, AssistantBase, AssistantGraph, AssistantVersion, Checkpoint, Config, Cron, CronCreateForThreadResponse, CronCreateResponse, DefaultValues, GraphSchema, Interrupt, Item, ListNamespaceResponse, Metadata, Run, SearchItem, SearchItemsResponse, Thread, ThreadState, ThreadStatus, ThreadTask, } from "./schema.js";
3
4
  export { overrideFetchImplementation } from "./singletons/fetch.js";
4
- export type { OnConflictBehavior, Command } from "./types.js";
5
- export type { StreamMode } from "./types.stream.js";
6
- export type { ValuesStreamEvent, MessagesTupleStreamEvent, MetadataStreamEvent, UpdatesStreamEvent, CustomStreamEvent, MessagesStreamEvent, DebugStreamEvent, EventsStreamEvent, ErrorStreamEvent, FeedbackStreamEvent, } from "./types.stream.js";
7
- export type { Message, HumanMessage, AIMessage, ToolMessage, SystemMessage, FunctionMessage, RemoveMessage, } from "./types.messages.js";
5
+ export type { Command, OnConflictBehavior, RunsInvokePayload, } from "./types.js";
6
+ export type { AIMessage, FunctionMessage, HumanMessage, Message, RemoveMessage, SystemMessage, ToolMessage, } from "./types.messages.js";
7
+ export type { CustomStreamEvent, DebugStreamEvent, ErrorStreamEvent, EventsStreamEvent, FeedbackStreamEvent, MessagesStreamEvent, MessagesTupleStreamEvent, MetadataStreamEvent, StreamMode, UpdatesStreamEvent, ValuesStreamEvent, } from "./types.stream.js";
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export { Client } from "./client.js";
1
+ export { Client, getApiKey } from "./client.js";
2
2
  export { overrideFetchImplementation } from "./singletons/fetch.js";
package/dist/types.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { LangChainTracer } from "@langchain/core/tracers/tracer_langchain";
1
2
  import { Checkpoint, Config, Metadata } from "./schema.js";
2
3
  import { StreamMode } from "./types.stream.js";
3
4
  export type MultitaskStrategy = "reject" | "interrupt" | "rollback" | "enqueue";
@@ -25,7 +26,7 @@ export interface Command {
25
26
  */
26
27
  goto?: Send | Send[] | string | string[];
27
28
  }
28
- interface RunsInvokePayload {
29
+ export interface RunsInvokePayload {
29
30
  /**
30
31
  * Input to the run. Pass `null` to resume from the current state of the thread.
31
32
  */
@@ -111,6 +112,11 @@ interface RunsInvokePayload {
111
112
  run_id: string;
112
113
  thread_id?: string;
113
114
  }) => void;
115
+ /**
116
+ * @internal
117
+ * For LangSmith tracing purposes only. Not part of the public API.
118
+ */
119
+ _langsmithTracer?: LangChainTracer;
114
120
  }
115
121
  export interface RunsStreamPayload<TStreamMode extends StreamMode | StreamMode[] = [], TSubgraphs extends boolean = false> extends RunsInvokePayload {
116
122
  /**
@@ -159,4 +165,3 @@ export interface RunsWaitPayload extends RunsStreamPayload {
159
165
  */
160
166
  raiseError?: boolean;
161
167
  }
162
- export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/langgraph-sdk",
3
- "version": "0.0.79",
3
+ "version": "0.0.81",
4
4
  "description": "Client library for interacting with the LangGraph API",
5
5
  "type": "module",
6
6
  "packageManager": "yarn@1.22.19",