@principal-ai/subsystems-core 0.29.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 (614) hide show
  1. package/README.md +124 -0
  2. package/dist/ConfigurationLoader.d.ts +76 -0
  3. package/dist/ConfigurationLoader.d.ts.map +1 -0
  4. package/dist/ConfigurationLoader.js +148 -0
  5. package/dist/ConfigurationLoader.js.map +1 -0
  6. package/dist/ConfigurationValidator.d.ts +31 -0
  7. package/dist/ConfigurationValidator.d.ts.map +1 -0
  8. package/dist/ConfigurationValidator.js +239 -0
  9. package/dist/ConfigurationValidator.js.map +1 -0
  10. package/dist/EventProcessor.d.ts +49 -0
  11. package/dist/EventProcessor.d.ts.map +1 -0
  12. package/dist/EventProcessor.js +220 -0
  13. package/dist/EventProcessor.js.map +1 -0
  14. package/dist/EventRecorderService.d.ts +305 -0
  15. package/dist/EventRecorderService.d.ts.map +1 -0
  16. package/dist/EventRecorderService.js +467 -0
  17. package/dist/EventRecorderService.js.map +1 -0
  18. package/dist/LibraryLoader.d.ts +65 -0
  19. package/dist/LibraryLoader.d.ts.map +1 -0
  20. package/dist/LibraryLoader.js +197 -0
  21. package/dist/LibraryLoader.js.map +1 -0
  22. package/dist/PathBasedEventProcessor.d.ts +77 -0
  23. package/dist/PathBasedEventProcessor.d.ts.map +1 -0
  24. package/dist/PathBasedEventProcessor.js +136 -0
  25. package/dist/PathBasedEventProcessor.js.map +1 -0
  26. package/dist/SessionManager.d.ts +194 -0
  27. package/dist/SessionManager.d.ts.map +1 -0
  28. package/dist/SessionManager.js +302 -0
  29. package/dist/SessionManager.js.map +1 -0
  30. package/dist/ValidationEngine.d.ts +31 -0
  31. package/dist/ValidationEngine.d.ts.map +1 -0
  32. package/dist/ValidationEngine.js +162 -0
  33. package/dist/ValidationEngine.js.map +1 -0
  34. package/dist/agent-sessions/fixture.d.ts +80 -0
  35. package/dist/agent-sessions/fixture.d.ts.map +1 -0
  36. package/dist/agent-sessions/fixture.js +130 -0
  37. package/dist/agent-sessions/fixture.js.map +1 -0
  38. package/dist/agent-sessions/index.d.ts +3 -0
  39. package/dist/agent-sessions/index.d.ts.map +1 -0
  40. package/dist/agent-sessions/index.js +6 -0
  41. package/dist/agent-sessions/index.js.map +1 -0
  42. package/dist/auxiliary/AuxiliaryManifestValidator.d.ts +41 -0
  43. package/dist/auxiliary/AuxiliaryManifestValidator.d.ts.map +1 -0
  44. package/dist/auxiliary/AuxiliaryManifestValidator.js +100 -0
  45. package/dist/auxiliary/AuxiliaryManifestValidator.js.map +1 -0
  46. package/dist/auxiliary/index.d.ts +9 -0
  47. package/dist/auxiliary/index.d.ts.map +1 -0
  48. package/dist/auxiliary/index.js +14 -0
  49. package/dist/auxiliary/index.js.map +1 -0
  50. package/dist/auxiliary/validateAreaScopeDisjoint.d.ts +24 -0
  51. package/dist/auxiliary/validateAreaScopeDisjoint.d.ts.map +1 -0
  52. package/dist/auxiliary/validateAreaScopeDisjoint.js +61 -0
  53. package/dist/auxiliary/validateAreaScopeDisjoint.js.map +1 -0
  54. package/dist/cli/codegen.d.ts +41 -0
  55. package/dist/cli/codegen.d.ts.map +1 -0
  56. package/dist/cli/codegen.js +257 -0
  57. package/dist/cli/codegen.js.map +1 -0
  58. package/dist/codegen/type-generator.d.ts +123 -0
  59. package/dist/codegen/type-generator.d.ts.map +1 -0
  60. package/dist/codegen/type-generator.js +433 -0
  61. package/dist/codegen/type-generator.js.map +1 -0
  62. package/dist/codegen/usage-example.d.ts +103 -0
  63. package/dist/codegen/usage-example.d.ts.map +1 -0
  64. package/dist/codegen/usage-example.js +258 -0
  65. package/dist/codegen/usage-example.js.map +1 -0
  66. package/dist/dashboard/DashboardValidator.d.ts +85 -0
  67. package/dist/dashboard/DashboardValidator.d.ts.map +1 -0
  68. package/dist/dashboard/DashboardValidator.js +775 -0
  69. package/dist/dashboard/DashboardValidator.js.map +1 -0
  70. package/dist/dashboard/index.d.ts +6 -0
  71. package/dist/dashboard/index.d.ts.map +1 -0
  72. package/dist/dashboard/index.js +10 -0
  73. package/dist/dashboard/index.js.map +1 -0
  74. package/dist/discovery/CanvasDiscovery.d.ts +160 -0
  75. package/dist/discovery/CanvasDiscovery.d.ts.map +1 -0
  76. package/dist/discovery/CanvasDiscovery.js +865 -0
  77. package/dist/discovery/CanvasDiscovery.js.map +1 -0
  78. package/dist/discovery/CanvasFileManifest.d.ts +86 -0
  79. package/dist/discovery/CanvasFileManifest.d.ts.map +1 -0
  80. package/dist/discovery/CanvasFileManifest.js +338 -0
  81. package/dist/discovery/CanvasFileManifest.js.map +1 -0
  82. package/dist/discovery/LibraryDiscovery.d.ts +108 -0
  83. package/dist/discovery/LibraryDiscovery.d.ts.map +1 -0
  84. package/dist/discovery/LibraryDiscovery.js +263 -0
  85. package/dist/discovery/LibraryDiscovery.js.map +1 -0
  86. package/dist/discovery/types.d.ts +403 -0
  87. package/dist/discovery/types.d.ts.map +1 -0
  88. package/dist/discovery/types.js +6 -0
  89. package/dist/discovery/types.js.map +1 -0
  90. package/dist/events/EventsCanvasValidator.d.ts +139 -0
  91. package/dist/events/EventsCanvasValidator.d.ts.map +1 -0
  92. package/dist/events/EventsCanvasValidator.js +281 -0
  93. package/dist/events/EventsCanvasValidator.js.map +1 -0
  94. package/dist/events/NamespacePathIndex.d.ts +61 -0
  95. package/dist/events/NamespacePathIndex.d.ts.map +1 -0
  96. package/dist/events/NamespacePathIndex.js +74 -0
  97. package/dist/events/NamespacePathIndex.js.map +1 -0
  98. package/dist/events/OtelEventPathsValidator.d.ts +75 -0
  99. package/dist/events/OtelEventPathsValidator.d.ts.map +1 -0
  100. package/dist/events/OtelEventPathsValidator.js +126 -0
  101. package/dist/events/OtelEventPathsValidator.js.map +1 -0
  102. package/dist/events/ScopeEventsValidator.d.ts +68 -0
  103. package/dist/events/ScopeEventsValidator.d.ts.map +1 -0
  104. package/dist/events/ScopeEventsValidator.js +91 -0
  105. package/dist/events/ScopeEventsValidator.js.map +1 -0
  106. package/dist/events/index.d.ts +9 -0
  107. package/dist/events/index.d.ts.map +1 -0
  108. package/dist/events/index.js +12 -0
  109. package/dist/events/index.js.map +1 -0
  110. package/dist/events/path-helpers.d.ts +33 -0
  111. package/dist/events/path-helpers.d.ts.map +1 -0
  112. package/dist/events/path-helpers.js +59 -0
  113. package/dist/events/path-helpers.js.map +1 -0
  114. package/dist/execution/ExecutionLoader.d.ts +135 -0
  115. package/dist/execution/ExecutionLoader.d.ts.map +1 -0
  116. package/dist/execution/ExecutionLoader.js +266 -0
  117. package/dist/execution/ExecutionLoader.js.map +1 -0
  118. package/dist/execution/ExecutionValidator.d.ts +94 -0
  119. package/dist/execution/ExecutionValidator.d.ts.map +1 -0
  120. package/dist/execution/ExecutionValidator.js +503 -0
  121. package/dist/execution/ExecutionValidator.js.map +1 -0
  122. package/dist/generated/graph-converter-execution.types.d.ts +177 -0
  123. package/dist/generated/graph-converter-execution.types.d.ts.map +1 -0
  124. package/dist/generated/graph-converter-execution.types.js +12 -0
  125. package/dist/generated/graph-converter-execution.types.js.map +1 -0
  126. package/dist/helpers/GraphInstrumentationHelper.d.ts +93 -0
  127. package/dist/helpers/GraphInstrumentationHelper.d.ts.map +1 -0
  128. package/dist/helpers/GraphInstrumentationHelper.js +252 -0
  129. package/dist/helpers/GraphInstrumentationHelper.js.map +1 -0
  130. package/dist/index.d.ts +82 -0
  131. package/dist/index.d.ts.map +1 -0
  132. package/dist/index.js +214 -0
  133. package/dist/index.js.map +1 -0
  134. package/dist/matchers/SpanMatcher.d.ts +107 -0
  135. package/dist/matchers/SpanMatcher.d.ts.map +1 -0
  136. package/dist/matchers/SpanMatcher.js +274 -0
  137. package/dist/matchers/SpanMatcher.js.map +1 -0
  138. package/dist/node.d.ts +78 -0
  139. package/dist/node.d.ts.map +1 -0
  140. package/dist/node.js +177 -0
  141. package/dist/node.js.map +1 -0
  142. package/dist/opencode/OpenCodeEventStore.d.ts +25 -0
  143. package/dist/opencode/OpenCodeEventStore.d.ts.map +1 -0
  144. package/dist/opencode/OpenCodeEventStore.js +182 -0
  145. package/dist/opencode/OpenCodeEventStore.js.map +1 -0
  146. package/dist/opencode/agent-sessions.d.ts +46 -0
  147. package/dist/opencode/agent-sessions.d.ts.map +1 -0
  148. package/dist/opencode/agent-sessions.js +302 -0
  149. package/dist/opencode/agent-sessions.js.map +1 -0
  150. package/dist/opencode/index.d.ts +6 -0
  151. package/dist/opencode/index.d.ts.map +1 -0
  152. package/dist/opencode/index.js +15 -0
  153. package/dist/opencode/index.js.map +1 -0
  154. package/dist/opencode/node-path-adapter.d.ts +25 -0
  155. package/dist/opencode/node-path-adapter.d.ts.map +1 -0
  156. package/dist/opencode/node-path-adapter.js +188 -0
  157. package/dist/opencode/node-path-adapter.js.map +1 -0
  158. package/dist/opencode/pipeline.d.ts +42 -0
  159. package/dist/opencode/pipeline.d.ts.map +1 -0
  160. package/dist/opencode/pipeline.js +90 -0
  161. package/dist/opencode/pipeline.js.map +1 -0
  162. package/dist/opencode/types.d.ts +39 -0
  163. package/dist/opencode/types.d.ts.map +1 -0
  164. package/dist/opencode/types.js +3 -0
  165. package/dist/opencode/types.js.map +1 -0
  166. package/dist/orchestration/TraceOrchestrator.d.ts +71 -0
  167. package/dist/orchestration/TraceOrchestrator.d.ts.map +1 -0
  168. package/dist/orchestration/TraceOrchestrator.js +416 -0
  169. package/dist/orchestration/TraceOrchestrator.js.map +1 -0
  170. package/dist/parsers/OtlpTraceParser.d.ts +131 -0
  171. package/dist/parsers/OtlpTraceParser.d.ts.map +1 -0
  172. package/dist/parsers/OtlpTraceParser.js +310 -0
  173. package/dist/parsers/OtlpTraceParser.js.map +1 -0
  174. package/dist/registry/CompositeRegistry.d.ts +71 -0
  175. package/dist/registry/CompositeRegistry.d.ts.map +1 -0
  176. package/dist/registry/CompositeRegistry.js +113 -0
  177. package/dist/registry/CompositeRegistry.js.map +1 -0
  178. package/dist/registry/EventRegistry.d.ts +79 -0
  179. package/dist/registry/EventRegistry.d.ts.map +1 -0
  180. package/dist/registry/EventRegistry.js +165 -0
  181. package/dist/registry/EventRegistry.js.map +1 -0
  182. package/dist/registry/LocalRegistry.d.ts +111 -0
  183. package/dist/registry/LocalRegistry.d.ts.map +1 -0
  184. package/dist/registry/LocalRegistry.js +335 -0
  185. package/dist/registry/LocalRegistry.js.map +1 -0
  186. package/dist/registry/RemoteRegistry.d.ts +122 -0
  187. package/dist/registry/RemoteRegistry.d.ts.map +1 -0
  188. package/dist/registry/RemoteRegistry.js +399 -0
  189. package/dist/registry/RemoteRegistry.js.map +1 -0
  190. package/dist/registry/VersionRegistry.d.ts +51 -0
  191. package/dist/registry/VersionRegistry.d.ts.map +1 -0
  192. package/dist/registry/VersionRegistry.js +105 -0
  193. package/dist/registry/VersionRegistry.js.map +1 -0
  194. package/dist/rules/config.d.ts +57 -0
  195. package/dist/rules/config.d.ts.map +1 -0
  196. package/dist/rules/config.js +382 -0
  197. package/dist/rules/config.js.map +1 -0
  198. package/dist/rules/engine.d.ts +70 -0
  199. package/dist/rules/engine.d.ts.map +1 -0
  200. package/dist/rules/engine.js +373 -0
  201. package/dist/rules/engine.js.map +1 -0
  202. package/dist/rules/implementations/connection-type-references.d.ts +7 -0
  203. package/dist/rules/implementations/connection-type-references.d.ts.map +1 -0
  204. package/dist/rules/implementations/connection-type-references.js +107 -0
  205. package/dist/rules/implementations/connection-type-references.js.map +1 -0
  206. package/dist/rules/implementations/dead-end-states.d.ts +17 -0
  207. package/dist/rules/implementations/dead-end-states.d.ts.map +1 -0
  208. package/dist/rules/implementations/dead-end-states.js +75 -0
  209. package/dist/rules/implementations/dead-end-states.js.map +1 -0
  210. package/dist/rules/implementations/index.d.ts +23 -0
  211. package/dist/rules/implementations/index.d.ts.map +1 -0
  212. package/dist/rules/implementations/index.js +73 -0
  213. package/dist/rules/implementations/index.js.map +1 -0
  214. package/dist/rules/implementations/minimum-node-sources.d.ts +24 -0
  215. package/dist/rules/implementations/minimum-node-sources.d.ts.map +1 -0
  216. package/dist/rules/implementations/minimum-node-sources.js +59 -0
  217. package/dist/rules/implementations/minimum-node-sources.js.map +1 -0
  218. package/dist/rules/implementations/no-unknown-fields.d.ts +7 -0
  219. package/dist/rules/implementations/no-unknown-fields.d.ts.map +1 -0
  220. package/dist/rules/implementations/no-unknown-fields.js +216 -0
  221. package/dist/rules/implementations/no-unknown-fields.js.map +1 -0
  222. package/dist/rules/implementations/orphaned-edge-types.d.ts +7 -0
  223. package/dist/rules/implementations/orphaned-edge-types.d.ts.map +1 -0
  224. package/dist/rules/implementations/orphaned-edge-types.js +50 -0
  225. package/dist/rules/implementations/orphaned-edge-types.js.map +1 -0
  226. package/dist/rules/implementations/orphaned-node-types.d.ts +7 -0
  227. package/dist/rules/implementations/orphaned-node-types.d.ts.map +1 -0
  228. package/dist/rules/implementations/orphaned-node-types.js +53 -0
  229. package/dist/rules/implementations/orphaned-node-types.js.map +1 -0
  230. package/dist/rules/implementations/required-metadata.d.ts +7 -0
  231. package/dist/rules/implementations/required-metadata.d.ts.map +1 -0
  232. package/dist/rules/implementations/required-metadata.js +48 -0
  233. package/dist/rules/implementations/required-metadata.js.map +1 -0
  234. package/dist/rules/implementations/state-transition-references.d.ts +7 -0
  235. package/dist/rules/implementations/state-transition-references.d.ts.map +1 -0
  236. package/dist/rules/implementations/state-transition-references.js +138 -0
  237. package/dist/rules/implementations/state-transition-references.js.map +1 -0
  238. package/dist/rules/implementations/unreachable-states.d.ts +7 -0
  239. package/dist/rules/implementations/unreachable-states.d.ts.map +1 -0
  240. package/dist/rules/implementations/unreachable-states.js +83 -0
  241. package/dist/rules/implementations/unreachable-states.js.map +1 -0
  242. package/dist/rules/implementations/valid-action-patterns.d.ts +17 -0
  243. package/dist/rules/implementations/valid-action-patterns.d.ts.map +1 -0
  244. package/dist/rules/implementations/valid-action-patterns.js +112 -0
  245. package/dist/rules/implementations/valid-action-patterns.js.map +1 -0
  246. package/dist/rules/implementations/valid-color-format.d.ts +7 -0
  247. package/dist/rules/implementations/valid-color-format.d.ts.map +1 -0
  248. package/dist/rules/implementations/valid-color-format.js +94 -0
  249. package/dist/rules/implementations/valid-color-format.js.map +1 -0
  250. package/dist/rules/implementations/valid-edge-types.d.ts +7 -0
  251. package/dist/rules/implementations/valid-edge-types.d.ts.map +1 -0
  252. package/dist/rules/implementations/valid-edge-types.js +248 -0
  253. package/dist/rules/implementations/valid-edge-types.js.map +1 -0
  254. package/dist/rules/implementations/valid-node-types.d.ts +7 -0
  255. package/dist/rules/implementations/valid-node-types.d.ts.map +1 -0
  256. package/dist/rules/implementations/valid-node-types.js +187 -0
  257. package/dist/rules/implementations/valid-node-types.js.map +1 -0
  258. package/dist/rules/index.d.ts +28 -0
  259. package/dist/rules/index.d.ts.map +1 -0
  260. package/dist/rules/index.js +70 -0
  261. package/dist/rules/index.js.map +1 -0
  262. package/dist/rules/types.d.ts +309 -0
  263. package/dist/rules/types.d.ts.map +1 -0
  264. package/dist/rules/types.js +40 -0
  265. package/dist/rules/types.js.map +1 -0
  266. package/dist/scopes/ScopePathIndex.d.ts +56 -0
  267. package/dist/scopes/ScopePathIndex.d.ts.map +1 -0
  268. package/dist/scopes/ScopePathIndex.js +67 -0
  269. package/dist/scopes/ScopePathIndex.js.map +1 -0
  270. package/dist/scopes/ScopesCanvasValidator.d.ts +76 -0
  271. package/dist/scopes/ScopesCanvasValidator.d.ts.map +1 -0
  272. package/dist/scopes/ScopesCanvasValidator.js +221 -0
  273. package/dist/scopes/ScopesCanvasValidator.js.map +1 -0
  274. package/dist/scopes/index.d.ts +12 -0
  275. package/dist/scopes/index.d.ts.map +1 -0
  276. package/dist/scopes/index.js +30 -0
  277. package/dist/scopes/index.js.map +1 -0
  278. package/dist/scopes/utils.d.ts +85 -0
  279. package/dist/scopes/utils.d.ts.map +1 -0
  280. package/dist/scopes/utils.js +143 -0
  281. package/dist/scopes/utils.js.map +1 -0
  282. package/dist/scopes/validateScopeNamespaceNesting.d.ts +38 -0
  283. package/dist/scopes/validateScopeNamespaceNesting.d.ts.map +1 -0
  284. package/dist/scopes/validateScopeNamespaceNesting.js +69 -0
  285. package/dist/scopes/validateScopeNamespaceNesting.js.map +1 -0
  286. package/dist/spans/index.d.ts +12 -0
  287. package/dist/spans/index.d.ts.map +1 -0
  288. package/dist/spans/index.js +25 -0
  289. package/dist/spans/index.js.map +1 -0
  290. package/dist/spans/utils.d.ts +70 -0
  291. package/dist/spans/utils.d.ts.map +1 -0
  292. package/dist/spans/utils.js +205 -0
  293. package/dist/spans/utils.js.map +1 -0
  294. package/dist/storage/topic-types.d.ts +203 -0
  295. package/dist/storage/topic-types.d.ts.map +1 -0
  296. package/dist/storage/topic-types.js +60 -0
  297. package/dist/storage/topic-types.js.map +1 -0
  298. package/dist/storage/topicStore.d.ts +135 -0
  299. package/dist/storage/topicStore.d.ts.map +1 -0
  300. package/dist/storage/topicStore.js +389 -0
  301. package/dist/storage/topicStore.js.map +1 -0
  302. package/dist/storyboard/builder.d.ts +135 -0
  303. package/dist/storyboard/builder.d.ts.map +1 -0
  304. package/dist/storyboard/builder.js +235 -0
  305. package/dist/storyboard/builder.js.map +1 -0
  306. package/dist/storyboard/index.d.ts +9 -0
  307. package/dist/storyboard/index.d.ts.map +1 -0
  308. package/dist/storyboard/index.js +18 -0
  309. package/dist/storyboard/index.js.map +1 -0
  310. package/dist/storyboard/types.d.ts +101 -0
  311. package/dist/storyboard/types.d.ts.map +1 -0
  312. package/dist/storyboard/types.js +10 -0
  313. package/dist/storyboard/types.js.map +1 -0
  314. package/dist/telemetry/coverage.d.ts +92 -0
  315. package/dist/telemetry/coverage.d.ts.map +1 -0
  316. package/dist/telemetry/coverage.js +335 -0
  317. package/dist/telemetry/coverage.js.map +1 -0
  318. package/dist/telemetry/event-validator.d.ts +86 -0
  319. package/dist/telemetry/event-validator.d.ts.map +1 -0
  320. package/dist/telemetry/event-validator.js +257 -0
  321. package/dist/telemetry/event-validator.js.map +1 -0
  322. package/dist/types/audit.d.ts +236 -0
  323. package/dist/types/audit.d.ts.map +1 -0
  324. package/dist/types/audit.js +53 -0
  325. package/dist/types/audit.js.map +1 -0
  326. package/dist/types/auxiliary.d.ts +54 -0
  327. package/dist/types/auxiliary.d.ts.map +1 -0
  328. package/dist/types/auxiliary.js +27 -0
  329. package/dist/types/auxiliary.js.map +1 -0
  330. package/dist/types/canvas-scope.d.ts +156 -0
  331. package/dist/types/canvas-scope.d.ts.map +1 -0
  332. package/dist/types/canvas-scope.js +62 -0
  333. package/dist/types/canvas-scope.js.map +1 -0
  334. package/dist/types/canvas.d.ts +1138 -0
  335. package/dist/types/canvas.d.ts.map +1 -0
  336. package/dist/types/canvas.js +178 -0
  337. package/dist/types/canvas.js.map +1 -0
  338. package/dist/types/dashboard.d.ts +170 -0
  339. package/dist/types/dashboard.d.ts.map +1 -0
  340. package/dist/types/dashboard.js +14 -0
  341. package/dist/types/dashboard.js.map +1 -0
  342. package/dist/types/index.d.ts +352 -0
  343. package/dist/types/index.d.ts.map +1 -0
  344. package/dist/types/index.js +39 -0
  345. package/dist/types/index.js.map +1 -0
  346. package/dist/types/library.d.ts +227 -0
  347. package/dist/types/library.d.ts.map +1 -0
  348. package/dist/types/library.js +16 -0
  349. package/dist/types/library.js.map +1 -0
  350. package/dist/types/otel.d.ts +465 -0
  351. package/dist/types/otel.d.ts.map +1 -0
  352. package/dist/types/otel.js +163 -0
  353. package/dist/types/otel.js.map +1 -0
  354. package/dist/types/path-based-config.d.ts +235 -0
  355. package/dist/types/path-based-config.d.ts.map +1 -0
  356. package/dist/types/path-based-config.js +11 -0
  357. package/dist/types/path-based-config.js.map +1 -0
  358. package/dist/types/registered-trace.d.ts +337 -0
  359. package/dist/types/registered-trace.d.ts.map +1 -0
  360. package/dist/types/registered-trace.js +16 -0
  361. package/dist/types/registered-trace.js.map +1 -0
  362. package/dist/types/resource-match.d.ts +207 -0
  363. package/dist/types/resource-match.d.ts.map +1 -0
  364. package/dist/types/resource-match.js +74 -0
  365. package/dist/types/resource-match.js.map +1 -0
  366. package/dist/types/subsystem-model.d.ts +265 -0
  367. package/dist/types/subsystem-model.d.ts.map +1 -0
  368. package/dist/types/subsystem-model.js +35 -0
  369. package/dist/types/subsystem-model.js.map +1 -0
  370. package/dist/types/version-registry.d.ts +137 -0
  371. package/dist/types/version-registry.d.ts.map +1 -0
  372. package/dist/types/version-registry.js +10 -0
  373. package/dist/types/version-registry.js.map +1 -0
  374. package/dist/utils/CanvasConverter.d.ts +148 -0
  375. package/dist/utils/CanvasConverter.d.ts.map +1 -0
  376. package/dist/utils/CanvasConverter.js +530 -0
  377. package/dist/utils/CanvasConverter.js.map +1 -0
  378. package/dist/utils/GraphConverter.d.ts +18 -0
  379. package/dist/utils/GraphConverter.d.ts.map +1 -0
  380. package/dist/utils/GraphConverter.js +80 -0
  381. package/dist/utils/GraphConverter.js.map +1 -0
  382. package/dist/utils/PathMatcher.d.ts +55 -0
  383. package/dist/utils/PathMatcher.d.ts.map +1 -0
  384. package/dist/utils/PathMatcher.js +178 -0
  385. package/dist/utils/PathMatcher.js.map +1 -0
  386. package/dist/utils/TraceToCanvas.d.ts +83 -0
  387. package/dist/utils/TraceToCanvas.d.ts.map +1 -0
  388. package/dist/utils/TraceToCanvas.js +336 -0
  389. package/dist/utils/TraceToCanvas.js.map +1 -0
  390. package/dist/utils/YamlParser.d.ts +36 -0
  391. package/dist/utils/YamlParser.d.ts.map +1 -0
  392. package/dist/utils/YamlParser.js +92 -0
  393. package/dist/utils/YamlParser.js.map +1 -0
  394. package/dist/utils/registeredTraceHelpers.d.ts +76 -0
  395. package/dist/utils/registeredTraceHelpers.d.ts.map +1 -0
  396. package/dist/utils/registeredTraceHelpers.js +203 -0
  397. package/dist/utils/registeredTraceHelpers.js.map +1 -0
  398. package/dist/utils/traceAggregation.d.ts +25 -0
  399. package/dist/utils/traceAggregation.d.ts.map +1 -0
  400. package/dist/utils/traceAggregation.js +140 -0
  401. package/dist/utils/traceAggregation.js.map +1 -0
  402. package/dist/validation/OtelCanvasValidator.d.ts +40 -0
  403. package/dist/validation/OtelCanvasValidator.d.ts.map +1 -0
  404. package/dist/validation/OtelCanvasValidator.js +59 -0
  405. package/dist/validation/OtelCanvasValidator.js.map +1 -0
  406. package/dist/validation/index.d.ts +8 -0
  407. package/dist/validation/index.d.ts.map +1 -0
  408. package/dist/validation/index.js +13 -0
  409. package/dist/validation/index.js.map +1 -0
  410. package/dist/validation/libraryValidation.d.ts +53 -0
  411. package/dist/validation/libraryValidation.d.ts.map +1 -0
  412. package/dist/validation/libraryValidation.js +115 -0
  413. package/dist/validation/libraryValidation.js.map +1 -0
  414. package/dist/workflow/edge-derivation.d.ts +111 -0
  415. package/dist/workflow/edge-derivation.d.ts.map +1 -0
  416. package/dist/workflow/edge-derivation.js +174 -0
  417. package/dist/workflow/edge-derivation.js.map +1 -0
  418. package/dist/workflow/edge-validation.d.ts +170 -0
  419. package/dist/workflow/edge-validation.d.ts.map +1 -0
  420. package/dist/workflow/edge-validation.js +332 -0
  421. package/dist/workflow/edge-validation.js.map +1 -0
  422. package/dist/workflow/example.d.ts +11 -0
  423. package/dist/workflow/example.d.ts.map +1 -0
  424. package/dist/workflow/example.js +310 -0
  425. package/dist/workflow/example.js.map +1 -0
  426. package/dist/workflow/index.d.ts +20 -0
  427. package/dist/workflow/index.d.ts.map +1 -0
  428. package/dist/workflow/index.js +49 -0
  429. package/dist/workflow/index.js.map +1 -0
  430. package/dist/workflow/scenario-matcher.d.ts +63 -0
  431. package/dist/workflow/scenario-matcher.d.ts.map +1 -0
  432. package/dist/workflow/scenario-matcher.js +215 -0
  433. package/dist/workflow/scenario-matcher.js.map +1 -0
  434. package/dist/workflow/template-parser.d.ts +73 -0
  435. package/dist/workflow/template-parser.d.ts.map +1 -0
  436. package/dist/workflow/template-parser.js +280 -0
  437. package/dist/workflow/template-parser.js.map +1 -0
  438. package/dist/workflow/template-renderer.d.ts +45 -0
  439. package/dist/workflow/template-renderer.d.ts.map +1 -0
  440. package/dist/workflow/template-renderer.js +401 -0
  441. package/dist/workflow/template-renderer.js.map +1 -0
  442. package/dist/workflow/types.d.ts +393 -0
  443. package/dist/workflow/types.d.ts.map +1 -0
  444. package/dist/workflow/types.js +40 -0
  445. package/dist/workflow/types.js.map +1 -0
  446. package/dist/workflow/validator.d.ts +363 -0
  447. package/dist/workflow/validator.d.ts.map +1 -0
  448. package/dist/workflow/validator.js +2283 -0
  449. package/dist/workflow/validator.js.map +1 -0
  450. package/package.json +84 -0
  451. package/schemas/auxiliary.manifest.schema.json +56 -0
  452. package/schemas/subsystem-model.schema.json +767 -0
  453. package/src/ConfigurationLoader.test.ts +466 -0
  454. package/src/ConfigurationLoader.ts +184 -0
  455. package/src/ConfigurationValidator.test.ts +200 -0
  456. package/src/ConfigurationValidator.ts +273 -0
  457. package/src/EventProcessor.test.ts +405 -0
  458. package/src/EventProcessor.ts +256 -0
  459. package/src/EventRecorderService.test.ts +543 -0
  460. package/src/EventRecorderService.ts +741 -0
  461. package/src/LibraryLoader.ts +194 -0
  462. package/src/PathBasedEventProcessor.test.ts +336 -0
  463. package/src/PathBasedEventProcessor.ts +196 -0
  464. package/src/SessionManager.test.ts +424 -0
  465. package/src/SessionManager.ts +471 -0
  466. package/src/ValidationEngine.test.ts +520 -0
  467. package/src/ValidationEngine.ts +200 -0
  468. package/src/agent-sessions/fixture.ts +225 -0
  469. package/src/agent-sessions/index.ts +10 -0
  470. package/src/auxiliary/AuxiliaryManifestValidator.test.ts +93 -0
  471. package/src/auxiliary/AuxiliaryManifestValidator.ts +132 -0
  472. package/src/auxiliary/index.ts +18 -0
  473. package/src/auxiliary/validateAreaScopeDisjoint.test.ts +85 -0
  474. package/src/auxiliary/validateAreaScopeDisjoint.ts +72 -0
  475. package/src/browser-safety.test.ts +170 -0
  476. package/src/cli/codegen.ts +286 -0
  477. package/src/codegen/type-generator.test.ts +219 -0
  478. package/src/codegen/type-generator.ts +560 -0
  479. package/src/codegen/usage-example.ts +357 -0
  480. package/src/dashboard/DashboardValidator.ts +904 -0
  481. package/src/dashboard/index.ts +14 -0
  482. package/src/discovery/CanvasDiscovery.test.ts +691 -0
  483. package/src/discovery/CanvasDiscovery.ts +1114 -0
  484. package/src/discovery/CanvasFileManifest.test.ts +521 -0
  485. package/src/discovery/CanvasFileManifest.ts +419 -0
  486. package/src/discovery/LibraryDiscovery.test.ts +329 -0
  487. package/src/discovery/LibraryDiscovery.ts +386 -0
  488. package/src/discovery/types.ts +453 -0
  489. package/src/events/EventsCanvasValidator.test.ts +191 -0
  490. package/src/events/EventsCanvasValidator.ts +428 -0
  491. package/src/events/NamespacePathIndex.test.ts +97 -0
  492. package/src/events/NamespacePathIndex.ts +100 -0
  493. package/src/events/OtelEventPathsValidator.test.ts +243 -0
  494. package/src/events/OtelEventPathsValidator.ts +191 -0
  495. package/src/events/ScopeEventsValidator.test.ts +173 -0
  496. package/src/events/ScopeEventsValidator.ts +158 -0
  497. package/src/events/index.ts +27 -0
  498. package/src/events/path-helpers.ts +53 -0
  499. package/src/execution/ExecutionLoader.test.ts +378 -0
  500. package/src/execution/ExecutionLoader.ts +331 -0
  501. package/src/execution/ExecutionValidator.test.ts +503 -0
  502. package/src/execution/ExecutionValidator.ts +617 -0
  503. package/src/generated/graph-converter-execution.types.ts +193 -0
  504. package/src/helpers/GraphInstrumentationHelper.test.ts +364 -0
  505. package/src/helpers/GraphInstrumentationHelper.ts +323 -0
  506. package/src/index.ts +587 -0
  507. package/src/matchers/SpanMatcher.test.ts +1105 -0
  508. package/src/matchers/SpanMatcher.ts +381 -0
  509. package/src/node.ts +316 -0
  510. package/src/opencode/EVENT_MAPPING.md +82 -0
  511. package/src/opencode/OpenCodeEventStore.ts +214 -0
  512. package/src/opencode/__fixtures__/event-shapes.json +443 -0
  513. package/src/opencode/__fixtures__/session-events.json +13491 -0
  514. package/src/opencode/agent-sessions.ts +376 -0
  515. package/src/opencode/index.ts +23 -0
  516. package/src/opencode/node-path-adapter.ts +205 -0
  517. package/src/opencode/pipeline.ts +141 -0
  518. package/src/opencode/types.ts +43 -0
  519. package/src/orchestration/TraceOrchestrator.ts +560 -0
  520. package/src/orchestration/__tests__/TraceOrchestrator.test.ts +1098 -0
  521. package/src/parsers/OtlpTraceParser.ts +401 -0
  522. package/src/parsers/__tests__/OtlpTraceParser.test.ts +197 -0
  523. package/src/registry/CompositeRegistry.ts +140 -0
  524. package/src/registry/EventRegistry.test.ts +387 -0
  525. package/src/registry/EventRegistry.ts +191 -0
  526. package/src/registry/LocalRegistry.ts +416 -0
  527. package/src/registry/RemoteRegistry.ts +499 -0
  528. package/src/registry/VersionRegistry.test.ts +223 -0
  529. package/src/registry/VersionRegistry.ts +121 -0
  530. package/src/rules/config.test.ts +277 -0
  531. package/src/rules/config.ts +450 -0
  532. package/src/rules/engine.test.ts +331 -0
  533. package/src/rules/engine.ts +448 -0
  534. package/src/rules/implementations/connection-type-references.ts +117 -0
  535. package/src/rules/implementations/dead-end-states.ts +101 -0
  536. package/src/rules/implementations/index.ts +66 -0
  537. package/src/rules/implementations/minimum-node-sources.ts +84 -0
  538. package/src/rules/implementations/no-unknown-fields.ts +372 -0
  539. package/src/rules/implementations/orphaned-edge-types.ts +55 -0
  540. package/src/rules/implementations/orphaned-node-types.ts +58 -0
  541. package/src/rules/implementations/required-metadata.ts +52 -0
  542. package/src/rules/implementations/state-transition-references.ts +155 -0
  543. package/src/rules/implementations/unreachable-states.ts +94 -0
  544. package/src/rules/implementations/valid-action-patterns.ts +140 -0
  545. package/src/rules/implementations/valid-color-format.ts +152 -0
  546. package/src/rules/implementations/valid-edge-types.ts +273 -0
  547. package/src/rules/implementations/valid-node-types.ts +200 -0
  548. package/src/rules/index.ts +92 -0
  549. package/src/rules/types.ts +426 -0
  550. package/src/scopes/ScopePathIndex.test.ts +94 -0
  551. package/src/scopes/ScopePathIndex.ts +89 -0
  552. package/src/scopes/ScopesCanvasValidator.test.ts +127 -0
  553. package/src/scopes/ScopesCanvasValidator.ts +305 -0
  554. package/src/scopes/__tests__/utils.test.ts +383 -0
  555. package/src/scopes/index.ts +42 -0
  556. package/src/scopes/utils.ts +182 -0
  557. package/src/scopes/validateScopeNamespaceNesting.test.ts +127 -0
  558. package/src/scopes/validateScopeNamespaceNesting.ts +88 -0
  559. package/src/spans/index.ts +24 -0
  560. package/src/spans/utils.ts +249 -0
  561. package/src/storage/topic-types.ts +235 -0
  562. package/src/storage/topicStore.test.ts +193 -0
  563. package/src/storage/topicStore.ts +489 -0
  564. package/src/storyboard/builder.ts +308 -0
  565. package/src/storyboard/index.ts +26 -0
  566. package/src/storyboard/types.ts +117 -0
  567. package/src/telemetry/coverage.ts +480 -0
  568. package/src/telemetry/event-validator.ts +312 -0
  569. package/src/types/audit.ts +314 -0
  570. package/src/types/auxiliary.ts +63 -0
  571. package/src/types/canvas-scope.ts +190 -0
  572. package/src/types/canvas.test.ts +199 -0
  573. package/src/types/canvas.ts +1395 -0
  574. package/src/types/dashboard.ts +257 -0
  575. package/src/types/index.ts +460 -0
  576. package/src/types/library.ts +283 -0
  577. package/src/types/otel.test.ts +219 -0
  578. package/src/types/otel.ts +620 -0
  579. package/src/types/path-based-config.ts +285 -0
  580. package/src/types/registered-trace.ts +432 -0
  581. package/src/types/resource-match.ts +263 -0
  582. package/src/types/subsystem-model.ts +352 -0
  583. package/src/types/version-registry.ts +150 -0
  584. package/src/utils/CanvasConverter.ts +670 -0
  585. package/src/utils/GraphConverter.test.ts +322 -0
  586. package/src/utils/GraphConverter.ts +84 -0
  587. package/src/utils/PathMatcher.test.ts +139 -0
  588. package/src/utils/PathMatcher.ts +185 -0
  589. package/src/utils/TraceToCanvas.test.ts +310 -0
  590. package/src/utils/TraceToCanvas.ts +510 -0
  591. package/src/utils/YamlParser.ts +77 -0
  592. package/src/utils/registeredTraceHelpers.ts +251 -0
  593. package/src/utils/traceAggregation.test.ts +385 -0
  594. package/src/utils/traceAggregation.ts +173 -0
  595. package/src/validation/OtelCanvasValidator.ts +86 -0
  596. package/src/validation/index.ts +17 -0
  597. package/src/validation/libraryValidation.ts +206 -0
  598. package/src/workflow/README.md +408 -0
  599. package/src/workflow/__tests__/edge-derivation.test.ts +449 -0
  600. package/src/workflow/__tests__/edge-validation.test.ts +417 -0
  601. package/src/workflow/__tests__/scenario-matcher.test.ts +225 -0
  602. package/src/workflow/__tests__/template-parser.test.ts +276 -0
  603. package/src/workflow/__tests__/template-renderer.test.ts +509 -0
  604. package/src/workflow/__tests__/types.test.ts +187 -0
  605. package/src/workflow/__tests__/validator.test.ts +3225 -0
  606. package/src/workflow/edge-derivation.ts +265 -0
  607. package/src/workflow/edge-validation.ts +503 -0
  608. package/src/workflow/example.ts +330 -0
  609. package/src/workflow/index.ts +86 -0
  610. package/src/workflow/scenario-matcher.ts +253 -0
  611. package/src/workflow/template-parser.ts +350 -0
  612. package/src/workflow/template-renderer.ts +453 -0
  613. package/src/workflow/types.ts +511 -0
  614. package/src/workflow/validator.ts +2737 -0
