@langchain/langgraph-api 0.0.39 → 0.0.40

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/api/meta.mjs CHANGED
@@ -1,5 +1,17 @@
1
1
  import { Hono } from "hono";
2
+ import * as fs from "node:fs/promises";
3
+ import * as url from "node:url";
2
4
  const api = new Hono();
5
+ // Get the version using the same pattern as semver/index.mts
6
+ const packageJsonPath = url.fileURLToPath(new URL("../../package.json", import.meta.url));
7
+ let version;
8
+ try {
9
+ const packageJson = JSON.parse(await fs.readFile(packageJsonPath, "utf-8"));
10
+ version = packageJson.version;
11
+ }
12
+ catch {
13
+ console.warn("Could not determine version of langgraph-api");
14
+ }
3
15
  // read env variable
4
16
  const env = process.env;
5
17
  api.get("/info", (c) => {
@@ -19,7 +31,14 @@ api.get("/info", (c) => {
19
31
  return undefined;
20
32
  })();
21
33
  return c.json({
22
- flags: { assistants: true, crons: false, langsmith: !!langsmithTracing },
34
+ version,
35
+ context: "js",
36
+ flags: {
37
+ assistants: true,
38
+ crons: false,
39
+ langsmith: !!langsmithTracing,
40
+ langsmith_tracing_replicas: true,
41
+ },
23
42
  });
24
43
  });
25
44
  api.get("/ok", (c) => c.json({ ok: true }));
package/dist/api/runs.mjs CHANGED
@@ -1,15 +1,15 @@
1
+ import { zValidator } from "@hono/zod-validator";
1
2
  import { Hono } from "hono";
2
3
  import { HTTPException } from "hono/http-exception";
3
4
  import { streamSSE } from "hono/streaming";
5
+ import { v4 as uuid4 } from "uuid";
6
+ import { z } from "zod";
4
7
  import { getAssistantId } from "../graph/load.mjs";
5
- import { zValidator } from "@hono/zod-validator";
8
+ import { logError, logger } from "../logging.mjs";
6
9
  import * as schemas from "../schemas.mjs";
7
- import { z } from "zod";
8
10
  import { Runs, Threads } from "../storage/ops.mjs";
9
- import { serialiseAsDict } from "../utils/serde.mjs";
10
11
  import { getDisconnectAbortSignal, jsonExtra, waitKeepAlive, } from "../utils/hono.mjs";
11
- import { logError, logger } from "../logging.mjs";
12
- import { v4 as uuid4 } from "uuid";
12
+ import { serialiseAsDict } from "../utils/serde.mjs";
13
13
  const api = new Hono();
