# Plugin API reference (/docs/plugins/reference)

Look up an import or a field here. Each table is generated from the published packages' types. The list under it says
what each row is for. The [guides](/docs/plugins) show each one in use.

## What to import [#what-to-import]

| Import                                     | You import it when you                                       |
| ------------------------------------------ | ------------------------------------------------------------ |
| `@conciv/backend-plugin-api`               | write an engine part with async and await                    |
| `@conciv/backend-plugin-api/effect`        | write an engine part with Effect                             |
| `@conciv/backend-plugin-api/effect/plugin` | type a helper function that takes the Effect `ctx`           |
| `@conciv/backend-plugin-api/effect/rpc`    | type the registration your RPC handlers belong to, in Effect |
| `@conciv/protocol/schema/rpc`              | declare an RPC contract that both parts import               |
| `@conciv/protocol/schema/tool`             | fail a tool call with a `Tool.Error` in Effect               |
| `@conciv/frontend-plugin-api`              | write a browser part: panels, slots, pills, cards, settings  |
| `@conciv/frontend-plugin-api/vite`         | build a browser part into the bundle the engine serves       |
| `@conciv/react`                            | draw a browser part's UI with React components, in your app  |
| `@conciv/preact`                           | draw a browser part's UI with Preact components, in your app |
| `@conciv/client`                           | read data in a browser part through the widget's query cache |
| `@conciv/backend-test-utils`               | start a real engine in a test and script the agent           |

## Plugin.define [#plugindefine]

What the engine part's `Plugin.define` takes:

<Tabs groupId="plugin-api" persist items={['Promise', 'Effect']}>
<Tab value="Promise">

### $Fumadocs

| Prop    | Type                                                                | Description |
| ------- | ------------------------------------------------------------------- | ----------- |
| `id`    | `string`                                                            |             |
| `setup` | `(context: Context) => Promise<Cleanup \| void> \| Cleanup \| void` |             |

- `id`: the plugin's name. A config entry turns it off as `-<id>`.
- `setup`: runs once when the engine loads the plugin. It can return a cleanup that runs when the plugin unloads.

</Tab>
<Tab value="Effect">

### $Fumadocs

| Prop     | Type                                               | Description |
| -------- | -------------------------------------------------- | ----------- |
| `id`     | `string`                                           |             |
| `effect` | `(context: Context) => Effect<void, never, Scope>` |             |

- `id`: the plugin's name. A config entry turns it off as `-<id>`.
- `effect`: runs once when the engine loads the plugin. Its scope closes when the plugin unloads.

</Tab>
</Tabs>

What the browser part's `Plugin.define` takes:

### $Fumadocs

| Prop              | Type                                                                                                                                                                       | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `stores?`         | `Readonly<Record<string, StoreDeclaration<StoreSchema, "global" \| "project" \| "session">>> \| undefined`                                                                 |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| `icons?`          | `Readonly<Record<string, string>> \| undefined`                                                                                                                            | The plugin's own icons, by name, for artwork the app's icon catalog does not have. Each value is an SVG document as text, as a design tool exports it; a bundle built with `gui()` imports the file with `?raw`. The host registers them before setup, and `ctx.icons` gives each one's name for every SDK icon field and for `ctx.ui.Icon`. A value that is not an SVG document fails the plugin when it starts. - The document's `viewBox` frames the drawing, else its `width` and `height`. The host scales the drawing to the place that shows it, so draw on the app's 16px grid. - Draw with `currentColor`: the icon takes the color of the place that shows it, such as a pill's `tone`. - A drawing may move with SVG animation elements (`animate`, `animateTransform`). Every place that shows the icon moves in step, and the animation goes on while the host renders that place again. Under the user's reduced motion setting the host holds the icon on its first frame, so make that frame the resting drawing. - An `id` in the drawing is the whole window's; keep it unique, or leave it out. |
| `beforeRegister?` | `((options: PluginOptions) => void) \| undefined`                                                                                                                          | Runs once, synchronously, with the plugin's options, before any plugin's window setup: as soon as the host knows the plugin, which for a built-in is the top of the app's mount. For page-wide hooks that must exist before the host page's own code reads them. `enforce` orders the calls as Vite orders plugins: every `pre`, then those without, then every `post`. Return nothing; a throw is logged and the plugin still loads.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `enforce?`        | `Enforce \| undefined`                                                                                                                                                     |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| `setup?`          | `Setup<NoInfer<Declarations<Readonly<Record<string, StoreDeclaration<StoreSchema, "global" \| "project" \| "session">>>, Readonly<Record<string, string>>>>> \| undefined` |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |

