@agentforge/core 0.15.7 → 0.15.8
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/index.cjs +62 -24
- package/dist/index.d.cts +53 -7
- package/dist/index.d.ts +53 -7
- package/dist/index.js +62 -24
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2211,46 +2211,84 @@ function createToolSimulator(config) {
|
|
|
2211
2211
|
|
|
2212
2212
|
// src/langgraph/state.ts
|
|
2213
2213
|
var import_langgraph = require("@langchain/langgraph");
|
|
2214
|
+
function entriesOf(value) {
|
|
2215
|
+
return Object.entries(value);
|
|
2216
|
+
}
|
|
2217
|
+
function keysOf(value) {
|
|
2218
|
+
return Object.keys(value);
|
|
2219
|
+
}
|
|
2220
|
+
function hasOwnProperty(value, key) {
|
|
2221
|
+
return Object.prototype.hasOwnProperty.call(value, key);
|
|
2222
|
+
}
|
|
2223
|
+
function useLatestValue(_left, right) {
|
|
2224
|
+
return right;
|
|
2225
|
+
}
|
|
2226
|
+
function setStateValue(target, key, value) {
|
|
2227
|
+
target[key] = value;
|
|
2228
|
+
}
|
|
2229
|
+
function setStateDefinitionValue(target, key, value) {
|
|
2230
|
+
target[key] = value;
|
|
2231
|
+
}
|
|
2232
|
+
function createChannel(channelConfig) {
|
|
2233
|
+
if (channelConfig.reducer) {
|
|
2234
|
+
return (0, import_langgraph.Annotation)({
|
|
2235
|
+
reducer: channelConfig.reducer,
|
|
2236
|
+
default: channelConfig.default
|
|
2237
|
+
});
|
|
2238
|
+
}
|
|
2239
|
+
if (channelConfig.default) {
|
|
2240
|
+
return (0, import_langgraph.Annotation)({
|
|
2241
|
+
reducer: useLatestValue,
|
|
2242
|
+
default: channelConfig.default
|
|
2243
|
+
});
|
|
2244
|
+
}
|
|
2245
|
+
return (0, import_langgraph.Annotation)();
|
|
2246
|
+
}
|
|
2214
2247
|
function createStateAnnotation(config) {
|
|
2215
2248
|
const stateDefinition = {};
|
|
2216
|
-
for (const [key, channelConfig] of
|
|
2217
|
-
|
|
2218
|
-
stateDefinition
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
} else if (channelConfig.default) {
|
|
2223
|
-
stateDefinition[key] = (0, import_langgraph.Annotation)({
|
|
2224
|
-
reducer: (_left, right) => right,
|
|
2225
|
-
default: channelConfig.default
|
|
2226
|
-
});
|
|
2227
|
-
} else {
|
|
2228
|
-
stateDefinition[key] = (0, import_langgraph.Annotation)();
|
|
2229
|
-
}
|
|
2249
|
+
for (const [key, channelConfig] of entriesOf(config)) {
|
|
2250
|
+
setStateDefinitionValue(
|
|
2251
|
+
stateDefinition,
|
|
2252
|
+
key,
|
|
2253
|
+
createChannel(channelConfig)
|
|
2254
|
+
);
|
|
2230
2255
|
}
|
|
2231
2256
|
return import_langgraph.Annotation.Root(stateDefinition);
|
|
2232
2257
|
}
|
|
2233
2258
|
function validateState(state, config) {
|
|
2234
2259
|
const validated = {};
|
|
2235
|
-
for (const [key, channelConfig] of
|
|
2236
|
-
if (channelConfig.schema && key
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2260
|
+
for (const [key, channelConfig] of entriesOf(config)) {
|
|
2261
|
+
if (channelConfig.schema && hasOwnProperty(state, key)) {
|
|
2262
|
+
setStateValue(
|
|
2263
|
+
validated,
|
|
2264
|
+
key,
|
|
2265
|
+
channelConfig.schema.parse(state[key])
|
|
2266
|
+
);
|
|
2267
|
+
} else if (hasOwnProperty(state, key)) {
|
|
2268
|
+
setStateValue(validated, key, state[key]);
|
|
2240
2269
|
} else if (channelConfig.default) {
|
|
2241
|
-
validated
|
|
2270
|
+
setStateValue(validated, key, channelConfig.default());
|
|
2242
2271
|
}
|
|
2243
2272
|
}
|
|
2244
2273
|
return validated;
|
|
2245
2274
|
}
|
|
2246
2275
|
function mergeState(currentState, update, config) {
|
|
2247
2276
|
const merged = { ...currentState };
|
|
2248
|
-
for (const
|
|
2277
|
+
for (const key of keysOf(update)) {
|
|
2278
|
+
const value = update[key];
|
|
2249
2279
|
const channelConfig = config[key];
|
|
2250
|
-
|
|
2251
|
-
|
|
2280
|
+
const reducer = channelConfig?.reducer;
|
|
2281
|
+
if (reducer && hasOwnProperty(merged, key)) {
|
|
2282
|
+
setStateValue(
|
|
2283
|
+
merged,
|
|
2284
|
+
key,
|
|
2285
|
+
reducer(
|
|
2286
|
+
merged[key],
|
|
2287
|
+
value
|
|
2288
|
+
)
|
|
2289
|
+
);
|
|
2252
2290
|
} else {
|
|
2253
|
-
merged
|
|
2291
|
+
setStateValue(merged, key, value);
|
|
2254
2292
|
}
|
|
2255
2293
|
}
|
|
2256
2294
|
return merged;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { z, ZodType, ZodTypeDef } from 'zod';
|
|
1
|
+
import { z, ZodTypeAny, output, ZodType, ZodTypeDef } from 'zod';
|
|
2
2
|
import { DynamicStructuredTool } from '@langchain/core/tools';
|
|
3
|
-
import { AnnotationRoot,
|
|
3
|
+
import { AnnotationRoot, BaseChannel, StateGraph, END, MemorySaver, BaseCheckpointSaver, CheckpointTuple } from '@langchain/langgraph';
|
|
4
4
|
import { RunnableConfig } from '@langchain/core/runnables';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -1901,11 +1901,11 @@ declare function getToolDescription<TInput, TOutput>(tool: Tool<TInput, TOutput>
|
|
|
1901
1901
|
/**
|
|
1902
1902
|
* State channel configuration with optional Zod schema validation
|
|
1903
1903
|
*/
|
|
1904
|
-
interface StateChannelConfig<T =
|
|
1904
|
+
interface StateChannelConfig<T = unknown, U = T> {
|
|
1905
1905
|
/**
|
|
1906
1906
|
* Optional Zod schema for runtime validation
|
|
1907
1907
|
*/
|
|
1908
|
-
schema?: ZodType<T, ZodTypeDef,
|
|
1908
|
+
schema?: ZodType<T, ZodTypeDef, unknown>;
|
|
1909
1909
|
/**
|
|
1910
1910
|
* Optional reducer function for aggregating updates
|
|
1911
1911
|
*/
|
|
@@ -1919,6 +1919,52 @@ interface StateChannelConfig<T = any, U = T> {
|
|
|
1919
1919
|
*/
|
|
1920
1920
|
description?: string;
|
|
1921
1921
|
}
|
|
1922
|
+
type StateChannelConfigLike = {
|
|
1923
|
+
schema?: ZodTypeAny;
|
|
1924
|
+
reducer?: (left: never, right: never) => unknown;
|
|
1925
|
+
default?: () => unknown;
|
|
1926
|
+
description?: string;
|
|
1927
|
+
};
|
|
1928
|
+
type StateConfigMap = Record<string, StateChannelConfigLike>;
|
|
1929
|
+
type IsExact<TLeft, TRight> = [
|
|
1930
|
+
TLeft
|
|
1931
|
+
] extends [TRight] ? ([TRight] extends [TLeft] ? true : false) : false;
|
|
1932
|
+
type HasReducer<TChannel extends StateChannelConfigLike> = TChannel extends {
|
|
1933
|
+
reducer: (left: unknown, right: unknown) => unknown;
|
|
1934
|
+
} ? true : false;
|
|
1935
|
+
type SchemaValue<TChannel extends StateChannelConfigLike> = TChannel extends {
|
|
1936
|
+
schema: infer TSchema extends ZodTypeAny;
|
|
1937
|
+
} ? output<TSchema> : never;
|
|
1938
|
+
type DefaultValue<TChannel extends StateChannelConfigLike> = TChannel extends {
|
|
1939
|
+
default: () => infer TValue;
|
|
1940
|
+
} ? TValue : never;
|
|
1941
|
+
type ReducerValue<TChannel extends StateChannelConfigLike> = TChannel extends {
|
|
1942
|
+
reducer: (left: infer TValue, right: unknown) => infer TResult;
|
|
1943
|
+
} ? IsExact<TValue, TResult> extends true ? TValue : never : never;
|
|
1944
|
+
type ReducerUpdate<TChannel extends StateChannelConfigLike> = TChannel extends {
|
|
1945
|
+
reducer: (left: unknown, right: infer TUpdate) => unknown;
|
|
1946
|
+
} ? TUpdate : never;
|
|
1947
|
+
type ChannelValue<TChannel extends StateChannelConfigLike> = HasReducer<TChannel> extends true ? ReducerValue<TChannel> : [SchemaValue<TChannel>] extends [never] ? [DefaultValue<TChannel>] extends [never] ? unknown : DefaultValue<TChannel> : SchemaValue<TChannel>;
|
|
1948
|
+
type ChannelUpdate<TChannel extends StateChannelConfigLike> = HasReducer<TChannel> extends true ? ReducerUpdate<TChannel> : ChannelValue<TChannel>;
|
|
1949
|
+
type StateShape<TConfig extends StateConfigMap> = {
|
|
1950
|
+
[K in keyof TConfig]: ChannelValue<TConfig[K]>;
|
|
1951
|
+
};
|
|
1952
|
+
type StateUpdateShape<TConfig extends StateConfigMap> = {
|
|
1953
|
+
[K in keyof TConfig]?: ChannelUpdate<TConfig[K]>;
|
|
1954
|
+
};
|
|
1955
|
+
type StateChannelDefinition<TChannel extends StateChannelConfigLike> = BaseChannel<ChannelValue<TChannel>, ChannelUpdate<TChannel>>;
|
|
1956
|
+
type StateAnnotationDefinition<TConfig extends StateConfigMap> = {
|
|
1957
|
+
[K in keyof TConfig]: StateChannelDefinition<TConfig[K]>;
|
|
1958
|
+
};
|
|
1959
|
+
type DefaultedKeys<TConfig extends StateConfigMap> = {
|
|
1960
|
+
[K in keyof TConfig]-?: TConfig[K] extends {
|
|
1961
|
+
default: () => ChannelValue<TConfig[K]>;
|
|
1962
|
+
} ? K : never;
|
|
1963
|
+
}[keyof TConfig];
|
|
1964
|
+
type InputStateKeys<TConfig extends StateConfigMap, TState> = Extract<keyof TConfig, keyof TState>;
|
|
1965
|
+
type ValidatedState<TConfig extends StateConfigMap, TState extends Partial<Record<keyof TConfig, unknown>>> = {
|
|
1966
|
+
[K in InputStateKeys<TConfig, TState> | DefaultedKeys<TConfig>]: ChannelValue<TConfig[K]>;
|
|
1967
|
+
};
|
|
1922
1968
|
/**
|
|
1923
1969
|
* Create a type-safe state annotation with optional Zod validation
|
|
1924
1970
|
*
|
|
@@ -1949,7 +1995,7 @@ interface StateChannelConfig<T = any, U = T> {
|
|
|
1949
1995
|
* type State = typeof AgentState.State;
|
|
1950
1996
|
* ```
|
|
1951
1997
|
*/
|
|
1952
|
-
declare function createStateAnnotation<
|
|
1998
|
+
declare function createStateAnnotation<TConfig extends StateConfigMap>(config: TConfig): AnnotationRoot<StateAnnotationDefinition<TConfig>>;
|
|
1953
1999
|
/**
|
|
1954
2000
|
* Validate state against Zod schemas
|
|
1955
2001
|
*
|
|
@@ -1971,7 +2017,7 @@ declare function createStateAnnotation<T extends Record<string, StateChannelConf
|
|
|
1971
2017
|
* );
|
|
1972
2018
|
* ```
|
|
1973
2019
|
*/
|
|
1974
|
-
declare function validateState<
|
|
2020
|
+
declare function validateState<TConfig extends StateConfigMap, TState extends Partial<Record<keyof TConfig, unknown>>>(state: TState, config: TConfig): ValidatedState<TConfig, TState>;
|
|
1975
2021
|
/**
|
|
1976
2022
|
* Merge state updates using configured reducers
|
|
1977
2023
|
*
|
|
@@ -1996,7 +2042,7 @@ declare function validateState<T extends Record<string, StateChannelConfig>>(sta
|
|
|
1996
2042
|
* // Result: { messages: ['a', 'b', 'c'] }
|
|
1997
2043
|
* ```
|
|
1998
2044
|
*/
|
|
1999
|
-
declare function mergeState<
|
|
2045
|
+
declare function mergeState<TConfig extends StateConfigMap>(currentState: Partial<StateShape<TConfig>>, update: StateUpdateShape<TConfig>, config: TConfig): Partial<StateShape<TConfig>>;
|
|
2000
2046
|
|
|
2001
2047
|
/**
|
|
2002
2048
|
* Sequential Workflow Builder
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { z, ZodType, ZodTypeDef } from 'zod';
|
|
1
|
+
import { z, ZodTypeAny, output, ZodType, ZodTypeDef } from 'zod';
|
|
2
2
|
import { DynamicStructuredTool } from '@langchain/core/tools';
|
|
3
|
-
import { AnnotationRoot,
|
|
3
|
+
import { AnnotationRoot, BaseChannel, StateGraph, END, MemorySaver, BaseCheckpointSaver, CheckpointTuple } from '@langchain/langgraph';
|
|
4
4
|
import { RunnableConfig } from '@langchain/core/runnables';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -1901,11 +1901,11 @@ declare function getToolDescription<TInput, TOutput>(tool: Tool<TInput, TOutput>
|
|
|
1901
1901
|
/**
|
|
1902
1902
|
* State channel configuration with optional Zod schema validation
|
|
1903
1903
|
*/
|
|
1904
|
-
interface StateChannelConfig<T =
|
|
1904
|
+
interface StateChannelConfig<T = unknown, U = T> {
|
|
1905
1905
|
/**
|
|
1906
1906
|
* Optional Zod schema for runtime validation
|
|
1907
1907
|
*/
|
|
1908
|
-
schema?: ZodType<T, ZodTypeDef,
|
|
1908
|
+
schema?: ZodType<T, ZodTypeDef, unknown>;
|
|
1909
1909
|
/**
|
|
1910
1910
|
* Optional reducer function for aggregating updates
|
|
1911
1911
|
*/
|
|
@@ -1919,6 +1919,52 @@ interface StateChannelConfig<T = any, U = T> {
|
|
|
1919
1919
|
*/
|
|
1920
1920
|
description?: string;
|
|
1921
1921
|
}
|
|
1922
|
+
type StateChannelConfigLike = {
|
|
1923
|
+
schema?: ZodTypeAny;
|
|
1924
|
+
reducer?: (left: never, right: never) => unknown;
|
|
1925
|
+
default?: () => unknown;
|
|
1926
|
+
description?: string;
|
|
1927
|
+
};
|
|
1928
|
+
type StateConfigMap = Record<string, StateChannelConfigLike>;
|
|
1929
|
+
type IsExact<TLeft, TRight> = [
|
|
1930
|
+
TLeft
|
|
1931
|
+
] extends [TRight] ? ([TRight] extends [TLeft] ? true : false) : false;
|
|
1932
|
+
type HasReducer<TChannel extends StateChannelConfigLike> = TChannel extends {
|
|
1933
|
+
reducer: (left: unknown, right: unknown) => unknown;
|
|
1934
|
+
} ? true : false;
|
|
1935
|
+
type SchemaValue<TChannel extends StateChannelConfigLike> = TChannel extends {
|
|
1936
|
+
schema: infer TSchema extends ZodTypeAny;
|
|
1937
|
+
} ? output<TSchema> : never;
|
|
1938
|
+
type DefaultValue<TChannel extends StateChannelConfigLike> = TChannel extends {
|
|
1939
|
+
default: () => infer TValue;
|
|
1940
|
+
} ? TValue : never;
|
|
1941
|
+
type ReducerValue<TChannel extends StateChannelConfigLike> = TChannel extends {
|
|
1942
|
+
reducer: (left: infer TValue, right: unknown) => infer TResult;
|
|
1943
|
+
} ? IsExact<TValue, TResult> extends true ? TValue : never : never;
|
|
1944
|
+
type ReducerUpdate<TChannel extends StateChannelConfigLike> = TChannel extends {
|
|
1945
|
+
reducer: (left: unknown, right: infer TUpdate) => unknown;
|
|
1946
|
+
} ? TUpdate : never;
|
|
1947
|
+
type ChannelValue<TChannel extends StateChannelConfigLike> = HasReducer<TChannel> extends true ? ReducerValue<TChannel> : [SchemaValue<TChannel>] extends [never] ? [DefaultValue<TChannel>] extends [never] ? unknown : DefaultValue<TChannel> : SchemaValue<TChannel>;
|
|
1948
|
+
type ChannelUpdate<TChannel extends StateChannelConfigLike> = HasReducer<TChannel> extends true ? ReducerUpdate<TChannel> : ChannelValue<TChannel>;
|
|
1949
|
+
type StateShape<TConfig extends StateConfigMap> = {
|
|
1950
|
+
[K in keyof TConfig]: ChannelValue<TConfig[K]>;
|
|
1951
|
+
};
|
|
1952
|
+
type StateUpdateShape<TConfig extends StateConfigMap> = {
|
|
1953
|
+
[K in keyof TConfig]?: ChannelUpdate<TConfig[K]>;
|
|
1954
|
+
};
|
|
1955
|
+
type StateChannelDefinition<TChannel extends StateChannelConfigLike> = BaseChannel<ChannelValue<TChannel>, ChannelUpdate<TChannel>>;
|
|
1956
|
+
type StateAnnotationDefinition<TConfig extends StateConfigMap> = {
|
|
1957
|
+
[K in keyof TConfig]: StateChannelDefinition<TConfig[K]>;
|
|
1958
|
+
};
|
|
1959
|
+
type DefaultedKeys<TConfig extends StateConfigMap> = {
|
|
1960
|
+
[K in keyof TConfig]-?: TConfig[K] extends {
|
|
1961
|
+
default: () => ChannelValue<TConfig[K]>;
|
|
1962
|
+
} ? K : never;
|
|
1963
|
+
}[keyof TConfig];
|
|
1964
|
+
type InputStateKeys<TConfig extends StateConfigMap, TState> = Extract<keyof TConfig, keyof TState>;
|
|
1965
|
+
type ValidatedState<TConfig extends StateConfigMap, TState extends Partial<Record<keyof TConfig, unknown>>> = {
|
|
1966
|
+
[K in InputStateKeys<TConfig, TState> | DefaultedKeys<TConfig>]: ChannelValue<TConfig[K]>;
|
|
1967
|
+
};
|
|
1922
1968
|
/**
|
|
1923
1969
|
* Create a type-safe state annotation with optional Zod validation
|
|
1924
1970
|
*
|
|
@@ -1949,7 +1995,7 @@ interface StateChannelConfig<T = any, U = T> {
|
|
|
1949
1995
|
* type State = typeof AgentState.State;
|
|
1950
1996
|
* ```
|
|
1951
1997
|
*/
|
|
1952
|
-
declare function createStateAnnotation<
|
|
1998
|
+
declare function createStateAnnotation<TConfig extends StateConfigMap>(config: TConfig): AnnotationRoot<StateAnnotationDefinition<TConfig>>;
|
|
1953
1999
|
/**
|
|
1954
2000
|
* Validate state against Zod schemas
|
|
1955
2001
|
*
|
|
@@ -1971,7 +2017,7 @@ declare function createStateAnnotation<T extends Record<string, StateChannelConf
|
|
|
1971
2017
|
* );
|
|
1972
2018
|
* ```
|
|
1973
2019
|
*/
|
|
1974
|
-
declare function validateState<
|
|
2020
|
+
declare function validateState<TConfig extends StateConfigMap, TState extends Partial<Record<keyof TConfig, unknown>>>(state: TState, config: TConfig): ValidatedState<TConfig, TState>;
|
|
1975
2021
|
/**
|
|
1976
2022
|
* Merge state updates using configured reducers
|
|
1977
2023
|
*
|
|
@@ -1996,7 +2042,7 @@ declare function validateState<T extends Record<string, StateChannelConfig>>(sta
|
|
|
1996
2042
|
* // Result: { messages: ['a', 'b', 'c'] }
|
|
1997
2043
|
* ```
|
|
1998
2044
|
*/
|
|
1999
|
-
declare function mergeState<
|
|
2045
|
+
declare function mergeState<TConfig extends StateConfigMap>(currentState: Partial<StateShape<TConfig>>, update: StateUpdateShape<TConfig>, config: TConfig): Partial<StateShape<TConfig>>;
|
|
2000
2046
|
|
|
2001
2047
|
/**
|
|
2002
2048
|
* Sequential Workflow Builder
|
package/dist/index.js
CHANGED
|
@@ -2036,46 +2036,84 @@ function createToolSimulator(config) {
|
|
|
2036
2036
|
|
|
2037
2037
|
// src/langgraph/state.ts
|
|
2038
2038
|
import { Annotation } from "@langchain/langgraph";
|
|
2039
|
+
function entriesOf(value) {
|
|
2040
|
+
return Object.entries(value);
|
|
2041
|
+
}
|
|
2042
|
+
function keysOf(value) {
|
|
2043
|
+
return Object.keys(value);
|
|
2044
|
+
}
|
|
2045
|
+
function hasOwnProperty(value, key) {
|
|
2046
|
+
return Object.prototype.hasOwnProperty.call(value, key);
|
|
2047
|
+
}
|
|
2048
|
+
function useLatestValue(_left, right) {
|
|
2049
|
+
return right;
|
|
2050
|
+
}
|
|
2051
|
+
function setStateValue(target, key, value) {
|
|
2052
|
+
target[key] = value;
|
|
2053
|
+
}
|
|
2054
|
+
function setStateDefinitionValue(target, key, value) {
|
|
2055
|
+
target[key] = value;
|
|
2056
|
+
}
|
|
2057
|
+
function createChannel(channelConfig) {
|
|
2058
|
+
if (channelConfig.reducer) {
|
|
2059
|
+
return Annotation({
|
|
2060
|
+
reducer: channelConfig.reducer,
|
|
2061
|
+
default: channelConfig.default
|
|
2062
|
+
});
|
|
2063
|
+
}
|
|
2064
|
+
if (channelConfig.default) {
|
|
2065
|
+
return Annotation({
|
|
2066
|
+
reducer: useLatestValue,
|
|
2067
|
+
default: channelConfig.default
|
|
2068
|
+
});
|
|
2069
|
+
}
|
|
2070
|
+
return Annotation();
|
|
2071
|
+
}
|
|
2039
2072
|
function createStateAnnotation(config) {
|
|
2040
2073
|
const stateDefinition = {};
|
|
2041
|
-
for (const [key, channelConfig] of
|
|
2042
|
-
|
|
2043
|
-
stateDefinition
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
} else if (channelConfig.default) {
|
|
2048
|
-
stateDefinition[key] = Annotation({
|
|
2049
|
-
reducer: (_left, right) => right,
|
|
2050
|
-
default: channelConfig.default
|
|
2051
|
-
});
|
|
2052
|
-
} else {
|
|
2053
|
-
stateDefinition[key] = Annotation();
|
|
2054
|
-
}
|
|
2074
|
+
for (const [key, channelConfig] of entriesOf(config)) {
|
|
2075
|
+
setStateDefinitionValue(
|
|
2076
|
+
stateDefinition,
|
|
2077
|
+
key,
|
|
2078
|
+
createChannel(channelConfig)
|
|
2079
|
+
);
|
|
2055
2080
|
}
|
|
2056
2081
|
return Annotation.Root(stateDefinition);
|
|
2057
2082
|
}
|
|
2058
2083
|
function validateState(state, config) {
|
|
2059
2084
|
const validated = {};
|
|
2060
|
-
for (const [key, channelConfig] of
|
|
2061
|
-
if (channelConfig.schema && key
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2085
|
+
for (const [key, channelConfig] of entriesOf(config)) {
|
|
2086
|
+
if (channelConfig.schema && hasOwnProperty(state, key)) {
|
|
2087
|
+
setStateValue(
|
|
2088
|
+
validated,
|
|
2089
|
+
key,
|
|
2090
|
+
channelConfig.schema.parse(state[key])
|
|
2091
|
+
);
|
|
2092
|
+
} else if (hasOwnProperty(state, key)) {
|
|
2093
|
+
setStateValue(validated, key, state[key]);
|
|
2065
2094
|
} else if (channelConfig.default) {
|
|
2066
|
-
validated
|
|
2095
|
+
setStateValue(validated, key, channelConfig.default());
|
|
2067
2096
|
}
|
|
2068
2097
|
}
|
|
2069
2098
|
return validated;
|
|
2070
2099
|
}
|
|
2071
2100
|
function mergeState(currentState, update, config) {
|
|
2072
2101
|
const merged = { ...currentState };
|
|
2073
|
-
for (const
|
|
2102
|
+
for (const key of keysOf(update)) {
|
|
2103
|
+
const value = update[key];
|
|
2074
2104
|
const channelConfig = config[key];
|
|
2075
|
-
|
|
2076
|
-
|
|
2105
|
+
const reducer = channelConfig?.reducer;
|
|
2106
|
+
if (reducer && hasOwnProperty(merged, key)) {
|
|
2107
|
+
setStateValue(
|
|
2108
|
+
merged,
|
|
2109
|
+
key,
|
|
2110
|
+
reducer(
|
|
2111
|
+
merged[key],
|
|
2112
|
+
value
|
|
2113
|
+
)
|
|
2114
|
+
);
|
|
2077
2115
|
} else {
|
|
2078
|
-
merged
|
|
2116
|
+
setStateValue(merged, key, value);
|
|
2079
2117
|
}
|
|
2080
2118
|
}
|
|
2081
2119
|
return merged;
|
package/package.json
CHANGED