fix(config): use package.json name for file:// plugin identity#16200
fix(config): use package.json name for file:// plugin identity#16200coleleavitt wants to merge 4 commits intoanomalyco:devfrom
Conversation
When switching between models (e.g., Claude to ChatGPT), the SDK may be created from @ai-sdk/openai-compatible which does not have a .responses() method. This causes TypeError: sdk.responses is not a function. Added fallback checks to openai, azure, and azure-cognitive-services custom loaders to use sdk.languageModel() when sdk.responses is undefined. Fixes model switching crashes.
The Codex plugin's custom fetch wrapper was mutating the global provider.options object, which caused subsequent Anthropic model loads to fail with 'Bad Request'. This happened because: 1. User switches to Codex (OpenAI) - custom fetch added to options 2. options.fetch mutation persists in provider.options 3. User switches to Anthropic - SDK cache key includes mutated options 4. Anthropic SDK loads with corrupted options, causing API errors Fix: Create a local copy (sdkOptions) before adding the fetch wrapper, preserving the original provider.options for other provider instances. Fixes: Model switching from Codex to Anthropic causes API errors
Previously, file:// plugins were deduplicated by filename only, causing collisions when multiple plugins used standard entry points like index.js. Example: file:///path/to/plugin-a/dist/index.js -> 'index' (COLLISION) file:///path/to/plugin-b/dist/index.js -> 'index' (COLLISION) This change: - First checks for package.json 'name' field (up to 5 dirs up) - Falls back to full canonical URL (via realpathSync) if no package.json - Properly deduplicates file:// plugins with their npm counterparts This matches Node.js ESM loader semantics and handles: - Multiple plugins with same filename in different directories - npm package + local file:// version of same plugin (deduplicates correctly) - Symlinks resolved to canonical paths - Cross-platform support (Windows + Unix) Fixes anomalyco#8759, anomalyco#11159, anomalyco#14304
|
Thanks for the mention — I previously tried to address the same collision in #15598. The approach here (use nearest package.json name for file:// plugins, and fall back to canonicalized URL via realpath) looks like a solid way to avoid the "dist/index.js" filename collision while still deduping npm vs local dev installs. One question/concern: this PR also changes packages/opencode/src/plugin/codex.ts and packages/opencode/src/provider/provider.ts. Those look orthogonal to getPluginName()/plugin deduplication — was that intentional? If not, I’d strongly recommend splitting them into a separate PR to keep review + risk surface tight. Minor: findPackageJsonName() currently caps the upward search at 5 dirs; might be worth confirming that’s enough for typical layouts (dist/, build/, etc.). |
|
The following comment was made by an LLM, it may be inaccurate: Related PRs found:
These PRs are addressing the same underlying problem of plugin deduplication collisions. PR #16200 appears to be a more comprehensive fix that builds upon or supersedes these earlier attempts (the PR notes it "Supersedes #8758" and closes multiple related issues #8759, #10115, #11159, #12285, #14304). |
Issue for this PR
Closes #8759
Closes #10115
Closes #11159
Closes #12285
Closes #14304
Supersedes #8758 (my previous attempt, had conflicts)
Related to #15598 (similar fix by @cyberprophet)
Type of change
What does this PR do?
Problem: Multiple file:// plugins with the same entry filename (e.g.,
dist/index.js) were incorrectly deduplicated becausegetPluginName()only extracted the filename.Solution: For file:// URLs, first look up the nearest
package.jsonand use itsnamefield. If no package.json exists, fall back to the full canonical URL (viarealpathSync).This approach:
oh-my-opencode@2.4.3andfile:///path/to/oh-my-opencode/dist/index.jsresolve to"oh-my-opencode"(from package.json)How did you verify your code works?
bun test test/config/config.test.ts- all 65 tests passbun run typecheckpasses for opencode packageScreenshots / recordings
N/A - non-UI change
Checklist