@langchain/langgraph 0.0.11 → 0.0.13

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 (134) hide show
  1. package/dist/channels/any_value.cjs +57 -0
  2. package/dist/channels/any_value.d.ts +16 -0
  3. package/dist/channels/any_value.js +53 -0
  4. package/dist/channels/base.cjs +19 -28
  5. package/dist/channels/base.d.ts +13 -19
  6. package/dist/channels/base.js +17 -24
  7. package/dist/channels/binop.cjs +4 -3
  8. package/dist/channels/binop.d.ts +1 -1
  9. package/dist/channels/binop.js +3 -2
  10. package/dist/channels/dynamic_barrier_value.cjs +88 -0
  11. package/dist/channels/dynamic_barrier_value.d.ts +26 -0
  12. package/dist/channels/dynamic_barrier_value.js +84 -0
  13. package/dist/channels/ephemeral_value.cjs +64 -0
  14. package/dist/channels/ephemeral_value.d.ts +14 -0
  15. package/dist/channels/ephemeral_value.js +60 -0
  16. package/dist/channels/index.cjs +1 -3
  17. package/dist/channels/index.d.ts +1 -1
  18. package/dist/channels/index.js +1 -1
  19. package/dist/channels/last_value.cjs +11 -5
  20. package/dist/channels/last_value.d.ts +5 -1
  21. package/dist/channels/last_value.js +9 -3
  22. package/dist/channels/named_barrier_value.cjs +71 -0
  23. package/dist/channels/named_barrier_value.d.ts +18 -0
  24. package/dist/channels/named_barrier_value.js +66 -0
  25. package/dist/channels/topic.cjs +5 -3
  26. package/dist/channels/topic.d.ts +3 -3
  27. package/dist/channels/topic.js +5 -3
  28. package/dist/checkpoint/base.cjs +30 -12
  29. package/dist/checkpoint/base.d.ts +39 -22
  30. package/dist/checkpoint/base.js +28 -11
  31. package/dist/checkpoint/id.cjs +40 -0
  32. package/dist/checkpoint/id.d.ts +2 -0
  33. package/dist/checkpoint/id.js +35 -0
  34. package/dist/checkpoint/index.cjs +2 -2
  35. package/dist/checkpoint/index.d.ts +2 -2
  36. package/dist/checkpoint/index.js +2 -2
  37. package/dist/checkpoint/memory.cjs +63 -49
  38. package/dist/checkpoint/memory.d.ts +7 -10
  39. package/dist/checkpoint/memory.js +62 -47
  40. package/dist/checkpoint/sqlite.cjs +170 -0
  41. package/dist/checkpoint/sqlite.d.ts +14 -0
  42. package/dist/checkpoint/sqlite.js +163 -0
  43. package/dist/constants.cjs +3 -1
  44. package/dist/constants.d.ts +2 -0
  45. package/dist/constants.js +2 -0
  46. package/dist/errors.cjs +31 -0
  47. package/dist/errors.d.ts +12 -0
  48. package/dist/errors.js +24 -0
  49. package/dist/graph/graph.cjs +234 -96
  50. package/dist/graph/graph.d.ts +52 -23
  51. package/dist/graph/graph.js +233 -97
  52. package/dist/graph/index.cjs +2 -2
  53. package/dist/graph/index.d.ts +2 -2
  54. package/dist/graph/index.js +2 -2
  55. package/dist/graph/message.cjs +4 -3
  56. package/dist/graph/message.d.ts +4 -1
  57. package/dist/graph/message.js +4 -3
  58. package/dist/graph/state.cjs +237 -102
  59. package/dist/graph/state.d.ts +41 -18
  60. package/dist/graph/state.js +238 -104
  61. package/dist/index.cjs +6 -2
  62. package/dist/index.d.ts +3 -2
  63. package/dist/index.js +2 -1
  64. package/dist/prebuilt/agent_executor.cjs +22 -36
  65. package/dist/prebuilt/agent_executor.d.ts +7 -10
  66. package/dist/prebuilt/agent_executor.js +23 -37
  67. package/dist/prebuilt/chat_agent_executor.cjs +13 -13
  68. package/dist/prebuilt/chat_agent_executor.d.ts +3 -1
  69. package/dist/prebuilt/chat_agent_executor.js +15 -15
  70. package/dist/prebuilt/index.cjs +4 -1
  71. package/dist/prebuilt/index.d.ts +1 -0
  72. package/dist/prebuilt/index.js +1 -0
  73. package/dist/prebuilt/tool_node.cjs +59 -0
  74. package/dist/prebuilt/tool_node.d.ts +17 -0
  75. package/dist/prebuilt/tool_node.js +54 -0
  76. package/dist/pregel/debug.cjs +6 -8
  77. package/dist/pregel/debug.d.ts +2 -2
  78. package/dist/pregel/debug.js +5 -7
  79. package/dist/pregel/index.cjs +406 -236
  80. package/dist/pregel/index.d.ts +77 -41
  81. package/dist/pregel/index.js +408 -241
  82. package/dist/pregel/io.cjs +117 -30
  83. package/dist/pregel/io.d.ts +11 -3
  84. package/dist/pregel/io.js +111 -28
  85. package/dist/pregel/read.cjs +126 -46
  86. package/dist/pregel/read.d.ts +27 -18
  87. package/dist/pregel/read.js +125 -45
  88. package/dist/pregel/types.cjs +2 -0
  89. package/dist/pregel/types.d.ts +32 -0
  90. package/dist/pregel/types.js +1 -0
  91. package/dist/pregel/validate.cjs +58 -51
  92. package/dist/pregel/validate.d.ts +14 -13
  93. package/dist/pregel/validate.js +56 -50
  94. package/dist/pregel/write.cjs +46 -30
  95. package/dist/pregel/write.d.ts +18 -8
  96. package/dist/pregel/write.js +45 -29
  97. package/dist/serde/base.cjs +2 -0
  98. package/dist/serde/base.d.ts +4 -0
  99. package/dist/serde/base.js +1 -0
  100. package/dist/setup/async_local_storage.cjs +2 -2
  101. package/dist/setup/async_local_storage.js +1 -1
  102. package/dist/tests/channels.test.d.ts +1 -0
  103. package/dist/tests/channels.test.js +151 -0
  104. package/dist/tests/chatbot.int.test.d.ts +1 -0
  105. package/dist/tests/chatbot.int.test.js +61 -0
  106. package/dist/tests/checkpoints.test.d.ts +1 -0
  107. package/dist/tests/checkpoints.test.js +190 -0
  108. package/dist/tests/graph.test.d.ts +1 -0
  109. package/dist/tests/graph.test.js +15 -0
  110. package/dist/tests/prebuilt.int.test.d.ts +1 -0
  111. package/dist/tests/prebuilt.int.test.js +101 -0
  112. package/dist/tests/prebuilt.test.d.ts +1 -0
  113. package/dist/tests/prebuilt.test.js +195 -0
  114. package/dist/tests/pregel.io.test.d.ts +1 -0
  115. package/dist/tests/pregel.io.test.js +332 -0
  116. package/dist/tests/pregel.read.test.d.ts +1 -0
  117. package/dist/tests/pregel.read.test.js +109 -0
  118. package/dist/tests/pregel.test.d.ts +1 -0
  119. package/dist/tests/pregel.test.js +1879 -0
  120. package/dist/tests/pregel.validate.test.d.ts +1 -0
  121. package/dist/tests/pregel.validate.test.js +198 -0
  122. package/dist/tests/pregel.write.test.d.ts +1 -0
  123. package/dist/tests/pregel.write.test.js +44 -0
  124. package/dist/tests/tracing.int.test.d.ts +1 -0
  125. package/dist/tests/tracing.int.test.js +449 -0
  126. package/dist/tests/utils.d.ts +22 -0
  127. package/dist/tests/utils.js +76 -0
  128. package/dist/utils.cjs +74 -0
  129. package/dist/utils.d.ts +18 -0
  130. package/dist/utils.js +70 -0
  131. package/package.json +12 -8
  132. package/dist/pregel/reserved.cjs +0 -6
  133. package/dist/pregel/reserved.d.ts +0 -3
  134. package/dist/pregel/reserved.js +0 -3
