feat(plugin): expose app metadata (#38179)
This commit is contained in:
parent
2ed8fe5960
commit
8de40be6ea
71 changed files with 477 additions and 286 deletions
|
|
@ -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,
|
||||
}),
|
||||
),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -1,17 +1,16 @@
|
|||
import { InstallationVersion } from "@opencode-ai/util/installation/version"
|
||||
import { Effect } from "effect"
|
||||
import { SimulationControlServer } from "../control-server"
|
||||
import { SimulationProtocol } from "../protocol"
|
||||
import { SimulationActions, type Harness } from "./actions"
|
||||
import { SimulationRenderer } from "./renderer"
|
||||
|
||||
function handle(harness: Harness, request: SimulationProtocol.Frontend.Request) {
|
||||
function handle(harness: Harness, request: SimulationProtocol.Frontend.Request, version: string) {
|
||||
switch (request.method) {
|
||||
case "simulation.handshake":
|
||||
return SimulationProtocol.Handshake.dispatch(
|
||||
{
|
||||
role: "ui",
|
||||
server: { name: "opencode", version: InstallationVersion },
|
||||
server: { name: "opencode", version },
|
||||
capabilities: SimulationProtocol.Frontend.Capabilities,
|
||||
},
|
||||
request.params,
|
||||
|
|
@ -59,13 +58,17 @@ function handle(harness: Harness, request: SimulationProtocol.Frontend.Request)
|
|||
}
|
||||
}
|
||||
|
||||
export const start = Effect.fn("SimulationServer.start")(function* (harness: Harness, endpoint: string) {
|
||||
export const start = Effect.fn("SimulationServer.start")(function* (
|
||||
harness: Harness,
|
||||
endpoint: string,
|
||||
version = "unknown",
|
||||
) {
|
||||
return yield* SimulationControlServer.start({
|
||||
endpoint,
|
||||
label: "opencode drive ui websocket",
|
||||
data: () => ({ drive: true as const }),
|
||||
decode: SimulationProtocol.Frontend.decodeRequestEffect,
|
||||
handle: (_socket, request) => handle(harness, request),
|
||||
handle: (_socket, request) => handle(harness, request, version),
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import { SimulationRenderer } from "./renderer"
|
|||
import { SimulationServer } from "./server"
|
||||
|
||||
/** Drive-mode renderer and control-server acquisition. */
|
||||
export const create = Effect.fn("Drive.create")(function* (options: CliRendererConfig) {
|
||||
export const create = Effect.fn("Drive.create")(function* (options: CliRendererConfig, version: string) {
|
||||
const headless = (yield* Config.string("OPENCODE_DRIVE_RENDERER").pipe(Config.withDefault("visible"))) === "headless"
|
||||
const manifest = yield* DriveManifest.resolve()
|
||||
const renderer = headless
|
||||
|
|
@ -19,7 +19,7 @@ export const create = Effect.fn("Drive.create")(function* (options: CliRendererC
|
|||
}),
|
||||
)
|
||||
if (!headless && manifest.viewport) renderer.resize(manifest.viewport.cols, manifest.viewport.rows)
|
||||
const server = yield* SimulationServer.start(SimulationActions.createHarness(renderer), manifest.endpoints.ui)
|
||||
const server = yield* SimulationServer.start(SimulationActions.createHarness(renderer), manifest.endpoints.ui, version)
|
||||
yield* Effect.sync(() => process.stderr.write(`opencode drive ui websocket: ${server.url}\n`))
|
||||
return renderer
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue