@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,6 +1,8 @@
1
1
  import { anthropic } from "@ai-sdk/anthropic";
2
2
  import { CONFIRM_ACTION_TOOL } from "@engenty/wizards-shared/assistant";
3
3
  import { textClassOf } from "@engenty/wizards-shared/definition";
4
+ import { RWX_ALL } from "@engenty/wizards-shared/rwx";
5
+ import { SPACE_DATA_LIMITS } from "@engenty/wizards-shared/space-data";
4
6
  import { cleanAssetSections, cleanLogoSections, FACT_TYPES, FONT_USES, factKey, gradientCss, parseGradient, RULE_MARKS, SPACE_FILE_KINDS, SPACE_LIMITS, textStyleLine, } from "@engenty/wizards-shared/spaces";
5
7
  import { pickedClass } from "@engenty/wizards-shared/tiers";
6
8
  import { createTool } from "@mastra/core/tools";
@@ -10,17 +12,20 @@ import { knowsTools } from "../assistant/knows.js";
10
12
  import { subjectsOfGoose } from "../broker/rwx.js";
11
13
  import { gooseCaller } from "../elements/caller.js";
12
14
  import { elementTools } from "../elements/catalogue.js";
13
- import { brokered } from "../elements/gate.js";
15
+ import { brokered, elementCall } from "../elements/gate.js";
14
16
  import { currentFeatures } from "../features.js";
15
17
  import { managed } from "../manage.js";
16
18
  import { chatModel, contextWindowOf, costOf, currentTier, gatewayTools, searchAllowed, textModel, totalUsage, usageOf, } from "../models.js";
19
+ import { mountsOf } from "../mounts/source.js";
17
20
  import { prompt } from "../prompts.js";
18
21
  import { contentPolicy } from "../safety.js";
19
- import { knowledgeCounts } from "../services/knowledge.js";
22
+ import { knowledgeCounts, pageTree, resolvePath } from "../services/knowledge.js";
20
23
  import { activeSkills, skillList } from "../services/skills.js";
21
24
  import { categoryRows } from "../services/space-categories.js";
25
+ import { createPage, updatePage } from "../services/space-data.js";
22
26
  import { addSpaceFileFromUrl, spaceFileContent, spaceFiles, updateSpaceFile, } from "../services/space-files.js";
23
27
  import { documentText } from "../services/space-index.js";
28
+ import { CORE, kindsOf, listSources, proposeSource, takeSource, } from "../services/space-sources.js";
24
29
  import { ownedSpace, updateSpace } from "../services/spaces.js";
25
30
  import { currentTenant } from "../tenants/tenant.js";
26
31
  import { serverText } from "../texts.js";
