feat(plugin): expose app metadata (#38179)

This commit is contained in:
Dax 2026-07-21 18:16:25 -04:00 committed by GitHub
commit 8de40be6ea
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
71 changed files with 477 additions and 286 deletions

View file

@ -21,7 +21,7 @@ import { SimulatedProvider } from "./simulated-provider"
*
*/
export const simulationReplacements = Effect.fn("Simulation.replacements")(function* () {
export const simulationReplacements = Effect.fn("Simulation.replacements")(function* (app: { readonly version: string }) {
// ModelsDev dies when its catalog fetch fails, so simulation answers it with
// an empty catalog; providers come from seeded config instead.
const models = SimulationNetwork.json("GET", "https://models.dev/api.json", {})
@ -40,6 +40,7 @@ export const simulationReplacements = Effect.fn("Simulation.replacements")(funct
Layer.provide(
SimulatedProvider.layerDrive({
endpoint: manifest.endpoints.backend,
version: app.version,
}),
),
)

View file

@ -1,4 +1,3 @@
import { InstallationVersion } from "@opencode-ai/util/installation/version"
import { SdkPlugins } from "@opencode-ai/core/plugin/sdk"
import { Plugin } from "@opencode-ai/plugin/v2/effect"
import { Tool } from "@opencode-ai/plugin/v2/effect/tool"
@ -152,7 +151,7 @@ class ToolControllerError extends Schema.TaggedErrorClass<ToolControllerError>()
{ message: Schema.String },
) {}
export const layerDrive = (options: { readonly endpoint: string }) =>
export const layerDrive = (options: { readonly endpoint: string; readonly version: string }) =>
Layer.effect(
Service,
Effect.gen(function* () {
@ -277,7 +276,8 @@ export const layerDrive = (options: { readonly endpoint: string }) =>
label: "opencode drive backend websocket",
data: () => ({}),
decode: SimulationProtocol.Backend.decodeRequestEffect,
handle: (socket, request) => handle(driver, tools, fibers, activeController, controllerLock, socket, request),
handle: (socket, request) =>
handle(driver, tools, fibers, activeController, controllerLock, socket, request, options.version),
close: (socket) =>
Effect.all([releaseController(activeController, controllerLock, socket), tools.release(socket)], {
discard: true,
@ -306,13 +306,14 @@ function handle(
controllerLock: Semaphore.Semaphore,
socket: ControlSocket,
request: SimulationProtocol.Backend.Request,
version: string,
) {
switch (request.method) {
case "simulation.handshake":
return SimulationProtocol.Handshake.dispatch(
{
role: "backend",
server: { name: "opencode", version: InstallationVersion },
server: { name: "opencode", version },
capabilities: SimulationProtocol.Backend.Capabilities,
},
request.params,