wizards 0.2.47 → 0.2.49

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 (181) hide show
  1. package/README.md +2 -1
  2. package/apps/runtime/dist/agents/{project-assistant.js → studio-assistant.js} +199 -69
  3. package/apps/runtime/dist/agents/website.js +25 -2
  4. package/apps/runtime/dist/app.js +2 -1
  5. package/apps/runtime/dist/apple/wizards-apple +0 -0
  6. package/apps/runtime/dist/assistant/browser.js +26 -0
  7. package/apps/runtime/dist/assistant/docs.js +158 -0
  8. package/apps/runtime/dist/assistant/knows.js +325 -0
  9. package/apps/runtime/dist/assistant/primer.js +26 -0
  10. package/apps/runtime/dist/authoring/guide.js +5 -0
  11. package/apps/runtime/dist/cli/status.js +1 -1
  12. package/apps/runtime/dist/connectors/plugin-connections.js +123 -29
  13. package/apps/runtime/dist/db/migrations/tenant/0012_assistant_chat.sql +40 -0
  14. package/apps/runtime/dist/db/migrations/tenant/0013_run_origin.sql +1 -0
  15. package/apps/runtime/dist/db/migrations/tenant/meta/0012_snapshot.json +3132 -0
  16. package/apps/runtime/dist/db/migrations/tenant/meta/0013_snapshot.json +3139 -0
  17. package/apps/runtime/dist/db/migrations/tenant/meta/_journal.json +14 -0
  18. package/apps/runtime/dist/db/schema.js +35 -0
  19. package/apps/runtime/dist/docs/dev/index.md +34 -0
  20. package/apps/runtime/dist/docs/dev/meta.json +7 -0
  21. package/apps/runtime/dist/docs/dev/plugins/connections.md +70 -0
  22. package/apps/runtime/dist/docs/dev/plugins/events.md +86 -0
  23. package/apps/runtime/dist/docs/dev/plugins/examples.md +99 -0
  24. package/apps/runtime/dist/docs/dev/plugins/index.md +72 -0
  25. package/apps/runtime/dist/docs/dev/plugins/layout.md +88 -0
  26. package/apps/runtime/dist/docs/dev/plugins/meta.json +29 -0
  27. package/apps/runtime/dist/docs/dev/plugins/pro-modules.md +59 -0
  28. package/apps/runtime/dist/docs/dev/plugins/quick-start.md +92 -0
  29. package/apps/runtime/dist/docs/dev/plugins/reference.md +298 -0
  30. package/apps/runtime/dist/docs/dev/plugins/reloading.md +75 -0
  31. package/apps/runtime/dist/docs/dev/plugins/routes.md +123 -0
  32. package/apps/runtime/dist/docs/dev/plugins/runners.md +184 -0
  33. package/apps/runtime/dist/docs/dev/plugins/server.md +191 -0
  34. package/apps/runtime/dist/docs/dev/plugins/shipping.md +98 -0
  35. package/apps/runtime/dist/docs/dev/plugins/space.md +260 -0
  36. package/apps/runtime/dist/docs/dev/plugins/starters.md +62 -0
  37. package/apps/runtime/dist/docs/dev/plugins/studio.md +261 -0
  38. package/apps/runtime/dist/docs/dev/plugins/styling.md +109 -0
  39. package/apps/runtime/dist/docs/dev/plugins/tables.md +102 -0
  40. package/apps/runtime/dist/docs/dev/plugins/tools.md +128 -0
  41. package/apps/runtime/dist/docs/meta.json +3 -0
  42. package/apps/runtime/dist/docs/user/ai-apps.md +99 -0
  43. package/apps/runtime/dist/docs/user/assistant.md +52 -0
  44. package/apps/runtime/dist/docs/user/build-a-wizard.md +79 -0
  45. package/apps/runtime/dist/docs/user/command-line.md +76 -0
  46. package/apps/runtime/dist/docs/user/connectors.md +80 -0
  47. package/apps/runtime/dist/docs/user/data.md +61 -0
  48. package/apps/runtime/dist/docs/user/first-start.md +42 -0
  49. package/apps/runtime/dist/docs/user/index.md +45 -0
  50. package/apps/runtime/dist/docs/user/install.md +76 -0
  51. package/apps/runtime/dist/docs/user/meta.json +30 -0
  52. package/apps/runtime/dist/docs/user/models.md +125 -0
  53. package/apps/runtime/dist/docs/user/plugins.md +61 -0
  54. package/apps/runtime/dist/docs/user/run.md +92 -0
  55. package/apps/runtime/dist/docs/user/server.md +50 -0
  56. package/apps/runtime/dist/docs/user/space.md +97 -0
  57. package/apps/runtime/dist/docs/user/steps.md +196 -0
  58. package/apps/runtime/dist/docs/user/test-and-share.md +216 -0
  59. package/apps/runtime/dist/docs/user/troubleshooting.md +57 -0
  60. package/apps/runtime/dist/docs/user/wordpress.md +103 -0
  61. package/apps/runtime/dist/engine/device.js +182 -0
  62. package/apps/runtime/dist/engine/events.js +3 -0
  63. package/apps/runtime/dist/engine/input.js +3 -0
  64. package/apps/runtime/dist/engine/prepare.js +1 -0
  65. package/apps/runtime/dist/engine/requirements.js +6 -109
  66. package/apps/runtime/dist/engine/runner.js +13 -5
  67. package/apps/runtime/dist/engine/steps.js +2 -1
  68. package/apps/runtime/dist/env.js +1 -1
  69. package/apps/runtime/dist/harness/apple.js +258 -0
  70. package/apps/runtime/dist/harness/model.js +3 -1
  71. package/apps/runtime/dist/manage.js +11 -0
  72. package/apps/runtime/dist/mcp/auth.js +3 -0
  73. package/apps/runtime/dist/mcp/scopes.js +11 -2
  74. package/apps/runtime/dist/media/transcribe.js +6 -1
  75. package/apps/runtime/dist/models.js +63 -9
  76. package/apps/runtime/dist/plugins/loader.js +2 -0
  77. package/apps/runtime/dist/routes/api.js +232 -1
  78. package/apps/runtime/dist/routes/plugins.js +6 -2
  79. package/apps/runtime/dist/routes/runs.js +65 -3
  80. package/apps/runtime/dist/routes/studio.js +130 -69
  81. package/apps/runtime/dist/services/api.js +244 -0
  82. package/apps/runtime/dist/services/assistant-chats.js +267 -0
  83. package/apps/runtime/dist/services/engenty-shapes.js +1 -1
  84. package/apps/runtime/dist/services/package.js +77 -9
  85. package/apps/runtime/dist/services/project-index.js +1 -1
  86. package/apps/runtime/dist/services/runs.js +4 -3
  87. package/apps/runtime/dist/services/site.js +262 -0
  88. package/apps/runtime/dist/services/space-origin.js +45 -2
  89. package/apps/web/dist/assets/AboutDialog-6CCpWqAl.js +1 -0
  90. package/apps/web/dist/assets/ChangelogDialog-ApswqjRk.js +1 -0
  91. package/apps/web/dist/assets/ChatView-D7N2QyGS.js +10 -0
  92. package/apps/web/dist/assets/EditorPage-CbtYQTWj.js +3 -0
  93. package/apps/web/dist/assets/FlowPreview-KTaelucs.js +1 -0
  94. package/apps/web/dist/assets/{Harness-zKMptCzB.js → Harness-_mD1Stm4.js} +2 -2
  95. package/apps/web/dist/assets/Marketplace-DKQ9j4OC.js +2 -0
  96. package/apps/web/dist/assets/NewWizardPage-CoCCRcoi.js +1 -0
  97. package/apps/web/dist/assets/ProjectPage-DDLh_qxi.js +2 -0
  98. package/apps/web/dist/assets/PublicRunner-Lpu-BY5w.js +1 -0
  99. package/apps/web/dist/assets/ReadOnly-ClY8xMQS.js +1 -0
  100. package/apps/web/dist/assets/RunDrawer-JXG5wZp7.js +4 -0
  101. package/apps/web/dist/assets/RunnerView-BlUSqfqB.js +1 -0
  102. package/apps/web/dist/assets/SettingsPage-V_E267hI.js +1 -0
  103. package/apps/web/dist/assets/SetupPage-Dvoze8cZ.js +1 -0
  104. package/apps/web/dist/assets/SharePage-DBcp_npb.js +1 -0
  105. package/apps/web/dist/assets/brand-CNF5NxD9.js +2 -0
  106. package/apps/web/dist/assets/changelog-CmZrNHwc.js +1 -0
  107. package/apps/web/dist/assets/circle-alert-r2qc1Vej.js +1 -0
  108. package/apps/web/dist/assets/engenty-eXZ-EAwd.js +1 -0
  109. package/apps/web/dist/assets/esm-DZeij_95.js +7 -0
  110. package/apps/web/dist/assets/{fluffy-engenty-D7rFrNcJ.js → fluffy-engenty-ClRou7yu.js} +1 -1
  111. package/apps/web/dist/assets/index-BbogBDv_.js +11 -0
  112. package/apps/web/dist/assets/index-Dr0bv52Q.css +1 -0
  113. package/apps/web/dist/assets/jsx-runtime-BNakU3Ej.js +1 -0
  114. package/apps/web/dist/assets/lock-N-C6-ZeG.js +1 -0
  115. package/apps/web/dist/assets/logo-C4V2_3Ar.js +1 -0
  116. package/apps/web/dist/assets/oss-credits-BQQX0kvk.js +1 -0
  117. package/apps/web/dist/assets/pdfmake-Cx9scTbD.js +228 -0
  118. package/apps/web/dist/assets/rolldown-runtime-hePW80VL.js +1 -0
  119. package/apps/web/dist/assets/session-Cpg5S8B3.js +1 -0
  120. package/apps/web/dist/assets/settings-menu-C7m2i7Sf.js +1 -0
  121. package/apps/web/dist/assets/ui-DKcggL84.js +133 -0
  122. package/apps/web/dist/assets/upload-D24SDj7W.js +1 -0
  123. package/apps/web/dist/assets/useMutation-DKyQXgyj.js +1 -0
  124. package/apps/web/dist/assets/vfs_fonts-DllDSYt1.js +1 -0
  125. package/apps/web/dist/assets/volume-2-C-Y7-S4b.js +1 -0
  126. package/apps/web/dist/embed.js +57 -8
  127. package/apps/web/dist/index.html +12 -16
  128. package/apps/web/dist/mcp/flow.html +435 -207
  129. package/modules/calls/dist/client.css +1 -1
  130. package/modules/sms/dist/client.css +1 -1
  131. package/modules/whatsapp/dist/client.css +1 -1
  132. package/node_modules/@engenty-wizards/plugin-sdk/dist/index.d.ts +82 -7
  133. package/node_modules/@engenty-wizards/plugin-sdk/dist/studio.d.ts +58 -4
  134. package/node_modules/@engenty-wizards/shared/dist/assistant.d.ts +113 -0
  135. package/node_modules/@engenty-wizards/shared/dist/assistant.js +55 -0
  136. package/node_modules/@engenty-wizards/shared/dist/definition.d.ts +58 -1
  137. package/node_modules/@engenty-wizards/shared/dist/definition.js +94 -4
  138. package/node_modules/@engenty-wizards/shared/dist/fit.d.ts +71 -0
  139. package/node_modules/@engenty-wizards/shared/dist/fit.js +381 -0
  140. package/node_modules/@engenty-wizards/shared/dist/run.d.ts +3 -1
  141. package/package.json +1 -1
  142. package/apps/web/dist/assets/AboutDialog-t7bpiasT.js +0 -1
  143. package/apps/web/dist/assets/ChangelogDialog-B87yS6aN.js +0 -1
  144. package/apps/web/dist/assets/ChatView-Dm764bYy.js +0 -10
  145. package/apps/web/dist/assets/EditorPage-BG_Ue2iC.js +0 -3
  146. package/apps/web/dist/assets/FlowPreview-ChXfiMn_.js +0 -1
  147. package/apps/web/dist/assets/HomePage-BXSg5P5k.js +0 -1
  148. package/apps/web/dist/assets/Marketplace-BWhUJ4UX.js +0 -2
  149. package/apps/web/dist/assets/NewWizardPage-C3NqEGmg.js +0 -1
  150. package/apps/web/dist/assets/ProjectPage-D6Fy7uTV.js +0 -2
  151. package/apps/web/dist/assets/PublicRunner-ChgJs0C9.js +0 -1
  152. package/apps/web/dist/assets/ReadOnly-C9P9aiU6.js +0 -1
  153. package/apps/web/dist/assets/RunDrawer-CvIKLphz.js +0 -4
  154. package/apps/web/dist/assets/RunnerView-Bmayop7s.js +0 -2
  155. package/apps/web/dist/assets/SettingsPage-QkwtRFoD.js +0 -1
  156. package/apps/web/dist/assets/SetupPage-B3IOQLO3.js +0 -1
  157. package/apps/web/dist/assets/SharePage-C3QEzicl.js +0 -1
  158. package/apps/web/dist/assets/ThemeSwitch-3IzIOlNz.js +0 -1
  159. package/apps/web/dist/assets/arrow-right-Dpp_mpHe.js +0 -1
  160. package/apps/web/dist/assets/changelog-Du2gWzlN.js +0 -1
  161. package/apps/web/dist/assets/circle-alert-CPo3Naay.js +0 -1
  162. package/apps/web/dist/assets/definition-CQGiBQ4X.js +0 -56
  163. package/apps/web/dist/assets/engenty-Cm8yZLON.js +0 -1
  164. package/apps/web/dist/assets/esm-rJY59Ixx.js +0 -7
  165. package/apps/web/dist/assets/external-link-CpU8aJY2.js +0 -1
  166. package/apps/web/dist/assets/index-Cz6c1S5g.js +0 -78
  167. package/apps/web/dist/assets/index-DKHClEy3.css +0 -1
  168. package/apps/web/dist/assets/jsx-runtime-D3jfb0Ew.js +0 -1
  169. package/apps/web/dist/assets/lock-C_WlXIQ0.js +0 -1
  170. package/apps/web/dist/assets/logo-C80CWCDM.js +0 -1
  171. package/apps/web/dist/assets/oss-credits-CIxnNZor.js +0 -1
  172. package/apps/web/dist/assets/react-dom-DenslgJm.js +0 -1
  173. package/apps/web/dist/assets/refresh-cw-Cli5WGnW.js +0 -1
  174. package/apps/web/dist/assets/session-miDEdw2c.js +0 -1
  175. package/apps/web/dist/assets/settings-menu-ROT8Lbbj.js +0 -1
  176. package/apps/web/dist/assets/sparkles-CP5H-O1E.js +0 -1
  177. package/apps/web/dist/assets/trash-DU-hZpV0.js +0 -1
  178. package/apps/web/dist/assets/ui-D92EkdEB.js +0 -9
  179. package/apps/web/dist/assets/upload-DMq5N6Fw.js +0 -1
  180. package/apps/web/dist/assets/useMutation-DKcIz55V.js +0 -1
  181. package/apps/web/dist/assets/volume-2-0SfkvOho.js +0 -1
