mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-19 17:01:37 +03:00
docs(www): format yield* in Effect snippets (#56568)
This commit is contained in:
committed by
GitHub
Unverified
parent
fd7bb3bc14
commit
8f7b0120eb
@@ -39,33 +39,34 @@ Configure default headers on the supplied `HttpClient`. Native operations use
|
||||
normal Effect interruption for cancellation. RPC methods additionally accept
|
||||
per-call location, header, and signal options.
|
||||
|
||||
{/* prettier-ignore */}
|
||||
```ts
|
||||
import { HttpClient, HttpClientRequest } from "effect/http"
|
||||
|
||||
const httpClient = yield * HttpClient.HttpClient
|
||||
const client =
|
||||
yield *
|
||||
OpenCode.make({ baseUrl: "https://opencode.example.com" }).pipe(
|
||||
Effect.provideService(
|
||||
HttpClient.HttpClient,
|
||||
HttpClient.mapRequest(httpClient, (request) =>
|
||||
HttpClientRequest.setHeaders(request, { authorization: `Bearer ${process.env.OPENCODE_TOKEN}` }),
|
||||
),
|
||||
const httpClient = yield* HttpClient.HttpClient
|
||||
const client = yield* OpenCode.make({ baseUrl: "https://opencode.example.com" }).pipe(
|
||||
Effect.provideService(
|
||||
HttpClient.HttpClient,
|
||||
HttpClient.mapRequest(httpClient, (request) =>
|
||||
HttpClientRequest.setHeaders(request, { authorization: `Bearer ${process.env.OPENCODE_TOKEN}` }),
|
||||
),
|
||||
)
|
||||
),
|
||||
)
|
||||
|
||||
const sessions = yield * client.session.list()
|
||||
const sessions = yield* client.session.list()
|
||||
```
|
||||
|
||||
## Stream events
|
||||
|
||||
Streaming operations such as `event.subscribe()` and `session.log()` return Effect Streams.
|
||||
|
||||
{/* prettier-ignore */}
|
||||
```ts
|
||||
import { Effect, Stream } from "effect"
|
||||
|
||||
yield *
|
||||
client.event.subscribe().pipe(Stream.runForEach((event) => Effect.logInfo("OpenCode event", { type: event.type })))
|
||||
yield* client.event
|
||||
.subscribe()
|
||||
.pipe(Stream.runForEach((event) => Effect.logInfo("OpenCode event", { type: event.type })))
|
||||
```
|
||||
|
||||
Native and RPC event Streams share one lazy connection per client. Constructing
|
||||
@@ -78,20 +79,20 @@ receive the current connection marker before live events.
|
||||
|
||||
Use the same shared contract as Promise clients and server plugins:
|
||||
|
||||
{/* prettier-ignore */}
|
||||
```ts
|
||||
import { Acme } from "opencode-acme-plugin/rpc"
|
||||
|
||||
const acme = client.rpc(Acme)
|
||||
const result = yield * acme.search({ query: "hello" }, { location: { directory: "/workspace" } })
|
||||
const result = yield* acme.search({ query: "hello" }, { location: { directory: "/workspace" } })
|
||||
|
||||
yield *
|
||||
acme.events
|
||||
.subscribe("updated")
|
||||
.pipe(
|
||||
Stream.runForEach((event) =>
|
||||
Effect.logInfo("Plugin event", { type: event.type, location: event.location, text: event.data.text }),
|
||||
),
|
||||
)
|
||||
yield* acme.events
|
||||
.subscribe("updated")
|
||||
.pipe(
|
||||
Stream.runForEach((event) =>
|
||||
Effect.logInfo("Plugin event", { type: event.type, location: event.location, text: event.data.text }),
|
||||
),
|
||||
)
|
||||
```
|
||||
|
||||
Method arguments and results are inferred from the contract. The second optional
|
||||
@@ -144,7 +145,8 @@ const health = await Effect.runPromise(
|
||||
|
||||
Discover without starting, or stop the exact registered service.
|
||||
|
||||
{/* prettier-ignore */}
|
||||
```ts
|
||||
const endpoint = yield * Service.discover()
|
||||
yield * Service.stop()
|
||||
const endpoint = yield* Service.discover()
|
||||
yield* Service.stop()
|
||||
```
|
||||
|
||||
@@ -348,14 +348,14 @@ effect: (ctx) =>
|
||||
For account-specific discovery, pass the connection used to load the inventory as `sourceConnection`. OpenCode excludes
|
||||
that provider while another connection is selected, until your plugin publishes its refreshed inventory.
|
||||
|
||||
{/* prettier-ignore */}
|
||||
```ts
|
||||
const connection = yield * ctx.integration.connection.active("acme")
|
||||
const connection = yield* ctx.integration.connection.active("acme")
|
||||
if (!connection) return
|
||||
const inventory = yield * loadInventory(connection)
|
||||
yield *
|
||||
ctx.provider.transform((editor) => {
|
||||
editor.add({ info: inventory.provider, models: inventory.models, sourceConnection: connection })
|
||||
})
|
||||
const inventory = yield* loadInventory(connection)
|
||||
yield* ctx.provider.transform((editor) => {
|
||||
editor.add({ info: inventory.provider, models: inventory.models, sourceConnection: connection })
|
||||
})
|
||||
```
|
||||
|
||||
Schemas: [`Provider.Info`](/api#schema-Provider.Info), [`Model.Info`](/api#schema-Model.Info).
|
||||
@@ -1020,14 +1020,14 @@ namespaces and unsupported characters in tool names become `_`. Missing names ar
|
||||
`add` with a complete definition. Updates preserve the name and namespace. Assign new schemas or options to replace
|
||||
them rather than mutating nested values. Invalid updates are logged and leave the previous definition intact.
|
||||
|
||||
{/* prettier-ignore */}
|
||||
```ts
|
||||
yield *
|
||||
ctx.tool.transform((editor) => {
|
||||
editor.update("acme_greeting", (tool) => {
|
||||
tool.description = "Greet the user by name"
|
||||
})
|
||||
editor.remove("acme_obsolete")
|
||||
yield* ctx.tool.transform((editor) => {
|
||||
editor.update("acme_greeting", (tool) => {
|
||||
tool.description = "Greet the user by name"
|
||||
})
|
||||
editor.remove("acme_obsolete")
|
||||
})
|
||||
```
|
||||
|
||||
Updates and removals replay in order with additions, including after MCP catalog refreshes.
|
||||
|
||||
@@ -154,16 +154,16 @@ effect: (ctx) =>
|
||||
RPC events are Streams. Subscribe by event name and run the Stream in a scoped
|
||||
fiber:
|
||||
|
||||
{/* prettier-ignore */}
|
||||
```ts
|
||||
import { Effect, Stream } from "effect"
|
||||
|
||||
const acme = ctx.rpc(Acme)
|
||||
|
||||
yield *
|
||||
acme.events.subscribe("updated").pipe(
|
||||
Stream.runForEach((event) => Effect.logInfo(event.data.text)),
|
||||
Effect.forkScoped,
|
||||
)
|
||||
yield* acme.events.subscribe("updated").pipe(
|
||||
Stream.runForEach((event) => Effect.logInfo(event.data.text)),
|
||||
Effect.forkScoped,
|
||||
)
|
||||
```
|
||||
|
||||
Subscriptions are live only and close when Stream consumption stops.
|
||||
|
||||
Reference in New Issue
Block a user