@engenty/wizards-runtime 0.14.2 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (263) hide show
  1. package/apps/runtime/dist/agents/studio-assistant.js +180 -4
  2. package/apps/runtime/dist/agents/website.js +10 -5
  3. package/apps/runtime/dist/app.js +27 -2
  4. package/apps/runtime/dist/auth/index.js +5 -0
  5. package/apps/runtime/dist/broker/account.js +5 -0
  6. package/apps/runtime/dist/broker/call.js +2 -0
  7. package/apps/runtime/dist/broker/host.js +1 -0
  8. package/apps/runtime/dist/broker/index.js +5 -0
  9. package/apps/runtime/dist/broker/rwx.js +293 -11
  10. package/apps/runtime/dist/cli/main.js +7 -0
  11. package/apps/runtime/dist/cli/move-files.js +68 -0
  12. package/apps/runtime/dist/cli/move-folder-sources.js +120 -0
  13. package/apps/runtime/dist/connectors/plugin-connections.js +74 -4
  14. package/apps/runtime/dist/db/migrations/tenant/0040_rwx_elements.sql +21 -0
  15. package/apps/runtime/dist/db/migrations/tenant/0041_broker_log_client.sql +1 -0
  16. package/apps/runtime/dist/db/migrations/tenant/0042_client_spaces.sql +16 -0
  17. package/apps/runtime/dist/db/migrations/tenant/0043_space_member_invite.sql +19 -0
  18. package/apps/runtime/dist/db/migrations/tenant/0044_client_portal.sql +8 -0
  19. package/apps/runtime/dist/db/migrations/tenant/0045_client_portal_no_slug.sql +2 -0
  20. package/apps/runtime/dist/db/migrations/tenant/0046_space_file_hash.sql +2 -0
  21. package/apps/runtime/dist/db/migrations/tenant/0047_knowledge_folders.sql +3 -0
  22. package/apps/runtime/dist/db/migrations/tenant/0048_space_chunk_kind.sql +1 -0
  23. package/apps/runtime/dist/db/migrations/tenant/0049_knowledge_sources.sql +57 -0
  24. package/apps/runtime/dist/db/migrations/tenant/0050_dateien.sql +71 -0
  25. package/apps/runtime/dist/db/migrations/tenant/0051_dateien_drafts.sql +23 -0
  26. package/apps/runtime/dist/db/migrations/tenant/0052_dateien_plugin_kinds.sql +5 -0
  27. package/apps/runtime/dist/db/migrations/tenant/0053_dateien_file_title.sql +3 -0
  28. package/apps/runtime/dist/db/migrations/tenant/0054_dateien_ocr.sql +14 -0
  29. package/apps/runtime/dist/db/migrations/tenant/0055_dateien_doc_reread.sql +3 -0
  30. package/apps/runtime/dist/db/migrations/tenant/meta/0040_snapshot.json +5153 -0
  31. package/apps/runtime/dist/db/migrations/tenant/meta/0041_snapshot.json +5160 -0
  32. package/apps/runtime/dist/db/migrations/tenant/meta/0042_snapshot.json +5286 -0
  33. package/apps/runtime/dist/db/migrations/tenant/meta/0043_snapshot.json +5293 -0
  34. package/apps/runtime/dist/db/migrations/tenant/meta/0044_snapshot.json +5344 -0
  35. package/apps/runtime/dist/db/migrations/tenant/meta/0045_snapshot.json +5329 -0
  36. package/apps/runtime/dist/db/migrations/tenant/meta/0046_snapshot.json +5343 -0
  37. package/apps/runtime/dist/db/migrations/tenant/meta/0047_snapshot.json +5391 -0
  38. package/apps/runtime/dist/db/migrations/tenant/meta/0048_snapshot.json +5398 -0
  39. package/apps/runtime/dist/db/migrations/tenant/meta/0049_snapshot.json +5793 -0
  40. package/apps/runtime/dist/db/migrations/tenant/meta/0050_snapshot.json +6288 -0
  41. package/apps/runtime/dist/db/migrations/tenant/meta/0051_snapshot.json +6461 -0
  42. package/apps/runtime/dist/db/migrations/tenant/meta/0052_snapshot.json +6497 -0
  43. package/apps/runtime/dist/db/migrations/tenant/meta/0053_snapshot.json +6504 -0
  44. package/apps/runtime/dist/db/migrations/tenant/meta/0054_snapshot.json +6504 -0
  45. package/apps/runtime/dist/db/migrations/tenant/meta/0055_snapshot.json +6504 -0
  46. package/apps/runtime/dist/db/migrations/tenant/meta/_journal.json +112 -0
  47. package/apps/runtime/dist/db/schema.js +296 -5
  48. package/apps/runtime/dist/docs/dev/api.md +49 -2
  49. package/apps/runtime/dist/docs/dev/architecture.md +13 -2
  50. package/apps/runtime/dist/docs/dev/plugins/connections.md +30 -2
  51. package/apps/runtime/dist/docs/dev/plugins/index.md +1 -1
  52. package/apps/runtime/dist/docs/dev/plugins/reference.md +7 -4
  53. package/apps/runtime/dist/docs/dev/plugins/server.md +11 -5
  54. package/apps/runtime/dist/docs/dev/plugins/space.md +130 -4
  55. package/apps/runtime/dist/docs/dev/plugins/studio.md +13 -3
  56. package/apps/runtime/dist/docs/user-guide/command-line.md +2 -0
  57. package/apps/runtime/dist/docs/user-guide/plugins.md +1 -1
  58. package/apps/runtime/dist/docs/user-guide/space.md +6 -6
  59. package/apps/runtime/dist/docs/user-guide/steps.md +1 -1
  60. package/apps/runtime/dist/documents/ocr.js +72 -0
  61. package/apps/runtime/dist/documents/parse.js +81 -12
  62. package/apps/runtime/dist/elements/caller.js +47 -0
  63. package/apps/runtime/dist/elements/catalogue.js +14 -0
  64. package/apps/runtime/dist/elements/connections.js +60 -0
  65. package/apps/runtime/dist/elements/gate.js +81 -0
  66. package/apps/runtime/dist/elements/knowledge.js +308 -0
  67. package/apps/runtime/dist/elements/outside.js +103 -0
  68. package/apps/runtime/dist/elements/specs.js +102 -0
  69. package/apps/runtime/dist/elements/wizards.js +72 -0
  70. package/apps/runtime/dist/engenty/connections-google/connectors/drive.js +3 -0
  71. package/apps/runtime/dist/engenty/connections-microsoft/onedrive.js +3 -0
  72. package/apps/runtime/dist/engenty/connections-s3/s3.js +6 -0
  73. package/apps/runtime/dist/engine/runner.js +19 -2
  74. package/apps/runtime/dist/engine/steps.js +1 -1
  75. package/apps/runtime/dist/env.js +11 -2
  76. package/apps/runtime/dist/files/blobs.js +57 -1
  77. package/apps/runtime/dist/files/objects.js +1 -0
  78. package/apps/runtime/dist/files/pictures.js +41 -0
  79. package/apps/runtime/dist/files/storage.js +14 -26
  80. package/apps/runtime/dist/files/thumbs.js +77 -0
  81. package/apps/runtime/dist/files/upload-check.js +2 -2
  82. package/apps/runtime/dist/index.js +22 -0
  83. package/apps/runtime/dist/live/views.js +2 -1
  84. package/apps/runtime/dist/manage.js +4 -1
  85. package/apps/runtime/dist/mcp/elements.js +88 -0
  86. package/apps/runtime/dist/mcp/handler.js +2 -0
  87. package/apps/runtime/dist/mcp/scopes.js +5 -0
  88. package/apps/runtime/dist/mcp/tools.js +5 -0
  89. package/apps/runtime/dist/models.js +82 -13
  90. package/apps/runtime/dist/mounts/cache.js +71 -0
  91. package/apps/runtime/dist/mounts/drafts.js +367 -0
  92. package/apps/runtime/dist/mounts/folder.js +148 -0
  93. package/apps/runtime/dist/mounts/mounts.js +1315 -0
  94. package/apps/runtime/dist/mounts/source.js +179 -0
  95. package/apps/runtime/dist/mounts/units.js +97 -0
  96. package/apps/runtime/dist/move-files.js +4 -0
  97. package/apps/runtime/dist/plugins/loader.js +73 -1
  98. package/apps/runtime/dist/plugins/registry.js +2 -0
  99. package/apps/runtime/dist/prompts/authoring.md +2 -2
  100. package/apps/runtime/dist/prompts/goose.md +13 -1
  101. package/apps/runtime/dist/prompts/tools.md +8 -2
  102. package/apps/runtime/dist/render/convert.js +188 -1
  103. package/apps/runtime/dist/routes/api.js +7 -2
  104. package/apps/runtime/dist/routes/client-contract.js +164 -0
  105. package/apps/runtime/dist/routes/client-spaces.js +58 -0
  106. package/apps/runtime/dist/routes/dateien.js +173 -0
  107. package/apps/runtime/dist/routes/elements.js +76 -0
  108. package/apps/runtime/dist/routes/plugins.js +2 -1
  109. package/apps/runtime/dist/routes/runs.js +24 -10
  110. package/apps/runtime/dist/routes/studio.js +168 -8
  111. package/apps/runtime/dist/secrets/signing.js +16 -0
  112. package/apps/runtime/dist/services/client-portal.js +439 -0
  113. package/apps/runtime/dist/services/client-spaces.js +228 -0
  114. package/apps/runtime/dist/services/cloud.js +2 -0
  115. package/apps/runtime/dist/services/knowledge-model.js +24 -8
  116. package/apps/runtime/dist/services/knowledge.js +72 -42
  117. package/apps/runtime/dist/services/links.js +17 -0
  118. package/apps/runtime/dist/services/members-studio.js +5 -1
  119. package/apps/runtime/dist/services/page-pictures.js +162 -0
  120. package/apps/runtime/dist/services/runs.js +22 -6
  121. package/apps/runtime/dist/services/space-categories.js +41 -5
  122. package/apps/runtime/dist/services/space-data.js +165 -8
  123. package/apps/runtime/dist/services/space-files.js +102 -19
  124. package/apps/runtime/dist/services/space-index.js +384 -41
  125. package/apps/runtime/dist/services/space-origin.js +25 -1
  126. package/apps/runtime/dist/services/space-sources.js +937 -0
  127. package/apps/runtime/dist/services/spaces.js +60 -12
  128. package/apps/runtime/dist/services/synced-spaces.js +10 -1
  129. package/apps/runtime/dist/services/work-ai.js +53 -24
  130. package/apps/runtime/dist/services/work-chats.js +3 -2
  131. package/apps/runtime/dist/services/work-connections.js +2 -2
  132. package/apps/runtime/dist/sharing/index.js +2 -0
  133. package/apps/runtime/dist/store/index.js +29 -8
  134. package/apps/runtime/dist/store/shared-lists.js +30 -17
  135. package/apps/runtime/dist/sync/records.js +22 -27
  136. package/apps/runtime/dist/texts.js +4 -0
  137. package/apps/runtime/dist/tools/index.js +5 -4
  138. package/apps/runtime/dist/tools/pages.js +1 -1
  139. package/apps/runtime/dist/tools/skills.js +80 -54
  140. package/apps/runtime/dist/tools/space.js +8 -152
  141. package/apps/runtime/dist/widgets/step.js +2 -1
  142. package/apps/web/dist/assets/AboutDialog-0q4P80yv.js +1 -0
  143. package/apps/web/dist/assets/BlockEditor-CUYFH_CU.js +173 -0
  144. package/apps/web/dist/assets/BlockEditor-CtW6lw0y.css +1 -0
  145. package/apps/web/dist/assets/CapabilitiesPage-BlZP8DYb.js +2 -0
  146. package/apps/web/dist/assets/{ChangelogDialog-D_dQOMIq.js → ChangelogDialog-CDN7kMs1.js} +1 -1
  147. package/apps/web/dist/assets/{CodeEditor-nxoOt8ge.js → CodeEditor-D-Y16fdk.js} +1 -1
  148. package/apps/web/dist/assets/EditorPage-CrMVsgUt.js +3 -0
  149. package/apps/web/dist/assets/{FlowPreview-aMfwcPul.js → FlowPreview-DXnk7m9P.js} +1 -1
  150. package/apps/web/dist/assets/{LangSwitch-DpD0inR4.js → LangSwitch-Dkd0FBIH.js} +1 -1
  151. package/apps/web/dist/assets/Marketplace-Cty40VwG.js +2 -0
  152. package/apps/web/dist/assets/NewWizardChannels-Czool7s1.js +1 -0
  153. package/apps/web/dist/assets/NewWizardPage-CfVe_4a2.js +7 -0
  154. package/apps/web/dist/assets/OnboardingPage-D3SEpTmt.js +1 -0
  155. package/apps/web/dist/assets/PreviewPane-CQDKQO6z.js +7 -0
  156. package/apps/web/dist/assets/PublicRunner-BDZNnlQw.js +1 -0
  157. package/apps/web/dist/assets/ReadOnly-B7MUySpC.js +1 -0
  158. package/apps/web/dist/assets/SettingsPage-Bgurv3l2.js +2 -0
  159. package/apps/web/dist/assets/SetupPage-C3km8vqv.js +1 -0
  160. package/apps/web/dist/assets/{SharePage-N80EhoD7.js → SharePage-UwEJBIzq.js} +1 -1
  161. package/apps/web/dist/assets/SkillEditor-BaEiqqXl.js +1 -0
  162. package/apps/web/dist/assets/Skills-Bv6XbKxc.js +9 -0
  163. package/apps/web/dist/assets/SpacePage-D9PXLSU_.js +2 -0
  164. package/apps/web/dist/assets/UpdateCheck-C7I43zFZ.js +2 -0
  165. package/apps/web/dist/assets/changelog-DwgWiSZb.js +1 -0
  166. package/apps/web/dist/assets/circle-check-DDLzlcXP.js +1 -0
  167. package/apps/web/dist/assets/code-DsnwzN1x.js +1 -0
  168. package/apps/web/dist/assets/code-editor-Ca5EAxmd.js +2 -0
  169. package/apps/web/dist/assets/code-xml-S4IFi5Jc.js +1 -0
  170. package/apps/web/dist/assets/connection-sign-in-hI3HXhq4.js +1 -0
  171. package/apps/web/dist/assets/{dist-H1UN89OA.js → dist-B3Ray2U5.js} +1 -1
  172. package/apps/web/dist/assets/dist-CQpLJoQZ.js +10 -0
  173. package/apps/web/dist/assets/{dist-GlRRx9Xl.js → dist-D1uGQ_tB.js} +1 -1
  174. package/apps/web/dist/assets/{dist-BdDd1FxP.js → dist-DFI-tsfx.js} +1 -1
  175. package/apps/web/dist/assets/eye-TJSuiHHO.js +1 -0
  176. package/apps/web/dist/assets/floating-ui.dom-pwdNGv4b.js +1 -0
  177. package/apps/web/dist/assets/host-D5hNHbhF.js +125 -0
  178. package/apps/web/dist/assets/i18n-BBzMbGoo.js +55 -0
  179. package/apps/web/dist/assets/index-CyBrvupM.js +10 -0
  180. package/apps/web/dist/assets/index-w-3J3ZJ9.css +1 -0
  181. package/apps/web/dist/assets/{json-CEsfHdlZ.js → json-Ce3iHrtf.js} +1 -1
  182. package/apps/web/dist/assets/link-CPL8pB1P.js +1 -0
  183. package/apps/web/dist/assets/list-checks-DaxmUPqK.js +1 -0
  184. package/apps/web/dist/assets/{markdown-5-I9_izp.js → markdown-hqKQy2pp.js} +1 -1
  185. package/apps/web/dist/assets/marked.esm-DQ7XA7AC.js +67 -0
  186. package/apps/web/dist/assets/oss-credits-BrwV0a4F.js +1 -0
  187. package/apps/web/dist/assets/pdf-Dg-raaUo.js +54 -0
  188. package/apps/web/dist/assets/pdf.worker.min-68CMzziE.js +1 -0
  189. package/apps/web/dist/assets/pdf.worker.min-CjEcRF4W.mjs +28 -0
  190. package/apps/web/dist/assets/phone-B4uKDBFq.js +1 -0
  191. package/apps/web/dist/assets/read-aloud-Bfp9_bUY.js +1 -0
  192. package/apps/web/dist/assets/{runners-CyIvJIHr.js → runners-CUpBpSji.js} +1 -1
  193. package/apps/web/dist/assets/scroll-text-BEnPzQEi.js +1 -0
  194. package/apps/web/dist/assets/session-CMQo8P-G.js +2 -0
  195. package/apps/web/dist/assets/table-5B9G3oA6.js +1 -0
  196. package/apps/web/dist/assets/theme-CdX0marK.js +11 -0
  197. package/apps/web/dist/assets/ui-BCfu5sia.js +16 -0
  198. package/apps/web/dist/assets/upload-CAlHC232.js +1 -0
  199. package/apps/web/dist/assets/{useMutation-DEkZhp5c.js → useMutation-1fV4Nnxq.js} +1 -1
  200. package/apps/web/dist/assets/viewers-ChriFcRy.js +2 -0
  201. package/apps/web/dist/assets/volume-2-BqlBtCIJ.js +1 -0
  202. package/apps/web/dist/assets/w3c-keyname-BOAvb0qz.js +1 -0
  203. package/apps/web/dist/assets/xlsx-CuSbHU4R.js +141 -0
  204. package/apps/web/dist/index.html +19 -14
  205. package/apps/web/dist/mcp/flow.html +2 -2
  206. package/node_modules/@engenty/wizards/dist/plugin/index.d.ts +223 -4
  207. package/node_modules/@engenty/wizards/dist/plugin/mount.d.ts +123 -0
  208. package/node_modules/@engenty/wizards/dist/plugin/mount.js +7 -0
  209. package/node_modules/@engenty/wizards/dist/plugin/studio.d.ts +110 -1
  210. package/node_modules/@engenty/wizards-shared/dist/connectors.d.ts +1 -1
  211. package/node_modules/@engenty/wizards-shared/dist/feature-flags.d.ts +24 -0
  212. package/node_modules/@engenty/wizards-shared/dist/feature-flags.js +24 -0
  213. package/node_modules/@engenty/wizards-shared/dist/knowledge.d.ts +33 -4
  214. package/node_modules/@engenty/wizards-shared/dist/run.d.ts +6 -0
  215. package/node_modules/@engenty/wizards-shared/dist/run.js +12 -0
  216. package/node_modules/@engenty/wizards-shared/dist/rwx.d.ts +21 -4
  217. package/node_modules/@engenty/wizards-shared/dist/rwx.js +30 -3
  218. package/node_modules/@engenty/wizards-shared/dist/spaces.d.ts +11 -1
  219. package/node_modules/@engenty/wizards-shared/dist/spaces.js +9 -2
  220. package/node_modules/@engenty/wizards-shared/dist/text-merge.d.ts +6 -0
  221. package/node_modules/@engenty/wizards-shared/dist/text-merge.js +25 -0
  222. package/package.json +3 -1
  223. package/plugin/.claude-plugin/plugin.json +1 -1
  224. package/plugin/README.md +3 -0
  225. package/plugin/plugin.json +1 -1
  226. package/plugin/skills/work-in-space/SKILL.md +16 -0
  227. package/apps/web/dist/assets/AboutDialog-Cag3RJuT.js +0 -1
  228. package/apps/web/dist/assets/CapabilitiesPage-BQYiN0gT.js +0 -2
  229. package/apps/web/dist/assets/EditorPage-C4_8LsQN.js +0 -3
  230. package/apps/web/dist/assets/Marketplace-CpzD9pNQ.js +0 -2
  231. package/apps/web/dist/assets/NewWizardChannels-CcE3UMVb.js +0 -1
  232. package/apps/web/dist/assets/NewWizardPage-BzN7zrQx.js +0 -7
  233. package/apps/web/dist/assets/OnboardingPage-ztHT01ah.js +0 -1
  234. package/apps/web/dist/assets/PreviewPane-BabMbBZI.js +0 -9
  235. package/apps/web/dist/assets/PublicRunner-D-JmtqCi.js +0 -1
  236. package/apps/web/dist/assets/ReadOnly-GAORKKqV.js +0 -1
  237. package/apps/web/dist/assets/SettingsPage-BKAiYmXl.js +0 -2
  238. package/apps/web/dist/assets/SetupPage-C1EZZHIp.js +0 -1
  239. package/apps/web/dist/assets/SkillEditor-CqQMg2MC.js +0 -1
  240. package/apps/web/dist/assets/Skills-CnhpgoOA.js +0 -9
  241. package/apps/web/dist/assets/SpacePage-CRR8JvV1.js +0 -2
  242. package/apps/web/dist/assets/UpdateCheck-CfXZBQNv.js +0 -2
  243. package/apps/web/dist/assets/changelog-6MqC8Vy8.js +0 -1
  244. package/apps/web/dist/assets/circle-alert-C8Ma-bPY.js +0 -1
  245. package/apps/web/dist/assets/circle-check-Bu9Z3mlJ.js +0 -1
  246. package/apps/web/dist/assets/code-editor-CfTGqOpp.js +0 -2
  247. package/apps/web/dist/assets/code-xml-B4kLFZSj.js +0 -1
  248. package/apps/web/dist/assets/connection-sign-in-B2D0O8W-.js +0 -1
  249. package/apps/web/dist/assets/dist-EBVTpvRr.js +0 -10
  250. package/apps/web/dist/assets/eye-BpoKpIdt.js +0 -1
  251. package/apps/web/dist/assets/host-BlKXX7YK.js +0 -118
  252. package/apps/web/dist/assets/i18n-BJ7Ld6O6.js +0 -55
  253. package/apps/web/dist/assets/index-66tE1oti.js +0 -10
  254. package/apps/web/dist/assets/index-D18DvnxX.css +0 -1
  255. package/apps/web/dist/assets/oss-credits-IdX5bc71.js +0 -1
  256. package/apps/web/dist/assets/phone-Ctvf-Am-.js +0 -1
  257. package/apps/web/dist/assets/read-aloud-Da_RSm2S.js +0 -1
  258. package/apps/web/dist/assets/scroll-text-ChrjRu9Y.js +0 -1
  259. package/apps/web/dist/assets/session-SXPtTWRK.js +0 -2
  260. package/apps/web/dist/assets/theme-Br1S0j5h.js +0 -11
  261. package/apps/web/dist/assets/ui-Uqnx1UpK.js +0 -82
  262. package/apps/web/dist/assets/upload-BchUnQGV.js +0 -1
  263. package/apps/web/dist/assets/volume-2-CU_oy81Z.js +0 -1
