@langchain/langgraph-sdk 0.0.56 → 0.0.57

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.
@@ -2,8 +2,17 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.typedUi = void 0;
4
4
  const uuid_1 = require("uuid");
5
- const typedUi = (config) => {
5
+ /**
6
+ * Helper to send and persist UI messages. Accepts a map of component names to React components
7
+ * as type argument to provide type safety. Will also write to the `options?.stateKey` state.
8
+ *
9
+ * @param config LangGraphRunnableConfig
10
+ * @param options
11
+ * @returns
12
+ */
13
+ const typedUi = (config, options) => {
6
14
  let items = [];
15
+ const stateKey = options?.stateKey ?? "ui";
7
16
  const runId = config.metadata?.run_id ?? config.runId;
8
17
  if (!runId)
9
18
  throw new Error("run_id is required");
@@ -27,12 +36,14 @@ const typedUi = (config) => {
27
36
  };
28
37
  items.push(evt);
29
38
  config.writer?.(evt);
39
+ config.configurable?.__pregel_send?.([[stateKey, evt]]);
30
40
  return evt;
31
41
  };
32
42
  const handleDelete = (id) => {
33
43
  const evt = { type: "remove-ui", id };
34
44
  items.push(evt);
35
45
  config.writer?.(evt);
46
+ config.configurable?.__pregel_send?.([[stateKey, evt]]);
36
47
  return evt;
37
48
  };
38
49
  return { push: handlePush, delete: handleDelete, items };
@@ -3,12 +3,27 @@ import type { RemoveUIMessage, UIMessage } from "../types.js";
3
3
  interface MessageLike {
4
4
  id?: string;
5
5
  }
6
+ /**
7
+ * Helper to send and persist UI messages. Accepts a map of component names to React components
8
+ * as type argument to provide type safety. Will also write to the `options?.stateKey` state.
9
+ *
10
+ * @param config LangGraphRunnableConfig
11
+ * @param options
12
+ * @returns
13
+ */
6
14
  export declare const typedUi: <Decl extends Record<string, ElementType>>(config: {
7
15
  writer?: (chunk: unknown) => void;
8
16
  runId?: string;
9
17
  metadata?: Record<string, unknown>;
10
18
  tags?: string[];
11
19
  runName?: string;
20
+ configurable?: {
21
+ __pregel_send?: (writes_: [string, unknown][]) => void;
22
+ [key: string]: unknown;
23
+ };
24
+ }, options?: {
25
+ /** The key to write the UI messages to. Defaults to `ui`. */
26
+ stateKey?: string;
12
27
  }) => {
13
28
  push: <K extends keyof Decl & string>(message: {
14
29
  id?: string | undefined;
@@ -1,6 +1,15 @@
1
1
  import { v4 as uuidv4 } from "uuid";
2
- export const typedUi = (config) => {
2
+ /**
3
+ * Helper to send and persist UI messages. Accepts a map of component names to React components
4
+ * as type argument to provide type safety. Will also write to the `options?.stateKey` state.
5
+ *
6
+ * @param config LangGraphRunnableConfig
7
+ * @param options
8
+ * @returns
9
+ */
10
+ export const typedUi = (config, options) => {
3
11
  let items = [];
12
+ const stateKey = options?.stateKey ?? "ui";
4
13
  const runId = config.metadata?.run_id ?? config.runId;
5
14
  if (!runId)
6
15
  throw new Error("run_id is required");
@@ -24,12 +33,14 @@ export const typedUi = (config) => {
24
33
  };
25
34
  items.push(evt);
26
35
  config.writer?.(evt);
36
+ config.configurable?.__pregel_send?.([[stateKey, evt]]);
27
37
  return evt;
28
38
  };
29
39
  const handleDelete = (id) => {
30
40
  const evt = { type: "remove-ui", id };
31
41
  items.push(evt);
32
42
  config.writer?.(evt);
43
+ config.configurable?.__pregel_send?.([[stateKey, evt]]);
33
44
  return evt;
34
45
  };
35
46
  return { push: handlePush, delete: handleDelete, items };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/langgraph-sdk",
3
- "version": "0.0.56",
3
+ "version": "0.0.57",
4
4
  "description": "Client library for interacting with the LangGraph API",
5
5
  "type": "module",
6
6
  "packageManager": "yarn@1.22.19",