agentworkshop 0.2.1

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 (895) hide show
  1. package/.AgentWorkShop/prompts/host-tools.json +631 -0
  2. package/.AgentWorkShop/prompts/lead-supervise.md +42 -0
  3. package/.AgentWorkShop/prompts/mode-goal.md +26 -0
  4. package/.AgentWorkShop/prompts/mode-loop.md +10 -0
  5. package/.AgentWorkShop/prompts/mode-pipeline.md +16 -0
  6. package/.AgentWorkShop/prompts/peer-lead-roster.md +3 -0
  7. package/.AgentWorkShop/prompts/peer-message.md +14 -0
  8. package/.AgentWorkShop/prompts/peer-reply-optional.md +2 -0
  9. package/.AgentWorkShop/prompts/peer-reply-required.md +8 -0
  10. package/.AgentWorkShop/prompts/scenario-default.md +11 -0
  11. package/.AgentWorkShop/prompts/system-manual.md +18 -0
  12. package/.AgentWorkShop/prompts/team-roster.md +9 -0
  13. package/.AgentWorkShop/prompts/worker-workflow.md +19 -0
  14. package/.env.example +34 -0
  15. package/README-zh.md +424 -0
  16. package/README.md +424 -0
  17. package/app/.mimosa/hook-state/sess_05189059-e42d-4188-8911-4f7baabe009b.json +1 -0
  18. package/app/.mimosa/hook-state/sess_05189059-e42d-4188-8911-4f7baabe009b.mtg0vz68-49792-75b0709555.baseline/1459e6269990a5d229b9228c8b2f62ffaa7d350068380ae8b875fee0db45cca6.source +180 -0
  19. package/app/.mimosa/hook-state/sess_05189059-e42d-4188-8911-4f7baabe009b.mtg0vz68-49792-75b0709555.baseline/c2991e909c70c5c12b90a407c7adcf63384c51668a2b334e6e047fa675c268fe.source +305 -0
  20. package/app/.mimosa/hook-state/sess_05189059-e42d-4188-8911-4f7baabe009b.mtg0vz68-49792-75b0709555.baseline/e09129039d1e27e3fac24becc9bdafd2d1a7c8049bff24173df007be865f0165.source +264 -0
  21. package/app/.mimosa/hook-status/sess_05189059-e42d-4188-8911-4f7baabe009b-28ef7c75ea.json +14 -0
  22. package/app/app.vue +139 -0
  23. package/app/assets/css/main.css +1257 -0
  24. package/app/components/AppHeader.vue +675 -0
  25. package/app/components/AppSidebar.vue +286 -0
  26. package/app/components/AwChart.vue +44 -0
  27. package/app/components/AwLogo.vue +75 -0
  28. package/app/components/workshop/A2aRpcDebugger.vue +237 -0
  29. package/app/components/workshop/AgentInspectorDrawer.vue +424 -0
  30. package/app/components/workshop/AgentLanesView.vue +947 -0
  31. package/app/components/workshop/ArtifactCard.vue +120 -0
  32. package/app/components/workshop/AssetLibrary.vue +450 -0
  33. package/app/components/workshop/ChannelSessionList.vue +593 -0
  34. package/app/components/workshop/CommandPalette.vue +270 -0
  35. package/app/components/workshop/Composer.vue +731 -0
  36. package/app/components/workshop/DeviceTwinPanel.vue +607 -0
  37. package/app/components/workshop/EventBlock.vue +602 -0
  38. package/app/components/workshop/FileSelectorModal.vue +188 -0
  39. package/app/components/workshop/InspectorPanel.vue +265 -0
  40. package/app/components/workshop/LiveAgentBar.vue +362 -0
  41. package/app/components/workshop/MemoryPanel.vue +364 -0
  42. package/app/components/workshop/MentionHoverCard.vue +155 -0
  43. package/app/components/workshop/MultiChannelView.vue +189 -0
  44. package/app/components/workshop/PaneSplitter.vue +142 -0
  45. package/app/components/workshop/StatsPanel.vue +168 -0
  46. package/app/components/workshop/TaskBoardView.vue +636 -0
  47. package/app/components/workshop/TaskInspectorDrawer.vue +390 -0
  48. package/app/components/workshop/TranscriptTimeline.vue +545 -0
  49. package/app/components/workshop/blocks/ClusterArtifact.vue +77 -0
  50. package/app/components/workshop/blocks/ClusterError.vue +85 -0
  51. package/app/components/workshop/blocks/ClusterLife.vue +87 -0
  52. package/app/components/workshop/blocks/ClusterMember.vue +93 -0
  53. package/app/components/workshop/blocks/ClusterMemory.vue +84 -0
  54. package/app/components/workshop/blocks/ClusterOther.vue +67 -0
  55. package/app/components/workshop/blocks/ClusterRoute.vue +359 -0
  56. package/app/components/workshop/blocks/ClusterStatus.vue +147 -0
  57. package/app/components/workshop/blocks/ClusterStream.vue +325 -0
  58. package/app/components/workshop/blocks/ClusterTask.vue +151 -0
  59. package/app/components/workshop/blocks/ClusterTool.vue +158 -0
  60. package/app/components/workshop/lanes/LaneBlocks.vue +149 -0
  61. package/app/components/workshop/terminal/OmpTerminalPanel.vue +1010 -0
  62. package/app/components/workshop/town/ModelPreview3D.vue +276 -0
  63. package/app/components/workshop/town/TownScene.ts +1355 -0
  64. package/app/components/workshop/town/TownScene3D.ts +4533 -0
  65. package/app/components/workshop/town/TownView.vue +7071 -0
  66. package/app/composables/useCodeCopy.ts +30 -0
  67. package/app/composables/useHttp.ts +8 -0
  68. package/app/composables/useRouteMeta.ts +50 -0
  69. package/app/composables/useSiteConfig.ts +21 -0
  70. package/app/composables/workshop/apiClient.ts +95 -0
  71. package/app/composables/workshop/useCharacterAssets.ts +292 -0
  72. package/app/composables/workshop/useClusteredBlocks.ts +150 -0
  73. package/app/composables/workshop/useComposerBus.ts +16 -0
  74. package/app/composables/workshop/useDaqStream.ts +379 -0
  75. package/app/composables/workshop/useDcwStream.ts +300 -0
  76. package/app/composables/workshop/useDeviceTwins.ts +147 -0
  77. package/app/composables/workshop/useEventBlocks.ts +662 -0
  78. package/app/composables/workshop/useLocalTime.ts +33 -0
  79. package/app/composables/workshop/useOpsLog.ts +164 -0
  80. package/app/composables/workshop/useSceneLayouts.ts +166 -0
  81. package/app/composables/workshop/useTownBus.ts +47 -0
  82. package/app/composables/workshop/useVisibleInterval.ts +42 -0
  83. package/app/composables/workshop/useWorkshopApi.ts +224 -0
  84. package/app/composables/workshop/useWorkshopWs.ts +113 -0
  85. package/app/config/index.ts +66 -0
  86. package/app/config/schema.ts +68 -0
  87. package/app/error.vue +76 -0
  88. package/app/layouts/default.vue +100 -0
  89. package/app/layouts/town.vue +16 -0
  90. package/app/pages/daq/[id].vue +796 -0
  91. package/app/pages/daq/index.vue +2577 -0
  92. package/app/pages/dcw/[id].vue +2259 -0
  93. package/app/pages/dcw/index.vue +1079 -0
  94. package/app/pages/index.vue +830 -0
  95. package/app/pages/logs/index.vue +621 -0
  96. package/app/pages/monitor.vue +665 -0
  97. package/app/pages/settings.vue +757 -0
  98. package/app/pages/tokens.vue +610 -0
  99. package/app/pages/town.vue +145 -0
  100. package/app/pages/users.vue +257 -0
  101. package/app/pages/workshop/agents.vue +382 -0
  102. package/app/pages/workshop/channel-templates.vue +456 -0
  103. package/app/pages/workshop/index.vue +604 -0
  104. package/app/pages/workshop/teams.vue +448 -0
  105. package/app/pages/workshop/w/[wsId].vue +516 -0
  106. package/app/plugins/http.ts +71 -0
  107. package/app/plugins/locale-restore.client.ts +13 -0
  108. package/app/plugins/runtime-config.client.ts +65 -0
  109. package/app/plugins/session-restore.client.ts +24 -0
  110. package/app/plugins/theme.client.ts +15 -0
  111. package/app/stores/app.ts +32 -0
  112. package/app/stores/route-trail.ts +45 -0
  113. package/app/stores/runtime-config.ts +212 -0
  114. package/app/stores/workshop/connection.ts +184 -0
  115. package/app/stores/workshop/entities.ts +350 -0
  116. package/app/stores/workshop/events.ts +292 -0
  117. package/app/stores/workshop/user.ts +176 -0
  118. package/app/stores/workshop/workspaces.ts +133 -0
  119. package/bin/aw.mjs +13 -0
  120. package/cli/aw.mjs +184 -0
  121. package/cli/commands/build.mjs +33 -0
  122. package/cli/commands/config.mjs +157 -0
  123. package/cli/commands/dev.mjs +74 -0
  124. package/cli/commands/doctor.mjs +120 -0
  125. package/cli/commands/home.mjs +75 -0
  126. package/cli/commands/init.mjs +150 -0
  127. package/cli/commands/register.mjs +123 -0
  128. package/cli/commands/start.mjs +106 -0
  129. package/cli/commands/status.mjs +67 -0
  130. package/cli/commands/update.mjs +116 -0
  131. package/cli/commands/version.mjs +32 -0
  132. package/cli/core/args.mjs +95 -0
  133. package/cli/core/context.mjs +264 -0
  134. package/cli/core/errors.mjs +18 -0
  135. package/cli/core/help.mjs +68 -0
  136. package/cli/core/logger.mjs +40 -0
  137. package/cli/core/registry.mjs +111 -0
  138. package/config.yml +70 -0
  139. package/docker-compose.yml +34 -0
  140. package/docs/cli.md +220 -0
  141. package/i18n/dicts/_en.json +1097 -0
  142. package/i18n/dicts/_en2.json +300 -0
  143. package/i18n/dicts/_en3.json +102 -0
  144. package/i18n/dicts/_en4.json +115 -0
  145. package/i18n/dicts/_en5.json +33 -0
  146. package/i18n/dicts/a2aRpcDebugger.json +10 -0
  147. package/i18n/dicts/agentInspectorDrawer.json +25 -0
  148. package/i18n/dicts/agentLanesView.json +57 -0
  149. package/i18n/dicts/agents.json +27 -0
  150. package/i18n/dicts/appHeader.json +7 -0
  151. package/i18n/dicts/appSidebar.json +1 -0
  152. package/i18n/dicts/artifactCard.json +6 -0
  153. package/i18n/dicts/assetLibrary.json +18 -0
  154. package/i18n/dicts/awChart.json +1 -0
  155. package/i18n/dicts/awLogo.json +1 -0
  156. package/i18n/dicts/channelSessionList.json +45 -0
  157. package/i18n/dicts/clusterArtifact.json +4 -0
  158. package/i18n/dicts/clusterError.json +3 -0
  159. package/i18n/dicts/clusterLife.json +5 -0
  160. package/i18n/dicts/clusterMember.json +3 -0
  161. package/i18n/dicts/clusterMemory.json +3 -0
  162. package/i18n/dicts/clusterOther.json +3 -0
  163. package/i18n/dicts/clusterRoute.json +15 -0
  164. package/i18n/dicts/clusterStatus.json +3 -0
  165. package/i18n/dicts/clusterStream.json +3 -0
  166. package/i18n/dicts/clusterTask.json +10 -0
  167. package/i18n/dicts/clusterTool.json +3 -0
  168. package/i18n/dicts/commandPalette.json +16 -0
  169. package/i18n/dicts/composer.json +38 -0
  170. package/i18n/dicts/ctpl.json +32 -0
  171. package/i18n/dicts/daq.json +157 -0
  172. package/i18n/dicts/daqDetail.json +55 -0
  173. package/i18n/dicts/dcw.json +68 -0
  174. package/i18n/dicts/dcwDetail.json +199 -0
  175. package/i18n/dicts/deviceTwinPanel.json +12 -0
  176. package/i18n/dicts/eventBlock.json +8 -0
  177. package/i18n/dicts/fileSelectorModal.json +6 -0
  178. package/i18n/dicts/inspectorPanel.json +12 -0
  179. package/i18n/dicts/laneBlocks.json +6 -0
  180. package/i18n/dicts/liveAgentBar.json +8 -0
  181. package/i18n/dicts/logs.json +39 -0
  182. package/i18n/dicts/memoryPanel.json +20 -0
  183. package/i18n/dicts/mentionHoverCard.json +4 -0
  184. package/i18n/dicts/modelPreview3D.json +1 -0
  185. package/i18n/dicts/monitor.json +5 -0
  186. package/i18n/dicts/multiChannelView.json +13 -0
  187. package/i18n/dicts/ompTerminalPanel.json +7 -0
  188. package/i18n/dicts/paneSplitter.json +3 -0
  189. package/i18n/dicts/settings.json +1 -0
  190. package/i18n/dicts/statsPanel.json +6 -0
  191. package/i18n/dicts/taskBoardView.json +22 -0
  192. package/i18n/dicts/taskInspectorDrawer.json +19 -0
  193. package/i18n/dicts/teams.json +33 -0
  194. package/i18n/dicts/tokens.json +30 -0
  195. package/i18n/dicts/town.json +7 -0
  196. package/i18n/dicts/townView.json +209 -0
  197. package/i18n/dicts/transcriptTimeline.json +31 -0
  198. package/i18n/dicts/users.json +15 -0
  199. package/i18n/dicts/wsHome.json +33 -0
  200. package/i18n/dicts/wsView.json +15 -0
  201. package/i18n/locales/en.ts +1737 -0
  202. package/i18n/locales/zh-CN.ts +1736 -0
  203. package/nuxt.config.ts +209 -0
  204. package/package.json +123 -0
  205. package/public/assets/game/character/bot.png +0 -0
  206. package/public/assets/game/character/device-3d.glb +0 -0
  207. package/public/assets/game/character/hero-3d.glb +0 -0
  208. package/public/assets/game/character/hero-anime-1.glb +0 -0
  209. package/public/assets/game/character/hero-anime-2.glb +0 -0
  210. package/public/assets/game/character/hero-anime-3.glb +0 -0
  211. package/public/assets/game/character/hero-anime-4.glb +0 -0
  212. package/public/assets/game/character/knight.png +0 -0
  213. package/public/assets/game/character/mage.png +0 -0
  214. package/public/assets/game/coin.png +0 -0
  215. package/public/assets/game/devices/agv.glb +0 -0
  216. package/public/assets/game/devices/caster.glb +0 -0
  217. package/public/assets/game/devices/device-console.glb +0 -0
  218. package/public/assets/game/devices/device-robot-arm.glb +0 -0
  219. package/public/assets/game/devices/device-scanner.glb +0 -0
  220. package/public/assets/game/devices/extruder.glb +0 -0
  221. package/public/assets/game/devices/mdo.glb +0 -0
  222. package/public/assets/game/devices/power-cabinet.glb +0 -0
  223. package/public/assets/game/devices/pump.glb +0 -0
  224. package/public/assets/game/devices/tdo.glb +0 -0
  225. package/public/assets/game/devices/thickness-scanner.glb +0 -0
  226. package/public/assets/game/devices/winder.glb +0 -0
  227. package/public/assets/game/npc/boltnu-sheet.png +0 -0
  228. package/public/assets/game/npc/fluttaflap-sheet.png +0 -0
  229. package/public/assets/game/npc/rockitten-sheet.png +0 -0
  230. package/public/assets/game/npc/tux-sheet.png +0 -0
  231. package/public/assets/game/player/misa-back-walk.000.png +0 -0
  232. package/public/assets/game/player/misa-back-walk.001.png +0 -0
  233. package/public/assets/game/player/misa-back-walk.002.png +0 -0
  234. package/public/assets/game/player/misa-back-walk.003.png +0 -0
  235. package/public/assets/game/player/misa-back.png +0 -0
  236. package/public/assets/game/player/misa-front-walk.000.png +0 -0
  237. package/public/assets/game/player/misa-front-walk.001.png +0 -0
  238. package/public/assets/game/player/misa-front-walk.002.png +0 -0
  239. package/public/assets/game/player/misa-front-walk.003.png +0 -0
  240. package/public/assets/game/player/misa-front.png +0 -0
  241. package/public/assets/game/player/misa-left-walk.000.png +0 -0
  242. package/public/assets/game/player/misa-left-walk.001.png +0 -0
  243. package/public/assets/game/player/misa-left-walk.002.png +0 -0
  244. package/public/assets/game/player/misa-left-walk.003.png +0 -0
  245. package/public/assets/game/player/misa-left.png +0 -0
  246. package/public/assets/game/player/misa-right-walk.000.png +0 -0
  247. package/public/assets/game/player/misa-right-walk.001.png +0 -0
  248. package/public/assets/game/player/misa-right-walk.002.png +0 -0
  249. package/public/assets/game/player/misa-right-walk.003.png +0 -0
  250. package/public/assets/game/player/misa-right.png +0 -0
  251. package/public/assets/game/player-sheet.png +0 -0
  252. package/public/assets/game/tuxemon-town.json +1 -0
  253. package/public/assets/game/tuxmon-sample-32px-extruded.png +0 -0
  254. package/public/assets/game/wuwa/scene-map.png +0 -0
  255. package/public/assets/game/wuwa/world-far.png +0 -0
  256. package/public/assets/game/wuwa/world-middle.png +0 -0
  257. package/public/assets/game/wuwa/world-near.png +0 -0
  258. package/public/assets/game/wuwa/wu-aura.png +0 -0
  259. package/public/assets/game/wuwa/wu-lead.png +0 -0
  260. package/public/assets/game/wuwa/wu-ring.png +0 -0
  261. package/public/assets/game/wuwa/wu-slash.png +0 -0
  262. package/public/assets/game/wuwa/wu-worker-0.png +0 -0
  263. package/public/assets/game/wuwa/wu-worker-1.png +0 -0
  264. package/public/assets/game/wuwa/wu-worker-2.png +0 -0
  265. package/public/favicon.svg +14 -0
  266. package/public/scene/background/cyber-town-background.svg +110 -0
  267. package/scripts/_daq-realtime-probe.mjs +68 -0
  268. package/scripts/_daq-warn-probe.mjs +50 -0
  269. package/scripts/_dbg-agent-tools-audit.mjs +154 -0
  270. package/scripts/_dbg-agent-workflow-audit.mjs +177 -0
  271. package/scripts/_dbg-anim-verify.mjs +81 -0
  272. package/scripts/_dbg-audit-all-pages.mjs +43 -0
  273. package/scripts/_dbg-autoframe.mjs +103 -0
  274. package/scripts/_dbg-beacon-final.mjs +181 -0
  275. package/scripts/_dbg-bind-bidi-e2e.mjs +239 -0
  276. package/scripts/_dbg-callout-near.mjs +108 -0
  277. package/scripts/_dbg-chan-focus.mjs +49 -0
  278. package/scripts/_dbg-cleanup.mjs +31 -0
  279. package/scripts/_dbg-closedloop-ui-shot.mjs +61 -0
  280. package/scripts/_dbg-console-audit.mjs +61 -0
  281. package/scripts/_dbg-console-probe.mjs +23 -0
  282. package/scripts/_dbg-context-inject-audit.mjs +231 -0
  283. package/scripts/_dbg-crash-recovery.mjs +143 -0
  284. package/scripts/_dbg-crop-shot.mjs +16 -0
  285. package/scripts/_dbg-daq-acc-probe.mjs +24 -0
  286. package/scripts/_dbg-daq-attrib.mjs +34 -0
  287. package/scripts/_dbg-daq-bind-audit.mjs +119 -0
  288. package/scripts/_dbg-daq-cadence.mjs +104 -0
  289. package/scripts/_dbg-daq-debug.mjs +22 -0
  290. package/scripts/_dbg-daq-diag.mjs +33 -0
  291. package/scripts/_dbg-daq-e2e.mjs +171 -0
  292. package/scripts/_dbg-daq-film.mjs +136 -0
  293. package/scripts/_dbg-daq-filter-e2e.mjs +109 -0
  294. package/scripts/_dbg-daq-filter-e2e2.mjs +62 -0
  295. package/scripts/_dbg-daq-final-regression.mjs +78 -0
  296. package/scripts/_dbg-daq-full-check.mjs +179 -0
  297. package/scripts/_dbg-daq-line-note-verify.mjs +61 -0
  298. package/scripts/_dbg-daq-linebanner-audit.mjs +107 -0
  299. package/scripts/_dbg-daq-pages-shot.mjs +37 -0
  300. package/scripts/_dbg-daq-perf.mjs +61 -0
  301. package/scripts/_dbg-daq-probe.mjs +27 -0
  302. package/scripts/_dbg-daq-recipe-e2e.mjs +30 -0
  303. package/scripts/_dbg-daq-redesign-shot.mjs +88 -0
  304. package/scripts/_dbg-daq-rows-probe.mjs +26 -0
  305. package/scripts/_dbg-daq-rowstate-e2e.mjs +152 -0
  306. package/scripts/_dbg-daq-rowstate-shot.mjs +45 -0
  307. package/scripts/_dbg-daq-rowstate-shot2.mjs +38 -0
  308. package/scripts/_dbg-daq-tpl.mjs +144 -0
  309. package/scripts/_dbg-dash-console-check.mjs +49 -0
  310. package/scripts/_dbg-dash-deep-probe.mjs +61 -0
  311. package/scripts/_dbg-dash-hitpoint.mjs +44 -0
  312. package/scripts/_dbg-dash-live-shot.mjs +36 -0
  313. package/scripts/_dbg-dash-shot.mjs +21 -0
  314. package/scripts/_dbg-dashboard-shot.mjs +35 -0
  315. package/scripts/_dbg-dcw-audit.mjs +126 -0
  316. package/scripts/_dbg-dcw-card-e2e.mjs +108 -0
  317. package/scripts/_dbg-dcw-channel-ui.mjs +144 -0
  318. package/scripts/_dbg-dcw-examples.mjs +81 -0
  319. package/scripts/_dbg-dcw-light-shot.mjs +19 -0
  320. package/scripts/_dbg-dcw-line-audit.mjs +107 -0
  321. package/scripts/_dbg-dcw-pause-tpl-audit.mjs +161 -0
  322. package/scripts/_dbg-dcw-pause-ui.mjs +175 -0
  323. package/scripts/_dbg-dcw-scene.mjs +72 -0
  324. package/scripts/_dbg-dcw-shot2.mjs +14 -0
  325. package/scripts/_dbg-dcw-twin-e2e.mjs +192 -0
  326. package/scripts/_dbg-dt-interact.mjs +193 -0
  327. package/scripts/_dbg-error-probe.mjs +54 -0
  328. package/scripts/_dbg-filter-light-verify.mjs +54 -0
  329. package/scripts/_dbg-final-acceptance-2.mjs +72 -0
  330. package/scripts/_dbg-final-acceptance.mjs +192 -0
  331. package/scripts/_dbg-final-agent-e2e.mjs +151 -0
  332. package/scripts/_dbg-final-full-e2e.mjs +218 -0
  333. package/scripts/_dbg-final-line-e2e.mjs +173 -0
  334. package/scripts/_dbg-final-t6-hitl.mjs +38 -0
  335. package/scripts/_dbg-focus-range.mjs +115 -0
  336. package/scripts/_dbg-fresh-scene-e2e.mjs +125 -0
  337. package/scripts/_dbg-full-feature-e2e.mjs +219 -0
  338. package/scripts/_dbg-fullchain-e2e.mjs +178 -0
  339. package/scripts/_dbg-gate-debug.mjs +37 -0
  340. package/scripts/_dbg-gif-encode.mjs +111 -0
  341. package/scripts/_dbg-gizmo.mjs +95 -0
  342. package/scripts/_dbg-glass-probe.mjs +57 -0
  343. package/scripts/_dbg-glass-shot.mjs +50 -0
  344. package/scripts/_dbg-glass-sweep.mjs +25 -0
  345. package/scripts/_dbg-glb-probe.mjs +43 -0
  346. package/scripts/_dbg-hardening-probe.mjs +90 -0
  347. package/scripts/_dbg-hero-btn-probe.mjs +21 -0
  348. package/scripts/_dbg-hidden-check.mjs +21 -0
  349. package/scripts/_dbg-hitl-timeout-e2e.mjs +93 -0
  350. package/scripts/_dbg-hmi-audit.mjs +164 -0
  351. package/scripts/_dbg-home-repro.mjs +24 -0
  352. package/scripts/_dbg-home-stack.mjs +13 -0
  353. package/scripts/_dbg-huashu-survey.mjs +31 -0
  354. package/scripts/_dbg-huashu-survey2.mjs +35 -0
  355. package/scripts/_dbg-huashu-verify.mjs +25 -0
  356. package/scripts/_dbg-huashu-verify2.mjs +26 -0
  357. package/scripts/_dbg-hydration-detail.mjs +18 -0
  358. package/scripts/_dbg-i18n-debug.mjs +27 -0
  359. package/scripts/_dbg-i18n-debug2.mjs +26 -0
  360. package/scripts/_dbg-i18n-final.mjs +42 -0
  361. package/scripts/_dbg-i18n-scan.mjs +38 -0
  362. package/scripts/_dbg-infra-lifecycle.mjs +44 -0
  363. package/scripts/_dbg-line-aura-shots.mjs +54 -0
  364. package/scripts/_dbg-line-control-e2e.mjs +120 -0
  365. package/scripts/_dbg-line-gate-audit.mjs +108 -0
  366. package/scripts/_dbg-line-live-e2e.mjs +144 -0
  367. package/scripts/_dbg-line-scenario-e2e.mjs +256 -0
  368. package/scripts/_dbg-minimal-omp.mjs +77 -0
  369. package/scripts/_dbg-mode-nav.mjs +173 -0
  370. package/scripts/_dbg-mqtt-chain-e2e.mjs +90 -0
  371. package/scripts/_dbg-nav-rpg.mjs +84 -0
  372. package/scripts/_dbg-nav-shot.mjs +28 -0
  373. package/scripts/_dbg-nav.mjs +27 -0
  374. package/scripts/_dbg-opslog-e2e.mjs +121 -0
  375. package/scripts/_dbg-opslog-shots.mjs +62 -0
  376. package/scripts/_dbg-opt-team-e2e.mjs +133 -0
  377. package/scripts/_dbg-optimization-e2e.mjs +94 -0
  378. package/scripts/_dbg-orbit.mjs +58 -0
  379. package/scripts/_dbg-panesplitter-fix-check.mjs +62 -0
  380. package/scripts/_dbg-phase-e3-monitor.mjs +25 -0
  381. package/scripts/_dbg-pop-clamp-verify.mjs +77 -0
  382. package/scripts/_dbg-preset-e2e.mjs +116 -0
  383. package/scripts/_dbg-preview-console.mjs +28 -0
  384. package/scripts/_dbg-preview-minrepro.mjs +156 -0
  385. package/scripts/_dbg-preview-pixels.mjs +93 -0
  386. package/scripts/_dbg-quality-pages-e2e.mjs +84 -0
  387. package/scripts/_dbg-query-cancel.ts +12 -0
  388. package/scripts/_dbg-rail-tree-e2e.mjs +183 -0
  389. package/scripts/_dbg-real-driver-e2e.mjs +55 -0
  390. package/scripts/_dbg-redesign-shots.mjs +34 -0
  391. package/scripts/_dbg-restart-persist.mjs +41 -0
  392. package/scripts/_dbg-rollback-mgr-audit.mjs +169 -0
  393. package/scripts/_dbg-rpg.mjs +71 -0
  394. package/scripts/_dbg-sc001-dispatch.mjs +63 -0
  395. package/scripts/_dbg-scenario-final-shot.mjs +24 -0
  396. package/scripts/_dbg-scenario-phase-e2.mjs +75 -0
  397. package/scripts/_dbg-scenario-phase-e3.mjs +96 -0
  398. package/scripts/_dbg-scenario-phase1.mjs +90 -0
  399. package/scripts/_dbg-scenario-phase2.mjs +105 -0
  400. package/scripts/_dbg-scenario-phase3-monitor.mjs +48 -0
  401. package/scripts/_dbg-scenario-phase3.mjs +111 -0
  402. package/scripts/_dbg-scene-polish-shot.mjs +118 -0
  403. package/scripts/_dbg-selring-probe.mjs +47 -0
  404. package/scripts/_dbg-sideinfo.mjs +101 -0
  405. package/scripts/_dbg-splitter.mjs +88 -0
  406. package/scripts/_dbg-team-repro.mjs +76 -0
  407. package/scripts/_dbg-town-alarm-e2e.mjs +40 -0
  408. package/scripts/_dbg-town-beauty-shots.mjs +54 -0
  409. package/scripts/_dbg-town-daq-shot.mjs +26 -0
  410. package/scripts/_dbg-town-full-e2e.mjs +104 -0
  411. package/scripts/_dbg-town-gate.mjs +44 -0
  412. package/scripts/_dbg-town-ins-probe.mjs +37 -0
  413. package/scripts/_dbg-town-perf.mjs +50 -0
  414. package/scripts/_dbg-town-polish-shots.mjs +82 -0
  415. package/scripts/_dbg-town-realtime.mjs +42 -0
  416. package/scripts/_dbg-town-shot3.mjs +17 -0
  417. package/scripts/_dbg-town-truth.mjs +37 -0
  418. package/scripts/_dbg-town-truth2.mjs +27 -0
  419. package/scripts/_dbg-transform-audit.mjs +98 -0
  420. package/scripts/_dbg-trend-expand-test.mjs +38 -0
  421. package/scripts/_dbg-twindaq-focus.mjs +81 -0
  422. package/scripts/_dbg-ui-polish-shot.mjs +43 -0
  423. package/scripts/_dbg-ui-polish-verify1.mjs +92 -0
  424. package/scripts/_dbg-ui-polish-verify2.mjs +50 -0
  425. package/scripts/_dbg-ui-polish-verify3.mjs +51 -0
  426. package/scripts/_dbg-ui-polish-verify4.mjs +50 -0
  427. package/scripts/_dbg-ui-shot.mjs +26 -0
  428. package/scripts/_dbg-unify-shot.mjs +43 -0
  429. package/scripts/_dbg-uplink-probe.mjs +36 -0
  430. package/scripts/_dbg-wizard-preview-shot.mjs +58 -0
  431. package/scripts/_dbg-wizard-ui-e2e.mjs +93 -0
  432. package/scripts/_dbg-ws-probe.mjs +86 -0
  433. package/scripts/_dbg-ws-shot2.mjs +23 -0
  434. package/scripts/_dbg-wsdot-sanity.mjs +25 -0
  435. package/scripts/_dev-stack.mjs +46 -0
  436. package/scripts/_http-driver-probe.mjs +30 -0
  437. package/scripts/_lib-dcw-line.mjs +24 -0
  438. package/scripts/_mqtt-driver-probe.mjs +30 -0
  439. package/scripts/_newdriver-rest-probe.mjs +100 -0
  440. package/scripts/_node-state-probe.mjs +5 -0
  441. package/scripts/_opcua-driver-probe.mjs +31 -0
  442. package/scripts/_rtu-debug.mjs +41 -0
  443. package/scripts/_rtu-direct.mjs +6 -0
  444. package/scripts/_rtu-driver-probe.mjs +53 -0
  445. package/scripts/_rtu-mini-slave.mjs +63 -0
  446. package/scripts/_townview_style.css +1185 -0
  447. package/scripts/_townview_template.html +1215 -0
  448. package/scripts/_wizard-shots.mjs +90 -0
  449. package/scripts/acceptance-suite.py +207 -0
  450. package/scripts/api-live-e2e.mjs +467 -0
  451. package/scripts/build-anime-models.mjs +339 -0
  452. package/scripts/build-character-models.mjs +175 -0
  453. package/scripts/build-film-devices.mjs +227 -0
  454. package/scripts/build-model-3d.mjs +173 -0
  455. package/scripts/build-player-sheet.mjs +58 -0
  456. package/scripts/build-world-map.mjs +188 -0
  457. package/scripts/build-wuwa-assets.mjs +345 -0
  458. package/scripts/collab-live-test.py +177 -0
  459. package/scripts/debug-mcp-http.ts +64 -0
  460. package/scripts/demo-lead-worker.ts +256 -0
  461. package/scripts/demo-modes.ts +415 -0
  462. package/scripts/demo-omp-channel.ts +135 -0
  463. package/scripts/design-preflight.mjs +223 -0
  464. package/scripts/design-verify-templates.mjs +110 -0
  465. package/scripts/design-verify.mjs +170 -0
  466. package/scripts/dev-guard.mjs +74 -0
  467. package/scripts/dev-modbus-simulator.mjs +55 -0
  468. package/scripts/dev-opcua-simulator.mjs +57 -0
  469. package/scripts/dev-protocol-simulators.mjs +145 -0
  470. package/scripts/dev-window.cmd +6 -0
  471. package/scripts/device-line-restore.mjs +34 -0
  472. package/scripts/diag-lead-status.ts +101 -0
  473. package/scripts/e2e-a2a-steer-live.mjs +193 -0
  474. package/scripts/e2e-agent-channel-task.ts +151 -0
  475. package/scripts/e2e-agent-team.mjs +168 -0
  476. package/scripts/e2e-auth-matrix.mjs +119 -0
  477. package/scripts/e2e-channel-isolation.ts +325 -0
  478. package/scripts/e2e-dual-drive-comm.ts +259 -0
  479. package/scripts/e2e-lead-team-mgmt.ts +217 -0
  480. package/scripts/e2e-memory-persistence.ts +320 -0
  481. package/scripts/e2e-memory-system.ts +332 -0
  482. package/scripts/e2e-omp-modes.ts +274 -0
  483. package/scripts/e2e-omp-realtime.ts +258 -0
  484. package/scripts/e2e-omp-workspace.ts +180 -0
  485. package/scripts/e2e-parallel-execution.mjs +151 -0
  486. package/scripts/e2e-rest-memory.mjs +251 -0
  487. package/scripts/e2e-rest-robustness.mjs +177 -0
  488. package/scripts/e2e-resume-crash.mjs +254 -0
  489. package/scripts/e2e-tab-close.mjs +136 -0
  490. package/scripts/e2e-task-queue.ts +277 -0
  491. package/scripts/e2e-template-isolation.mjs +267 -0
  492. package/scripts/e2e-token-ui.mjs +149 -0
  493. package/scripts/final-soup-run.py +192 -0
  494. package/scripts/final-soup-watch.py +83 -0
  495. package/scripts/home-bootstrap.mjs +117 -0
  496. package/scripts/i18n-codemod.mjs +173 -0
  497. package/scripts/i18n-fix-en.py +28 -0
  498. package/scripts/i18n-fix-en2.py +31 -0
  499. package/scripts/i18n-merge.mjs +67 -0
  500. package/scripts/omp-real-test.py +328 -0
  501. package/scripts/smoke-optimization-verify.ts +72 -0
  502. package/scripts/start.mjs +60 -0
  503. package/scripts/test-a2a-relay.mjs +222 -0
  504. package/scripts/test-a2a-types.ts +296 -0
  505. package/scripts/test-agent-brain.ts +135 -0
  506. package/scripts/test-agent-multi-channel.ts +160 -0
  507. package/scripts/test-agent-runtime.ts +348 -0
  508. package/scripts/test-api-client.ts +108 -0
  509. package/scripts/test-api-suite.mjs +271 -0
  510. package/scripts/test-block-consumption.mjs +194 -0
  511. package/scripts/test-channel-routing.ts +301 -0
  512. package/scripts/test-cmd-render.mjs +218 -0
  513. package/scripts/test-collab-e2e.mjs +136 -0
  514. package/scripts/test-collab-omp.mjs +192 -0
  515. package/scripts/test-dedup-logic.ts +132 -0
  516. package/scripts/test-dual-drive.ts +227 -0
  517. package/scripts/test-e2e-collaboration.ts +262 -0
  518. package/scripts/test-e2e-monitor.ts +192 -0
  519. package/scripts/test-event-history.ts +112 -0
  520. package/scripts/test-event-persistence.mjs +169 -0
  521. package/scripts/test-exec-modes.ts +316 -0
  522. package/scripts/test-fifo-realtime.mjs +193 -0
  523. package/scripts/test-final-e2e.mjs +290 -0
  524. package/scripts/test-full-system.ts +439 -0
  525. package/scripts/test-game-session.ts +160 -0
  526. package/scripts/test-goal-summary.ts +202 -0
  527. package/scripts/test-harness-liveness.ts +109 -0
  528. package/scripts/test-harness-terminal.ts +164 -0
  529. package/scripts/test-header-trail.mjs +95 -0
  530. package/scripts/test-hitl.ts +360 -0
  531. package/scripts/test-koda-restyle.mjs +105 -0
  532. package/scripts/test-lane-history-live.mjs +103 -0
  533. package/scripts/test-lane-raw.ts +67 -0
  534. package/scripts/test-lanes-history-render.mjs +138 -0
  535. package/scripts/test-loop-omp.mjs +154 -0
  536. package/scripts/test-mcp-tools.ts +285 -0
  537. package/scripts/test-mdlite.ts +53 -0
  538. package/scripts/test-memory-dynamic.ts +99 -0
  539. package/scripts/test-memory-maintenance.ts +117 -0
  540. package/scripts/test-memory-vector.ts +154 -0
  541. package/scripts/test-memory.ts +431 -0
  542. package/scripts/test-mock-collab.mjs +226 -0
  543. package/scripts/test-modern-render.mjs +174 -0
  544. package/scripts/test-omp-terminal.mjs +187 -0
  545. package/scripts/test-orchestration.ts +425 -0
  546. package/scripts/test-persistence-lazy.ts +323 -0
  547. package/scripts/test-prompt-system.mjs +181 -0
  548. package/scripts/test-prompts-loader.ts +56 -0
  549. package/scripts/test-protocol.ts +156 -0
  550. package/scripts/test-real-scenario.mjs +290 -0
  551. package/scripts/test-route-reason.mjs +111 -0
  552. package/scripts/test-scheduler-loop.ts +469 -0
  553. package/scripts/test-stream-render.ts +37 -0
  554. package/scripts/test-task-drawer.mjs +204 -0
  555. package/scripts/test-task-engine.ts +433 -0
  556. package/scripts/test-task-invariants.mjs +169 -0
  557. package/scripts/test-terminal-e2e.mjs +264 -0
  558. package/scripts/test-town-3d.mjs +121 -0
  559. package/scripts/test-town-drag.mjs +218 -0
  560. package/scripts/test-town-layout.mjs +200 -0
  561. package/scripts/test-town-page.mjs +136 -0
  562. package/scripts/test-town-scene-math.ts +169 -0
  563. package/scripts/test-town-twin.mjs +121 -0
  564. package/scripts/test-town-upload.mjs +89 -0
  565. package/scripts/test-town-user-flow.mjs +619 -0
  566. package/scripts/test-town-world.mjs +76 -0
  567. package/scripts/test-town-wuwa.mjs +198 -0
  568. package/scripts/test-user-isolation.mjs +193 -0
  569. package/scripts/test-workshop-db.ts +280 -0
  570. package/scripts/test-workshop-entries.ts +370 -0
  571. package/scripts/test-workspace-api.ts +329 -0
  572. package/scripts/test-ws-aep.mjs +187 -0
  573. package/scripts/test-ws-protocol.ts +134 -0
  574. package/scripts/test-ws-stress.mjs +208 -0
  575. package/scripts/town-demo-seed.mjs +75 -0
  576. package/scripts/town-scene-clear.mjs +56 -0
  577. package/scripts/ui-screenshot.mjs +128 -0
  578. package/scripts/verify-a2a-live.mjs +124 -0
  579. package/scripts/verify-exec-modes-report.ts +248 -0
  580. package/scripts/verify-game.mjs +477 -0
  581. package/scripts/verify-lead-mail.ts +188 -0
  582. package/scripts/verify-page-smoke.mjs +87 -0
  583. package/scripts/verify-ws-events.mjs +123 -0
  584. package/scripts/ws-test.mjs +176 -0
  585. package/scripts/ws-test.py +4 -0
  586. package/server/api/health.get.ts +32 -0
  587. package/server/api/mcp/workshop.ts +78 -0
  588. package/server/api/metrics.ts +75 -0
  589. package/server/api/system/config.get.ts +12 -0
  590. package/server/api/system/monitor/terminal/ws.ts +177 -0
  591. package/server/api/system/monitor/terminate.post.ts +36 -0
  592. package/server/api/system/monitor.get.ts +13 -0
  593. package/server/api/system/settings/events.get.ts +28 -0
  594. package/server/api/system/settings/index.get.ts +14 -0
  595. package/server/api/system/settings/index.patch.ts +22 -0
  596. package/server/api/system/settings/reset.post.ts +12 -0
  597. package/server/api/users/[id].delete.ts +11 -0
  598. package/server/api/users/[id].get.ts +11 -0
  599. package/server/api/users/[id].put.ts +14 -0
  600. package/server/api/users/index.get.ts +13 -0
  601. package/server/api/users/index.post.ts +13 -0
  602. package/server/api/users/login.post.ts +11 -0
  603. package/server/api/users/logout.post.ts +9 -0
  604. package/server/api/users/me.get.ts +9 -0
  605. package/server/api/users/register.post.ts +11 -0
  606. package/server/api/users/tokens/[id]/token.get.ts +11 -0
  607. package/server/api/users/tokens/[id].delete.ts +11 -0
  608. package/server/api/users/tokens/[id].patch.ts +14 -0
  609. package/server/api/users/tokens/index.get.ts +9 -0
  610. package/server/api/users/tokens/index.post.ts +13 -0
  611. package/server/api/workshop/[...path].ts +13 -0
  612. package/server/api/workshop/a2a/[agentId]/card/index.get.ts +75 -0
  613. package/server/api/workshop/a2a/[agentId]/rpc/index.post.ts +429 -0
  614. package/server/api/workshop/a2a/send.post.ts +28 -0
  615. package/server/api/workshop/agent-tools/approvals/[id]/decide.post.ts +21 -0
  616. package/server/api/workshop/agent-tools/approvals/index.get.ts +18 -0
  617. package/server/api/workshop/agent-tools/bindings/[id].delete.ts +21 -0
  618. package/server/api/workshop/agent-tools/bindings/[id].patch.ts +14 -0
  619. package/server/api/workshop/agent-tools/bindings/index.get.ts +14 -0
  620. package/server/api/workshop/agent-tools/bindings/index.post.ts +20 -0
  621. package/server/api/workshop/agent-tools/invoke.post.ts +34 -0
  622. package/server/api/workshop/agents/[id].delete.ts +20 -0
  623. package/server/api/workshop/agents/[id].get.ts +19 -0
  624. package/server/api/workshop/agents/[id].patch.ts +30 -0
  625. package/server/api/workshop/agents/index.get.ts +13 -0
  626. package/server/api/workshop/agents/index.post.ts +29 -0
  627. package/server/api/workshop/agents/subscribe.post.ts +21 -0
  628. package/server/api/workshop/approvals/[id]/decide.post.ts +30 -0
  629. package/server/api/workshop/approvals/index.get.ts +22 -0
  630. package/server/api/workshop/assets/character/[id].delete.ts +33 -0
  631. package/server/api/workshop/assets/character/index.get.ts +17 -0
  632. package/server/api/workshop/assets/character/index.post.ts +87 -0
  633. package/server/api/workshop/assets/devices/[id].delete.ts +43 -0
  634. package/server/api/workshop/assets/devices/index.get.ts +103 -0
  635. package/server/api/workshop/assets/devices/index.post.ts +53 -0
  636. package/server/api/workshop/audit.get.ts +43 -0
  637. package/server/api/workshop/caller.ts +141 -0
  638. package/server/api/workshop/channel-templates/[id]/instantiate.post.ts +31 -0
  639. package/server/api/workshop/channel-templates/[id].delete.ts +20 -0
  640. package/server/api/workshop/channel-templates/[id].get.ts +19 -0
  641. package/server/api/workshop/channel-templates/[id].patch.ts +48 -0
  642. package/server/api/workshop/channel-templates/from-channel.post.ts +31 -0
  643. package/server/api/workshop/channel-templates/index.get.ts +13 -0
  644. package/server/api/workshop/channel-templates/index.post.ts +61 -0
  645. package/server/api/workshop/channels/[id]/activate.post.ts +19 -0
  646. package/server/api/workshop/channels/[id]/agents/[agentId]/memories/[memoryId].delete.ts +30 -0
  647. package/server/api/workshop/channels/[id]/agents/[agentId]/memories/index.get.ts +29 -0
  648. package/server/api/workshop/channels/[id]/agents/[agentId]/memories/index.post.ts +48 -0
  649. package/server/api/workshop/channels/[id]/agents/[agentId]/memories/search.post.ts +43 -0
  650. package/server/api/workshop/channels/[id]/agents/[agentId]/model.patch.ts +39 -0
  651. package/server/api/workshop/channels/[id]/agents/[agentId]/position.patch.ts +33 -0
  652. package/server/api/workshop/channels/[id]/agents/[agentId]/range.patch.ts +54 -0
  653. package/server/api/workshop/channels/[id]/agents/[agentId]/stop.post.ts +25 -0
  654. package/server/api/workshop/channels/[id]/agents/[agentId].delete.ts +23 -0
  655. package/server/api/workshop/channels/[id]/agents/[agentId].patch.ts +28 -0
  656. package/server/api/workshop/channels/[id]/agents/index.get.ts +27 -0
  657. package/server/api/workshop/channels/[id]/agents/index.post.ts +61 -0
  658. package/server/api/workshop/channels/[id]/events.get.ts +55 -0
  659. package/server/api/workshop/channels/[id]/index.get.ts +18 -0
  660. package/server/api/workshop/channels/[id]/index.patch.ts +30 -0
  661. package/server/api/workshop/channels/[id]/memories/[memoryId].delete.ts +29 -0
  662. package/server/api/workshop/channels/[id]/memories/index.get.ts +28 -0
  663. package/server/api/workshop/channels/[id]/memories/index.post.ts +42 -0
  664. package/server/api/workshop/channels/[id]/messages/index.get.ts +56 -0
  665. package/server/api/workshop/channels/[id]/messages/index.post.ts +75 -0
  666. package/server/api/workshop/channels/[id]/queue.get.ts +25 -0
  667. package/server/api/workshop/channels/[id]/tasks/index.get.ts +24 -0
  668. package/server/api/workshop/channels/[id]/tasks/index.post.ts +79 -0
  669. package/server/api/workshop/channels/[id]/terminals.get.ts +21 -0
  670. package/server/api/workshop/channels/[id].delete.ts +18 -0
  671. package/server/api/workshop/channels.get.ts +11 -0
  672. package/server/api/workshop/channels.post.ts +48 -0
  673. package/server/api/workshop/daq/[id]/bind.post.ts +19 -0
  674. package/server/api/workshop/daq/[id]/samples.get.ts +22 -0
  675. package/server/api/workshop/daq/[id]/test.post.ts +17 -0
  676. package/server/api/workshop/daq/[id].delete.ts +30 -0
  677. package/server/api/workshop/daq/[id].patch.ts +31 -0
  678. package/server/api/workshop/daq/alarms/[id]/ack.post.ts +15 -0
  679. package/server/api/workshop/daq/alarms.get.ts +16 -0
  680. package/server/api/workshop/daq/controller.post.ts +52 -0
  681. package/server/api/workshop/daq/index.get.ts +40 -0
  682. package/server/api/workshop/daq/index.post.ts +33 -0
  683. package/server/api/workshop/daq/infra/reconnect.post.ts +17 -0
  684. package/server/api/workshop/daq/infra.get.ts +11 -0
  685. package/server/api/workshop/daq/templates/[key].delete.ts +17 -0
  686. package/server/api/workshop/daq/templates/[key].patch.ts +18 -0
  687. package/server/api/workshop/daq/templates/index.post.ts +17 -0
  688. package/server/api/workshop/daq/test-driver.post.ts +23 -0
  689. package/server/api/workshop/dcw/[id]/bind.post.ts +17 -0
  690. package/server/api/workshop/dcw/[id]/param-ledger.get.ts +15 -0
  691. package/server/api/workshop/dcw/[id]/test.post.ts +15 -0
  692. package/server/api/workshop/dcw/[id]/write.post.ts +19 -0
  693. package/server/api/workshop/dcw/[id].delete.ts +30 -0
  694. package/server/api/workshop/dcw/[id].patch.ts +18 -0
  695. package/server/api/workshop/dcw/controller.post.ts +43 -0
  696. package/server/api/workshop/dcw/index.get.ts +25 -0
  697. package/server/api/workshop/dcw/index.post.ts +20 -0
  698. package/server/api/workshop/dcw/journal/index.get.ts +21 -0
  699. package/server/api/workshop/dcw/journal/node/[nodeId]/rollback.post.ts +22 -0
  700. package/server/api/workshop/dcw/line/query.get.ts +31 -0
  701. package/server/api/workshop/dcw/lines/[id]/start.post.ts +35 -0
  702. package/server/api/workshop/dcw/lines/[id]/stop.post.ts +34 -0
  703. package/server/api/workshop/dcw/lines/[id].delete.ts +35 -0
  704. package/server/api/workshop/dcw/lines/[id].patch.ts +15 -0
  705. package/server/api/workshop/dcw/lines/index.get.ts +14 -0
  706. package/server/api/workshop/dcw/lines/index.post.ts +31 -0
  707. package/server/api/workshop/dcw/optimizations/[id]/judge.post.ts +24 -0
  708. package/server/api/workshop/dcw/optimizations/[id]/rollback.post.ts +29 -0
  709. package/server/api/workshop/dcw/optimizations/[id]/series.get.ts +18 -0
  710. package/server/api/workshop/dcw/optimizations/[id].get.ts +17 -0
  711. package/server/api/workshop/dcw/optimizations/index.get.ts +23 -0
  712. package/server/api/workshop/dcw/products/[id].delete.ts +16 -0
  713. package/server/api/workshop/dcw/products/[id].patch.ts +17 -0
  714. package/server/api/workshop/dcw/products/index.post.ts +16 -0
  715. package/server/api/workshop/dcw/recipes/[id]/apply.post.ts +40 -0
  716. package/server/api/workshop/dcw/recipes/[id]/mark-good.post.ts +21 -0
  717. package/server/api/workshop/dcw/recipes/[id]/rollback-good.post.ts +19 -0
  718. package/server/api/workshop/dcw/recipes/[id].delete.ts +14 -0
  719. package/server/api/workshop/dcw/recipes/[id].patch.ts +16 -0
  720. package/server/api/workshop/dcw/recipes/index.get.ts +12 -0
  721. package/server/api/workshop/dcw/recipes/index.post.ts +15 -0
  722. package/server/api/workshop/dcw/runs/[id]/close.post.ts +15 -0
  723. package/server/api/workshop/dcw/runs/[id]/data.get.ts +15 -0
  724. package/server/api/workshop/dcw/runs/[id]/rollback.post.ts +20 -0
  725. package/server/api/workshop/dcw/runs/index.get.ts +11 -0
  726. package/server/api/workshop/dcw/templates/[key].delete.ts +14 -0
  727. package/server/api/workshop/dcw/templates/[key].patch.ts +16 -0
  728. package/server/api/workshop/dcw/templates/index.post.ts +15 -0
  729. package/server/api/workshop/dcw/test-driver.post.ts +16 -0
  730. package/server/api/workshop/device-twins/[id]/control.post.ts +21 -0
  731. package/server/api/workshop/device-twins/[id]/telemetry.post.ts +21 -0
  732. package/server/api/workshop/device-twins/[id].delete.ts +25 -0
  733. package/server/api/workshop/device-twins/[id].patch.ts +29 -0
  734. package/server/api/workshop/device-twins/index.get.ts +16 -0
  735. package/server/api/workshop/device-twins/index.post.ts +32 -0
  736. package/server/api/workshop/fs/dirs.get.ts +40 -0
  737. package/server/api/workshop/mailbox/all.get.ts +19 -0
  738. package/server/api/workshop/mailbox.get.ts +14 -0
  739. package/server/api/workshop/memories/maintenance.post.ts +15 -0
  740. package/server/api/workshop/ops-logs/index.get.ts +30 -0
  741. package/server/api/workshop/ops-logs/index.post.ts +39 -0
  742. package/server/api/workshop/runtime.get.ts +11 -0
  743. package/server/api/workshop/scene/layouts/[channelId].delete.ts +23 -0
  744. package/server/api/workshop/scene/layouts/[channelId].put.ts +31 -0
  745. package/server/api/workshop/scene/layouts.get.ts +13 -0
  746. package/server/api/workshop/tasks/[id]/cancel/index.post.ts +34 -0
  747. package/server/api/workshop/tasks/[id]/complete.post.ts +32 -0
  748. package/server/api/workshop/tasks/[id]/dispatch.post.ts +30 -0
  749. package/server/api/workshop/tasks/[id]/report.post.ts +38 -0
  750. package/server/api/workshop/tasks/[id]/retry.post.ts +33 -0
  751. package/server/api/workshop/tasks/[id].get.ts +32 -0
  752. package/server/api/workshop/tasks.get.ts +13 -0
  753. package/server/api/workshop/teams/[id]/deploy.post.ts +40 -0
  754. package/server/api/workshop/teams/[id]/members/[agentId].delete.ts +19 -0
  755. package/server/api/workshop/teams/[id]/members/index.get.ts +19 -0
  756. package/server/api/workshop/teams/[id]/members/index.post.ts +32 -0
  757. package/server/api/workshop/teams/[id].delete.ts +20 -0
  758. package/server/api/workshop/teams/[id].get.ts +19 -0
  759. package/server/api/workshop/teams/[id].patch.ts +32 -0
  760. package/server/api/workshop/teams/index.get.ts +13 -0
  761. package/server/api/workshop/teams/index.post.ts +27 -0
  762. package/server/api/workshop/users/me.get.ts +23 -0
  763. package/server/api/workshop/users/register.post.ts +33 -0
  764. package/server/api/workshop/workspaces/[id]/channel-templates/[tplId].post.ts +31 -0
  765. package/server/api/workshop/workspaces/[id]/channels/[channelId].delete.ts +15 -0
  766. package/server/api/workshop/workspaces/[id]/channels/[channelId].post.ts +15 -0
  767. package/server/api/workshop/workspaces/[id]/index.delete.ts +14 -0
  768. package/server/api/workshop/workspaces/index.get.ts +11 -0
  769. package/server/api/workshop/workspaces/index.post.ts +17 -0
  770. package/server/api/workshop/ws.ts +694 -0
  771. package/server/data/agent-node-bindings.json +554 -0
  772. package/server/data/daq-templates.json +16 -0
  773. package/server/data/daqs.json +2680 -0
  774. package/server/data/dcw-lines.json +919 -0
  775. package/server/data/dcw-products.json +835 -0
  776. package/server/data/dcw-recipes.json +1650 -0
  777. package/server/data/dcw-rollback.json +9339 -0
  778. package/server/data/dcw-runs.json +4633 -0
  779. package/server/data/dcw-templates.json +26 -0
  780. package/server/data/dcw-writes.json +9770 -0
  781. package/server/data/dcws.json +1736 -0
  782. package/server/data/device-twins.json +133 -0
  783. package/server/data/line-runs.json +152 -0
  784. package/server/data/scene-layouts.json +200 -0
  785. package/server/mcp/workshop-server.ts +510 -0
  786. package/server/middleware/request-log.ts +15 -0
  787. package/server/plugins/backup.ts +85 -0
  788. package/server/plugins/daq.ts +65 -0
  789. package/server/plugins/dev-stability-guard.ts +42 -0
  790. package/server/plugins/security.ts +29 -0
  791. package/server/plugins/system-config.ts +38 -0
  792. package/server/plugins/workshop.ts +145 -0
  793. package/server/repositories/user.repository.ts +391 -0
  794. package/server/schemas/user.schema.ts +67 -0
  795. package/server/services/system-config.ts +356 -0
  796. package/server/services/user.service.ts +186 -0
  797. package/server/services/workshop/agents/adapters/omp-rpc-client.ts +539 -0
  798. package/server/services/workshop/agents/adapters/to-a2a.ts +40 -0
  799. package/server/services/workshop/agents/agent-interface.ts +219 -0
  800. package/server/services/workshop/agents/claude-agent.ts +47 -0
  801. package/server/services/workshop/agents/factory.ts +24 -0
  802. package/server/services/workshop/agents/harness-process.ts +158 -0
  803. package/server/services/workshop/agents/harness-terminal.ts +545 -0
  804. package/server/services/workshop/agents/industrial-context.ts +222 -0
  805. package/server/services/workshop/agents/industrial-tools.ts +362 -0
  806. package/server/services/workshop/agents/mock-agent.ts +396 -0
  807. package/server/services/workshop/agents/node-bindings.repo.ts +165 -0
  808. package/server/services/workshop/agents/omp-agent.ts +1598 -0
  809. package/server/services/workshop/agents/tool-approvals.ts +174 -0
  810. package/server/services/workshop/assets/character-asset.repo.ts +120 -0
  811. package/server/services/workshop/assets/device-twin.repo.ts +236 -0
  812. package/server/services/workshop/daq/alarm-notify.ts +100 -0
  813. package/server/services/workshop/daq/bus/index.ts +46 -0
  814. package/server/services/workshop/daq/bus/inproc.adapter.ts +62 -0
  815. package/server/services/workshop/daq/bus/mqtt.adapter.ts +112 -0
  816. package/server/services/workshop/daq/bus/queue-port.ts +36 -0
  817. package/server/services/workshop/daq/daq-controller.ts +778 -0
  818. package/server/services/workshop/daq/daq-node.repo.ts +96 -0
  819. package/server/services/workshop/daq/daq-node.ts +247 -0
  820. package/server/services/workshop/daq/daq-runtime.ts +168 -0
  821. package/server/services/workshop/daq/daq-templates.ts +157 -0
  822. package/server/services/workshop/daq/drivers.ts +771 -0
  823. package/server/services/workshop/daq/host-bindings.ts +71 -0
  824. package/server/services/workshop/daq/host-ports.ts +64 -0
  825. package/server/services/workshop/daq/infra.ts +202 -0
  826. package/server/services/workshop/daq/storage/index.ts +96 -0
  827. package/server/services/workshop/daq/storage/sqlite.adapter.ts +205 -0
  828. package/server/services/workshop/daq/storage/timescale.adapter.ts +185 -0
  829. package/server/services/workshop/daq/storage/tsdb-port.ts +74 -0
  830. package/server/services/workshop/db/agent.repo.ts +105 -0
  831. package/server/services/workshop/db/channel-agent.repo.ts +119 -0
  832. package/server/services/workshop/db/channel-event.repo.ts +154 -0
  833. package/server/services/workshop/db/channel-template.repo.ts +113 -0
  834. package/server/services/workshop/db/channel.repo.ts +101 -0
  835. package/server/services/workshop/db/database.ts +934 -0
  836. package/server/services/workshop/db/memory.repo.ts +249 -0
  837. package/server/services/workshop/db/message.repo.ts +149 -0
  838. package/server/services/workshop/db/ops.repo.ts +323 -0
  839. package/server/services/workshop/db/schema.sql +143 -0
  840. package/server/services/workshop/db/subscription.repo.ts +62 -0
  841. package/server/services/workshop/db/task.repo.ts +175 -0
  842. package/server/services/workshop/db/team-member.repo.ts +70 -0
  843. package/server/services/workshop/db/team.repo.ts +109 -0
  844. package/server/services/workshop/db/user.repo.ts +100 -0
  845. package/server/services/workshop/dcw/dcw-controller.ts +841 -0
  846. package/server/services/workshop/dcw/dcw-line.repo.ts +86 -0
  847. package/server/services/workshop/dcw/dcw-node.repo.ts +89 -0
  848. package/server/services/workshop/dcw/dcw-node.ts +200 -0
  849. package/server/services/workshop/dcw/dcw-product.repo.ts +95 -0
  850. package/server/services/workshop/dcw/dcw-recipe.repo.ts +349 -0
  851. package/server/services/workshop/dcw/dcw-runtime.ts +82 -0
  852. package/server/services/workshop/dcw/dcw-templates.ts +138 -0
  853. package/server/services/workshop/dcw/drivers.ts +523 -0
  854. package/server/services/workshop/dcw/line-run.ts +101 -0
  855. package/server/services/workshop/dcw/recipe-rollback-manager.ts +702 -0
  856. package/server/services/workshop/dcw/recipe-rollback.repo.ts +197 -0
  857. package/server/services/workshop/logger.ts +58 -0
  858. package/server/services/workshop/ops/ops.ts +78 -0
  859. package/server/services/workshop/prompts/loader.ts +112 -0
  860. package/server/services/workshop/runtime/agent-runtime.ts +698 -0
  861. package/server/services/workshop/runtime/channel-runtime.ts +202 -0
  862. package/server/services/workshop/runtime/embedding-provider.ts +79 -0
  863. package/server/services/workshop/runtime/execution-mode.ts +215 -0
  864. package/server/services/workshop/runtime/mailbox.ts +148 -0
  865. package/server/services/workshop/runtime/manager.ts +2543 -0
  866. package/server/services/workshop/runtime/memory.ts +439 -0
  867. package/server/services/workshop/runtime/monitor.ts +194 -0
  868. package/server/services/workshop/runtime/scheduler-loop.ts +773 -0
  869. package/server/services/workshop/runtime/task-engine.ts +574 -0
  870. package/server/services/workshop/scene/scene-layout.repo.ts +112 -0
  871. package/server/services/workshop/scene-events.ts +63 -0
  872. package/server/services/workshop/types/a2a.ts +61 -0
  873. package/server/services/workshop/types/task.ts +85 -0
  874. package/server/types/user.ts +53 -0
  875. package/server/utils/approval-gate.ts +67 -0
  876. package/server/utils/auth.ts +13 -0
  877. package/server/utils/config.ts +40 -0
  878. package/server/utils/errors.ts +24 -0
  879. package/server/utils/response.ts +49 -0
  880. package/server/utils/validate.ts +19 -0
  881. package/shared/config/engine.d.mts +41 -0
  882. package/shared/config/engine.mjs +291 -0
  883. package/shared/config/home.d.mts +48 -0
  884. package/shared/config/home.mjs +146 -0
  885. package/shared/config/schema.json +30 -0
  886. package/shared/daq-protocol.ts +361 -0
  887. package/shared/dcw-protocol.ts +576 -0
  888. package/shared/terminal-protocol.ts +70 -0
  889. package/shared/town-anim.ts +56 -0
  890. package/shared/town-behavior.ts +136 -0
  891. package/shared/town-protocol.ts +110 -0
  892. package/shared/town-scene-math.ts +283 -0
  893. package/shared/workshop-protocol.ts +199 -0
  894. package/tsconfig.json +10 -0
  895. package/uno.config.ts +37 -0