@@ -64,6 +69,7 @@ const LABELS = {
64
69
  set_profile: "doingSetProfile",
65
70
  set_facts: "doingSetFacts",
66
71
  set_colors: "doingSetColors",
72
+ write_knowledge_page: "doingWriteKnowledgePage",
67
73
  look_at_file: "doingLookAtFile",
68
74
  describe_file: "doingDescribeFile",
69
75
  web_search: "doingWebSearch",
@@ -200,6 +206,21 @@ export function gooseSpaceTools(input, space, wrote, on) {
200
206
  turn = next.catch(() => undefined);
201
207
  return next;
202
208
  };
209
+ const caller = gooseCaller({
210
+ space: { id: spaceId, name: space.name },
211
+ userId,
212
+ role: input.user.role,
213
+ signal: signal ?? new AbortController().signal,
214
+ chatId: input.chat?.id,
215
+ });
216
+ /** A page of the space's own Knowledge by its path; an error the model can read where there is none. */
217
+ const pageAt = async (path) => {
218
+ const found = await resolvePath(spaceId, path);
219
+ if (found?.kind !== "page") {
220
+ throw new Error(`There is no page "${path}" in Knowledge. space_list gives the paths.`);
221
+ }
222
+ return found;
223
+ };
203
224
  const tools = {
204
225
  read_website: createTool({
205
226
  id: "read_website",
@@ -563,6 +584,54 @@ export function gooseSpaceTools(input, space, wrote, on) {
563
584
  return { ok: true };
564
585
  }),
565
586
  }),
587
+ // Knowledge's own pages, as a person writes them in the studio: `w` on the page, or on every
588
+ // page for a new one.
589
+ write_knowledge_page: createTool({
590
+ id: "write_knowledge_page",
591
+ description: prompt("goose", "tool.write_knowledge_page"),
592
+ inputSchema: z.object({
593
+ title: z.string().min(1).max(200),
594
+ markdown: z.string().max(SPACE_DATA_LIMITS.pageChars),
595
+ path: z
596
+ .string()
597
+ .max(600)
598
+ .optional()
599
+ .describe("An existing page to replace (pages/…); left out, a new page"),
600
+ parent: z
601
+ .string()
602
+ .max(600)
603
+ .optional()
604
+ .describe("The page it stands under (pages/…); left out, a page of its own"),
605
+ }),
606
+ execute: (args) => attempt(async () => {
607
+ doing("write_knowledge_page");
608
+ const at = args.path ? await pageAt(args.path) : null;
609
+ const parent = args.parent ? await pageAt(args.parent) : null;
610
+ const id = await elementCall(caller, {
611
+ action: "write_knowledge_page",
612
+ resource: { kind: "page", id: at?.id ?? RWX_ALL },
613
+ perm: "w",
614
+ input: args,
615
+ }, async () => {
616
+ if (at) {
617
+ await updatePage(userId, at.id, {
618
+ title: args.title,
619
+ markdown: args.markdown,
620
+ ...(parent ? { parentId: parent.id } : {}),
621
+ });
622
+ return at.id;
623
+ }
624
+ const made = await createPage(userId, spaceId, {
625
+ title: args.title,
626
+ markdown: args.markdown,
627
+ parentId: parent?.id ?? null,
628
+ });
629
+ return made.id;
630
+ });
631
+ wrote();
632
+ return { ok: true, path: (await pageTree(spaceId)).get(id)?.path ?? "" };
633
+ }),
634
+ }),
566
635
  look_at_file: createTool({
567
636
  id: "look_at_file",
568
637
  description: prompt("goose", "tool.look_at_file"),
@@ -605,13 +674,6 @@ export function gooseSpaceTools(input, space, wrote, on) {
605
674
  }
606
675
  // Every write to the space's setup is the broker's: `w` on it, for Goose for its person
607
676
  // (docs/plans/modular.md, B4). An admin's deny for Goose stops it; each write is a log line.
608
- const caller = gooseCaller({
609
- space: { id: spaceId, name: space.name },
610
- userId,
611
- role: input.user.role,
612
- signal: signal ?? new AbortController().signal,
613
- chatId: input.chat?.id,
614
- });
615
677
  for (const name of SETUP_WRITES) {
616
678
  if (tools[name]) {
617
679
  tools[name] = brokered(tools[name], caller, (args) => ({
@@ -808,6 +870,73 @@ export async function runStudioAssistant(input) {
808
870
  },
809
871
  }));
810
872
  }
873
+ // Sources of Knowledge, when a plugin brings a kind of them: proposed on a card, taken on it.
874
+ const sourceKinds = writable ? await kindsOf() : [];
875
+ if (writable && sourceKinds.length) {
876
+ // „Aus Dateien übernehmen“: the folders Goose may name are the space's mounts.
877
+ const mounted = sourceKinds.some((k) => k.plugin === CORE && k.source.kind === "dateien")
878
+ ? await mountsOf(writable.id)
879
+ : [];
880
+ const card = (data) => {
881
+ const record = { plugin: "", tool: "sourceProposal", data };
882
+ cards.push(record);
883
+ input.onCard?.(record);
884
+ };
885
+ const sourceSignal = input.signal ?? new AbortController().signal;
886
+ Object.assign(tools, {
887
+ propose_source: createTool({
888
+ id: "propose_source",
889
+ description: [
890
+ prompt("goose", "tool.propose_source"),
891
+ ...(mounted.length
892
+ ? [
893
+ `Mounted in Dateien: ${mounted.map((m) => `dateien/${m.slug} (${m.name})`).join(", ")}.`,
894
+ ]
895
+ : []),
896
+ ].join("\n"),
897
+ inputSchema: z.object({
898
+ address: z
899
+ .string()
900
+ .describe("The website's address, the sitemap's, or a folder's path in Dateien"),
901
+ label: z.string().optional().describe("What the person calls the source, if they said"),
902
+ }),
903
+ execute: (args) => attempt(async () => {
904
+ const proposal = await proposeSource(writable.id, args, {
905
+ signal: sourceSignal,
906
+ emit: (message) => input.onActivity?.(message),
907
+ });
908
+ card(proposal);
909
+ return proposal;
910
+ }),
911
+ }),
912
+ take_source: createTool({
913
+ id: "take_source",
914
+ description: prompt("goose", "tool.take_source"),
915
+ inputSchema: z.object({ id: z.string().describe("The proposal's id") }),
916
+ execute: ({ id }) => attempt(async () => {
917
+ const taken = await takeSource(writable.id, id);
918
+ wrote();
919
+ return { ...taken, running: true };
920
+ }),
921
+ }),
922
+ list_sources: createTool({
923
+ id: "list_sources",
924
+ description: prompt("goose", "tool.list_sources"),
925
+ inputSchema: z.object({}),
926
+ execute: () => attempt(async () => (await listSources(writable.id)).sources.map((s) => ({
927
+ id: s.id,
928
+ label: s.label,
929
+ kind: s.kind,
930
+ address: s.address,
931
+ state: s.state,
932
+ entries: s.counts.included,
933
+ written: s.counts.done,
934
+ toCheck: s.counts.check,
935
+ status: s.status,
936
+ }))),
937
+ }),
938
+ });
939
+ }
811
940
  // The person's own sign-ins to the spaces' connections (goose-connections.ts): reads run, a
812
941
  // write asks them on a card. Never a connection that signs in as the space.
813
942
  Object.assign(tools, await gooseConnectionTools(input));
@@ -1,6 +1,6 @@
1
1
  import { FONT_WEIGHTS } from "@engenty/wizards-shared/spaces";
2
2
  import { webContext } from "../render/chromium.js";
3
- import { htmlToMarkdown } from "../render/convert.js";
3
+ import { absolutePictures, htmlToContent, htmlToMarkdown, picturesOf } from "../render/convert.js";
4
4
  import { safeFetch } from "../tools/net-guard.js";
5
5
  const UA = { "user-agent": "Mozilla/5.0 (compatible; engenty-wizards/0.1)" };
6
6
  const attr = (tag, name) => tag
@@ -327,9 +327,9 @@ export function jsonLdOf(html) {
327
327
  return out.slice(0, 50);
328
328
  }
329
329
  /**
330
- * A page for a plugin (`server.web.read`): its whole text as Markdown, every link and its
331
- * structured data, as against `readWebsite`, which picks what the assistant needs of a
332
- * company's site.
330
+ * A page for a plugin (`server.web.read`): its whole text and its content as Markdown, every
331
+ * link and its structured data, as against `readWebsite`, which picks what the assistant needs
332
+ * of a company's site.
333
333
  */
334
334
  export async function readPage(raw, signal) {
335
335
  const { res, base, html } = await loadPage(raw, signal);
@@ -340,6 +340,9 @@ export async function readPage(raw, signal) {
340
340
  links.push({ url, text: linkText(m[2]) });
341
341
  }
342
342
  }
343
+ // Text and content show the same pictures at the same addresses as `images` names them.
344
+ const pictured = absolutePictures(html, base);
345
+ const content = htmlToContent(pictured).slice(0, 400_000);
343
346
  return {
344
347
  url: base,
345
348
  status: res.status,
@@ -347,7 +350,9 @@ export async function readPage(raw, signal) {
347
350
  lastModified: res.headers.get("last-modified"),
348
351
  title: titleOf(html),
349
352
  description: metaOf(html, "description") || metaOf(html, "og:description"),
350
- text: htmlToMarkdown(html).slice(0, 400_000),
353
+ text: htmlToMarkdown(pictured).slice(0, 400_000),
354
+ content,
355
+ images: picturesOf(content),
351
356
  links,
352
357
  jsonld: jsonLdOf(html),
353
358
  };
@@ -26,7 +26,10 @@ import { openCommand } from "./open-command.js";
26
26
  import { PLUGIN_NAME, pluginArchive, pluginMarketplace } from "./plugin.js";
27
27
  import { apiRoutes } from "./routes/api.js";
28
28
  import { brokerRoutes } from "./routes/broker.js";
29
+ import { clientContractRoutes } from "./routes/client-contract.js";
30
+ import { clientSpaceRoutes } from "./routes/client-spaces.js";
29
31
  import { connectionRoutes } from "./routes/connections.js";
32
+ import { dateienRoutes } from "./routes/dateien.js";
30
33
  import { browserReport, localDebugRoutes } from "./routes/debug.js";
31
34
  import { discoverRoutes } from "./routes/discover.js";
32
35
  import { elementRoutes } from "./routes/elements.js";
@@ -242,6 +245,8 @@ if (serves.doors) {
242
245
  ]);
243
246
  });
244
247
  }
248
+ /** What a client of the organization may ask the studio's routes for: who they are, their client spaces. */
249
+ const CLIENT_OPEN = /\/api\/studio\/(me|spaces)$/;
245
250
  /** The studio's requests that open an item: a wizard, a page, a table, a skill, a space. */
246
251
  const STUDIO_LOADS = /\/api\/studio\/(wizards\/[^/]+|pages\/[^/]+|tables\/[^/]+|skills\/[^/]+|spaces(\/[^/]+(\/(data|knowledge|files|wizards|page|skills))?)?)$/;
247
252
  if (serves.studio) {
@@ -294,12 +299,23 @@ if (serves.studio) {
294
299
  });
295
300
  // A member reaches a space's studio only where its admins opened it (behind `capabilities`).
296
301
  app.use("/api/studio/*", membersStudioGate);
302
+ // A client of the organization reaches no Studio and no Work (docs/plans/client-spaces.md):
303
+ // who they are and their own client spaces, until the client portal brings its own routes.
304
+ app.use("/api/studio/*", async (c, next) => {
305
+ const user = c.get("user");
306
+ if (user?.role !== "client" || (c.req.method === "GET" && CLIENT_OPEN.test(c.req.path))) {
307
+ return next();
308
+ }
309
+ return c.json({ error: say(c, "clientsNotHere"), code: "forbidden" }, 403);
310
+ });
297
311
  }