- `stores`: values the widget keeps for the plugin. See [Add settings](/docs/plugins/guides/settings).
- `icons`: SVG icons of your own, named for `ctx.ui.Icon`.
- `beforeRegister`: runs once with the options, before any plugin's setup, for hooks the page needs early.
- `enforce`: orders `beforeRegister` calls: every `pre`, then the rest, then every `post`.
- `setup`: runs once when the widget loads the browser part. It has no `id`. It takes the engine part's.

## Engine ctx [#engine-ctx]

What `setup` or `effect` gets as `ctx`. In the Promise style each domain returns a `Promise`. In the Effect style the
same fields return an `Effect`.

<Tabs groupId="plugin-api" persist items={['Promise', 'Effect']}>
<Tab value="Promise">

### $Fumadocs

| Prop           | Type                                                                                                             | Description |
| -------------- | ---------------------------------------------------------------------------------------------------------------- | ----------- |
| `app`          | `App \| undefined`                                                                                               |             |
| `location`     | `Info`                                                                                                           |             |
| `options`      | `Readonly<Record<string, Json>>`                                                                                 |             |
| `agent`        | `AgentDomain`                                                                                                    |             |
| `bundler`      | `BundlerDomain`                                                                                                  |             |
| `credential`   | `CredentialDomain`                                                                                               |             |
| `event`        | `EventDomain`                                                                                                    |             |
| `experimental` | `{ readonly generate: ExperimentalGenerateApi \| undefined; }`                                                   |             |
| `integration`  | `IntegrationDomain`                                                                                              |             |
| `model`        | `ModelDomain`                                                                                                    |             |
| `permission`   | `PermissionDomain`                                                                                               |             |
| `plugin`       | `{ readonly list: (requestOptions?: RpcCallOptions) => Promise<{ location: PublicRef; data: PluginInfo[]; }>; }` |             |
| `rpc`          | `RpcDomain`                                                                                                      |             |
| `browserTabs`  | `BrowserTabDomain`                                                                                               |             |
| `job`          | `JobDomain`                                                                                                      |             |
| `session`      | `SessionDomain`                                                                                                  |             |
| `skill`        | `SkillDomain`                                                                                                    |             |
| `storage`      | `StorageDomain`                                                                                                  |             |
| `tool`         | `ToolDomain`                                                                                                     |             |
| `servers`      | `Servers`                                                                                                        |             |

</Tab>
<Tab value="Effect">

### $Fumadocs

| Prop           | Type                                                                                                                                                                                                          | Description |
| -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- |
| `app`          | `App`                                                                                                                                                                                                         |             |
| `location`     | `Info`                                                                                                                                                                                                        |             |
| `options`      | `Readonly<Record<string, Json>>`                                                                                                                                                                              |             |
| `agent`        | `AgentDomain`                                                                                                                                                                                                 |             |
| `bundler`      | `BundlerDomain`                                                                                                                                                                                               |             |
| `credential`   | `CredentialDomain`                                                                                                                                                                                            |             |
| `event`        | `EventDomain`                                                                                                                                                                                                 |             |
| `experimental` | `{ readonly generate: undefined; }`                                                                                                                                                                           |             |
| `integration`  | `IntegrationDomain`                                                                                                                                                                                           |             |
| `model`        | `ModelDomain`                                                                                                                                                                                                 |             |
| `permission`   | `PermissionDomain`                                                                                                                                                                                            |             |
| `plugin`       | `{ readonly list: (input?: { readonly location?: { readonly directory?: string \| undefined; } \| undefined; }) => Effect<{ readonly location: PublicRef; readonly data: ReadonlyArray<Info>; }, unknown>; }` |             |
| `rpc`          | `RpcDomain`                                                                                                                                                                                                   |             |
| `browserTabs`  | `BrowserTabDomain`                                                                                                                                                                                            |             |
| `job`          | `JobDomain`                                                                                                                                                                                                   |             |
| `session`      | `SessionDomain`                                                                                                                                                                                               |             |
| `skill`        | `SkillDomain`                                                                                                                                                                                                 |             |
| `storage`      | `StorageDomain`                                                                                                                                                                                               |             |
| `tool`         | `ToolDomain`                                                                                                                                                                                                  |             |
| `servers`      | `Servers`                                                                                                                                                                                                     |             |

</Tab>
</Tabs>