@@ -1,75 +1,111 @@
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 } 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
+ _defaults(config: PregelOptions<Nn, Cc>): [
89
+ boolean,
90
+ StreamMode,
91
+ // stream mode
92
+ keyof Cc | Array<keyof Cc>,
93
+ // input keys
94
+ keyof Cc | Array<keyof Cc>,
95
+ RunnableConfig,
96
+ // config without pregel keys
97
+ All | Array<keyof Nn>,
98
+ // interrupt before
99
+ All | Array<keyof Nn>
100
+ ];
101
+ _transform(input: AsyncGenerator<PregelInputType>, runManager?: CallbackManagerForChainRun, config?: PregelOptions<Nn, Cc>): AsyncGenerator<PregelOutputType>;
102
+ invoke(input: PregelInputType, options?: PregelOptions<Nn, Cc>): Promise<PregelOutputType>;
103
+ stream(input: PregelInputType, config?: PregelOptions<Nn, Cc>): Promise<IterableReadableStream<PregelOutputType>>;
104
+ transform(generator: AsyncGenerator<PregelInputType>, config?: PregelOptions<Nn, Cc>): AsyncGenerator<PregelOutputType>;
75
105
  }
106
+ 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;
107
+ 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;
108
+ export declare function _applyWrites<Cc extends Record<string, BaseChannel>>(checkpoint: Checkpoint, channels: Cc, pendingWrites: Array<[keyof Cc, unknown]>): void;
109
+ 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>];
110
+ 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>>];
111
+ export {};