package/README.md CHANGED
@@ -187,4 +187,5 @@ and is a site of its own: `pnpm dev:docs`.
187
187
 
188
188
  [FSL-1.1-MIT](LICENSE): use it for yourself and your company, run it, change it — just don't
189
189
  offer it to others as a competing product or service. Each release becomes MIT two years
190
- after it is published.
190
+ after it is published. [COPYRIGHTS.md](COPYRIGHTS.md) names the owner, the marks, what is not ours and the
191
+ third-party software with its licences.
@@ -2,40 +2,66 @@ import { anthropic } from "@ai-sdk/anthropic";
2
2
  import { FACT_TYPES, factKey, PROJECT_FILE_KINDS, PROJECT_LIMITS, projectFileLimit, } from "@engenty-wizards/shared/projects";
3
3
  import { Agent } from "@mastra/core/agent";
4
4
  import { createTool } from "@mastra/core/tools";
5
+ import { nanoid } from "nanoid";
5
6
  import { z } from "zod";
7
+ import { knowsTools } from "../assistant/knows.js";
8
+ import { PRIMER } from "../assistant/primer.js";
6
9
  import { attachTools, costOf, gatewayTools, textModel } from "../models.js";
7
10
  import { ServiceError } from "../services/errors.js";
8
11
  import { knowledgeCounts } from "../services/knowledge.js";
