chore(core): checkpoint model capability defaults
This commit is contained in:
parent
ed4f833813
commit
77fce8b24c
14 changed files with 301 additions and 25 deletions
|
|
@ -680,9 +680,17 @@ describe("Config", () => {
|
|||
options: { apiKey: "secret" },
|
||||
models: {
|
||||
model: {
|
||||
attachment: true,
|
||||
options: { reasoningEffort: "high" },
|
||||
variants: { fast: { temperature: 0.2 } },
|
||||
},
|
||||
text: {
|
||||
attachment: false,
|
||||
},
|
||||
audio: {
|
||||
attachment: true,
|
||||
modalities: { input: ["audio"], output: ["audio"] },
|
||||
},
|
||||
},
|
||||
},
|
||||
openai: {
|
||||
|
|
@ -758,9 +766,16 @@ describe("Config", () => {
|
|||
settings: { apiKey: "secret" },
|
||||
models: {
|
||||
model: {
|
||||
capabilities: { tools: false, input: ["text", "image"], output: ["text"] },
|
||||
settings: { reasoningEffort: "high" },
|
||||
variants: [{ id: "fast", settings: { temperature: 0.2 } }],
|
||||
},
|
||||
text: {
|
||||
capabilities: { tools: false, input: ["text"], output: ["text"] },
|
||||
},
|
||||
audio: {
|
||||
capabilities: { tools: false, input: ["audio"], output: ["audio"] },
|
||||
},
|
||||
},
|
||||
})
|
||||
expect(documents[0]?.info.providers?.openai).toMatchObject({
|
||||
|
|
|
|||
|
|
@ -237,6 +237,7 @@ describe("ConfigProviderPlugin.Plugin", () => {
|
|||
|
||||
const provider = required(yield* catalog.provider.get(providerID))
|
||||
const model = required(yield* catalog.model.get(providerID, modelID))
|
||||
const defaultModel = required(yield* catalog.model.get(providerID, ModelV2.ID.make("default")))
|
||||
expect((yield* catalog.model.default())?.id).toBe(ModelV2.ID.make("default"))
|
||||
expect(provider.name).toBe("Renamed")
|
||||
expect((yield* integrations.get(Integration.ID.make("custom")))?.methods).toContainEqual({
|
||||
|
|
@ -252,6 +253,7 @@ describe("ConfigProviderPlugin.Plugin", () => {
|
|||
expect(model.modelID).toBe(ModelV2.ID.make("api-chat"))
|
||||
expect(model.name).toBe("Last")
|
||||
expect(model.capabilities).toEqual({ tools: true, input: ["text"], output: ["text"] })
|
||||
expect(defaultModel.capabilities).toEqual({ tools: false, input: ["text", "image"], output: ["text"] })
|
||||
expect(model.enabled).toBe(false)
|
||||
expect(model.limit).toEqual({ context: 100, output: 75 })
|
||||
expect(model.cost).toEqual([
|
||||
|
|
|
|||
|
|
@ -165,6 +165,21 @@ describe("ModelsDev Service", () => {
|
|||
}),
|
||||
)
|
||||
|
||||
it.effect("allows models.dev entries without legacy attachment metadata", () =>
|
||||
Effect.sync(() => {
|
||||
const result = Schema.decodeUnknownSync(ModelsDev.Model)({
|
||||
id: "no-attachment-model",
|
||||
name: "No Attachment Model",
|
||||
release_date: "2026-01-01",
|
||||
reasoning: false,
|
||||
tool_call: true,
|
||||
limit: { context: 128000, output: 8192 },
|
||||
})
|
||||
|
||||
expect(result.attachment).toBeUndefined()
|
||||
}),
|
||||
)
|
||||
|
||||
it.live("get() returns providers from disk when cache file exists", () =>
|
||||
Effect.gen(function* () {
|
||||
yield* writeCache(fixture)
|
||||
|
|
|
|||
|
|
@ -85,6 +85,24 @@ describe("ModelsDevPlugin", () => {
|
|||
},
|
||||
},
|
||||
},
|
||||
default: {
|
||||
id: "default",
|
||||
name: "Default",
|
||||
release_date: "2026-01-01",
|
||||
reasoning: false,
|
||||
tool_call: false,
|
||||
limit: { context: 128_000, output: 8_192 },
|
||||
},
|
||||
explicit: {
|
||||
id: "explicit",
|
||||
name: "Explicit",
|
||||
release_date: "2026-01-01",
|
||||
attachment: true,
|
||||
reasoning: false,
|
||||
tool_call: false,
|
||||
modalities: { input: ["audio"], output: ["audio"] },
|
||||
limit: { context: 128_000, output: 8_192 },
|
||||
},
|
||||
},
|
||||
},
|
||||
} satisfies Record<string, ModelsDev.Provider>),
|
||||
|
|
@ -101,9 +119,14 @@ describe("ModelsDevPlugin", () => {
|
|||
const providerID = ProviderV2.ID.make("acme")
|
||||
const base = yield* catalog.model.get(providerID, ModelV2.ID.make("gpt-5.4"))
|
||||
const fast = yield* catalog.model.get(providerID, ModelV2.ID.make("gpt-5.4-fast"))
|
||||
const defaults = yield* catalog.model.get(providerID, ModelV2.ID.make("default"))
|
||||
const explicit = yield* catalog.model.get(providerID, ModelV2.ID.make("explicit"))
|
||||
|
||||
expect(base?.variants).toEqual([])
|
||||
expect(base?.body).toEqual({})
|
||||
expect(base?.capabilities).toEqual({ tools: true, input: ["text"], output: ["text"] })
|
||||
expect(defaults?.capabilities).toEqual({ tools: false, input: ["text", "image"], output: ["text"] })
|
||||
expect(explicit?.capabilities).toEqual({ tools: false, input: ["audio"], output: ["audio"] })
|
||||
expect(fast).toMatchObject({
|
||||
id: "gpt-5.4-fast",
|
||||
modelID: "gpt-5.4",
|
||||
|
|
@ -181,6 +204,9 @@ describe("ModelsDevPlugin", () => {
|
|||
connections: [],
|
||||
}),
|
||||
])
|
||||
expect(yield* catalog.model.get(ProviderV2.ID.opencode, ModelV2.ID.make("gpt-5.5"))).toMatchObject({
|
||||
capabilities: { tools: true, input: ["text", "image"], output: ["text"] },
|
||||
})
|
||||
}).pipe(Effect.provide(AppNodeBuilder.build(ModelsDev.node))),
|
||||
(previous) =>
|
||||
Effect.sync(() => {
|
||||
|
|
|
|||
|
|
@ -240,7 +240,7 @@ Recent work
|
|||
expect(messages[1]?.content).toEqual([{ type: "text", text: "Review this directory" }])
|
||||
})
|
||||
|
||||
test("uses materialized image data as provider media and drops unsupported attachments", () => {
|
||||
test("defaults missing model capabilities to text and image input", () => {
|
||||
const data = Base64.make("AAECAw==")
|
||||
const messages = toLLMMessages(
|
||||
[
|
||||
|
|
@ -266,6 +266,113 @@ Recent work
|
|||
expect(messages[0]?.content).toEqual([
|
||||
{ type: "text", text: "Inspect this image" },
|
||||
{ type: "media", mediaType: "image/png", data, filename: "image.png" },
|
||||
{
|
||||
type: "text",
|
||||
text: 'ERROR: Cannot read "document.pdf" (this model does not support pdf input). Inform the user.',
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
test("uses explicit model input capabilities instead of attachment defaults", () => {
|
||||
const data = Base64.make("AAECAw==")
|
||||
const messages = toLLMMessages(
|
||||
[
|
||||
SessionMessage.User.make({
|
||||
id: id("user-unsupported-pdf"),
|
||||
type: "user",
|
||||
text: "Inspect these files",
|
||||
files: [
|
||||
FileAttachment.make({ data, mime: "image/png", source: { type: "inline" }, name: "image.png" }),
|
||||
FileAttachment.make({
|
||||
data: Base64.make("JVBERg=="),
|
||||
mime: "application/pdf",
|
||||
source: { type: "inline" },
|
||||
name: "document.pdf",
|
||||
}),
|
||||
],
|
||||
time: { created },
|
||||
}),
|
||||
],
|
||||
model,
|
||||
model.providerID,
|
||||
{ tools: true, input: ["text", "pdf"], output: ["text"] },
|
||||
)
|
||||
|
||||
expect(messages[0]?.content).toEqual([
|
||||
{ type: "text", text: "Inspect these files" },
|
||||
{
|
||||
type: "text",
|
||||
text: 'ERROR: Cannot read "image.png" (this model does not support image input). Inform the user.',
|
||||
},
|
||||
{ type: "media", mediaType: "application/pdf", data: "JVBERg==", filename: "document.pdf" },
|
||||
])
|
||||
})
|
||||
|
||||
test("treats explicit empty input capabilities as authoritative", () => {
|
||||
const messages = toLLMMessages(
|
||||
[
|
||||
SessionMessage.User.make({
|
||||
id: id("user-empty-capabilities"),
|
||||
type: "user",
|
||||
text: "Inspect this image",
|
||||
files: [
|
||||
FileAttachment.make({
|
||||
data: Base64.make("AAECAw=="),
|
||||
mime: "image/png",
|
||||
source: { type: "inline" },
|
||||
name: "image.png",
|
||||
}),
|
||||
],
|
||||
time: { created },
|
||||
}),
|
||||
],
|
||||
model,
|
||||
model.providerID,
|
||||
{ tools: false, input: [], output: [] },
|
||||
)
|
||||
|
||||
expect(messages[0]?.content).toEqual([
|
||||
{ type: "text", text: "Inspect this image" },
|
||||
{
|
||||
type: "text",
|
||||
text: 'ERROR: Cannot read "image.png" (this model does not support image input). Inform the user.',
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
test("classifies audio and video MIME families through explicit capabilities", () => {
|
||||
const messages = toLLMMessages(
|
||||
[
|
||||
SessionMessage.User.make({
|
||||
id: id("user-media-capabilities"),
|
||||
type: "user",
|
||||
text: "Inspect this media",
|
||||
files: [
|
||||
FileAttachment.make({
|
||||
data: Base64.make("AAECAw=="),
|
||||
mime: "audio/mpeg",
|
||||
source: { type: "inline" },
|
||||
name: "audio.mp3",
|
||||
}),
|
||||
FileAttachment.make({
|
||||
data: Base64.make("AAECAw=="),
|
||||
mime: "video/webm",
|
||||
source: { type: "inline" },
|
||||
name: "video.webm",
|
||||
}),
|
||||
],
|
||||
time: { created },
|
||||
}),
|
||||
],
|
||||
model,
|
||||
model.providerID,
|
||||
{ tools: false, input: ["text", "audio", "video"], output: ["text"] },
|
||||
)
|
||||
|
||||
expect(messages[0]?.content).toEqual([
|
||||
{ type: "text", text: "Inspect this media" },
|
||||
{ type: "media", mediaType: "audio/mpeg", data: "AAECAw==", filename: "audio.mp3" },
|
||||
{ type: "media", mediaType: "video/webm", data: "AAECAw==", filename: "video.webm" },
|
||||
])
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import { EventTable } from "@opencode-ai/core/event/sql"
|
|||
import { Job } from "@opencode-ai/core/job"
|
||||
import { PermissionV2 } from "@opencode-ai/core/permission"
|
||||
import { AgentV2 } from "@opencode-ai/core/agent"
|
||||
import { Catalog } from "@opencode-ai/core/catalog"
|
||||
import { Config } from "@opencode-ai/core/config"
|
||||
import { Project } from "@opencode-ai/core/project"
|
||||
import { ProjectTable } from "@opencode-ai/core/project/sql"
|
||||
|
|
@ -37,6 +38,7 @@ import { Instructions } from "@opencode-ai/core/instructions"
|
|||
import { SkillGuidance } from "@opencode-ai/core/skill/guidance"
|
||||
import { ReferenceGuidance } from "@opencode-ai/core/reference/guidance"
|
||||
import { McpGuidance } from "@opencode-ai/core/mcp/guidance"
|
||||
import { ModelV2 } from "@opencode-ai/core/model"
|
||||
import { describe, expect } from "bun:test"
|
||||
import { eq } from "drizzle-orm"
|
||||
import { Effect, Layer } from "effect"
|
||||
|
|
@ -73,6 +75,20 @@ const model = OpenAIChat.route
|
|||
})
|
||||
.model({ id: "gpt-4o-mini" })
|
||||
const models = SessionRunnerModel.layerWith(() => Effect.succeed(SessionRunnerModel.resolved(model)))
|
||||
const catalog = Layer.mock(Catalog.Service, {
|
||||
provider: {
|
||||
get: () => Effect.die("unused"),
|
||||
all: () => Effect.die("unused"),
|
||||
available: () => Effect.die("unused"),
|
||||
},
|
||||
model: {
|
||||
get: (providerID, modelID) => Effect.succeed(ModelV2.Info.empty(providerID, modelID)),
|
||||
all: () => Effect.die("unused"),
|
||||
available: () => Effect.die("unused"),
|
||||
default: () => Effect.die("unused"),
|
||||
small: () => Effect.die("unused"),
|
||||
},
|
||||
})
|
||||
const systemContext = Layer.mock(InstructionBuiltIns.Service, { load: () => Effect.succeed(Instructions.empty) })
|
||||
const instructionContext = Layer.mock(InstructionDiscovery.Service, { load: () => Effect.succeed(Instructions.empty) })
|
||||
const skillGuidance = Layer.mock(SkillGuidance.Service, { load: () => Effect.succeed(Instructions.empty) })
|
||||
|
|
@ -83,6 +99,7 @@ const runnerLayer = AppNodeBuilder.build(SessionRunnerLLM.node, [
|
|||
[Snapshot.node, Snapshot.noopLayer],
|
||||
[LayerNodePlatform.llmClient, client],
|
||||
[SessionRunnerModel.node, models],
|
||||
[Catalog.node, catalog],
|
||||
[InstructionBuiltIns.node, systemContext],
|
||||
[InstructionDiscovery.node, instructionContext],
|
||||
[Location.node, Location.boundNode({ directory: AbsolutePath.make("/project") })],
|
||||
|
|
@ -133,6 +150,7 @@ const it = testEffect(
|
|||
[PermissionV2.node, permission],
|
||||
[ToolOutputStore.node, ToolOutputStore.nodeWithoutConfig],
|
||||
[SessionRunnerModel.node, models],
|
||||
[Catalog.node, catalog],
|
||||
[InstructionBuiltIns.node, systemContext],
|
||||
[InstructionDiscovery.node, instructionContext],
|
||||
[Location.node, Location.boundNode({ directory: AbsolutePath.make("/project") })],
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ import { ToolRegistry } from "@opencode-ai/core/tool/registry"
|
|||
import { QuestionTool } from "@opencode-ai/core/tool/question"
|
||||
import { ToolOutputStore } from "@opencode-ai/core/tool-output-store"
|
||||
import { AgentV2 } from "@opencode-ai/core/agent"
|
||||
import { Catalog } from "@opencode-ai/core/catalog"
|
||||
import { Config } from "@opencode-ai/core/config"
|
||||
import { ConfigCompaction } from "@opencode-ai/core/config/compaction"
|
||||
import { Tool } from "@opencode-ai/core/tool/tool"
|
||||
|
|
@ -245,6 +246,24 @@ const models = SessionRunnerModel.layerWith((session) =>
|
|||
),
|
||||
),
|
||||
)
|
||||
let catalogCapabilities = ModelV2.Capabilities.defaults({ tools: true })
|
||||
const catalog = Layer.mock(Catalog.Service, {
|
||||
provider: {
|
||||
get: () => Effect.die("unused"),
|
||||
all: () => Effect.die("unused"),
|
||||
available: () => Effect.die("unused"),
|
||||
},
|
||||
model: {
|
||||
get: (providerID, modelID) =>
|
||||
Effect.succeed(
|
||||
ModelV2.Info.make({ ...ModelV2.Info.empty(providerID, modelID), capabilities: catalogCapabilities }),
|
||||
),
|
||||
all: () => Effect.die("unused"),
|
||||
available: () => Effect.die("unused"),
|
||||
default: () => Effect.die("unused"),
|
||||
small: () => Effect.die("unused"),
|
||||
},
|
||||
})
|
||||
const systemContextKey = Instructions.Key.make("test/context")
|
||||
let systemBaseline = "Initial context"
|
||||
let systemRemoved = false
|
||||
|
|
@ -311,6 +330,7 @@ const runnerLayer = AppNodeBuilder.build(SessionRunnerLLM.node, [
|
|||
[Snapshot.node, Snapshot.noopLayer],
|
||||
[LayerNodePlatform.llmClient, client],
|
||||
[SessionRunnerModel.node, models],
|
||||
[Catalog.node, catalog],
|
||||
[InstructionBuiltIns.node, systemContext],
|
||||
[InstructionDiscovery.node, instructionContext],
|
||||
[Location.node, Location.boundNode({ directory: AbsolutePath.make("/project") })],
|
||||
|
|
@ -365,6 +385,7 @@ const it = testEffect(
|
|||
[LayerNodePlatform.llmClient, client],
|
||||
[PermissionV2.node, permission],
|
||||
[SessionRunnerModel.node, models],
|
||||
[Catalog.node, catalog],
|
||||
[InstructionBuiltIns.node, systemContext],
|
||||
[InstructionDiscovery.node, instructionContext],
|
||||
[Location.node, Location.boundNode({ directory: AbsolutePath.make("/project") })],
|
||||
|
|
@ -412,6 +433,7 @@ const setup = Effect.gen(function* () {
|
|||
systemLoadHook = Effect.void
|
||||
modelResolveHook = Effect.void
|
||||
currentModel = model
|
||||
catalogCapabilities = ModelV2.Capabilities.defaults({ tools: true })
|
||||
skillBaselines.clear()
|
||||
responses = undefined
|
||||
streamFailure = undefined
|
||||
|
|
@ -787,6 +809,22 @@ describe("SessionRunnerLLM", () => {
|
|||
}),
|
||||
)
|
||||
|
||||
it.effect("does not advertise tools to a model without tool capability", () =>
|
||||
Effect.gen(function* () {
|
||||
yield* setup
|
||||
catalogCapabilities = ModelV2.Capabilities.defaults()
|
||||
const session = yield* SessionV2.Service
|
||||
yield* session.prompt({ sessionID, prompt: PromptInput.Prompt.make({ text: "No tools" }), resume: false })
|
||||
|
||||
requests.length = 0
|
||||
response = []
|
||||
yield* session.resume(sessionID)
|
||||
|
||||
expect(requests).toHaveLength(1)
|
||||
expect(requests[0]?.tools).toEqual([])
|
||||
}),
|
||||
)
|
||||
|
||||
it.effect("retries the first provider turn after system context becomes available", () =>
|
||||
Effect.gen(function* () {
|
||||
const session = yield* setup
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue