@engenty/wizards-runtime 0.15.0 → 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 (243) hide show
  1. package/apps/runtime/dist/agents/studio-assistant.js +138 -9
  2. package/apps/runtime/dist/agents/website.js +10 -5
  3. package/apps/runtime/dist/app.js +18 -0
  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/index.js +5 -0
  7. package/apps/runtime/dist/broker/rwx.js +255 -7
  8. package/apps/runtime/dist/cli/main.js +7 -0
  9. package/apps/runtime/dist/cli/move-files.js +68 -0
  10. package/apps/runtime/dist/cli/move-folder-sources.js +120 -0
  11. package/apps/runtime/dist/connectors/plugin-connections.js +74 -4
  12. package/apps/runtime/dist/db/migrations/tenant/0042_client_spaces.sql +16 -0
  13. package/apps/runtime/dist/db/migrations/tenant/0043_space_member_invite.sql +19 -0
  14. package/apps/runtime/dist/db/migrations/tenant/0044_client_portal.sql +8 -0
  15. package/apps/runtime/dist/db/migrations/tenant/0045_client_portal_no_slug.sql +2 -0
  16. package/apps/runtime/dist/db/migrations/tenant/0046_space_file_hash.sql +2 -0
  17. package/apps/runtime/dist/db/migrations/tenant/0047_knowledge_folders.sql +3 -0
  18. package/apps/runtime/dist/db/migrations/tenant/0048_space_chunk_kind.sql +1 -0
  19. package/apps/runtime/dist/db/migrations/tenant/0049_knowledge_sources.sql +57 -0
  20. package/apps/runtime/dist/db/migrations/tenant/0050_dateien.sql +71 -0
  21. package/apps/runtime/dist/db/migrations/tenant/0051_dateien_drafts.sql +23 -0
  22. package/apps/runtime/dist/db/migrations/tenant/0052_dateien_plugin_kinds.sql +5 -0
  23. package/apps/runtime/dist/db/migrations/tenant/0053_dateien_file_title.sql +3 -0
  24. package/apps/runtime/dist/db/migrations/tenant/0054_dateien_ocr.sql +14 -0
  25. package/apps/runtime/dist/db/migrations/tenant/0055_dateien_doc_reread.sql +3 -0
  26. package/apps/runtime/dist/db/migrations/tenant/meta/0042_snapshot.json +5286 -0
  27. package/apps/runtime/dist/db/migrations/tenant/meta/0043_snapshot.json +5293 -0
  28. package/apps/runtime/dist/db/migrations/tenant/meta/0044_snapshot.json +5344 -0
  29. package/apps/runtime/dist/db/migrations/tenant/meta/0045_snapshot.json +5329 -0
  30. package/apps/runtime/dist/db/migrations/tenant/meta/0046_snapshot.json +5343 -0
  31. package/apps/runtime/dist/db/migrations/tenant/meta/0047_snapshot.json +5391 -0
  32. package/apps/runtime/dist/db/migrations/tenant/meta/0048_snapshot.json +5398 -0
  33. package/apps/runtime/dist/db/migrations/tenant/meta/0049_snapshot.json +5793 -0
  34. package/apps/runtime/dist/db/migrations/tenant/meta/0050_snapshot.json +6288 -0
  35. package/apps/runtime/dist/db/migrations/tenant/meta/0051_snapshot.json +6461 -0
  36. package/apps/runtime/dist/db/migrations/tenant/meta/0052_snapshot.json +6497 -0
  37. package/apps/runtime/dist/db/migrations/tenant/meta/0053_snapshot.json +6504 -0
  38. package/apps/runtime/dist/db/migrations/tenant/meta/0054_snapshot.json +6504 -0
  39. package/apps/runtime/dist/db/migrations/tenant/meta/0055_snapshot.json +6504 -0
  40. package/apps/runtime/dist/db/migrations/tenant/meta/_journal.json +98 -0
  41. package/apps/runtime/dist/db/schema.js +294 -5
  42. package/apps/runtime/dist/docs/dev/api.md +25 -0
  43. package/apps/runtime/dist/docs/dev/plugins/connections.md +30 -2
  44. package/apps/runtime/dist/docs/dev/plugins/index.md +1 -1
  45. package/apps/runtime/dist/docs/dev/plugins/reference.md +7 -4
  46. package/apps/runtime/dist/docs/dev/plugins/server.md +11 -5
  47. package/apps/runtime/dist/docs/dev/plugins/space.md +130 -4
  48. package/apps/runtime/dist/docs/dev/plugins/studio.md +13 -3
  49. package/apps/runtime/dist/docs/user-guide/command-line.md +2 -0
  50. package/apps/runtime/dist/docs/user-guide/plugins.md +1 -1
  51. package/apps/runtime/dist/docs/user-guide/space.md +6 -6
  52. package/apps/runtime/dist/docs/user-guide/steps.md +1 -1
  53. package/apps/runtime/dist/documents/ocr.js +72 -0
  54. package/apps/runtime/dist/documents/parse.js +81 -12
  55. package/apps/runtime/dist/elements/caller.js +5 -3
  56. package/apps/runtime/dist/elements/gate.js +1 -1
  57. package/apps/runtime/dist/elements/knowledge.js +181 -12
  58. package/apps/runtime/dist/elements/specs.js +1 -1
  59. package/apps/runtime/dist/elements/wizards.js +15 -2
  60. package/apps/runtime/dist/engenty/connections-google/connectors/drive.js +3 -0
  61. package/apps/runtime/dist/engenty/connections-microsoft/onedrive.js +3 -0
  62. package/apps/runtime/dist/engenty/connections-s3/s3.js +6 -0
  63. package/apps/runtime/dist/engine/runner.js +19 -2
  64. package/apps/runtime/dist/engine/steps.js +1 -1
  65. package/apps/runtime/dist/env.js +6 -0
  66. package/apps/runtime/dist/files/blobs.js +57 -1
  67. package/apps/runtime/dist/files/objects.js +1 -0
  68. package/apps/runtime/dist/files/pictures.js +41 -0
  69. package/apps/runtime/dist/files/storage.js +14 -26
  70. package/apps/runtime/dist/files/thumbs.js +77 -0
  71. package/apps/runtime/dist/files/upload-check.js +2 -2
  72. package/apps/runtime/dist/index.js +22 -0
  73. package/apps/runtime/dist/live/views.js +2 -1
  74. package/apps/runtime/dist/manage.js +4 -1
  75. package/apps/runtime/dist/mcp/tools.js +5 -0
  76. package/apps/runtime/dist/models.js +82 -13
  77. package/apps/runtime/dist/mounts/cache.js +71 -0
  78. package/apps/runtime/dist/mounts/drafts.js +367 -0
  79. package/apps/runtime/dist/mounts/folder.js +148 -0
  80. package/apps/runtime/dist/mounts/mounts.js +1315 -0
  81. package/apps/runtime/dist/mounts/source.js +179 -0
  82. package/apps/runtime/dist/mounts/units.js +97 -0
  83. package/apps/runtime/dist/move-files.js +4 -0
  84. package/apps/runtime/dist/plugins/loader.js +73 -1
  85. package/apps/runtime/dist/plugins/registry.js +2 -0
  86. package/apps/runtime/dist/prompts/goose.md +13 -1
  87. package/apps/runtime/dist/prompts/tools.md +5 -2
  88. package/apps/runtime/dist/render/convert.js +188 -1
  89. package/apps/runtime/dist/routes/api.js +6 -1
  90. package/apps/runtime/dist/routes/client-contract.js +164 -0
  91. package/apps/runtime/dist/routes/client-spaces.js +58 -0
  92. package/apps/runtime/dist/routes/dateien.js +173 -0
  93. package/apps/runtime/dist/routes/elements.js +2 -2
  94. package/apps/runtime/dist/routes/plugins.js +2 -1
  95. package/apps/runtime/dist/routes/runs.js +24 -10
  96. package/apps/runtime/dist/routes/studio.js +168 -8
  97. package/apps/runtime/dist/secrets/signing.js +16 -0
  98. package/apps/runtime/dist/services/client-portal.js +439 -0
  99. package/apps/runtime/dist/services/client-spaces.js +228 -0
  100. package/apps/runtime/dist/services/cloud.js +2 -0
  101. package/apps/runtime/dist/services/knowledge-model.js +24 -8
  102. package/apps/runtime/dist/services/knowledge.js +72 -42
  103. package/apps/runtime/dist/services/links.js +17 -0
  104. package/apps/runtime/dist/services/members-studio.js +5 -1
  105. package/apps/runtime/dist/services/page-pictures.js +162 -0
  106. package/apps/runtime/dist/services/runs.js +22 -6
  107. package/apps/runtime/dist/services/space-categories.js +41 -5
  108. package/apps/runtime/dist/services/space-data.js +165 -8
  109. package/apps/runtime/dist/services/space-files.js +102 -19
  110. package/apps/runtime/dist/services/space-index.js +384 -41
  111. package/apps/runtime/dist/services/space-origin.js +25 -1
  112. package/apps/runtime/dist/services/space-sources.js +937 -0
  113. package/apps/runtime/dist/services/spaces.js +60 -12
  114. package/apps/runtime/dist/services/synced-spaces.js +10 -1
  115. package/apps/runtime/dist/services/work-ai.js +29 -8
  116. package/apps/runtime/dist/services/work-chats.js +3 -2
  117. package/apps/runtime/dist/sharing/index.js +2 -0
  118. package/apps/runtime/dist/store/index.js +29 -8
  119. package/apps/runtime/dist/store/shared-lists.js +30 -17
  120. package/apps/runtime/dist/sync/records.js +22 -27
  121. package/apps/runtime/dist/texts.js +4 -0
  122. package/apps/runtime/dist/tools/pages.js +1 -1
  123. package/apps/runtime/dist/widgets/step.js +2 -1
  124. package/apps/web/dist/assets/AboutDialog-0q4P80yv.js +1 -0
  125. package/apps/web/dist/assets/BlockEditor-CUYFH_CU.js +173 -0
  126. package/apps/web/dist/assets/BlockEditor-CtW6lw0y.css +1 -0
  127. package/apps/web/dist/assets/CapabilitiesPage-BlZP8DYb.js +2 -0
  128. package/apps/web/dist/assets/{ChangelogDialog-Do7pwmFv.js → ChangelogDialog-CDN7kMs1.js} +1 -1
  129. package/apps/web/dist/assets/{CodeEditor-Cdox-51M.js → CodeEditor-D-Y16fdk.js} +1 -1
  130. package/apps/web/dist/assets/EditorPage-CrMVsgUt.js +3 -0
  131. package/apps/web/dist/assets/{FlowPreview-BPS86xzA.js → FlowPreview-DXnk7m9P.js} +1 -1
  132. package/apps/web/dist/assets/{LangSwitch-BRHbi_Sd.js → LangSwitch-Dkd0FBIH.js} +1 -1
  133. package/apps/web/dist/assets/Marketplace-Cty40VwG.js +2 -0
  134. package/apps/web/dist/assets/NewWizardChannels-Czool7s1.js +1 -0
  135. package/apps/web/dist/assets/NewWizardPage-CfVe_4a2.js +7 -0
  136. package/apps/web/dist/assets/OnboardingPage-D3SEpTmt.js +1 -0
  137. package/apps/web/dist/assets/PreviewPane-CQDKQO6z.js +7 -0
  138. package/apps/web/dist/assets/PublicRunner-BDZNnlQw.js +1 -0
  139. package/apps/web/dist/assets/ReadOnly-B7MUySpC.js +1 -0
  140. package/apps/web/dist/assets/SettingsPage-Bgurv3l2.js +2 -0
  141. package/apps/web/dist/assets/SetupPage-C3km8vqv.js +1 -0
  142. package/apps/web/dist/assets/{SharePage-PKHX8a8a.js → SharePage-UwEJBIzq.js} +1 -1
  143. package/apps/web/dist/assets/SkillEditor-BaEiqqXl.js +1 -0
  144. package/apps/web/dist/assets/Skills-Bv6XbKxc.js +9 -0
  145. package/apps/web/dist/assets/SpacePage-D9PXLSU_.js +2 -0
  146. package/apps/web/dist/assets/UpdateCheck-C7I43zFZ.js +2 -0
  147. package/apps/web/dist/assets/changelog-DwgWiSZb.js +1 -0
  148. package/apps/web/dist/assets/circle-check-DDLzlcXP.js +1 -0
  149. package/apps/web/dist/assets/code-DsnwzN1x.js +1 -0
  150. package/apps/web/dist/assets/code-editor-Ca5EAxmd.js +2 -0
  151. package/apps/web/dist/assets/code-xml-S4IFi5Jc.js +1 -0
  152. package/apps/web/dist/assets/connection-sign-in-hI3HXhq4.js +1 -0
  153. package/apps/web/dist/assets/{dist-H1UN89OA.js → dist-B3Ray2U5.js} +1 -1
  154. package/apps/web/dist/assets/dist-CQpLJoQZ.js +10 -0
  155. package/apps/web/dist/assets/{dist-GlRRx9Xl.js → dist-D1uGQ_tB.js} +1 -1
  156. package/apps/web/dist/assets/{dist-BdDd1FxP.js → dist-DFI-tsfx.js} +1 -1
  157. package/apps/web/dist/assets/eye-TJSuiHHO.js +1 -0
  158. package/apps/web/dist/assets/floating-ui.dom-pwdNGv4b.js +1 -0
  159. package/apps/web/dist/assets/host-D5hNHbhF.js +125 -0
  160. package/apps/web/dist/assets/i18n-BBzMbGoo.js +55 -0
  161. package/apps/web/dist/assets/index-CyBrvupM.js +10 -0
  162. package/apps/web/dist/assets/index-w-3J3ZJ9.css +1 -0
  163. package/apps/web/dist/assets/{json-CEsfHdlZ.js → json-Ce3iHrtf.js} +1 -1
  164. package/apps/web/dist/assets/link-CPL8pB1P.js +1 -0
  165. package/apps/web/dist/assets/list-checks-DaxmUPqK.js +1 -0
  166. package/apps/web/dist/assets/{markdown-5-I9_izp.js → markdown-hqKQy2pp.js} +1 -1
  167. package/apps/web/dist/assets/marked.esm-DQ7XA7AC.js +67 -0
  168. package/apps/web/dist/assets/oss-credits-BrwV0a4F.js +1 -0
  169. package/apps/web/dist/assets/pdf-Dg-raaUo.js +54 -0
  170. package/apps/web/dist/assets/pdf.worker.min-68CMzziE.js +1 -0
  171. package/apps/web/dist/assets/pdf.worker.min-CjEcRF4W.mjs +28 -0
  172. package/apps/web/dist/assets/phone-B4uKDBFq.js +1 -0
  173. package/apps/web/dist/assets/read-aloud-Bfp9_bUY.js +1 -0
  174. package/apps/web/dist/assets/{runners-BoPaPsjN.js → runners-CUpBpSji.js} +1 -1
  175. package/apps/web/dist/assets/scroll-text-BEnPzQEi.js +1 -0
  176. package/apps/web/dist/assets/session-CMQo8P-G.js +2 -0
  177. package/apps/web/dist/assets/table-5B9G3oA6.js +1 -0
  178. package/apps/web/dist/assets/theme-CdX0marK.js +11 -0
  179. package/apps/web/dist/assets/ui-BCfu5sia.js +16 -0
  180. package/apps/web/dist/assets/upload-CAlHC232.js +1 -0
  181. package/apps/web/dist/assets/{useMutation-7_FOHoEl.js → useMutation-1fV4Nnxq.js} +1 -1
  182. package/apps/web/dist/assets/viewers-ChriFcRy.js +2 -0
  183. package/apps/web/dist/assets/volume-2-BqlBtCIJ.js +1 -0
  184. package/apps/web/dist/assets/w3c-keyname-BOAvb0qz.js +1 -0
  185. package/apps/web/dist/assets/xlsx-CuSbHU4R.js +141 -0
  186. package/apps/web/dist/index.html +19 -14
  187. package/apps/web/dist/mcp/flow.html +2 -2
  188. package/node_modules/@engenty/wizards/dist/plugin/index.d.ts +223 -4
  189. package/node_modules/@engenty/wizards/dist/plugin/mount.d.ts +123 -0
  190. package/node_modules/@engenty/wizards/dist/plugin/mount.js +7 -0
  191. package/node_modules/@engenty/wizards/dist/plugin/studio.d.ts +110 -1
  192. package/node_modules/@engenty/wizards-shared/dist/connectors.d.ts +1 -1
  193. package/node_modules/@engenty/wizards-shared/dist/feature-flags.d.ts +24 -0
  194. package/node_modules/@engenty/wizards-shared/dist/feature-flags.js +24 -0
  195. package/node_modules/@engenty/wizards-shared/dist/knowledge.d.ts +33 -4
  196. package/node_modules/@engenty/wizards-shared/dist/run.d.ts +3 -0
  197. package/node_modules/@engenty/wizards-shared/dist/run.js +6 -0
  198. package/node_modules/@engenty/wizards-shared/dist/rwx.d.ts +21 -4
  199. package/node_modules/@engenty/wizards-shared/dist/rwx.js +27 -3
  200. package/node_modules/@engenty/wizards-shared/dist/spaces.d.ts +11 -1
  201. package/node_modules/@engenty/wizards-shared/dist/spaces.js +9 -2
  202. package/node_modules/@engenty/wizards-shared/dist/text-merge.d.ts +6 -0
  203. package/node_modules/@engenty/wizards-shared/dist/text-merge.js +25 -0
  204. package/package.json +3 -1
  205. package/plugin/.claude-plugin/plugin.json +1 -1
  206. package/plugin/plugin.json +1 -1
  207. package/apps/web/dist/assets/AboutDialog-DaWEIHFN.js +0 -1
  208. package/apps/web/dist/assets/CapabilitiesPage-Dt91U_sK.js +0 -2
  209. package/apps/web/dist/assets/EditorPage-DS_a5K3s.js +0 -3
  210. package/apps/web/dist/assets/Marketplace-CS7JTgiv.js +0 -2
  211. package/apps/web/dist/assets/NewWizardChannels-D-OLsex6.js +0 -1
  212. package/apps/web/dist/assets/NewWizardPage-BM_pkk41.js +0 -7
  213. package/apps/web/dist/assets/OnboardingPage-Cpn5pubC.js +0 -1
  214. package/apps/web/dist/assets/PreviewPane-BOk1-yO4.js +0 -9
  215. package/apps/web/dist/assets/PublicRunner-CgzMZb0r.js +0 -1
  216. package/apps/web/dist/assets/ReadOnly-8DEx-ly3.js +0 -1
  217. package/apps/web/dist/assets/SettingsPage-CcrknFcI.js +0 -2
  218. package/apps/web/dist/assets/SetupPage-D5nzjgPU.js +0 -1
  219. package/apps/web/dist/assets/SkillEditor-BsXTqNli.js +0 -1
  220. package/apps/web/dist/assets/Skills-C_X1ZsKg.js +0 -9
  221. package/apps/web/dist/assets/SpacePage-wZGqUoSQ.js +0 -2
  222. package/apps/web/dist/assets/UpdateCheck-D6x7MqEl.js +0 -2
  223. package/apps/web/dist/assets/changelog-M-eOBqgu.js +0 -1
  224. package/apps/web/dist/assets/circle-alert-DJbCyxcg.js +0 -1
  225. package/apps/web/dist/assets/circle-check-jqtsKi_b.js +0 -1
  226. package/apps/web/dist/assets/code-editor-BpCEnf8H.js +0 -2
  227. package/apps/web/dist/assets/code-xml-q88cSTV8.js +0 -1
  228. package/apps/web/dist/assets/connection-sign-in-UJ6xk-TD.js +0 -1
  229. package/apps/web/dist/assets/dist-EBVTpvRr.js +0 -10
  230. package/apps/web/dist/assets/eye-CgkvVlba.js +0 -1
  231. package/apps/web/dist/assets/host-Bd_bon_c.js +0 -118
  232. package/apps/web/dist/assets/i18n-0fUKyVRE.js +0 -55
  233. package/apps/web/dist/assets/index-D18DvnxX.css +0 -1
  234. package/apps/web/dist/assets/index-DOgwxnto.js +0 -10
  235. package/apps/web/dist/assets/oss-credits-IdX5bc71.js +0 -1
  236. package/apps/web/dist/assets/phone-CjPvZ0nk.js +0 -1
  237. package/apps/web/dist/assets/read-aloud-CLXo_asN.js +0 -1
  238. package/apps/web/dist/assets/scroll-text-2BhJO_W7.js +0 -1
  239. package/apps/web/dist/assets/session-CpYa5hwd.js +0 -2
  240. package/apps/web/dist/assets/theme-Bj3wNQR0.js +0 -11
  241. package/apps/web/dist/assets/ui-CktezodE.js +0 -82
  242. package/apps/web/dist/assets/upload-CHGCFVZK.js +0 -1
  243. package/apps/web/dist/assets/volume-2-Bw5KASy8.js +0 -1
