wizards 0.7.3 → 0.7.5

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 (517) hide show
  1. package/README.md +4 -4
  2. package/bin/wizards.mjs +95 -26
  3. package/{apps/web/dist/install.sh → install.sh} +23 -5
  4. package/package.json +2 -58
  5. package/apps/runtime/dist/agents/architect.js +0 -444
  6. package/apps/runtime/dist/agents/studio-assistant.js +0 -883
  7. package/apps/runtime/dist/agents/subscription.js +0 -207
  8. package/apps/runtime/dist/agents/thought.js +0 -21
  9. package/apps/runtime/dist/agents/website.js +0 -480
  10. package/apps/runtime/dist/app.js +0 -359
  11. package/apps/runtime/dist/apple/wizards-apple +0 -0
  12. package/apps/runtime/dist/assistant/browser.js +0 -26
  13. package/apps/runtime/dist/assistant/docs.js +0 -158
  14. package/apps/runtime/dist/assistant/knows.js +0 -353
  15. package/apps/runtime/dist/assistant/primer.js +0 -26
  16. package/apps/runtime/dist/assistant/runs.js +0 -24
  17. package/apps/runtime/dist/auth/account.js +0 -175
  18. package/apps/runtime/dist/auth/device.js +0 -112
  19. package/apps/runtime/dist/auth/index.js +0 -358
  20. package/apps/runtime/dist/auth/keys.js +0 -55
  21. package/apps/runtime/dist/auth/local-ticket.js +0 -26
  22. package/apps/runtime/dist/authoring/example.js +0 -74
  23. package/apps/runtime/dist/authoring/guide.js +0 -433
  24. package/apps/runtime/dist/authoring/ops.js +0 -117
  25. package/apps/runtime/dist/browser/fast/action-space.js +0 -160
  26. package/apps/runtime/dist/browser/fast/classifier.js +0 -91
  27. package/apps/runtime/dist/browser/fast/decide.js +0 -171
  28. package/apps/runtime/dist/browser/fast/driver.js +0 -141
  29. package/apps/runtime/dist/browser/fast/instructions.js +0 -33
  30. package/apps/runtime/dist/browser/fast/run.js +0 -249
  31. package/apps/runtime/dist/browser/fast/span-picker.js +0 -153
  32. package/apps/runtime/dist/browser/fast/text-helper.js +0 -178
  33. package/apps/runtime/dist/browser/snapshot.js +0 -335
  34. package/apps/runtime/dist/cli/account.js +0 -385
  35. package/apps/runtime/dist/cli/autostart.js +0 -182
  36. package/apps/runtime/dist/cli/autoupdate.js +0 -221
  37. package/apps/runtime/dist/cli/clients.js +0 -44
  38. package/apps/runtime/dist/cli/connect.js +0 -539
  39. package/apps/runtime/dist/cli/environment.js +0 -93
  40. package/apps/runtime/dist/cli/exec.js +0 -45
  41. package/apps/runtime/dist/cli/features.js +0 -50
  42. package/apps/runtime/dist/cli/home.js +0 -88
  43. package/apps/runtime/dist/cli/install-env.js +0 -33
  44. package/apps/runtime/dist/cli/machine.js +0 -106
  45. package/apps/runtime/dist/cli/main.js +0 -222
  46. package/apps/runtime/dist/cli/mcp.js +0 -136
  47. package/apps/runtime/dist/cli/menu.js +0 -202
  48. package/apps/runtime/dist/cli/processes.js +0 -72
  49. package/apps/runtime/dist/cli/report.js +0 -66
  50. package/apps/runtime/dist/cli/setup.js +0 -335
  51. package/apps/runtime/dist/cli/start.js +0 -276
  52. package/apps/runtime/dist/cli/status.js +0 -203
  53. package/apps/runtime/dist/cli/ui.js +0 -59
  54. package/apps/runtime/dist/cli/uninstall-main.js +0 -20
  55. package/apps/runtime/dist/cli/uninstall.js +0 -231
  56. package/apps/runtime/dist/cli/update.js +0 -86
  57. package/apps/runtime/dist/cli/validate.js +0 -75
  58. package/apps/runtime/dist/cli/versions.js +0 -106
  59. package/apps/runtime/dist/connectors/builtin.js +0 -86
  60. package/apps/runtime/dist/connectors/external.js +0 -409
  61. package/apps/runtime/dist/connectors/gmail.js +0 -107
  62. package/apps/runtime/dist/connectors/imap.js +0 -261
  63. package/apps/runtime/dist/connectors/index.js +0 -325
  64. package/apps/runtime/dist/connectors/mail.js +0 -72
  65. package/apps/runtime/dist/connectors/outlook.js +0 -90
  66. package/apps/runtime/dist/connectors/plugin-connections.js +0 -343
  67. package/apps/runtime/dist/connectors/via-account.js +0 -65
  68. package/apps/runtime/dist/credits/credits.js +0 -100
  69. package/apps/runtime/dist/credits/estimate.js +0 -152
  70. package/apps/runtime/dist/db/adopt.js +0 -149
  71. package/apps/runtime/dist/db/client.js +0 -173
  72. package/apps/runtime/dist/db/control-schema.js +0 -133
  73. package/apps/runtime/dist/db/migrations/control/0000_last_absorbing_man.sql +0 -47
  74. package/apps/runtime/dist/db/migrations/control/0001_gorgeous_nicolaos.sql +0 -41
  75. package/apps/runtime/dist/db/migrations/control/0002_secret_penance.sql +0 -1
  76. package/apps/runtime/dist/db/migrations/control/0003_nasty_mordo.sql +0 -3
  77. package/apps/runtime/dist/db/migrations/control/0004_breezy_eddie_brock.sql +0 -6
  78. package/apps/runtime/dist/db/migrations/control/0005_chilly_oracle.sql +0 -1
  79. package/apps/runtime/dist/db/migrations/control/0006_sleepy_mojo.sql +0 -1
  80. package/apps/runtime/dist/db/migrations/control/0007_common_the_hand.sql +0 -15
  81. package/apps/runtime/dist/db/migrations/control/0008_runner.sql +0 -8
  82. package/apps/runtime/dist/db/migrations/control/0009_plugin_claim.sql +0 -9
  83. package/apps/runtime/dist/db/migrations/control/0010_tan_snowbird.sql +0 -6
  84. package/apps/runtime/dist/db/migrations/control/meta/0000_snapshot.json +0 -311
  85. package/apps/runtime/dist/db/migrations/control/meta/0001_snapshot.json +0 -599
  86. package/apps/runtime/dist/db/migrations/control/meta/0002_snapshot.json +0 -607
  87. package/apps/runtime/dist/db/migrations/control/meta/0003_snapshot.json +0 -311
  88. package/apps/runtime/dist/db/migrations/control/meta/0004_snapshot.json +0 -350
  89. package/apps/runtime/dist/db/migrations/control/meta/0005_snapshot.json +0 -358
  90. package/apps/runtime/dist/db/migrations/control/meta/0006_snapshot.json +0 -365
  91. package/apps/runtime/dist/db/migrations/control/meta/0007_snapshot.json +0 -460
  92. package/apps/runtime/dist/db/migrations/control/meta/0008_snapshot.json +0 -505
  93. package/apps/runtime/dist/db/migrations/control/meta/0009_snapshot.json +0 -561
  94. package/apps/runtime/dist/db/migrations/control/meta/0010_snapshot.json +0 -600
  95. package/apps/runtime/dist/db/migrations/control/meta/_journal.json +0 -83
  96. package/apps/runtime/dist/db/migrations/tenant/0000_eminent_freak.sql +0 -188
  97. package/apps/runtime/dist/db/migrations/tenant/0001_salty_master_chief.sql +0 -1
  98. package/apps/runtime/dist/db/migrations/tenant/0002_cloudy_firebird.sql +0 -1
  99. package/apps/runtime/dist/db/migrations/tenant/0003_brown_warbound.sql +0 -52
  100. package/apps/runtime/dist/db/migrations/tenant/0004_romantic_nocturne.sql +0 -6
  101. package/apps/runtime/dist/db/migrations/tenant/0005_reflective_forgotten_one.sql +0 -2
  102. package/apps/runtime/dist/db/migrations/tenant/0006_hard_war_machine.sql +0 -30
  103. package/apps/runtime/dist/db/migrations/tenant/0007_space_data.sql +0 -43
  104. package/apps/runtime/dist/db/migrations/tenant/0008_run_event_note.sql +0 -1
  105. package/apps/runtime/dist/db/migrations/tenant/0009_knowledge.sql +0 -104
  106. package/apps/runtime/dist/db/migrations/tenant/0010_plugin_connection.sql +0 -15
  107. package/apps/runtime/dist/db/migrations/tenant/0011_runners.sql +0 -2
  108. package/apps/runtime/dist/db/migrations/tenant/0012_assistant_chat.sql +0 -40
  109. package/apps/runtime/dist/db/migrations/tenant/0013_run_origin.sql +0 -1
  110. package/apps/runtime/dist/db/migrations/tenant/0014_run_answer.sql +0 -2
  111. package/apps/runtime/dist/db/migrations/tenant/0015_device_calls.sql +0 -13
  112. package/apps/runtime/dist/db/migrations/tenant/0016_even_trish_tilby.sql +0 -12
  113. package/apps/runtime/dist/db/migrations/tenant/meta/0000_snapshot.json +0 -1323
  114. package/apps/runtime/dist/db/migrations/tenant/meta/0001_snapshot.json +0 -1330
  115. package/apps/runtime/dist/db/migrations/tenant/meta/0002_snapshot.json +0 -1337
  116. package/apps/runtime/dist/db/migrations/tenant/meta/0003_snapshot.json +0 -1605
  117. package/apps/runtime/dist/db/migrations/tenant/meta/0004_snapshot.json +0 -1645
  118. package/apps/runtime/dist/db/migrations/tenant/meta/0005_snapshot.json +0 -1659
  119. package/apps/runtime/dist/db/migrations/tenant/meta/0006_snapshot.json +0 -1696
  120. package/apps/runtime/dist/db/migrations/tenant/meta/0007_snapshot.json +0 -2012
  121. package/apps/runtime/dist/db/migrations/tenant/meta/0008_snapshot.json +0 -2019
  122. package/apps/runtime/dist/db/migrations/tenant/meta/0009_snapshot.json +0 -2837
  123. package/apps/runtime/dist/db/migrations/tenant/meta/0010_snapshot.json +0 -2942
  124. package/apps/runtime/dist/db/migrations/tenant/meta/0011_snapshot.json +0 -2956
  125. package/apps/runtime/dist/db/migrations/tenant/meta/0012_snapshot.json +0 -3132
  126. package/apps/runtime/dist/db/migrations/tenant/meta/0013_snapshot.json +0 -3139
  127. package/apps/runtime/dist/db/migrations/tenant/meta/0014_snapshot.json +0 -3154
  128. package/apps/runtime/dist/db/migrations/tenant/meta/0015_snapshot.json +0 -3243
  129. package/apps/runtime/dist/db/migrations/tenant/meta/0016_snapshot.json +0 -3326
  130. package/apps/runtime/dist/db/migrations/tenant/meta/_journal.json +0 -125
  131. package/apps/runtime/dist/db/schema.js +0 -602
  132. package/apps/runtime/dist/debug.js +0 -196
  133. package/apps/runtime/dist/docs/dev/index.md +0 -41
  134. package/apps/runtime/dist/docs/dev/meta.json +0 -7
  135. package/apps/runtime/dist/docs/dev/plugins/connections.md +0 -74
  136. package/apps/runtime/dist/docs/dev/plugins/events.md +0 -89
  137. package/apps/runtime/dist/docs/dev/plugins/examples.md +0 -101
  138. package/apps/runtime/dist/docs/dev/plugins/index.md +0 -78
  139. package/apps/runtime/dist/docs/dev/plugins/layout.md +0 -90
  140. package/apps/runtime/dist/docs/dev/plugins/meta.json +0 -28
  141. package/apps/runtime/dist/docs/dev/plugins/quick-start.md +0 -94
  142. package/apps/runtime/dist/docs/dev/plugins/reference.md +0 -348
  143. package/apps/runtime/dist/docs/dev/plugins/reloading.md +0 -76
  144. package/apps/runtime/dist/docs/dev/plugins/routes.md +0 -185
  145. package/apps/runtime/dist/docs/dev/plugins/runners.md +0 -230
  146. package/apps/runtime/dist/docs/dev/plugins/server.md +0 -281
  147. package/apps/runtime/dist/docs/dev/plugins/shipping.md +0 -79
  148. package/apps/runtime/dist/docs/dev/plugins/space.md +0 -297
  149. package/apps/runtime/dist/docs/dev/plugins/starters.md +0 -70
  150. package/apps/runtime/dist/docs/dev/plugins/studio.md +0 -363
  151. package/apps/runtime/dist/docs/dev/plugins/styling.md +0 -129
  152. package/apps/runtime/dist/docs/dev/plugins/tables.md +0 -104
  153. package/apps/runtime/dist/docs/dev/plugins/tools.md +0 -139
  154. package/apps/runtime/dist/docs/dev/wizard-format.md +0 -121
  155. package/apps/runtime/dist/docs/meta.json +0 -3
  156. package/apps/runtime/dist/docs/user/ai-apps.md +0 -112
  157. package/apps/runtime/dist/docs/user/assistant.md +0 -77
  158. package/apps/runtime/dist/docs/user/build-a-wizard.md +0 -116
  159. package/apps/runtime/dist/docs/user/command-line.md +0 -83
  160. package/apps/runtime/dist/docs/user/connectors.md +0 -90
  161. package/apps/runtime/dist/docs/user/create-account.md +0 -52
  162. package/apps/runtime/dist/docs/user/data.md +0 -66
  163. package/apps/runtime/dist/docs/user/first-start.md +0 -55
  164. package/apps/runtime/dist/docs/user/index.md +0 -49
  165. package/apps/runtime/dist/docs/user/install.md +0 -121
  166. package/apps/runtime/dist/docs/user/local-only.md +0 -42
  167. package/apps/runtime/dist/docs/user/meta.json +0 -32
  168. package/apps/runtime/dist/docs/user/models.md +0 -156
  169. package/apps/runtime/dist/docs/user/plugins.md +0 -71
  170. package/apps/runtime/dist/docs/user/run.md +0 -98
  171. package/apps/runtime/dist/docs/user/server.md +0 -52
  172. package/apps/runtime/dist/docs/user/space.md +0 -126
  173. package/apps/runtime/dist/docs/user/steps.md +0 -220
  174. package/apps/runtime/dist/docs/user/test-and-share.md +0 -224
  175. package/apps/runtime/dist/docs/user/troubleshooting.md +0 -67
  176. package/apps/runtime/dist/docs/user/wordpress.md +0 -121
  177. package/apps/runtime/dist/documents/parse.js +0 -246
  178. package/apps/runtime/dist/engenty/connections-external/build-connector.js +0 -193
  179. package/apps/runtime/dist/engenty/connections-external/errors.js +0 -11
  180. package/apps/runtime/dist/engenty/connections-external/import-service.js +0 -270
  181. package/apps/runtime/dist/engenty/connections-external/importer/classify.js +0 -34
  182. package/apps/runtime/dist/engenty/connections-external/importer/map-auth.js +0 -185
  183. package/apps/runtime/dist/engenty/connections-external/importer/normalize-mcp.js +0 -63
  184. package/apps/runtime/dist/engenty/connections-external/importer/normalize-openapi.js +0 -130
  185. package/apps/runtime/dist/engenty/connections-external/invoke/http-invoker.js +0 -143
  186. package/apps/runtime/dist/engenty/connections-external/invoke/mcp-client.js +0 -143
  187. package/apps/runtime/dist/engenty/connections-external/net/guarded-fetch.js +0 -119
  188. package/apps/runtime/dist/engenty/connections-external/oauth-dcr.js +0 -88
  189. package/apps/runtime/dist/engenty/connections-external/registry-client.js +0 -336
  190. package/apps/runtime/dist/engenty/connections-external/registry-source.js +0 -82
  191. package/apps/runtime/dist/engenty/connections-external/types.js +0 -7
  192. package/apps/runtime/dist/engenty/connections-github/connector.js +0 -209
  193. package/apps/runtime/dist/engenty/connections-google/connectors/calendar.js +0 -381
  194. package/apps/runtime/dist/engenty/connections-google/connectors/contacts.js +0 -94
  195. package/apps/runtime/dist/engenty/connections-google/connectors/drive.js +0 -290
  196. package/apps/runtime/dist/engenty/connections-google/connectors/gmail.js +0 -567
  197. package/apps/runtime/dist/engenty/connections-google/definitions.js +0 -11
  198. package/apps/runtime/dist/engenty/connections-google/shared.js +0 -73
  199. package/apps/runtime/dist/engenty/connections-hubspot/connector.js +0 -140
  200. package/apps/runtime/dist/engenty/connections-microsoft/action.js +0 -17
  201. package/apps/runtime/dist/engenty/connections-microsoft/graph.js +0 -114
  202. package/apps/runtime/dist/engenty/connections-microsoft/onedrive.js +0 -286
  203. package/apps/runtime/dist/engenty/connections-microsoft/outlook.js +0 -492
  204. package/apps/runtime/dist/engenty/connections-s3/s3.js +0 -328
  205. package/apps/runtime/dist/engenty/connections-sdk/files-capability.js +0 -86
  206. package/apps/runtime/dist/engenty/connections-sdk/oauth2.js +0 -150
  207. package/apps/runtime/dist/engenty/connections-sdk/registry.js +0 -89
  208. package/apps/runtime/dist/engenty/connections-sdk/storage-capability.js +0 -84
  209. package/apps/runtime/dist/engenty/connections-sdk/types.js +0 -30
  210. package/apps/runtime/dist/engenty/connections-slack/connector.js +0 -360
  211. package/apps/runtime/dist/engenty/csv-import/csv-matrix.js +0 -178
  212. package/apps/runtime/dist/engenty/csv-import/import-sources.js +0 -87
  213. package/apps/runtime/dist/engenty/csv-import/parse-csv.js +0 -129
  214. package/apps/runtime/dist/engenty/csv-import/serialize-csv.js +0 -20
  215. package/apps/runtime/dist/engenty/csv-import/types.js +0 -1
  216. package/apps/runtime/dist/engenty/csv-import/xlsx-workbook.js +0 -159
  217. package/apps/runtime/dist/engenty/doc-converter/interface.js +0 -9
  218. package/apps/runtime/dist/engenty/doc-converter/page-break.js +0 -92
  219. package/apps/runtime/dist/engenty/doc-converter/providers/local/index.js +0 -72
  220. package/apps/runtime/dist/engenty/document-scanner/schemas/classifier.js +0 -30
  221. package/apps/runtime/dist/engenty/document-scanner/schemas/index.js +0 -4
  222. package/apps/runtime/dist/engenty/document-scanner/schemas/invoice.js +0 -73
  223. package/apps/runtime/dist/engenty/document-scanner/schemas/receipt.js +0 -63
  224. package/apps/runtime/dist/engenty/document-scanner/schemas/shared.js +0 -40
  225. package/apps/runtime/dist/engenty/search-index/chunks.js +0 -164
  226. package/apps/runtime/dist/engenty/search-index/contracts.js +0 -9
  227. package/apps/runtime/dist/engenty/shims/connections-sdk.js +0 -39
  228. package/apps/runtime/dist/engenty/shims/plugin-sdk.js +0 -1
  229. package/apps/runtime/dist/engenty/shims/web-ingest.js +0 -19
  230. package/apps/runtime/dist/engenty/web-ingest/ssrf.js +0 -277
  231. package/apps/runtime/dist/engine/asks.js +0 -82
  232. package/apps/runtime/dist/engine/decide.js +0 -82
  233. package/apps/runtime/dist/engine/device.js +0 -194
  234. package/apps/runtime/dist/engine/events.js +0 -128
  235. package/apps/runtime/dist/engine/input.js +0 -208
  236. package/apps/runtime/dist/engine/owner.js +0 -32
  237. package/apps/runtime/dist/engine/prepare.js +0 -90
  238. package/apps/runtime/dist/engine/push.js +0 -58
  239. package/apps/runtime/dist/engine/requirements.js +0 -355
  240. package/apps/runtime/dist/engine/resources.js +0 -198
  241. package/apps/runtime/dist/engine/runner.js +0 -970
  242. package/apps/runtime/dist/engine/steps.js +0 -1000
  243. package/apps/runtime/dist/engine/surface.js +0 -91
  244. package/apps/runtime/dist/engine/template.js +0 -240
  245. package/apps/runtime/dist/engine/types.js +0 -4
  246. package/apps/runtime/dist/env.js +0 -295
  247. package/apps/runtime/dist/features.js +0 -123
  248. package/apps/runtime/dist/files/blobs.js +0 -22
  249. package/apps/runtime/dist/files/objects.js +0 -86
  250. package/apps/runtime/dist/files/storage.js +0 -120
  251. package/apps/runtime/dist/files/web-images.js +0 -101
  252. package/apps/runtime/dist/film/project.js +0 -257
  253. package/apps/runtime/dist/film/skills.js +0 -91
  254. package/apps/runtime/dist/film/sounds.js +0 -122
  255. package/apps/runtime/dist/film/step.js +0 -289
  256. package/apps/runtime/dist/film/tools.js +0 -99
  257. package/apps/runtime/dist/geocode.js +0 -58
  258. package/apps/runtime/dist/harness/apple.js +0 -269
  259. package/apps/runtime/dist/harness/claude.js +0 -147
  260. package/apps/runtime/dist/harness/codex.js +0 -229
  261. package/apps/runtime/dist/harness/cursor.js +0 -93
  262. package/apps/runtime/dist/harness/env.js +0 -124
  263. package/apps/runtime/dist/harness/gemini.js +0 -126
  264. package/apps/runtime/dist/harness/index.js +0 -95
  265. package/apps/runtime/dist/harness/model.js +0 -271
  266. package/apps/runtime/dist/harness/prompt.js +0 -121
  267. package/apps/runtime/dist/harness/terminal.js +0 -194
  268. package/apps/runtime/dist/harness/types.js +0 -7
  269. package/apps/runtime/dist/index.js +0 -113
  270. package/apps/runtime/dist/limits.js +0 -81
  271. package/apps/runtime/dist/link-preview.js +0 -60
  272. package/apps/runtime/dist/log.js +0 -106
  273. package/apps/runtime/dist/manage.js +0 -249
  274. package/apps/runtime/dist/mcp/auth.js +0 -161
  275. package/apps/runtime/dist/mcp/bridge.js +0 -59
  276. package/apps/runtime/dist/mcp/flow-app.js +0 -97
  277. package/apps/runtime/dist/mcp/handler.js +0 -54
  278. package/apps/runtime/dist/mcp/scopes.js +0 -14
  279. package/apps/runtime/dist/mcp/seen.js +0 -65
  280. package/apps/runtime/dist/mcp/tools.js +0 -572
  281. package/apps/runtime/dist/media/conversation.js +0 -167
  282. package/apps/runtime/dist/media/ffmpeg.js +0 -121
  283. package/apps/runtime/dist/media/generate.js +0 -120
  284. package/apps/runtime/dist/media/marking.js +0 -121
  285. package/apps/runtime/dist/media/transcribe.js +0 -198
  286. package/apps/runtime/dist/model-errors.js +0 -42
  287. package/apps/runtime/dist/models.js +0 -1106
  288. package/apps/runtime/dist/plugin.js +0 -61
  289. package/apps/runtime/dist/plugins/channels.js +0 -78
  290. package/apps/runtime/dist/plugins/claims.js +0 -56
  291. package/apps/runtime/dist/plugins/discovery.js +0 -155
  292. package/apps/runtime/dist/plugins/events.js +0 -63
  293. package/apps/runtime/dist/plugins/jobs.js +0 -64
  294. package/apps/runtime/dist/plugins/loader.js +0 -501
  295. package/apps/runtime/dist/plugins/migrations.js +0 -69
  296. package/apps/runtime/dist/plugins/pro-keys.js +0 -34
  297. package/apps/runtime/dist/plugins/pro-state.js +0 -83
  298. package/apps/runtime/dist/plugins/pro.js +0 -310
  299. package/apps/runtime/dist/plugins/public.js +0 -44
  300. package/apps/runtime/dist/plugins/registry.js +0 -122
  301. package/apps/runtime/dist/plugins/runs.js +0 -210
  302. package/apps/runtime/dist/render/browser-path.js +0 -54
  303. package/apps/runtime/dist/render/chromium.js +0 -98
  304. package/apps/runtime/dist/render/convert.js +0 -158
  305. package/apps/runtime/dist/render/downloads.js +0 -299
  306. package/apps/runtime/dist/render/guard.js +0 -25
  307. package/apps/runtime/dist/render/shaped.js +0 -137
  308. package/apps/runtime/dist/routes/api.js +0 -440
  309. package/apps/runtime/dist/routes/debug.js +0 -42
  310. package/apps/runtime/dist/routes/delivery.js +0 -90
  311. package/apps/runtime/dist/routes/internal.js +0 -81
  312. package/apps/runtime/dist/routes/lang.js +0 -25
  313. package/apps/runtime/dist/routes/marketplace.js +0 -43
  314. package/apps/runtime/dist/routes/plugin-public.js +0 -113
  315. package/apps/runtime/dist/routes/plugins.js +0 -212
  316. package/apps/runtime/dist/routes/runs.js +0 -1422
  317. package/apps/runtime/dist/routes/studio.js +0 -1600
  318. package/apps/runtime/dist/routes/wizard-stream.js +0 -30
  319. package/apps/runtime/dist/running.js +0 -39
  320. package/apps/runtime/dist/sandbox/docker.js +0 -75
  321. package/apps/runtime/dist/sandbox/index.js +0 -23
  322. package/apps/runtime/dist/sandbox/types.js +0 -1
  323. package/apps/runtime/dist/secrets/crypto.js +0 -28
  324. package/apps/runtime/dist/secrets/signing.js +0 -52
  325. package/apps/runtime/dist/secrets/vault.js +0 -59
  326. package/apps/runtime/dist/services/access.js +0 -88
  327. package/apps/runtime/dist/services/api.js +0 -248
  328. package/apps/runtime/dist/services/architect.js +0 -95
  329. package/apps/runtime/dist/services/assistant-chats.js +0 -311
  330. package/apps/runtime/dist/services/brand.js +0 -85
  331. package/apps/runtime/dist/services/cloud.js +0 -456
  332. package/apps/runtime/dist/services/draft-events.js +0 -27
  333. package/apps/runtime/dist/services/engenty-shapes.js +0 -71
  334. package/apps/runtime/dist/services/errors.js +0 -29
  335. package/apps/runtime/dist/services/files.js +0 -178
  336. package/apps/runtime/dist/services/knowledge-model.js +0 -559
  337. package/apps/runtime/dist/services/knowledge.js +0 -721
  338. package/apps/runtime/dist/services/links.js +0 -16
  339. package/apps/runtime/dist/services/marketplace.js +0 -492
  340. package/apps/runtime/dist/services/onboarding.js +0 -152
  341. package/apps/runtime/dist/services/package-file.js +0 -82
  342. package/apps/runtime/dist/services/package.js +0 -170
  343. package/apps/runtime/dist/services/profile.js +0 -51
  344. package/apps/runtime/dist/services/project-files.js +0 -439
  345. package/apps/runtime/dist/services/project-index.js +0 -707
  346. package/apps/runtime/dist/services/projects.js +0 -387
  347. package/apps/runtime/dist/services/relevance.js +0 -58
  348. package/apps/runtime/dist/services/runners.js +0 -178
  349. package/apps/runtime/dist/services/runs.js +0 -524
  350. package/apps/runtime/dist/services/shares.js +0 -130
  351. package/apps/runtime/dist/services/site.js +0 -270
  352. package/apps/runtime/dist/services/space-categories.js +0 -861
  353. package/apps/runtime/dist/services/space-data.js +0 -792
  354. package/apps/runtime/dist/services/space-origin.js +0 -207
  355. package/apps/runtime/dist/services/spaces.js +0 -656
  356. package/apps/runtime/dist/services/translations.js +0 -306
  357. package/apps/runtime/dist/services/widgets.js +0 -34
  358. package/apps/runtime/dist/services/wizard-icon.js +0 -157
  359. package/apps/runtime/dist/services/wizards.js +0 -420
  360. package/apps/runtime/dist/settings.js +0 -16
  361. package/apps/runtime/dist/store/errors.js +0 -4
  362. package/apps/runtime/dist/store/index.js +0 -299
  363. package/apps/runtime/dist/store/shared-lists.js +0 -123
  364. package/apps/runtime/dist/tenants/control.js +0 -238
  365. package/apps/runtime/dist/tenants/tenant.js +0 -26
  366. package/apps/runtime/dist/texts.js +0 -203
  367. package/apps/runtime/dist/tools/browser.js +0 -703
  368. package/apps/runtime/dist/tools/connector.js +0 -204
  369. package/apps/runtime/dist/tools/index.js +0 -291
  370. package/apps/runtime/dist/tools/mail.js +0 -104
  371. package/apps/runtime/dist/tools/net-guard.js +0 -170
  372. package/apps/runtime/dist/tools/pages.js +0 -81
  373. package/apps/runtime/dist/tools/plugin.js +0 -180
  374. package/apps/runtime/dist/tools/project.js +0 -154
  375. package/apps/runtime/dist/tools/shared.js +0 -69
  376. package/apps/runtime/dist/tools/store.js +0 -238
  377. package/apps/runtime/dist/update.js +0 -113
  378. package/apps/runtime/dist/widgets/bundle.js +0 -99
  379. package/apps/runtime/dist/widgets/render.js +0 -329
  380. package/apps/runtime/dist/widgets/runtime.js +0 -108
  381. package/apps/runtime/dist/widgets/script.js +0 -30
  382. package/apps/runtime/dist/widgets/step.js +0 -223
  383. package/apps/web/dist/ai-labels/ai-black.svg +0 -20
  384. package/apps/web/dist/ai-labels/ai-generated-black.svg +0 -31
  385. package/apps/web/dist/ai-labels/ai-generated-white.svg +0 -32
  386. package/apps/web/dist/ai-labels/ai-modified-black.svg +0 -30
  387. package/apps/web/dist/ai-labels/ai-modified-white.svg +0 -31
  388. package/apps/web/dist/ai-labels/ai-white.svg +0 -21
  389. package/apps/web/dist/assets/AboutDialog--aZOfowz.js +0 -1
  390. package/apps/web/dist/assets/ChangelogDialog-CcMXT8l9.js +0 -1
  391. package/apps/web/dist/assets/ChatView-BqK5nH84.js +0 -10
  392. package/apps/web/dist/assets/EditorPage-BRZmuMsK.js +0 -3
  393. package/apps/web/dist/assets/FlowPreview-CpA_aX8t.js +0 -1
  394. package/apps/web/dist/assets/Harness-BrP-ENHg.css +0 -1
  395. package/apps/web/dist/assets/Harness-C8demwfW.js +0 -16
  396. package/apps/web/dist/assets/NewWizardChannels-vph1mN1m.js +0 -1
  397. package/apps/web/dist/assets/NewWizardPage-u1BIy4q9.js +0 -7
  398. package/apps/web/dist/assets/OnboardingPage-BR3FmORm.js +0 -1
  399. package/apps/web/dist/assets/ProjectPage-BWN0iO0X.js +0 -1
  400. package/apps/web/dist/assets/PublicRunner-CohatW8Y.js +0 -1
  401. package/apps/web/dist/assets/ReadOnly-rQGZBuzb.js +0 -1
  402. package/apps/web/dist/assets/RunDrawer-Cs8XqQUo.js +0 -4
  403. package/apps/web/dist/assets/RunnerView-B85O0i1h.js +0 -1
  404. package/apps/web/dist/assets/SettingsPage-CM6HfO-O.js +0 -1
  405. package/apps/web/dist/assets/SetupPage-BpAobBc4.js +0 -1
  406. package/apps/web/dist/assets/SharePage-CbmAN4M4.js +0 -1
  407. package/apps/web/dist/assets/changelog-BBR59khF.js +0 -1
  408. package/apps/web/dist/assets/engenty-eXZ-EAwd.js +0 -1
  409. package/apps/web/dist/assets/esm-CY-A_13f.js +0 -7
  410. package/apps/web/dist/assets/fluffy-engenty-ClRou7yu.js +0 -456
  411. package/apps/web/dist/assets/index-C7HL_Fjz.js +0 -14
  412. package/apps/web/dist/assets/index-Co9Yr23e.css +0 -1
  413. package/apps/web/dist/assets/jsx-runtime-BNakU3Ej.js +0 -1
  414. package/apps/web/dist/assets/lock--JFmtLDU.js +0 -1
  415. package/apps/web/dist/assets/oss-credits-BJrR7BR1.js +0 -1
  416. package/apps/web/dist/assets/pdfmake-Cx9scTbD.js +0 -228
  417. package/apps/web/dist/assets/phone-DMtADQ4-.js +0 -1
  418. package/apps/web/dist/assets/preload-helper-CNEI7N0N.js +0 -1
  419. package/apps/web/dist/assets/qr-scanner-worker.min-CJaXo3yu.js +0 -98
  420. package/apps/web/dist/assets/qr-scanner.min-C_UI0gH-.js +0 -1
  421. package/apps/web/dist/assets/rolldown-runtime-hePW80VL.js +0 -1
  422. package/apps/web/dist/assets/settings-menu-Dac4JUiM.js +0 -1
  423. package/apps/web/dist/assets/ui-CTXSFCzc.js +0 -137
  424. package/apps/web/dist/assets/upload-Bcpc3mDn.js +0 -1
  425. package/apps/web/dist/assets/vfs_fonts-DllDSYt1.js +0 -1
  426. package/apps/web/dist/embed.js +0 -266
  427. package/apps/web/dist/favicon.svg +0 -1
  428. package/apps/web/dist/icons/apple-touch-icon.png +0 -0
  429. package/apps/web/dist/icons/icon-192.png +0 -0
  430. package/apps/web/dist/icons/icon-512.png +0 -0
  431. package/apps/web/dist/icons/icon-maskable-512.png +0 -0
  432. package/apps/web/dist/index.html +0 -48
  433. package/apps/web/dist/manifest.webmanifest +0 -21
  434. package/apps/web/dist/mcp/flow.html +0 -980
  435. package/apps/web/dist/sw.js +0 -15
  436. package/modules/README.md +0 -15
  437. package/node_modules/@engenty-wizards/plugin-sdk/dist/index.d.ts +0 -1150
  438. package/node_modules/@engenty-wizards/plugin-sdk/dist/index.js +0 -4
  439. package/node_modules/@engenty-wizards/plugin-sdk/dist/studio.d.ts +0 -322
  440. package/node_modules/@engenty-wizards/plugin-sdk/dist/studio.js +0 -4
  441. package/node_modules/@engenty-wizards/plugin-sdk/dist/thread.d.ts +0 -174
  442. package/node_modules/@engenty-wizards/plugin-sdk/dist/thread.js +0 -821
  443. package/node_modules/@engenty-wizards/plugin-sdk/package.json +0 -11
  444. package/node_modules/@engenty-wizards/shared/dist/assistant.d.ts +0 -174
  445. package/node_modules/@engenty-wizards/shared/dist/assistant.js +0 -65
  446. package/node_modules/@engenty-wizards/shared/dist/changes.d.ts +0 -22
  447. package/node_modules/@engenty-wizards/shared/dist/changes.js +0 -61
  448. package/node_modules/@engenty-wizards/shared/dist/connectors.d.ts +0 -77
  449. package/node_modules/@engenty-wizards/shared/dist/connectors.js +0 -2
  450. package/node_modules/@engenty-wizards/shared/dist/decision.d.ts +0 -76
  451. package/node_modules/@engenty-wizards/shared/dist/decision.js +0 -147
  452. package/node_modules/@engenty-wizards/shared/dist/definition.d.ts +0 -2922
  453. package/node_modules/@engenty-wizards/shared/dist/definition.js +0 -1920
  454. package/node_modules/@engenty-wizards/shared/dist/engenty/data-tables/columns-format.d.ts +0 -5
  455. package/node_modules/@engenty-wizards/shared/dist/engenty/data-tables/columns-format.js +0 -132
  456. package/node_modules/@engenty-wizards/shared/dist/engenty/data-tables/columns-value.d.ts +0 -11
  457. package/node_modules/@engenty-wizards/shared/dist/engenty/data-tables/columns-value.js +0 -209
  458. package/node_modules/@engenty-wizards/shared/dist/engenty/data-tables/columns.d.ts +0 -532
  459. package/node_modules/@engenty-wizards/shared/dist/engenty/data-tables/columns.js +0 -217
  460. package/node_modules/@engenty-wizards/shared/dist/engenty/data-tables/index.d.ts +0 -3
  461. package/node_modules/@engenty-wizards/shared/dist/engenty/data-tables/index.js +0 -3
  462. package/node_modules/@engenty-wizards/shared/dist/engenty/search-index/catalog-lexical.d.ts +0 -14
  463. package/node_modules/@engenty-wizards/shared/dist/engenty/search-index/catalog-lexical.js +0 -166
  464. package/node_modules/@engenty-wizards/shared/dist/engenty/search-index/catalog-rank.d.ts +0 -33
  465. package/node_modules/@engenty-wizards/shared/dist/engenty/search-index/catalog-rank.js +0 -99
  466. package/node_modules/@engenty-wizards/shared/dist/feature-flags.d.ts +0 -78
  467. package/node_modules/@engenty-wizards/shared/dist/feature-flags.js +0 -70
  468. package/node_modules/@engenty-wizards/shared/dist/features.d.ts +0 -41
  469. package/node_modules/@engenty-wizards/shared/dist/features.js +0 -89
  470. package/node_modules/@engenty-wizards/shared/dist/fit.d.ts +0 -71
  471. package/node_modules/@engenty-wizards/shared/dist/fit.js +0 -382
  472. package/node_modules/@engenty-wizards/shared/dist/json-schema.d.ts +0 -14
  473. package/node_modules/@engenty-wizards/shared/dist/json-schema.js +0 -66
  474. package/node_modules/@engenty-wizards/shared/dist/knowledge.d.ts +0 -199
  475. package/node_modules/@engenty-wizards/shared/dist/knowledge.js +0 -68
  476. package/node_modules/@engenty-wizards/shared/dist/marketplace-entry.d.ts +0 -35
  477. package/node_modules/@engenty-wizards/shared/dist/marketplace-entry.js +0 -107
  478. package/node_modules/@engenty-wizards/shared/dist/marketplace-search.d.ts +0 -20
  479. package/node_modules/@engenty-wizards/shared/dist/marketplace-search.js +0 -136
  480. package/node_modules/@engenty-wizards/shared/dist/marketplace.d.ts +0 -227
  481. package/node_modules/@engenty-wizards/shared/dist/marketplace.js +0 -354
  482. package/node_modules/@engenty-wizards/shared/dist/merge.d.ts +0 -7
  483. package/node_modules/@engenty-wizards/shared/dist/merge.js +0 -40
  484. package/node_modules/@engenty-wizards/shared/dist/numbers.d.ts +0 -24
  485. package/node_modules/@engenty-wizards/shared/dist/numbers.js +0 -54
  486. package/node_modules/@engenty-wizards/shared/dist/projects.d.ts +0 -224
  487. package/node_modules/@engenty-wizards/shared/dist/projects.js +0 -319
  488. package/node_modules/@engenty-wizards/shared/dist/providers.d.ts +0 -101
  489. package/node_modules/@engenty-wizards/shared/dist/providers.js +0 -390
  490. package/node_modules/@engenty-wizards/shared/dist/run.d.ts +0 -679
  491. package/node_modules/@engenty-wizards/shared/dist/run.js +0 -618
  492. package/node_modules/@engenty-wizards/shared/dist/runner-texts.d.ts +0 -546
  493. package/node_modules/@engenty-wizards/shared/dist/runner-texts.js +0 -523
  494. package/node_modules/@engenty-wizards/shared/dist/runners.d.ts +0 -93
  495. package/node_modules/@engenty-wizards/shared/dist/runners.js +0 -146
  496. package/node_modules/@engenty-wizards/shared/dist/shape.d.ts +0 -102
  497. package/node_modules/@engenty-wizards/shared/dist/shape.js +0 -318
  498. package/node_modules/@engenty-wizards/shared/dist/space-data.d.ts +0 -89
  499. package/node_modules/@engenty-wizards/shared/dist/space-data.js +0 -47
  500. package/node_modules/@engenty-wizards/shared/dist/store.d.ts +0 -117
  501. package/node_modules/@engenty-wizards/shared/dist/store.js +0 -81
  502. package/node_modules/@engenty-wizards/shared/dist/surface.d.ts +0 -115
  503. package/node_modules/@engenty-wizards/shared/dist/surface.js +0 -442
  504. package/node_modules/@engenty-wizards/shared/dist/texts.d.ts +0 -45
  505. package/node_modules/@engenty-wizards/shared/dist/texts.js +0 -54
  506. package/node_modules/@engenty-wizards/shared/dist/translation.d.ts +0 -23
  507. package/node_modules/@engenty-wizards/shared/dist/translation.js +0 -154
  508. package/node_modules/@engenty-wizards/shared/dist/wizard-package.d.ts +0 -48
  509. package/node_modules/@engenty-wizards/shared/dist/wizard-package.js +0 -49
  510. package/node_modules/@engenty-wizards/shared/dist/workspace.d.ts +0 -16
  511. package/node_modules/@engenty-wizards/shared/dist/workspace.js +0 -51
  512. package/node_modules/@engenty-wizards/shared/package.json +0 -10
  513. package/plugin/.claude-plugin/plugin.json +0 -9
  514. package/plugin/.mcp.json +0 -8
  515. package/plugin/commands/wizard.md +0 -8
  516. package/plugin/skills/build-wizard/SKILL.md +0 -27
  517. package/plugin/skills/use-wizard/SKILL.md +0 -18
