agentworkshop 0.7.71 → 0.8.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 (358) hide show
  1. package/.AgentWorkShop/prompts/host-tools.json +332 -0
  2. package/.output/.AgentWorkShop/prompts/host-tools.json +332 -0
  3. package/.output/nitro.json +1 -1
  4. package/.output/public/_nuxt/BH8RvpVy.js +1 -0
  5. package/.output/public/_nuxt/Byf4IxU2.js +14 -0
  6. package/.output/public/_nuxt/CxVhG0Xx.js +1 -0
  7. package/.output/public/_nuxt/D0mzKkZr.js +1 -0
  8. package/.output/public/_nuxt/DIFkTkdS.js +1 -0
  9. package/.output/public/_nuxt/DgrK8UCQ.js +0 -0
  10. package/.output/public/_nuxt/builds/latest.json +1 -1
  11. package/.output/public/_nuxt/builds/meta/7a79a7e4-d691-4cf5-ae3a-3b01814479fb.json +1 -0
  12. package/.output/public/_nuxt/{default.BzOcvmSE.css → default.BEXGWZFQ.css} +1 -1
  13. package/.output/public/_nuxt/{entry.CL2i0F8o.css → entry.C7koBPom.css} +1 -1
  14. package/.output/public/_nuxt/ontology.QMGeh66l.css +1 -0
  15. package/.output/server/chunks/_/access.mjs +1 -1
  16. package/.output/server/chunks/_/binding-authz.mjs +1 -1
  17. package/.output/server/chunks/_/catalog-view.mjs +1 -1
  18. package/.output/server/chunks/_/character-asset.repo.mjs +1 -1
  19. package/.output/server/chunks/_/chart-repo.mjs +1 -1
  20. package/.output/server/chunks/_/dashboard-repo.mjs +1 -1
  21. package/.output/server/chunks/_/data-export.mjs +6 -6
  22. package/.output/server/chunks/_/data-query.mjs +3 -3
  23. package/.output/server/chunks/_/eda-run.repo.mjs +2 -2
  24. package/.output/server/chunks/_/entity.mjs +1 -1
  25. package/.output/server/chunks/_/features.mjs +5 -5
  26. package/.output/server/chunks/_/golden.mjs +3 -3
  27. package/.output/server/chunks/_/host-bindings.mjs +1 -1
  28. package/.output/server/chunks/_/index.mjs +1 -1
  29. package/.output/server/chunks/_/mes-console.mjs +1 -1
  30. package/.output/server/chunks/_/nitro.mjs +5362 -2240
  31. package/.output/server/chunks/_/nitro.mjs.map +1 -1
  32. package/.output/server/chunks/_/ocap.mjs +1 -1
  33. package/.output/server/chunks/_/rest-auth.mjs +1 -1
  34. package/.output/server/chunks/_/scene-layout.repo.mjs +1 -1
  35. package/.output/server/chunks/_/spc.mjs +2 -2
  36. package/.output/server/chunks/build/TownView-BWMDbosY.mjs +1 -1
  37. package/.output/server/chunks/build/api-BEW_ebY_.mjs +64 -0
  38. package/.output/server/chunks/build/api-BEW_ebY_.mjs.map +1 -0
  39. package/.output/server/chunks/build/daq-CdxcfY_G.mjs +1 -1
  40. package/.output/server/chunks/build/dcw-BlDQtS4q.mjs +1 -1
  41. package/.output/server/chunks/build/{default-BeB88U7y.mjs → default-CJkOcmrm.mjs} +14 -8
  42. package/.output/server/chunks/build/{default-BeB88U7y.mjs.map → default-CJkOcmrm.mjs.map} +1 -1
  43. package/.output/server/chunks/build/ontology-C3HS5pMo.mjs +977 -0
  44. package/.output/server/chunks/build/ontology-C3HS5pMo.mjs.map +1 -0
  45. package/.output/server/chunks/build/types-D6J7slEa.mjs +6 -2
  46. package/.output/server/chunks/build/useDaqAddNode-D_Rkju0f.mjs +1 -1
  47. package/.output/server/chunks/build/useDaqDetailNode-DeOsDxK5.mjs +1 -1
  48. package/.output/server/chunks/build/useDaqDetailParams-Cm9a9r5G.mjs +1 -1
  49. package/.output/server/chunks/build/useDaqFilters-CctmO03p.mjs +1 -1
  50. package/.output/server/chunks/build/useDaqStream-B9ZBVQrI.mjs +1 -1
  51. package/.output/server/chunks/build/useDaqTemplates-CK37sMfi.mjs +1 -1
  52. package/.output/server/chunks/build/useDcwAddNode-DACVcEHs.mjs +1 -1
  53. package/.output/server/chunks/build/useDcwStream-Dir5ufAU.mjs +1 -1
  54. package/.output/server/chunks/routes/api/mcp/workshop.mjs +1 -1
  55. package/.output/server/chunks/routes/api/system/backup/run.post.mjs +2 -2
  56. package/.output/server/chunks/routes/api/workshop/agent-tools/approvals/_id/decide.post.mjs +17 -4
  57. package/.output/server/chunks/routes/api/workshop/agent-tools/approvals/_id/decide.post.mjs.map +1 -1
  58. package/.output/server/chunks/routes/api/workshop/agent-tools/bindings/_id_.delete.mjs +1 -1
  59. package/.output/server/chunks/routes/api/workshop/agent-tools/bindings/_id_.patch.mjs +1 -1
  60. package/.output/server/chunks/routes/api/workshop/agent-tools/bindings/grant.post.mjs +1 -1
  61. package/.output/server/chunks/routes/api/workshop/agent-tools/bindings/revoke.post.mjs +1 -1
  62. package/.output/server/chunks/routes/api/workshop/agent-tools/index.get.mjs +1 -1
  63. package/.output/server/chunks/routes/api/workshop/agent-tools/index.post.mjs +1 -1
  64. package/.output/server/chunks/routes/api/workshop/agent-tools/index2.get.mjs +1 -1
  65. package/.output/server/chunks/routes/api/workshop/agent-tools/invoke.post.mjs +1 -1
  66. package/.output/server/chunks/routes/api/workshop/agent-tools/list.get.mjs +1 -1
  67. package/.output/server/chunks/routes/api/workshop/aml/datasets/_id/preview.get.mjs +1 -1
  68. package/.output/server/chunks/routes/api/workshop/aml/datasets/_id_.delete.mjs +1 -1
  69. package/.output/server/chunks/routes/api/workshop/aml/datasets/_id_.get.mjs +1 -1
  70. package/.output/server/chunks/routes/api/workshop/aml/datasets/_id_.patch.mjs +1 -1
  71. package/.output/server/chunks/routes/api/workshop/aml/env/recheck.post.mjs +1 -1
  72. package/.output/server/chunks/routes/api/workshop/aml/env/uv.post.mjs +1 -1
  73. package/.output/server/chunks/routes/api/workshop/aml/env/venv.post.mjs +1 -1
  74. package/.output/server/chunks/routes/api/workshop/aml/index.get.mjs +1 -1
  75. package/.output/server/chunks/routes/api/workshop/aml/index.post.mjs +1 -1
  76. package/.output/server/chunks/routes/api/workshop/aml/index2.post.mjs +1 -1
  77. package/.output/server/chunks/routes/api/workshop/aml/index3.get.mjs +1 -1
  78. package/.output/server/chunks/routes/api/workshop/aml/index3.post.mjs +1 -1
  79. package/.output/server/chunks/routes/api/workshop/aml/index4.get.mjs +1 -1
  80. package/.output/server/chunks/routes/api/workshop/aml/index5.get.mjs +1 -1
  81. package/.output/server/chunks/routes/api/workshop/aml/index6.get.mjs +1 -1
  82. package/.output/server/chunks/routes/api/workshop/aml/index7.get.mjs +1 -1
  83. package/.output/server/chunks/routes/api/workshop/aml/jobs/_id/cancel.post.mjs +1 -1
  84. package/.output/server/chunks/routes/api/workshop/aml/jobs/_id/logs.get.mjs +1 -1
  85. package/.output/server/chunks/routes/api/workshop/aml/jobs/_id/retry.post.mjs +1 -1
  86. package/.output/server/chunks/routes/api/workshop/aml/jobs/_id_.delete.mjs +1 -1
  87. package/.output/server/chunks/routes/api/workshop/aml/jobs/_id_.get.mjs +1 -1
  88. package/.output/server/chunks/routes/api/workshop/aml/models/_id/predict.post.mjs +1 -1
  89. package/.output/server/chunks/routes/api/workshop/aml/models/_id/promote.post.mjs +1 -1
  90. package/.output/server/chunks/routes/api/workshop/aml/models/_id_.delete.mjs +1 -1
  91. package/.output/server/chunks/routes/api/workshop/aml/models/_id_.patch.mjs +1 -1
  92. package/.output/server/chunks/routes/api/workshop/aml/training-plans/_id/train.post.mjs +1 -1
  93. package/.output/server/chunks/routes/api/workshop/aml/training-plans/_id_.delete.mjs +1 -1
  94. package/.output/server/chunks/routes/api/workshop/aml/training-plans/_id_.patch.mjs +1 -1
  95. package/.output/server/chunks/routes/api/workshop/aml/twin/providers.get.mjs +1 -1
  96. package/.output/server/chunks/routes/api/workshop/analysis/_id_.delete.mjs +1 -1
  97. package/.output/server/chunks/routes/api/workshop/analysis/_id_.get.mjs +1 -1
  98. package/.output/server/chunks/routes/api/workshop/analysis/_id_.patch.mjs +1 -1
  99. package/.output/server/chunks/routes/api/workshop/approvals/_id/decide.post.mjs +1 -1
  100. package/.output/server/chunks/routes/api/workshop/assets/index.post.mjs +1 -1
  101. package/.output/server/chunks/routes/api/workshop/assets/index2.post.mjs +1 -1
  102. package/.output/server/chunks/routes/api/workshop/channel-templates/_id/instantiate.post.mjs +2 -2
  103. package/.output/server/chunks/routes/api/workshop/channels/_id/activate.post.mjs +1 -1
  104. package/.output/server/chunks/routes/api/workshop/channels/_id/chat/index.post.mjs +1 -1
  105. package/.output/server/chunks/routes/api/workshop/channels/_id/index.post.mjs +1 -1
  106. package/.output/server/chunks/routes/api/workshop/channels/_id/index.put.mjs +1 -1
  107. package/.output/server/chunks/routes/api/workshop/channels/_id/index2.put.mjs +1 -1
  108. package/.output/server/chunks/routes/api/workshop/channels/_id/index3.post.mjs +1 -1
  109. package/.output/server/chunks/routes/api/workshop/channels/_id/index4.post.mjs +1 -1
  110. package/.output/server/chunks/routes/api/workshop/channels/_id/index5.get.mjs +1 -1
  111. package/.output/server/chunks/routes/api/workshop/channels/_id/line.put.mjs +1 -1
  112. package/.output/server/chunks/routes/api/workshop/channels/_id/members/join.post.mjs +1 -1
  113. package/.output/server/chunks/routes/api/workshop/channels/_id/terminals.get.mjs +1 -1
  114. package/.output/server/chunks/routes/api/workshop/channels/_id/tools/reset.post.mjs +1 -1
  115. package/.output/server/chunks/routes/api/workshop/channels/_id/twin-profile.get.mjs +1 -1
  116. package/.output/server/chunks/routes/api/workshop/channels/_id/twin-profile.patch.mjs +1 -1
  117. package/.output/server/chunks/routes/api/workshop/channels/index.get.mjs +1 -1
  118. package/.output/server/chunks/routes/api/workshop/channels.post.mjs +7 -7
  119. package/.output/server/chunks/routes/api/workshop/daq/_id/bind.post.mjs +1 -1
  120. package/.output/server/chunks/routes/api/workshop/daq/_id/bindings.put.mjs +1 -1
  121. package/.output/server/chunks/routes/api/workshop/daq/_id/frames/content.get.mjs +1 -1
  122. package/.output/server/chunks/routes/api/workshop/daq/_id/frames.get.mjs +1 -1
  123. package/.output/server/chunks/routes/api/workshop/daq/_id/ingest.post.mjs +2 -2
  124. package/.output/server/chunks/routes/api/workshop/daq/_id/samples.get.mjs +1 -1
  125. package/.output/server/chunks/routes/api/workshop/daq/_id/test.post.mjs +1 -1
  126. package/.output/server/chunks/routes/api/workshop/daq/_id_.delete.mjs +1 -1
  127. package/.output/server/chunks/routes/api/workshop/daq/_id_.patch.mjs +1 -1
  128. package/.output/server/chunks/routes/api/workshop/daq/alarms/_id/ack.post.mjs +1 -1
  129. package/.output/server/chunks/routes/api/workshop/daq/alarms.get.mjs +1 -1
  130. package/.output/server/chunks/routes/api/workshop/daq/controller.post.mjs +1 -1
  131. package/.output/server/chunks/routes/api/workshop/daq/export/_id_.get.mjs +1 -1
  132. package/.output/server/chunks/routes/api/workshop/daq/index2.post.mjs +1 -1
  133. package/.output/server/chunks/routes/api/workshop/daq/infra/reconnect.post.mjs +1 -1
  134. package/.output/server/chunks/routes/api/workshop/daq/infra.get.mjs +1 -1
  135. package/.output/server/chunks/routes/api/workshop/daq/templates/_key_.delete.mjs +1 -1
  136. package/.output/server/chunks/routes/api/workshop/daq/templates/_key_.patch.mjs +1 -1
  137. package/.output/server/chunks/routes/api/workshop/daq/test-driver.post.mjs +1 -1
  138. package/.output/server/chunks/routes/api/workshop/dcw/_id/bind.post.mjs +1 -1
  139. package/.output/server/chunks/routes/api/workshop/dcw/_id/bindings.put.mjs +1 -1
  140. package/.output/server/chunks/routes/api/workshop/dcw/_id/param-ledger.get.mjs +1 -1
  141. package/.output/server/chunks/routes/api/workshop/dcw/_id/read.post.mjs +1 -1
  142. package/.output/server/chunks/routes/api/workshop/dcw/_id/test.post.mjs +1 -1
  143. package/.output/server/chunks/routes/api/workshop/dcw/_id/write.post.mjs +1 -1
  144. package/.output/server/chunks/routes/api/workshop/dcw/_id_.delete.mjs +1 -1
  145. package/.output/server/chunks/routes/api/workshop/dcw/_id_.patch.mjs +1 -1
  146. package/.output/server/chunks/routes/api/workshop/dcw/controller.post.mjs +1 -1
  147. package/.output/server/chunks/routes/api/workshop/dcw/index.get.mjs +1 -1
  148. package/.output/server/chunks/routes/api/workshop/dcw/index.post.mjs +1 -1
  149. package/.output/server/chunks/routes/api/workshop/dcw/index2.get.mjs +1 -1
  150. package/.output/server/chunks/routes/api/workshop/dcw/index2.post.mjs +1 -1
  151. package/.output/server/chunks/routes/api/workshop/dcw/index3.get.mjs +1 -1
  152. package/.output/server/chunks/routes/api/workshop/dcw/index3.post.mjs +1 -1
  153. package/.output/server/chunks/routes/api/workshop/dcw/index4.get.mjs +1 -1
  154. package/.output/server/chunks/routes/api/workshop/dcw/index4.post.mjs +1 -1
  155. package/.output/server/chunks/routes/api/workshop/dcw/index5.get.mjs +1 -1
  156. package/.output/server/chunks/routes/api/workshop/dcw/index5.post.mjs +1 -1
  157. package/.output/server/chunks/routes/api/workshop/dcw/index6.get.mjs +1 -1
  158. package/.output/server/chunks/routes/api/workshop/dcw/index7.get.mjs +1 -1
  159. package/.output/server/chunks/routes/api/workshop/dcw/journal/node/_nodeId/rollback.post.mjs +1 -1
  160. package/.output/server/chunks/routes/api/workshop/dcw/line/query.get.mjs +1 -1
  161. package/.output/server/chunks/routes/api/workshop/dcw/lines/_id/start.post.mjs +1 -1
  162. package/.output/server/chunks/routes/api/workshop/dcw/lines/_id/stop.post.mjs +1 -1
  163. package/.output/server/chunks/routes/api/workshop/dcw/lines/_id_.delete.mjs +1 -1
  164. package/.output/server/chunks/routes/api/workshop/dcw/lines/_id_.patch.mjs +1 -1
  165. package/.output/server/chunks/routes/api/workshop/dcw/mes-artifacts/file.get.mjs +1 -1
  166. package/.output/server/chunks/routes/api/workshop/dcw/mes-hook-test.post.mjs +1 -1
  167. package/.output/server/chunks/routes/api/workshop/dcw/mes-test-read.post.mjs +1 -1
  168. package/.output/server/chunks/routes/api/workshop/dcw/optimizations/_id/judge.post.mjs +1 -1
  169. package/.output/server/chunks/routes/api/workshop/dcw/optimizations/_id/rollback.post.mjs +1 -1
  170. package/.output/server/chunks/routes/api/workshop/dcw/optimizations/_id/series.get.mjs +1 -1
  171. package/.output/server/chunks/routes/api/workshop/dcw/optimizations/_id_.get.mjs +1 -1
  172. package/.output/server/chunks/routes/api/workshop/dcw/params/_id/read.post.mjs +1 -1
  173. package/.output/server/chunks/routes/api/workshop/dcw/params/_id/write.post.mjs +1 -1
  174. package/.output/server/chunks/routes/api/workshop/dcw/params/_id_.delete.mjs +1 -1
  175. package/.output/server/chunks/routes/api/workshop/dcw/params/_id_.patch.mjs +1 -1
  176. package/.output/server/chunks/routes/api/workshop/dcw/products/_id_.delete.mjs +1 -1
  177. package/.output/server/chunks/routes/api/workshop/dcw/products/_id_.patch.mjs +1 -1
  178. package/.output/server/chunks/routes/api/workshop/dcw/recipes/_id/apply.post.mjs +1 -1
  179. package/.output/server/chunks/routes/api/workshop/dcw/recipes/_id/mark-good.post.mjs +1 -1
  180. package/.output/server/chunks/routes/api/workshop/dcw/recipes/_id/revert.post.mjs +1 -1
  181. package/.output/server/chunks/routes/api/workshop/dcw/recipes/_id/rollback-good.post.mjs +1 -1
  182. package/.output/server/chunks/routes/api/workshop/dcw/recipes/_id/versions.get.mjs +1 -1
  183. package/.output/server/chunks/routes/api/workshop/dcw/recipes/_id_.delete.mjs +1 -1
  184. package/.output/server/chunks/routes/api/workshop/dcw/recipes/index.patch.mjs +1 -1
  185. package/.output/server/chunks/routes/api/workshop/dcw/runs/_id/close.post.mjs +1 -1
  186. package/.output/server/chunks/routes/api/workshop/dcw/runs/_id/data.get.mjs +1 -1
  187. package/.output/server/chunks/routes/api/workshop/dcw/runs/_id/rollback.post.mjs +1 -1
  188. package/.output/server/chunks/routes/api/workshop/dcw/templates/_key_.delete.mjs +1 -1
  189. package/.output/server/chunks/routes/api/workshop/dcw/templates/_key_.patch.mjs +1 -1
  190. package/.output/server/chunks/routes/api/workshop/dcw/test-driver.post.mjs +1 -1
  191. package/.output/server/chunks/routes/api/workshop/device-twins/_id/control.post.mjs +1 -1
  192. package/.output/server/chunks/routes/api/workshop/device-twins/_id/telemetry.post.mjs +1 -1
  193. package/.output/server/chunks/routes/api/workshop/device-twins/_id_.delete.mjs +1 -1
  194. package/.output/server/chunks/routes/api/workshop/device-twins/_id_.patch.mjs +1 -1
  195. package/.output/server/chunks/routes/api/workshop/eda/commonality.get.mjs +1 -1
  196. package/.output/server/chunks/routes/api/workshop/eda/features/run.post.mjs +1 -1
  197. package/.output/server/chunks/routes/api/workshop/eda/index3.get.mjs +1 -1
  198. package/.output/server/chunks/routes/api/workshop/eda/index6.get.mjs +1 -1
  199. package/.output/server/chunks/routes/api/workshop/eda/index6.post.mjs +1 -1
  200. package/.output/server/chunks/routes/api/workshop/eda/runs/_id/labels.patch.mjs +1 -1
  201. package/.output/server/chunks/routes/api/workshop/eda/runs.get.mjs +1 -1
  202. package/.output/server/chunks/routes/api/workshop/eda/vm/predict.post.mjs +1 -1
  203. package/.output/server/chunks/routes/api/workshop/exp/confirmations/_id/decide.post.mjs +1 -1
  204. package/.output/server/chunks/routes/api/workshop/exp/index.get.mjs +1 -1
  205. package/.output/server/chunks/routes/api/workshop/fs/dirs.get.mjs +1 -1
  206. package/.output/server/chunks/routes/api/workshop/harnesses/_id/providers.get.mjs +1 -1
  207. package/.output/server/chunks/routes/api/workshop/harnesses.get.mjs +1 -1
  208. package/.output/server/chunks/routes/api/workshop/hitl/pending.get.mjs +1 -1
  209. package/.output/server/chunks/routes/api/workshop/hitl/respond.post.mjs +1 -1
  210. package/.output/server/chunks/routes/api/workshop/index.mjs +62 -0
  211. package/.output/server/chunks/routes/api/workshop/index.mjs.map +1 -0
  212. package/.output/server/chunks/routes/api/workshop/index.put.mjs +1 -1
  213. package/.output/server/chunks/routes/api/workshop/index10.get.mjs +1 -1
  214. package/.output/server/chunks/routes/api/workshop/index11.get.mjs +1 -1
  215. package/.output/server/chunks/routes/api/workshop/index12.get.mjs +1 -1
  216. package/.output/server/chunks/routes/api/workshop/index2.get.mjs +1 -1
  217. package/.output/server/chunks/routes/api/workshop/index3.get.mjs +1 -1
  218. package/.output/server/chunks/routes/api/workshop/index3.post.mjs +1 -1
  219. package/.output/server/chunks/routes/api/workshop/index4.post.mjs +1 -1
  220. package/.output/server/chunks/routes/api/workshop/index5.post.mjs +1 -1
  221. package/.output/server/chunks/routes/api/workshop/index6.get.mjs +1 -1
  222. package/.output/server/chunks/routes/api/workshop/index6.post.mjs +1 -1
  223. package/.output/server/chunks/routes/api/workshop/index7.get.mjs +1 -1
  224. package/.output/server/chunks/routes/api/workshop/index8.get.mjs +1 -1
  225. package/.output/server/chunks/routes/api/workshop/mes/datasets.get.mjs +1 -1
  226. package/.output/server/chunks/routes/api/workshop/mes/preview.post.mjs +1 -1
  227. package/.output/server/chunks/routes/api/workshop/ontology/drafts/_draftId/compile.mjs +54 -0
  228. package/.output/server/chunks/routes/api/workshop/ontology/drafts/_draftId/compile.mjs.map +1 -0
  229. package/.output/server/chunks/routes/api/workshop/ontology/drafts/_draftId/evidence.mjs +51 -0
  230. package/.output/server/chunks/routes/api/workshop/ontology/drafts/_draftId/evidence.mjs.map +1 -0
  231. package/.output/server/chunks/routes/api/workshop/ontology/drafts/_draftId/publish.mjs +67 -0
  232. package/.output/server/chunks/routes/api/workshop/ontology/drafts/_draftId/publish.mjs.map +1 -0
  233. package/.output/server/chunks/routes/api/workshop/ontology/drafts/_draftId/rules/_ruleId/approval-decision.mjs +49 -0
  234. package/.output/server/chunks/routes/api/workshop/ontology/drafts/_draftId/rules/_ruleId/approval-decision.mjs.map +1 -0
  235. package/.output/server/chunks/routes/api/workshop/ontology/drafts/_draftId/rules/_ruleId/approval.mjs +35 -0
  236. package/.output/server/chunks/routes/api/workshop/ontology/drafts/_draftId/rules/_ruleId/approval.mjs.map +1 -0
  237. package/.output/server/chunks/routes/api/workshop/ontology/drafts/_draftId/rules/_ruleId/transition.mjs +49 -0
  238. package/.output/server/chunks/routes/api/workshop/ontology/drafts/_draftId/rules/_ruleId/transition.mjs.map +1 -0
  239. package/.output/server/chunks/routes/api/workshop/ontology/drafts/_draftId/validate.mjs +35 -0
  240. package/.output/server/chunks/routes/api/workshop/ontology/drafts/_draftId/validate.mjs.map +1 -0
  241. package/.output/server/chunks/routes/api/workshop/ontology/drafts/_draftId_.mjs +70 -0
  242. package/.output/server/chunks/routes/api/workshop/ontology/drafts/_draftId_.mjs.map +1 -0
  243. package/.output/server/chunks/routes/api/workshop/ontology/export/_ontologyId_.mjs +64 -0
  244. package/.output/server/chunks/routes/api/workshop/ontology/export/_ontologyId_.mjs.map +1 -0
  245. package/.output/server/chunks/routes/api/workshop/ontology/index.mjs +44 -0
  246. package/.output/server/chunks/routes/api/workshop/ontology/index.mjs.map +1 -0
  247. package/.output/server/chunks/routes/api/workshop/ontology/scene.mjs +36 -0
  248. package/.output/server/chunks/routes/api/workshop/ontology/scene.mjs.map +1 -0
  249. package/.output/server/chunks/routes/api/workshop/ontology/traces/_ontologyId_.mjs +38 -0
  250. package/.output/server/chunks/routes/api/workshop/ontology/traces/_ontologyId_.mjs.map +1 -0
  251. package/.output/server/chunks/routes/api/workshop/ontology/versions/_ontologyId/compare.mjs +40 -0
  252. package/.output/server/chunks/routes/api/workshop/ontology/versions/_ontologyId/compare.mjs.map +1 -0
  253. package/.output/server/chunks/routes/api/workshop/ontology/versions/_ontologyId_.mjs +63 -0
  254. package/.output/server/chunks/routes/api/workshop/ontology/versions/_ontologyId_.mjs.map +1 -0
  255. package/.output/server/chunks/routes/api/workshop/optimization/capabilities.get.mjs +1 -1
  256. package/.output/server/chunks/routes/api/workshop/optimization/index.get.mjs +1 -1
  257. package/.output/server/chunks/routes/api/workshop/optimization/index.mjs +1 -1
  258. package/.output/server/chunks/routes/api/workshop/optimization/index2.mjs +1 -1
  259. package/.output/server/chunks/routes/api/workshop/optimization/profiles/_id/publish.post.mjs +1 -1
  260. package/.output/server/chunks/routes/api/workshop/optimization/recommendations/_id/crosscheck.post.mjs +1 -1
  261. package/.output/server/chunks/routes/api/workshop/optimization/recommendations/_id/dispatch.post.mjs +1 -1
  262. package/.output/server/chunks/routes/api/workshop/optimization/solve.post.mjs +1 -1
  263. package/.output/server/chunks/routes/api/workshop/plugins/_name/disable.post.mjs +1 -1
  264. package/.output/server/chunks/routes/api/workshop/plugins/_name/enable.post.mjs +1 -1
  265. package/.output/server/chunks/routes/api/workshop/process-model/datasets.post.mjs +1 -1
  266. package/.output/server/chunks/routes/api/workshop/process-model/eligibility.mjs +1 -1
  267. package/.output/server/chunks/routes/api/workshop/process-model/experiments.mjs +1 -1
  268. package/.output/server/chunks/routes/api/workshop/process-model/index.mjs +1 -1
  269. package/.output/server/chunks/routes/api/workshop/process-model/specs/_id/publish.post.mjs +1 -1
  270. package/.output/server/chunks/routes/api/workshop/process-model/train.post.mjs +1 -1
  271. package/.output/server/chunks/routes/api/workshop/scene/layouts/_channelId_.delete.mjs +1 -1
  272. package/.output/server/chunks/routes/api/workshop/scene/layouts/_channelId_.put.mjs +1 -1
  273. package/.output/server/chunks/routes/api/workshop/teams/_id/deploy.post.mjs +1 -1
  274. package/.output/server/chunks/routes/api/workshop/teams/_id/index.put.mjs +1 -1
  275. package/.output/server/chunks/routes/api/workshop/teams/_id/index2.get.mjs +1 -1
  276. package/.output/server/chunks/routes/api/workshop/tools/_name_.get.mjs +1 -1
  277. package/.output/server/chunks/routes/api/workshop/tools/sync.post.mjs +1 -1
  278. package/.output/server/chunks/routes/api/workshop/workspaces/_id/channel-templates/_tplId_.post.mjs +2 -2
  279. package/.output/server/chunks/routes/renderer.mjs +2 -2
  280. package/.output/server/chunks/virtual/entry.mjs +234 -3
  281. package/.output/server/chunks/virtual/precomputed.mjs +1 -1
  282. package/.output/server/package.json +1 -1
  283. package/README-zh.md +27 -6
  284. package/README.md +25 -4
  285. package/app/components/AppSidebar.vue +1 -0
  286. package/app/pages/ontology/api.ts +18 -0
  287. package/app/pages/ontology/index.vue +779 -0
  288. package/app/pages/ontology/types.ts +122 -0
  289. package/config.yml +1 -1
  290. package/docs/cli.en.md +2 -2
  291. package/docs/cli.md +2 -2
  292. package/docs/plugins.en.md +1 -1
  293. package/docs/plugins.md +1 -1
  294. package/docs/sdk.en.md +1 -1
  295. package/docs/sdk.md +1 -1
  296. package/i18n/locales/en.ts +58 -0
  297. package/i18n/locales/zh-CN.ts +58 -0
  298. package/mcp/aw-mcp-server.mjs +35 -1
  299. package/package.json +1 -1
  300. package/scripts/docs-shots.mjs +36 -0
  301. package/scripts/e2e-model-loop-live.mjs +731 -0
  302. package/scripts/e2e-ontology-live.mjs +774 -0
  303. package/scripts/e2e-ontology.mjs +328 -0
  304. package/scripts/ontology-idd-rag-e2e.mjs +449 -0
  305. package/server/api/workshop/agent-tools/approvals/[id]/decide.post.ts +16 -0
  306. package/server/api/workshop/ontology/drafts/[draftId]/compile.ts +39 -0
  307. package/server/api/workshop/ontology/drafts/[draftId]/evidence.ts +33 -0
  308. package/server/api/workshop/ontology/drafts/[draftId]/publish.ts +44 -0
  309. package/server/api/workshop/ontology/drafts/[draftId]/rules/[ruleId]/approval-decision.ts +28 -0
  310. package/server/api/workshop/ontology/drafts/[draftId]/rules/[ruleId]/approval.ts +17 -0
  311. package/server/api/workshop/ontology/drafts/[draftId]/rules/[ruleId]/transition.ts +32 -0
  312. package/server/api/workshop/ontology/drafts/[draftId]/validate.ts +16 -0
  313. package/server/api/workshop/ontology/drafts/[draftId].ts +52 -0
  314. package/server/api/workshop/ontology/drafts/index.ts +20 -0
  315. package/server/api/workshop/ontology/export/[ontologyId].ts +50 -0
  316. package/server/api/workshop/ontology/index.ts +38 -0
  317. package/server/api/workshop/ontology/scene.ts +21 -0
  318. package/server/api/workshop/ontology/traces/[ontologyId].ts +19 -0
  319. package/server/api/workshop/ontology/versions/[ontologyId]/compare.ts +21 -0
  320. package/server/api/workshop/ontology/versions/[ontologyId].ts +42 -0
  321. package/server/services/workshop/agents/hitl-decision/dispatcher.ts +15 -0
  322. package/server/services/workshop/agents/host-tool-bridge/tools/industrial.ts +13 -1
  323. package/server/services/workshop/agents/industrial/grant-guard.ts +59 -0
  324. package/server/services/workshop/agents/industrial/index.ts +38 -32
  325. package/server/services/workshop/agents/industrial/ontology-tools.ts +320 -0
  326. package/server/services/workshop/agents/industrial/optimizer-tools.ts +79 -0
  327. package/server/services/workshop/agents/industrial/tool-verify.ts +32 -2
  328. package/server/services/workshop/agents/tool-reference-spec.ts +1 -1
  329. package/server/services/workshop/aml/twin/physics-spec.ts +6 -22
  330. package/server/services/workshop/daq/storage/index.ts +6 -5
  331. package/server/services/workshop/daq/storage/sqlite.adapter.ts +25 -13
  332. package/server/services/workshop/db/database/open.ts +2 -0
  333. package/server/services/workshop/db/database/schema.ts +155 -1
  334. package/server/services/workshop/ontology/compiler.ts +474 -0
  335. package/server/services/workshop/ontology/contracts.ts +441 -0
  336. package/server/services/workshop/ontology/guards.ts +139 -0
  337. package/server/services/workshop/ontology/index.ts +10 -0
  338. package/server/services/workshop/ontology/ontology.service.ts +892 -0
  339. package/server/services/workshop/ontology/repo.ts +449 -0
  340. package/server/services/workshop/ontology/semantic-binding.service.ts +226 -0
  341. package/server/services/workshop/ontology/validator.ts +218 -0
  342. package/server/services/workshop/optimization/binding.repo.ts +7 -0
  343. package/server/services/workshop/optimization/contracts.ts +14 -0
  344. package/server/services/workshop/optimization/dispatch.service.ts +16 -0
  345. package/server/services/workshop/optimization/profile-adopt.service.ts +256 -0
  346. package/server/services/workshop/optimization/profile.repo.ts +19 -3
  347. package/server/services/workshop/optimization/python/__pycache__/problems.cpython-312.pyc +0 -0
  348. package/shared/dimensions.ts +124 -0
  349. package/.output/public/_nuxt/B7s2qeyT.js +0 -14
  350. package/.output/public/_nuxt/LHIav-Kv.js +0 -1
  351. package/.output/public/_nuxt/RuMLNeQE.js +0 -1
  352. package/.output/public/_nuxt/builds/meta/0ae8cb0f-6ce5-4096-9692-9b1fc197b30d.json +0 -1
  353. /package/.output/public/_nuxt/{62J4vljm2.js → 62J4vljm.js} +0 -0
  354. /package/.output/public/_nuxt/{BO0BJx3w.js → BO0BJx3w2.js} +0 -0
  355. /package/.output/public/_nuxt/{C-MY-JQE2.js → C-MY-JQE.js} +0 -0
  356. /package/.output/public/_nuxt/{D5kCimyw.js → D5kCimyw2.js} +0 -0
  357. /package/.output/public/_nuxt/{DGrrucbG2.js → DGrrucbG.js} +0 -0
  358. /package/.output/public/_nuxt/{Y4sMSPrS.js → Y4sMSPrS2.js} +0 -0
