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
@@ -0,0 +1,92 @@
1
+ ---
2
+ title: Quick start
3
+ description: A tool for AI steps in one file. No build, no restart.
4
+ ---
5
+
6
+ You write one file. The running app finds it, and every AI step can use the tool in it.
7
+
8
+ ## 1. Find the plugins folder
9
+
10
+ | You run | The folder |
11
+ |---|---|
12
+ | The installed app (`wizards`) | `~/.engenty/wizards/plugins` |
13
+ | A checkout (`pnpm dev`) | The folders `PLUGINS_DIR` names in `.env.local`, for example `PLUGINS_DIR=../my-plugins`. A relative path starts at the checkout's root |
14
+
15
+ Start the app. It makes the folder if it is missing and watches it while it runs.
16
+
17
+ ## 2. Write the plugin
18
+
19
+ Save this as `workdays.ts` in the plugins folder:
20
+
21
+ ```ts
22
+ import { definePlugin } from "@engenty-wizards/plugin-sdk";
23
+ import { z } from "zod";
24
+
25
+ export default definePlugin((wizards) => {
26
+ wizards.server.registerTool({
27
+ name: "count",
28
+ title: "Working days",
29
+ description:
30
+ "Counts the working days (Monday to Friday) from one date to another, both included.",
31
+ inputSchema: z.object({
32
+ from: z.string().describe("First day, YYYY-MM-DD"),
33
+ to: z.string().describe("Last day, YYYY-MM-DD"),
34
+ }),
35
+ execute: async ({ from, to }, step) => {
36
+ await step.emit("Counting working days …");
37
+ const last = new Date(`${to}T00:00:00Z`);
38
+ let workingDays = 0;
39
+ for (let day = new Date(`${from}T00:00:00Z`); day <= last; day.setUTCDate(day.getUTCDate() + 1)) {
40
+ if (day.getUTCDay() % 6 !== 0) {
41
+ workingDays += 1;
42
+ }
43
+ }
44
+ return { from, to, workingDays };
45
+ },
46
+ });
47
+ });
48
+ ```
49
+
50
+ - The file's name is the plugin's id: `workdays`.
51
+ - The tool's full id is `workdays.count`.
52
+ - `@engenty-wizards/plugin-sdk` and `zod` come from the app. Nothing to install.
53
+
54
+ ## 3. See it
55
+
56
+ The app loaded the file the moment you saved it.
57
+
58
+ - **Settings → Plugins** lists `workdays` with its tool "Working days".
59
+ - **In the editor**, open an AI step: "Working days" is in its tool list, beside "Web search"
60
+ and the other built-in tools.
61
+ - **In the conversation**, ask for it: "Add a step that counts the working days between the two
62
+ dates." The assistant knows the tool from its description.
63
+
64
+ In a wizard's definition the step lists the tool by its full id:
65
+
66
+ ```json
67
+ {
68
+ "id": "countDays",
69
+ "type": "agent",
70
+ "title": "Count the working days",
71
+ "instructions": "Count the working days from {{start}} to {{end}}.",
72
+ "tools": ["workdays.count"],
73
+ "model": "standard",
74
+ "output": { "format": "json", "fields": [{ "id": "days", "kind": "number", "description": "Working days" }] }
75
+ }
76
+ ```
77
+
78
+ ## 4. Change it
79
+
80
+ Edit the file and save. The plugin loads again; the next step that runs uses the new code.
81
+
82
+ If the file has an error, Settings → Plugins says "The server half did not load" with the
83
+ reason. Mend the file and save again.
84
+
85
+ ## Next
86
+
87
+ | To | Read |
88
+ |---|---|
89
+ | Keep data | [Tables](./tables.md) |
90
+ | React when a run ends | [Events](./events.md) |
91
+ | Show a page in the studio | [The studio half](./studio.md) |
92
+ | Give the plugin a name, a version and more than one file | [Files and manifest](./layout.md) |
@@ -0,0 +1,298 @@
1
+ ---
2
+ title: Reference
3
+ description: Every call, type, address and setting of the plugin framework on one page.
4
+ ---
5
+
6
+ ## Server half
7
+
8
+ `import { definePlugin } from "@engenty-wizards/plugin-sdk"`
9
+
10
+ `import { ThreadDoor } from "@engenty-wizards/plugin-sdk/thread"` — a wizard run in a
11
+ messenger's thread, one message at a time; a plugin brings the surface. See
12
+ [Runners](./runners.md#a-thread-door-from-the-sdk).
13
+
14
+ The default export is a `WizardsPluginFactory`: `(wizards: WizardsPluginApi) => void | Promise<void>`.
15
+
16
+ ### `wizards`
17
+
18
+ | | Type | |
19
+ |---|---|---|
20
+ | `plugin` | `PluginManifest` | The manifest |
21
+ | `server` | `PluginServerApi` | Below |
22
+ | `config.get(key)` | `string \| undefined` | A setting of the install |
23
+ | `log.info`, `log.warn`, `log.error` | `(...args) => void` | A log line with the plugin's name |
24
+ | `resolvePath(relative)` | `string` | A file of the plugin as an absolute path |
25
+
26
+ ### `wizards.server`
27
+
28
+ | Call | |
29
+ |---|---|
30
+ | `registerTool(tool: PluginTool)` | [Tools](./tools.md) |
31
+ | `registerRunner(runner: PluginRunner)` | [Runners](./runners.md). A door a wizard runs through; `page` runners answer at `/w/<token>/<id>` |
32
+ | `runs` | [Runners](./runners.md#drive-a-run). `start`, `report`, `wizards`, `answerPage`, `review`, `answerAsk`, `control`, `subscribe`, `handoffUrl`, `upload`, `transcribe`: the functions behind the MCP tools, for the plugin's door |
33
+ | `speech.conversation()` | [Runners](./runners.md#a-call). `{ provider: "openai", apiKey, model }`: the tenant's realtime speech model, for a call a plugin drives itself. Throws `503` / `no_model` while none is set up |
34
+ | `registerSpaceContext({ block, tools? })` | [The space](./space.md). `block(space): string \| null` |
35
+ | `registerAssistantTool(tool: PluginAssistantTool)` | [The space](./space.md#tools-of-the-space-assistant) |
36
+ | `index.put({ space, key, title, text, link? })`, `index.remove(space, key?)` | [The space](./space.md#the-search-index) |
37
+ | `registerHttpRoute(route: PluginRoute)` | [Routes](./routes.md) |
38
+ | `registerPublicRoute(route: PluginPublicRoute)` | [Routes](./routes.md#public-routes) |
39
+ | `publicUrl(path): Promise<string>` | The full address of a public route for the current tenant |
40
+ | `registerMigrations(folder: string)` | [Tables](./tables.md). The folder is relative to the plugin's |
41
+ | `on(event, listener)` | [Events](./events.md). `event`: `"run.done"`, `"run.failed"`, `"run.cancelled"`, `"space.created"`, `"space.updated"`, `"space.deleted"`, `"space.file.ready"`, `"space.file.removed"` |
42
+ | `every(name, everyMs, handler)` | [Jobs](./server.md#jobs). `handler({ tenantId, lastRun, signal })` |
43
+ | `web.fetch(url, init?)`, `web.read(url, { signal? })` | [The web](./server.md#the-web) |
44
+ | `documents.parse({ data, name, mime }, { signal? })` | [Documents](./server.md#documents). `{ markdown, pages }` |
45
+ | `getTenantDb(): PluginDb` | The current tenant's database, a Drizzle libSQL database |
46
+ | `generate(request): Promise<{ text, object }>` | Asks a model of the current tenant: `prompt`, `system?`, `schema?`, `model?`, `maxOutputTokens?`, `signal?`. See [The server half](./server.md#asking-a-model) |
47
+ | `connections.available(ids)`, `.start({ space, connector, actions })`, `.list(space)`, `.get(id)`, `.call(id, action, input)`, `.remove(id)` | [Accounts](./connections.md) |
48
+ | `registerAssistantContext({ block })` | [The space](./space.md#the-assistant-on-the-plugins-own-page). `block(space): string \| null` |
49
+ | `registerStarter(starter: PluginStarter)` | [Starters](./starters.md). Known as `<plugin id>.<starter id>` |
50
+ | `onUnload(fn)` | Runs when the plugin unloads or loads again |
51
+
52
+ ### `PluginTool`
53
+
54
+ ```ts
55
+ interface PluginTool<S extends z.ZodType = z.ZodType> {
56
+ name: string; // lower case, digits and "_"
57
+ title?: string; // what the editor calls it
58
+ description: string; // for the model
59
+ inputSchema: S;
60
+ execute(input: z.infer<S>, step: PluginStepContext): unknown | Promise<unknown>;
61
+ }
62
+
63
+ interface PluginStepContext {
64
+ runId: string;
65
+ stepId: string;
66
+ tenantId: string;
67
+ space: { id: string; name: string }; // the space of the step's wizard
68
+ project: { id: string; name: string }; // the same, by its older name
69
+ wizard: { id: string; title: string };
70
+ mode: "test" | "live"; // "test": a test run from the studio
71
+ signal: AbortSignal; // aborted when the run is cancelled
72
+ emit(message: string): Promise<void>; // tells the person what the step is doing
73
+ }
74
+ ```
75
+
76
+ ### `PluginRunner`
77
+
78
+ ```ts
79
+ interface PluginRunner {
80
+ id: string; // lower case, digits and "-", at most 24 characters
81
+ label: { de: string; en: string };
82
+ kind: "page" | "channel"; // an address the person opens, or a channel of its own
83
+ capabilities: {
84
+ input: string[]; // field kinds asked by the runner itself
85
+ output: { shows: string[]; pictures: string[] };
86
+ asks: ("confirm" | "login")[];
87
+ review: ("accept" | "regenerate" | "edit")[];
88
+ waits: boolean;
89
+ handoff: ("screen" | "thread" | "sms" | "push")[];
90
+ };
91
+ page?(request: PluginRunnerRequest): Response | Promise<Response>;
92
+ problem?(): string | null | Promise<string | null>; // why not usable in this tenant right now
93
+ }
94
+
95
+ interface PluginRunnerRequest {
96
+ request: Request;
97
+ tenantId: string;
98
+ wizard: { id: string; token: string; title: string };
99
+ path: string; // below /w/<token>/<id>
100
+ query: URLSearchParams;
101
+ }
102
+ ```
103
+
104
+ ### `PluginRuns`
105
+
106
+ ```ts
107
+ interface PluginRuns {
108
+ start(input: ({ token: string } | { wizardId: string }) & {
109
+ person: { channel: string; id: string };
110
+ answers?: Record<string, unknown>;
111
+ runner?: string;
112
+ }): Promise<{ runId: string; ticket: string; refused: { field: string; message: string }[] | null }>;
113
+ report(runId: string, options?: { waitSeconds?: number }): Promise<PluginRunReport>;
114
+ answerPage(runId: string, stepId: string, values: Record<string, unknown>): Promise<void>;
115
+ review(runId: string, stepId: string, action: PluginReviewAction): Promise<void>;
116
+ answerAsk(runId: string, askId: string, answer: "allow" | "skip"): Promise<void>;
117
+ control(runId: string, action: "back" | "retry" | "cancel"): Promise<void>;
118
+ subscribe(runId: string, listener: (signal: PluginRunSignal) => void): () => void;
119
+ handoffUrl(runId: string): Promise<string>;
120
+ upload(runId: string, file: { data: Uint8Array | ArrayBuffer; mime: string; name: string }): Promise<{ assetId: string }>;
121
+ }
122
+ ```
123
+
124
+ `PluginRunReport` is what `get_run` gives an MCP client: status, the step, `waitingFor` (a
125
+ page with its fields shown, a review, a question), outputs with signed links, cost,
126
+ `browserUrl`. The types carry the fields.
127
+
128
+ ### `PluginRoute`
129
+
130
+ ```ts
131
+ interface PluginRoute {
132
+ method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
133
+ path: string; // "/", "/items", "/items/:id"
134
+ role?: "member" | "admin"; // "admin": owners and admins only
135
+ handler(request: PluginRequest): unknown | Promise<unknown>;
136
+ }
137
+
138
+ interface PluginRequest {
139
+ request: Request;
140
+ path: string;
141
+ params: Record<string, string>;
142
+ query: URLSearchParams;
143
+ user: { id: string; tenantId: string; role: "owner" | "admin" | "member"; name: string; email: string };
144
+ json<T = unknown>(): Promise<T>;
145
+ }
146
+ ```
147
+
148
+ ### `PluginAssistantTool`
149
+
150
+ ```ts
151
+ interface PluginAssistantTool<S extends z.ZodType = z.ZodType> {
152
+ name: string; // lower case, digits and "_"
153
+ description: string; // for the model
154
+ inputSchema: S;
155
+ card?: boolean; // the result also goes to the chat, for the studio half's card
156
+ execute(input: z.infer<S>, turn: PluginAssistantContext): unknown | Promise<unknown>;
157
+ }
158
+
159
+ interface PluginAssistantContext {
160
+ tenantId: string;
161
+ space: { id: string; name: string };
162
+ userId: string;
163
+ signal: AbortSignal;
164
+ emit(message: string): void; // the line the chat shows
165
+ changed(): void; // the space page draws again
166
+ }
167
+ ```
168
+
169
+ ### `PluginPublicRoute`
170
+
171
+ ```ts
172
+ interface PluginPublicRoute {
173
+ method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
174
+ path: string;
175
+ handler(request: PluginPublicRequest): unknown | Promise<unknown>;
176
+ }
177
+
178
+ interface PluginPublicRequest {
179
+ request: Request;
180
+ path: string;
181
+ params: Record<string, string>;
182
+ query: URLSearchParams;
183
+ tenantId: string; // the tenant of the address; nobody is signed in
184
+ json<T = unknown>(): Promise<T>;
185
+ }
186
+ ```
187
+
188
+ ### `PluginStarter`
189
+
190
+ ```ts
191
+ interface PluginStarter {
192
+ id: string; // lower case, digits and "-"
193
+ title: string;
194
+ description: string; // what it makes, in one or two sentences
195
+ language?: "de" | "en"; // the language of its texts; default "de"
196
+ definition: unknown; // a complete wizard definition, checked when it is registered
197
+ files?: Record<string, string | Uint8Array>; // workspace files by path; a string is UTF-8
198
+ }
199
+ ```
200
+
201
+ ### `PluginRunEvent`
202
+
203
+ ```ts
204
+ interface PluginRunEvent {
205
+ run: { id: string; wizardId: string; mode: "test" | "live"; status: "done" | "failed" | "cancelled" };
206
+ wizard: { id: string; title: string; projectId: string };
207
+ values: Record<string, unknown>; // what the person answered, by field id
208
+ }
209
+ ```
210
+
211
+ ## Studio half
212
+
213
+ `import { defineStudioPlugin } from "@engenty-wizards/plugin-sdk/studio"`
214
+
215
+ The default export is a `StudioPlugin`: `(studio: StudioPluginContext) => void`.
216
+
217
+ | | |
218
+ |---|---|
219
+ | `studio.plugin` | `{ id, name, version }` |
220
+ | `studio.registerPage({ path, component, wide? })` | A page at `/studio<path>` |
221
+ | `studio.registerNav({ to, label, icon })` | An icon in the app bar. `label: () => string` |
222
+ | `studio.registerSettingsSection({ id, label, icon, component, menu? })` | A section at `/studio/settings/<id>` |
223
+ | `studio.registerAssistantCard({ tool, component })` | Draws a tool's result in the space assistant's chat. `component` gets `{ data, send }` |
224
+ | `studio.registerSpaceSection({ id, group?, label, hint?, component })` | A section of a part of the space page at `/studio/space/<group>#<id>`; `group`: `info`, `knowledge` (default), `data` or `results` |
225
+ | `studio.useCrumbs(items)` | A hook: the trail in the top bar for the page shown, `{ label, to? }[]`, instead of a heading of the page's own |
226
+ | `studio.Assistant` | Tells the studio's assistant what to say on a page of the plugin: `title?`, `hello?`, `placeholder?`, `suggestions?: { label, message?, fill? }[]`, `onChanged?`. Draws nothing |
227
+ | `studio.useAssistantPage(page)` | A hook: what the page shows, for the assistant: `open?: { kind, id?, label }`, `selection?`, `summary?`, `fields?: { id, label, value }[]`, `compact?`, and the words of `studio.Assistant` |
228
+ | `studio.useAssistantTool(name, { description, parameters? }, run)` | A hook: a tool the assistant runs in the page while it is shown, as `<plugin>_<name>`. `parameters`: JSON Schema; `run(args)` returns what the assistant learns |
229
+ | `studio.useSpace()` | A hook: `{ id, name, readOnly }` of the space the studio shows, or `null` |
230
+ | `studio.i18n.register({ de, en })` | Gives `t(key, vars?)` |
231
+ | `studio.i18n.lang()` | `"de"` or `"en"` |
232
+ | `studio.api.get`, `.post`, `.put`, `.patch`, `.del` | The plugin's own routes |
233
+ | `studio.me()` | `{ user: { id, name, email }, tenant: { id, role }, mode: "managed" \| "local" }` |
234
+ | `studio.onUnload(fn)` | Runs when the studio half loads again |
235
+
236
+ ## Ids and names
237
+
238
+ | | Rule | Example |
239
+ |---|---|---|
240
+ | Plugin id | Lower case, digits and `-`, starting with a letter, at most 40 characters | `run-log` |
241
+ | Tool name | Lower case, digits and `_`, starting with a letter, at most 40 characters | `recent` |
242
+ | Tool id in a wizard | `<plugin id>.<tool name>` | `run-log.recent` |
243
+ | Tool name for the model | The id with `_` for `.` and `-` | `run_log_recent` |
244
+ | Starter id | Lower case, digits and `-`, starting with a letter, at most 40 characters | `book` |
245
+ | Starter id in a list of templates | `<plugin id>.<starter id>` | `appointments.book` |
246
+ | Table name | Begins with the plugin's id | `run_log_entry` |
247
+ | Runner id | Lower case, digits and `-`, at most 24 characters; not `steps`, `chat` or a sub-path of a wizard's address | `kiosk` |
248
+ | Element around what a plugin draws | `data-plugin="<plugin id>"` | |
249
+
250
+ ## Addresses
251
+
252
+ All below `/api/studio/plugins`, all signed in:
253
+
254
+ | Address | | Who |
255
+ |---|---|---|
256
+ | `GET /` | The tenant's plugins: id, name, version, tools, where the built files are, what did not load | Everyone |
257
+ | `ALL /<id>/…` | The plugin's own routes | Members of a tenant that has the plugin; `role: "admin"` routes owners and admins |
258
+ | `GET /-/assets/<id>/client.js`, `/client.css` | The built studio half | Members of a tenant that has the plugin |
259
+ | `GET /-/events` | A stream that says when a plugin loaded again | A runtime that runs alone |
260
+
261
+ And public, nobody signed in: `/w/<token>/<runner>` serves a plugin's page runner for a wizard
262
+ that switched it on (built; from source `/api/public/wizards/<token>/runners/<runner>`).
263
+ | `POST /-/reload` | Loads every plugin again | Owners and admins, alone |
264
+ | `POST /-/reload/<id>` | Loads one plugin again | Owners and admins, alone |
265
+
266
+ The studio's addresses of a plugin: `/studio<path>` for its pages, `/studio/settings/<id>` for a
267
+ section.
268
+
269
+ ## Settings
270
+
271
+ In the install's `.env`:
272
+
273
+ | Setting | | Default |
274
+ |---|---|---|
275
+ | `PLUGINS_DIR` | Folders to look for plugins in, comma-separated, besides the runtime's `modules/` | Installed app: `~/.engenty/wizards/plugins`. Checkout: none |
276
+ | `PLUGINS_WATCH` | `0`: plugins do not load again when their files change | `1` where the runtime runs alone. Never as the runtime of a Manage-App |
277
+ | `PLUGINS_DEFAULT` | Runtime of a Manage-App: ids of the plugins every tenant has | none |
278
+
279
+ ## Files
280
+
281
+ | File | |
282
+ |---|---|
283
+ | `engenty.plugin.json` | The manifest: [Files and manifest](./layout.md#the-manifest) |
284
+ | `src/plugin.ts` | The server half |
285
+ | `migrations/*.sql` | Tables, where the server half registers the folder |
286
+ | `ui/plugin.tsx` | The studio half's source |
287
+ | `dist/client.js`, `dist/client.css` | The studio half, built by `node scripts/build-plugin.mjs <folder>` |
288
+
289
+ ## In the repository
290
+
291
+ | | |
292
+ |---|---|
293
+ | `packages/plugin-sdk/src/` | The types, with their comments |
294
+ | `apps/runtime/src/plugins/` | Finding, loading, tables, events |
295
+ | `apps/runtime/src/routes/plugins.ts` | The addresses above |
296
+ | `apps/web/src/plugins/` | The studio's side |
297
+ | `scripts/build-plugin.mjs` | The build of a studio half |
298
+ | `apps/runtime/test/plugins.test.ts` | Loading, routes, tools, tables per tenant, reloading |
@@ -0,0 +1,75 @@
1
+ ---
2
+ title: While it runs
3
+ description: Save a file and the plugin loads again — what reloads, what survives, and how to work on a plugin.
4
+ ---
5
+
6
+ A runtime that runs alone watches its plugins. You do not restart it while you write one.
7
+
8
+ ## What happens on a change
9
+
10
+ | You change | What happens |
11
+ |---|---|
12
+ | A file of the server half | The plugin loads again: what it registered goes, its `onUnload` functions run, its files are read anew |
13
+ | `dist/client.js`, `dist/client.css` | The open studio takes the new files in place. A page of the plugin that is open stays open |
14
+ | A file below `ui/` | Nothing, until it is built: the change counts once `dist/` changes |
15
+ | A new file or folder in a plugins folder | The runtime looks again: new plugins load, the others stay as they are |
16
+ | A plugin's file or folder is removed | That plugin unloads. Its tables stay |
17
+ | A new `.sql` file | Runs on the open tenant databases with the reload |
18
+ | An npm dependency of the plugin | Needs a restart: Node keeps a package once it was imported |
19
+ | The manifest's `id` | The plugin is gone under the old id and new under the new one |
20
+
21
+ A reload takes about as long as reading the files: well under a second.
22
+
23
+ ## What survives a reload
24
+
25
+ | | |
26
+ |---|---|
27
+ | Rows in the plugin's tables | Stay |
28
+ | Variables of the module | Start again |
29
+ | A step that is running | Keeps the tools it started with |
30
+ | Timers, sockets, watchers | Are yours to stop: `server.onUnload`, `studio.onUnload` |
31
+ | A plugin page open in the studio | Stays open, drawn by the new code |
32
+
33
+ ## A plugin that breaks
34
+
35
+ A plugin that fails when it loads again is out until its file is mended: its tools are gone and
36
+ its routes answer `404`. Settings → Plugins shows the error. Save a mended file and it is back.
37
+
38
+ ## By hand
39
+
40
+ Settings → Plugins, for owners and admins of a runtime that runs alone:
41
+
42
+ | Button | Does |
43
+ |---|---|
44
+ | Reload, on a plugin | Loads that plugin again |
45
+ | Look again | Loads every plugin again, finds new ones, drops missing ones |
46
+
47
+ `PLUGINS_WATCH=0` in the install's `.env` turns the watching off; the buttons still work.
48
+
49
+ ## Working on a plugin
50
+
51
+ A loop that needs no restart, from a checkout:
52
+
53
+ 1. Put the plugin's folder somewhere and name its parent in `PLUGINS_DIR` (`.env.local`).
54
+ 2. Start the app:
55
+
56
+ ```bash
57
+ pnpm dev
58
+ ```
59
+
60
+ 3. In a second terminal, build the studio half on every save:
61
+
62
+ ```bash
63
+ node scripts/build-plugin.mjs <plugin folder> --watch
64
+ ```
65
+
66
+ 4. Open the plugin's page in the studio and edit. The server half reloads on save; the page
67
+ updates when the build finished.
68
+
69
+ The runtime's log names the plugins it loaded at start (`plugins: contacts, workdays`) and
70
+ prints why one did not load.
71
+
72
+ ## A runtime of a Manage-App
73
+
74
+ Nothing reloads there: a reload would hit every tenant at once. A new version of a plugin comes
75
+ with a new start of the runtime. See [Shipping](./shipping.md).
@@ -0,0 +1,123 @@
1
+ ---
2
+ title: Routes
3
+ description: HTTP routes below the plugin's own address — signed in, inside the person's tenant.
4
+ ---
5
+
6
+ A plugin's routes live below `/api/studio/plugins/<id>`. Every request is a signed-in person's,
7
+ inside that person's tenant.
8
+
9
+ ```ts
10
+ // GET /api/studio/plugins/contacts/
11
+ server.registerHttpRoute({
12
+ method: "GET",
13
+ path: "/",
14
+ handler: async () => ({
15
+ contacts: await db().select().from(person).orderBy(desc(person.seenAt)).limit(200),
16
+ }),
17
+ });
18
+
19
+ // DELETE /api/studio/plugins/contacts/42
20
+ server.registerHttpRoute({
21
+ method: "DELETE",
22
+ path: "/:id",
23
+ role: "admin",
24
+ handler: async ({ params }) => {
25
+ const [gone] = await db()
26
+ .delete(person)
27
+ .where(eq(person.id, Number(params.id)))
28
+ .returning();
29
+ if (!gone) {
30
+ throw Object.assign(new Error("No such contact."), { status: 404, code: "no_contact" });
31
+ }
32
+ return { ok: true };
33
+ },
34
+ });
35
+ ```
36
+
37
+ | Field | |
38
+ |---|---|
39
+ | `method` | `GET`, `POST`, `PUT`, `PATCH` or `DELETE` |
40
+ | `path` | `/`, `/items`, `/items/:id`. A `:name` part matches one segment |
41
+ | `role` | `"admin"`: owners and admins only; others get `403`. Default: every member of the tenant |
42
+ | `handler(request)` | Answers with a value, sent as JSON, or with a `Response` |
43
+
44
+ ## The request
45
+
46
+ | | |
47
+ |---|---|
48
+ | `request.params` | What the `:name` parts matched |
49
+ | `request.query` | The query string, as `URLSearchParams` |
50
+ | `request.json()` | The body as JSON. An empty body is `{}` |
51
+ | `request.user` | `{ id, tenantId, role, name, email }`: the signed-in person. `role` is `owner`, `admin` or `member` |
52
+ | `request.path` | The address below the plugin's own |
53
+ | `request.request` | The web `Request` as it came in: headers, a body that is not JSON |
54
+
55
+ ## The answer
56
+
57
+ | The handler | The client gets |
58
+ |---|---|
59
+ | Returns a value | `200` with the value as JSON. `undefined` becomes `null` |
60
+ | Returns a `Response` | That response: a file, a redirect, another status |
61
+ | Throws an error with a `status` and a `code` | That status with `{ "error": "<message>", "code": "<code>" }` |
62
+ | Throws anything else | `500` with `{ "error": "The plugin failed.", "code": "plugin_failed" }`. The error itself is logged, not sent |
63
+
64
+ Send a `code`, not a sentence for the person. The studio half says it in the person's language:
65
+
66
+ ```ts
67
+ throw Object.assign(new Error("No such contact."), { status: 404, code: "no_contact" });
68
+ ```
69
+
70
+ ## Who can call a route
71
+
72
+ - Only the studio, signed in. A request without a session gets `401` before it reaches the
73
+ plugin.
74
+ - Only people of a tenant that has the plugin. For any other tenant the address answers `404`.
75
+ - Not the people who run a wizard on its link, and not the outside world. For a webhook of
76
+ another service, a plugin has [public routes](#public-routes).
77
+
78
+ ## Public routes
79
+
80
+ A public route answers anyone: a CMS that says a page changed, another service's webhook. Its
81
+ address names the tenant without giving its id away; the plugin hands it out:
82
+
83
+ ```ts
84
+ server.registerPublicRoute({
85
+ method: "POST",
86
+ path: "/signal/:token",
87
+ handler: async ({ params, tenantId, json }) => {
88
+ const source = await sourceByToken(params.token);
89
+ if (!source) {
90
+ throw Object.assign(new Error("Unknown."), { status: 404, code: "unknown" });
91
+ }
92
+ await refreshSoon(source, await json());
93
+ return { ok: true };
94
+ },
95
+ });
96
+
97
+ // In a route of the studio: the address to paste into the CMS.
98
+ const address = await server.publicUrl(`/signal/${source.token}`);
99
+ // https://…/api/public/plugins/<id>/<ref>/signal/<token>
100
+ ```
101
+
102
+ - Nobody is signed in. Check a secret of your own: a token in the address, a signature of the
103
+ body. Keep only a hash of it.
104
+ - The handler runs inside the tenant of the address: `server.getTenantDb()` is its database.
105
+ - `publicUrl` gives the same address for a tenant every time.
106
+ - A body is taken up to 4 MB. Answers and errors work as for the plugin's other routes.
107
+ - A tenant without the plugin, or a suspended one, answers `404`.
108
+
109
+ ## From the studio half
110
+
111
+ `studio.api` calls the plugin's own routes and gives the parsed JSON:
112
+
113
+ ```ts
114
+ const { contacts } = await studio.api.get<{ contacts: Person[] }>("/");
115
+ await studio.api.del(`/${id}`);
116
+ ```
117
+
118
+ See [The studio half](./studio.md#the-plugins-own-routes).
119
+
120
+ ## Addresses that are taken
121
+
122
+ `/api/studio/plugins/-/…` is the runtime's own part: the built files, reloading. No plugin is
123
+ called `-`, so the two never meet.