@foresthubai/workflow-core 0.4.3 → 0.4.5

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.
Files changed (298) hide show
  1. package/LICENSE +202 -202
  2. package/NOTICE +14 -14
  3. package/README.md +63 -63
  4. package/dist/api/deployment.d.ts +74 -0
  5. package/dist/api/deployment.d.ts.map +1 -0
  6. package/dist/api/deployment.js +6 -0
  7. package/dist/api/deployment.js.map +1 -0
  8. package/dist/api/engine.d.ts +744 -0
  9. package/dist/api/engine.d.ts.map +1 -0
  10. package/dist/api/engine.js +6 -0
  11. package/dist/api/engine.js.map +1 -0
  12. package/dist/api/index.d.ts +4 -0
  13. package/dist/api/index.d.ts.map +1 -1
  14. package/dist/api/index.js +2 -0
  15. package/dist/api/index.js.map +1 -1
  16. package/dist/api/workflow.d.ts +25 -9
  17. package/dist/api/workflow.d.ts.map +1 -1
  18. package/dist/channel/Channel.d.ts +1 -1
  19. package/dist/channel/Channel.d.ts.map +1 -1
  20. package/dist/channel/Channel.js +3 -1
  21. package/dist/channel/Channel.js.map +1 -1
  22. package/dist/channel/ChannelDefinition.d.ts.map +1 -1
  23. package/dist/channel/ChannelDefinition.js +24 -0
  24. package/dist/channel/ChannelDefinition.js.map +1 -1
  25. package/dist/channel/index.d.ts.map +1 -1
  26. package/dist/channel/index.js +2 -0
  27. package/dist/channel/index.js.map +1 -1
  28. package/dist/channel/serialization.d.ts.map +1 -1
  29. package/dist/channel/serialization.js +8 -0
  30. package/dist/channel/serialization.js.map +1 -1
  31. package/dist/deploy/index.d.ts +5 -1
  32. package/dist/deploy/index.d.ts.map +1 -1
  33. package/dist/deploy/index.js +4 -1
  34. package/dist/deploy/index.js.map +1 -1
  35. package/dist/deploy/inputs.d.ts +26 -0
  36. package/dist/deploy/inputs.d.ts.map +1 -0
  37. package/dist/deploy/inputs.js +4 -0
  38. package/dist/deploy/inputs.js.map +1 -0
  39. package/dist/deploy/requirements.d.ts +24 -0
  40. package/dist/deploy/requirements.d.ts.map +1 -1
  41. package/dist/deploy/requirements.js +63 -0
  42. package/dist/deploy/requirements.js.map +1 -1
  43. package/dist/deploy/spec.d.ts +27 -0
  44. package/dist/deploy/spec.d.ts.map +1 -0
  45. package/dist/deploy/spec.js +352 -0
  46. package/dist/deploy/spec.js.map +1 -0
  47. package/dist/diagnostics/__fixtures__/diagnosticFixtures.d.ts.map +1 -1
  48. package/dist/diagnostics/__fixtures__/diagnosticFixtures.js +2 -0
  49. package/dist/diagnostics/__fixtures__/diagnosticFixtures.js.map +1 -1
  50. package/dist/diagnostics/diagnostics.d.ts.map +1 -1
  51. package/dist/diagnostics/diagnostics.js +2 -0
  52. package/dist/diagnostics/diagnostics.js.map +1 -1
  53. package/dist/diagnostics/index.d.ts.map +1 -1
  54. package/dist/diagnostics/index.js +2 -0
  55. package/dist/diagnostics/index.js.map +1 -1
  56. package/dist/edge/Edge.d.ts.map +1 -1
  57. package/dist/edge/Edge.js +2 -0
  58. package/dist/edge/Edge.js.map +1 -1
  59. package/dist/edge/EdgeDefinition.d.ts.map +1 -1
  60. package/dist/edge/EdgeDefinition.js +2 -0
  61. package/dist/edge/EdgeDefinition.js.map +1 -1
  62. package/dist/edge/EdgeType.d.ts.map +1 -1
  63. package/dist/edge/EdgeType.js +2 -0
  64. package/dist/edge/EdgeType.js.map +1 -1
  65. package/dist/edge/index.d.ts.map +1 -1
  66. package/dist/edge/index.js +2 -2
  67. package/dist/edge/index.js.map +1 -1
  68. package/dist/edge/serialization.d.ts.map +1 -1
  69. package/dist/edge/serialization.js +2 -0
  70. package/dist/edge/serialization.js.map +1 -1
  71. package/dist/expression/index.d.ts.map +1 -1
  72. package/dist/expression/index.js +2 -0
  73. package/dist/expression/index.js.map +1 -1
  74. package/dist/expression/parser.d.ts.map +1 -1
  75. package/dist/expression/parser.js +2 -0
  76. package/dist/expression/parser.js.map +1 -1
  77. package/dist/expression/types.d.ts.map +1 -1
  78. package/dist/expression/types.js +2 -0
  79. package/dist/expression/types.js.map +1 -1
  80. package/dist/function/FunctionDeclaration.d.ts.map +1 -1
  81. package/dist/function/FunctionDeclaration.js +2 -0
  82. package/dist/function/FunctionDeclaration.js.map +1 -1
  83. package/dist/function/index.d.ts.map +1 -1
  84. package/dist/function/index.js +2 -0
  85. package/dist/function/index.js.map +1 -1
  86. package/dist/function/serialization.d.ts.map +1 -1
  87. package/dist/function/serialization.js +2 -0
  88. package/dist/function/serialization.js.map +1 -1
  89. package/dist/id/index.d.ts.map +1 -1
  90. package/dist/id/index.js +2 -0
  91. package/dist/id/index.js.map +1 -1
  92. package/dist/index.d.ts.map +1 -1
  93. package/dist/index.js +2 -0
  94. package/dist/index.js.map +1 -1
  95. package/dist/memory/Memory.d.ts.map +1 -1
  96. package/dist/memory/Memory.js +2 -0
  97. package/dist/memory/Memory.js.map +1 -1
  98. package/dist/memory/MemoryDefinition.d.ts.map +1 -1
  99. package/dist/memory/MemoryDefinition.js +2 -0
  100. package/dist/memory/MemoryDefinition.js.map +1 -1
  101. package/dist/memory/MemoryFileDefinition.d.ts.map +1 -1
  102. package/dist/memory/MemoryFileDefinition.js +2 -0
  103. package/dist/memory/MemoryFileDefinition.js.map +1 -1
  104. package/dist/memory/MemoryRegistry.d.ts.map +1 -1
  105. package/dist/memory/MemoryRegistry.js +2 -0
  106. package/dist/memory/MemoryRegistry.js.map +1 -1
  107. package/dist/memory/VectorDatabaseDefinition.d.ts.map +1 -1
  108. package/dist/memory/VectorDatabaseDefinition.js +2 -0
  109. package/dist/memory/VectorDatabaseDefinition.js.map +1 -1
  110. package/dist/memory/index.d.ts.map +1 -1
  111. package/dist/memory/index.js +2 -0
  112. package/dist/memory/index.js.map +1 -1
  113. package/dist/memory/serialization.d.ts.map +1 -1
  114. package/dist/memory/serialization.js +2 -0
  115. package/dist/memory/serialization.js.map +1 -1
  116. package/dist/migration/index.d.ts.map +1 -1
  117. package/dist/migration/index.js +2 -0
  118. package/dist/migration/index.js.map +1 -1
  119. package/dist/migration/migrate.d.ts.map +1 -1
  120. package/dist/migration/migrate.js +2 -0
  121. package/dist/migration/migrate.js.map +1 -1
  122. package/dist/migration/migrations.d.ts.map +1 -1
  123. package/dist/migration/migrations.js +2 -0
  124. package/dist/migration/migrations.js.map +1 -1
  125. package/dist/migration/version.d.ts.map +1 -1
  126. package/dist/migration/version.js +2 -0
  127. package/dist/migration/version.js.map +1 -1
  128. package/dist/model/LLMModelDefinition.d.ts.map +1 -1
  129. package/dist/model/LLMModelDefinition.js +2 -0
  130. package/dist/model/LLMModelDefinition.js.map +1 -1
  131. package/dist/model/Model.d.ts.map +1 -1
  132. package/dist/model/Model.js +2 -13
  133. package/dist/model/Model.js.map +1 -1
  134. package/dist/model/ModelDefinition.d.ts.map +1 -1
  135. package/dist/model/ModelDefinition.js +2 -0
  136. package/dist/model/ModelDefinition.js.map +1 -1
  137. package/dist/model/ModelRegistry.d.ts.map +1 -1
  138. package/dist/model/ModelRegistry.js +2 -0
  139. package/dist/model/ModelRegistry.js.map +1 -1
  140. package/dist/model/index.d.ts.map +1 -1
  141. package/dist/model/index.js +2 -0
  142. package/dist/model/index.js.map +1 -1
  143. package/dist/model/serialization.d.ts.map +1 -1
  144. package/dist/model/serialization.js +2 -0
  145. package/dist/model/serialization.js.map +1 -1
  146. package/dist/node/AgentNode.d.ts.map +1 -1
  147. package/dist/node/AgentNode.js +2 -0
  148. package/dist/node/AgentNode.js.map +1 -1
  149. package/dist/node/DataNode.d.ts.map +1 -1
  150. package/dist/node/DataNode.js +2 -0
  151. package/dist/node/DataNode.js.map +1 -1
  152. package/dist/node/FunctionNode.d.ts.map +1 -1
  153. package/dist/node/FunctionNode.js +2 -0
  154. package/dist/node/FunctionNode.js.map +1 -1
  155. package/dist/node/InputNode.d.ts.map +1 -1
  156. package/dist/node/InputNode.js +2 -0
  157. package/dist/node/InputNode.js.map +1 -1
  158. package/dist/node/LogicNode.d.ts.map +1 -1
  159. package/dist/node/LogicNode.js +2 -0
  160. package/dist/node/LogicNode.js.map +1 -1
  161. package/dist/node/MqttNode.d.ts.map +1 -1
  162. package/dist/node/MqttNode.js +2 -0
  163. package/dist/node/MqttNode.js.map +1 -1
  164. package/dist/node/Node.d.ts.map +1 -1
  165. package/dist/node/Node.js +2 -7
  166. package/dist/node/Node.js.map +1 -1
  167. package/dist/node/NodeDefinition.d.ts.map +1 -1
  168. package/dist/node/NodeDefinition.js +2 -0
  169. package/dist/node/NodeDefinition.js.map +1 -1
  170. package/dist/node/NodeRegistry.d.ts.map +1 -1
  171. package/dist/node/NodeRegistry.js +2 -0
  172. package/dist/node/NodeRegistry.js.map +1 -1
  173. package/dist/node/OutputNode.d.ts.map +1 -1
  174. package/dist/node/OutputNode.js +4 -2
  175. package/dist/node/OutputNode.js.map +1 -1
  176. package/dist/node/ToolNode.d.ts.map +1 -1
  177. package/dist/node/ToolNode.js +2 -0
  178. package/dist/node/ToolNode.js.map +1 -1
  179. package/dist/node/TriggerNode.d.ts.map +1 -1
  180. package/dist/node/TriggerNode.js +2 -0
  181. package/dist/node/TriggerNode.js.map +1 -1
  182. package/dist/node/constants.d.ts.map +1 -1
  183. package/dist/node/constants.js +2 -0
  184. package/dist/node/constants.js.map +1 -1
  185. package/dist/node/index.d.ts.map +1 -1
  186. package/dist/node/index.js +2 -0
  187. package/dist/node/index.js.map +1 -1
  188. package/dist/node/methods.d.ts.map +1 -1
  189. package/dist/node/methods.js +2 -0
  190. package/dist/node/methods.js.map +1 -1
  191. package/dist/node/serialization.d.ts.map +1 -1
  192. package/dist/node/serialization.js +33 -13
  193. package/dist/node/serialization.js.map +1 -1
  194. package/dist/parameter/OutputParameter.d.ts.map +1 -1
  195. package/dist/parameter/OutputParameter.js +2 -0
  196. package/dist/parameter/OutputParameter.js.map +1 -1
  197. package/dist/parameter/Parameter.d.ts.map +1 -1
  198. package/dist/parameter/Parameter.js +2 -0
  199. package/dist/parameter/Parameter.js.map +1 -1
  200. package/dist/parameter/index.d.ts.map +1 -1
  201. package/dist/parameter/index.js +2 -0
  202. package/dist/parameter/index.js.map +1 -1
  203. package/dist/variable/Variable.d.ts.map +1 -1
  204. package/dist/variable/Variable.js +2 -0
  205. package/dist/variable/Variable.js.map +1 -1
  206. package/dist/variable/index.d.ts.map +1 -1
  207. package/dist/variable/index.js +2 -3
  208. package/dist/variable/index.js.map +1 -1
  209. package/dist/variable/operations.d.ts.map +1 -1
  210. package/dist/variable/operations.js +2 -0
  211. package/dist/variable/operations.js.map +1 -1
  212. package/dist/workflow/Workflow.d.ts.map +1 -1
  213. package/dist/workflow/Workflow.js +2 -0
  214. package/dist/workflow/Workflow.js.map +1 -1
  215. package/dist/workflow/index.d.ts.map +1 -1
  216. package/dist/workflow/index.js +2 -0
  217. package/dist/workflow/index.js.map +1 -1
  218. package/dist/workflow/serialization.d.ts.map +1 -1
  219. package/dist/workflow/serialization.js +2 -4
  220. package/dist/workflow/serialization.js.map +1 -1
  221. package/package.json +2 -2
  222. package/src/api/deployment.ts +74 -0
  223. package/src/api/engine.ts +744 -0
  224. package/src/api/index.ts +29 -11
  225. package/src/api/workflow.ts +25 -9
  226. package/src/channel/Channel.ts +14 -11
  227. package/src/channel/ChannelDefinition.ts +101 -76
  228. package/src/channel/index.ts +9 -6
  229. package/src/channel/serialization.ts +77 -68
  230. package/src/deploy/index.ts +17 -1
  231. package/src/deploy/inputs.ts +44 -0
  232. package/src/deploy/requirements.test.ts +64 -61
  233. package/src/deploy/requirements.ts +159 -41
  234. package/src/deploy/spec.test.ts +227 -0
  235. package/src/deploy/spec.ts +397 -0
  236. package/src/diagnostics/__fixtures__/diagnosticFixtures.ts +161 -158
  237. package/src/diagnostics/diagnostics.test.ts +881 -878
  238. package/src/diagnostics/diagnostics.ts +939 -936
  239. package/src/diagnostics/index.ts +14 -11
  240. package/src/edge/Edge.ts +26 -23
  241. package/src/edge/EdgeDefinition.ts +48 -45
  242. package/src/edge/EdgeType.ts +22 -19
  243. package/src/edge/index.ts +11 -8
  244. package/src/edge/serialization.ts +86 -83
  245. package/src/expression/index.ts +7 -4
  246. package/src/expression/parser.ts +365 -362
  247. package/src/expression/types.ts +33 -30
  248. package/src/function/FunctionDeclaration.ts +57 -54
  249. package/src/function/index.ts +6 -3
  250. package/src/function/serialization.ts +43 -40
  251. package/src/globals.d.ts +12 -9
  252. package/src/id/index.ts +11 -8
  253. package/src/index.ts +25 -22
  254. package/src/memory/Memory.ts +18 -15
  255. package/src/memory/MemoryDefinition.ts +19 -16
  256. package/src/memory/MemoryFileDefinition.ts +40 -37
  257. package/src/memory/MemoryRegistry.ts +38 -35
  258. package/src/memory/VectorDatabaseDefinition.ts +24 -21
  259. package/src/memory/index.ts +11 -8
  260. package/src/memory/serialization.ts +50 -47
  261. package/src/migration/index.ts +7 -4
  262. package/src/migration/migrate.test.ts +47 -44
  263. package/src/migration/migrate.ts +61 -58
  264. package/src/migration/migrations.ts +27 -24
  265. package/src/migration/version.ts +12 -9
  266. package/src/model/LLMModelDefinition.ts +15 -12
  267. package/src/model/Model.ts +42 -39
  268. package/src/model/ModelDefinition.ts +18 -15
  269. package/src/model/ModelRegistry.ts +36 -33
  270. package/src/model/index.ts +10 -7
  271. package/src/model/serialization.ts +33 -30
  272. package/src/node/AgentNode.ts +85 -82
  273. package/src/node/DataNode.ts +44 -41
  274. package/src/node/FunctionNode.ts +79 -76
  275. package/src/node/InputNode.ts +188 -185
  276. package/src/node/LogicNode.ts +36 -33
  277. package/src/node/MqttNode.ts +130 -127
  278. package/src/node/Node.ts +64 -61
  279. package/src/node/NodeDefinition.ts +40 -37
  280. package/src/node/NodeRegistry.ts +88 -85
  281. package/src/node/OutputNode.ts +90 -87
  282. package/src/node/ToolNode.ts +35 -32
  283. package/src/node/TriggerNode.ts +275 -272
  284. package/src/node/constants.ts +19 -16
  285. package/src/node/index.ts +29 -26
  286. package/src/node/methods.ts +281 -278
  287. package/src/node/serialization.test.ts +51 -0
  288. package/src/node/serialization.ts +565 -544
  289. package/src/parameter/OutputParameter.ts +71 -68
  290. package/src/parameter/Parameter.ts +246 -243
  291. package/src/parameter/index.ts +36 -33
  292. package/src/variable/Variable.ts +13 -10
  293. package/src/variable/index.ts +19 -16
  294. package/src/variable/operations.ts +109 -106
  295. package/src/workflow/Workflow.ts +44 -41
  296. package/src/workflow/index.ts +6 -3
  297. package/src/workflow/serialization.test.ts +243 -240
  298. package/src/workflow/serialization.ts +245 -242