@@ -1,1600 +0,0 @@
1
- import { mkdirSync } from "node:fs";
2
- import { join } from "node:path";
3
- import { ASSISTANT_LAYOUTS, ASSISTANT_PAGE_BYTES, assistantSignalSchema, assistantTurnSchema, } from "@engenty-wizards/shared/assistant";
4
- import { LANGS, MODEL_CLASSES, TEXT_CLASSES, wizardLang, } from "@engenty-wizards/shared/definition";
5
- import { CATEGORY_TYPES, whereSchema } from "@engenty-wizards/shared/knowledge";
6
- import { PROJECT_FILE_KINDS } from "@engenty-wizards/shared/projects";
7
- import { isCreditsRef } from "@engenty-wizards/shared/providers";
8
- import { note } from "@engenty-wizards/shared/run";
9
- import { wizardTexts } from "@engenty-wizards/shared/translation";
10
- import { PACKAGE_EXTENSION, PACKAGE_MAX_BYTES, PACKAGE_MIME, } from "@engenty-wizards/shared/wizard-package";
11
- import { generateText } from "ai";
12
- import { Hono } from "hono";
13
- import { streamSSE } from "hono/streaming";
14
- import { nanoid } from "nanoid";
15
- import { z } from "zod";
16
- import { runStudioAssistant, signalText } from "../agents/studio-assistant.js";
17
- import { chatEngine, setChatEngine, subscriptionClients } from "../agents/subscription.js";
18
- import { scanColors, scanFonts, scanImages, scanLogos } from "../agents/website.js";
19
- import { answerBrowser, awaitBrowser } from "../assistant/browser.js";
20
- import { endRun, signalRun, startRun, takeSignals } from "../assistant/runs.js";
21
- import { accountOverview, linkedAccount, startLink, unlink } from "../auth/account.js";
22
- import { createLocalKey, deleteLocalKey, listLocalKeys } from "../auth/keys.js";
23
- import { appStates, connectApps } from "../cli/connect.js";
24
- import { layout } from "../cli/home.js";
25
- import { connectorImportSchema, importConnector, listConnectors, previewSource, refreshConnector, registryService, removeConnector, searchRegistry, } from "../connectors/external.js";
26
- import { balanceCredits, canSpend } from "../credits/credits.js";
27
- import { estimateRun } from "../credits/estimate.js";
28
- import { missingModels, stepsWithoutModel } from "../engine/requirements.js";
29
- import { env } from "../env.js";
30
- import { feature, features } from "../features.js";
31
- import { appleStatus } from "../harness/apple.js";
32
- import { freshAuth, loginEnv } from "../harness/env.js";
33
- import { detectHarness, detectHarnesses, HARNESS_IDS, harness, installSpec, } from "../harness/index.js";
34
- import { closeTerminal, openTerminal, resizeTerminal, subscribeTerminal, writeTerminal, } from "../harness/terminal.js";
35
- import { installMail, managed, renameTenant, saveTeamProfile, tenantInfo, tenantMembers, userInfo, } from "../manage.js";
36
- import { seenApps } from "../mcp/seen.js";
37
- import { generateImageMedia, generateSpeechMedia, generateVideoMedia } from "../media/generate.js";
38
- import { transcribeAudio } from "../media/transcribe.js";
39
- import { errorText, saidOf } from "../model-errors.js";
40
- import { checkKey, classProblem, classWays, embeddingModel, hasTextModel, LOCAL_KEYS, localModelSettings, ModelUnavailableError, modelSettings, saveLocalModels, saveModels, storedKey, textModel, } from "../models.js";
41
- import { refreshPro } from "../plugins/pro.js";
42
- import { HTML_RESPONSE_CSP } from "../render/guard.js";
43
- import { isAdminRole, mayBuild, mayCreate, projectWritable, requireAdmin, requireWritable, } from "../services/access.js";
44
- import { architectTurn } from "../services/architect.js";
45
- import { addMessage, assistantLayout, currentChat, earlierChats, foldChat, newChat, openChat, readChat, turnHistory, } from "../services/assistant-chats.js";
46
- import { describeGradient } from "../services/brand.js";
47
- import { checkForCloud, cloudLinked, cloudSpaces, cloudState, forgetCloud, publishAndSync, pushSharing, removeFromCloud, replaceCloudSpaces, rotateInCloud, syncToCloud, } from "../services/cloud.js";
48
- import { notFound, ServiceError } from "../services/errors.js";
49
- import { deleteFile, listFiles, readFile, writeFile } from "../services/files.js";
50
- import { categoryContents, listKnowledge, resolvePath, valueContents, } from "../services/knowledge.js";
51
- import { writeSummary } from "../services/knowledge-model.js";
52
- import { applyWebsite, finishOnboarding, needsOnboarding } from "../services/onboarding.js";
53
- import { exportWizard, importWizard } from "../services/package.js";
54
- import { profileSchema, saveProfile, saveUserLang, userLang, userProfile, } from "../services/profile.js";
55
- import { addProjectFile, addProjectFileFromUrl, fileView, orderProjectFiles, projectFile, projectFileContent, projectFiles, reindexProjectFile, removeProjectFile, updateProjectFile, } from "../services/project-files.js";
56
- import { documentText, queueIndex, searchKnowledge } from "../services/project-index.js";
57
- import { createProject, deleteProject, gradientSchema, listProjects, maskedServers, ownedProject, projectLimitOrNull, projectPatchSchema, updateProject, } from "../services/projects.js";
58
- import { runnersOf, wizardRunners } from "../services/runners.js";
59
- import { listResults, listRuns, startTestRun } from "../services/runs.js";
60
- import { addCategoryValue, categoryRow, categoryValue, deleteCategory, deleteCategoryValue, mergeCategoryValues, orderCategoryValues, putCategory, renameCategoryValue, setItemCategory, updateCategory, } from "../services/space-categories.js";
61
- import { addTableRow, createPage, createTable, deletePage, deleteTable, deleteTableRows, getPage, getTable, listSpaceData, orderSubPages, updatePage, updateTable, updateTableRow, } from "../services/space-data.js";
62
- import { deleteTranslation, editTranslation, isLangCode, publishedDefinition, translationsOf, } from "../services/translations.js";
63
- import { draftWidgetPreview } from "../services/widgets.js";
64
- import { createWizard, deleteWizard, draftChanges, duplicateWizard, listWizards, ownedWizard, rotateShareLink, updateWizardSettings, wizardMessages, wizardState, writableWizard, writeDraft, } from "../services/wizards.js";
65
- import { readSetting, writeSetting } from "../settings.js";
66
- import { codeOf } from "../tenants/control.js";
67
- import { currentTenant } from "../tenants/tenant.js";
68
- import { serverText } from "../texts.js";
69
- import { applyUpdate, updateStatus } from "../update.js";
70
- import { byteRange } from "./delivery.js";
71
- import { notFoundAnswer, requestLang, say } from "./lang.js";
72
- /** The model sources a test call has worked on: the setup is done for those, not for the others. */
73
- async function testedSources() {
74
- const tested = await readSetting("setup-done");
75
- return Array.isArray(tested) ? tested : [];
76
- }
77
- /**
78
- * The chosen source has passed a test call and can still answer: its client is there and signed
79
- * in. Where Apple Intelligence thinks the short classes, the test ran there; a client behind High
80
- * and Highest is no condition then.
81
- */
82
- async function setupDone() {
83
- const { source, bindings } = localModelSettings();
84
- if (!(await testedSources()).includes(source)) {
85
- return false;
86
- }
87
- const client = bindings.standard.startsWith("apple:") ? null : harness(source);
88
- if (client) {
89
- const status = await detectHarness(client.id);
90
- return Boolean(status?.version) && status?.auth !== "none";
91
- }
92
- return hasTextModel();
93
- }
94
- const modelsInput = z.object({
95
- source: z.enum([...HARNESS_IDS, "account", "own"]).optional(),
96
- bindings: z.partialRecord(z.enum(MODEL_CLASSES), z.string().max(160)).optional(),
97
- ollamaUrl: z.string().max(200).optional(),
98
- creditFallback: z.boolean().optional(),
99
- keys: z.partialRecord(z.enum(LOCAL_KEYS), z.string().max(400)).optional(),
100
- });
101
- /** Alone the person changes everything; in a team its owner and admins. */
102
- function mayChangeModels(user) {
103
- return !managed || user.role === "owner" || user.role === "admin";
104
- }
105
- /** A binding the cloud can run: a provider's model or the credits, no client, no local model. */
106
- function cloudBinding(ref) {
107
- return (isCreditsRef(ref) || /^(openai|anthropic|google|fal|elevenlabs|replicate|gateway):/.test(ref));
108
- }
109
- const TEST_TEXT = {
110
- de: {
111
- image: "Ein kleiner, freundlicher Zauberhut aus orangem Filz auf einem Holztisch, weiches Licht, flache Illustration.",
112
- speech: "Hallo! So klingt die Stimme deiner Wizards.",
113
- video: "Ein orangefarbener Zauberhut dreht sich langsam auf einem Holztisch, weiches Licht.",
114
- },
115
- en: {
116
- image: "A small, friendly wizard hat of orange felt on a wooden table, soft light, flat illustration.",
117
- speech: "Hello! This is how your wizards sound.",
118
- video: "An orange wizard hat slowly turns on a wooden table, soft light.",
119
- },
120
- };
121
- const asDataUrl = (bytes, mime) => `data:${mime};base64,${Buffer.from(bytes).toString("base64")}`;
122
- /** One second of silence as WAV: what a voice note test listens to where nothing speaks. */
123
- function silentWav() {
124
- const rate = 16_000;
125
- const samples = rate;
126
- const buf = Buffer.alloc(44 + samples * 2);
127
- buf.write("RIFF", 0);
128
- buf.writeUInt32LE(36 + samples * 2, 4);
129
- buf.write("WAVEfmt ", 8);
130
- buf.writeUInt32LE(16, 16);
131
- buf.writeUInt16LE(1, 20);
132
- buf.writeUInt16LE(1, 22);
133
- buf.writeUInt32LE(rate, 24);
134
- buf.writeUInt32LE(rate * 2, 28);
135
- buf.writeUInt16LE(2, 32);
136
- buf.writeUInt16LE(16, 34);
137
- buf.write("data", 36);
138
- buf.writeUInt32LE(samples * 2, 40);
139
- return new Uint8Array(buf);
140
- }
141
- async function testClass(cls, lang) {
142
- const started = Date.now();
143
- const signal = AbortSignal.timeout(cls === "video" ? 300_000 : 120_000);
144
- const done = (result) => ({
145
- ok: true,
146
- ms: Date.now() - started,
147
- ...result,
148
- });
149
- try {
150
- if (TEXT_CLASSES.includes(cls)) {
151
- const resolved = await textModel(cls);
152
- const result = await generateText({
153
- model: resolved.model,
154
- prompt: "Reply with the single word: OK",
155
- maxOutputTokens: 20,
156
- abortSignal: signal,
157
- });
158
- return done({ ref: resolved.ref, reply: result.text.trim().slice(0, 200) });
159
- }
160
- if (cls === "image") {
161
- const image = await generateImageMedia({
162
- prompt: TEST_TEXT[lang].image,
163
- aspectRatio: "1:1",
164
- abortSignal: signal,
165
- });
166
- return done({ ref: image.system, media: asDataUrl(image.bytes, image.mime) });
167
- }
168
- if (cls === "speech") {
169
- const voice = await generateSpeechMedia({
170
- text: TEST_TEXT[lang].speech,
171
- abortSignal: signal,
172
- });
173
- return done({ ref: voice.system, media: asDataUrl(voice.bytes, voice.mime) });
174
- }
175
- if (cls === "video") {
176
- const clip = await generateVideoMedia({
177
- prompt: TEST_TEXT[lang].video,
178
- aspectRatio: "16:9",
179
- duration: 4,
180
- resolution: "480p",
181
- abortSignal: signal,
182
- });
183
- return done({ ref: clip.system, media: asDataUrl(clip.bytes, clip.mime) });
184
- }
185
- // A voice note: the test voice where one speaks here, else a second of silence.
186
- const voice = (await classProblem("speech"))
187
- ? null
188
- : await generateSpeechMedia({ text: TEST_TEXT[lang].speech, abortSignal: signal }).catch(() => null);
189
- const heard = await transcribeAudio({
190
- bytes: voice?.bytes ?? silentWav(),
191
- mediaType: voice?.mime ?? "audio/wav",
192
- abortSignal: signal,
193
- });
194
- return done({ reply: heard.text.slice(0, 300) });
195
- }
196
- catch (err) {
197
- const message = err?.message ?? String(err);
198
- return { ok: false, ms: Date.now() - started, error: message.slice(0, 500) };
199
- }
200
- }
201
- /** The size of an inline terminal, as the page lays it out. */
202
- /** Whether the studio assistant's developer mode is offered to this person. */
203
- async function assistantDevFor(user) {
204
- return managed ? (await userInfo(user.id)).admin : env.assistantDev;
205
- }
206
- const terminalSize = z.object({
207
- cols: z.number().int().min(10).max(500).optional(),
208
- rows: z.number().int().min(4).max(200).optional(),
209
- });
210
- export const studio = new Hono()
211
- .get("/me", async (c) => {
212
- const user = c.get("user");
213
- // A runtime that runs alone may be linked to an account: its credits and the cloud to publish to.
214
- const linked = managed ? null : await linkedAccount();
215
- const overview = linked ? await accountOverview() : null;
216
- const profile = await userProfile(user);
217
- // What the Manage-App says of the tenant: its plan and feature switches; and of the person.
218
- const info = managed ? await tenantInfo(user.tenantId).catch(() => null) : null;
219
- const person = managed ? await userInfo(user.id) : null;
220
- return c.json({
221
- user: { id: user.id, name: profile.name, email: profile.email, image: user.image ?? null },
222
- /** What the person says about themselves; name and e-mail are the account's when managed. */
223
- profile,
224
- /** The language the person picked, wherever they picked it; null until they do. */
225
- lang: await userLang(user),
226
- tenant: {
227
- id: user.tenantId,
228
- role: user.role,
229
- /** The plan the team is on; null alone, or where the Manage-App names none. */
230
- plan: info?.plan ?? null,
231
- },
232
- /** The feature switches: the code's defaults, what the Manage-App says of the team and the person, this install's file. */
233
- features: features(managed ? { ...info?.features, ...person?.features } : overview?.tenant.features),
234
- /** The studio assistant's developer mode may be switched on: ASSISTANT_DEV here, the platform's admins when managed. */
235
- assistantDev: await assistantDevFor(user),
236
- mode: managed ? "managed" : "local",
237
- /** The tenant's balance; null where the runtime resolves models itself. */
238
- credits: managed ? await balanceCredits() : null,
239
- /** Where the account, members, API keys and credits are managed. */
240
- manageUrl: managed ? env.manage.url : null,
241
- account: linked
242
- ? {
243
- name: linked.name,
244
- email: linked.email,
245
- /** The team the account's space belongs to, as the Manage-App names it. */
246
- team: overview?.tenant.name ?? null,
247
- credits: overview?.tenant.balanceCredits ?? null,
248
- /** What of the credits ends on a date, the nearest first. */
249
- expiring: overview?.tenant.expiring ?? [],
250
- url: env.local.accountUrl,
251
- cloudUrl: env.local.cloudUrl,
252
- signedIn: Boolean(overview),
253
- }
254
- : null,
255
- models: managed ? null : localModelSettings(),
256
- /** Apple Intelligence on this Mac: offered where the machine can run it (harness/apple.ts). */
257
- apple: managed ? null : await appleStatus(),
258
- /** The AI clients this runtime can think with — installed or not, and how each is signed in. */
259
- harnesses: managed ? [] : await detectHarnesses(),
260
- /** Installed AI clients whose subscription can answer the studio chat. */
261
- subscriptions: managed ? [] : await subscriptionClients(),
262
- /** A runtime that runs alone keeps its setup in front until a test call has worked on the chosen source and the way is still open. */
263
- setupDone: managed ? true : await setupDone(),
264
- /** The cloud studio's first visit: the short wizard that names the team and fills the space (services/onboarding.ts). */
265
- onboarding: await needsOnboarding(user),
266
- /** What answers the studio chat: a model of class `highest`, or the admin's own subscription. */
267
- chatEngine: managed ? "models" : await chatEngine(await hasTextModel()),
268
- aiReady: (await hasTextModel()) || (!managed && (await subscriptionClients()).length > 0),
269
- mcpUrl: `${env.appUrl}/api/mcp`,
270
- /**
271
- * One project: the studio shows no project switcher; null: as many as wanted. `build:
272
- * false`: nothing is made or changed here; the studio shows what the person's local
273
- * install synced. `create`: the person makes and deletes here (builds, and is no mere
274
- * member). `members`: the people the plan allows, null for no limit.
275
- */
276
- limits: {
277
- projects: await projectLimitOrNull(),
278
- build: await mayBuild(),
279
- create: await mayCreate(),
280
- members: info?.limits.members ?? null,
281
- },
282
- });
283
- })
284
- // The team as the Manage-App keeps it: its people, who is invited, the places the plan gives.
285
- .get("/team", async (c) => {
286
- if (!managed) {
287
- return c.json({
288
- error: say(c, "onlyAvailableCloud"),
289
- code: "not_managed",
290
- }, 404);
291
- }
292
- const user = c.get("user");
293
- const [info, team] = await Promise.all([
294
- tenantInfo(user.tenantId).catch(() => null),
295
- tenantMembers(currentTenant()),
296
- ]);
297
- return c.json({
298
- ...team,
299
- plan: info?.plan ?? null,
300
- /** Where members are invited and roles changed: the account pages of the Manage-App. */
301
- manageUrl: env.manage.url,
302
- /** Whether this person manages the team there. */
303
- canManage: isAdminRole(user.role),
304
- });
305
- })
306
- // A runtime that runs alone says when a newer release is out and can run the update itself;
307
- // `?fresh=1` asks GitHub now instead of within the hour.
308
- .get("/update", async (c) => managed
309
- ? c.json({
310
- error: say(c, "onlyAvailableComputer"),
311
- code: "not_local",
312
- }, 404)
313
- : c.json(await updateStatus(c.req.query("fresh") === "1")))
314
- .post("/update", async (c) => {
315
- if (managed) {
316
- return c.json({
317
- error: say(c, "onlyAvailableComputer"),
318
- code: "not_local",
319
- }, 404);
320
- }
321
- applyUpdate();
322
- return c.json(await updateStatus());
323
- })
324
- .put("/profile", async (c) => c.json(await saveProfile(c.get("user"), profileSchema.parse(await c.req.json()))))
325
- .put("/lang", async (c) => {
326
- const { lang } = z.object({ lang: z.enum(LANGS) }).parse(await c.req.json());
327
- await saveUserLang(c.get("user"), lang);
328
- return c.json({ lang });
329
- })
330
- // --- the studio's assistant -------------------------------------------------
331
- // One open chat per person and tenant, on every page; turns stream as SSE events shaped like
332
- // AG-UI's (packages/shared/src/assistant.ts).
333
- .get("/assistant/chat", async (c) => c.json(await currentChat(c.get("user"))))
334
- .post("/assistant/chat/new", async (c) => c.json(await newChat(c.get("user"))))
335
- .get("/assistant/chats", async (c) => c.json({ chats: await earlierChats(c.get("user")) }))
336
- .get("/assistant/chats/:id", async (c) => c.json(await readChat(c.get("user"), c.req.param("id"))))
337
- .get("/assistant/layout", async (c) => c.json({ layout: await assistantLayout(c.get("user")) }))
338
- .put("/assistant/layout", async (c) => {
339
- const { layout } = z.object({ layout: z.enum(ASSISTANT_LAYOUTS) }).parse(await c.req.json());
340
- await writeSetting(`assistant-layout:${c.get("user").tenantId}:${c.get("user").id}`, layout);
341
- return c.json({ layout });
342
- })
343
- // Live chat reads answers aloud with the speech model where one is set up; else the browser's voices.
344
- .get("/assistant/voice", async (c) => c.json({ way: (await classWays()).speech.kind }))
345
- .post("/assistant/speak", async (c) => {
346
- const { text } = z.object({ text: z.string().min(1).max(4000) }).parse(await c.req.json());
347
- if ((await classWays()).speech.kind === "none") {
348
- throw new ServiceError("refused", note("noLanguageModelSet"));
349
- }
350
- if (!(await canSpend())) {
351
- throw new ServiceError("no_credits", note("creditsUsedUp"));
352
- }
353
- const voice = await generateSpeechMedia({ text, abortSignal: c.req.raw.signal });
354
- return c.body(new Uint8Array(voice.bytes), 200, { "content-type": voice.mime });
355
- })
356
- // A message written while a turn runs: the turn takes it before its next step or after its answer.
357
- .post("/assistant/run/:runId/signal", async (c) => {
358
- const body = assistantSignalSchema.parse(await c.req.json());
359
- const taken = signalRun(c.get("user").id, c.req.param("runId"), body);
360
- return c.json({ ok: taken }, taken ? 200 : 404);
361
- })
362
- // A browser tool's result: the turn that waits for it goes on.
363
- .post("/assistant/tool/:callId", async (c) => {
364
- const body = z.object({ result: z.unknown() }).parse(await c.req.json());
365
- const taken = answerBrowser(c.get("user").id, c.req.param("callId"), body.result ?? null);
366
- return c.json({ ok: taken }, taken ? 200 : 404);
367
- })
368
- .post("/assistant/turn", async (c) => {
369
- const user = c.get("user");
370
- const body = assistantTurnSchema
371
- .extend({ lang: z.enum(LANGS).default("en") })
372
- .parse(await c.req.json());
373
- if (!(await canSpend())) {
374
- throw new ServiceError("no_credits", note("creditsUsedUp"));
375
- }
376
- const project = body.projectId ? await ownedProject(user.id, body.projectId) : null;
377
- const writable = project ? await projectWritable(project) : false;
378
- // The page's snapshot is cut, not refused: a page that says too much still gets an answer.
379
- const page = body.page && JSON.stringify(body.page).length > ASSISTANT_PAGE_BYTES
380
- ? { route: body.page.route, title: body.page.title, view: body.page.view }
381
- : (body.page ?? null);
382
- const chat = await openChat(user);
383
- const debug = Boolean(body.debug) && (await assistantDevFor(user));
384
- let history = await turnHistory(user, chat);
385
- const runId = nanoid(10);
386
- const userMessageId = await addMessage(chat.id, {
387
- role: "user",
388
- content: body.message,
389
- page: page ? { route: page.route, title: page.title } : null,
390
- });
391
- startRun(runId, user.id);
392
- return streamSSE(c, async (stream) => {
393
- const abort = new AbortController();
394
- stream.onAbort(() => abort.abort());
395
- const send = (event, data) => stream.writeSSE({ event, data: JSON.stringify(data) });
396
- let messageId = nanoid(14);
397
- await send("run_started", { threadId: chat.id, runId, messageId: userMessageId });
398
- // The answer's text since the last message written meanwhile.
399
- let reply = "";
400
- let changed = false;
401
- let steps = 0;
402
- /** What the answer said and did up to messages written meanwhile; null when nothing. */
403
- const storePart = async (before) => {
404
- changed ||= before.changed;
405
- return before.reply || before.toolCalls.length || before.cards.length
406
- ? await addMessage(chat.id, { role: "assistant", content: before.reply, ...before })
407
- : null;
408
- };
409
- /** The messages written meanwhile, after the part of the answer before them. */
410
- const storeSignals = async (taken, answerId) => {
411
- for (const [i, s] of taken.entries()) {
412
- const stored = await addMessage(chat.id, { role: "user", content: s.message });
413
- await send("signal", {
414
- ref: s.ref,
415
- messageId: stored,
416
- content: s.message,
417
- answerId: i === 0 ? answerId : null,
418
- });
419
- }
420
- reply = "";
421
- messageId = nanoid(14);
422
- };
423
- try {
424
- let message = body.message;
425
- for (;;) {
426
- const result = await runStudioAssistant({
427
- user,
428
- chat,
429
- history,
430
- project,
431
- writable,
432
- message,
433
- page,
434
- browserTools: body.tools,
435
- lang: body.lang,
436
- signal: abort.signal,
437
- onText: (delta) => {
438
- reply += delta;
439
- void send("text", { messageId, delta });
440
- },
441
- onActivity: (label) => void send("activity", { label }),
442
- onChanged: () => void send("changed", {}),
443
- onCard: (card) => void send("card", card),
444
- onToolCall: (call) => void send("tool_call", call),
445
- onToolResult: (result) => void send("tool_result", result),
446
- callBrowser: (call) => awaitBrowser(user.id, call.toolCallId, abort.signal),
447
- takeSignals: () => takeSignals(runId),
448
- onSignal: async (taken, before) => storeSignals(taken, await storePart(before)),
449
- ...(debug
450
- ? {
451
- onPrompt: (prompt) => void send("prompt", prompt),
452
- onStep: (step) => void send("step", { ...step, step: ++steps }),
453
- }
454
- : {}),
455
- });
456
- // Written after the answer's last step: the turn goes on with it.
457
- const left = takeSignals(runId);
458
- if (!left.length || abort.signal.aborted) {
459
- changed ||= result.changed;
460
- reply = result.reply || (changed ? serverText(body.lang, "done") : "");
461
- const stored = await addMessage(chat.id, {
462
- role: "assistant",
463
- content: reply,
464
- cards: result.cards,
465
- toolCalls: result.toolCalls,
466
- changed: result.changed,
467
- });
468
- await send("done", { messageId: stored, reply, changed });
469
- break;
470
- }
471
- // The next answer knows this one: it is stored before the history is read again.
472
- const answerId = await storePart(result);
473
- history = await turnHistory(user, chat);
474
- await storeSignals(left, answerId);
475
- message = signalText(left);
476
- }
477
- }
478
- catch (err) {
479
- console.error("[studio-assistant]", err);
480
- if (reply.trim()) {
481
- await addMessage(chat.id, { role: "assistant", content: reply.trim() }).catch(() => null);
482
- }
483
- await send("error", {
484
- message: err instanceof ServiceError || err instanceof ModelUnavailableError
485
- ? errorText(err, body.lang)
486
- : serverText(body.lang, "somethingWrong"),
487
- });
488
- }
489
- endRun(runId);
490
- // Older messages fold into the chat's running summary once enough have piled up.
491
- void foldChat(chat.id).catch((err) => console.error("[studio-assistant] fold:", err));
492
- });
493
- })
494
- // --- projects --------------------------------------------------------------
495
- .get("/projects", async (c) => {
496
- const projects = await listProjects(c.get("user").id, requestLang(c));
497
- const build = await mayBuild();
498
- return c.json(projects.map((p) => ({
499
- id: p.id,
500
- name: p.name,
501
- brand: p.brand,
502
- facts: p.facts,
503
- mcpServers: maskedServers(p),
504
- wizardCount: p.wizardCount,
505
- /** `local`: synced from a local install, where it is changed. */
506
- origin: p.origin,
507
- syncedAt: p.syncedAt?.toISOString() ?? null,
508
- readOnly: p.origin === "local" || !build,
509
- })));
510
- })
511
- .post("/projects", async (c) => {
512
- const body = z.object({ name: z.string().min(1).max(80) }).parse(await c.req.json());
513
- return c.json(await createProject(c.get("user").id, body.name));
514
- })
515
- .patch("/projects/:id", async (c) => {
516
- const patch = projectPatchSchema.parse(await c.req.json());
517
- await updateProject(c.get("user").id, c.req.param("id"), patch);
518
- return c.json({ ok: true });
519
- })
520
- // --- what a project holds for all its wizards: logos, assets, documents -------
521
- .get("/projects/:id/files", async (c) => {
522
- const project = await ownedProject(c.get("user").id, c.req.param("id"));
523
- return c.json({
524
- files: (await projectFiles(project.id)).map(fileView),
525
- /** Whether documents get vectors, or the index works on keywords alone. */
526
- embeddings: Boolean(await embeddingModel().catch(() => null)),
527
- });
528
- })
529
- .post("/projects/:id/files", async (c) => {
530
- const project = await ownedProject(c.get("user").id, c.req.param("id"));
531
- const kind = z.enum(PROJECT_FILE_KINDS).parse(c.req.query("kind"));
532
- const file = (await c.req.formData()).get("file");
533
- if (!(file instanceof File)) {
534
- throw new ServiceError("invalid", note("chooseFile"));
535
- }
536
- const row = await addProjectFile(project.id, {
537
- kind,
538
- name: file.name,
539
- mime: file.type.split(";")[0].trim().toLowerCase(),
540
- data: new Uint8Array(await file.arrayBuffer()),
541
- });
542
- return c.json(fileView(row));
543
- })
544
- .post("/projects/:id/files/url", async (c) => {
545
- const project = await ownedProject(c.get("user").id, c.req.param("id"));
546
- const input = z
547
- .object({ url: z.string().min(1).max(500_000), kind: z.enum(PROJECT_FILE_KINDS) })
548
- .parse(await c.req.json());
549
- const url = /^(https?:\/\/|data:)/i.test(input.url) ? input.url : `https://${input.url}`;
550
- try {
551
- return c.json({ file: fileView(await addProjectFileFromUrl(project.id, { ...input, url })) });
552
- }
553
- catch (err) {
554
- // A web page where a logo or an asset was asked for: its logos or pictures, to pick from.
555
- if (err instanceof ServiceError && err.data.reason === "page") {
556
- const page = String(err.data.url ?? url);
557
- const scan = input.kind === "logo" ? scanLogos : scanImages;
558
- return c.json({ candidates: await scan(page) });
559
- }
560
- throw err;
561
- }
562
- })
563
- .post("/projects/:id/colors/scan", async (c) => {
564
- await ownedProject(c.get("user").id, c.req.param("id"));
565
- const { url } = z.object({ url: z.string().min(1).max(2000) }).parse(await c.req.json());
566
- const colors = await scanColors(url).catch(() => {
567
- throw new ServiceError("invalid", note("pageNotReached"));
568
- });
569
- return c.json({ colors });
570
- })
571
- // A gradient from the admin's words, or theirs changed as they say. Nothing is saved.
572
- .post("/projects/:id/gradients/describe", async (c) => {
573
- const project = await ownedProject(c.get("user").id, c.req.param("id"));
574
- const { text, gradient } = z
575
- .object({
576
- text: z.string().trim().min(1).max(1000),
577
- gradient: gradientSchema
578
- .pick({ name: true, type: true, angle: true, stops: true })
579
- .optional(),
580
- })
581
- .parse(await c.req.json());
582
- if (!(await canSpend())) {
583
- throw new ServiceError("no_credits", note("creditsUsedUp"));
584
- }
585
- try {
586
- return c.json({
587
- gradient: await describeGradient(project.brand.colors ?? [], text, gradient),
588
- });
589
- }
590
- catch (err) {
591
- if (err instanceof ModelUnavailableError) {
592
- throw new ServiceError("refused", saidOf(err));
593
- }
594
- throw err;
595
- }
596
- })
597
- .post("/projects/:id/fonts/scan", async (c) => {
598
- await ownedProject(c.get("user").id, c.req.param("id"));
599
- const { url } = z.object({ url: z.string().min(1).max(2000) }).parse(await c.req.json());
600
- const fonts = await scanFonts(url).catch(() => {
601
- throw new ServiceError("invalid", note("pageNotReached"));
602
- });
603
- return c.json({ fonts });
604
- })
605
- .put("/projects/:id/files/order", async (c) => {
606
- const project = await ownedProject(c.get("user").id, c.req.param("id"));
607
- const body = z
608
- .object({ kind: z.enum(PROJECT_FILE_KINDS), ids: z.array(z.string()).max(200) })
609
- .parse(await c.req.json());
610
- await orderProjectFiles(project.id, body.kind, body.ids);
611
- return c.json({ ok: true });
612
- })
613
- .patch("/projects/:id/files/:fileId", async (c) => {
614
- const project = await ownedProject(c.get("user").id, c.req.param("id"));
615
- const patch = z
616
- .object({ name: z.string().max(120).optional(), description: z.string().max(600).optional() })
617
- .parse(await c.req.json());
618
- return c.json(fileView(await updateProjectFile(project.id, c.req.param("fileId"), patch)));
619
- })
620
- .post("/projects/:id/files/:fileId/reindex", async (c) => {
621
- const project = await ownedProject(c.get("user").id, c.req.param("id"));
622
- return c.json(fileView(await reindexProjectFile(project.id, c.req.param("fileId"))));
623
- })
624
- .delete("/projects/:id/files/:fileId", async (c) => {
625
- const project = await ownedProject(c.get("user").id, c.req.param("id"));
626
- await removeProjectFile(project.id, c.req.param("fileId"));
627
- return c.json({ ok: true });
628
- })
629
- .get("/projects/:id/files/:fileId/content", async (c) => {
630
- const project = await ownedProject(c.get("user").id, c.req.param("id"));
631
- const { row, data } = await projectFileContent(project.id, c.req.param("fileId"));
632
- const headers = {
633
- "content-type": row.mime,
634
- "cache-control": "private, max-age=3600",
635
- "x-content-type-options": "nosniff",
636
- // An uploaded SVG or HTML file is shown, never run. A PDF is left to the browser's own
637
- // viewer, which a sandbox would keep from starting.
638
- ...(row.mime === "application/pdf" ? {} : { "content-security-policy": "sandbox" }),
639
- };
640
- if (/^(audio|video)\//.test(row.mime)) {
641
- headers["accept-ranges"] = "bytes";
642
- const range = byteRange(c.req.header("range"), data.byteLength);
643
- if (range === "unsatisfiable") {
644
- return c.body(null, 416, { "content-range": `bytes */${data.byteLength}` });
645
- }
646
- if (range) {
647
- headers["content-range"] = `bytes ${range.start}-${range.end}/${data.byteLength}`;
648
- return c.body(new Uint8Array(data.subarray(range.start, range.end + 1)), 206, headers);
649
- }
650
- }
651
- return c.body(new Uint8Array(data), 200, headers);
652
- })
653
- // A document as the models read it: its text as Markdown, or the start of it.
654
- .get("/projects/:id/files/:fileId/text", async (c) => {
655
- const project = await ownedProject(c.get("user").id, c.req.param("id"));
656
- const row = await projectFile(project.id, c.req.param("fileId"));
657
- const limit = z.coerce
658
- .number()
659
- .int()
660
- .min(100)
661
- .max(400_000)
662
- .catch(200_000)
663
- .parse(c.req.query("limit"));
664
- const text = await documentText(row);
665
- return c.json({ text: text.slice(0, limit), chars: text.length });
666
- })
667
- // What a search of Knowledge finds for a question: the items an agent step would get.
668
- .post("/projects/:id/search", async (c) => {
669
- const project = await ownedProject(c.get("user").id, c.req.param("id"));
670
- const body = z
671
- .object({ query: z.string().min(1).max(400), where: whereSchema.optional() })
672
- .parse(await c.req.json());
673
- return c.json(await searchKnowledge(project.id, body.query, { where: body.where }));
674
- })
675
- .delete("/projects/:id", async (c) => {
676
- await deleteProject(c.get("user").id, c.req.param("id"));
677
- return c.json({ ok: true });
678
- })
679
- // --- connectors: services imported from the integrations registry ------------
680
- .post("/connectors/search", async (c) => {
681
- const { query } = z.object({ query: z.string().min(1).max(200) }).parse(await c.req.json());
682
- return c.json(await searchRegistry(query));
683
- })
684
- .get("/connectors/registry/:domain", async (c) => c.json(await registryService(c.req.param("domain"))))
685
- .post("/connectors/preview", async (c) => {
686
- const body = z
687
- .object({
688
- domain: z.string().min(1).max(253).optional(),
689
- sourceKind: z.enum(["openapi", "mcp"]),
690
- sourceUrl: z.string().url(),
691
- })
692
- .parse(await c.req.json());
693
- return c.json(await previewSource(body));
694
- })
695
- .get("/projects/:id/connectors", async (c) => {
696
- const project = await ownedProject(c.get("user").id, c.req.param("id"));
697
- return c.json(await listConnectors(project.id));
698
- })
699
- .post("/projects/:id/connectors", async (c) => {
700
- const user = c.get("user");
701
- const project = await ownedProject(user.id, c.req.param("id"));
702
- return c.json(await importConnector(user.id, project.id, connectorImportSchema.parse(await c.req.json())));
703
- })
704
- .post("/projects/:id/connectors/:connectorId/refresh", async (c) => {
705
- const project = await ownedProject(c.get("user").id, c.req.param("id"));
706
- return c.json(await refreshConnector(project.id, c.req.param("connectorId"), null));
707
- })
708
- .delete("/projects/:id/connectors/:connectorId", async (c) => {
709
- const project = await ownedProject(c.get("user").id, c.req.param("id"));
710
- await removeConnector(project.id, c.req.param("connectorId"));
711
- return c.json({ ok: true });
712
- })
713
- // The runs of the space's wizards that reached their result: of one wizard, or of all.
714
- .get("/projects/:id/results", async (c) => {
715
- const project = await ownedProject(c.get("user").id, c.req.param("id"));
716
- const query = z
717
- .object({
718
- wizard: z.string().optional(),
719
- q: z.string().max(200).optional(),
720
- mode: z.enum(["live", "test"]).optional(),
721
- days: z.coerce.number().int().min(1).max(3650).optional(),
722
- })
723
- .parse(c.req.query());
724
- return c.json(await listResults(project.id, {
725
- wizardId: query.wizard || undefined,
726
- q: query.q,
727
- mode: query.mode,
728
- days: query.days,
729
- }));
730
- })
731
- // --- Knowledge: its items and categories ------------------------------------
732
- .get("/projects/:id/knowledge", async (c) => c.json(await listKnowledge(c.get("user").id, c.req.param("id"))))
733
- // What a link in a page names (`pages/bgb/p-281`): the studio opens it.
734
- .get("/projects/:id/resolve", async (c) => {
735
- const project = await ownedProject(c.get("user").id, c.req.param("id"));
736
- const found = await resolvePath(project.id, z.string().max(600).parse(c.req.query("path")));
737
- if (!found) {
738
- throw notFound();
739
- }
740
- return c.json(found);
741
- })
742
- .post("/projects/:id/categories", async (c) => {
743
- const project = await ownedProject(c.get("user").id, c.req.param("id"));
744
- await requireWritable(project);
745
- const body = z
746
- .object({
747
- name: z.string().min(1).max(80),
748
- type: z.enum(CATEGORY_TYPES),
749
- unit: z.string().max(20).nullish(),
750
- multiple: z.boolean().optional(),
751
- ordered: z.boolean().optional(),
752
- hint: z.string().max(120).nullish(),
753
- values: z.array(z.string().max(200)).max(200).optional(),
754
- tableId: z.string().nullish(),
755
- columnId: z.string().nullish(),
756
- })
757
- .parse(await c.req.json());
758
- const row = await putCategory(project.id, body);
759
- return c.json({ id: row.id });
760
- })
761
- .patch("/categories/:id", async (c) => {
762
- const row = await categoryRow(c.req.param("id"));
763
- await ownedProject(c.get("user").id, row.projectId);
764
- const body = z
765
- .object({
766
- name: z.string().min(1).max(80).optional(),
767
- unit: z.string().max(20).nullish(),
768
- multiple: z.boolean().optional(),
769
- ordered: z.boolean().optional(),
770
- hint: z.string().max(120).nullish(),
771
- proposed: z.literal(false).optional(),
772
- position: z.number().int().min(0).optional(),
773
- })
774
- .parse(await c.req.json());
775
- await updateCategory(row.id, body);
776
- return c.json({ ok: true });
777
- })
778
- .delete("/categories/:id", async (c) => {
779
- const row = await categoryRow(c.req.param("id"));
780
- await ownedProject(c.get("user").id, row.projectId);
781
- await deleteCategory(row.id);
782
- return c.json({ ok: true });
783
- })
784
- .post("/categories/:id/values", async (c) => {
785
- const row = await categoryRow(c.req.param("id"));
786
- await ownedProject(c.get("user").id, row.projectId);
787
- const { value } = z.object({ value: z.string().min(1).max(200) }).parse(await c.req.json());
788
- return c.json(await addCategoryValue(row.id, value));
789
- })
790
- .put("/categories/:id/values/order", async (c) => {
791
- const row = await categoryRow(c.req.param("id"));
792
- await ownedProject(c.get("user").id, row.projectId);
793
- const { ids } = z.object({ ids: z.array(z.string()).max(500) }).parse(await c.req.json());
794
- await orderCategoryValues(row.id, ids);
795
- return c.json({ ok: true });
796
- })
797
- .get("/values/:id", async (c) => c.json(await valueContents(c.get("user").id, c.req.param("id"))))
798
- // Everything that has a category: the entries its page lists.
799
- .get("/categories/:id/items", async (c) => c.json(await categoryContents(c.get("user").id, c.req.param("id"))))
800
- .patch("/values/:id", async (c) => {
801
- const { category } = await categoryValue(c.req.param("id"));
802
- await ownedProject(c.get("user").id, category.projectId);
803
- const { value } = z.object({ value: z.string().min(1).max(200) }).parse(await c.req.json());
804
- await renameCategoryValue(c.req.param("id"), value);
805
- return c.json({ ok: true });
806
- })
807
- .post("/values/:id/merge", async (c) => {
808
- const { category } = await categoryValue(c.req.param("id"));
809
- await ownedProject(c.get("user").id, category.projectId);
810
- const { into } = z.object({ into: z.string() }).parse(await c.req.json());
811
- await mergeCategoryValues(c.req.param("id"), into);
812
- return c.json({ ok: true });
813
- })
814
- .delete("/values/:id", async (c) => {
815
- const { category } = await categoryValue(c.req.param("id"));
816
- await ownedProject(c.get("user").id, category.projectId);
817
- await deleteCategoryValue(c.req.param("id"));
818
- return c.json({ ok: true });
819
- })
820
- // The summary of a value: a model writes it from the value's items.
821
- .post("/values/:id/summary", async (c) => {
822
- const { category } = await categoryValue(c.req.param("id"));
823
- const project = await ownedProject(c.get("user").id, category.projectId);
824
- await requireWritable(project);
825
- return c.json({ summary: await writeSummary(c.req.param("id")) });
826
- })
827
- // A category a person sets on an item: `p:<page>`, `t:<table>`, `r:<row>`, `f:<file>`.
828
- .put("/projects/:id/items/:key/categories/:categoryId", async (c) => {
829
- const project = await ownedProject(c.get("user").id, c.req.param("id"));
830
- await requireWritable(project);
831
- const key = c.req.param("key");
832
- const id = key.slice(2);
833
- const ref = key[0] === "p"
834
- ? { pageId: id }
835
- : key[0] === "t"
836
- ? { tableId: id }
837
- : key[0] === "r"
838
- ? { rowId: id }
839
- : key[0] === "f"
840
- ? { fileId: id }
841
- : null;
842
- if (!ref || key[1] !== ":") {
843
- throw new ServiceError("invalid", note("unknownEntry"));
844
- }
845
- const { values } = z
846
- .object({ values: z.array(z.union([z.string().max(300), z.number(), z.boolean()])).max(50) })
847
- .parse(await c.req.json());
848
- if (await setItemCategory(project.id, ref, c.req.param("categoryId"), values)) {
849
- queueIndex(key[0] === "p" ? `P:${id}` : key);
850
- }
851
- return c.json({ ok: true });
852
- })
853
- // --- the space's tables and pages --------------------------------------------
854
- .get("/projects/:id/data", async (c) => c.json(await listSpaceData(c.get("user").id, c.req.param("id"))))
855
- .post("/projects/:id/tables", async (c) => {
856
- const body = z
857
- .object({
858
- title: z.string().max(120),
859
- wizardId: z.string().nullish(),
860
- columns: z.unknown().optional(),
861
- format: z.enum(["faq"]).nullish(),
862
- })
863
- .parse(await c.req.json());
864
- return c.json(await createTable(c.get("user").id, c.req.param("id"), body, requestLang(c)));
865
- })
866
- .get("/tables/:id", async (c) => c.json(await getTable(c.get("user").id, c.req.param("id"))))
867
- .patch("/tables/:id", async (c) => {
868
- const body = z
869
- .object({
870
- title: z.string().max(120).optional(),
871
- wizardId: z.string().nullish(),
872
- columns: z.unknown().optional(),
873
- format: z.enum(["faq"]).nullish(),
874
- review: z.null().optional(),
875
- })
876
- .parse(await c.req.json());
877
- await updateTable(c.get("user").id, c.req.param("id"), body);
878
- return c.json({ ok: true });
879
- })
880
- .delete("/tables/:id", async (c) => {
881
- await deleteTable(c.get("user").id, c.req.param("id"));
882
- return c.json({ ok: true });
883
- })
884
- .post("/tables/:id/rows", async (c) => {
885
- const body = z
886
- .object({ cells: z.record(z.string(), z.unknown()).optional() })
887
- .parse(await c.req.json());
888
- return c.json(await addTableRow(c.get("user").id, c.req.param("id"), body.cells));
889
- })
890
- .patch("/tables/:id/rows/:rowId", async (c) => {
891
- const body = z.object({ cells: z.record(z.string(), z.unknown()) }).parse(await c.req.json());
892
- return c.json(await updateTableRow(c.get("user").id, c.req.param("id"), c.req.param("rowId"), body.cells));
893
- })
894
- .post("/tables/:id/rows/delete", async (c) => {
895
- const body = z.object({ ids: z.array(z.string()).max(5000) }).parse(await c.req.json());
896
- await deleteTableRows(c.get("user").id, c.req.param("id"), body.ids);
897
- return c.json({ ok: true });
898
- })
899
- .post("/projects/:id/pages", async (c) => {
900
- const body = z
901
- .object({
902
- title: z.string().max(200),
903
- wizardId: z.string().nullish(),
904
- parentId: z.string().nullish(),
905
- markdown: z.string().optional(),
906
- })
907
- .parse(await c.req.json());
908
- return c.json(await createPage(c.get("user").id, c.req.param("id"), body));
909
- })
910
- .get("/pages/:id", async (c) => c.json(await getPage(c.get("user").id, c.req.param("id"))))
911
- .patch("/pages/:id", async (c) => {
912
- const body = z
913
- .object({
914
- title: z.string().max(200).optional(),
915
- wizardId: z.string().nullish(),
916
- parentId: z.string().nullish(),
917
- markdown: z.string().optional(),
918
- review: z.null().optional(),
919
- })
920
- .parse(await c.req.json());
921
- await updatePage(c.get("user").id, c.req.param("id"), body);
922
- return c.json({ ok: true });
923
- })
924
- .put("/pages/:id/order", async (c) => {
925
- const { ids } = z.object({ ids: z.array(z.string()).max(5000) }).parse(await c.req.json());
926
- await orderSubPages(c.get("user").id, c.req.param("id"), ids);
927
- return c.json({ ok: true });
928
- })
929
- .delete("/pages/:id", async (c) => {
930
- await deletePage(c.get("user").id, c.req.param("id"));
931
- return c.json({ ok: true });
932
- })
933
- // --- wizards ---------------------------------------------------------------
934
- .get("/projects/:id/wizards", async (c) => {
935
- const user = c.get("user");
936
- await ownedProject(user.id, c.req.param("id"));
937
- const wizards = await listWizards(user.id, c.req.param("id"));
938
- // A local install with an account: where each wizard stands in its cloud, for the cards.
939
- const linked = await cloudLinked();
940
- return c.json(await Promise.all(wizards.map(async (w) => ({ ...w, cloud: linked ? await cloudState(w.id) : null }))));
941
- })
942
- .post("/wizards", async (c) => {
943
- const body = z
944
- .object({
945
- projectId: z.string(),
946
- starterId: z.string().optional(),
947
- lang: z.string().optional(),
948
- })
949
- .parse(await c.req.json());
950
- const { id } = await createWizard(c.get("user").id, body);
951
- return c.json({ id });
952
- })
953
- // A wizard as a file, and a new wizard made of such a file.
954
- .post("/projects/:id/wizards/import", async (c) => {
955
- const file = (await c.req.formData()).get("file");
956
- if (!(file instanceof File) || !file.size || file.size > PACKAGE_MAX_BYTES) {
957
- throw new ServiceError("invalid", note("chooseWizardFileMb", { PACKAGE_EXTENSION }));
958
- }
959
- return c.json(await importWizard(c.get("user").id, c.req.param("id"), new Uint8Array(await file.arrayBuffer()), file.name, requestLang(c)));
960
- })
961
- .get("/wizards/:id/export", async (c) => {
962
- const found = await exportWizard(c.get("user").id, c.req.param("id"), {
963
- published: c.req.query("published") === "1",
964
- knowledge: c.req.query("knowledge") === "1",
965
- });
966
- if (!found) {
967
- return c.json({
968
- error: say(c, "wizardNotPublishedYet"),
969
- }, 404);
970
- }
971
- const { name, zip } = found;
972
- return c.body(new Uint8Array(zip), 200, {
973
- "content-type": PACKAGE_MIME,
974
- "content-disposition": `attachment; filename="${name}"`,
975
- "cache-control": "private, no-store",
976
- });
977
- })
978
- .get("/wizards/:id", async (c) => {
979
- const user = c.get("user");
980
- const w = await ownedWizard(user.id, c.req.param("id"));
981
- const messages = await wizardMessages(w.id);
982
- const project = await ownedProject(user.id, w.projectId);
983
- return c.json({
984
- ...(await wizardState(w)),
985
- /** Shown and run here, changed elsewhere: a local install's wizard, or nothing is built here. */
986
- readOnly: !(await projectWritable(project)),
987
- blank: messages.length === 0 && !w.starter,
988
- messages: messages.map((m) => ({
989
- id: m.id,
990
- role: m.role,
991
- content: m.content,
992
- changed: m.changed,
993
- source: m.source,
994
- client: m.client,
995
- })),
996
- mcpServers: project.mcpServers.map((s) => ({ id: s.id, name: s.name })),
997
- });
998
- })
999
- .put("/wizards/:id/draft", async (c) => {
1000
- const body = z
1001
- .object({ definition: z.unknown(), baseRevision: z.number().int().min(0) })
1002
- .parse(await c.req.json());
1003
- const { revision, issues } = await writeDraft(c.get("user").id, c.req.param("id"), body);
1004
- return c.json({ ok: true, revision, issues });
1005
- })
1006
- .patch("/wizards/:id", async (c) => {
1007
- const patch = z
1008
- .object({
1009
- shareEnabled: z.boolean().optional(),
1010
- dailyRunLimit: z.number().int().min(1).max(10_000).optional(),
1011
- projectId: z.string().optional(),
1012
- runners: z.object({ default: z.string(), enabled: z.array(z.string()).max(20) }).optional(),
1013
- translate: z.boolean().optional(),
1014
- })
1015
- .parse(await c.req.json());
1016
- await updateWizardSettings(c.get("user").id, c.req.param("id"), patch);
1017
- // The copy in the cloud of a linked account is shared the same way.
1018
- if (patch.shareEnabled !== undefined ||
1019
- patch.dailyRunLimit !== undefined ||
1020
- patch.runners !== undefined ||
1021
- patch.translate !== undefined) {
1022
- await pushSharing(c.get("user").id, c.req.param("id"));
1023
- }
1024
- return c.json({ ok: true });
1025
- })
1026
- // The languages the published wizard is kept in, each original text with its translation.
1027
- .get("/wizards/:id/translations", async (c) => {
1028
- const w = await ownedWizard(c.get("user").id, c.req.param("id"));
1029
- const def = await publishedDefinition(w);
1030
- const kept = await translationsOf(w.id);
1031
- return c.json({
1032
- lang: def ? wizardLang(def) : wizardLang(w.draft),
1033
- texts: def ? wizardTexts(def) : [],
1034
- translations: kept.map((t) => ({
1035
- lang: t.lang,
1036
- texts: t.texts,
1037
- updatedAt: t.updatedAt.toISOString(),
1038
- })),
1039
- });
1040
- })
1041
- // The author's own lines for a language: they replace what a model wrote.
1042
- .put("/wizards/:id/translations/:lang", async (c) => {
1043
- const w = await writableWizard(c.get("user").id, c.req.param("id"));
1044
- const def = await publishedDefinition(w);
1045
- const lang = c.req.param("lang");
1046
- if (!(def && isLangCode(lang))) {
1047
- return c.json(notFoundAnswer(c), 404);
1048
- }
1049
- const { lines } = z
1050
- .object({ lines: z.record(z.string(), z.string().max(4000)) })
1051
- .parse(await c.req.json());
1052
- await editTranslation(w.id, def, lang, lines);
1053
- return c.json({ ok: true });
1054
- })
1055
- .delete("/wizards/:id/translations/:lang", async (c) => {
1056
- const w = await writableWizard(c.get("user").id, c.req.param("id"));
1057
- await deleteTranslation(w.id, c.req.param("lang"));
1058
- return c.json({ ok: true });
1059
- })
1060
- // The wizard's ID for the mobile app, beside its link.
1061
- .get("/wizards/:id/code", async (c) => {
1062
- const w = await ownedWizard(c.get("user").id, c.req.param("id"));
1063
- return c.json({ code: await codeOf(w.shareToken) });
1064
- })
1065
- // A new link here, and for the copy in the cloud of a linked account: the old ones stop.
1066
- .post("/wizards/:id/rotate-link", async (c) => {
1067
- const rotated = await rotateShareLink(c.get("user").id, c.req.param("id"));
1068
- const cloud = managed ? null : await rotateInCloud(c.get("user").id, c.req.param("id"));
1069
- return c.json({ ...rotated, cloud });
1070
- })
1071
- .post("/wizards/:id/duplicate", async (c) => c.json(await duplicateWizard(c.get("user").id, c.req.param("id"))))
1072
- .delete("/wizards/:id", async (c) => {
1073
- if (!managed) {
1074
- await removeFromCloud(c.get("user").id, c.req.param("id"));
1075
- }
1076
- await deleteWizard(c.get("user").id, c.req.param("id"));
1077
- return c.json({ ok: true });
1078
- })
1079
- // With an account linked the published version also goes to its cloud: `cloud` says how that went.
1080
- .post("/wizards/:id/publish", async (c) => c.json(await publishAndSync(c.get("user").id, c.req.param("id"))))
1081
- // What publishing the draft would change: the steps and files, its last test, the cost of a run before and after.
1082
- .get("/wizards/:id/changes", async (c) => {
1083
- const w = await ownedWizard(c.get("user").id, c.req.param("id"));
1084
- const { published, ...found } = await draftChanges(w);
1085
- const cost = async (def) => estimateRun(w.id, null, def, await stepsWithoutModel(def));
1086
- const [before, after] = published ? await Promise.all([cost(published), cost(w.draft)]) : [];
1087
- return c.json({
1088
- ...found,
1089
- cost: before?.available && after?.available
1090
- ? { before: before.credits, after: after.credits }
1091
- : null,
1092
- });
1093
- })
1094
- // What a run of the draft is expected to cost, per step and in total.
1095
- .get("/wizards/:id/estimate", async (c) => {
1096
- const w = await ownedWizard(c.get("user").id, c.req.param("id"));
1097
- return c.json(await estimateRun(w.id, null, w.draft, await stepsWithoutModel(w.draft)));
1098
- })
1099
- // The runners this tenant has: the home's channel filter and the icons on its cards.
1100
- .get("/runners", async (c) => c.json(await runnersOf()))
1101
- // The runners this tenant has, how each fits the draft, and how the wizard is offered.
1102
- .get("/wizards/:id/runners", async (c) => {
1103
- const w = await ownedWizard(c.get("user").id, c.req.param("id"));
1104
- return c.json(await wizardRunners(w));
1105
- })
1106
- // The models the draft needs that this runtime cannot serve, by class, with the steps that call them.
1107
- .get("/wizards/:id/models", async (c) => {
1108
- const w = await ownedWizard(c.get("user").id, c.req.param("id"));
1109
- return c.json({ missing: await missingModels(w.draft, requestLang(c)) });
1110
- })
1111
- // A runtime that runs alone: the wizard's copy in the cloud of the linked account.
1112
- .get("/wizards/:id/cloud", async (c) => {
1113
- const w = await ownedWizard(c.get("user").id, c.req.param("id"));
1114
- const linked = await cloudLinked();
1115
- return c.json({ linked, ...(linked ? await cloudState(w.id) : { copy: null, error: null }) });
1116
- })
1117
- // Sends the published version again: after a try that failed, or a change of the project.
1118
- .post("/wizards/:id/cloud", async (c) => {
1119
- if (!(await cloudLinked())) {
1120
- return c.notFound();
1121
- }
1122
- return c.json({
1123
- linked: true,
1124
- ...(await syncToCloud(c.get("user").id, c.req.param("id"))),
1125
- });
1126
- })
1127
- // What the cloud would lack for the draft, before it is published.
1128
- .get("/wizards/:id/cloud/check", async (c) => {
1129
- if (!(await cloudLinked())) {
1130
- return c.notFound();
1131
- }
1132
- return c.json(await checkForCloud(c.get("user").id, c.req.param("id")));
1133
- })
1134
- // The projects of local installs the account's cloud holds.
1135
- .get("/cloud/spaces", async (c) => {
1136
- if (!(await cloudLinked())) {
1137
- return c.notFound();
1138
- }
1139
- return c.json({ spaces: await cloudSpaces() });
1140
- })
1141
- // Another install's project is in the way: it goes, and what is published here is sent.
1142
- .post("/cloud/replace", async (c) => {
1143
- if (!(await cloudLinked())) {
1144
- return c.notFound();
1145
- }
1146
- return c.json(await replaceCloudSpaces(c.get("user").id));
1147
- })
1148
- .post("/wizards/:id/chat", async (c) => {
1149
- const user = c.get("user");
1150
- const wizardId = c.req.param("id");
1151
- const { message } = z
1152
- .object({ message: z.string().min(1).max(8000) })
1153
- .parse(await c.req.json());
1154
- await writableWizard(user.id, wizardId);
1155
- if (!(await canSpend())) {
1156
- throw new ServiceError("no_credits", note("creditsUsedUp"));
1157
- }
1158
- return streamSSE(c, async (stream) => {
1159
- const abort = new AbortController();
1160
- stream.onAbort(() => abort.abort());
1161
- try {
1162
- const result = await architectTurn(user.id, wizardId, message, requestLang(c), {
1163
- signal: abort.signal,
1164
- onText: (delta) => {
1165
- void stream.writeSSE({ event: "text", data: JSON.stringify(delta) });
1166
- },
1167
- onActivity: (label) => {
1168
- void stream.writeSSE({ event: "activity", data: JSON.stringify(label) });
1169
- },
1170
- onThought: (line) => {
1171
- void stream.writeSSE({ event: "thought", data: JSON.stringify(line) });
1172
- },
1173
- onBuilding: () => {
1174
- void stream.writeSSE({ event: "building", data: "1" });
1175
- },
1176
- });
1177
- await stream.writeSSE({ event: "done", data: JSON.stringify(result) });
1178
- }
1179
- catch (err) {
1180
- console.error("[architect]", err);
1181
- await stream.writeSSE({
1182
- event: "error",
1183
- data: JSON.stringify({
1184
- message: err instanceof ServiceError
1185
- ? errorText(err, requestLang(c))
1186
- : say(c, "somethingWentWrongTry"),
1187
- }),
1188
- });
1189
- }
1190
- });
1191
- })
1192
- // What the admin says into the composer, written down — where the browser cannot do it itself.
1193
- .post("/transcribe", async (c) => {
1194
- const file = (await c.req.formData()).get("file");
1195
- if (!(file instanceof File) || !file.size || file.size > 10_000_000) {
1196
- throw new ServiceError("invalid", note("recordingMbMost"));
1197
- }
1198
- if (!(await canSpend())) {
1199
- throw new ServiceError("no_credits", note("creditsUsedUp"));
1200
- }
1201
- try {
1202
- const { text } = await transcribeAudio({
1203
- bytes: new Uint8Array(await file.arrayBuffer()),
1204
- mediaType: file.type || "audio/webm",
1205
- });
1206
- return c.json({ text });
1207
- }
1208
- catch (err) {
1209
- if (err instanceof ModelUnavailableError) {
1210
- throw new ServiceError("refused", saidOf(err));
1211
- }
1212
- throw err;
1213
- }
1214
- })
1215
- .post("/wizards/:id/test-runs", async (c) => c.json(await startTestRun(c.get("user").id, c.req.param("id"))))
1216
- .get("/wizards/:id/runs", async (c) => c.json(await listRuns(c.get("user").id, c.req.param("id"))))
1217
- // --- workspace -------------------------------------------------------------
1218
- .get("/wizards/:id/files", async (c) => c.json(await listFiles(c.get("user").id, c.req.param("id"))))
1219
- .get("/wizards/:id/files/:path{.+}", async (c) => {
1220
- const { file, data } = await readFile(c.get("user").id, c.req.param("id"), c.req.param("path"));
1221
- return c.body(new Uint8Array(data), 200, {
1222
- "content-type": file.mime,
1223
- "content-disposition": `attachment; filename="${file.path.split("/").pop()}"`,
1224
- "cache-control": "private, no-cache",
1225
- });
1226
- })
1227
- .put("/wizards/:id/files/:path{.+}", async (c) => {
1228
- const data = new Uint8Array(await c.req.arrayBuffer());
1229
- const file = await writeFile(c.get("user").id, c.req.param("id"), c.req.param("path"), data, c.req.header("content-type")?.split(";")[0]);
1230
- return c.json(file);
1231
- })
1232
- .delete("/wizards/:id/files/:path{.+}", async (c) => {
1233
- await deleteFile(c.get("user").id, c.req.param("id"), c.req.param("path"));
1234
- return c.json({ ok: true });
1235
- })
1236
- .get("/wizards/:id/widgets/:stepId/preview", async (c) => {
1237
- const html = await draftWidgetPreview(c.get("user").id, c.req.param("id"), c.req.param("stepId"));
1238
- return c.body(new TextEncoder().encode(html), 200, {
1239
- "content-type": "text/html; charset=utf-8",
1240
- "content-security-policy": HTML_RESPONSE_CSP,
1241
- "cache-control": "no-store",
1242
- });
1243
- })
1244
- // --- a runtime that runs alone: its keys, models and linked account -----------
1245
- .get("/api-keys", async (c) => (managed ? c.notFound() : c.json(await listLocalKeys())))
1246
- .post("/api-keys", async (c) => {
1247
- if (managed) {
1248
- return c.notFound();
1249
- }
1250
- const { name } = z.object({ name: z.string().min(1).max(32) }).parse(await c.req.json());
1251
- return c.json(await createLocalKey(name));
1252
- })
1253
- .delete("/api-keys/:id", async (c) => {
1254
- if (managed) {
1255
- return c.notFound();
1256
- }
1257
- await deleteLocalKey(c.req.param("id"));
1258
- return c.json({ ok: true });
1259
- })
1260
- // The person's AI apps on this machine (Claude Desktop, Cursor, Codex …) and whether they
1261
- // have this install's MCP server: the same as `wizards connect`.
1262
- .get("/local/apps", async (c) => (managed ? c.notFound() : c.json(await appStates(layout()))))
1263
- .post("/local/apps/:id", async (c) => {
1264
- if (managed) {
1265
- return c.notFound();
1266
- }
1267
- const { connect } = z.object({ connect: z.boolean() }).parse(await c.req.json());
1268
- const [done] = await connectApps(layout(), [c.req.param("id")], !connect);
1269
- if (!done) {
1270
- return c.json({ error: say(c, "unknownApp"), code: "not_found" }, 404);
1271
- }
1272
- // Not done is an answer too: the app's file is no plain JSON, here is what to paste.
1273
- return c.json(done.outcome);
1274
- })
1275
- // What each AI client did with the MCP server since the start: the test on "Integrate".
1276
- .get("/integrations/seen", (c) => c.json(seenApps(c.get("user").tenantId)))
1277
- .get("/local/models", (c) => (managed ? c.notFound() : c.json(localModelSettings())))
1278
- .put("/local/models", async (c) => {
1279
- if (managed) {
1280
- return c.notFound();
1281
- }
1282
- await saveLocalModels(modelsInput.parse(await c.req.json()));
1283
- return c.json(localModelSettings());
1284
- })
1285
- // --- models: where each class runs, own API keys, the credits behind them -----------------
1286
- // Alone for this machine; on a Manage-App's runtime for the team, whose admins change it.
1287
- .get("/models", async (c) => c.json(await modelSettings(requestLang(c))))
1288
- .put("/models", async (c) => {
1289
- if (!mayChangeModels(c.get("user"))) {
1290
- return c.json({
1291
- error: say(c, "onlyTeamAdminsChange"),
1292
- code: "forbidden",
1293
- }, 403);
1294
- }
1295
- const input = modelsInput.parse(await c.req.json());
1296
- // In the cloud nothing runs on a machine's client or local model.
1297
- if (managed &&
1298
- (input.source ||
1299
- input.ollamaUrl ||
1300
- Object.values(input.bindings ?? {}).some((ref) => ref && !cloudBinding(ref)))) {
1301
- return c.json({
1302
- error: say(c, "notAvailableCloud"),
1303
- code: "not_local",
1304
- }, 400);
1305
- }
1306
- // Own keys and bindings to a provider's model are a feature of the team's plan.
1307
- // When the Manage-App can't say what the plan holds, own keys wait: nothing is taken unchecked.
1308
- const own = Object.values(input.keys ?? {}).some((key) => key?.trim()) ||
1309
- Object.values(input.bindings ?? {}).some((ref) => ref && !isCreditsRef(ref));
1310
- if (managed && own) {
1311
- const info = await tenantInfo(c.get("user").tenantId).catch((err) => {
1312
- console.error("[models] plan of the tenant:", err);
1313
- return null;
1314
- });
1315
- if (!info) {
1316
- return c.json({
1317
- error: say(c, "planUnavailable"),
1318
- code: "manage_unavailable",
1319
- }, 503);
1320
- }
1321
- if (!feature("ownKeys", info.features)) {
1322
- return c.json({
1323
- error: info.plan?.name
1324
- ? say(c, "ownKeysNotInPlan", { plan: info.plan.name })
1325
- : say(c, "ownKeysNotInTeamPlan"),
1326
- code: "plan",
1327
- }, 403);
1328
- }
1329
- }
1330
- await saveModels(input);
1331
- return c.json(await modelSettings(requestLang(c)));
1332
- })
1333
- // Whether a provider takes a key — the one typed, or the one stored. Nothing is generated.
1334
- .post("/models/keys/:provider/check", async (c) => {
1335
- const provider = z.enum(LOCAL_KEYS).parse(c.req.param("provider"));
1336
- const { key } = z
1337
- .object({ key: z.string().max(400).optional() })
1338
- .parse(await c.req.json().catch(() => ({})));
1339
- const value = key?.trim() || (await storedKey(provider));
1340
- if (!value) {
1341
- return c.json({
1342
- ok: false,
1343
- message: say(c, "noApiKeySet"),
1344
- });
1345
- }
1346
- return c.json(await checkKey(provider, value, requestLang(c)));
1347
- })
1348
- // One call on a class, as a run makes it: text answers a word, an image, a voice or a short
1349
- // clip comes back to look at, a voice note comes back as text. Paid like any call.
1350
- .post("/models/test", async (c) => {
1351
- if (!mayChangeModels(c.get("user"))) {
1352
- return c.json({
1353
- error: say(c, "onlyTeamAdminsTest"),
1354
- code: "forbidden",
1355
- }, 403);
1356
- }
1357
- const { cls, lang } = z
1358
- .object({ cls: z.enum(MODEL_CLASSES), lang: z.enum(LANGS).default("en") })
1359
- .parse(await c.req.json());
1360
- return c.json(await testClass(cls, lang));
1361
- })
1362
- // One short call on a class, as a run would make it: shows that the way to the model is open.
1363
- .post("/local/models/test", async (c) => {
1364
- if (managed) {
1365
- return c.notFound();
1366
- }
1367
- const { cls } = z
1368
- .object({ cls: z.enum(TEXT_CLASSES).default("classifier") })
1369
- .parse(await c.req.json().catch(() => ({})));
1370
- const started = Date.now();
1371
- // The source this call runs on: the person may pick another one while it is under way.
1372
- const source = localModelSettings().source;
1373
- try {
1374
- const resolved = await textModel(cls);
1375
- const result = await generateText({
1376
- model: resolved.model,
1377
- prompt: "Reply with the single word: OK",
1378
- maxOutputTokens: 20,
1379
- abortSignal: AbortSignal.timeout(120_000),
1380
- });
1381
- // A working call is what ends the setup — for the source it ran on.
1382
- const tested = await testedSources();
1383
- if (!tested.includes(source)) {
1384
- await writeSetting("setup-done", [...tested, source]);
1385
- }
1386
- return c.json({
1387
- ok: true,
1388
- ref: resolved.ref,
1389
- reply: result.text.trim().slice(0, 200),
1390
- ms: Date.now() - started,
1391
- });
1392
- }
1393
- catch (err) {
1394
- const message = err?.message ?? String(err);
1395
- return c.json({ ok: false, error: message.slice(0, 500), ms: Date.now() - started });
1396
- }
1397
- })
1398
- // --- the AI clients on this machine: looked at afresh, signed in through the inline terminal ----
1399
- .post("/local/harness/:id/detect", async (c) => {
1400
- const id = c.req.param("id");
1401
- if (managed || !harness(id)) {
1402
- return c.notFound();
1403
- }
1404
- return c.json({ harness: await detectHarness(id, true) });
1405
- })
1406
- .post("/local/harness/:id/install", async (c) => {
1407
- const spec = managed ? null : await installSpec(c.req.param("id"));
1408
- if (!spec) {
1409
- return c.notFound();
1410
- }
1411
- const { cols, rows } = terminalSize.parse(await c.req.json().catch(() => ({})));
1412
- const cwd = join(env.dataDir, "harness");
1413
- mkdirSync(cwd, { recursive: true });
1414
- // The page asks again once the command is over: then the client is there, or its output says why not.
1415
- const terminal = await openTerminal({ ...spec, cwd, cols, rows });
1416
- return c.json({ terminal });
1417
- })
1418
- .post("/local/harness/:id/login", async (c) => {
1419
- const id = c.req.param("id");
1420
- const client = harness(id);
1421
- if (managed || !client) {
1422
- return c.notFound();
1423
- }
1424
- const { cols, rows } = terminalSize.parse(await c.req.json().catch(() => ({})));
1425
- const cwd = join(env.dataDir, "harness");
1426
- mkdirSync(cwd, { recursive: true });
1427
- const terminal = await openTerminal({
1428
- bin: client.bin,
1429
- args: client.login.args,
1430
- cwd,
1431
- env: { ...(await loginEnv(client)), ...client.login.env },
1432
- cols,
1433
- rows,
1434
- // Signed in: the client says so on its own, and the settings learn it right away.
1435
- until: async () => (await freshAuth(client)) !== "none",
1436
- onDone: () => void detectHarness(id, true),
1437
- });
1438
- return c.json({ terminal });
1439
- })
1440
- .get("/local/terminal/:id/stream", (c) => {
1441
- if (managed) {
1442
- return c.notFound();
1443
- }
1444
- const id = c.req.param("id");
1445
- return streamSSE(c, async (stream) => {
1446
- let ended = false;
1447
- // One write after the other, and all of them out before the stream ends: the last one is
1448
- // the exit, and a page that comes after the end gets everything at once.
1449
- let written = Promise.resolve();
1450
- const done = new Promise((resolve) => {
1451
- const unsubscribe = subscribeTerminal(id, (event) => {
1452
- written = written.then(() => stream.writeSSE({ event: event.type, data: JSON.stringify(event) }));
1453
- if (event.type === "exit") {
1454
- ended = true;
1455
- resolve();
1456
- }
1457
- });
1458
- stream.onAbort(() => {
1459
- unsubscribe();
1460
- resolve();
1461
- });
1462
- });
1463
- // The page keeps the stream open while the terminal lives; a heartbeat keeps proxies from closing it.
1464
- const beat = setInterval(() => {
1465
- if (!ended) {
1466
- void stream.writeSSE({ event: "ping", data: "" });
1467
- }
1468
- }, 15_000);
1469
- await done;
1470
- clearInterval(beat);
1471
- await written;
1472
- });
1473
- })
1474
- .post("/local/terminal/:id/input", async (c) => {
1475
- if (managed) {
1476
- return c.notFound();
1477
- }
1478
- const { data } = z.object({ data: z.string().max(10_000) }).parse(await c.req.json());
1479
- writeTerminal(c.req.param("id"), data);
1480
- return c.json({ ok: true });
1481
- })
1482
- .post("/local/terminal/:id/resize", async (c) => {
1483
- if (managed) {
1484
- return c.notFound();
1485
- }
1486
- const { cols, rows } = z
1487
- .object({ cols: z.number().int().min(10).max(500), rows: z.number().int().min(4).max(200) })
1488
- .parse(await c.req.json());
1489
- resizeTerminal(c.req.param("id"), cols, rows);
1490
- return c.json({ ok: true });
1491
- })
1492
- .delete("/local/terminal/:id", (c) => {
1493
- if (managed) {
1494
- return c.notFound();
1495
- }
1496
- closeTerminal(c.req.param("id"));
1497
- return c.json({ ok: true });
1498
- })
1499
- .put("/local/chat", async (c) => {
1500
- if (managed) {
1501
- return c.notFound();
1502
- }
1503
- const { engine } = z.object({ engine: z.enum(["models", "claude"]) }).parse(await c.req.json());
1504
- await setChatEngine(engine);
1505
- return c.json({ ok: true });
1506
- })
1507
- // The address the system browser opens: the account's sign-in, or — for someone without an
1508
- // account — its sign-up page with the invitation code, which then goes on to the sign-in.
1509
- // --- the first visit of a cloud studio: who the team is, its website, first documents -----
1510
- .put("/team", async (c) => {
1511
- if (!managed) {
1512
- return c.json({
1513
- error: say(c, "onlyAvailableCloud"),
1514
- code: "not_managed",
1515
- }, 404);
1516
- }
1517
- await requireAdmin();
1518
- const { name } = z.object({ name: z.string().trim().min(1).max(80) }).parse(await c.req.json());
1519
- const info = await renameTenant(c.get("user").tenantId, name);
1520
- return c.json({ name: info.name });
1521
- })
1522
- // What the team uses engenty for, and the questions that fit: kept at the Manage-App.
1523
- .put("/team/profile", async (c) => {
1524
- if (!managed) {
1525
- return c.json({
1526
- error: say(c, "onlyAvailableCloud"),
1527
- code: "not_managed",
1528
- }, 404);
1529
- }
1530
- await requireAdmin();
1531
- const field = (max) => z.string().trim().max(max).nullable().optional();
1532
- const profile = z
1533
- .object({
1534
- kind: z.enum(["personal", "club", "small", "corp"]),
1535
- size: field(40),
1536
- sector: field(120),
1537
- role: field(120),
1538
- need: field(2000),
1539
- legalName: field(200),
1540
- phone: field(40),
1541
- website: field(400),
1542
- })
1543
- .parse(await c.req.json());
1544
- const user = c.get("user");
1545
- await saveTeamProfile(user.tenantId, user.id, requestLang(c) === "de" ? "de" : "en", profile);
1546
- return c.json({ ok: true });
1547
- })
1548
- .post("/onboarding/done", async (c) => {
1549
- if (!managed) {
1550
- return c.json({
1551
- error: say(c, "onlyAvailableCloud"),
1552
- code: "not_managed",
1553
- }, 404);
1554
- }
1555
- await finishOnboarding(c.get("user").tenantId);
1556
- return c.json({ ok: true });
1557
- })
1558
- .post("/projects/:id/website", async (c) => {
1559
- const user = c.get("user");
1560
- const project = await ownedProject(user.id, c.req.param("id"));
1561
- const { url } = z.object({ url: z.string().trim().min(3).max(400) }).parse(await c.req.json());
1562
- return c.json(await applyWebsite(user.id, project.id, url));
1563
- })
1564
- // The install command and the first steps, mailed to the signed-in person by the Manage-App.
1565
- .post("/install-mail", async (c) => {
1566
- if (!managed) {
1567
- return c.json({
1568
- error: say(c, "onlyAvailableCloud"),
1569
- code: "not_managed",
1570
- }, 404);
1571
- }
1572
- const { lang } = z
1573
- .object({ lang: z.enum(LANGS).default("en") })
1574
- .parse(await c.req.json().catch(() => ({})));
1575
- await installMail(c.get("user").email, lang);
1576
- return c.json({ ok: true });
1577
- })
1578
- .post("/account/link", async (c) => {
1579
- if (managed) {
1580
- return c.notFound();
1581
- }
1582
- const input = z
1583
- .object({ signup: z.boolean().optional(), code: z.string().max(64).optional() })
1584
- .parse(await c.req.json().catch(() => ({})));
1585
- return c.json({ url: await startLink(input) });
1586
- })
1587
- .delete("/account", async (c) => {
1588
- if (managed) {
1589
- return c.notFound();
1590
- }
1591
- await unlink();
1592
- await forgetCloud();
1593
- // Pro modules went with the account's plan; installed ones stay on disk.
1594
- await refreshPro();
1595
- // Models that ran on the account's credits have nothing to run on now; another source stays.
1596
- if (localModelSettings().source === "account") {
1597
- await saveLocalModels({ source: "own" });
1598
- }
1599
- return c.json({ ok: true });
1600
- });