wizards 0.2.46 → 0.2.48

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 (130) hide show
  1. package/apps/runtime/dist/agents/{project-assistant.js → studio-assistant.js} +199 -69
  2. package/apps/runtime/dist/agents/website.js +25 -2
  3. package/apps/runtime/dist/app.js +5 -1
  4. package/apps/runtime/dist/assistant/browser.js +26 -0
  5. package/apps/runtime/dist/assistant/docs.js +158 -0
  6. package/apps/runtime/dist/assistant/knows.js +325 -0
  7. package/apps/runtime/dist/assistant/primer.js +26 -0
  8. package/apps/runtime/dist/authoring/guide.js +5 -0
  9. package/apps/runtime/dist/cli/features.js +50 -0
  10. package/apps/runtime/dist/cli/main.js +4 -1
  11. package/apps/runtime/dist/connectors/plugin-connections.js +123 -29
  12. package/apps/runtime/dist/db/migrations/tenant/0012_assistant_chat.sql +40 -0
  13. package/apps/runtime/dist/db/migrations/tenant/meta/0012_snapshot.json +3132 -0
  14. package/apps/runtime/dist/db/migrations/tenant/meta/_journal.json +7 -0
  15. package/apps/runtime/dist/db/schema.js +30 -0
  16. package/apps/runtime/dist/docs/dev/index.md +34 -0
  17. package/apps/runtime/dist/docs/dev/meta.json +7 -0
  18. package/apps/runtime/dist/docs/dev/plugins/connections.md +70 -0
  19. package/apps/runtime/dist/docs/dev/plugins/events.md +86 -0
  20. package/apps/runtime/dist/docs/dev/plugins/examples.md +99 -0
  21. package/apps/runtime/dist/docs/dev/plugins/index.md +72 -0
  22. package/apps/runtime/dist/docs/dev/plugins/layout.md +88 -0
  23. package/apps/runtime/dist/docs/dev/plugins/meta.json +29 -0
  24. package/apps/runtime/dist/docs/dev/plugins/pro-modules.md +59 -0
  25. package/apps/runtime/dist/docs/dev/plugins/quick-start.md +92 -0
  26. package/apps/runtime/dist/docs/dev/plugins/reference.md +298 -0
  27. package/apps/runtime/dist/docs/dev/plugins/reloading.md +75 -0
  28. package/apps/runtime/dist/docs/dev/plugins/routes.md +123 -0
  29. package/apps/runtime/dist/docs/dev/plugins/runners.md +184 -0
  30. package/apps/runtime/dist/docs/dev/plugins/server.md +191 -0
  31. package/apps/runtime/dist/docs/dev/plugins/shipping.md +98 -0
  32. package/apps/runtime/dist/docs/dev/plugins/space.md +260 -0
  33. package/apps/runtime/dist/docs/dev/plugins/starters.md +62 -0
  34. package/apps/runtime/dist/docs/dev/plugins/studio.md +261 -0
  35. package/apps/runtime/dist/docs/dev/plugins/styling.md +109 -0
  36. package/apps/runtime/dist/docs/dev/plugins/tables.md +102 -0
  37. package/apps/runtime/dist/docs/dev/plugins/tools.md +128 -0
  38. package/apps/runtime/dist/docs/meta.json +3 -0
  39. package/apps/runtime/dist/docs/user/ai-apps.md +99 -0
  40. package/apps/runtime/dist/docs/user/assistant.md +52 -0
  41. package/apps/runtime/dist/docs/user/build-a-wizard.md +79 -0
  42. package/apps/runtime/dist/docs/user/command-line.md +76 -0
  43. package/apps/runtime/dist/docs/user/connectors.md +80 -0
  44. package/apps/runtime/dist/docs/user/data.md +61 -0
  45. package/apps/runtime/dist/docs/user/first-start.md +42 -0
  46. package/apps/runtime/dist/docs/user/index.md +45 -0
  47. package/apps/runtime/dist/docs/user/install.md +76 -0
  48. package/apps/runtime/dist/docs/user/meta.json +29 -0
  49. package/apps/runtime/dist/docs/user/models.md +100 -0
  50. package/apps/runtime/dist/docs/user/plugins.md +61 -0
  51. package/apps/runtime/dist/docs/user/run.md +92 -0
  52. package/apps/runtime/dist/docs/user/server.md +50 -0
  53. package/apps/runtime/dist/docs/user/space.md +97 -0
  54. package/apps/runtime/dist/docs/user/steps.md +196 -0
  55. package/apps/runtime/dist/docs/user/test-and-share.md +210 -0
  56. package/apps/runtime/dist/docs/user/troubleshooting.md +57 -0
  57. package/apps/runtime/dist/engine/runner.js +12 -5
  58. package/apps/runtime/dist/features.js +123 -0
  59. package/apps/runtime/dist/manage.js +24 -0
  60. package/apps/runtime/dist/plugins/discovery.js +11 -0
  61. package/apps/runtime/dist/plugins/loader.js +12 -0
  62. package/apps/runtime/dist/routes/internal.js +3 -0
  63. package/apps/runtime/dist/routes/studio.js +126 -73
  64. package/apps/runtime/dist/services/assistant-chats.js +267 -0
  65. package/apps/runtime/dist/services/project-index.js +1 -1
  66. package/apps/runtime/dist/services/space-origin.js +45 -2
  67. package/apps/web/dist/assets/{AboutDialog-DkY1j7k6.js → AboutDialog-CuiVGknS.js} +1 -1
  68. package/apps/web/dist/assets/{ChangelogDialog-820LI5Jt.js → ChangelogDialog-DCEQD3Jd.js} +1 -1
  69. package/apps/web/dist/assets/ChatView-DFxrG2PD.js +10 -0
  70. package/apps/web/dist/assets/EditorPage-B5rzKNMy.js +3 -0
  71. package/apps/web/dist/assets/{FlowPreview-ChXfiMn_.js → FlowPreview-CYoR5DRY.js} +1 -1
  72. package/apps/web/dist/assets/{Harness-CfUfchNw.js → Harness-DAR1u4Dk.js} +1 -1
  73. package/apps/web/dist/assets/HomePage-BnYdh_Nx.js +1 -0
  74. package/apps/web/dist/assets/Marketplace-BDQNwMDB.js +2 -0
  75. package/apps/web/dist/assets/{NewWizardPage-C3NqEGmg.js → NewWizardPage-DztTEUlG.js} +1 -1
  76. package/apps/web/dist/assets/ProjectPage-B7-Lqx9a.js +2 -0
  77. package/apps/web/dist/assets/PublicRunner-CaH3bHHd.js +1 -0
  78. package/apps/web/dist/assets/{ReadOnly-C9P9aiU6.js → ReadOnly-DnB47DQC.js} +1 -1
  79. package/apps/web/dist/assets/RunDrawer-Dv0KRqGA.js +4 -0
  80. package/apps/web/dist/assets/RunnerView-Bzwv1u4j.js +2 -0
  81. package/apps/web/dist/assets/SettingsPage-oVO7CKvc.js +1 -0
  82. package/apps/web/dist/assets/SetupPage-D--8cWA0.js +1 -0
  83. package/apps/web/dist/assets/{SharePage-D5AvnhlY.js → SharePage-DjU08q7T.js} +1 -1
  84. package/apps/web/dist/assets/ThemeSwitch-C3EJRN06.js +1 -0
  85. package/apps/web/dist/assets/arrow-right-F7X_SjK9.js +1 -0
  86. package/apps/web/dist/assets/changelog-BRoVI_JJ.js +1 -0
  87. package/apps/web/dist/assets/{circle-alert-CPo3Naay.js → circle-alert-DdpaAYgd.js} +1 -1
  88. package/apps/web/dist/assets/{definition-CQGiBQ4X.js → definition-CHacJYmI.js} +2 -2
  89. package/apps/web/dist/assets/{external-link-CpU8aJY2.js → external-link-Dfc1VFvS.js} +1 -1
  90. package/apps/web/dist/assets/index-CX_yxZVQ.js +79 -0
  91. package/apps/web/dist/assets/index-Dr0bv52Q.css +1 -0
  92. package/apps/web/dist/assets/{lock-C_WlXIQ0.js → lock-Bu1wDFs8.js} +1 -1
  93. package/apps/web/dist/assets/{refresh-cw-Cli5WGnW.js → refresh-cw-BUDPOT39.js} +1 -1
  94. package/apps/web/dist/assets/{session-miDEdw2c.js → session-Blj2os_v.js} +1 -1
  95. package/apps/web/dist/assets/{settings-menu-ROT8Lbbj.js → settings-menu-BvxRnNtf.js} +1 -1
  96. package/apps/web/dist/assets/{sparkles-CP5H-O1E.js → sparkles-DWGJluyV.js} +1 -1
  97. package/apps/web/dist/assets/{trash-DU-hZpV0.js → trash-D9UB6TtS.js} +1 -1
  98. package/apps/web/dist/assets/ui-GsuU9WTj.js +9 -0
  99. package/apps/web/dist/assets/{upload-DMq5N6Fw.js → upload-BngimDBR.js} +1 -1
  100. package/apps/web/dist/assets/{volume-2-0SfkvOho.js → volume-2-BZju_bOP.js} +1 -1
  101. package/apps/web/dist/index.html +11 -11
  102. package/apps/web/dist/mcp/flow.html +51 -51
  103. package/node_modules/@engenty-wizards/plugin-sdk/dist/index.d.ts +103 -7
  104. package/node_modules/@engenty-wizards/plugin-sdk/dist/studio.d.ts +58 -4
  105. package/node_modules/@engenty-wizards/shared/dist/assistant.d.ts +113 -0
  106. package/node_modules/@engenty-wizards/shared/dist/assistant.js +55 -0
  107. package/node_modules/@engenty-wizards/shared/dist/definition.d.ts +56 -1
  108. package/node_modules/@engenty-wizards/shared/dist/definition.js +94 -4
  109. package/node_modules/@engenty-wizards/shared/dist/feature-flags.d.ts +54 -0
  110. package/node_modules/@engenty-wizards/shared/dist/feature-flags.js +46 -0
  111. package/node_modules/@engenty-wizards/shared/dist/features.d.ts +36 -0
  112. package/node_modules/@engenty-wizards/shared/dist/features.js +78 -0
  113. package/node_modules/@engenty-wizards/shared/dist/run.d.ts +3 -1
  114. package/package.json +1 -1
  115. package/apps/web/dist/assets/ChatView-DBl0iRMg.js +0 -10
  116. package/apps/web/dist/assets/EditorPage-BwJ-hqPg.js +0 -3
  117. package/apps/web/dist/assets/HomePage-BG5OZJkv.js +0 -1
  118. package/apps/web/dist/assets/Marketplace-BWhUJ4UX.js +0 -2
  119. package/apps/web/dist/assets/ProjectPage-Btf0TeP_.js +0 -2
  120. package/apps/web/dist/assets/PublicRunner-BxYinn04.js +0 -1
  121. package/apps/web/dist/assets/RunDrawer-DfnEMPTq.js +0 -4
  122. package/apps/web/dist/assets/RunnerView-CLrGb-oq.js +0 -2
  123. package/apps/web/dist/assets/SettingsPage-FWH84btd.js +0 -1
  124. package/apps/web/dist/assets/SetupPage-BI0kUNVW.js +0 -1
  125. package/apps/web/dist/assets/ThemeSwitch-C1qYFoYP.js +0 -1
  126. package/apps/web/dist/assets/arrow-right-Dpp_mpHe.js +0 -1
  127. package/apps/web/dist/assets/changelog-B6QMrVxX.js +0 -1
  128. package/apps/web/dist/assets/index-CIO9W4pe.js +0 -78
  129. package/apps/web/dist/assets/index-DKHClEy3.css +0 -1
  130. package/apps/web/dist/assets/ui-D92EkdEB.js +0 -9
