docs: fix build code samples (#58281)

This commit is contained in:
DS 2026-10-22 21:56:41 -04:00 • committed by GitHub
parent 58a2066e0b
commit ea1f209f4d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 41 additions and 27 deletions

View file

@ -6,7 +6,7 @@ title: "Effect"
and decodes responses into OpenCode schema values.
```sh
bun add @opencode/client effect
bun add @opencode/client effect@4.0.1
```
## Create a client
@ -114,7 +114,7 @@ The Node-only `@opencode/client/effect/service` entrypoint discovers, starts, au
background service as Effects.
```sh
bun add @effect/platform-node
bun add @effect/platform-node@4.0.1
```
Create an authenticated client for the ensured service.
@ -132,7 +132,9 @@ const program = Effect.gen(function* () {
const client = yield* OpenCode.make({ baseUrl: endpoint.url }).pipe(
Effect.provideService(
HttpClient.HttpClient,
HttpClient.mapRequest(httpClient, (request) => HttpClientRequest.setHeaders(request, Service.headers(endpoint))),
HttpClient.mapRequest(httpClient, (request) =>
HttpClientRequest.setHeaders(request, Service.headers(endpoint) ?? {}),
),
),
)
return yield* client.server.info()

View file

@ -110,9 +110,9 @@ context.data.session.permission.invalidate(sessionID)
Forms can be listed, refreshed, replied to, or cancelled at a location.
```ts
import type { FormCancelInput, FormReplyInput } from "@opencode/client"
import type { SessionFormCancelInput, SessionFormReplyInput } from "@opencode/client"
async function handleForm(reply: FormReplyInput, cancel: FormCancelInput) {
async function handleForm(reply: SessionFormReplyInput, cancel: SessionFormCancelInput) {
const location = context.location
await context.data.session.form.sync(sessionID, location)
const forms = context.data.session.form.list(sessionID, location) ?? []

View file

@ -10,7 +10,7 @@ plugins and their `node_modules` dependencies. Install them as peer/dev dependen
rather than bundling them into your plugin.
```sh
bun add --peer @opencode/plugin effect
bun add --peer @opencode/plugin effect@4.0.1
```
Export an Effect plugin from `.opencode/plugins/` to load it automatically.
@ -721,7 +721,7 @@ effect: (ctx) =>
const plugin = ctx.plugin
const active = yield* plugin.list().pipe(
Effect.orDie,
Effect.map((result) => result.data.filter((item) => item.status === "active")),
Effect.map((result) => result.data.filter((item) => item.state.status === "active")),
)
yield* Effect.logInfo("active plugin count", { count: active.length })
}),
@ -817,7 +817,7 @@ effect: (ctx) =>
const summary = yield* session
.generate({ sessionID: created.id, prompt: "Summarize this project" })
.pipe(Effect.orDie)
yield* session.command({ sessionID: created.id, command: "review", arguments: "--staged" }).pipe(Effect.orDie)
yield* session.command({ sessionID: created.id, name: "review", text: "--staged" }).pipe(Effect.orDie)
yield* session
.synthetic({ sessionID: created.id, text: `Summary generated: ${summary.text}`, resume: false })
.pipe(Effect.orDie)
@ -892,7 +892,7 @@ Read skills at the current location.
effect: (ctx) =>
Effect.gen(function* () {
const skill = ctx.skill
const skills = yield* skill.list()
const skills = yield* skill.list().pipe(Effect.orDie)
yield* Effect.logInfo("skills", { ids: skills.data.map((item) => item.id) })
}),
```
@ -909,7 +909,7 @@ effect: (ctx) =>
id: Skill.ID.make("review"),
name: Skill.Name.make("Review"),
description: "Review the current changes",
path: "/workspace/.opencode/skills/review/SKILL.md",
path: Skill.Info.fields.path.make("/workspace/.opencode/skills/review/SKILL.md"),
content: "Review the current changes for correctness and missing tests.",
}))
const review = editor.get("review")
@ -1071,7 +1071,7 @@ effect: (ctx) =>
Effect.gen(function* () {
const vcs = ctx.vcs
const info = yield* vcs.get().pipe(Effect.orDie)
const branches = yield* vcs.branches({ search: "feature", limit: 10 }).pipe(Effect.orDie)
const branches = yield* vcs.branch.list({ search: "feature", limit: 10 }).pipe(Effect.orDie)
const changes = yield* vcs.status().pipe(Effect.orDie)
const diff = yield* vcs.diff({ mode: "working", context: 3 }).pipe(Effect.orDie)
yield* Effect.logInfo("vcs", { branch: info.data.branch.current, files: changes.data.length })
@ -1517,7 +1517,8 @@ type Transform<Input> = (callback: (input: Input) => void) => Effect.Effect<Regi
## Publish
A package plugin uses the same default export as a local Effect plugin. Export the Effect implementation from the main
entrypoint and declare `effect` as a `peerDependency`.
entrypoint and declare `effect` as a `peerDependency`. Under `devDependencies`, pin the version `@opencode/plugin` uses
so development installs only one copy.
```json title="package.json"
{
@ -1531,7 +1532,10 @@ entrypoint and declare `effect` as a `peerDependency`.
"@opencode/plugin": "latest"
},
"peerDependencies": {
"effect": "^4.0.0"
"effect": "^4.0.1"
},
"devDependencies": {
"effect": "4.0.1"
}
}
```

View file

@ -769,7 +769,7 @@ Inspect or resolve pending permission requests.
```ts
const pending = await ctx.permission.list({ sessionID })
const request = await ctx.permission.get({ sessionID, requestID })
await ctx.permission.reply({ sessionID, requestID, reply: "once" })
await ctx.permission.reply({ sessionID, requestID, decision: "once" })
```
Replace the session-scoped permission rules. They are evaluated after the agent's rules, and the
@ -812,7 +812,7 @@ Send user prompts, transient generation requests, commands, or synthetic message
```ts
const prompt = await ctx.session.prompt({ sessionID, text: "Review the current changes" })
const generated = await ctx.session.generate({ sessionID, prompt: "Summarize this project" })
const command = await ctx.session.command({ sessionID, command: "review", arguments: "--staged" })
await ctx.session.command({ sessionID, name: "review", text: "--staged" })
const synthetic = await ctx.session.synthetic({ sessionID, text: "Deployment completed" })
```
@ -820,7 +820,7 @@ Rename, interrupt, or wait for a session.
```ts
await ctx.session.update({ sessionID, title: "Review" })
await ctx.session.interrupt({ sessionID, continue: false })
await ctx.session.interrupt({ sessionID, resume: false })
await ctx.session.wait({ sessionID })
```
@ -854,10 +854,10 @@ interface SessionContext {
move(input: SessionMoveInput, requestOptions?: RequestOptions): Promise<void>
prompt(input: SessionPromptInput, requestOptions?: RequestOptions): Promise<SessionInboxUser>
generate(input: SessionGenerateInput, requestOptions?: RequestOptions): Promise<{ text: string }>
command(input: SessionCommandInput, requestOptions?: RequestOptions): Promise<SessionInboxUser>
command(input: SessionCommandInput, requestOptions?: RequestOptions): Promise<void>
compact(input: SessionCompactInput, requestOptions?: RequestOptions): Promise<SessionInboxCompaction>
synthetic(input: SessionSyntheticInput, requestOptions?: RequestOptions): Promise<SessionInboxSynthetic>
interrupt(input: SessionInterruptInput, requestOptions?: RequestOptions): Promise<void>
interrupt(input: SessionInterruptInput, requestOptions?: RequestOptions): Promise<{ interrupted: boolean }>
wait(input: SessionWaitInput, requestOptions?: RequestOptions): Promise<void>
}
```
@ -874,13 +874,15 @@ Register a transform to inspect, add, update, or remove skills. `get(id)` return
when the skill is absent.
```ts
import { Skill } from "@opencode/plugin"
await ctx.skill.transform((editor) => {
const skills = editor.list()
editor.add({
id: "review",
name: "Review",
id: Skill.ID.make("review"),
name: Skill.Name.make("Review"),
description: "Review the current changes",
path: "/workspace/.opencode/skills/review/SKILL.md",
path: Skill.Info.fields.path.make("/workspace/.opencode/skills/review/SKILL.md"),
content: "Review the current changes for correctness and missing tests.",
})
const review = editor.get("review")
@ -1069,7 +1071,7 @@ Read repository information, working-copy status, or file diffs.
```ts
const info = await ctx.vcs.get()
const branches = await ctx.vcs.branches({ search: "feature", limit: 10 })
const branches = await ctx.vcs.branch.list({ search: "feature", limit: 10 })
const changes = await ctx.vcs.status()
const diff = await ctx.vcs.diff({ mode: "working", context: 3 })
```
@ -1108,7 +1110,9 @@ Schemas: [`Vcs.Info`](/api#schema-Vcs.Info), [`Vcs.FileStatus`](/api#schema-Vcs.
```ts
interface VcsContext {
get(input?: VcsGetInput, requestOptions?: RequestOptions): Promise<VcsGetOutput>
branches(input?: VcsBranchesInput, requestOptions?: RequestOptions): Promise<VcsBranchesOutput>
branch: {
list(input?: VcsBranchListInput, requestOptions?: RequestOptions): Promise<VcsBranchListOutput>
}
status(input?: VcsStatusInput, requestOptions?: RequestOptions): Promise<VcsStatusOutput>
diff(input: VcsDiffInput, requestOptions?: RequestOptions): Promise<VcsDiffOutput>
transform(callback: (editor: VcsEditor) => void): Promise<Registration>
@ -1268,7 +1272,7 @@ await ctx.websearch.transform((editor) => {
name: "Internal search",
execute: async ({ query }, { signal }) => {
const response = await fetch(`https://search.example.com?q=${encodeURIComponent(query)}`, { signal })
const result = await response.json()
const result = (await response.json()) as { url: string; title: string; content: string }
return [{ url: result.url, title: result.title, content: result.content, time: {} }]
},
})

View file

@ -28,7 +28,7 @@ Rename `plugin` to `plugins`. Replace a package-and-options tuple with an object
"plugins": [
"opencode-example-plugin",
{
"package": "./plugin/local.ts",
"package": "./plugin/local",
"options": { "enabled": true }
}
]
@ -36,6 +36,8 @@ Rename `plugin` to `plugins`. Replace a package-and-options tuple with an object
```
V2 discovers local plugins from both `.opencode/plugin/` and `.opencode/plugins/`; use `.opencode/plugins/` for V2 files.
Configured local paths must name directories. For the example above, move the ported implementation to
`./plugin/local/index.ts`; a configured `./plugin/local.ts` file is skipped with a warning in the log.
Keep supporting modules beside the plugin when moving it. Local plugins and package plugins use the same implementation
API.
@ -180,7 +182,9 @@ V2 separates prompt admission, model-visible context, semantic model options, an
layer your plugin needs.
```ts title="V1"
export const RequestPlugin = async () => ({
import type { Plugin } from "@opencode-ai/plugin"
export const RequestPlugin: Plugin = async () => ({
"chat.params": async (_input, output) => {
output.temperature = 0.2
output.maxOutputTokens = 8_000

View file

@ -6,7 +6,7 @@ title: "Effect"
the owning Scope releases the router, Location services, fibers, and plugin registrations.
```sh
bun add @opencode/sdk effect
bun add @opencode/sdk effect@4.0.1
```
## Create a host