@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
@@ -0,0 +1,77 @@
1
+ import { spawn } from "node:child_process";
2
+ import { inTurn } from "./upload-check.js";
3
+ /**
4
+ * A 320 px JPEG of a picture, or of a PDF's first page, for lists and search. Drawn in a process
5
+ * of its own, as an upload is checked (upload-check.ts): a broken file can crash the libraries.
6
+ */
7
+ /** The longest side of a thumbnail. */
8
+ export const THUMB_SIDE = 320;
9
+ const PICTURES = new Set([
10
+ "image/png",
11
+ "image/jpeg",
12
+ "image/webp",
13
+ "image/gif",
14
+ "image/avif",
15
+ "image/svg+xml",
16
+ ]);
17
+ /** Whether a file of this type gets a thumbnail. */
18
+ export function hasThumb(mime) {
19
+ return PICTURES.has(mime) || mime === "application/pdf";
20
+ }
21
+ /**
22
+ * Reads the file on stdin, writes the JPEG on stdout, ends with 3 when it doesn't decode. A PDF's
23
+ * first page is drawn at twice the size first, so its text stays sharp when it is scaled down. A
24
+ * picture with transparency stands on white.
25
+ */
26
+ const THUMB = `
27
+ const [canvasUrl, pdfUrl, mime, side] = process.argv.slice(1);
28
+ const { createCanvas, loadImage } = await import(canvasUrl);
29
+ const chunks = [];
30
+ for await (const chunk of process.stdin) chunks.push(chunk);
31
+ let data = Buffer.concat(chunks);
32
+ let image;
33
+ try {
34
+ if (mime === "application/pdf") {
35
+ const { PDFParse } = await import(pdfUrl);
36
+ const parser = new PDFParse({ data: new Uint8Array(data) });
37
+ const shot = await parser.getScreenshot({ partial: [1], desiredWidth: Number(side) * 2, imageBuffer: true, imageDataUrl: false });
38
+ await parser.destroy();
39
+ data = Buffer.from(shot.pages[0].data);
40
+ }
41
+ image = await loadImage(data);
42
+ } catch { process.exit(3); }
43
+ if (!image.width || !image.height) process.exit(3);
44
+ const scale = Math.min(1, Number(side) / Math.max(image.width, image.height));
45
+ const w = Math.max(1, Math.round(image.width * scale));
46
+ const h = Math.max(1, Math.round(image.height * scale));
47
+ const canvas = createCanvas(w, h);
48
+ const ctx = canvas.getContext("2d");
49
+ ctx.fillStyle = "#fff";
50
+ ctx.fillRect(0, 0, w, h);
51
+ ctx.drawImage(image, 0, 0, w, h);
52
+ process.stdout.write(await canvas.encode("jpeg", 80), () => process.exit(0));
53
+ `;
54
+ const THUMB_TIMEOUT_MS = 60_000;
55
+ /** The thumbnail of a file, or null when it has none or doesn't decode. */
56
+ export function makeThumb(data, mime) {
57
+ if (!hasThumb(mime)) {
58
+ return Promise.resolve(null);
59
+ }
60
+ return inTurn(() => new Promise((resolve) => {
61
+ const child = spawn(process.execPath, [
62
+ "--input-type=module",
63
+ "-e",
64
+ THUMB,
65
+ import.meta.resolve("@napi-rs/canvas"),
66
+ import.meta.resolve("pdf-parse"),
67
+ mime,
68
+ String(THUMB_SIDE),
69
+ ], { env: {}, stdio: ["pipe", "pipe", "ignore"], timeout: THUMB_TIMEOUT_MS });
70
+ const out = [];
71
+ child.stdout.on("data", (chunk) => out.push(chunk));
72
+ child.on("error", () => resolve(null));
73
+ child.on("close", (code) => resolve(code === 0 && out.length ? Buffer.concat(out) : null));
74
+ child.stdin.on("error", () => undefined);
75
+ child.stdin.end(Buffer.from(data));
76
+ }));
77
+ }
@@ -344,10 +344,10 @@ const out =
344
344
  process.stdout.write(out, () => process.exit(0));