298
312
  if (serves.api) {
299
313
  // Outside clients: MCP and the API (docs/plans/modular.md), the space's elements among them.
300
314
  const mcp = mcpHandler();
301
315
  app.on(["GET", "POST", "DELETE"], "/api/mcp", (c) => mcp(c.req.raw));
302
316
  app.route("/api/v1", elementRoutes);
317
+ // The client contract: a client's own client spaces, for the client portal.
318
+ app.route("/api/v1", clientContractRoutes);
303
319
  app.route("/api/v1", apiRoutes);
304
320
  }
305
321
  if (serves.runner) {
@@ -330,8 +346,10 @@ if (serves.studio) {
330
346
  app.route("/api/studio", skillRoutes);
331
347
  app.route("/api/studio", discoverRoutes);
332
348
  app.route("/api/studio", ruleRoutes);
349
+ app.route("/api/studio", clientSpaceRoutes);
333
350
  app.route("/api/studio", connectionRoutes);
334
351
  app.route("/api/studio", brokerRoutes);
352
+ app.route("/api/studio", dateienRoutes);
335
353
  app.route("/api/studio/runtime", runtimeSettingsRoutes);
336
354
  app.route("/api/studio/work", workRoutes);
337
355
  app.route("/api/studio", studio);
@@ -10,6 +10,7 @@ import { discovery, managed, tokenRequest, verifyToken, } from "../manage.js";
10
10
  import { refreshPro } from "../plugins/pro.js";
11
11
  import { requestLang, say } from "../routes/lang.js";
12
12
  import { seal, unseal } from "../secrets/crypto.js";
13
+ import { claimClientInvites } from "../services/client-spaces.js";
13
14
  import { LOCAL_TENANT } from "../tenants/tenant.js";
14
15
  import { finishLink } from "./account.js";
15
16
  import { localTicketExpiry } from "./local-ticket.js";
@@ -400,6 +401,10 @@ export const authRoutes = new Hono()
400
401
  impersonatedBy: admin?.id ?? null,
401
402
  impersonatorEmail: admin?.email ?? null,
402
403
  });
