@stablekernel/opencode-bifrost 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/package.json +1 -1
- package/src/index.test.ts +43 -0
- package/src/index.ts +10 -2
- package/src/shared.test.ts +17 -0
- package/src/shared.ts +9 -0
- package/src/v2.test.ts +22 -0
- package/src/v2.ts +3 -1
package/README.md
CHANGED
|
@@ -7,6 +7,7 @@ OpenCode plugin that routes model traffic through a [Bifrost](https://docs.getbi
|
|
|
7
7
|
- Registers a `bifrost` provider on OpenCode's OpenAI-compatible surface.
|
|
8
8
|
- Fetches the model list at startup through `gateway-cli models --wire=openai`, with per-model context/output limits and pricing already applied — no catalog is checked in, so a model added to the gateway appears without a local edit.
|
|
9
9
|
- Seeds reasoning capability per model: catalog-flagged models are registered `reasoning: true` with one variant per effort value they accept. The config cascade's default `reasoning_effort` is seeded as the model's default when the model accepts it — on OpenCode 1.x as `options.reasoningEffort`, on OpenCode 2 as model-level `settings.reasoningEffort` — and a variant picked in the model picker overrides it. The static `gateway-cli emit opencode` block mirrors this (`--v2` for the 2.x form).
|
|
10
|
+
- Routes first-party OpenAI GPT models (`…openai.gpt-*`, not `gpt-oss`) over the Responses API, since the gateway answers their chat-completions requests with 400: a per-model `provider.npm: "@ai-sdk/openai"` (+ `options.forceReasoning`) on 1.x, `package: "@opencode/ai/providers/openai/responses"` on 2.x.
|
|
10
11
|
- Resolves the virtual key per project directory (`gateway-cli resolve` / `gateway-cli key print`), so two projects on different keys never collide in OpenCode's global auth store. On OpenCode 1.x it falls back to a credential stored via `opencode auth login` on machines without `gateway-cli`; OpenCode 2 removed that hook, so there discovery requires the CLI.
|
|
11
12
|
|
|
12
13
|
No secret is held by the plugin; the key is read at runtime.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stablekernel/opencode-bifrost",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "OpenCode plugin that routes models through the Bifrost gateway, resolving per-project virtual keys via gateway-cli. Supports OpenCode 1.x and 2.x.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.ts",
|
package/src/index.test.ts
CHANGED
|
@@ -788,3 +788,46 @@ describe("stale-plugin notice", () => {
|
|
|
788
788
|
expect(isStale("dev", "dev")).toBe(false);
|
|
789
789
|
});
|
|
790
790
|
});
|
|
791
|
+
|
|
792
|
+
describe("responses routing", () => {
|
|
793
|
+
const GPT: CliModel = {
|
|
794
|
+
id: "bedrock/openai.gpt-6.1-sol",
|
|
795
|
+
name: "GPT-6.1 Sol",
|
|
796
|
+
context_window: 400000,
|
|
797
|
+
max_output_tokens: 128000,
|
|
798
|
+
limits_source: "catalog",
|
|
799
|
+
reasoning: true,
|
|
800
|
+
reasoning_efforts: ["low", "medium", "high"],
|
|
801
|
+
};
|
|
802
|
+
const OSS: CliModel = {
|
|
803
|
+
...GPT,
|
|
804
|
+
id: "bedrock/openai.gpt-oss-120b",
|
|
805
|
+
name: "GPT OSS 120B",
|
|
806
|
+
};
|
|
807
|
+
|
|
808
|
+
test("sends first-party GPT models to the OpenAI Responses package", () => {
|
|
809
|
+
const m = toConfigModels({ models: [GPT] })[GPT.id];
|
|
810
|
+
expect(m.provider).toEqual({ npm: "@ai-sdk/openai" });
|
|
811
|
+
});
|
|
812
|
+
|
|
813
|
+
test("leaves gpt-oss and non-GPT models on the provider's package", () => {
|
|
814
|
+
const models = toConfigModels({ models: [OSS, HAIKU] });
|
|
815
|
+
expect(models[OSS.id].provider).toBeUndefined();
|
|
816
|
+
expect(models[HAIKU.id].provider).toBeUndefined();
|
|
817
|
+
});
|
|
818
|
+
|
|
819
|
+
test("forces reasoning mode: @ai-sdk/openai only recognizes ids starting gpt-", () => {
|
|
820
|
+
// Without it the SDK drops reasoningEffort for the prefixed id.
|
|
821
|
+
expect(toConfigModels({ models: [GPT] })[GPT.id].options).toEqual({
|
|
822
|
+
forceReasoning: true,
|
|
823
|
+
});
|
|
824
|
+
const plain: CliModel = { ...GPT, reasoning: false };
|
|
825
|
+
expect(toConfigModels({ models: [plain] })[GPT.id].options).toBeUndefined();
|
|
826
|
+
});
|
|
827
|
+
|
|
828
|
+
test("still seeds the default effort and variants for a routed model", () => {
|
|
829
|
+
const m = toConfigModels({ models: [GPT] }, "high")[GPT.id];
|
|
830
|
+
expect(m.options).toEqual({ forceReasoning: true, reasoningEffort: "high" });
|
|
831
|
+
expect(Object.keys(m.variants ?? {})).toEqual(["low", "medium", "high"]);
|
|
832
|
+
});
|
|
833
|
+
});
|
package/src/index.ts
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
REFRESH_DESCRIPTION,
|
|
12
12
|
REFRESH_TEMPLATE,
|
|
13
13
|
resolveInfo,
|
|
14
|
+
usesResponsesApi,
|
|
14
15
|
type CliModels,
|
|
15
16
|
} from "./shared.js";
|
|
16
17
|
import { setupV2 } from "./v2.js";
|
|
@@ -53,6 +54,9 @@ type ConfigModel = {
|
|
|
53
54
|
/** Provider options passed on every request (e.g. a seeded default
|
|
54
55
|
* reasoningEffort); a variant or agent override replaces these. */
|
|
55
56
|
options?: Record<string, unknown>;
|
|
57
|
+
/** Per-model package override; OpenCode resolves model.provider.npm ahead
|
|
58
|
+
* of the provider's. */
|
|
59
|
+
provider?: { npm: string };
|
|
56
60
|
};
|
|
57
61
|
|
|
58
62
|
/**
|
|
@@ -290,16 +294,20 @@ export function toConfigModels(
|
|
|
290
294
|
? { attachment: true, modalities: { input: ["text", "image"] } }
|
|
291
295
|
: {}),
|
|
292
296
|
};
|
|
297
|
+
const responses = usesResponsesApi(m.id);
|
|
298
|
+
if (responses) entry.provider = { npm: "@ai-sdk/openai" };
|
|
293
299
|
if (m.reasoning) {
|
|
294
300
|
entry.reasoning = true;
|
|
301
|
+
// @ai-sdk/openai only treats ids starting "gpt-" as reasoning models, so
|
|
302
|
+
// a prefixed id would silently lose reasoningEffort without this.
|
|
303
|
+
if (responses) entry.options = { forceReasoning: true };
|
|
295
304
|
const variants: Record<string, { reasoningEffort: string }> = {};
|
|
296
305
|
for (const e of efforts) variants[e] = { reasoningEffort: e };
|
|
297
306
|
if (Object.keys(variants).length > 0) entry.variants = variants;
|
|
298
307
|
if (defaultEffort && efforts.includes(defaultEffort)) {
|
|
299
308
|
// Seeding at model level makes the effort the default unless a
|
|
300
309
|
// variant or agent override replaces it.
|
|
301
|
-
|
|
302
|
-
{ reasoningEffort: defaultEffort };
|
|
310
|
+
entry.options = { ...entry.options, reasoningEffort: defaultEffort };
|
|
303
311
|
}
|
|
304
312
|
}
|
|
305
313
|
out[m.id] = entry;
|
package/src/shared.test.ts
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
listCliModels,
|
|
4
4
|
readCliKey,
|
|
5
5
|
resolveInfo,
|
|
6
|
+
usesResponsesApi,
|
|
6
7
|
} from "./shared.js";
|
|
7
8
|
|
|
8
9
|
/**
|
|
@@ -106,3 +107,19 @@ describe("listCliModels", () => {
|
|
|
106
107
|
).toBeNull();
|
|
107
108
|
});
|
|
108
109
|
});
|
|
110
|
+
|
|
111
|
+
describe("usesResponsesApi", () => {
|
|
112
|
+
// The gateway answers every first-party GPT chat-completions request with
|
|
113
|
+
// 400 ("use /v1/responses"); gpt-oss and other vendors stay on completions.
|
|
114
|
+
test.each([
|
|
115
|
+
["bedrock/openai.gpt-6.1-sol", true],
|
|
116
|
+
["bedrock/openai.gpt-5.5", true],
|
|
117
|
+
["openai/gpt-6.0", true],
|
|
118
|
+
["bedrock/openai.gpt-oss-120b", false],
|
|
119
|
+
["fireworks/gpt-oss-120b", false],
|
|
120
|
+
["bedrock/amazon.nova-lite-v1:0", false],
|
|
121
|
+
["claude-sonnet-4-6", false],
|
|
122
|
+
])("%s -> %p", (id, want) => {
|
|
123
|
+
expect(usesResponsesApi(id)).toBe(want);
|
|
124
|
+
});
|
|
125
|
+
});
|
package/src/shared.ts
CHANGED
|
@@ -8,6 +8,15 @@ export const PROVIDER_ID = "bifrost";
|
|
|
8
8
|
/** Overridable so a non-PATH install still works. */
|
|
9
9
|
export const CLI = process.env.GATEWAY_CLI_BIN ?? "gateway-cli";
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* First-party OpenAI GPT ids ("openai/gpt-6.0", "bedrock/openai.gpt-6.1-sol")
|
|
13
|
+
* are served only on /v1/responses: the gateway answers every chat-completions
|
|
14
|
+
* request with 400. gpt-oss is open-weight and fine on completions. Mirrors
|
|
15
|
+
* OPENAI_GPT in packages/pi-bifrost/src/index.ts.
|
|
16
|
+
*/
|
|
17
|
+
export const usesResponsesApi = (id: string): boolean =>
|
|
18
|
+
/(?:^|\/)openai[./]gpt-(?!oss)/.test(id);
|
|
19
|
+
|
|
11
20
|
/**
|
|
12
21
|
* Suffix for models nothing could price.
|
|
13
22
|
*
|
package/src/v2.test.ts
CHANGED
|
@@ -384,3 +384,25 @@ describe("setupV2", () => {
|
|
|
384
384
|
expect(commands.map((c) => c.name)).toEqual(["bifrost-refresh"]);
|
|
385
385
|
});
|
|
386
386
|
});
|
|
387
|
+
|
|
388
|
+
describe("responses routing", () => {
|
|
389
|
+
const GPT: CliModel = {
|
|
390
|
+
...REASONING,
|
|
391
|
+
id: "bedrock/openai.gpt-6.1-sol",
|
|
392
|
+
name: "GPT-6.1 Sol",
|
|
393
|
+
};
|
|
394
|
+
const OSS: CliModel = { ...GPT, id: "bedrock/openai.gpt-oss-120b" };
|
|
395
|
+
|
|
396
|
+
test("overrides the package for first-party GPT models only", () => {
|
|
397
|
+
const models = toV2Models({ models: [GPT, OSS, NOVA] });
|
|
398
|
+
expect(byId(models, GPT.id)!.package).toBe(
|
|
399
|
+
"@opencode/ai/providers/openai/responses",
|
|
400
|
+
);
|
|
401
|
+
expect(byId(models, OSS.id)!.package).toBe(
|
|
402
|
+
"@opencode/ai/providers/openai-compatible",
|
|
403
|
+
);
|
|
404
|
+
expect(byId(models, NOVA.id)!.package).toBe(
|
|
405
|
+
"@opencode/ai/providers/openai-compatible",
|
|
406
|
+
);
|
|
407
|
+
});
|
|
408
|
+
});
|
package/src/v2.ts
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
readKeyFile,
|
|
11
11
|
REFRESH_DESCRIPTION,
|
|
12
12
|
resolveInfo,
|
|
13
|
+
usesResponsesApi,
|
|
13
14
|
type CliModels,
|
|
14
15
|
} from "./shared.js";
|
|
15
16
|
|
|
@@ -21,6 +22,7 @@ const exec = promisify(execFile);
|
|
|
21
22
|
* gateway route is built by the host rather than bundled here.
|
|
22
23
|
*/
|
|
23
24
|
const PROVIDER_PACKAGE = "@opencode/ai/providers/openai-compatible";
|
|
25
|
+
const RESPONSES_PACKAGE = "@opencode/ai/providers/openai/responses";
|
|
24
26
|
|
|
25
27
|
/**
|
|
26
28
|
* Directories searched for the CLI when it is not on the inherited PATH.
|
|
@@ -86,7 +88,7 @@ export function toV2Models(
|
|
|
86
88
|
modelID: m.id,
|
|
87
89
|
providerID: PROVIDER_ID,
|
|
88
90
|
name: m.cost ? m.name : `${m.name}${UNPRICED_SUFFIX}`,
|
|
89
|
-
package: PROVIDER_PACKAGE,
|
|
91
|
+
package: usesResponsesApi(m.id) ? RESPONSES_PACKAGE : PROVIDER_PACKAGE,
|
|
90
92
|
capabilities: {
|
|
91
93
|
tools: true,
|
|
92
94
|
input: m.image_input ? ["text", "image"] : ["text"],
|