wizards 0.2.47 → 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.
- package/apps/runtime/dist/agents/{project-assistant.js → studio-assistant.js} +199 -69
- package/apps/runtime/dist/agents/website.js +25 -2
- package/apps/runtime/dist/app.js +2 -1
- package/apps/runtime/dist/assistant/browser.js +26 -0
- package/apps/runtime/dist/assistant/docs.js +158 -0
- package/apps/runtime/dist/assistant/knows.js +325 -0
- package/apps/runtime/dist/assistant/primer.js +26 -0
- package/apps/runtime/dist/authoring/guide.js +5 -0
- package/apps/runtime/dist/connectors/plugin-connections.js +123 -29
- package/apps/runtime/dist/db/migrations/tenant/0012_assistant_chat.sql +40 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0012_snapshot.json +3132 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/_journal.json +7 -0
- package/apps/runtime/dist/db/schema.js +30 -0
- package/apps/runtime/dist/docs/dev/index.md +34 -0
- package/apps/runtime/dist/docs/dev/meta.json +7 -0
- package/apps/runtime/dist/docs/dev/plugins/connections.md +70 -0
- package/apps/runtime/dist/docs/dev/plugins/events.md +86 -0
- package/apps/runtime/dist/docs/dev/plugins/examples.md +99 -0
- package/apps/runtime/dist/docs/dev/plugins/index.md +72 -0
- package/apps/runtime/dist/docs/dev/plugins/layout.md +88 -0
- package/apps/runtime/dist/docs/dev/plugins/meta.json +29 -0
- package/apps/runtime/dist/docs/dev/plugins/pro-modules.md +59 -0
- package/apps/runtime/dist/docs/dev/plugins/quick-start.md +92 -0
- package/apps/runtime/dist/docs/dev/plugins/reference.md +298 -0
- package/apps/runtime/dist/docs/dev/plugins/reloading.md +75 -0
- package/apps/runtime/dist/docs/dev/plugins/routes.md +123 -0
- package/apps/runtime/dist/docs/dev/plugins/runners.md +184 -0
- package/apps/runtime/dist/docs/dev/plugins/server.md +191 -0
- package/apps/runtime/dist/docs/dev/plugins/shipping.md +98 -0
- package/apps/runtime/dist/docs/dev/plugins/space.md +260 -0
- package/apps/runtime/dist/docs/dev/plugins/starters.md +62 -0
- package/apps/runtime/dist/docs/dev/plugins/studio.md +261 -0
- package/apps/runtime/dist/docs/dev/plugins/styling.md +109 -0
- package/apps/runtime/dist/docs/dev/plugins/tables.md +102 -0
- package/apps/runtime/dist/docs/dev/plugins/tools.md +128 -0
- package/apps/runtime/dist/docs/meta.json +3 -0
- package/apps/runtime/dist/docs/user/ai-apps.md +99 -0
- package/apps/runtime/dist/docs/user/assistant.md +52 -0
- package/apps/runtime/dist/docs/user/build-a-wizard.md +79 -0
- package/apps/runtime/dist/docs/user/command-line.md +76 -0
- package/apps/runtime/dist/docs/user/connectors.md +80 -0
- package/apps/runtime/dist/docs/user/data.md +61 -0
- package/apps/runtime/dist/docs/user/first-start.md +42 -0
- package/apps/runtime/dist/docs/user/index.md +45 -0
- package/apps/runtime/dist/docs/user/install.md +76 -0
- package/apps/runtime/dist/docs/user/meta.json +29 -0
- package/apps/runtime/dist/docs/user/models.md +100 -0
- package/apps/runtime/dist/docs/user/plugins.md +61 -0
- package/apps/runtime/dist/docs/user/run.md +92 -0
- package/apps/runtime/dist/docs/user/server.md +50 -0
- package/apps/runtime/dist/docs/user/space.md +97 -0
- package/apps/runtime/dist/docs/user/steps.md +196 -0
- package/apps/runtime/dist/docs/user/test-and-share.md +210 -0
- package/apps/runtime/dist/docs/user/troubleshooting.md +57 -0
- package/apps/runtime/dist/engine/runner.js +12 -5
- package/apps/runtime/dist/manage.js +11 -0
- package/apps/runtime/dist/plugins/loader.js +2 -0
- package/apps/runtime/dist/routes/studio.js +119 -68
- package/apps/runtime/dist/services/assistant-chats.js +267 -0
- package/apps/runtime/dist/services/project-index.js +1 -1
- package/apps/runtime/dist/services/space-origin.js +45 -2
- package/apps/web/dist/assets/{AboutDialog-t7bpiasT.js → AboutDialog-CuiVGknS.js} +1 -1
- package/apps/web/dist/assets/{ChangelogDialog-B87yS6aN.js → ChangelogDialog-DCEQD3Jd.js} +1 -1
- package/apps/web/dist/assets/ChatView-DFxrG2PD.js +10 -0
- package/apps/web/dist/assets/EditorPage-B5rzKNMy.js +3 -0
- package/apps/web/dist/assets/{FlowPreview-ChXfiMn_.js → FlowPreview-CYoR5DRY.js} +1 -1
- package/apps/web/dist/assets/{Harness-zKMptCzB.js → Harness-DAR1u4Dk.js} +1 -1
- package/apps/web/dist/assets/HomePage-BnYdh_Nx.js +1 -0
- package/apps/web/dist/assets/Marketplace-BDQNwMDB.js +2 -0
- package/apps/web/dist/assets/{NewWizardPage-C3NqEGmg.js → NewWizardPage-DztTEUlG.js} +1 -1
- package/apps/web/dist/assets/ProjectPage-B7-Lqx9a.js +2 -0
- package/apps/web/dist/assets/PublicRunner-CaH3bHHd.js +1 -0
- package/apps/web/dist/assets/{ReadOnly-C9P9aiU6.js → ReadOnly-DnB47DQC.js} +1 -1
- package/apps/web/dist/assets/RunDrawer-Dv0KRqGA.js +4 -0
- package/apps/web/dist/assets/RunnerView-Bzwv1u4j.js +2 -0
- package/apps/web/dist/assets/SettingsPage-oVO7CKvc.js +1 -0
- package/apps/web/dist/assets/{SetupPage-B3IOQLO3.js → SetupPage-D--8cWA0.js} +1 -1
- package/apps/web/dist/assets/{SharePage-C3QEzicl.js → SharePage-DjU08q7T.js} +1 -1
- package/apps/web/dist/assets/{ThemeSwitch-3IzIOlNz.js → ThemeSwitch-C3EJRN06.js} +1 -1
- package/apps/web/dist/assets/arrow-right-F7X_SjK9.js +1 -0
- package/apps/web/dist/assets/changelog-BRoVI_JJ.js +1 -0
- package/apps/web/dist/assets/{circle-alert-CPo3Naay.js → circle-alert-DdpaAYgd.js} +1 -1
- package/apps/web/dist/assets/{definition-CQGiBQ4X.js → definition-CHacJYmI.js} +2 -2
- package/apps/web/dist/assets/{external-link-CpU8aJY2.js → external-link-Dfc1VFvS.js} +1 -1
- package/apps/web/dist/assets/index-CX_yxZVQ.js +79 -0
- package/apps/web/dist/assets/index-Dr0bv52Q.css +1 -0
- package/apps/web/dist/assets/{lock-C_WlXIQ0.js → lock-Bu1wDFs8.js} +1 -1
- package/apps/web/dist/assets/{refresh-cw-Cli5WGnW.js → refresh-cw-BUDPOT39.js} +1 -1
- package/apps/web/dist/assets/{session-miDEdw2c.js → session-Blj2os_v.js} +1 -1
- package/apps/web/dist/assets/{settings-menu-ROT8Lbbj.js → settings-menu-BvxRnNtf.js} +1 -1
- package/apps/web/dist/assets/{sparkles-CP5H-O1E.js → sparkles-DWGJluyV.js} +1 -1
- package/apps/web/dist/assets/{trash-DU-hZpV0.js → trash-D9UB6TtS.js} +1 -1
- package/apps/web/dist/assets/ui-GsuU9WTj.js +9 -0
- package/apps/web/dist/assets/{upload-DMq5N6Fw.js → upload-BngimDBR.js} +1 -1
- package/apps/web/dist/assets/{volume-2-0SfkvOho.js → volume-2-BZju_bOP.js} +1 -1
- package/apps/web/dist/index.html +11 -11
- package/apps/web/dist/mcp/flow.html +51 -51
- package/node_modules/@engenty-wizards/plugin-sdk/dist/index.d.ts +82 -7
- package/node_modules/@engenty-wizards/plugin-sdk/dist/studio.d.ts +58 -4
- package/node_modules/@engenty-wizards/shared/dist/assistant.d.ts +113 -0
- package/node_modules/@engenty-wizards/shared/dist/assistant.js +55 -0
- package/node_modules/@engenty-wizards/shared/dist/definition.d.ts +56 -1
- package/node_modules/@engenty-wizards/shared/dist/definition.js +94 -4
- package/node_modules/@engenty-wizards/shared/dist/run.d.ts +3 -1
- package/package.json +1 -1
- package/apps/web/dist/assets/ChatView-Dm764bYy.js +0 -10
- package/apps/web/dist/assets/EditorPage-BG_Ue2iC.js +0 -3
- package/apps/web/dist/assets/HomePage-BXSg5P5k.js +0 -1
- package/apps/web/dist/assets/Marketplace-BWhUJ4UX.js +0 -2
- package/apps/web/dist/assets/ProjectPage-D6Fy7uTV.js +0 -2
- package/apps/web/dist/assets/PublicRunner-ChgJs0C9.js +0 -1
- package/apps/web/dist/assets/RunDrawer-CvIKLphz.js +0 -4
- package/apps/web/dist/assets/RunnerView-Bmayop7s.js +0 -2
- package/apps/web/dist/assets/SettingsPage-QkwtRFoD.js +0 -1
- package/apps/web/dist/assets/arrow-right-Dpp_mpHe.js +0 -1
- package/apps/web/dist/assets/changelog-Du2gWzlN.js +0 -1
- package/apps/web/dist/assets/index-Cz6c1S5g.js +0 -78
- package/apps/web/dist/assets/index-DKHClEy3.css +0 -1
- package/apps/web/dist/assets/ui-D92EkdEB.js +0 -9
|
@@ -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.
|