From a756c60a0b405d04ff9cf21118eef3d996f803a0 Mon Sep 17 00:00:00 2001 From: rookie136 <1362411491@qq.com> Date: Thu, 19 Nov 2026 17:46:12 +0800 Subject: [PATCH] fix(provider): keep configured provider connected when directory is unavailable Some plugin contexts (notably the V2 host) do not expose the provider directory, so refreshing the connectivity snapshot throws and ensureProviderConnected() denies providers that are actually configured. Fall back to the explicitly configured opencodeProvider so internal structured-output calls are still attempted; an invalid provider id still fails on the call and falls back to the external API. --- src/index.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/index.ts b/src/index.ts index 2dc657d5..cb8df6a1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -30,6 +30,7 @@ import { isInternalStructuredSession, noteStructuredOutputStep, rememberSessionModel, + setConnectedProviders, STRUCTURED_OUTPUT_AGENT, STRUCTURED_OUTPUT_MAX_STEPS, STRUCTURED_OUTPUT_TOOLS, @@ -435,6 +436,14 @@ export const OpenCodeMemPlugin: Plugin = async (ctx: PluginInput) => { } } catch (error) { log("Failed to refresh opencode provider state", { error: String(error) }); + // The host provider directory may be unavailable (e.g. a plugin context + // without `ctx.provider`). Keep the explicitly configured provider + // connected so structured-output calls are attempted instead of being + // denied by the connectivity gate; a bad provider id still fails loudly + // on the call itself and falls back to the external API. + if (CONFIG.opencodeProvider) { + setConnectedProviders([CONFIG.opencodeProvider]); + } } };