@engenty/wizards-runtime 0.20.5 → 0.21.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 (363) hide show
  1. package/README.md +3 -3
  2. package/apps/runtime/dist/agents/studio-assistant.js +7 -3
  3. package/apps/runtime/dist/agents/subscription.js +20 -25
  4. package/apps/runtime/dist/app.js +4 -1
  5. package/apps/runtime/dist/cli/clients.js +6 -24
  6. package/apps/runtime/dist/cli/connect.js +2 -1
  7. package/apps/runtime/dist/cli/environment.js +3 -0
  8. package/apps/runtime/dist/cli/machine.js +1 -70
  9. package/apps/runtime/dist/cli/main.js +2 -1
  10. package/apps/runtime/dist/cli/ollama.js +7 -254
  11. package/apps/runtime/dist/cli/setup.js +12 -9
  12. package/apps/runtime/dist/decision-model.js +1 -4
  13. package/apps/runtime/dist/docs/dev/licensing.md +20 -9
  14. package/apps/runtime/dist/docs/user-guide/command-line.md +5 -2
  15. package/apps/runtime/dist/elements/outside.js +2 -1
  16. package/apps/runtime/dist/engine/code-step.js +1 -1
  17. package/apps/runtime/dist/engine/decide.js +2 -2
  18. package/apps/runtime/dist/engine/device.js +3 -2
  19. package/apps/runtime/dist/engine/input.js +1 -1
  20. package/apps/runtime/dist/engine/runner.js +1 -1
  21. package/apps/runtime/dist/engine/steps.js +27 -8
  22. package/apps/runtime/dist/engine/surface.js +1 -1
  23. package/apps/runtime/dist/engine/template.js +1 -1
  24. package/apps/runtime/dist/env.js +1 -0
  25. package/apps/runtime/dist/harness/apple.js +4 -3
  26. package/apps/runtime/dist/harness/clients.js +117 -0
  27. package/apps/runtime/dist/harness/index.js +32 -87
  28. package/apps/runtime/dist/harness/model.js +32 -270
  29. package/apps/runtime/dist/harness/prompt.js +6 -120
  30. package/apps/runtime/dist/harness/types.js +5 -3
  31. package/apps/runtime/dist/local-call.js +6 -0
  32. package/apps/runtime/dist/local-models.js +53 -177
  33. package/apps/runtime/dist/mcp/bridge.js +12 -55
  34. package/apps/runtime/dist/mcp/elements.js +39 -4
  35. package/apps/runtime/dist/mcp/handler.js +12 -0
  36. package/apps/runtime/dist/mcp/run-pages.js +238 -0
  37. package/apps/runtime/dist/mcp/run-tasks.js +157 -0
  38. package/apps/runtime/dist/mcp/runs.js +129 -0
  39. package/apps/runtime/dist/mcp/tools.js +4 -95
  40. package/apps/runtime/dist/models.js +82 -32
  41. package/apps/runtime/dist/motion-graphics/step.js +2 -2
  42. package/apps/runtime/dist/prompts/mcp.md +4 -1
  43. package/apps/runtime/dist/render/downloads.js +1 -1
  44. package/apps/runtime/dist/render/shaped.js +1 -1
  45. package/apps/runtime/dist/routes/model-setup.js +77 -0
  46. package/apps/runtime/dist/routes/studio.js +8 -251
  47. package/apps/runtime/dist/services/space-categories.js +1 -1
  48. package/apps/runtime/dist/services/work-ai.js +11 -5
  49. package/apps/runtime/dist/texts.js +4 -6
  50. package/apps/runtime/dist/tools/connections.js +3 -0
  51. package/apps/runtime/dist/tools/harness.js +124 -0
  52. package/apps/web/dist/assets/AboutDialog-BSdAA4Wi.js +1 -0
  53. package/apps/web/dist/assets/{BlockEditor-CgjXTWly.js → BlockEditor-0noqMcAl.js} +1 -1
  54. package/apps/web/dist/assets/Bundle-Ctrq7lHH.js +1 -0
  55. package/apps/web/dist/assets/CapabilitiesPage-CZlVhBmU.js +2 -0
  56. package/apps/web/dist/assets/ChangelogDialog-BLCYV4jT.js +1 -0
  57. package/apps/web/dist/assets/{CodeEditor-2LyHbSre.js → CodeEditor-CpRn9BZq.js} +1 -1
  58. package/apps/web/dist/assets/ConnectorsSection-B4rRDlFo.js +1 -0
  59. package/apps/web/dist/assets/EditorPage-CXN-_zzG.js +3 -0
  60. package/apps/web/dist/assets/FlowPreview-DjQvcWxs.js +1 -0
  61. package/apps/web/dist/assets/LangSwitch-BuzsLp16.js +1 -0
  62. package/apps/web/dist/assets/LocalModels-BDfP2v5-.js +1 -0
  63. package/apps/web/dist/assets/Marketplace-4baBNzEc.js +2 -0
  64. package/apps/web/dist/assets/NewWizardChannels-B_xHm-bI.js +1 -0
  65. package/apps/web/dist/assets/NewWizardPage-BmZAY4zi.js +7 -0
  66. package/apps/web/dist/assets/OnboardingPage-fZq3WiTk.js +1 -0
  67. package/apps/web/dist/assets/ProtocolSection-v9wIxisg.js +1 -0
  68. package/apps/web/dist/assets/PublicRunner-BCh0VzAT.js +1 -0
  69. package/apps/web/dist/assets/{ReadOnly-CbvEK0rz.js → ReadOnly-13stkvNz.js} +1 -1
  70. package/apps/web/dist/assets/Results-4gmguYzH.js +1 -0
  71. package/apps/web/dist/assets/RunDrawer-CeEldWRn.js +1 -0
  72. package/apps/web/dist/assets/SettingsPage-BsKRRlfP.js +2 -0
  73. package/apps/web/dist/assets/SetupPage-FgA5Kl8z.js +1 -0
  74. package/apps/web/dist/assets/SharePage-BlBW4oxl.js +1 -0
  75. package/apps/web/dist/assets/SkillEditor-9QSskfmY.js +1 -0
  76. package/apps/web/dist/assets/Skills-DdUAyNhR.js +9 -0
  77. package/apps/web/dist/assets/SpacePage-CHkNPuqt.js +2 -0
  78. package/apps/web/dist/assets/StudioHome-BwPD-inc.js +1 -0
  79. package/apps/web/dist/assets/TableEditor-Du1DhbEC.js +7 -0
  80. package/apps/web/dist/assets/UpdateCheck-DPr9NXq_.js +2 -0
  81. package/apps/web/dist/assets/brand-DY3lzrOd.js +2 -0
  82. package/apps/web/dist/assets/changelog-BSdb22c3.js +1 -0
  83. package/apps/web/dist/assets/code-editor-Bep_LzQ5.js +2 -0
  84. package/apps/web/dist/assets/host-DiZQ_uws.js +1 -0
  85. package/apps/web/dist/assets/host-Dw-sMUSd.js +54 -0
  86. package/apps/web/dist/assets/i18n-DVrYWJaj.js +55 -0
  87. package/apps/web/dist/assets/index-C2gxK14s.css +1 -0
  88. package/apps/web/dist/assets/index-lQ4JYHYQ.js +102 -0
  89. package/apps/web/dist/assets/oss-credits-BHy69wkx.js +1 -0
  90. package/apps/web/dist/assets/{read-aloud-CRFt5q6k.js → read-aloud-CBycd8TA.js} +1 -1
  91. package/apps/web/dist/assets/{session-RDdtfee2.js → session-BYLtgklo.js} +1 -1
  92. package/apps/web/dist/assets/terminal-DmGdMags.js +16 -0
  93. package/apps/web/dist/assets/texts-ClKS2xhh.js +1 -0
  94. package/apps/web/dist/assets/theme-DFDOMsVo.js +14 -0
  95. package/apps/web/dist/assets/ui-CW2I3ecu.js +1 -0
  96. package/apps/web/dist/assets/ui-DfVpZYIW.js +16 -0
  97. package/apps/web/dist/assets/{useMutation-BSffqL6W.js → useMutation-BnkuLlQC.js} +1 -1
  98. package/apps/web/dist/assets/viewers-C6FfRwG1.js +2 -0
  99. package/apps/web/dist/index.html +18 -16
  100. package/apps/web/dist/mcp/flow.html +129 -129
  101. package/bin/bot-tunnel.mjs +375 -0
  102. package/bin/bot.mjs +494 -69
  103. package/node_modules/@engenty/{wizards-shared → chatviews}/dist/calc.js +1 -1
  104. package/node_modules/@engenty/chatviews/dist/chat/a2ui.d.ts +48 -0
  105. package/node_modules/@engenty/chatviews/dist/chat/a2ui.js +514 -0
  106. package/node_modules/@engenty/chatviews/dist/chat/check.d.ts +18 -0
  107. package/node_modules/@engenty/chatviews/dist/chat/check.js +97 -0
  108. package/node_modules/@engenty/chatviews/dist/chat/index.d.ts +3 -0
  109. package/node_modules/@engenty/chatviews/dist/chat/index.js +4 -0
  110. package/node_modules/@engenty/chatviews/dist/chat/library.d.ts +39 -0
  111. package/node_modules/@engenty/chatviews/dist/chat/library.js +314 -0
  112. package/node_modules/@engenty/{wizards-shared → chatviews}/dist/numbers.js +1 -1
  113. package/node_modules/@engenty/chatviews/dist/react/chat.d.ts +33 -0
  114. package/node_modules/@engenty/chatviews/dist/react/chat.js +150 -0
  115. package/node_modules/@engenty/chatviews/dist/react/field-looks.d.ts +39 -0
  116. package/node_modules/@engenty/chatviews/dist/react/field-looks.js +47 -0
  117. package/node_modules/@engenty/chatviews/dist/react/markdown.d.ts +5 -0
  118. package/node_modules/@engenty/chatviews/dist/react/markdown.js +11 -0
  119. package/node_modules/@engenty/chatviews/dist/react/no-devtools.d.ts +0 -0
  120. package/node_modules/@engenty/chatviews/dist/react/no-devtools.js +8 -0
  121. package/node_modules/@engenty/chatviews/dist/react/surface.d.ts +39 -0
  122. package/node_modules/@engenty/chatviews/dist/react/surface.js +552 -0
  123. package/node_modules/@engenty/chatviews/dist/react/texts.d.ts +39 -0
  124. package/node_modules/@engenty/chatviews/dist/react/texts.js +42 -0
  125. package/node_modules/@engenty/chatviews/dist/react/ui.d.ts +112 -0
  126. package/node_modules/@engenty/chatviews/dist/react/ui.js +212 -0
  127. package/node_modules/@engenty/{wizards-shared → chatviews}/dist/shape.js +1 -1
  128. package/node_modules/@engenty/{wizards-shared → chatviews}/dist/surface.js +1 -1
  129. package/node_modules/@engenty/chatviews/package.json +19 -0
  130. package/node_modules/@engenty/decision-model/dist/client.d.ts +76 -0
  131. package/node_modules/@engenty/decision-model/dist/client.js +188 -0
  132. package/node_modules/@engenty/decision-model/dist/index.d.ts +6 -0
  133. package/node_modules/@engenty/decision-model/dist/index.js +5 -0
  134. package/node_modules/@engenty/decision-model/dist/local.d.ts +11 -0
  135. package/node_modules/@engenty/decision-model/dist/local.js +116 -0
  136. package/node_modules/@engenty/decision-model/dist/resolve.d.ts +26 -0
  137. package/node_modules/@engenty/decision-model/dist/resolve.js +53 -0
  138. package/node_modules/@engenty/decision-model/dist/types.d.ts +80 -0
  139. package/node_modules/@engenty/decision-model/dist/types.js +6 -0
  140. package/node_modules/@engenty/decision-model/dist/validate.d.ts +9 -0
  141. package/node_modules/@engenty/decision-model/dist/validate.js +50 -0
  142. package/node_modules/@engenty/decision-model/dist/ways.d.ts +42 -0
  143. package/node_modules/@engenty/decision-model/dist/ways.js +72 -0
  144. package/node_modules/@engenty/decision-model/package.json +9 -0
  145. package/node_modules/@engenty/local-models/dist/bridge/index.d.ts +54 -0
  146. package/node_modules/@engenty/local-models/dist/bridge/index.js +117 -0
  147. package/node_modules/@engenty/local-models/dist/clients/antigravity.d.ts +37 -0
  148. package/{apps/runtime/dist/harness → node_modules/@engenty/local-models/dist/clients}/antigravity.js +72 -17
  149. package/node_modules/@engenty/local-models/dist/clients/chat.d.ts +89 -0
  150. package/node_modules/@engenty/local-models/dist/clients/chat.js +22 -0
  151. package/node_modules/@engenty/local-models/dist/clients/claude.d.ts +32 -0
  152. package/node_modules/@engenty/local-models/dist/clients/claude.js +239 -0
  153. package/node_modules/@engenty/local-models/dist/clients/client.d.ts +31 -0
  154. package/node_modules/@engenty/local-models/dist/clients/client.js +2 -0
  155. package/node_modules/@engenty/local-models/dist/clients/codex.d.ts +35 -0
  156. package/node_modules/@engenty/local-models/dist/clients/codex.js +254 -0
  157. package/node_modules/@engenty/local-models/dist/clients/cursor.d.ts +35 -0
  158. package/node_modules/@engenty/local-models/dist/clients/cursor.js +192 -0
  159. package/node_modules/@engenty/local-models/dist/clients/detect.d.ts +18 -0
  160. package/node_modules/@engenty/local-models/dist/clients/detect.js +34 -0
  161. package/node_modules/@engenty/local-models/dist/clients/env.d.ts +66 -0
  162. package/{apps/runtime/dist/harness → node_modules/@engenty/local-models/dist/clients}/env.js +62 -31
  163. package/node_modules/@engenty/local-models/dist/clients/failure.d.ts +26 -0
  164. package/node_modules/@engenty/local-models/dist/clients/failure.js +35 -0
  165. package/node_modules/@engenty/local-models/dist/clients/index.d.ts +15 -0
  166. package/node_modules/@engenty/local-models/dist/clients/index.js +18 -0
  167. package/node_modules/@engenty/local-models/dist/clients/model.d.ts +129 -0
  168. package/node_modules/@engenty/local-models/dist/clients/model.js +225 -0
  169. package/node_modules/@engenty/local-models/dist/clients/prompt.d.ts +36 -0
  170. package/node_modules/@engenty/local-models/dist/clients/prompt.js +123 -0
  171. package/node_modules/@engenty/local-models/dist/clients/run.d.ts +15 -0
  172. package/node_modules/@engenty/local-models/dist/clients/run.js +41 -0
  173. package/node_modules/@engenty/local-models/dist/index.d.ts +4 -0
  174. package/node_modules/@engenty/local-models/dist/index.js +4 -0
  175. package/node_modules/@engenty/local-models/dist/lmstudio/api.d.ts +49 -0
  176. package/node_modules/@engenty/local-models/dist/lmstudio/api.js +101 -0
  177. package/node_modules/@engenty/local-models/dist/lmstudio/index.d.ts +3 -0
  178. package/node_modules/@engenty/local-models/dist/lmstudio/index.js +3 -0
  179. package/node_modules/@engenty/local-models/dist/lmstudio/load.d.ts +12 -0
  180. package/node_modules/@engenty/local-models/dist/lmstudio/load.js +100 -0
  181. package/node_modules/@engenty/local-models/dist/lmstudio/server.d.ts +3 -0
  182. package/node_modules/@engenty/local-models/dist/lmstudio/server.js +29 -0
  183. package/node_modules/@engenty/local-models/dist/mlx/helper.d.ts +54 -0
  184. package/node_modules/@engenty/local-models/dist/mlx/helper.js +149 -0
  185. package/node_modules/@engenty/local-models/dist/mlx/index.d.ts +3 -0
  186. package/node_modules/@engenty/local-models/dist/mlx/index.js +3 -0
  187. package/node_modules/@engenty/local-models/dist/mlx/server.d.ts +19 -0
  188. package/node_modules/@engenty/local-models/dist/mlx/server.js +82 -0
  189. package/node_modules/@engenty/local-models/dist/mlx/store.d.ts +16 -0
  190. package/node_modules/@engenty/local-models/dist/mlx/store.js +153 -0
  191. package/node_modules/@engenty/local-models/dist/ollama/api.d.ts +37 -0
  192. package/node_modules/@engenty/local-models/dist/ollama/api.js +147 -0
  193. package/node_modules/@engenty/local-models/dist/ollama/index.d.ts +3 -0
  194. package/node_modules/@engenty/local-models/dist/ollama/index.js +3 -0
  195. package/node_modules/@engenty/local-models/dist/ollama/model.d.ts +54 -0
  196. package/node_modules/@engenty/local-models/dist/ollama/model.js +302 -0
  197. package/node_modules/@engenty/local-models/dist/ollama/server.d.ts +3 -0
  198. package/node_modules/@engenty/local-models/dist/ollama/server.js +45 -0
  199. package/node_modules/@engenty/local-models/dist/probe.d.ts +57 -0
  200. package/node_modules/@engenty/local-models/dist/probe.js +174 -0
  201. package/node_modules/@engenty/local-models/dist/servers/index.d.ts +6 -0
  202. package/node_modules/@engenty/local-models/dist/servers/index.js +12 -0
  203. package/node_modules/@engenty/local-models/dist/servers/server.d.ts +84 -0
  204. package/node_modules/@engenty/local-models/dist/servers/server.js +38 -0
  205. package/node_modules/@engenty/local-models/package.json +16 -0
  206. package/node_modules/@engenty/model-setup/dist/catalog.d.ts +36 -0
  207. package/node_modules/@engenty/model-setup/dist/catalog.js +81 -0
  208. package/node_modules/@engenty/model-setup/dist/index.d.ts +3 -0
  209. package/node_modules/@engenty/model-setup/dist/index.js +3 -0
  210. package/node_modules/@engenty/model-setup/dist/offered.d.ts +7 -0
  211. package/node_modules/@engenty/model-setup/dist/offered.js +64 -0
  212. package/node_modules/@engenty/model-setup/dist/react/client.d.ts +46 -0
  213. package/node_modules/@engenty/model-setup/dist/react/client.js +147 -0
  214. package/node_modules/@engenty/model-setup/dist/react/columns.d.ts +78 -0
  215. package/node_modules/@engenty/model-setup/dist/react/columns.js +99 -0
  216. package/node_modules/@engenty/model-setup/dist/react/host.d.ts +31 -0
  217. package/node_modules/@engenty/model-setup/dist/react/host.js +48 -0
  218. package/node_modules/@engenty/model-setup/dist/react/index.d.ts +7 -0
  219. package/node_modules/@engenty/model-setup/dist/react/index.js +7 -0
  220. package/node_modules/@engenty/model-setup/dist/react/keys.d.ts +48 -0
  221. package/node_modules/@engenty/model-setup/dist/react/keys.js +74 -0
  222. package/node_modules/@engenty/model-setup/dist/react/local-models.d.ts +23 -0
  223. package/node_modules/@engenty/model-setup/dist/react/local-models.js +134 -0
  224. package/node_modules/@engenty/model-setup/dist/react/servers.d.ts +4 -0
  225. package/node_modules/@engenty/model-setup/dist/react/servers.js +13 -0
  226. package/node_modules/@engenty/model-setup/dist/react/terminal.d.ts +13 -0
  227. package/node_modules/@engenty/model-setup/dist/react/terminal.js +79 -0
  228. package/node_modules/@engenty/model-setup/dist/react/tone.d.ts +13 -0
  229. package/node_modules/@engenty/model-setup/dist/react/tone.js +66 -0
  230. package/node_modules/@engenty/model-setup/dist/server/apps.d.ts +12 -0
  231. package/node_modules/@engenty/model-setup/dist/server/apps.js +22 -0
  232. package/node_modules/@engenty/model-setup/dist/server/clients.d.ts +55 -0
  233. package/node_modules/@engenty/model-setup/dist/server/clients.js +96 -0
  234. package/node_modules/@engenty/model-setup/dist/server/index.d.ts +8 -0
  235. package/node_modules/@engenty/model-setup/dist/server/index.js +8 -0
  236. package/node_modules/@engenty/model-setup/dist/server/install.d.ts +24 -0
  237. package/node_modules/@engenty/model-setup/dist/server/install.js +68 -0
  238. package/node_modules/@engenty/model-setup/dist/server/lmstudio.d.ts +9 -0
  239. package/node_modules/@engenty/model-setup/dist/server/lmstudio.js +52 -0
  240. package/node_modules/@engenty/model-setup/dist/server/local-models.d.ts +47 -0
  241. package/node_modules/@engenty/model-setup/dist/server/local-models.js +164 -0
  242. package/node_modules/@engenty/model-setup/dist/server/models.d.ts +12 -0
  243. package/node_modules/@engenty/model-setup/dist/server/models.js +16 -0
  244. package/node_modules/@engenty/model-setup/dist/server/ollama.d.ts +22 -0
  245. package/node_modules/@engenty/model-setup/dist/server/ollama.js +146 -0
  246. package/node_modules/@engenty/model-setup/dist/server/routes.d.ts +51 -0
  247. package/node_modules/@engenty/model-setup/dist/server/routes.js +211 -0
  248. package/node_modules/@engenty/model-setup/dist/server/server-apps.d.ts +14 -0
  249. package/node_modules/@engenty/model-setup/dist/server/server-apps.js +24 -0
  250. package/node_modules/@engenty/model-setup/dist/server/terminal.d.ts +43 -0
  251. package/node_modules/@engenty/model-setup/dist/server/terminal.js +222 -0
  252. package/node_modules/@engenty/model-setup/dist/texts.d.ts +222 -0
  253. package/node_modules/@engenty/model-setup/dist/texts.js +222 -0
  254. package/node_modules/@engenty/model-setup/dist/types.d.ts +111 -0
  255. package/node_modules/@engenty/model-setup/dist/types.js +2 -0
  256. package/node_modules/@engenty/model-setup/package.json +12 -0
  257. package/node_modules/@engenty/search-index/dist/catalog-lexical.d.ts +14 -0
  258. package/node_modules/@engenty/search-index/dist/catalog-lexical.js +165 -0
  259. package/node_modules/@engenty/search-index/dist/catalog-rank.d.ts +33 -0
  260. package/node_modules/@engenty/search-index/dist/catalog-rank.js +99 -0
  261. package/node_modules/@engenty/search-index/dist/catalog-search.d.ts +40 -0
  262. package/node_modules/@engenty/search-index/dist/catalog-search.js +161 -0
  263. package/node_modules/@engenty/search-index/dist/chunks.d.ts +17 -0
  264. package/node_modules/@engenty/search-index/dist/chunks.js +164 -0
  265. package/node_modules/@engenty/search-index/dist/contracts.d.ts +135 -0
  266. package/node_modules/@engenty/search-index/dist/contracts.js +9 -0
  267. package/node_modules/@engenty/search-index/dist/embedder.d.ts +31 -0
  268. package/node_modules/@engenty/search-index/dist/embedder.js +82 -0
  269. package/node_modules/@engenty/search-index/dist/embedders/gemini.d.ts +11 -0
  270. package/node_modules/@engenty/search-index/dist/embedders/gemini.js +54 -0
  271. package/node_modules/@engenty/search-index/dist/embedders/index.d.ts +5 -0
  272. package/node_modules/@engenty/search-index/dist/embedders/index.js +5 -0
  273. package/node_modules/@engenty/search-index/dist/embedders/ollama.d.ts +12 -0
  274. package/node_modules/@engenty/search-index/dist/embedders/ollama.js +43 -0
  275. package/node_modules/@engenty/search-index/dist/embedders/openai.d.ts +11 -0
  276. package/node_modules/@engenty/search-index/dist/embedders/openai.js +36 -0
  277. package/node_modules/@engenty/search-index/dist/embedders/shared.d.ts +5 -0
  278. package/node_modules/@engenty/search-index/dist/embedders/shared.js +26 -0
  279. package/node_modules/@engenty/search-index/dist/embedders/ways.d.ts +16 -0
  280. package/node_modules/@engenty/search-index/dist/embedders/ways.js +90 -0
  281. package/node_modules/@engenty/search-index/dist/index.d.ts +10 -0
  282. package/node_modules/@engenty/search-index/dist/index.js +10 -0
  283. package/node_modules/@engenty/search-index/dist/payload.d.ts +13 -0
  284. package/node_modules/@engenty/search-index/dist/payload.js +51 -0
  285. package/node_modules/@engenty/search-index/dist/registry.d.ts +25 -0
  286. package/node_modules/@engenty/search-index/dist/registry.js +56 -0
  287. package/node_modules/@engenty/search-index/dist/scoring.d.ts +10 -0
  288. package/node_modules/@engenty/search-index/dist/scoring.js +45 -0
  289. package/node_modules/@engenty/search-index/dist/strategy.d.ts +6 -0
  290. package/node_modules/@engenty/search-index/dist/strategy.js +25 -0
  291. package/node_modules/@engenty/search-index/package.json +10 -0
  292. package/node_modules/@engenty/tool-harness/dist/harness.d.ts +70 -0
  293. package/node_modules/@engenty/tool-harness/dist/harness.js +170 -0
  294. package/node_modules/@engenty/tool-harness/dist/index.d.ts +5 -0
  295. package/node_modules/@engenty/tool-harness/dist/index.js +5 -0
  296. package/node_modules/@engenty/tool-harness/dist/judge.d.ts +8 -0
  297. package/node_modules/@engenty/tool-harness/dist/judge.js +39 -0
  298. package/node_modules/@engenty/tool-harness/dist/levels.d.ts +18 -0
  299. package/node_modules/@engenty/tool-harness/dist/levels.js +47 -0
  300. package/node_modules/@engenty/tool-harness/dist/model.d.ts +6 -0
  301. package/node_modules/@engenty/tool-harness/dist/model.js +60 -0
  302. package/node_modules/@engenty/tool-harness/dist/schema.d.ts +26 -0
  303. package/node_modules/@engenty/tool-harness/dist/schema.js +57 -0
  304. package/node_modules/@engenty/tool-harness/package.json +9 -0
  305. package/node_modules/@engenty/wizards-shared/dist/catalog-prompt.js +2 -1
  306. package/node_modules/@engenty/wizards-shared/dist/definition.d.ts +10 -10
  307. package/node_modules/@engenty/wizards-shared/dist/definition.js +4 -4
  308. package/node_modules/@engenty/wizards-shared/dist/run-schema.js +1 -1
  309. package/node_modules/@engenty/wizards-shared/dist/run.d.ts +3 -1
  310. package/node_modules/@engenty/wizards-shared/dist/run.js +4 -0
  311. package/node_modules/@engenty/wizards-shared/dist/store.js +2 -1
  312. package/node_modules/@engenty/wizards-shared/dist/wizard-agents.d.ts +1 -1
  313. package/node_modules/@engenty/wizards-shared/dist/wizard-agents.js +1 -1
  314. package/node_modules/@engenty/wizards-shared/dist/wizard-text.js +2 -2
  315. package/package.json +13 -1
  316. package/plugin/.claude-plugin/plugin.json +1 -1
  317. package/plugin/plugin.json +1 -1
  318. package/apps/runtime/dist/agents/chat-clients.js +0 -344
  319. package/apps/runtime/dist/harness/claude.js +0 -141
  320. package/apps/runtime/dist/harness/codex.js +0 -222
  321. package/apps/runtime/dist/harness/cursor.js +0 -89
  322. package/apps/runtime/dist/harness/terminal.js +0 -201
  323. package/apps/web/dist/assets/AboutDialog-DM_2-iLP.js +0 -1
  324. package/apps/web/dist/assets/Bundle-C0u5HUZL.js +0 -1
  325. package/apps/web/dist/assets/CapabilitiesPage-DxRUERr-.js +0 -2
  326. package/apps/web/dist/assets/ChangelogDialog-Cyn3LAch.js +0 -1
  327. package/apps/web/dist/assets/ConnectorsSection-BYOrwccO.js +0 -1
  328. package/apps/web/dist/assets/EditorPage-BFUQzJpN.js +0 -3
  329. package/apps/web/dist/assets/FlowPreview-BXf4EKjU.js +0 -1
  330. package/apps/web/dist/assets/LangSwitch-BLB7dDce.js +0 -1
  331. package/apps/web/dist/assets/Marketplace-B3NoH5Va.js +0 -2
  332. package/apps/web/dist/assets/NewWizardChannels-DhmYe2C8.js +0 -1
  333. package/apps/web/dist/assets/NewWizardPage-MGKJVDp2.js +0 -7
  334. package/apps/web/dist/assets/OnboardingPage-RawpCO9J.js +0 -1
  335. package/apps/web/dist/assets/ProtocolSection-B1MshkAx.js +0 -1
  336. package/apps/web/dist/assets/PublicRunner-COatyxMi.js +0 -1
  337. package/apps/web/dist/assets/Results-DI4EHtkh.js +0 -1
  338. package/apps/web/dist/assets/RunDrawer-xXcbQ9wP.js +0 -1
  339. package/apps/web/dist/assets/SettingsPage-BcqqYDqw.js +0 -2
  340. package/apps/web/dist/assets/SetupPage-DG3fJ6fk.js +0 -1
  341. package/apps/web/dist/assets/SharePage-Drntg_oj.js +0 -1
  342. package/apps/web/dist/assets/SkillEditor-Ca_bzmjD.js +0 -1
  343. package/apps/web/dist/assets/Skills-BcgxuD15.js +0 -9
  344. package/apps/web/dist/assets/SpacePage-CzQAEQj8.js +0 -2
  345. package/apps/web/dist/assets/StudioHome-DWTDTslp.js +0 -1
  346. package/apps/web/dist/assets/TableEditor-DirMDIGk.js +0 -7
  347. package/apps/web/dist/assets/UpdateCheck-C6GlE6Am.js +0 -2
  348. package/apps/web/dist/assets/brand-BIT7AumL.js +0 -2
  349. package/apps/web/dist/assets/changelog-CMovB3yB.js +0 -1
  350. package/apps/web/dist/assets/code-editor-CufyaUFC.js +0 -2
  351. package/apps/web/dist/assets/host-DNvnJXoi.js +0 -69
  352. package/apps/web/dist/assets/i18n-WXeVnv7i.js +0 -55
  353. package/apps/web/dist/assets/index-D1iL3986.css +0 -1
  354. package/apps/web/dist/assets/index-DOq0CvXM.js +0 -102
  355. package/apps/web/dist/assets/oss-credits-C4SGbRkz.js +0 -1
  356. package/apps/web/dist/assets/theme-23bNrOQh.js +0 -14
  357. package/apps/web/dist/assets/ui-DkEhb2Rt.js +0 -16
  358. package/apps/web/dist/assets/viewers-CmGDpBjn.js +0 -2
  359. /package/apps/web/dist/assets/{host-BrP-ENHg.css → terminal-BrP-ENHg.css} +0 -0
  360. /package/node_modules/@engenty/{wizards-shared → chatviews}/dist/calc.d.ts +0 -0
  361. /package/node_modules/@engenty/{wizards-shared → chatviews}/dist/numbers.d.ts +0 -0
  362. /package/node_modules/@engenty/{wizards-shared → chatviews}/dist/shape.d.ts +0 -0
  363. /package/node_modules/@engenty/{wizards-shared → chatviews}/dist/surface.d.ts +0 -0