@@ -0,0 +1,474 @@
1
+ /**
2
+ * Ontology Compiler —— 本体图 → 四类产物 + Rule Trace。
3
+ *
4
+ * 铁律:
5
+ * 1) **只收紧不放宽**:提供 currentBounds 时,任何放宽现行界/步限的规则被
6
+ * rejected(TIGHTEN_ONLY_VIOLATED);无现行界时不产生「放开」语义,只新增约束。
7
+ * 2) **fail-closed**:每条规则必留一条 trace(compiled|guard|explained|rejected),
8
+ * 禁止静默丢弃;rejected/explained 都带可行动 message。
9
+ * 3) **不承诺后端不支持的能力**:线性耦合/复杂非线性一律 REJECTED_UNSUPPORTED_FORM,
10
+ * 绝不伪装成盒约束(当前 IR 无自由 A_ub)。
11
+ * 4) 产物只填既有 IR/Profile/SceneContract 的字段形状,不发明新约束族。
12
+ */
13
+ import type {
14
+ BoundsEntry,
15
+ CompileIssue,
16
+ CompileOptions,
17
+ CompiledArtifacts,
18
+ ControlGuard,
19
+ OntologyCompileResult,
20
+ OntologyDraftDoc,
21
+ OntologyEntity,
22
+ OntologyRelation,
23
+ OntologyRule,
24
+ OntologyRuleTrace,
25
+ RuleDecision,
26
+ } from './contracts'
27
+ import {
28
+ ONTOLOGY_SCHEMA_VERSION,
29
+ RULE_ERROR_CODES,
30
+ emptyArtifacts,
31
+ evidenceLevelRank,
32
+ unitsCompatible,
33
+ } from './contracts'
34
+ import { ruleEvidenceLevel, validateDraftDoc } from './validator'
35
+ import { canonicalJson, sha256 } from '../aml/twin/contracts'
36
+
37
+ const COMPARISON_RE = /^\s*([a-z][a-z0-9_.]*)\s*(<=|>=|<|>|==|!=)\s*(-?\d+(?:\.\d+)?)\s*$/
38
+
39
+ /** 把「X <= 阈值」阈值断言反演为守卫:违反条件 + 禁止继续同向增量 */
40
+ function invertComparison(op: string): ControlGuard['when']['op'] | null {
41
+ switch (op) {
42
+ case '<=': return 'gt'
43
+ case '<': return 'gte'
44
+ case '>=': return 'lt'
45
+ case '>': return 'lte'
46
+ case '==': return 'neq'
47
+ case '!=': return 'eq'
48
+ default: return null
49
+ }
50
+ }
51
+
52
+ function scopeOf(rule: OntologyRule, options: CompileOptions) {
53
+ return {
54
+ lineId: rule.scope.lineId || options.scope?.lineId || '',
55
+ recipeId: rule.scope.recipeId || options.scope?.recipeId || '',
56
+ conditionId: rule.scope.conditionId || options.scope?.conditionId || '',
57
+ }
58
+ }
59
+
60
+ function guardOnViolate(rule: OntologyRule, level: ReturnType<typeof ruleEvidenceLevel>, approvedOnly: boolean | undefined): ControlGuard['onViolate'] {
61
+ if (approvedOnly && rule.status !== 'approved_for_control') return 'annotate'
62
+ return evidenceLevelRank(level) >= evidenceLevelRank('observed_correlation') ? 'block_recommendation' : 'annotate'
63
+ }
64
+
65
+ function roleBucket(role: string | undefined): 'mv' | 'cv' | null {
66
+ if (!role) return null
67
+ if (role === 'control' || role === 'disturbance' || role === 'feature') return 'mv'
68
+ if (role === 'target' || role === 'observation') return 'cv'
69
+ return null
70
+ }
71
+
72
+ interface RuleOutcome {
73
+ decision: RuleDecision
74
+ code: string
75
+ message: string
76
+ hint?: string
77
+ guard?: ControlGuard
78
+ bound?: { bucket: 'mv' | 'cv', key: string, entry: BoundsEntry }
79
+ rate?: { key: string, maxStep: number }
80
+ soft?: string
81
+ /** 产物落点引用(编译时回填,供 trace 溯源) */
82
+ decidingRef?: string
83
+ }
84
+
85
+ function decideRule(
86
+ rule: OntologyRule,
87
+ entities: Map<string, OntologyEntity>,
88
+ options: CompileOptions,
89
+ ): RuleOutcome {
90
+ const level = ruleEvidenceLevel(rule)
91
+ const hardCapable = level === 'validated_control'
92
+ const currentMv = options.currentBounds?.mv ?? {}
93
+ const currentCv = options.currentBounds?.cv ?? {}
94
+ const currentOf = (bucket: 'mv' | 'cv', key: string): BoundsEntry | undefined => (bucket === 'mv' ? currentMv : currentCv)[key]
95
+
96
+ switch (rule.dsl.type) {
97
+ case 'bound': {
98
+ const entity = entities.get(rule.dsl.variableKey)
99
+ if (!entity) return { decision: 'rejected', code: RULE_ERROR_CODES.UNKNOWN_ENTITY, message: `规则 ${rule.id} 引用的实体「${rule.dsl.variableKey}」不存在` }
100
+ const bucket = roleBucket(entity.role)
101
+ if (!bucket) {
102
+ return {
103
+ decision: 'rejected', code: RULE_ERROR_CODES.ROLE_UNRESOLVED,
104
+ message: `实体「${entity.key}」缺少可判定角色(role=${entity.role ?? '空'}),无法决定产 mvBounds 还是 cvBounds`,
105
+ hint: '为该实体补 role=control(可控)/target(质量目标)/disturbance/feature/observation',
106
+ }
107
+ }
108
+ if (rule.dsl.unit && entity.unit && !unitsCompatible(rule.dsl.unit, entity.unit)) {
109
+ return {
110
+ decision: 'rejected', code: RULE_ERROR_CODES.UNIT_MISMATCH,
111
+ message: `规则 ${rule.id} 的界单位「${rule.dsl.unit}」与实体单位「${entity.unit}」量纲不相容`,
112
+ hint: '统一单位声明;数值换算请走 shared/units.ts(本体不做换算)',
113
+ }
114
+ }
115
+ if (rule.constraintLevel === 'hard' && !hardCapable) {
116
+ return {
117
+ decision: 'rejected', code: RULE_ERROR_CODES.EVIDENCE_INSUFFICIENT,
118
+ message: `规则 ${rule.id} 声明硬约束,但证据最高级别为 ${level || '无'}`,
119
+ hint: '硬约束只接受 validated_control(run+crosscheck+outcome 全链证据)',
120
+ }
121
+ }
122
+ if (rule.constraintLevel === 'hard' && options.approvedOnly && rule.status !== 'approved_for_control') {
123
+ return {
124
+ decision: 'rejected', code: RULE_ERROR_CODES.NOT_APPROVED,
125
+ message: `规则 ${rule.id} 尚未获批(当前状态 ${rule.status}),不能进入发布版求解约束`,
126
+ hint: '先完成 proposed→reviewed→validated→approved_for_control 审批链(approved_for_control 需第二人批准)',
127
+ }
128
+ }
129
+ if (rule.constraintLevel === 'soft') {
130
+ return {
131
+ decision: 'explained', code: '',
132
+ message: `规则 ${rule.id} 为软约束,仅作为训练/评审参考,不写入求解约束`,
133
+ soft: `soft bound ${rule.dsl.variableKey}: ${canonicalJson(rule.dsl)}`,
134
+ }
135
+ }
136
+ const proposed: BoundsEntry = {}
137
+ if (rule.dsl.min !== undefined) proposed.min = rule.dsl.min
138
+ if (rule.dsl.max !== undefined) proposed.max = rule.dsl.max
139
+ const current = currentOf(bucket, entity.key)
140
+ if (current?.min !== undefined && proposed.min !== undefined && proposed.min < current.min) {
141
+ return {
142
+ decision: 'rejected', code: RULE_ERROR_CODES.TIGHTEN_ONLY,
143
+ message: `规则 ${rule.id} 把 ${entity.key} 的下界从 ${current.min} 放宽到 ${proposed.min}`,
144
+ hint: '本体产物只能收紧现行界;放宽需要新的 Profile 版本并由人审',
145
+ }
146
+ }
147
+ if (current?.max !== undefined && proposed.max !== undefined && proposed.max > current.max) {
148
+ return {
149
+ decision: 'rejected', code: RULE_ERROR_CODES.TIGHTEN_ONLY,
150
+ message: `规则 ${rule.id} 把 ${entity.key} 的上界从 ${current.max} 放宽到 ${proposed.max}`,
151
+ hint: '本体产物只能收紧现行界;放宽需要新的 Profile 版本并由人审',
152
+ }
153
+ }
154
+ return {
155
+ decision: 'compiled', code: '',
156
+ message: `规则 ${rule.id} 收紧 ${entity.key} 的${bucket === 'mv' ? '可调' : '目标'}界${current ? '(已与现行界求交)' : ''}`,
157
+ bound: { bucket, key: entity.key, entry: proposed },
158
+ }
159
+ }
160
+ case 'rate': {
161
+ const entity = entities.get(rule.dsl.variableKey)
162
+ if (!entity) return { decision: 'rejected', code: RULE_ERROR_CODES.UNKNOWN_ENTITY, message: `规则 ${rule.id} 引用的实体「${rule.dsl.variableKey}」不存在` }
163
+ const bucket = roleBucket(entity.role)
164
+ if (bucket !== 'mv') {
165
+ return {
166
+ decision: 'rejected', code: RULE_ERROR_CODES.ROLE_UNRESOLVED,
167
+ message: `变化率规则 ${rule.id} 只能作用于可控变量(control/disturbance/feature),实体「${entity.key}」role=${entity.role ?? '空'}`,
168
+ hint: '为策略变量补 role=control',
169
+ }
170
+ }
171
+ if (rule.dsl.unit && entity.unit && !unitsCompatible(rule.dsl.unit, entity.unit)) {
172
+ return { decision: 'rejected', code: RULE_ERROR_CODES.UNIT_MISMATCH, message: `规则 ${rule.id} 的步限单位「${rule.dsl.unit}」与实体单位「${entity.unit}」不相容` }
173
+ }
174
+ if (rule.constraintLevel === 'hard' && !hardCapable) {
175
+ return {
176
+ decision: 'rejected', code: RULE_ERROR_CODES.EVIDENCE_INSUFFICIENT,
177
+ message: `规则 ${rule.id} 声明硬步限,但证据最高级别为 ${level || '无'}`,
178
+ hint: '硬步限只接受 validated_control',
179
+ }
180
+ }
181
+ if (rule.constraintLevel === 'hard' && options.approvedOnly && rule.status !== 'approved_for_control') {
182
+ return {
183
+ decision: 'rejected', code: RULE_ERROR_CODES.NOT_APPROVED,
184
+ message: `规则 ${rule.id} 尚未获批(当前状态 ${rule.status}),不能进入发布版步限`,
185
+ hint: '先完成审批链',
186
+ }
187
+ }
188
+ if (rule.constraintLevel === 'soft') {
189
+ return { decision: 'explained', code: '', message: `规则 ${rule.id} 为软步限,仅作训练/评审参考`, soft: `soft rate ${entity.key}: ${rule.dsl.maxStep}` }
190
+ }
191
+ const current = currentOf('mv', entity.key)
192
+ if (current?.maxStep !== undefined && rule.dsl.maxStep > current.maxStep) {
193
+ return {
194
+ decision: 'rejected', code: RULE_ERROR_CODES.TIGHTEN_ONLY,
195
+ message: `规则 ${rule.id} 把 ${entity.key} 的步限从 ${current.maxStep} 放宽到 ${rule.dsl.maxStep}`,
196
+ hint: '本体产物只能收紧步限;放宽需要新的 Profile 版本',
197
+ }
198
+ }
199
+ return {
200
+ decision: 'compiled', code: '',
201
+ message: `规则 ${rule.id} 收紧 ${entity.key} 的最大单步 ${rule.dsl.maxStep}`,
202
+ rate: { key: entity.key, maxStep: rule.dsl.maxStep },
203
+ }
204
+ }
205
+ case 'linear_coupling':
206
+ return {
207
+ decision: 'rejected', code: RULE_ERROR_CODES.UNSUPPORTED_FORM,
208
+ message: `规则 ${rule.id} 是线性耦合约束(${rule.dsl.variableKey} 随 ${rule.dsl.ofKey}),当前 ProblemIR 无自由 A_ub 形态`,
209
+ hint: '需 IR v2 + OSQP A 矩阵支持(超出 v4.1 范围);可改写为状态条件守卫或落到孪生 PhysicsSpec',
210
+ }
211
+ case 'nonlinear': {
212
+ const match = rule.dsl.expression.match(COMPARISON_RE)
213
+ if (!match) {
214
+ return {
215
+ decision: 'rejected', code: RULE_ERROR_CODES.UNSUPPORTED_FORM,
216
+ message: `规则 ${rule.id} 的非线性表达式无法由运行时守卫执行(仅支持「变量 比较 阈值」)`,
217
+ hint: '改写为阈值形式,或落 PhysicsSpec 由后端支持',
218
+ }
219
+ }
220
+ const lhs = match[1]!
221
+ const inverted = invertComparison(match[2]!)
222
+ const value = Number(match[3])
223
+ if (!inverted || !Number.isFinite(value)) {
224
+ return { decision: 'rejected', code: RULE_ERROR_CODES.UNSUPPORTED_FORM, message: `规则 ${rule.id} 的比较算子不受支持` }
225
+ }
226
+ if (!entities.has(lhs)) {
227
+ return { decision: 'rejected', code: RULE_ERROR_CODES.UNKNOWN_ENTITY, message: `规则 ${rule.id} 引用的实体「${lhs}」不存在` }
228
+ }
229
+ const guard: ControlGuard = {
230
+ id: `guard-${rule.id}`,
231
+ ruleId: rule.id,
232
+ when: { variableKey: lhs, op: inverted, value },
233
+ forbid: { kind: 'nonzero_increment', variableKey: lhs },
234
+ scope: scopeOf(rule, options),
235
+ onViolate: guardOnViolate(rule, level, options.approvedOnly),
236
+ message: `${rule.id}: ${rule.dsl.expression} 已越界,禁止继续同向调整`,
237
+ }
238
+ return { decision: 'guard', code: '', message: `规则 ${rule.id} 编译为运行时守卫(阈值 ${rule.dsl.expression})`, guard }
239
+ }
240
+ case 'state_condition': {
241
+ if (!entities.has(rule.dsl.when.variableKey)) {
242
+ return {
243
+ decision: 'rejected', code: RULE_ERROR_CODES.OBSERVABLE_UNRESOLVED,
244
+ message: `规则 ${rule.id} 的状态变量「${rule.dsl.when.variableKey}」未在本体中定义,无法观测`,
245
+ hint: '先定义该状态实体并做语义绑定,或改用工况条件',
246
+ }
247
+ }
248
+ if (!entities.has(rule.dsl.forbid.variableKey)) {
249
+ return { decision: 'rejected', code: RULE_ERROR_CODES.UNKNOWN_ENTITY, message: `规则 ${rule.id} 的目标变量「${rule.dsl.forbid.variableKey}」不存在` }
250
+ }
251
+ const guard: ControlGuard = {
252
+ id: `guard-${rule.id}`,
253
+ ruleId: rule.id,
254
+ when: rule.dsl.when,
255
+ forbid: rule.dsl.forbid,
256
+ scope: scopeOf(rule, options),
257
+ onViolate: guardOnViolate(rule, level, options.approvedOnly),
258
+ message: rule.dsl.message ?? `规则 ${rule.id}: 前置条件未满足,禁止调整「${rule.dsl.forbid.variableKey}」`,
259
+ }
260
+ return { decision: 'guard', code: '', message: `规则 ${rule.id} 编译为运行时守卫(条件未满足时禁止增量)`, guard }
261
+ }
262
+ case 'interlock':
263
+ return {
264
+ decision: 'explained', code: RULE_ERROR_CODES.PLC_LAYER,
265
+ message: `规则 ${rule.id} 属于安全联锁,归 PLC/DCW 配置层(${rule.dsl.text})`,
266
+ hint: '请在 DCW 节点限界或 PLC 联锁逻辑中落实;本体不会替代现场安全回路',
267
+ }
268
+ case 'informal':
269
+ return { decision: 'explained', code: '', message: `规则 ${rule.id} 无法形式化,仅作解释与人工审核依据(${rule.dsl.text})` }
270
+ default:
271
+ return { decision: 'rejected', code: RULE_ERROR_CODES.INVALID, message: `规则 ${rule.id} 的 DSL 形态未知` }
272
+ }
273
+ }
274
+
275
+ /** 由关系派生训练先验(特征候选/时滞/单调性) */
276
+ function deriveProcessModel(doc: OntologyDraftDoc, entities: Map<string, OntologyEntity>) {
277
+ const featureCandidates: CompiledArtifacts['processModel']['featureCandidates'] = []
278
+ const delayPriors: CompiledArtifacts['processModel']['delayPriors'] = []
279
+ const monotonicity: CompiledArtifacts['processModel']['monotonicity'] = []
280
+ const seenFeature = new Set<string>()
281
+
282
+ for (const rel of doc.relations as OntologyRelation[]) {
283
+ if (rel.kind !== 'influences') continue
284
+ const dst = entities.get(rel.dstKey)
285
+ const src = entities.get(rel.srcKey)
286
+ if (dst?.role === 'target' || dst?.role === 'observation') {
287
+ const dedupe = `${rel.srcKey}|${rel.dstKey}`
288
+ if (!seenFeature.has(dedupe)) {
289
+ seenFeature.add(dedupe)
290
+ featureCandidates.push({
291
+ entityKey: rel.srcKey,
292
+ role: src?.role === 'disturbance' ? 'disturbance' : 'feature',
293
+ relation: `influences→${rel.dstKey}`,
294
+ evidenceLevel: rel.properties.evidenceTier,
295
+ priorDelayMs: rel.properties.lagMs,
296
+ variabilityChecked: rel.properties.variabilityChecked,
297
+ })
298
+ }
299
+ }
300
+ if (rel.properties.sign) {
301
+ monotonicity.push({
302
+ output: rel.dstKey,
303
+ input: rel.srcKey,
304
+ direction: rel.properties.sign === 'positive' ? 'increasing' : 'decreasing',
305
+ })
306
+ }
307
+ if (rel.properties.lagMs !== undefined) {
308
+ delayPriors.push({
309
+ entityKey: rel.srcKey, delayMs: rel.properties.lagMs, basis: 'relation_lag',
310
+ variabilityChecked: rel.properties.variabilityChecked,
311
+ })
312
+ }
313
+ else if (rel.properties.transportDistanceM && rel.properties.nominalSpeedMps) {
314
+ const delayMs = Math.round((rel.properties.transportDistanceM / rel.properties.nominalSpeedMps) * 1000)
315
+ delayPriors.push({
316
+ entityKey: rel.srcKey, delayMs, basis: 'tau_eq_D_over_v',
317
+ variabilityChecked: rel.properties.variabilityChecked,
318
+ })
319
+ }
320
+ }
321
+ return { featureCandidates, delayPriors, monotonicity }
322
+ }
323
+
324
+ function traceId(ontologyId: string, version: number, ruleId: string): string {
325
+ return `ort-${ontologyId}@${version}:${ruleId}`
326
+ }
327
+
328
+ function buildTrace(
329
+ ontologyId: string, version: number, rulePackHash: string, rule: OntologyRule,
330
+ outcome: RuleOutcome, createdAt: string,
331
+ ): OntologyRuleTrace {
332
+ const level = ruleEvidenceLevel(rule)
333
+ const base: OntologyRuleTrace = {
334
+ id: traceId(ontologyId, version, rule.id),
335
+ ontologyId,
336
+ version,
337
+ rulePackHash,
338
+ ruleId: rule.id,
339
+ ruleKey: rule.key,
340
+ ruleRevision: sha256(canonicalJson({ kind: rule.kind, dsl: rule.dsl, constraintLevel: rule.constraintLevel, evidence: rule.evidence.map(e => `${e.id}:${e.level}`) })),
341
+ ruleKind: rule.kind,
342
+ evidenceLevel: level,
343
+ constraintLevel: rule.constraintLevel,
344
+ decision: outcome.decision,
345
+ decisionCode: outcome.code,
346
+ message: outcome.hint ? `${outcome.message}。建议:${outcome.hint}` : outcome.message,
347
+ bindings: [],
348
+ artifacts: [],
349
+ scope: { lineId: rule.scope.lineId, recipeId: rule.scope.recipeId, conditionId: rule.scope.conditionId },
350
+ rowHash: '',
351
+ createdAt,
352
+ }
353
+ base.rowHash = sha256(canonicalJson({ ...base, rowHash: '' }))
354
+ return base
355
+ }
356
+
357
+ /** 编译入口(纯函数;不写库) */
358
+ export function compileOntology(doc: OntologyDraftDoc, options: CompileOptions): OntologyCompileResult {
359
+ const createdAt = options.createdAt ?? new Date().toISOString()
360
+ const validation = validateDraftDoc(doc)
361
+ const rules = [...doc.rules].sort((a, b) => a.id.localeCompare(b.id))
362
+ const rulePackHash = sha256(canonicalJson(rules.map(r => ({
363
+ id: r.id, key: r.key, kind: r.kind, dsl: r.dsl, constraintLevel: r.constraintLevel,
364
+ evidence: r.evidence.map(e => e.level),
365
+ }))))
366
+
367
+ if (!validation.ok) {
368
+ return {
369
+ status: 'rejected',
370
+ ontologyId: options.ontologyId,
371
+ ontologyVersion: options.version,
372
+ contentHash: sha256(canonicalJson(doc)),
373
+ rulePackHash,
374
+ artifacts: emptyArtifacts(),
375
+ traces: [],
376
+ issues: validation.issues,
377
+ compiledCount: 0,
378
+ guardCount: 0,
379
+ explainedCount: 0,
380
+ rejectedCount: rules.length,
381
+ }
382
+ }
383
+
384
+ const entities = new Map(doc.entities.map(e => [e.key, e]))
385
+ const artifacts = emptyArtifacts()
386
+ const traces: OntologyRuleTrace[] = []
387
+ const issues: CompileIssue[] = []
388
+ let compiledCount = 0
389
+ let guardCount = 0
390
+ let explainedCount = 0
391
+ let rejectedCount = 0
392
+
393
+ for (const rule of rules) {
394
+ const outcome = decideRule(rule, entities, options)
395
+ if (outcome.decision === 'compiled') compiledCount += 1
396
+ else if (outcome.decision === 'guard') guardCount += 1
397
+ else if (outcome.decision === 'explained') explainedCount += 1
398
+ else rejectedCount += 1
399
+
400
+ if (outcome.bound) {
401
+ const bucket = outcome.bound.bucket === 'mv' ? artifacts.problemIr.mvBounds : artifacts.problemIr.cvBounds
402
+ const merged = bucket[outcome.bound.key] ?? {}
403
+ if (outcome.bound.entry.min !== undefined) merged.min = Math.max(merged.min ?? Number.NEGATIVE_INFINITY, outcome.bound.entry.min)
404
+ if (outcome.bound.entry.max !== undefined) merged.max = Math.min(merged.max ?? Number.POSITIVE_INFINITY, outcome.bound.entry.max)
405
+ bucket[outcome.bound.key] = merged
406
+ outcome.decidingRef = `problem-ir:${outcome.bound.key}`
407
+ }
408
+ if (outcome.rate) {
409
+ const merged = artifacts.problemIr.mvBounds[outcome.rate.key] ?? {}
410
+ merged.maxStep = Math.min(merged.maxStep ?? Number.POSITIVE_INFINITY, outcome.rate.maxStep)
411
+ artifacts.problemIr.mvBounds[outcome.rate.key] = merged
412
+ outcome.decidingRef = `problem-ir:${outcome.rate.key}`
413
+ }
414
+ if (outcome.soft) artifacts.problemIr.softRegularization.push({ ruleId: rule.id, note: outcome.soft })
415
+ if (outcome.guard) artifacts.controlGuard.guards.push(outcome.guard)
416
+ if (outcome.decision === 'rejected' || outcome.decision === 'explained') {
417
+ issues.push({
418
+ code: outcome.code || RULE_ERROR_CODES.INVALID,
419
+ path: `rules[${rule.id}]`,
420
+ message: outcome.message,
421
+ severity: outcome.decision === 'rejected' ? 'error' : 'warning',
422
+ ruleId: rule.id,
423
+ hint: outcome.hint,
424
+ })
425
+ }
426
+ const trace = buildTrace(options.ontologyId, options.version, rulePackHash, rule, outcome, createdAt)
427
+ if (outcome.guard) trace.artifacts.push({ kind: 'control_guard', ref: outcome.guard.id, artifactHash: sha256(canonicalJson(outcome.guard)) })
428
+ if (outcome.decidingRef) trace.artifacts.push({ kind: 'problem_ir', ref: outcome.decidingRef })
429
+ traces.push(trace)
430
+ }
431
+
432
+ const derived = deriveProcessModel(doc, entities)
433
+ artifacts.processModel = derived
434
+
435
+ artifacts.sceneContract.inferredRelations = doc.relations.map(rel => ({
436
+ srcKey: rel.srcKey, dstKey: rel.dstKey, predicate: rel.kind, evidenceTier: rel.properties.evidenceTier,
437
+ }))
438
+ artifacts.sceneContract.variables = doc.entities
439
+ .filter(e => !!e.role && (e.kind === 'process_variable' || e.kind === 'quality_variable'))
440
+ .map((e) => {
441
+ const bound = artifacts.problemIr.mvBounds[e.key] ?? artifacts.problemIr.cvBounds[e.key]
442
+ return { id: e.key, role: e.role as string, unit: e.unit, min: bound?.min, max: bound?.max, maxStep: bound?.maxStep }
443
+ })
444
+ artifacts.sceneContract.constraints = [
445
+ ...Object.entries(artifacts.problemIr.mvBounds)
446
+ .map(([key, entry]) => ({ id: `mv:${key}`, kind: 'hard_range' as const, min: entry.min, max: entry.max })),
447
+ ...Object.entries(artifacts.problemIr.mvBounds).filter(([, entry]) => entry.maxStep !== undefined)
448
+ .map(([key, entry]) => ({ id: `rate:${key}`, kind: 'rate' as const, max: entry.maxStep })),
449
+ ]
450
+
451
+ const status: OntologyCompileResult['status'] = (compiledCount + guardCount) === 0 && rejectedCount > 0
452
+ ? 'rejected'
453
+ : (rejectedCount > 0 || explainedCount > 0 ? 'warning' : 'success')
454
+
455
+ return {
456
+ status,
457
+ ontologyId: options.ontologyId,
458
+ ontologyVersion: options.version,
459
+ contentHash: sha256(canonicalJson(doc)),
460
+ rulePackHash,
461
+ artifacts,
462
+ traces,
463
+ issues,
464
+ compiledCount,
465
+ guardCount,
466
+ explainedCount,
467
+ rejectedCount,
468
+ }
469
+ }
470
+
471
+ /** 规则集 hash(用于 Profile 侧漂移比对) */
472
+ export function ontologyPackHash(input: { rulePackHash: string, contentHash: string }): string {
473
+ return sha256(canonicalJson({ v: ONTOLOGY_SCHEMA_VERSION, rulePackHash: input.rulePackHash, contentHash: input.contentHash }))
474
+ }