- `app`: the running conciv, with its version, release channel and platform.
- `location`: where the engine runs. Its `directory` is your project folder.
- `options`: the options from the plugin's config entry, as JSON.
- `agent`: change the agent profiles, such as their permission rules.
- `event`: follow the engine's events.
- `model`: list the models, and add or change them.
- `permission`: ask the user before an action. See [Ask for permission](/docs/plugins/guides/permission).
- `plugin`: list the plugins the engine loaded.
- `rpc`: answer an RPC contract, or call another plugin's. See [Share an RPC method](/docs/plugins/guides/rpc).
- `browserTabs`: list the browser tabs a session's page plugin sees.
- `job`: start, wait on and cancel background jobs.
- `session`: list, create and drive sessions.
- `skill`: add, change and remove skills. See [Add a skill](/docs/plugins/guides/skill).
- `storage`: a key-value store kept for your plugin, and a folder for its files.
- `tool`: add, change and remove tools, and hook into their calls. See [Add a tool](/docs/plugins/guides/tool).
- `servers`: the dev servers the engine knows about.
- `bundler`: hook into your app's bundler, with `resolveId`, `load` and `transform`.
- `experimental`: APIs that can still change. Its `generate` asks a model for text, decisions or an image. It is
  `undefined` in the Effect style.

## A tool [#a-tool]

What `tools.add` takes:

<Tabs groupId="plugin-api" persist items={['Promise', 'Effect']}>
<Tab value="Promise">

### $Fumadocs

| Prop          | Type                                                                                           | Description |
| ------------- | ---------------------------------------------------------------------------------------------- | ----------- |
| `name`        | `string`                                                                                       |             |
| `input`       | `ValueSchema<unknown>`                                                                         |             |
| `description` | `string`                                                                                       |             |
| `output?`     | `ValueSchema<unknown> \| undefined`                                                            |             |
| `options?`    | `Options \| undefined`                                                                         |             |
| `execute`     | `(input: unknown, context: ToolContext) => Promise<Result<ValueSchema<unknown> \| undefined>>` |             |

</Tab>
<Tab value="Effect">

### $Fumadocs

| Prop          | Type                                                                                            | Description |
| ------------- | ----------------------------------------------------------------------------------------------- | ----------- |
| `name`        | `string`                                                                                        |             |
| `input`       | `ValueSchema<any>`                                                                              |             |
| `description` | `string`                                                                                        |             |
| `execute`     | `(input: any, context: Context) => Effect<Result<ValueSchema<any> \| undefined>, Error, never>` |             |
| `output?`     | `ValueSchema<any> \| undefined`                                                                 |             |
| `options?`    | `Options \| undefined`                                                                          |             |

</Tab>
</Tabs>

- `name`: what the agent calls. Use letters, digits and `_`.
- `description`: how the agent decides when to call it.
- `input`: the schema the agent's input must match. The engine checks it before your code runs.
- `output`: the schema of the result's `output`.
- `options`: `codemode`, `namespace`, `permission` and `pinned`. See
  [Tools and code mode](/docs/tools-and-code-mode).
- `execute`: runs one call. It returns a `Promise` or an `Effect` of the result.

What `execute` gets as its second argument:

<Tabs groupId="plugin-api" persist items={['Promise', 'Effect']}>
<Tab value="Promise">

### $Fumadocs

| Prop        | Type                                                  | Description |
| ----------- | ----------------------------------------------------- | ----------- |
| `signal`    | `AbortSignal`                                         |             |
| `progress`  | `(update: Metadata) => Promise<void>`                 |             |
| `sessionId` | `string & $brand<"ConcivSessionId">`                  |             |
| `agent`     | `string & Brand<"Agent.ID">`                          |             |
| `messageId` | `(string & Brand<"Session.Message.ID">) \| undefined` |             |
| `id`        | `string & Brand<"Tool.CallID">`                       |             |
| `origin`    | `Origin`                                              |             |

</Tab>
<Tab value="Effect">

### $Fumadocs

| Prop        | Type                                                  | Description |
| ----------- | ----------------------------------------------------- | ----------- |
| `sessionId` | `string & $brand<"ConcivSessionId">`                  |             |
| `agent`     | `string & Brand<"Agent.ID">`                          |             |
| `messageId` | `(string & Brand<"Session.Message.ID">) \| undefined` |             |
| `id`        | `string & Brand<"Tool.CallID">`                       |             |
| `origin`    | `Origin`                                              |             |
| `progress`  | `(update: Metadata) => Effect<void>`                  |             |
| `cancel?`   | `Effect<void, never, never> \| undefined`             |             |

</Tab>
</Tabs>

- `sessionId`: the chat the call runs in.
- `agent`: the agent profile running the call.
- `messageId`: the agent message that holds the call, when there is one.
- `id`: the call's own id.
- `origin`: where the call came from: `chat` for the widget, `hub` for an agent outside it.
- `progress`: sends an update the card can show while the call runs.
- `signal` (Promise): aborts when the user stops the turn.
- `cancel` (Effect): set when the call can be cancelled.

What `execute` returns:

### $Fumadocs

