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,1106 +0,0 @@
1
- import { createHash } from "node:crypto";
2
- import { createAnthropic } from "@ai-sdk/anthropic";
3
- import { createElevenLabs } from "@ai-sdk/elevenlabs";
4
- import { createFal } from "@ai-sdk/fal";
5
- import { createGateway } from "@ai-sdk/gateway";
6
- import { createGoogle } from "@ai-sdk/google";
7
- import { createOpenAI } from "@ai-sdk/openai";
8
- import { createReplicate } from "@ai-sdk/replicate";
9
- import { MODEL_CLASSES, TEXT_CLASSES, } from "@engenty-wizards/shared/definition";
10
- import { creditsModelOf, isCreditsRef, PROVIDER_IDS, providerInfo, providerOfRef, } from "@engenty-wizards/shared/providers";
11
- import { note, saidText } from "@engenty-wizards/shared/run";
12
- import { generateSpeech, generateText, } from "ai";
13
- import { accountToken, linkedAccount } from "./auth/account.js";
14
- import { DeviceModel, deviceThinks } from "./engine/device.js";
15
- import { env } from "./env.js";
16
- import { appleModel, appleStatus, appleTranscriptionModel, appleUnavailableNote, } from "./harness/apple.js";
17
- import { detectHarness, HarnessModel, harness, isHarnessVendor, notInstalled, signedOut, } from "./harness/index.js";
18
- import { managed } from "./manage.js";
19
- import { hasFfmpeg } from "./media/ffmpeg.js";
20
- import { ModelUnavailableError, saidOf } from "./model-errors.js";
21
- import { seal, unseal } from "./secrets/crypto.js";
22
- import { vaultDelete, vaultGet, vaultSet } from "./secrets/vault.js";
23
- import { readSetting, writeSetting } from "./settings.js";
24
- import { currentTenant, currentTenantOrNull } from "./tenants/tenant.js";
25
- import { serverText } from "./texts.js";
26
- export { isHarnessVendor } from "./harness/index.js";
27
- /**
28
- * A step names a model class, never a model. Where the class runs is decided here, in this order:
29
- * 1. its own way: an AI client installed on the machine (Claude Code, Codex, Gemini CLI, Cursor
30
- * Agent — on its subscription), an API key the person brought (OpenAI, Anthropic, Google,
31
- * fal.ai, ElevenLabs, Replicate, AI Gateway) or a local model;
32
- * 2. credits: the model-gateway binds `wizards/<class>`, meters the call and books it — on the
33
- * tenant of a Manage-App's runtime, or on the account a runtime that runs alone is linked to.
34
- * A runtime of a Manage-App keeps a tenant's own keys (sealed) and runs on its credits where it
35
- * has none. A binding is `[provider:]vendor/model`, e.g. `anthropic/claude-haiku-4.5` (AI
36
- * Gateway), `openai:gpt-5.4-mini`, `fal:fal-ai/flux/schnell`, `ollama:qwen3`, `claude/sonnet`
37
- * (an installed client), or `credits`.
38
- */
39
- export { ModelUnavailableError } from "./model-errors.js";
40
- // --- configuration -----------------------------------------------------------------
41
- export const LOCAL_KEYS = PROVIDER_IDS;
42
- const local = { settings: { source: "own", bindings: {} }, keys: {} };
43
- function envKey(name) {
44
- const value = {
45
- gateway: env.aiGatewayKey,
46
- openai: env.openaiKey,
47
- anthropic: env.anthropicKey,
48
- google: env.googleKey,
49
- fal: env.falKey,
50
- elevenlabs: env.elevenlabsKey,
51
- replicate: env.replicateKey,
52
- }[name];
53
- return value || undefined;
54
- }
55
- /** Reads the model settings and keys of a runtime that runs alone; called at start and after a change. */
56
- export async function loadLocalModels() {
57
- if (managed) {
58
- return;
59
- }
60
- local.settings = (await readSetting("models")) ?? {
61
- source: "own",
62
- bindings: {},
63
- };
64
- const keys = {};
65
- for (const name of LOCAL_KEYS) {
66
- keys[name] = (await vaultGet(`key.${name}`)) ?? envKey(name);
67
- }
68
- local.keys = keys;
69
- }
70
- const tenantConfigs = new Map();
71
- const tenantSetting = (tenant) => `models:${tenant}`;
72
- /** A team thinks on its credits unless it brought a key: `own`, with the credits behind it. */
73
- function teamSettings(bindings) {
74
- return { source: "own", bindings, creditFallback: true };
75
- }
76
- async function tenantConfig(tenant) {
77
- const hit = tenantConfigs.get(tenant);
78
- if (hit) {
79
- return hit;
80
- }
81
- const stored = await readSetting(tenantSetting(tenant));
82
- const value = {
83
- settings: teamSettings(stored?.bindings ?? {}),
84
- keys: (stored?.keys ? unseal(stored.keys) : null) ?? {},
85
- };
86
- tenantConfigs.set(tenant, value);
87
- return value;
88
- }
89
- async function config() {
90
- if (!managed) {
91
- return local;
92
- }
93
- const tenant = currentTenantOrNull();
94
- return tenant ? tenantConfig(tenant) : { settings: teamSettings({}), keys: {} };
95
- }
96
- function mergeBindings(current, changes = {}) {
97
- const bindings = { ...current };
98
- for (const [cls, ref] of Object.entries(changes)) {
99
- if (ref?.trim()) {
100
- bindings[cls] = ref.trim();
101
- }
102
- else {
103
- delete bindings[cls];
104
- }
105
- }
106
- return bindings;
107
- }
108
- export function localModelSettings() {
109
- return {
110
- ...local.settings,
111
- creditFallback: local.settings.creditFallback !== false,
112
- bindings: Object.fromEntries(MODEL_CLASSES.map((c) => [c, ownRef(local, c) || local.settings.bindings[c] || ""])),
113
- ollamaUrl: local.settings.ollamaUrl ?? env.ollamaUrl,
114
- keys: Object.fromEntries(LOCAL_KEYS.map((k) => [k, Boolean(local.keys[k])])),
115
- };
116
- }
117
- export async function saveLocalModels(input) {
118
- await writeSetting("models", {
119
- source: input.source ?? local.settings.source,
120
- bindings: mergeBindings(local.settings.bindings, input.bindings),
121
- ollamaUrl: input.ollamaUrl?.trim() || local.settings.ollamaUrl,
122
- creditFallback: input.creditFallback ?? local.settings.creditFallback,
123
- });
124
- for (const [name, value] of Object.entries(input.keys ?? {})) {
125
- if (value?.trim()) {
126
- await vaultSet(`key.${name}`, value.trim());
127
- }
128
- else {
129
- await vaultDelete(`key.${name}`);
130
- }
131
- }
132
- await loadLocalModels();
133
- }
134
- /** A team's keys and bindings on a runtime of a Manage-App. No client and no local model there. */
135
- async function saveTenantModels(tenant, input) {
136
- const current = await tenantConfig(tenant);
137
- const keys = { ...current.keys };
138
- for (const [name, value] of Object.entries(input.keys ?? {})) {
139
- if (value?.trim()) {
140
- keys[name] = value.trim();
141
- }
142
- else {
143
- delete keys[name];
144
- }
145
- }
146
- await writeSetting(tenantSetting(tenant), {
147
- bindings: mergeBindings(current.settings.bindings, input.bindings),
148
- keys: Object.keys(keys).length ? seal(keys) : null,
149
- });
150
- tenantConfigs.delete(tenant);
151
- }
152
- /** Saves for this machine, or for the current tenant of a Manage-App's runtime. */
153
- export async function saveModels(input) {
154
- if (managed) {
155
- await saveTenantModels(currentTenant(), input);
156
- }
157
- else {
158
- await saveLocalModels(input);
159
- }
160
- }
161
- /** A stored key, for a check of the key itself; never sent to the studio. */
162
- export async function storedKey(name) {
163
- return (await config()).keys[name];
164
- }
165
- // --- where a class runs -------------------------------------------------------------
166
- const isText = (cls) => TEXT_CLASSES.includes(cls);
167
- /**
168
- * `fal:fal-ai/flux/schnell` → provider fal, id `fal-ai/flux/schnell`. Without a provider the
169
- * binding is an AI Gateway id (`google/veo-…`) or an installed client (`codex/default`).
170
- */
171
- function parse(ref) {
172
- const match = /^([a-z]+):(.*)$/s.exec(ref);
173
- if (match) {
174
- const [, provider, id] = match;
175
- // Ollama and the gateway name a model as the gateway does; the others are their own vendor.
176
- const vendor = provider === "ollama" || provider === "gateway" ? id.split("/")[0] : provider;
177
- return { provider, id, vendor };
178
- }
179
- return { provider: null, id: ref, vendor: ref.split("/")[0] };
180
- }
181
- const vendorOf = (ref) => parse(ref).vendor;
182
- /** A model on this machine: Ollama, or Apple Intelligence on a Mac (harness/apple.ts). */
183
- const isLocalProvider = (provider) => provider === "ollama" || provider === "apple";
184
- /** The part of `codex/default` after the client. */
185
- const aliasOf = (id) => id.split("/").slice(1).join("/");
186
- /** Whether this configuration can reach a binding without credits. */
187
- function reachable(cfg, ref) {
188
- if (!ref || isCreditsRef(ref)) {
189
- return false;
190
- }
191
- const { provider, vendor } = parse(ref);
192
- if ((provider === null && isHarnessVendor(vendor)) || isLocalProvider(provider)) {
193
- // An installed client and a local model are of this machine.
194
- return !managed;
195
- }
196
- if (provider === null || provider === "gateway") {
197
- return (Boolean(cfg.keys.gateway) ||
198
- (provider === null &&
199
- (vendor === "openai" || vendor === "anthropic") &&
200
- Boolean(cfg.keys[vendor])));
201
- }
202
- return Boolean(cfg.keys[provider]);
203
- }
204
- /** What a class runs on without credits: a client, an own key or a local model. "" = no way of its own. */
205
- function ownRef(cfg, cls) {
206
- const bound = cfg.settings.bindings[cls];
207
- // A text class bound to Apple Intelligence (Classifier, Standard) thinks on this Mac whatever
208
- // the source is: the others keep the installed client, the account's credits or the keys.
209
- if (isText(cls) && bound && parse(bound).provider === "apple") {
210
- return reachable(cfg, bound) ? bound : "";
211
- }
212
- const client = managed ? null : harness(cfg.settings.source);
213
- if (isText(cls) && client) {
214
- // Text thinks on the installed client; a binding counts only where it names that client.
215
- return bound?.startsWith(`${client.id}/`)
216
- ? bound
217
- : `${client.id}/${client.classes[cls]}`;
218
- }
219
- // Text on the account's credits: every text class goes there.
220
- if (isText(cls) && cfg.settings.source === "account") {
221
- return "";
222
- }
223
- if (isCreditsRef(bound)) {
224
- return "";
225
- }
226
- if (bound) {
227
- return reachable(cfg, bound) ? bound : "";
228
- }
229
- // A client that makes images on the sign-in makes them too, before any key is paid for.
230
- if (cls === "image" && client?.image) {
231
- return `${client.id}/${client.image.alias}`;
232
- }
233
- // The defaults name gateway models; without a gateway key nothing reaches them.
234
- return reachable(cfg, env.models[cls]) ? env.models[cls] : "";
235
- }
236
- /** What a class makes, to say that nothing makes it. */
237
- const MAKES = {
238
- classifier: "makesText",
239
- standard: "makesText",
240
- high: "makesText",
241
- highest: "makesText",
242
- image: "makesImages",
243
- video: "makesVideos",
244
- speech: "makesSpeech",
245
- audio: "makesVoiceNotes",
246
- };
247
- /** Why a class has no way: the provider picked for it lacks its key, or nothing is set up. */
248
- function missingText(cfg, cls) {
249
- const bound = cfg.settings.bindings[cls];
250
- if (isCreditsRef(bound)) {
251
- return note("creditsNotSignedIn");
252
- }
253
- const provider = bound ? providerInfo(providerOfRef(bound) ?? "") : null;
254
- if (provider) {
255
- return note("providerKeyMissing", { provider: provider.name, makes: note(MAKES[cls]) });
256
- }
257
- return note("noModelFor", { makes: note(MAKES[cls]) });
258
- }
259
- /**
260
- * The way to the credits. On a Manage-App's runtime always; alone, through the linked account —
261
- * where text runs on it (`chosen`), or as the fallback for what has no way of its own.
262
- */
263
- async function creditAccess(cfg, chosen) {
264
- if (managed) {
265
- return {
266
- baseUrl: env.manage.gatewayUrl,
267
- token: env.manage.serviceKey,
268
- tenant: currentTenantOrNull(),
269
- };
270
- }
271
- if (!chosen && (cfg.settings.creditFallback === false || !(await linkedAccount()))) {
272
- return null;
273
- }
274
- const token = await accountToken();
275
- if (!token) {
276
- if (chosen) {
277
- throw new ModelUnavailableError(note("accountNoLongerSigned"));
278
- }
279
- return null;
280
- }
281
- return { baseUrl: env.local.gatewayUrl, token, tenant: null };
282
- }
283
- /** A class goes to the credits on purpose: text on the account, or a binding that says so. */
284
- function creditsChosen(cfg, cls) {
285
- return (isCreditsRef(cfg.settings.bindings[cls]) ||
286
- (isText(cls) && cfg.settings.source === "account" && !managed));
287
- }
288
- async function routeOf(cls) {
289
- const cfg = await config();
290
- const ref = ownRef(cfg, cls);
291
- if (ref) {
292
- return { kind: "own", cfg, ref };
293
- }
294
- const access = await creditAccess(cfg, creditsChosen(cfg, cls));
295
- if (access) {
296
- return { kind: "credits", access, model: creditsModelOf(cfg.settings.bindings[cls]) };
297
- }
298
- throw new ModelUnavailableError(missingText(cfg, cls));
299
- }
300
- /** The key of a provider, or why the call cannot be made. */
301
- function need(cfg, name) {
302
- const key = cfg.keys[name];
303
- if (!key) {
304
- throw new ModelUnavailableError(note("noApiKeyFor", { provider: providerInfo(name)?.name ?? name }));
305
- }
306
- return key;
307
- }
308
- function gatewayClient(access, meta) {
309
- return createGateway({
310
- baseURL: `${access.baseUrl}/v4/ai`,
311
- apiKey: access.token,
312
- headers: {
313
- ...(access.tenant ? { "x-wizards-tenant": access.tenant } : {}),
314
- ...(meta.runId ? { "x-wizards-run": meta.runId } : {}),
315
- ...(meta.stepId ? { "x-wizards-step": meta.stepId } : {}),
316
- ...(meta.effort ? { "x-wizards-effort": meta.effort } : {}),
317
- },
318
- });
319
- }
320
- let gatewayCatalog = null;
321
- /** What the gateway binds each class to, with prices in credits. Cached for five minutes. */
322
- export async function classCatalog() {
323
- const cfg = await config();
324
- const access = await creditAccess(cfg, cfg.settings.source === "account").catch(() => null);
325
- if (!access) {
326
- return null;
327
- }
328
- if (gatewayCatalog &&
329
- gatewayCatalog.base === access.baseUrl &&
330
- Date.now() - gatewayCatalog.at < 300_000) {
331
- return gatewayCatalog.value;
332
- }
333
- try {
334
- const res = await fetch(`${access.baseUrl}/v1/models`, {
335
- headers: {
336
- authorization: `Bearer ${access.token}`,
337
- ...(access.tenant ? { "x-wizards-tenant": access.tenant } : {}),
338
- },
339
- signal: AbortSignal.timeout(10_000),
340
- });
341
- if (!res.ok) {
342
- return gatewayCatalog?.value ?? null;
343
- }
344
- const value = (await res.json());
345
- gatewayCatalog = { at: Date.now(), base: access.baseUrl, value };
346
- return value;
347
- }
348
- catch {
349
- return gatewayCatalog?.value ?? null;
350
- }
351
- }
352
- /** A call on the credits: the model a binding names, or the gateway's model of the class. */
353
- async function viaCredits(route, cls, meta, pick) {
354
- const bound = route.model ?? (await classCatalog())?.classes[cls]?.model ?? "";
355
- return {
356
- model: pick(gatewayClient(route.access, meta), route.model ?? `wizards/${cls}`),
357
- ref: bound,
358
- vendor: vendorOf(bound.replace(/^[a-z]+:/, "")),
359
- gateway: true,
360
- metered: true,
361
- };
362
- }
363
- /** The installed client a binding names, checked to be there. */
364
- async function installedClient(ref) {
365
- const { provider, vendor } = parse(ref);
366
- const client = provider === null ? harness(vendor) : null;
367
- if (client && !(await detectHarness(client.id))?.version) {
368
- throw new ModelUnavailableError(notInstalled(client));
369
- }
370
- return client;
371
- }
372
- async function ownLanguageModel(cfg, ref, meta) {
373
- const { provider, id, vendor } = parse(ref);
374
- const client = await installedClient(ref);
375
- if (client) {
376
- return { model: client.model(aliasOf(id), meta.effort), gateway: false };
377
- }
378
- switch (provider) {
379
- case "ollama":
380
- return {
381
- model: createOpenAI({
382
- baseURL: cfg.settings.ollamaUrl ?? env.ollamaUrl,
383
- apiKey: "ollama",
384
- }).chat(id),
385
- gateway: false,
386
- };
387
- case "apple": {
388
- const status = await appleStatus();
389
- if (!status.available) {
390
- throw new ModelUnavailableError(appleUnavailableNote(status));
391
- }
392
- return { model: appleModel(id), gateway: false };
393
- }
394
- case "openai":
395
- return { model: createOpenAI({ apiKey: need(cfg, "openai") })(id), gateway: false };
396
- case "anthropic":
397
- return { model: createAnthropic({ apiKey: need(cfg, "anthropic") })(id), gateway: false };
398
- case "google":
399
- return { model: createGoogle({ apiKey: need(cfg, "google") })(id), gateway: false };
400
- case null:
401
- case "gateway":
402
- if (cfg.keys.gateway) {
403
- return { model: createGateway({ apiKey: cfg.keys.gateway })(id), gateway: true };
404
- }
405
- if (provider === null && vendor === "openai" && cfg.keys.openai) {
406
- return { model: createOpenAI({ apiKey: cfg.keys.openai })(aliasOf(id)), gateway: false };
407
- }
408
- if (provider === null && vendor === "anthropic" && cfg.keys.anthropic) {
409
- return {
410
- model: createAnthropic({ apiKey: cfg.keys.anthropic })(aliasOf(id)),
411
- gateway: false,
412
- };
413
- }
414
- }
415
- throw new ModelUnavailableError(note("modelNotUsedYet", { ref }));
416
- }
417
- /**
418
- * The language model a text class runs on. A run watched from a device that offers the class
419
- * (the app's Apple Intelligence, engine/device.ts) asks the device first and falls back to this.
420
- */
421
- export async function textModel(cls, meta = {}) {
422
- const resolved = await ownTextModel(cls, meta);
423
- const device = meta.runId && isText(cls) ? await deviceThinks(meta.runId, cls) : null;
424
- return device
425
- ? { ...resolved, model: new DeviceModel(meta.runId, resolved.model, device.maxChars) }
426
- : resolved;
427
- }
428
- async function ownTextModel(cls, meta) {
429
- const route = await routeOf(cls);
430
- if (route.kind === "credits") {
431
- return viaCredits(route, cls, meta, (client, id) => client(id));
432
- }
433
- const { model, gateway } = await ownLanguageModel(route.cfg, route.ref, meta);
434
- return { model, ref: route.ref, vendor: vendorOf(route.ref), gateway, metered: false };
435
- }
436
- /**
437
- * Hands the tools an agent will call to a model that runs them itself (an installed AI client).
438
- * `ignorable`: the step declared no tools and has no uploads — the run's device may answer
439
- * without the generic ones (engine/device.ts).
440
- */
441
- export function attachTools(resolved, tools, ignorable = false) {
442
- if (resolved.model instanceof HarnessModel) {
443
- resolved.model.attach(tools);
444
- }
445
- else if (resolved.model instanceof DeviceModel) {
446
- resolved.model.attach(tools, ignorable);
447
- }
448
- }
449
- /** Gemini image models of the gateway are chat models answering with image files. */
450
- export function isChatImageModel(ref) {
451
- return ref.includes("gemini") && ref.includes("image");
452
- }
453
- /** `chat`: the model answers through chat with an image file (`textModel("image")`). */
454
- export async function imageModel(meta = {}) {
455
- const route = await routeOf("image");
456
- if (route.kind === "credits") {
457
- const resolved = await viaCredits(route, "image", meta, (c, id) => c.imageModel(id));
458
- return { ...resolved, chat: isChatImageModel(resolved.ref) };
459
- }
460
- const { cfg, ref } = route;
461
- const { provider, id, vendor } = parse(ref);
462
- const own = (model, gateway = false) => ({
463
- model,
464
- ref,
465
- vendor,
466
- gateway,
467
- metered: false,
468
- chat: false,
469
- });
470
- const client = await installedClient(ref);
471
- if (client?.image) {
472
- return own(client.image.model(aliasOf(id)));
473
- }
474
- switch (provider) {
475
- case "openai":
476
- return own(createOpenAI({ apiKey: need(cfg, "openai") }).image(id));
477
- case "google":
478
- return own(createGoogle({ apiKey: need(cfg, "google") }).image(id));
479
- case "fal":
480
- return own(createFal({ apiKey: need(cfg, "fal") }).image(id));
481
- case "replicate":
482
- return own(createReplicate({ apiToken: need(cfg, "replicate") }).image(id));
483
- case null:
484
- case "gateway":
485
- if (cfg.keys.gateway) {
486
- return {
487
- ...own(createGateway({ apiKey: cfg.keys.gateway }).imageModel(id), true),
488
- chat: isChatImageModel(id),
489
- };
490
- }
491
- if (provider === null && vendor === "openai" && cfg.keys.openai) {
492
- return own(createOpenAI({ apiKey: cfg.keys.openai }).image(aliasOf(id)));
493
- }
494
- }
495
- throw new ModelUnavailableError(note("noModelForImages"));
496
- }
497
- export async function videoModel(meta = {}) {
498
- const route = await routeOf("video");
499
- if (route.kind === "credits") {
500
- return viaCredits(route, "video", meta, (c, id) => c.videoModel(id));
501
- }
502
- const { cfg, ref } = route;
503
- const { provider, id, vendor } = parse(ref);
504
- const own = (model, gateway = false) => ({
505
- model,
506
- ref,
507
- vendor,
508
- gateway,
509
- metered: false,
510
- });
511
- switch (provider) {
512
- case "google":
513
- return own(createGoogle({ apiKey: need(cfg, "google") }).video(id));
514
- case "fal":
515
- return own(createFal({ apiKey: need(cfg, "fal") }).video(id));
516
- case "replicate":
517
- return own(createReplicate({ apiToken: need(cfg, "replicate") }).video(id));
518
- case null:
519
- case "gateway":
520
- if (cfg.keys.gateway) {
521
- return own(createGateway({ apiKey: cfg.keys.gateway }).videoModel(id), true);
522
- }
523
- }
524
- throw new ModelUnavailableError(note("noModelForVideos"));
525
- }
526
- /** The model that reads a text aloud. */
527
- export async function speechModel(meta = {}) {
528
- const route = await routeOf("speech");
529
- if (route.kind === "credits") {
530
- const resolved = await viaCredits(route, "speech", meta, (c, id) => c.speechModel(id));
531
- if (!resolved.ref) {
532
- throw new ModelUnavailableError(note("noModelForSpeech"));
533
- }
534
- return resolved;
535
- }
536
- const { cfg, ref } = route;
537
- const { provider, id, vendor } = parse(ref);
538
- const own = (model, gateway = false) => ({
539
- model,
540
- ref,
541
- vendor,
542
- gateway,
543
- metered: false,
544
- });
545
- switch (provider) {
546
- case "openai":
547
- return own(createOpenAI({ apiKey: need(cfg, "openai") }).speech(id));
548
- case "google":
549
- return own(createGoogle({ apiKey: need(cfg, "google") }).speech(id));
550
- case "fal":
551
- return own(createFal({ apiKey: need(cfg, "fal") }).speech(id));
552
- case "elevenlabs":
553
- return own(createElevenLabs({ apiKey: need(cfg, "elevenlabs") }).speech(id));
554
- case null:
555
- case "gateway":
556
- if (cfg.keys.gateway) {
557
- return own(createGateway({ apiKey: cfg.keys.gateway }).speechModel(id), true);
558
- }
559
- if (provider === null && vendor === "openai" && cfg.keys.openai) {
560
- return own(createOpenAI({ apiKey: cfg.keys.openai }).speech(aliasOf(id)));
561
- }
562
- }
563
- throw new ModelUnavailableError(note("noModelForSpeech"));
564
- }
565
- /**
566
- * What turns a voice note into text: a transcription model (ElevenLabs Scribe, Whisper), or a
567
- * chat model that takes audio files (Gemini) — that one also on the credits.
568
- */
569
- export async function listenerModel(meta = {}) {
570
- const route = await routeOf("audio");
571
- if (route.kind === "credits") {
572
- // On the credits a transcription model is called as one: named so, or bound to the class.
573
- const catalog = await classCatalog();
574
- const transcribes = route.model
575
- ? catalog?.models?.find((m) => m.id === route.model)?.kind === "transcription"
576
- : Boolean(catalog?.classes.audio?.transcribes);
577
- if (transcribes) {
578
- return {
579
- kind: "transcription",
580
- resolved: await viaCredits(route, "audio", meta, (c, id) => c.transcriptionModel(id)),
581
- };
582
- }
583
- }
584
- if (route.kind === "own") {
585
- const { cfg, ref } = route;
586
- const { provider, id, vendor } = parse(ref);
587
- if (provider === "apple") {
588
- // This Mac writes the note down itself (SpeechAnalyzer); nothing is paid.
589
- return {
590
- kind: "transcription",
591
- resolved: {
592
- model: appleTranscriptionModel(),
593
- ref,
594
- vendor,
595
- gateway: false,
596
- metered: false,
597
- },
598
- };
599
- }
600
- const transcriber = provider === "elevenlabs"
601
- ? createElevenLabs({ apiKey: need(cfg, "elevenlabs") }).transcription(id)
602
- : provider === "fal"
603
- ? createFal({ apiKey: need(cfg, "fal") }).transcription(id)
604
- : provider === "openai" && /transcribe|whisper/.test(id)
605
- ? createOpenAI({ apiKey: need(cfg, "openai") }).transcription(id)
606
- : null;
607
- if (transcriber) {
608
- return {
609
- kind: "transcription",
610
- resolved: { model: transcriber, ref, vendor, gateway: false, metered: false },
611
- };
612
- }
613
- }
614
- return { kind: "chat", resolved: await textModel("audio", meta) };
615
- }
616
- /**
617
- * The model that turns passages and questions into vectors for a project's document index.
618
- * Null where none is set up — an installed AI client has no such model — and the index then
619
- * works on keywords alone.
620
- */
621
- export async function embeddingModel() {
622
- const cfg = await config();
623
- if (managed) {
624
- const access = await creditAccess(cfg, true).catch(() => null);
625
- const bound = access ? (await classCatalog())?.classes.embedding : null;
626
- return access && bound
627
- ? { model: gatewayClient(access, {}).embeddingModel("wizards/embedding"), ref: bound.model }
628
- : null;
629
- }
630
- const ref = env.models.embedding;
631
- const { provider, id, vendor } = parse(ref);
632
- if (provider === "ollama") {
633
- const ollama = createOpenAI({
634
- baseURL: cfg.settings.ollamaUrl ?? env.ollamaUrl,
635
- apiKey: "ollama",
636
- });
637
- return { model: ollama.embedding(id), ref };
638
- }
639
- if ((provider === null || provider === "gateway") && cfg.keys.gateway) {
640
- return { model: createGateway({ apiKey: cfg.keys.gateway }).embeddingModel(id), ref };
641
- }
642
- if ((provider === "openai" || vendor === "openai") && cfg.keys.openai) {
643
- return {
644
- model: createOpenAI({ apiKey: cfg.keys.openai }).embedding(provider ? id : aliasOf(id)),
645
- ref,
646
- };
647
- }
648
- // No key of its own: the linked account's gateway, where its catalog has the class.
649
- const access = await creditAccess(cfg, false).catch(() => null);
650
- const bound = access ? (await classCatalog())?.classes.embedding : null;
651
- return access && bound
652
- ? { model: gatewayClient(access, {}).embeddingModel("wizards/embedding"), ref: bound.model }
653
- : null;
654
- }
655
- /**
656
- * The way to TypeSafe's Jev, a classifier that answers typed questions with probabilities and
657
- * writes no text: the credits on a Manage-App's runtime; alone, an AI Gateway key, a TypeSafe
658
- * key, or the linked account's credits. Null when there is none.
659
- */
660
- export async function systemOneAccess() {
661
- const cfg = await config();
662
- const viaCredits = (access) => ({
663
- url: `${access.baseUrl}/v4/ai/systemone`,
664
- headers: {
665
- authorization: `Bearer ${access.token}`,
666
- // Booked under the classifier class; its evaluation model answers.
667
- "ai-model-id": "wizards/classifier",
668
- ...(access.tenant ? { "x-wizards-tenant": access.tenant } : {}),
669
- },
670
- model: null,
671
- });
672
- if (managed) {
673
- const access = await creditAccess(cfg, true).catch(() => null);
674
- return access ? viaCredits(access) : null;
675
- }
676
- if (cfg.keys.gateway) {
677
- return {
678
- url: "https://ai-gateway.vercel.sh/typesafe/v1/systemone",
679
- headers: { authorization: `Bearer ${cfg.keys.gateway}` },
680
- model: "typesafe-ai/jev",
681
- };
682
- }
683
- if (env.typesafeKey) {
684
- return {
685
- url: "https://api.typesafe.ai/v1/systemone",
686
- headers: { authorization: `Bearer ${env.typesafeKey}` },
687
- model: "jev-latest",
688
- };
689
- }
690
- const access = await creditAccess(cfg, false).catch(() => null);
691
- return access ? viaCredits(access) : null;
692
- }
693
- /** Search tools an AI Gateway runs itself; they travel in the request, so any gateway client names them. */
694
- export const gatewayTools = createGateway({ apiKey: "unused" }).tools;
695
- // --- An AI Gateway key on Vercel's free tier ------------------------------------------
696
- /** Where Vercel tops an AI Gateway account up to paid credits. */
697
- const GATEWAY_TOP_UP = "https://vercel.com/d?to=%2F%5Bteam%5D%2F%7E%2Fai%3Fmodal%3Dtop-up";
698
- /**
699
- * The model Vercel refused because the key's account is on the free tier ("" where the answer
700
- * names none); null where the error is something else.
701
- */
702
- export function freeTierRefusal(err) {
703
- let text = "";
704
- for (let e = err; e && text.length < 100_000; e = e.cause) {
705
- text += ` ${e.message ?? ""} ${e.responseBody ?? ""}`;
706
- }
707
- if (!/RestrictedModelsError|Free tier users do not have access/i.test(text)) {
708
- return null;
709
- }
710
- return /"originalModelId":"([^"]+)"/.exec(text)?.[1] ?? "";
711
- }
712
- /** What the person reads when Vercel's free tier leaves a model out, and how to fix it. */
713
- export function freeTierText(model) {
714
- return note("freeTier", {
715
- model: model ? note("quoted", { text: model }) : note("thisModel"),
716
- url: GATEWAY_TOP_UP,
717
- });
718
- }
719
- /** What a key was answered for a model: refusals are asked again soon, as a top-up lifts them. */
720
- const gatewayProbes = new Map();
721
- const probeId = (key, id) => `${createHash("sha256").update(key).digest("hex").slice(0, 16)}|${id}`;
722
- /** A call refused for the free tier: the next run's check knows before it starts. */
723
- export async function noteFreeTierRefusal(err) {
724
- const model = freeTierRefusal(err);
725
- const key = model ? (await config()).keys.gateway : undefined;
726
- if (model && key) {
727
- gatewayProbes.set(probeId(key, model), { refused: true, at: Date.now() });
728
- }
729
- }
730
- /**
731
- * Whether the key's account may call the model. Vercel refuses before any provider is asked, so
732
- * a refused probe costs nothing; an allowed one costs a token or a word. Images (but those a chat
733
- * model makes) and videos cannot be asked that cheaply: only a refusal already seen counts.
734
- */
735
- async function gatewayRefuses(key, id, cls) {
736
- const at = probeId(key, id);
737
- const known = gatewayProbes.get(at);
738
- if (known && Date.now() - known.at < (known.refused ? 300_000 : 86_400_000)) {
739
- return known.refused;
740
- }
741
- if (cls === "video" || (cls === "image" && !isChatImageModel(id))) {
742
- return known?.refused ?? false;
743
- }
744
- const gateway = createGateway({ apiKey: key });
745
- const limits = { maxRetries: 0, abortSignal: AbortSignal.timeout(15_000) };
746
- let refused = false;
747
- try {
748
- if (cls === "speech") {
749
- await generateSpeech({ model: gateway.speechModel(id), text: "Ok.", ...limits });
750
- }
751
- else {
752
- await generateText({ model: gateway(id), prompt: "Ok.", maxOutputTokens: 1, ...limits });
753
- }
754
- }
755
- catch (err) {
756
- // Anything else (a limit of the model, the network) is not the tier: the run will tell.
757
- refused = freeTierRefusal(err) !== null;
758
- }
759
- gatewayProbes.set(at, { refused, at: Date.now() });
760
- return refused;
761
- }
762
- /** The realtime speech model a live conversation runs on; a setting of the install may name another. */
763
- const CONVERSATION_MODEL = env.conversationModel || "gpt-realtime";
764
- /**
765
- * What a live conversation with a wizard runs on: the tenant's own OpenAI key, until a class of
766
- * its own exists on the Models page and on the account's credits.
767
- */
768
- export async function conversationAccess() {
769
- const cfg = await config();
770
- if (!cfg.keys.openai) {
771
- throw new ModelUnavailableError(note("noOpenaiApiKey"));
772
- }
773
- return { apiKey: cfg.keys.openai, model: CONVERSATION_MODEL };
774
- }
775
- /** Whether a live conversation can be started here. */
776
- export async function conversationAvailable() {
777
- return Boolean((await config()).keys.openai);
778
- }
779
- /** Why the own AI Gateway key cannot reach what a class runs on, or null. */
780
- async function gatewayProblem(cls, ref) {
781
- const { provider, id } = parse(ref);
782
- const key = (await config()).keys.gateway;
783
- if (!key || (provider !== null && provider !== "gateway")) {
784
- return null;
785
- }
786
- return (await gatewayRefuses(key, id, cls)) ? freeTierText(id) : null;
787
- }
788
- /**
789
- * Whether a class can run here, found out without calling it: null, or what the person reads.
790
- * A class the gateway serves counts as there unless its catalog leaves it unbound.
791
- */
792
- export async function classProblem(cls) {
793
- try {
794
- const resolved = cls === "image"
795
- ? await imageModel()
796
- : cls === "video"
797
- ? await videoModel()
798
- : cls === "speech"
799
- ? await speechModel()
800
- : cls === "audio"
801
- ? (await listenerModel()).resolved
802
- : await textModel(cls);
803
- if (resolved.metered) {
804
- const catalog = await classCatalog();
805
- const named = creditsModelOf((await config()).settings.bindings[cls]);
806
- if (named) {
807
- return catalog?.models && !catalog.models.some((m) => m.id === named)
808
- ? note("modelNotAvailableAccount")
809
- : null;
810
- }
811
- return catalog?.classes && !catalog.classes[cls] ? note("accountNoModelSet") : null;
812
- }
813
- const client = harness(resolved.vendor);
814
- if (client && (await detectHarness(client.id))?.auth === "none") {
815
- return signedOut(client);
816
- }
817
- return resolved.gateway ? await gatewayProblem(cls, resolved.ref) : null;
818
- }
819
- catch (err) {
820
- if (err instanceof ModelUnavailableError) {
821
- return saidOf(err);
822
- }
823
- throw err;
824
- }
825
- }
826
- /** Clients that can make a film: they work in a folder of their own with a shell and skills. */
827
- const FILM_CLIENTS = new Set(["claude"]);
828
- /**
829
- * The installed client a film step of this class runs on, and the model it names; or why a
830
- * film cannot be made here. Films never run on credits or keys: one takes a client many minutes.
831
- */
832
- export async function filmClient(cls) {
833
- const cfg = await config();
834
- const client = managed ? null : harness(cfg.settings.source);
835
- if (!client || !FILM_CLIENTS.has(client.id)) {
836
- return {
837
- problem: note("claudeCodeMakesFilms"),
838
- };
839
- }
840
- const status = await detectHarness(client.id);
841
- if (!status?.version) {
842
- return { problem: notInstalled(client) };
843
- }
844
- if (status.auth === "none") {
845
- return { problem: signedOut(client) };
846
- }
847
- // A class that thinks on Apple Intelligence makes its films on the client's model of the class.
848
- const ref = ownRef(cfg, cls);
849
- return {
850
- client,
851
- alias: ref.startsWith(`${client.id}/`) ? ref.slice(client.id.length + 1) : client.classes[cls],
852
- };
853
- }
854
- /** Whether any text model can answer at all: the studio says so before the first chat turn. */
855
- export async function hasTextModel() {
856
- try {
857
- await textModel("standard");
858
- return true;
859
- }
860
- catch {
861
- return false;
862
- }
863
- }
864
- export async function classWays() {
865
- const cfg = await config();
866
- const ways = {};
867
- for (const cls of MODEL_CLASSES) {
868
- const ref = ownRef(cfg, cls);
869
- if (ref) {
870
- const { provider, vendor } = parse(ref);
871
- const client = provider === null && isHarnessVendor(vendor);
872
- ways[cls] = {
873
- kind: client ? "client" : isLocalProvider(provider) ? "local" : "key",
874
- by: client
875
- ? vendor
876
- : isLocalProvider(provider)
877
- ? provider
878
- : providerOfRef(ref) === "gateway" && !cfg.keys.gateway
879
- ? vendor
880
- : providerOfRef(ref),
881
- ref,
882
- problem: client
883
- ? null
884
- : provider === "apple"
885
- ? await appleProblem(cls)
886
- : await gatewayProblem(cls, ref),
887
- };
888
- continue;
889
- }
890
- let problem = null;
891
- const access = await creditAccess(cfg, creditsChosen(cfg, cls)).catch((err) => {
892
- problem = saidOf(err);
893
- return null;
894
- });
895
- ways[cls] = access
896
- ? {
897
- kind: "credits",
898
- by: null,
899
- ref: creditsModelOf(cfg.settings.bindings[cls]) ??
900
- (await classCatalog())?.classes[cls]?.model ??
901
- "",
902
- problem: null,
903
- }
904
- : { kind: "none", by: null, ref: "", problem: problem ?? missingText(cfg, cls) };
905
- }
906
- return ways;
907
- }
908
- /**
909
- * Why this Mac's models do not take a class right now; null while they do. Text needs Apple
910
- * Intelligence switched on. A voice note needs only the Mac (macOS 26 on Apple silicon, the
911
- * helper; the system fetches a language on its first note), and ffmpeg for a recording it
912
- * cannot read itself: a browser's WebM or Ogg.
913
- */
914
- async function appleProblem(cls) {
915
- const status = await appleStatus();
916
- if (cls !== "audio") {
917
- return status.available ? null : appleUnavailableNote(status);
918
- }
919
- if (!status.supported || status.reason === "missing") {
920
- return appleUnavailableNote(status);
921
- }
922
- return (await hasFfmpeg()) ? null : note("macNeedsFfmpegTranscribe");
923
- }
924
- /** At start the ways are asked once, so a model the key cannot reach shows before a run meets it. */
925
- export async function checkModelsAtStart() {
926
- for (const [cls, way] of Object.entries(await classWays())) {
927
- if (way.kind !== "none" && way.problem) {
928
- console.warn(`models: ${cls}: ${saidText(way.problem, "en")}`);
929
- }
930
- }
931
- }
932
- /** The ways with their problems in a language, for whoever reads them. */
933
- export function waysIn(ways, lang) {
934
- return Object.fromEntries(Object.entries(ways).map(([cls, way]) => [
935
- cls,
936
- { ...way, problem: way.problem && saidText(way.problem, lang) },
937
- ]));
938
- }
939
- /** What the settings page shows: the choices, which keys are there (never the keys), and the ways. */
940
- export async function modelSettings(lang = "en") {
941
- const cfg = await config();
942
- return {
943
- source: cfg.settings.source,
944
- bindings: cfg.settings.bindings,
945
- ollamaUrl: cfg.settings.ollamaUrl ?? env.ollamaUrl,
946
- creditFallback: cfg.settings.creditFallback !== false,
947
- keys: Object.fromEntries(LOCAL_KEYS.map((k) => [k, Boolean(cfg.keys[k])])),
948
- ways: waysIn(await classWays(), lang),
949
- /** Apple Intelligence on this Mac: shown where the machine can run it, picked once it answers. */
950
- apple: managed ? null : await appleStatus(),
951
- /** What a class costs on the credits, where they are at hand. */
952
- prices: (await classCatalog())?.classes ?? null,
953
- /** The media models the credits pay for, which a binding may name. */
954
- creditModels: (await classCatalog())?.models ?? [],
955
- };
956
- }
957
- // --- Checking a key ------------------------------------------------------------------
958
- /** A cheap authenticated call: whether the provider takes the key. Nothing is generated. */
959
- export async function checkKey(name, key, lang = "en") {
960
- const requests = {
961
- openai: ["https://api.openai.com/v1/models", { authorization: `Bearer ${key}` }],
962
- anthropic: [
963
- "https://api.anthropic.com/v1/models?limit=1",
964
- { "x-api-key": key, "anthropic-version": "2023-06-01" },
965
- ],
966
- google: [
967
- "https://generativelanguage.googleapis.com/v1beta/models?pageSize=1",
968
- { "x-goog-api-key": key },
969
- ],
970
- fal: [
971
- "https://api.fal.ai/v1/models?endpoint_id=fal-ai/flux/schnell",
972
- { authorization: `Key ${key}` },
973
- ],
974
- elevenlabs: ["https://api.elevenlabs.io/v1/models", { "xi-api-key": key }],
975
- replicate: ["https://api.replicate.com/v1/account", { authorization: `Bearer ${key}` }],
976
- gateway: ["https://ai-gateway.vercel.sh/v1/credits", { authorization: `Bearer ${key}` }],
977
- };
978
- const [url, headers] = requests[name];
979
- try {
980
- const res = await fetch(url, { headers, signal: AbortSignal.timeout(10_000) });
981
- if (res.ok) {
982
- return { ok: true, message: null };
983
- }
984
- const body = await res.text().catch(() => "");
985
- // A key restricted to some permissions is still a key the provider knows.
986
- if (res.status === 403 || /missing_permissions/.test(body)) {
987
- return { ok: true, message: null };
988
- }
989
- return {
990
- ok: false,
991
- message: res.status === 401
992
- ? serverText(lang, "keyUnknown")
993
- : serverText(lang, "providerError", { status: String(res.status) }),
994
- };
995
- }
996
- catch {
997
- return {
998
- ok: false,
999
- message: serverText(lang, "providerUnreachable"),
1000
- };
1001
- }
1002
- }
1003
- let catalog = new Map();
1004
- let catalogLoadedAt = 0;
1005
- /** Public prices of the AI Gateway: what a runtime that runs alone shows as the cost of a run. */
1006
- export async function loadCatalog(force = false) {
1007
- if (!force && Date.now() - catalogLoadedAt < 6 * 3600_000 && catalog.size) {
1008
- return;
1009
- }
1010
- try {
1011
- const res = await fetch("https://ai-gateway.vercel.sh/v1/models", {
1012
- signal: AbortSignal.timeout(10_000),
1013
- });
1014
- const body = (await res.json());
1015
- catalog = new Map(body.data.map((m) => [m.id, m]));
1016
- catalogLoadedAt = Date.now();
1017
- }
1018
- catch {
1019
- // Prices fall back to conservative defaults below.
1020
- }
1021
- }
1022
- /** The AI Gateway's prices, by its id of the model: what an own key of the same model costs too. */
1023
- function priceOf(ref) {
1024
- const { provider, id } = parse(ref);
1025
- return (catalog.get(provider === null || provider === "gateway" ? id : `${provider}/${id}`)?.pricing ??
1026
- {});
1027
- }
1028
- /** A model's context window in tokens, as the AI Gateway's catalog gives it; null where unknown. */
1029
- export function contextWindowOf(ref) {
1030
- const { provider, id } = parse(ref);
1031
- const entry = catalog.get(provider === null || provider === "gateway" ? id : `${provider}/${id}`);
1032
- return typeof entry?.context_window === "number" ? entry.context_window : null;
1033
- }
1034
- const n = (v, fallback) => {
1035
- const x = Number(v);
1036
- return Number.isFinite(x) ? x : fallback;
1037
- };
1038
- export function usageOf(u) {
1039
- return {
1040
- inputTokens: u?.inputTokens ?? 0,
1041
- outputTokens: u?.outputTokens ?? 0,
1042
- cachedInputTokens: u?.cachedInputTokens ?? u?.inputTokenDetails?.cacheReadTokens ?? 0,
1043
- };
1044
- }
1045
- /** A class's model as Mastra's `Agent` takes it: the AI SDK's model, typed by Mastra's own copy of it. */
1046
- export function agentModel(resolved) {
1047
- return resolved.model;
1048
- }
1049
- /**
1050
- * What an agent's call used over all its steps: `totalUsage` where Mastra's result has it, else
1051
- * `usage`. Takes a stream's promises and a finished call's values alike.
1052
- */
1053
- export async function totalUsage(out) {
1054
- const result = out;
1055
- return (await result.totalUsage) ?? (await result.usage);
1056
- }
1057
- /** Provider cost of a text call a runtime that runs alone made; the gateway books the others itself. */
1058
- export function costOf(resolved, usage) {
1059
- // An installed client answers on its subscription: nothing to book.
1060
- return resolved.metered || isHarnessVendor(resolved.vendor)
1061
- ? 0
1062
- : tokenCostUsd(resolved.ref, usageOf(usage));
1063
- }
1064
- export function tokenCostUsd(ref, usage) {
1065
- if (!usage) {
1066
- return 0;
1067
- }
1068
- const p = priceOf(ref);
1069
- const input = n(p.input, 0.000003);
1070
- const output = n(p.output, 0.000015);
1071
- const cached = n(p.input_cache_read, input / 10);
1072
- const cachedTokens = usage.cachedInputTokens ?? 0;
1073
- const freshInput = Math.max(0, (usage.inputTokens ?? 0) - cachedTokens);
1074
- return freshInput * input + cachedTokens * cached + (usage.outputTokens ?? 0) * output;
1075
- }
1076
- export function imageCostUsd(ref) {
1077
- const p = priceOf(ref);
1078
- const tiers = p.image_dimension_quality_pricing;
1079
- const tier = tiers?.find((t) => t.size === "default") ?? tiers?.[0];
1080
- return n(tier?.cost ?? p.image, 0.08);
1081
- }
1082
- export function videoCostUsd(ref, seconds, resolution = "720p") {
1083
- const p = priceOf(ref);
1084
- const tiers = p.video_duration_pricing;
1085
- // We render at 720p or 480p with sound: price that tier where the catalog has one; else the
1086
- // dearest below 4K, so the estimate is never short.
1087
- const exact = tiers?.filter((t) => t.resolution === resolution) ?? [];
1088
- const usable = exact.length ? exact : (tiers?.filter((t) => t.resolution !== "4k") ?? []);
1089
- const withAudio = usable.filter((t) => t.audio !== false);
1090
- const pick = withAudio.length ? withAudio : usable;
1091
- const perSecond = pick.length ? Math.max(...pick.map((t) => n(t.cost_per_second, 0))) : 0.4;
1092
- return perSecond * seconds;
1093
- }
1094
- /** Speech is priced per character read, or per audio token (about 25 a second, 15 characters). */
1095
- export function speechCostUsd(ref, characters) {
1096
- const p = priceOf(ref);
1097
- if (p.speech_input_character_cost !== undefined) {
1098
- return n(p.speech_input_character_cost, 0.00003) * characters;
1099
- }
1100
- return n(p.audio_output_token_cost, 0.00001) * Math.ceil((characters / 15) * 25);
1101
- }
1102
- export const WEB_SEARCH_COST_USD = 0.01;
1103
- /** A transcript, priced by the minute; the gateway's catalog has no transcription prices. */
1104
- export function transcriptionCostUsd(seconds) {
1105
- return (seconds / 60) * 0.006;
1106
- }