9
12
  import { addProjectFile, projectFileContent, projectFiles, updateProjectFile, } from "../services/project-files.js";
10
13
  import { documentText } from "../services/project-index.js";
11
- import { brandColorSchema, ownedProject, updateProject } from "../services/projects.js";
14
+ import { brandColorSchema, ownedProject, updateProject, } from "../services/projects.js";
12
15
  import { categoryRows } from "../services/space-categories.js";
13
16
  import { currentTenant } from "../tenants/tenant.js";
14
17
  import { safeFetch } from "../tools/net-guard.js";
15
18
  import { assistantPageOf, assistantToolsOf } from "../tools/plugin.js";
16
19
  import { readWebsite } from "./website.js";
17
20
  const MAX_STEPS = 24;
18
- const SYSTEM = `You help the admin of "engenty wizards" set up a SPACE: what every wizard of the space draws on — who they are (title, about), the brand (logos, colours), assets (images, graphics, videos), documents, and facts (label → value: address, VAT id, phone, opening hours — anything).
21
+ const SYSTEM = `You are the assistant of the engenty wizards studio. You stand on every page of the studio except the wizard editor, which has a chat of its own: the space's pages, the settings, the plugins' pages. You help the person who works here understand the app, set it up and find their way.
19
22
 
20
- You talk to the admin. Answer in the admin's language, briefly and warmly. Never mention JSON, ids, keys or tool names. Call it a space (German „Space“), never a project: the tools say project, the app says space.
23
+ You talk to the person. Answer in their language, briefly and warmly: a few sentences, a short list where it helps. Never mention JSON, ids, keys or tool names. Call it a space (German „Space“), never a project: the tools say project, the app says space.
21
24
 
