Skip to Content
DocsPluginsComparisonChangelog
0
DocsChangelog

More

Discussionsllms.txtllms-full.txt
Getting startedWhat is concivComparisonRequirementsPlaygroundExamplesAPI reference

Engine and widgetSessionsHarnessesTools and code modeAgents and permissionsSkills

Use conciv
Bundlers
Agents
PluginsBuild your first plugin
Add a toolAsk for permissionAdd a skillShare an RPC methodCall from a terminalAdd a panelSlot or pillAdd settingsTest your plugin
Plugin API reference
PluginsGuides

Share an RPC method

Let your plugin's browser part, a terminal or another plugin call methods on its engine part, and follow its events.

An RPC method is a function your engine part answers. Anything else calls it by name: your browser part, a terminal, or another plugin. This guide builds a plant shelf, with a count method and a sell method that can fail.

The contract file imports @conciv/protocol, which the tutorial installed only for the Effect style.

npm install -D @conciv/protocol
pnpm add -D @conciv/protocol
yarn add --dev @conciv/protocol
bun add --dev @conciv/protocol

Copy this prompt into your agent. It builds this in your project from this page.

Prompt
Build this in my project with conciv. conciv is a dev-only AI agent widget, and it already runs in my app.

1. Read https://conciv.dev/docs/plugins/guides/rpc.md and follow it. It is the source of truth for the API.
2. If the project has the conciv-develop skill (conciv init installs it with the @conciv/skills docs pack), load it too.
3. Share an RPC method between my plugin's engine part and its browser part: the contract in rpc.ts, the method in server.ts, and the call in the browser part.
4. If I did not say what it should do, ask me before you write code.
5. Write the browser part in the UI framework my app uses. For React or Preact, put it in my app with @conciv/react or @conciv/preact and give it to <ConcivWidget>, as the page shows. For anything else, use Solid in the plugin folder and build it as the page shows.
6. Install only the packages the page lists, with the package manager this project uses.
7. While the dev server runs, call the method with `npx @conciv/cli plugin call <plugin> <method> --data <json>` and show me the output.
8. When you are done, tell me what you changed and how to see it.

Declare the contract

Declare the contract in its own file, so the engine part and the browser part both import it:

conciv/plugins/plant-shelf/rpc.ts
import * as  from '@conciv/protocol/schema/rpc'
import {} from 'zod'

const  = .({: .()})
export const  = .({: .(), : .()})

export const  = .({
  : 'plant-shelf', // <- the name callers use
  : {
    : {: , : },
    : {: , : , : {'sold-out': }}, // <- a failure callers can tell apart
  },
  : {: {: }}, // <- sent to everyone listening
})

The contract imports Rpc from @conciv/protocol/schema/rpc because the widget provides that module to browser parts. Then answer every method in the engine part:

conciv/plugins/plant-shelf/server.ts
import {Plugin, type } from '@conciv/backend-plugin-api'
import {} from './rpc'

