@langchain/langgraph 0.0.12 → 0.0.14

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.
Files changed (138) hide show
  1. package/checkpoint/sqlite.cjs +1 -0
  2. package/checkpoint/sqlite.d.cts +1 -0
  3. package/checkpoint/sqlite.d.ts +1 -0
  4. package/checkpoint/sqlite.js +1 -0
  5. package/dist/channels/any_value.cjs +57 -0
  6. package/dist/channels/any_value.d.ts +16 -0
  7. package/dist/channels/any_value.js +53 -0
  8. package/dist/channels/base.cjs +19 -28
  9. package/dist/channels/base.d.ts +13 -19
  10. package/dist/channels/base.js +17 -24
  11. package/dist/channels/binop.cjs +4 -3
  12. package/dist/channels/binop.d.ts +1 -1
  13. package/dist/channels/binop.js +3 -2
  14. package/dist/channels/dynamic_barrier_value.cjs +88 -0
  15. package/dist/channels/dynamic_barrier_value.d.ts +26 -0
  16. package/dist/channels/dynamic_barrier_value.js +84 -0
  17. package/dist/channels/ephemeral_value.cjs +64 -0
  18. package/dist/channels/ephemeral_value.d.ts +14 -0
  19. package/dist/channels/ephemeral_value.js +60 -0
  20. package/dist/channels/index.cjs +1 -3
  21. package/dist/channels/index.d.ts +1 -1
  22. package/dist/channels/index.js +1 -1
  23. package/dist/channels/last_value.cjs +11 -5
  24. package/dist/channels/last_value.d.ts +5 -1
  25. package/dist/channels/last_value.js +9 -3
  26. package/dist/channels/named_barrier_value.cjs +71 -0
  27. package/dist/channels/named_barrier_value.d.ts +18 -0
  28. package/dist/channels/named_barrier_value.js +66 -0
  29. package/dist/channels/topic.cjs +5 -3
  30. package/dist/channels/topic.d.ts +3 -3
  31. package/dist/channels/topic.js +5 -3
  32. package/dist/checkpoint/base.cjs +30 -12
  33. package/dist/checkpoint/base.d.ts +39 -22
  34. package/dist/checkpoint/base.js +28 -11
  35. package/dist/checkpoint/id.cjs +40 -0
  36. package/dist/checkpoint/id.d.ts +2 -0
  37. package/dist/checkpoint/id.js +35 -0
  38. package/dist/checkpoint/index.cjs +2 -2
  39. package/dist/checkpoint/index.d.ts +2 -2
  40. package/dist/checkpoint/index.js +2 -2
  41. package/dist/checkpoint/memory.cjs +66 -49
  42. package/dist/checkpoint/memory.d.ts +7 -10
  43. package/dist/checkpoint/memory.js +65 -47
  44. package/dist/checkpoint/sqlite.cjs +173 -0
  45. package/dist/checkpoint/sqlite.d.ts +14 -0
  46. package/dist/checkpoint/sqlite.js +166 -0
  47. package/dist/constants.cjs +3 -1
  48. package/dist/constants.d.ts +2 -0
  49. package/dist/constants.js +2 -0
  50. package/dist/errors.cjs +31 -0
  51. package/dist/errors.d.ts +12 -0
  52. package/dist/errors.js +24 -0
  53. package/dist/graph/graph.cjs +235 -95
  54. package/dist/graph/graph.d.ts +52 -23
  55. package/dist/graph/graph.js +234 -96
  56. package/dist/graph/index.cjs +2 -2
  57. package/dist/graph/index.d.ts +2 -2
  58. package/dist/graph/index.js +2 -2
  59. package/dist/graph/message.cjs +4 -3
  60. package/dist/graph/message.d.ts +4 -1
  61. package/dist/graph/message.js +4 -3
  62. package/dist/graph/state.cjs +237 -102
  63. package/dist/graph/state.d.ts +41 -18
  64. package/dist/graph/state.js +238 -104
  65. package/dist/index.cjs +12 -7
  66. package/dist/index.d.ts +3 -2
  67. package/dist/index.js +3 -2
  68. package/dist/prebuilt/agent_executor.cjs +22 -36
  69. package/dist/prebuilt/agent_executor.d.ts +7 -10
  70. package/dist/prebuilt/agent_executor.js +23 -37
  71. package/dist/prebuilt/chat_agent_executor.cjs +13 -13
  72. package/dist/prebuilt/chat_agent_executor.d.ts +3 -1
  73. package/dist/prebuilt/chat_agent_executor.js +15 -15
  74. package/dist/prebuilt/index.cjs +4 -1
  75. package/dist/prebuilt/index.d.ts +1 -0
  76. package/dist/prebuilt/index.js +1 -0
  77. package/dist/prebuilt/tool_node.cjs +59 -0
  78. package/dist/prebuilt/tool_node.d.ts +17 -0
  79. package/dist/prebuilt/tool_node.js +54 -0
  80. package/dist/pregel/debug.cjs +6 -8
  81. package/dist/pregel/debug.d.ts +2 -2
  82. package/dist/pregel/debug.js +5 -7
  83. package/dist/pregel/index.cjs +504 -232
  84. package/dist/pregel/index.d.ts +80 -41
  85. package/dist/pregel/index.js +507 -238
  86. package/dist/pregel/io.cjs +117 -30
  87. package/dist/pregel/io.d.ts +11 -3
  88. package/dist/pregel/io.js +111 -28
  89. package/dist/pregel/read.cjs +126 -46
  90. package/dist/pregel/read.d.ts +27 -18
  91. package/dist/pregel/read.js +125 -45
  92. package/dist/pregel/types.cjs +2 -0
  93. package/dist/pregel/types.d.ts +37 -0
  94. package/dist/pregel/types.js +1 -0
  95. package/dist/pregel/validate.cjs +58 -51
  96. package/dist/pregel/validate.d.ts +14 -13
  97. package/dist/pregel/validate.js +56 -50
  98. package/dist/pregel/write.cjs +46 -30
  99. package/dist/pregel/write.d.ts +18 -8
  100. package/dist/pregel/write.js +45 -29
  101. package/dist/serde/base.cjs +2 -0
  102. package/dist/serde/base.d.ts +4 -0
  103. package/dist/serde/base.js +1 -0
  104. package/dist/setup/async_local_storage.cjs +2 -2
  105. package/dist/setup/async_local_storage.js +1 -1
  106. package/dist/tests/channels.test.d.ts +1 -0
  107. package/dist/tests/channels.test.js +151 -0
  108. package/dist/tests/chatbot.int.test.d.ts +1 -0
  109. package/dist/tests/chatbot.int.test.js +61 -0
  110. package/dist/tests/checkpoints.test.d.ts +1 -0
  111. package/dist/tests/checkpoints.test.js +190 -0
  112. package/dist/tests/graph.test.d.ts +1 -0
  113. package/dist/tests/graph.test.js +15 -0
  114. package/dist/tests/prebuilt.int.test.d.ts +1 -0
  115. package/dist/tests/prebuilt.int.test.js +101 -0
  116. package/dist/tests/prebuilt.test.d.ts +1 -0
  117. package/dist/tests/prebuilt.test.js +195 -0
  118. package/dist/tests/pregel.io.test.d.ts +1 -0
  119. package/dist/tests/pregel.io.test.js +332 -0
  120. package/dist/tests/pregel.read.test.d.ts +1 -0
  121. package/dist/tests/pregel.read.test.js +109 -0
  122. package/dist/tests/pregel.test.d.ts +1 -0
  123. package/dist/tests/pregel.test.js +1879 -0
  124. package/dist/tests/pregel.validate.test.d.ts +1 -0
  125. package/dist/tests/pregel.validate.test.js +198 -0
  126. package/dist/tests/pregel.write.test.d.ts +1 -0
  127. package/dist/tests/pregel.write.test.js +44 -0
  128. package/dist/tests/tracing.int.test.d.ts +1 -0
  129. package/dist/tests/tracing.int.test.js +449 -0
  130. package/dist/tests/utils.d.ts +22 -0
  131. package/dist/tests/utils.js +76 -0
  132. package/dist/utils.cjs +74 -0
  133. package/dist/utils.d.ts +18 -0
  134. package/dist/utils.js +70 -0
  135. package/package.json +33 -8
  136. package/dist/pregel/reserved.cjs +0 -6
  137. package/dist/pregel/reserved.d.ts +0 -3
  138. package/dist/pregel/reserved.js +0 -3
