Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/plugin/v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,12 @@ async function reconcileProviderSources(
const definition = Plugin.define({
id: 'opencode-litellm',
async setup(context) {
// OpenCode 1.18.x embeds a v2 plugin host whose context has no `provider`
// domain. It still calls `setup` on any plugin that exports one, but those
// versions are served by the `server()` entrypoint below. Bail out before
// touching the logger so `server()`'s client-backed logging stays intact.
if (!context.provider) return

initV2Logging()

const pluginOptions = asRecord(context.options)
Expand Down
19 changes: 19 additions & 0 deletions test/plugin-v2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,25 @@ describe('OpenCode 2 plugin entrypoint', () => {
expect(legacy.event).toEqual(expect.any(Function))
})

it('does nothing when the host context has no provider API', async () => {
const log = vi.spyOn(console, 'log').mockImplementation(() => {})
globalThis.fetch = vi.fn(async () => {
throw new Error('setup must not probe the network without a provider API')
})
// OpenCode 1.18.x embeds a v2 plugin host whose context exposes `catalog`
// instead of `provider`; the legacy `server()` entrypoint serves that host.
const context = {
options: {},
catalog: { transform: vi.fn(), reload: vi.fn() },
} as unknown as Context

const cleanup = await plugin.setup(context)

expect(cleanup).toBeUndefined()
expect(log).not.toHaveBeenCalled()
expect(globalThis.fetch).not.toHaveBeenCalled()
})

it('registers discovered LiteLLM models through the provider transform', async () => {
cacheDirectory = mkdtempSync(join(tmpdir(), 'opencode-litellm-test-'))
process.env.XDG_CACHE_HOME = cacheDirectory
Expand Down