@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.
Files changed (339) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +14 -0
  3. package/README.md +63 -0
  4. package/dist/api/index.d.ts +7 -0
  5. package/dist/api/index.d.ts.map +1 -0
  6. package/dist/api/index.js +2 -0
  7. package/dist/api/index.js.map +1 -0
  8. package/dist/api/workflow.d.ts +607 -0
  9. package/dist/api/workflow.d.ts.map +1 -0
  10. package/dist/api/workflow.js +6 -0
  11. package/dist/api/workflow.js.map +1 -0
  12. package/dist/channel/Channel.d.ts +10 -0
  13. package/dist/channel/Channel.d.ts.map +1 -0
  14. package/dist/channel/Channel.js +2 -0
  15. package/dist/channel/Channel.js.map +1 -0
  16. package/dist/channel/ChannelDefinition.d.ts +27 -0
  17. package/dist/channel/ChannelDefinition.d.ts.map +1 -0
  18. package/dist/channel/ChannelDefinition.js +50 -0
  19. package/dist/channel/ChannelDefinition.js.map +1 -0
  20. package/dist/channel/index.d.ts +7 -0
  21. package/dist/channel/index.d.ts.map +1 -0
  22. package/dist/channel/index.js +4 -0
  23. package/dist/channel/index.js.map +1 -0
  24. package/dist/channel/serialization.d.ts +17 -0
  25. package/dist/channel/serialization.d.ts.map +1 -0
  26. package/dist/channel/serialization.js +63 -0
  27. package/dist/channel/serialization.js.map +1 -0
  28. package/dist/deploy/index.d.ts +2 -0
  29. package/dist/deploy/index.d.ts.map +1 -0
  30. package/dist/deploy/index.js +2 -0
  31. package/dist/deploy/index.js.map +1 -0
  32. package/dist/deploy/requirements.d.ts +17 -0
  33. package/dist/deploy/requirements.d.ts.map +1 -0
  34. package/dist/deploy/requirements.js +41 -0
  35. package/dist/deploy/requirements.js.map +1 -0
  36. package/dist/diagnostics/__fixtures__/diagnosticFixtures.d.ts +28 -0
  37. package/dist/diagnostics/__fixtures__/diagnosticFixtures.d.ts.map +1 -0
  38. package/dist/diagnostics/__fixtures__/diagnosticFixtures.js +125 -0
  39. package/dist/diagnostics/__fixtures__/diagnosticFixtures.js.map +1 -0
  40. package/dist/diagnostics/diagnostics.d.ts +128 -0
  41. package/dist/diagnostics/diagnostics.d.ts.map +1 -0
  42. package/dist/diagnostics/diagnostics.js +783 -0
  43. package/dist/diagnostics/diagnostics.js.map +1 -0
  44. package/dist/diagnostics/index.d.ts +3 -0
  45. package/dist/diagnostics/index.d.ts.map +1 -0
  46. package/dist/diagnostics/index.js +2 -0
  47. package/dist/diagnostics/index.js.map +1 -0
  48. package/dist/edge/Edge.d.ts +22 -0
  49. package/dist/edge/Edge.d.ts.map +1 -0
  50. package/dist/edge/Edge.js +2 -0
  51. package/dist/edge/Edge.js.map +1 -0
  52. package/dist/edge/EdgeDefinition.d.ts +10 -0
  53. package/dist/edge/EdgeDefinition.d.ts.map +1 -0
  54. package/dist/edge/EdgeDefinition.js +36 -0
  55. package/dist/edge/EdgeDefinition.js.map +1 -0
  56. package/dist/edge/EdgeType.d.ts +6 -0
  57. package/dist/edge/EdgeType.d.ts.map +1 -0
  58. package/dist/edge/EdgeType.js +7 -0
  59. package/dist/edge/EdgeType.js.map +1 -0
  60. package/dist/edge/index.d.ts +6 -0
  61. package/dist/edge/index.d.ts.map +1 -0
  62. package/dist/edge/index.js +6 -0
  63. package/dist/edge/index.js.map +1 -0
  64. package/dist/edge/serialization.d.ts +18 -0
  65. package/dist/edge/serialization.d.ts.map +1 -0
  66. package/dist/edge/serialization.js +76 -0
  67. package/dist/edge/serialization.js.map +1 -0
  68. package/dist/expression/index.d.ts +5 -0
  69. package/dist/expression/index.d.ts.map +1 -0
  70. package/dist/expression/index.js +3 -0
  71. package/dist/expression/index.js.map +1 -0
  72. package/dist/expression/parser.d.ts +14 -0
  73. package/dist/expression/parser.d.ts.map +1 -0
  74. package/dist/expression/parser.js +309 -0
  75. package/dist/expression/parser.js.map +1 -0
  76. package/dist/expression/types.d.ts +11 -0
  77. package/dist/expression/types.d.ts.map +1 -0
  78. package/dist/expression/types.js +20 -0
  79. package/dist/expression/types.js.map +1 -0
  80. package/dist/function/FunctionDeclaration.d.ts +43 -0
  81. package/dist/function/FunctionDeclaration.d.ts.map +1 -0
  82. package/dist/function/FunctionDeclaration.js +17 -0
  83. package/dist/function/FunctionDeclaration.js.map +1 -0
  84. package/dist/function/index.d.ts +4 -0
  85. package/dist/function/index.d.ts.map +1 -0
  86. package/dist/function/index.js +3 -0
  87. package/dist/function/index.js.map +1 -0
  88. package/dist/function/serialization.d.ts +20 -0
  89. package/dist/function/serialization.d.ts.map +1 -0
  90. package/dist/function/serialization.js +26 -0
  91. package/dist/function/serialization.js.map +1 -0
  92. package/dist/id/index.d.ts +7 -0
  93. package/dist/id/index.d.ts.map +1 -0
  94. package/dist/id/index.js +9 -0
  95. package/dist/id/index.js.map +1 -0
  96. package/dist/index.d.ts +11 -0
  97. package/dist/index.d.ts.map +1 -0
  98. package/dist/index.js +14 -0
  99. package/dist/index.js.map +1 -0
  100. package/dist/memory/Memory.d.ts +12 -0
  101. package/dist/memory/Memory.d.ts.map +1 -0
  102. package/dist/memory/Memory.js +2 -0
  103. package/dist/memory/Memory.js.map +1 -0
  104. package/dist/memory/MemoryDefinition.d.ts +16 -0
  105. package/dist/memory/MemoryDefinition.d.ts.map +1 -0
  106. package/dist/memory/MemoryDefinition.js +2 -0
  107. package/dist/memory/MemoryDefinition.js.map +1 -0
  108. package/dist/memory/MemoryFileDefinition.d.ts +8 -0
  109. package/dist/memory/MemoryFileDefinition.d.ts.map +1 -0
  110. package/dist/memory/MemoryFileDefinition.js +36 -0
  111. package/dist/memory/MemoryFileDefinition.js.map +1 -0
  112. package/dist/memory/MemoryRegistry.d.ts +17 -0
  113. package/dist/memory/MemoryRegistry.d.ts.map +1 -0
  114. package/dist/memory/MemoryRegistry.js +29 -0
  115. package/dist/memory/MemoryRegistry.js.map +1 -0
  116. package/dist/memory/VectorDatabaseDefinition.d.ts +7 -0
  117. package/dist/memory/VectorDatabaseDefinition.d.ts.map +1 -0
  118. package/dist/memory/VectorDatabaseDefinition.js +20 -0
  119. package/dist/memory/VectorDatabaseDefinition.js.map +1 -0
  120. package/dist/memory/index.d.ts +9 -0
  121. package/dist/memory/index.d.ts.map +1 -0
  122. package/dist/memory/index.js +6 -0
  123. package/dist/memory/index.js.map +1 -0
  124. package/dist/memory/serialization.d.ts +11 -0
  125. package/dist/memory/serialization.d.ts.map +1 -0
  126. package/dist/memory/serialization.js +44 -0
  127. package/dist/memory/serialization.js.map +1 -0
  128. package/dist/migration/index.d.ts +5 -0
  129. package/dist/migration/index.d.ts.map +1 -0
  130. package/dist/migration/index.js +4 -0
  131. package/dist/migration/index.js.map +1 -0
  132. package/dist/migration/migrate.d.ts +11 -0
  133. package/dist/migration/migrate.d.ts.map +1 -0
  134. package/dist/migration/migrate.js +52 -0
  135. package/dist/migration/migrate.js.map +1 -0
  136. package/dist/migration/migrations.d.ts +22 -0
  137. package/dist/migration/migrations.d.ts.map +1 -0
  138. package/dist/migration/migrations.js +10 -0
  139. package/dist/migration/migrations.js.map +1 -0
  140. package/dist/migration/version.d.ts +9 -0
  141. package/dist/migration/version.d.ts.map +1 -0
  142. package/dist/migration/version.js +9 -0
  143. package/dist/migration/version.js.map +1 -0
  144. package/dist/model/LLMModelDefinition.d.ts +7 -0
  145. package/dist/model/LLMModelDefinition.d.ts.map +1 -0
  146. package/dist/model/LLMModelDefinition.js +11 -0
  147. package/dist/model/LLMModelDefinition.js.map +1 -0
  148. package/dist/model/Model.d.ts +21 -0
  149. package/dist/model/Model.d.ts.map +1 -0
  150. package/dist/model/Model.js +15 -0
  151. package/dist/model/Model.js.map +1 -0
  152. package/dist/model/ModelDefinition.d.ts +15 -0
  153. package/dist/model/ModelDefinition.d.ts.map +1 -0
  154. package/dist/model/ModelDefinition.js +2 -0
  155. package/dist/model/ModelDefinition.js.map +1 -0
  156. package/dist/model/ModelRegistry.d.ts +17 -0
  157. package/dist/model/ModelRegistry.d.ts.map +1 -0
  158. package/dist/model/ModelRegistry.js +27 -0
  159. package/dist/model/ModelRegistry.js.map +1 -0
  160. package/dist/model/index.d.ts +8 -0
  161. package/dist/model/index.d.ts.map +1 -0
  162. package/dist/model/index.js +5 -0
  163. package/dist/model/index.js.map +1 -0
  164. package/dist/model/serialization.d.ts +8 -0
  165. package/dist/model/serialization.d.ts.map +1 -0
  166. package/dist/model/serialization.js +25 -0
  167. package/dist/model/serialization.js.map +1 -0
  168. package/dist/node/AgentNode.d.ts +21 -0
  169. package/dist/node/AgentNode.d.ts.map +1 -0
  170. package/dist/node/AgentNode.js +60 -0
  171. package/dist/node/AgentNode.js.map +1 -0
  172. package/dist/node/DataNode.d.ts +14 -0
  173. package/dist/node/DataNode.d.ts.map +1 -0
  174. package/dist/node/DataNode.js +26 -0
  175. package/dist/node/DataNode.js.map +1 -0
  176. package/dist/node/FunctionNode.d.ts +24 -0
  177. package/dist/node/FunctionNode.d.ts.map +1 -0
  178. package/dist/node/FunctionNode.js +44 -0
  179. package/dist/node/FunctionNode.js.map +1 -0
  180. package/dist/node/InputNode.d.ts +46 -0
  181. package/dist/node/InputNode.d.ts.map +1 -0
  182. package/dist/node/InputNode.js +133 -0
  183. package/dist/node/InputNode.js.map +1 -0
  184. package/dist/node/LogicNode.d.ts +13 -0
  185. package/dist/node/LogicNode.d.ts.map +1 -0
  186. package/dist/node/LogicNode.js +19 -0
  187. package/dist/node/LogicNode.js.map +1 -0
  188. package/dist/node/MqttNode.d.ts +27 -0
  189. package/dist/node/MqttNode.d.ts.map +1 -0
  190. package/dist/node/MqttNode.js +96 -0
  191. package/dist/node/MqttNode.js.map +1 -0
  192. package/dist/node/Node.d.ts +49 -0
  193. package/dist/node/Node.d.ts.map +1 -0
  194. package/dist/node/Node.js +9 -0
  195. package/dist/node/Node.js.map +1 -0
  196. package/dist/node/NodeDefinition.d.ts +30 -0
  197. package/dist/node/NodeDefinition.d.ts.map +1 -0
  198. package/dist/node/NodeDefinition.js +2 -0
  199. package/dist/node/NodeDefinition.js.map +1 -0
  200. package/dist/node/NodeRegistry.d.ts +19 -0
  201. package/dist/node/NodeRegistry.d.ts.map +1 -0
  202. package/dist/node/NodeRegistry.js +65 -0
  203. package/dist/node/NodeRegistry.js.map +1 -0
  204. package/dist/node/OutputNode.d.ts +23 -0
  205. package/dist/node/OutputNode.d.ts.map +1 -0
  206. package/dist/node/OutputNode.js +62 -0
  207. package/dist/node/OutputNode.js.map +1 -0
  208. package/dist/node/ToolNode.d.ts +12 -0
  209. package/dist/node/ToolNode.d.ts.map +1 -0
  210. package/dist/node/ToolNode.js +18 -0
  211. package/dist/node/ToolNode.js.map +1 -0
  212. package/dist/node/TriggerNode.d.ts +67 -0
  213. package/dist/node/TriggerNode.d.ts.map +1 -0
  214. package/dist/node/TriggerNode.js +172 -0
  215. package/dist/node/TriggerNode.js.map +1 -0
  216. package/dist/node/constants.d.ts +16 -0
  217. package/dist/node/constants.d.ts.map +1 -0
  218. package/dist/node/constants.js +18 -0
  219. package/dist/node/constants.js.map +1 -0
  220. package/dist/node/index.d.ts +12 -0
  221. package/dist/node/index.d.ts.map +1 -0
  222. package/dist/node/index.js +9 -0
  223. package/dist/node/index.js.map +1 -0
  224. package/dist/node/methods.d.ts +73 -0
  225. package/dist/node/methods.d.ts.map +1 -0
  226. package/dist/node/methods.js +261 -0
  227. package/dist/node/methods.js.map +1 -0
  228. package/dist/node/serialization.d.ts +25 -0
  229. package/dist/node/serialization.d.ts.map +1 -0
  230. package/dist/node/serialization.js +525 -0
  231. package/dist/node/serialization.js.map +1 -0
  232. package/dist/parameter/OutputParameter.d.ts +69 -0
  233. package/dist/parameter/OutputParameter.d.ts.map +1 -0
  234. package/dist/parameter/OutputParameter.js +6 -0
  235. package/dist/parameter/OutputParameter.js.map +1 -0
  236. package/dist/parameter/Parameter.d.ts +152 -0
  237. package/dist/parameter/Parameter.d.ts.map +1 -0
  238. package/dist/parameter/Parameter.js +86 -0
  239. package/dist/parameter/Parameter.js.map +1 -0
  240. package/dist/parameter/index.d.ts +5 -0
  241. package/dist/parameter/index.d.ts.map +1 -0
  242. package/dist/parameter/index.js +3 -0
  243. package/dist/parameter/index.js.map +1 -0
  244. package/dist/variable/Variable.d.ts +25 -0
  245. package/dist/variable/Variable.d.ts.map +1 -0
  246. package/dist/variable/Variable.js +2 -0
  247. package/dist/variable/Variable.js.map +1 -0
  248. package/dist/variable/index.d.ts +3 -0
  249. package/dist/variable/index.d.ts.map +1 -0
  250. package/dist/variable/index.js +5 -0
  251. package/dist/variable/index.js.map +1 -0
  252. package/dist/variable/operations.d.ts +37 -0
  253. package/dist/variable/operations.d.ts.map +1 -0
  254. package/dist/variable/operations.js +88 -0
  255. package/dist/variable/operations.js.map +1 -0
  256. package/dist/workflow/Workflow.d.ts +38 -0
  257. package/dist/workflow/Workflow.d.ts.map +1 -0
  258. package/dist/workflow/Workflow.js +8 -0
  259. package/dist/workflow/Workflow.js.map +1 -0
  260. package/dist/workflow/index.d.ts +4 -0
  261. package/dist/workflow/index.d.ts.map +1 -0
  262. package/dist/workflow/index.js +3 -0
  263. package/dist/workflow/index.js.map +1 -0
  264. package/dist/workflow/serialization.d.ts +43 -0
  265. package/dist/workflow/serialization.d.ts.map +1 -0
  266. package/dist/workflow/serialization.js +215 -0
  267. package/dist/workflow/serialization.js.map +1 -0
  268. package/package.json +105 -0
  269. package/src/api/index.ts +11 -0
  270. package/src/api/workflow.ts +607 -0
  271. package/src/channel/Channel.ts +11 -0
  272. package/src/channel/ChannelDefinition.ts +76 -0
  273. package/src/channel/index.ts +6 -0
  274. package/src/channel/serialization.ts +68 -0
  275. package/src/deploy/index.ts +1 -0
  276. package/src/deploy/requirements.test.ts +61 -0
  277. package/src/deploy/requirements.ts +41 -0
  278. package/src/diagnostics/__fixtures__/diagnosticFixtures.ts +158 -0
  279. package/src/diagnostics/diagnostics.test.ts +878 -0
  280. package/src/diagnostics/diagnostics.ts +936 -0
  281. package/src/diagnostics/index.ts +11 -0
  282. package/src/edge/Edge.ts +23 -0
  283. package/src/edge/EdgeDefinition.ts +45 -0
  284. package/src/edge/EdgeType.ts +19 -0
  285. package/src/edge/index.ts +8 -0
  286. package/src/edge/serialization.ts +83 -0
  287. package/src/expression/index.ts +4 -0
  288. package/src/expression/parser.ts +362 -0
  289. package/src/expression/types.ts +30 -0
  290. package/src/function/FunctionDeclaration.ts +54 -0
  291. package/src/function/index.ts +3 -0
  292. package/src/function/serialization.ts +40 -0
  293. package/src/globals.d.ts +9 -0
  294. package/src/id/index.ts +8 -0
  295. package/src/index.ts +22 -0
  296. package/src/memory/Memory.ts +15 -0
  297. package/src/memory/MemoryDefinition.ts +16 -0
  298. package/src/memory/MemoryFileDefinition.ts +37 -0
  299. package/src/memory/MemoryRegistry.ts +35 -0
  300. package/src/memory/VectorDatabaseDefinition.ts +21 -0
  301. package/src/memory/index.ts +8 -0
  302. package/src/memory/serialization.ts +47 -0
  303. package/src/migration/index.ts +4 -0
  304. package/src/migration/migrate.test.ts +44 -0
  305. package/src/migration/migrate.ts +58 -0
  306. package/src/migration/migrations.ts +24 -0
  307. package/src/migration/version.ts +9 -0
  308. package/src/model/LLMModelDefinition.ts +12 -0
  309. package/src/model/Model.ts +39 -0
  310. package/src/model/ModelDefinition.ts +15 -0
  311. package/src/model/ModelRegistry.ts +33 -0
  312. package/src/model/index.ts +7 -0
  313. package/src/model/serialization.ts +30 -0
  314. package/src/node/AgentNode.ts +82 -0
  315. package/src/node/DataNode.ts +41 -0
  316. package/src/node/FunctionNode.ts +76 -0
  317. package/src/node/InputNode.ts +185 -0
  318. package/src/node/LogicNode.ts +33 -0
  319. package/src/node/MqttNode.ts +127 -0
  320. package/src/node/Node.ts +61 -0
  321. package/src/node/NodeDefinition.ts +37 -0
  322. package/src/node/NodeRegistry.ts +85 -0
  323. package/src/node/OutputNode.ts +87 -0
  324. package/src/node/ToolNode.ts +32 -0
  325. package/src/node/TriggerNode.ts +272 -0
  326. package/src/node/constants.ts +16 -0
  327. package/src/node/index.ts +26 -0
  328. package/src/node/methods.ts +278 -0
  329. package/src/node/serialization.ts +544 -0
  330. package/src/parameter/OutputParameter.ts +68 -0
  331. package/src/parameter/Parameter.ts +243 -0
  332. package/src/parameter/index.ts +33 -0
  333. package/src/variable/Variable.ts +10 -0
  334. package/src/variable/index.ts +16 -0
  335. package/src/variable/operations.ts +106 -0
  336. package/src/workflow/Workflow.ts +41 -0
  337. package/src/workflow/index.ts +3 -0
  338. package/src/workflow/serialization.test.ts +240 -0
  339. 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
+ }