@@ -0,0 +1,560 @@
1
+ /**
2
+ * Type Generator
3
+ *
4
+ * Generates TypeScript types from canvas event schemas.
5
+ * Similar to how GraphQL Code Generator works for GraphQL schemas,
6
+ * or how OpenAPI generators work for API specs.
7
+ *
8
+ * Precedents:
9
+ * - GraphQL Code Generator: graphql-code-generator.com
10
+ * - OpenAPI Generator: openapi-generator.tech
11
+ * - Protobuf: generates code from .proto files
12
+ * - Zod: runtime validation with TypeScript inference
13
+ */
14
+
15
+ import type { ExtendedCanvas, PVEventSchema, PVEventFieldSchema, ExtendedCanvasNode } from '../types/canvas';
16
+ import { isOtelEventNode, isStandardCanvasNode } from '../types/canvas';
17
+ import type { ComponentLibrary } from '../types/library';
18
+
19
+ /**
20
+ * Code generation options
21
+ */
22
+ export interface CodegenOptions {
23
+ /** Output language (extensible for future languages) */
24
+ language: 'typescript' | 'python' | 'go' | 'rust';
25
+ /** Style preferences */
26
+ style?: {
27
+ /** Use readonly for immutable types */
28
+ readonly?: boolean;
29
+ /** Use strict null checks */
30
+ strictNullChecks?: boolean;
31
+ /** Generate JSDoc comments */
32
+ includeDocComments?: boolean;
33
+ };
34
+ /** Namespace/module name */
35
+ namespace?: string;
36
+ }
37
+
38
+ /**
39
+ * Generated code result
40
+ */
41
+ export interface CodegenResult {
42
+ /** Generated code content */
43
+ code: string;
44
+ /** File extension for the language */
45
+ extension: string;
46
+ /** Suggested filename */
47
+ filename: string;
48
+ }
49
+
50
+ /**
51
+ * Abstract code generator interface
52
+ *
53
+ * This allows us to implement generators for different languages
54
+ * following the same pattern as OpenAPI generators.
55
+ */
56
+ export interface CodeGenerator {
57
+ /** Target language */
58
+ language: string;
59
+ /** Generate code from canvas */
60
+ generate(canvas: ExtendedCanvas, options?: CodegenOptions, library?: ComponentLibrary): CodegenResult;
61
+ }
62
+
63
+ /**
64
+ * TypeScript Type Generator
65
+ *
66
+ * Generates TypeScript types from canvas event schemas.
67
+ * Similar to GraphQL Code Generator but for canvas schemas.
68
+ */
69
+ export class TypeScriptGenerator implements CodeGenerator {
70
+ language = 'typescript';
71
+
72
+ generate(canvas: ExtendedCanvas, options?: CodegenOptions, library?: ComponentLibrary): CodegenResult {
73
+ const opts = {
74
+ readonly: options?.style?.readonly ?? false,
75
+ strictNullChecks: options?.style?.strictNullChecks ?? true,
76
+ includeDocComments: options?.style?.includeDocComments ?? true,
77
+ namespace: options?.namespace,
78
+ };
79
+
80
+ const lines: string[] = [];
81
+
82
+ // File header
83
+ lines.push('/**');
84
+ lines.push(` * Generated types from canvas: ${canvas.name || canvas.pv?.name || 'Untitled'}`);
85
+ lines.push(' *');
86
+ lines.push(' * DO NOT EDIT MANUALLY - This file is auto-generated');
87
+ lines.push(' * Generated by @principal-ai/subsystems-core');
88
+ lines.push(' *');
89
+ lines.push(` * Canvas: ${canvas.pv?.description || 'No description'}`);
90
+ lines.push(' */');
91
+ lines.push('');
92
+
93
+ // Namespace (if specified)
94
+ if (opts.namespace) {
95
+ lines.push(`export namespace ${opts.namespace} {`);
96
+ }
97
+
98
+ // Group nodes by base ID (strip numeric suffixes like -1, -2, etc.)
99
+ // This allows multiple nodes representing states of the same component
100
+ // to be grouped into a single namespace
101
+ if (canvas.nodes) {
102
+ const nodeGroups = new Map<string, Array<{ nodeId: string; eventSchema: PVEventSchema }>>();
103
+
104
+ for (const node of canvas.nodes) {
105
+ let eventSchema: PVEventSchema | undefined;
106
+
107
+ // Check for OTEL event node (top-level event/eventRef fields)
108
+ if (isOtelEventNode(node)) {
109
+ if (node.event) {
110
+ eventSchema = node.event;
111
+ } else if (node.eventRef) {
112
+ eventSchema = this.resolveLibraryEvent(node.eventRef, library);
113
+ if (!eventSchema) {
114
+ console.warn(
115
+ `Node '${node.id}' references unknown library event '${node.eventRef}'`
116
+ );
117
+ continue;
118
+ }
119
+ }
120
+ }
121
+ // Check for standard node with pv.event/pv.eventRef
122
+ else if (isStandardCanvasNode(node)) {
123
+ if (node.pv?.event) {
124
+ eventSchema = node.pv.event;
125
+ } else if (node.pv?.eventRef) {
126
+ eventSchema = this.resolveLibraryEvent(node.pv.eventRef, library);
127
+ if (!eventSchema) {
128
+ console.warn(
129
+ `Node '${node.id}' references unknown library event '${node.pv.eventRef}'`
130
+ );
131
+ continue;
132
+ }
133
+ }
134
+ }
135
+
136
+ if (eventSchema) {
137
+ // Group by base ID (e.g., "graph-converter-1" -> "graph-converter")
138
+ const baseId = node.id.replace(/-\d+$/, '');
139
+ if (!nodeGroups.has(baseId)) {
140
+ nodeGroups.set(baseId, []);
141
+ }
142
+ nodeGroups.get(baseId)!.push({ nodeId: node.id, eventSchema });
143
+ }
144
+ }
145
+
146
+ // Generate types for each component group
147
+ for (const [baseId, nodes] of nodeGroups) {
148
+ lines.push(...this.generateComponentTypes(baseId, nodes, opts));
149
+ lines.push('');
150
+ }
151
+ }
152
+
153
+ // Generate union type of all event names
154
+ lines.push(...this.generateEventNameUnion(canvas, opts, library));
155
+ lines.push('');
156
+
157
+ // Generate event emitter helper type
158
+ lines.push(...this.generateEmitterTypes(canvas, opts));
159
+
160
+ // Close namespace
161
+ if (opts.namespace) {
162
+ lines.push('}');
163
+ }
164
+
165
+ const code = lines.join('\n');
166
+ const filename = this.generateFilename(canvas);
167
+
168
+ return {
169
+ code,
170
+ extension: 'ts',
171
+ filename,
172
+ };
173
+ }
174
+
175
+ /**
176
+ * Generate types for a component (group of related nodes)
177
+ * Groups multiple node instances (e.g., graph-converter-1, graph-converter-2)
178
+ * into a single namespace with all their events
179
+ */
180
+ private generateComponentTypes(
181
+ baseId: string,
182
+ nodes: Array<{ nodeId: string; eventSchema: PVEventSchema }>,
183
+ opts: { readonly: boolean; strictNullChecks: boolean; includeDocComments: boolean }
184
+ ): string[] {
185
+ const lines: string[] = [];
186
+ const typeName = this.nodeIdToTypeName(baseId);
187
+
188
+ if (opts.includeDocComments) {
189
+ lines.push(`/**`);
190
+ lines.push(` * Event types for component: ${baseId}`);
191
+ lines.push(` */`);
192
+ }
193
+
194
+ lines.push(`export namespace ${typeName} {`);
195
+
196
+ // Generate interface for each event in the component
197
+ const interfaceNames: string[] = [];
198
+ const eventNames: string[] = [];
199
+
200
+ for (const { eventSchema } of nodes) {
201
+ lines.push(...this.generateEventInterface(eventSchema.name, eventSchema, opts));
202
+ lines.push('');
203
+ interfaceNames.push(this.eventNameToTypeName(eventSchema.name));
204
+ eventNames.push(eventSchema.name);
205
+ }
206
+
207
+ // Export union of all event types
208
+ if (opts.includeDocComments) {
209
+ lines.push(' /**');
210
+ lines.push(` * All event types for ${baseId}`);
211
+ lines.push(' */');
212
+ }
213
+ if (interfaceNames.length === 1) {
214
+ lines.push(` export type Event = ${interfaceNames[0]};`);
215
+ } else {
216
+ lines.push(` export type Event = ${interfaceNames.join(' | ')};`);
217
+ }
218
+ lines.push('');
219
+
220
+ // Generate event name union
221
+ if (opts.includeDocComments) {
222
+ lines.push(' /**');
223
+ lines.push(` * All event names for ${baseId}`);
224
+ lines.push(' */');
225
+ }
226
+ if (eventNames.length === 1) {
227
+ lines.push(` export type EventName = '${eventNames[0]}';`);
228
+ } else {
229
+ lines.push(` export type EventName = ${eventNames.map(n => `'${n}'`).join(' | ')};`);
230
+ }
231
+
232
+ lines.push('}');
233
+
234
+ return lines;
235
+ }
236
+
237
+ private generateNodeTypes(
238
+ nodeId: string,
239
+ eventSchema: PVEventSchema,
240
+ opts: { readonly: boolean; strictNullChecks: boolean; includeDocComments: boolean }
241
+ ): string[] {
242
+ const lines: string[] = [];
243
+ const typeName = this.nodeIdToTypeName(nodeId);
244
+
245
+ if (opts.includeDocComments) {
246
+ lines.push(`/**`);
247
+ lines.push(` * Event type for node: ${nodeId}`);
248
+ lines.push(` */`);
249
+ }
250
+
251
+ lines.push(`export namespace ${typeName} {`);
252
+
253
+ // Generate interface for the single event
254
+ lines.push(...this.generateEventInterface(eventSchema.name, eventSchema, opts));
255
+ lines.push('');
256
+
257
+ // Export the event type directly (no union needed for single event)
258
+ const interfaceName = this.eventNameToTypeName(eventSchema.name);
259
+ lines.push(' /**');
260
+ lines.push(` * Event type for ${nodeId}`);
261
+ lines.push(' */');
262
+ lines.push(` export type Event = ${interfaceName};`);
263
+ lines.push('');
264
+
265
+ // Generate event name literal
266
+ lines.push(' /**');
267
+ lines.push(` * Event name for ${nodeId}`);
268
+ lines.push(' */');
269
+ lines.push(` export type EventName = '${eventSchema.name}';`);
270
+
271
+ lines.push('}');
272
+
273
+ return lines;
274
+ }
275
+
276
+ private generateEventInterface(
277
+ eventName: string,
278
+ schema: PVEventSchema,
279
+ opts: { readonly: boolean; strictNullChecks: boolean; includeDocComments: boolean }
280
+ ): string[] {
281
+ const lines: string[] = [];
282
+ const interfaceName = this.eventNameToTypeName(eventName);
283
+ const readonly = opts.readonly ? 'readonly ' : '';
284
+
285
+ if (opts.includeDocComments) {
286
+ lines.push(' /**');
287
+ lines.push(` * ${schema.description}`);
288
+ lines.push(' */');
289
+ }
290
+
291
+ lines.push(` export interface ${interfaceName} {`);
292
+
293
+ // Event name as literal type
294
+ lines.push(` ${readonly}name: '${eventName}';`);
295
+
296
+ // Attributes
297
+ lines.push(` ${readonly}attributes: {`);
298
+
299
+ for (const [fieldName, fieldSchema] of Object.entries(schema.attributes)) {
300
+ const optional = !fieldSchema.required && opts.strictNullChecks ? '?' : '';
301
+ const type = this.fieldTypeToTsType(fieldSchema);
302
+
303
+ if (opts.includeDocComments && fieldSchema.description) {
304
+ lines.push(` /** ${fieldSchema.description} */`);
305
+ }
306
+
307
+ lines.push(` ${readonly}'${fieldName}'${optional}: ${type};`);
308
+ }
309
+
310
+ lines.push(' };');
311
+ lines.push(' }');
312
+
313
+ return lines;
314
+ }
315
+
316
+ private generateEventNameUnion(
317
+ canvas: ExtendedCanvas,
318
+ opts: { includeDocComments: boolean },
319
+ library?: ComponentLibrary
320
+ ): string[] {
321
+ const lines: string[] = [];
322
+ const allEventNames = new Set<string>();
323
+
324
+ if (canvas.nodes) {
325
+ for (const node of canvas.nodes) {
326
+ // Check for OTEL event node (top-level event/eventRef fields)
327
+ if (isOtelEventNode(node)) {
328
+ if (node.event?.name) {
329
+ allEventNames.add(node.event.name);
330
+ } else if (node.eventRef) {
331
+ const eventSchema = this.resolveLibraryEvent(node.eventRef, library);
332
+ if (eventSchema) {
333
+ allEventNames.add(eventSchema.name);
334
+ }
335
+ }
336
+ }
337
+ // Check for standard node with pv.event/pv.eventRef
338
+ else if (isStandardCanvasNode(node)) {
339
+ if (node.pv?.event?.name) {
340
+ allEventNames.add(node.pv.event.name);
341
+ } else if (node.pv?.eventRef) {
342
+ const eventSchema = this.resolveLibraryEvent(node.pv.eventRef, library);
343
+ if (eventSchema) {
344
+ allEventNames.add(eventSchema.name);
345
+ }
346
+ }
347
+ }
348
+ }
349
+ }
350
+
351
+ if (allEventNames.size === 0) {
352
+ return lines;
353
+ }
354
+
355
+ if (opts.includeDocComments) {
356
+ lines.push('/**');
357
+ lines.push(' * Union of all event names in the canvas');
358
+ lines.push(' */');
359
+ }
360
+
361
+ lines.push(`export type AllEventNames = ${Array.from(allEventNames).map(n => `'${n}'`).join(' | ')};`);
362
+
363
+ return lines;
364
+ }
365
+
366
+ private generateEmitterTypes(
367
+ canvas: ExtendedCanvas,
368
+ opts: { includeDocComments: boolean }
369
+ ): string[] {
370
+ const lines: string[] = [];
371
+
372
+ if (opts.includeDocComments) {
373
+ lines.push('/**');
374
+ lines.push(' * Type-safe event emitter for a specific node');
375
+ lines.push(' *');
376
+ lines.push(' * @example');
377
+ lines.push(' * ```typescript');
378
+ lines.push(' * const emit: NodeEmitter<GraphConverter.EventName, GraphConverter.Event> = ...');
379
+ lines.push(" * emit('conversion.started', {");
380
+ lines.push(" * name: 'conversion.started',");
381
+ lines.push(' * attributes: { ... }');
382
+ lines.push(' * });');
383
+ lines.push(' * ```');
384
+ lines.push(' */');
385
+ }
386
+
387
+ lines.push('export type NodeEmitter<');
388
+ lines.push(' TEventName extends string,');
389
+ lines.push(' TEvent extends { name: TEventName; attributes: Record<string, any> }');
390
+ lines.push('> = (event: TEvent) => void;');
391
+ lines.push('');
392
+
393
+ if (opts.includeDocComments) {
394
+ lines.push('/**');
395
+ lines.push(' * Type-safe event emitter by event name');
396
+ lines.push(' *');
397
+ lines.push(' * @example');
398
+ lines.push(' * ```typescript');
399
+ lines.push(' * const emit: NodeEmitterByName<GraphConverter.Event> = ...');
400
+ lines.push(" * emit('conversion.started', {");
401
+ lines.push(" * 'config.nodeTypes': 2,");
402
+ lines.push(" * 'config.edgeTypes': 1");
403
+ lines.push(' * });');
404
+ lines.push(' * ```');
405
+ lines.push(' */');
406
+ }
407
+
408
+ lines.push('export type NodeEmitterByName<');
409
+ lines.push(' TEvent extends { name: string; attributes: Record<string, any> }');
410
+ lines.push('> = <TName extends TEvent[\'name\']>(');
411
+ lines.push(' eventName: TName,');
412
+ lines.push(' attributes: Extract<TEvent, { name: TName }>[\'attributes\']');
413
+ lines.push(') => void;');
414
+
415
+ return lines;
416
+ }
417
+
418
+ private nodeIdToTypeName(nodeId: string): string {
419
+ // Convert kebab-case or snake_case to PascalCase
420
+ return nodeId
421
+ .split(/[-_]/)
422
+ .map(part => part.charAt(0).toUpperCase() + part.slice(1))
423
+ .join('');
424
+ }
425
+
426
+ private eventNameToTypeName(eventName: string): string {
427
+ // Convert "conversion.started" to "ConversionStarted"
428
+ return eventName
429
+ .split('.')
430
+ .map(part => part.charAt(0).toUpperCase() + part.slice(1))
431
+ .join('');
432
+ }
433
+
434
+ private fieldTypeToTsType(fieldSchema: PVEventFieldSchema): string {
435
+ switch (fieldSchema.type) {
436
+ case 'string':
437
+ return 'string';
438
+ case 'number':
439
+ return 'number';
440
+ case 'boolean':
441
+ return 'boolean';
442
+ case 'array':
443
+ return 'any[]';
444
+ case 'object':
445
+ return 'Record<string, any>';
446
+ default:
447
+ return 'any';
448
+ }
449
+ }
450
+
451
+ private generateFilename(canvas: ExtendedCanvas): string {
452
+ const name = canvas.pv?.name || 'canvas';
453
+ // Convert to kebab-case
454
+ const kebab = name
455
+ .toLowerCase()
456
+ .replace(/\s+/g, '-')
457
+ .replace(/[^a-z0-9-]/g, '');
458
+ return `${kebab}.types.ts`;
459
+ }
460
+
461
+ /**
462
+ * Resolve an event schema from library by event name
463
+ */
464
+ private resolveLibraryEvent(eventName: string, library?: ComponentLibrary): PVEventSchema | undefined {
465
+ if (!library?.eventSchemas) {
466
+ return undefined;
467
+ }
468
+
469
+ const librarySchema = library.eventSchemas[eventName];
470
+ if (!librarySchema) {
471
+ return undefined;
472
+ }
473
+
474
+ // Convert library schema (without name) to full PVEventSchema
475
+ return {
476
+ name: eventName,
477
+ description: librarySchema.description,
478
+ attributes: librarySchema.attributes,
479
+ };
480
+ }
481
+ }
482
+
483
+ /**
484
+ * Generate types from canvas
485
+ *
486
+ * @example
487
+ * ```typescript
488
+ * import fs from 'fs';
489
+ * import { generateTypes } from '@principal-ai/subsystems-core';
490
+ *
491
+ * const canvas = JSON.parse(fs.readFileSync('my-flow.canvas', 'utf-8'));
492
+ * const result = generateTypes(canvas, { language: 'typescript' });
493
+ *
494
+ * fs.writeFileSync(result.filename, result.code);
495
+ * ```
496
+ */
497
+ export function generateTypes(
498
+ canvas: ExtendedCanvas,
499
+ options: CodegenOptions = { language: 'typescript' },
500
+ library?: ComponentLibrary
501
+ ): CodegenResult {
502
+ const generator = getGenerator(options.language);
503
+ return generator.generate(canvas, options, library);
504
+ }
505
+
506
+ /**
507
+ * Get code generator for a language
508
+ */
509
+ function getGenerator(language: CodegenOptions['language']): CodeGenerator {
510
+ switch (language) {
511
+ case 'typescript':
512
+ return new TypeScriptGenerator();
513
+ case 'python':
514
+ // TODO: Implement Python generator
515
+ throw new Error('Python generator not yet implemented. See TypeScriptGenerator as reference.');
516
+ case 'go':
517
+ // TODO: Implement Go generator
518
+ throw new Error('Go generator not yet implemented. See TypeScriptGenerator as reference.');
519
+ case 'rust':
520
+ // TODO: Implement Rust generator
521
+ throw new Error('Rust generator not yet implemented. See TypeScriptGenerator as reference.');
522
+ default:
523
+ throw new Error(`Unsupported language: ${language}`);
524
+ }
525
+ }
526
+
527
+ /**
528
+ * Registry of available generators
529
+ *
530
+ * This allows external packages to register custom generators:
531
+ *
532
+ * @example
533
+ * ```typescript
534
+ * import { generatorRegistry } from '@principal-ai/subsystems-core';
535
+ *
536
+ * class PythonGenerator implements CodeGenerator {
537
+ * language = 'python';
538
+ * generate(canvas, options) { ... }
539
+ * }
540
+ *
541
+ * generatorRegistry.register(new PythonGenerator());
542
+ * ```
543
+ */
544
+ export const generatorRegistry = {
545
+ generators: new Map<string, CodeGenerator>([
546
+ ['typescript', new TypeScriptGenerator()],
547
+ ]),
548
+
549
+ register(generator: CodeGenerator) {
550
+ this.generators.set(generator.language, generator);
551
+ },
552
+
553
+ get(language: string): CodeGenerator | undefined {
554
+ return this.generators.get(language);
555
+ },
556
+
557
+ list(): string[] {
558
+ return Array.from(this.generators.keys());
559
+ },
560
+ };