@langchain/langgraph 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/func/index.cjs +10 -5
- package/dist/func/index.d.ts +3 -3
- package/dist/func/index.js +10 -5
- package/dist/func/index.js.map +1 -1
- package/dist/graph/messages_annotation.cjs +2 -2
- package/dist/graph/messages_annotation.d.ts +2 -2
- package/dist/graph/messages_annotation.js +1 -1
- package/dist/graph/messages_annotation.js.map +1 -1
- package/dist/graph/state.cjs +46 -21
- package/dist/graph/state.d.ts +22 -15
- package/dist/graph/state.js +46 -21
- package/dist/graph/state.js.map +1 -1
- package/dist/graph/zod/index.cjs +5 -3
- package/dist/graph/zod/index.d.ts +2 -1
- package/dist/graph/zod/index.js +2 -1
- package/dist/graph/zod/index.js.map +1 -1
- package/dist/graph/zod/meta.cjs +180 -0
- package/dist/graph/zod/meta.d.ts +110 -0
- package/dist/graph/zod/meta.js +175 -0
- package/dist/graph/zod/meta.js.map +1 -0
- package/dist/graph/zod/plugin.cjs +30 -27
- package/dist/graph/zod/plugin.d.ts +16 -3
- package/dist/graph/zod/plugin.js +31 -28
- package/dist/graph/zod/plugin.js.map +1 -1
- package/dist/graph/zod/schema.cjs +45 -19
- package/dist/graph/zod/schema.d.ts +7 -8
- package/dist/graph/zod/schema.js +45 -19
- package/dist/graph/zod/schema.js.map +1 -1
- package/dist/graph/zod/zod-registry.cjs +49 -0
- package/dist/graph/zod/zod-registry.d.ts +24 -0
- package/dist/graph/zod/zod-registry.js +45 -0
- package/dist/graph/zod/zod-registry.js.map +1 -0
- package/dist/prebuilt/react_agent_executor.d.ts +3 -3
- package/dist/pregel/types.d.ts +1 -1
- package/dist/web.d.ts +1 -1
- package/dist/web.js.map +1 -1
- package/package.json +7 -7
- package/dist/graph/zod/state.cjs +0 -135
- package/dist/graph/zod/state.d.ts +0 -39
- package/dist/graph/zod/state.js +0 -125
- package/dist/graph/zod/state.js.map +0 -1
|
@@ -3,8 +3,8 @@ import { LanguageModelLike } from "@langchain/core/language_models/base";
|
|
|
3
3
|
import { BaseMessage, BaseMessageLike, SystemMessage } from "@langchain/core/messages";
|
|
4
4
|
import { Runnable, RunnableToolLike, type RunnableLike } from "@langchain/core/runnables";
|
|
5
5
|
import { DynamicTool, StructuredToolInterface } from "@langchain/core/tools";
|
|
6
|
+
import { InteropZodType } from "@langchain/core/utils/types";
|
|
6
7
|
import { All, BaseCheckpointSaver, BaseStore } from "@langchain/langgraph-checkpoint";
|
|
7
|
-
import { z } from "zod";
|
|
8
8
|
import { type CompiledStateGraph, AnnotationRoot } from "../graph/index.js";
|
|
9
9
|
import { MessagesAnnotation } from "../graph/messages_annotation.js";
|
|
10
10
|
import { ToolNode } from "./tool_node.js";
|
|
@@ -18,7 +18,7 @@ export interface AgentState<StructuredResponseType extends Record<string, any> =
|
|
|
18
18
|
export type N = typeof START | "agent" | "tools";
|
|
19
19
|
export type StructuredResponseSchemaAndPrompt<StructuredResponseType> = {
|
|
20
20
|
prompt: string;
|
|
21
|
-
schema:
|
|
21
|
+
schema: InteropZodType<StructuredResponseType> | Record<string, any>;
|
|
22
22
|
};
|
|
23
23
|
type ServerTool = Record<string, unknown>;
|
|
24
24
|
type ClientTool = StructuredToolInterface | DynamicTool | RunnableToolLike;
|
|
@@ -101,7 +101,7 @@ export type CreateReactAgentParams<A extends AnnotationRoot<any> = AnnotationRoo
|
|
|
101
101
|
* **Note**: The graph will make a separate call to the LLM to generate the structured response after the agent loop is finished.
|
|
102
102
|
* This is not the only strategy to get structured responses, see more options in [this guide](https://langchain-ai.github.io/langgraph/how-tos/react-agent-structured-output/).
|
|
103
103
|
*/
|
|
104
|
-
responseFormat?:
|
|
104
|
+
responseFormat?: InteropZodType<StructuredResponseType> | StructuredResponseSchemaAndPrompt<StructuredResponseType> | Record<string, any>;
|
|
105
105
|
/**
|
|
106
106
|
* An optional name for the agent.
|
|
107
107
|
*/
|
package/dist/pregel/types.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ type StreamMessageOutput = [BaseMessage, Record<string, any>];
|
|
|
19
19
|
type StreamCustomOutput = any;
|
|
20
20
|
type StreamDebugOutput = Record<string, any>;
|
|
21
21
|
type DefaultStreamMode = "updates";
|
|
22
|
-
export type StreamOutputMap<TStreamMode extends StreamMode | StreamMode[] | undefined, TStreamSubgraphs extends boolean, StreamUpdates, StreamValues, Nodes> = (undefined extends TStreamMode ? [] : StreamMode | StreamMode[] extends TStreamMode ? TStreamMode extends StreamMode[] ? TStreamMode[number] : TStreamMode : TStreamMode extends StreamMode[] ? TStreamMode[number] : []) extends infer Multiple extends StreamMode ? [TStreamSubgraphs] extends [true] ? {
|
|
22
|
+
export type StreamOutputMap<TStreamMode extends StreamMode | StreamMode[] | undefined, TStreamSubgraphs extends boolean, StreamUpdates, StreamValues, Nodes = string> = (undefined extends TStreamMode ? [] : StreamMode | StreamMode[] extends TStreamMode ? TStreamMode extends StreamMode[] ? TStreamMode[number] : TStreamMode : TStreamMode extends StreamMode[] ? TStreamMode[number] : []) extends infer Multiple extends StreamMode ? [TStreamSubgraphs] extends [true] ? {
|
|
23
23
|
values: [string[], "values", StreamValues];
|
|
24
24
|
updates: [
|
|
25
25
|
string[],
|
package/dist/web.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { Graph, type StateGraphArgs, StateGraph, CompiledStateGraph, MessageGraph, typedNode, messagesStateReducer, messagesStateReducer as addMessages, REMOVE_ALL_MESSAGES, type Messages, Annotation, type StateType, type UpdateType, type NodeType, type StateDefinition, type SingleReducer, type CompiledGraph, } from "./graph/index.js";
|
|
2
|
-
export type { StateSnapshot, StreamMode, PregelParams, PregelOptions, SingleChannelSubscriptionOptions, MultipleChannelSubscriptionOptions, GetStateOptions, } from "./pregel/types.js";
|
|
2
|
+
export type { StateSnapshot, StreamMode, StreamOutputMap, PregelParams, PregelOptions, SingleChannelSubscriptionOptions, MultipleChannelSubscriptionOptions, GetStateOptions, } from "./pregel/types.js";
|
|
3
3
|
export type { PregelNode } from "./pregel/read.js";
|
|
4
4
|
export type { Pregel } from "./pregel/index.js";
|
|
5
5
|
export * from "./errors.js";
|
package/dist/web.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web.js","sourceRoot":"","sources":["../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EAEL,UAAU,EACV,kBAAkB,EAClB,YAAY,EACZ,SAAS,EACT,oBAAoB,EACpB,oBAAoB,IAAI,WAAW,EACnC,mBAAmB,EAEnB,UAAU,GAOX,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EAEL,UAAU,EACV,kBAAkB,EAClB,YAAY,EACZ,SAAS,EACT,oBAAoB,EACpB,oBAAoB,IAAI,WAAW,EACnC,mBAAmB,EAEnB,UAAU,GAOX,MAAM,kBAAkB,CAAC;AAa1B,cAAc,aAAa,CAAC;AAC5B,OAAO,EACL,WAAW,EAEX,uBAAuB,GAOxB,MAAM,qBAAqB,CAAC;AAI7B,OAAO,EACL,IAAI,EACJ,OAAO,EAEP,SAAS,EACT,KAAK,EACL,GAAG,EACH,SAAS,EACT,aAAa,GAEd,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,WAAW,EAIX,cAAc,EACd,eAAe,EACf,mBAAmB,EAOnB,SAAS,EACT,iBAAiB,EACjB,aAAa,GAKd,MAAM,iCAAiC,CAAC;AACzC,cAAc,oBAAoB,CAAC;AAEnC,OAAO,EACL,UAAU,EAEV,IAAI,GAEL,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,gCAAgC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/langgraph",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "LangGraph",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -35,10 +35,10 @@
|
|
|
35
35
|
"@langchain/langgraph-checkpoint": "~0.0.18",
|
|
36
36
|
"@langchain/langgraph-sdk": "~0.0.32",
|
|
37
37
|
"uuid": "^10.0.0",
|
|
38
|
-
"zod": "^3.
|
|
38
|
+
"zod": "^3.25.32"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"@langchain/core": ">=0.
|
|
41
|
+
"@langchain/core": ">=0.3.58 < 0.4.0",
|
|
42
42
|
"zod-to-json-schema": "^3.x"
|
|
43
43
|
},
|
|
44
44
|
"peerDependenciesMeta": {
|
|
@@ -49,9 +49,9 @@
|
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@langchain/anthropic": "^0.3.12",
|
|
51
51
|
"@langchain/community": "^0.3.27",
|
|
52
|
-
"@langchain/core": "^0.3.
|
|
53
|
-
"@langchain/langgraph-checkpoint-postgres": "
|
|
54
|
-
"@langchain/langgraph-checkpoint-sqlite": "
|
|
52
|
+
"@langchain/core": "^0.3.58",
|
|
53
|
+
"@langchain/langgraph-checkpoint-postgres": "workspace:*",
|
|
54
|
+
"@langchain/langgraph-checkpoint-sqlite": "workspace:*",
|
|
55
55
|
"@langchain/openai": "^0.4.0",
|
|
56
56
|
"@langchain/scripts": ">=0.1.3 <0.2.0",
|
|
57
57
|
"@swc/core": "^1.3.90",
|
|
@@ -185,4 +185,4 @@
|
|
|
185
185
|
"zod/schema.d.ts",
|
|
186
186
|
"zod/schema.d.cts"
|
|
187
187
|
]
|
|
188
|
-
}
|
|
188
|
+
}
|
package/dist/graph/zod/state.cjs
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isZodDefault = isZodDefault;
|
|
4
|
-
exports.isAnyZodObject = isAnyZodObject;
|
|
5
|
-
exports.withLangGraph = withLangGraph;
|
|
6
|
-
exports.getMeta = getMeta;
|
|
7
|
-
exports.extendMeta = extendMeta;
|
|
8
|
-
exports.getChannelsFromZod = getChannelsFromZod;
|
|
9
|
-
exports.applyZodPlugin = applyZodPlugin;
|
|
10
|
-
exports.applyExtraFromDescription = applyExtraFromDescription;
|
|
11
|
-
const binop_js_1 = require("../../channels/binop.cjs");
|
|
12
|
-
const last_value_js_1 = require("../../channels/last_value.cjs");
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
-
const META_MAP = new WeakMap();
|
|
15
|
-
function isZodType(value) {
|
|
16
|
-
return (typeof value === "object" &&
|
|
17
|
-
value != null &&
|
|
18
|
-
"_parse" in value &&
|
|
19
|
-
typeof value._parse === "function");
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* @internal
|
|
23
|
-
*/
|
|
24
|
-
function isZodDefault(value) {
|
|
25
|
-
return (isZodType(value) &&
|
|
26
|
-
"removeDefault" in value &&
|
|
27
|
-
typeof value.removeDefault === "function");
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* @internal
|
|
31
|
-
*/
|
|
32
|
-
function isAnyZodObject(value) {
|
|
33
|
-
return (isZodType(value) &&
|
|
34
|
-
"partial" in value &&
|
|
35
|
-
typeof value.partial === "function");
|
|
36
|
-
}
|
|
37
|
-
function withLangGraph(schema, meta) {
|
|
38
|
-
if (meta.reducer && !meta.default) {
|
|
39
|
-
const defaultValue = isZodDefault(schema)
|
|
40
|
-
? schema._def.defaultValue
|
|
41
|
-
: undefined;
|
|
42
|
-
if (defaultValue != null) {
|
|
43
|
-
// eslint-disable-next-line no-param-reassign
|
|
44
|
-
meta.default = defaultValue;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
META_MAP.set(schema, meta);
|
|
48
|
-
return schema;
|
|
49
|
-
}
|
|
50
|
-
function getMeta(schema) {
|
|
51
|
-
return META_MAP.get(schema);
|
|
52
|
-
}
|
|
53
|
-
function extendMeta(schema, update) {
|
|
54
|
-
const existingMeta = getMeta(schema);
|
|
55
|
-
const newMeta = update(existingMeta);
|
|
56
|
-
META_MAP.set(schema, newMeta);
|
|
57
|
-
}
|
|
58
|
-
function getChannelsFromZod(schema) {
|
|
59
|
-
const channels = {};
|
|
60
|
-
for (const key in schema.shape) {
|
|
61
|
-
if (Object.prototype.hasOwnProperty.call(schema.shape, key)) {
|
|
62
|
-
const keySchema = schema.shape[key];
|
|
63
|
-
const meta = getMeta(keySchema);
|
|
64
|
-
if (meta?.reducer) {
|
|
65
|
-
channels[key] = new binop_js_1.BinaryOperatorAggregate(meta.reducer.fn, meta.default);
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
channels[key] = new last_value_js_1.LastValue();
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return channels;
|
|
73
|
-
}
|
|
74
|
-
const ZOD_TYPE_CACHE = {};
|
|
75
|
-
const ZOD_DESCRIPTION_PREFIX = "lg:";
|
|
76
|
-
function applyZodPlugin(schema, actions) {
|
|
77
|
-
const cacheKey = [
|
|
78
|
-
`reducer:${actions.reducer ?? false}`,
|
|
79
|
-
`jsonSchemaExtra:${actions.jsonSchemaExtra ?? false}`,
|
|
80
|
-
`partial:${actions.partial ?? false}`,
|
|
81
|
-
].join("|");
|
|
82
|
-
ZOD_TYPE_CACHE[cacheKey] ??= new WeakMap();
|
|
83
|
-
const cache = ZOD_TYPE_CACHE[cacheKey];
|
|
84
|
-
if (cache.has(schema))
|
|
85
|
-
return cache.get(schema);
|
|
86
|
-
let shape = schema.extend({
|
|
87
|
-
...Object.fromEntries(Object.entries(schema.shape).map(([key, input]) => {
|
|
88
|
-
const meta = getMeta(input);
|
|
89
|
-
let output = actions.reducer ? meta?.reducer?.schema ?? input : input;
|
|
90
|
-
if (actions.jsonSchemaExtra) {
|
|
91
|
-
const strMeta = JSON.stringify({
|
|
92
|
-
...meta?.jsonSchemaExtra,
|
|
93
|
-
description: output.description ?? input.description,
|
|
94
|
-
});
|
|
95
|
-
if (strMeta !== "{}") {
|
|
96
|
-
output = output.describe(`${ZOD_DESCRIPTION_PREFIX}${strMeta}`);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return [key, output];
|
|
100
|
-
})),
|
|
101
|
-
});
|
|
102
|
-
// using zObject.extend() will set `unknownKeys` to `passthrough`
|
|
103
|
-
// which trips up `zod-to-json-schema`
|
|
104
|
-
if ("_def" in shape &&
|
|
105
|
-
shape._def != null &&
|
|
106
|
-
typeof shape._def === "object" &&
|
|
107
|
-
"unknownKeys" in shape._def) {
|
|
108
|
-
shape._def.unknownKeys = "strip";
|
|
109
|
-
}
|
|
110
|
-
if (actions.partial)
|
|
111
|
-
shape = shape.partial();
|
|
112
|
-
cache.set(schema, shape);
|
|
113
|
-
return shape;
|
|
114
|
-
}
|
|
115
|
-
function applyExtraFromDescription(schema) {
|
|
116
|
-
if (Array.isArray(schema)) {
|
|
117
|
-
return schema.map(applyExtraFromDescription);
|
|
118
|
-
}
|
|
119
|
-
if (typeof schema === "object" && schema != null) {
|
|
120
|
-
const output = Object.fromEntries(Object.entries(schema).map(([key, value]) => [
|
|
121
|
-
key,
|
|
122
|
-
applyExtraFromDescription(value),
|
|
123
|
-
]));
|
|
124
|
-
if ("description" in output &&
|
|
125
|
-
typeof output.description === "string" &&
|
|
126
|
-
output.description.startsWith(ZOD_DESCRIPTION_PREFIX)) {
|
|
127
|
-
const strMeta = output.description.slice(ZOD_DESCRIPTION_PREFIX.length);
|
|
128
|
-
delete output.description;
|
|
129
|
-
Object.assign(output, JSON.parse(strMeta));
|
|
130
|
-
}
|
|
131
|
-
return output;
|
|
132
|
-
}
|
|
133
|
-
return schema;
|
|
134
|
-
}
|
|
135
|
-
//# sourceMappingURL=state.js.map
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import type { z } from "zod";
|
|
2
|
-
import { BaseChannel } from "../../channels/base.js";
|
|
3
|
-
export interface Meta<ValueType, UpdateType = ValueType> {
|
|
4
|
-
jsonSchemaExtra?: {
|
|
5
|
-
langgraph_nodes?: string[];
|
|
6
|
-
langgraph_type?: "prompt" | "messages";
|
|
7
|
-
[key: string]: unknown;
|
|
8
|
-
};
|
|
9
|
-
reducer?: {
|
|
10
|
-
schema?: z.ZodType<UpdateType>;
|
|
11
|
-
fn: (a: ValueType, b: UpdateType) => ValueType;
|
|
12
|
-
};
|
|
13
|
-
default?: () => ValueType;
|
|
14
|
-
}
|
|
15
|
-
export type AnyZodObject = z.ZodObject<z.ZodRawShape>;
|
|
16
|
-
/**
|
|
17
|
-
* @internal
|
|
18
|
-
*/
|
|
19
|
-
export declare function isZodDefault(value: unknown): value is z.ZodDefault<z.ZodTypeAny>;
|
|
20
|
-
/**
|
|
21
|
-
* @internal
|
|
22
|
-
*/
|
|
23
|
-
export declare function isAnyZodObject(value: unknown): value is AnyZodObject;
|
|
24
|
-
export declare function withLangGraph<ValueType, UpdateType = ValueType>(schema: z.ZodType<ValueType | undefined>, meta: Meta<ValueType, UpdateType>): z.ZodType<ValueType, z.ZodTypeDef, UpdateType>;
|
|
25
|
-
export declare function getMeta<ValueType, UpdateType = ValueType>(schema: z.ZodType<ValueType>): Meta<ValueType, UpdateType> | undefined;
|
|
26
|
-
export declare function extendMeta<ValueType, UpdateType = ValueType>(schema: z.ZodType<ValueType>, update: (meta: Meta<ValueType, UpdateType> | undefined) => Meta<ValueType, UpdateType>): void;
|
|
27
|
-
export type ZodToStateDefinition<T extends AnyZodObject> = {
|
|
28
|
-
[key in keyof T["shape"]]: T["shape"][key] extends z.ZodType<infer V, z.ZodTypeDef, infer U> ? BaseChannel<V, U> : never;
|
|
29
|
-
};
|
|
30
|
-
export declare function getChannelsFromZod<T extends z.ZodRawShape>(schema: z.ZodObject<T>): ZodToStateDefinition<z.ZodObject<T>>;
|
|
31
|
-
export declare function applyZodPlugin(schema: z.AnyZodObject, actions: {
|
|
32
|
-
/** Apply .langgraph.reducer calls */
|
|
33
|
-
reducer?: boolean;
|
|
34
|
-
/** Apply .langgraph.metadata() calls */
|
|
35
|
-
jsonSchemaExtra?: boolean;
|
|
36
|
-
/** Apply .partial() */
|
|
37
|
-
partial?: boolean;
|
|
38
|
-
}): z.AnyZodObject;
|
|
39
|
-
export declare function applyExtraFromDescription(schema: unknown): unknown;
|
package/dist/graph/zod/state.js
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { BinaryOperatorAggregate } from "../../channels/binop.js";
|
|
2
|
-
import { LastValue } from "../../channels/last_value.js";
|
|
3
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4
|
-
const META_MAP = new WeakMap();
|
|
5
|
-
function isZodType(value) {
|
|
6
|
-
return (typeof value === "object" &&
|
|
7
|
-
value != null &&
|
|
8
|
-
"_parse" in value &&
|
|
9
|
-
typeof value._parse === "function");
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* @internal
|
|
13
|
-
*/
|
|
14
|
-
export function isZodDefault(value) {
|
|
15
|
-
return (isZodType(value) &&
|
|
16
|
-
"removeDefault" in value &&
|
|
17
|
-
typeof value.removeDefault === "function");
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* @internal
|
|
21
|
-
*/
|
|
22
|
-
export function isAnyZodObject(value) {
|
|
23
|
-
return (isZodType(value) &&
|
|
24
|
-
"partial" in value &&
|
|
25
|
-
typeof value.partial === "function");
|
|
26
|
-
}
|
|
27
|
-
export function withLangGraph(schema, meta) {
|
|
28
|
-
if (meta.reducer && !meta.default) {
|
|
29
|
-
const defaultValue = isZodDefault(schema)
|
|
30
|
-
? schema._def.defaultValue
|
|
31
|
-
: undefined;
|
|
32
|
-
if (defaultValue != null) {
|
|
33
|
-
// eslint-disable-next-line no-param-reassign
|
|
34
|
-
meta.default = defaultValue;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
META_MAP.set(schema, meta);
|
|
38
|
-
return schema;
|
|
39
|
-
}
|
|
40
|
-
export function getMeta(schema) {
|
|
41
|
-
return META_MAP.get(schema);
|
|
42
|
-
}
|
|
43
|
-
export function extendMeta(schema, update) {
|
|
44
|
-
const existingMeta = getMeta(schema);
|
|
45
|
-
const newMeta = update(existingMeta);
|
|
46
|
-
META_MAP.set(schema, newMeta);
|
|
47
|
-
}
|
|
48
|
-
export function getChannelsFromZod(schema) {
|
|
49
|
-
const channels = {};
|
|
50
|
-
for (const key in schema.shape) {
|
|
51
|
-
if (Object.prototype.hasOwnProperty.call(schema.shape, key)) {
|
|
52
|
-
const keySchema = schema.shape[key];
|
|
53
|
-
const meta = getMeta(keySchema);
|
|
54
|
-
if (meta?.reducer) {
|
|
55
|
-
channels[key] = new BinaryOperatorAggregate(meta.reducer.fn, meta.default);
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
channels[key] = new LastValue();
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return channels;
|
|
63
|
-
}
|
|
64
|
-
const ZOD_TYPE_CACHE = {};
|
|
65
|
-
const ZOD_DESCRIPTION_PREFIX = "lg:";
|
|
66
|
-
export function applyZodPlugin(schema, actions) {
|
|
67
|
-
const cacheKey = [
|
|
68
|
-
`reducer:${actions.reducer ?? false}`,
|
|
69
|
-
`jsonSchemaExtra:${actions.jsonSchemaExtra ?? false}`,
|
|
70
|
-
`partial:${actions.partial ?? false}`,
|
|
71
|
-
].join("|");
|
|
72
|
-
ZOD_TYPE_CACHE[cacheKey] ??= new WeakMap();
|
|
73
|
-
const cache = ZOD_TYPE_CACHE[cacheKey];
|
|
74
|
-
if (cache.has(schema))
|
|
75
|
-
return cache.get(schema);
|
|
76
|
-
let shape = schema.extend({
|
|
77
|
-
...Object.fromEntries(Object.entries(schema.shape).map(([key, input]) => {
|
|
78
|
-
const meta = getMeta(input);
|
|
79
|
-
let output = actions.reducer ? meta?.reducer?.schema ?? input : input;
|
|
80
|
-
if (actions.jsonSchemaExtra) {
|
|
81
|
-
const strMeta = JSON.stringify({
|
|
82
|
-
...meta?.jsonSchemaExtra,
|
|
83
|
-
description: output.description ?? input.description,
|
|
84
|
-
});
|
|
85
|
-
if (strMeta !== "{}") {
|
|
86
|
-
output = output.describe(`${ZOD_DESCRIPTION_PREFIX}${strMeta}`);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return [key, output];
|
|
90
|
-
})),
|
|
91
|
-
});
|
|
92
|
-
// using zObject.extend() will set `unknownKeys` to `passthrough`
|
|
93
|
-
// which trips up `zod-to-json-schema`
|
|
94
|
-
if ("_def" in shape &&
|
|
95
|
-
shape._def != null &&
|
|
96
|
-
typeof shape._def === "object" &&
|
|
97
|
-
"unknownKeys" in shape._def) {
|
|
98
|
-
shape._def.unknownKeys = "strip";
|
|
99
|
-
}
|
|
100
|
-
if (actions.partial)
|
|
101
|
-
shape = shape.partial();
|
|
102
|
-
cache.set(schema, shape);
|
|
103
|
-
return shape;
|
|
104
|
-
}
|
|
105
|
-
export function applyExtraFromDescription(schema) {
|
|
106
|
-
if (Array.isArray(schema)) {
|
|
107
|
-
return schema.map(applyExtraFromDescription);
|
|
108
|
-
}
|
|
109
|
-
if (typeof schema === "object" && schema != null) {
|
|
110
|
-
const output = Object.fromEntries(Object.entries(schema).map(([key, value]) => [
|
|
111
|
-
key,
|
|
112
|
-
applyExtraFromDescription(value),
|
|
113
|
-
]));
|
|
114
|
-
if ("description" in output &&
|
|
115
|
-
typeof output.description === "string" &&
|
|
116
|
-
output.description.startsWith(ZOD_DESCRIPTION_PREFIX)) {
|
|
117
|
-
const strMeta = output.description.slice(ZOD_DESCRIPTION_PREFIX.length);
|
|
118
|
-
delete output.description;
|
|
119
|
-
Object.assign(output, JSON.parse(strMeta));
|
|
120
|
-
}
|
|
121
|
-
return output;
|
|
122
|
-
}
|
|
123
|
-
return schema;
|
|
124
|
-
}
|
|
125
|
-
//# sourceMappingURL=state.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"state.js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