@@ -1,192 +1,68 @@
1
- import { totalmem } from "node:os";
2
- import { ollamaRoot } from "./decision-model.js";
1
+ import { SERVERS, serversHere } from "@engenty/local-models/servers";
2
+ import { MODEL_JOBS, OFFERED_MODELS } from "@engenty/model-setup";
3
+ import { LocalModels } from "@engenty/model-setup/server";
4
+ import { layout } from "./cli/home.js";
3
5
  import { env } from "./env.js";
4
- import { forgetLocalModels, localOllamaUrl } from "./models.js";
6
+ import { embeddingModel, forgetLocalModels, localServerUrl } from "./models.js";
5
7
  /**
6
- * The models in Ollama on this computer, for Settings › Models: what is there and what each can
7
- * do (Ollama's own `capabilities`), the models the Manage-App offers per job (`GET
8
- * /v1/local-models` of the account's Manage-App), and the downloads and removals the studio
9
- * starts. Text, search and decisions each pick their model from it.
8
+ * The servers for open models on this computer (@engenty/model-setup). Ollama's models come with
9
+ * the ones the Manage-App offers per job (`GET /v1/local-models` of the account's Manage-App):
10
+ * text, search and decisions each pick their model from it. LM Studio's and MLX's are for text.
10
11
  */