14
14
  const createValidRun = async (threadId, payload, kwargs) => {
15
15
  const { assistant_id: assistantId, ...run } = payload;
@@ -33,6 +33,13 @@ const createValidRun = async (threadId, payload, kwargs) => {
33
33
  config.configurable ??= {};
34
34
  Object.assign(config.configurable, run.checkpoint);
35
35
  }
36
+ if (run.langsmith_tracer) {
37
+ config.configurable ??= {};
38
+ Object.assign(config.configurable, {
39
+ langsmith_project: run.langsmith_tracer.project_name,
40
+ langsmith_example_id: run.langsmith_tracer.example_id,
41
+ });
42
+ }
36
43
  if (headers) {
37
44
  for (const [rawKey, value] of headers.entries()) {
38
45
  const key = rawKey.toLowerCase();
@@ -579,6 +579,16 @@ export declare const CommandSchema: z.ZodObject<{
579
579
  })[] | undefined;
580
580
  resume?: unknown;
581
581
  }>;
582
+ export declare const LangsmithTracer: z.ZodObject<{
583
+ project_name: z.ZodOptional<z.ZodString>;
584
+ example_id: z.ZodOptional<z.ZodString>;
585
+ }, "strip", z.ZodTypeAny, {
586
+ project_name?: string | undefined;
587
+ example_id?: string | undefined;
588
+ }, {
589
+ project_name?: string | undefined;
590
+ example_id?: string | undefined;
591
+ }>;
582
592
  export declare const RunCreate: z.ZodObject<{
583
593
  assistant_id: z.ZodUnion<[z.ZodString, z.ZodString]>;
584
594
  checkpoint_id: z.ZodOptional<z.ZodString>;
@@ -692,6 +702,16 @@ export declare const RunCreate: z.ZodObject<{
692
702
  if_not_exists: z.ZodOptional<z.ZodEnum<["reject", "create"]>>;
693
703
  on_completion: z.ZodOptional<z.ZodEnum<["delete", "keep"]>>;
694
704
  feedback_keys: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
705
+ langsmith_tracer: z.ZodOptional<z.ZodObject<{
706
+ project_name: z.ZodOptional<z.ZodString>;
707
+ example_id: z.ZodOptional<z.ZodString>;
708
+ }, "strip", z.ZodTypeAny, {
709
+ project_name?: string | undefined;
710
+ example_id?: string | undefined;
711
+ }, {
712
+ project_name?: string | undefined;
713
+ example_id?: string | undefined;
714
+ }>>;
695
715
  }, "strip", z.ZodTypeAny, {
696
716
  assistant_id: string;
697
717
  on_disconnect: "cancel" | "continue";
@@ -739,6 +759,10 @@ export declare const RunCreate: z.ZodObject<{
739
759
  stream_subgraphs?: boolean | undefined;
740
760
  stream_resumable?: boolean | undefined;
741
761
  on_completion?: "delete" | "keep" | undefined;
762
+ langsmith_tracer?: {
763
+ project_name?: string | undefined;
764
+ example_id?: string | undefined;
765
+ } | undefined;
742
766
  }, {
743
767
  assistant_id: string;
744
768
  metadata?: z.objectInputType<{}, z.ZodAny, "strip"> | undefined;
@@ -786,6 +810,10 @@ export declare const RunCreate: z.ZodObject<{
786
810
  stream_subgraphs?: boolean | undefined;
787
811
  stream_resumable?: boolean | undefined;
788
812
  on_completion?: "delete" | "keep" | undefined;
813
+ langsmith_tracer?: {
814
+ project_name?: string | undefined;
815
+ example_id?: string | undefined;
816
+ } | undefined;
789
817
  }>;
790
818
  export declare const RunBatchCreate: z.ZodArray<z.ZodObject<{
791
819
  assistant_id: z.ZodUnion<[z.ZodString, z.ZodString]>;
@@ -900,6 +928,16 @@ export declare const RunBatchCreate: z.ZodArray<z.ZodObject<{
900
928
  if_not_exists: z.ZodOptional<z.ZodEnum<["reject", "create"]>>;
901
929
  on_completion: z.ZodOptional<z.ZodEnum<["delete", "keep"]>>;
902
930
  feedback_keys: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
931
+ langsmith_tracer: z.ZodOptional<z.ZodObject<{
932
+ project_name: z.ZodOptional<z.ZodString>;
933
+ example_id: z.ZodOptional<z.ZodString>;
934
+ }, "strip", z.ZodTypeAny, {
935
+ project_name?: string | undefined;
936
+ example_id?: string | undefined;
937
+ }, {
938
+ project_name?: string | undefined;
939
+ example_id?: string | undefined;
940
+ }>>;
903
941
  }, "strip", z.ZodTypeAny, {
904
942
  assistant_id: string;
905
943
  on_disconnect: "cancel" | "continue";
@@ -947,6 +985,10 @@ export declare const RunBatchCreate: z.ZodArray<z.ZodObject<{
947
985
  stream_subgraphs?: boolean | undefined;
948
986
  stream_resumable?: boolean | undefined;
949
987
  on_completion?: "delete" | "keep" | undefined;
988
+ langsmith_tracer?: {
989
+ project_name?: string | undefined;
990
+ example_id?: string | undefined;
991
+ } | undefined;
950
992
  }, {
951
993
  assistant_id: string;
952
994
  metadata?: z.objectInputType<{}, z.ZodAny, "strip"> | undefined;
@@ -994,6 +1036,10 @@ export declare const RunBatchCreate: z.ZodArray<z.ZodObject<{
994
1036
  stream_subgraphs?: boolean | undefined;
995
1037
  stream_resumable?: boolean | undefined;
996
1038
  on_completion?: "delete" | "keep" | undefined;
1039
+ langsmith_tracer?: {
1040
+ project_name?: string | undefined;
1041
+ example_id?: string | undefined;
1042
+ } | undefined;
997
1043
  }>, "many">;
998
1044
  export declare const SearchResult: z.ZodObject<{
999
1045
  metadata: z.ZodOptional<z.ZodObject<{}, "strip", z.ZodAny, z.objectOutputType<{}, z.ZodAny, "strip">, z.objectInputType<{}, z.ZodAny, "strip">>>;
package/dist/schemas.mjs CHANGED
@@ -159,6 +159,10 @@ export const CommandSchema = z.object({
159
159
  .optional(),
160
160
  resume: z.unknown().optional(),
161
161
  });
162
+ export const LangsmithTracer = z.object({
163
+ project_name: z.string().optional(),
164
+ example_id: z.string().optional(),
165
+ });
162
166
  export const RunCreate = z
163
167
  .object({
164
168
  assistant_id: z.union([z.string().uuid(), z.string()]),
@@ -210,6 +214,7 @@ export const RunCreate = z
210
214
  if_not_exists: z.enum(["reject", "create"]).optional(),
211
215
  on_completion: z.enum(["delete", "keep"]).optional(),
212
216
  feedback_keys: z.array(z.string()).optional(),
217
+ langsmith_tracer: LangsmithTracer.optional(),
213
218
  })
214
219
  .describe("Payload for creating a stateful run.");
215
220
  export const RunBatchCreate = z
package/dist/stream.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import type { Run, RunnableConfig, Checkpoint } from "./storage/ops.mjs";
2
1
  import { type CheckpointMetadata, type Interrupt, type StateSnapshot } from "@langchain/langgraph";
2
+ import type { Checkpoint, Run, RunnableConfig } from "./storage/ops.mjs";
3
3
  interface DebugTask {
4
4
  id: string;
5
5
  name: string;
package/dist/stream.mjs CHANGED
@@ -1,9 +1,10 @@
1
- import { getGraph } from "./graph/load.mjs";
2
- import { Client as LangSmithClient } from "langsmith";
3
- import { runnableConfigToCheckpoint, taskRunnableConfigToCheckpoint, } from "./utils/runnableConfig.mjs";
4
1
  import { isBaseMessage } from "@langchain/core/messages";
2
+ import { LangChainTracer } from "@langchain/core/tracers/tracer_langchain";
3
+ import { Client as LangSmithClient, getDefaultProjectName } from "langsmith";
5
4
  import { getLangGraphCommand } from "./command.mjs";
5
+ import { getGraph } from "./graph/load.mjs";
6
6
  import { checkLangGraphSemver } from "./semver/index.mjs";
7
+ import { runnableConfigToCheckpoint, taskRunnableConfigToCheckpoint, } from "./utils/runnableConfig.mjs";
7
8
  const isRunnableConfig = (config) => {
8
9
  if (typeof config !== "object" || config == null)
9
10
  return false;
@@ -88,6 +89,19 @@ export async function* streamState(run, attempt = 1, options) {
88
89
  langgraph_host: "self-hosted",
89
90
  langgraph_api_url: process.env.LANGGRAPH_API_URL ?? undefined,
90
91
  };
92
+ const tracer = run.kwargs?.config?.configurable?.langsmith_project
93
+ ? new LangChainTracer({
94
+ replicas: [
95
+ [
96
+ run.kwargs?.config?.configurable?.langsmith_project,
97
+ {
98
+ reference_example_id: run.kwargs?.config?.configurable?.langsmith_example_id,
99
+ },
100
+ ],
101
+ [getDefaultProjectName(), undefined],
102
+ ],
103
+ })
104
+ : undefined;
91
105
  const events = graph.streamEvents(kwargs.command != null
92
106
  ? getLangGraphCommand(kwargs.command)
93
107
  : (kwargs.input ?? null), {
@@ -102,6 +116,7 @@ export async function* streamState(run, attempt = 1, options) {
102
116
  runId: run.run_id,
103
117
  streamMode: [...libStreamMode],
104
118
  signal: options?.signal,
119
+ ...(tracer && { callbacks: [tracer] }),
105
120
  });
106
121
  const messages = {};
107
122
  const completedIds = new Set();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/langgraph-api",
3
- "version": "0.0.39",
3
+ "version": "0.0.40",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": "^18.19.0 || >=20.16.0"
@@ -49,14 +49,14 @@
49
49
  "@babel/code-frame": "^7.26.2",
50
50
  "@hono/node-server": "^1.12.0",
51
51
  "@hono/zod-validator": "^0.2.2",
52
- "@langchain/langgraph-ui": "0.0.39",
52
+ "@langchain/langgraph-ui": "0.0.40",
53
53
  "@types/json-schema": "^7.0.15",
54
54
  "@typescript/vfs": "^1.6.0",
55
55
  "dedent": "^1.5.3",
56
56
  "dotenv": "^16.4.7",
57
57
  "exit-hook": "^4.0.0",
58
58
  "hono": "^4.5.4",
59
- "langsmith": "^0.2.15",
59
+ "langsmith": "^0.3.33",
60
60
  "open": "^10.1.0",
61
61
  "semver": "^7.7.1",
62
62
  "stacktrace-parser": "^0.1.10",
@@ -68,7 +68,7 @@
68
68
  "zod": "^3.23.8"
69
69
  },
70
70
  "peerDependencies": {
71
- "@langchain/core": "^0.3.42",
71
+ "@langchain/core": "^0.3.59",
72
72
  "@langchain/langgraph": "^0.2.57 || ^0.3.0",
73
73
  "@langchain/langgraph-checkpoint": "~0.0.16",
74
74
  "@langchain/langgraph-sdk": "~0.0.70",
@@ -80,7 +80,7 @@
80
80
  }
81
81
  },
82
82
  "devDependencies": {
83
- "@langchain/core": "^0.3.42",
83
+ "@langchain/core": "^0.3.59",
84
84
  "@langchain/langgraph": "^0.2.57",
85
85
  "@langchain/langgraph-checkpoint": "~0.0.16",
86
86
  "@langchain/langgraph-sdk": "^0.0.77",