| Prop        | Type                                                                                                                                                                                                    | Description |
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- |
| `output?`   | `any`                                                                                                                                                                                                   |             |
| `content?`  | `string \| readonly ({ readonly type: "text"; readonly text: string; } \| { readonly type: "file"; readonly uri: string; readonly mime: string; readonly name?: string \| undefined; })[] \| undefined` |             |
| `metadata?` | `Readonly<Record<string, any>> \| undefined`                                                                                                                                                            |             |

- `output`: the result the agent reads, matching the `output` schema.
- `content`: text or files for the agent, in place of or beside `output`.
- `metadata`: data for the card. The agent does not read it.

What `tools` is inside `ctx.tool.transform`:

<Tabs groupId="plugin-api" persist items={['Promise', 'Effect']}>
<Tab value="Promise">

### $Fumadocs

| Prop        | Type                                                                                                                   | Description |
| ----------- | ---------------------------------------------------------------------------------------------------------------------- | ----------- |
| `list`      | `() => readonly (Info & { readonly id: string; })[]`                                                                   |             |
| `get`       | `(id: string) => (Info & { readonly id: string; }) \| undefined`                                                       |             |
| `namespace` | `(namespace: Namespace) => void`                                                                                       |             |
| `add`       | `<Input extends ValueSchema, Output extends ValueSchema \| undefined>(tool: Info<Input, Output>) => void`              |             |
| `update`    | `(id: string, update: (tool: Mutable<Info<ValueSchema<unknown>, ValueSchema<unknown> \| undefined>>) => void) => void` |             |
| `remove`    | `(id: string) => void`                                                                                                 |             |

</Tab>
<Tab value="Effect">

### $Fumadocs

| Prop        | Type                                                                                                      | Description |
| ----------- | --------------------------------------------------------------------------------------------------------- | ----------- |
| `list`      | `() => readonly (Info & { readonly id: string; })[]`                                                      |             |
| `get`       | `(id: string) => (Info & { readonly id: string; }) \| undefined`                                          |             |
| `namespace` | `(namespace: Namespace) => void`                                                                          |             |
| `add`       | `<Input extends ValueSchema, Output extends ValueSchema \| undefined>(tool: Info<Input, Output>) => void` |             |
| `update`    | `(id: string, update: (tool: Mutable<Info>) => void) => void`                                             |             |
| `remove`    | `(id: string) => void`                                                                                    |             |

</Tab>
</Tabs>

- `list`: every tool, with its full id.
- `get`: one tool by its id.
- `namespace`: describe a group of tools once.
- `add`: add one tool.
- `update`: change a tool, such as another plugin's.
- `remove`: remove a tool by its id.

## An RPC method [#an-rpc-method]

One entry of a contract's `methods`:

### $Fumadocs

| Prop      | Type                    | Description |
| --------- | ----------------------- | ----------- |
| `input`   | `ValueSchema`           |             |
| `output`  | `ValueSchema`           |             |
| `errors?` | `ErrorMap \| undefined` |             |

- `input`: the schema the caller's input must match.
- `output`: the schema of what the method returns.
- `errors`: the failures callers can tell apart, each with the schema of its data.

## Browser ctx [#browser-ctx]

What the browser part's `setup` gets as `ctx`:

### $Fumadocs