@@ -0,0 +1,76 @@
1
+ import { Hono } from "hono";
2
+ import { z } from "zod";
3
+ import { clientOf } from "../clients.js";
4
+ import { callOutside, RUN_COMMAND } from "../elements/outside.js";
5
+ import { ELEMENT_SPECS, ELEMENT_TOOL_NAMES } from "../elements/specs.js";
6
+ import { caller, inTenantAs } from "./api.js";
7
+ /**
8
+ * The space's elements on the API (docs/plans/modular.md, phase 2): the same calls as the MCP
9
+ * tools, made from the catalogue's specs, for a program with a key or token. `GET` lists the
10
+ * calls the token may make with their inputs as JSON Schema; `POST /:name` makes one, as the
11
+ * token's person, in the space of the path (checked against the token, I2).
12
+ */
13
+ const calls = () => [
14
+ ...ELEMENT_TOOL_NAMES.map((name) => ({
15
+ name,
16
+ scope: ELEMENT_SPECS[name].scope,
17
+ description: ELEMENT_SPECS[name].description(),
18
+ input: ELEMENT_SPECS[name].input,
19
+ })),
20
+ {
21
+ name: "run_command",
22
+ scope: RUN_COMMAND.scope,
23
+ description: "Runs a shell command in the sandbox where loaded skills put their scripts.",
24
+ input: RUN_COMMAND.input,
25
+ },
26
+ ];
27
+ const callBody = z.object({ input: z.record(z.string(), z.unknown()).default({}) });
28
+ export const elementRoutes = new Hono()
29
+ .get("/spaces/:spaceId/elements", async (c) => {
30
+ const who = await caller(c, [], { clients: true });
31
+ if (who instanceof Response) {
32
+ return who;
33
+ }
34
+ return c.json({
35
+ calls: calls()
36
+ .filter((call) => who.scopes.includes(call.scope))
37
+ .map(({ input, ...call }) => ({
38
+ ...call,
39
+ input: z.toJSONSchema(input, { unrepresentable: "any" }),
40
+ })),
41
+ });
42
+ })
43
+ .post("/spaces/:spaceId/elements/:name", async (c) => {
44
+ const who = await caller(c, [], { clients: true });
45
+ if (who instanceof Response) {
46
+ return who;
47
+ }
48
+ const name = c.req.param("name");
49
+ const call = calls().find((k) => k.name === name);
50
+ if (!call) {
51
+ return c.json({ error: `No call ${name}.`, code: "not_found" }, 404);
52
+ }
53
+ if (!who.scopes.includes(call.scope)) {
54
+ return c.json({ error: "This token isn’t allowed to do that.", code: "insufficient_scope" }, 403);
55
+ }
56
+ const body = callBody.safeParse(await c.req.json().catch(() => ({})));
57
+ if (!body.success) {
58
+ return c.json({ error: "Invalid input", code: "invalid", issues: body.error.issues }, 400);
59
+ }
60
+ const result = await inTenantAs(who, () => callOutside({
61
+ userId: who.userId,
62
+ role: who.role,
63
+ client: clientOf(c) ?? who.client,
64
+ tenantId: who.tenantId,
65
+ scopes: who.scopes,
66
+ }, c.req.param("spaceId"), name, body.data.input, c.req.raw.signal)).catch((err) => ({
67
+ ok: false,
68
+ error: String(err?.message ?? err).slice(0, 400),
69
+ status: err?.code === "not_found" ? 404 : 500,
70
+ }));
71
+ if (result.ok) {
72
+ return c.json({ result: result.result });
73
+ }
74
+ const status = "status" in result ? result.status : 403;
75
+ return c.json({ error: result.error, ...("data" in result ? { data: result.data } : {}) }, status);
76
+ });
@@ -54,7 +54,8 @@ export function answerOf(err) {
54
54
  export async function dispatchAs(c, user) {
55
55
  const id = c.req.param("id") ?? "";
56
56
  const plugin = (await pluginIdsOf(user.tenantId)).has(id) ? loadedPlugin(id) : undefined;
57
- if (!plugin) {
57
+ // A client of the organization reaches no plugin's studio routes (docs/plans/client-spaces.md).
58
+ if (!plugin || user.role === "client") {
58
59
  return c.json(notFoundAnswer(c), 404);
59
60
  }
60
61
  const url = new URL(c.req.url);
@@ -37,12 +37,14 @@ import { transcribeAudio } from "../media/transcribe.js";
37
37
  import { errorText, ModelUnavailableError, noteOf } from "../model-errors.js";
38
38
  import { listDownload, renderDownload, stepHtml } from "../render/downloads.js";
39
39
  import { HTML_RESPONSE_CSP } from "../render/guard.js";
40
- import { runTicketValid, verifySignedUrl } from "../secrets/signing.js";
40
+ import { runTicketValid, runViewTicketValid, verifySignedUrl } from "../secrets/signing.js";
41
41
  import { brandView } from "../services/brand.js";
42
+ import { clientMayOpen } from "../services/client-portal.js";
42
43
  import { ServiceError } from "../services/errors.js";
43
44
  import { publicRunners, servePageRunner } from "../services/runners.js";
44
45
  import { sharedRun, sharedStepIds, shareImage, shareRun, shareView, unshareRun, } from "../services/shares.js";
45
46
  import { shippedFontCss, shippedFontFile } from "../services/shipped-fonts.js";
47
+ import { spaceFileBytes } from "../services/space-files.js";
46
48
  import { isLangCode, storedTranslation, translateResult, translationFor, uiTexts, } from "../services/translations.js";
47
49
  import { isIconFile, wizardAvatarSvg, wizardIcon } from "../services/wizard-icon.js";
48
50
  import { shareOverview } from "../sharing/index.js";
@@ -132,12 +134,21 @@ async function accessibleRun(c, runId, opts = {}) {
132
134
  if (runTicketValid(run.id, c.req.query("rt"))) {
133
135
  return run;
134
136
  }
137
+ // A ticket that only reads: a run the firm shared with a client (services/client-portal.ts).
138
+ if (c.req.method === "GET" && runViewTicketValid(run.id, c.req.query("rt"))) {
139
+ return run;
140
+ }
135
141
  const vid = visitorId(c, false);
136
142
  if (vid && run.visitorId === vid) {
137
143
  return run;
138
144
  }
139
145
  const user = await principalOf(c);
140
146
  if (user && user.tenantId === run.tenantId) {
147
+ // A client of the organization opens only the runs of their client spaces that are theirs
148
+ // or shared with them (docs/plans/client-portal.md); the firm opens every run.
149
+ if (user.role === "client" && !(await clientMayOpen(user.id, run))) {
150
+ return null;
151
+ }
141
152
  return run;
142
153
  }
143
154
  return null;
@@ -145,7 +156,7 @@ async function accessibleRun(c, runId, opts = {}) {
145
156
  /** Whether a signed-in member of the run's organization is looking, not the guest who ran it. */
146
157
  async function memberViewing(c, run) {
147
158
  const user = await principalOf(c);
148
- return !!user && user.tenantId === run.tenantId;
159
+ return !!user && user.tenantId === run.tenantId && user.role !== "client";
149
160
  }
150
161
  /**
151
162
  * What a step of a guest's run made from a connection the space keeps for its members stays in
@@ -508,12 +519,15 @@ export const publicRoutes = new Hono()
508
519
  });
509
520
  })
510
521
  .get("/logos/:id", async (c) => {
511
- const found = await loadAsset(c.req.param("id"));
512
- if (found?.row.kind !== "logo") {
522
+ const row = await db.query.spaceFile.findFirst({
523
+ where: eq(schema.spaceFile.id, c.req.param("id")),
524
+ });
525
+ const data = row?.kind === "logo" ? await spaceFileBytes(row) : null;
526
+ if (!row || !data) {
513
527
  return c.notFound();
514
528
  }
515
- return c.body(new Uint8Array(found.data), 200, {
516
- "content-type": bareMime(found.row.mime) ?? "application/octet-stream",
529
+ return c.body(new Uint8Array(data), 200, {
530
+ "content-type": bareMime(row.mime) ?? "application/octet-stream",
517
531
  "cache-control": "public, max-age=86400",
518
532
  "x-content-type-options": "nosniff",
519
533
  // An SVG logo is shown, never run.
@@ -554,12 +568,12 @@ export const publicRoutes = new Hono()
554
568
  ? await db.query.space.findFirst({ where: eq(schema.space.id, row.spaceId) })
555
569
  : null;
556
570
  const named = p?.brand.fonts?.some((f) => f.source && "file" in f.source && f.source.file === id);
557
- const found = named && row?.mime.startsWith("font/") ? await loadAsset(id) : null;
558
- if (!found) {
571
+ const data = named && row?.mime.startsWith("font/") ? await spaceFileBytes(row) : null;
572
+ if (!row || !data) {
559
573
  return c.notFound();
560
574
  }
561
- return c.body(new Uint8Array(found.data), 200, {
562
- "content-type": bareMime(found.row.mime) ?? "application/octet-stream",
575
+ return c.body(new Uint8Array(data), 200, {
576
+ "content-type": bareMime(row.mime) ?? "application/octet-stream",
563
577
  "cache-control": "public, max-age=86400",
564
578
  "x-content-type-options": "nosniff",
565
579
  "access-control-allow-origin": "*",
@@ -6,6 +6,7 @@ import { CATEGORY_TYPES, whereSchema } from "@engenty/wizards-shared/knowledge";
6
6
  import { PRESENCE_KINDS } from "@engenty/wizards-shared/live";
7
7
  import { CLASS_NAMES, isCreditsRef, modelLabel } from "@engenty/wizards-shared/providers";
8
8
  import { note } from "@engenty/wizards-shared/run";
9
+ import { AUDIENCES } from "@engenty/wizards-shared/rwx";
9
10
  import { SPACE_FILE_KINDS } from "@engenty/wizards-shared/spaces";
10
11
  import { MAX_MASK_LABEL_CHARS, MAX_MASK_LABELS, modelPolicySchema, } from "@engenty/wizards-shared/tiers";
11
12
  import { PACKAGE_EXTENSION, PACKAGE_MAX_BYTES, PACKAGE_MIME, } from "@engenty/wizards-shared/wizard-package";
@@ -21,7 +22,7 @@ import { answerBrowser, awaitBrowser } from "../assistant/browser.js";
21
22
  import { endRun, signalRun, startRun, takeSignals } from "../assistant/runs.js";
22
23
  import { accountOverview, linkedAccount, startLink, unlink } from "../auth/account.js";
23
24
  import { createLocalKey, deleteLocalKey, listLocalKeys } from "../auth/keys.js";
24
- import { assertRwx, subjectsOfPerson } from "../broker/rwx.js";
25
+ import { assertRwx, folderAudience, setFolderAudience, subjectsOfPerson } from "../broker/rwx.js";
25
26
  import { appStates, connectApps } from "../cli/connect.js";
26
27
  import { layout } from "../cli/home.js";
27
28
  import { connectorImportSchema, importConnector, previewSource, refreshConnector, registryService, removeConnector, searchRegistry, } from "../connectors/external.js";
@@ -65,9 +66,10 @@ import { profileSchema, saveProfile, saveUserLang, userLang, userProfile, } from
65
66
  import { runnersOf, wizardRunners } from "../services/runners.js";
66
67
  import { draftStepView, listResults, listRuns, startTestRun } from "../services/runs.js";
67
68
  import { addCategoryValue, categoryRow, categoryValue, deleteCategory, deleteCategoryValue, mergeCategoryValues, orderCategoryValues, putCategory, renameCategoryValue, setItemCategory, updateCategory, } from "../services/space-categories.js";
68
- import { addTableRow, createPage, createTable, deletePage, deleteTable, deleteTableRows, getPage, getTable, listSpaceData, orderSubPages, updatePage, updateTable, updateTableRow, } from "../services/space-data.js";
69
- import { addSpaceFile, addSpaceFileFromUrl, fileView, orderSpaceFiles, reindexSpaceFile, removeSpaceFile, spaceFile, spaceFileContent, updateSpaceFile, } from "../services/space-files.js";
69
+ import { addTableRow, createPage, createTable, deletePage, deleteTable, deleteTableRows, getPage, getTable, listSpaceData, moveKnowledgeItem, orderSubPages, updatePage, updateTable, updateTableRow, } from "../services/space-data.js";
70
+ import { addSpaceFile, addSpaceFileFromUrl, fileView, orderSpaceFiles, pictureToBrand, reindexSpaceFile, removeSpaceFile, spaceFile, spaceFileContent, spaceFileThumb, updateSpaceFile, } from "../services/space-files.js";
70
71
  import { documentText, queueIndex, reindexAll, searchKnowledge } from "../services/space-index.js";
72
+ import { addSourceEntries, getSource, keepItem, listSources, proposeSource, removeSource, setEntryIncluded, startSource, stopSource, takeSource, updateSourceSettings, } from "../services/space-sources.js";
71
73
  import { createSpace, deleteSpace, gradientSchema, ownedSpace, spaceLimitOrNull, spacePatchSchema, updateSpace, } from "../services/spaces.js";
72
74
  import { deleteTheme, listThemes, saveTheme } from "../services/themes.js";
73
75
  import { deleteTranslation, editTranslation, isLangCode, publishedDefinition, } from "../services/translations.js";
@@ -322,6 +324,10 @@ export const studio = new Hono()
322
324
  credits: managed ? await balanceCredits() : null,
323
325
  /** Where the account, members, API keys and credits are managed. */
324
326
  manageUrl: managed ? env.manage.url : null,
327
+ /** A client's place is the client portal, never the studio; null for everyone else. */
328
+ portalUrl: user.role === "client" && info?.pagesHost
329
+ ? env.clientPortalUrl.replace("{host}", info.pagesHost)
330
+ : null,
325
331
  account: linked
326
332
  ? {
327
333
  name: linked.name,
@@ -674,6 +680,11 @@ export const studio = new Hono()
674
680
  mime: file.type.split(";")[0].trim().toLowerCase(),
675
681
  data: new Uint8Array(await file.arrayBuffer()),
676
682
  });
683
+ // A document uploaded into a folder of Knowledge.
684
+ const parent = c.req.query("parent");
685
+ if (kind === "document" && parent) {
686
+ await moveKnowledgeItem(c.get("user").id, space.id, { key: `f:${row.id}`, parentId: parent });
687
+ }
677
688
  return c.json(fileView(row));
678
689
  })
679
690
  .post("/spaces/:id/files/url", async (c) => {
@@ -765,6 +776,17 @@ export const studio = new Hono()
765
776
  const space = await ownedSpace(c.get("user").id, c.req.param("id"));
766
777
  const { row, data } = await spaceFileContent(space.id, c.req.param("fileId"), whoOf(c));
767
778
  return spaceFileResponse(c, row.mime, data);
779
+ })
780
+ // A page's picture into the brand's assets: the same bytes.
781
+ .post("/spaces/:id/files/:fileId/brand", async (c) => {
782
+ const space = await ownedSpace(c.get("user").id, c.req.param("id"));
783
+ return c.json(fileView(await pictureToBrand(space.id, c.req.param("fileId"))));
784
+ })
785
+ // Its 320 px JPEG for lists and search: pictures and PDFs.
786
+ .get("/spaces/:id/files/:fileId/thumb", async (c) => {
787
+ const space = await ownedSpace(c.get("user").id, c.req.param("id"));
788
+ const thumb = await spaceFileThumb(space.id, c.req.param("fileId"), whoOf(c));
789
+ return thumb ? spaceFileResponse(c, "image/jpeg", thumb) : c.notFound();
768
790
  })
769
791
  // A document as the models read it: its text as Markdown, or the start of it.
770
792
  .get("/spaces/:id/files/:fileId/text", async (c) => {
@@ -781,13 +803,25 @@ export const studio = new Hono()
781
803
  const text = await documentText(row);
782
804
  return c.json({ text: text.slice(0, limit), chars: text.length });
783
805
  })
784
- // What a search of Knowledge finds for a question: the items an agent step would get.
806
+ // What a search of Knowledge finds for a question: the items an agent step would get. The
807
+ // palette asks twice: at once without the classifier (`check: false`), then with it.
785
808
  .post("/spaces/:id/search", async (c) => {
786
809
  const space = await ownedSpace(c.get("user").id, c.req.param("id"));
787
810
  const body = z
788
- .object({ query: z.string().min(1).max(400), where: whereSchema.optional() })
811
+ .object({
812
+ query: z.string().min(1).max(400),
813
+ where: whereSchema.optional(),
814
+ limit: z.number().int().min(1).max(12).optional(),
815
+ check: z.boolean().optional(),
816
+ })
789
817
  .parse(await c.req.json());
790
- return c.json(await searchKnowledge(space.id, body.query, { where: body.where, who: whoOf(c) }));
818
+ return c.json(await searchKnowledge(space.id, body.query, {
819
+ where: body.where,
820
+ limit: body.limit,
821
+ check: body.check,
822
+ signal: c.req.raw.signal,
823
+ who: whoOf(c),
824
+ }));
791
825
  })
792
826
  .delete("/spaces/:id", async (c) => {
793
827
  await deleteSpace(c.get("user").id, c.req.param("id"));
@@ -844,6 +878,128 @@ export const studio = new Hono()
844
878
  })
845
879
  // --- Knowledge: its items and categories ------------------------------------
846
880
  .get("/spaces/:id/knowledge", async (c) => c.json(await listKnowledge(c.get("user").id, c.req.param("id"), whoOf(c))))
881
+ // Who besides the admins sees a folder and what lies in it: the team, clients, guests.
882
+ .get("/spaces/:id/knowledge/folders/:folderId/audience", async (c) => c.json({
883
+ see: await folderAudience(c.get("user").id, c.req.param("id"), c.req.param("folderId")),
884
+ }))
885
+ .put("/spaces/:id/knowledge/folders/:folderId/audience", async (c) => {
886
+ const body = z
887
+ .object({ see: z.array(z.enum(AUDIENCES)).max(AUDIENCES.length) })
888
+ .parse(await c.req.json());
889
+ await setFolderAudience(c.get("user").id, c.req.param("id"), c.req.param("folderId"), body.see);
890
+ return c.json({ see: body.see });
891
+ })
892
+ // An item moved into a folder (a page, or the top), at a place among its contents.
893
+ .post("/spaces/:id/knowledge/move", async (c) => {
894
+ const body = z
895
+ .object({
896
+ key: z.string().regex(/^[ptf]:[\w-]{1,40}$/),
897
+ parentId: z.string().max(40).nullable(),
898
+ index: z.number().int().min(0).max(100_000).optional(),
899
+ })
900
+ .parse(await c.req.json());
901
+ await moveKnowledgeItem(c.get("user").id, c.req.param("id"), body);
902
+ return c.json({ ok: true });
903
+ })
904
+ // „Als eigene Seite übernehmen“: what a source wrote becomes the space's own.
905
+ .post("/spaces/:id/knowledge/keep", async (c) => {
906
+ await requireAdmin();
907
+ const space = await ownedSpace(c.get("user").id, c.req.param("id"));
908
+ const body = z
909
+ .object({ key: z.string().regex(/^[pt]:[\w-]{1,40}$/) })
910
+ .parse(await c.req.json());
911
+ await keepItem(space.id, body.key);
912
+ return c.json({ ok: true });
913
+ })
914
+ // --- sources of Knowledge: each fills a folder of its own ----------------------
915
+ .get("/spaces/:id/sources", async (c) => {
916
+ const space = await ownedSpace(c.get("user").id, c.req.param("id"));
917
+ return c.json(await listSources(space.id));
918
+ })
919
+ .post("/spaces/:id/sources", async (c) => {
920
+ await requireAdmin();
921
+ const space = await ownedSpace(c.get("user").id, c.req.param("id"));
922
+ const body = z
923
+ .object({
924
+ address: z.string().trim().min(1).max(1000),
925
+ kind: z.string().max(24).nullish(),
926
+ label: z.string().trim().max(120).nullish(),
927
+ })
928
+ .parse(await c.req.json());
929
+ return c.json(await proposeSource(space.id, body, { signal: c.req.raw.signal }));
930
+ })
931
+ .get("/spaces/:id/sources/:sourceId", async (c) => {
932
+ const space = await ownedSpace(c.get("user").id, c.req.param("id"));
933
+ return c.json(await getSource(space.id, c.req.param("sourceId")));
934
+ })
935
+ .post("/spaces/:id/sources/:sourceId/take", async (c) => {
936
+ await requireAdmin();
937
+ const space = await ownedSpace(c.get("user").id, c.req.param("id"));
938
+ const body = z
939
+ .object({ parentId: z.string().max(40).nullish() })
940
+ .parse(await c.req.json().catch(() => ({})));
941
+ return c.json(await takeSource(space.id, c.req.param("sourceId"), body));
942
+ })
943
+ .patch("/spaces/:id/sources/:sourceId", async (c) => {
944
+ await requireAdmin();
945
+ const space = await ownedSpace(c.get("user").id, c.req.param("id"));
946
+ const patch = z
947
+ .object({
948
+ label: z.string().trim().min(1).max(120).optional(),
949
+ everyHours: z
950
+ .number()
951
+ .int()
952
+ .min(1)
953
+ .max(24 * 30)
954
+ .nullable()
955
+ .optional(),
956
+ rules: z
957
+ .array(z.object({ pattern: z.string().trim().min(1).max(200), reason: z.string().max(120) }))
958
+ .max(100)
959
+ .optional(),
960
+ })
961
+ .parse(await c.req.json());
962
+ return c.json(await updateSourceSettings(space.id, c.req.param("sourceId"), patch));
963
+ })
964
+ .post("/spaces/:id/sources/:sourceId/run", async (c) => {
965
+ await requireAdmin();
966
+ const space = await ownedSpace(c.get("user").id, c.req.param("id"));
967
+ const { source } = await getSource(space.id, c.req.param("sourceId"));
968
+ if (source.state !== "taken") {
969
+ throw new ServiceError("invalid", "The source is not taken yet.");
970
+ }
971
+ startSource(source.id);
972
+ return c.json({ ok: true });
973
+ })
974
+ .post("/spaces/:id/sources/:sourceId/stop", async (c) => {
975
+ await requireAdmin();
976
+ const space = await ownedSpace(c.get("user").id, c.req.param("id"));
977
+ const { source } = await getSource(space.id, c.req.param("sourceId"));
978
+ stopSource(source.id);
979
+ return c.json({ ok: true });
980
+ })
981
+ .post("/spaces/:id/sources/:sourceId/entries", async (c) => {
982
+ await requireAdmin();
983
+ const space = await ownedSpace(c.get("user").id, c.req.param("id"));
984
+ const { addresses } = z
985
+ .object({ addresses: z.array(z.string().trim().url()).min(1).max(200) })
986
+ .parse(await c.req.json());
987
+ return c.json({
988
+ entries: await addSourceEntries(space.id, c.req.param("sourceId"), addresses),
989
+ });
990
+ })
991
+ .patch("/spaces/:id/sources/:sourceId/entries/:entryId", async (c) => {
992
+ await requireAdmin();
993
+ const space = await ownedSpace(c.get("user").id, c.req.param("id"));
994
+ const { included } = z.object({ included: z.boolean() }).parse(await c.req.json());
995
+ return c.json(await setEntryIncluded(space.id, c.req.param("sourceId"), c.req.param("entryId"), included));
996
+ })
997
+ .delete("/spaces/:id/sources/:sourceId", async (c) => {
998
+ await requireAdmin();
999
+ const space = await ownedSpace(c.get("user").id, c.req.param("id"));
1000
+ await removeSource(space.id, c.req.param("sourceId"));
1001
+ return c.json({ ok: true });
1002
+ })
847
1003
  // What a link in a page names (`pages/bgb/p-281`): the studio opens it.
848
1004
  .get("/spaces/:id/resolve", async (c) => {
849
1005
  const space = await ownedSpace(c.get("user").id, c.req.param("id"));
@@ -938,7 +1094,8 @@ export const studio = new Hono()
938
1094
  await requireWritable(space);
939
1095
  return c.json({ summary: await writeSummary(c.req.param("id")) });
940
1096
  })
941
- // A category a person sets on an item: `p:<page>`, `t:<table>`, `r:<row>`, `f:<file>`.
1097
+ // A category a person sets on an item: `p:<page>`, `t:<table>`, `r:<row>`, `f:<file>`,
1098
+ // `m:<a file of a mount in Dateien>`.
942
1099
  .put("/spaces/:id/items/:key/categories/:categoryId", async (c) => {
943
1100
  const space = await ownedSpace(c.get("user").id, c.req.param("id"));
944
1101
  await requireWritable(space);
@@ -952,7 +1109,9 @@ export const studio = new Hono()
952
1109
  ? { rowId: id }
953
1110
  : key[0] === "f"
954
1111
  ? { fileId: id }
955
- : null;
1112
+ : key[0] === "m"
1113
+ ? { mountFileId: id }
1114
+ : null;
956
1115
  if (!ref || key[1] !== ":") {
957
1116
  throw new ServiceError("invalid", note("unknownEntry"));
958
1117
  }
@@ -971,6 +1130,7 @@ export const studio = new Hono()
971
1130
  .object({
972
1131
  title: z.string().max(120),
973
1132
  wizardId: z.string().nullish(),
1133
+ parentId: z.string().nullish(),
974
1134
  columns: z.unknown().optional(),
975
1135
  format: z.enum(["faq"]).nullish(),
976
1136
  })
@@ -50,3 +50,19 @@ export function runTicketValid(runId, ticket) {
50
50
  }
51
51
  return sameSignature(`run:${runId}|${exp}`, sig);
52
52
  }
53
+ /**
54
+ * A ticket that only reads one run: its view, its stream, its downloads. A client of the
55
+ * organization gets one for a run the firm shared with them (docs/plans/client-portal.md): they
56
+ * see it, they do not steer it.
57
+ */
58
+ export function runViewTicket(runId, ttlSeconds = 12 * 3600) {
59
+ const exp = String(Math.floor(Date.now() / 1000) + ttlSeconds);
60
+ return `${exp}.${sign(`run-view:${runId}|${exp}`)}`;
61
+ }
62
+ export function runViewTicketValid(runId, ticket) {
63
+ const [exp, sig] = (ticket ?? "").split(".");
64
+ if (!exp || !sig || Number(exp) * 1000 < Date.now()) {
65
+ return false;
66
+ }
67
+ return sameSignature(`run-view:${runId}|${exp}`, sig);
68
+ }