// RPC contract — template // // Docs: https://opencode.ai/v2/docs/build/plugins/rpc/ // // Copy to src/rpc.ts. This file is the contract only — no implementation. // Registered by rpc-implementation.ts (Promise) or rpc-implementation-effect.ts // (Effect). Use rpc-effect.ts instead if you want Effect Schema. // --------------------------------------------------------------------------- // PREREQUISITE: install @opencode/plugin at your OpenCode version and restart // the service — see the PREREQUISITE block in promise-plugin.ts. // --------------------------------------------------------------------------- import { Rpc } from "@opencode/plugin/rpc" // --------------------------------------------------------------------------- // src/rpc.ts — the contract. No implementation here. // // Schemas may be JSON Schema (simple, no deps; values are `unknown` in // TypeScript so narrow them) or any Standard Schema validator such as Zod, // Valibot, or ArkType (types are inferred). // // Error names starting with "rpc." are reserved by OpenCode. // Event data must be an object: scalars, arrays, null, and undefined are invalid. export const Acme = Rpc.define({ // The page shows received event types arriving prefixed, e.g. rpc.acme.updated. // It does not otherwise describe how `id` affects method routing. id: "acme", methods: { search: { input: { type: "object", properties: { query: { type: "string" } }, required: ["query"], additionalProperties: false, }, output: { type: "object", properties: { text: { type: "string" } }, required: ["text"], additionalProperties: false, }, // Omit input or output entirely if the method takes or returns nothing. errors: { // Each key becomes the error's `type`; this schema defines its `data`. not_found: { type: "object", properties: { query: { type: "string" } }, required: ["query"], additionalProperties: false, }, }, }, }, events: { updated: { schema: { type: "object", properties: { itemID: { type: "string" }, text: { type: "string" }, }, required: ["itemID", "text"], additionalProperties: false, }, }, // No data at all? Use an empty object schema. // refreshed: { schema: { type: "object", additionalProperties: false } }, }, })