22
- HOW YOU WORK
23
- - The space as it is now comes with every message. You change it ONLY through tools.
25
+ ${PRIMER}
26
+
27
+ WHAT YOU KNOW
28
+ - How the app works: from the guides of this installed version. Before you explain how something works, docs_search (and docs_read a page); link the page you used (engenty.ai/docs/…). How wizards are written: authoring_guide. Never guess at a menu, a button or a feature.
29
+ - Live data only from tools, never from memory: gallery_search / gallery_detail for templates, plans for plans and prices, account for the person, team, plan and credits, usage for what was spent, wizards and runs for the space, models for what thinks and makes here.
30
+ - You never buy, upgrade, top up or change a plan or a setting that costs money. Explain it, then open the page where the person does it (navigate, or give the billing page's link).
31
+ - Earlier chats: their summaries come with every message. chats_search and chat_read find more when the person refers to something said before.
32
+
33
+ THE PAGE
34
+ - Every message comes with the page the person writes from: its address, title, the section in view, an open item, what is selected, a line on what it holds and its fields. Answer about what they see; "this" and "here" mean that page.
35
+ - In the browser you may: navigate (open a studio page), highlight (dim the page except one element, or ring it, with a short card), look_at_page (what is visible: headings, buttons, fields with their values), read_section (one area in full), fill_field (put a value into a field, not saved), scroll_to. A page may add tools of its own (filter its list, show a week): use them to show what you talk about. A page you open during an answer brings its tools too: navigate and look_at_page list them, page_tool runs them. Targets are what look_at_page lists.
36
+ - Show rather than describe: open the page and highlight the place when the person asks where or how. look_at_page first when you are not sure what is there.
37
+ - fill_field never saves: say that the person checks and saves. You never press buttons for the person.
38
+
39
+ THE SPACE
40
+ - Where a space's tools are there, you also fill the space in: what every wizard of the space draws on — who they are (title, about), the brand (logos, colours), assets (images, graphics, videos), documents, and facts (label → value: address, VAT id, phone, opening hours — anything). The space as it is now comes with every message then; you change it ONLY through tools.
24
41
  - A website: read_website it first. You get the page's text, colours from its stylesheet, logo candidates and the links to imprint / contact / about. Read those pages too (at most four more) for address, VAT id, register number, phone, email, bank details, who runs it.
25
- - Facts: one fact per thing, a short label in the admin's language ("Adresse", "UID", "Telefon"), the value on one line where it fits. Only what a source or the admin states — never guess, never invent. Keep the facts that are there; a fact with a known label is updated.
26
- - About: two to five sentences — what they do, for whom, what sets them apart, the tone they write in. Rewrite it only when you learned something new or the admin asks.
42
+ - Facts: one fact per thing, a short label in the person's language ("Adresse", "UID", "Telefon"), the value on one line where it fits. Only what a source or the person states — never guess, never invent. Keep the facts that are there; a fact with a known label is updated.
43
+ - About: two to five sentences — what they do, for whom, what sets them apart, the tone they write in. Rewrite it only when you learned something new or the person asks.
27
44
  - Colours: two to six, the main one first, each with a name that says what it is for ("Primär", "Hintergrund", "Text"). Take them from the stylesheet's variables or its most used colours, never from photos. set_colors replaces the list: pass all colours that should remain.
28
45
  - Logos: save the best candidate (an SVG or a large PNG rather than a favicon); a second one only if it truly differs (for dark ground, a signet). A few images that show the business (header, team, products) may be saved as assets — a handful, never everything.
29
- - Files the admin attached are stored already; the message names them. look_at_file shows you a picture or a document's text. Give a file a description with describe_file when it has none or the admin says what it is. Take facts from a document when the admin asks for it.
30
- - Call independent tools together. Work in few steps.
31
- - Finish with one to three sentences: what you filled in, what is still missing, and at most one question.
46
+ - Files the person attached are stored already; the message names them. look_at_file shows you a picture or a document's text. Give a file a description with describe_file when it has none or the person says what it is. Take facts from a document when asked.
47
+ - Wissen (German „Wissen“) is what the wizards' steps look things up in: pages, tables and files, kept apart by typed Kategorien. Documents the person attaches are read into Wissen by themselves: say so; do not copy their text into facts unless asked. A website, a sitemap or a folder whose entries should go into Wissen is a source: where a tool proposes sources, use it (the person takes the proposal on its card); where there is none, say that sources need the Sources plugin.
48
+ - Talking from another page than Info & brand, change title, about, logos, colours and facts only when the person asks.
49
+ - A space that is read-only (synced from a local install, or a team that builds elsewhere) has no tools: say where it is changed.
32
50
 
33
- WISSEN
34
- - Wissen (German „Wissen“) is what the wizards' steps look things up in: pages, tables and files, kept apart by typed Kategorien (Baustelle, Berichtsdatum, Art der Förderung …). The admin sees it on the page below you.
35
- - Documents the admin attaches are read into Wissen by themselves: a page, sub-pages for a long structured document, a table per sheet. Say so; do not copy their text into facts unless asked.
36
- - A website, a sitemap or a folder whose entries should go into Wissen is a source. Where a tool proposes sources, use it: the admin takes the proposal on its card. Where there is none, say that sources need the Sources plugin, and offer to read the site for the space's own details instead.
37
- - Talking from Wissen, change title, about, logos, colours and facts only when the admin asks.`;
38
- function activity(tool, args) {
51
+ HOW YOU WORK
52
+ - Call independent tools together. Work in few steps.
53
+ - Finish with one to three sentences: what you did or found, what is still open, and at most one question.`;
54
+ const LABELS = {
55
+ save_logo: { de: "Holt das Logo …", en: "Fetching the logo …" },
56
+ save_file: { de: "Holt eine Datei …", en: "Fetching a file …" },
57
+ set_profile: { de: "Schreibt Titel und Beschreibung …", en: "Writing title and description …" },
58
+ set_facts: { de: "Trägt Fakten ein …", en: "Entering facts …" },
59
+ set_colors: { de: "Trägt die Farben ein …", en: "Entering the colours …" },
60
+ look_at_file: { de: "Sieht sich eine Datei an …", en: "Looking at a file …" },
61
+ describe_file: { de: "Beschreibt eine Datei …", en: "Describing a file …" },
62
+ web_search: { de: "Sucht im Web …", en: "Searching the web …" },
63
+ };
64
+ function activity(tool, args, lang) {
39
65
  const host = (u) => {
40
66
  try {
41
67
  return new URL(/^https?:/i.test(String(u)) ? String(u) : `https://${u}`).hostname;
@@ -44,25 +70,22 @@ function activity(tool, args) {
44
70
  return "";
45
71
  }
46
72
  };
47
- switch (tool) {
48
- case "read_website":
49
- return args.url ? `Liest ${host(args.url)} …` : "Liest die Website …";
50
- case "save_file":
51
- return args.kind === "logo" ? "Holt das Logo …" : "Holt eine Datei …";
52
- case "set_profile":
53
- return "Schreibt Titel und Beschreibung …";
54
- case "set_facts":
55
- case "remove_facts":
56
- return "Trägt Fakten ein …";
57
- case "set_colors":
58
- return "Trägt die Farben ein …";
59
- case "look_at_file":
60
- return "Sieht sich eine Datei an …";
61
- case "describe_file":
62
- return "Beschreibt eine Datei …";
63
- default:
64
- return null;
73
+ if (tool === "read_website") {
74
+ const at = args.url ? host(args.url) : "";
75
+ return lang === "de"
76
+ ? at
77
+ ? `Liest ${at} …`
78
+ : "Liest die Website …"
79
+ : at
80
+ ? `Reading ${at} …`
81
+ : "Reading the website …";
65
82
  }
83
+ const key = tool === "save_file" && args.kind === "logo"
84
+ ? "save_logo"
85
+ : tool === "remove_facts"
86
+ ? "set_facts"
87
+ : tool;
88
+ return LABELS[key]?.[lang] ?? null;
66
89
  }
67
90
  async function attempt(run) {
68
91
  try {
@@ -94,11 +117,14 @@ async function projectState(userId, projectId) {
94
117
  })),
95
118
  };
96
119
  }
97
- function buildTools(input, resolved, wrote) {
98
- const { userId, projectId, signal } = input;
120
+ /** The space's own tools: what fills it in. */
121
+ function spaceTools(input, project, wrote) {
122
+ const { signal } = input;
123
+ const userId = input.user.id;
124
+ const projectId = project.id;
99
125
  // Said from inside the tool: an installed AI client runs tools without the stream showing it.
100
126
  const doing = (tool, args = {}) => {
101
- const label = activity(tool, args);
127
+ const label = activity(tool, args, input.lang);
102
128
  if (label) {
103
129
  input.onActivity?.(label);
104
130
  }
@@ -297,38 +323,128 @@ function buildTools(input, resolved, wrote) {
297
323
  },
298
324
  }),
299
325
  };
300
- if (resolved.vendor === "anthropic") {
301
- tools.web_search = anthropic.tools.webSearch_20250305({ maxUses: 5 });
326
+ return tools;
327
+ }
328
+ /** A browser tool as the model calls it: sent to the page, its answer awaited. */
329
+ function browserTool(input, spec) {
330
+ let inputSchema;
331
+ try {
332
+ inputSchema = z.fromJSONSchema(spec.parameters);
302
333
  }
303
- else if (resolved.gateway) {
304
- tools.web_search = gatewayTools.perplexitySearch({ maxResults: 6 });
334
+ catch {
335
+ return null;
305
336
  }
306
- return tools;
337
+ return createTool({
338
+ id: spec.name,
339
+ description: spec.description,
340
+ inputSchema,
341
+ // The id is the one `traced` gave the call: the browser answers to it.
342
+ execute: async (args, ctx) => input.callBrowser({
343
+ toolCallId: ctx?.toolCallId ?? nanoid(10),
344
+ toolCallName: spec.name,
345
+ args,
346
+ }),
347
+ });
307
348
  }
308
- /** One turn with the project assistant: it reads what the admin gave and fills the project in. */
309
- export async function runProjectAssistant(input) {
349
+ /** Text of a tool's result for the chat's record, cut short. */
350
+ function resultText(out) {
351
+ if (typeof out === "string") {
352
+ return out.slice(0, 1200);
353
+ }
354
+ try {
355
+ return (JSON.stringify(out, (key, value) => (key === "image" ? "(picture)" : value))?.slice(0, 1200) ?? "");
356
+ }
357
+ catch {
358
+ return "";
359
+ }
360
+ }
361
+ /**
362
+ * Every tool says when it is called and what it gave back (AG-UI's tool call), from inside: an
363
+ * installed AI client runs tools without the stream showing it. A browser tool's call carries the
364
+ * same id to the page.
365
+ */
366
+ function traced(tools, input, record) {
367
+ for (const [name, tool] of Object.entries(tools)) {
368
+ const run = tool?.execute;
369
+ if (typeof run !== "function") {
370
+ continue;
371
+ }
372
+ tool.execute = async (args, ctx = {}) => {
373
+ const toolCallId = nanoid(10);
374
+ const call = { toolCallId, toolCallName: name, args };
375
+ input.onToolCall?.(call);
376
+ const out = await run(args, { ...ctx, toolCallId });
377
+ const content = resultText(out);
378
+ record.push({ ...call, result: content });
379
+ input.onToolResult?.({ toolCallId, content });
380
+ return out;
381
+ };
382
+ }
383
+ }
384
+ /** The part of the space page a route stands on. */
385
+ function partOf(route) {
386
+ const m = route.match(/^\/space\/(info|knowledge|data|results)/);
387
+ return m ? m[1] : route === "/space" ? "info" : null;
388
+ }
389
+ /** One turn of the studio assistant. */
390
+ export async function runStudioAssistant(input) {
310
391
  let changed = false;
311
392
  const resolved = await textModel("high");
312
393
  const wrote = () => {
313
394
  changed = true;
314
395
  input.onChanged?.();
315
396
  };
316
- const tools = buildTools(input, resolved, wrote);
397
+ const cards = [];
398
+ const { project } = input;
399
+ const space = project && input.writable ? project : null;
400
+ const tools = {
401
+ ...knowsTools({
402
+ user: input.user,
403
+ project: project
404
+ ? { id: project.id, name: project.name, mcpServers: project.mcpServers }
405
+ : null,
406
+ lang: input.lang,
407
+ chatId: input.chat.id,
408
+ doing: (label) => input.onActivity?.(label),
409
+ }),
410
+ ...(space ? spaceTools(input, space, wrote) : {}),
411
+ };
317
412
  // What the tenant's plugins let the assistant do besides: a source of knowledge, say.
318
- const project = await ownedProject(input.userId, input.projectId);
319
- Object.assign(tools, await assistantToolsOf({
320
- tenantId: currentTenant(),
321
- space: { id: project.id, name: project.name },
322
- userId: input.userId,
323
- signal: input.signal ?? new AbortController().signal,
324
- emit: (message) => input.onActivity?.(message),
325
- changed: wrote,
326
- card: (card) => input.onCard?.(card),
327
- }));
413
+ if (space) {
414
+ Object.assign(tools, await assistantToolsOf({
415
+ tenantId: currentTenant(),
416
+ space: { id: space.id, name: space.name },
417
+ userId: input.user.id,
418
+ signal: input.signal ?? new AbortController().signal,
419
+ emit: (message) => input.onActivity?.(message),
420
+ changed: wrote,
421
+ card: (card) => {
422
+ cards.push(card);
423
+ input.onCard?.(card);
424
+ },
425
+ }));
426
+ }
427
+ for (const spec of input.browserTools) {
428
+ if (tools[spec.name]) {
429
+ continue;
430
+ }
431
+ const tool = browserTool(input, spec);
432
+ if (tool) {
433
+ tools[spec.name] = tool;
434
+ }
435
+ }
436
+ const toolCalls = [];
437
+ traced(tools, input, toolCalls);
438
+ if (resolved.vendor === "anthropic") {
439
+ tools.web_search = anthropic.tools.webSearch_20250305({ maxUses: 5 });
440
+ }
441
+ else if (resolved.gateway) {
442
+ tools.web_search = gatewayTools.perplexitySearch({ maxResults: 6 });
443
+ }
328
444
  attachTools(resolved, tools);
329
445
  const agent = new Agent({
330
- id: "project-assistant",
331
- name: "Project assistant",
446
+ id: "studio-assistant",
447
+ name: "Studio assistant",
332
448
  instructions: {
333
449
  role: "system",
334
450
  content: SYSTEM,
@@ -337,28 +453,42 @@ export async function runProjectAssistant(input) {
337
453
  model: resolved.model,
338
454
  tools,
339
455
  });
340
- const page = input.plugin
341
- ? await assistantPageOf(currentTenant(), input.plugin, { id: project.id, name: project.name })
456
+ const page = input.page;
457
+ const pluginPage = page?.plugin && project
458
+ ? await assistantPageOf(currentTenant(), page.plugin, { id: project.id, name: project.name })
342
459
  : null;
460
+ const part = page ? partOf(page.route) : null;
461
+ const { history } = input;
343
462
  const context = [
463
+ history.earlier.length
464
+ ? `Earlier chats with this person, newest first (chats_search finds more):\n${history.earlier
465
+ .map((c) => `- ${c.closedAt.slice(0, 10)} "${c.title}": ${c.summary.replace(/\n+/g, " ")}`)
466
+ .join("\n")}`
467
+ : "",
468
+ history.running ? `What this chat said before the messages above:\n${history.running}` : "",
344
469
  page
470
+ ? `Current page:\n\`\`\`json\n${JSON.stringify(page)}\n\`\`\``
471
+ : "The person writes from a page that tells nothing about itself.",
472
+ pluginPage
345
473
  ? [
346
- `The admin talks to you from the page of "${page.name}" in the studio${page.description ? `: ${page.description}` : "."} They most likely want to change what that page holds: use its tools (their names begin with "${input.plugin?.replace(/-/g, "_")}_"). Space settings stay possible when they ask for them.`,
347
- ...page.blocks,
474
+ `The page is the plugin "${pluginPage.name}"'s${pluginPage.description ? `: ${pluginPage.description}` : "."} They most likely mean what that page holds: use its tools first (their names begin with "${page?.plugin?.replace(/-/g, "_")}_"). Space settings stay possible when they ask for them.`,
475
+ ...pluginPage.blocks,
348
476
  ].join("\n\n")
349
477
  : "",
350
- `The project now:\n\`\`\`json\n${JSON.stringify(await projectState(input.userId, input.projectId))}\n\`\`\``,
351
- input.part === "knowledge"
352
- ? "The admin talks to you from Wissen: they want the wizards to know something."
478
+ space
479
+ ? `The space now:\n\`\`\`json\n${JSON.stringify(await projectState(input.user.id, space.id))}\n\`\`\``
480
+ : project
481
+ ? `The space "${project.name}" is read-only here: nothing of it can be changed in this studio.`
482
+ : "No space is open.",
483
+ part === "knowledge"
484
+ ? "The person talks to you from Wissen: they want the wizards to know something."
353
485
  : "",
354
486
  input.message,
355
487
  ]
356
488
  .filter(Boolean)
357
489
  .join("\n\n");
358
490
  const stream = await agent.stream([
359
- ...input.history
360
- .slice(-12)
361
- .map((m) => m.role === "user"
491
+ ...history.messages.map((m) => m.role === "user"
362
492
  ? { role: "user", content: m.content }
363
493
  : { role: "assistant", content: m.content }),
364
494
  { role: "user", content: context },
@@ -378,7 +508,7 @@ export async function runProjectAssistant(input) {
378
508
  else if (chunk.type === "tool-call") {
379
509
  // The model's own search has no tool of ours that could say so.
380
510
  if (payload.toolName === "web_search") {
381
- input.onActivity?.("Sucht im Web …");
511
+ input.onActivity?.(LABELS.web_search[input.lang]);
382
512
  }
383
513
  // Keep what it says before and after a tool call apart.
384
514
  if (reply.trim() && !reply.endsWith("\n\n")) {
@@ -391,5 +521,5 @@ export async function runProjectAssistant(input) {
391
521
  }
392
522
  }
393
523
  const usage = (await stream.totalUsage) ?? (await stream.usage);
394
- return { reply: reply.trim(), changed, costUsd: costOf(resolved, usage) };
524
+ return { reply: reply.trim(), changed, cards, toolCalls, costUsd: costOf(resolved, usage) };
395
525
  }
@@ -126,9 +126,31 @@ const linkText = (inner) => inner
126
126
  .replace(/\s+/g, " ")
127
127
  .trim()
128
128
  .slice(0, 120);
129
+ /** The `<script type="application/ld+json">` blocks of a page, parsed; a `@graph` is spread out. */
130
+ export function jsonLdOf(html) {
131
+ const out = [];
132
+ for (const m of html.matchAll(/<script\b[^>]*type\s*=\s*["']application\/ld\+json["'][^>]*>([\s\S]*?)<\/script>/gi)) {
133
+ let parsed;
134
+ try {
135
+ parsed = JSON.parse(m[1].trim());
136
+ }
137
+ catch {
138
+ continue;
139
+ }
140
+ for (const item of Array.isArray(parsed) ? parsed : [parsed]) {
141
+ const graph = item?.["@graph"];
142
+ out.push(...(Array.isArray(graph) ? graph : [item]));
143
+ }
144
+ if (out.length >= 50) {
145
+ break;
146
+ }
147
+ }
148
+ return out.slice(0, 50);
149
+ }
129
150
  /**
130
- * A page for a plugin (`server.web.read`): its whole text as Markdown and every link, as against
131
- * `readWebsite`, which picks what the assistant needs of a company's site.
151
+ * A page for a plugin (`server.web.read`): its whole text as Markdown, every link and its
152
+ * structured data, as against `readWebsite`, which picks what the assistant needs of a
153
+ * company's site.
132
154
  */
133
155
  export async function readPage(raw, signal) {
134
156
  const { res, base, html } = await loadPage(raw, signal);
@@ -148,6 +170,7 @@ export async function readPage(raw, signal) {
148
170
  description: metaOf(html, "description") || metaOf(html, "og:description"),
149
171
  text: htmlToMarkdown(html).slice(0, 400_000),
150
172
  links,
173
+ jsonld: jsonLdOf(html),
151
174
  };
152
175
  }
153
176
  export async function readWebsite(raw, signal) {
@@ -62,7 +62,8 @@ const hostAllowed = (host) => ownHosts.has(host) || loopback.test(host);
62
62
  const ticketedRun = /^\/api\/runs\/([^/]+)(\/|$)/;
63
63
  app.use("*", async (c, next) => {
64
64
  if (!managed && !hostAllowed(c.req.header("host") ?? new URL(c.req.url).host)) {
65
- return c.text("Forbidden host", 403);
65
+ // Says where it does answer: the studio opened under another name shows the way there.
66
+ return c.json({ error: "Forbidden host", code: "host", appUrl: env.appUrl }, 403);
66
67
  }
67
68
  const origin = c.req.header("origin");
68
69
  const path = c.req.path.startsWith(`${basePath}/`)
@@ -0,0 +1,26 @@
1
+ import { BROWSER_TOOL_TIMEOUT_MS } from "@engenty-wizards/shared/assistant";
2
+ const waiting = new Map();
3
+ /** The browser's answer to `callId`; a note for the model when it gives none in time. */
4
+ export function awaitBrowser(userId, callId, signal) {
5
+ return new Promise((resolve) => {
6
+ const done = (result) => {
7
+ clearTimeout(timer);
8
+ signal?.removeEventListener("abort", aborted);
9
+ waiting.delete(callId);
10
+ resolve(result);
11
+ };
12
+ const aborted = () => done({ error: "The person closed the page." });
13
+ const timer = setTimeout(() => done({ error: "The page did not answer in time; it may be closed or busy." }), BROWSER_TOOL_TIMEOUT_MS);
14
+ signal?.addEventListener("abort", aborted, { once: true });
15
+ waiting.set(callId, { userId, resolve: done });
16
+ });
17
+ }
18
+ /** Hands the browser's result to the turn that waits for it; false when none does. */
19
+ export function answerBrowser(userId, callId, result) {
20
+ const found = waiting.get(callId);
21
+ if (!found || found.userId !== userId) {
22
+ return false;
23
+ }
24
+ found.resolve(result);
25
+ return true;
26
+ }
@@ -0,0 +1,158 @@
1
+ import { existsSync, readdirSync, readFileSync } from "node:fs";
2
+ import { dirname, join, relative } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ /**
5
+ * The user guide and the plugin guide (docs/content), as the studio assistant reads them: bundled
6
+ * with each release (the build copies them to dist/docs), so an answer matches the installed
7
+ * version. Links point to engenty.ai/docs.
8
+ */
9
+ const here = dirname(fileURLToPath(import.meta.url));
10
+ const SITE = "https://engenty.ai/docs";
11
+ /** Built: dist/docs. From source: the repo's docs/content. */
12
+ function contentDir() {
13
+ for (const dir of [
14
+ join(here, "..", "docs"),
15
+ join(here, "..", "..", "..", "..", "docs", "content"),
16
+ ]) {
17
+ if (existsSync(join(dir, "user"))) {
18
+ return dir;
19
+ }
20
+ }
21
+ return null;
22
+ }
23
+ let pages = null;
24
+ function walk(dir) {
25
+ return readdirSync(dir, { withFileTypes: true }).flatMap((entry) => entry.isDirectory()
26
+ ? walk(join(dir, entry.name))
27
+ : /\.mdx?$/.test(entry.name)
28
+ ? [join(dir, entry.name)]
29
+ : []);
30
+ }
31
+ function parse(root, file) {
32
+ const raw = readFileSync(file, "utf8");
33
+ const front = raw.match(/^---\n([\s\S]*?)\n---\n?/);
34
+ const meta = Object.fromEntries((front?.[1] ?? "")
35
+ .split("\n")
36
+ .map((line) => line.match(/^(\w+):\s*(.*)$/))
37
+ .filter((m) => Boolean(m))
38
+ .map((m) => [m[1], m[2].replace(/^["']|["']$/g, "")]));
39
+ const text = raw
40
+ .slice(front?.[0].length ?? 0)
41
+ // Pictures say nothing to the assistant; their alt text stays.
42
+ .replace(/!\[([^\]]*)\]\([^)]*\)/g, "($1)")
43
+ .trim();
44
+ const id = relative(root, file)
45
+ .replace(/\\/g, "/")
46
+ .replace(/\.mdx?$/, "");
47
+ const sections = [];
48
+ let heading = meta.title ?? id;
49
+ let lines = [];
50
+ for (const line of text.split("\n")) {
51
+ const h = line.match(/^#{2,3}\s+(.*)$/);
52
+ if (h) {
53
+ if (lines.join("").trim()) {
54
+ sections.push({ heading, text: lines.join("\n").trim() });
55
+ }
56
+ heading = h[1].trim();
57
+ lines = [];
58
+ }
59
+ else {
60
+ lines.push(line);
61
+ }
62
+ }
63
+ if (lines.join("").trim()) {
64
+ sections.push({ heading, text: lines.join("\n").trim() });
65
+ }
66
+ return {
67
+ id,
68
+ title: meta.title ?? id,
69
+ description: meta.description ?? "",
70
+ url: `${SITE}/${id.replace(/\/index$/, "")}`,
71
+ text,
72
+ sections,
73
+ };
74
+ }
75
+ /** Every page of the guides; read once. */
76
+ export function docPages() {
77
+ if (!pages) {
78
+ const root = contentDir();
79
+ pages = root ? walk(root).map((file) => parse(root, file)) : [];
80
+ }
81
+ return pages;
82
+ }
83
+ const fold = (s) => s.toLowerCase().normalize("NFD").replace(/\p{M}/gu, "");
84
+ function termsOf(query) {
85
+ return [
86
+ ...new Set(fold(query)
87
+ .split(/[^\p{L}\p{N}]+/u)
88
+ .filter((w) => w.length >= 3)),
89
+ ];
90
+ }
91
+ function count(hay, term) {
92
+ let n = 0;
93
+ for (let at = hay.indexOf(term); at >= 0; at = hay.indexOf(term, at + term.length)) {
94
+ n++;
95
+ }
96
+ return n;
97
+ }
98
+ /** The sections of the guides that speak most of the query's words, best first. */
99
+ export function searchDocs(query, limit = 6) {
100
+ const terms = termsOf(query);
101
+ if (!terms.length) {
102
+ return [];
103
+ }
104
+ const hits = [];
105
+ for (const page of docPages()) {
106
+ const title = fold(`${page.title} ${page.description}`);
107
+ for (const section of page.sections) {
108
+ const heading = fold(section.heading);
109
+ const body = fold(section.text);
110
+ let score = 0;
111
+ let matched = 0;
112
+ for (const term of terms) {
113
+ const found = count(title, term) * 3 + count(heading, term) * 4 + count(body, term);
114
+ if (found) {
115
+ matched++;
116
+ score += Math.log(1 + found);
117
+ }
118
+ }
119
+ if (matched) {
120
+ hits.push({ page, heading: section.heading, text: section.text, score: score * matched });
121
+ }
122
+ }
123
+ }
124
+ return hits
125
+ .sort((a, b) => b.score - a.score)
126
+ .slice(0, limit)
127
+ .map((h) => ({
128
+ page: h.page.id,
129
+ title: h.page.title,
130
+ section: h.heading,
131
+ url: h.page.url,
132
+ excerpt: h.text.slice(0, 700),
133
+ }));
134
+ }
135
+ /** One page of the guides, from character `from` on. */
136
+ export function readDoc(id, from = 0, size = 14_000) {
137
+ const wanted = id
138
+ .replace(/^https?:\/\/[^/]+\/docs\//, "")
139
+ .replace(/^\/+|\/+$/g, "")
140
+ .replace(/\.mdx?$/, "");
141
+ const page = docPages().find((p) => p.id === wanted) ??
142
+ docPages().find((p) => p.id === `${wanted}/index`) ??
143
+ docPages().find((p) => p.id.endsWith(`/${wanted}`));
144
+ if (!page) {
145
+ return {
146
+ error: `No page "${id}".`,
147
+ pages: docPages().map((p) => `${p.id}: ${p.title}`),
148
+ };
149
+ }
150
+ const start = Math.max(0, Math.min(from, page.text.length));
151
+ return {
152
+ page: page.id,
153
+ title: page.title,
154
+ url: page.url,
155
+ text: page.text.slice(start, start + size),
156
+ next: start + size < page.text.length ? start + size : null,
157
+ };
158
+ }