-
Notifications
You must be signed in to change notification settings - Fork 3k
fix: respect multimodal provider vision capabilities #2371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4eb8a2f
fix(plugin-state): track vision-capable multimodal models
code-yeongyu f801811
fix(shared): add vision-capable model cache store
code-yeongyu dd68035
fix(plugin-handlers): cache vision-capable provider models
code-yeongyu 8b0ca63
fix(look-at): build dynamic multimodal fallback chain
code-yeongyu 5d31bf4
fix(look-at): resolve multimodal models from vision-capable providers
code-yeongyu e513f66
fix: rename test file to .ts extension
code-yeongyu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| /// <reference types="bun-types" /> | ||
|
|
||
| import { describe, expect, test } from "bun:test" | ||
| import { applyProviderConfig } from "./provider-config-handler" | ||
| import { createModelCacheState } from "../plugin-state" | ||
| import { clearVisionCapableModelsCache, readVisionCapableModelsCache } from "../shared/vision-capable-models-cache" | ||
|
|
||
| describe("applyProviderConfig", () => { | ||
| test("caches vision-capable models from modalities and capabilities", () => { | ||
| // given | ||
| const modelCacheState = createModelCacheState() | ||
| const visionCapableModelsCache = modelCacheState.visionCapableModelsCache | ||
| if (!visionCapableModelsCache) { | ||
| throw new Error("visionCapableModelsCache should be initialized") | ||
| } | ||
| const config = { | ||
| provider: { | ||
| rundao: { | ||
| models: { | ||
| "public/qwen3.5-397b": { | ||
| modalities: { | ||
| input: ["text", "image"], | ||
| }, | ||
| }, | ||
| "public/text-only": { | ||
| modalities: { | ||
| input: ["text"], | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| google: { | ||
| models: { | ||
| "gemini-3-flash": { | ||
| capabilities: { | ||
| input: { | ||
| image: true, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } satisfies Record<string, unknown> | ||
|
|
||
| // when | ||
| applyProviderConfig({ config, modelCacheState }) | ||
|
|
||
| // then | ||
| expect(Array.from(visionCapableModelsCache.keys())).toEqual([ | ||
| "rundao/public/qwen3.5-397b", | ||
| "google/gemini-3-flash", | ||
| ]) | ||
| expect(readVisionCapableModelsCache()).toEqual([ | ||
| { providerID: "rundao", modelID: "public/qwen3.5-397b" }, | ||
| { providerID: "google", modelID: "gemini-3-flash" }, | ||
| ]) | ||
| }) | ||
|
|
||
| test("clears stale vision-capable models when provider config changes", () => { | ||
| // given | ||
| const modelCacheState = createModelCacheState() | ||
| const visionCapableModelsCache = modelCacheState.visionCapableModelsCache | ||
| if (!visionCapableModelsCache) { | ||
| throw new Error("visionCapableModelsCache should be initialized") | ||
| } | ||
| visionCapableModelsCache.set("stale/old-model", { | ||
| providerID: "stale", | ||
| modelID: "old-model", | ||
| }) | ||
|
|
||
| // when | ||
| applyProviderConfig({ | ||
| config: { provider: {} }, | ||
| modelCacheState, | ||
| }) | ||
|
|
||
| // then | ||
| expect(visionCapableModelsCache.size).toBe(0) | ||
| expect(readVisionCapableModelsCache()).toEqual([]) | ||
| }) | ||
| }) | ||
|
|
||
| clearVisionCapableModelsCache() | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,18 @@ | ||
| export type VisionCapableModel = { | ||
| providerID: string | ||
| modelID: string | ||
| } | ||
|
|
||
| export interface ModelCacheState { | ||
| modelContextLimitsCache: Map<string, number>; | ||
| visionCapableModelsCache?: Map<string, VisionCapableModel>; | ||
| anthropicContext1MEnabled: boolean; | ||
| } | ||
|
|
||
| export function createModelCacheState(): ModelCacheState { | ||
| return { | ||
| modelContextLimitsCache: new Map<string, number>(), | ||
| visionCapableModelsCache: new Map<string, VisionCapableModel>(), | ||
| anthropicContext1MEnabled: false, | ||
| }; | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import type { VisionCapableModel } from "../plugin-state" | ||
|
|
||
| let visionCapableModelsCache = new Map<string, VisionCapableModel>() | ||
|
|
||
| export function setVisionCapableModelsCache( | ||
| cache: Map<string, VisionCapableModel>, | ||
| ): void { | ||
| visionCapableModelsCache = cache | ||
| } | ||
|
|
||
| export function readVisionCapableModelsCache(): VisionCapableModel[] { | ||
| return Array.from(visionCapableModelsCache.values()) | ||
| } | ||
|
|
||
| export function clearVisionCapableModelsCache(): void { | ||
| visionCapableModelsCache = new Map<string, VisionCapableModel>() | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| /// <reference types="bun-types" /> | ||
|
|
||
| import { afterEach, beforeEach, describe, expect, mock, spyOn, test } from "bun:test" | ||
| import type { PluginInput } from "@opencode-ai/plugin" | ||
| import { resolveMultimodalLookerAgentMetadata } from "./multimodal-agent-metadata" | ||
| import { setVisionCapableModelsCache, clearVisionCapableModelsCache } from "../../shared/vision-capable-models-cache" | ||
| import * as connectedProvidersCache from "../../shared/connected-providers-cache" | ||
| import * as modelAvailability from "../../shared/model-availability" | ||
|
|
||
| function createPluginInput(agentData: Array<Record<string, unknown>>): PluginInput { | ||
| const client = {} as PluginInput["client"] | ||
| Object.assign(client, { | ||
| app: { | ||
| agents: mock(async () => ({ data: agentData })), | ||
| }, | ||
| }) | ||
|
|
||
| return { | ||
| client, | ||
| project: {} as PluginInput["project"], | ||
| directory: "/project", | ||
| worktree: "/project", | ||
| serverUrl: new URL("http://localhost"), | ||
| $: {} as PluginInput["$"], | ||
| } | ||
| } | ||
|
|
||
| describe("resolveMultimodalLookerAgentMetadata", () => { | ||
| beforeEach(() => { | ||
| clearVisionCapableModelsCache() | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| clearVisionCapableModelsCache() | ||
| ;(modelAvailability.fetchAvailableModels as unknown as { mockRestore?: () => void }).mockRestore?.() | ||
| ;(connectedProvidersCache.readConnectedProvidersCache as unknown as { mockRestore?: () => void }).mockRestore?.() | ||
| }) | ||
|
|
||
| test("returns configured multimodal-looker model when it already matches a vision-capable override", async () => { | ||
| // given | ||
| setVisionCapableModelsCache(new Map([ | ||
| [ | ||
| "rundao/public/qwen3.5-397b", | ||
| { providerID: "rundao", modelID: "public/qwen3.5-397b" }, | ||
| ], | ||
| ])) | ||
| spyOn(modelAvailability, "fetchAvailableModels").mockResolvedValue( | ||
| new Set(["rundao/public/qwen3.5-397b"]), | ||
| ) | ||
| spyOn(connectedProvidersCache, "readConnectedProvidersCache").mockReturnValue(["rundao"]) | ||
| const ctx = createPluginInput([ | ||
| { | ||
| name: "multimodal-looker", | ||
| model: { providerID: "rundao", modelID: "public/qwen3.5-397b" }, | ||
| }, | ||
| ]) | ||
|
|
||
| // when | ||
| const result = await resolveMultimodalLookerAgentMetadata(ctx) | ||
|
|
||
| // then | ||
| expect(result).toEqual({ | ||
| agentModel: { providerID: "rundao", modelID: "public/qwen3.5-397b" }, | ||
| agentVariant: undefined, | ||
| }) | ||
| }) | ||
|
|
||
| test("prefers connected vision-capable provider models before the hardcoded fallback chain", async () => { | ||
| // given | ||
| setVisionCapableModelsCache(new Map([ | ||
| [ | ||
| "rundao/public/qwen3.5-397b", | ||
| { providerID: "rundao", modelID: "public/qwen3.5-397b" }, | ||
| ], | ||
| ])) | ||
| spyOn(modelAvailability, "fetchAvailableModels").mockResolvedValue( | ||
| new Set(["openai/gpt-5.4", "rundao/public/qwen3.5-397b"]), | ||
| ) | ||
| spyOn(connectedProvidersCache, "readConnectedProvidersCache").mockReturnValue(["openai", "rundao"]) | ||
| const ctx = createPluginInput([ | ||
| { | ||
| name: "multimodal-looker", | ||
| model: { providerID: "openai", modelID: "gpt-5.4" }, | ||
| variant: "medium", | ||
| }, | ||
| ]) | ||
|
|
||
| // when | ||
| const result = await resolveMultimodalLookerAgentMetadata(ctx) | ||
|
|
||
| // then | ||
| expect(result).toEqual({ | ||
| agentModel: { providerID: "rundao", modelID: "public/qwen3.5-397b" }, | ||
| agentVariant: undefined, | ||
| }) | ||
| }) | ||
|
|
||
| test("falls back to the hardcoded multimodal chain when no dynamic vision model exists", async () => { | ||
| // given | ||
| spyOn(modelAvailability, "fetchAvailableModels").mockResolvedValue( | ||
| new Set(["google/gemini-3-flash"]), | ||
| ) | ||
| spyOn(connectedProvidersCache, "readConnectedProvidersCache").mockReturnValue(["google"]) | ||
| const ctx = createPluginInput([]) | ||
|
|
||
| // when | ||
| const result = await resolveMultimodalLookerAgentMetadata(ctx) | ||
|
|
||
| // then | ||
| expect(result).toEqual({ | ||
| agentModel: { providerID: "google", modelID: "gemini-3-flash" }, | ||
| agentVariant: undefined, | ||
| }) | ||
| }) | ||
| }) |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: Custom agent: Opencode Compatibility
According to the OpenCode SDK source code,
capabilitiesis not a valid property withinProviderConfig.models. Image support in user configuration is exclusively declared usingmodalities: { input: ['image'] }. Thecapabilitiesobject is an internal model representation in OpenCode and is not exposed in the user-facing configuration schema.Prompt for AI agents