@@ -1,5 +1,5 @@
1
1
  import { note } from "@engenty/wizards-shared/run";
2
- import { COLOR_SECTION_KINDS, cleanAssetSections, cleanLogoSections, FACT_TYPES, FONT_USES, FONT_WEIGHTS, GRADIENT_TYPES, NOTIFY_MAIL, orderColors, PAGE_LANGS, PAGE_LIMITS, PAGE_SLUG, RULE_MARKS, SPACE_LIMITS, } from "@engenty/wizards-shared/spaces";
2
+ import { COLOR_SECTION_KINDS, cleanAssetSections, cleanLogoSections, FACT_TYPES, FONT_USES, FONT_WEIGHTS, GRADIENT_TYPES, NOTIFY_MAIL, orderColors, PAGE_LANGS, PAGE_LIMITS, PAGE_SLUG, RESERVED_PAGE_SLUGS, RULE_MARKS, SPACE_LIMITS, } from "@engenty/wizards-shared/spaces";
3
3
  import { and, count, eq, isNull, ne } from "drizzle-orm";
4
4
  import { nanoid } from "nanoid";
5
5
  import { z } from "zod";
@@ -11,9 +11,9 @@ import { cloudSpaceLimit, twoWayActive } from "../sync/state.js";
11
11
  import { putLink } from "../tenants/control.js";
