@langchain/langgraph 1.1.0 → 1.1.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/errors.d.cts.map +1 -1
- package/dist/graph/annotation.cjs +3 -0
- package/dist/graph/annotation.cjs.map +1 -1
- package/dist/graph/annotation.d.cts +1 -0
- package/dist/graph/annotation.d.cts.map +1 -1
- package/dist/graph/annotation.d.ts +1 -0
- package/dist/graph/annotation.d.ts.map +1 -1
- package/dist/graph/annotation.js +3 -0
- package/dist/graph/annotation.js.map +1 -1
- package/dist/graph/graph.cjs +3 -3
- package/dist/graph/graph.cjs.map +1 -1
- package/dist/graph/graph.js +3 -3
- package/dist/graph/graph.js.map +1 -1
- package/dist/graph/message.d.cts +2 -2
- package/dist/graph/message.d.cts.map +1 -1
- package/dist/graph/message.d.ts +2 -2
- package/dist/graph/message.d.ts.map +1 -1
- package/dist/graph/messages_annotation.d.cts +5 -5
- package/dist/graph/messages_annotation.d.cts.map +1 -1
- package/dist/graph/messages_annotation.d.ts +5 -5
- package/dist/graph/messages_annotation.d.ts.map +1 -1
- package/dist/graph/state.cjs +98 -78
- package/dist/graph/state.cjs.map +1 -1
- package/dist/graph/state.d.cts +68 -35
- package/dist/graph/state.d.cts.map +1 -1
- package/dist/graph/state.d.ts +68 -35
- package/dist/graph/state.d.ts.map +1 -1
- package/dist/graph/state.js +99 -79
- package/dist/graph/state.js.map +1 -1
- package/dist/graph/types.cjs +41 -0
- package/dist/graph/types.cjs.map +1 -0
- package/dist/graph/types.d.cts +247 -18
- package/dist/graph/types.d.cts.map +1 -1
- package/dist/graph/types.d.ts +247 -18
- package/dist/graph/types.d.ts.map +1 -1
- package/dist/graph/types.js +40 -0
- package/dist/graph/types.js.map +1 -0
- package/dist/graph/zod/meta.cjs +4 -4
- package/dist/graph/zod/meta.cjs.map +1 -1
- package/dist/graph/zod/meta.js +4 -4
- package/dist/graph/zod/meta.js.map +1 -1
- package/dist/graph/zod/zod-registry.d.cts.map +1 -1
- package/dist/graph/zod/zod-registry.d.ts.map +1 -1
- package/dist/hash.cjs +1 -1
- package/dist/hash.cjs.map +1 -1
- package/dist/hash.js +1 -1
- package/dist/hash.js.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/prebuilt/agent_executor.d.cts +5 -5
- package/dist/prebuilt/agent_executor.d.cts.map +1 -1
- package/dist/prebuilt/agent_executor.d.ts +5 -5
- package/dist/prebuilt/agent_executor.d.ts.map +1 -1
- package/dist/prebuilt/react_agent_executor.cjs +12 -12
- package/dist/prebuilt/react_agent_executor.cjs.map +1 -1
- package/dist/prebuilt/react_agent_executor.d.cts +3 -3
- package/dist/prebuilt/react_agent_executor.d.cts.map +1 -1
- package/dist/prebuilt/react_agent_executor.d.ts +3 -3
- package/dist/prebuilt/react_agent_executor.d.ts.map +1 -1
- package/dist/prebuilt/react_agent_executor.js +12 -12
- package/dist/prebuilt/react_agent_executor.js.map +1 -1
- package/dist/prebuilt/tool_node.cjs +1 -1
- package/dist/prebuilt/tool_node.cjs.map +1 -1
- package/dist/prebuilt/tool_node.js +1 -1
- package/dist/prebuilt/tool_node.js.map +1 -1
- package/dist/pregel/debug.cjs +9 -9
- package/dist/pregel/debug.cjs.map +1 -1
- package/dist/pregel/debug.js +9 -9
- package/dist/pregel/debug.js.map +1 -1
- package/dist/pregel/index.cjs +44 -44
- package/dist/pregel/index.cjs.map +1 -1
- package/dist/pregel/index.js +44 -44
- package/dist/pregel/index.js.map +1 -1
- package/dist/pregel/loop.cjs +1 -1
- package/dist/pregel/loop.cjs.map +1 -1
- package/dist/pregel/loop.js +1 -1
- package/dist/pregel/loop.js.map +1 -1
- package/dist/pregel/utils/subgraph.cjs +2 -2
- package/dist/pregel/utils/subgraph.cjs.map +1 -1
- package/dist/pregel/utils/subgraph.js +2 -2
- package/dist/pregel/utils/subgraph.js.map +1 -1
- package/dist/state/schema.cjs +8 -9
- package/dist/state/schema.cjs.map +1 -1
- package/dist/state/schema.d.cts +18 -22
- package/dist/state/schema.d.cts.map +1 -1
- package/dist/state/schema.d.ts +18 -22
- package/dist/state/schema.d.ts.map +1 -1
- package/dist/state/schema.js +8 -9
- package/dist/state/schema.js.map +1 -1
- package/dist/state/values/reduced.cjs.map +1 -1
- package/dist/state/values/reduced.d.cts +1 -1
- package/dist/state/values/reduced.d.cts.map +1 -1
- package/dist/state/values/reduced.d.ts +1 -1
- package/dist/state/values/reduced.d.ts.map +1 -1
- package/dist/state/values/reduced.js.map +1 -1
- package/dist/state/values/untracked.cjs.map +1 -1
- package/dist/state/values/untracked.d.cts +4 -0
- package/dist/state/values/untracked.d.cts.map +1 -1
- package/dist/state/values/untracked.d.ts +4 -0
- package/dist/state/values/untracked.d.ts.map +1 -1
- package/dist/state/values/untracked.js.map +1 -1
- package/dist/web.d.cts +3 -3
- package/dist/web.d.ts +3 -3
- package/package.json +6 -6
package/dist/state/schema.cjs
CHANGED
|
@@ -48,9 +48,8 @@ var StateSchema = class {
|
|
|
48
48
|
* @internal Used by isInstance for runtime type checking
|
|
49
49
|
*/
|
|
50
50
|
[STATE_SCHEMA_SYMBOL] = true;
|
|
51
|
-
constructor(
|
|
52
|
-
this.
|
|
53
|
-
this.init = init;
|
|
51
|
+
constructor(fields) {
|
|
52
|
+
this.fields = fields;
|
|
54
53
|
}
|
|
55
54
|
/**
|
|
56
55
|
* Get the channel definitions for use with StateGraph.
|
|
@@ -58,7 +57,7 @@ var StateSchema = class {
|
|
|
58
57
|
*/
|
|
59
58
|
getChannels() {
|
|
60
59
|
const channels = {};
|
|
61
|
-
for (const [key, value] of Object.entries(this.
|
|
60
|
+
for (const [key, value] of Object.entries(this.fields)) if (require_reduced.ReducedValue.isInstance(value)) {
|
|
62
61
|
const defaultGetter = require_adapter.getSchemaDefaultGetter(value.valueSchema);
|
|
63
62
|
channels[key] = new require_binop.BinaryOperatorAggregate(value.reducer, defaultGetter);
|
|
64
63
|
} else if (require_untracked.UntrackedValue.isInstance(value)) {
|
|
@@ -78,7 +77,7 @@ var StateSchema = class {
|
|
|
78
77
|
getJsonSchema() {
|
|
79
78
|
const properties = {};
|
|
80
79
|
const required = [];
|
|
81
|
-
for (const [key, value] of Object.entries(this.
|
|
80
|
+
for (const [key, value] of Object.entries(this.fields)) {
|
|
82
81
|
let fieldSchema;
|
|
83
82
|
if (require_reduced.ReducedValue.isInstance(value)) {
|
|
84
83
|
fieldSchema = require_adapter.getJsonSchemaFromSchema(value.valueSchema);
|
|
@@ -109,7 +108,7 @@ var StateSchema = class {
|
|
|
109
108
|
*/
|
|
110
109
|
getInputJsonSchema() {
|
|
111
110
|
const properties = {};
|
|
112
|
-
for (const [key, value] of Object.entries(this.
|
|
111
|
+
for (const [key, value] of Object.entries(this.fields)) {
|
|
113
112
|
let fieldSchema;
|
|
114
113
|
if (require_reduced.ReducedValue.isInstance(value)) fieldSchema = require_adapter.getJsonSchemaFromSchema(value.inputSchema);
|
|
115
114
|
else if (require_untracked.UntrackedValue.isInstance(value)) fieldSchema = value.schema ? require_adapter.getJsonSchemaFromSchema(value.schema) : void 0;
|
|
@@ -125,13 +124,13 @@ var StateSchema = class {
|
|
|
125
124
|
* Get the list of channel keys (excluding managed values).
|
|
126
125
|
*/
|
|
127
126
|
getChannelKeys() {
|
|
128
|
-
return Object.entries(this.
|
|
127
|
+
return Object.entries(this.fields).map(([key]) => key);
|
|
129
128
|
}
|
|
130
129
|
/**
|
|
131
130
|
* Get all keys (channels + managed values).
|
|
132
131
|
*/
|
|
133
132
|
getAllKeys() {
|
|
134
|
-
return Object.keys(this.
|
|
133
|
+
return Object.keys(this.fields);
|
|
135
134
|
}
|
|
136
135
|
/**
|
|
137
136
|
* Validate input data against the schema.
|
|
@@ -144,7 +143,7 @@ var StateSchema = class {
|
|
|
144
143
|
if (data == null || typeof data !== "object") return data;
|
|
145
144
|
const result = {};
|
|
146
145
|
for (const [key, value] of Object.entries(data)) {
|
|
147
|
-
const fieldDef = this.
|
|
146
|
+
const fieldDef = this.fields[key];
|
|
148
147
|
if (fieldDef === void 0) {
|
|
149
148
|
result[key] = value;
|
|
150
149
|
continue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.cjs","names":["ReducedValue","getSchemaDefaultGetter","BinaryOperatorAggregate","UntrackedValue","UntrackedValueChannel","isStandardSchema","LastValue","getJsonSchemaFromSchema"],"sources":["../../src/state/schema.ts"],"sourcesContent":["import type { JSONSchema } from \"@langchain/core/utils/json_schema\";\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\n\nimport type { RunnableLike } from \"../pregel/runnable_types.js\";\nimport {\n BaseChannel,\n LastValue,\n BinaryOperatorAggregate,\n} from \"../channels/index.js\";\nimport { UntrackedValueChannel } from \"../channels/untracked_value.js\";\n\nimport type { SerializableSchema } from \"./types.js\";\nimport { isStandardSchema } from \"./types.js\";\nimport { getJsonSchemaFromSchema, getSchemaDefaultGetter } from \"./adapter.js\";\nimport { ReducedValue } from \"./values/reduced.js\";\nimport { UntrackedValue } from \"./values/untracked.js\";\n\nconst STATE_SCHEMA_SYMBOL = Symbol.for(\"langgraph.state.state_schema\");\n\n/**\n * Maps a single StateSchema field definition to its corresponding Channel type.\n *\n * This utility type inspects the type of the field and returns an appropriate\n * `BaseChannel` type, parameterized with the state \"value\" and \"input\" types according to the field's shape.\n *\n * Rules:\n * - If the field (`F`) is a `ReducedValue<V, I>`, the channel will store values of type `V`\n * and accept input of type `I`.\n * - If the field is a `UntrackedValue<V>`, the channel will store and accept values of type `V`.\n * - If the field is a `SerializableSchema<I, O>`, the channel will store values of type `O`\n * (the schema's output/validated value) and accept input of type `I`.\n * - For all other types, a generic `BaseChannel<unknown, unknown>` is used as fallback.\n *\n * @template F - The StateSchema field type to map to a Channel type.\n *\n * @example\n * ```typescript\n * type MyField = ReducedValue<number, string>;\n * type ChannelType = StateSchemaFieldToChannel<MyField>;\n * // ChannelType is BaseChannel<number, string>\n * ```\n */\nexport type StateSchemaFieldToChannel<F> = F extends ReducedValue<\n infer V,\n infer I\n>\n ? BaseChannel<V, I>\n : F extends UntrackedValue<infer V>\n ? BaseChannel<V, V>\n : F extends SerializableSchema<infer I, infer O>\n ? BaseChannel<O, I>\n : BaseChannel<unknown, unknown>;\n\n/**\n * Converts a StateSchema \"init\" object (field map) into a strongly-typed\n * State Definition object, where each key is mapped to its channel type.\n *\n * This utility type is used internally to create the shape of the state channels for a given schema,\n * substituting each field with the result of `StateSchemaFieldToChannel`.\n *\n * If you define a state schema as:\n * ```typescript\n * const fields = {\n * a: ReducedValue<number, string>(),\n * b: UntrackedValue<boolean>(),\n * c: SomeSerializableSchemaType, // SerializableSchema<in, out>\n * }\n * ```\n * then `StateSchemaFieldsToStateDefinition<typeof fields>` yields:\n * ```typescript\n * {\n * a: BaseChannel<number, string>;\n * b: BaseChannel<boolean, boolean>;\n * c: BaseChannel<typeof schema's output type, typeof schema's input type>;\n * }\n * ```\n *\n * @template TInit - The mapping of field names to StateSchema field types.\n * @returns An object type mapping keys to channel types.\n *\n * @see StateSchemaFieldToChannel\n */\nexport type StateSchemaFieldsToStateDefinition<TInit extends StateSchemaInit> =\n {\n [K in keyof TInit]: StateSchemaFieldToChannel<TInit[K]>;\n };\n\n/**\n * Valid field types for StateSchema.\n * Either a LangGraph state value type or a raw schema (e.g., Zod schema).\n */\nexport type StateSchemaField<Input = unknown, Output = Input> =\n | ReducedValue<Input, Output>\n | UntrackedValue<Output>\n | SerializableSchema<Input, Output>;\n\n/**\n * Init object for StateSchema constructor.\n * Uses `any` to allow variance in generic types (e.g., ReducedValue<string, string[]>).\n */\nexport type StateSchemaInit = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [key: string]: StateSchemaField<any, any>;\n};\n\n/**\n * Infer the State type from a StateSchemaInit.\n * This is the type of the full state object.\n *\n * - ReducedValue<Value, Input> → Value (the stored type)\n * - UntrackedValue<Value> → Value\n * - SerializableSchema<Input, Output> → Output (the validated type)\n */\nexport type InferStateSchemaValue<TInit extends StateSchemaInit> = {\n [K in keyof TInit]: TInit[K] extends { ValueType: infer TValue }\n ? TValue\n : TInit[K] extends UntrackedValue<infer TValue>\n ? TValue\n : TInit[K] extends SerializableSchema<unknown, infer TOutput>\n ? TOutput\n : never;\n};\n\n/**\n * Infer the Update type from a StateSchemaInit.\n * This is the type for partial updates to state.\n *\n * - ReducedValue<Value, Input> → Input (the reducer input type)\n * - UntrackedValue<Value> → Value\n * - SerializableSchema<Input, Output> → Input (what you provide)\n */\nexport type InferStateSchemaUpdate<TInit extends StateSchemaInit> = {\n [K in keyof TInit]?: TInit[K] extends { InputType: infer TInput }\n ? TInput\n : TInit[K] extends UntrackedValue<infer TValue>\n ? TValue\n : TInit[K] extends SerializableSchema<infer TInput, unknown>\n ? TInput\n : never;\n};\n\n/**\n * StateSchema provides a unified API for defining LangGraph state schemas.\n *\n * @example\n * ```ts\n * import { z } from \"zod\";\n * import { StateSchema, ReducedValue, MessagesValue } from \"@langchain/langgraph\";\n *\n * const AgentState = new StateSchema({\n * // Prebuilt messages value\n * messages: MessagesValue,\n * // Basic LastValue channel from any standard schema\n * currentStep: z.string(),\n * // LastValue with native default\n * count: z.number().default(0),\n * // ReducedValue for fields needing reducers\n * history: new ReducedValue(\n * z.array(z.string()).default(() => []),\n * {\n * inputSchema: z.string(),\n * reducer: (current, next) => [...current, next],\n * }\n * ),\n * });\n *\n * // Extract types\n * type State = typeof AgentState.State;\n * type Update = typeof AgentState.Update;\n *\n * // Use in StateGraph\n * const graph = new StateGraph(AgentState);\n * ```\n */\nexport class StateSchema<TInit extends StateSchemaInit> {\n /**\n * Symbol for runtime identification.\n * @internal Used by isInstance for runtime type checking\n */\n // @ts-expect-error - Symbol is read via `in` operator in isInstance\n private readonly [STATE_SCHEMA_SYMBOL] = true;\n\n /**\n * Type declaration for the full state type.\n * Use: `typeof myState.State`\n */\n declare State: InferStateSchemaValue<TInit>;\n\n /**\n * Type declaration for the update type.\n * Use: `typeof myState.Update`\n */\n declare Update: InferStateSchemaUpdate<TInit>;\n\n /**\n * Type declaration for node functions.\n * Use: `typeof myState.Node` to type node functions outside the graph builder.\n *\n * @example\n * ```typescript\n * const AgentState = new StateSchema({\n * count: z.number().default(0),\n * });\n *\n * const myNode: typeof AgentState.Node = (state) => {\n * return { count: state.count + 1 };\n * };\n * ```\n */\n declare Node: RunnableLike<\n InferStateSchemaValue<TInit>,\n InferStateSchemaUpdate<TInit>\n >;\n\n constructor(readonly init: TInit) {\n this.init = init;\n }\n\n /**\n * Get the channel definitions for use with StateGraph.\n * This converts the StateSchema fields into BaseChannel instances.\n */\n getChannels(): Record<string, BaseChannel> {\n const channels: Record<string, BaseChannel> = {};\n\n for (const [key, value] of Object.entries(this.init)) {\n if (ReducedValue.isInstance(value)) {\n // ReducedValue -> BinaryOperatorAggregate\n const defaultGetter = getSchemaDefaultGetter(value.valueSchema);\n channels[key] = new BinaryOperatorAggregate(\n value.reducer,\n defaultGetter\n );\n } else if (UntrackedValue.isInstance(value)) {\n // UntrackedValue -> UntrackedValueChannel\n const defaultGetter = value.schema\n ? getSchemaDefaultGetter(value.schema)\n : undefined;\n channels[key] = new UntrackedValueChannel({\n guard: value.guard,\n initialValueFactory: defaultGetter,\n });\n } else if (isStandardSchema(value)) {\n // Plain schema -> LastValue channel\n const defaultGetter = getSchemaDefaultGetter(value);\n channels[key] = new LastValue(defaultGetter);\n } else {\n throw new Error(\n `Invalid state field \"${key}\": must be a schema, ReducedValue, UntrackedValue, or ManagedValue`\n );\n }\n }\n\n return channels;\n }\n\n /**\n * Get the JSON schema for the full state type.\n * Used by Studio and API for schema introspection.\n */\n getJsonSchema(): JSONSchema {\n const properties: Record<string, JSONSchema> = {};\n const required: string[] = [];\n\n for (const [key, value] of Object.entries(this.init)) {\n let fieldSchema: JSONSchema | undefined;\n\n if (ReducedValue.isInstance(value)) {\n fieldSchema = getJsonSchemaFromSchema(value.valueSchema) as JSONSchema;\n if (fieldSchema && value.jsonSchemaExtra) {\n fieldSchema = { ...fieldSchema, ...value.jsonSchemaExtra };\n }\n } else if (UntrackedValue.isInstance(value)) {\n fieldSchema = value.schema\n ? (getJsonSchemaFromSchema(value.schema) as JSONSchema)\n : undefined;\n } else if (isStandardSchema(value)) {\n fieldSchema = getJsonSchemaFromSchema(value) as JSONSchema;\n }\n\n if (fieldSchema) {\n properties[key] = fieldSchema;\n\n // Field is required if it doesn't have a default\n let hasDefault = false;\n if (ReducedValue.isInstance(value)) {\n hasDefault = getSchemaDefaultGetter(value.valueSchema) !== undefined;\n } else if (UntrackedValue.isInstance(value)) {\n hasDefault = value.schema\n ? getSchemaDefaultGetter(value.schema) !== undefined\n : false;\n } else {\n hasDefault = getSchemaDefaultGetter(value) !== undefined;\n }\n\n if (!hasDefault) {\n required.push(key);\n }\n }\n }\n\n return {\n type: \"object\",\n properties,\n required: required.length > 0 ? required : undefined,\n };\n }\n\n /**\n * Get the JSON schema for the update/input type.\n * All fields are optional in updates.\n */\n getInputJsonSchema(): JSONSchema {\n const properties: Record<string, JSONSchema> = {};\n\n for (const [key, value] of Object.entries(this.init)) {\n let fieldSchema: JSONSchema | undefined;\n\n if (ReducedValue.isInstance(value)) {\n // Use input schema for updates\n fieldSchema = getJsonSchemaFromSchema(value.inputSchema) as JSONSchema;\n } else if (UntrackedValue.isInstance(value)) {\n fieldSchema = value.schema\n ? (getJsonSchemaFromSchema(value.schema) as JSONSchema)\n : undefined;\n } else if (isStandardSchema(value)) {\n fieldSchema = getJsonSchemaFromSchema(value) as JSONSchema;\n }\n\n if (fieldSchema) {\n properties[key] = fieldSchema;\n }\n }\n\n return {\n type: \"object\",\n properties,\n };\n }\n\n /**\n * Get the list of channel keys (excluding managed values).\n */\n getChannelKeys(): string[] {\n return Object.entries(this.init).map(([key]) => key);\n }\n\n /**\n * Get all keys (channels + managed values).\n */\n getAllKeys(): string[] {\n return Object.keys(this.init);\n }\n\n /**\n * Validate input data against the schema.\n * This validates each field using its corresponding schema.\n *\n * @param data - The input data to validate\n * @returns The validated data with coerced types\n */\n async validateInput<T>(data: T): Promise<T> {\n if (data == null || typeof data !== \"object\") {\n return data;\n }\n\n const result: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(data)) {\n const fieldDef = this.init[key];\n\n if (fieldDef === undefined) {\n // Unknown field, pass through\n result[key] = value;\n continue;\n }\n\n // Get the schema to use for validation\n let schema: StandardSchemaV1 | undefined;\n\n if (ReducedValue.isInstance(fieldDef)) {\n schema = fieldDef.inputSchema;\n } else if (UntrackedValue.isInstance(fieldDef)) {\n schema = fieldDef.schema;\n } else if (isStandardSchema(fieldDef)) {\n schema = fieldDef;\n }\n\n if (schema) {\n // Validate using standard schema\n const validationResult = await schema[\"~standard\"].validate(value);\n if (validationResult.issues) {\n throw new Error(\n `Validation failed for field \"${key}\": ${JSON.stringify(\n validationResult.issues\n )}`\n );\n }\n result[key] = validationResult.value;\n } else {\n // No schema or not a standard schema, pass through\n result[key] = value;\n }\n }\n\n return result as T;\n }\n\n /**\n * Type guard to check if a value is a StateSchema instance.\n *\n * @param value - The value to check.\n * @returns True if the value is a StateSchema instance with the correct runtime tag.\n */\n static isInstance<TInit extends StateSchemaInit>(\n value: StateSchema<TInit>\n ): value is StateSchema<TInit>;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n static isInstance(value: unknown): value is StateSchema<any>;\n\n static isInstance<TInit extends StateSchemaInit>(\n value: unknown\n ): value is StateSchema<TInit> {\n return (\n typeof value === \"object\" &&\n value !== null &&\n STATE_SCHEMA_SYMBOL in value &&\n value[STATE_SCHEMA_SYMBOL] === true\n );\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyStateSchema = StateSchema<any>;\n"],"mappings":";;;;;;;;;;AAiBA,MAAM,sBAAsB,OAAO,IAAI,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6JtE,IAAa,cAAb,MAAwD;;;;;CAMtD,CAAkB,uBAAuB;CAkCzC,YAAY,AAAS,MAAa;EAAb;AACnB,OAAK,OAAO;;;;;;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AIlB,SAAO;;CAgBT,OAAO,WACL,OAC6B;AAC7B,SACE,OAAO,UAAU,YACjB,UAAU,QACV,uBAAuB,SACvB,MAAM,yBAAyB"}
|
|
1
|
+
{"version":3,"file":"schema.cjs","names":["ReducedValue","getSchemaDefaultGetter","BinaryOperatorAggregate","UntrackedValue","UntrackedValueChannel","isStandardSchema","LastValue","getJsonSchemaFromSchema"],"sources":["../../src/state/schema.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { JSONSchema } from \"@langchain/core/utils/json_schema\";\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\n\nimport type { RunnableLike } from \"../pregel/runnable_types.js\";\nimport {\n BaseChannel,\n LastValue,\n BinaryOperatorAggregate,\n} from \"../channels/index.js\";\nimport { UntrackedValueChannel } from \"../channels/untracked_value.js\";\n\nimport type { SerializableSchema } from \"./types.js\";\nimport { isStandardSchema } from \"./types.js\";\nimport { getJsonSchemaFromSchema, getSchemaDefaultGetter } from \"./adapter.js\";\nimport { ReducedValue } from \"./values/reduced.js\";\nimport { UntrackedValue } from \"./values/untracked.js\";\n\nconst STATE_SCHEMA_SYMBOL = Symbol.for(\"langgraph.state.state_schema\");\n\n/**\n * Maps a single StateSchema field definition to its corresponding Channel type.\n *\n * This utility type inspects the type of the field and returns an appropriate\n * `BaseChannel` type, parameterized with the state \"value\" and \"input\" types according to the field's shape.\n *\n * Rules:\n * - If the field (`F`) is a `ReducedValue<V, I>`, the channel will store values of type `V`\n * and accept input of type `I`.\n * - If the field is a `UntrackedValue<V>`, the channel will store and accept values of type `V`.\n * - If the field is a `SerializableSchema<I, O>`, the channel will store values of type `O`\n * (the schema's output/validated value) and accept input of type `I`.\n * - For all other types, a generic `BaseChannel<unknown, unknown>` is used as fallback.\n *\n * @template F - The StateSchema field type to map to a Channel type.\n *\n * @example\n * ```typescript\n * type MyField = ReducedValue<number, string>;\n * type ChannelType = StateSchemaFieldToChannel<MyField>;\n * // ChannelType is BaseChannel<number, string>\n * ```\n */\nexport type StateSchemaFieldToChannel<F> = F extends ReducedValue<\n infer V,\n infer I\n>\n ? BaseChannel<V, I>\n : F extends UntrackedValue<infer V>\n ? BaseChannel<V, V>\n : F extends SerializableSchema<infer I, infer O>\n ? BaseChannel<O, I>\n : BaseChannel<unknown, unknown>;\n\n/**\n * Converts StateSchema fields into a strongly-typed\n * State Definition object, where each field is mapped to its channel type.\n *\n * This utility type is used internally to create the shape of the state channels for a given schema,\n * substituting each field with the result of `StateSchemaFieldToChannel`.\n *\n * If you define a state schema as:\n * ```typescript\n * const fields = {\n * a: ReducedValue<number, string>(),\n * b: UntrackedValue<boolean>(),\n * c: SomeSerializableSchemaType, // SerializableSchema<in, out>\n * }\n * ```\n * then `StateSchemaFieldsToStateDefinition<typeof fields>` yields:\n * ```typescript\n * {\n * a: BaseChannel<number, string>;\n * b: BaseChannel<boolean, boolean>;\n * c: BaseChannel<typeof schema's output type, typeof schema's input type>;\n * }\n * ```\n *\n * @template TFields - The mapping of field names to StateSchema field types.\n * @returns An object type mapping field names to channel types.\n *\n * @see StateSchemaFieldToChannel\n */\nexport type StateSchemaFieldsToStateDefinition<\n TFields extends StateSchemaFields\n> = {\n [K in keyof TFields]: StateSchemaFieldToChannel<TFields[K]>;\n};\n\n/**\n * Valid field types for StateSchema.\n * Either a LangGraph state value type or a raw schema (e.g., Zod schema).\n */\nexport type StateSchemaField<Input = unknown, Output = Input> =\n | ReducedValue<Input, Output>\n | UntrackedValue<Output>\n | SerializableSchema<Input, Output>;\n\n/**\n * Init object for StateSchema constructor.\n * Uses `any` to allow variance in generic types (e.g., ReducedValue<string, string[]>).\n */\nexport type StateSchemaFields = {\n [key: string]: StateSchemaField<any, any>;\n};\n\n/**\n * Infer the State type from a StateSchemaFields.\n * This is the type of the full state object.\n *\n * - ReducedValue<Value, Input> → Value (the stored type)\n * - UntrackedValue<Value> → Value\n * - SerializableSchema<Input, Output> → Output (the validated type)\n */\nexport type InferStateSchemaValue<TFields extends StateSchemaFields> = {\n [K in keyof TFields]: TFields[K] extends ReducedValue<any, any>\n ? TFields[K][\"ValueType\"]\n : TFields[K] extends UntrackedValue<any>\n ? TFields[K][\"ValueType\"]\n : TFields[K] extends SerializableSchema<any, infer TOutput>\n ? TOutput\n : never;\n};\n\n/**\n * Infer the Update type from a StateSchemaFields.\n * This is the type for partial updates to state.\n *\n * - ReducedValue<Value, Input> → Input (the reducer input type)\n * - UntrackedValue<Value> → Value\n * - SerializableSchema<Input, Output> → Input (what you provide)\n */\nexport type InferStateSchemaUpdate<TFields extends StateSchemaFields> = {\n [K in keyof TFields]?: TFields[K] extends ReducedValue<any, any>\n ? TFields[K][\"InputType\"]\n : TFields[K] extends UntrackedValue<any>\n ? TFields[K][\"ValueType\"]\n : TFields[K] extends SerializableSchema<infer TInput, any>\n ? TInput\n : never;\n};\n\n/**\n * StateSchema provides a unified API for defining LangGraph state schemas.\n *\n * @example\n * ```ts\n * import { z } from \"zod\";\n * import { StateSchema, ReducedValue, MessagesValue } from \"@langchain/langgraph\";\n *\n * const AgentState = new StateSchema({\n * // Prebuilt messages value\n * messages: MessagesValue,\n * // Basic LastValue channel from any standard schema\n * currentStep: z.string(),\n * // LastValue with native default\n * count: z.number().default(0),\n * // ReducedValue for fields needing reducers\n * history: new ReducedValue(\n * z.array(z.string()).default(() => []),\n * {\n * inputSchema: z.string(),\n * reducer: (current, next) => [...current, next],\n * }\n * ),\n * });\n *\n * // Extract types\n * type State = typeof AgentState.State;\n * type Update = typeof AgentState.Update;\n *\n * // Use in StateGraph\n * const graph = new StateGraph(AgentState);\n * ```\n */\nexport class StateSchema<TFields extends StateSchemaFields> {\n /**\n * Symbol for runtime identification.\n * @internal Used by isInstance for runtime type checking\n */\n // @ts-expect-error - Symbol is read via `in` operator in isInstance\n private readonly [STATE_SCHEMA_SYMBOL] = true;\n\n /**\n * Type declaration for the full state type.\n * Use: `typeof myState.State`\n */\n declare State: InferStateSchemaValue<TFields>;\n\n /**\n * Type declaration for the update type.\n * Use: `typeof myState.Update`\n */\n declare Update: InferStateSchemaUpdate<TFields>;\n\n /**\n * Type declaration for node functions.\n * Use: `typeof myState.Node` to type node functions outside the graph builder.\n *\n * @example\n * ```typescript\n * const AgentState = new StateSchema({\n * count: z.number().default(0),\n * });\n *\n * const myNode: typeof AgentState.Node = (state) => {\n * return { count: state.count + 1 };\n * };\n * ```\n */\n declare Node: RunnableLike<\n InferStateSchemaValue<TFields>,\n InferStateSchemaUpdate<TFields>\n >;\n\n constructor(readonly fields: TFields) {}\n\n /**\n * Get the channel definitions for use with StateGraph.\n * This converts the StateSchema fields into BaseChannel instances.\n */\n getChannels(): Record<string, BaseChannel> {\n const channels: Record<string, BaseChannel> = {};\n\n for (const [key, value] of Object.entries(this.fields)) {\n if (ReducedValue.isInstance(value)) {\n // ReducedValue -> BinaryOperatorAggregate\n const defaultGetter = getSchemaDefaultGetter(value.valueSchema);\n channels[key] = new BinaryOperatorAggregate(\n value.reducer,\n defaultGetter\n );\n } else if (UntrackedValue.isInstance(value)) {\n // UntrackedValue -> UntrackedValueChannel\n const defaultGetter = value.schema\n ? getSchemaDefaultGetter(value.schema)\n : undefined;\n channels[key] = new UntrackedValueChannel({\n guard: value.guard,\n initialValueFactory: defaultGetter,\n });\n } else if (isStandardSchema(value)) {\n // Plain schema -> LastValue channel\n const defaultGetter = getSchemaDefaultGetter(value);\n channels[key] = new LastValue(defaultGetter);\n } else {\n throw new Error(\n `Invalid state field \"${key}\": must be a schema, ReducedValue, UntrackedValue, or ManagedValue`\n );\n }\n }\n\n return channels;\n }\n\n /**\n * Get the JSON schema for the full state type.\n * Used by Studio and API for schema introspection.\n */\n getJsonSchema(): JSONSchema {\n const properties: Record<string, JSONSchema> = {};\n const required: string[] = [];\n\n for (const [key, value] of Object.entries(this.fields)) {\n let fieldSchema: JSONSchema | undefined;\n\n if (ReducedValue.isInstance(value)) {\n fieldSchema = getJsonSchemaFromSchema(value.valueSchema) as JSONSchema;\n if (fieldSchema && value.jsonSchemaExtra) {\n fieldSchema = { ...fieldSchema, ...value.jsonSchemaExtra };\n }\n } else if (UntrackedValue.isInstance(value)) {\n fieldSchema = value.schema\n ? (getJsonSchemaFromSchema(value.schema) as JSONSchema)\n : undefined;\n } else if (isStandardSchema(value)) {\n fieldSchema = getJsonSchemaFromSchema(value) as JSONSchema;\n }\n\n if (fieldSchema) {\n properties[key] = fieldSchema;\n\n // Field is required if it doesn't have a default\n let hasDefault = false;\n if (ReducedValue.isInstance(value)) {\n hasDefault = getSchemaDefaultGetter(value.valueSchema) !== undefined;\n } else if (UntrackedValue.isInstance(value)) {\n hasDefault = value.schema\n ? getSchemaDefaultGetter(value.schema) !== undefined\n : false;\n } else {\n hasDefault = getSchemaDefaultGetter(value) !== undefined;\n }\n\n if (!hasDefault) {\n required.push(key);\n }\n }\n }\n\n return {\n type: \"object\",\n properties,\n required: required.length > 0 ? required : undefined,\n };\n }\n\n /**\n * Get the JSON schema for the update/input type.\n * All fields are optional in updates.\n */\n getInputJsonSchema(): JSONSchema {\n const properties: Record<string, JSONSchema> = {};\n\n for (const [key, value] of Object.entries(this.fields)) {\n let fieldSchema: JSONSchema | undefined;\n\n if (ReducedValue.isInstance(value)) {\n // Use input schema for updates\n fieldSchema = getJsonSchemaFromSchema(value.inputSchema) as JSONSchema;\n } else if (UntrackedValue.isInstance(value)) {\n fieldSchema = value.schema\n ? (getJsonSchemaFromSchema(value.schema) as JSONSchema)\n : undefined;\n } else if (isStandardSchema(value)) {\n fieldSchema = getJsonSchemaFromSchema(value) as JSONSchema;\n }\n\n if (fieldSchema) {\n properties[key] = fieldSchema;\n }\n }\n\n return {\n type: \"object\",\n properties,\n };\n }\n\n /**\n * Get the list of channel keys (excluding managed values).\n */\n getChannelKeys(): string[] {\n return Object.entries(this.fields).map(([key]) => key);\n }\n\n /**\n * Get all keys (channels + managed values).\n */\n getAllKeys(): string[] {\n return Object.keys(this.fields);\n }\n\n /**\n * Validate input data against the schema.\n * This validates each field using its corresponding schema.\n *\n * @param data - The input data to validate\n * @returns The validated data with coerced types\n */\n async validateInput<T>(data: T): Promise<T> {\n if (data == null || typeof data !== \"object\") {\n return data;\n }\n\n const result: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(data)) {\n const fieldDef = this.fields[key];\n\n if (fieldDef === undefined) {\n // Unknown field, pass through\n result[key] = value;\n continue;\n }\n\n // Get the schema to use for validation\n let schema: StandardSchemaV1 | undefined;\n\n if (ReducedValue.isInstance(fieldDef)) {\n schema = fieldDef.inputSchema;\n } else if (UntrackedValue.isInstance(fieldDef)) {\n schema = fieldDef.schema;\n } else if (isStandardSchema(fieldDef)) {\n schema = fieldDef;\n }\n\n if (schema) {\n // Validate using standard schema\n const validationResult = await schema[\"~standard\"].validate(value);\n if (validationResult.issues) {\n throw new Error(\n `Validation failed for field \"${key}\": ${JSON.stringify(\n validationResult.issues\n )}`\n );\n }\n result[key] = validationResult.value;\n } else {\n // No schema or not a standard schema, pass through\n result[key] = value;\n }\n }\n\n return result as T;\n }\n\n /**\n * Type guard to check if a value is a StateSchema instance.\n *\n * @param value - The value to check.\n * @returns True if the value is a StateSchema instance with the correct runtime tag.\n */\n static isInstance<TFields extends StateSchemaFields>(\n value: StateSchema<TFields>\n ): value is StateSchema<TFields>;\n\n static isInstance(value: unknown): value is StateSchema<any>;\n\n static isInstance<TFields extends StateSchemaFields>(\n value: unknown\n ): value is StateSchema<TFields> {\n return (\n typeof value === \"object\" &&\n value !== null &&\n STATE_SCHEMA_SYMBOL in value &&\n value[STATE_SCHEMA_SYMBOL] === true\n );\n }\n}\n\nexport type AnyStateSchema = StateSchema<any>;\n"],"mappings":";;;;;;;;;;AAkBA,MAAM,sBAAsB,OAAO,IAAI,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6JtE,IAAa,cAAb,MAA4D;;;;;CAM1D,CAAkB,uBAAuB;CAkCzC,YAAY,AAAS,QAAiB;EAAjB;;;;;;CAMrB,cAA2C;EACzC,MAAM,WAAwC,EAAE;AAEhD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SACE,OAAO,UAAU,YACjB,UAAU,QACV,uBAAuB,SACvB,MAAM,yBAAyB"}
|
package/dist/state/schema.d.cts
CHANGED
|
@@ -32,8 +32,8 @@ declare const STATE_SCHEMA_SYMBOL: unique symbol;
|
|
|
32
32
|
*/
|
|
33
33
|
type StateSchemaFieldToChannel<F> = F extends ReducedValue<infer V, infer I> ? BaseChannel<V, I> : F extends UntrackedValue<infer V> ? BaseChannel<V, V> : F extends SerializableSchema<infer I, infer O> ? BaseChannel<O, I> : BaseChannel<unknown, unknown>;
|
|
34
34
|
/**
|
|
35
|
-
* Converts
|
|
36
|
-
* State Definition object, where each
|
|
35
|
+
* Converts StateSchema fields into a strongly-typed
|
|
36
|
+
* State Definition object, where each field is mapped to its channel type.
|
|
37
37
|
*
|
|
38
38
|
* This utility type is used internally to create the shape of the state channels for a given schema,
|
|
39
39
|
* substituting each field with the result of `StateSchemaFieldToChannel`.
|
|
@@ -55,12 +55,12 @@ type StateSchemaFieldToChannel<F> = F extends ReducedValue<infer V, infer I> ? B
|
|
|
55
55
|
* }
|
|
56
56
|
* ```
|
|
57
57
|
*
|
|
58
|
-
* @template
|
|
59
|
-
* @returns An object type mapping
|
|
58
|
+
* @template TFields - The mapping of field names to StateSchema field types.
|
|
59
|
+
* @returns An object type mapping field names to channel types.
|
|
60
60
|
*
|
|
61
61
|
* @see StateSchemaFieldToChannel
|
|
62
62
|
*/
|
|
63
|
-
type StateSchemaFieldsToStateDefinition<
|
|
63
|
+
type StateSchemaFieldsToStateDefinition<TFields extends StateSchemaFields> = { [K in keyof TFields]: StateSchemaFieldToChannel<TFields[K]> };
|
|
64
64
|
/**
|
|
65
65
|
* Valid field types for StateSchema.
|
|
66
66
|
* Either a LangGraph state value type or a raw schema (e.g., Zod schema).
|
|
@@ -70,31 +70,27 @@ type StateSchemaField<Input = unknown, Output = Input> = ReducedValue<Input, Out
|
|
|
70
70
|
* Init object for StateSchema constructor.
|
|
71
71
|
* Uses `any` to allow variance in generic types (e.g., ReducedValue<string, string[]>).
|
|
72
72
|
*/
|
|
73
|
-
type
|
|
73
|
+
type StateSchemaFields = {
|
|
74
74
|
[key: string]: StateSchemaField<any, any>;
|
|
75
75
|
};
|
|
76
76
|
/**
|
|
77
|
-
* Infer the State type from a
|
|
77
|
+
* Infer the State type from a StateSchemaFields.
|
|
78
78
|
* This is the type of the full state object.
|
|
79
79
|
*
|
|
80
80
|
* - ReducedValue<Value, Input> → Value (the stored type)
|
|
81
81
|
* - UntrackedValue<Value> → Value
|
|
82
82
|
* - SerializableSchema<Input, Output> → Output (the validated type)
|
|
83
83
|
*/
|
|
84
|
-
type InferStateSchemaValue<
|
|
85
|
-
ValueType: infer TValue;
|
|
86
|
-
} ? TValue : TInit[K] extends UntrackedValue<infer TValue> ? TValue : TInit[K] extends SerializableSchema<unknown, infer TOutput> ? TOutput : never };
|
|
84
|
+
type InferStateSchemaValue<TFields extends StateSchemaFields> = { [K in keyof TFields]: TFields[K] extends ReducedValue<any, any> ? TFields[K]["ValueType"] : TFields[K] extends UntrackedValue<any> ? TFields[K]["ValueType"] : TFields[K] extends SerializableSchema<any, infer TOutput> ? TOutput : never };
|
|
87
85
|
/**
|
|
88
|
-
* Infer the Update type from a
|
|
86
|
+
* Infer the Update type from a StateSchemaFields.
|
|
89
87
|
* This is the type for partial updates to state.
|
|
90
88
|
*
|
|
91
89
|
* - ReducedValue<Value, Input> → Input (the reducer input type)
|
|
92
90
|
* - UntrackedValue<Value> → Value
|
|
93
91
|
* - SerializableSchema<Input, Output> → Input (what you provide)
|
|
94
92
|
*/
|
|
95
|
-
type InferStateSchemaUpdate<
|
|
96
|
-
InputType: infer TInput;
|
|
97
|
-
} ? TInput : TInit[K] extends UntrackedValue<infer TValue> ? TValue : TInit[K] extends SerializableSchema<infer TInput, unknown> ? TInput : never };
|
|
93
|
+
type InferStateSchemaUpdate<TFields extends StateSchemaFields> = { [K in keyof TFields]?: TFields[K] extends ReducedValue<any, any> ? TFields[K]["InputType"] : TFields[K] extends UntrackedValue<any> ? TFields[K]["ValueType"] : TFields[K] extends SerializableSchema<infer TInput, any> ? TInput : never };
|
|
98
94
|
/**
|
|
99
95
|
* StateSchema provides a unified API for defining LangGraph state schemas.
|
|
100
96
|
*
|
|
@@ -128,8 +124,8 @@ type InferStateSchemaUpdate<TInit extends StateSchemaInit> = { [K in keyof TInit
|
|
|
128
124
|
* const graph = new StateGraph(AgentState);
|
|
129
125
|
* ```
|
|
130
126
|
*/
|
|
131
|
-
declare class StateSchema<
|
|
132
|
-
readonly
|
|
127
|
+
declare class StateSchema<TFields extends StateSchemaFields> {
|
|
128
|
+
readonly fields: TFields;
|
|
133
129
|
/**
|
|
134
130
|
* Symbol for runtime identification.
|
|
135
131
|
* @internal Used by isInstance for runtime type checking
|
|
@@ -139,12 +135,12 @@ declare class StateSchema<TInit extends StateSchemaInit> {
|
|
|
139
135
|
* Type declaration for the full state type.
|
|
140
136
|
* Use: `typeof myState.State`
|
|
141
137
|
*/
|
|
142
|
-
State: InferStateSchemaValue<
|
|
138
|
+
State: InferStateSchemaValue<TFields>;
|
|
143
139
|
/**
|
|
144
140
|
* Type declaration for the update type.
|
|
145
141
|
* Use: `typeof myState.Update`
|
|
146
142
|
*/
|
|
147
|
-
Update: InferStateSchemaUpdate<
|
|
143
|
+
Update: InferStateSchemaUpdate<TFields>;
|
|
148
144
|
/**
|
|
149
145
|
* Type declaration for node functions.
|
|
150
146
|
* Use: `typeof myState.Node` to type node functions outside the graph builder.
|
|
@@ -160,8 +156,8 @@ declare class StateSchema<TInit extends StateSchemaInit> {
|
|
|
160
156
|
* };
|
|
161
157
|
* ```
|
|
162
158
|
*/
|
|
163
|
-
Node: RunnableLike<InferStateSchemaValue<
|
|
164
|
-
constructor(
|
|
159
|
+
Node: RunnableLike<InferStateSchemaValue<TFields>, InferStateSchemaUpdate<TFields>>;
|
|
160
|
+
constructor(fields: TFields);
|
|
165
161
|
/**
|
|
166
162
|
* Get the channel definitions for use with StateGraph.
|
|
167
163
|
* This converts the StateSchema fields into BaseChannel instances.
|
|
@@ -199,10 +195,10 @@ declare class StateSchema<TInit extends StateSchemaInit> {
|
|
|
199
195
|
* @param value - The value to check.
|
|
200
196
|
* @returns True if the value is a StateSchema instance with the correct runtime tag.
|
|
201
197
|
*/
|
|
202
|
-
static isInstance<
|
|
198
|
+
static isInstance<TFields extends StateSchemaFields>(value: StateSchema<TFields>): value is StateSchema<TFields>;
|
|
203
199
|
static isInstance(value: unknown): value is StateSchema<any>;
|
|
204
200
|
}
|
|
205
201
|
type AnyStateSchema = StateSchema<any>;
|
|
206
202
|
//#endregion
|
|
207
|
-
export { AnyStateSchema, InferStateSchemaUpdate, InferStateSchemaValue, StateSchema, StateSchemaField,
|
|
203
|
+
export { AnyStateSchema, InferStateSchemaUpdate, InferStateSchemaValue, StateSchema, StateSchemaField, StateSchemaFields, StateSchemaFieldsToStateDefinition };
|
|
208
204
|
//# sourceMappingURL=schema.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.cts","names":["JSONSchema","RunnableLike","BaseChannel","SerializableSchema","ReducedValue","UntrackedValue","STATE_SCHEMA_SYMBOL","StateSchemaFieldToChannel","F","V","I","O","StateSchemaFieldsToStateDefinition","StateSchemaInit","TInit","K","StateSchemaField","Input","Output","InferStateSchemaValue","TValue","TOutput","InferStateSchemaUpdate","TInput","StateSchema","Record","T","Promise","AnyStateSchema"],"sources":["../../src/state/schema.d.ts"],"sourcesContent":["import type { JSONSchema } from \"@langchain/core/utils/json_schema\";\nimport type { RunnableLike } from \"../pregel/runnable_types.js\";\nimport { BaseChannel } from \"../channels/index.js\";\nimport type { SerializableSchema } from \"./types.js\";\nimport { ReducedValue } from \"./values/reduced.js\";\nimport { UntrackedValue } from \"./values/untracked.js\";\ndeclare const STATE_SCHEMA_SYMBOL: unique symbol;\n/**\n * Maps a single StateSchema field definition to its corresponding Channel type.\n *\n * This utility type inspects the type of the field and returns an appropriate\n * `BaseChannel` type, parameterized with the state \"value\" and \"input\" types according to the field's shape.\n *\n * Rules:\n * - If the field (`F`) is a `ReducedValue<V, I>`, the channel will store values of type `V`\n * and accept input of type `I`.\n * - If the field is a `UntrackedValue<V>`, the channel will store and accept values of type `V`.\n * - If the field is a `SerializableSchema<I, O>`, the channel will store values of type `O`\n * (the schema's output/validated value) and accept input of type `I`.\n * - For all other types, a generic `BaseChannel<unknown, unknown>` is used as fallback.\n *\n * @template F - The StateSchema field type to map to a Channel type.\n *\n * @example\n * ```typescript\n * type MyField = ReducedValue<number, string>;\n * type ChannelType = StateSchemaFieldToChannel<MyField>;\n * // ChannelType is BaseChannel<number, string>\n * ```\n */\nexport type StateSchemaFieldToChannel<F> = F extends ReducedValue<infer V, infer I> ? BaseChannel<V, I> : F extends UntrackedValue<infer V> ? BaseChannel<V, V> : F extends SerializableSchema<infer I, infer O> ? BaseChannel<O, I> : BaseChannel<unknown, unknown>;\n/**\n * Converts a StateSchema \"init\" object (field map) into a strongly-typed\n * State Definition object, where each key is mapped to its channel type.\n *\n * This utility type is used internally to create the shape of the state channels for a given schema,\n * substituting each field with the result of `StateSchemaFieldToChannel`.\n *\n * If you define a state schema as:\n * ```typescript\n * const fields = {\n * a: ReducedValue<number, string>(),\n * b: UntrackedValue<boolean>(),\n * c: SomeSerializableSchemaType, // SerializableSchema<in, out>\n * }\n * ```\n * then `StateSchemaFieldsToStateDefinition<typeof fields>` yields:\n * ```typescript\n * {\n * a: BaseChannel<number, string>;\n * b: BaseChannel<boolean, boolean>;\n * c: BaseChannel<typeof schema's output type, typeof schema's input type>;\n * }\n * ```\n *\n * @template TInit - The mapping of field names to StateSchema field types.\n * @returns An object type mapping keys to channel types.\n *\n * @see StateSchemaFieldToChannel\n */\nexport type StateSchemaFieldsToStateDefinition<TInit extends StateSchemaInit> = {\n [K in keyof TInit]: StateSchemaFieldToChannel<TInit[K]>;\n};\n/**\n * Valid field types for StateSchema.\n * Either a LangGraph state value type or a raw schema (e.g., Zod schema).\n */\nexport type StateSchemaField<Input = unknown, Output = Input> = ReducedValue<Input, Output> | UntrackedValue<Output> | SerializableSchema<Input, Output>;\n/**\n * Init object for StateSchema constructor.\n * Uses `any` to allow variance in generic types (e.g., ReducedValue<string, string[]>).\n */\nexport type StateSchemaInit = {\n [key: string]: StateSchemaField<any, any>;\n};\n/**\n * Infer the State type from a StateSchemaInit.\n * This is the type of the full state object.\n *\n * - ReducedValue<Value, Input> → Value (the stored type)\n * - UntrackedValue<Value> → Value\n * - SerializableSchema<Input, Output> → Output (the validated type)\n */\nexport type InferStateSchemaValue<TInit extends StateSchemaInit> = {\n [K in keyof TInit]: TInit[K] extends {\n ValueType: infer TValue;\n } ? TValue : TInit[K] extends UntrackedValue<infer TValue> ? TValue : TInit[K] extends SerializableSchema<unknown, infer TOutput> ? TOutput : never;\n};\n/**\n * Infer the Update type from a StateSchemaInit.\n * This is the type for partial updates to state.\n *\n * - ReducedValue<Value, Input> → Input (the reducer input type)\n * - UntrackedValue<Value> → Value\n * - SerializableSchema<Input, Output> → Input (what you provide)\n */\nexport type InferStateSchemaUpdate<TInit extends StateSchemaInit> = {\n [K in keyof TInit]?: TInit[K] extends {\n InputType: infer TInput;\n } ? TInput : TInit[K] extends UntrackedValue<infer TValue> ? TValue : TInit[K] extends SerializableSchema<infer TInput, unknown> ? TInput : never;\n};\n/**\n * StateSchema provides a unified API for defining LangGraph state schemas.\n *\n * @example\n * ```ts\n * import { z } from \"zod\";\n * import { StateSchema, ReducedValue, MessagesValue } from \"@langchain/langgraph\";\n *\n * const AgentState = new StateSchema({\n * // Prebuilt messages value\n * messages: MessagesValue,\n * // Basic LastValue channel from any standard schema\n * currentStep: z.string(),\n * // LastValue with native default\n * count: z.number().default(0),\n * // ReducedValue for fields needing reducers\n * history: new ReducedValue(\n * z.array(z.string()).default(() => []),\n * {\n * inputSchema: z.string(),\n * reducer: (current, next) => [...current, next],\n * }\n * ),\n * });\n *\n * // Extract types\n * type State = typeof AgentState.State;\n * type Update = typeof AgentState.Update;\n *\n * // Use in StateGraph\n * const graph = new StateGraph(AgentState);\n * ```\n */\nexport declare class StateSchema<TInit extends StateSchemaInit> {\n readonly init: TInit;\n /**\n * Symbol for runtime identification.\n * @internal Used by isInstance for runtime type checking\n */\n private readonly [STATE_SCHEMA_SYMBOL];\n /**\n * Type declaration for the full state type.\n * Use: `typeof myState.State`\n */\n State: InferStateSchemaValue<TInit>;\n /**\n * Type declaration for the update type.\n * Use: `typeof myState.Update`\n */\n Update: InferStateSchemaUpdate<TInit>;\n /**\n * Type declaration for node functions.\n * Use: `typeof myState.Node` to type node functions outside the graph builder.\n *\n * @example\n * ```typescript\n * const AgentState = new StateSchema({\n * count: z.number().default(0),\n * });\n *\n * const myNode: typeof AgentState.Node = (state) => {\n * return { count: state.count + 1 };\n * };\n * ```\n */\n Node: RunnableLike<InferStateSchemaValue<TInit>, InferStateSchemaUpdate<TInit>>;\n constructor(init: TInit);\n /**\n * Get the channel definitions for use with StateGraph.\n * This converts the StateSchema fields into BaseChannel instances.\n */\n getChannels(): Record<string, BaseChannel>;\n /**\n * Get the JSON schema for the full state type.\n * Used by Studio and API for schema introspection.\n */\n getJsonSchema(): JSONSchema;\n /**\n * Get the JSON schema for the update/input type.\n * All fields are optional in updates.\n */\n getInputJsonSchema(): JSONSchema;\n /**\n * Get the list of channel keys (excluding managed values).\n */\n getChannelKeys(): string[];\n /**\n * Get all keys (channels + managed values).\n */\n getAllKeys(): string[];\n /**\n * Validate input data against the schema.\n * This validates each field using its corresponding schema.\n *\n * @param data - The input data to validate\n * @returns The validated data with coerced types\n */\n validateInput<T>(data: T): Promise<T>;\n /**\n * Type guard to check if a value is a StateSchema instance.\n *\n * @param value - The value to check.\n * @returns True if the value is a StateSchema instance with the correct runtime tag.\n */\n static isInstance<TInit extends StateSchemaInit>(value: StateSchema<TInit>): value is StateSchema<TInit>;\n static isInstance(value: unknown): value is StateSchema<any>;\n}\nexport type AnyStateSchema = StateSchema<any>;\nexport {};\n"],"mappings":";;;;;;;;cAMcM;;AADyC;AA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BAAkBU,YAAYV;8CACtDU;;KAEpCI,cAAAA,GAAiBJ"}
|
|
1
|
+
{"version":3,"file":"schema.d.cts","names":["JSONSchema","RunnableLike","BaseChannel","SerializableSchema","ReducedValue","UntrackedValue","STATE_SCHEMA_SYMBOL","StateSchemaFieldToChannel","F","V","I","O","StateSchemaFieldsToStateDefinition","StateSchemaFields","TFields","K","StateSchemaField","Input","Output","InferStateSchemaValue","TOutput","InferStateSchemaUpdate","TInput","StateSchema","Record","T","Promise","AnyStateSchema"],"sources":["../../src/state/schema.d.ts"],"sourcesContent":["import type { JSONSchema } from \"@langchain/core/utils/json_schema\";\nimport type { RunnableLike } from \"../pregel/runnable_types.js\";\nimport { BaseChannel } from \"../channels/index.js\";\nimport type { SerializableSchema } from \"./types.js\";\nimport { ReducedValue } from \"./values/reduced.js\";\nimport { UntrackedValue } from \"./values/untracked.js\";\ndeclare const STATE_SCHEMA_SYMBOL: unique symbol;\n/**\n * Maps a single StateSchema field definition to its corresponding Channel type.\n *\n * This utility type inspects the type of the field and returns an appropriate\n * `BaseChannel` type, parameterized with the state \"value\" and \"input\" types according to the field's shape.\n *\n * Rules:\n * - If the field (`F`) is a `ReducedValue<V, I>`, the channel will store values of type `V`\n * and accept input of type `I`.\n * - If the field is a `UntrackedValue<V>`, the channel will store and accept values of type `V`.\n * - If the field is a `SerializableSchema<I, O>`, the channel will store values of type `O`\n * (the schema's output/validated value) and accept input of type `I`.\n * - For all other types, a generic `BaseChannel<unknown, unknown>` is used as fallback.\n *\n * @template F - The StateSchema field type to map to a Channel type.\n *\n * @example\n * ```typescript\n * type MyField = ReducedValue<number, string>;\n * type ChannelType = StateSchemaFieldToChannel<MyField>;\n * // ChannelType is BaseChannel<number, string>\n * ```\n */\nexport type StateSchemaFieldToChannel<F> = F extends ReducedValue<infer V, infer I> ? BaseChannel<V, I> : F extends UntrackedValue<infer V> ? BaseChannel<V, V> : F extends SerializableSchema<infer I, infer O> ? BaseChannel<O, I> : BaseChannel<unknown, unknown>;\n/**\n * Converts StateSchema fields into a strongly-typed\n * State Definition object, where each field is mapped to its channel type.\n *\n * This utility type is used internally to create the shape of the state channels for a given schema,\n * substituting each field with the result of `StateSchemaFieldToChannel`.\n *\n * If you define a state schema as:\n * ```typescript\n * const fields = {\n * a: ReducedValue<number, string>(),\n * b: UntrackedValue<boolean>(),\n * c: SomeSerializableSchemaType, // SerializableSchema<in, out>\n * }\n * ```\n * then `StateSchemaFieldsToStateDefinition<typeof fields>` yields:\n * ```typescript\n * {\n * a: BaseChannel<number, string>;\n * b: BaseChannel<boolean, boolean>;\n * c: BaseChannel<typeof schema's output type, typeof schema's input type>;\n * }\n * ```\n *\n * @template TFields - The mapping of field names to StateSchema field types.\n * @returns An object type mapping field names to channel types.\n *\n * @see StateSchemaFieldToChannel\n */\nexport type StateSchemaFieldsToStateDefinition<TFields extends StateSchemaFields> = {\n [K in keyof TFields]: StateSchemaFieldToChannel<TFields[K]>;\n};\n/**\n * Valid field types for StateSchema.\n * Either a LangGraph state value type or a raw schema (e.g., Zod schema).\n */\nexport type StateSchemaField<Input = unknown, Output = Input> = ReducedValue<Input, Output> | UntrackedValue<Output> | SerializableSchema<Input, Output>;\n/**\n * Init object for StateSchema constructor.\n * Uses `any` to allow variance in generic types (e.g., ReducedValue<string, string[]>).\n */\nexport type StateSchemaFields = {\n [key: string]: StateSchemaField<any, any>;\n};\n/**\n * Infer the State type from a StateSchemaFields.\n * This is the type of the full state object.\n *\n * - ReducedValue<Value, Input> → Value (the stored type)\n * - UntrackedValue<Value> → Value\n * - SerializableSchema<Input, Output> → Output (the validated type)\n */\nexport type InferStateSchemaValue<TFields extends StateSchemaFields> = {\n [K in keyof TFields]: TFields[K] extends ReducedValue<any, any> ? TFields[K][\"ValueType\"] : TFields[K] extends UntrackedValue<any> ? TFields[K][\"ValueType\"] : TFields[K] extends SerializableSchema<any, infer TOutput> ? TOutput : never;\n};\n/**\n * Infer the Update type from a StateSchemaFields.\n * This is the type for partial updates to state.\n *\n * - ReducedValue<Value, Input> → Input (the reducer input type)\n * - UntrackedValue<Value> → Value\n * - SerializableSchema<Input, Output> → Input (what you provide)\n */\nexport type InferStateSchemaUpdate<TFields extends StateSchemaFields> = {\n [K in keyof TFields]?: TFields[K] extends ReducedValue<any, any> ? TFields[K][\"InputType\"] : TFields[K] extends UntrackedValue<any> ? TFields[K][\"ValueType\"] : TFields[K] extends SerializableSchema<infer TInput, any> ? TInput : never;\n};\n/**\n * StateSchema provides a unified API for defining LangGraph state schemas.\n *\n * @example\n * ```ts\n * import { z } from \"zod\";\n * import { StateSchema, ReducedValue, MessagesValue } from \"@langchain/langgraph\";\n *\n * const AgentState = new StateSchema({\n * // Prebuilt messages value\n * messages: MessagesValue,\n * // Basic LastValue channel from any standard schema\n * currentStep: z.string(),\n * // LastValue with native default\n * count: z.number().default(0),\n * // ReducedValue for fields needing reducers\n * history: new ReducedValue(\n * z.array(z.string()).default(() => []),\n * {\n * inputSchema: z.string(),\n * reducer: (current, next) => [...current, next],\n * }\n * ),\n * });\n *\n * // Extract types\n * type State = typeof AgentState.State;\n * type Update = typeof AgentState.Update;\n *\n * // Use in StateGraph\n * const graph = new StateGraph(AgentState);\n * ```\n */\nexport declare class StateSchema<TFields extends StateSchemaFields> {\n readonly fields: TFields;\n /**\n * Symbol for runtime identification.\n * @internal Used by isInstance for runtime type checking\n */\n private readonly [STATE_SCHEMA_SYMBOL];\n /**\n * Type declaration for the full state type.\n * Use: `typeof myState.State`\n */\n State: InferStateSchemaValue<TFields>;\n /**\n * Type declaration for the update type.\n * Use: `typeof myState.Update`\n */\n Update: InferStateSchemaUpdate<TFields>;\n /**\n * Type declaration for node functions.\n * Use: `typeof myState.Node` to type node functions outside the graph builder.\n *\n * @example\n * ```typescript\n * const AgentState = new StateSchema({\n * count: z.number().default(0),\n * });\n *\n * const myNode: typeof AgentState.Node = (state) => {\n * return { count: state.count + 1 };\n * };\n * ```\n */\n Node: RunnableLike<InferStateSchemaValue<TFields>, InferStateSchemaUpdate<TFields>>;\n constructor(fields: TFields);\n /**\n * Get the channel definitions for use with StateGraph.\n * This converts the StateSchema fields into BaseChannel instances.\n */\n getChannels(): Record<string, BaseChannel>;\n /**\n * Get the JSON schema for the full state type.\n * Used by Studio and API for schema introspection.\n */\n getJsonSchema(): JSONSchema;\n /**\n * Get the JSON schema for the update/input type.\n * All fields are optional in updates.\n */\n getInputJsonSchema(): JSONSchema;\n /**\n * Get the list of channel keys (excluding managed values).\n */\n getChannelKeys(): string[];\n /**\n * Get all keys (channels + managed values).\n */\n getAllKeys(): string[];\n /**\n * Validate input data against the schema.\n * This validates each field using its corresponding schema.\n *\n * @param data - The input data to validate\n * @returns The validated data with coerced types\n */\n validateInput<T>(data: T): Promise<T>;\n /**\n * Type guard to check if a value is a StateSchema instance.\n *\n * @param value - The value to check.\n * @returns True if the value is a StateSchema instance with the correct runtime tag.\n */\n static isInstance<TFields extends StateSchemaFields>(value: StateSchema<TFields>): value is StateSchema<TFields>;\n static isInstance(value: unknown): value is StateSchema<any>;\n}\nexport type AnyStateSchema = StateSchema<any>;\nexport {};\n"],"mappings":";;;;;;;;cAMcM;;AADyC;AAyBvD;;;;;;;;;;;;;;;;;;;AA8BA;;AAA+DO,KA9BnDN,yBA8BmDM,CAAAA,CAAAA,CAAAA,GA9BpBL,CA8BoBK,SA9BVT,YA8BUS,CAAAA,KAAAA,EAAAA,EAAAA,KAAAA,EAAAA,CAAAA,GA9BuBX,WA8BvBW,CA9BmCJ,CA8BnCI,EA9BsCH,CA8BtCG,CAAAA,GA9B2CL,CA8B3CK,SA9BqDR,cA8BrDQ,CAAAA,KAAAA,EAAAA,CAAAA,GA9B+EX,WA8B/EW,CA9B2FJ,CA8B3FI,EA9B8FJ,CA8B9FI,CAAAA,GA9BmGL,CA8BnGK,SA9B6GV,kBA8B7GU,CAAAA,KAAAA,EAAAA,EAAAA,KAAAA,EAAAA,CAAAA,GA9BoJX,WA8BpJW,CA9BgKF,CA8BhKE,EA9BmKH,CA8BnKG,CAAAA,G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AoDuBP,CAAAA,gBApDgBD,iBAoDhBC,CAAAA,GAAAA,QAAvBO,MAnDIP,OAmDJO,IAnDeP,OAmDfO,CAnDuBN,CAmDvBM,CAAAA,SAnDkCjB,YAmDlCiB,CAAAA,GAAAA,EAAAA,GAAAA,CAAAA,GAnD2DP,OAmD3DO,CAnDmEN,CAmDnEM,CAAAA,CAAAA,WAAAA,CAAAA,GAnDqFP,OAmDrFO,CAnD6FN,CAmD7FM,CAAAA,SAnDwGhB,cAmDxGgB,CAAAA,GAAAA,CAAAA,GAnD8HP,OAmD9HO,CAnDsIN,CAmDtIM,CAAAA,CAAAA,WAAAA,CAAAA,GAnDwJP,OAmDxJO,CAnDgKN,CAmDhKM,CAAAA,SAnD2KlB,kBAmD3KkB,CAAAA,KAAAA,OAAAA,EAAAA,GAAAA,CAAAA,GAnDmNC,MAmDnND,GAAAA,KAAAA;;;;;;;;;;;;;;;;;;;;AA0DZ;;;;;;;;;;;;;;cA1EqBE,4BAA4BV;mBAC5BC;;;;;oBAKCR,mBAAAA;;;;;SAKXa,sBAAsBL;;;;;UAKrBO,uBAAuBP;;;;;;;;;;;;;;;;QAgBzBb,aAAakB,sBAAsBL,UAAUO,uBAAuBP;sBACtDA;;;;;iBAKLU,eAAetB;;;;;mBAKbF;;;;;wBAKKA;;;;;;;;;;;;;;;;yBAgBCyB,IAAIC,QAAQD;;;;;;;oCAODZ,0BAA0BU,YAAYT,oBAAoBS,YAAYT;8CAC5DS;;KAEpCI,cAAAA,GAAiBJ"}
|
package/dist/state/schema.d.ts
CHANGED
|
@@ -32,8 +32,8 @@ declare const STATE_SCHEMA_SYMBOL: unique symbol;
|
|
|
32
32
|
*/
|
|
33
33
|
type StateSchemaFieldToChannel<F> = F extends ReducedValue<infer V, infer I> ? BaseChannel<V, I> : F extends UntrackedValue<infer V> ? BaseChannel<V, V> : F extends SerializableSchema<infer I, infer O> ? BaseChannel<O, I> : BaseChannel<unknown, unknown>;
|
|
34
34
|
/**
|
|
35
|
-
* Converts
|
|
36
|
-
* State Definition object, where each
|
|
35
|
+
* Converts StateSchema fields into a strongly-typed
|
|
36
|
+
* State Definition object, where each field is mapped to its channel type.
|
|
37
37
|
*
|
|
38
38
|
* This utility type is used internally to create the shape of the state channels for a given schema,
|
|
39
39
|
* substituting each field with the result of `StateSchemaFieldToChannel`.
|
|
@@ -55,12 +55,12 @@ type StateSchemaFieldToChannel<F> = F extends ReducedValue<infer V, infer I> ? B
|
|
|
55
55
|
* }
|
|
56
56
|
* ```
|
|
57
57
|
*
|
|
58
|
-
* @template
|
|
59
|
-
* @returns An object type mapping
|
|
58
|
+
* @template TFields - The mapping of field names to StateSchema field types.
|
|
59
|
+
* @returns An object type mapping field names to channel types.
|
|
60
60
|
*
|
|
61
61
|
* @see StateSchemaFieldToChannel
|
|
62
62
|
*/
|
|
63
|
-
type StateSchemaFieldsToStateDefinition<
|
|
63
|
+
type StateSchemaFieldsToStateDefinition<TFields extends StateSchemaFields> = { [K in keyof TFields]: StateSchemaFieldToChannel<TFields[K]> };
|
|
64
64
|
/**
|
|
65
65
|
* Valid field types for StateSchema.
|
|
66
66
|
* Either a LangGraph state value type or a raw schema (e.g., Zod schema).
|
|
@@ -70,31 +70,27 @@ type StateSchemaField<Input = unknown, Output = Input> = ReducedValue<Input, Out
|
|
|
70
70
|
* Init object for StateSchema constructor.
|
|
71
71
|
* Uses `any` to allow variance in generic types (e.g., ReducedValue<string, string[]>).
|
|
72
72
|
*/
|
|
73
|
-
type
|
|
73
|
+
type StateSchemaFields = {
|
|
74
74
|
[key: string]: StateSchemaField<any, any>;
|
|
75
75
|
};
|
|
76
76
|
/**
|
|
77
|
-
* Infer the State type from a
|
|
77
|
+
* Infer the State type from a StateSchemaFields.
|
|
78
78
|
* This is the type of the full state object.
|
|
79
79
|
*
|
|
80
80
|
* - ReducedValue<Value, Input> → Value (the stored type)
|
|
81
81
|
* - UntrackedValue<Value> → Value
|
|
82
82
|
* - SerializableSchema<Input, Output> → Output (the validated type)
|
|
83
83
|
*/
|
|
84
|
-
type InferStateSchemaValue<
|
|
85
|
-
ValueType: infer TValue;
|
|
86
|
-
} ? TValue : TInit[K] extends UntrackedValue<infer TValue> ? TValue : TInit[K] extends SerializableSchema<unknown, infer TOutput> ? TOutput : never };
|
|
84
|
+
type InferStateSchemaValue<TFields extends StateSchemaFields> = { [K in keyof TFields]: TFields[K] extends ReducedValue<any, any> ? TFields[K]["ValueType"] : TFields[K] extends UntrackedValue<any> ? TFields[K]["ValueType"] : TFields[K] extends SerializableSchema<any, infer TOutput> ? TOutput : never };
|
|
87
85
|
/**
|
|
88
|
-
* Infer the Update type from a
|
|
86
|
+
* Infer the Update type from a StateSchemaFields.
|
|
89
87
|
* This is the type for partial updates to state.
|
|
90
88
|
*
|
|
91
89
|
* - ReducedValue<Value, Input> → Input (the reducer input type)
|
|
92
90
|
* - UntrackedValue<Value> → Value
|
|
93
91
|
* - SerializableSchema<Input, Output> → Input (what you provide)
|
|
94
92
|
*/
|
|
95
|
-
type InferStateSchemaUpdate<
|
|
96
|
-
InputType: infer TInput;
|
|
97
|
-
} ? TInput : TInit[K] extends UntrackedValue<infer TValue> ? TValue : TInit[K] extends SerializableSchema<infer TInput, unknown> ? TInput : never };
|
|
93
|
+
type InferStateSchemaUpdate<TFields extends StateSchemaFields> = { [K in keyof TFields]?: TFields[K] extends ReducedValue<any, any> ? TFields[K]["InputType"] : TFields[K] extends UntrackedValue<any> ? TFields[K]["ValueType"] : TFields[K] extends SerializableSchema<infer TInput, any> ? TInput : never };
|
|
98
94
|
/**
|
|
99
95
|
* StateSchema provides a unified API for defining LangGraph state schemas.
|
|
100
96
|
*
|
|
@@ -128,8 +124,8 @@ type InferStateSchemaUpdate<TInit extends StateSchemaInit> = { [K in keyof TInit
|
|
|
128
124
|
* const graph = new StateGraph(AgentState);
|
|
129
125
|
* ```
|
|
130
126
|
*/
|
|
131
|
-
declare class StateSchema<
|
|
132
|
-
readonly
|
|
127
|
+
declare class StateSchema<TFields extends StateSchemaFields> {
|
|
128
|
+
readonly fields: TFields;
|
|
133
129
|
/**
|
|
134
130
|
* Symbol for runtime identification.
|
|
135
131
|
* @internal Used by isInstance for runtime type checking
|
|
@@ -139,12 +135,12 @@ declare class StateSchema<TInit extends StateSchemaInit> {
|
|
|
139
135
|
* Type declaration for the full state type.
|
|
140
136
|
* Use: `typeof myState.State`
|
|
141
137
|
*/
|
|
142
|
-
State: InferStateSchemaValue<
|
|
138
|
+
State: InferStateSchemaValue<TFields>;
|
|
143
139
|
/**
|
|
144
140
|
* Type declaration for the update type.
|
|
145
141
|
* Use: `typeof myState.Update`
|
|
146
142
|
*/
|
|
147
|
-
Update: InferStateSchemaUpdate<
|
|
143
|
+
Update: InferStateSchemaUpdate<TFields>;
|
|
148
144
|
/**
|
|
149
145
|
* Type declaration for node functions.
|
|
150
146
|
* Use: `typeof myState.Node` to type node functions outside the graph builder.
|
|
@@ -160,8 +156,8 @@ declare class StateSchema<TInit extends StateSchemaInit> {
|
|
|
160
156
|
* };
|
|
161
157
|
* ```
|
|
162
158
|
*/
|
|
163
|
-
Node: RunnableLike<InferStateSchemaValue<
|
|
164
|
-
constructor(
|
|
159
|
+
Node: RunnableLike<InferStateSchemaValue<TFields>, InferStateSchemaUpdate<TFields>>;
|
|
160
|
+
constructor(fields: TFields);
|
|
165
161
|
/**
|
|
166
162
|
* Get the channel definitions for use with StateGraph.
|
|
167
163
|
* This converts the StateSchema fields into BaseChannel instances.
|
|
@@ -199,10 +195,10 @@ declare class StateSchema<TInit extends StateSchemaInit> {
|
|
|
199
195
|
* @param value - The value to check.
|
|
200
196
|
* @returns True if the value is a StateSchema instance with the correct runtime tag.
|
|
201
197
|
*/
|
|
202
|
-
static isInstance<
|
|
198
|
+
static isInstance<TFields extends StateSchemaFields>(value: StateSchema<TFields>): value is StateSchema<TFields>;
|
|
203
199
|
static isInstance(value: unknown): value is StateSchema<any>;
|
|
204
200
|
}
|
|
205
201
|
type AnyStateSchema = StateSchema<any>;
|
|
206
202
|
//#endregion
|
|
207
|
-
export { AnyStateSchema, InferStateSchemaUpdate, InferStateSchemaValue, StateSchema, StateSchemaField,
|
|
203
|
+
export { AnyStateSchema, InferStateSchemaUpdate, InferStateSchemaValue, StateSchema, StateSchemaField, StateSchemaFields, StateSchemaFieldsToStateDefinition };
|
|
208
204
|
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","names":["JSONSchema","RunnableLike","BaseChannel","SerializableSchema","ReducedValue","UntrackedValue","STATE_SCHEMA_SYMBOL","StateSchemaFieldToChannel","F","V","I","O","StateSchemaFieldsToStateDefinition","StateSchemaInit","TInit","K","StateSchemaField","Input","Output","InferStateSchemaValue","TValue","TOutput","InferStateSchemaUpdate","TInput","StateSchema","Record","T","Promise","AnyStateSchema"],"sources":["../../src/state/schema.d.ts"],"sourcesContent":["import type { JSONSchema } from \"@langchain/core/utils/json_schema\";\nimport type { RunnableLike } from \"../pregel/runnable_types.js\";\nimport { BaseChannel } from \"../channels/index.js\";\nimport type { SerializableSchema } from \"./types.js\";\nimport { ReducedValue } from \"./values/reduced.js\";\nimport { UntrackedValue } from \"./values/untracked.js\";\ndeclare const STATE_SCHEMA_SYMBOL: unique symbol;\n/**\n * Maps a single StateSchema field definition to its corresponding Channel type.\n *\n * This utility type inspects the type of the field and returns an appropriate\n * `BaseChannel` type, parameterized with the state \"value\" and \"input\" types according to the field's shape.\n *\n * Rules:\n * - If the field (`F`) is a `ReducedValue<V, I>`, the channel will store values of type `V`\n * and accept input of type `I`.\n * - If the field is a `UntrackedValue<V>`, the channel will store and accept values of type `V`.\n * - If the field is a `SerializableSchema<I, O>`, the channel will store values of type `O`\n * (the schema's output/validated value) and accept input of type `I`.\n * - For all other types, a generic `BaseChannel<unknown, unknown>` is used as fallback.\n *\n * @template F - The StateSchema field type to map to a Channel type.\n *\n * @example\n * ```typescript\n * type MyField = ReducedValue<number, string>;\n * type ChannelType = StateSchemaFieldToChannel<MyField>;\n * // ChannelType is BaseChannel<number, string>\n * ```\n */\nexport type StateSchemaFieldToChannel<F> = F extends ReducedValue<infer V, infer I> ? BaseChannel<V, I> : F extends UntrackedValue<infer V> ? BaseChannel<V, V> : F extends SerializableSchema<infer I, infer O> ? BaseChannel<O, I> : BaseChannel<unknown, unknown>;\n/**\n * Converts a StateSchema \"init\" object (field map) into a strongly-typed\n * State Definition object, where each key is mapped to its channel type.\n *\n * This utility type is used internally to create the shape of the state channels for a given schema,\n * substituting each field with the result of `StateSchemaFieldToChannel`.\n *\n * If you define a state schema as:\n * ```typescript\n * const fields = {\n * a: ReducedValue<number, string>(),\n * b: UntrackedValue<boolean>(),\n * c: SomeSerializableSchemaType, // SerializableSchema<in, out>\n * }\n * ```\n * then `StateSchemaFieldsToStateDefinition<typeof fields>` yields:\n * ```typescript\n * {\n * a: BaseChannel<number, string>;\n * b: BaseChannel<boolean, boolean>;\n * c: BaseChannel<typeof schema's output type, typeof schema's input type>;\n * }\n * ```\n *\n * @template TInit - The mapping of field names to StateSchema field types.\n * @returns An object type mapping keys to channel types.\n *\n * @see StateSchemaFieldToChannel\n */\nexport type StateSchemaFieldsToStateDefinition<TInit extends StateSchemaInit> = {\n [K in keyof TInit]: StateSchemaFieldToChannel<TInit[K]>;\n};\n/**\n * Valid field types for StateSchema.\n * Either a LangGraph state value type or a raw schema (e.g., Zod schema).\n */\nexport type StateSchemaField<Input = unknown, Output = Input> = ReducedValue<Input, Output> | UntrackedValue<Output> | SerializableSchema<Input, Output>;\n/**\n * Init object for StateSchema constructor.\n * Uses `any` to allow variance in generic types (e.g., ReducedValue<string, string[]>).\n */\nexport type StateSchemaInit = {\n [key: string]: StateSchemaField<any, any>;\n};\n/**\n * Infer the State type from a StateSchemaInit.\n * This is the type of the full state object.\n *\n * - ReducedValue<Value, Input> → Value (the stored type)\n * - UntrackedValue<Value> → Value\n * - SerializableSchema<Input, Output> → Output (the validated type)\n */\nexport type InferStateSchemaValue<TInit extends StateSchemaInit> = {\n [K in keyof TInit]: TInit[K] extends {\n ValueType: infer TValue;\n } ? TValue : TInit[K] extends UntrackedValue<infer TValue> ? TValue : TInit[K] extends SerializableSchema<unknown, infer TOutput> ? TOutput : never;\n};\n/**\n * Infer the Update type from a StateSchemaInit.\n * This is the type for partial updates to state.\n *\n * - ReducedValue<Value, Input> → Input (the reducer input type)\n * - UntrackedValue<Value> → Value\n * - SerializableSchema<Input, Output> → Input (what you provide)\n */\nexport type InferStateSchemaUpdate<TInit extends StateSchemaInit> = {\n [K in keyof TInit]?: TInit[K] extends {\n InputType: infer TInput;\n } ? TInput : TInit[K] extends UntrackedValue<infer TValue> ? TValue : TInit[K] extends SerializableSchema<infer TInput, unknown> ? TInput : never;\n};\n/**\n * StateSchema provides a unified API for defining LangGraph state schemas.\n *\n * @example\n * ```ts\n * import { z } from \"zod\";\n * import { StateSchema, ReducedValue, MessagesValue } from \"@langchain/langgraph\";\n *\n * const AgentState = new StateSchema({\n * // Prebuilt messages value\n * messages: MessagesValue,\n * // Basic LastValue channel from any standard schema\n * currentStep: z.string(),\n * // LastValue with native default\n * count: z.number().default(0),\n * // ReducedValue for fields needing reducers\n * history: new ReducedValue(\n * z.array(z.string()).default(() => []),\n * {\n * inputSchema: z.string(),\n * reducer: (current, next) => [...current, next],\n * }\n * ),\n * });\n *\n * // Extract types\n * type State = typeof AgentState.State;\n * type Update = typeof AgentState.Update;\n *\n * // Use in StateGraph\n * const graph = new StateGraph(AgentState);\n * ```\n */\nexport declare class StateSchema<TInit extends StateSchemaInit> {\n readonly init: TInit;\n /**\n * Symbol for runtime identification.\n * @internal Used by isInstance for runtime type checking\n */\n private readonly [STATE_SCHEMA_SYMBOL];\n /**\n * Type declaration for the full state type.\n * Use: `typeof myState.State`\n */\n State: InferStateSchemaValue<TInit>;\n /**\n * Type declaration for the update type.\n * Use: `typeof myState.Update`\n */\n Update: InferStateSchemaUpdate<TInit>;\n /**\n * Type declaration for node functions.\n * Use: `typeof myState.Node` to type node functions outside the graph builder.\n *\n * @example\n * ```typescript\n * const AgentState = new StateSchema({\n * count: z.number().default(0),\n * });\n *\n * const myNode: typeof AgentState.Node = (state) => {\n * return { count: state.count + 1 };\n * };\n * ```\n */\n Node: RunnableLike<InferStateSchemaValue<TInit>, InferStateSchemaUpdate<TInit>>;\n constructor(init: TInit);\n /**\n * Get the channel definitions for use with StateGraph.\n * This converts the StateSchema fields into BaseChannel instances.\n */\n getChannels(): Record<string, BaseChannel>;\n /**\n * Get the JSON schema for the full state type.\n * Used by Studio and API for schema introspection.\n */\n getJsonSchema(): JSONSchema;\n /**\n * Get the JSON schema for the update/input type.\n * All fields are optional in updates.\n */\n getInputJsonSchema(): JSONSchema;\n /**\n * Get the list of channel keys (excluding managed values).\n */\n getChannelKeys(): string[];\n /**\n * Get all keys (channels + managed values).\n */\n getAllKeys(): string[];\n /**\n * Validate input data against the schema.\n * This validates each field using its corresponding schema.\n *\n * @param data - The input data to validate\n * @returns The validated data with coerced types\n */\n validateInput<T>(data: T): Promise<T>;\n /**\n * Type guard to check if a value is a StateSchema instance.\n *\n * @param value - The value to check.\n * @returns True if the value is a StateSchema instance with the correct runtime tag.\n */\n static isInstance<TInit extends StateSchemaInit>(value: StateSchema<TInit>): value is StateSchema<TInit>;\n static isInstance(value: unknown): value is StateSchema<any>;\n}\nexport type AnyStateSchema = StateSchema<any>;\nexport {};\n"],"mappings":";;;;;;;;cAMcM;;AADyC;AAyBvD;;;;;;;;;;;;;;;;;;;AA8BA;;AAA6DO,KA9BjDN,yBA8BiDM,CAAAA,CAAAA,CAAAA,GA9BlBL,CA8BkBK,SA9BRT,YA8BQS,CAAAA,KAAAA,EAAAA,EAAAA,KAAAA,EAAAA,CAAAA,GA9ByBX,WA8BzBW,CA9BqCJ,CA8BrCI,EA9BwCH,CA8BxCG,CAAAA,GA9B6CL,CA8B7CK,SA9BuDR,cA8BvDQ,CAAAA,KAAAA,EAAAA,CAAAA,GA9BiFX,WA8BjFW,CA9B6FJ,CA8B7FI,EA9BgGJ,CA8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A,EAAAA,KAAAA,QAAAA,CAAAA,GA3DuGO,OA2DvGP,GAAAA,KAAAA;;;;;;;;;AA2BCZ,KA5EtBoB,sBA4EsBpB,CAAAA,cA5EeW,eA4EfX,CAAAA,GAAAA,QAAfuB,MA3EHX,KA2EGW,IA3EMX,KA2ENW,CA3EYV,CA2EZU,CAAAA,SAAAA;EAKEzB,SAAAA,EAAAA,KAAAA,OAAAA;IA9EbuB,MAmFkBvB,GAnFTc,KAmFSd,CAnFHe,CAmFGf,CAAAA,SAnFQK,cAmFRL,CAAAA,KAAAA,OAAAA,CAAAA,GAnFuCoB,MAmFvCpB,GAnFgDc,KAmFhDd,CAnFsDe,CAmFtDf,CAAAA,SAnFiEG,kBAmFjEH,CAAAA,KAAAA,OAAAA,EAAAA,OAAAA,CAAAA,GAnF6GuB,MAmF7GvB,GAAAA,KAAAA;;;;;;;;;;AA0B1B;;;;;;;;;;;;;;;;;;;;;;;;cA1EqBwB,0BAA0BX;iBAC5BC;;;;;oBAKGR,mBAAAA;;;;;SAKXa,sBAAsBL;;;;;UAKrBQ,uBAAuBR;;;;;;;;;;;;;;;;QAgBzBb,aAAakB,sBAAsBL,QAAQQ,uBAAuBR;oBACtDA;;;;;iBAKHW,eAAevB;;;;;mBAKbF;;;;;wBAKKA;;;;;;;;;;;;;;;;yBAgBC0B,IAAIC,QAAQD;;;;;;;kCAOHb,wBAAwBW,YAAYV,kBAAkBU,YAAYV;8CACtDU;;KAEpCI,cAAAA,GAAiBJ"}
|
|
1
|
+
{"version":3,"file":"schema.d.ts","names":["JSONSchema","RunnableLike","BaseChannel","SerializableSchema","ReducedValue","UntrackedValue","STATE_SCHEMA_SYMBOL","StateSchemaFieldToChannel","F","V","I","O","StateSchemaFieldsToStateDefinition","StateSchemaFields","TFields","K","StateSchemaField","Input","Output","InferStateSchemaValue","TOutput","InferStateSchemaUpdate","TInput","StateSchema","Record","T","Promise","AnyStateSchema"],"sources":["../../src/state/schema.d.ts"],"sourcesContent":["import type { JSONSchema } from \"@langchain/core/utils/json_schema\";\nimport type { RunnableLike } from \"../pregel/runnable_types.js\";\nimport { BaseChannel } from \"../channels/index.js\";\nimport type { SerializableSchema } from \"./types.js\";\nimport { ReducedValue } from \"./values/reduced.js\";\nimport { UntrackedValue } from \"./values/untracked.js\";\ndeclare const STATE_SCHEMA_SYMBOL: unique symbol;\n/**\n * Maps a single StateSchema field definition to its corresponding Channel type.\n *\n * This utility type inspects the type of the field and returns an appropriate\n * `BaseChannel` type, parameterized with the state \"value\" and \"input\" types according to the field's shape.\n *\n * Rules:\n * - If the field (`F`) is a `ReducedValue<V, I>`, the channel will store values of type `V`\n * and accept input of type `I`.\n * - If the field is a `UntrackedValue<V>`, the channel will store and accept values of type `V`.\n * - If the field is a `SerializableSchema<I, O>`, the channel will store values of type `O`\n * (the schema's output/validated value) and accept input of type `I`.\n * - For all other types, a generic `BaseChannel<unknown, unknown>` is used as fallback.\n *\n * @template F - The StateSchema field type to map to a Channel type.\n *\n * @example\n * ```typescript\n * type MyField = ReducedValue<number, string>;\n * type ChannelType = StateSchemaFieldToChannel<MyField>;\n * // ChannelType is BaseChannel<number, string>\n * ```\n */\nexport type StateSchemaFieldToChannel<F> = F extends ReducedValue<infer V, infer I> ? BaseChannel<V, I> : F extends UntrackedValue<infer V> ? BaseChannel<V, V> : F extends SerializableSchema<infer I, infer O> ? BaseChannel<O, I> : BaseChannel<unknown, unknown>;\n/**\n * Converts StateSchema fields into a strongly-typed\n * State Definition object, where each field is mapped to its channel type.\n *\n * This utility type is used internally to create the shape of the state channels for a given schema,\n * substituting each field with the result of `StateSchemaFieldToChannel`.\n *\n * If you define a state schema as:\n * ```typescript\n * const fields = {\n * a: ReducedValue<number, string>(),\n * b: UntrackedValue<boolean>(),\n * c: SomeSerializableSchemaType, // SerializableSchema<in, out>\n * }\n * ```\n * then `StateSchemaFieldsToStateDefinition<typeof fields>` yields:\n * ```typescript\n * {\n * a: BaseChannel<number, string>;\n * b: BaseChannel<boolean, boolean>;\n * c: BaseChannel<typeof schema's output type, typeof schema's input type>;\n * }\n * ```\n *\n * @template TFields - The mapping of field names to StateSchema field types.\n * @returns An object type mapping field names to channel types.\n *\n * @see StateSchemaFieldToChannel\n */\nexport type StateSchemaFieldsToStateDefinition<TFields extends StateSchemaFields> = {\n [K in keyof TFields]: StateSchemaFieldToChannel<TFields[K]>;\n};\n/**\n * Valid field types for StateSchema.\n * Either a LangGraph state value type or a raw schema (e.g., Zod schema).\n */\nexport type StateSchemaField<Input = unknown, Output = Input> = ReducedValue<Input, Output> | UntrackedValue<Output> | SerializableSchema<Input, Output>;\n/**\n * Init object for StateSchema constructor.\n * Uses `any` to allow variance in generic types (e.g., ReducedValue<string, string[]>).\n */\nexport type StateSchemaFields = {\n [key: string]: StateSchemaField<any, any>;\n};\n/**\n * Infer the State type from a StateSchemaFields.\n * This is the type of the full state object.\n *\n * - ReducedValue<Value, Input> → Value (the stored type)\n * - UntrackedValue<Value> → Value\n * - SerializableSchema<Input, Output> → Output (the validated type)\n */\nexport type InferStateSchemaValue<TFields extends StateSchemaFields> = {\n [K in keyof TFields]: TFields[K] extends ReducedValue<any, any> ? TFields[K][\"ValueType\"] : TFields[K] extends UntrackedValue<any> ? TFields[K][\"ValueType\"] : TFields[K] extends SerializableSchema<any, infer TOutput> ? TOutput : never;\n};\n/**\n * Infer the Update type from a StateSchemaFields.\n * This is the type for partial updates to state.\n *\n * - ReducedValue<Value, Input> → Input (the reducer input type)\n * - UntrackedValue<Value> → Value\n * - SerializableSchema<Input, Output> → Input (what you provide)\n */\nexport type InferStateSchemaUpdate<TFields extends StateSchemaFields> = {\n [K in keyof TFields]?: TFields[K] extends ReducedValue<any, any> ? TFields[K][\"InputType\"] : TFields[K] extends UntrackedValue<any> ? TFields[K][\"ValueType\"] : TFields[K] extends SerializableSchema<infer TInput, any> ? TInput : never;\n};\n/**\n * StateSchema provides a unified API for defining LangGraph state schemas.\n *\n * @example\n * ```ts\n * import { z } from \"zod\";\n * import { StateSchema, ReducedValue, MessagesValue } from \"@langchain/langgraph\";\n *\n * const AgentState = new StateSchema({\n * // Prebuilt messages value\n * messages: MessagesValue,\n * // Basic LastValue channel from any standard schema\n * currentStep: z.string(),\n * // LastValue with native default\n * count: z.number().default(0),\n * // ReducedValue for fields needing reducers\n * history: new ReducedValue(\n * z.array(z.string()).default(() => []),\n * {\n * inputSchema: z.string(),\n * reducer: (current, next) => [...current, next],\n * }\n * ),\n * });\n *\n * // Extract types\n * type State = typeof AgentState.State;\n * type Update = typeof AgentState.Update;\n *\n * // Use in StateGraph\n * const graph = new StateGraph(AgentState);\n * ```\n */\nexport declare class StateSchema<TFields extends StateSchemaFields> {\n readonly fields: TFields;\n /**\n * Symbol for runtime identification.\n * @internal Used by isInstance for runtime type checking\n */\n private readonly [STATE_SCHEMA_SYMBOL];\n /**\n * Type declaration for the full state type.\n * Use: `typeof myState.State`\n */\n State: InferStateSchemaValue<TFields>;\n /**\n * Type declaration for the update type.\n * Use: `typeof myState.Update`\n */\n Update: InferStateSchemaUpdate<TFields>;\n /**\n * Type declaration for node functions.\n * Use: `typeof myState.Node` to type node functions outside the graph builder.\n *\n * @example\n * ```typescript\n * const AgentState = new StateSchema({\n * count: z.number().default(0),\n * });\n *\n * const myNode: typeof AgentState.Node = (state) => {\n * return { count: state.count + 1 };\n * };\n * ```\n */\n Node: RunnableLike<InferStateSchemaValue<TFields>, InferStateSchemaUpdate<TFields>>;\n constructor(fields: TFields);\n /**\n * Get the channel definitions for use with StateGraph.\n * This converts the StateSchema fields into BaseChannel instances.\n */\n getChannels(): Record<string, BaseChannel>;\n /**\n * Get the JSON schema for the full state type.\n * Used by Studio and API for schema introspection.\n */\n getJsonSchema(): JSONSchema;\n /**\n * Get the JSON schema for the update/input type.\n * All fields are optional in updates.\n */\n getInputJsonSchema(): JSONSchema;\n /**\n * Get the list of channel keys (excluding managed values).\n */\n getChannelKeys(): string[];\n /**\n * Get all keys (channels + managed values).\n */\n getAllKeys(): string[];\n /**\n * Validate input data against the schema.\n * This validates each field using its corresponding schema.\n *\n * @param data - The input data to validate\n * @returns The validated data with coerced types\n */\n validateInput<T>(data: T): Promise<T>;\n /**\n * Type guard to check if a value is a StateSchema instance.\n *\n * @param value - The value to check.\n * @returns True if the value is a StateSchema instance with the correct runtime tag.\n */\n static isInstance<TFields extends StateSchemaFields>(value: StateSchema<TFields>): value is StateSchema<TFields>;\n static isInstance(value: unknown): value is StateSchema<any>;\n}\nexport type AnyStateSchema = StateSchema<any>;\nexport {};\n"],"mappings":";;;;;;;;cAMcM;;AADyC;AAyBvD;;;;;;;;;;;;;;;;;;;AA8BA;;AAA+DO,KA9BnDN,yBA8BmDM,CAAAA,CAAAA,CAAAA,GA9BpBL,CA8BoBK,SA9BVT,YA8BUS,CAAAA,KAAAA,EAAAA,EAAAA,KAAAA,EAAAA,CAAAA,GA9BuBX,WA8BvBW,CA9BmCJ,CA8BnCI,EA9BsCH,CA8BtCG,CAAAA,GA9B2CL,CA8B3CK,SA9BqDR,cA8BrDQ,CAAAA,KAAAA,EAAAA,CAAAA,GA9B+EX,WA8B/EW,CA9B2FJ,CA8B3FI,EA9B8FJ,CA8B9FI,CAAAA,GA9BmGL,CA8BnGK,SA9B6GV,kBA8B7GU,CAAAA,KAAAA,EAAAA,EAAAA,KAAAA,EAAAA,CAAAA,GA9BoJX,WA8BpJW,CA9BgKF,CA8BhKE,EA9BmKH,CA8BnKG,CAAAA,GA9BwKX,WA8BxKW,CAAAA,OAAAA,EAAAA,OAAAA,CAAAA;;;;;;AAO/D;;;;;;;;;;;;AAKA;AAWA;;;;;;;;;;;AACmHR,KAxBvGO,kCAwBuGP,CAAAA,gBAxBpDQ,iBAwBoDR,CAAAA,GAAAA,QAAsBS,MAvBzHA,OAuByHA,GAvB/GP,yBAuB+GO,CAvBrFA,OAuBqFA,CAvB7EC,CAuB6ED,CAAAA,CAAAA;;;;;AAA6F,KAjB1NE,gBAiB0N,CAAA,QAAA,OAAA,EAAA,SAjB/KC,KAiB+K,CAAA,GAjBt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CAmDtIM,CAAAA,CAAAA,WAAAA,CAAAA,GAnDwJP,OAmDxJO,CAnDgKN,CAmDhKM,CAAAA,SAnD2KlB,kBAmD3KkB,CAAAA,KAAAA,OAAAA,EAAAA,GAAAA,CAAAA,GAnDmNC,MAmDnND,GAAAA,KAAAA;;;;;;;;;;;;;;;;;;;;AA0DZ;;;;;;;;;;;;;;cA1EqBE,4BAA4BV;mBAC5BC;;;;;oBAKCR,mBAAAA;;;;;SAKXa,sBAAsBL;;;;;UAKrBO,uBAAuBP;;;;;;;;;;;;;;;;QAgBzBb,aAAakB,sBAAsBL,UAAUO,uBAAuBP;sBACtDA;;;;;iBAKLU,eAAetB;;;;;mBAKbF;;;;;wBAKKA;;;;;;;;;;;;;;;;yBAgBCyB,IAAIC,QAAQD;;;;;;;oCAODZ,0BAA0BU,YAAYT,oBAAoBS,YAAYT;8CAC5DS;;KAEpCI,cAAAA,GAAiBJ"}
|
package/dist/state/schema.js
CHANGED
|
@@ -48,9 +48,8 @@ var StateSchema = class {
|
|
|
48
48
|
* @internal Used by isInstance for runtime type checking
|
|
49
49
|
*/
|
|
50
50
|
[STATE_SCHEMA_SYMBOL] = true;
|
|
51
|
-
constructor(
|
|
52
|
-
this.
|
|
53
|
-
this.init = init;
|
|
51
|
+
constructor(fields) {
|
|
52
|
+
this.fields = fields;
|
|
54
53
|
}
|
|
55
54
|
/**
|
|
56
55
|
* Get the channel definitions for use with StateGraph.
|
|
@@ -58,7 +57,7 @@ var StateSchema = class {
|
|
|
58
57
|
*/
|
|
59
58
|
getChannels() {
|
|
60
59
|
const channels = {};
|
|
61
|
-
for (const [key, value] of Object.entries(this.
|
|
60
|
+
for (const [key, value] of Object.entries(this.fields)) if (ReducedValue.isInstance(value)) {
|
|
62
61
|
const defaultGetter = getSchemaDefaultGetter(value.valueSchema);
|
|
63
62
|
channels[key] = new BinaryOperatorAggregate(value.reducer, defaultGetter);
|
|
64
63
|
} else if (UntrackedValue.isInstance(value)) {
|
|
@@ -78,7 +77,7 @@ var StateSchema = class {
|
|
|
78
77
|
getJsonSchema() {
|
|
79
78
|
const properties = {};
|
|
80
79
|
const required = [];
|
|
81
|
-
for (const [key, value] of Object.entries(this.
|
|
80
|
+
for (const [key, value] of Object.entries(this.fields)) {
|
|
82
81
|
let fieldSchema;
|
|
83
82
|
if (ReducedValue.isInstance(value)) {
|
|
84
83
|
fieldSchema = getJsonSchemaFromSchema(value.valueSchema);
|
|
@@ -109,7 +108,7 @@ var StateSchema = class {
|
|
|
109
108
|
*/
|
|
110
109
|
getInputJsonSchema() {
|
|
111
110
|
const properties = {};
|
|
112
|
-
for (const [key, value] of Object.entries(this.
|
|
111
|
+
for (const [key, value] of Object.entries(this.fields)) {
|
|
113
112
|
let fieldSchema;
|
|
114
113
|
if (ReducedValue.isInstance(value)) fieldSchema = getJsonSchemaFromSchema(value.inputSchema);
|
|
115
114
|
else if (UntrackedValue.isInstance(value)) fieldSchema = value.schema ? getJsonSchemaFromSchema(value.schema) : void 0;
|
|
@@ -125,13 +124,13 @@ var StateSchema = class {
|
|
|
125
124
|
* Get the list of channel keys (excluding managed values).
|
|
126
125
|
*/
|
|
127
126
|
getChannelKeys() {
|
|
128
|
-
return Object.entries(this.
|
|
127
|
+
return Object.entries(this.fields).map(([key]) => key);
|
|
129
128
|
}
|
|
130
129
|
/**
|
|
131
130
|
* Get all keys (channels + managed values).
|
|
132
131
|
*/
|
|
133
132
|
getAllKeys() {
|
|
134
|
-
return Object.keys(this.
|
|
133
|
+
return Object.keys(this.fields);
|
|
135
134
|
}
|
|
136
135
|
/**
|
|
137
136
|
* Validate input data against the schema.
|
|
@@ -144,7 +143,7 @@ var StateSchema = class {
|
|
|
144
143
|
if (data == null || typeof data !== "object") return data;
|
|
145
144
|
const result = {};
|
|
146
145
|
for (const [key, value] of Object.entries(data)) {
|
|
147
|
-
const fieldDef = this.
|
|
146
|
+
const fieldDef = this.fields[key];
|
|
148
147
|
if (fieldDef === void 0) {
|
|
149
148
|
result[key] = value;
|
|
150
149
|
continue;
|