| Prop         | Type                                                                                                                 | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| ------------ | -------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `options`    | `PluginOptions`                                                                                                      | The plugin's options from the conciv config, as `ctx.options` in its engine part. A built-in gets the options of the config entry naming its id, else nothing.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `client`     | `ConcivClient`                                                                                                       | The client of the engine that runs the plugin. Call the plugin's engine part through it. A new client after that engine restarts; read it where you call it. While the engine is unreachable, every call rejects. A built-in plugin gets a client whose calls all reject.                                                                                                                                                                                                                                                                                                                                                                       |
| `id`         | `string`                                                                                                             | The plugin's id, as its engine part's `Plugin.define` declares it.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `signal`     | `AbortSignal`                                                                                                        | Aborts when the plugin is disabled or reloaded, or when the window closes. After an `await`, return if it aborted. A window has no owner after an `await`, so listen to the signal for teardown that starts there.                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `log`        | `Log`                                                                                                                | The widget's logger: off unless the engine's `logs.level` turns it on, and drained to the engine with the widget's own events. Log with an object whose `action` names the area and `message` says what happened.                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `add`        | `{ <T>(registry: Registry<T>, item: () => T \| undefined): Cleanup; <T>(registry: Registry<T>, item: T): Cleanup; }` | Contributes an item that follows reactive state: the window re-runs the function when what it reads changes. Return undefined to withdraw the item until it returns one again. The host withdraws it with the current owner (a `createKeyed` run or a component), else with the plugin; made after that owner or the plugin ended, it is withdrawn at once. Contributes a fixed item to a registry. The host withdraws it with the current owner (a `createKeyed` run or a component), else with the plugin; made after that owner or the plugin ended, it is withdrawn at once. Use the function form for an item that follows reactive state. |
| `list`       | `<T>(registry: Registry<T>) => readonly T[]`                                                                         | The items every plugin contributed to a registry, in contribution order. Reactive. Use it for a registry your plugin owns.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| `provide`    | `<C extends Contract<unknown>>(token: C, impl: TokenValue<C>) => Cleanup`                                            | Provides an in-process contract. Withdrawn with the current owner, else with the plugin. Throws for a contract whose id is not your plugin's id or under it (`<id>.<name>`).                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| `use`        | `<T extends Token>(token: T) => Accessor<Live<TokenValue<T>>>`                                                       | Follows a contract that another plugin provides. Returns a `Live` accessor: pending while its provider loads, active with its value, inactive while it is turned off or failed. The plugin must keep working while it is inactive. Branch on it, or follow it with `createKeyed`. The provider is the plugin whose id the token's id names.                                                                                                                                                                                                                                                                                                     |
| `layout`     | `Layout`                                                                                                             | Panel tabs, scroll offsets, and the settings page.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `sessions`   | `Sessions`                                                                                                           | The sessions of open shell tabs, and the mounted one.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `screen`     | `Screen`                                                                                                             | The mounted session screen and its route-following composer. Read it where you act, so an action targets the session routed at that moment; a `MountedSession` carries no such actions.                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `storage`    | `Storage`                                                                                                            | Stores for keys only known at runtime, and window-local memory. Declare `stores` for keys known up front.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `system`     | `System`                                                                                                             | The clipboard, saving files, and opening URLs in a new browser tab.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `desktop`    | `Desktop \| undefined`                                                                                               | Abilities on the user's machine, through the engine: opening a file in the user's editor.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `dialogs`    | `Dialogs`                                                                                                            | Dialogs that close with the owner that opened them, else when the plugin goes away.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `toast`      | `Toasts`                                                                                                             | Short messages in a corner of the window. A plugin's toasts close when it goes away.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| `tabs`       | `Tabs`                                                                                                               | The open session tabs across engines: list, open, show and close them.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `attention`  | `Attention`                                                                                                          | Tells the user something waits for them while the panel is closed, through the launcher.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `commands`   | `Commands \| undefined`                                                                                              |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `links`      | `Links`                                                                                                              | Routes local links to the plugins that handle them.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `ui`         | `Ui`                                                                                                                 | The app's own components: icons, buttons, tooltips, menus and menu rows, the loading indicator, the dialog frame, switches, text fields, selects, keybind chips, Markdown, highlighted code, and settings pages, sections and rows.                                                                                                                                                                                                                                                                                                                                                                                                             |
| `app`        | `App`                                                                                                                | The running app: its version, release channel and platform, as `ctx.app` in engine plugins.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `appearance` | `Appearance`                                                                                                         | The user's appearance settings.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `overlay`    | `(options?: { readonly styles?: readonly string[]; }) => { readonly element: HTMLElement; dispose(): void; }`        | A layer over the page, under the app: a `div` in its own shadow root on `document.body`, styled with the app's stylesheet and carrying the app's base font and text color, color scheme and skin. Removed by `dispose`, else with the current owner, else with the plugin. The layer lets clicks through to the page; content that must be clickable opts back in with `pointer-events-auto`. The layer is not an Ark environment: a `ctx.ui` popover, menu or tooltip rendered inside it portals to the page's `document.body`, outside the app's stylesheet.                                                                                  |
| `router`     | `Router`                                                                                                             | The app's route.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `keybinds`   | `Keybinds`                                                                                                           | The effective keybinds of published commands.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| `servers`    | `Servers`                                                                                                            | The servers the app lists: their ids, and each one's live `ServerRef`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |

- `id`: the plugin's id, from its engine part.
- `options`: the options from the plugin's config entry.
- `signal`: aborts when the plugin reloads or stops.
- `client`: calls the engine: `client.rpc(contract)` and `client.event.subscribe`.
- `add`: adds an entry to a registry, such as `Panel` or `ToolRegistry`. `list` reads a registry.
- `provide` and `use`: share an in-process contract with another plugin.
- `layout`: panel tabs, scroll offsets and the settings page.
- `sessions`: the sessions of open tabs, and the mounted one.
- `screen`: the mounted session's screen and its composer.
- `storage`: stores for keys known only at run time.
- `system`: the clipboard, saving files and opening URLs.
- `desktop`: opens a file in the user's editor, when the engine can.
- `dialogs`: opens dialogs that close with their owner.
- `toast`: short messages in a corner of the window.
- `tabs`: the open session tabs, across engines.
- `links`: routes local links to the plugins that handle them.
- `ui`: the widget's own Solid components, such as `Icon`, `Button`, `Switch` and `SettingsRow`.
- `app`: the widget's version, release channel and platform.
- `appearance`: the user's appearance settings.
- `overlay`: a layer over the page, under the widget.
- `router`: the widget's route.
- `keybinds`: the keybinds of published commands.
- `servers`: the dev servers the engine knows about.
- `attention` and `commands`: not implemented yet, always `undefined`.