@@ -1,75 +1,114 @@
1
- import { Runnable, RunnableConfig } from "@langchain/core/runnables";
1
+ import { Runnable, RunnableConfig, RunnableFunc } from "@langchain/core/runnables";
2
2
  import { CallbackManagerForChainRun } from "@langchain/core/callbacks/manager";
3
3
  import { IterableReadableStream } from "@langchain/core/utils/stream";
4
4
  import { BaseChannel } from "../channels/base.js";
5
- import { BaseCheckpointSaver } from "../checkpoint/base.js";
6
- import { ChannelInvoke } from "./read.js";
5
+ import { BaseCheckpointSaver, Checkpoint, ReadonlyCheckpoint } from "../checkpoint/base.js";
6
+ import { PregelNode } from "./read.js";
7
7
  import { ChannelWrite } from "./write.js";
8
- export declare class GraphRecursionError extends Error {
9
- constructor(message?: string);
10
- }
8
+ import { All, PregelExecutableTask, PregelTaskDescription, StateSnapshot } from "./types.js";
9
+ type WriteValue = Runnable | RunnableFunc<unknown, unknown> | unknown;
11
10
  export declare class Channel {
12
11
  static subscribeTo(channels: string, options?: {
13
12
  key?: string;
14
- when?: (arg: any) => boolean;
15
13
  tags?: string[];
16
- }): ChannelInvoke;
14
+ }): PregelNode;
17
15
  static subscribeTo(channels: string[], options?: {
18
- key?: string;
19
- when?: (arg: any) => boolean;
20
16
  tags?: string[];
21
- }): ChannelInvoke;
22
- static writeTo(...args: any[]): ChannelWrite;
17
+ }): PregelNode;
18
+ static writeTo(channels: string[], kwargs?: Record<string, WriteValue>): ChannelWrite;
23
19
  }