404
+ // A client's first sign-in: the client spaces that invited their address take them in.
405
+ if (claims.role === "client" && !admin) {
406
+ await withTenant(claims.tenantId, () => claimClientInvites(claims.userId, claims.email)).catch((err) => console.error("[clients] claiming invitations:", err));
407
+ }
403
408
  if (state.desktop) {
404
409
  // The session belongs to the app's window, not to this browser.
405
410
  const code = seal({
@@ -154,6 +154,11 @@ export async function spaceAccount(row, connector, who) {
154
154
  return { connector, ctx, label };
155
155
  }
156
156
  /** „Letzte Nutzung“: the connection was just used. */
157
+ /** The rights the provider granted a connection of the space at its sign-in; none for keys. */
158
+ export function grantedScopes(row) {
159
+ const data = row.secret ? unseal(row.secret) : null;
160
+ return data?.scopes ?? [];
161
+ }
157
162
  export async function markUsed(row) {
158
163
  await db
159
164
  .update(schema.spaceConnection)
@@ -1,3 +1,8 @@
1
+ /*
2
+ * The broker: the one path every connector call takes (docs/plans/broker.md). Tools, share
3
+ * targets, plugins and the run's browser import from here; `account.ts` stays the broker's own.
4
+ */
5
+ export { grantedScopes } from "./account.js";
1
6
  export { brokerCall, brokerConnected, brokerSecret, decide, grantBinds, inAudience, kindOf, signInRefused, whereOf, whereOfRun, whoOf, } from "./call.js";
2
7
  export { currentCaller, withCaller } from "./caller.js";
3
8
  export { grantNote, grantOf, hostInGrant, inGrant, runGrant, } from "./grant.js";