mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-19 00:03:13 +03:00
fix(core): allow local config to override Console-supplied providers
Reverts the lock from #60315 that ignored user, project and remote overrides on providers the Console supplies. It also blocked harmless overrides such as model limits, names and variants (#60597) and internal gateways.
This commit is contained in:
@@ -12,7 +12,6 @@ import { Model } from "../../model.js"
|
||||
import { Provider } from "../../provider.js"
|
||||
import { Variant } from "../../variant.js"
|
||||
import { ConfigIntegration } from "../integration.js"
|
||||
import { ConfigManaged } from "../managed.js"
|
||||
import { ConfigEntryObserver } from "./entry-observer.js"
|
||||
|
||||
export const Plugin = define({
|
||||
@@ -144,21 +143,10 @@ export const Plugin = define({
|
||||
|
||||
// Integration documents are left out: their providers authenticate with the integration's connection, so they add no
|
||||
// integration or method, and the integration's own plugin applies them earlier in the provider chain (`integrate`).
|
||||
// A provider the Console supplies is shaped only by the Console and managed configuration: user, project, and remote
|
||||
// documents cannot override any part of it, since it carries the org's token and a repository must not redirect it.
|
||||
function configuredProviders(entries: readonly Entry[]) {
|
||||
const supplied = new Set(
|
||||
entries
|
||||
.filter((entry): entry is ConfigIntegration.Document => entry instanceof ConfigIntegration.Document)
|
||||
.flatMap((document) => Object.keys(document.info.providers ?? {})),
|
||||
)
|
||||
return entries
|
||||
.filter((entry): entry is Document => entry.type === "document" && !(entry instanceof ConfigIntegration.Document))
|
||||
.flatMap((file) =>
|
||||
Object.entries(file.info.providers ?? {}).filter(
|
||||
([id]) => !supplied.has(id) || file instanceof ConfigManaged.Document,
|
||||
),
|
||||
)
|
||||
.flatMap((file) => Object.entries(file.info.providers ?? {}))
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -13,7 +13,6 @@ import { Bus } from "@opencode/core/bus"
|
||||
import { Config } from "@opencode/core/config"
|
||||
import { ConfigIntegration } from "@opencode/core/config/integration"
|
||||
import { ConfigPolicyPlugin } from "@opencode/core/config/plugin/policy"
|
||||
import { ConfigManaged } from "@opencode/core/config/managed"
|
||||
import { ConfigProviderPlugin } from "@opencode/core/config/plugin/provider"
|
||||
import { ConfigWebSearchPlugin } from "@opencode/core/config/plugin/websearch"
|
||||
import { Credential } from "@opencode/core/credential"
|
||||
@@ -1901,7 +1900,7 @@ describe("OpencodePlugin with a Console config", () => {
|
||||
),
|
||||
)
|
||||
|
||||
it.live("keeps Console providers out of user and project config's reach, bound to the Console connection", () =>
|
||||
it.live("layers Console providers below user config, bound to the Console connection", () =>
|
||||
Effect.acquireUseRelease(
|
||||
Effect.sync(() =>
|
||||
Bun.serve({
|
||||
@@ -1930,23 +1929,17 @@ describe("OpencodePlugin with a Console config", () => {
|
||||
const providers = yield* Provider.Service
|
||||
const models = yield* Model.Service
|
||||
const config = yield* Config.Test
|
||||
const overlay = {
|
||||
name: "Mine",
|
||||
settings: { apiKey: "my-key", baseURL: "https://mine.example/v1" },
|
||||
headers: { "x-org-id": "mine" },
|
||||
models: { chat: { name: "My Chat" }, mine: { name: "My Model" } },
|
||||
}
|
||||
yield* config.setEntries([
|
||||
new ConfigManaged.Document({
|
||||
type: "document",
|
||||
info: Schema.decodeUnknownSync(Info)({ providers: { remote: { headers: { "x-managed": "true" } } } }),
|
||||
}),
|
||||
new Document({
|
||||
type: "document",
|
||||
info: Schema.decodeUnknownSync(Info)({
|
||||
providers: {
|
||||
remote: overlay,
|
||||
normal: { ...overlay, package: "aisdk:@ai-sdk/openai-compatible" },
|
||||
remote: {
|
||||
name: "Mine",
|
||||
settings: { apiKey: "my-key" },
|
||||
headers: { "x-org-id": "mine" },
|
||||
models: { chat: { name: "My Chat" } },
|
||||
},
|
||||
},
|
||||
}),
|
||||
}),
|
||||
@@ -1959,26 +1952,22 @@ describe("OpencodePlugin with a Console config", () => {
|
||||
yield* OpencodePlugin.effect(host)
|
||||
yield* ConfigProviderPlugin.Plugin.effect(host)
|
||||
|
||||
// Managed configuration may still shape a Console provider; a project or user file cannot.
|
||||
const provider = required(yield* providers.get(Provider.ID.make("remote")))
|
||||
expect(provider.name).toBe("Console")
|
||||
expect(provider.name).toBe("Mine")
|
||||
expect(provider.integrationID).toBe(Integration.ID.make("opencode"))
|
||||
expect(provider.headers).toEqual({ "x-org-id": "console", "x-console": "true", "x-managed": "true" })
|
||||
expect(provider.headers).toEqual({ "x-org-id": "mine", "x-console": "true" })
|
||||
expect(provider.settings).toEqual({
|
||||
baseURL: `${server.url.origin}/v1`,
|
||||
custom: "console",
|
||||
apiKey: "my-key",
|
||||
provider: "remote",
|
||||
})
|
||||
const chat = required(yield* models.get(Provider.ID.make("remote"), Model.ID.make("chat")))
|
||||
expect(chat.name).toBe("Console Chat")
|
||||
expect(chat.name).toBe("My Chat")
|
||||
expect(chat.settings).toMatchObject({ temperature: 0.1 })
|
||||
expect(yield* models.get(Provider.ID.make("remote"), Model.ID.make("mine"))).toBeUndefined()
|
||||
|
||||
// Providers the Console does not supply stay overridable.
|
||||
const normal = required(yield* providers.get(Provider.ID.make("normal")))
|
||||
expect(normal.headers).toEqual({ "x-org-id": "mine" })
|
||||
expect(normal.settings).toMatchObject({ baseURL: "https://mine.example/v1", apiKey: "my-key" })
|
||||
expect(required(yield* models.get(Provider.ID.make("normal"), Model.ID.make("chat"))).name).toBe("My Chat")
|
||||
expect(required(yield* models.get(Provider.ID.make("remote"), Model.ID.make("other"))).name).toBe(
|
||||
"Console Other",
|
||||
)
|
||||
}),
|
||||
(server) => Effect.promise(() => server.stop(true)),
|
||||
),
|
||||
|
||||
@@ -192,11 +192,6 @@ web search work, and changing them in the Console needs no new MDM profile.
|
||||
Only managed policies can withhold the MCP servers and config an integration
|
||||
delivers; its own policies keep applying either way.
|
||||
|
||||
A provider the connected Console workspace supplies can't be changed by user,
|
||||
project, or remote configuration: its settings, headers, models, and package come
|
||||
only from the Console and managed configuration. Other providers stay configurable
|
||||
as usual.
|
||||
|
||||
## MCP servers, skills, and plugins
|
||||
|
||||
| Action | Resource |
|
||||
|
||||
Reference in New Issue
Block a user