@evermore.work/plugin-sdk 2026.509.0-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1215 -0
- package/dist/bundlers.d.ts +57 -0
- package/dist/bundlers.d.ts.map +1 -0
- package/dist/bundlers.js +106 -0
- package/dist/bundlers.js.map +1 -0
- package/dist/define-plugin.d.ts +266 -0
- package/dist/define-plugin.d.ts.map +1 -0
- package/dist/define-plugin.js +85 -0
- package/dist/define-plugin.js.map +1 -0
- package/dist/dev-cli.d.ts +3 -0
- package/dist/dev-cli.d.ts.map +1 -0
- package/dist/dev-cli.js +49 -0
- package/dist/dev-cli.js.map +1 -0
- package/dist/dev-server.d.ts +34 -0
- package/dist/dev-server.d.ts.map +1 -0
- package/dist/dev-server.js +194 -0
- package/dist/dev-server.js.map +1 -0
- package/dist/host-client-factory.d.ts +272 -0
- package/dist/host-client-factory.d.ts.map +1 -0
- package/dist/host-client-factory.js +481 -0
- package/dist/host-client-factory.js.map +1 -0
- package/dist/index.d.ts +84 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +84 -0
- package/dist/index.js.map +1 -0
- package/dist/protocol.d.ts +1285 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +306 -0
- package/dist/protocol.js.map +1 -0
- package/dist/testing.d.ts +166 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +1766 -0
- package/dist/testing.js.map +1 -0
- package/dist/types.d.ts +1330 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +12 -0
- package/dist/types.js.map +1 -0
- package/dist/ui/components.d.ts +511 -0
- package/dist/ui/components.d.ts.map +1 -0
- package/dist/ui/components.js +135 -0
- package/dist/ui/components.js.map +1 -0
- package/dist/ui/hooks.d.ts +155 -0
- package/dist/ui/hooks.d.ts.map +1 -0
- package/dist/ui/hooks.js +195 -0
- package/dist/ui/hooks.js.map +1 -0
- package/dist/ui/index.d.ts +54 -0
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +51 -0
- package/dist/ui/index.js.map +1 -0
- package/dist/ui/runtime.d.ts +3 -0
- package/dist/ui/runtime.d.ts.map +1 -0
- package/dist/ui/runtime.js +30 -0
- package/dist/ui/runtime.js.map +1 -0
- package/dist/ui/types.d.ts +388 -0
- package/dist/ui/types.d.ts.map +1 -0
- package/dist/ui/types.js +17 -0
- package/dist/ui/types.js.map +1 -0
- package/dist/worker-rpc-host.d.ts +127 -0
- package/dist/worker-rpc-host.d.ts.map +1 -0
- package/dist/worker-rpc-host.js +1279 -0
- package/dist/worker-rpc-host.js.map +1 -0
- package/package.json +88 -0
package/README.md
ADDED
|
@@ -0,0 +1,1215 @@
|
|
|
1
|
+
# `@evermore.work/plugin-sdk`
|
|
2
|
+
|
|
3
|
+
Official TypeScript SDK for Evermore plugin authors.
|
|
4
|
+
|
|
5
|
+
- **Worker SDK:** `@evermore.work/plugin-sdk` — `definePlugin`, context, lifecycle
|
|
6
|
+
- **UI SDK:** `@evermore.work/plugin-sdk/ui` — React hooks and slot props
|
|
7
|
+
- **Testing:** `@evermore.work/plugin-sdk/testing` — in-memory host harness
|
|
8
|
+
- **Bundlers:** `@evermore.work/plugin-sdk/bundlers` — esbuild/rollup presets
|
|
9
|
+
- **Dev server:** `@evermore.work/plugin-sdk/dev-server` — static UI server + SSE reload
|
|
10
|
+
|
|
11
|
+
Reference: `doc/plugins/PLUGIN_SPEC.md`
|
|
12
|
+
|
|
13
|
+
## Package surface
|
|
14
|
+
|
|
15
|
+
| Import | Purpose |
|
|
16
|
+
|--------|--------|
|
|
17
|
+
| `@evermore.work/plugin-sdk` | Worker entry: `definePlugin`, `runWorker`, context types, protocol helpers |
|
|
18
|
+
| `@evermore.work/plugin-sdk/ui` | UI entry: `usePluginData`, `usePluginAction`, `usePluginStream`, `useHostContext`, `useHostNavigation`, slot prop types |
|
|
19
|
+
| `@evermore.work/plugin-sdk/ui/hooks` | Hooks only |
|
|
20
|
+
| `@evermore.work/plugin-sdk/ui/types` | UI types and slot prop interfaces |
|
|
21
|
+
| `@evermore.work/plugin-sdk/testing` | `createTestHarness` for unit/integration tests |
|
|
22
|
+
| `@evermore.work/plugin-sdk/bundlers` | `createPluginBundlerPresets` for worker/manifest/ui builds |
|
|
23
|
+
| `@evermore.work/plugin-sdk/dev-server` | `startPluginDevServer`, `getUiBuildSnapshot` |
|
|
24
|
+
| `@evermore.work/plugin-sdk/protocol` | JSON-RPC protocol types and helpers (advanced) |
|
|
25
|
+
| `@evermore.work/plugin-sdk/types` | Worker context and API types (advanced) |
|
|
26
|
+
|
|
27
|
+
## Manifest entrypoints
|
|
28
|
+
|
|
29
|
+
In your plugin manifest you declare:
|
|
30
|
+
|
|
31
|
+
- **`entrypoints.worker`** (required) — Path to the worker bundle (e.g. `dist/worker.js`). The host loads this and calls `setup(ctx)`.
|
|
32
|
+
- **`entrypoints.ui`** (required if you use UI) — Path to the UI bundle directory. The host loads components from here for slots and launchers.
|
|
33
|
+
|
|
34
|
+
## Install
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pnpm add @evermore.work/plugin-sdk
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Current deployment caveats
|
|
41
|
+
|
|
42
|
+
The SDK is stable enough for local development and first-party examples, but the runtime deployment model is still early.
|
|
43
|
+
|
|
44
|
+
- Plugin workers and plugin UI should both be treated as trusted code today.
|
|
45
|
+
- Plugin UI bundles run as same-origin JavaScript inside the main Evermore app. They can call ordinary Evermore HTTP APIs with the board session, so manifest capabilities are not a frontend sandbox.
|
|
46
|
+
- Local-path installs and the repo example plugins are development workflows. They assume the plugin source checkout exists on disk.
|
|
47
|
+
- For deployed plugins, publish an npm package and install that package into the Evermore instance at runtime.
|
|
48
|
+
- The current host runtime expects a writable filesystem, `npm` available at runtime, and network access to the package registry used for plugin installation.
|
|
49
|
+
- Dynamic plugin install is currently best suited to single-node persistent deployments. Multi-instance cloud deployments still need a shared artifact/distribution model before runtime installs are reliable across nodes.
|
|
50
|
+
- The host ships a small shared React component kit through `@evermore.work/plugin-sdk/ui`. Use it for native Evermore controls; custom React and CSS are still supported.
|
|
51
|
+
- `ctx.assets` is not part of the supported runtime in this build. Do not depend on asset upload/read APIs yet.
|
|
52
|
+
|
|
53
|
+
If you are authoring a plugin for others to deploy, treat npm-packaged installation as the supported path and treat repo-local example installs as a development convenience.
|
|
54
|
+
|
|
55
|
+
## Worker quick start
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
import { definePlugin, runWorker } from "@evermore.work/plugin-sdk";
|
|
59
|
+
|
|
60
|
+
const plugin = definePlugin({
|
|
61
|
+
async setup(ctx) {
|
|
62
|
+
ctx.events.on("issue.created", async (event) => {
|
|
63
|
+
ctx.logger.info("Issue created", { issueId: event.entityId });
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
ctx.data.register("health", async () => ({ status: "ok" }));
|
|
67
|
+
ctx.actions.register("ping", async () => ({ pong: true }));
|
|
68
|
+
|
|
69
|
+
ctx.tools.register("calculator", {
|
|
70
|
+
displayName: "Calculator",
|
|
71
|
+
description: "Basic math",
|
|
72
|
+
parametersSchema: {
|
|
73
|
+
type: "object",
|
|
74
|
+
properties: { a: { type: "number" }, b: { type: "number" } },
|
|
75
|
+
required: ["a", "b"]
|
|
76
|
+
}
|
|
77
|
+
}, async (params) => {
|
|
78
|
+
const { a, b } = params as { a: number; b: number };
|
|
79
|
+
return { content: `Result: ${a + b}`, data: { result: a + b } };
|
|
80
|
+
});
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
export default plugin;
|
|
85
|
+
runWorker(plugin, import.meta.url);
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
**Note:** `runWorker(plugin, import.meta.url)` must be called so that when the host runs your worker (e.g. `node dist/worker.js`), the RPC host starts and the process stays alive. When the file is imported (e.g. for tests), the main-module check prevents the host from starting.
|
|
89
|
+
|
|
90
|
+
### Worker lifecycle and context
|
|
91
|
+
|
|
92
|
+
**Lifecycle (definePlugin):**
|
|
93
|
+
|
|
94
|
+
| Hook | Purpose |
|
|
95
|
+
|------|--------|
|
|
96
|
+
| `setup(ctx)` | **Required.** Called once at startup. Register event handlers, jobs, data/actions/tools, etc. |
|
|
97
|
+
| `onHealth?()` | Optional. Return `{ status, message?, details? }` for health dashboard. |
|
|
98
|
+
| `onConfigChanged?(newConfig)` | Optional. Apply new config without restart; if omitted, host restarts worker. |
|
|
99
|
+
| `onShutdown?()` | Optional. Clean up before process exit (limited time window). |
|
|
100
|
+
| `onValidateConfig?(config)` | Optional. Return `{ ok, warnings?, errors? }` for settings UI / Test Connection. |
|
|
101
|
+
| `onWebhook?(input)` | Optional. Handle `POST /api/plugins/:pluginId/webhooks/:endpointKey`; required if webhooks declared. |
|
|
102
|
+
|
|
103
|
+
**Context (`ctx`) in setup:** `config`, `localFolders`, `events`, `jobs`, `launchers`, `http`, `secrets`, `activity`, `state`, `entities`, `projects`, `companies`, `issues`, `agents`, `goals`, `data`, `actions`, `streams`, `tools`, `metrics`, `logger`, `manifest`. Worker-side host APIs are capability-gated; declare capabilities in the manifest.
|
|
104
|
+
|
|
105
|
+
**Agents:** `ctx.agents.invoke(agentId, companyId, opts)` for one-shot invocation. `ctx.agents.sessions` for two-way chat: `create`, `list`, `sendMessage` (with streaming `onEvent` callback), `close`. See the [Plugin Authoring Guide](../../doc/plugins/PLUGIN_AUTHORING_GUIDE.md#agent-sessions-two-way-chat) for details.
|
|
106
|
+
|
|
107
|
+
**Jobs:** Declare in `manifest.jobs` with `jobKey`, `displayName`, `schedule` (cron). Register handler with `ctx.jobs.register(jobKey, fn)`. **Webhooks:** Declare in `manifest.webhooks` with `endpointKey`; handle in `onWebhook(input)`. **State:** `ctx.state.get/set/delete(scopeKey)`; scope kinds: `instance`, `company`, `project`, `project_workspace`, `agent`, `issue`, `goal`, `run`.
|
|
108
|
+
|
|
109
|
+
**Trusted local folders:** Declare `manifest.localFolders[]` and the `local.folders` capability when a plugin needs an operator-configured company-scoped folder. Use `ctx.localFolders.configure()`, `status()`, `readText()`, and `writeTextAtomic()` instead of resolving arbitrary filesystem paths yourself. The host validates absolute roots, read/write access, required relative folders/files, traversal attempts, symlink escapes, and writes through temp-file-plus-rename atomic replacement.
|
|
110
|
+
|
|
111
|
+
## Events
|
|
112
|
+
|
|
113
|
+
Subscribe in `setup` with `ctx.events.on(name, handler)` or `ctx.events.on(name, filter, handler)`. Emit plugin-scoped events with `ctx.events.emit(name, companyId, payload)` (requires `events.emit`).
|
|
114
|
+
|
|
115
|
+
**Core domain events (subscribe with `events.subscribe`):**
|
|
116
|
+
|
|
117
|
+
| Event | Typical entity |
|
|
118
|
+
|-------|-----------------|
|
|
119
|
+
| `company.created`, `company.updated` | company |
|
|
120
|
+
| `project.created`, `project.updated` | project |
|
|
121
|
+
| `project.workspace_created`, `project.workspace_updated`, `project.workspace_deleted` | project_workspace |
|
|
122
|
+
| `issue.created`, `issue.updated`, `issue.comment.created` | issue |
|
|
123
|
+
| `issue.document.created`, `issue.document.updated`, `issue.document.deleted` | issue |
|
|
124
|
+
| `issue.relations.updated`, `issue.checked_out`, `issue.released`, `issue.assignment_wakeup_requested` | issue |
|
|
125
|
+
| `agent.created`, `agent.updated`, `agent.status_changed` | agent |
|
|
126
|
+
| `agent.run.started`, `agent.run.finished`, `agent.run.failed`, `agent.run.cancelled` | run |
|
|
127
|
+
| `goal.created`, `goal.updated` | goal |
|
|
128
|
+
| `approval.created`, `approval.decided` | approval |
|
|
129
|
+
| `budget.incident.opened`, `budget.incident.resolved` | budget_incident |
|
|
130
|
+
| `cost_event.created` | cost |
|
|
131
|
+
| `activity.logged` | activity |
|
|
132
|
+
|
|
133
|
+
**Plugin-to-plugin:** Subscribe to `plugin.<pluginId>.<eventName>` (e.g. `plugin.acme.linear.sync-done`). Emit with `ctx.events.emit("sync-done", companyId, payload)`; the host namespaces it automatically.
|
|
134
|
+
|
|
135
|
+
**Filter (optional):** Pass a second argument to `on()`: `{ projectId?, companyId?, agentId? }` so the host only delivers matching events.
|
|
136
|
+
|
|
137
|
+
**Company context:** Events still carry `companyId` for company-scoped data, but plugin installation and activation are instance-wide in the current runtime.
|
|
138
|
+
|
|
139
|
+
## Scheduled (recurring) jobs
|
|
140
|
+
|
|
141
|
+
Plugins can declare **scheduled jobs** that the host runs on a cron schedule. Use this for recurring tasks like syncs, digest reports, or cleanup.
|
|
142
|
+
|
|
143
|
+
1. **Capability:** Add `jobs.schedule` to `manifest.capabilities`.
|
|
144
|
+
2. **Declare jobs** in `manifest.jobs`: each entry has `jobKey`, `displayName`, optional `description`, and `schedule` (a 5-field cron expression).
|
|
145
|
+
3. **Register a handler** in `setup()` with `ctx.jobs.register(jobKey, async (job) => { ... })`.
|
|
146
|
+
|
|
147
|
+
**Cron format** (5 fields: minute, hour, day-of-month, month, day-of-week):
|
|
148
|
+
|
|
149
|
+
| Field | Values | Example |
|
|
150
|
+
|-------------|----------|---------|
|
|
151
|
+
| minute | 0–59 | `0`, `*/15` |
|
|
152
|
+
| hour | 0–23 | `2`, `*` |
|
|
153
|
+
| day of month | 1–31 | `1`, `*` |
|
|
154
|
+
| month | 1–12 | `*` |
|
|
155
|
+
| day of week | 0–6 (Sun=0) | `*`, `1-5` |
|
|
156
|
+
|
|
157
|
+
Examples: `"0 * * * *"` = every hour at minute 0; `"*/5 * * * *"` = every 5 minutes; `"0 2 * * *"` = daily at 2:00.
|
|
158
|
+
|
|
159
|
+
**Job handler context** (`PluginJobContext`):
|
|
160
|
+
|
|
161
|
+
| Field | Type | Description |
|
|
162
|
+
|-------------|----------|-------------|
|
|
163
|
+
| `jobKey` | string | Matches the manifest declaration. |
|
|
164
|
+
| `runId` | string | UUID for this run. |
|
|
165
|
+
| `trigger` | `"schedule" \| "manual" \| "retry"` | What caused this run. |
|
|
166
|
+
| `scheduledAt` | string | ISO 8601 time when the run was scheduled. |
|
|
167
|
+
|
|
168
|
+
Runs can be triggered by the **schedule**, **manually** from the UI/API, or as a **retry** (when an operator re-runs a job after a failure). Re-throw from the handler to mark the run as failed; the host records the failure. The host does not automatically retry—operators can trigger another run manually from the UI or API.
|
|
169
|
+
|
|
170
|
+
Example:
|
|
171
|
+
|
|
172
|
+
**Manifest** — include `jobs.schedule` and declare the job:
|
|
173
|
+
|
|
174
|
+
```ts
|
|
175
|
+
// In your manifest (e.g. manifest.ts):
|
|
176
|
+
const manifest = {
|
|
177
|
+
// ...
|
|
178
|
+
capabilities: ["jobs.schedule", "plugin.state.write"],
|
|
179
|
+
jobs: [
|
|
180
|
+
{
|
|
181
|
+
jobKey: "heartbeat",
|
|
182
|
+
displayName: "Heartbeat",
|
|
183
|
+
description: "Runs every 5 minutes",
|
|
184
|
+
schedule: "*/5 * * * *",
|
|
185
|
+
},
|
|
186
|
+
],
|
|
187
|
+
// ...
|
|
188
|
+
};
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
**Worker** — register the handler in `setup()`:
|
|
192
|
+
|
|
193
|
+
```ts
|
|
194
|
+
ctx.jobs.register("heartbeat", async (job) => {
|
|
195
|
+
ctx.logger.info("Heartbeat run", { runId: job.runId, trigger: job.trigger });
|
|
196
|
+
await ctx.state.set({ scopeKind: "instance", stateKey: "last-heartbeat" }, new Date().toISOString());
|
|
197
|
+
});
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## UI slots and launchers
|
|
201
|
+
|
|
202
|
+
Slots are mount points for plugin React components. Launchers are host-rendered entry points (buttons, menu items) that open plugin UI. Declare slots in `manifest.ui.slots` with `type`, `id`, `displayName`, `exportName`; for context-sensitive slots add `entityTypes`. Declare launchers in `manifest.ui.launchers` (or legacy `manifest.launchers`).
|
|
203
|
+
|
|
204
|
+
### Slot types / launcher placement zones
|
|
205
|
+
|
|
206
|
+
Slot types describe where a component mounts. Most values also exist as launcher placement zones.
|
|
207
|
+
|
|
208
|
+
| Slot type / placement zone | Scope | Entity types (when context-sensitive) |
|
|
209
|
+
|----------------------------|-------|---------------------------------------|
|
|
210
|
+
| `page` | Global | — |
|
|
211
|
+
| `sidebar` | Global | — |
|
|
212
|
+
| `routeSidebar` | Global | — |
|
|
213
|
+
| `sidebarPanel` | Global | — |
|
|
214
|
+
| `settingsPage` | Global | — |
|
|
215
|
+
| `dashboardWidget` | Global | — |
|
|
216
|
+
| `globalToolbarButton` | Global | — |
|
|
217
|
+
| `detailTab` | Entity | `project`, `issue`, `agent`, `goal`, `run` |
|
|
218
|
+
| `taskDetailView` | Entity | (task/issue context) |
|
|
219
|
+
| `commentAnnotation` | Entity | `comment` |
|
|
220
|
+
| `commentContextMenuItem` | Entity | `comment` |
|
|
221
|
+
| `projectSidebarItem` | Entity | `project` |
|
|
222
|
+
| `toolbarButton` | Entity | varies by host surface |
|
|
223
|
+
| `contextMenuItem` | Entity | varies by host surface |
|
|
224
|
+
|
|
225
|
+
**Scope** describes whether the slot requires an entity to render. **Global** slots render without a specific entity but still receive the active `companyId` through `PluginHostContext` — use it to scope data fetches to the current company. **Entity** slots additionally require `entityId` and `entityType` (e.g. a detail tab on a specific issue).
|
|
226
|
+
|
|
227
|
+
**Entity types** (for `entityTypes` on slots): `project` \| `issue` \| `agent` \| `goal` \| `run` \| `comment`. Full list: import `PLUGIN_UI_SLOT_TYPES` and `PLUGIN_UI_SLOT_ENTITY_TYPES` from `@evermore.work/plugin-sdk`.
|
|
228
|
+
|
|
229
|
+
### Slot component descriptions
|
|
230
|
+
|
|
231
|
+
#### `page`
|
|
232
|
+
|
|
233
|
+
A full-page extension mounted at `/plugins/:pluginId` (global) or `/:company/plugins/:pluginId` (company-context route). Use this for rich, standalone plugin experiences such as dashboards, configuration wizards, or multi-step workflows. Receives `PluginPageProps` with `context.companyId` set to the active company. Requires the `ui.page.register` capability.
|
|
234
|
+
|
|
235
|
+
#### `sidebar`
|
|
236
|
+
|
|
237
|
+
Adds a navigation-style entry to the main company sidebar navigation area, rendered alongside the core nav items (Dashboard, Issues, Goals, etc.). Use this for lightweight, always-visible links or status indicators that feel native to the sidebar. Receives `PluginSidebarProps` with `context.companyId` set to the active company. Requires the `ui.sidebar.register` capability.
|
|
238
|
+
|
|
239
|
+
#### `routeSidebar`
|
|
240
|
+
|
|
241
|
+
Replaces the normal company sidebar while the current route is a plugin page route with the same `routePath`. Use this for full-page plugin workspaces that need their own local navigation while keeping the company rail and account footer. Receives `PluginRouteSidebarProps` with `context.companyId` and `context.companyPrefix` set to the active company. Requires the `ui.sidebar.register` capability.
|
|
242
|
+
|
|
243
|
+
#### `sidebarPanel`
|
|
244
|
+
|
|
245
|
+
Renders richer inline content in a dedicated panel area below the company sidebar navigation sections. Use this for mini-widgets, summary cards, quick-action panels, or at-a-glance status views that need more vertical space than a nav link. Receives `context.companyId` set to the active company via `useHostContext()`. Requires the `ui.sidebar.register` capability.
|
|
246
|
+
|
|
247
|
+
#### `settingsPage`
|
|
248
|
+
|
|
249
|
+
Replaces the auto-generated JSON Schema settings form with a custom React component. Use this when the default form is insufficient — for example, when your plugin needs multi-step configuration, OAuth flows, "Test Connection" buttons, or rich input controls. Receives `PluginSettingsPageProps` with `context.companyId` set to the active company. The component is responsible for reading and writing config through the bridge (via `usePluginData` and `usePluginAction`).
|
|
250
|
+
|
|
251
|
+
#### `dashboardWidget`
|
|
252
|
+
|
|
253
|
+
A card or section rendered on the main dashboard. Use this for at-a-glance metrics, status indicators, or summary views that surface plugin data alongside core Evermore information. Receives `PluginWidgetProps` with `context.companyId` set to the active company. Requires the `ui.dashboardWidget.register` capability.
|
|
254
|
+
|
|
255
|
+
#### `detailTab`
|
|
256
|
+
|
|
257
|
+
An additional tab on a project, issue, agent, goal, or run detail page. Rendered when the user navigates to that entity's detail view. Receives `PluginDetailTabProps` with `context.companyId` set to the active company and `context.entityId` / `context.entityType` guaranteed to be non-null, so you can immediately scope data fetches to the relevant entity. Specify which entity types the tab applies to via the `entityTypes` array in the manifest slot declaration. Requires the `ui.detailTab.register` capability.
|
|
258
|
+
|
|
259
|
+
#### `taskDetailView`
|
|
260
|
+
|
|
261
|
+
A specialized slot rendered in the context of a task or issue detail view. Similar to `detailTab` but designed for inline content within the task detail layout rather than a separate tab. Receives `context.companyId`, `context.entityId`, and `context.entityType` like `detailTab`. Requires the `ui.detailTab.register` capability.
|
|
262
|
+
|
|
263
|
+
#### `projectSidebarItem`
|
|
264
|
+
|
|
265
|
+
A link or small component rendered **once per project** under that project's row in the sidebar Projects list. Use this to add project-scoped navigation entries (e.g. "Files", "Linear Sync") that deep-link into a plugin detail tab: `/:company/projects/:projectRef?tab=plugin:<key>:<slotId>`. Receives `PluginProjectSidebarItemProps` with `context.companyId` set to the active company, `context.entityId` set to the project id, and `context.entityType` set to `"project"`. Use the optional `order` field in the manifest slot to control sort position. Requires the `ui.sidebar.register` capability.
|
|
266
|
+
|
|
267
|
+
#### `globalToolbarButton`
|
|
268
|
+
|
|
269
|
+
A button rendered in the global top bar (breadcrumb bar) that appears on every page. Use this for company-wide actions that are not scoped to a specific entity — for example, a universal search trigger, a global sync status indicator, or a floating action that applies across the whole workspace. Receives only `context.companyId` and `context.companyPrefix`; no entity context is available. Requires the `ui.action.register` capability.
|
|
270
|
+
|
|
271
|
+
#### `toolbarButton`
|
|
272
|
+
|
|
273
|
+
A button rendered in the toolbar of an entity page (e.g. project detail, issue detail). Use this for short-lived, contextual actions scoped to the current entity — like triggering a project sync, opening a picker, or running a quick command on that entity. The component can open a plugin-owned modal internally for confirmations or compact forms. Receives `context.companyId`, `context.entityId`, and `context.entityType`; declare `entityTypes` in the manifest to control which entity pages the button appears on. Requires the `ui.action.register` capability.
|
|
274
|
+
|
|
275
|
+
#### `contextMenuItem`
|
|
276
|
+
|
|
277
|
+
An entry added to a right-click or overflow context menu on a host surface. Use this for secondary actions that apply to the entity under the cursor (e.g. "Copy to Linear", "Re-run analysis"). Receives `context.companyId` set to the active company; entity context varies by host surface. Requires the `ui.action.register` capability.
|
|
278
|
+
|
|
279
|
+
#### `commentAnnotation`
|
|
280
|
+
|
|
281
|
+
A per-comment annotation region rendered below each individual comment in the issue detail timeline. Use this to augment comments with parsed file links, sentiment badges, inline actions, or any per-comment metadata. Receives `PluginCommentAnnotationProps` with `context.entityId` set to the comment UUID, `context.entityType` set to `"comment"`, `context.parentEntityId` set to the parent issue UUID, `context.projectId` set to the issue's project (if any), and `context.companyPrefix` set to the active company slug. Requires the `ui.commentAnnotation.register` capability.
|
|
282
|
+
|
|
283
|
+
#### `commentContextMenuItem`
|
|
284
|
+
|
|
285
|
+
A per-comment context menu item rendered in the "more" dropdown menu (⋮) on each comment in the issue detail timeline. Use this to add per-comment actions such as "Create sub-issue from comment", "Translate", "Flag for review", or custom plugin actions. Receives `PluginCommentContextMenuItemProps` with `context.entityId` set to the comment UUID, `context.entityType` set to `"comment"`, `context.parentEntityId` set to the parent issue UUID, `context.projectId` set to the issue's project (if any), and `context.companyPrefix` set to the active company slug. Plugins can open drawers, modals, or popovers scoped to that comment. The ⋮ menu button only appears on comments where at least one plugin renders visible content. Requires the `ui.action.register` capability.
|
|
286
|
+
|
|
287
|
+
### Launcher actions and render options
|
|
288
|
+
|
|
289
|
+
| Launcher action | Description |
|
|
290
|
+
|-----------------|-------------|
|
|
291
|
+
| `navigate` | Navigate to a route (plugin or host). |
|
|
292
|
+
| `openModal` | Open a modal. |
|
|
293
|
+
| `openDrawer` | Open a drawer. |
|
|
294
|
+
| `openPopover` | Open a popover. |
|
|
295
|
+
| `performAction` | Run an action (e.g. call plugin). |
|
|
296
|
+
| `deepLink` | Deep link to plugin or external URL. |
|
|
297
|
+
|
|
298
|
+
| Render option | Values | Description |
|
|
299
|
+
|---------------|--------|-------------|
|
|
300
|
+
| `environment` | `hostInline`, `hostOverlay`, `hostRoute`, `external`, `iframe` | Container the launcher expects after activation. |
|
|
301
|
+
| `bounds` | `inline`, `compact`, `default`, `wide`, `full` | Size hint for overlays/drawers. |
|
|
302
|
+
|
|
303
|
+
### Capabilities
|
|
304
|
+
|
|
305
|
+
Declare in `manifest.capabilities`. Grouped by scope:
|
|
306
|
+
|
|
307
|
+
| Scope | Capability |
|
|
308
|
+
|-------|------------|
|
|
309
|
+
| **Company** | `companies.read` |
|
|
310
|
+
| | `projects.read` |
|
|
311
|
+
| | `project.workspaces.read` |
|
|
312
|
+
| | `issues.read` |
|
|
313
|
+
| | `issue.comments.read` |
|
|
314
|
+
| | `issue.documents.read` |
|
|
315
|
+
| | `issue.relations.read` |
|
|
316
|
+
| | `issue.subtree.read` |
|
|
317
|
+
| | `agents.read` |
|
|
318
|
+
| | `goals.read` |
|
|
319
|
+
| | `goals.create` |
|
|
320
|
+
| | `goals.update` |
|
|
321
|
+
| | `activity.read` |
|
|
322
|
+
| | `costs.read` |
|
|
323
|
+
| | `issues.orchestration.read` |
|
|
324
|
+
| | `database.namespace.read` |
|
|
325
|
+
| | `issues.create` |
|
|
326
|
+
| | `issues.update` |
|
|
327
|
+
| | `issues.checkout` |
|
|
328
|
+
| | `issues.wakeup` |
|
|
329
|
+
| | `issue.comments.create` |
|
|
330
|
+
| | `issue.documents.write` |
|
|
331
|
+
| | `issue.relations.write` |
|
|
332
|
+
| | `activity.log.write` |
|
|
333
|
+
| | `metrics.write` |
|
|
334
|
+
| | `telemetry.track` |
|
|
335
|
+
| | `database.namespace.migrate` |
|
|
336
|
+
| | `database.namespace.write` |
|
|
337
|
+
| **Instance** | `instance.settings.register` |
|
|
338
|
+
| | `plugin.state.read` |
|
|
339
|
+
| | `plugin.state.write` |
|
|
340
|
+
| **Runtime** | `events.subscribe` |
|
|
341
|
+
| | `events.emit` |
|
|
342
|
+
| | `jobs.schedule` |
|
|
343
|
+
| | `webhooks.receive` |
|
|
344
|
+
| | `api.routes.register` |
|
|
345
|
+
| | `http.outbound` |
|
|
346
|
+
| | `secrets.read-ref` |
|
|
347
|
+
| | `environment.drivers.register` |
|
|
348
|
+
| | `local.folders` |
|
|
349
|
+
| **Agent** | `agent.tools.register` |
|
|
350
|
+
| | `agents.invoke` |
|
|
351
|
+
| | `agent.sessions.create` |
|
|
352
|
+
| | `agent.sessions.list` |
|
|
353
|
+
| | `agent.sessions.send` |
|
|
354
|
+
| | `agent.sessions.close` |
|
|
355
|
+
| **UI** | `ui.sidebar.register` |
|
|
356
|
+
| | `ui.page.register` |
|
|
357
|
+
| | `ui.detailTab.register` |
|
|
358
|
+
| | `ui.dashboardWidget.register` |
|
|
359
|
+
| | `ui.commentAnnotation.register` |
|
|
360
|
+
| | `ui.action.register` |
|
|
361
|
+
|
|
362
|
+
Full list in code: import `PLUGIN_CAPABILITIES` from `@evermore.work/plugin-sdk`.
|
|
363
|
+
|
|
364
|
+
### Restricted Database Namespace
|
|
365
|
+
|
|
366
|
+
Trusted orchestration plugins can declare a host-owned PostgreSQL namespace:
|
|
367
|
+
|
|
368
|
+
```ts
|
|
369
|
+
database: {
|
|
370
|
+
migrationsDir: "migrations",
|
|
371
|
+
coreReadTables: ["issues"],
|
|
372
|
+
}
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
Declare `database.namespace.migrate` and `database.namespace.read`; add
|
|
376
|
+
`database.namespace.write` when the worker needs runtime writes. Migrations run
|
|
377
|
+
before worker startup, are checksum-recorded, and may create or alter objects
|
|
378
|
+
only inside the plugin namespace. Runtime `ctx.db.query()` allows `SELECT` from
|
|
379
|
+
`ctx.db.namespace` plus manifest-whitelisted `public` core tables. Runtime
|
|
380
|
+
`ctx.db.execute()` allows `INSERT`, `UPDATE`, and `DELETE` only against the
|
|
381
|
+
plugin namespace.
|
|
382
|
+
|
|
383
|
+
### Trusted Local Folders
|
|
384
|
+
|
|
385
|
+
Trusted local plugins can request operator-configured folders per company:
|
|
386
|
+
|
|
387
|
+
```ts
|
|
388
|
+
export const manifest = {
|
|
389
|
+
// ...
|
|
390
|
+
capabilities: ["local.folders"],
|
|
391
|
+
localFolders: [
|
|
392
|
+
{
|
|
393
|
+
folderKey: "content-root",
|
|
394
|
+
displayName: "Content root",
|
|
395
|
+
access: "readWrite",
|
|
396
|
+
requiredDirectories: ["sources", "pages"],
|
|
397
|
+
requiredFiles: ["schema.md"],
|
|
398
|
+
},
|
|
399
|
+
],
|
|
400
|
+
};
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
The host stores the selected path in company-scoped plugin settings and exposes
|
|
404
|
+
readiness through:
|
|
405
|
+
|
|
406
|
+
- `GET /api/plugins/:pluginId/companies/:companyId/local-folders`
|
|
407
|
+
- `GET /api/plugins/:pluginId/companies/:companyId/local-folders/:folderKey/status`
|
|
408
|
+
- `POST /api/plugins/:pluginId/companies/:companyId/local-folders/:folderKey/validate`
|
|
409
|
+
- `PUT /api/plugins/:pluginId/companies/:companyId/local-folders/:folderKey`
|
|
410
|
+
|
|
411
|
+
Worker code should access files through `ctx.localFolders.readText()` and
|
|
412
|
+
`ctx.localFolders.writeTextAtomic()`. Relative paths must stay inside the
|
|
413
|
+
configured root; symlinks that escape the root are rejected.
|
|
414
|
+
|
|
415
|
+
### Scoped API Routes
|
|
416
|
+
|
|
417
|
+
Manifest-declared `apiRoutes` expose JSON routes under
|
|
418
|
+
`/api/plugins/:pluginId/api/*` without letting a plugin claim core paths:
|
|
419
|
+
|
|
420
|
+
```ts
|
|
421
|
+
apiRoutes: [
|
|
422
|
+
{
|
|
423
|
+
routeKey: "initialize",
|
|
424
|
+
method: "POST",
|
|
425
|
+
path: "/issues/:issueId/smoke",
|
|
426
|
+
auth: "board-or-agent",
|
|
427
|
+
capability: "api.routes.register",
|
|
428
|
+
checkoutPolicy: "required-for-agent-in-progress",
|
|
429
|
+
companyResolution: { from: "issue", param: "issueId" },
|
|
430
|
+
},
|
|
431
|
+
]
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
Implement `onApiRequest(input)` in the worker to handle the route. The host
|
|
435
|
+
performs auth, company access, capability, route matching, and checkout policy
|
|
436
|
+
before dispatch. The worker receives route params, query, parsed JSON body,
|
|
437
|
+
sanitized headers, actor context, and `companyId`; responses are JSON `{ status?,
|
|
438
|
+
headers?, body? }`.
|
|
439
|
+
|
|
440
|
+
## Issue Orchestration APIs
|
|
441
|
+
|
|
442
|
+
Workflow plugins can use `ctx.issues` for orchestration-grade issue operations without importing host server internals.
|
|
443
|
+
|
|
444
|
+
Expanded create/update fields include blockers, billing code, board or agent assignees, labels, namespaced plugin origins, request depth, and safe execution workspace fields:
|
|
445
|
+
|
|
446
|
+
```ts
|
|
447
|
+
const child = await ctx.issues.create({
|
|
448
|
+
companyId,
|
|
449
|
+
parentId: missionIssueId,
|
|
450
|
+
inheritExecutionWorkspaceFromIssueId: missionIssueId,
|
|
451
|
+
title: "Implement feature slice",
|
|
452
|
+
status: "todo",
|
|
453
|
+
assigneeAgentId: workerAgentId,
|
|
454
|
+
billingCode: "mission:alpha",
|
|
455
|
+
originKind: "plugin:evermore.missions:feature",
|
|
456
|
+
originId: "mission-alpha:feature-1",
|
|
457
|
+
blockedByIssueIds: [planningIssueId],
|
|
458
|
+
});
|
|
459
|
+
```
|
|
460
|
+
|
|
461
|
+
If `originKind` is omitted, the host stores `plugin:<pluginKey>`. Plugins may use sub-kinds such as `plugin:<pluginKey>:feature`, but the host rejects attempts to set another plugin's namespace.
|
|
462
|
+
|
|
463
|
+
Blocker relationships are also exposed as first-class helpers:
|
|
464
|
+
|
|
465
|
+
```ts
|
|
466
|
+
const relations = await ctx.issues.relations.get(child.id, companyId);
|
|
467
|
+
await ctx.issues.relations.setBlockedBy(child.id, [planningIssueId], companyId);
|
|
468
|
+
await ctx.issues.relations.addBlockers(child.id, [validationIssueId], companyId);
|
|
469
|
+
await ctx.issues.relations.removeBlockers(child.id, [planningIssueId], companyId);
|
|
470
|
+
```
|
|
471
|
+
|
|
472
|
+
Subtree reads can include just the issue tree, or compact related data for orchestration dashboards:
|
|
473
|
+
|
|
474
|
+
```ts
|
|
475
|
+
const subtree = await ctx.issues.getSubtree(missionIssueId, companyId, {
|
|
476
|
+
includeRoot: true,
|
|
477
|
+
includeRelations: true,
|
|
478
|
+
includeDocuments: true,
|
|
479
|
+
includeActiveRuns: true,
|
|
480
|
+
includeAssignees: true,
|
|
481
|
+
});
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
Agent-run actions can assert checkout ownership before mutating in-progress work:
|
|
485
|
+
|
|
486
|
+
```ts
|
|
487
|
+
await ctx.issues.assertCheckoutOwner({
|
|
488
|
+
issueId,
|
|
489
|
+
companyId,
|
|
490
|
+
actorAgentId: runCtx.agentId,
|
|
491
|
+
actorRunId: runCtx.runId,
|
|
492
|
+
});
|
|
493
|
+
```
|
|
494
|
+
|
|
495
|
+
Plugins can request assignment wakeups through the host so budget stops, execution locks, blocker checks, and heartbeat policy still apply:
|
|
496
|
+
|
|
497
|
+
```ts
|
|
498
|
+
await ctx.issues.requestWakeup(child.id, companyId, {
|
|
499
|
+
reason: "mission_advance",
|
|
500
|
+
contextSource: "missions.advance",
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
await ctx.issues.requestWakeups([featureIssueId, validationIssueId], companyId, {
|
|
504
|
+
reason: "mission_advance",
|
|
505
|
+
contextSource: "missions.advance",
|
|
506
|
+
idempotencyKeyPrefix: `mission:${missionIssueId}:advance`,
|
|
507
|
+
});
|
|
508
|
+
```
|
|
509
|
+
|
|
510
|
+
Use `ctx.issues.summaries.getOrchestration()` when a workflow needs compact reads across a root issue or subtree:
|
|
511
|
+
|
|
512
|
+
```ts
|
|
513
|
+
const summary = await ctx.issues.summaries.getOrchestration({
|
|
514
|
+
issueId: missionIssueId,
|
|
515
|
+
companyId,
|
|
516
|
+
includeSubtree: true,
|
|
517
|
+
billingCode: "mission:alpha",
|
|
518
|
+
});
|
|
519
|
+
```
|
|
520
|
+
|
|
521
|
+
Required capabilities:
|
|
522
|
+
|
|
523
|
+
| API | Capability |
|
|
524
|
+
|-----|------------|
|
|
525
|
+
| `ctx.issues.relations.get` | `issue.relations.read` |
|
|
526
|
+
| `ctx.issues.relations.setBlockedBy` / `addBlockers` / `removeBlockers` | `issue.relations.write` |
|
|
527
|
+
| `ctx.issues.getSubtree` | `issue.subtree.read` |
|
|
528
|
+
| `ctx.issues.assertCheckoutOwner` | `issues.checkout` |
|
|
529
|
+
| `ctx.issues.requestWakeup` / `requestWakeups` | `issues.wakeup` |
|
|
530
|
+
| `ctx.issues.summaries.getOrchestration` | `issues.orchestration.read` |
|
|
531
|
+
|
|
532
|
+
Plugin-originated mutations are logged with `actorType: "plugin"` and details fields `sourcePluginId`, `sourcePluginKey`, `initiatingActorType`, `initiatingActorId`, and `initiatingRunId` when a user or agent run initiated the plugin work.
|
|
533
|
+
|
|
534
|
+
## UI quick start
|
|
535
|
+
|
|
536
|
+
```tsx
|
|
537
|
+
import { usePluginData, usePluginAction } from "@evermore.work/plugin-sdk/ui";
|
|
538
|
+
|
|
539
|
+
export function DashboardWidget() {
|
|
540
|
+
const { data } = usePluginData<{ status: string }>("health");
|
|
541
|
+
const ping = usePluginAction("ping");
|
|
542
|
+
return (
|
|
543
|
+
<div style={{ display: "grid", gap: 8 }}>
|
|
544
|
+
<strong>Health</strong>
|
|
545
|
+
<div>{data?.status ?? "unknown"}</div>
|
|
546
|
+
<button onClick={() => void ping()}>Ping</button>
|
|
547
|
+
</div>
|
|
548
|
+
);
|
|
549
|
+
}
|
|
550
|
+
```
|
|
551
|
+
|
|
552
|
+
### Hooks reference
|
|
553
|
+
|
|
554
|
+
#### `usePluginData<T>(key, params?)`
|
|
555
|
+
|
|
556
|
+
Fetches data from the worker's registered `getData` handler. Re-fetches when `params` changes. Returns `{ data, loading, error, refresh }`.
|
|
557
|
+
|
|
558
|
+
```tsx
|
|
559
|
+
import { usePluginData } from "@evermore.work/plugin-sdk/ui";
|
|
560
|
+
|
|
561
|
+
interface SyncStatus {
|
|
562
|
+
lastSyncAt: string;
|
|
563
|
+
syncedCount: number;
|
|
564
|
+
healthy: boolean;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
export function SyncStatusWidget({ context }: PluginWidgetProps) {
|
|
568
|
+
const { data, loading, error, refresh } = usePluginData<SyncStatus>("sync-status", {
|
|
569
|
+
companyId: context.companyId,
|
|
570
|
+
});
|
|
571
|
+
|
|
572
|
+
if (loading) return <div>Loading…</div>;
|
|
573
|
+
if (error) return <div>Error: {error.message}</div>;
|
|
574
|
+
|
|
575
|
+
return (
|
|
576
|
+
<div>
|
|
577
|
+
<p>Status: {data!.healthy ? "Healthy" : "Unhealthy"}</p>
|
|
578
|
+
<p>Synced {data!.syncedCount} items</p>
|
|
579
|
+
<p>Last sync: {data!.lastSyncAt}</p>
|
|
580
|
+
<button onClick={refresh}>Refresh</button>
|
|
581
|
+
</div>
|
|
582
|
+
);
|
|
583
|
+
}
|
|
584
|
+
```
|
|
585
|
+
|
|
586
|
+
#### `usePluginAction(key)`
|
|
587
|
+
|
|
588
|
+
Returns an async function that calls the worker's `performAction` handler. Throws `PluginBridgeError` on failure.
|
|
589
|
+
|
|
590
|
+
```tsx
|
|
591
|
+
import { useState } from "react";
|
|
592
|
+
import { usePluginAction, type PluginBridgeError } from "@evermore.work/plugin-sdk/ui";
|
|
593
|
+
|
|
594
|
+
export function ResyncButton({ context }: PluginWidgetProps) {
|
|
595
|
+
const resync = usePluginAction("resync");
|
|
596
|
+
const [busy, setBusy] = useState(false);
|
|
597
|
+
const [error, setError] = useState<string | null>(null);
|
|
598
|
+
|
|
599
|
+
async function handleClick() {
|
|
600
|
+
setBusy(true);
|
|
601
|
+
setError(null);
|
|
602
|
+
try {
|
|
603
|
+
await resync({ companyId: context.companyId });
|
|
604
|
+
} catch (err) {
|
|
605
|
+
setError((err as PluginBridgeError).message);
|
|
606
|
+
} finally {
|
|
607
|
+
setBusy(false);
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
return (
|
|
612
|
+
<div>
|
|
613
|
+
<button onClick={handleClick} disabled={busy}>
|
|
614
|
+
{busy ? "Syncing..." : "Resync Now"}
|
|
615
|
+
</button>
|
|
616
|
+
{error && <p style={{ color: "red" }}>{error}</p>}
|
|
617
|
+
</div>
|
|
618
|
+
);
|
|
619
|
+
}
|
|
620
|
+
```
|
|
621
|
+
|
|
622
|
+
#### `useHostContext()`
|
|
623
|
+
|
|
624
|
+
Reads the active company, project, entity, and user context. Use this to scope data fetches and actions.
|
|
625
|
+
|
|
626
|
+
```tsx
|
|
627
|
+
import { useHostContext, usePluginData } from "@evermore.work/plugin-sdk/ui";
|
|
628
|
+
import type { PluginDetailTabProps } from "@evermore.work/plugin-sdk/ui";
|
|
629
|
+
|
|
630
|
+
export function IssueLinearLink({ context }: PluginDetailTabProps) {
|
|
631
|
+
const { companyId, entityId, entityType } = context;
|
|
632
|
+
const { data } = usePluginData<{ url: string }>("linear-link", {
|
|
633
|
+
companyId,
|
|
634
|
+
issueId: entityId,
|
|
635
|
+
});
|
|
636
|
+
|
|
637
|
+
if (!data?.url) return <p>No linked Linear issue.</p>;
|
|
638
|
+
return <a href={data.url} target="_blank" rel="noopener">View in Linear</a>;
|
|
639
|
+
}
|
|
640
|
+
```
|
|
641
|
+
|
|
642
|
+
#### `useHostNavigation()`
|
|
643
|
+
|
|
644
|
+
Routes Evermore-internal plugin links through the host router without a full document reload. Use `linkProps()` for anchors so the browser still gets a real `href` for copy-link, modifier-click, middle-click, and open-in-new-tab behavior.
|
|
645
|
+
|
|
646
|
+
```tsx
|
|
647
|
+
import { useHostNavigation } from "@evermore.work/plugin-sdk/ui";
|
|
648
|
+
|
|
649
|
+
export function WikiSidebarLink() {
|
|
650
|
+
const hostNavigation = useHostNavigation();
|
|
651
|
+
return <a {...hostNavigation.linkProps("/wiki")}>Wiki</a>;
|
|
652
|
+
}
|
|
653
|
+
```
|
|
654
|
+
|
|
655
|
+
`linkProps("/wiki")` resolves against the active company prefix, so in company `EVR` it renders `href="/EVR/wiki"`. Already-prefixed paths such as `/EVR/wiki` are not prefixed again. For button-style commands, call `hostNavigation.navigate("/issues/EVR-123")`.
|
|
656
|
+
|
|
657
|
+
Avoid raw same-origin `href`s or `window.location.assign()` for Evermore-internal navigation from plugin UI. Those bypass the host router and can reload the whole app. External links should keep normal anchors with `target="_blank"` and `rel="noopener noreferrer"` as appropriate.
|
|
658
|
+
|
|
659
|
+
#### `usePluginStream<T>(channel, options?)`
|
|
660
|
+
|
|
661
|
+
Subscribes to a real-time event stream pushed from the plugin worker via SSE. The worker pushes events using `ctx.streams.emit(channel, event)` and the hook receives them as they arrive. Returns `{ events, lastEvent, connecting, connected, error, close }`.
|
|
662
|
+
|
|
663
|
+
```tsx
|
|
664
|
+
import { usePluginStream } from "@evermore.work/plugin-sdk/ui";
|
|
665
|
+
|
|
666
|
+
interface ChatToken {
|
|
667
|
+
text: string;
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
export function ChatMessages({ context }: PluginWidgetProps) {
|
|
671
|
+
const { events, connected, close } = usePluginStream<ChatToken>("chat-stream", {
|
|
672
|
+
companyId: context.companyId ?? undefined,
|
|
673
|
+
});
|
|
674
|
+
|
|
675
|
+
return (
|
|
676
|
+
<div>
|
|
677
|
+
{events.map((e, i) => <span key={i}>{e.text}</span>)}
|
|
678
|
+
{connected && <span className="pulse" />}
|
|
679
|
+
<button onClick={close}>Stop</button>
|
|
680
|
+
</div>
|
|
681
|
+
);
|
|
682
|
+
}
|
|
683
|
+
```
|
|
684
|
+
|
|
685
|
+
The SSE connection targets `GET /api/plugins/:pluginId/bridge/stream/:channel?companyId=...`. The host bridge manages the EventSource lifecycle; `close()` terminates the connection.
|
|
686
|
+
|
|
687
|
+
### UI authoring note
|
|
688
|
+
|
|
689
|
+
The host provides selected shared UI components through `@evermore.work/plugin-sdk/ui`.
|
|
690
|
+
Plugins can also use normal React components, their own CSS, or small design
|
|
691
|
+
primitives inside the plugin package.
|
|
692
|
+
|
|
693
|
+
Use the shared components when the plugin needs to look and behave like a native
|
|
694
|
+
Evermore surface:
|
|
695
|
+
|
|
696
|
+
| Component | Use when |
|
|
697
|
+
|---|---|
|
|
698
|
+
| `MarkdownBlock` | Rendering markdown from plugin or host data |
|
|
699
|
+
| `MarkdownEditor` | Editing markdown with the host editor treatment |
|
|
700
|
+
| `FileTree` | Showing serializable workspace/wiki/import paths |
|
|
701
|
+
| `IssuesList` | Embedding a company-scoped native issue list |
|
|
702
|
+
| `AssigneePicker` | Selecting an agent or board user with the same picker as the new issue pane |
|
|
703
|
+
| `ProjectPicker` | Selecting a project with the same picker as the new issue pane |
|
|
704
|
+
| `ManagedRoutinesList` | Showing plugin-managed routines in settings UI |
|
|
705
|
+
|
|
706
|
+
#### Shared Markdown Components
|
|
707
|
+
|
|
708
|
+
Plugin UI can render markdown and edit markdown using the same host components
|
|
709
|
+
used by Evermore issue comments and documents:
|
|
710
|
+
|
|
711
|
+
```tsx
|
|
712
|
+
import { MarkdownBlock, MarkdownEditor } from "@evermore.work/plugin-sdk/ui";
|
|
713
|
+
|
|
714
|
+
export function WikiPageEditor() {
|
|
715
|
+
const [body, setBody] = useState("# Wiki page");
|
|
716
|
+
|
|
717
|
+
return (
|
|
718
|
+
<>
|
|
719
|
+
<MarkdownBlock content={body} />
|
|
720
|
+
<MarkdownEditor value={body} onChange={setBody} bordered />
|
|
721
|
+
</>
|
|
722
|
+
);
|
|
723
|
+
}
|
|
724
|
+
```
|
|
725
|
+
|
|
726
|
+
`MarkdownBlock` can opt into Obsidian-style wikilinks when a plugin owns the
|
|
727
|
+
target URL shape:
|
|
728
|
+
|
|
729
|
+
```tsx
|
|
730
|
+
<MarkdownBlock
|
|
731
|
+
content={"See [[wiki/entities/evermore|Evermore]]."}
|
|
732
|
+
enableWikiLinks
|
|
733
|
+
wikiLinkRoot="/wiki/page"
|
|
734
|
+
/>
|
|
735
|
+
```
|
|
736
|
+
|
|
737
|
+
#### Shared FileTree
|
|
738
|
+
|
|
739
|
+
Plugin UI can render the host file tree without importing host internals:
|
|
740
|
+
|
|
741
|
+
```tsx
|
|
742
|
+
import { FileTree, type FileTreeNode } from "@evermore.work/plugin-sdk/ui";
|
|
743
|
+
|
|
744
|
+
const nodes: FileTreeNode[] = [
|
|
745
|
+
{ name: "AGENTS.md", path: "AGENTS.md", kind: "file", children: [] },
|
|
746
|
+
{
|
|
747
|
+
name: "wiki",
|
|
748
|
+
path: "wiki",
|
|
749
|
+
kind: "dir",
|
|
750
|
+
children: [
|
|
751
|
+
{ name: "index.md", path: "wiki/index.md", kind: "file", children: [] },
|
|
752
|
+
],
|
|
753
|
+
},
|
|
754
|
+
];
|
|
755
|
+
|
|
756
|
+
export function WikiFiles() {
|
|
757
|
+
return (
|
|
758
|
+
<FileTree
|
|
759
|
+
nodes={nodes}
|
|
760
|
+
expandedPaths={["wiki"]}
|
|
761
|
+
selectedFile="wiki/index.md"
|
|
762
|
+
onToggleDir={(path) => console.log("toggle", path)}
|
|
763
|
+
onSelectFile={(path) => console.log("select", path)}
|
|
764
|
+
/>
|
|
765
|
+
);
|
|
766
|
+
}
|
|
767
|
+
```
|
|
768
|
+
|
|
769
|
+
#### Shared Assignee and Project Pickers
|
|
770
|
+
|
|
771
|
+
Use `AssigneePicker` and `ProjectPicker` when a plugin needs to create, filter,
|
|
772
|
+
or configure work against Evermore entities. Both are controlled components and
|
|
773
|
+
load their options from the host for the provided company.
|
|
774
|
+
|
|
775
|
+
```tsx
|
|
776
|
+
import { AssigneePicker, ProjectPicker } from "@evermore.work/plugin-sdk/ui";
|
|
777
|
+
|
|
778
|
+
export function AssignmentControls({ companyId }: { companyId: string }) {
|
|
779
|
+
const [assignee, setAssignee] = useState("");
|
|
780
|
+
const [projectId, setProjectId] = useState("");
|
|
781
|
+
|
|
782
|
+
return (
|
|
783
|
+
<>
|
|
784
|
+
<AssigneePicker
|
|
785
|
+
companyId={companyId}
|
|
786
|
+
value={assignee}
|
|
787
|
+
onChange={(value, selection) => {
|
|
788
|
+
setAssignee(value);
|
|
789
|
+
console.log(selection.assigneeAgentId, selection.assigneeUserId);
|
|
790
|
+
}}
|
|
791
|
+
/>
|
|
792
|
+
<ProjectPicker
|
|
793
|
+
companyId={companyId}
|
|
794
|
+
value={projectId}
|
|
795
|
+
onChange={setProjectId}
|
|
796
|
+
/>
|
|
797
|
+
</>
|
|
798
|
+
);
|
|
799
|
+
}
|
|
800
|
+
```
|
|
801
|
+
|
|
802
|
+
### Slot component props
|
|
803
|
+
|
|
804
|
+
Each slot type receives a typed props object with `context: PluginHostContext`. Import from `@evermore.work/plugin-sdk/ui`.
|
|
805
|
+
|
|
806
|
+
| Slot type | Props interface | `context` extras |
|
|
807
|
+
|-----------|----------------|------------------|
|
|
808
|
+
| `page` | `PluginPageProps` | — |
|
|
809
|
+
| `sidebar` | `PluginSidebarProps` | — |
|
|
810
|
+
| `routeSidebar` | `PluginRouteSidebarProps` | — |
|
|
811
|
+
| `settingsPage` | `PluginSettingsPageProps` | — |
|
|
812
|
+
| `dashboardWidget` | `PluginWidgetProps` | — |
|
|
813
|
+
| `globalToolbarButton` | `PluginGlobalToolbarButtonProps` | — |
|
|
814
|
+
| `detailTab` | `PluginDetailTabProps` | `entityId: string`, `entityType: string` |
|
|
815
|
+
| `toolbarButton` | `PluginToolbarButtonProps` | `entityId: string`, `entityType: string` |
|
|
816
|
+
| `commentAnnotation` | `PluginCommentAnnotationProps` | `entityId: string`, `entityType: "comment"`, `parentEntityId: string`, `projectId`, `companyPrefix` |
|
|
817
|
+
| `commentContextMenuItem` | `PluginCommentContextMenuItemProps` | `entityId: string`, `entityType: "comment"`, `parentEntityId: string`, `projectId`, `companyPrefix` |
|
|
818
|
+
| `projectSidebarItem` | `PluginProjectSidebarItemProps` | `entityId: string`, `entityType: "project"` |
|
|
819
|
+
|
|
820
|
+
Example detail tab with entity context:
|
|
821
|
+
|
|
822
|
+
```tsx
|
|
823
|
+
import type { PluginDetailTabProps } from "@evermore.work/plugin-sdk/ui";
|
|
824
|
+
import { usePluginData } from "@evermore.work/plugin-sdk/ui";
|
|
825
|
+
|
|
826
|
+
export function AgentMetricsTab({ context }: PluginDetailTabProps) {
|
|
827
|
+
const { data, loading } = usePluginData<Record<string, string>>("agent-metrics", {
|
|
828
|
+
agentId: context.entityId,
|
|
829
|
+
companyId: context.companyId,
|
|
830
|
+
});
|
|
831
|
+
|
|
832
|
+
if (loading) return <div>Loading…</div>;
|
|
833
|
+
if (!data) return <p>No metrics available.</p>;
|
|
834
|
+
|
|
835
|
+
return (
|
|
836
|
+
<dl>
|
|
837
|
+
{Object.entries(data).map(([label, value]) => (
|
|
838
|
+
<div key={label}>
|
|
839
|
+
<dt>{label}</dt>
|
|
840
|
+
<dd>{value}</dd>
|
|
841
|
+
</div>
|
|
842
|
+
))}
|
|
843
|
+
</dl>
|
|
844
|
+
);
|
|
845
|
+
}
|
|
846
|
+
```
|
|
847
|
+
|
|
848
|
+
## Launcher surfaces and modals
|
|
849
|
+
|
|
850
|
+
V1 does not provide a dedicated `modal` slot. Plugins can either:
|
|
851
|
+
|
|
852
|
+
- declare concrete UI mount points in `ui.slots`
|
|
853
|
+
- declare host-rendered entry points in `ui.launchers`
|
|
854
|
+
|
|
855
|
+
Supported launcher placement zones currently mirror the major host surfaces such as `projectSidebarItem`, `globalToolbarButton`, `toolbarButton`, `detailTab`, `settingsPage`, and `contextMenuItem`. Plugins may still open their own local modal from those entry points when needed.
|
|
856
|
+
|
|
857
|
+
Declarative launcher example:
|
|
858
|
+
|
|
859
|
+
```json
|
|
860
|
+
{
|
|
861
|
+
"ui": {
|
|
862
|
+
"launchers": [
|
|
863
|
+
{
|
|
864
|
+
"id": "sync-project",
|
|
865
|
+
"displayName": "Sync",
|
|
866
|
+
"placementZone": "toolbarButton",
|
|
867
|
+
"entityTypes": ["project"],
|
|
868
|
+
"action": {
|
|
869
|
+
"type": "openDrawer",
|
|
870
|
+
"target": "sync-project"
|
|
871
|
+
},
|
|
872
|
+
"render": {
|
|
873
|
+
"environment": "hostOverlay",
|
|
874
|
+
"bounds": "wide"
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
]
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
```
|
|
881
|
+
|
|
882
|
+
The host returns launcher metadata from `GET /api/plugins/ui-contributions` alongside slot declarations.
|
|
883
|
+
|
|
884
|
+
When a launcher opens a host-owned overlay or page, `useHostContext()`,
|
|
885
|
+
`usePluginData()`, and `usePluginAction()` receive the current
|
|
886
|
+
`renderEnvironment` through the bridge. Use that to tailor compact modal UI vs.
|
|
887
|
+
full-page layouts without adding custom route parsing in the plugin.
|
|
888
|
+
|
|
889
|
+
## Project sidebar item
|
|
890
|
+
|
|
891
|
+
Plugins can add a link under each project in the sidebar via the `projectSidebarItem` slot. This is the recommended slot-based launcher pattern for project-scoped workflows because it can deep-link into a richer plugin tab. The component is rendered once per project with that project’s id in `context.entityId`. Declare the slot and capability in your manifest:
|
|
892
|
+
|
|
893
|
+
```json
|
|
894
|
+
{
|
|
895
|
+
"ui": {
|
|
896
|
+
"slots": [
|
|
897
|
+
{
|
|
898
|
+
"type": "projectSidebarItem",
|
|
899
|
+
"id": "files",
|
|
900
|
+
"displayName": "Files",
|
|
901
|
+
"exportName": "FilesLink",
|
|
902
|
+
"entityTypes": ["project"]
|
|
903
|
+
}
|
|
904
|
+
]
|
|
905
|
+
},
|
|
906
|
+
"capabilities": ["ui.sidebar.register", "ui.detailTab.register"]
|
|
907
|
+
}
|
|
908
|
+
```
|
|
909
|
+
|
|
910
|
+
Minimal React component that links to the project’s plugin tab (see project detail tabs in the spec):
|
|
911
|
+
|
|
912
|
+
```tsx
|
|
913
|
+
import {
|
|
914
|
+
useHostNavigation,
|
|
915
|
+
type PluginProjectSidebarItemProps,
|
|
916
|
+
} from "@evermore.work/plugin-sdk/ui";
|
|
917
|
+
|
|
918
|
+
export function FilesLink({ context }: PluginProjectSidebarItemProps) {
|
|
919
|
+
const hostNavigation = useHostNavigation();
|
|
920
|
+
const projectId = context.entityId;
|
|
921
|
+
const projectRef = projectId; // or resolve from host; entityId is project id
|
|
922
|
+
return (
|
|
923
|
+
<a {...hostNavigation.linkProps(`/projects/${projectRef}?tab=plugin:your-plugin:files`)}>
|
|
924
|
+
Files
|
|
925
|
+
</a>
|
|
926
|
+
);
|
|
927
|
+
}
|
|
928
|
+
```
|
|
929
|
+
|
|
930
|
+
Use optional `order` in the slot to sort among other project sidebar items. See §19.5.1 in the plugin spec and project detail plugin tabs (§19.3) for the full flow.
|
|
931
|
+
|
|
932
|
+
## Toolbar launcher with a local modal
|
|
933
|
+
|
|
934
|
+
Two toolbar slot types are available depending on where the button should appear:
|
|
935
|
+
|
|
936
|
+
- **`globalToolbarButton`** — renders in the top bar on every page, scoped to the company. No entity context. Use for workspace-wide actions.
|
|
937
|
+
- **`toolbarButton`** — renders on entity detail pages (project, issue, etc.). Receives `entityId` and `entityType`. Declare `entityTypes` to control which pages the button appears on.
|
|
938
|
+
|
|
939
|
+
For short-lived actions, mount the appropriate slot type and open a plugin-owned modal inside the component. Use `useHostContext()` to scope the action to the current company or entity.
|
|
940
|
+
|
|
941
|
+
Project-scoped example (appears only on project detail pages):
|
|
942
|
+
|
|
943
|
+
```json
|
|
944
|
+
{
|
|
945
|
+
"ui": {
|
|
946
|
+
"slots": [
|
|
947
|
+
{
|
|
948
|
+
"type": "toolbarButton",
|
|
949
|
+
"id": "sync-toolbar-button",
|
|
950
|
+
"displayName": "Sync",
|
|
951
|
+
"exportName": "SyncToolbarButton",
|
|
952
|
+
"entityTypes": ["project"]
|
|
953
|
+
}
|
|
954
|
+
]
|
|
955
|
+
},
|
|
956
|
+
"capabilities": ["ui.action.register"]
|
|
957
|
+
}
|
|
958
|
+
```
|
|
959
|
+
|
|
960
|
+
```tsx
|
|
961
|
+
import { useState } from "react";
|
|
962
|
+
import {
|
|
963
|
+
useHostContext,
|
|
964
|
+
usePluginAction,
|
|
965
|
+
} from "@evermore.work/plugin-sdk/ui";
|
|
966
|
+
|
|
967
|
+
export function SyncToolbarButton() {
|
|
968
|
+
const context = useHostContext();
|
|
969
|
+
const syncProject = usePluginAction("sync-project");
|
|
970
|
+
const [open, setOpen] = useState(false);
|
|
971
|
+
const [submitting, setSubmitting] = useState(false);
|
|
972
|
+
const [errorMessage, setErrorMessage] = useState<string | null>(null);
|
|
973
|
+
|
|
974
|
+
async function confirm() {
|
|
975
|
+
if (!context.projectId) return;
|
|
976
|
+
setSubmitting(true);
|
|
977
|
+
setErrorMessage(null);
|
|
978
|
+
try {
|
|
979
|
+
await syncProject({ projectId: context.projectId });
|
|
980
|
+
setOpen(false);
|
|
981
|
+
} catch (err) {
|
|
982
|
+
setErrorMessage(err instanceof Error ? err.message : "Sync failed");
|
|
983
|
+
} finally {
|
|
984
|
+
setSubmitting(false);
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
return (
|
|
989
|
+
<>
|
|
990
|
+
<button type="button" onClick={() => setOpen(true)}>
|
|
991
|
+
Sync
|
|
992
|
+
</button>
|
|
993
|
+
{open ? (
|
|
994
|
+
<div
|
|
995
|
+
role="dialog"
|
|
996
|
+
aria-modal="true"
|
|
997
|
+
className="fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4"
|
|
998
|
+
onClick={() => !submitting && setOpen(false)}
|
|
999
|
+
>
|
|
1000
|
+
<div
|
|
1001
|
+
className="w-full max-w-md rounded-lg bg-background p-4 shadow-xl"
|
|
1002
|
+
onClick={(event) => event.stopPropagation()}
|
|
1003
|
+
>
|
|
1004
|
+
<h2 className="text-base font-semibold">Sync this project?</h2>
|
|
1005
|
+
<p className="mt-2 text-sm text-muted-foreground">
|
|
1006
|
+
Queue a sync for <code>{context.projectId}</code>.
|
|
1007
|
+
</p>
|
|
1008
|
+
{errorMessage ? (
|
|
1009
|
+
<p className="mt-2 text-sm text-destructive">{errorMessage}</p>
|
|
1010
|
+
) : null}
|
|
1011
|
+
<div className="mt-4 flex justify-end gap-2">
|
|
1012
|
+
<button type="button" onClick={() => setOpen(false)}>
|
|
1013
|
+
Cancel
|
|
1014
|
+
</button>
|
|
1015
|
+
<button type="button" onClick={() => void confirm()} disabled={submitting}>
|
|
1016
|
+
{submitting ? "Running…" : "Run sync"}
|
|
1017
|
+
</button>
|
|
1018
|
+
</div>
|
|
1019
|
+
</div>
|
|
1020
|
+
</div>
|
|
1021
|
+
) : null}
|
|
1022
|
+
</>
|
|
1023
|
+
);
|
|
1024
|
+
}
|
|
1025
|
+
```
|
|
1026
|
+
|
|
1027
|
+
Prefer deep-linkable tabs and pages for primary workflows. Reserve plugin-owned modals for confirmations, pickers, and compact editors.
|
|
1028
|
+
|
|
1029
|
+
## Real-time streaming (`ctx.streams`)
|
|
1030
|
+
|
|
1031
|
+
Plugins can push real-time events from the worker to the UI using server-sent events (SSE). This is useful for streaming LLM tokens, live sync progress, or any push-based data.
|
|
1032
|
+
|
|
1033
|
+
### Worker side
|
|
1034
|
+
|
|
1035
|
+
In `setup()`, use `ctx.streams` to open a channel, emit events, and close when done:
|
|
1036
|
+
|
|
1037
|
+
```ts
|
|
1038
|
+
const plugin = definePlugin({
|
|
1039
|
+
async setup(ctx) {
|
|
1040
|
+
ctx.actions.register("chat", async (params) => {
|
|
1041
|
+
const companyId = params.companyId as string;
|
|
1042
|
+
ctx.streams.open("chat-stream", companyId);
|
|
1043
|
+
|
|
1044
|
+
for await (const token of streamFromLLM(params.prompt as string)) {
|
|
1045
|
+
ctx.streams.emit("chat-stream", { text: token });
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
ctx.streams.close("chat-stream");
|
|
1049
|
+
return { ok: true };
|
|
1050
|
+
});
|
|
1051
|
+
},
|
|
1052
|
+
});
|
|
1053
|
+
```
|
|
1054
|
+
|
|
1055
|
+
**API:**
|
|
1056
|
+
|
|
1057
|
+
| Method | Description |
|
|
1058
|
+
|--------|-------------|
|
|
1059
|
+
| `ctx.streams.open(channel, companyId)` | Open a named stream channel and associate it with a company. Sends a `streams.open` notification to the host. |
|
|
1060
|
+
| `ctx.streams.emit(channel, event)` | Push an event to the channel. The `companyId` is automatically resolved from the prior `open()` call. |
|
|
1061
|
+
| `ctx.streams.close(channel)` | Close the channel and clear the company mapping. Sends a `streams.close` notification. |
|
|
1062
|
+
|
|
1063
|
+
Stream notifications are fire-and-forget JSON-RPC messages (no `id` field). They are sent via `notifyHost()` synchronously during handler execution.
|
|
1064
|
+
|
|
1065
|
+
### UI side
|
|
1066
|
+
|
|
1067
|
+
Use the `usePluginStream` hook (see [Hooks reference](#usepluginstreamtchannel-options) above) to subscribe to events from the UI.
|
|
1068
|
+
|
|
1069
|
+
### Host-side architecture
|
|
1070
|
+
|
|
1071
|
+
The host maintains an in-memory `PluginStreamBus` that fans out worker notifications to connected SSE clients:
|
|
1072
|
+
|
|
1073
|
+
1. Worker emits `streams.emit` notification via stdout
|
|
1074
|
+
2. Host (`plugin-worker-manager`) receives the notification and publishes to `PluginStreamBus`
|
|
1075
|
+
3. SSE endpoint (`GET /api/plugins/:pluginId/bridge/stream/:channel?companyId=...`) subscribes to the bus and writes events to the response
|
|
1076
|
+
|
|
1077
|
+
The bus is keyed by `pluginId:channel:companyId`, so multiple UI clients can subscribe to the same stream independently.
|
|
1078
|
+
|
|
1079
|
+
### Streaming agent responses to the UI
|
|
1080
|
+
|
|
1081
|
+
`ctx.streams` and `ctx.agents.sessions` are complementary. The worker sits between them, relaying agent events to the browser in real time:
|
|
1082
|
+
|
|
1083
|
+
```
|
|
1084
|
+
UI ──usePluginAction──▶ Worker ──sessions.sendMessage──▶ Agent
|
|
1085
|
+
UI ◀──usePluginStream── Worker ◀──onEvent callback────── Agent
|
|
1086
|
+
```
|
|
1087
|
+
|
|
1088
|
+
The agent doesn't know about streams — the worker decides what to relay. Encode the agent ID in the channel name to scope streams per agent.
|
|
1089
|
+
|
|
1090
|
+
**Worker:**
|
|
1091
|
+
|
|
1092
|
+
```ts
|
|
1093
|
+
ctx.actions.register("ask-agent", async (params) => {
|
|
1094
|
+
const { agentId, companyId, prompt } = params as {
|
|
1095
|
+
agentId: string; companyId: string; prompt: string;
|
|
1096
|
+
};
|
|
1097
|
+
|
|
1098
|
+
const channel = `agent:${agentId}`;
|
|
1099
|
+
ctx.streams.open(channel, companyId);
|
|
1100
|
+
|
|
1101
|
+
const session = await ctx.agents.sessions.create(agentId, companyId);
|
|
1102
|
+
|
|
1103
|
+
await ctx.agents.sessions.sendMessage(session.sessionId, companyId, {
|
|
1104
|
+
prompt,
|
|
1105
|
+
onEvent: (event) => {
|
|
1106
|
+
ctx.streams.emit(channel, {
|
|
1107
|
+
type: event.eventType, // "chunk" | "done" | "error"
|
|
1108
|
+
text: event.message ?? "",
|
|
1109
|
+
});
|
|
1110
|
+
},
|
|
1111
|
+
});
|
|
1112
|
+
|
|
1113
|
+
ctx.streams.close(channel);
|
|
1114
|
+
return { sessionId: session.sessionId };
|
|
1115
|
+
});
|
|
1116
|
+
```
|
|
1117
|
+
|
|
1118
|
+
**UI:**
|
|
1119
|
+
|
|
1120
|
+
```tsx
|
|
1121
|
+
import { useState } from "react";
|
|
1122
|
+
import { usePluginAction, usePluginStream } from "@evermore.work/plugin-sdk/ui";
|
|
1123
|
+
|
|
1124
|
+
interface AgentEvent {
|
|
1125
|
+
type: "chunk" | "done" | "error";
|
|
1126
|
+
text: string;
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
export function AgentChat({ agentId, companyId }: { agentId: string; companyId: string }) {
|
|
1130
|
+
const askAgent = usePluginAction("ask-agent");
|
|
1131
|
+
const { events, connected, close } = usePluginStream<AgentEvent>(`agent:${agentId}`, { companyId });
|
|
1132
|
+
const [prompt, setPrompt] = useState("");
|
|
1133
|
+
|
|
1134
|
+
async function send() {
|
|
1135
|
+
setPrompt("");
|
|
1136
|
+
await askAgent({ agentId, companyId, prompt });
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
return (
|
|
1140
|
+
<div>
|
|
1141
|
+
<div>{events.filter(e => e.type === "chunk").map((e, i) => <span key={i}>{e.text}</span>)}</div>
|
|
1142
|
+
<input value={prompt} onChange={(e) => setPrompt(e.target.value)} />
|
|
1143
|
+
<button onClick={send}>Send</button>
|
|
1144
|
+
{connected && <button onClick={close}>Stop</button>}
|
|
1145
|
+
</div>
|
|
1146
|
+
);
|
|
1147
|
+
}
|
|
1148
|
+
```
|
|
1149
|
+
|
|
1150
|
+
## Agent sessions (two-way chat)
|
|
1151
|
+
|
|
1152
|
+
Plugins can hold multi-turn conversational sessions with agents:
|
|
1153
|
+
|
|
1154
|
+
```ts
|
|
1155
|
+
// Create a session
|
|
1156
|
+
const session = await ctx.agents.sessions.create(agentId, companyId);
|
|
1157
|
+
|
|
1158
|
+
// Send a message and stream the response
|
|
1159
|
+
await ctx.agents.sessions.sendMessage(session.sessionId, companyId, {
|
|
1160
|
+
prompt: "Help me triage this issue",
|
|
1161
|
+
onEvent: (event) => {
|
|
1162
|
+
if (event.eventType === "chunk") console.log(event.message);
|
|
1163
|
+
if (event.eventType === "done") console.log("Stream complete");
|
|
1164
|
+
},
|
|
1165
|
+
});
|
|
1166
|
+
|
|
1167
|
+
// List active sessions
|
|
1168
|
+
const sessions = await ctx.agents.sessions.list(agentId, companyId);
|
|
1169
|
+
|
|
1170
|
+
// Close when done
|
|
1171
|
+
await ctx.agents.sessions.close(session.sessionId, companyId);
|
|
1172
|
+
```
|
|
1173
|
+
|
|
1174
|
+
Requires capabilities: `agent.sessions.create`, `agent.sessions.list`, `agent.sessions.send`, `agent.sessions.close`.
|
|
1175
|
+
|
|
1176
|
+
Exported types: `AgentSession`, `AgentSessionEvent`, `AgentSessionSendResult`, `PluginAgentSessionsClient`.
|
|
1177
|
+
|
|
1178
|
+
## Testing utilities
|
|
1179
|
+
|
|
1180
|
+
```ts
|
|
1181
|
+
import { createTestHarness } from "@evermore.work/plugin-sdk/testing";
|
|
1182
|
+
import plugin from "../src/worker.js";
|
|
1183
|
+
import manifest from "../src/manifest.js";
|
|
1184
|
+
|
|
1185
|
+
const harness = createTestHarness({ manifest });
|
|
1186
|
+
await plugin.definition.setup(harness.ctx);
|
|
1187
|
+
await harness.emit("issue.created", { issueId: "iss_1" }, { entityId: "iss_1", entityType: "issue" });
|
|
1188
|
+
```
|
|
1189
|
+
|
|
1190
|
+
## Bundler presets
|
|
1191
|
+
|
|
1192
|
+
```ts
|
|
1193
|
+
import { createPluginBundlerPresets } from "@evermore.work/plugin-sdk/bundlers";
|
|
1194
|
+
|
|
1195
|
+
const presets = createPluginBundlerPresets({ uiEntry: "src/ui/index.tsx" });
|
|
1196
|
+
// presets.esbuild.worker / presets.esbuild.manifest / presets.esbuild.ui
|
|
1197
|
+
// presets.rollup.worker / presets.rollup.manifest / presets.rollup.ui
|
|
1198
|
+
```
|
|
1199
|
+
|
|
1200
|
+
## Local dev server (hot-reload events)
|
|
1201
|
+
|
|
1202
|
+
```bash
|
|
1203
|
+
evermore-plugin-dev-server --root . --ui-dir dist/ui --port 4177
|
|
1204
|
+
```
|
|
1205
|
+
|
|
1206
|
+
Or programmatically:
|
|
1207
|
+
|
|
1208
|
+
```ts
|
|
1209
|
+
import { startPluginDevServer } from "@evermore.work/plugin-sdk/dev-server";
|
|
1210
|
+
const server = await startPluginDevServer({ rootDir: process.cwd() });
|
|
1211
|
+
```
|
|
1212
|
+
|
|
1213
|
+
Dev server endpoints:
|
|
1214
|
+
- `GET /__evermore__/health` returns `{ ok, rootDir, uiDir }`
|
|
1215
|
+
- `GET /__evermore__/events` streams `reload` SSE events on UI build changes
|