@foresthubai/workflow-core 0.3.0
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/LICENSE +202 -0
- package/NOTICE +14 -0
- package/README.md +63 -0
- package/dist/api/index.d.ts +7 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +2 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/workflow.d.ts +607 -0
- package/dist/api/workflow.d.ts.map +1 -0
- package/dist/api/workflow.js +6 -0
- package/dist/api/workflow.js.map +1 -0
- package/dist/channel/Channel.d.ts +10 -0
- package/dist/channel/Channel.d.ts.map +1 -0
- package/dist/channel/Channel.js +2 -0
- package/dist/channel/Channel.js.map +1 -0
- package/dist/channel/ChannelDefinition.d.ts +27 -0
- package/dist/channel/ChannelDefinition.d.ts.map +1 -0
- package/dist/channel/ChannelDefinition.js +50 -0
- package/dist/channel/ChannelDefinition.js.map +1 -0
- package/dist/channel/index.d.ts +7 -0
- package/dist/channel/index.d.ts.map +1 -0
- package/dist/channel/index.js +4 -0
- package/dist/channel/index.js.map +1 -0
- package/dist/channel/serialization.d.ts +17 -0
- package/dist/channel/serialization.d.ts.map +1 -0
- package/dist/channel/serialization.js +63 -0
- package/dist/channel/serialization.js.map +1 -0
- package/dist/deploy/index.d.ts +2 -0
- package/dist/deploy/index.d.ts.map +1 -0
- package/dist/deploy/index.js +2 -0
- package/dist/deploy/index.js.map +1 -0
- package/dist/deploy/requirements.d.ts +17 -0
- package/dist/deploy/requirements.d.ts.map +1 -0
- package/dist/deploy/requirements.js +41 -0
- package/dist/deploy/requirements.js.map +1 -0
- package/dist/diagnostics/__fixtures__/diagnosticFixtures.d.ts +28 -0
- package/dist/diagnostics/__fixtures__/diagnosticFixtures.d.ts.map +1 -0
- package/dist/diagnostics/__fixtures__/diagnosticFixtures.js +125 -0
- package/dist/diagnostics/__fixtures__/diagnosticFixtures.js.map +1 -0
- package/dist/diagnostics/diagnostics.d.ts +128 -0
- package/dist/diagnostics/diagnostics.d.ts.map +1 -0
- package/dist/diagnostics/diagnostics.js +783 -0
- package/dist/diagnostics/diagnostics.js.map +1 -0
- package/dist/diagnostics/index.d.ts +3 -0
- package/dist/diagnostics/index.d.ts.map +1 -0
- package/dist/diagnostics/index.js +2 -0
- package/dist/diagnostics/index.js.map +1 -0
- package/dist/edge/Edge.d.ts +22 -0
- package/dist/edge/Edge.d.ts.map +1 -0
- package/dist/edge/Edge.js +2 -0
- package/dist/edge/Edge.js.map +1 -0
- package/dist/edge/EdgeDefinition.d.ts +10 -0
- package/dist/edge/EdgeDefinition.d.ts.map +1 -0
- package/dist/edge/EdgeDefinition.js +36 -0
- package/dist/edge/EdgeDefinition.js.map +1 -0
- package/dist/edge/EdgeType.d.ts +6 -0
- package/dist/edge/EdgeType.d.ts.map +1 -0
- package/dist/edge/EdgeType.js +7 -0
- package/dist/edge/EdgeType.js.map +1 -0
- package/dist/edge/index.d.ts +6 -0
- package/dist/edge/index.d.ts.map +1 -0
- package/dist/edge/index.js +6 -0
- package/dist/edge/index.js.map +1 -0
- package/dist/edge/serialization.d.ts +18 -0
- package/dist/edge/serialization.d.ts.map +1 -0
- package/dist/edge/serialization.js +76 -0
- package/dist/edge/serialization.js.map +1 -0
- package/dist/expression/index.d.ts +5 -0
- package/dist/expression/index.d.ts.map +1 -0
- package/dist/expression/index.js +3 -0
- package/dist/expression/index.js.map +1 -0
- package/dist/expression/parser.d.ts +14 -0
- package/dist/expression/parser.d.ts.map +1 -0
- package/dist/expression/parser.js +309 -0
- package/dist/expression/parser.js.map +1 -0
- package/dist/expression/types.d.ts +11 -0
- package/dist/expression/types.d.ts.map +1 -0
- package/dist/expression/types.js +20 -0
- package/dist/expression/types.js.map +1 -0
- package/dist/function/FunctionDeclaration.d.ts +43 -0
- package/dist/function/FunctionDeclaration.d.ts.map +1 -0
- package/dist/function/FunctionDeclaration.js +17 -0
- package/dist/function/FunctionDeclaration.js.map +1 -0
- package/dist/function/index.d.ts +4 -0
- package/dist/function/index.d.ts.map +1 -0
- package/dist/function/index.js +3 -0
- package/dist/function/index.js.map +1 -0
- package/dist/function/serialization.d.ts +20 -0
- package/dist/function/serialization.d.ts.map +1 -0
- package/dist/function/serialization.js +26 -0
- package/dist/function/serialization.js.map +1 -0
- package/dist/id/index.d.ts +7 -0
- package/dist/id/index.d.ts.map +1 -0
- package/dist/id/index.js +9 -0
- package/dist/id/index.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/memory/Memory.d.ts +12 -0
- package/dist/memory/Memory.d.ts.map +1 -0
- package/dist/memory/Memory.js +2 -0
- package/dist/memory/Memory.js.map +1 -0
- package/dist/memory/MemoryDefinition.d.ts +16 -0
- package/dist/memory/MemoryDefinition.d.ts.map +1 -0
- package/dist/memory/MemoryDefinition.js +2 -0
- package/dist/memory/MemoryDefinition.js.map +1 -0
- package/dist/memory/MemoryFileDefinition.d.ts +8 -0
- package/dist/memory/MemoryFileDefinition.d.ts.map +1 -0
- package/dist/memory/MemoryFileDefinition.js +36 -0
- package/dist/memory/MemoryFileDefinition.js.map +1 -0
- package/dist/memory/MemoryRegistry.d.ts +17 -0
- package/dist/memory/MemoryRegistry.d.ts.map +1 -0
- package/dist/memory/MemoryRegistry.js +29 -0
- package/dist/memory/MemoryRegistry.js.map +1 -0
- package/dist/memory/VectorDatabaseDefinition.d.ts +7 -0
- package/dist/memory/VectorDatabaseDefinition.d.ts.map +1 -0
- package/dist/memory/VectorDatabaseDefinition.js +20 -0
- package/dist/memory/VectorDatabaseDefinition.js.map +1 -0
- package/dist/memory/index.d.ts +9 -0
- package/dist/memory/index.d.ts.map +1 -0
- package/dist/memory/index.js +6 -0
- package/dist/memory/index.js.map +1 -0
- package/dist/memory/serialization.d.ts +11 -0
- package/dist/memory/serialization.d.ts.map +1 -0
- package/dist/memory/serialization.js +44 -0
- package/dist/memory/serialization.js.map +1 -0
- package/dist/migration/index.d.ts +5 -0
- package/dist/migration/index.d.ts.map +1 -0
- package/dist/migration/index.js +4 -0
- package/dist/migration/index.js.map +1 -0
- package/dist/migration/migrate.d.ts +11 -0
- package/dist/migration/migrate.d.ts.map +1 -0
- package/dist/migration/migrate.js +52 -0
- package/dist/migration/migrate.js.map +1 -0
- package/dist/migration/migrations.d.ts +22 -0
- package/dist/migration/migrations.d.ts.map +1 -0
- package/dist/migration/migrations.js +10 -0
- package/dist/migration/migrations.js.map +1 -0
- package/dist/migration/version.d.ts +9 -0
- package/dist/migration/version.d.ts.map +1 -0
- package/dist/migration/version.js +9 -0
- package/dist/migration/version.js.map +1 -0
- package/dist/model/LLMModelDefinition.d.ts +7 -0
- package/dist/model/LLMModelDefinition.d.ts.map +1 -0
- package/dist/model/LLMModelDefinition.js +11 -0
- package/dist/model/LLMModelDefinition.js.map +1 -0
- package/dist/model/Model.d.ts +21 -0
- package/dist/model/Model.d.ts.map +1 -0
- package/dist/model/Model.js +15 -0
- package/dist/model/Model.js.map +1 -0
- package/dist/model/ModelDefinition.d.ts +15 -0
- package/dist/model/ModelDefinition.d.ts.map +1 -0
- package/dist/model/ModelDefinition.js +2 -0
- package/dist/model/ModelDefinition.js.map +1 -0
- package/dist/model/ModelRegistry.d.ts +17 -0
- package/dist/model/ModelRegistry.d.ts.map +1 -0
- package/dist/model/ModelRegistry.js +27 -0
- package/dist/model/ModelRegistry.js.map +1 -0
- package/dist/model/index.d.ts +8 -0
- package/dist/model/index.d.ts.map +1 -0
- package/dist/model/index.js +5 -0
- package/dist/model/index.js.map +1 -0
- package/dist/model/serialization.d.ts +8 -0
- package/dist/model/serialization.d.ts.map +1 -0
- package/dist/model/serialization.js +25 -0
- package/dist/model/serialization.js.map +1 -0
- package/dist/node/AgentNode.d.ts +21 -0
- package/dist/node/AgentNode.d.ts.map +1 -0
- package/dist/node/AgentNode.js +60 -0
- package/dist/node/AgentNode.js.map +1 -0
- package/dist/node/DataNode.d.ts +14 -0
- package/dist/node/DataNode.d.ts.map +1 -0
- package/dist/node/DataNode.js +26 -0
- package/dist/node/DataNode.js.map +1 -0
- package/dist/node/FunctionNode.d.ts +24 -0
- package/dist/node/FunctionNode.d.ts.map +1 -0
- package/dist/node/FunctionNode.js +44 -0
- package/dist/node/FunctionNode.js.map +1 -0
- package/dist/node/InputNode.d.ts +46 -0
- package/dist/node/InputNode.d.ts.map +1 -0
- package/dist/node/InputNode.js +133 -0
- package/dist/node/InputNode.js.map +1 -0
- package/dist/node/LogicNode.d.ts +13 -0
- package/dist/node/LogicNode.d.ts.map +1 -0
- package/dist/node/LogicNode.js +19 -0
- package/dist/node/LogicNode.js.map +1 -0
- package/dist/node/MqttNode.d.ts +27 -0
- package/dist/node/MqttNode.d.ts.map +1 -0
- package/dist/node/MqttNode.js +96 -0
- package/dist/node/MqttNode.js.map +1 -0
- package/dist/node/Node.d.ts +49 -0
- package/dist/node/Node.d.ts.map +1 -0
- package/dist/node/Node.js +9 -0
- package/dist/node/Node.js.map +1 -0
- package/dist/node/NodeDefinition.d.ts +30 -0
- package/dist/node/NodeDefinition.d.ts.map +1 -0
- package/dist/node/NodeDefinition.js +2 -0
- package/dist/node/NodeDefinition.js.map +1 -0
- package/dist/node/NodeRegistry.d.ts +19 -0
- package/dist/node/NodeRegistry.d.ts.map +1 -0
- package/dist/node/NodeRegistry.js +65 -0
- package/dist/node/NodeRegistry.js.map +1 -0
- package/dist/node/OutputNode.d.ts +23 -0
- package/dist/node/OutputNode.d.ts.map +1 -0
- package/dist/node/OutputNode.js +62 -0
- package/dist/node/OutputNode.js.map +1 -0
- package/dist/node/ToolNode.d.ts +12 -0
- package/dist/node/ToolNode.d.ts.map +1 -0
- package/dist/node/ToolNode.js +18 -0
- package/dist/node/ToolNode.js.map +1 -0
- package/dist/node/TriggerNode.d.ts +67 -0
- package/dist/node/TriggerNode.d.ts.map +1 -0
- package/dist/node/TriggerNode.js +172 -0
- package/dist/node/TriggerNode.js.map +1 -0
- package/dist/node/constants.d.ts +16 -0
- package/dist/node/constants.d.ts.map +1 -0
- package/dist/node/constants.js +18 -0
- package/dist/node/constants.js.map +1 -0
- package/dist/node/index.d.ts +12 -0
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.js +9 -0
- package/dist/node/index.js.map +1 -0
- package/dist/node/methods.d.ts +73 -0
- package/dist/node/methods.d.ts.map +1 -0
- package/dist/node/methods.js +261 -0
- package/dist/node/methods.js.map +1 -0
- package/dist/node/serialization.d.ts +25 -0
- package/dist/node/serialization.d.ts.map +1 -0
- package/dist/node/serialization.js +525 -0
- package/dist/node/serialization.js.map +1 -0
- package/dist/parameter/OutputParameter.d.ts +69 -0
- package/dist/parameter/OutputParameter.d.ts.map +1 -0
- package/dist/parameter/OutputParameter.js +6 -0
- package/dist/parameter/OutputParameter.js.map +1 -0
- package/dist/parameter/Parameter.d.ts +152 -0
- package/dist/parameter/Parameter.d.ts.map +1 -0
- package/dist/parameter/Parameter.js +86 -0
- package/dist/parameter/Parameter.js.map +1 -0
- package/dist/parameter/index.d.ts +5 -0
- package/dist/parameter/index.d.ts.map +1 -0
- package/dist/parameter/index.js +3 -0
- package/dist/parameter/index.js.map +1 -0
- package/dist/variable/Variable.d.ts +25 -0
- package/dist/variable/Variable.d.ts.map +1 -0
- package/dist/variable/Variable.js +2 -0
- package/dist/variable/Variable.js.map +1 -0
- package/dist/variable/index.d.ts +3 -0
- package/dist/variable/index.d.ts.map +1 -0
- package/dist/variable/index.js +5 -0
- package/dist/variable/index.js.map +1 -0
- package/dist/variable/operations.d.ts +37 -0
- package/dist/variable/operations.d.ts.map +1 -0
- package/dist/variable/operations.js +88 -0
- package/dist/variable/operations.js.map +1 -0
- package/dist/workflow/Workflow.d.ts +38 -0
- package/dist/workflow/Workflow.d.ts.map +1 -0
- package/dist/workflow/Workflow.js +8 -0
- package/dist/workflow/Workflow.js.map +1 -0
- package/dist/workflow/index.d.ts +4 -0
- package/dist/workflow/index.d.ts.map +1 -0
- package/dist/workflow/index.js +3 -0
- package/dist/workflow/index.js.map +1 -0
- package/dist/workflow/serialization.d.ts +43 -0
- package/dist/workflow/serialization.d.ts.map +1 -0
- package/dist/workflow/serialization.js +215 -0
- package/dist/workflow/serialization.js.map +1 -0
- package/package.json +105 -0
- package/src/api/index.ts +11 -0
- package/src/api/workflow.ts +607 -0
- package/src/channel/Channel.ts +11 -0
- package/src/channel/ChannelDefinition.ts +76 -0
- package/src/channel/index.ts +6 -0
- package/src/channel/serialization.ts +68 -0
- package/src/deploy/index.ts +1 -0
- package/src/deploy/requirements.test.ts +61 -0
- package/src/deploy/requirements.ts +41 -0
- package/src/diagnostics/__fixtures__/diagnosticFixtures.ts +158 -0
- package/src/diagnostics/diagnostics.test.ts +878 -0
- package/src/diagnostics/diagnostics.ts +936 -0
- package/src/diagnostics/index.ts +11 -0
- package/src/edge/Edge.ts +23 -0
- package/src/edge/EdgeDefinition.ts +45 -0
- package/src/edge/EdgeType.ts +19 -0
- package/src/edge/index.ts +8 -0
- package/src/edge/serialization.ts +83 -0
- package/src/expression/index.ts +4 -0
- package/src/expression/parser.ts +362 -0
- package/src/expression/types.ts +30 -0
- package/src/function/FunctionDeclaration.ts +54 -0
- package/src/function/index.ts +3 -0
- package/src/function/serialization.ts +40 -0
- package/src/globals.d.ts +9 -0
- package/src/id/index.ts +8 -0
- package/src/index.ts +22 -0
- package/src/memory/Memory.ts +15 -0
- package/src/memory/MemoryDefinition.ts +16 -0
- package/src/memory/MemoryFileDefinition.ts +37 -0
- package/src/memory/MemoryRegistry.ts +35 -0
- package/src/memory/VectorDatabaseDefinition.ts +21 -0
- package/src/memory/index.ts +8 -0
- package/src/memory/serialization.ts +47 -0
- package/src/migration/index.ts +4 -0
- package/src/migration/migrate.test.ts +44 -0
- package/src/migration/migrate.ts +58 -0
- package/src/migration/migrations.ts +24 -0
- package/src/migration/version.ts +9 -0
- package/src/model/LLMModelDefinition.ts +12 -0
- package/src/model/Model.ts +39 -0
- package/src/model/ModelDefinition.ts +15 -0
- package/src/model/ModelRegistry.ts +33 -0
- package/src/model/index.ts +7 -0
- package/src/model/serialization.ts +30 -0
- package/src/node/AgentNode.ts +82 -0
- package/src/node/DataNode.ts +41 -0
- package/src/node/FunctionNode.ts +76 -0
- package/src/node/InputNode.ts +185 -0
- package/src/node/LogicNode.ts +33 -0
- package/src/node/MqttNode.ts +127 -0
- package/src/node/Node.ts +61 -0
- package/src/node/NodeDefinition.ts +37 -0
- package/src/node/NodeRegistry.ts +85 -0
- package/src/node/OutputNode.ts +87 -0
- package/src/node/ToolNode.ts +32 -0
- package/src/node/TriggerNode.ts +272 -0
- package/src/node/constants.ts +16 -0
- package/src/node/index.ts +26 -0
- package/src/node/methods.ts +278 -0
- package/src/node/serialization.ts +544 -0
- package/src/parameter/OutputParameter.ts +68 -0
- package/src/parameter/Parameter.ts +243 -0
- package/src/parameter/index.ts +33 -0
- package/src/variable/Variable.ts +10 -0
- package/src/variable/index.ts +16 -0
- package/src/variable/operations.ts +106 -0
- package/src/workflow/Workflow.ts +41 -0
- package/src/workflow/index.ts +3 -0
- package/src/workflow/serialization.test.ts +240 -0
- package/src/workflow/serialization.ts +242 -0
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import type { Expression, Reference } from "../api";
|
|
2
|
+
import type { ChannelType } from "../channel";
|
|
3
|
+
import type { MemoryType } from "../memory";
|
|
4
|
+
import type { ModelType, ModelCapability } from "../model";
|
|
5
|
+
import { refToLookupKey } from "../variable";
|
|
6
|
+
import type { Schemas } from "../api";
|
|
7
|
+
|
|
8
|
+
export type DataType = Schemas["DataType"];
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A field that is either a static value of T, or a function that derives T
|
|
12
|
+
* from the owning node's current arguments. Scope is strictly args-only —
|
|
13
|
+
* no access to variables, IO labels, or other canvas state. For wider
|
|
14
|
+
* context, use a purpose-named accessor (e.g. resolveExpressionType).
|
|
15
|
+
*/
|
|
16
|
+
export type FromArgs<T> = T | ((args: Record<string, unknown>) => T);
|
|
17
|
+
|
|
18
|
+
/** Unwrap a FromArgs value against the current node arguments. */
|
|
19
|
+
export function unwrapFromArgs<T>(value: FromArgs<T>, args: Record<string, unknown>): T {
|
|
20
|
+
return typeof value === "function" ? (value as (args: Record<string, unknown>) => T)(args) : value;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// ============================================================================
|
|
24
|
+
// Parameter definitions
|
|
25
|
+
// ============================================================================
|
|
26
|
+
|
|
27
|
+
export interface ParameterBase {
|
|
28
|
+
id: string;
|
|
29
|
+
label: string;
|
|
30
|
+
description: string;
|
|
31
|
+
optional?: boolean;
|
|
32
|
+
/** Parameter is only active (visible, validated, serialized) when all rules are met. */
|
|
33
|
+
activationRules?: ActivationRule[];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface BasicParam {
|
|
37
|
+
type: "int" | "float" | "time";
|
|
38
|
+
default?: number | string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface StringParam {
|
|
42
|
+
type: "string";
|
|
43
|
+
multiline?: boolean;
|
|
44
|
+
default?: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface BoolParam {
|
|
48
|
+
type: "bool";
|
|
49
|
+
default: boolean;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface WeekdaysParam {
|
|
53
|
+
type: "weekdays";
|
|
54
|
+
default: string[];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface SelectionParam {
|
|
58
|
+
type: "selection";
|
|
59
|
+
options: Array<{ value: string; label: string }>;
|
|
60
|
+
default?: string;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface ExpressionParam {
|
|
64
|
+
type: "expression";
|
|
65
|
+
/** Type can be dynamic (static value or args-only lambda). */
|
|
66
|
+
expressionType: FromArgs<DataType>;
|
|
67
|
+
/**
|
|
68
|
+
* Escape hatch for the variableSelect case: when set, points to the id of a sibling
|
|
69
|
+
* variableSelect parameter. If that parameter holds a live Reference, the expressionType
|
|
70
|
+
* is taken from the referenced variable. Falls back to `expressionType` otherwise.
|
|
71
|
+
*/
|
|
72
|
+
fromReference?: string;
|
|
73
|
+
/**
|
|
74
|
+
* Required: An expression always has a value object never an unset state.
|
|
75
|
+
*/
|
|
76
|
+
default: Expression;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Reference-select parameters: pick an external entity by id. No `default`.
|
|
80
|
+
|
|
81
|
+
export interface VariableSelectParam {
|
|
82
|
+
type: "variableSelect";
|
|
83
|
+
default?: never;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Model reference parameter — selects a model id from the static catalog (props)
|
|
87
|
+
// unioned with declared custom models, filtered by model type and capability.
|
|
88
|
+
export interface ModelSelectParam {
|
|
89
|
+
type: "modelSelect";
|
|
90
|
+
/** Model types this slot accepts (e.g. ["LLMModel"]). Static list or args-derived lambda. */
|
|
91
|
+
modelType: FromArgs<ModelType[]>;
|
|
92
|
+
/** Optional capability filter (e.g. ["chat"]) applied to catalog and declared models alike. */
|
|
93
|
+
capabilities?: FromArgs<ModelCapability[]>;
|
|
94
|
+
default?: never;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export interface ChannelSelectParam {
|
|
98
|
+
type: "channelSelect";
|
|
99
|
+
/** Channel types this slot accepts. Static list or args-derived lambda. */
|
|
100
|
+
channelType: FromArgs<ChannelType[]>;
|
|
101
|
+
default?: never;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export interface MemorySelectParam {
|
|
105
|
+
type: "memorySelect";
|
|
106
|
+
/** Memory types this slot accepts (e.g. ["VectorDatabase"]). Static list or args-derived lambda. */
|
|
107
|
+
memoryType: FromArgs<MemoryType[]>;
|
|
108
|
+
default?: never;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* List parameter that binds an agent node to project-declared memory files,
|
|
113
|
+
* each with an access mode (`r` = read-only, `rw` = read + write). The editor
|
|
114
|
+
* holds the array directly; the API schema (`MemoryRef[]`) round-trips 1:1.
|
|
115
|
+
*
|
|
116
|
+
* `default` is required: a list param is always a
|
|
117
|
+
* concrete array, never unset — declare `default: []` for "starts empty".
|
|
118
|
+
*/
|
|
119
|
+
export interface MemoryRefsParam {
|
|
120
|
+
type: "memory-refs";
|
|
121
|
+
default: Schemas["MemoryRef"][];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Union of all reference-select parameter variants, used for type guards. */
|
|
125
|
+
export type ReferenceSelectParam = VariableSelectParam | ChannelSelectParam | MemorySelectParam | ModelSelectParam;
|
|
126
|
+
|
|
127
|
+
export function isReferenceSelectParam(param: Parameter): param is ParameterBase & ReferenceSelectParam {
|
|
128
|
+
return param.type === "variableSelect" || param.type === "channelSelect" || param.type === "memorySelect" || param.type === "modelSelect";
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export type Parameter =
|
|
132
|
+
| (ParameterBase & BasicParam)
|
|
133
|
+
| (ParameterBase & VariableSelectParam)
|
|
134
|
+
| (ParameterBase & StringParam)
|
|
135
|
+
| (ParameterBase & BoolParam)
|
|
136
|
+
| (ParameterBase & WeekdaysParam)
|
|
137
|
+
| (ParameterBase & SelectionParam)
|
|
138
|
+
| (ParameterBase & MemorySelectParam)
|
|
139
|
+
| (ParameterBase & ModelSelectParam)
|
|
140
|
+
| (ParameterBase & ExpressionParam)
|
|
141
|
+
| (ParameterBase & ChannelSelectParam)
|
|
142
|
+
| (ParameterBase & MemoryRefsParam);
|
|
143
|
+
|
|
144
|
+
// ============================================================================
|
|
145
|
+
// Parameter activation rules
|
|
146
|
+
// ============================================================================
|
|
147
|
+
|
|
148
|
+
/** Typed union of rules that control whether a parameter is active (visible, validated, serialized). */
|
|
149
|
+
export type ActivationRule =
|
|
150
|
+
| { type: "parameterIn"; parameterId: string; values: unknown[] }
|
|
151
|
+
| { type: "isControlFlow" }
|
|
152
|
+
| { type: "isToolInput" };
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Evaluate whether a parameter is active (visible, validated, serialized) given current context.
|
|
156
|
+
* All rules must be satisfied (AND logic). Undefined or empty array = always active.
|
|
157
|
+
*/
|
|
158
|
+
export function isParameterActive(param: Parameter, parameterValues: Record<string, unknown>, isToolInput: boolean): boolean {
|
|
159
|
+
if (!param.activationRules?.length) return true;
|
|
160
|
+
return param.activationRules.every((cond) => {
|
|
161
|
+
switch (cond.type) {
|
|
162
|
+
case "isControlFlow":
|
|
163
|
+
return !isToolInput;
|
|
164
|
+
case "isToolInput":
|
|
165
|
+
return isToolInput;
|
|
166
|
+
case "parameterIn":
|
|
167
|
+
return cond.values.includes(parameterValues[cond.parameterId]);
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Whether a scalar argument value counts as "unset" for api purposes:
|
|
174
|
+
* `undefined`, `null`, or `""`. Deliberately NOT `false`/`0` (valid values) nor
|
|
175
|
+
* `[]` — an empty list is a real value, since list params are always
|
|
176
|
+
* materialized to a concrete array. Shared by required-param diagnostics and
|
|
177
|
+
* {@link pruneArguments} so "unset" has exactly one definition.
|
|
178
|
+
*/
|
|
179
|
+
export function isEmpty(value: unknown): boolean {
|
|
180
|
+
return value === undefined || value === null || value === "";
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Prune arguments that must not appear in the api, at the domain→api boundary.
|
|
185
|
+
* Mutates `args` in place. Two reasons an arg is dropped:
|
|
186
|
+
* 1. inactive — its parameter's activation rules aren't met for this context.
|
|
187
|
+
* 2. the parameter {@link isEmpty}.
|
|
188
|
+
*/
|
|
189
|
+
export function pruneArguments(args: Record<string, unknown>, parameters: readonly Parameter[], isToolInput = false): void {
|
|
190
|
+
for (const param of parameters) {
|
|
191
|
+
const inactive = !!param.activationRules?.length && !isParameterActive(param, args, isToolInput);
|
|
192
|
+
if (inactive || isEmpty(args[param.id])) {
|
|
193
|
+
delete args[param.id];
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// ============================================================================
|
|
199
|
+
// Parameter resolvers
|
|
200
|
+
// ============================================================================
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Resolve an ExpressionParam's expected dataType. Handles the `fromReference` escape hatch
|
|
204
|
+
* (type taken from a live variableSelect sibling parameter) and falls back to the
|
|
205
|
+
* declared FromArgs<DataType>.
|
|
206
|
+
*/
|
|
207
|
+
export function resolveExpressionType(
|
|
208
|
+
param: ExpressionParam,
|
|
209
|
+
args: Record<string, unknown>,
|
|
210
|
+
variables: Record<string, { dataType: DataType }>,
|
|
211
|
+
): DataType {
|
|
212
|
+
if (param.fromReference) {
|
|
213
|
+
const ref = args[param.fromReference] as Reference | undefined;
|
|
214
|
+
if (ref?.varId) {
|
|
215
|
+
const v = variables[refToLookupKey(ref)];
|
|
216
|
+
if (v) return v.dataType;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return unwrapFromArgs(param.expressionType, args);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** Resolve a capability filter (ModelSelectParam) for the current node arguments. */
|
|
223
|
+
export function resolveCapabilities(
|
|
224
|
+
param: { capabilities?: FromArgs<ModelCapability[]> },
|
|
225
|
+
args: Record<string, unknown>,
|
|
226
|
+
): ModelCapability[] | undefined {
|
|
227
|
+
return param.capabilities === undefined ? undefined : unwrapFromArgs(param.capabilities, args);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** Resolve the allowed channel types for a ChannelSelectParam. */
|
|
231
|
+
export function resolveChannelTypes(param: ChannelSelectParam, args: Record<string, unknown>): ChannelType[] {
|
|
232
|
+
return unwrapFromArgs(param.channelType, args);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** Resolve the allowed memory types for a MemorySelectParam. */
|
|
236
|
+
export function resolveMemoryTypes(param: MemorySelectParam, args: Record<string, unknown>): MemoryType[] {
|
|
237
|
+
return unwrapFromArgs(param.memoryType, args);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** Resolve the allowed model types for a ModelSelectParam. */
|
|
241
|
+
export function resolveModelTypes(param: ModelSelectParam, args: Record<string, unknown>): ModelType[] {
|
|
242
|
+
return unwrapFromArgs(param.modelType, args);
|
|
243
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export type {
|
|
2
|
+
DataType,
|
|
3
|
+
FromArgs,
|
|
4
|
+
ParameterBase,
|
|
5
|
+
BasicParam,
|
|
6
|
+
StringParam,
|
|
7
|
+
BoolParam,
|
|
8
|
+
WeekdaysParam,
|
|
9
|
+
SelectionParam,
|
|
10
|
+
ExpressionParam,
|
|
11
|
+
VariableSelectParam,
|
|
12
|
+
ModelSelectParam,
|
|
13
|
+
ChannelSelectParam,
|
|
14
|
+
MemorySelectParam,
|
|
15
|
+
MemoryRefsParam,
|
|
16
|
+
ReferenceSelectParam,
|
|
17
|
+
Parameter,
|
|
18
|
+
ActivationRule,
|
|
19
|
+
} from "./Parameter";
|
|
20
|
+
export {
|
|
21
|
+
unwrapFromArgs,
|
|
22
|
+
isReferenceSelectParam,
|
|
23
|
+
isParameterActive,
|
|
24
|
+
isEmpty,
|
|
25
|
+
pruneArguments,
|
|
26
|
+
resolveExpressionType,
|
|
27
|
+
resolveCapabilities,
|
|
28
|
+
resolveChannelTypes,
|
|
29
|
+
resolveMemoryTypes,
|
|
30
|
+
resolveModelTypes,
|
|
31
|
+
} from "./Parameter";
|
|
32
|
+
export type { OutputBinding, OutputDeclaration, StaticOutput, OutputList, OutputParameter } from "./OutputParameter";
|
|
33
|
+
export { resolveStaticOutputDataType } from "./OutputParameter";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Schemas } from "../api";
|
|
2
|
+
import type { DataType } from "../api";
|
|
3
|
+
|
|
4
|
+
export type ApiVariable = Schemas["Variable"]; // Differentiate from domain variable type
|
|
5
|
+
|
|
6
|
+
export type NodeOutputVariable = { kind: "node"; nodeId: string; outputId: string; name: string; dataType: DataType };
|
|
7
|
+
export type DeclaredVariable = { kind: "declared"; uid: string; name: string; dataType: DataType; initialValue?: unknown };
|
|
8
|
+
export type FunctionArgVariable = { kind: "fnarg"; uid: string; name: string; dataType: DataType };
|
|
9
|
+
|
|
10
|
+
export type Variable = NodeOutputVariable | DeclaredVariable | FunctionArgVariable;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Public surface of the variable module. The discriminated-union types live in
|
|
2
|
+
// ./Variable; the key/lookup/uid helpers and availability computation live in
|
|
3
|
+
// ./operations. This file is a barrel only. Mirrors channel/memory/model.
|
|
4
|
+
|
|
5
|
+
export type { ApiVariable, NodeOutputVariable, DeclaredVariable, FunctionArgVariable, Variable } from "./Variable";
|
|
6
|
+
export {
|
|
7
|
+
varKey,
|
|
8
|
+
declaredVarKey,
|
|
9
|
+
fnargKey,
|
|
10
|
+
nodeOutputVarKey,
|
|
11
|
+
refToLookupKey,
|
|
12
|
+
ensureUid,
|
|
13
|
+
ensureUids,
|
|
14
|
+
paramKey,
|
|
15
|
+
computeAvailableVariables,
|
|
16
|
+
} from "./operations";
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { NodeOutput } from "../node";
|
|
2
|
+
import type { Reference } from "../api";
|
|
3
|
+
import type { ApiVariable } from "./Variable";
|
|
4
|
+
import { isToolFlow, type EdgeType, type Edge } from "../edge";
|
|
5
|
+
import { generateId } from "../id";
|
|
6
|
+
import type { Variable } from "./Variable";
|
|
7
|
+
|
|
8
|
+
// ============================================================================
|
|
9
|
+
// Key Helpers
|
|
10
|
+
// ============================================================================
|
|
11
|
+
|
|
12
|
+
/** Compute the canonical map key for any CanvasVariable (or AvailableVariable). */
|
|
13
|
+
export function varKey(v: Variable): string {
|
|
14
|
+
switch (v.kind) {
|
|
15
|
+
case "node":
|
|
16
|
+
return `${v.nodeId}:${v.outputId}`;
|
|
17
|
+
case "declared":
|
|
18
|
+
return `declared:${v.uid}`;
|
|
19
|
+
case "fnarg":
|
|
20
|
+
return `fnarg:${v.uid}`;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Key for a declared variable: `declared:<uid>` */
|
|
25
|
+
export function declaredVarKey(uid: string): string {
|
|
26
|
+
return `declared:${uid}`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Key for a function argument variable: `fnarg:<uid>` */
|
|
30
|
+
export function fnargKey(uid: string): string {
|
|
31
|
+
return `fnarg:${uid}`;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Key for a node output variable: `<nodeId>:<outputId>` */
|
|
35
|
+
export function nodeOutputVarKey(nodeId: string, outputId: string): string {
|
|
36
|
+
return `${nodeId}:${outputId}`;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// ============================================================================
|
|
40
|
+
// Reference → Lookup Key
|
|
41
|
+
// ============================================================================
|
|
42
|
+
|
|
43
|
+
/** Convert a Reference to the canonical lookup key used in the variables record. */
|
|
44
|
+
export function refToLookupKey(ref: Reference): string {
|
|
45
|
+
switch (ref.srcId) {
|
|
46
|
+
case "declared":
|
|
47
|
+
return declaredVarKey(ref.varId);
|
|
48
|
+
case "fnarg":
|
|
49
|
+
return fnargKey(ref.varId);
|
|
50
|
+
default:
|
|
51
|
+
return nodeOutputVarKey(ref.srcId, ref.varId);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// ============================================================================
|
|
56
|
+
// Variable UID Helpers for dynamic variable definitions (e.g. Agent output definitions)
|
|
57
|
+
// ============================================================================
|
|
58
|
+
|
|
59
|
+
/** Create a Variable from a NodeOutput by assigning a uid. If it already has a uid, return as-is. */
|
|
60
|
+
export function ensureUid(v: NodeOutput | ApiVariable): ApiVariable {
|
|
61
|
+
if ("uid" in v && v.uid) return v as ApiVariable;
|
|
62
|
+
return { uid: generateId(), name: v.name, dataType: v.dataType };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Ensure every NodeOutput/Variable in an array has a uid. */
|
|
66
|
+
export function ensureUids(vars: (NodeOutput | ApiVariable)[]): ApiVariable[] {
|
|
67
|
+
return vars.map(ensureUid);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Get the binding key for a Variable — always its uid. */
|
|
71
|
+
export function paramKey(p: ApiVariable): string {
|
|
72
|
+
return p.uid;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Pure function that computes available variables for a canvas from its own
|
|
77
|
+
* variables record + edges. Function canvases are self-contained: only their
|
|
78
|
+
* own declared variables, node outputs, and function arguments are visible;
|
|
79
|
+
* main-canvas state is never merged in.
|
|
80
|
+
*
|
|
81
|
+
* Only `type`/`target` are read, but the param takes the shared structural
|
|
82
|
+
* {@link Edge} so there's one edge shape across core — workflow-builder
|
|
83
|
+
* still passes its React Flow `Edge[]` without an adapter, and core stays free
|
|
84
|
+
* of `@xyflow/react`.
|
|
85
|
+
*/
|
|
86
|
+
export function computeAvailableVariables(
|
|
87
|
+
variables: Record<string, Variable>,
|
|
88
|
+
canvasEdges: readonly Edge[],
|
|
89
|
+
): { list: Variable[]; lookup: Record<string, Variable> } {
|
|
90
|
+
const list: Variable[] = [];
|
|
91
|
+
const lookup: Record<string, Variable> = {};
|
|
92
|
+
|
|
93
|
+
// Node outputs routed to a tool port are scoped to the agent — exclude them.
|
|
94
|
+
const toolNodeIds = new Set<string>();
|
|
95
|
+
for (const edge of canvasEdges) {
|
|
96
|
+
if (isToolFlow(edge.type as EdgeType)) toolNodeIds.add(edge.target);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
for (const [key, variable] of Object.entries(variables)) {
|
|
100
|
+
if (variable.kind === "node" && toolNodeIds.has(variable.nodeId)) continue;
|
|
101
|
+
list.push(variable);
|
|
102
|
+
lookup[key] = variable;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return { list, lookup };
|
|
106
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Channel } from "../channel";
|
|
2
|
+
import type { Memory } from "../memory";
|
|
3
|
+
import type { Model } from "../model";
|
|
4
|
+
import type { Node } from "../node";
|
|
5
|
+
import type { FunctionDeclaration } from "../function";
|
|
6
|
+
import type { Edge } from "../edge";
|
|
7
|
+
import type { Variable } from "../variable";
|
|
8
|
+
import type { Schemas } from "../api";
|
|
9
|
+
|
|
10
|
+
export type ApiWorkflow = Schemas["Workflow"];
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The id of the project's main canvas. All other canvas ids identify function
|
|
14
|
+
* definitions. Lives here next to {@link Workflow} (which keys canvases
|
|
15
|
+
* by this value) so the headless validator can reason about canvas scope
|
|
16
|
+
* without depending on a UI store.
|
|
17
|
+
*/
|
|
18
|
+
export const MAIN_CANVAS_ID = "main" as const;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* In-memory domain state for a workflow, which the headless validator consumes.
|
|
22
|
+
* NOT a persistence format, NOT the format the editor uses internally (Zustand stores).
|
|
23
|
+
* This format is used as intermediary when importing/exporting to api format and to run validation
|
|
24
|
+
*/
|
|
25
|
+
export interface Workflow {
|
|
26
|
+
canvases: Record<string, Canvas>;
|
|
27
|
+
functions: Record<string, FunctionDeclaration>;
|
|
28
|
+
channels: Record<string, Channel>;
|
|
29
|
+
memory: Record<string, Memory>;
|
|
30
|
+
models: Record<string, Model>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* One canvas's worth of in-memory domain state — the body of either the main canvas
|
|
35
|
+
* or a function.
|
|
36
|
+
*/
|
|
37
|
+
export interface Canvas {
|
|
38
|
+
nodes: Node[];
|
|
39
|
+
edges: Edge[];
|
|
40
|
+
variables: Record<string, Variable>;
|
|
41
|
+
}
|