## Browser registries [#browser-registries]

### Panel [#panel]

### $Fumadocs

| Prop         | Type                                                                                                                                                 | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `id`         | `string`                                                                                                                                             |                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `region`     | `"pane"`                                                                                                                                             |                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `transient?` | `boolean \| undefined`                                                                                                                               |                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `normalize?` | `((input: { readonly id: string; readonly session: MountedSession; readonly screen: SessionScreen; }) => string) \| undefined`                       | The canonical form of one of this panel's stored tab ids, when one tab can be stored more than one way (e.g. the same file as an absolute and a relative path). The host rewrites stored ids and drops duplicates. Reactive.                                                                                                                                                                                                                                              |
| `mobile?`    | `MobileView \| undefined`                                                                                                                            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `list`       | `(input: { readonly session: MountedSession; readonly screen: SessionScreen; readonly open: readonly string[]; }) => readonly PanelTab[]`            | Reactive, and runs again when another session is routed. `open` holds this plugin's tab ids stored in the strip. List those that still apply, plus any `pinned` tab. The host renders triggers, restore, and selection from this data. Cache tab objects by something that outlives one session object (the tab id, `session.key`, or the screen passed as `input.screen`), so a session switch does not render their labels again. Read the getters; do not destructure. |
| `render`     | `(props: PanelProps) => JSX.Element`                                                                                                                 | Renders a tab's content once; its own reactivity updates it, also when another session is routed. A render that throws renders nothing and records the error.                                                                                                                                                                                                                                                                                                             |
| `close?`     | `((input: PanelProps) => void) \| undefined`                                                                                                         | Runs after the host removes the tab from the strip.                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `closed?`    | `((input: PanelProps) => ClosedPanelTab \| false \| undefined) \| undefined`                                                                         | Read as the user closes a tab, so it can come back. Return how the entry reads and the data `restore` needs, or `false` when the tab cannot come back. Without it, a tab that is not `transient` comes back under the same key. The host stores the entry, so keep `data` small.                                                                                                                                                                                          |
| `restore?`   | `((input: { readonly session: MountedSession; readonly screen: SessionScreen; readonly id: string; readonly data?: string; }) => void) \| undefined` | Brings back a tab `closed` listed. Without it, the host opens the same key again.                                                                                                                                                                                                                                                                                                                                                                                         |
| `focus?`     | `((input: PanelProps & { readonly restored: boolean; }) => void) \| undefined`                                                                       | Runs when the tab becomes selected. `restored` is true for the selection the pane mounts with, e.g. the tab selected before a reload, and false for every later selection change.                                                                                                                                                                                                                                                                                         |

- `id`: the panel's name, unique in your plugin.
- `region`: where the tabs go. It is required, and `'pane'` is the only value.
- `list`: the tabs to show. It runs again when what it reads changes.
- `render`: draws a tab's content once.
- `close`, `closed` and `restore`: run as the user closes a tab, and bring it back.
- `focus`: runs when one of your tabs is selected.
- `normalize`, `mobile` and `transient`: how stored tabs are matched, shown on a phone, and kept.

One tab that `list` returns:

### $Fumadocs

| Prop         | Type                                                                                                                                | Description |
| ------------ | ----------------------------------------------------------------------------------------------------------------------------------- | ----------- |
| `id`         | `string`                                                                                                                            |             |
| `title`      | `string`                                                                                                                            |             |
| `label?`     | `((state: { readonly active: boolean; readonly preview: boolean; readonly session: MountedSession; }) => JSX.Element) \| undefined` |             |
| `pinned?`    | `boolean \| undefined`                                                                                                              |             |
| `draggable?` | `boolean \| undefined`                                                                                                              |             |
| `closable?`  | `"compact" \| "hover" \| false \| undefined`                                                                                        |             |
| `transient?` | `boolean \| undefined`                                                                                                              |             |
| `fallback?`  | `boolean \| undefined`                                                                                                              |             |
| `group?`     | `string \| undefined`                                                                                                               |             |
| `missing?`   | `boolean \| undefined`                                                                                                              |             |
| `hidden?`    | `boolean \| undefined`                                                                                                              |             |
| `file?`      | `string \| undefined`                                                                                                               |             |
| `tabbable?`  | `boolean \| undefined`                                                                                                              |             |