12
12
  import { currentTenant } from "../tenants/tenant.js";
13
13
  import { serverText } from "../texts.js";
14
- import { mayBuild, requireAdmin, requireBuild, requireWritable } from "./access.js";
14
+ import { currentRole, mayBuild, requireAdmin, requireBuild, requireWritable } from "./access.js";
15
15
  import { notFound, ServiceError } from "./errors.js";
16
- import { forgetWizardLinks } from "./links.js";
16
+ import { forgetWizardLinks, removeClientSpaceRuns } from "./links.js";
17
17
  import { pushPages } from "./pages.js";
18
18
  import { removeSpaceFiles } from "./space-files.js";
19
19
  const sectionId = z.string().regex(/^[A-Za-z0-9_-]{1,40}$/);
@@ -200,15 +200,28 @@ export async function spaceLimitOrNull() {
200
200
  const limit = await spaceLimit();
201
201
  return Number.isFinite(limit) ? limit : null;
202
202
  }
203
- export async function ownedSpace(_userId, spaceId) {
203
+ export async function ownedSpace(userId, spaceId) {
204
204
  const p = await db.query.space.findFirst({
205
205
  where: and(eq(schema.space.id, spaceId), eq(schema.space.tenantId, currentTenant())),
206
206
  });
207
207
  if (!p) {
208
208
  throw notFound();
209
209
  }
210
+ // A client of the organization reaches only the client spaces they are in
211
+ // (docs/plans/client-spaces.md); every other space is not there for them.
212
+ if (currentRole() === "client" && !(p.kind === "client" && (await inSpace(userId, p.id)))) {
213
+ throw notFound();
214
+ }
210
215
  return p;
211
216
  }
217
+ /** Whether the person is a member of the space, as a client or as the firm's (`space_member`). */
218
+ async function inSpace(userId, spaceId) {
219
+ const row = await db.query.spaceMember.findFirst({
220
+ columns: { id: true },
221
+ where: and(eq(schema.spaceMember.spaceId, spaceId), eq(schema.spaceMember.userId, userId)),
222
+ });
223
+ return Boolean(row);
224
+ }
212
225
  /** The tenant's spaces that were made here, not synced from a local install. */
213
226
  const madeHere = () => and(eq(schema.space.tenantId, currentTenant()), isNull(schema.space.origin));
214
227
  /** The tenant's spaces a local install synced. */
@@ -235,13 +248,20 @@ async function ensureSpace(lang = "en") {
235
248
  * The space a caller means when it names none: the oldest one made here, where a wizard
236
249
  * lands; for a tenant that builds nothing here, the one its local install synced.
237
250
  */
238
- export async function defaultSpace(_userId) {
251
+ export async function defaultSpace(userId) {
252
+ if (currentRole() === "client") {
253
+ const [first] = await clientSpacesOf(userId);
254
+ if (!first) {
255
+ throw notFound();
256
+ }
257
+ return first;
258
+ }
239
259
  const build = await mayBuild();
240
260
  if (build) {
241
261
  await ensureSpace();
242
262
  }
243
263
  const p = await db.query.space.findFirst({
244
- where: build ? madeHere() : synced(),
264
+ where: and(build ? madeHere() : synced(), eq(schema.space.kind, "space")),
245
265
  orderBy: [schema.space.createdAt],
246
266
  });
247
267
  if (!p) {
@@ -253,15 +273,20 @@ export async function defaultSpace(_userId) {
253
273
  * The spaces the studio shows. A tenant that builds here: its own and the synced ones, up to
254
274
  * its number. One that does not: only what its local install synced — possibly nothing yet.
255
275
  */
256
- export async function listSpaces(_userId, lang) {
276
+ export async function listSpaces(userId, lang) {
277
+ // A client sees the client spaces they are in, nothing else (docs/plans/client-spaces.md).
278
+ if (currentRole() === "client") {
279
+ return clientSpacesOf(userId);
280
+ }
257
281
  const build = await mayBuild();
258
282
  if (build) {
259
283
  await ensureSpace(lang);
260
284
  }
261
- // The oldest come first: with a limit of one, that is the space everything lands in.
285
+ // The oldest come first: with a limit of one, that is the space everything lands in. Client
286
+ // spaces stay out: they are a part of their space, never a space of the menu.
262
287
  const limit = await spaceLimit();
263
288
  const spaces = await db.query.space.findMany({
264
- where: build ? eq(schema.space.tenantId, currentTenant()) : synced(),
289
+ where: and(build ? eq(schema.space.tenantId, currentTenant()) : synced(), eq(schema.space.kind, "space")),
265
290
  orderBy: [schema.space.createdAt],
266
291
  ...(Number.isFinite(limit) ? { limit } : {}),
267
292
  });
@@ -275,13 +300,23 @@ export async function listSpaces(_userId, lang) {
275
300
  wizardCount: counts.find((x) => x.spaceId === p.id)?.n ?? 0,
276
301
  }));
277
302
  }
303
+ /** The client spaces a client is in, as the space list shows them. */
304
+ async function clientSpacesOf(userId) {
305
+ const rows = await db
306
+ .select({ space: schema.space })
307
+ .from(schema.spaceMember)
308
+ .innerJoin(schema.space, eq(schema.space.id, schema.spaceMember.spaceId))
309
+ .where(and(eq(schema.spaceMember.userId, userId), eq(schema.space.tenantId, currentTenant()), eq(schema.space.kind, "client")));
310
+ return rows.map((r) => ({ ...r.space, wizardCount: 0 }));
311
+ }
278
312
  export async function createSpace(_userId, name) {
279
313
  await requireBuild();
280
314
  await requireAdmin();
315
+ // Client spaces do not count as spaces of the plan.
281
316
  const [{ n }] = await db
282
317
  .select({ n: count() })
283
318
  .from(schema.space)
284
- .where(eq(schema.space.tenantId, currentTenant()));
319
+ .where(and(eq(schema.space.tenantId, currentTenant()), eq(schema.space.kind, "space")));
285
320
  const limit = await spaceLimit();
286
321
  if (n >= limit) {
287
322
  throw new ServiceError("refused", limit === 1 ? note("onlyOneSpaceAllowed") : note("mostSpaces", { count: limit }));
@@ -330,6 +365,9 @@ async function checkedPage(p, page) {
330
365
  if (!PAGE_SLUG.test(page.slug)) {
331
366
  throw new ServiceError("invalid", note("pageSlugInvalid"));
332
367
  }
368
+ if (RESERVED_PAGE_SLUGS.includes(page.slug)) {
369
+ throw new ServiceError("invalid", note("pageSlugReserved"));
370
+ }
333
371
  const others = await db.query.space.findMany({
334
372
  where: and(eq(schema.space.tenantId, currentTenant()), ne(schema.space.id, p.id)),
335
373
  columns: { id: true, name: true, page: true },
@@ -510,14 +548,23 @@ export function spaceProfile(p) {
510
548
  export async function deleteSpace(userId, spaceId) {
511
549
  await requireWritable(await ownedSpace(userId, spaceId));
512
550
  await requireAdmin();
513
- const all = await db.query.space.findMany({ where: madeHere() });
551
+ const all = await db.query.space.findMany({
552
+ where: and(madeHere(), eq(schema.space.kind, "space")),
553
+ });
514
554
  if (all.length <= 1) {
515
555
  throw new ServiceError("refused", note("notDeleteLastSpace"));
516
556
  }
517
557
  await removeSpace(spaceId);
518
558
  }
519
- /** Takes a space away with its wizards' links and its files. */
559
+ /** Takes a space away with its wizards' links and its files, and its client spaces first. */
520
560
  export async function removeSpace(spaceId) {
561
+ const clients = await db
562
+ .select({ id: schema.space.id })
563
+ .from(schema.space)
564
+ .where(and(eq(schema.space.parentId, spaceId), eq(schema.space.tenantId, currentTenant())));
565
+ for (const c of clients) {
566
+ await removeSpace(c.id);
567
+ }
521
568
  const wizards = await db
522
569
  .select({ id: schema.wizard.id })
523
570
  .from(schema.wizard)
@@ -525,6 +572,7 @@ export async function removeSpace(spaceId) {
525
572
  for (const w of wizards) {
526
573
  await forgetWizardLinks(w.id);
527
574
  }
575
+ await removeClientSpaceRuns(spaceId);
528
576
  await removeSpaceFiles(spaceId);
529
577
  await db
530
578
  .delete(schema.space)
@@ -434,6 +434,8 @@ export const syncDataSchema = z.object({
434
434
  title: z.string().min(1).max(120),
435
435
  format: z.enum(["faq"]).nullish(),
436
436
  originLabel: z.string().max(120).nullish(),
437
+ parentId: syncedId.nullish(),
438
+ position: z.number().int().min(0).optional(),
437
439
  columns: tableColumnsSchema,
438
440
  rows: z
439
441
  .array(z.object({ id: syncedId, cells: z.record(z.string(), z.unknown()) }))
@@ -576,7 +578,14 @@ export async function syncSpaceData(rawSpaceId, input) {
576
578
  for (const table of input.tables) {
577
579
  await db
578
580
  .update(schema.spaceTable)
579
- .set({ format: table.format ?? null, originLabel: table.originLabel ?? null, slug: null })
581
+ .set({
582
+ format: table.format ?? null,
583
+ originLabel: table.originLabel ?? null,
584
+ slug: null,
585
+ // Its folder, once every page is there.
586
+ parentId: table.parentId && pagesThere.has(table.parentId) ? table.parentId : null,
587
+ position: table.position ?? 0,
588
+ })
580
589
  .where(eq(schema.spaceTable.id, table.id));
581
590
  }
582
591
  if (input.categories) {
@@ -34,8 +34,10 @@ export const TURN_KEY = "workTurn";
34
34
  export const TURN_MS = 20 * 60_000;
35
35
  /** Steps one turn may take. */
36
36
  export const MAX_STEPS = 16;
37
- const instructionsFor = (space, skills, knowledge) => [
38
- `You are the AI of the space "${space}" in engenty wizards. The team of the space talks with you and with each other in this chat.`,
37
+ const instructionsFor = (space, skills, knowledge, client) => [
38
+ client
39
+ ? `You are the AI of the firm that runs the client space "${space}" in engenty wizards, and you answer one of the firm's clients there. The firm's people read this chat too. Answer from the client space and what the firm opened to its clients; where you can't know, say so and suggest asking the firm. When one of the firm's wizards fits the request, run it with wizard_run. In German, say du, as the client portal does.`
40
+ : `You are the AI of the space "${space}" in engenty wizards. The team of the space talks with you and with each other in this chat.`,
39
41
  'Each message of a person comes as <user name="…">; answer the person who asked you, in their language, and call them by their name only when it helps.',
40
42
  knowledge
41
43
  ? "Before you answer about the space (its clients, matters, files, data), look it up with space_search; say where you found it. When you can't find it, say so."
@@ -116,12 +118,30 @@ export const showView = () => createTool({
116
118
  });
117
119
  /** Whether the model can search the web itself: on Anthropic's API, or through the gateway. */
118
120
  const searches = (resolved) => resolved.vendor === "anthropic" || resolved.gateway;
121
+ /**
122
+ * A client's turn (docs/plans/client-portal.md, phase 1): the client space's Knowledge with what
123
+ * the firm opened to clients, the wizards opened to them (a run lands in the client space) and
124
+ * views. No skills, sandbox, connections, plugins or web: nothing that reaches past the client
125
+ * space or spends on the firm's sign-ins.
126
+ */
127
+ async function clientTools(space, userId, signal, chatId) {
128
+ const caller = personCaller({ space, userId, role: "client", signal, chatId });
129
+ return sortedTools({
130
+ ...(await elementTools(caller, { knowledge: true, wizards: true })),
131
+ show_view: showView(),
132
+ });
133
+ }
119
134
  /**
120
135
  * The space's tools for a turn: its knowledge, its skills, the chat's sandbox, the space's
121
136
  * connections open to the person (work-connections.ts), the plugins' tools, the web; the plugins
122
- * and the web the person turned off (`choice`) left out.
137
+ * and the web the person turned off (`choice`) left out. A client gets `clientTools` alone.
138
+ * `role`: the person's, where the session knows it; else the organization's list says.
123
139
  */
124
- async function toolsFor(resolved, space, userId, signal, choice = {}, chatId = null, approved = null) {
140
+ async function toolsFor(resolved, space, userId, signal, choice = {}, chatId = null, approved = null, known = null) {
141
+ const role = known ?? (await roleOf(userId));
142
+ if (role === "client") {
143
+ return clientTools(space, userId, signal, chatId ?? approved?.chatId ?? null);
144
+ }
125
145
  const sandbox = sandboxTools(chatId);
126
146
  const connections = await workConnectionTools({
127
147
  space,
@@ -134,7 +154,7 @@ async function toolsFor(resolved, space, userId, signal, choice = {}, chatId = n
134
154
  const caller = personCaller({
135
155
  space,
136
156
  userId,
137
- role: await roleOf(userId),
157
+ role,
138
158
  signal,
139
159
  chatId: chatId ?? approved?.chatId ?? null,
140
160
  sandbox: sandbox.skill,
@@ -234,17 +254,18 @@ export async function toolToRun(space, userId, name, signal, approved) {
234
254
  */
235
255
  export async function workTurn(turn, signal, steps, choice = {}) {
236
256
  const resolved = await chatModel(await chatTurnWay(managed), choice.extra ? "high" : "standard");
237
- const made = gated(await toolsFor(resolved, turn.space, turn.userId, signal, choice, turn.chatId), turn);
257
+ const client = turn.role === "client";
258
+ const made = gated(await toolsFor(resolved, turn.space, turn.userId, signal, choice, turn.chatId, null, turn.role ?? null), turn);
238
259
  const tools = resolved.model instanceof HarnessModel ? steps.wrap(made) : made;
239
260
  attachTools(resolved, tools);
240
- const skills = await spaceSkills(turn.space.id);
261
+ const skills = client ? null : await spaceSkills(turn.space.id);
241
262
  const block = skills
242
263
  ? skillsBlock(skills, { tools: true, sandbox: sandboxCapabilities() !== null })
243
264
  : "";
244
265
  return {
245
266
  resolved,
246
267
  tools,
247
- instructions: instructionsFor(turn.space.name, block, "space_search" in tools),
268
+ instructions: instructionsFor(turn.space.name, block, "space_search" in tools, client),
248
269
  };
249
270
  }
250
271
  export function lazyTurn(turn, choice = {}) {
@@ -380,7 +380,7 @@ options = {}) {
380
380
  return { kind: "kept" };
381
381
  }
382
382
  // Asking the AI is a signal that isn't stored: the stored message is what it answers.
383
- const { turn, streamOptions } = await turnFor(chat, user.id, options.choice);
383
+ const { turn, streamOptions } = await turnFor(chat, user.id, options.choice, user.role);
384
384
  const asked = {
385
385
  type: "reactive",
386
386
  tagName: "asked",
@@ -412,12 +412,13 @@ options = {}) {
412
412
  * A turn for the person, made when it really starts (Mastra resolves the agent's model then):
413
413
  * input taken into a running turn builds nothing, and a queued one's 20 minutes start with it.
414
414
  */
415
- async function turnFor(chat, userId, choice = {}) {
415
+ async function turnFor(chat, userId, choice = {}, role) {
416
416
  const space = await db.query.space.findFirst({ where: eq(schema.space.id, chat.spaceId) });
417
417
  const turn = lazyTurn({
418
418
  space: { id: chat.spaceId, name: space?.name ?? "" },
419
419
  chatId: chat.id,
420
420
  userId,
421
+ role,
421
422
  }, choice);
422
423
  const requestContext = new RequestContext();
423
424
  requestContext.set(TURN_KEY, turn);
@@ -233,6 +233,8 @@ function standIn(wizard, userId) {
233
233
  unattended: false,
234
234
  deviceOffer: null,
235
235
  costMicros: 0,
236
+ clientSpaceId: null,
237
+ clientSharedAt: null,
236
238
  shareToken: null,
237
239
  sharedAt: null,
238
240
  expiresAt: null,
@@ -18,13 +18,17 @@ export function holderOf(run) {
18
18
  return run.visitorId ? `v:${run.visitorId}` : `r:${run.id}`;
19
19
  }
20
20
  export function scopeOf(run) {
21
- return { wizardId: run.wizardId, holder: holderOf(run) };
21
+ return {
22
+ wizardId: run.wizardId,
23
+ holder: holderOf(run),
24
+ ...(run.clientSpaceId ? { clientSpaceId: run.clientSpaceId } : {}),
25
+ };
22
26
  }
23
27
  /** Marks the store as in use; stores nobody came back to are cleaned up. */
24
28
  export async function touchStore(scope) {
25
29
  await db
26
30
  .insert(schema.storeHolder)
27
- .values({ ...scope, usedAt: new Date() })
31
+ .values({ wizardId: scope.wizardId, holder: scope.holder, usedAt: new Date() })
28
32
  .onConflictDoUpdate({
29
33
  target: [schema.storeHolder.wizardId, schema.storeHolder.holder],
30
34
  set: { usedAt: new Date() },
@@ -41,7 +45,7 @@ function toRow(r) {
41
45
  */
42
46
  export async function listRows(scope, def, who = []) {
43
47
  if (def.shared) {
44
- return sharedRows(scope.wizardId, def, who);
48
+ return sharedRows(scope, def, who);
45
49
  }
46
50
  const rows = await db.query.storeRow.findMany({
47
51
  where: inList(scope, def.id),
@@ -56,7 +60,7 @@ export async function listRows(scope, def, who = []) {
56
60
  */
57
61
  export async function saveRows(scope, def, input) {
58
62
  if (def.shared) {
59
- return saveSharedRows(scope.wizardId, def, input);
63
+ return saveSharedRows(scope, def, input);
60
64
  }
61
65
  let added = 0;
62
66
  let updated = 0;
@@ -86,7 +90,8 @@ export async function saveRows(scope, def, input) {
86
90
  }
87
91
  const row = {
88
92
  id: nanoid(14),
89
- ...scope,
93
+ wizardId: scope.wizardId,
94
+ holder: scope.holder,
90
95
  list: def.id,
91
96
  key,
92
97
  cells,
@@ -132,7 +137,7 @@ export async function updateRow(scope, def, rowId, patch) {
132
137
  /** Deletes rows by id, or by the value of the key column. */
133
138
  export async function deleteRows(scope, def, idsOrKeys) {
134
139
  if (def.shared) {
135
- return deleteSharedRows(scope.wizardId, def, idsOrKeys);
140
+ return deleteSharedRows(scope, def, idsOrKeys);
136
141
  }
137
142
  if (!idsOrKeys.length) {
138
143
  return 0;
@@ -227,7 +232,15 @@ export async function writeStoreFile(scope, rawPath, content, meta = {}) {
227
232
  const updatedAt = new Date();
228
233
  await db
229
234
  .insert(schema.storeFile)
230
- .values({ ...scope, path, hash, mime, size: data.byteLength, source: meta.source ?? null })
235
+ .values({
236
+ wizardId: scope.wizardId,
237
+ holder: scope.holder,
238
+ path,
239
+ hash,
240
+ mime,
241
+ size: data.byteLength,
242
+ source: meta.source ?? null,
243
+ })
231
244
  .onConflictDoUpdate({
232
245
  target: [schema.storeFile.wizardId, schema.storeFile.holder, schema.storeFile.path],
233
246
  set: { hash, mime, size: data.byteLength, source: meta.source ?? null, updatedAt },
@@ -264,7 +277,15 @@ export async function putSecret(scope, slot, provider, label, data) {
264
277
  const sealed = seal(data);
265
278
  await db
266
279
  .insert(schema.storeSecret)
267
- .values({ id: nanoid(14), ...scope, slot, provider, label, data: sealed })
280
+ .values({
281
+ id: nanoid(14),
282
+ wizardId: scope.wizardId,
283
+ holder: scope.holder,
284
+ slot,
285
+ provider,
286
+ label,
287
+ data: sealed,
288
+ })
268
289
  .onConflictDoUpdate({
269
290
  target: [schema.storeSecret.wizardId, schema.storeSecret.holder, schema.storeSecret.slot],
270
291
  set: { provider, label, data: sealed, updatedAt: new Date() },
@@ -5,9 +5,22 @@ import { assertRwx } from "../broker/rwx.js";
5
5
  import { db, schema } from "../db/client.js";
6
6
  import { StoreError } from "./errors.js";
7
7
  const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
8
- /** The table a shared list is kept in: made the first time, following the list as it changes. */
9
- export async function sharedTable(wizardId, def) {
10
- const where = and(eq(schema.spaceTable.wizardId, wizardId), eq(schema.spaceTable.list, def.id));
8
+ /**
9
+ * The table a shared list is kept in: made the first time, following the list as it changes. A
10
+ * run of a client space keeps it in the client space (docs/plans/client-portal.md): the firm's
11
+ * clients never share a list.
12
+ */
13
+ export async function sharedTable(scope, def) {
14
+ const { wizardId } = scope;
15
+ const wizard = await db.query.wizard.findFirst({
16
+ where: eq(schema.wizard.id, wizardId),
17
+ columns: { spaceId: true, tenantId: true },
18
+ });
19
+ if (!wizard) {
20
+ throw new StoreError("The wizard is gone.");
21
+ }
22
+ const spaceId = scope.clientSpaceId ?? wizard.spaceId;
23
+ const where = and(eq(schema.spaceTable.spaceId, spaceId), eq(schema.spaceTable.wizardId, wizardId), eq(schema.spaceTable.list, def.id));
11
24
  const found = await db.query.spaceTable.findFirst({ where });
12
25
  const shape = { title: def.title, columns: def.columns, keyColumn: def.key ?? null };
13
26
  if (found) {
@@ -22,17 +35,17 @@ export async function sharedTable(wizardId, def) {
22
35
  }
23
36
  return found;
24
37
  }
25
- const wizard = await db.query.wizard.findFirst({
26
- where: eq(schema.wizard.id, wizardId),
27
- columns: { spaceId: true, tenantId: true },
28
- });
29
- if (!wizard) {
30
- throw new StoreError("The wizard is gone.");
31
- }
32
38
  // Two runs that start at once make it once.
33
39
  await db
34
40
  .insert(schema.spaceTable)
35
- .values({ id: nanoid(12), ...wizard, wizardId, list: def.id, ...shape })
41
+ .values({
42
+ id: nanoid(12),
43
+ spaceId,
44
+ tenantId: wizard.tenantId,
45
+ wizardId,
46
+ list: def.id,
47
+ ...shape,
48
+ })
36
49
  .onConflictDoNothing();
37
50
  const made = await db.query.spaceTable.findFirst({ where });
38
51
  if (!made) {
@@ -49,8 +62,8 @@ async function touch(tableId) {
49
62
  function toRow(r) {
50
63
  return { id: r.id, cells: r.cells, updatedAt: r.updatedAt.toISOString() };
51
64
  }
52
- export async function sharedRows(wizardId, def, who) {
53
- const table = await sharedTable(wizardId, def);
65
+ export async function sharedRows(scope, def, who) {
66
+ const table = await sharedTable(scope, def);
54
67
  await assertRwx(table.spaceId, who, { kind: "table", id: table.id }, "r");
55
68
  const rows = await db.query.spaceTableRow.findMany({
56
69
  where: eq(schema.spaceTableRow.tableId, table.id),
@@ -59,8 +72,8 @@ export async function sharedRows(wizardId, def, who) {
59
72
  return rows.map(toRow);
60
73
  }
61
74
  /** As `saveRows` does for one person's list: a row with a known key updates that row. */
62
- export async function saveSharedRows(wizardId, def, input) {
63
- const table = await sharedTable(wizardId, def);
75
+ export async function saveSharedRows(scope, def, input) {
76
+ const table = await sharedTable(scope, def);
64
77
  const existing = await db.query.spaceTableRow.findMany({
65
78
  where: eq(schema.spaceTableRow.tableId, table.id),
66
79
  });
@@ -103,11 +116,11 @@ export async function saveSharedRows(wizardId, def, input) {
103
116
  return { added, updated };
104
117
  }
105
118
  /** Deletes rows by id, or by the value of the key column. */
106
- export async function deleteSharedRows(wizardId, def, idsOrKeys) {
119
+ export async function deleteSharedRows(scope, def, idsOrKeys) {
107
120
  if (!idsOrKeys.length) {
108
121
  return 0;
109
122
  }
110
- const table = await sharedTable(wizardId, def);
123
+ const table = await sharedTable(scope, def);
111
124
  const keys = idsOrKeys.map((k) => k.trim().toLowerCase());
112
125
  const inTable = eq(schema.spaceTableRow.tableId, table.id);
113
126
  const byId = await db
@@ -1,14 +1,13 @@
1
1
  import { validateWizard } from "@engenty/wizards-shared/definition";
2
2
  import { tableColumnsSchema } from "@engenty/wizards-shared/engenty/data-tables";
3
3
  import { SKILL_MODES, SKILL_SOURCES, } from "@engenty/wizards-shared/skills";
4
+ import { SPACE_FILE_KINDS } from "@engenty/wizards-shared/spaces";
4
5
  import { themeSchema } from "@engenty/wizards-shared/theme";
5
6
  import { and, asc, eq, inArray, isNull, ne, sql } from "drizzle-orm";
6
7
  import { nanoid } from "nanoid";
7
8
  import { z } from "zod";
8
9
  import { db, schema } from "../db/client.js";
9
- import { getBlob, putBlob } from "../files/blobs.js";
10
- import { objects } from "../files/objects.js";
11
- import { extFor } from "../files/storage.js";
10
+ import { blobThumb, hasBlob, releaseBlob } from "../files/blobs.js";
12
11
  import { spaceChanged } from "../plugins/events.js";
13
12
  import { asSync } from "../services/access.js";
14
13
  import { emitDraftChanged } from "../services/draft-events.js";
@@ -452,6 +451,8 @@ const table = {
452
451
  spaceId: t.spaceId,
453
452
  title: t.title,
454
453
  slug: t.slug,
454
+ parentId: t.parentId,
455
+ position: t.position,
455
456
  format: t.format,
456
457
  columns: t.columns,
457
458
  origin: t.origin,
@@ -470,6 +471,8 @@ const table = {
470
471
  spaceId,
471
472
  title: str(r.title) ?? "",
472
473
  slug: str(r.slug),
474
+ parentId: str(r.parentId),
475
+ position: num(r.position) ?? 0,
473
476
  format: (r.format === "faq" ? "faq" : null),
474
477
  columns: tableColumnsSchema.parse(r.columns ?? []),
475
478
  origin: str(r.origin),
@@ -720,7 +723,6 @@ const category = {
720
723
  },
721
724
  title: (r, item) => str(r?.name) ?? item,
722
725
  };
723
- const assetKey = (path) => `assets/${path}`;
724
726
  const file = {
725
727
  async read(id) {
726
728
  const f = await db.query.spaceFile.findFirst({ where: eq(schema.spaceFile.id, id) });
@@ -737,9 +739,7 @@ const file = {
737
739
  if (f.status !== "ready") {
738
740
  return "skip";
739
741
  }
740
- const asset = await db.query.asset.findFirst({ where: eq(schema.asset.id, id) });
741
- const bytes = asset ? await objects.get(assetKey(asset.path)) : null;
742
- if (!bytes) {
742
+ if (!f.hash || !(await hasBlob(f.hash))) {
743
743
  return "skip";
744
744
  }
745
745
  return {
@@ -753,13 +753,14 @@ const file = {
753
753
  description: f.description,
754
754
  source: f.source,
755
755
  position: f.position,
756
+ parentId: f.parentId,
756
757
  textHash: f.textHash,
757
758
  pages: f.pages,
758
759
  chars: f.chars,
759
760
  origin: f.origin,
760
761
  originKey: f.originKey,
761
762
  originLabel: f.originLabel,
762
- content: await putBlob(bytes),
763
+ content: f.hash,
763
764
  categories: await categoriesOf("fileId", id),
764
765
  },
765
766
  };
@@ -768,31 +769,24 @@ const file = {
768
769
  await clearOrigin(schema.spaceFile, spaceId, id, r);
769
770
  const mime = str(r.mime) ?? "application/octet-stream";
770
771
  const name = str(r.name) ?? "file";
771
- const kind = (["logo", "asset", "document", "pattern"].includes(r.kind) ? r.kind : "asset");
772
- const bytes = await getBlob(String(r.content));
773
- const before = await db.query.asset.findFirst({ where: eq(schema.asset.id, id) });
774
- const path = `${id}-${nanoid(6)}.${extFor(mime)}`;
775
- await objects.put(assetKey(path), bytes);
776
- const assetValues = {
777
- kind: kind === "logo" ? "logo" : "space",
778
- mime,
779
- name,
780
- path,
781
- size: bytes.byteLength,
782
- };
783
- await db
784
- .insert(schema.asset)
785
- .values({ id, tenantId: currentTenant(), ...assetValues })
786
- .onConflictDoUpdate({ target: schema.asset.id, set: assetValues });
772
+ const kind = (SPACE_FILE_KINDS.includes(r.kind) ? r.kind : "asset");
773
+ // The bytes came ahead of the record, by their hash (client.ts, hub.ts).
774
+ const hash = String(r.content);
775
+ if (!(await hasBlob(hash))) {
776
+ throw new Error("blob missing");
777
+ }
778
+ const before = await db.query.spaceFile.findFirst({ where: eq(schema.spaceFile.id, id) });
787
779
  const values = {
788
780
  spaceId,
789
781
  kind,
790
782
  name,
791
783
  mime,
792
- size: bytes.byteLength,
784
+ size: num(r.size) ?? 0,
785
+ hash,
793
786
  description: str(r.description) ?? "",
794
787
  source: str(r.source),
795
788
  position: num(r.position) ?? 0,
789
+ parentId: str(r.parentId),
796
790
  status: "ready",
797
791
  error: null,
798
792
  textHash: str(r.textHash),
@@ -811,8 +805,9 @@ const file = {
811
805
  });
812
806
  await writeCategories(spaceId, "fileId", id, r.categories);
813
807
  return async () => {
814
- if (before && before.path !== path) {
815
- await objects.remove(assetKey(before.path));
808
+ if (before?.hash !== hash) {
809
+ await releaseBlob(before?.hash);
810
+ void blobThumb(hash, mime).catch(() => null);
816
811
  }
817
812
  if (kind === "logo") {
818
813
  await putLink(id, "logo", id);
@@ -61,6 +61,7 @@ const EN = {
61
61
  doingLookAtFile: "Looking at a file…",
62
62
  doingReadSkill: "Reading the skill {name}…",
63
63
  doingDescribeFile: "Describing a file…",
64
+ doingWriteKnowledgePage: "Writing a page into Knowledge…",
64
65
  doingWebSearch: "Searching the web…",
65
66
  doingReadSite: "Reading {host}…",
66
67
  doingReadWebsite: "Reading the website…",
@@ -97,6 +98,7 @@ const EN = {
97
98
  invalidInput: "Invalid input",
98
99
  internalError: "Internal error",
99
100
  notSignedIn: "You’re not signed in.",
101
+ clientsNotHere: "This is for the team. Your client space is open to you in the client view.",
100
102
  accountSuspended: "This account is suspended.",
101
103
  tooLarge: "That is too large.",
102
104
  tooManyStreams: "Too many studio windows are open. Close one, or reload in a moment.",
@@ -289,6 +291,7 @@ const DE = {
289
291
  doingLookAtFile: "Sieht sich eine Datei an …",
290
292
  doingReadSkill: "Liest den Skill {name} …",
291
293
  doingDescribeFile: "Beschreibt eine Datei …",
294
+ doingWriteKnowledgePage: "Schreibt eine Seite ins Wissen …",
292
295
  doingWebSearch: "Sucht im Web …",
293
296
  doingReadSite: "Liest {host} …",
294
297
  doingReadWebsite: "Liest die Website …",
@@ -326,6 +329,7 @@ const DE = {
326
329
  internalError: "Interner Fehler",
327
330
  schemaMismatch: "Der Wizard passt nicht zum Schema.",
328
331
  notSignedIn: "Du bist nicht angemeldet.",
332
+ clientsNotHere: "Das ist für das Team. Dein Space ist für dich in der Ansicht für Kund:innen offen.",
329
333
  accountSuspended: "Dieses Konto ist gesperrt.",
330
334
  tooLarge: "Das ist zu groß.",
331
335
  tooManyStreams: "Zu viele Fenster des Studios sind offen. Schließ eines, oder lade gleich neu.",
@@ -12,7 +12,7 @@ import { pageReadInput, readKnowledgePage } from "./space.js";
12
12
  * writes into a copy of its own in the run's state, which goes with the run.
13
13
  */
14
14
  export function pageTools(ctx) {
15
- const spaceId = ctx.space.id;
15
+ const spaceId = ctx.dataSpace.id;
16
16
  const wizardId = ctx.store.wizardId;
17
17
  /**
18
18
  * The wizard's pages as this run sees them: those its holder may read, a test run's own
@@ -8,11 +8,12 @@ import { snapshotDataImages } from "../files/web-images.js";
8
8
  import { markMedia } from "../media/marking.js";
9
9
  import { mainLogoId } from "../services/brand.js";
10
10
  import { snapshotFile } from "../services/files.js";
11
+ import { spaceFileContent } from "../services/space-files.js";
11
12
  import { bundleWidget } from "./bundle.js";
12
13
  import { MOTION_MEDIA_ORIGIN, probeWidget, renderMotion } from "./render.js";
13
14
  export async function widgetBrand(space) {
14
15
  const logoId = await mainLogoId(space.id);
15
- const logo = logoId ? await loadAsset(logoId) : null;
16
+ const logo = logoId ? await spaceFileContent(space.id, logoId).catch(() => null) : null;
16
17
  const colors = space.brand.colors ?? [];
17
18
  return {
18
19
  name: space.brand.name ?? "",