@@ -0,0 +1,184 @@
1
+ ---
2
+ title: Runners
3
+ description: A door a wizard runs through, beside the page and the chat — a call, a messenger, a kiosk — and the run API that drives runs from it.
4
+ ---
5
+
6
+ A runner is a way to run a wizard. The runtime has two: the stepped page at `/w/<token>` and
7
+ the chat at `/w/<token>/chat`. A plugin adds more. The owner switches them on per wizard in
8
+ the share dialog; the link opens the default, the others answer under their own address or
9
+ from their own channel.
10
+
11
+ ## Register a runner
12
+
13
+ ```ts
14
+ server.registerRunner({
15
+ id: "kiosk",
16
+ label: { de: "Kiosk", en: "Kiosk" },
17
+ kind: "page",
18
+ capabilities: {
19
+ input: ["text", "select", "multiselect", "toggle", "number", "date"],
20
+ output: { shows: ["text", "image"], pictures: ["dashboard", "widget"] },
21
+ asks: ["confirm"],
22
+ review: ["accept", "regenerate"],
23
+ waits: true,
24
+ handoff: ["screen"],
25
+ },
26
+ page: ({ wizard, path, query }) => new Response(renderKiosk(wizard, path, query)),
27
+ });
28
+ ```
29
+
30
+ | | |
31
+ |---|---|
32
+ | `id` | Lower case, digits and `-`, at most 24 characters. The sub-path of the wizard's address |
33
+ | `kind` | `page`: the person opens an address. `channel`: the runner has an address of its own (a number, a bot) and drives runs from its webhooks |
34
+ | `capabilities` | What the runner takes in and shows; see below |
35
+ | `page` | A page runner's handler: what `/w/<token>/<id>` answers with. Nobody is signed in |
36
+ | `problem` | `() => string \| null`, may be async: why the runner cannot be used in the current tenant right now ("Not connected: Settings → WhatsApp"), asked inside the tenant whenever the studio lists the runners. With a problem the owner cannot switch it on |
37
+
38
+ A page runner is served at `/w/<token>/<id>` for every wizard that switched it on. From
39
+ source, where Vite serves the pages, the same handler answers at
40
+ `/api/public/wizards/<token>/runners/<id>`; the public wizard's `runners` list carries the
41
+ right address either way.
42
+
43
+ ### Capabilities
44
+
45
+ The runner declares; the runtime works out per wizard how far it gets, and the editor shows it:
46
+ everything in the channel, hands off to the page at these steps, or not possible.
47
+
48
+ | Field | Says |
49
+ |---|---|
50
+ | `input` | The field kinds the runner asks itself. Any other field hands off to the run page |
51
+ | `output.shows` | What it shows as it is: `text`, `data`, `image`, `video`, `voice`, `document`, `dashboard`, `widget`, `film`, `surface` |
52
+ | `output.pictures` | What it shows as a picture with a link to the real thing. Anything else is a link |
53
+ | `asks` | `confirm` for a running step that asks before it changes something; `login` only where a browser types the sign-in |
54
+ | `review` | `accept`, `regenerate`, `edit` |
55
+ | `waits` | Whether it stays through a step that takes minutes. A runner that cannot gets "not possible" for such wizards |
56
+ | `handoff` | How a link to the run page reaches the person: `screen`, `thread`, `sms`, `push`. A runner with none cannot hand off |
57
+
58
+ ## Drive a run
59
+
60
+ `server.runs` holds the functions behind the MCP tools, for the plugin's own door. A run
61
+ started here is a live run of the published wizard for a person of that door.
62
+
63
+ ```ts
64
+ server.registerPublicRoute({
65
+ method: "POST",
66
+ path: "/call/:token",
67
+ handler: async ({ params, json }) => {
68
+ const { from, said } = await json<{ from: string; said: string }>();
69
+ const { runId, ticket, refused } = await server.runs.start({
70
+ token: params.token,
71
+ person: { channel: "phone", id: from },
72
+ answers: { name: said },
73
+ });
74
+ const report = await server.runs.report(runId, { waitSeconds: 20 });
75
+ if (report.waitingFor && "page" in report.waitingFor) {
76
+ // Ask the next field; fields with inChat=false need the run page.
77
+ const link = await server.runs.handoffUrl(runId);
78
+ }
79
+ return { runId, ticket, refused, report };
80
+ },
81
+ });
82
+ ```
83
+
84
+ | Call | |
85
+ |---|---|
86
+ | `runs.start({ token \| wizardId, person, answers?, runner? })` | Starts a live run. `person` names who it is for on the door; the runtime keeps a hash of it as the run's visitor, so what the wizard remembers is theirs on the run page too. `answers` fills the first page; what did not fit comes back as `refused`. Gives the run's ticket |
87
+ | `runs.report(runId, { waitSeconds?, draft? })` | The run as it stands: `lang`, `waitingFor` (a page with the fields shown and what they know, a review, a question), outputs with signed links and a `picture` (a PNG of a document, a dashboard or a widget), cost, `browserUrl`. Waits up to 45 seconds while the run works. A door that asks a page one field at a time passes what it has as `draft`: a field's `shown` then follows those answers, as the form on the screen does |
88
+ | `runs.wizards(runner)` | The published wizards of the tenant that switched the runner on: what the door offers, with `token`, `title` and `lang` |
89
+ | `runs.answerPage(runId, stepId, values)` | Fills the page the run waits for |
90
+ | `runs.review(runId, stepId, action)` | Accepts a review, or asks for one of the shown steps again with a note |
91
+ | `runs.answerAsk(runId, askId, "allow" \| "skip")` | Answers a running step's question. A sign-in cannot be answered here: hand off |
92
+ | `runs.control(runId, "back" \| "retry" \| "cancel")` | |
93
+ | `runs.subscribe(runId, listener)` | Hears every change of the run: its events with their note in both languages, or a status change. Returns the function that stops it |
94
+ | `runs.handoffUrl(runId)` | The run page with the run's ticket: the link to send for what the door cannot do. The person who opens it and the door's person are one to the wizard |
95
+ | `runs.upload(runId, { data, mime, name })` | A file of the person; the asset id goes into an image or file field with `answerPage` |
96
+ | `runs.transcribe(runId, { data, mime })` | What is said in a recording of the person (a voice message), written down with the tenant's listener and charged to the run |
97
+
98
+ A refused command throws an error with `code` (`invalid`, `refused`, `no_credits`) and the
99
+ fields that did not fit, which a route passes on as it is.
100
+
101
+ ## What the person sees
102
+
103
+ - The wizard's first page offers the runners that are on beside "Let's go".
104
+ - A hand-off is a link to the same run; nothing is asked twice. The run page knows the
105
+ door's person through the run, and "What this wizard remembers" is theirs there too.
106
+ - The space's results carry the door a run came through.
107
+
108
+ ## The runner's part of the share dialog
109
+
110
+ A channel has something to show per wizard: the keyword that starts it, the number, a link with
111
+ its QR code. The studio half registers it, and the share dialog draws it under the runner's row
112
+ once the owner switched the runner on:
113
+
114
+ ```tsx
115
+ studio.registerShareSection({ runner: "whatsapp", component: ShareSection });
116
+
117
+ function ShareSection({ wizard }: StudioShareSectionProps) {
118
+ // wizard: { id, title }; the plugin's own routes hold the rest.
119
+ }
120
+ ```
121
+
122
+ One section per runner. The settings a channel needs once per tenant (the number, the token)
123
+ go into a [settings section](./studio.md).
124
+
125
+ ## A thread door from the SDK
126
+
127
+ A messenger runs a wizard one message at a time: a field per question, options to tap or to
128
+ number, a link to the screen for what the thread cannot take, the result as pictures and links.
129
+ That conversation is the same on every messenger; the SDK holds it, and a plugin brings the
130
+ surface: how a question is drawn there, how a file is fetched.
131
+
132
+ ```ts
133
+ import { ThreadDoor, type ThreadSurface } from "@engenty-wizards/plugin-sdk/thread";
134
+
135
+ const surface: ThreadSurface = {
136
+ runner: "sms",
137
+ asks: ["text", "number", "select", "multiselect", "toggle", "date", "email", "url", "location"],
138
+ async send(thread, prompt) {
139
+ // prompt.kind: "text" | "choice" | "location" | "link" | "media" — draw it as the channel allows.
140
+ await twilio.send(thread.id, toText(prompt, thread.state.lang));
141
+ },
142
+ };
143
+
144
+ const door = new ThreadDoor({ runs: server.runs, surface, offered, watch, unwatch, log });
145
+ // A webhook: door.inbound(thread, message). A run that changed: door.resume(thread).
146
+ ```
147
+
148
+ | | |
149
+ |---|---|
150
+ | `ThreadSurface.asks` | The field kinds the thread asks itself; a page with any other field goes to the screen as a link |
151
+ | `send(thread, prompt)` | A `choice` is drawn as buttons, a list or numbered lines; a typed number or title counts as a tap, the door works that out. `link` and `media` carry a URL |
152
+ | `media(ref)` | A file the person sent, by what the webhook named; without it files hand off |
153
+ | `mayDeliver`, `reach` | A messenger with a window (WhatsApp's 24 hours): whether a free message may go out now, and the link by other means when not |
154
+ | `offered()` | The wizards switched on for the runner (`runs.wizards`) with their keywords; a keyword in the thread starts its wizard, else the door offers the menu |
155
+ | `watch(thread)`, `unwatch(runId)` | Hear the run (`runs.subscribe`) and call `door.resume` when it moves; the plugin keeps the subscriptions |
156
+ | `Thread` | `{ id, name, runId, state, lastInboundAt, lastMessageId }`: the plugin keeps it in a table per person and hands it to the door before and after |
157
+
158
+ The WhatsApp module in `modules/whatsapp` and the SMS module in `modules/sms` are two surfaces
159
+ of this door: the webhook on a public route, the keyword table, the number in the settings and
160
+ the keyword in the share dialog are theirs; buttons and lists, the location request and files
161
+ through the Cloud API are WhatsApp's surface, numbered lines and links are SMS's.
162
+
163
+ ## A call
164
+
165
+ A call has no thread and no screen: the person and a realtime speech model talk, and the
166
+ model fills the run through tools, as the chat's live voice does in the browser. The runtime
167
+ hands a plugin the tenant's speech model for it:
168
+
169
+ ```ts
170
+ const { apiKey, model } = await server.speech.conversation();
171
+ // Throws with the status 503 and the code `no_model` while no OpenAI key is set under Models.
172
+ ```
173
+
174
+ The calls module in `modules/calls` is the whole of it: Twilio carries the call (a WhatsApp
175
+ call arrives over Meta's SIP on a Twilio SIP domain, a phone call on a Twilio number) and asks
176
+ the plugin for TwiML, which hands the call to the tenant's OpenAI project over SIP with a token
177
+ in a header; OpenAI posts the incoming call to the plugin's public route, the plugin accepts it
178
+ with the wizard's rules and tools and answers the model's tool calls over a WebSocket, driving
179
+ the run with `server.runs`. The audio never touches the runtime. What a voice cannot take is
180
+ texted as a link.
181
+
182
+ ## Not there yet
183
+
184
+ - An event when a wizard is published, for a runner that prepares something per wizard.
@@ -0,0 +1,191 @@
1
+ ---
2
+ title: The server half
3
+ description: The function a plugin exports, what it is handed, and the rules it runs under.
4
+ ---
5
+
6
+ The server half is a file whose default export is a function. The runtime calls it once when the
7
+ plugin loads and hands it `wizards`. The function registers what the plugin adds.
8
+
9
+ ```ts
10
+ import { definePlugin } from "@engenty-wizards/plugin-sdk";
11
+
12
+ export default definePlugin((wizards) => {
13
+ const { server } = wizards;
14
+
15
+ server.registerMigrations("migrations");
16
+ server.registerHttpRoute({ method: "GET", path: "/", handler: async () => ({ ok: true }) });
17
+ server.registerTool({ /* … */ });
18
+ server.on("run.done", async (event) => { /* … */ });
19
+ });
20
+ ```
21
+
22
+ `definePlugin` only types the function. The function may be `async`.
23
+
24
+ ## What it is handed
25
+
26
+ | | |
27
+ |---|---|
28
+ | `wizards.server` | Registers tools, routes, tables and listeners. See the table below |
29
+ | `wizards.plugin` | The manifest: `id`, `name`, `version` and whatever else it holds |
30
+ | `wizards.config.get(key)` | A setting of the install: a line of its `.env`. Empty and missing are both `undefined` |
31
+ | `wizards.log.info`, `.warn`, `.error` | A log line with the plugin's name in front |
32
+ | `wizards.resolvePath(relative)` | A file of the plugin as an absolute path |
33
+
34
+ | `wizards.server.` | Does | Page |
35
+ |---|---|---|
36
+ | `registerTool(tool)` | A tool for AI steps | [Tools](./tools.md) |
37
+ | `registerSpaceContext(context)` | A block and tools for every AI step of a space | [The space](./space.md) |
38
+ | `registerAssistantTool(tool)` | A tool of the space assistant | [The space](./space.md#tools-of-the-space-assistant) |
39
+ | `spaceData.putPage(input)`, `putTable`, `putFile`, `putDocument`, `putCategories`, … | Wissen of a space: pages, tables, files and Kategorien | [The space](./space.md#wissen-a-plugin-writes) |
40
+ | `index.put(entry)`, `index.remove(space, key?)` | Texts in the space's search index | [The space](./space.md#the-search-index) |
41
+ | `registerHttpRoute(route)` | A route below `/api/studio/plugins/<id>` | [Routes](./routes.md) |
42
+ | `registerPublicRoute(route)`, `publicUrl(path)` | A route anyone may call, and its address | [Routes](./routes.md#public-routes) |
43
+ | `registerMigrations(folder)` | `.sql` files with the plugin's tables | [Tables](./tables.md) |
44
+ | `on(event, listener)` | Called when a run ends or a space changes | [Events](./events.md) |
45
+ | `connections.start(…)`, `list`, `call`, … | Accounts of a space, through the built-in connectors | [Accounts](./connections.md) |
46
+ | `every(name, everyMs, handler)` | A job, again and again | below |
47
+ | `web.fetch(url, init?)`, `web.read(url)` | Requests to the web, guarded | below |
48
+ | `documents.parse(file)` | A file as Markdown | below |
49
+ | `getTenantDb()` | The database of the tenant the current request, step or event belongs to | [Tables](./tables.md) |
50
+ | `generate(request)` | Asks a model of the current tenant | below |
51
+ | `onUnload(fn)` | Something to undo when the plugin unloads | below |
52
+
53
+ ## Settings
54
+
55
+ Name a plugin's settings after the plugin and read them when the plugin loads:
56
+
57
+ ```ts
58
+ const url = wizards.config.get("NOTIFY_URL");
59
+ if (!url) {
60
+ wizards.log.warn("NOTIFY_URL is not set: nothing will be sent.");
61
+ return;
62
+ }
63
+ ```
64
+
65
+ The person sets them in the install's `.env` and restarts. There is no settings page a plugin
66
+ gets for free: a plugin that wants one adds a [settings section](./studio.md) and keeps the
67
+ values in a [table](./tables.md).
68
+
69
+ ## Tenants
70
+
71
+ A runtime serves one tenant on a person's computer and many as the runtime of a Manage-App.
72
+ Either way a plugin never names a tenant:
73
+
74
+ - A route, a tool and a listener each run inside one tenant.
75
+ - `server.getTenantDb()` is that tenant's database. Call it where you use it, not once at load
76
+ time: at load time there is no tenant.
77
+ - State kept in a variable of the module is shared by all tenants. Keep per-tenant state in a
78
+ table.
79
+
80
+ ## Asking a model
81
+
82
+ `server.generate` asks one of the tenant's models, the same ones its wizards run on, and is paid
83
+ like any other of its calls. With a `schema` the answer is an object of that shape:
84
+
85
+ ```ts
86
+ const { object } = await server.generate({
87
+ model: "classifier",
88
+ system: "You sort support mails.",
89
+ prompt: `Which team does this mail go to?\n\n${mail}`,
90
+ schema: z.object({ team: z.enum(["sales", "support", "billing"]) }),
91
+ });
92
+ ```
93
+
94
+ | Field | | Default |
95
+ |---|---|---|
96
+ | `prompt` | What the model is asked | required |
97
+ | `system` | How it should answer | |
98
+ | `schema` | A zod schema: `object` is the answer in that shape | text only |
99
+ | `model` | `classifier` (fast, cheap), `standard`, `high`, `highest` | `standard` |
100
+ | `maxOutputTokens` | A limit on the answer | the model's |
101
+ | `signal` | Aborts the call | two minutes |
102
+
103
+ It answers `{ text, object }`. Without a model set up it throws an error with the status `503`
104
+ and the code `no_model`: a route that lets it through answers just that, and the studio half
105
+ says it in the person's language.
106
+
107
+ ## Jobs
108
+
109
+ ```ts
110
+ server.every("refresh", 60 * 60_000, async ({ tenantId, lastRun, signal }) => {
111
+ for (const source of await dueSources()) {
112
+ await refresh(source, signal);
113
+ }
114
+ });
115
+ ```
116
+
117
+ - The handler runs for every tenant that has the plugin, inside that tenant, at most once per
118
+ `everyMs`. A minute is the least.
119
+ - When it ran is kept: a restart does not start the count again. A runtime that was off runs a
120
+ due job once when it starts, not once per turn it missed. A local install runs jobs while it
121
+ runs.
122
+ - One turn per tenant at a time. A turn that throws is logged and counts as run.
123
+ - `lastRun` is when the turn before started; `null` the first time. `signal` is aborted
124
+ when the plugin unloads.
125
+ - `PLUGIN_JOBS=0` keeps a runtime from running jobs, for one whose jobs another process runs.
126
+
127
+ ## The web
128
+
129
+ ```ts
130
+ const page = await server.web.read("https://example.com/preise");
131
+ // { url, status, etag, lastModified, title, description, text, links, jsonld }
132
+
133
+ const res = await server.web.fetch(`${origin}/sitemap.xml`, {
134
+ headers: { "if-none-match": source.etag ?? "" },
135
+ });
136
+ ```
137
+
138
+ - Both refuse addresses of this machine and of the local network, after a redirect too, as the
139
+ runtime's own requests do.
140
+ - `read` gives the page's text as Markdown and every link, absolute and each once. A page with
141
+ hardly any text without its scripts is drawn in a browser first. `etag` and
142
+ `lastModified` are what the server sent, for asking later whether the page changed. `jsonld`
143
+ is the page's structured data (its `application/ld+json` blocks, parsed): a shop's product
144
+ page says title, price, availability and image there exactly, without a model.
145
+ - `fetch` is `fetch` behind the guard: for a sitemap, `robots.txt`, a question with
146
+ `if-none-match`.
147
+
148
+ ## Keys of the plugin's own
149
+
150
+ A plugin that talks to a shop or a service with keys the person typed keeps them sealed, as the
151
+ runtime seals a connection's tokens:
152
+
153
+ ```ts
154
+ await db().update(store).set({ credentials: server.secrets.seal({ token }) });
155
+ const keys = server.secrets.unseal<{ token: string }>(row.credentials);
156
+ ```
157
+
158
+ `unseal` answers null for a value sealed on another install: ask for the keys again.
159
+
160
+ ## Documents
161
+
162
+ ```ts
163
+ const { markdown, pages } = await server.documents.parse({ data, name: "preise.pdf", mime });
164
+ ```
165
+
166
+ PDF and Word files by their own text, scans and photos by a vision model, spreadsheets and CSV as
167
+ tables. What was read is kept by content: the same bytes are read, and paid for, once.
168
+
169
+ ## Undo on unload
170
+
171
+ A plugin can load again while the runtime runs. What it registered through `wizards.server` is
172
+ taken back for it. Anything else it started, it undoes itself:
173
+
174
+ ```ts
175
+ const timer = setInterval(sync, 60_000);
176
+ server.onUnload(() => clearInterval(timer));
177
+ ```
178
+
179
+ The functions run last-first when the plugin unloads or loads again.
180
+
181
+ ## When loading fails
182
+
183
+ A plugin whose function throws keeps nothing of what it registered before the error: no half
184
+ plugins. Settings → Plugins shows the error, and the plugin's routes answer `404` until its file
185
+ is mended.
186
+
187
+ ## Imports
188
+
189
+ `@engenty-wizards/plugin-sdk`, `zod`, `drizzle-orm` and `drizzle-orm/sqlite-core` come from the
190
+ runtime's own copies, so a schema or a table a plugin makes is one the runtime understands. See
191
+ [Files and manifest](./layout.md#dependencies) for everything else.
@@ -0,0 +1,98 @@
1
+ ---
2
+ title: Shipping
3
+ description: Hand a plugin to someone else, put it into a server's image, and decide which tenant has it.
4
+ ---
5
+
6
+ ## To someone's install
7
+
8
+ A plugin is a file or a folder. Whoever installs it puts it into their plugins folder:
9
+ `~/.engenty/wizards/plugins` for an installed app.
10
+
11
+ Give them:
12
+
13
+ | | |
14
+ |---|---|
15
+ | One file | `notify.ts` |
16
+ | A folder | The manifest, `src/`, `migrations/`, and the built `dist/`. Not `ui/`: it is the source of `dist/` |
17
+ | Dependencies | A `node_modules` beside the plugin, if it imports anything but the SDK, `zod` and `drizzle-orm` |
18
+ | Settings | The names of the `.env` lines it reads, in its description |
19
+
20
+ Say what it does with data: a plugin runs with the app's full rights, and the person who
21
+ installs it trusts you with them.
22
+
23
+ ## As a package
24
+
25
+ Packages installed into a plugins folder count as plugins when they carry a manifest:
26
+
27
+ ```bash
28
+ cd ~/.engenty/wizards/plugins
29
+ npm install @acme/wizards-contacts
30
+ ```
31
+
32
+ The runtime finds `node_modules/@acme/wizards-contacts/engenty.plugin.json` at its next start,
33
+ or with "Look again" in Settings → Plugins. Put the manifest, the server half and the built
34
+ `dist/` into the package's `files`.
35
+
36
+ ## Into a server
37
+
38
+ With Docker, mount a folder and name it:
39
+
40
+ ```yaml
41
+ services:
42
+ wizards:
43
+ environment:
44
+ PLUGINS_DIR: /plugins
45
+ volumes:
46
+ - ./plugins:/plugins
47
+ ```
48
+
49
+ Or copy the plugins into an image of your own, built on the runtime's.
50
+
51
+ ## With engenty wizards itself
52
+
53
+ Plugins in the repository's `modules/` folder ship with every runtime: in a checkout, in the
54
+ installed app and in the Docker image. A module there is part of the open product.
55
+
56
+ - Its server half imports only what the runtime hands every plugin and its own files. It has no
57
+ `node_modules` of its own where it is installed.
58
+ - A module with a studio half is a workspace package whose `build` script is
59
+ `node ../../scripts/build-plugin.mjs .`, so the product's build builds its `dist/`.
60
+
61
+ A plugin that is not part of the open product stays out of `modules/` and goes into a folder of
62
+ `PLUGINS_DIR`.
63
+
64
+ engenty's own closed plugins reach a local install as [Pro modules](./pro-modules): signed
65
+ packages from the linked account, on while its plan includes them.
66
+
67
+ ## Which tenant has a plugin
68
+
69
+ | The runtime runs | A tenant has |
70
+ |---|---|
71
+ | Alone: one person's install, your own server | Every plugin the runtime loaded |
72
+ | As the runtime of a Manage-App | The plugins in `PLUGINS_DEFAULT`, and the ones the Manage-App lists for that tenant |
73
+
74
+ In a runtime of a Manage-App:
75
+
76
+ - Plugins are installed by whoever runs the runtime, into the image or a folder of
77
+ `PLUGINS_DIR`. A tenant cannot install one.
78
+ - `PLUGINS_DEFAULT` is a comma-separated list of ids every tenant has.
79
+ - The Manage-App switches further ones on per tenant: `modules` in its answer to
80
+ `GET /v1/tenants/:id`
81
+ ([manage-contract.md](https://github.com/engenty/engenty-wizards/blob/main/docs/manage-contract.md)).
82
+ It learns which plugins a runtime carries from `GET /api/internal/plugins` (with the
83
+ runtime's service key), so a plan's modules are picked from what exists.
84
+ - For a tenant without a plugin, that plugin does not exist: no routes, no tools, no listeners,
85
+ no studio half.
86
+ - A plugin's tables are made in every tenant's database, whether the tenant has the plugin or
87
+ not.
88
+ - Nothing reloads while it runs.
89
+
90
+ So one image serves tenants with different sets of plugins: the plugin is in the image, and the
91
+ Manage-App decides who has it.
92
+
93
+ ## Versions
94
+
95
+ - `version` in the manifest is shown in the settings. The runtime does not compare versions.
96
+ - A plugin's `.sql` files only ever grow: an update adds files, it never changes one that ran.
97
+ - A wizard that uses a plugin's tool names it by id. Renaming a tool or the plugin breaks those
98
+ wizards: keep ids for good.