- `id`: the tab's id, stored in the user's open tabs.
- `title`: the tab's name, shown when it has no `label`.
- `label`: what the tab strip draws.
- `pinned`: always in the strip.
- `closable`, `draggable` and `tabbable`: how the user can close, move and reach the tab.
- `transient`, `fallback`, `group`, `missing`, `hidden` and `file`: how the strip treats the tab.

### Slot [#slot]

### $Fumadocs

| Prop     | Type                                                                                                                                                                                                                                                                                                                                                            | Description                                                                                                                                                                                                                                                                                                                                                              |
| -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `at`     | `"page.overlay" \| "session.header" \| "session.status" \| "window.bottom"`                                                                                                                                                                                                                                                                                     |                                                                                                                                                                                                                                                                                                                                                                          |
| `order?` | `number \| undefined`                                                                                                                                                                                                                                                                                                                                           |                                                                                                                                                                                                                                                                                                                                                                          |
| `render` | `((input: Record<string, never>) => JSX.Element) \| ((input: { readonly screen: SessionScreen; readonly session: MountedSession; readonly active: boolean; readonly compact: boolean; }) => JSX.Element) \| ((input: { readonly screen: SessionScreen; readonly session: MountedSession; }) => JSX.Element) \| ((input: Record<string, never>) => JSX.Element)` | Renders the content once; its own reactivity updates it. Session and active fields are reactive getters, so read `input.session` where you use it: another routed session arrives through it without a remount. `screen` on a session slot is its constant owning screen, available during the first render. A render that throws renders nothing and records the error. |

- `at`: the place: `session.header`, `session.status`, `window.bottom` or `page.overlay`.
- `order`: sorts the slot among others at the same place.
- `render`: draws the content once. A `page.overlay` slot also takes `hides`.

### ComposerPill [#composerpill]

### $Fumadocs

| Prop     | Type                                                           | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| -------- | -------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `id`     | `string`                                                       |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `order?` | `number \| undefined`                                          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `show`   | `(input: ComposerPillProps) => ComposerPillView \| undefined`  | The pill above one session's composer, or undefined to show none there. Reactive: the host runs it for each mounted composer and again when what it reads changes, so read the session's state and your own here.                                                                                                                                                                                                                                                                                                                         |
| `menu?`  | `((input: ComposerPillMenuProps) => JSX.Element) \| undefined` | Your content for the popover the pill opens, for a pill that needs more than `rows`, such as status text and buttons. The host owns the capsule and the popover around this content: its placement, focus, dismissal, and the heading (`title`, else `label`). When set, clicking the pill opens the popover, and the view's `rows` and `run` are unused. Renders each time the popover opens; its own reactivity updates it while open, also when another session is routed. A render that throws renders nothing and records the error. |

- `id`: the pill's name.
- `order`: sorts it among the other pills.
- `show`: what the pill looks like for one composer, or `undefined` to hide it.
- `menu`: your own content for the popover the pill opens.

What `show` returns:

### $Fumadocs

| Prop     | Type                                      | Description |
| -------- | ----------------------------------------- | ----------- |
| `label`  | `string`                                  |             |
| `icon?`  | `IconName \| undefined`                   |             |
| `tone?`  | `ComposerPillTone \| undefined`           |             |
| `title?` | `string \| undefined`                     |             |
| `rows?`  | `readonly ComposerPillRow[] \| undefined` |             |
| `run?`   | `(() => void) \| undefined`               |             |

- `label`: the pill's text, and `title` the popover's heading.
- `icon` and `tone`: the pill's icon, and its colour for success, warning or danger.
- `run`: what a click does.
- `rows`: a menu of rows, each with its own `run`, in place of `run`.

### SettingsPage [#settingspage]

### $Fumadocs

| Prop       | Type                                                    | Description                                                                                                                                                                        |
| ---------- | ------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `id`       | `string`                                                |                                                                                                                                                                                    |
| `page?`    | `"general" \| undefined`                                |                                                                                                                                                                                    |
| `section?` | `"general" \| undefined`                                |                                                                                                                                                                                    |
| `title`    | `string`                                                |                                                                                                                                                                                    |
| `icon?`    | `IconName \| undefined`                                 |                                                                                                                                                                                    |
| `entries?` | `readonly SettingEntry[] \| undefined`                  |                                                                                                                                                                                    |
| `render`   | `(input: { readonly target?: string; }) => JSX.Element` | Renders the page, section or rows: `Ui.SettingsLayout` frames a page, `Ui.SettingsSection` a section, and `Ui.SettingsRow` is one row, each as the app's own settings render them. |

