|
|
@@ -18,7 +18,6 @@ import { gitlabAuthPlugin as GitlabAuthPlugin } from "opencode-gitlab-auth"
|
|
|
import { PoeAuthPlugin } from "opencode-poe-auth"
|
|
|
import { CloudflareAIGatewayAuthPlugin, CloudflareWorkersAuthPlugin } from "./cloudflare"
|
|
|
import { Effect, Layer, Context, Stream } from "effect"
|
|
|
-import { EffectLogger } from "@/effect/logger"
|
|
|
import { InstanceState } from "@/effect/instance-state"
|
|
|
import { errorMessage } from "@/util/error"
|
|
|
import { PluginLoader } from "./loader"
|
|
|
@@ -90,14 +89,6 @@ export namespace Plugin {
|
|
|
return result
|
|
|
}
|
|
|
|
|
|
- function publishPluginError(bus: Bus.Interface, message: string) {
|
|
|
- Effect.runFork(
|
|
|
- bus
|
|
|
- .publish(Session.Event.Error, { error: new NamedError.Unknown({ message }).toObject() })
|
|
|
- .pipe(Effect.provide(EffectLogger.layer)),
|
|
|
- )
|
|
|
- }
|
|
|
-
|
|
|
async function applyPlugin(load: PluginLoader.Loaded, input: PluginInput, hooks: Hooks[]) {
|
|
|
const plugin = readV1Plugin(load.mod, load.spec, "server", "detect")
|
|
|
if (plugin) {
|
|
|
@@ -116,6 +107,13 @@ export namespace Plugin {
|
|
|
Effect.gen(function* () {
|
|
|
const bus = yield* Bus.Service
|
|
|
const config = yield* Config.Service
|
|
|
+ const ctx = yield* Effect.context()
|
|
|
+
|
|
|
+ function publishPluginError(message: string) {
|
|
|
+ Effect.runForkWith(ctx)(
|
|
|
+ bus.publish(Session.Event.Error, { error: new NamedError.Unknown({ message }).toObject() }),
|
|
|
+ )
|
|
|
+ }
|
|
|
|
|
|
const state = yield* InstanceState.make<State>(
|
|
|
Effect.fn("Plugin.state")(function* (ctx) {
|
|
|
@@ -187,24 +185,24 @@ export namespace Plugin {
|
|
|
if (stage === "install") {
|
|
|
const parsed = parsePluginSpecifier(spec)
|
|
|
log.error("failed to install plugin", { pkg: parsed.pkg, version: parsed.version, error: message })
|
|
|
- publishPluginError(bus, `Failed to install plugin ${parsed.pkg}@${parsed.version}: ${message}`)
|
|
|
+ publishPluginError(`Failed to install plugin ${parsed.pkg}@${parsed.version}: ${message}`)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
if (stage === "compatibility") {
|
|
|
log.warn("plugin incompatible", { path: spec, error: message })
|
|
|
- publishPluginError(bus, `Plugin ${spec} skipped: ${message}`)
|
|
|
+ publishPluginError(`Plugin ${spec} skipped: ${message}`)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
if (stage === "entry") {
|
|
|
log.error("failed to resolve plugin server entry", { path: spec, error: message })
|
|
|
- publishPluginError(bus, `Failed to load plugin ${spec}: ${message}`)
|
|
|
+ publishPluginError(`Failed to load plugin ${spec}: ${message}`)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
log.error("failed to load plugin", { path: spec, target: resolved?.entry, error: message })
|
|
|
- publishPluginError(bus, `Failed to load plugin ${spec}: ${message}`)
|
|
|
+ publishPluginError(`Failed to load plugin ${spec}: ${message}`)
|
|
|
},
|
|
|
},
|
|
|
}),
|