@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,76 @@
|
|
|
1
|
+
import type { Parameter } from "../parameter";
|
|
2
|
+
import { ALL_CHANNEL_TYPES } from "./Channel";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Single union definition for all Channel variants — deliberately NOT the
|
|
6
|
+
* per-type registry pattern used by Node/Memory/Model (`*Definition` +
|
|
7
|
+
* `*Registry`, one definition object per type).
|
|
8
|
+
*
|
|
9
|
+
* The reason is in-place `type` switching that preserves shared parameter state.
|
|
10
|
+
* Because `type` is a parameter and all variants share one `arguments` bag,
|
|
11
|
+
* changing a channel's type keeps the same instance (id, label) and retains any
|
|
12
|
+
* entered values that are still valid for the new type: the parameter +
|
|
13
|
+
* `activationRules` machinery just re-gates which fields show, and `serialize`
|
|
14
|
+
* (via `pruneArguments`) drops the now-inactive ones. A per-type registry
|
|
15
|
+
* would make each variant its own definition, so switching type would mean
|
|
16
|
+
* delete-and-recreate — losing id/label and every shared value the user entered.
|
|
17
|
+
* (It also lets channels add from one "Add Channel" button with type as a field,
|
|
18
|
+
* rather than an add-button per type. Node/Memory/Model instead treat `type` as
|
|
19
|
+
* an immutable registry key chosen at creation.)
|
|
20
|
+
*
|
|
21
|
+
* The same could be achieved with a UI-layer "type selector" over a
|
|
22
|
+
* ChannelRegistry; this union trades cross-family consistency for that
|
|
23
|
+
* shared-state-preserving switch.
|
|
24
|
+
*/
|
|
25
|
+
export interface ChannelDefinition {
|
|
26
|
+
parameters: Parameter[];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const CHANNEL_DEFINITION: ChannelDefinition = {
|
|
30
|
+
parameters: [
|
|
31
|
+
{
|
|
32
|
+
id: "type",
|
|
33
|
+
label: "Type",
|
|
34
|
+
description: "Channel type",
|
|
35
|
+
type: "selection",
|
|
36
|
+
default: "GPIOIN",
|
|
37
|
+
options: ALL_CHANNEL_TYPES.map((t) => ({ value: t, label: t })),
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
id: "bias",
|
|
41
|
+
label: "Bias",
|
|
42
|
+
description: "Pin bias configuration",
|
|
43
|
+
type: "selection",
|
|
44
|
+
default: "none",
|
|
45
|
+
options: [
|
|
46
|
+
{ value: "none", label: "None" },
|
|
47
|
+
{ value: "pullup", label: "Pull-up" },
|
|
48
|
+
{ value: "pulldown", label: "Pull-down" },
|
|
49
|
+
],
|
|
50
|
+
activationRules: [{ type: "parameterIn", parameterId: "type", values: ["GPIOIN"] }],
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
id: "debounceMs",
|
|
54
|
+
label: "Debounce (ms)",
|
|
55
|
+
description: "Debounce window in milliseconds",
|
|
56
|
+
type: "int",
|
|
57
|
+
default: 50,
|
|
58
|
+
activationRules: [{ type: "parameterIn", parameterId: "type", values: ["GPIOIN"] }],
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
id: "frequency",
|
|
62
|
+
label: "Frequency (Hz)",
|
|
63
|
+
description: "PWM frequency in Hz",
|
|
64
|
+
type: "int",
|
|
65
|
+
default: 1000,
|
|
66
|
+
activationRules: [{ type: "parameterIn", parameterId: "type", values: ["PWM"] }],
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
id: "topic",
|
|
70
|
+
label: "Topic",
|
|
71
|
+
description: "MQTT topic this channel publishes to / subscribes on (e.g. sensors/temperature)",
|
|
72
|
+
type: "string",
|
|
73
|
+
activationRules: [{ type: "parameterIn", parameterId: "type", values: ["MQTT"] }],
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type { ChannelType, Channel } from "./Channel";
|
|
2
|
+
export { ALL_CHANNEL_TYPES } from "./Channel";
|
|
3
|
+
export type { ChannelDefinition } from "./ChannelDefinition";
|
|
4
|
+
export { CHANNEL_DEFINITION } from "./ChannelDefinition";
|
|
5
|
+
export { serialize, deserialize } from "./serialization";
|
|
6
|
+
export type { ApiChannel } from "./serialization";
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { Schemas } from "../api";
|
|
2
|
+
import { pruneArguments } from "../parameter";
|
|
3
|
+
import { CHANNEL_DEFINITION } from "./ChannelDefinition";
|
|
4
|
+
import type { Channel } from "./Channel";
|
|
5
|
+
|
|
6
|
+
export type ApiChannel = Schemas["Channel"];
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Serialize a domain Channel to the API discriminated-union shape.
|
|
10
|
+
*
|
|
11
|
+
* The domain store retains inactive parameters (non-destructive type switching),
|
|
12
|
+
* so this is the boundary that drops them. The `type` discriminator must be in
|
|
13
|
+
* the args record so `parameterIn` rules can evaluate — otherwise every gated
|
|
14
|
+
* field (bias/debounceMs/frequency) is stripped as "inactive". Physical
|
|
15
|
+
* addressing (GPIO line, ADC/PWM/DAC channel) is not here — it's a deploy
|
|
16
|
+
* binding, not workflow state.
|
|
17
|
+
*/
|
|
18
|
+
export function serialize(ch: Channel): ApiChannel {
|
|
19
|
+
const { id, label, type } = ch;
|
|
20
|
+
const args: Record<string, unknown> = { ...ch.arguments, type };
|
|
21
|
+
pruneArguments(args, CHANNEL_DEFINITION.parameters);
|
|
22
|
+
switch (type) {
|
|
23
|
+
case "GPIOIN":
|
|
24
|
+
return {
|
|
25
|
+
type,
|
|
26
|
+
id,
|
|
27
|
+
label,
|
|
28
|
+
bias: args.bias as Schemas["GPIOINChannel"]["bias"],
|
|
29
|
+
debounceMs: args.debounceMs as number,
|
|
30
|
+
};
|
|
31
|
+
case "GPIOOUT":
|
|
32
|
+
return { type, id, label };
|
|
33
|
+
case "ADC":
|
|
34
|
+
return { type, id, label };
|
|
35
|
+
case "PWM":
|
|
36
|
+
return { type, id, label, frequency: args.frequency as number };
|
|
37
|
+
case "DAC":
|
|
38
|
+
return { type, id, label };
|
|
39
|
+
case "UART":
|
|
40
|
+
return { type, id, label };
|
|
41
|
+
case "MQTT":
|
|
42
|
+
return { type, id, label, topic: args.topic as string };
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Convert an API Channel into a domain Channel. */
|
|
47
|
+
export function deserialize(api: ApiChannel): Channel {
|
|
48
|
+
const { id, label, type } = api;
|
|
49
|
+
const args: Record<string, unknown> = {};
|
|
50
|
+
switch (type) {
|
|
51
|
+
case "GPIOIN":
|
|
52
|
+
args.bias = api.bias;
|
|
53
|
+
args.debounceMs = api.debounceMs;
|
|
54
|
+
break;
|
|
55
|
+
case "PWM":
|
|
56
|
+
args.frequency = api.frequency;
|
|
57
|
+
break;
|
|
58
|
+
case "MQTT":
|
|
59
|
+
args.topic = api.topic;
|
|
60
|
+
break;
|
|
61
|
+
case "GPIOOUT":
|
|
62
|
+
case "ADC":
|
|
63
|
+
case "DAC":
|
|
64
|
+
case "UART":
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
return { id, label, type, arguments: args };
|
|
68
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getReferencedCatalogModelIds } from "./requirements";
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { getReferencedCatalogModelIds } from "./requirements";
|
|
3
|
+
import { MAIN_CANVAS_ID, type Workflow, type Canvas } from "../workflow";
|
|
4
|
+
import type { Node } from "../node";
|
|
5
|
+
import type { Model } from "../model";
|
|
6
|
+
|
|
7
|
+
// Minimal Agent node referencing `model`. Cast through the union — only id/type/
|
|
8
|
+
// arguments.model matter to the walk.
|
|
9
|
+
function agent(id: string, model: string): Node {
|
|
10
|
+
return {
|
|
11
|
+
id,
|
|
12
|
+
type: "Agent",
|
|
13
|
+
position: { x: 0, y: 0 },
|
|
14
|
+
arguments: {
|
|
15
|
+
name: id,
|
|
16
|
+
model,
|
|
17
|
+
instructions: "",
|
|
18
|
+
outputDeclarations: [],
|
|
19
|
+
memoryRefs: [],
|
|
20
|
+
answer: { active: true, mode: "emit", name: "answer" },
|
|
21
|
+
},
|
|
22
|
+
} as Node;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function canvas(nodes: Node[]): Canvas {
|
|
26
|
+
return { nodes, edges: [], variables: {} };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const customModel: Model = { id: "custom-llm", label: "Custom", type: "LLMModel", arguments: {} };
|
|
30
|
+
|
|
31
|
+
function workflow(canvases: Workflow["canvases"], models: Record<string, Model> = {}): Workflow {
|
|
32
|
+
return { canvases, functions: {}, channels: {}, memory: {}, models };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
describe("getReferencedCatalogModelIds", () => {
|
|
36
|
+
it("returns catalog ids (referenced but not declared), excluding declared customs", () => {
|
|
37
|
+
const wf = workflow(
|
|
38
|
+
{ [MAIN_CANVAS_ID]: canvas([agent("n1", "claude-opus-4-7"), agent("n2", "custom-llm")]) },
|
|
39
|
+
{ "custom-llm": customModel },
|
|
40
|
+
);
|
|
41
|
+
expect(getReferencedCatalogModelIds(wf)).toEqual(["claude-opus-4-7"]);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("ignores unset model references", () => {
|
|
45
|
+
const wf = workflow({ [MAIN_CANVAS_ID]: canvas([agent("n1", "")]) });
|
|
46
|
+
expect(getReferencedCatalogModelIds(wf)).toEqual([]);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("dedupes across nodes and walks every canvas (main + function bodies)", () => {
|
|
50
|
+
const wf = workflow({
|
|
51
|
+
[MAIN_CANVAS_ID]: canvas([agent("n1", "claude-opus-4-7"), agent("n2", "claude-opus-4-7")]),
|
|
52
|
+
fnBody: canvas([agent("n3", "gemini-2")]),
|
|
53
|
+
});
|
|
54
|
+
expect(getReferencedCatalogModelIds(wf).sort()).toEqual(["claude-opus-4-7", "gemini-2"]);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("returns nothing when every referenced model is declared", () => {
|
|
58
|
+
const wf = workflow({ [MAIN_CANVAS_ID]: canvas([agent("n1", "custom-llm")]) }, { "custom-llm": customModel });
|
|
59
|
+
expect(getReferencedCatalogModelIds(wf)).toEqual([]);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Workflow } from "../workflow";
|
|
2
|
+
import { NodeRegistry, isNodeUsedAsTool } from "../node";
|
|
3
|
+
import { isParameterActive } from "../parameter";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Model ids that nodes reference but the workflow does not declare in `models`.
|
|
7
|
+
* A `modelSelect` accepts exactly two sources — declared custom models and the
|
|
8
|
+
* static catalog — so any referenced id that isn't a declared model is a catalog
|
|
9
|
+
* model: it carries no declared config, yet still needs a provider/credential
|
|
10
|
+
* supplied at deploy.
|
|
11
|
+
*
|
|
12
|
+
* This is the one deploy demand the workflow's resource arrays can't express:
|
|
13
|
+
* channels/memory/declared-models are enumerable directly from
|
|
14
|
+
* `workflow.{channels,memory,models}`, but catalog model ids live only on the
|
|
15
|
+
* nodes that pick them — hence the walk. Spans every canvas (main + function
|
|
16
|
+
* bodies) and honors parameter activation, so a model behind an inactive
|
|
17
|
+
* `modelSelect` (pruned on serialize, never deployed) is not counted.
|
|
18
|
+
*/
|
|
19
|
+
export function getReferencedCatalogModelIds(workflow: Workflow): string[] {
|
|
20
|
+
const declaredModel = new Set(Object.keys(workflow.models));
|
|
21
|
+
const catalogIds = new Set<string>();
|
|
22
|
+
|
|
23
|
+
for (const canvas of Object.values(workflow.canvases)) {
|
|
24
|
+
for (const node of canvas.nodes) {
|
|
25
|
+
const def = NodeRegistry.getByType(node.type);
|
|
26
|
+
if (!def) continue;
|
|
27
|
+
const args = node.arguments as Record<string, unknown>;
|
|
28
|
+
const isToolInput = isNodeUsedAsTool(node.id, node, canvas.edges);
|
|
29
|
+
for (const param of def.parameters) {
|
|
30
|
+
if (param.type !== "modelSelect") continue;
|
|
31
|
+
if (!isParameterActive(param, args, isToolInput)) continue;
|
|
32
|
+
const id = args[param.id];
|
|
33
|
+
if (typeof id === "string" && id !== "" && !declaredModel.has(id)) {
|
|
34
|
+
catalogIds.add(id);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return [...catalogIds];
|
|
41
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import type { Edge } from "../../edge";
|
|
2
|
+
import type { NodeDefinition, NodeData } from "../../node";
|
|
3
|
+
import type { DataType, Expression, Reference } from "../../api";
|
|
4
|
+
import type { Channel } from "../../channel";
|
|
5
|
+
import type { Memory } from "../../memory";
|
|
6
|
+
import { NodeCategory } from "../../node";
|
|
7
|
+
import type { Variable, DeclaredVariable, NodeOutputVariable } from "../../variable";
|
|
8
|
+
import type { Diagnostic, DiagnosticCategory } from "../diagnostics";
|
|
9
|
+
|
|
10
|
+
// ============================================================================
|
|
11
|
+
// Variable builders
|
|
12
|
+
// ============================================================================
|
|
13
|
+
|
|
14
|
+
export function makeDeclaredVar(overrides: Partial<DeclaredVariable> = {}): Variable {
|
|
15
|
+
return {
|
|
16
|
+
kind: "declared",
|
|
17
|
+
uid: "v1",
|
|
18
|
+
name: "count",
|
|
19
|
+
dataType: "int" as DataType,
|
|
20
|
+
...overrides,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function makeNodeOutputVar(overrides: Partial<NodeOutputVariable> = {}): Variable {
|
|
25
|
+
return {
|
|
26
|
+
kind: "node",
|
|
27
|
+
nodeId: "n1",
|
|
28
|
+
outputId: "output",
|
|
29
|
+
name: "result",
|
|
30
|
+
dataType: "int" as DataType,
|
|
31
|
+
...overrides,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Build an `availableVariables` map from a list of `AvailableVariable` entries. */
|
|
36
|
+
export function makeAvailableVars(vars: Variable[]): Record<string, Variable> {
|
|
37
|
+
const map: Record<string, Variable> = {};
|
|
38
|
+
for (const v of vars) {
|
|
39
|
+
const key = v.kind === "declared" ? `declared:${v.uid}` : v.kind === "fnarg" ? `fnarg:${v.uid}` : `${v.nodeId}:${v.outputId}`;
|
|
40
|
+
map[key] = v;
|
|
41
|
+
}
|
|
42
|
+
return map;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// ============================================================================
|
|
46
|
+
// Expression / Reference builders
|
|
47
|
+
// ============================================================================
|
|
48
|
+
|
|
49
|
+
export function makeExpression(expression: string, dataType: DataType = "int", references: Reference[] = []): Expression {
|
|
50
|
+
return { expression, references, dataType };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function makeDeclaredRef(uid: string): Reference {
|
|
54
|
+
return { srcId: "declared", varId: uid };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// ============================================================================
|
|
58
|
+
// Edge builder
|
|
59
|
+
// ============================================================================
|
|
60
|
+
|
|
61
|
+
export function makeEdge(
|
|
62
|
+
id: string,
|
|
63
|
+
source: string,
|
|
64
|
+
sourceHandle: string,
|
|
65
|
+
target: string,
|
|
66
|
+
targetHandle: string,
|
|
67
|
+
overrides: Partial<Edge> = {},
|
|
68
|
+
): Edge {
|
|
69
|
+
return {
|
|
70
|
+
id,
|
|
71
|
+
source,
|
|
72
|
+
sourceHandle,
|
|
73
|
+
target,
|
|
74
|
+
targetHandle,
|
|
75
|
+
type: "control",
|
|
76
|
+
...overrides,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// ============================================================================
|
|
81
|
+
// Channel builders
|
|
82
|
+
// ============================================================================
|
|
83
|
+
|
|
84
|
+
export function makeChannel(overrides: Partial<Channel> = {}): Channel {
|
|
85
|
+
return {
|
|
86
|
+
id: "ch1",
|
|
87
|
+
label: "GPIO 4",
|
|
88
|
+
type: "GPIOIN",
|
|
89
|
+
arguments: {},
|
|
90
|
+
...overrides,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function makeChannels(channels: Channel[]): Record<string, Channel> {
|
|
95
|
+
const map: Record<string, Channel> = {};
|
|
96
|
+
for (const v of channels) map[v.id] = v;
|
|
97
|
+
return map;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// ============================================================================
|
|
101
|
+
// Memory builders
|
|
102
|
+
// ============================================================================
|
|
103
|
+
|
|
104
|
+
export function makeMemory(overrides: Partial<Memory> = {}): Memory {
|
|
105
|
+
return {
|
|
106
|
+
id: "mem1",
|
|
107
|
+
label: "memory1",
|
|
108
|
+
type: "MemoryFile",
|
|
109
|
+
arguments: {},
|
|
110
|
+
...overrides,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function makeMemories(memories: Memory[]): Record<string, Memory> {
|
|
115
|
+
const map: Record<string, Memory> = {};
|
|
116
|
+
for (const m of memories) map[m.id] = m;
|
|
117
|
+
return map;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// ============================================================================
|
|
121
|
+
// Node instance builder — untyped escape hatch
|
|
122
|
+
// ============================================================================
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Build a minimal NodeData. Tests assert against the shape `computeNodeDiagnostics`
|
|
126
|
+
* sees (arguments record + type discriminator), not against the strict per-type shapes,
|
|
127
|
+
* so we widen to `NodeData` via unknown at the boundary.
|
|
128
|
+
*/
|
|
129
|
+
export function makeNode(type: string, args: Record<string, unknown>, overrides: Record<string, unknown> = {}): NodeData {
|
|
130
|
+
return { id: "n1", type, arguments: args, ...overrides } as unknown as NodeData;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// ============================================================================
|
|
134
|
+
// Synthetic NodeDefinition builder
|
|
135
|
+
// ============================================================================
|
|
136
|
+
|
|
137
|
+
export function makeNodeDef(overrides: Partial<NodeDefinition> = {}): NodeDefinition {
|
|
138
|
+
return {
|
|
139
|
+
type: "Synthetic" as NodeDefinition["type"],
|
|
140
|
+
label: "Synthetic Node",
|
|
141
|
+
category: NodeCategory.Input,
|
|
142
|
+
description: "Synthetic node used only in tests",
|
|
143
|
+
parameters: [],
|
|
144
|
+
...overrides,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// ============================================================================
|
|
149
|
+
// Diagnostic assertion helpers
|
|
150
|
+
// ============================================================================
|
|
151
|
+
|
|
152
|
+
export function diagsOfCategory(diags: Diagnostic[], category: DiagnosticCategory): Diagnostic[] {
|
|
153
|
+
return diags.filter((d) => d.category === category);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export function hasDiag(diags: Diagnostic[], predicate: (d: Diagnostic) => boolean): boolean {
|
|
157
|
+
return diags.some(predicate);
|
|
158
|
+
}
|