export default Plugin.({
  : 'plant-shelf',
  async () {
    let  = 3
    const : <typeof > = await ..(, {
      : async ({}) => ({, }),
      : async ({}, ) => {
        if ( === 0) return .('sold-out', `${} is sold out`, {}) // <- a declared error
         -= 1
        await .
          .('sold', {, })
          .((: unknown) 
        return {, }
      },
    })
  },
})
conciv/plugins/plant-shelf/server.ts
import {, } from 'effect'
import {Plugin} from '@conciv/backend-plugin-api/effect'
import





















A few things to notice:

  • Each handler gets the checked input. What it returns is checked against output before it goes back.
  • call.error makes one of the method's declared errors: its name, a message and its data.
  • In both tabs the plugin logs a failed emit. The sale still succeeds.
  • Effect.catchCause catches any failure of the emit. Effect.orDie makes a failed register stop the plugin load, as a rejected register does in the Promise tab.
  • shelf has its type written out, because a handler uses the registration it belongs to.

Call it from the browser part

ctx.client.rpc(Shelf) gives one typed function per method. You write the browser part in Solid, React, Preact or plain DOM. This code draws nothing, so it is the same in every tab. Only where it lives changes:

conciv/plugins/plant-shelf/plugin-experimental.tsx
import {, Plugin} from '@conciv/frontend-plugin-api'
import {












The code lives in your app. Give it to <ConcivWidget> as in Build your first plugin.

src/conciv/plant-shelf.ts
import {











The code lives in your app. Give it to <ConcivWidget> as in Build your first plugin.

src/conciv/plant-shelf.ts
import {











conciv/plugins/plant-shelf/plugin-experimental.ts
import {













Read ctx.client where you call it, because the widget makes a new client after the engine restarts. Build or wire it as in Build or wire the browser part, then reload.

Follow the events

Subscribe to an event by its full name, rpc.<contract id>.<event>:

conciv/plugins/plant-shelf/plugin-experimental.tsx
import {Plugin} from '@conciv/frontend-plugin-api'
import {} from './rpc'

export default Plugin.










src/conciv/plant-shelf.ts
import type {Plugin} from '@conciv/frontend-plugin-api'
import {










src/conciv/plant-shelf.ts
import type {Plugin} from '@conciv/frontend-plugin-api'
import {










conciv/plugins/plant-shelf/plugin-experimental.ts
import {Plugin} from '@conciv/frontend-plugin-api'
import {












A few things to notice:

  • subscribe always lets server.connected through, at the start and after each reconnect. Read your data again then. You can have missed events in between.
  • event.data is what the engine part sent. Check it with your schema before you use it.
  • ctx.signal ends the loop when the plugin reloads or stops.

Build or wire it as in Build or wire the browser part, then reload.

Call it from a terminal

The same methods answer from your shell, while the dev server runs:

terminal
npx @conciv/cli plugin call plant-shelf count --data '{"plant": "fern"}'
output
{"ok": true, "data": {"plant": "fern", "count": 3}}

Learn more in Call your plugin from a terminal.

Next steps

  • Add a panel: show the data in a tab next to the chat.
  • Call your plugin from a terminal: every flag and every error.

Add a skill

Ship instructions with your plugin, so the agent knows when and how to use its tools.

Call from a terminal

Run one of your plugin's RPC methods on the running engine with npx @conciv/cli plugin call, and read its JSON answer.

On this page

Declare the contractCall it from the browser partFollow the eventsCall it from a terminalNext steps
Edit on GitHubView .mdOpen in ClaudeOpen in ChatGPT
=>
.
(
'a sold event was not delivered'
,
))
type
{
}
from
'@conciv/backend-plugin-api/effect/rpc'
import {
export default Plugin.({
: 'plant-shelf',
: () =>
.
const = yield* .
const
.
const = yield* .
if ( === 0) return yield* .
yield* .
yield*
.('sold', {, :
.(
return {, : - 1}
}),
})
}).(
})
}
from
'./rpc'
export default Plugin.
() {
.
: 'count-ferns',
: 'Count the ferns',
const = await .
.
},
})
},
})
,
type
Plugin
}
from
'@conciv/frontend-plugin-api'
import {
export const : Plugin.
.
: 'count-ferns',
: 'Count the ferns',
const = await .
..
},
})
}
,
type
Plugin
}
from
'@conciv/frontend-plugin-api'
import {
export const : Plugin.
.
: 'count-ferns',
: 'Count the ferns',
const = await .
..
},
})
}
,
Plugin
}
from
'@conciv/frontend-plugin-api'
import {
export default Plugin.
() {
.
: 'count-ferns',
: 'Count the ferns',
const = await .
.
},
})
},
})
({
() {
const = async () => {
for await (const of .
if (. !== 'rpc.plant-shelf.sold') continue // <- server.connected comes through too
const =
if (.) .
}
}
void ()
},
})
}
from
'../../conciv/plugins/plant-shelf/rpc'
export const : Plugin.
const = async () => {
for await (const of .
if (. !== 'rpc.plant-shelf.sold') continue // <- server.connected comes through too
const =
if (.) .
}
}
void ()
}
}
from
'../../conciv/plugins/plant-shelf/rpc'
export const : Plugin.
const = async () => {
for await (const of .
if (. !== 'rpc.plant-shelf.sold') continue // <- server.connected comes through too
const =
if (.) .
}
}
void ()
}
}
from
'./rpc'
export default Plugin.
() {
const = async () => {
for await (const of .
if (. !== 'rpc.plant-shelf.sold') continue // <- server.connected comes through too
const =
if (.) .
}
}
void ()
},
})
}
from
'./rpc'
(
function*
() {
(
3
)
:
<
typeof
>
=
yield*
.
.
(
, {
: ({
})
=>
.
(
).
(
.
((
)
=>
({
,
:
}))),
: ({
},
)
=>
(
function*
() {
(
)
(
.
(
'sold-out'
,
`${
} is sold out`
, {
}))
// <- a declared error
(
,
-
1
)
.
-
1
})
.
((
)
=>
.
(
'a sold event was not delivered'
,
)))
.
),
({
(
, {
:
async
()
=>
{
.
(
).
({
:
'fern'
})
.
({
:
`${
.
} ferns on the shelf`
})
}
from
'../../conciv/plugins/plant-shelf/rpc'
=
(
)
=>
{
(
, {
:
async
()
=>
{
.
(
).
({
:
'fern'
})
({
:
`${
.
} ferns on the shelf`
})
}
from
'../../conciv/plugins/plant-shelf/rpc'
=
(
)
=>
{
(
, {
:
async
()
=>
{
.
(
).
({
:
'fern'
})
({
:
`${
.
} ferns on the shelf`
})
}
from
'./rpc'
({
(
, {
:
async
()
=>
{
.
(
).
({
:
'fern'
})
.
({
:
`${
.
} ferns on the shelf`
})
.
.
({
: [
'rpc.plant-shelf.sold'
],
:
.
})) {
.
(
.
)
.
({
:
`${
.
.
} sold, ${
.
.
} left`
})
=
(
)
=>
{
.
.
({
: [
'rpc.plant-shelf.sold'
],
:
.
})) {
.
(
.
)
.
({
:
`${
.
.
} sold, ${
.
.
} left`
})
=
(
)
=>
{
.
.
({
: [
'rpc.plant-shelf.sold'
],
:
.
})) {
.
(
.
)
.
({
:
`${
.
.
} sold, ${
.
.
} left`
})
({
.
.
({
: [
'rpc.plant-shelf.sold'
],
:
.
})) {
.
(
.
)
.
({
:
`${
.
.
} sold, ${
.
.
} left`
})