@@ -1,243 +1,246 @@
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
- }
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright (c) 2026 ForestHub.
3
+
4
+ import type { Expression, Reference } from "../api";
5
+ import type { ChannelType } from "../channel";
6
+ import type { MemoryType } from "../memory";
7
+ import type { ModelType, ModelCapability } from "../model";
8
+ import { refToLookupKey } from "../variable";
9
+ import type { Schemas } from "../api";
10
+
11
+ export type DataType = Schemas["DataType"];
12
+
13
+ /**
14
+ * A field that is either a static value of T, or a function that derives T
15
+ * from the owning node's current arguments. Scope is strictly args-only —
16
+ * no access to variables, IO labels, or other canvas state. For wider
17
+ * context, use a purpose-named accessor (e.g. resolveExpressionType).
18
+ */
19
+ export type FromArgs<T> = T | ((args: Record<string, unknown>) => T);
20
+
21
+ /** Unwrap a FromArgs value against the current node arguments. */
22
+ export function unwrapFromArgs<T>(value: FromArgs<T>, args: Record<string, unknown>): T {
23
+ return typeof value === "function" ? (value as (args: Record<string, unknown>) => T)(args) : value;
24
+ }
25
+
26
+ // ============================================================================
27
+ // Parameter definitions
28
+ // ============================================================================
29
+
30
+ export interface ParameterBase {
31
+ id: string;
32
+ label: string;
33
+ description: string;
34
+ optional?: boolean;
35
+ /** Parameter is only active (visible, validated, serialized) when all rules are met. */
36
+ activationRules?: ActivationRule[];
37
+ }
38
+
39
+ export interface BasicParam {
40
+ type: "int" | "float" | "time";
41
+ default?: number | string;
42
+ }
43
+
44
+ export interface StringParam {
45
+ type: "string";
46
+ multiline?: boolean;
47
+ default?: string;
48
+ }
49
+
50
+ export interface BoolParam {
51
+ type: "bool";
52
+ default: boolean;
53
+ }
54
+
55
+ export interface WeekdaysParam {
56
+ type: "weekdays";
57
+ default: string[];
58
+ }
59
+
60
+ export interface SelectionParam {
61
+ type: "selection";
62
+ options: Array<{ value: string; label: string }>;
63
+ default?: string;
64
+ }
65
+
66
+ export interface ExpressionParam {
67
+ type: "expression";
68
+ /** Type can be dynamic (static value or args-only lambda). */
69
+ expressionType: FromArgs<DataType>;
70
+ /**
71
+ * Escape hatch for the variableSelect case: when set, points to the id of a sibling
72
+ * variableSelect parameter. If that parameter holds a live Reference, the expressionType
73
+ * is taken from the referenced variable. Falls back to `expressionType` otherwise.
74
+ */
75
+ fromReference?: string;
76
+ /**
77
+ * Required: An expression always has a value object never an unset state.
78
+ */
79
+ default: Expression;
80
+ }
81
+
82
+ // Reference-select parameters: pick an external entity by id. No `default`.
83
+
84
+ export interface VariableSelectParam {
85
+ type: "variableSelect";
86
+ default?: never;
87
+ }
88
+
89
+ // Model reference parameter — selects a model id from the static catalog (props)
90
+ // unioned with declared custom models, filtered by model type and capability.
91
+ export interface ModelSelectParam {
92
+ type: "modelSelect";
93
+ /** Model types this slot accepts (e.g. ["LLMModel"]). Static list or args-derived lambda. */
94
+ modelType: FromArgs<ModelType[]>;
95
+ /** Optional capability filter (e.g. ["chat"]) applied to catalog and declared models alike. */
96
+ capabilities?: FromArgs<ModelCapability[]>;
97
+ default?: never;
98
+ }
99
+
100
+ export interface ChannelSelectParam {
101
+ type: "channelSelect";
102
+ /** Channel types this slot accepts. Static list or args-derived lambda. */
103
+ channelType: FromArgs<ChannelType[]>;
104
+ default?: never;
105
+ }
106
+
107
+ export interface MemorySelectParam {
108
+ type: "memorySelect";
109
+ /** Memory types this slot accepts (e.g. ["VectorDatabase"]). Static list or args-derived lambda. */
110
+ memoryType: FromArgs<MemoryType[]>;
111
+ default?: never;
112
+ }
113
+
114
+ /**
115
+ * List parameter that binds an agent node to project-declared memory files,
116
+ * each with an access mode (`r` = read-only, `rw` = read + write). The editor
117
+ * holds the array directly; the API schema (`MemoryRef[]`) round-trips 1:1.
118
+ *
119
+ * `default` is required: a list param is always a
120
+ * concrete array, never unset — declare `default: []` for "starts empty".
121
+ */
122
+ export interface MemoryRefsParam {
123
+ type: "memory-refs";
124
+ default: Schemas["MemoryRef"][];
125
+ }
126
+
127
+ /** Union of all reference-select parameter variants, used for type guards. */
128
+ export type ReferenceSelectParam = VariableSelectParam | ChannelSelectParam | MemorySelectParam | ModelSelectParam;
129
+
130
+ export function isReferenceSelectParam(param: Parameter): param is ParameterBase & ReferenceSelectParam {
131
+ return param.type === "variableSelect" || param.type === "channelSelect" || param.type === "memorySelect" || param.type === "modelSelect";
132
+ }
133
+
134
+ export type Parameter =
135
+ | (ParameterBase & BasicParam)
136
+ | (ParameterBase & VariableSelectParam)
137
+ | (ParameterBase & StringParam)
138
+ | (ParameterBase & BoolParam)
139
+ | (ParameterBase & WeekdaysParam)
140
+ | (ParameterBase & SelectionParam)
141
+ | (ParameterBase & MemorySelectParam)
142
+ | (ParameterBase & ModelSelectParam)
143
+ | (ParameterBase & ExpressionParam)
144
+ | (ParameterBase & ChannelSelectParam)
145
+ | (ParameterBase & MemoryRefsParam);
146
+
147
+ // ============================================================================
148
+ // Parameter activation rules
149
+ // ============================================================================
150
+
151
+ /** Typed union of rules that control whether a parameter is active (visible, validated, serialized). */
152
+ export type ActivationRule =
153
+ | { type: "parameterIn"; parameterId: string; values: unknown[] }
154
+ | { type: "isControlFlow" }
155
+ | { type: "isToolInput" };
156
+
157
+ /**
158
+ * Evaluate whether a parameter is active (visible, validated, serialized) given current context.
159
+ * All rules must be satisfied (AND logic). Undefined or empty array = always active.
160
+ */
161
+ export function isParameterActive(param: Parameter, parameterValues: Record<string, unknown>, isToolInput: boolean): boolean {
162
+ if (!param.activationRules?.length) return true;
163
+ return param.activationRules.every((cond) => {
164
+ switch (cond.type) {
165
+ case "isControlFlow":
166
+ return !isToolInput;
167
+ case "isToolInput":
168
+ return isToolInput;
169
+ case "parameterIn":
170
+ return cond.values.includes(parameterValues[cond.parameterId]);
171
+ }
172
+ });
173
+ }
174
+
175
+ /**
176
+ * Whether a scalar argument value counts as "unset" for api purposes:
177
+ * `undefined`, `null`, or `""`. Deliberately NOT `false`/`0` (valid values) nor
178
+ * `[]` — an empty list is a real value, since list params are always
179
+ * materialized to a concrete array. Shared by required-param diagnostics and
180
+ * {@link pruneArguments} so "unset" has exactly one definition.
181
+ */
182
+ export function isEmpty(value: unknown): boolean {
183
+ return value === undefined || value === null || value === "";
184
+ }
185
+
186
+ /**
187
+ * Prune arguments that must not appear in the api, at the domain→api boundary.
188
+ * Mutates `args` in place. Two reasons an arg is dropped:
189
+ * 1. inactive its parameter's activation rules aren't met for this context.
190
+ * 2. the parameter {@link isEmpty}.
191
+ */
192
+ export function pruneArguments(args: Record<string, unknown>, parameters: readonly Parameter[], isToolInput = false): void {
193
+ for (const param of parameters) {
194
+ const inactive = !!param.activationRules?.length && !isParameterActive(param, args, isToolInput);
195
+ if (inactive || isEmpty(args[param.id])) {
196
+ delete args[param.id];
197
+ }
198
+ }
199
+ }
200
+
201
+ // ============================================================================
202
+ // Parameter resolvers
203
+ // ============================================================================
204
+
205
+ /**
206
+ * Resolve an ExpressionParam's expected dataType. Handles the `fromReference` escape hatch
207
+ * (type taken from a live variableSelect sibling parameter) and falls back to the
208
+ * declared FromArgs<DataType>.
209
+ */
210
+ export function resolveExpressionType(
211
+ param: ExpressionParam,
212
+ args: Record<string, unknown>,
213
+ variables: Record<string, { dataType: DataType }>,
214
+ ): DataType {
215
+ if (param.fromReference) {
216
+ const ref = args[param.fromReference] as Reference | undefined;
217
+ if (ref?.varId) {
218
+ const v = variables[refToLookupKey(ref)];
219
+ if (v) return v.dataType;
220
+ }
221
+ }
222
+ return unwrapFromArgs(param.expressionType, args);
223
+ }
224
+
225
+ /** Resolve a capability filter (ModelSelectParam) for the current node arguments. */
226
+ export function resolveCapabilities(
227
+ param: { capabilities?: FromArgs<ModelCapability[]> },
228
+ args: Record<string, unknown>,
229
+ ): ModelCapability[] | undefined {
230
+ return param.capabilities === undefined ? undefined : unwrapFromArgs(param.capabilities, args);
231
+ }
232
+
233
+ /** Resolve the allowed channel types for a ChannelSelectParam. */
234
+ export function resolveChannelTypes(param: ChannelSelectParam, args: Record<string, unknown>): ChannelType[] {
235
+ return unwrapFromArgs(param.channelType, args);
236
+ }
237
+
238
+ /** Resolve the allowed memory types for a MemorySelectParam. */
239
+ export function resolveMemoryTypes(param: MemorySelectParam, args: Record<string, unknown>): MemoryType[] {
240
+ return unwrapFromArgs(param.memoryType, args);
241
+ }
242
+
243
+ /** Resolve the allowed model types for a ModelSelectParam. */
244
+ export function resolveModelTypes(param: ModelSelectParam, args: Record<string, unknown>): ModelType[] {
245
+ return unwrapFromArgs(param.modelType, args);
246
+ }
@@ -1,33 +1,36 @@
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";
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright (c) 2026 ForestHub.
3
+
4
+ export type {
5
+ DataType,
6
+ FromArgs,
7
+ ParameterBase,
8
+ BasicParam,
9
+ StringParam,
10
+ BoolParam,
11
+ WeekdaysParam,
12
+ SelectionParam,
13
+ ExpressionParam,
14
+ VariableSelectParam,
15
+ ModelSelectParam,
16
+ ChannelSelectParam,
17
+ MemorySelectParam,
18
+ MemoryRefsParam,
19
+ ReferenceSelectParam,
20
+ Parameter,
21
+ ActivationRule,
22
+ } from "./Parameter";
23
+ export {
24
+ unwrapFromArgs,
25
+ isReferenceSelectParam,
26
+ isParameterActive,
27
+ isEmpty,
28
+ pruneArguments,
29
+ resolveExpressionType,
30
+ resolveCapabilities,
31
+ resolveChannelTypes,
32
+ resolveMemoryTypes,
33
+ resolveModelTypes,
34
+ } from "./Parameter";
35
+ export type { OutputBinding, OutputDeclaration, StaticOutput, OutputList, OutputParameter } from "./OutputParameter";
36
+ export { resolveStaticOutputDataType } from "./OutputParameter";
@@ -1,10 +1,13 @@
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;
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright (c) 2026 ForestHub.
3
+
4
+ import type { Schemas } from "../api";
5
+ import type { DataType } from "../api";
6
+
7
+ export type ApiVariable = Schemas["Variable"]; // Differentiate from domain variable type
8
+
9
+ export type NodeOutputVariable = { kind: "node"; nodeId: string; outputId: string; name: string; dataType: DataType };
10
+ export type DeclaredVariable = { kind: "declared"; uid: string; name: string; dataType: DataType; initialValue?: unknown };
11
+ export type FunctionArgVariable = { kind: "fnarg"; uid: string; name: string; dataType: DataType };
12
+
13
+ export type Variable = NodeOutputVariable | DeclaredVariable | FunctionArgVariable;
@@ -1,16 +1,19 @@
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";
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright (c) 2026 ForestHub.
3
+
4
+ // Public surface of the variable module. The discriminated-union types live in
5
+ // ./Variable; the key/lookup/uid helpers and availability computation live in
6
+ // ./operations. This file is a barrel only. Mirrors channel/memory/model.
7
+
8
+ export type { ApiVariable, NodeOutputVariable, DeclaredVariable, FunctionArgVariable, Variable } from "./Variable";
9
+ export {
10
+ varKey,
11
+ declaredVarKey,
12
+ fnargKey,
13
+ nodeOutputVarKey,
14
+ refToLookupKey,
15
+ ensureUid,
16
+ ensureUids,
17
+ paramKey,
18
+ computeAvailableVariables,
19
+ } from "./operations";