fix(plugin): add V1 default export descriptor to stop legacy loader probing every helper - #89
Open
Futuri-Risk wants to merge 1 commit into
Open
fix(plugin): add V1 default export descriptor to stop legacy loader probing every helper#89Futuri-Risk wants to merge 1 commit into
Futuri-Risk wants to merge 1 commit into
Conversation
…robing every helper
opencode's plugin loader prefers a { id, server } default export
(readV1Plugin) and invokes only `server`. Without one, the legacy
fallback invokes every function-typed export as if it were the plugin;
the pure helpers throw on the plugin-init argument and every worker
logs "failed to load plugin" (messages.filter / finish.includes /
messages.map is not a function) even though the proxy still serves.
Fixes KochC#86
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #86.
What
Adds a V1 plugin descriptor as the default export of
index.js(and the rebuiltdist/llm-proxy.js):All 28 named exports stay untouched, so direct imports and the test suite are unaffected.
Why
Without a default export, opencode's loader takes the legacy path (
getLegacyPlugins), which invokes every function-typed export as if it were the plugin factory. The pure helpers (buildPrompt,mapFinishReason, …) throw on the plugin-init argument, so every worker logsfailed to load plugin(messages.filter/finish.includes/messages.map is not a function— whichever helper it reaches). The proxy still serves today only becauseOpenAIProxyPluginhappens to run first inObject.valuesorder andBun.servefires as a side effect before any helper throws — i.e. it works by iteration-order luck.With the descriptor present,
readV1Plugin(packages/opencode/src/plugin/shared.ts) detects it and invokes onlyserver.Verification
Shipped-artifact path (not a wrapper):
npm packfrom this branch → installed the tarball into opencode's package cache → registered bare-name ("plugin": ["opencode-llm-proxy"]) in a scratch project → bootedopencode serve(1.18.18, current latest) and forced instance creation:failed to load pluginlines: 0 (previously 1 per worker on every boot)GET /v1/models→ HTTP 200 with the model listUnit suite: 232/232 pass (230 baseline + 2 new), eslint clean. New tests assert the descriptor shape and invoke
descriptor.server({ client })under the existing mocked-Bunfixture (hoisted to a sharedwithMockedBunhelper) to prove the proxy actually boots through it.Older-opencode behavior (no regression)
readV1Pluginexists in every opencode release I checked back to v1.15.0, so the V1 path covers everything reasonably current.getServerPluginexplicitly recognizes{ server }objects (index.ts L88–93) — the descriptor is treated as a plugin whoseserverisOpenAIProxyPlugin, and the plugin's existingstate.startedguard makes the second invocation a no-op returning{}. Helper-probe log noise on those old builds is unchanged from today.Extras
.gitattributeswithdist/** text eol=lf— the committed bundle is regenerated byprepack, so keeping it LF-only avoids whole-file churn on rebuilds.