11
- /** What a model does in the studio: a text class, the search of a space's knowledge, decisions. */
12
- export const LOCAL_JOBS = ["text", "search", "decision"];
13
12
  /** The share of the computer's memory a model may take and still leave room for the rest. */
14
13
  const MEMORY_SHARE = 0.7;
15
- /** The job a capability of Ollama's serves. */
16
- const JOB_OF = {
17
- completion: "text",
18
- embedding: "search",
19
- decision: "decision",
20
- };
21
- const gb = (bytes) => Math.round((bytes / 1e9) * 10) / 10;
22
- async function getJson(url, init, timeoutMs = 2000) {
23
- try {
24
- const res = await fetch(url, { ...init, signal: AbortSignal.timeout(timeoutMs) });
25
- return res.ok ? (await res.json()) : null;
26
- }
27
- catch {
28
- return null;
29
- }
30
- }
31
- /** What `/api/show` said about a model, by its digest: it does not change while the digest stays. */
32
- const shown = new Map();
33
- async function installedModels(root) {
34
- const [tags, ps] = await Promise.all([
35
- getJson(`${root}/api/tags`),
36
- getJson(`${root}/api/ps`),
37
- ]);
38
- const loaded = new Set((ps?.models ?? []).map((m) => m.name));
39
- return Promise.all((tags?.models ?? []).map(async (m) => {
40
- let show = shown.get(m.digest);
41
- if (!show) {
42
- show =
43
- (await getJson(`${root}/api/show`, {
44
- method: "POST",
45
- headers: { "content-type": "application/json" },
46
- body: JSON.stringify({ model: m.name }),
47
- }, 5000)) ?? {};
48
- shown.set(m.digest, show);
49
- }
50
- const capabilities = show.capabilities ?? [];
51
- return {
52
- name: m.name,
53
- size: gb(m.size),
54
- jobs: LOCAL_JOBS.filter((job) => capabilities.some((c) => JOB_OF[c] === job)),
55
- capabilities,
56
- runner: show.details?.runner || null,
57
- quantization: show.details?.quantization_level || null,
58
- loaded: loaded.has(m.name),
59
- };
60
- }));
61
- }
62
14
  /** The Manage-App's list at the last look: kept for an hour, asked again after five minutes when it did not answer. */