345
345
  `;
346
346
  const REDRAW_TIMEOUT_MS = 30_000;
347
- /** Two pictures are drawn at a time; each process holds a decoded picture in memory. */
347
+ /** Two pictures are drawn at a time (an upload, a thumbnail); each process holds one in memory. */
348
348
  let drawing = 0;
349
349
  const waiting = [];
350
- async function inTurn(work) {
350
+ export async function inTurn(work) {
351
351
  if (drawing >= 2) {
352
352
  await new Promise((resolve) => waiting.push(resolve));
353
353
  }
@@ -41,6 +41,12 @@ if (managed) {
41
41
  void migrateAllTenants()
42
42
  .then(({ migrated, failed }) => {
43
43
  console.log(`tenant databases: ${migrated} current${failed.length ? `, failed: ${failed}` : ""}`);
44
+ // The files of before 0.16 move to the blob store, once (cli/move-files.ts).
45
+ if (env.serves.studio) {
46
+ void import("./cli/move-files.js")
47
+ .then((m) => m.moveFilesAtStart())
48
+ .catch((err) => console.error("[move-files]", err));
49
+ }
44
50
  // The admin app's list of every team's wizards starts from what is here now.
45
51
  return reportAllWizards();
46
52
  })
@@ -103,6 +109,12 @@ async function purge() {
103
109
  }
104
110
  }
105
111
  void purge().catch((err) => console.error("[retention]", err));
112
+ // The files of before 0.16 move to the blob store, once (cli/move-files.ts). In the cloud this
113
+ // waits for the tenants' migrations, above.
114
+ if (!managed && env.serves.studio) {
115
+ const { moveFilesAtStart } = await import("./cli/move-files.js");
116
+ void moveFilesAtStart().catch((err) => console.error("[move-files]", err));
117
+ }
106
118
  // Assets came into the index later than documents: what is not there yet goes in once.
107
119
  if (env.serves.studio) {
108
120
  const { indexMissingAssets } = await import("./services/space-index.js");
@@ -110,6 +122,16 @@ if (env.serves.studio) {
110
122
  void withTenant(id, () => indexMissingAssets()).catch((err) => console.error(`[space-index ${id}]`, err));
111
123
  }
112
124
  }
125
+ // Dateien: the folders of this computer mounted in a space, watched and listed again.
126
+ if (env.serves.studio) {
127
+ const { startMounts } = await import("./mounts/mounts.js");
128
+ void startMounts().catch((err) => console.error("[dateien]", err));
129
+ }
130
+ // „Aus Dateien übernehmen“: the core's source of Knowledge on a mount, run when the mount changes.
131
+ if (env.serves.studio) {
132
+ const { startFileSources } = await import("./mounts/source.js");
133
+ startFileSources();
134
+ }
113
135
  // The broker is heard (docs/plans/broker.md, "Notifications"): a guest's critical lines go to
114
136
  // the Manage-App at once, the rest daily; the admins of each space get a mail once an hour where
115
137
  // none of them was in the app. The studio alone, so several runners don't send the same mail.
@@ -85,7 +85,8 @@ export async function translationsView(r, wizardId) {
85
85
  export async function filesView(r, spaceId) {
86
86
  const space = await ownedSpace(r.userId, spaceId);
87
87
  return {
88
- files: (await spaceFiles(space.id)).map(fileView),
88
+ // A page's pictures show in their page, not among the space's files.
89
+ files: (await spaceFiles(space.id)).filter((f) => f.kind !== "picture").map(fileView),
89
90
  /** Whether documents get vectors, or the index works on keywords alone. */
90
91
  embeddings: Boolean(await embeddingModel().catch(() => null)),
91
92
  };
@@ -37,7 +37,10 @@ function toClaims(payload) {
37
37
  if (typeof p.sub !== "string" || typeof p.tenant !== "string") {
38
38
  return null;
39
39
  }
40
- const role = p.role === "owner" || p.role === "admin" ? p.role : "member";
40
+ // A role this runtime does not know gets the least: a client's (docs/plans/client-spaces.md).
41
+ const role = p.role === "owner" || p.role === "admin" || p.role === "member" || p.role === "client"
42
+ ? p.role
43
+ : "client";
41
44
  return {
42
45
  userId: p.sub,
43
46
  tenantId: p.tenant,
@@ -83,6 +83,11 @@ function presentNote(people) {
83
83
  return prompt("mcp", "note.present", { who, verb: people.length > 1 ? "are" : "is" });
84
84
  }
85
85
  export function registerTools(server, who) {
86
+ // A client of the organization authors nothing: only the elements of their client spaces
87
+ // (mcp/elements.ts, docs/plans/client-spaces.md).
88
+ if (who.role === "client") {
89
+ return;
90
+ }
86
91
  const writer = { source: "mcp", client: who.client };
87
92
  /** This client, for this person: how the studio shows it among who is in a wizard. */
88
93
  const agent = {
@@ -52,7 +52,7 @@ export const EMBEDDING_WAYS = ["gateway", "openai", "local", "credits"];
52
52
  export const EMBEDDING_CHOICES = ["auto", ...EMBEDDING_WAYS, "off"];
53
53
  /**
54
54
  * Google's EmbeddingGemma 2: open weights, about 1.3 GB in Ollama's library. Text, images and
55
- * sound share one space; the index uses its text so far.
55
+ * sound share one space; the index uses text, and pictures while `knowledgeMedia` is on.
56
56
  */
57
57
  export const LOCAL_EMBEDDING_MODEL = "embeddinggemma-2:740m";
58
58
  /** The ways to a decision model, in the order `auto` tries them. */
@@ -873,19 +873,26 @@ function localEmbeddingName(cfg) {
873
873
  }
874
874
  /** What the local Ollama held at the last look, by address and model, so a call does not ask it every time. */
875
875
  const ollamaHeld = new Map();
876
- /** Whether Ollama on this computer holds `name`, looked up once a minute. */
876
+ /** What Ollama on this computer can do with `name` ("embedding", "vision"); null where it does not hold it. Looked up once a minute. */
877
877
  async function ollamaHolds(url, name) {
878
878
  const key = `${url} ${name}`;
879
879
  const hit = ollamaHeld.get(key);
880
880
  if (hit && Date.now() < hit.at) {
881
- return hit.there;
882
- }
883
- const there = await fetch(`${ollamaRoot(url)}/api/tags`, { signal: AbortSignal.timeout(1500) })
884
- .then((res) => (res.ok ? res.json() : null))
885
- .then((body) => (body?.models ?? []).some((m) => m.name === name || m.name === `${name}:latest`))
886
- .catch(() => false);
887
- ollamaHeld.set(key, { there, at: Date.now() + 60_000 });
888
- return there;
881
+ return hit.capabilities;
882
+ }
883
+ const capabilities = await fetch(`${ollamaRoot(url)}/api/tags`, {
884
+ signal: AbortSignal.timeout(1500),
885
+ })
886
+ .then((res) => res.ok
887
+ ? res.json()
888
+ : null)
889
+ .then((body) => {
890
+ const found = (body?.models ?? []).find((m) => m.name === name || m.name === `${name}:latest`);
891
+ return found ? (found.capabilities ?? []) : null;
892
+ })
893
+ .catch(() => null);
894
+ ollamaHeld.set(key, { capabilities, at: Date.now() + 60_000 });
895
+ return capabilities;
889
896
  }
890
897
  /** Forgets what Ollama held: after a model was downloaded or removed (local-models.ts). */
891
898
  export function forgetLocalModels() {
@@ -896,6 +903,57 @@ export function forgetLocalModels() {
896
903
  export async function localOllamaUrl() {
897
904
  return (await config()).settings.ollamaUrl ?? env.ollamaUrl;
898
905
  }
906
+ /** A vector scaled to length one, as the text embeddings come. */
907
+ function unitVector(v) {
908
+ const len = Math.sqrt(v.reduce((sum, x) => sum + x * x, 0)) || 1;
909
+ return v.map((x) => x / len);
910
+ }
911
+ /** Pictures through Ollama's own /api/embed: its OpenAI-style endpoint takes no pictures. */
912
+ function ollamaImageEmbedder(url, name) {
913
+ return async (jpeg) => {
914
+ const res = await fetch(`${ollamaRoot(url)}/api/embed`, {
915
+ method: "POST",
916
+ headers: { "content-type": "application/json" },
917
+ body: JSON.stringify({ model: name, input: [{ image: jpeg.toString("base64") }] }),
918
+ signal: AbortSignal.timeout(120_000),
919
+ });
920
+ if (!res.ok) {
921
+ throw new Error(`Ollama answered ${res.status}: ${(await res.text()).slice(0, 200)}`);
922
+ }
923
+ const [v] = (await res.json()).embeddings ?? [];
924
+ if (!v) {
925
+ throw new Error("Ollama gave no vector for the picture.");
926
+ }
927
+ return unitVector(v);
928
+ };
929
+ }
930
+ /** Pictures through the gateway of the credits, where the embedding class's model takes them. */
931
+ function gatewayImageEmbedder(access) {
932
+ return async (jpeg) => {
933
+ const res = await fetch(`${access.baseUrl}/v4/ai/picture-embedding`, {
934
+ method: "POST",
935
+ headers: {
936
+ authorization: `Bearer ${access.token}`,
937
+ "content-type": "application/json",
938
+ "ai-model-id": "wizards/embedding",
939
+ ...DEFINITION_HEADER,
940
+ ...(access.tenant ? { "x-wizards-tenant": access.tenant } : {}),
941
+ },
942
+ body: JSON.stringify({ pictures: [jpeg.toString("base64")] }),
943
+ signal: AbortSignal.timeout(120_000),
944
+ });
945
+ if (!res.ok) {
946
+ throw new Error(`The gateway answered ${res.status}: ${(await res.text()).slice(0, 200)}`);
947
+ }
948
+ const [v] = (await res.json()).embeddings ?? [];
949
+ if (!v) {
950
+ throw new Error("The gateway gave no vector for the picture.");
951
+ }
952
+ return unitVector(v);
953
+ };
954
+ }
955
+ /** Whether pictures go into the index as pictures (docs/plans/media-and-files.md). */
956
+ const picturesOn = async () => feature("knowledgeMedia", await remoteFeatures().catch(() => null));
899
957
  /** The embedding model one way reaches; null where that way has none. */
900
958
  async function embeddingBy(cfg, way, chosen) {
901
959
  const ref = env.models.embedding;
@@ -925,11 +983,19 @@ async function embeddingBy(cfg, way, chosen) {
925
983
  case "local": {
926
984
  const url = cfg.settings.ollamaUrl ?? env.ollamaUrl;
927
985
  const name = localEmbeddingName(cfg);
928
- if (!(await ollamaHolds(url, name))) {
986
+ const capabilities = await ollamaHolds(url, name);
987
+ if (!capabilities) {
929
988
  return null;
930
989
  }
990
+ // Text through the OpenAI-style API, pictures through /api/embed: the same vectors.
931
991
  const ollama = createOpenAI({ baseURL: url, apiKey: "ollama" });
932
- return { model: ollama.embedding(name), ref: `ollama:${name}` };
992
+ return {
993
+ model: ollama.embedding(name),
994
+ ref: `ollama:${name}`,
995
+ ...(capabilities.includes("vision") && (await picturesOn())
996
+ ? { embedImage: ollamaImageEmbedder(url, name) }
997
+ : {}),
998
+ };
933
999
  }
934
1000
  default: {
935
1001
  const access = await creditAccess(cfg, chosen).catch(() => null);
@@ -938,6 +1004,9 @@ async function embeddingBy(cfg, way, chosen) {
938
1004
  ? {
939
1005
  model: gatewayClient(access, {}, await tiersOn()).embeddingModel("wizards/embedding"),
940
1006
  ref: bound.model,
1007
+ ...(bound.pictures && (await picturesOn())
1008
+ ? { embedImage: gatewayImageEmbedder(access) }
1009
+ : {}),
941
1010
  }
942
1011
  : null;
943
1012
  }
@@ -975,7 +1044,7 @@ async function embeddingAccess(cfg) {
975
1044
  */
976
1045
  export async function embeddingModel() {
977
1046
  const found = await embeddingAccess(await config());
978
- return found ? { model: found.model, ref: found.ref } : null;
1047
+ return found ? { model: found.model, ref: found.ref, embedImage: found.embedImage } : null;
979
1048
  }
980
1049
  /**
981
1050
  * The search, for the settings page: the choice, which ways have an embedding model, and which
@@ -0,0 +1,71 @@
1
+ import { mkdirSync } from "node:fs";
2
+ import { readdir, readFile, rm, stat, utimes, writeFile } from "node:fs/promises";
3
+ import { join } from "node:path";
4
+ import { env } from "../env.js";
5
+ /**
6
+ * What was read of mounted files' originals, by their hash: a mount keeps no text (decision D3),
7
+ * so a search's snippets, a step's read and the vectors read the original again, and this keeps
8
+ * the last of them. Bounded: past MAX_BYTES the least recently used go first. Rebuildable,
9
+ * never backed up.
10
+ */
11
+ const DIR = join(env.dataDir, "parsed", "m");
12
+ const MAX_BYTES = 2 * 1024 ** 3;
13
+ let size = null;
14
+ const fileOf = (hash) => join(DIR, `${hash}.json`);
15
+ async function sizeNow() {
16
+ if (size === null) {
17
+ mkdirSync(DIR, { recursive: true });
18
+ let total = 0;
19
+ for (const name of await readdir(DIR)) {
20
+ total += (await stat(join(DIR, name)).catch(() => null))?.size ?? 0;
21
+ }
22
+ size = total;
23
+ }
24
+ return size;
25
+ }
26
+ /** The oldest out until the cache is under nine tenths of its bound. */
27
+ async function trim() {
28
+ const files = await Promise.all((await readdir(DIR)).map(async (name) => {
29
+ const s = await stat(join(DIR, name)).catch(() => null);
30
+ return { name, size: s?.size ?? 0, at: s?.mtimeMs ?? 0 };
31
+ }));
32
+ files.sort((a, b) => a.at - b.at);
33
+ let total = files.reduce((n, f) => n + f.size, 0);
34
+ for (const f of files) {
35
+ if (total <= MAX_BYTES * 0.9) {
36
+ break;
37
+ }
38
+ await rm(join(DIR, f.name), { force: true });
39
+ total -= f.size;
40
+ }
41
+ size = total;
42
+ }
43
+ /**
44
+ * The text of the bytes `hash`: from the cache, else made by `read` and kept. Null when the file
45
+ * has no text (a photo, a scan OCR couldn't read); that is kept too, so it is not read again,
46
+ * unless `again` asks for another try at a kept read without text.
47
+ */
48
+ export async function cachedText(hash, read, again = false) {
49
+ await sizeNow();
50
+ const file = fileOf(hash);
51
+ const kept = await readFile(file, "utf8").catch(() => null);
52
+ const parsed = kept === null ? undefined : JSON.parse(kept);
53
+ if (parsed !== undefined && !(again && !parsed?.markdown.trim())) {
54
+ const now = new Date();
55
+ await utimes(file, now, now).catch(() => undefined);
56
+ return parsed;
57
+ }
58
+ const made = await read();
59
+ const json = JSON.stringify(made);
60
+ await writeFile(file, json);
61
+ size = (size ?? 0) + Buffer.byteLength(json);
62
+ if (size > MAX_BYTES) {
63
+ await trim();
64
+ }
65
+ return made;
66
+ }
67
+ /** The text kept for `hash`, without reading the original; undefined where none is kept. */
68
+ export async function keptText(hash) {
69
+ const kept = await readFile(fileOf(hash), "utf8").catch(() => null);
70
+ return kept === null ? undefined : JSON.parse(kept);
71
+ }