mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-20 18:57:17 +03:00
fix(server): stop waiting for plugins in request handlers (#62796)
This commit is contained in:
committed by
GitHub
Unverified
parent
adb0053d09
commit
bcaf561d94
@@ -2,6 +2,7 @@ import { Effect } from "effect"
|
||||
import { OpenCode, type IntegrationInfo, type IntegrationMethod, type OpenCodeClient } from "@opencode/client"
|
||||
import { Service } from "@opencode/client/effect/service"
|
||||
import { ServerConnection } from "../../../services/server-connection"
|
||||
import { waitForPlugins } from "../../../services/plugin-startup"
|
||||
|
||||
export const location = { directory: process.cwd() }
|
||||
|
||||
@@ -15,8 +16,7 @@ export function request<A>(run: (signal: AbortSignal) => Promise<A>) {
|
||||
}
|
||||
|
||||
export const loadIntegrations = Effect.fn("cli.auth.integrations")(function* (client: OpenCodeClient) {
|
||||
// The model endpoint is the existing public readiness boundary for the initial plugin generation.
|
||||
yield* request((signal) => client.model.default({ location }, { signal }))
|
||||
yield* waitForPlugins(client, location.directory)
|
||||
return yield* request((signal) => client.integration.list({ location }, { signal })).pipe(
|
||||
Effect.map((response) =>
|
||||
response.data.toSorted((a, b) => Number(b.id === "opencode-go") - Number(a.id === "opencode-go")),
|
||||
|
||||
@@ -5,12 +5,14 @@ import { Commands } from "../../commands"
|
||||
import { Runtime } from "../../../framework/runtime"
|
||||
import { Service } from "@opencode/client/effect/service"
|
||||
import { ServerConnection } from "../../../services/server-connection"
|
||||
import { waitForPlugins } from "../../../services/plugin-startup"
|
||||
|
||||
export default Runtime.handler(
|
||||
Commands.commands.debug.commands.agents,
|
||||
Effect.fn("cli.debug.agents")(function* () {
|
||||
const { endpoint } = yield* ServerConnection.resolve()
|
||||
const client = OpenCode.make({ baseUrl: endpoint.url, headers: Service.headers(endpoint) })
|
||||
yield* waitForPlugins(client, process.cwd())
|
||||
const response = yield* Effect.promise(() => client.agent.list({ location: { directory: process.cwd() } }))
|
||||
process.stdout.write(
|
||||
JSON.stringify(
|
||||
|
||||
@@ -5,6 +5,7 @@ import { EOL } from "node:os"
|
||||
import { Commands } from "../commands"
|
||||
import { Runtime } from "../../framework/runtime"
|
||||
import { ServerConnection } from "../../services/server-connection"
|
||||
import { waitForPlugins } from "../../services/plugin-startup"
|
||||
|
||||
export default Runtime.handler(
|
||||
Commands.commands.models,
|
||||
@@ -14,6 +15,7 @@ export default Runtime.handler(
|
||||
baseUrl: server.endpoint.url,
|
||||
headers: Service.headers(server.endpoint),
|
||||
})
|
||||
yield* waitForPlugins(client, process.cwd())
|
||||
const response = yield* Effect.promise(() => client.model.list({ location: { directory: process.cwd() } }))
|
||||
const models = response.data
|
||||
.map((model) => `${model.providerID}/${model.id}`)
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import type { OpenCodeClient } from "@opencode/client"
|
||||
import { Effect, Schedule } from "effect"
|
||||
|
||||
// Catalog reads return whatever is loaded, and a cold Location lists no plugins until its first activation.
|
||||
// One-shot commands read once and exit, so they give that activation a moment before reading.
|
||||
export const waitForPlugins = (client: OpenCodeClient, directory: string) =>
|
||||
Effect.tryPromise((signal) => client.plugin.list({ location: { directory } }, { signal })).pipe(
|
||||
Effect.repeat({
|
||||
until: (plugins) => plugins.data.length > 0,
|
||||
schedule: Schedule.spaced("25 millis").pipe(Schedule.upTo({ duration: "5 seconds" })),
|
||||
}),
|
||||
Effect.ignore,
|
||||
)
|
||||
Reference in New Issue
Block a user