63
15
  let offered = null;
64
16
  async function offeredModels() {
65
17
  if (offered && Date.now() < offered.at) {
66
18
  return offered.models;
67
19
  }
68
- const body = await getJson(`${env.local.accountUrl}/v1/local-models`, undefined, 3000);
69
- const models = body?.models?.filter((m) => LOCAL_JOBS.includes(m.job)) ?? null;
70
- offered = { models, at: Date.now() + (models ? 60 : 5) * 60_000 };
71
- return models;
72
- }
73
- const downloads = new Map();
74
- /** While Ollama is being installed or started from the studio, and how that ended. */
75
- let ollamaStart = null;
76
- /** Ollama on this computer, its models and the ones to download, for the settings page. */
77
- export async function localModels() {
78
- const url = await localOllamaUrl();
79
- const root = ollamaRoot(url);
80
- const { findOllama, freeGb } = await import("./cli/ollama.js");
81
- const version = (await getJson(`${root}/api/version`))?.version ?? null;
82
- const memory = Math.round(totalmem() / 2 ** 30);
83
- const installed = version ? await installedModels(root) : [];
84
- const held = new Set(installed.map((m) => m.name));
85
- const list = await offeredModels();
86
- return {
87
- ollama: {
88
- url,
89
- /** Null: Ollama does not answer at the address. */
90
- version,
91
- /** The `ollama` command is on this computer, though it may not run. */
92
- installed: Boolean(version || findOllama()),
93
- /** The studio can install Ollama itself: on a Mac, as the setup does. */
94
- canInstall: process.platform === "darwin",
95
- start: ollamaStart,
96
- },
97
- /** The computer's memory and the free space for models, in GB. */
98
- memory,
99
- free: await freeGb(),
100
- installed,
101
- /** Null: the Manage-App did not answer, the list shows the installed models alone. */
102
- offered: list?.map((m) => ({
103
- ...m,
104
- installed: held.has(m.name) || held.has(`${m.name}:latest`),
105
- fits: m.memory <= memory * MEMORY_SHARE,
106
- })) ?? null,
107
- downloads: [...downloads.values()],
108
- };
109
- }
110
- /**
111
- * Pulls a model into Ollama in the background; `then` runs once it ended well. A download of
112
- * the same model that runs already is left to finish.
113
- */
114
- export async function downloadLocalModel(model, then) {
115
- const running = downloads.get(model);
116
- if (running && !running.finished) {
117
- return;
20
+ let models = null;
21
+ try {
22
+ const res = await fetch(`${env.local.accountUrl}/v1/local-models`, {
23
+ signal: AbortSignal.timeout(3000),
24
+ });
25
+ const body = res.ok ? (await res.json()) : null;
26
+ models = body?.models?.filter((m) => MODEL_JOBS.includes(m.job)) ?? null;
118
27
  }
119
- const state = { model, done: 0, total: 0, error: null, finished: false };
120
- downloads.set(model, state);
121
- const { pullModel } = await import("./cli/ollama.js");
122
- void pullModel(model, (done, total) => {
123
- state.done = done;
124
- state.total = total;
125
- }, { OLLAMA_URL: await localOllamaUrl() })
126
- .then(async () => {
127
- forgetLocalModels();
128
- state.finished = true;
129
- // A finished download is done; the list shows the model itself now.
130
- downloads.delete(model);
131
- await then?.();
132
- })
133
- .catch((err) => {
134
- const unreachable = /fetch failed|ECONNREFUSED/i.test(`${err.message} ${err.cause ?? ""}`);
135
- state.error = unreachable ? "ollama" : err.message;
136
- state.finished = true;
137
- });
138
- }
139
- /** Removes a model from Ollama, and a download of it that failed; Ollama's reason where it refuses. */
140
- export async function removeLocalModel(model) {
141
- downloads.delete(model);
142
- forgetLocalModels();
143
- const res = await fetch(`${ollamaRoot(await localOllamaUrl())}/api/delete`, {
144
- method: "DELETE",
145
- headers: { "content-type": "application/json" },
146
- body: JSON.stringify({ model }),
147
- signal: AbortSignal.timeout(10_000),
148
- });
149
- if (!res.ok) {
150
- const text = (await res.text()).trim();
151
- let reason = text;
152
- try {
153
- reason = JSON.parse(text).error ?? text;
154
- }
155
- catch { }
156
- throw new Error(reason || `Ollama answered ${res.status}.`);
28
+ catch {
29
+ // Asked again in five minutes.
157
30
  }
31
+ offered = { models, at: Date.now() + (models ? 60 : 5) * 60_000 };
32
+ return models;
158
33
  }
159
- /**
160
- * Installs Ollama where it is missing (on a Mac) and starts it, as `wizards setup` does, in the
161
- * background; the settings page follows `ollama.start`.
162
- */
163
- export async function startLocalOllama() {
164
- if (ollamaStart?.running) {
165
- return;
166
- }
167
- const state = { running: true, error: null };
168
- ollamaStart = state;
169
- const { findOllama, installOllama, startOllama } = await import("./cli/ollama.js");
170
- const { layout } = await import("./cli/home.js");
171
- const paths = layout();
172
- void (async () => {
173
- let path = findOllama();
174
- if (!path) {
175
- const outcome = await installOllama(paths, () => undefined);
176
- if (!outcome.ok) {
177
- throw new Error(outcome.message);
34
+ /** The model the spaces are indexed with now. */
35
+ const embeddedBy = async () => (await embeddingModel().catch(() => null))?.ref ?? null;
36
+ const ollama = new LocalModels({
37
+ server: SERVERS.ollama,
38
+ url: () => localServerUrl("ollama"),
39
+ offered: offeredModels,
40
+ share: MEMORY_SHARE,
41
+ logs: () => layout().logs,
42
+ changed: forgetLocalModels,
43
+ // Where the pulled model is the embedding model now, the spaces are indexed with it after.
44
+ async pulling() {
45
+ const before = await embeddedBy();
46
+ return async () => {
47
+ if ((await embeddedBy()) !== before) {
48
+ const { reindexAll } = await import("./services/space-index.js");
49
+ await reindexAll();
178
50
  }
179
- path = findOllama();
180
- }
181
- if (!(await startOllama(path, paths))) {
182
- throw new Error("Ollama isn’t answering.");
183
- }
184
- forgetLocalModels();
185
- })()
186
- .catch((err) => {
187
- state.error = err.message;
188
- })
189
- .finally(() => {
190
- state.running = false;
191
- });
192
- }
51
+ };
52
+ },
53
+ });
54
+ const lmStudio = new LocalModels({
55
+ server: SERVERS.lmstudio,
56
+ url: () => localServerUrl("lmstudio"),
57
+ offered: () => OFFERED_MODELS.lmstudio,
58
+ share: MEMORY_SHARE,
59
+ logs: () => layout().logs,
60
+ });
61
+ const mlx = new LocalModels({
62
+ server: SERVERS.mlx,
63
+ url: () => localServerUrl("mlx"),
64
+ offered: () => OFFERED_MODELS.mlx,
65
+ share: MEMORY_SHARE,
66
+ logs: () => layout().logs,
67
+ });
68
+ export const localServers = [ollama, lmStudio, mlx].filter((server) => serversHere().includes(server.id));
@@ -1,59 +1,16 @@
1
- import { AsyncLocalStorage } from "node:async_hooks";
2
- import { randomBytes } from "node:crypto";
3
- import { createMcpHandler, fromJsonSchema, McpServer, } from "@modelcontextprotocol/server";
1
+ import { Bridges } from "@engenty/local-models/bridge";
4
2
  import { env } from "../env.js";
5
- const bridges = new Map();
6
- const textOf = (value) => typeof value === "string" ? value : JSON.stringify(value ?? null);
7
- /** A tool's result as MCP content: text, or the blocks its `toModelOutput` shapes (text and images). */
8
- function contentOf(tool, output) {
9
- const shaped = tool.toModelOutput?.(output);
10
- if (shaped?.type === "content") {
11
- return {
12
- content: shaped.value.map((part) => part.type === "image-data"
13
- ? { type: "image", data: part.data ?? "", mimeType: part.mediaType ?? "image/png" }
14
- : { type: "text", text: part.text ?? textOf(part) }),
15
- };
16
- }
17
- return { content: [{ type: "text", text: textOf(shaped ? shaped.value : output) }] };
18
- }
19
- export function openBridge(tools) {
20
- const token = randomBytes(24).toString("base64url");
21
- // The client's requests arrive on their own; the tools run as the call that opened the bridge —
22
- // in its tenant, as its person.
23
- const inCall = AsyncLocalStorage.snapshot();
24
- const handler = createMcpHandler(() => {
25
- const server = new McpServer({ name: "step", version: "0.1.0" }, { capabilities: { tools: {} } });
26
- for (const tool of tools) {
27
- server.registerTool(tool.name, {
28
- description: tool.description,
29
- inputSchema: fromJsonSchema(tool.inputSchema),
30
- }, (async (args) => {
31
- try {
32
- return contentOf(tool, await inCall(() => tool.execute(args)));
33
- }
34
- catch (err) {
35
- return {
36
- isError: true,
37
- content: [{ type: "text", text: err?.message ?? String(err) }],
38
- };
39
- }
40
- }));
41
- }
42
- return server;
43
- }, { legacy: "stateless" });
44
- bridges.set(token, handler);
45
- return {
46
- url: `http://127.0.0.1:${env.port}/api/mcp/bridge/${token}`,
47
- close: () => {
48
- bridges.delete(token);
49
- },
50
- };
51
- }
3
+ /**
4
+ * The tools of one model call, served over MCP to the AI client installed on this machine while
5
+ * it answers that call (@engenty/local-models/bridge). A bridge lives as long as the call: it
6
+ * opens with it, is reached through a random path on the loopback address, and closes with it.
7
+ * Nothing but this process knows the path; the client works through the tools itself and comes
8
+ * back with the answer.
9
+ */
10
+ const bridges = new Bridges({ name: "step" });
11
+ /** Opens a call's tools; the client reaches them at the URL until `close`. */
12
+ export const openBridge = (tools) => bridges.at(`http://127.0.0.1:${env.port}/api/mcp/bridge`)(tools);
52
13
  /** Answers an MCP request of an open bridge; a closed or unknown one is not found. */
53
14
  export function bridgeRequest(token, request) {
54
- const handler = bridges.get(token);
55
- if (!handler) {
56
- return Promise.resolve(new Response("not found", { status: 404 }));
57
- }
58
- return handler.fetch(request);
15
+ return bridges.fetch(request, token);
59
16
  }
@@ -3,6 +3,8 @@ import { callOutside, RUN_COMMAND } from "../elements/outside.js";
3
3
  import { ELEMENT_SPECS, ELEMENT_TOOL_NAMES } from "../elements/specs.js";
4
4
  import { prompt } from "../prompts.js";
5
5
  import { listSpaces, spaceIs } from "../services/spaces.js";
6
+ import { FLOW_VIEW_KEY, flowAppMeta, flowView } from "./flow-app.js";
7
+ import { withPages } from "./run-pages.js";
6
8
  /**
7
9
  * The space's elements as MCP tools (docs/plans/modular.md, phase 2): what a Work chat uses,
8
10
  * for Claude Code, Codex or any MCP client signed in as a person. Made from the catalogue's specs
@@ -26,7 +28,29 @@ const READ_ONLY = new Set([
26
28
  "connection_list",
27
29
  "wizard_list",
28
30
  ]);
29
- function answer(result) {
31
+ /**
32
+ * A run `wizard_run` started, with the flow widget's data: hosts that render MCP Apps show the
33
+ * run and the person answers its pages there. Without a view (a wizard the person can't open
34
+ * as a diagram) the run comes back as text alone.
35
+ */
36
+ export async function withFlow(userId, answered, result) {
37
+ const report = result;
38
+ if (answered.isError || !report?.runId || !report.wizardId) {
39
+ return answered;
40
+ }
41
+ try {
42
+ const view = await flowView(userId, report.wizardId, { run: report });
43
+ return {
44
+ ...answered,
45
+ structuredContent: report,
46
+ _meta: { [FLOW_VIEW_KEY]: view },
47
+ };
48
+ }
49
+ catch {
50
+ return answered;
51
+ }
52
+ }
53
+ export function answer(result) {
30
54
  const body = result.ok
31
55
  ? result.result
32
56
  : { error: result.error, ...(result.data ? { data: result.data } : {}) };
@@ -48,10 +72,13 @@ export function registerElementTools(server, who) {
48
72
  return;
49
73
  }
50
74
  const withSpace = input.extend({ spaceId });
75
+ const runs = name === "wizard_run";
51
76
  server.registerTool(name, {
52
77
  title: name.replace(/_/g, " "),
53
- description,
78
+ // Over MCP the client answers the run's pages itself, with the run tools (mcp/runs.ts).
79
+ description: runs ? prompt("mcp", "tool.wizard_run") : description,
54
80
  inputSchema: withSpace,
81
+ ...(runs ? { _meta: flowAppMeta } : {}),
55
82
  annotations: {
56
83
  readOnlyHint: READ_ONLY.has(name),
57
84
  // A connection's action may write, send or delete in a connected account.
@@ -59,9 +86,17 @@ export function registerElementTools(server, who) {
59
86
  // Running a wizard or a command reaches past the person's own data.
60
87
  openWorldHint: !READ_ONLY.has(name),
61
88
  },
62
- }, (async (args) => {
89
+ }, (async (args, ctx) => {
63
90
  const { spaceId: space, ...rest } = args;
64
- return answer(await callOutside(outside, typeof space === "string" ? space : undefined, name, rest, AbortSignal.timeout(10 * 60_000)));
91
+ const call = () => callOutside(outside, typeof space === "string" ? space : undefined, name, rest, AbortSignal.timeout(10 * 60_000));
92
+ if (!runs) {
93
+ return answer(await call());
94
+ }
95
+ // The run's pages go to the person where the client asks them, then the run's report.
96
+ return withPages(ctx, who, async () => {
97
+ const result = await call();
98
+ return result.ok ? result.result : { failed: answer(result) };
99
+ }, (report) => withFlow(who.userId, answer({ ok: true, result: report }), report));
65
100
  }));
66
101
  };
67
102
  for (const name of ELEMENT_TOOL_NAMES) {
@@ -11,6 +11,9 @@ import { serverText } from "../texts.js";
11
11
  import { authenticate, principalOf } from "./auth.js";
12
12
  import { registerElementTools } from "./elements.js";
13
13
  import { registerFlowApp } from "./flow-app.js";
14
+ import { requestStateVerify } from "./run-pages.js";
15
+ import { runTaskRequest } from "./run-tasks.js";
16
+ import { registerRunTools } from "./runs.js";
14
17
  import { appKind, clientNameOf, noteChecked, noteRequest } from "./seen.js";
15
18
  import { registerPrompts, registerTools } from "./tools.js";
16
19
  /**
@@ -73,10 +76,13 @@ export function mcpHandler() {
73
76
  const server = new McpServer({ name: "engenty-wizards", version: "0.1.0" }, {
74
77
  instructions: prompt("mcp", "instructions"),
75
78
  capabilities: { tools: {}, prompts: {}, resources: {} },
79
+ // A run's page asked of the person comes back with its sealed state (mcp/run-pages.ts).
80
+ requestState: { verify: requestStateVerify },
76
81
  });
77
82
  const who = principalOf(ctx.authInfo);
78
83
  registerTools(server, who);
79
84
  registerElementTools(server, who);
85
+ registerRunTools(server, who);
80
86
  registerPrompts(server);
81
87
  registerFlowApp(server);
82
88
  return server;
@@ -104,6 +110,12 @@ export function mcpHandler() {
104
110
  if (refused) {
105
111
  return refused;
106
112
  }
113
+ // Runs followed as tasks: the SDK has no runtime for the Tasks extension (mcp/run-tasks.ts).
114
+ const tasked = await withTenant(who.tenantId, () => asRole(who.role, () => runTaskRequest(who, body)));
115
+ if (tasked) {
116
+ nudge(who.tenantId);
117
+ return tasked;
118
+ }
107
119
  }
108
120
  const answer = await withTenant(who.tenantId, () => asRole(who.role, () => handler.fetch(request, { authInfo })));
109
121
  if (request.method === "POST") {
@@ -0,0 +1,238 @@
1
+ import { createHmac } from "node:crypto";
2
+ import { createRequestStateCodec, inputRequired, inputResponse, } from "@modelcontextprotocol/server";
3
+ import { env } from "../env.js";
4
+ import { ServiceError } from "../services/errors.js";
5
+ import { answerRunAsk, answerRunForm, answerRunQuestion, reviewRun, runReport, } from "../services/runs.js";
6
+ const PAGE = "page";
7
+ /** How long an answered page waits for the run to reach its next page. */
8
+ const AFTER_ANSWER_SECONDS = 20;
9
+ /** A page waits this long for the person; the run itself waits on. */
10
+ const PAGE_TTL_SECONDS = 60 * 60;
11
+ /** As many fields as a form question may have before the run page takes over. */
12
+ const MAX_FIELDS = 12;
13
+ const CLIENT_CAPABILITIES = "io.modelcontextprotocol/clientCapabilities";
14
+ const codec = createRequestStateCodec({
15
+ key: createHmac("sha256", env.authSecret).update("mcp.run-pages").digest(),
16
+ ttlSeconds: PAGE_TTL_SECONDS,
17
+ // A page's state is the person's own: it does not work for another token's person.
18
+ bind: (ctx) => {
19
+ const who = ctx.http?.authInfo?.extra;
20
+ return `${who?.tenantId ?? ""}\n${who?.userId ?? ""}`;
21
+ },
22
+ });
23
+ /** For the server's options: checks a page's state when it comes back. */
24
+ export const requestStateVerify = codec.verify;
25
+ /** The client shows forms the server asks for, on this request. */
26
+ export function asksPages(ctx) {
27
+ const envelope = ctx.mcpReq.envelope;
28
+ const caps = envelope?.[CLIENT_CAPABILITIES];
29
+ const elicitation = caps?.elicitation;
30
+ // An empty `elicitation` capability means forms (the url mode is declared on its own).
31
+ return Boolean(elicitation && (elicitation.form || Object.keys(elicitation).length === 0));
32
+ }
33
+ /** A form field as an elicitation property, or nothing when only the run page can ask it. */
34
+ function propertyOf(field) {
35
+ const base = { title: field.label, ...(field.help ? { description: field.help } : {}) };
36
+ switch (field.kind) {
37
+ case "text":
38
+ case "textarea":
39
+ return { type: "string", ...base };
40
+ case "email":
41
+ return { type: "string", format: "email", ...base };
42
+ case "url":
43
+ return { type: "string", format: "uri", ...base };
44
+ case "date":
45
+ return { type: "string", format: "date", ...base };
46
+ case "number":
47
+ return { type: "number", ...base };
48
+ case "toggle":
49
+ return { type: "boolean", ...base };
50
+ case "select":
51
+ return field.options?.length ? { type: "string", enum: field.options, ...base } : null;
52
+ case "slot":
53
+ return field.times?.length
54
+ ? {
55
+ type: "string",
56
+ oneOf: field.times.map((t) => ({ const: t.value, title: t.label })),
57
+ ...base,
58
+ }
59
+ : null;
60
+ case "multiselect":
61
+ return field.options?.length
62
+ ? { type: "array", items: { type: "string", enum: field.options }, ...base }
63
+ : null;
64
+ default:
65
+ return null;
66
+ }
67
+ }
68
+ /** The run page in the person's browser, for what a form question cannot ask. */
69
+ function onThePage(report, title) {
70
+ return report.browserUrl
71
+ ? inputRequired.elicitUrl({ message: title, url: report.browserUrl })
72
+ : null;
73
+ }
74
+ /** What the person is asked for the page the run waits on; nothing when it waits on no one. */
75
+ export function pageOf(report) {
76
+ const w = report.waitingFor;
77
+ if (!w) {
78
+ return null;
79
+ }
80
+ const runId = report.runId;
81
+ if (w.question) {
82
+ return {
83
+ state: { runId, kind: "question", id: report.step?.id ?? "" },
84
+ request: inputRequired.elicit({
85
+ message: w.question,
86
+ requestedSchema: {
87
+ type: "object",
88
+ properties: { answer: { type: "string", title: w.title ?? "Answer" } },
89
+ required: ["answer"],
90
+ },
91
+ }),
92
+ };
93
+ }
94
+ if (w.ask && w.kind === "confirm") {
95
+ const what = [w.reason, w.service && w.action ? `${w.service}: ${w.action}` : "", w.input]
96
+ .filter(Boolean)
97
+ .join("\n\n");
98
+ return {
99
+ state: { runId, kind: "ask", id: w.ask },
100
+ request: inputRequired.elicit({
101
+ message: what,
102
+ requestedSchema: {
103
+ type: "object",
104
+ properties: {
105
+ answer: {
106
+ type: "string",
107
+ title: "Allow this?",
108
+ oneOf: [
109
+ { const: "allow", title: "Allow" },
110
+ { const: "skip", title: "Skip" },
111
+ ],
112
+ },
113
+ },
114
+ required: ["answer"],
115
+ },
116
+ }),
117
+ };
118
+ }
119
+ if (w.ask) {
120
+ const request = onThePage(report, w.reason ?? w.title ?? report.step?.title ?? "");
121
+ return request ? { state: { runId, kind: "page", id: w.ask }, request } : null;
122
+ }
123
+ if (w.review) {
124
+ const outputs = report.outputs
125
+ .map((o) => (o.text ? `${o.title}\n${o.text}` : o.title))
126
+ .join("\n\n");
127
+ return {
128
+ state: { runId, kind: "review", id: w.review },
129
+ request: inputRequired.elicit({
130
+ message: [w.title, outputs].filter(Boolean).join("\n\n"),
131
+ requestedSchema: {
132
+ type: "object",
133
+ properties: {
134
+ decision: {
135
+ type: "string",
136
+ title: w.title ?? "Review",
137
+ oneOf: [
138
+ { const: "accept", title: "Accept" },
139
+ ...(w.approve ? [{ const: "decline", title: "Decline" }] : []),
140
+ ],
141
+ },
142
+ note: { type: "string", title: "Note" },
143
+ },
144
+ required: ["decision"],
145
+ },
146
+ }),
147
+ };
148
+ }
149
+ if (w.form && w.fields) {
150
+ const title = w.title ?? report.step?.title ?? "";
151
+ const fields = w.fields;
152
+ const properties = fields.map((f) => [f.id, f.inChat && !f.when ? propertyOf(f) : null]);
153
+ // A page with a field only the run page asks, or fields that depend on each other, goes
154
+ // whole to the run page.
155
+ if (fields.length > MAX_FIELDS || properties.some(([, p]) => p === null)) {
156
+ const request = onThePage(report, title);
157
+ return request ? { state: { runId, kind: "page", id: w.form }, request } : null;
158
+ }
159
+ return {
160
+ state: { runId, kind: "form", id: w.form },
161
+ request: inputRequired.elicit({
162
+ message: title,
163
+ requestedSchema: {
164
+ type: "object",
165
+ properties: Object.fromEntries(properties),
166
+ required: fields.filter((f) => f.required).map((f) => f.id),
167
+ },
168
+ }),
169
+ };
170
+ }
171
+ return null;
172
+ }
173
+ /** Puts the person's answer into the run. Answered elsewhere meanwhile: nothing to do. */
174
+ export async function answerPage(userId, state, content) {
175
+ try {
176
+ if (state.kind === "form") {
177
+ await answerRunForm(userId, state.runId, state.id, content);
178
+ }
179
+ else if (state.kind === "question") {
180
+ await answerRunQuestion(userId, state.runId, String(content.answer ?? ""));
181
+ }
182
+ else if (state.kind === "ask") {
183
+ await answerRunAsk(userId, state.runId, state.id, content.answer === "allow" ? "allow" : "skip");
184
+ }
185
+ else if (state.kind === "review") {
186
+ const note = typeof content.note === "string" && content.note ? content.note : undefined;
187
+ await reviewRun(userId, state.runId, state.id, content.decision === "decline" ? { type: "decline", note } : { type: "accept", note });
188
+ }
189
+ }
190
+ catch (err) {
191
+ const now = await runReport(userId, state.runId);
192
+ const still = pageOf(now)?.state;
193
+ // The page was answered on the run page or in the widget: the run went on without this.
194
+ if (!(err instanceof ServiceError) || (still?.kind === state.kind && still.id === state.id)) {
195
+ throw err;
196
+ }
197
+ }
198
+ }
199
+ /**
200
+ * Runs a run tool with its pages asked of the person. `start` is what the tool does on its first
201
+ * call (start the run, answer a page) and gives the run's report; `finish` turns the report into
202
+ * the tool's answer once the run waits on no one the client can ask.
203
+ */
204
+ export async function withPages(ctx, who, start, finish) {
205
+ if (!asksPages(ctx)) {
206
+ const first = await start();
207
+ return "failed" in first ? first.failed : finish(first);
208
+ }
209
+ const state = ctx.mcpReq.requestState();
210
+ let report;
211
+ if (state) {
212
+ const answer = inputResponse(ctx.mcpReq.inputResponses, PAGE);
213
+ if (answer.kind === "elicit" && answer.action !== "accept") {
214
+ // The person put the page off or said no: the run waits, the client hears it.
215
+ const now = await runReport(who.userId, state.runId);
216
+ return finish({ ...now, unanswered: true });
217
+ }
218
+ if (answer.kind === "elicit" && state.kind !== "page") {
219
+ await answerPage(who.userId, state, answer.content ?? {});
220
+ }
221
+ report = await runReport(who.userId, state.runId, AFTER_ANSWER_SECONDS);
222
+ }
223
+ else {
224
+ const first = await start();
225
+ if ("failed" in first) {
226
+ return first.failed;
227
+ }
228
+ report = first;
229
+ }
230
+ const page = pageOf(report);
231
+ if (!page) {
232
+ return finish(report);
233
+ }
234
+ return inputRequired({
235
+ inputRequests: { [PAGE]: page.request },
236
+ requestState: await codec.mint(page.state, ctx),
237
+ });
238
+ }