- `id`: the entry's name.
- `page` and `section`: put it on the General page, or in its General section.
- `title` and `icon`: how the entry reads.
- `entries`: what the settings search finds.
- `render`: draws the page, section or row.

### ToolRegistry [#toolregistry]

### $Fumadocs

| Prop              | Type                         | Description |
| ----------------- | ---------------------------- | ----------- |
| `name`            | `string`                     |             |
| `render?`         | `ToolComponent \| undefined` |             |
| `errorComponent?` | `ToolComponent \| undefined` |             |

- `name`: the tool whose calls this card draws.
- `render`: draws one call.
- `errorComponent`: draws a failed call.

What `render` gets:

### $Fumadocs

| Prop                 | Type                                                    | Description |
| -------------------- | ------------------------------------------------------- | ----------- |
| `input`              | `Record<string, unknown>`                               |             |
| `error?`             | `string \| undefined`                                   |             |
| `metadata`           | `Record<string, unknown>`                               |             |
| `tool`               | `string`                                                |             |
| `sessionID?`         | `string \| undefined`                                   |             |
| `output?`            | `string \| undefined`                                   |             |
| `status?`            | `string \| undefined`                                   |             |
| `hideDetails?`       | `boolean \| undefined`                                  |             |
| `defaultOpen?`       | `boolean \| undefined`                                  |             |
| `open?`              | `boolean \| undefined`                                  |             |
| `onOpenChange?`      | `((open: boolean) => void) \| undefined`                |             |
| `fileOpen?`          | `((path: string) => boolean \| undefined) \| undefined` |             |
| `onFileOpenChange?`  | `((path: string, open: boolean) => void) \| undefined`  |             |
| `deferContent?`      | `boolean \| undefined`                                  |             |
| `virtualizeDiff?`    | `boolean \| undefined`                                  |             |
| `onContentRendered?` | `(() => void) \| undefined`                             |             |
| `pendingFiles?`      | `readonly string[] \| undefined`                        |             |
| `forceOpen?`         | `boolean \| undefined`                                  |             |
| `locked?`            | `boolean \| undefined`                                  |             |

- `tool`, `input` and `status`: the tool's name, the agent's input, and where the call is.
- `output`: the result as JSON text, once the call ends.
- `error`: the message of a failed call.
- `metadata`: the call's metadata, such as progress updates.
- The other props are how the widget opens, locks and lays out the card.

## Load a part lazily [#load-a-part-lazily]

Any `render` above can draw a component made with Solid's `lazy()`, such as
`render: lazy(() => import('./ticket-card.js'))`. The part loads the first time it shows, and the widget shows its own
loader until then.

## Render in any framework [#render-in-any-framework]

Every `render` above takes a Solid component. Three helpers turn your own UI into one, so a browser part can draw in
another framework:

| Helper         | Import                        | Draws with                                        |
| -------------- | ----------------------------- | ------------------------------------------------- |
| `mountRender`  | `@conciv/frontend-plugin-api` | plain DOM, or any framework you mount by hand     |
| `reactRender`  | `@conciv/react`               | a React component, inside your app's React tree   |
| `preactRender` | `@conciv/preact`              | a Preact component, inside your app's Preact tree |

Each one fits every render a registry takes: a panel, a slot, a settings page, a pill's menu, a code block and a
tool card.

- `mountRender` calls your mount function with an element and the props, once the element is in the page. The
  mount returns a cleanup, which runs when the widget removes the contribution.
- `props.current()` gives the props as they are now. `props.subscribe(listener)` calls the listener at once and on
  every change, and returns a stop function.
- The React and Preact helpers draw through a portal into your app's tree, so your providers reach the component.
  They need a `<ConcivWidget>` from the same package above them, and throw without one.
- `<ConcivWidget>` mounts the widget itself. Set `widget: false` on the conciv bundler plugin, so the page does not
  get a second one.
- A plugin folder's browser part is built with `experimental()`, which compiles Solid. React and Preact UI lives in
  your app as a `Plugin.Setup`. You give it to `<ConcivWidget>` in its plugins.
- The widget's reactive values, such as `run.status()`, are Solid signals. So is a store's value. Outside Solid, read
  them in the function you pass to `ctx.add`, which runs again when they change.

Learn more in [Build your first plugin](/docs/plugins/first-plugin#draw-the-card).

## Next steps [#next-steps]

- **[Build your first plugin](/docs/plugins/first-plugin)**: every part in one tutorial.
- **[Plugins](/docs/plugins)**: every guide.