24
- export interface PregelInterface {
20
+ export type StreamMode = "values" | "updates";
21
+ /**
22
+ * Construct a type with a set of properties K of type T
23
+ */
24
+ type StrRecord<K extends string, T> = {
25
+ [P in K]: T;
26
+ };
27
+ export interface PregelInterface<Nn extends StrRecord<string, PregelNode>, Cc extends StrRecord<string, BaseChannel>> {
28
+ nodes: Nn;
29
+ channels: Cc;
30
+ inputs: keyof Cc | Array<keyof Cc>;
31
+ outputs: keyof Cc | Array<keyof Cc>;
25
32
  /**
26
- * @default {}
33
+ * @default true
27
34
  */
28
- channels?: Record<string, BaseChannel>;
35
+ autoValidate?: boolean;
29
36
  /**
30
- * @default "output"
37
+ * @default "values"
31
38
  */
32
- output?: string | Array<string>;
39
+ streamMode?: StreamMode;
40
+ streamChannels?: keyof Cc | Array<keyof Cc>;
33
41
  /**
34
- * @default "input"
42
+ * @default []
35
43
  */
36
- input?: string | Array<string>;
44
+ interruptAfter?: Array<keyof Nn> | All;
37
45
  /**
38
46
  * @default []
39
47
  */
40
- hidden?: Array<string>;
48
+ interruptBefore?: Array<keyof Nn> | All;
41
49
  /**
42
- * @default false
50
+ * @default undefined
43
51
  */
44
- debug?: boolean;
52
+ stepTimeout?: number;
45
53
  /**
46
- * @default []
54
+ * @default false
47
55
  */
48
- interrupt?: string[];
49
- nodes: Record<string, ChannelInvoke>;
56
+ debug?: boolean;
50
57
  checkpointer?: BaseCheckpointSaver;
51
- stepTimeout?: number;
52
58
  }
53
- export interface PregelOptions extends RunnableConfig {
54
- outputKeys?: string | string[];
59
+ export interface PregelOptions<Nn extends StrRecord<string, PregelNode>, Cc extends StrRecord<string, BaseChannel>> extends RunnableConfig {
60
+ streamMode?: StreamMode;
61
+ inputKeys?: keyof Cc | Array<keyof Cc>;
62
+ outputKeys?: keyof Cc | Array<keyof Cc>;
63
+ interruptBefore?: All | Array<keyof Nn>;
64
+ interruptAfter?: All | Array<keyof Nn>;
65
+ debug?: boolean;
55
66
  }
56
67
  export type PregelInputType = any;
57
68
  export type PregelOutputType = any;
58
- export declare class Pregel extends Runnable<PregelInputType, PregelOutputType, PregelOptions> implements PregelInterface {
69
+ export declare class Pregel<const Nn extends StrRecord<string, PregelNode>, const Cc extends StrRecord<string, BaseChannel>> extends Runnable<PregelInputType, PregelOutputType, PregelOptions<Nn, Cc>> implements PregelInterface<Nn, Cc> {
59
70
  static lc_name(): string;
60
71
  lc_namespace: string[];
61
- channels: Record<string, BaseChannel>;
62
- output: string | Array<string>;
63
- input: string | Array<string>;
64
- hidden: Array<string>;
72
+ nodes: Nn;
73
+ channels: Cc;
74
+ inputs: keyof Cc | Array<keyof Cc>;
75
+ outputs: keyof Cc | Array<keyof Cc>;
76
+ autoValidate: boolean;
77
+ streamMode: StreamMode;
78
+ streamChannels?: keyof Cc | Array<keyof Cc>;
79
+ interruptAfter?: Array<keyof Nn> | All;
80
+ interruptBefore?: Array<keyof Nn> | All;
81
+ stepTimeout?: number;
65
82
  debug: boolean;
66
- nodes: Record<string, ChannelInvoke>;
67
83
  checkpointer?: BaseCheckpointSaver;
68
- stepTimeout?: number;
69
- interrupt: string[];
70
- constructor(fields: PregelInterface);
71
- _transform(input: AsyncGenerator<PregelInputType>, runManager?: CallbackManagerForChainRun, config?: RunnableConfig & Partial<Record<string, unknown>>): AsyncGenerator<PregelOutputType>;
72
- invoke(input: PregelInputType, options?: PregelOptions): Promise<PregelOutputType>;
73
- stream(input: PregelInputType, config?: PregelOptions): Promise<IterableReadableStream<PregelOutputType>>;
74
- transform(generator: AsyncGenerator<PregelInputType>, config?: PregelOptions): AsyncGenerator<PregelOutputType>;
84
+ constructor(fields: PregelInterface<Nn, Cc>);
85
+ validate(): this;
86
+ get streamChannelsList(): Array<keyof Cc>;
87
+ get streamChannelsAsIs(): keyof Cc | Array<keyof Cc>;
88
+ getState(config: RunnableConfig): Promise<StateSnapshot>;
89
+ getStateHistory(config: RunnableConfig, limit?: number, before?: RunnableConfig): AsyncIterableIterator<StateSnapshot>;
90
+ updateState(config: RunnableConfig, values: Record<string, unknown> | unknown, asNode?: keyof Nn): Promise<RunnableConfig>;
91
+ _defaults(config: PregelOptions<Nn, Cc>): [
92
+ boolean,
93
+ StreamMode,
94
+ // stream mode
95
+ keyof Cc | Array<keyof Cc>,
96
+ // input keys
97
+ keyof Cc | Array<keyof Cc>,
98
+ RunnableConfig,
99
+ // config without pregel keys
100
+ All | Array<keyof Nn>,
101
+ // interrupt before
102
+ All | Array<keyof Nn>
103
+ ];
104
+ _transform(input: AsyncGenerator<PregelInputType>, runManager?: CallbackManagerForChainRun, config?: PregelOptions<Nn, Cc>): AsyncGenerator<PregelOutputType>;
105
+ invoke(input: PregelInputType, options?: PregelOptions<Nn, Cc>): Promise<PregelOutputType>;
106
+ stream(input: PregelInputType, config?: PregelOptions<Nn, Cc>): Promise<IterableReadableStream<PregelOutputType>>;
107
+ transform(generator: AsyncGenerator<PregelInputType>, config?: PregelOptions<Nn, Cc>): AsyncGenerator<PregelOutputType>;
75
108
  }
109
+ export declare function _shouldInterrupt<N extends PropertyKey, C extends PropertyKey>(checkpoint: ReadonlyCheckpoint, interruptNodes: All | Array<N>, snapshotChannels: Array<C>, tasks: Array<PregelExecutableTask<N, C>>): boolean;
110
+ export declare function _localRead<Cc extends StrRecord<string, BaseChannel>>(checkpoint: ReadonlyCheckpoint, channels: Cc, writes: Array<[keyof Cc, unknown]>, select: Array<keyof Cc> | keyof Cc, fresh?: boolean): Record<string, unknown> | unknown;
111
+ export declare function _applyWrites<Cc extends Record<string, BaseChannel>>(checkpoint: Checkpoint, channels: Cc, pendingWrites: Array<[keyof Cc, unknown]>): void;
112
+ export declare function _prepareNextTasks<Nn extends StrRecord<string, PregelNode>, Cc extends StrRecord<string, BaseChannel>>(checkpoint: ReadonlyCheckpoint, processes: Nn, channels: Cc, forExecution: false): [Checkpoint, Array<PregelTaskDescription>];
113
+ export declare function _prepareNextTasks<Nn extends StrRecord<string, PregelNode>, Cc extends StrRecord<string, BaseChannel>>(checkpoint: ReadonlyCheckpoint, processes: Nn, channels: Cc, forExecution: true): [Checkpoint, Array<PregelExecutableTask<keyof Nn, keyof Cc>>];
114
+ export {};