@@ -0,0 +1,841 @@
1
+ /**
2
+ * DcwController —— 数据写控制网关(应用级单例,与 DaqController 对称)。
3
+ *
4
+ * 每个写控制节点一个独立 DcwNodeRuntime(边缘控制运行时),网关统一调度:
5
+ * - 手动写命令(REST/前端设定)→ 工程量校验 → 驱动写(换算/回读校验在驱动)
6
+ * → ACK 记账(节点状态/写历史/WS dcw.written 直推)
7
+ * - 保写心跳(runtime 元数据 holdIntervalMs,PLC 设定恢复语义)
8
+ * - Recipe 应用:批次(Run)隔离 + 逐参数写 + 结果快照
9
+ * 用户语义 = 工程量;PLC 底层全部由系统封装。
10
+ */
11
+
12
+ import { randomUUID } from 'node:crypto'
13
+ import { applyTransform, inverseTransform, normalizeDataTransform, dcwKeyFromRef } from '../../../../shared/dcw-protocol'
14
+ import type { AepDcwNodeChange, DcwDriverKind, DcwNodeView, DataTransform, LineInput, LineQueryOpts, LineQueryResult, LineRunState, LineView, ProductInput, ProductView, RecipeInput, RecipeRunView, RecipeView, DcwWriteMeta } from '../../../../shared/dcw-protocol'
15
+ import { AppError, ErrorCodes } from '../../../utils/errors'
16
+ import { normalizeDcwDriverKind, resolveDcwDriver } from './drivers'
17
+ import { findDcwTemplate } from './dcw-templates'
18
+ import { getDeviceTwinRepo } from '../assets/device-twin.repo'
19
+ import { DcwNode } from './dcw-node'
20
+ import { getDcwNodeRepo } from './dcw-node.repo'
21
+ import { DcwNodeRuntime } from './dcw-runtime'
22
+ import { getDcwRecipeRepo, type DcwWriteHistoryEntry } from './dcw-recipe.repo'
23
+ import { getDcwProductRepo } from './dcw-product.repo'
24
+ import { getDcwLineRepo } from './dcw-line.repo'
25
+ import { clearActiveLineRun, getActiveLineRun, getAllActiveLineRuns, setActiveLineRun } from './line-run'
26
+ import { getRecipeRollBackManager } from './recipe-rollback-manager'
27
+ import { recordOps } from '../ops/ops'
28
+
29
+ /** 运维日志写下发防噪:同节点同值 10s 内的心跳重下发不重复入册 */
30
+ const opsWriteMemo = new Map<string, { eng: number, at: number }>()
31
+
32
+ /** write() 来源 → 日志来源(user 人工下发 / agent 智能体 / system 配方·回退等系统路径) */
33
+ function opsActorKindOf(source: string): 'user' | 'agent' | 'system' {
34
+ if (source === 'agent') return 'agent'
35
+ if (source === 'manual') return 'user'
36
+ return 'system'
37
+ }
38
+
39
+ type BroadcastFn = (type: string, payload: unknown) => void
40
+
41
+ export interface DcwCreateInput {
42
+ templateRef?: string
43
+ name?: string
44
+ driver?: DcwDriverKind
45
+ driverConfig?: Record<string, string | number | boolean>
46
+ /** 数据语义标定钩子(encode:物理值 → PLC 设定值) */
47
+ transform?: DataTransform
48
+ holdIntervalMs?: number | null
49
+ unit?: string
50
+ decimals?: number
51
+ min?: number
52
+ max?: number
53
+ enabled?: boolean
54
+ posX?: number
55
+ posZ?: number
56
+ deviceBindingId?: string | null
57
+ /** 所属产线('' = 未分配) */
58
+ lineId?: string
59
+ /** 节点级工艺语义备注(覆盖模板) */
60
+ semantics?: string
61
+ }
62
+
63
+ export interface DcwPatchInput {
64
+ name?: string
65
+ driver?: DcwDriverKind
66
+ driverConfig?: Record<string, string | number | boolean>
67
+ /** 数据语义标定钩子(encode) */
68
+ transform?: DataTransform
69
+ holdIntervalMs?: number | null
70
+ unit?: string
71
+ decimals?: number
72
+ min?: number
73
+ max?: number
74
+ enabled?: boolean
75
+ posX?: number
76
+ posZ?: number
77
+ lineId?: string
78
+ semantics?: string
79
+ }
80
+
81
+ /** 网关扫描周期(ms;保写心跳分辨率) */
82
+ const SWEEP_MS = 500
83
+
84
+ class DcwController {
85
+ private repo = getDcwNodeRepo()
86
+ private broadcast: BroadcastFn | null = null
87
+ private timer: NodeJS.Timeout | null = null
88
+ /** 边缘控制运行时注册表(节点 id → 独立运行时) */
89
+ private runtimes = new Map<string, DcwNodeRuntime>()
90
+
91
+ running = true
92
+ private writesTotal = 0
93
+ private writesFailed = 0
94
+
95
+ // ---------- 生命周期 ----------
96
+
97
+ private ensureLoop(): void {
98
+ this.syncRuntimes()
99
+ if (this.timer) return
100
+ this.timer = setInterval(() => this.sweep(), SWEEP_MS)
101
+ this.timer.unref?.()
102
+ }
103
+
104
+ /** 网关统一调度:保写心跳在各运行时内部自治(单节点写事务不波及邻居);
105
+ * 调控闭环:open 优化记录的系统兜底评估复用本节拍(F1,不建新定时器) */
106
+ private sweep(): void {
107
+ if (!this.running) return
108
+ const now = Date.now()
109
+ for (const rt of this.runtimes.values()) rt.tick(now)
110
+ getRecipeRollBackManager().evaluateOpenRecords(now)
111
+ }
112
+
113
+ private syncRuntimes(): void {
114
+ const live = new Set<string>()
115
+ for (const node of this.repo.all()) {
116
+ live.add(node.id)
117
+ if (!this.runtimes.has(node.id)) {
118
+ this.runtimes.set(node.id, new DcwNodeRuntime(node, this.host))
119
+ }
120
+ }
121
+ for (const id of [...this.runtimes.keys()]) {
122
+ if (!live.has(id)) this.runtimes.delete(id)
123
+ }
124
+ }
125
+
126
+ // ---------- 网关服务面(runtime host)----------
127
+
128
+ private host = {
129
+ running: () => this.running,
130
+ defaults: () => ({ holdIntervalMs: 0 }),
131
+ executeWrite: async (node: DcwNode, eng: number, tolerance: number, recipeRunId: string | null) =>
132
+ this.executeWrite(node, eng, tolerance, recipeRunId),
133
+ }
134
+
135
+ /**
136
+ * 核心写执行:驱动写(工程量→原始值换算 + 回读校验在驱动内)
137
+ * → ACK 记账(节点状态/写历史)→ WS 直推。真实/模拟驱动同一路径。
138
+ */
139
+ private async executeWrite(node: DcwNode, eng: number, tolerance: number, recipeRunId: string | null): Promise<{ ok: boolean, message: string, raw: number | null, readback: number | null }> {
140
+ const at = new Date().toISOString()
141
+ // 数据语义标定钩子(encode):物理值 → PLC 设定值。
142
+ // 回读值再经 decoder 换算回物理量做死区校验(容差按标定比例同步缩放)。
143
+ const t = node.transform
144
+ const plcValue = inverseTransform(eng, t)
145
+ const plcTolerance = Math.max(tolerance, 1e-9) / (t?.kind === 'linear' && Math.abs(t.scale ?? 1) > 0 ? Math.abs(t.scale!) : 1)
146
+ let outcome: { ok: boolean, message: string, raw: number | null, readback: number | null }
147
+ try {
148
+ outcome = await resolveDcwDriver(node.driver).write({
149
+ eng: plcValue,
150
+ tolerance: plcTolerance,
151
+ domain: { min: node.min, max: node.max },
152
+ driverConfig: node.driverConfig,
153
+ })
154
+ // 回读换算回物理量(message 保留 PLC 域数值供排查)
155
+ if (outcome.readback != null) outcome.readback = applyTransform(outcome.readback, t)
156
+ if (outcome.ok) outcome.message = `${outcome.message}(标定后物理值 ${Number((outcome.readback ?? eng).toFixed(node.decimals))})`
157
+ }
158
+ catch (err) {
159
+ outcome = { ok: false, message: err instanceof Error ? err.message : String(err), raw: null, readback: null }
160
+ }
161
+ this.writesTotal++
162
+ if (!outcome.ok) this.writesFailed++
163
+ // set 后 hook:节点暴露值 = PLC 回读经 decoder 解码的**真实物理值**(而非指令值);
164
+ // 回读缺失(驱动不支持)才回退指令值。节点对外呈现的始终是处理后的工艺参数。
165
+ node.applyWriteResult(outcome.readback ?? eng, outcome.ok, outcome.message, at)
166
+ // 写值走防抖落盘:保写心跳按 holdIntervalMs 周期触发本方法,同步全量重写
167
+ // dcws.json 会随节点数放大成周期性 fs 抖动;防抖窗内崩溃丢失的设定值可从 PLC 回读恢复
168
+ this.repo.flushDebounced()
169
+ const repo = getDcwRecipeRepo()
170
+ const entry: DcwWriteHistoryEntry = {
171
+ id: `wh-${randomUUID().slice(0, 8)}`,
172
+ nodeId: node.id,
173
+ nodeName: node.name,
174
+ param: findDcwTemplate(node.templateKey)?.ch ?? node.templateKey,
175
+ eng: node.value ?? eng,
176
+ raw: outcome.raw,
177
+ ok: outcome.ok,
178
+ message: outcome.message,
179
+ recipeRunId,
180
+ at,
181
+ }
182
+ repo.appendHistory(entry)
183
+ this.broadcast?.('dcw.written', {
184
+ nodeId: node.id,
185
+ templateRef: node.templateRef,
186
+ value: node.value ?? eng,
187
+ raw: outcome.raw,
188
+ ok: outcome.ok,
189
+ message: outcome.message,
190
+ recipeRunId,
191
+ at,
192
+ })
193
+ this.emitNodeChanged('updated', node)
194
+ return outcome
195
+ }
196
+
197
+ private emitNodeChanged(op: AepDcwNodeChange['op'], node: DcwNode | null): void {
198
+ const payload: AepDcwNodeChange = { op, node: node ? node.toView() : null }
199
+ this.broadcast?.('dcw.node.changed', payload)
200
+ }
201
+
202
+ setBroadcast(fn: BroadcastFn | null): void {
203
+ this.broadcast = fn
204
+ // 调控闭环 WS 帧(dcw.optimization.changed)与既有帧同一广播通道
205
+ getRecipeRollBackManager().setBroadcast(fn)
206
+ }
207
+
208
+ // ---------- 查询 ----------
209
+
210
+ listViews(): DcwNodeView[] {
211
+ this.ensureLoop()
212
+ return this.repo.all().map(n => n.toView())
213
+ }
214
+
215
+ byId(id: string): DcwNode | undefined {
216
+ return this.repo.byId(id)
217
+ }
218
+
219
+ controllerState() {
220
+ return {
221
+ running: this.running,
222
+ nodesTotal: this.repo.all().length,
223
+ nodesOnline: this.running ? this.repo.all().filter(n => n.enabled).length : 0,
224
+ writesTotal: this.writesTotal,
225
+ writesFailed: this.writesFailed,
226
+ }
227
+ }
228
+
229
+ // ---------- 网关全局 ----------
230
+
231
+ startAll() {
232
+ this.running = true
233
+ // 恢复控制:因「暂停全部控制」转 offline 的启用节点回待机(暂停态与恢复态对称)
234
+ for (const n of this.repo.all()) {
235
+ if (n.enabled && n.state === 'offline') n.state = 'idle'
236
+ }
237
+ this.ensureLoop()
238
+ this.broadcast?.('dcw.controller', this.controllerState())
239
+ return this.controllerState()
240
+ }
241
+
242
+ stopAll() {
243
+ this.running = false
244
+ for (const n of this.repo.all()) {
245
+ if (n.enabled && n.value != null) n.state = 'offline'
246
+ }
247
+ this.broadcast?.('dcw.controller', this.controllerState())
248
+ return this.controllerState()
249
+ }
250
+
251
+ /**
252
+ * 暂停全部控制 → 网关停止;恢复全部控制 → 网关启动。
253
+ * 节点启停与网关暂停完全独立:enabled 标志是唯一下发资格,恢复后只有
254
+ * enabled=true(即暂停时刻在控制的那批)的节点恢复;暂停前/暂停期间
255
+ * 手动停用的节点保持停用,不会被自动拉起。
256
+ */
257
+ pauseAll() {
258
+ return this.stopAll()
259
+ }
260
+
261
+ resumeAll() {
262
+ return this.startAll()
263
+ }
264
+
265
+ // ---------- 节点 CRUD(单点控制入口)----------
266
+
267
+ create(input: DcwCreateInput): DcwNode {
268
+ this.ensureLoop()
269
+ if (!input.templateRef) {
270
+ throw new AppError(400, ErrorCodes.VALIDATION_ERROR, 'templateRef 必填:控制节点必须绑定工艺参数模板')
271
+ }
272
+ const tpl = findDcwTemplate(dcwKeyFromRef(input.templateRef))
273
+ if (!tpl) {
274
+ throw new AppError(404, ErrorCodes.NOT_FOUND, `未知控制模板: ${input.templateRef}`)
275
+ }
276
+ const seq = this.repo.all().filter(n => n.templateKey === dcwKeyFromRef(input.templateRef!)).length + 1
277
+ const node = new DcwNode({
278
+ id: `dw-${randomUUID().slice(0, 8)}`,
279
+ templateRef: input.templateRef,
280
+ name: input.name ?? `${tpl.name} ${String(seq).padStart(2, '0')}`,
281
+ driver: input.driver ? normalizeDcwDriverKind(input.driver) : undefined,
282
+ driverConfig: input.driverConfig ?? {},
283
+ transform: normalizeDataTransform(input.transform),
284
+ enabled: input.enabled,
285
+ holdIntervalMs: input.holdIntervalMs ?? null,
286
+ unit: input.unit,
287
+ decimals: input.decimals,
288
+ min: input.min,
289
+ max: input.max,
290
+ deviceBindingId: input.deviceBindingId ?? null,
291
+ posX: input.posX,
292
+ posZ: input.posZ,
293
+ lineId: input.lineId,
294
+ semantics: input.semantics,
295
+ })
296
+ this.repo.insert(node)
297
+ this.syncRuntimes()
298
+ this.emitNodeChanged('added', node)
299
+ return node
300
+ }
301
+
302
+ patch(id: string, patch: DcwPatchInput): DcwNode {
303
+ const node = this.repo.byId(id)
304
+ if (!node) throw new AppError(404, ErrorCodes.NOT_FOUND, `控制节点不存在: ${id}`)
305
+ let rearm = false
306
+ if (patch.name !== undefined) node.name = patch.name
307
+ if (patch.driver !== undefined) node.driver = normalizeDcwDriverKind(patch.driver)
308
+ if (patch.driverConfig !== undefined) node.driverConfig = { ...node.driverConfig, ...patch.driverConfig }
309
+ if (patch.transform !== undefined) {
310
+ if (patch.transform.kind === 'linear' && (!Number.isFinite(Number(patch.transform.scale)) || Number(patch.transform.scale) === 0)) {
311
+ throw new AppError(400, ErrorCodes.VALIDATION_ERROR, '标定系数 scale 必须为非零数字(物理值 = scale × PLC值 + offset)')
312
+ }
313
+ node.transform = normalizeDataTransform(patch.transform)
314
+ }
315
+ if (patch.unit !== undefined) node.unit = patch.unit
316
+ if (patch.decimals !== undefined) node.decimals = patch.decimals
317
+ if (patch.min !== undefined) node.min = patch.min
318
+ if (patch.max !== undefined) node.max = patch.max
319
+ if (patch.holdIntervalMs !== undefined) {
320
+ node.holdIntervalMs = patch.holdIntervalMs == null ? null : Math.max(0, Math.min(3_600_000, Math.round(patch.holdIntervalMs)))
321
+ rearm = true
322
+ }
323
+ if (patch.enabled !== undefined) {
324
+ node.enabled = patch.enabled
325
+ // 暂停/恢复的状态同步:暂停 → offline(暂停控制);恢复 → 回到待机(等下次写 ACK 转 ok)
326
+ if (!patch.enabled) node.state = 'offline'
327
+ else if (node.state === 'offline') node.state = 'idle'
328
+ rearm = true
329
+ }
330
+ if (patch.posX !== undefined) node.posX = patch.posX
331
+ if (patch.posZ !== undefined) node.posZ = patch.posZ
332
+ if (patch.lineId !== undefined) {
333
+ const lid = String(patch.lineId)
334
+ if (lid && !getDcwLineRepo().byId(lid)) throw new AppError(404, ErrorCodes.NOT_FOUND, `产线不存在: ${lid}`)
335
+ node.lineId = lid
336
+ }
337
+ if (patch.semantics !== undefined) node.semantics = String(patch.semantics)
338
+ if (rearm) this.runtimes.get(id)?.rearm()
339
+ this.repo.flushNow()
340
+ this.emitNodeChanged('updated', node)
341
+ return node
342
+ }
343
+
344
+ remove(id: string): void {
345
+ const node = this.repo.byId(id)
346
+ if (!node) throw new AppError(404, ErrorCodes.NOT_FOUND, `控制节点不存在: ${id}`)
347
+ this.repo.remove(id)
348
+ this.runtimes.delete(id)
349
+ // 级联清理:该节点的 Agent 绑定移除,挂起中的手动审批按失效收敛
350
+ void import('../agents/node-bindings.repo').then(({ getAgentNodeBindingRepo }) => {
351
+ const repo = getAgentNodeBindingRepo()
352
+ for (const b of repo.byNode(id)) {
353
+ void import('../agents/tool-approvals').then(({ getToolApprovals }) => {
354
+ getToolApprovals().cancelPendingFor(b.agentId, id)
355
+ }).catch(() => {})
356
+ repo.removeAgentNode(b.agentId, id, 'dcw')
357
+ }
358
+ }).catch(() => {})
359
+ this.emitNodeChanged('removed', node)
360
+ }
361
+
362
+ bind(id: string, deviceId: string | null): DcwNode {
363
+ const node = this.repo.byId(id)
364
+ if (!node) throw new AppError(404, ErrorCodes.NOT_FOUND, `控制节点不存在: ${id}`)
365
+ if (deviceId) {
366
+ const twin = getDeviceTwinRepo().findById(deviceId)
367
+ if (!twin) throw new AppError(404, ErrorCodes.NOT_FOUND, `目标设备不存在: ${deviceId}`)
368
+ }
369
+ node.deviceBindingId = deviceId
370
+ this.repo.flushNow()
371
+ this.emitNodeChanged('updated', node)
372
+ return node
373
+ }
374
+
375
+ /** 设备删除级联解绑(device-twins 删除路由调用) */
376
+ unbindDevice(deviceId: string): void {
377
+ for (const node of this.repo.all()) {
378
+ if (node.deviceBindingId !== deviceId) continue
379
+ node.deviceBindingId = null
380
+ this.repo.flushNow()
381
+ this.emitNodeChanged('updated', node)
382
+ }
383
+ }
384
+
385
+ // ---------- 写命令(上位机核心操作)----------
386
+
387
+ /** 手动设定:用户提交工程量,网关校验/换算/下发/回读校验。
388
+ * 配方联锁:产线运行中,写入值还须落在活动配方对该参数的工艺窗口内
389
+ * (节点全局量程之外的第二道约束 —— 换配方即换工艺窗口)。
390
+ * meta(F7):账本与优化记录的身份信息 —— 手动/配方/Agent/回退四路共用本入口,
391
+ * 缺省按 manual/user 记账;调控闭环护栏(Agent 互斥/回退冷却)在 beforeWrite。 */
392
+ async write(id: string, eng: number, recipeRunId: string | null = null, meta?: DcwWriteMeta) {
393
+ this.ensureLoop()
394
+ const rt = this.runtimes.get(id)
395
+ if (!rt) throw new AppError(404, ErrorCodes.NOT_FOUND, `控制节点不存在: ${id}`)
396
+ const node = rt.node
397
+ // 控制暂停双重门控:网关全局暂停(暂停全部控制)或节点级暂停 → 一律拒绝下发。
398
+ // 手动 REST / 配方下发 / 产线开跑 / Agent 工具共用本入口,拒绝语义单点收敛。
399
+ if (!this.running) {
400
+ throw new AppError(409, ErrorCodes.CONFLICT, '控制网关已暂停(暂停全部控制):设定下发被拒绝,请先「恢复全部控制」')
401
+ }
402
+ if (!node.enabled) {
403
+ throw new AppError(409, ErrorCodes.CONFLICT, `当前节点暂停:「${node.name}」控制已暂停,仅开启控制的节点可被设定`)
404
+ }
405
+ // 调控闭环护栏(F1/F8):Agent 互斥(open 记录他人持有)+ 回退冷却方向性
406
+ getRecipeRollBackManager().beforeWrite(node, eng, meta)
407
+ // 写联锁按产线:仅当**本节点所属产线**在跑时,叠加该批次配方的工艺窗口
408
+ const run = getActiveLineRun(node.lineId)
409
+ if (run && recipeRunId == null) {
410
+ const recipe = getDcwRecipeRepo().byId(run.recipeId)
411
+ const param = recipe?.params.find(p => p.nodeId === id)
412
+ if (param) {
413
+ if (param.min != null && eng < param.min) {
414
+ throw new AppError(400, ErrorCodes.VALIDATION_ERROR, `设定值 ${eng}${node.unit} 低于当前配方「${run.recipeName}」的工艺下限 ${param.min}${node.unit}(节点全局量程 ${node.min}~${node.max} 不适用于本批次)`)
415
+ }
416
+ if (param.max != null && eng > param.max) {
417
+ throw new AppError(400, ErrorCodes.VALIDATION_ERROR, `设定值 ${eng}${node.unit} 超出当前配方「${run.recipeName}」的工艺上限 ${param.max}${node.unit}(节点全局量程 ${node.min}~${node.max} 不适用于本批次)`)
418
+ }
419
+ }
420
+ }
421
+ const prevValue = typeof node.value === 'number' ? node.value : null
422
+ const outcome = await rt.write(eng, recipeRunId)
423
+ // 调控闭环入册:仅成功写记锚/开记录(失败写不动账本 —— PLC 值未变更);
424
+ // 窗口聚合异步回填(F2)
425
+ if (outcome.ok !== false) {
426
+ try {
427
+ const rbInfo = getRecipeRollBackManager().afterWrite(
428
+ node,
429
+ eng,
430
+ prevValue,
431
+ meta ?? { source: recipeRunId ? 'recipe' : 'manual', actor: 'user' },
432
+ recipeRunId,
433
+ )
434
+ if (rbInfo) {
435
+ outcome.recordId = rbInfo.recordId
436
+ outcome.anchorId = rbInfo.anchorId
437
+ }
438
+ }
439
+ catch (err) {
440
+ console.error('[dcw] 调控闭环入册失败(不影响写结果):', err)
441
+ }
442
+ // 运维日志:所有下发路径(manual/recipe/agent/rollback)单点入册 + 实时事件
443
+ try {
444
+ const src = meta?.source ?? (recipeRunId ? 'recipe' : 'manual')
445
+ const memo = opsWriteMemo.get(id)
446
+ const now = Date.now()
447
+ if (!memo || memo.eng !== eng || now - memo.at > 10_000) {
448
+ opsWriteMemo.set(id, { eng, at: now })
449
+ if (opsWriteMemo.size > 500)
450
+ opsWriteMemo.clear()
451
+ const runNow = getActiveLineRun(node.lineId)
452
+ recordOps({
453
+ actor: meta?.actor ?? 'user',
454
+ actorName: meta?.actorName ?? meta?.actor ?? 'user',
455
+ actorKind: opsActorKindOf(src),
456
+ action: `dcw.write.${src}`,
457
+ kind: 'write',
458
+ targetKind: 'dcw-node',
459
+ targetId: id,
460
+ summary: `下发设定「${node.name}」→ ${eng}${node.unit ?? ''}(${src === 'manual' ? '手动' : src === 'agent' ? 'Agent' : src === 'rollback' ? '回退恢复' : '配方'})`,
461
+ lineId: node.lineId ?? '',
462
+ productId: runNow?.productId ?? '',
463
+ recipeId: runNow?.recipeId ?? recipeRunId ?? '',
464
+ detail: { eng, prevValue, ok: outcome.ok, message: outcome.message, taskId: meta?.taskId ?? null },
465
+ })
466
+ }
467
+ }
468
+ catch {
469
+ // 日志失败不影响写结果
470
+ }
471
+ }
472
+ return outcome
473
+ }
474
+
475
+ /** 连接测试 */
476
+ async testDriver(kind: DcwDriverKind, driverConfig: Record<string, unknown>) {
477
+ return resolveDcwDriver(normalizeDcwDriverKind(kind)).test(driverConfig)
478
+ }
479
+
480
+ async testNode(id: string) {
481
+ const node = this.repo.byId(id)
482
+ if (!node) throw new AppError(404, ErrorCodes.NOT_FOUND, `控制节点不存在: ${id}`)
483
+ return this.testDriver(node.driver, node.driverConfig)
484
+ }
485
+
486
+ // ---------- Recipe 配方 ----------
487
+
488
+ listRecipes() {
489
+ return getDcwRecipeRepo().list()
490
+ }
491
+
492
+ createRecipe(input: RecipeInput) {
493
+ return getDcwRecipeRepo().create(input)
494
+ }
495
+
496
+ updateRecipe(id: string, patch: Partial<RecipeInput>) {
497
+ return getDcwRecipeRepo().update(id, patch)
498
+ }
499
+
500
+ removeRecipe(id: string): void {
501
+ if (!getDcwRecipeRepo().remove(id)) throw new AppError(404, ErrorCodes.NOT_FOUND, `Recipe 不存在: ${id}`)
502
+ }
503
+
504
+ listRuns() {
505
+ return getDcwRecipeRepo().listRuns()
506
+ }
507
+
508
+ listHistory(limit = 100): DcwWriteHistoryEntry[] {
509
+ return getDcwRecipeRepo().historyList(limit)
510
+ }
511
+
512
+ /**
513
+ * 逐参数写核心(apply 与产线开跑共用):**节点级寻址** —— 每个参数显式指向
514
+ * 控制节点(节点才是真实控制 PLC 工艺参数的执行体)→ 逐参数写命令
515
+ * (runId 入写历史)→ 结果快照。节点不存在 → 该参数记失败不阻塞其余。
516
+ */
517
+ private async writeRecipeParams(recipe: RecipeView, run: RecipeRunView): Promise<void> {
518
+ const results: RecipeRunView['results'] = []
519
+ for (const param of recipe.params) {
520
+ const node = param.nodeId ? this.repo.byId(param.nodeId) : undefined
521
+ if (!node) {
522
+ results.push({ templateRef: param.templateRef ?? param.nodeId, nodeId: null, ok: false, message: `目标控制节点不存在(${param.nodeId}),参数未下发`, value: param.value })
523
+ continue
524
+ }
525
+ try {
526
+ const outcome = await this.write(node.id, param.value, run.id, { source: 'recipe', actor: 'recipe' })
527
+ results.push({ templateRef: node.templateRef, nodeId: node.id, ok: outcome.ok, message: outcome.message, value: param.value })
528
+ }
529
+ catch (err) {
530
+ results.push({ templateRef: node.templateRef, nodeId: node.id, ok: false, message: err instanceof Error ? err.message : String(err), value: param.value })
531
+ }
532
+ }
533
+ run.results = results
534
+ getDcwRecipeRepo().updateRun(run)
535
+ }
536
+
537
+ /** Recipe 手动应用(一键下发工艺参数集;不激活产线窗口) */
538
+ async applyRecipe(recipeId: string) {
539
+ this.ensureLoop()
540
+ const repo = getDcwRecipeRepo()
541
+ const recipe = repo.byId(recipeId)
542
+ if (!recipe) throw new AppError(404, ErrorCodes.NOT_FOUND, `Recipe 不存在: ${recipeId}`)
543
+ if (recipe.params.length === 0) throw new AppError(400, ErrorCodes.VALIDATION_ERROR, 'Recipe 无工艺参数,无可下发内容')
544
+ const run = repo.createRun(recipe)
545
+ await this.writeRecipeParams(recipe, run)
546
+ return run
547
+ }
548
+
549
+ closeRun(id: string) {
550
+ return getDcwRecipeRepo().closeRun(id)
551
+ }
552
+
553
+ // ---------- 产线(实体 CRUD;节点/产品/配方挂载其下实现隔离) ----------
554
+
555
+ listLines(): LineView[] {
556
+ return getDcwLineRepo().all()
557
+ }
558
+
559
+ createLine(input: LineInput): LineView {
560
+ return getDcwLineRepo().create(input)
561
+ }
562
+
563
+ updateLine(id: string, patch: Partial<LineInput>): LineView {
564
+ return getDcwLineRepo().update(id, patch)
565
+ }
566
+
567
+ /** 删除产线:自动停止运行窗口。purge=true 连同旗下节点(含 Agent 绑定级联)/产品/配方一并删除;
568
+ * 否则仅解除挂载(lineId='' 未分配),节点与历史数据保留 */
569
+ async removeLine(id: string, opts?: { purge?: boolean }): Promise<void> {
570
+ const line = getDcwLineRepo().byId(id)
571
+ if (!line) throw new AppError(404, ErrorCodes.NOT_FOUND, `产线不存在: ${id}`)
572
+ if (getActiveLineRun(id)) this.lineStop(id)
573
+ // 快照迭代:purge 分支的 this.remove 会边遍历边删节点
574
+ for (const n of [...this.repo.all()]) {
575
+ if (n.lineId !== id) continue
576
+ if (opts?.purge) this.remove(n.id)
577
+ else {
578
+ n.lineId = ''
579
+ this.emitNodeChanged('updated', n)
580
+ }
581
+ }
582
+ if (opts?.purge) {
583
+ this.repo.flushNow()
584
+ const productRepo = getDcwProductRepo()
585
+ for (const p of productRepo.all()) {
586
+ if (p.lineId === id) productRepo.remove(p.id)
587
+ }
588
+ const recipeRepo = getDcwRecipeRepo()
589
+ for (const r of recipeRepo.list()) {
590
+ if (r.lineId === id) recipeRepo.remove(r.id)
591
+ }
592
+ }
593
+ else {
594
+ const productRepo = getDcwProductRepo()
595
+ for (const p of productRepo.all()) {
596
+ if (p.lineId === id) productRepo.update(p.id, { lineId: '' })
597
+ }
598
+ const recipeRepo = getDcwRecipeRepo()
599
+ for (const r of recipeRepo.list()) {
600
+ if (r.lineId === id) recipeRepo.detachLine(r.id)
601
+ }
602
+ }
603
+ getDcwLineRepo().remove(id)
604
+ this.broadcast?.('dcw.controller', this.controllerState())
605
+ }
606
+
607
+ // ---------- 产线运营(逐产线开跑;开跑必设配方;窗口内数采逐样本打标) ----------
608
+
609
+ /**
610
+ * 产线开跑:选定产品+配方 → 下发配方参数 → 创建批次并激活**该产线**窗口。
611
+ * 门控:配方必归属本产线的产品且含工艺参数 —— 未设定配方不可开跑数据采集。
612
+ */
613
+ async lineStart(lineId: string, recipeId: string) {
614
+ this.ensureLoop()
615
+ if (!this.running) {
616
+ throw new AppError(409, ErrorCodes.CONFLICT, '控制网关已暂停(暂停全部控制):开跑需下发配方参数,请先「恢复全部控制」')
617
+ }
618
+ const line = getDcwLineRepo().byId(lineId)
619
+ if (!line) throw new AppError(404, ErrorCodes.NOT_FOUND, `产线不存在: ${lineId}`)
620
+ if (getActiveLineRun(lineId)) {
621
+ throw new AppError(409, ErrorCodes.CONFLICT, `产线「${line.name}」已在运行(批次 ${getActiveLineRun(lineId)!.runId}),请先停止当前数据采集`)
622
+ }
623
+ const repo = getDcwRecipeRepo()
624
+ const recipe = repo.byId(recipeId)
625
+ if (!recipe) throw new AppError(404, ErrorCodes.NOT_FOUND, `Recipe 不存在: ${recipeId}`)
626
+ if (recipe.lineId !== lineId) {
627
+ throw new AppError(400, ErrorCodes.VALIDATION_ERROR, `配方「${recipe.name}」不属于产线「${line.name}」,请先将其产品挂载到本产线`)
628
+ }
629
+ if (recipe.params.length === 0) {
630
+ throw new AppError(400, ErrorCodes.VALIDATION_ERROR, '开跑前必须先设定配方:当前 Recipe 无工艺参数')
631
+ }
632
+ const product = getDcwProductRepo().byId(recipe.productId)
633
+ if (!product) {
634
+ throw new AppError(400, ErrorCodes.VALIDATION_ERROR, '开跑前必须先设定配方:Recipe 未归属有效产品,请先补全产品信息')
635
+ }
636
+ const run = repo.createRun(recipe)
637
+ setActiveLineRun({
638
+ lineId,
639
+ runId: run.id,
640
+ recipeId: recipe.id,
641
+ recipeName: recipe.name,
642
+ productId: product.id,
643
+ productName: product.name,
644
+ startedAt: run.startedAt,
645
+ taggedSamples: 0,
646
+ })
647
+ await this.writeRecipeParams(recipe, run)
648
+ this.broadcast?.('dcw.controller', this.controllerState())
649
+ return run
650
+ }
651
+
652
+ /** 产线停止:关闭该产线批次窗口(此后样本不再打标;数据保留可查)+ 该产线数采停摆 */
653
+ lineStop(lineId: string) {
654
+ const line = getDcwLineRepo().byId(lineId)
655
+ if (!line) throw new AppError(404, ErrorCodes.NOT_FOUND, `产线不存在: ${lineId}`)
656
+ const prev = clearActiveLineRun(lineId)
657
+ if (!prev) throw new AppError(400, ErrorCodes.VALIDATION_ERROR, `产线「${line.name}」未在运行`)
658
+ const run = getDcwRecipeRepo().closeRun(prev.runId)
659
+ // 调控闭环封窗:该线 open 优化记录随批次窗口关闭(防跨批次污染)
660
+ getRecipeRollBackManager().closeForLine(lineId)
661
+ this.broadcast?.('dcw.controller', this.controllerState())
662
+ // 数采门控联动:该产线无活动配方即停止其节点采集,置 offline 并广播收敛
663
+ void import('../daq/daq-controller').then(({ getDaqController }) => {
664
+ getDaqController().markLineOffline(lineId)
665
+ }).catch(() => {})
666
+ return run
667
+ }
668
+
669
+ /** 单条产线运行状态(活动窗口 + 打标计数) */
670
+ lineState(lineId: string): LineRunState {
671
+ const base: LineRunState = { lineId, active: false, runId: null, recipeId: null, recipeName: null, productId: null, productName: null, startedAt: null, taggedSamples: 0 }
672
+ const r = getActiveLineRun(lineId)
673
+ if (!r) return base
674
+ return {
675
+ ...base,
676
+ active: true,
677
+ runId: r.runId,
678
+ recipeId: r.recipeId,
679
+ recipeName: r.recipeName,
680
+ productId: r.productId,
681
+ productName: r.productName,
682
+ startedAt: r.startedAt,
683
+ taggedSamples: r.taggedSamples,
684
+ }
685
+ }
686
+
687
+ /** 全部产线运行状态(产线总览/状态条聚合) */
688
+ allLineStates(): LineRunState[] {
689
+ const lines = getDcwLineRepo().all()
690
+ const seen = new Set(lines.map(l => l.id))
691
+ const states = lines.map(l => this.lineState(l.id))
692
+ // 已删除产线的残留窗口兜底展示(避免批次计数幽灵丢失)
693
+ for (const r of getAllActiveLineRuns()) {
694
+ if (!seen.has(r.lineId)) states.push(this.lineState(r.lineId))
695
+ }
696
+ return states
697
+ }
698
+
699
+ /** 是否存在任意活动产线窗口(数采全局快速门) */
700
+ hasAnyActiveLineRun(): boolean {
701
+ return getAllActiveLineRuns().length > 0
702
+ }
703
+
704
+ /**
705
+ * 产线数据查询(产品/配方/工艺参数/时间/间隔 五维):
706
+ * 打标样本跨通道聚合;paramKey 限定工艺参数(DAQ 模板),bucketMs 降采样。
707
+ */
708
+ async lineQuery(opts: LineQueryOpts): Promise<LineQueryResult> {
709
+ const { getTsdb, tsdbReady } = await import('../daq/storage')
710
+ await tsdbReady
711
+ const { getDaqNodeRepo } = await import('../daq/daq-node.repo')
712
+ const { findDaqTemplate } = await import('../daq/daq-templates')
713
+ const nodeFilter = opts.nodeId ? opts.nodeId.split(',').map(x => x.trim()).filter(Boolean) : []
714
+ const nodes = getDaqNodeRepo().all().filter((n) => {
715
+ if (opts.paramKey && n.templateKey !== opts.paramKey) return false
716
+ if (opts.lineId && (n.lineId ?? '') !== opts.lineId) return false
717
+ // 节点维过滤(多节点绑定同模板时精确定位;支持多节点逗号分隔)
718
+ if (nodeFilter.length > 0 && !nodeFilter.includes(n.id)) return false
719
+ return true
720
+ })
721
+ const series = await getTsdb().queryTagged({
722
+ productId: opts.productId,
723
+ recipeId: opts.recipeId,
724
+ lineId: opts.lineId,
725
+ nodeIds: nodes.map(n => n.id),
726
+ fromMs: opts.fromMs,
727
+ toMs: opts.toMs,
728
+ bucketMs: opts.bucketMs,
729
+ limit: opts.limit,
730
+ })
731
+ const channels: LineQueryResult['channels'] = []
732
+ for (const n of nodes) {
733
+ const points = series.get(n.id)
734
+ if (!points || points.length === 0) continue
735
+ const tpl = findDaqTemplate(n.templateKey)
736
+ channels.push({
737
+ nodeId: n.id,
738
+ nodeName: n.name,
739
+ templateRef: n.templateRef,
740
+ ch: tpl?.ch ?? n.templateKey,
741
+ unit: n.unit,
742
+ points,
743
+ })
744
+ }
745
+ return { productId: opts.productId ?? null, recipeId: opts.recipeId ?? null, channels }
746
+ }
747
+
748
+ // ---------- 产品 ----------
749
+
750
+ listProducts(): ProductView[] {
751
+ return getDcwProductRepo().all()
752
+ }
753
+
754
+ createProduct(input: ProductInput): ProductView {
755
+ const lineId = String(input.lineId ?? '')
756
+ if (lineId && !getDcwLineRepo().byId(lineId)) throw new AppError(404, ErrorCodes.NOT_FOUND, `产线不存在: ${lineId}`)
757
+ return getDcwProductRepo().create({ ...input, lineId })
758
+ }
759
+
760
+ updateProduct(id: string, patch: Partial<ProductInput>): ProductView {
761
+ if (patch.lineId) {
762
+ const lid = String(patch.lineId)
763
+ if (!getDcwLineRepo().byId(lid)) throw new AppError(404, ErrorCodes.NOT_FOUND, `产线不存在: ${lid}`)
764
+ }
765
+ const prev = getDcwProductRepo().byId(id)
766
+ const updated = getDcwProductRepo().update(id, patch)
767
+ // 产品换线 → 旗下配方产线归属级联(开跑校验按 recipe.lineId)
768
+ if (prev && prev.lineId !== updated.lineId) {
769
+ const recipeRepo = getDcwRecipeRepo()
770
+ for (const r of recipeRepo.list()) {
771
+ if (r.productId === id) recipeRepo.setRecipeLine(r.id, updated.lineId)
772
+ }
773
+ }
774
+ return updated
775
+ }
776
+
777
+ removeProduct(id: string): void {
778
+ const product = getDcwProductRepo().byId(id)
779
+ if (!product) throw new AppError(404, ErrorCodes.NOT_FOUND, `产品不存在: ${id}`)
780
+ if (product.lineId && getActiveLineRun(product.lineId)?.productId === id) {
781
+ throw new AppError(409, ErrorCodes.CONFLICT, '产品正在产线运行中,不可删除(请先停止数据采集)')
782
+ }
783
+ getDcwProductRepo().remove(id)
784
+ }
785
+
786
+ /**
787
+ * 批次数据视图(产品隔离):批次窗口内的写历史 + 全部数采节点的窗口内汇总
788
+ * (latest/avg/min/max/cnt,窗口 > 60s 时按窗口/100 自动降采样)。
789
+ */
790
+ async runData(id: string) {
791
+ const repo = getDcwRecipeRepo()
792
+ const run = repo.runById(id)
793
+ if (!run) throw new AppError(404, ErrorCodes.NOT_FOUND, `批次不存在: ${id}`)
794
+ const endMs = run.endedAt ? Date.parse(run.endedAt) : Date.now()
795
+ const startMs = Date.parse(run.startedAt)
796
+ const writes = repo.historyInWindow(run.startedAt, run.endedAt, id)
797
+ const { getDaqNodeRepo } = await import('../daq/daq-node.repo')
798
+ const { getTsdb, tsdbReady } = await import('../daq/storage')
799
+ const { findDaqTemplate } = await import('../daq/daq-templates')
800
+ await tsdbReady
801
+ const bucketMs = endMs - startMs > 60_000 ? Math.max(1000, Math.round((endMs - startMs) / 200)) : undefined
802
+ const daq = [] as Array<{ templateRef: string, nodeId: string, nodeName: string, ch: string, unit: string, latest: number | null, avg: number | null, min: number | null, max: number | null, cnt: number }>
803
+ for (const node of getDaqNodeRepo().all()) {
804
+ try {
805
+ const points = await getTsdb().query(node.id, { fromMs: startMs, toMs: endMs, bucketMs, limit: 500 })
806
+ if (points.length === 0) continue
807
+ const values = points.map(p => p.value ?? p.avg ?? 0).filter(v => Number.isFinite(v))
808
+ if (values.length === 0) continue
809
+ const tpl = findDaqTemplate(node.templateKey)
810
+ daq.push({
811
+ templateRef: node.templateRef,
812
+ nodeId: node.id,
813
+ nodeName: node.name,
814
+ ch: tpl?.ch ?? node.templateKey,
815
+ unit: node.unit,
816
+ latest: values[values.length - 1]!,
817
+ avg: Number((values.reduce((a, b) => a + b, 0) / values.length).toFixed(node.decimals)),
818
+ min: Number(Math.min(...values).toFixed(node.decimals)),
819
+ max: Number(Math.max(...values).toFixed(node.decimals)),
820
+ cnt: values.length,
821
+ })
822
+ }
823
+ catch { /* 单节点查询失败不阻塞整体 */ }
824
+ }
825
+ return { run, daq, writes }
826
+ }
827
+ }
828
+
829
+ // ---------- 单例(HMR 存活) ----------
830
+
831
+ const g = globalThis as typeof globalThis & { __dcwController?: DcwController }
832
+
833
+ export function getDcwController(): DcwController {
834
+ g.__dcwController ??= new DcwController()
835
+ return g.__dcwController
836
+ }
837
+
838
+ /** 广播装配(dcw 路由模块加载时调用一次;首访即上电) */
839
+ export function bindDcwBroadcast(fn: BroadcastFn | null): void {
840
+ getDcwController().setBroadcast(fn)
841
+ }