@langchain/langgraph 1.0.7 → 1.0.12
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/package.json +7 -7
- package/CHANGELOG.md +0 -286
- package/dist/_virtual/rolldown_runtime.cjs +0 -25
- package/dist/channels/any_value.cjs +0 -46
- package/dist/channels/any_value.cjs.map +0 -1
- package/dist/channels/any_value.d.cts +0 -24
- package/dist/channels/any_value.d.cts.map +0 -1
- package/dist/channels/any_value.d.ts +0 -24
- package/dist/channels/any_value.d.ts.map +0 -1
- package/dist/channels/any_value.js +0 -46
- package/dist/channels/any_value.js.map +0 -1
- package/dist/channels/base.cjs +0 -102
- package/dist/channels/base.cjs.map +0 -1
- package/dist/channels/base.d.cts +0 -79
- package/dist/channels/base.d.cts.map +0 -1
- package/dist/channels/base.d.ts +0 -79
- package/dist/channels/base.d.ts.map +0 -1
- package/dist/channels/base.js +0 -97
- package/dist/channels/base.js.map +0 -1
- package/dist/channels/binop.cjs +0 -49
- package/dist/channels/binop.cjs.map +0 -1
- package/dist/channels/binop.d.cts +0 -22
- package/dist/channels/binop.d.cts.map +0 -1
- package/dist/channels/binop.d.ts +0 -22
- package/dist/channels/binop.d.ts.map +0 -1
- package/dist/channels/binop.js +0 -49
- package/dist/channels/binop.js.map +0 -1
- package/dist/channels/dynamic_barrier_value.cjs +0 -76
- package/dist/channels/dynamic_barrier_value.cjs.map +0 -1
- package/dist/channels/dynamic_barrier_value.d.cts +0 -42
- package/dist/channels/dynamic_barrier_value.d.cts.map +0 -1
- package/dist/channels/dynamic_barrier_value.d.ts +0 -42
- package/dist/channels/dynamic_barrier_value.d.ts.map +0 -1
- package/dist/channels/dynamic_barrier_value.js +0 -76
- package/dist/channels/dynamic_barrier_value.js.map +0 -1
- package/dist/channels/ephemeral_value.cjs +0 -46
- package/dist/channels/ephemeral_value.cjs.map +0 -1
- package/dist/channels/ephemeral_value.d.cts +0 -22
- package/dist/channels/ephemeral_value.d.cts.map +0 -1
- package/dist/channels/ephemeral_value.d.ts +0 -22
- package/dist/channels/ephemeral_value.d.ts.map +0 -1
- package/dist/channels/ephemeral_value.js +0 -46
- package/dist/channels/ephemeral_value.js.map +0 -1
- package/dist/channels/index.cjs +0 -21
- package/dist/channels/index.d.cts +0 -9
- package/dist/channels/index.d.ts +0 -9
- package/dist/channels/index.js +0 -10
- package/dist/channels/last_value.cjs +0 -98
- package/dist/channels/last_value.cjs.map +0 -1
- package/dist/channels/last_value.d.cts +0 -44
- package/dist/channels/last_value.d.cts.map +0 -1
- package/dist/channels/last_value.d.ts +0 -44
- package/dist/channels/last_value.d.ts.map +0 -1
- package/dist/channels/last_value.js +0 -97
- package/dist/channels/last_value.js.map +0 -1
- package/dist/channels/named_barrier_value.cjs +0 -118
- package/dist/channels/named_barrier_value.cjs.map +0 -1
- package/dist/channels/named_barrier_value.d.cts +0 -46
- package/dist/channels/named_barrier_value.d.cts.map +0 -1
- package/dist/channels/named_barrier_value.d.ts +0 -46
- package/dist/channels/named_barrier_value.d.ts.map +0 -1
- package/dist/channels/named_barrier_value.js +0 -116
- package/dist/channels/named_barrier_value.js.map +0 -1
- package/dist/channels/topic.cjs +0 -65
- package/dist/channels/topic.cjs.map +0 -1
- package/dist/channels/topic.d.cts +0 -32
- package/dist/channels/topic.d.cts.map +0 -1
- package/dist/channels/topic.d.ts +0 -32
- package/dist/channels/topic.d.ts.map +0 -1
- package/dist/channels/topic.js +0 -65
- package/dist/channels/topic.js.map +0 -1
- package/dist/constants.cjs +0 -406
- package/dist/constants.cjs.map +0 -1
- package/dist/constants.d.cts +0 -285
- package/dist/constants.d.cts.map +0 -1
- package/dist/constants.d.ts +0 -285
- package/dist/constants.d.ts.map +0 -1
- package/dist/constants.js +0 -362
- package/dist/constants.js.map +0 -1
- package/dist/errors.cjs +0 -163
- package/dist/errors.cjs.map +0 -1
- package/dist/errors.d.cts +0 -81
- package/dist/errors.d.cts.map +0 -1
- package/dist/errors.d.ts +0 -81
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js +0 -146
- package/dist/errors.js.map +0 -1
- package/dist/func/index.cjs +0 -301
- package/dist/func/index.cjs.map +0 -1
- package/dist/func/index.d.cts +0 -293
- package/dist/func/index.d.cts.map +0 -1
- package/dist/func/index.d.ts +0 -293
- package/dist/func/index.d.ts.map +0 -1
- package/dist/func/index.js +0 -298
- package/dist/func/index.js.map +0 -1
- package/dist/func/types.d.cts +0 -64
- package/dist/func/types.d.cts.map +0 -1
- package/dist/func/types.d.ts +0 -64
- package/dist/func/types.d.ts.map +0 -1
- package/dist/graph/annotation.cjs +0 -101
- package/dist/graph/annotation.cjs.map +0 -1
- package/dist/graph/annotation.d.cts +0 -116
- package/dist/graph/annotation.d.cts.map +0 -1
- package/dist/graph/annotation.d.ts +0 -116
- package/dist/graph/annotation.d.ts.map +0 -1
- package/dist/graph/annotation.js +0 -99
- package/dist/graph/annotation.js.map +0 -1
- package/dist/graph/graph.cjs +0 -423
- package/dist/graph/graph.cjs.map +0 -1
- package/dist/graph/graph.d.cts +0 -132
- package/dist/graph/graph.d.cts.map +0 -1
- package/dist/graph/graph.d.ts +0 -132
- package/dist/graph/graph.d.ts.map +0 -1
- package/dist/graph/graph.js +0 -420
- package/dist/graph/graph.js.map +0 -1
- package/dist/graph/index.cjs +0 -5
- package/dist/graph/index.js +0 -7
- package/dist/graph/message.cjs +0 -99
- package/dist/graph/message.cjs.map +0 -1
- package/dist/graph/message.d.cts +0 -40
- package/dist/graph/message.d.cts.map +0 -1
- package/dist/graph/message.d.ts +0 -40
- package/dist/graph/message.d.ts.map +0 -1
- package/dist/graph/message.js +0 -95
- package/dist/graph/message.js.map +0 -1
- package/dist/graph/messages_annotation.cjs +0 -110
- package/dist/graph/messages_annotation.cjs.map +0 -1
- package/dist/graph/messages_annotation.d.cts +0 -112
- package/dist/graph/messages_annotation.d.cts.map +0 -1
- package/dist/graph/messages_annotation.d.ts +0 -112
- package/dist/graph/messages_annotation.d.ts.map +0 -1
- package/dist/graph/messages_annotation.js +0 -107
- package/dist/graph/messages_annotation.js.map +0 -1
- package/dist/graph/state.cjs +0 -501
- package/dist/graph/state.cjs.map +0 -1
- package/dist/graph/state.d.cts +0 -236
- package/dist/graph/state.d.cts.map +0 -1
- package/dist/graph/state.d.ts +0 -236
- package/dist/graph/state.d.ts.map +0 -1
- package/dist/graph/state.js +0 -499
- package/dist/graph/state.js.map +0 -1
- package/dist/graph/zod/index.cjs +0 -10
- package/dist/graph/zod/index.d.cts +0 -3
- package/dist/graph/zod/index.d.ts +0 -3
- package/dist/graph/zod/index.js +0 -5
- package/dist/graph/zod/meta.cjs +0 -145
- package/dist/graph/zod/meta.cjs.map +0 -1
- package/dist/graph/zod/meta.d.cts +0 -116
- package/dist/graph/zod/meta.d.cts.map +0 -1
- package/dist/graph/zod/meta.d.ts +0 -116
- package/dist/graph/zod/meta.d.ts.map +0 -1
- package/dist/graph/zod/meta.js +0 -141
- package/dist/graph/zod/meta.js.map +0 -1
- package/dist/graph/zod/plugin.cjs +0 -41
- package/dist/graph/zod/plugin.cjs.map +0 -1
- package/dist/graph/zod/plugin.js +0 -41
- package/dist/graph/zod/plugin.js.map +0 -1
- package/dist/graph/zod/schema.cjs +0 -99
- package/dist/graph/zod/schema.cjs.map +0 -1
- package/dist/graph/zod/schema.d.cts +0 -38
- package/dist/graph/zod/schema.d.cts.map +0 -1
- package/dist/graph/zod/schema.d.ts +0 -38
- package/dist/graph/zod/schema.d.ts.map +0 -1
- package/dist/graph/zod/schema.js +0 -94
- package/dist/graph/zod/schema.js.map +0 -1
- package/dist/graph/zod/zod-registry.cjs +0 -43
- package/dist/graph/zod/zod-registry.cjs.map +0 -1
- package/dist/graph/zod/zod-registry.d.cts +0 -51
- package/dist/graph/zod/zod-registry.d.cts.map +0 -1
- package/dist/graph/zod/zod-registry.d.ts +0 -51
- package/dist/graph/zod/zod-registry.d.ts.map +0 -1
- package/dist/graph/zod/zod-registry.js +0 -41
- package/dist/graph/zod/zod-registry.js.map +0 -1
- package/dist/hash.cjs +0 -271
- package/dist/hash.cjs.map +0 -1
- package/dist/hash.js +0 -269
- package/dist/hash.js.map +0 -1
- package/dist/index.cjs +0 -112
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -26
- package/dist/index.d.ts +0 -26
- package/dist/index.js +0 -22
- package/dist/index.js.map +0 -1
- package/dist/interrupt.cjs +0 -82
- package/dist/interrupt.cjs.map +0 -1
- package/dist/interrupt.d.cts +0 -58
- package/dist/interrupt.d.cts.map +0 -1
- package/dist/interrupt.d.ts +0 -58
- package/dist/interrupt.d.ts.map +0 -1
- package/dist/interrupt.js +0 -81
- package/dist/interrupt.js.map +0 -1
- package/dist/prebuilt/agentName.cjs +0 -153
- package/dist/prebuilt/agentName.cjs.map +0 -1
- package/dist/prebuilt/agentName.d.cts +0 -42
- package/dist/prebuilt/agentName.d.cts.map +0 -1
- package/dist/prebuilt/agentName.d.ts +0 -42
- package/dist/prebuilt/agentName.d.ts.map +0 -1
- package/dist/prebuilt/agentName.js +0 -152
- package/dist/prebuilt/agentName.js.map +0 -1
- package/dist/prebuilt/agent_executor.cjs +0 -44
- package/dist/prebuilt/agent_executor.cjs.map +0 -1
- package/dist/prebuilt/agent_executor.d.cts +0 -58
- package/dist/prebuilt/agent_executor.d.cts.map +0 -1
- package/dist/prebuilt/agent_executor.d.ts +0 -58
- package/dist/prebuilt/agent_executor.d.ts.map +0 -1
- package/dist/prebuilt/agent_executor.js +0 -44
- package/dist/prebuilt/agent_executor.js.map +0 -1
- package/dist/prebuilt/chat_agent_executor.cjs +0 -68
- package/dist/prebuilt/chat_agent_executor.cjs.map +0 -1
- package/dist/prebuilt/chat_agent_executor.d.cts +0 -23
- package/dist/prebuilt/chat_agent_executor.d.cts.map +0 -1
- package/dist/prebuilt/chat_agent_executor.d.ts +0 -23
- package/dist/prebuilt/chat_agent_executor.d.ts.map +0 -1
- package/dist/prebuilt/chat_agent_executor.js +0 -67
- package/dist/prebuilt/chat_agent_executor.js.map +0 -1
- package/dist/prebuilt/index.cjs +0 -15
- package/dist/prebuilt/index.d.cts +0 -8
- package/dist/prebuilt/index.d.ts +0 -8
- package/dist/prebuilt/index.js +0 -8
- package/dist/prebuilt/interrupt.d.cts +0 -61
- package/dist/prebuilt/interrupt.d.cts.map +0 -1
- package/dist/prebuilt/interrupt.d.ts +0 -61
- package/dist/prebuilt/interrupt.d.ts.map +0 -1
- package/dist/prebuilt/react_agent_executor.cjs +0 -344
- package/dist/prebuilt/react_agent_executor.cjs.map +0 -1
- package/dist/prebuilt/react_agent_executor.d.cts +0 -230
- package/dist/prebuilt/react_agent_executor.d.cts.map +0 -1
- package/dist/prebuilt/react_agent_executor.d.ts +0 -230
- package/dist/prebuilt/react_agent_executor.d.ts.map +0 -1
- package/dist/prebuilt/react_agent_executor.js +0 -342
- package/dist/prebuilt/react_agent_executor.js.map +0 -1
- package/dist/prebuilt/tool_executor.cjs +0 -48
- package/dist/prebuilt/tool_executor.cjs.map +0 -1
- package/dist/prebuilt/tool_executor.d.cts +0 -42
- package/dist/prebuilt/tool_executor.d.cts.map +0 -1
- package/dist/prebuilt/tool_executor.d.ts +0 -42
- package/dist/prebuilt/tool_executor.d.ts.map +0 -1
- package/dist/prebuilt/tool_executor.js +0 -47
- package/dist/prebuilt/tool_executor.js.map +0 -1
- package/dist/prebuilt/tool_node.cjs +0 -248
- package/dist/prebuilt/tool_node.cjs.map +0 -1
- package/dist/prebuilt/tool_node.d.cts +0 -182
- package/dist/prebuilt/tool_node.d.cts.map +0 -1
- package/dist/prebuilt/tool_node.d.ts +0 -182
- package/dist/prebuilt/tool_node.d.ts.map +0 -1
- package/dist/prebuilt/tool_node.js +0 -246
- package/dist/prebuilt/tool_node.js.map +0 -1
- package/dist/pregel/algo.cjs +0 -573
- package/dist/pregel/algo.cjs.map +0 -1
- package/dist/pregel/algo.d.cts +0 -13
- package/dist/pregel/algo.d.cts.map +0 -1
- package/dist/pregel/algo.d.ts +0 -13
- package/dist/pregel/algo.d.ts.map +0 -1
- package/dist/pregel/algo.js +0 -567
- package/dist/pregel/algo.js.map +0 -1
- package/dist/pregel/call.cjs +0 -53
- package/dist/pregel/call.cjs.map +0 -1
- package/dist/pregel/call.js +0 -50
- package/dist/pregel/call.js.map +0 -1
- package/dist/pregel/debug.cjs +0 -175
- package/dist/pregel/debug.cjs.map +0 -1
- package/dist/pregel/debug.js +0 -169
- package/dist/pregel/debug.js.map +0 -1
- package/dist/pregel/index.cjs +0 -1170
- package/dist/pregel/index.cjs.map +0 -1
- package/dist/pregel/index.d.cts +0 -546
- package/dist/pregel/index.d.cts.map +0 -1
- package/dist/pregel/index.d.ts +0 -546
- package/dist/pregel/index.d.ts.map +0 -1
- package/dist/pregel/index.js +0 -1168
- package/dist/pregel/index.js.map +0 -1
- package/dist/pregel/io.cjs +0 -140
- package/dist/pregel/io.cjs.map +0 -1
- package/dist/pregel/io.js +0 -135
- package/dist/pregel/io.js.map +0 -1
- package/dist/pregel/loop.cjs +0 -548
- package/dist/pregel/loop.cjs.map +0 -1
- package/dist/pregel/loop.js +0 -547
- package/dist/pregel/loop.js.map +0 -1
- package/dist/pregel/messages.cjs +0 -108
- package/dist/pregel/messages.cjs.map +0 -1
- package/dist/pregel/messages.js +0 -107
- package/dist/pregel/messages.js.map +0 -1
- package/dist/pregel/read.cjs +0 -152
- package/dist/pregel/read.cjs.map +0 -1
- package/dist/pregel/read.d.cts +0 -51
- package/dist/pregel/read.d.cts.map +0 -1
- package/dist/pregel/read.d.ts +0 -51
- package/dist/pregel/read.d.ts.map +0 -1
- package/dist/pregel/read.js +0 -150
- package/dist/pregel/read.js.map +0 -1
- package/dist/pregel/remote.cjs +0 -349
- package/dist/pregel/remote.cjs.map +0 -1
- package/dist/pregel/remote.d.cts +0 -123
- package/dist/pregel/remote.d.cts.map +0 -1
- package/dist/pregel/remote.d.ts +0 -123
- package/dist/pregel/remote.d.ts.map +0 -1
- package/dist/pregel/remote.js +0 -348
- package/dist/pregel/remote.js.map +0 -1
- package/dist/pregel/retry.cjs +0 -92
- package/dist/pregel/retry.cjs.map +0 -1
- package/dist/pregel/retry.js +0 -92
- package/dist/pregel/retry.js.map +0 -1
- package/dist/pregel/runnable_types.d.cts +0 -49
- package/dist/pregel/runnable_types.d.cts.map +0 -1
- package/dist/pregel/runnable_types.d.ts +0 -49
- package/dist/pregel/runnable_types.d.ts.map +0 -1
- package/dist/pregel/runner.cjs +0 -228
- package/dist/pregel/runner.cjs.map +0 -1
- package/dist/pregel/runner.js +0 -228
- package/dist/pregel/runner.js.map +0 -1
- package/dist/pregel/stream.cjs +0 -199
- package/dist/pregel/stream.cjs.map +0 -1
- package/dist/pregel/stream.js +0 -196
- package/dist/pregel/stream.js.map +0 -1
- package/dist/pregel/types.cjs +0 -27
- package/dist/pregel/types.cjs.map +0 -1
- package/dist/pregel/types.d.cts +0 -453
- package/dist/pregel/types.d.cts.map +0 -1
- package/dist/pregel/types.d.ts +0 -453
- package/dist/pregel/types.d.ts.map +0 -1
- package/dist/pregel/types.js +0 -25
- package/dist/pregel/types.js.map +0 -1
- package/dist/pregel/utils/config.cjs +0 -122
- package/dist/pregel/utils/config.cjs.map +0 -1
- package/dist/pregel/utils/config.d.cts +0 -36
- package/dist/pregel/utils/config.d.cts.map +0 -1
- package/dist/pregel/utils/config.d.ts +0 -36
- package/dist/pregel/utils/config.d.ts.map +0 -1
- package/dist/pregel/utils/config.js +0 -115
- package/dist/pregel/utils/config.js.map +0 -1
- package/dist/pregel/utils/index.cjs +0 -103
- package/dist/pregel/utils/index.cjs.map +0 -1
- package/dist/pregel/utils/index.d.cts +0 -51
- package/dist/pregel/utils/index.d.cts.map +0 -1
- package/dist/pregel/utils/index.d.ts +0 -51
- package/dist/pregel/utils/index.d.ts.map +0 -1
- package/dist/pregel/utils/index.js +0 -97
- package/dist/pregel/utils/index.js.map +0 -1
- package/dist/pregel/utils/subgraph.cjs +0 -19
- package/dist/pregel/utils/subgraph.cjs.map +0 -1
- package/dist/pregel/utils/subgraph.js +0 -17
- package/dist/pregel/utils/subgraph.js.map +0 -1
- package/dist/pregel/validate.cjs +0 -45
- package/dist/pregel/validate.cjs.map +0 -1
- package/dist/pregel/validate.js +0 -44
- package/dist/pregel/validate.js.map +0 -1
- package/dist/pregel/write.cjs +0 -97
- package/dist/pregel/write.cjs.map +0 -1
- package/dist/pregel/write.d.cts +0 -35
- package/dist/pregel/write.d.cts.map +0 -1
- package/dist/pregel/write.d.ts +0 -35
- package/dist/pregel/write.d.ts.map +0 -1
- package/dist/pregel/write.js +0 -95
- package/dist/pregel/write.js.map +0 -1
- package/dist/remote.cjs +0 -3
- package/dist/remote.d.cts +0 -2
- package/dist/remote.d.ts +0 -2
- package/dist/remote.js +0 -3
- package/dist/setup/async_local_storage.cjs +0 -12
- package/dist/setup/async_local_storage.cjs.map +0 -1
- package/dist/setup/async_local_storage.js +0 -11
- package/dist/setup/async_local_storage.js.map +0 -1
- package/dist/utils.cjs +0 -88
- package/dist/utils.cjs.map +0 -1
- package/dist/utils.d.cts +0 -32
- package/dist/utils.d.cts.map +0 -1
- package/dist/utils.d.ts +0 -32
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -81
- package/dist/utils.js.map +0 -1
- package/dist/web.cjs +0 -96
- package/dist/web.d.cts +0 -23
- package/dist/web.d.ts +0 -23
- package/dist/web.js +0 -15
- package/dist/writer.cjs +0 -15
- package/dist/writer.cjs.map +0 -1
- package/dist/writer.d.cts +0 -7
- package/dist/writer.d.cts.map +0 -1
- package/dist/writer.d.ts +0 -7
- package/dist/writer.d.ts.map +0 -1
- package/dist/writer.js +0 -14
- package/dist/writer.js.map +0 -1
package/dist/graph/zod/meta.cjs
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
-
const require_binop = require('../../channels/binop.cjs');
|
|
3
|
-
const require_last_value = require('../../channels/last_value.cjs');
|
|
4
|
-
const __langchain_core_utils_types = require_rolldown_runtime.__toESM(require("@langchain/core/utils/types"));
|
|
5
|
-
|
|
6
|
-
//#region src/graph/zod/meta.ts
|
|
7
|
-
const META_EXTRAS_DESCRIPTION_PREFIX = "lg:";
|
|
8
|
-
/**
|
|
9
|
-
* A registry for storing and managing metadata associated with schemas.
|
|
10
|
-
* This class provides methods to get, extend, remove, and check metadata for a given schema.
|
|
11
|
-
*/
|
|
12
|
-
var SchemaMetaRegistry = class {
|
|
13
|
-
/**
|
|
14
|
-
* Internal map storing schema metadata.
|
|
15
|
-
* @internal
|
|
16
|
-
*/
|
|
17
|
-
_map = /* @__PURE__ */ new WeakMap();
|
|
18
|
-
/**
|
|
19
|
-
* Cache for extended schfemas.
|
|
20
|
-
* @internal
|
|
21
|
-
*/
|
|
22
|
-
_extensionCache = /* @__PURE__ */ new Map();
|
|
23
|
-
/**
|
|
24
|
-
* Retrieves the metadata associated with a given schema.
|
|
25
|
-
* @template TValue The value type of the schema.
|
|
26
|
-
* @template TUpdate The update type of the schema (defaults to TValue).
|
|
27
|
-
* @param schema The schema to retrieve metadata for.
|
|
28
|
-
* @returns The associated SchemaMeta, or undefined if not present.
|
|
29
|
-
*/
|
|
30
|
-
get(schema) {
|
|
31
|
-
return this._map.get(schema);
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Extends or sets the metadata for a given schema.
|
|
35
|
-
* @template TValue The value type of the schema.
|
|
36
|
-
* @template TUpdate The update type of the schema (defaults to TValue).
|
|
37
|
-
* @param schema The schema to extend metadata for.
|
|
38
|
-
* @param predicate A function that receives the existing metadata (or undefined) and returns the new metadata.
|
|
39
|
-
*/
|
|
40
|
-
extend(schema, predicate) {
|
|
41
|
-
const existingMeta = this.get(schema);
|
|
42
|
-
this._map.set(schema, predicate(existingMeta));
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Removes the metadata associated with a given schema.
|
|
46
|
-
* @param schema The schema to remove metadata for.
|
|
47
|
-
* @returns The SchemaMetaRegistry instance (for chaining).
|
|
48
|
-
*/
|
|
49
|
-
remove(schema) {
|
|
50
|
-
this._map.delete(schema);
|
|
51
|
-
return this;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Checks if metadata exists for a given schema.
|
|
55
|
-
* @param schema The schema to check.
|
|
56
|
-
* @returns True if metadata exists, false otherwise.
|
|
57
|
-
*/
|
|
58
|
-
has(schema) {
|
|
59
|
-
return this._map.has(schema);
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Returns a mapping of channel instances for each property in the schema
|
|
63
|
-
* using the associated metadata in the registry.
|
|
64
|
-
*
|
|
65
|
-
* This is used to create the `channels` object that's passed to the `Graph` constructor.
|
|
66
|
-
*
|
|
67
|
-
* @template T The shape of the schema.
|
|
68
|
-
* @param schema The schema to extract channels from.
|
|
69
|
-
* @returns A mapping from property names to channel instances.
|
|
70
|
-
*/
|
|
71
|
-
getChannelsForSchema(schema) {
|
|
72
|
-
const channels = {};
|
|
73
|
-
const shape = (0, __langchain_core_utils_types.getInteropZodObjectShape)(schema);
|
|
74
|
-
for (const [key, channelSchema] of Object.entries(shape)) {
|
|
75
|
-
const meta = this.get(channelSchema);
|
|
76
|
-
if (meta?.reducer) channels[key] = new require_binop.BinaryOperatorAggregate(meta.reducer.fn, meta.default);
|
|
77
|
-
else channels[key] = new require_last_value.LastValue(meta?.default);
|
|
78
|
-
}
|
|
79
|
-
return channels;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Returns a modified schema that introspectively looks at all keys of the provided
|
|
83
|
-
* object schema, and applies the augmentations based on meta provided with those keys
|
|
84
|
-
* in the registry and the selectors provided in the `effects` parameter.
|
|
85
|
-
*
|
|
86
|
-
* This assumes that the passed in schema is the "root" schema object for a graph where
|
|
87
|
-
* the keys of the schema are the channels of the graph. Because we need to represent
|
|
88
|
-
* the input of a graph in a couple of different ways, the `effects` parameter allows
|
|
89
|
-
* us to apply those augmentations based on pre determined conditions.
|
|
90
|
-
*
|
|
91
|
-
* @param schema The root schema object to extend.
|
|
92
|
-
* @param effects The effects that are being applied.
|
|
93
|
-
* @returns The extended schema.
|
|
94
|
-
*/
|
|
95
|
-
getExtendedChannelSchemas(schema, effects) {
|
|
96
|
-
if (Object.keys(effects).length === 0) return schema;
|
|
97
|
-
const cacheKey = Object.entries(effects).filter(([, v]) => v === true).sort(([a], [b]) => a.localeCompare(b)).map(([k, v]) => `${k}:${v}`).join("|");
|
|
98
|
-
const cache = this._extensionCache.get(cacheKey) ?? /* @__PURE__ */ new WeakMap();
|
|
99
|
-
if (cache.has(schema)) return cache.get(schema);
|
|
100
|
-
let modifiedSchema = schema;
|
|
101
|
-
if (effects.withReducerSchema || effects.withJsonSchemaExtrasAsDescription) {
|
|
102
|
-
const newShapeEntries = Object.entries((0, __langchain_core_utils_types.getInteropZodObjectShape)(schema)).map(([key, schema$1]) => {
|
|
103
|
-
const meta = this.get(schema$1);
|
|
104
|
-
let outputSchema = effects.withReducerSchema ? meta?.reducer?.schema ?? schema$1 : schema$1;
|
|
105
|
-
if (effects.withJsonSchemaExtrasAsDescription && meta?.jsonSchemaExtra) {
|
|
106
|
-
const description = (0, __langchain_core_utils_types.getSchemaDescription)(outputSchema) ?? (0, __langchain_core_utils_types.getSchemaDescription)(schema$1);
|
|
107
|
-
const strExtras = JSON.stringify({
|
|
108
|
-
...meta.jsonSchemaExtra,
|
|
109
|
-
description
|
|
110
|
-
});
|
|
111
|
-
outputSchema = outputSchema.describe(`${META_EXTRAS_DESCRIPTION_PREFIX}${strExtras}`);
|
|
112
|
-
}
|
|
113
|
-
return [key, outputSchema];
|
|
114
|
-
});
|
|
115
|
-
modifiedSchema = (0, __langchain_core_utils_types.extendInteropZodObject)(schema, Object.fromEntries(newShapeEntries));
|
|
116
|
-
if ((0, __langchain_core_utils_types.isZodSchemaV3)(modifiedSchema)) modifiedSchema._def.unknownKeys = "strip";
|
|
117
|
-
}
|
|
118
|
-
if (effects.asPartial) modifiedSchema = (0, __langchain_core_utils_types.interopZodObjectPartial)(modifiedSchema);
|
|
119
|
-
cache.set(schema, modifiedSchema);
|
|
120
|
-
this._extensionCache.set(cacheKey, cache);
|
|
121
|
-
return modifiedSchema;
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
const schemaMetaRegistry = new SchemaMetaRegistry();
|
|
125
|
-
function withLangGraph(schema, meta) {
|
|
126
|
-
if (meta.reducer && !meta.default) {
|
|
127
|
-
const defaultValueGetter = (0, __langchain_core_utils_types.getInteropZodDefaultGetter)(schema);
|
|
128
|
-
if (defaultValueGetter != null) meta.default = defaultValueGetter;
|
|
129
|
-
}
|
|
130
|
-
if (meta.reducer) {
|
|
131
|
-
const schemaWithReducer = Object.assign(schema, { lg_reducer_schema: meta.reducer?.schema ?? schema });
|
|
132
|
-
schemaMetaRegistry.extend(schemaWithReducer, () => meta);
|
|
133
|
-
return schemaWithReducer;
|
|
134
|
-
} else {
|
|
135
|
-
schemaMetaRegistry.extend(schema, () => meta);
|
|
136
|
-
return schema;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
//#endregion
|
|
141
|
-
exports.META_EXTRAS_DESCRIPTION_PREFIX = META_EXTRAS_DESCRIPTION_PREFIX;
|
|
142
|
-
exports.SchemaMetaRegistry = SchemaMetaRegistry;
|
|
143
|
-
exports.schemaMetaRegistry = schemaMetaRegistry;
|
|
144
|
-
exports.withLangGraph = withLangGraph;
|
|
145
|
-
//# sourceMappingURL=meta.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"meta.cjs","names":["BinaryOperatorAggregate","LastValue","modifiedSchema: InteropZodObject","schema"],"sources":["../../../src/graph/zod/meta.ts"],"sourcesContent":["import {\n InferInteropZodOutput,\n InteropZodObject,\n InteropZodType,\n getInteropZodObjectShape,\n extendInteropZodObject,\n getInteropZodDefaultGetter,\n interopZodObjectPartial,\n InteropZodObjectShape,\n isZodSchemaV3,\n getSchemaDescription,\n} from \"@langchain/core/utils/types\";\nimport { BaseChannel } from \"../../channels/base.js\";\nimport { BinaryOperatorAggregate } from \"../../channels/binop.js\";\nimport { LastValue } from \"../../channels/last_value.js\";\n\nexport const META_EXTRAS_DESCRIPTION_PREFIX = \"lg:\";\n\n/** @internal */\nexport type ReducedZodChannel<\n T extends InteropZodType,\n TReducerSchema extends InteropZodType\n> = T & {\n lg_reducer_schema: TReducerSchema;\n};\n\n/** @internal */\nexport type InteropZodToStateDefinition<\n T extends InteropZodObject,\n TShape = InteropZodObjectShape<T>\n> = {\n [key in keyof TShape]: TShape[key] extends ReducedZodChannel<\n infer Schema,\n infer ReducerSchema\n >\n ? Schema extends InteropZodType<infer V>\n ? ReducerSchema extends InteropZodType<infer U>\n ? BaseChannel<V, U>\n : never\n : never\n : TShape[key] extends InteropZodType<infer V, infer U>\n ? BaseChannel<V, U>\n : never;\n};\n\nexport type UpdateType<\n T extends InteropZodObject,\n TShape = InteropZodObjectShape<T>\n> = {\n [key in keyof TShape]?: TShape[key] extends ReducedZodChannel<\n infer Schema,\n infer ReducerSchema\n >\n ? Schema extends InteropZodType<unknown>\n ? ReducerSchema extends InteropZodType<infer U>\n ? U\n : never\n : never\n : TShape[key] extends InteropZodType<unknown, infer U>\n ? U\n : never;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface SchemaMeta<TValue = any, TUpdate = TValue> {\n jsonSchemaExtra?: {\n langgraph_nodes?: string[];\n langgraph_type?: \"prompt\" | \"messages\";\n [key: string]: unknown;\n };\n reducer?: {\n schema?: InteropZodType<TUpdate>;\n fn: (a: TValue, b: TUpdate) => TValue;\n };\n default?: () => TValue;\n}\n\n/**\n * A registry for storing and managing metadata associated with schemas.\n * This class provides methods to get, extend, remove, and check metadata for a given schema.\n */\nexport class SchemaMetaRegistry {\n /**\n * Internal map storing schema metadata.\n * @internal\n */\n _map = new WeakMap<InteropZodType, SchemaMeta>();\n\n /**\n * Cache for extended schfemas.\n * @internal\n */\n _extensionCache = new Map<string, WeakMap<InteropZodType, InteropZodType>>();\n\n /**\n * Retrieves the metadata associated with a given schema.\n * @template TValue The value type of the schema.\n * @template TUpdate The update type of the schema (defaults to TValue).\n * @param schema The schema to retrieve metadata for.\n * @returns The associated SchemaMeta, or undefined if not present.\n */\n get<TValue, TUpdate = TValue>(\n schema: InteropZodType<TValue>\n ): SchemaMeta<TValue, TUpdate> | undefined {\n return this._map.get(schema);\n }\n\n /**\n * Extends or sets the metadata for a given schema.\n * @template TValue The value type of the schema.\n * @template TUpdate The update type of the schema (defaults to TValue).\n * @param schema The schema to extend metadata for.\n * @param predicate A function that receives the existing metadata (or undefined) and returns the new metadata.\n */\n extend<TValue, TUpdate>(\n schema: InteropZodType<TValue>,\n predicate: (\n meta: SchemaMeta<TValue, TUpdate> | undefined\n ) => SchemaMeta<TValue, TUpdate>\n ) {\n const existingMeta = this.get<TValue, TUpdate>(schema);\n this._map.set(schema, predicate(existingMeta));\n }\n\n /**\n * Removes the metadata associated with a given schema.\n * @param schema The schema to remove metadata for.\n * @returns The SchemaMetaRegistry instance (for chaining).\n */\n remove(schema: InteropZodType): this {\n this._map.delete(schema);\n return this;\n }\n\n /**\n * Checks if metadata exists for a given schema.\n * @param schema The schema to check.\n * @returns True if metadata exists, false otherwise.\n */\n has(schema: InteropZodType): boolean {\n return this._map.has(schema);\n }\n\n /**\n * Returns a mapping of channel instances for each property in the schema\n * using the associated metadata in the registry.\n *\n * This is used to create the `channels` object that's passed to the `Graph` constructor.\n *\n * @template T The shape of the schema.\n * @param schema The schema to extract channels from.\n * @returns A mapping from property names to channel instances.\n */\n getChannelsForSchema<T extends InteropZodObject>(\n schema: T\n ): InteropZodToStateDefinition<T> {\n const channels = {} as Record<string, BaseChannel>;\n const shape = getInteropZodObjectShape(schema);\n for (const [key, channelSchema] of Object.entries(shape)) {\n const meta = this.get(channelSchema);\n if (meta?.reducer) {\n channels[key] = new BinaryOperatorAggregate<\n InferInteropZodOutput<typeof channelSchema>\n >(meta.reducer.fn, meta.default);\n } else {\n channels[key] = new LastValue(meta?.default);\n }\n }\n return channels as InteropZodToStateDefinition<T>;\n }\n\n /**\n * Returns a modified schema that introspectively looks at all keys of the provided\n * object schema, and applies the augmentations based on meta provided with those keys\n * in the registry and the selectors provided in the `effects` parameter.\n *\n * This assumes that the passed in schema is the \"root\" schema object for a graph where\n * the keys of the schema are the channels of the graph. Because we need to represent\n * the input of a graph in a couple of different ways, the `effects` parameter allows\n * us to apply those augmentations based on pre determined conditions.\n *\n * @param schema The root schema object to extend.\n * @param effects The effects that are being applied.\n * @returns The extended schema.\n */\n getExtendedChannelSchemas<T extends InteropZodObject>(\n schema: T,\n effects: {\n /**\n * Augments the shape by using the reducer's schema if it exists\n */\n withReducerSchema?: boolean;\n /**\n * Applies the stringified jsonSchemaExtra as a description to the schema.\n */\n withJsonSchemaExtrasAsDescription?: boolean;\n /**\n * Applies the `.partial()` modifier to the schema.\n */\n asPartial?: boolean;\n }\n ): InteropZodObject {\n // If no effects are being applied, return the schema unchanged\n if (Object.keys(effects).length === 0) {\n return schema;\n }\n\n // Cache key is determined by looking at the effects that are being applied\n const cacheKey = Object.entries(effects)\n .filter(([, v]) => v === true)\n .sort(([a], [b]) => a.localeCompare(b))\n .map(([k, v]) => `${k}:${v}`)\n .join(\"|\");\n\n const cache = this._extensionCache.get(cacheKey) ?? new WeakMap();\n if (cache.has(schema)) return cache.get(schema)! as T;\n\n let modifiedSchema: InteropZodObject = schema;\n\n if (\n effects.withReducerSchema ||\n effects.withJsonSchemaExtrasAsDescription\n ) {\n const newShapeEntries = Object.entries(\n getInteropZodObjectShape(schema)\n ).map(([key, schema]) => {\n const meta = this.get(schema);\n let outputSchema = effects.withReducerSchema\n ? meta?.reducer?.schema ?? schema\n : schema;\n if (\n effects.withJsonSchemaExtrasAsDescription &&\n meta?.jsonSchemaExtra\n ) {\n const description =\n getSchemaDescription(outputSchema) ?? getSchemaDescription(schema);\n const strExtras = JSON.stringify({\n ...meta.jsonSchemaExtra,\n description,\n });\n outputSchema = outputSchema.describe(\n `${META_EXTRAS_DESCRIPTION_PREFIX}${strExtras}`\n );\n }\n return [key, outputSchema];\n });\n modifiedSchema = extendInteropZodObject(\n schema,\n Object.fromEntries(newShapeEntries)\n );\n if (isZodSchemaV3(modifiedSchema)) {\n modifiedSchema._def.unknownKeys = \"strip\";\n }\n }\n if (effects.asPartial) {\n modifiedSchema = interopZodObjectPartial(modifiedSchema);\n }\n\n cache.set(schema, modifiedSchema);\n this._extensionCache.set(cacheKey, cache);\n return modifiedSchema;\n }\n}\n\nexport const schemaMetaRegistry = new SchemaMetaRegistry();\n\nexport function withLangGraph<\n TValue,\n TUpdate,\n TSchema extends InteropZodType<TValue>\n>(\n schema: TSchema,\n meta: SchemaMeta<TValue, TUpdate> & { reducer?: undefined }\n): TSchema;\nexport function withLangGraph<\n TValue,\n TUpdate,\n TSchema extends InteropZodType<TValue>\n>(\n schema: TSchema,\n meta: SchemaMeta<TValue, TUpdate>\n): ReducedZodChannel<TSchema, InteropZodType<TUpdate>>;\nexport function withLangGraph<\n TValue,\n TUpdate,\n TSchema extends InteropZodType<TValue>\n>(\n schema: TSchema,\n meta: SchemaMeta<TValue, TUpdate>\n): ReducedZodChannel<TSchema, InteropZodType<TUpdate>> | TSchema {\n if (meta.reducer && !meta.default) {\n const defaultValueGetter = getInteropZodDefaultGetter(schema);\n if (defaultValueGetter != null) {\n // eslint-disable-next-line no-param-reassign\n meta.default = defaultValueGetter;\n }\n }\n if (meta.reducer) {\n const schemaWithReducer = Object.assign(schema, {\n lg_reducer_schema: meta.reducer?.schema ?? schema,\n });\n schemaMetaRegistry.extend(schemaWithReducer, () => meta);\n return schemaWithReducer;\n } else {\n schemaMetaRegistry.extend(schema, () => meta);\n return schema;\n }\n}\n"],"mappings":";;;;;;AAgBA,MAAa,iCAAiC;;;;;AAiE9C,IAAa,qBAAb,MAAgC;;;;;CAK9B,uBAAO,IAAI;;;;;CAMX,kCAAkB,IAAI;;;;;;;;CAStB,IACE,QACyC;AACzC,SAAO,KAAK,KAAK,IAAI;;;;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,iCAAiC;;AAGxC,WAAO,CAAC,KAAK;;AAEf,6EACE,QACA,OAAO,YAAY;AAErB,uDAAkB,gBAChB,gBAAe,KAAK,cAAc;;AAGtC,MAAI,QAAQ,UACV,4EAAyC;AAG3C,QAAM,IAAI,QAAQ;AAClB,OAAK,gBAAgB,IAAI,UAAU;AACnC,SAAO;;;AAIX,MAAa,qBAAqB,IAAI;AAkBtC,SAAgB,cAKd,QACA,MAC+D;AAC/D,KAAI,KAAK,WAAW,CAAC,KAAK,SAAS;EACjC,MAAM,kFAAgD;AACtD,MAAI,sBAAsB,KAExB,MAAK,UAAU;;AAGnB,KAAI,KAAK,SAAS;EAChB,MAAM,oBAAoB,OAAO,OAAO,QAAQ,EAC9C,mBAAmB,KAAK,SAAS,UAAU;AAE7C,qBAAmB,OAAO,yBAAyB;AACnD,SAAO;QACF;AACL,qBAAmB,OAAO,cAAc;AACxC,SAAO"}
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { BaseChannel } from "../../channels/base.cjs";
|
|
2
|
-
import { InteropZodObject, InteropZodObjectShape, InteropZodType } from "@langchain/core/utils/types";
|
|
3
|
-
|
|
4
|
-
//#region src/graph/zod/meta.d.ts
|
|
5
|
-
declare const META_EXTRAS_DESCRIPTION_PREFIX = "lg:";
|
|
6
|
-
/** @internal */
|
|
7
|
-
type ReducedZodChannel<T extends InteropZodType, TReducerSchema extends InteropZodType> = T & {
|
|
8
|
-
lg_reducer_schema: TReducerSchema;
|
|
9
|
-
};
|
|
10
|
-
/** @internal */
|
|
11
|
-
type InteropZodToStateDefinition<T extends InteropZodObject, TShape = InteropZodObjectShape<T>> = { [key in keyof TShape]: TShape[key] extends ReducedZodChannel<infer Schema, infer ReducerSchema> ? Schema extends InteropZodType<infer V> ? ReducerSchema extends InteropZodType<infer U> ? BaseChannel<V, U> : never : never : TShape[key] extends InteropZodType<infer V, infer U> ? BaseChannel<V, U> : never };
|
|
12
|
-
type UpdateType<T extends InteropZodObject, TShape = InteropZodObjectShape<T>> = { [key in keyof TShape]?: TShape[key] extends ReducedZodChannel<infer Schema, infer ReducerSchema> ? Schema extends InteropZodType<unknown> ? ReducerSchema extends InteropZodType<infer U> ? U : never : never : TShape[key] extends InteropZodType<unknown, infer U> ? U : never };
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
-
interface SchemaMeta<TValue = any, TUpdate = TValue> {
|
|
15
|
-
jsonSchemaExtra?: {
|
|
16
|
-
langgraph_nodes?: string[];
|
|
17
|
-
langgraph_type?: "prompt" | "messages";
|
|
18
|
-
[key: string]: unknown;
|
|
19
|
-
};
|
|
20
|
-
reducer?: {
|
|
21
|
-
schema?: InteropZodType<TUpdate>;
|
|
22
|
-
fn: (a: TValue, b: TUpdate) => TValue;
|
|
23
|
-
};
|
|
24
|
-
default?: () => TValue;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* A registry for storing and managing metadata associated with schemas.
|
|
28
|
-
* This class provides methods to get, extend, remove, and check metadata for a given schema.
|
|
29
|
-
*/
|
|
30
|
-
declare class SchemaMetaRegistry {
|
|
31
|
-
/**
|
|
32
|
-
* Internal map storing schema metadata.
|
|
33
|
-
* @internal
|
|
34
|
-
*/
|
|
35
|
-
_map: WeakMap<InteropZodType, SchemaMeta<any, any>>;
|
|
36
|
-
/**
|
|
37
|
-
* Cache for extended schfemas.
|
|
38
|
-
* @internal
|
|
39
|
-
*/
|
|
40
|
-
_extensionCache: Map<string, WeakMap<InteropZodType, InteropZodType>>;
|
|
41
|
-
/**
|
|
42
|
-
* Retrieves the metadata associated with a given schema.
|
|
43
|
-
* @template TValue The value type of the schema.
|
|
44
|
-
* @template TUpdate The update type of the schema (defaults to TValue).
|
|
45
|
-
* @param schema The schema to retrieve metadata for.
|
|
46
|
-
* @returns The associated SchemaMeta, or undefined if not present.
|
|
47
|
-
*/
|
|
48
|
-
get<TValue, TUpdate = TValue>(schema: InteropZodType<TValue>): SchemaMeta<TValue, TUpdate> | undefined;
|
|
49
|
-
/**
|
|
50
|
-
* Extends or sets the metadata for a given schema.
|
|
51
|
-
* @template TValue The value type of the schema.
|
|
52
|
-
* @template TUpdate The update type of the schema (defaults to TValue).
|
|
53
|
-
* @param schema The schema to extend metadata for.
|
|
54
|
-
* @param predicate A function that receives the existing metadata (or undefined) and returns the new metadata.
|
|
55
|
-
*/
|
|
56
|
-
extend<TValue, TUpdate>(schema: InteropZodType<TValue>, predicate: (meta: SchemaMeta<TValue, TUpdate> | undefined) => SchemaMeta<TValue, TUpdate>): void;
|
|
57
|
-
/**
|
|
58
|
-
* Removes the metadata associated with a given schema.
|
|
59
|
-
* @param schema The schema to remove metadata for.
|
|
60
|
-
* @returns The SchemaMetaRegistry instance (for chaining).
|
|
61
|
-
*/
|
|
62
|
-
remove(schema: InteropZodType): this;
|
|
63
|
-
/**
|
|
64
|
-
* Checks if metadata exists for a given schema.
|
|
65
|
-
* @param schema The schema to check.
|
|
66
|
-
* @returns True if metadata exists, false otherwise.
|
|
67
|
-
*/
|
|
68
|
-
has(schema: InteropZodType): boolean;
|
|
69
|
-
/**
|
|
70
|
-
* Returns a mapping of channel instances for each property in the schema
|
|
71
|
-
* using the associated metadata in the registry.
|
|
72
|
-
*
|
|
73
|
-
* This is used to create the `channels` object that's passed to the `Graph` constructor.
|
|
74
|
-
*
|
|
75
|
-
* @template T The shape of the schema.
|
|
76
|
-
* @param schema The schema to extract channels from.
|
|
77
|
-
* @returns A mapping from property names to channel instances.
|
|
78
|
-
*/
|
|
79
|
-
getChannelsForSchema<T extends InteropZodObject>(schema: T): InteropZodToStateDefinition<T>;
|
|
80
|
-
/**
|
|
81
|
-
* Returns a modified schema that introspectively looks at all keys of the provided
|
|
82
|
-
* object schema, and applies the augmentations based on meta provided with those keys
|
|
83
|
-
* in the registry and the selectors provided in the `effects` parameter.
|
|
84
|
-
*
|
|
85
|
-
* This assumes that the passed in schema is the "root" schema object for a graph where
|
|
86
|
-
* the keys of the schema are the channels of the graph. Because we need to represent
|
|
87
|
-
* the input of a graph in a couple of different ways, the `effects` parameter allows
|
|
88
|
-
* us to apply those augmentations based on pre determined conditions.
|
|
89
|
-
*
|
|
90
|
-
* @param schema The root schema object to extend.
|
|
91
|
-
* @param effects The effects that are being applied.
|
|
92
|
-
* @returns The extended schema.
|
|
93
|
-
*/
|
|
94
|
-
getExtendedChannelSchemas<T extends InteropZodObject>(schema: T, effects: {
|
|
95
|
-
/**
|
|
96
|
-
* Augments the shape by using the reducer's schema if it exists
|
|
97
|
-
*/
|
|
98
|
-
withReducerSchema?: boolean;
|
|
99
|
-
/**
|
|
100
|
-
* Applies the stringified jsonSchemaExtra as a description to the schema.
|
|
101
|
-
*/
|
|
102
|
-
withJsonSchemaExtrasAsDescription?: boolean;
|
|
103
|
-
/**
|
|
104
|
-
* Applies the `.partial()` modifier to the schema.
|
|
105
|
-
*/
|
|
106
|
-
asPartial?: boolean;
|
|
107
|
-
}): InteropZodObject;
|
|
108
|
-
}
|
|
109
|
-
declare const schemaMetaRegistry: SchemaMetaRegistry;
|
|
110
|
-
declare function withLangGraph<TValue, TUpdate, TSchema extends InteropZodType<TValue>>(schema: TSchema, meta: SchemaMeta<TValue, TUpdate> & {
|
|
111
|
-
reducer?: undefined;
|
|
112
|
-
}): TSchema;
|
|
113
|
-
declare function withLangGraph<TValue, TUpdate, TSchema extends InteropZodType<TValue>>(schema: TSchema, meta: SchemaMeta<TValue, TUpdate>): ReducedZodChannel<TSchema, InteropZodType<TUpdate>>;
|
|
114
|
-
//#endregion
|
|
115
|
-
export { InteropZodToStateDefinition, META_EXTRAS_DESCRIPTION_PREFIX, ReducedZodChannel, SchemaMeta, SchemaMetaRegistry, UpdateType, schemaMetaRegistry, withLangGraph };
|
|
116
|
-
//# sourceMappingURL=meta.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"meta.d.cts","names":["InteropZodObject","InteropZodType","InteropZodObjectShape","BaseChannel","META_EXTRAS_DESCRIPTION_PREFIX","ReducedZodChannel","T","TReducerSchema","InteropZodToStateDefinition","TShape","key","Schema","ReducerSchema","V","U","UpdateType","SchemaMeta","TValue","TUpdate","SchemaMetaRegistry","WeakMap","Map","schemaMetaRegistry","withLangGraph","TSchema"],"sources":["../../../src/graph/zod/meta.d.ts"],"sourcesContent":["import { InteropZodObject, InteropZodType, InteropZodObjectShape } from \"@langchain/core/utils/types\";\nimport { BaseChannel } from \"../../channels/base.js\";\nexport declare const META_EXTRAS_DESCRIPTION_PREFIX = \"lg:\";\n/** @internal */\nexport type ReducedZodChannel<T extends InteropZodType, TReducerSchema extends InteropZodType> = T & {\n lg_reducer_schema: TReducerSchema;\n};\n/** @internal */\nexport type InteropZodToStateDefinition<T extends InteropZodObject, TShape = InteropZodObjectShape<T>> = {\n [key in keyof TShape]: TShape[key] extends ReducedZodChannel<infer Schema, infer ReducerSchema> ? Schema extends InteropZodType<infer V> ? ReducerSchema extends InteropZodType<infer U> ? BaseChannel<V, U> : never : never : TShape[key] extends InteropZodType<infer V, infer U> ? BaseChannel<V, U> : never;\n};\nexport type UpdateType<T extends InteropZodObject, TShape = InteropZodObjectShape<T>> = {\n [key in keyof TShape]?: TShape[key] extends ReducedZodChannel<infer Schema, infer ReducerSchema> ? Schema extends InteropZodType<unknown> ? ReducerSchema extends InteropZodType<infer U> ? U : never : never : TShape[key] extends InteropZodType<unknown, infer U> ? U : never;\n};\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface SchemaMeta<TValue = any, TUpdate = TValue> {\n jsonSchemaExtra?: {\n langgraph_nodes?: string[];\n langgraph_type?: \"prompt\" | \"messages\";\n [key: string]: unknown;\n };\n reducer?: {\n schema?: InteropZodType<TUpdate>;\n fn: (a: TValue, b: TUpdate) => TValue;\n };\n default?: () => TValue;\n}\n/**\n * A registry for storing and managing metadata associated with schemas.\n * This class provides methods to get, extend, remove, and check metadata for a given schema.\n */\nexport declare class SchemaMetaRegistry {\n /**\n * Internal map storing schema metadata.\n * @internal\n */\n _map: WeakMap<InteropZodType, SchemaMeta<any, any>>;\n /**\n * Cache for extended schfemas.\n * @internal\n */\n _extensionCache: Map<string, WeakMap<InteropZodType, InteropZodType>>;\n /**\n * Retrieves the metadata associated with a given schema.\n * @template TValue The value type of the schema.\n * @template TUpdate The update type of the schema (defaults to TValue).\n * @param schema The schema to retrieve metadata for.\n * @returns The associated SchemaMeta, or undefined if not present.\n */\n get<TValue, TUpdate = TValue>(schema: InteropZodType<TValue>): SchemaMeta<TValue, TUpdate> | undefined;\n /**\n * Extends or sets the metadata for a given schema.\n * @template TValue The value type of the schema.\n * @template TUpdate The update type of the schema (defaults to TValue).\n * @param schema The schema to extend metadata for.\n * @param predicate A function that receives the existing metadata (or undefined) and returns the new metadata.\n */\n extend<TValue, TUpdate>(schema: InteropZodType<TValue>, predicate: (meta: SchemaMeta<TValue, TUpdate> | undefined) => SchemaMeta<TValue, TUpdate>): void;\n /**\n * Removes the metadata associated with a given schema.\n * @param schema The schema to remove metadata for.\n * @returns The SchemaMetaRegistry instance (for chaining).\n */\n remove(schema: InteropZodType): this;\n /**\n * Checks if metadata exists for a given schema.\n * @param schema The schema to check.\n * @returns True if metadata exists, false otherwise.\n */\n has(schema: InteropZodType): boolean;\n /**\n * Returns a mapping of channel instances for each property in the schema\n * using the associated metadata in the registry.\n *\n * This is used to create the `channels` object that's passed to the `Graph` constructor.\n *\n * @template T The shape of the schema.\n * @param schema The schema to extract channels from.\n * @returns A mapping from property names to channel instances.\n */\n getChannelsForSchema<T extends InteropZodObject>(schema: T): InteropZodToStateDefinition<T>;\n /**\n * Returns a modified schema that introspectively looks at all keys of the provided\n * object schema, and applies the augmentations based on meta provided with those keys\n * in the registry and the selectors provided in the `effects` parameter.\n *\n * This assumes that the passed in schema is the \"root\" schema object for a graph where\n * the keys of the schema are the channels of the graph. Because we need to represent\n * the input of a graph in a couple of different ways, the `effects` parameter allows\n * us to apply those augmentations based on pre determined conditions.\n *\n * @param schema The root schema object to extend.\n * @param effects The effects that are being applied.\n * @returns The extended schema.\n */\n getExtendedChannelSchemas<T extends InteropZodObject>(schema: T, effects: {\n /**\n * Augments the shape by using the reducer's schema if it exists\n */\n withReducerSchema?: boolean;\n /**\n * Applies the stringified jsonSchemaExtra as a description to the schema.\n */\n withJsonSchemaExtrasAsDescription?: boolean;\n /**\n * Applies the `.partial()` modifier to the schema.\n */\n asPartial?: boolean;\n }): InteropZodObject;\n}\nexport declare const schemaMetaRegistry: SchemaMetaRegistry;\nexport declare function withLangGraph<TValue, TUpdate, TSchema extends InteropZodType<TValue>>(schema: TSchema, meta: SchemaMeta<TValue, TUpdate> & {\n reducer?: undefined;\n}): TSchema;\nexport declare function withLangGraph<TValue, TUpdate, TSchema extends InteropZodType<TValue>>(schema: TSchema, meta: SchemaMeta<TValue, TUpdate>): ReducedZodChannel<TSchema, InteropZodType<TUpdate>>;\n"],"mappings":";;;;cAEqBI,8BAAAA;;AAAAA,KAETC,iBAFSD,CAAAA,UAEmBH,cAFW,EAAA,uBAE4BA,cAF5B,CAAA,GAE8CK,CAF9C,GAAA;EAEvCD,iBAAAA,EACWE,cADM;CAAA;;AAAkDN,KAInEO,2BAJmEP,CAAAA,UAI7BD,gBAJ6BC,EAAAA,SAIFC,qBAJED,CAIoBK,CAJpBL,CAAAA,CAAAA,GAAAA,UAAkBK,MAK/EG,MAL+EH,GAKtEG,MALsEH,CAK/DI,GAL+DJ,CAAAA,SAKlDD,iBALkDC,CAAAA,KAAAA,OAAAA,EAAAA,KAAAA,cAAAA,CAAAA,GAKKK,MALLL,SAKoBL,cALpBK,CAAAA,KAAAA,EAAAA,CAAAA,GAK8CM,aAL9CN,SAKoEL,cALpEK,CAAAA,KAAAA,EAAAA,CAAAA,GAK8FH,WAL9FG,CAK0GO,CAL1GP,EAK6GQ,CAL7GR,CAAAA,GAAAA,KAAAA,GAAAA,KAAAA,GAKkIG,MALlIH,CAKyII,GALzIJ,CAAAA,SAKsJL,cALtJK,CAAAA,KAAAA,EAAAA,EAAAA,KAAAA,EAAAA,CAA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A,MAAAA,EAHgCuB,OAGhCvB,EAAAA,IAAAA,EAH+Ce,UAG/Cf,CAH0DgB,MAG1DhB,EAHkEiB,OAGlEjB,CAAAA,GAAAA;SAAgCuB,CAAAA,EAAAA,SAAAA;IADnGA,OAC6HP;AAAQC,iBAAjHK,aAAiHL,CAAAA,MAAAA,EAAAA,OAAAA,EAAAA,gBAAlEjB,cAAkEiB,CAAnDD,MAAmDC,CAAAA,CAAAA,CAAAA,MAAAA,EAAlCM,OAAkCN,EAAAA,IAAAA,EAAnBF,UAAmBE,CAARD,MAAQC,EAAAA,OAAAA,CAAAA,CAAAA,EAAWb,iBAAXa,CAA6BM,OAA7BN,EAAsCjB,cAAtCiB,CAAqDA,OAArDA,CAAAA,CAAAA"}
|
package/dist/graph/zod/meta.d.ts
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { BaseChannel } from "../../channels/base.js";
|
|
2
|
-
import { InteropZodObject, InteropZodObjectShape, InteropZodType } from "@langchain/core/utils/types";
|
|
3
|
-
|
|
4
|
-
//#region src/graph/zod/meta.d.ts
|
|
5
|
-
declare const META_EXTRAS_DESCRIPTION_PREFIX = "lg:";
|
|
6
|
-
/** @internal */
|
|
7
|
-
type ReducedZodChannel<T extends InteropZodType, TReducerSchema extends InteropZodType> = T & {
|
|
8
|
-
lg_reducer_schema: TReducerSchema;
|
|
9
|
-
};
|
|
10
|
-
/** @internal */
|
|
11
|
-
type InteropZodToStateDefinition<T extends InteropZodObject, TShape = InteropZodObjectShape<T>> = { [key in keyof TShape]: TShape[key] extends ReducedZodChannel<infer Schema, infer ReducerSchema> ? Schema extends InteropZodType<infer V> ? ReducerSchema extends InteropZodType<infer U> ? BaseChannel<V, U> : never : never : TShape[key] extends InteropZodType<infer V, infer U> ? BaseChannel<V, U> : never };
|
|
12
|
-
type UpdateType<T extends InteropZodObject, TShape = InteropZodObjectShape<T>> = { [key in keyof TShape]?: TShape[key] extends ReducedZodChannel<infer Schema, infer ReducerSchema> ? Schema extends InteropZodType<unknown> ? ReducerSchema extends InteropZodType<infer U> ? U : never : never : TShape[key] extends InteropZodType<unknown, infer U> ? U : never };
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
-
interface SchemaMeta<TValue = any, TUpdate = TValue> {
|
|
15
|
-
jsonSchemaExtra?: {
|
|
16
|
-
langgraph_nodes?: string[];
|
|
17
|
-
langgraph_type?: "prompt" | "messages";
|
|
18
|
-
[key: string]: unknown;
|
|
19
|
-
};
|
|
20
|
-
reducer?: {
|
|
21
|
-
schema?: InteropZodType<TUpdate>;
|
|
22
|
-
fn: (a: TValue, b: TUpdate) => TValue;
|
|
23
|
-
};
|
|
24
|
-
default?: () => TValue;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* A registry for storing and managing metadata associated with schemas.
|
|
28
|
-
* This class provides methods to get, extend, remove, and check metadata for a given schema.
|
|
29
|
-
*/
|
|
30
|
-
declare class SchemaMetaRegistry {
|
|
31
|
-
/**
|
|
32
|
-
* Internal map storing schema metadata.
|
|
33
|
-
* @internal
|
|
34
|
-
*/
|
|
35
|
-
_map: WeakMap<InteropZodType, SchemaMeta<any, any>>;
|
|
36
|
-
/**
|
|
37
|
-
* Cache for extended schfemas.
|
|
38
|
-
* @internal
|
|
39
|
-
*/
|
|
40
|
-
_extensionCache: Map<string, WeakMap<InteropZodType, InteropZodType>>;
|
|
41
|
-
/**
|
|
42
|
-
* Retrieves the metadata associated with a given schema.
|
|
43
|
-
* @template TValue The value type of the schema.
|
|
44
|
-
* @template TUpdate The update type of the schema (defaults to TValue).
|
|
45
|
-
* @param schema The schema to retrieve metadata for.
|
|
46
|
-
* @returns The associated SchemaMeta, or undefined if not present.
|
|
47
|
-
*/
|
|
48
|
-
get<TValue, TUpdate = TValue>(schema: InteropZodType<TValue>): SchemaMeta<TValue, TUpdate> | undefined;
|
|
49
|
-
/**
|
|
50
|
-
* Extends or sets the metadata for a given schema.
|
|
51
|
-
* @template TValue The value type of the schema.
|
|
52
|
-
* @template TUpdate The update type of the schema (defaults to TValue).
|
|
53
|
-
* @param schema The schema to extend metadata for.
|
|
54
|
-
* @param predicate A function that receives the existing metadata (or undefined) and returns the new metadata.
|
|
55
|
-
*/
|
|
56
|
-
extend<TValue, TUpdate>(schema: InteropZodType<TValue>, predicate: (meta: SchemaMeta<TValue, TUpdate> | undefined) => SchemaMeta<TValue, TUpdate>): void;
|
|
57
|
-
/**
|
|
58
|
-
* Removes the metadata associated with a given schema.
|
|
59
|
-
* @param schema The schema to remove metadata for.
|
|
60
|
-
* @returns The SchemaMetaRegistry instance (for chaining).
|
|
61
|
-
*/
|
|
62
|
-
remove(schema: InteropZodType): this;
|
|
63
|
-
/**
|
|
64
|
-
* Checks if metadata exists for a given schema.
|
|
65
|
-
* @param schema The schema to check.
|
|
66
|
-
* @returns True if metadata exists, false otherwise.
|
|
67
|
-
*/
|
|
68
|
-
has(schema: InteropZodType): boolean;
|
|
69
|
-
/**
|
|
70
|
-
* Returns a mapping of channel instances for each property in the schema
|
|
71
|
-
* using the associated metadata in the registry.
|
|
72
|
-
*
|
|
73
|
-
* This is used to create the `channels` object that's passed to the `Graph` constructor.
|
|
74
|
-
*
|
|
75
|
-
* @template T The shape of the schema.
|
|
76
|
-
* @param schema The schema to extract channels from.
|
|
77
|
-
* @returns A mapping from property names to channel instances.
|
|
78
|
-
*/
|
|
79
|
-
getChannelsForSchema<T extends InteropZodObject>(schema: T): InteropZodToStateDefinition<T>;
|
|
80
|
-
/**
|
|
81
|
-
* Returns a modified schema that introspectively looks at all keys of the provided
|
|
82
|
-
* object schema, and applies the augmentations based on meta provided with those keys
|
|
83
|
-
* in the registry and the selectors provided in the `effects` parameter.
|
|
84
|
-
*
|
|
85
|
-
* This assumes that the passed in schema is the "root" schema object for a graph where
|
|
86
|
-
* the keys of the schema are the channels of the graph. Because we need to represent
|
|
87
|
-
* the input of a graph in a couple of different ways, the `effects` parameter allows
|
|
88
|
-
* us to apply those augmentations based on pre determined conditions.
|
|
89
|
-
*
|
|
90
|
-
* @param schema The root schema object to extend.
|
|
91
|
-
* @param effects The effects that are being applied.
|
|
92
|
-
* @returns The extended schema.
|
|
93
|
-
*/
|
|
94
|
-
getExtendedChannelSchemas<T extends InteropZodObject>(schema: T, effects: {
|
|
95
|
-
/**
|
|
96
|
-
* Augments the shape by using the reducer's schema if it exists
|
|
97
|
-
*/
|
|
98
|
-
withReducerSchema?: boolean;
|
|
99
|
-
/**
|
|
100
|
-
* Applies the stringified jsonSchemaExtra as a description to the schema.
|
|
101
|
-
*/
|
|
102
|
-
withJsonSchemaExtrasAsDescription?: boolean;
|
|
103
|
-
/**
|
|
104
|
-
* Applies the `.partial()` modifier to the schema.
|
|
105
|
-
*/
|
|
106
|
-
asPartial?: boolean;
|
|
107
|
-
}): InteropZodObject;
|
|
108
|
-
}
|
|
109
|
-
declare const schemaMetaRegistry: SchemaMetaRegistry;
|
|
110
|
-
declare function withLangGraph<TValue, TUpdate, TSchema extends InteropZodType<TValue>>(schema: TSchema, meta: SchemaMeta<TValue, TUpdate> & {
|
|
111
|
-
reducer?: undefined;
|
|
112
|
-
}): TSchema;
|
|
113
|
-
declare function withLangGraph<TValue, TUpdate, TSchema extends InteropZodType<TValue>>(schema: TSchema, meta: SchemaMeta<TValue, TUpdate>): ReducedZodChannel<TSchema, InteropZodType<TUpdate>>;
|
|
114
|
-
//#endregion
|
|
115
|
-
export { InteropZodToStateDefinition, META_EXTRAS_DESCRIPTION_PREFIX, ReducedZodChannel, SchemaMeta, SchemaMetaRegistry, UpdateType, schemaMetaRegistry, withLangGraph };
|
|
116
|
-
//# sourceMappingURL=meta.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"meta.d.ts","names":["InteropZodObject","InteropZodType","InteropZodObjectShape","BaseChannel","META_EXTRAS_DESCRIPTION_PREFIX","ReducedZodChannel","T","TReducerSchema","InteropZodToStateDefinition","TShape","key","Schema","ReducerSchema","V","U","UpdateType","SchemaMeta","TValue","TUpdate","SchemaMetaRegistry","WeakMap","Map","schemaMetaRegistry","withLangGraph","TSchema"],"sources":["../../../src/graph/zod/meta.d.ts"],"sourcesContent":["import { InteropZodObject, InteropZodType, InteropZodObjectShape } from \"@langchain/core/utils/types\";\nimport { BaseChannel } from \"../../channels/base.js\";\nexport declare const META_EXTRAS_DESCRIPTION_PREFIX = \"lg:\";\n/** @internal */\nexport type ReducedZodChannel<T extends InteropZodType, TReducerSchema extends InteropZodType> = T & {\n lg_reducer_schema: TReducerSchema;\n};\n/** @internal */\nexport type InteropZodToStateDefinition<T extends InteropZodObject, TShape = InteropZodObjectShape<T>> = {\n [key in keyof TShape]: TShape[key] extends ReducedZodChannel<infer Schema, infer ReducerSchema> ? Schema extends InteropZodType<infer V> ? ReducerSchema extends InteropZodType<infer U> ? BaseChannel<V, U> : never : never : TShape[key] extends InteropZodType<infer V, infer U> ? BaseChannel<V, U> : never;\n};\nexport type UpdateType<T extends InteropZodObject, TShape = InteropZodObjectShape<T>> = {\n [key in keyof TShape]?: TShape[key] extends ReducedZodChannel<infer Schema, infer ReducerSchema> ? Schema extends InteropZodType<unknown> ? ReducerSchema extends InteropZodType<infer U> ? U : never : never : TShape[key] extends InteropZodType<unknown, infer U> ? U : never;\n};\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface SchemaMeta<TValue = any, TUpdate = TValue> {\n jsonSchemaExtra?: {\n langgraph_nodes?: string[];\n langgraph_type?: \"prompt\" | \"messages\";\n [key: string]: unknown;\n };\n reducer?: {\n schema?: InteropZodType<TUpdate>;\n fn: (a: TValue, b: TUpdate) => TValue;\n };\n default?: () => TValue;\n}\n/**\n * A registry for storing and managing metadata associated with schemas.\n * This class provides methods to get, extend, remove, and check metadata for a given schema.\n */\nexport declare class SchemaMetaRegistry {\n /**\n * Internal map storing schema metadata.\n * @internal\n */\n _map: WeakMap<InteropZodType, SchemaMeta<any, any>>;\n /**\n * Cache for extended schfemas.\n * @internal\n */\n _extensionCache: Map<string, WeakMap<InteropZodType, InteropZodType>>;\n /**\n * Retrieves the metadata associated with a given schema.\n * @template TValue The value type of the schema.\n * @template TUpdate The update type of the schema (defaults to TValue).\n * @param schema The schema to retrieve metadata for.\n * @returns The associated SchemaMeta, or undefined if not present.\n */\n get<TValue, TUpdate = TValue>(schema: InteropZodType<TValue>): SchemaMeta<TValue, TUpdate> | undefined;\n /**\n * Extends or sets the metadata for a given schema.\n * @template TValue The value type of the schema.\n * @template TUpdate The update type of the schema (defaults to TValue).\n * @param schema The schema to extend metadata for.\n * @param predicate A function that receives the existing metadata (or undefined) and returns the new metadata.\n */\n extend<TValue, TUpdate>(schema: InteropZodType<TValue>, predicate: (meta: SchemaMeta<TValue, TUpdate> | undefined) => SchemaMeta<TValue, TUpdate>): void;\n /**\n * Removes the metadata associated with a given schema.\n * @param schema The schema to remove metadata for.\n * @returns The SchemaMetaRegistry instance (for chaining).\n */\n remove(schema: InteropZodType): this;\n /**\n * Checks if metadata exists for a given schema.\n * @param schema The schema to check.\n * @returns True if metadata exists, false otherwise.\n */\n has(schema: InteropZodType): boolean;\n /**\n * Returns a mapping of channel instances for each property in the schema\n * using the associated metadata in the registry.\n *\n * This is used to create the `channels` object that's passed to the `Graph` constructor.\n *\n * @template T The shape of the schema.\n * @param schema The schema to extract channels from.\n * @returns A mapping from property names to channel instances.\n */\n getChannelsForSchema<T extends InteropZodObject>(schema: T): InteropZodToStateDefinition<T>;\n /**\n * Returns a modified schema that introspectively looks at all keys of the provided\n * object schema, and applies the augmentations based on meta provided with those keys\n * in the registry and the selectors provided in the `effects` parameter.\n *\n * This assumes that the passed in schema is the \"root\" schema object for a graph where\n * the keys of the schema are the channels of the graph. Because we need to represent\n * the input of a graph in a couple of different ways, the `effects` parameter allows\n * us to apply those augmentations based on pre determined conditions.\n *\n * @param schema The root schema object to extend.\n * @param effects The effects that are being applied.\n * @returns The extended schema.\n */\n getExtendedChannelSchemas<T extends InteropZodObject>(schema: T, effects: {\n /**\n * Augments the shape by using the reducer's schema if it exists\n */\n withReducerSchema?: boolean;\n /**\n * Applies the stringified jsonSchemaExtra as a description to the schema.\n */\n withJsonSchemaExtrasAsDescription?: boolean;\n /**\n * Applies the `.partial()` modifier to the schema.\n */\n asPartial?: boolean;\n }): InteropZodObject;\n}\nexport declare const schemaMetaRegistry: SchemaMetaRegistry;\nexport declare function withLangGraph<TValue, TUpdate, TSchema extends InteropZodType<TValue>>(schema: TSchema, meta: SchemaMeta<TValue, TUpdate> & {\n reducer?: undefined;\n}): TSchema;\nexport declare function withLangGraph<TValue, TUpdate, TSchema extends InteropZodType<TValue>>(schema: TSchema, meta: SchemaMeta<TValue, TUpdate>): ReducedZodChannel<TSchema, InteropZodType<TUpdate>>;\n"],"mappings":";;;;cAEqBI,8BAAAA;;AAAAA,KAETC,iBAFSD,CAAAA,UAEmBH,cAFW,EAAA,uBAE4BA,cAF5B,CAAA,GAE8CK,CAF9C,GAAA;EAEvCD,iBAAAA,EACWE,cADM;CAAA;;AAAkDN,KAInEO,2BAJmEP,CAAAA,UAI7BD,gBAJ6BC,EAAAA,SAIFC,qBAJED,CAIoBK,CAJpBL,CAAAA,CAAAA,GAAAA,UAAkBK,MAK/EG,MAL+EH,GAKtEG,MALsEH,CAK/DI,GAL+DJ,CAAAA,SAKlDD,iBALkDC,CAAAA,KAAAA,OAAAA,EAAAA,KAAAA,cAAAA,CAAAA,GAKKK,MALLL,SAKoBL,cALpBK,CAAAA,KAAAA,EAAAA,CAAAA,GAK8CM,aAL9CN,SAKoEL,cALpEK,CAAAA,KAAAA,EAAAA,CAAAA,GAK8FH,WAL9FG,CAK0GO,CAL1GP,EAK6GQ,CAL7GR,CAAAA,GAAAA,KAAAA,GAAAA,KAAAA,GAKkIG,MALlIH,CAKyII,GALzIJ,CAAAA,SAKsJL,cALtJK,CAAAA,KAAAA,EAAAA,EAAAA,KAAAA,EAAAA,CAAAA,GAKyLH,WALzLG,CAKqMO,CALrMP,EAKwMQ,CALxMR,CAAAA,GAAAA,KAAAA;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AG1DhB,EAHkEiB,OAGlEjB,CAAAA,GAAAA;SAAgCuB,CAAAA,EAAAA,SAAAA;IADnGA,OAC6HP;AAAQC,iBAAjHK,aAAiHL,CAAAA,MAAAA,EAAAA,OAAAA,EAAAA,gBAAlEjB,cAAkEiB,CAAnDD,MAAmDC,CAAAA,CAAAA,CAAAA,MAAAA,EAAlCM,OAAkCN,EAAAA,IAAAA,EAAnBF,UAAmBE,CAARD,MAAQC,EAAAA,OAAAA,CAAAA,CAAAA,EAAWb,iBAAXa,CAA6BM,OAA7BN,EAAsCjB,cAAtCiB,CAAqDA,OAArDA,CAAAA,CAAAA"}
|
package/dist/graph/zod/meta.js
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { BinaryOperatorAggregate } from "../../channels/binop.js";
|
|
2
|
-
import { LastValue } from "../../channels/last_value.js";
|
|
3
|
-
import { extendInteropZodObject, getInteropZodDefaultGetter, getInteropZodObjectShape, getSchemaDescription, interopZodObjectPartial, isZodSchemaV3 } from "@langchain/core/utils/types";
|
|
4
|
-
|
|
5
|
-
//#region src/graph/zod/meta.ts
|
|
6
|
-
const META_EXTRAS_DESCRIPTION_PREFIX = "lg:";
|
|
7
|
-
/**
|
|
8
|
-
* A registry for storing and managing metadata associated with schemas.
|
|
9
|
-
* This class provides methods to get, extend, remove, and check metadata for a given schema.
|
|
10
|
-
*/
|
|
11
|
-
var SchemaMetaRegistry = class {
|
|
12
|
-
/**
|
|
13
|
-
* Internal map storing schema metadata.
|
|
14
|
-
* @internal
|
|
15
|
-
*/
|
|
16
|
-
_map = /* @__PURE__ */ new WeakMap();
|
|
17
|
-
/**
|
|
18
|
-
* Cache for extended schfemas.
|
|
19
|
-
* @internal
|
|
20
|
-
*/
|
|
21
|
-
_extensionCache = /* @__PURE__ */ new Map();
|
|
22
|
-
/**
|
|
23
|
-
* Retrieves the metadata associated with a given schema.
|
|
24
|
-
* @template TValue The value type of the schema.
|
|
25
|
-
* @template TUpdate The update type of the schema (defaults to TValue).
|
|
26
|
-
* @param schema The schema to retrieve metadata for.
|
|
27
|
-
* @returns The associated SchemaMeta, or undefined if not present.
|
|
28
|
-
*/
|
|
29
|
-
get(schema) {
|
|
30
|
-
return this._map.get(schema);
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Extends or sets the metadata for a given schema.
|
|
34
|
-
* @template TValue The value type of the schema.
|
|
35
|
-
* @template TUpdate The update type of the schema (defaults to TValue).
|
|
36
|
-
* @param schema The schema to extend metadata for.
|
|
37
|
-
* @param predicate A function that receives the existing metadata (or undefined) and returns the new metadata.
|
|
38
|
-
*/
|
|
39
|
-
extend(schema, predicate) {
|
|
40
|
-
const existingMeta = this.get(schema);
|
|
41
|
-
this._map.set(schema, predicate(existingMeta));
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Removes the metadata associated with a given schema.
|
|
45
|
-
* @param schema The schema to remove metadata for.
|
|
46
|
-
* @returns The SchemaMetaRegistry instance (for chaining).
|
|
47
|
-
*/
|
|
48
|
-
remove(schema) {
|
|
49
|
-
this._map.delete(schema);
|
|
50
|
-
return this;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Checks if metadata exists for a given schema.
|
|
54
|
-
* @param schema The schema to check.
|
|
55
|
-
* @returns True if metadata exists, false otherwise.
|
|
56
|
-
*/
|
|
57
|
-
has(schema) {
|
|
58
|
-
return this._map.has(schema);
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Returns a mapping of channel instances for each property in the schema
|
|
62
|
-
* using the associated metadata in the registry.
|
|
63
|
-
*
|
|
64
|
-
* This is used to create the `channels` object that's passed to the `Graph` constructor.
|
|
65
|
-
*
|
|
66
|
-
* @template T The shape of the schema.
|
|
67
|
-
* @param schema The schema to extract channels from.
|
|
68
|
-
* @returns A mapping from property names to channel instances.
|
|
69
|
-
*/
|
|
70
|
-
getChannelsForSchema(schema) {
|
|
71
|
-
const channels = {};
|
|
72
|
-
const shape = getInteropZodObjectShape(schema);
|
|
73
|
-
for (const [key, channelSchema] of Object.entries(shape)) {
|
|
74
|
-
const meta = this.get(channelSchema);
|
|
75
|
-
if (meta?.reducer) channels[key] = new BinaryOperatorAggregate(meta.reducer.fn, meta.default);
|
|
76
|
-
else channels[key] = new LastValue(meta?.default);
|
|
77
|
-
}
|
|
78
|
-
return channels;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Returns a modified schema that introspectively looks at all keys of the provided
|
|
82
|
-
* object schema, and applies the augmentations based on meta provided with those keys
|
|
83
|
-
* in the registry and the selectors provided in the `effects` parameter.
|
|
84
|
-
*
|
|
85
|
-
* This assumes that the passed in schema is the "root" schema object for a graph where
|
|
86
|
-
* the keys of the schema are the channels of the graph. Because we need to represent
|
|
87
|
-
* the input of a graph in a couple of different ways, the `effects` parameter allows
|
|
88
|
-
* us to apply those augmentations based on pre determined conditions.
|
|
89
|
-
*
|
|
90
|
-
* @param schema The root schema object to extend.
|
|
91
|
-
* @param effects The effects that are being applied.
|
|
92
|
-
* @returns The extended schema.
|
|
93
|
-
*/
|
|
94
|
-
getExtendedChannelSchemas(schema, effects) {
|
|
95
|
-
if (Object.keys(effects).length === 0) return schema;
|
|
96
|
-
const cacheKey = Object.entries(effects).filter(([, v]) => v === true).sort(([a], [b]) => a.localeCompare(b)).map(([k, v]) => `${k}:${v}`).join("|");
|
|
97
|
-
const cache = this._extensionCache.get(cacheKey) ?? /* @__PURE__ */ new WeakMap();
|
|
98
|
-
if (cache.has(schema)) return cache.get(schema);
|
|
99
|
-
let modifiedSchema = schema;
|
|
100
|
-
if (effects.withReducerSchema || effects.withJsonSchemaExtrasAsDescription) {
|
|
101
|
-
const newShapeEntries = Object.entries(getInteropZodObjectShape(schema)).map(([key, schema$1]) => {
|
|
102
|
-
const meta = this.get(schema$1);
|
|
103
|
-
let outputSchema = effects.withReducerSchema ? meta?.reducer?.schema ?? schema$1 : schema$1;
|
|
104
|
-
if (effects.withJsonSchemaExtrasAsDescription && meta?.jsonSchemaExtra) {
|
|
105
|
-
const description = getSchemaDescription(outputSchema) ?? getSchemaDescription(schema$1);
|
|
106
|
-
const strExtras = JSON.stringify({
|
|
107
|
-
...meta.jsonSchemaExtra,
|
|
108
|
-
description
|
|
109
|
-
});
|
|
110
|
-
outputSchema = outputSchema.describe(`${META_EXTRAS_DESCRIPTION_PREFIX}${strExtras}`);
|
|
111
|
-
}
|
|
112
|
-
return [key, outputSchema];
|
|
113
|
-
});
|
|
114
|
-
modifiedSchema = extendInteropZodObject(schema, Object.fromEntries(newShapeEntries));
|
|
115
|
-
if (isZodSchemaV3(modifiedSchema)) modifiedSchema._def.unknownKeys = "strip";
|
|
116
|
-
}
|
|
117
|
-
if (effects.asPartial) modifiedSchema = interopZodObjectPartial(modifiedSchema);
|
|
118
|
-
cache.set(schema, modifiedSchema);
|
|
119
|
-
this._extensionCache.set(cacheKey, cache);
|
|
120
|
-
return modifiedSchema;
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
const schemaMetaRegistry = new SchemaMetaRegistry();
|
|
124
|
-
function withLangGraph(schema, meta) {
|
|
125
|
-
if (meta.reducer && !meta.default) {
|
|
126
|
-
const defaultValueGetter = getInteropZodDefaultGetter(schema);
|
|
127
|
-
if (defaultValueGetter != null) meta.default = defaultValueGetter;
|
|
128
|
-
}
|
|
129
|
-
if (meta.reducer) {
|
|
130
|
-
const schemaWithReducer = Object.assign(schema, { lg_reducer_schema: meta.reducer?.schema ?? schema });
|
|
131
|
-
schemaMetaRegistry.extend(schemaWithReducer, () => meta);
|
|
132
|
-
return schemaWithReducer;
|
|
133
|
-
} else {
|
|
134
|
-
schemaMetaRegistry.extend(schema, () => meta);
|
|
135
|
-
return schema;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
//#endregion
|
|
140
|
-
export { META_EXTRAS_DESCRIPTION_PREFIX, SchemaMetaRegistry, schemaMetaRegistry, withLangGraph };
|
|
141
|
-
//# sourceMappingURL=meta.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"meta.js","names":["modifiedSchema: InteropZodObject","schema"],"sources":["../../../src/graph/zod/meta.ts"],"sourcesContent":["import {\n InferInteropZodOutput,\n InteropZodObject,\n InteropZodType,\n getInteropZodObjectShape,\n extendInteropZodObject,\n getInteropZodDefaultGetter,\n interopZodObjectPartial,\n InteropZodObjectShape,\n isZodSchemaV3,\n getSchemaDescription,\n} from \"@langchain/core/utils/types\";\nimport { BaseChannel } from \"../../channels/base.js\";\nimport { BinaryOperatorAggregate } from \"../../channels/binop.js\";\nimport { LastValue } from \"../../channels/last_value.js\";\n\nexport const META_EXTRAS_DESCRIPTION_PREFIX = \"lg:\";\n\n/** @internal */\nexport type ReducedZodChannel<\n T extends InteropZodType,\n TReducerSchema extends InteropZodType\n> = T & {\n lg_reducer_schema: TReducerSchema;\n};\n\n/** @internal */\nexport type InteropZodToStateDefinition<\n T extends InteropZodObject,\n TShape = InteropZodObjectShape<T>\n> = {\n [key in keyof TShape]: TShape[key] extends ReducedZodChannel<\n infer Schema,\n infer ReducerSchema\n >\n ? Schema extends InteropZodType<infer V>\n ? ReducerSchema extends InteropZodType<infer U>\n ? BaseChannel<V, U>\n : never\n : never\n : TShape[key] extends InteropZodType<infer V, infer U>\n ? BaseChannel<V, U>\n : never;\n};\n\nexport type UpdateType<\n T extends InteropZodObject,\n TShape = InteropZodObjectShape<T>\n> = {\n [key in keyof TShape]?: TShape[key] extends ReducedZodChannel<\n infer Schema,\n infer ReducerSchema\n >\n ? Schema extends InteropZodType<unknown>\n ? ReducerSchema extends InteropZodType<infer U>\n ? U\n : never\n : never\n : TShape[key] extends InteropZodType<unknown, infer U>\n ? U\n : never;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface SchemaMeta<TValue = any, TUpdate = TValue> {\n jsonSchemaExtra?: {\n langgraph_nodes?: string[];\n langgraph_type?: \"prompt\" | \"messages\";\n [key: string]: unknown;\n };\n reducer?: {\n schema?: InteropZodType<TUpdate>;\n fn: (a: TValue, b: TUpdate) => TValue;\n };\n default?: () => TValue;\n}\n\n/**\n * A registry for storing and managing metadata associated with schemas.\n * This class provides methods to get, extend, remove, and check metadata for a given schema.\n */\nexport class SchemaMetaRegistry {\n /**\n * Internal map storing schema metadata.\n * @internal\n */\n _map = new WeakMap<InteropZodType, SchemaMeta>();\n\n /**\n * Cache for extended schfemas.\n * @internal\n */\n _extensionCache = new Map<string, WeakMap<InteropZodType, InteropZodType>>();\n\n /**\n * Retrieves the metadata associated with a given schema.\n * @template TValue The value type of the schema.\n * @template TUpdate The update type of the schema (defaults to TValue).\n * @param schema The schema to retrieve metadata for.\n * @returns The associated SchemaMeta, or undefined if not present.\n */\n get<TValue, TUpdate = TValue>(\n schema: InteropZodType<TValue>\n ): SchemaMeta<TValue, TUpdate> | undefined {\n return this._map.get(schema);\n }\n\n /**\n * Extends or sets the metadata for a given schema.\n * @template TValue The value type of the schema.\n * @template TUpdate The update type of the schema (defaults to TValue).\n * @param schema The schema to extend metadata for.\n * @param predicate A function that receives the existing metadata (or undefined) and returns the new metadata.\n */\n extend<TValue, TUpdate>(\n schema: InteropZodType<TValue>,\n predicate: (\n meta: SchemaMeta<TValue, TUpdate> | undefined\n ) => SchemaMeta<TValue, TUpdate>\n ) {\n const existingMeta = this.get<TValue, TUpdate>(schema);\n this._map.set(schema, predicate(existingMeta));\n }\n\n /**\n * Removes the metadata associated with a given schema.\n * @param schema The schema to remove metadata for.\n * @returns The SchemaMetaRegistry instance (for chaining).\n */\n remove(schema: InteropZodType): this {\n this._map.delete(schema);\n return this;\n }\n\n /**\n * Checks if metadata exists for a given schema.\n * @param schema The schema to check.\n * @returns True if metadata exists, false otherwise.\n */\n has(schema: InteropZodType): boolean {\n return this._map.has(schema);\n }\n\n /**\n * Returns a mapping of channel instances for each property in the schema\n * using the associated metadata in the registry.\n *\n * This is used to create the `channels` object that's passed to the `Graph` constructor.\n *\n * @template T The shape of the schema.\n * @param schema The schema to extract channels from.\n * @returns A mapping from property names to channel instances.\n */\n getChannelsForSchema<T extends InteropZodObject>(\n schema: T\n ): InteropZodToStateDefinition<T> {\n const channels = {} as Record<string, BaseChannel>;\n const shape = getInteropZodObjectShape(schema);\n for (const [key, channelSchema] of Object.entries(shape)) {\n const meta = this.get(channelSchema);\n if (meta?.reducer) {\n channels[key] = new BinaryOperatorAggregate<\n InferInteropZodOutput<typeof channelSchema>\n >(meta.reducer.fn, meta.default);\n } else {\n channels[key] = new LastValue(meta?.default);\n }\n }\n return channels as InteropZodToStateDefinition<T>;\n }\n\n /**\n * Returns a modified schema that introspectively looks at all keys of the provided\n * object schema, and applies the augmentations based on meta provided with those keys\n * in the registry and the selectors provided in the `effects` parameter.\n *\n * This assumes that the passed in schema is the \"root\" schema object for a graph where\n * the keys of the schema are the channels of the graph. Because we need to represent\n * the input of a graph in a couple of different ways, the `effects` parameter allows\n * us to apply those augmentations based on pre determined conditions.\n *\n * @param schema The root schema object to extend.\n * @param effects The effects that are being applied.\n * @returns The extended schema.\n */\n getExtendedChannelSchemas<T extends InteropZodObject>(\n schema: T,\n effects: {\n /**\n * Augments the shape by using the reducer's schema if it exists\n */\n withReducerSchema?: boolean;\n /**\n * Applies the stringified jsonSchemaExtra as a description to the schema.\n */\n withJsonSchemaExtrasAsDescription?: boolean;\n /**\n * Applies the `.partial()` modifier to the schema.\n */\n asPartial?: boolean;\n }\n ): InteropZodObject {\n // If no effects are being applied, return the schema unchanged\n if (Object.keys(effects).length === 0) {\n return schema;\n }\n\n // Cache key is determined by looking at the effects that are being applied\n const cacheKey = Object.entries(effects)\n .filter(([, v]) => v === true)\n .sort(([a], [b]) => a.localeCompare(b))\n .map(([k, v]) => `${k}:${v}`)\n .join(\"|\");\n\n const cache = this._extensionCache.get(cacheKey) ?? new WeakMap();\n if (cache.has(schema)) return cache.get(schema)! as T;\n\n let modifiedSchema: InteropZodObject = schema;\n\n if (\n effects.withReducerSchema ||\n effects.withJsonSchemaExtrasAsDescription\n ) {\n const newShapeEntries = Object.entries(\n getInteropZodObjectShape(schema)\n ).map(([key, schema]) => {\n const meta = this.get(schema);\n let outputSchema = effects.withReducerSchema\n ? meta?.reducer?.schema ?? schema\n : schema;\n if (\n effects.withJsonSchemaExtrasAsDescription &&\n meta?.jsonSchemaExtra\n ) {\n const description =\n getSchemaDescription(outputSchema) ?? getSchemaDescription(schema);\n const strExtras = JSON.stringify({\n ...meta.jsonSchemaExtra,\n description,\n });\n outputSchema = outputSchema.describe(\n `${META_EXTRAS_DESCRIPTION_PREFIX}${strExtras}`\n );\n }\n return [key, outputSchema];\n });\n modifiedSchema = extendInteropZodObject(\n schema,\n Object.fromEntries(newShapeEntries)\n );\n if (isZodSchemaV3(modifiedSchema)) {\n modifiedSchema._def.unknownKeys = \"strip\";\n }\n }\n if (effects.asPartial) {\n modifiedSchema = interopZodObjectPartial(modifiedSchema);\n }\n\n cache.set(schema, modifiedSchema);\n this._extensionCache.set(cacheKey, cache);\n return modifiedSchema;\n }\n}\n\nexport const schemaMetaRegistry = new SchemaMetaRegistry();\n\nexport function withLangGraph<\n TValue,\n TUpdate,\n TSchema extends InteropZodType<TValue>\n>(\n schema: TSchema,\n meta: SchemaMeta<TValue, TUpdate> & { reducer?: undefined }\n): TSchema;\nexport function withLangGraph<\n TValue,\n TUpdate,\n TSchema extends InteropZodType<TValue>\n>(\n schema: TSchema,\n meta: SchemaMeta<TValue, TUpdate>\n): ReducedZodChannel<TSchema, InteropZodType<TUpdate>>;\nexport function withLangGraph<\n TValue,\n TUpdate,\n TSchema extends InteropZodType<TValue>\n>(\n schema: TSchema,\n meta: SchemaMeta<TValue, TUpdate>\n): ReducedZodChannel<TSchema, InteropZodType<TUpdate>> | TSchema {\n if (meta.reducer && !meta.default) {\n const defaultValueGetter = getInteropZodDefaultGetter(schema);\n if (defaultValueGetter != null) {\n // eslint-disable-next-line no-param-reassign\n meta.default = defaultValueGetter;\n }\n }\n if (meta.reducer) {\n const schemaWithReducer = Object.assign(schema, {\n lg_reducer_schema: meta.reducer?.schema ?? schema,\n });\n schemaMetaRegistry.extend(schemaWithReducer, () => meta);\n return schemaWithReducer;\n } else {\n schemaMetaRegistry.extend(schema, () => meta);\n return schema;\n }\n}\n"],"mappings":";;;;;AAgBA,MAAa,iCAAiC;;;;;AAiE9C,IAAa,qBAAb,MAAgC;;;;;CAK9B,uBAAO,IAAI;;;;;CAMX,kCAAkB,IAAI;;;;;;;;CAStB,IACE,QACyC;AACzC,SAAO,KAAK,KAAK,IAAI;;;;;;;;;CAUvB,OACE,QACA,WAGA;EACA,MAAM,eAAe,KAAK,IAAqB;AAC/C,OAAK,KAAK,IAAI,QAAQ,UAAU;;;;;;;CAQlC,OAAO,QAA8B;AACnC,OAAK,KAAK,OAAO;AACjB,SAAO;;;;;;;CAQT,IAAI,QAAiC;AACnC,SAAO,KAAK,KAAK,IAAI;;;;;;;;;;;;CAavB,qBACE,QACgC;EAChC,MAAM,WAAW;EACjB,MAAM,QAAQ,yBAAyB;AACvC,OAAK,MAAM,CAAC,KAAK,kBAAkB,OAAO,QAAQ,QAAQ;GACxD,MAAM,OAAO,KAAK,IAAI;AACtB,OAAI,MAAM,QACR,UAAS,OAAO,IAAI,wBAElB,KAAK,QAAQ,IAAI,KAAK;OAExB,UAAS,OAAO,IAAI,UAAU,MAAM;;AAGxC,SAAO;;;;;;;;;;;;;;;;CAiBT,0BACE,QACA,SAckB;AAElB,MAAI,OAAO,KAAK,SAAS,WAAW,EAClC,QAAO;EAIT,MAAM,WAAW,OAAO,QAAQ,SAC7B,QAAQ,GAAG,OAAO,MAAM,MACxB,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,cAAc,IACnC,KAAK,CAAC,GAAG,OAAO,GAAG,EAAE,GAAG,KACxB,KAAK;EAER,MAAM,QAAQ,KAAK,gBAAgB,IAAI,6BAAa,IAAI;AACxD,MAAI,MAAM,IAAI,QAAS,QAAO,MAAM,IAAI;EAExC,IAAIA,iBAAmC;AAEvC,MACE,QAAQ,qBACR,QAAQ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