feat(plugin): add namespaced hook API (#33416)
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { AgentV2 } from "@opencode-ai/core/agent"
|
||||
import { PluginBoot } from "@opencode-ai/core/plugin/boot"
|
||||
import { Effect } from "effect"
|
||||
import { HttpApiBuilder } from "effect/unstable/httpapi"
|
||||
import { Api } from "../api"
|
||||
@@ -8,7 +7,6 @@ import { response } from "../groups/location"
|
||||
export const AgentHandler = HttpApiBuilder.group(Api, "server.agent", (handlers) =>
|
||||
handlers.handle("agent.list", () =>
|
||||
Effect.gen(function* () {
|
||||
yield* PluginBoot.Service.use((plugin) => plugin.wait())
|
||||
return yield* response(AgentV2.Service.use((agent) => agent.all()))
|
||||
}),
|
||||
),
|
||||
|
||||
@@ -1,24 +1,15 @@
|
||||
import { Catalog } from "@opencode-ai/core/catalog"
|
||||
import { PluginBoot } from "@opencode-ai/core/plugin/boot"
|
||||
import { Effect } from "effect"
|
||||
import { HttpApiBuilder } from "effect/unstable/httpapi"
|
||||
import { Api } from "../api"
|
||||
import { ServiceUnavailableError } from "../errors"
|
||||
import { response } from "../groups/location"
|
||||
|
||||
const catalogUnavailable = new ServiceUnavailableError({
|
||||
message: "Model catalog is unavailable",
|
||||
service: "catalog",
|
||||
})
|
||||
|
||||
export const ModelHandler = HttpApiBuilder.group(Api, "server.model", (handlers) =>
|
||||
Effect.gen(function* () {
|
||||
return handlers.handle(
|
||||
"model.list",
|
||||
Effect.fn(function* () {
|
||||
const catalog = yield* Catalog.Service
|
||||
const pluginBoot = yield* PluginBoot.Service
|
||||
yield* pluginBoot.wait().pipe(Effect.catchDefect(() => Effect.fail(catalogUnavailable)))
|
||||
return yield* response(catalog.model.available())
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -1,17 +1,11 @@
|
||||
import { Catalog } from "@opencode-ai/core/catalog"
|
||||
import { PluginBoot } from "@opencode-ai/core/plugin/boot"
|
||||
import { ProviderV2 } from "@opencode-ai/core/provider"
|
||||
import { Effect } from "effect"
|
||||
import { HttpApiBuilder } from "effect/unstable/httpapi"
|
||||
import { Api } from "../api"
|
||||
import { ProviderNotFoundError, ServiceUnavailableError } from "../errors"
|
||||
import { ProviderNotFoundError } from "../errors"
|
||||
import { response } from "../groups/location"
|
||||
|
||||
const catalogUnavailable = new ServiceUnavailableError({
|
||||
message: "Provider catalog is unavailable",
|
||||
service: "catalog",
|
||||
})
|
||||
|
||||
export const ProviderHandler = HttpApiBuilder.group(Api, "server.provider", (handlers) =>
|
||||
Effect.gen(function* () {
|
||||
return handlers
|
||||
@@ -19,8 +13,6 @@ export const ProviderHandler = HttpApiBuilder.group(Api, "server.provider", (han
|
||||
"provider.list",
|
||||
Effect.fn(function* () {
|
||||
const catalog = yield* Catalog.Service
|
||||
const pluginBoot = yield* PluginBoot.Service
|
||||
yield* pluginBoot.wait().pipe(Effect.catchDefect(() => Effect.fail(catalogUnavailable)))
|
||||
return yield* response(catalog.provider.available())
|
||||
}),
|
||||
)
|
||||
@@ -28,8 +20,6 @@ export const ProviderHandler = HttpApiBuilder.group(Api, "server.provider", (han
|
||||
"provider.get",
|
||||
Effect.fn(function* (ctx) {
|
||||
const catalog = yield* Catalog.Service
|
||||
const pluginBoot = yield* PluginBoot.Service
|
||||
yield* pluginBoot.wait().pipe(Effect.catchDefect(() => Effect.fail(catalogUnavailable)))
|
||||
const provider = yield* catalog.provider.get(ctx.params.providerID)
|
||||
if (!provider)
|
||||
return yield* new ProviderNotFoundError({
|
||||
|
||||
Reference in New Issue
Block a user