@stablekernel/opencode-bifrost 0.5.0 → 0.5.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stablekernel/opencode-bifrost",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "OpenCode plugin that routes models through the Bifrost gateway, resolving per-project virtual keys via gateway-cli.",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -54,6 +54,60 @@ describe("parseDatasheet", () => {
54
54
  } satisfies SupplementalModel);
55
55
  });
56
56
 
57
+ test("maps supports_image_input to image_input only when true", () => {
58
+ const out = parseDatasheet({
59
+ "fireworks_ai/accounts/fireworks/models/glm-5p3-flash": {
60
+ ...glmFlash,
61
+ supports_image_input: true,
62
+ },
63
+ "fireworks_ai/accounts/fireworks/models/glm-5p2": {
64
+ ...glmFlash,
65
+ supports_image_input: false,
66
+ },
67
+ });
68
+ expect(out).toHaveLength(2);
69
+ const byId = new Map(out.map((m) => [m.id, m]));
70
+ expect(byId.get("accounts/fireworks/models/glm-5p3-flash")?.image_input).toBe(true);
71
+ expect(byId.get("accounts/fireworks/models/glm-5p2")?.image_input).toBeUndefined();
72
+ });
73
+
74
+ test("maps supports_vision to image_input — the upstream field name (1570 rows vs 8 for supports_image_input)", () => {
75
+ const out = parseDatasheet({
76
+ "fireworks_ai/accounts/fireworks/models/deepseek-v4-flash-vision-exp": {
77
+ ...glmFlash,
78
+ supports_vision: true,
79
+ },
80
+ "fireworks_ai/accounts/fireworks/models/deepseek-v4-flash": {
81
+ ...glmFlash,
82
+ supports_vision: false,
83
+ },
84
+ });
85
+ expect(out).toHaveLength(2);
86
+ const byId = new Map(out.map((m) => [m.id, m]));
87
+ expect(byId.get("accounts/fireworks/models/deepseek-v4-flash-vision-exp")?.image_input).toBe(true);
88
+ expect(byId.get("accounts/fireworks/models/deepseek-v4-flash")?.image_input).toBeUndefined();
89
+ });
90
+
91
+ test("falls back to max_input_tokens when context_length is absent — upstream rows never carry context_length", () => {
92
+ const { context_length, ...upstreamShape } = glmFlash;
93
+ const out = parseDatasheet({
94
+ "fireworks_ai/accounts/fireworks/models/glm-5p3-flash": upstreamShape,
95
+ });
96
+ expect(out).toHaveLength(1);
97
+ expect(out[0].context_window).toBe(upstreamShape.max_input_tokens);
98
+ });
99
+
100
+ test("reads cache_write from cache_creation_input_token_cost — the upstream field name (503 rows vs 0)", () => {
101
+ const out = parseDatasheet({
102
+ "fireworks_ai/accounts/fireworks/models/glm-5p3-flash": {
103
+ ...glmFlash,
104
+ cache_creation_input_token_cost: 0.00000015,
105
+ },
106
+ });
107
+ expect(out).toHaveLength(1);
108
+ expect(out[0].cost?.cache_write).toBe(0.15);
109
+ });
110
+
57
111
  test("drops non-chat entries, unknown providers, and rows without limits", () => {
58
112
  const out = parseDatasheet({
59
113
  "fireworks_ai/accounts/fireworks/models/qwen3-embedding-8b": {
@@ -64,6 +118,7 @@ describe("parseDatasheet", () => {
64
118
  "fireworks_ai/accounts/fireworks/models/no-limits": {
65
119
  ...glmFlash,
66
120
  context_length: undefined,
121
+ max_input_tokens: undefined,
67
122
  },
68
123
  "fireworks_ai/accounts/fireworks/models/no-max-out": {
69
124
  ...glmFlash,
package/src/datasheet.ts CHANGED
@@ -33,8 +33,16 @@ export type DatasheetEntry = {
33
33
  input_cost_per_token?: number;
34
34
  output_cost_per_token?: number;
35
35
  cache_read_input_token_cost?: number;
36
+ // Upstream rows name the cache-write rate `cache_creation_input_token_cost`
37
+ // (503 rows); the `cache_write_…` spelling appears on zero rows and is
38
+ // kept for symmetry with Bifrost's own pricing-card vocabulary.
36
39
  cache_write_input_token_cost?: number;
40
+ cache_creation_input_token_cost?: number;
37
41
  supports_reasoning?: boolean;
42
+ // Upstream rows express image capability as `supports_vision` (1,570
43
+ // rows); `supports_image_input` appears on only 8. Either true counts.
44
+ supports_vision?: boolean;
45
+ supports_image_input?: boolean;
38
46
  };
39
47
 
40
48
  /** A model in the same shape `gateway-cli models` emits (structural subset). */
@@ -52,6 +60,7 @@ export type SupplementalModel = {
52
60
  cache_write: number;
53
61
  };
54
62
  reasoning?: boolean;
63
+ image_input?: boolean;
55
64
  };
56
65
 
57
66
  /** Datasheet provider prefixes whose entries this module understands. */
@@ -208,8 +217,16 @@ export function parseDatasheet(
208
217
  if (!prefix) continue;
209
218
  const id = key.slice(prefix.length);
210
219
  if (!id) continue;
220
+ // Upstream rows never carry `context_length` (0 of 4,336); they state
221
+ // `max_input_tokens` instead. Either sets the context window.
222
+ const contextLength =
223
+ typeof e.context_length === "number"
224
+ ? e.context_length
225
+ : typeof e.max_input_tokens === "number"
226
+ ? e.max_input_tokens
227
+ : undefined;
211
228
  if (
212
- typeof e.context_length !== "number" ||
229
+ typeof contextLength !== "number" ||
213
230
  typeof e.max_output_tokens !== "number"
214
231
  ) {
215
232
  continue;
@@ -222,7 +239,7 @@ export function parseDatasheet(
222
239
  id,
223
240
  name:
224
241
  typeof e.base_model === "string" && e.base_model ? e.base_model : slug,
225
- context_window: e.context_length,
242
+ context_window: contextLength,
226
243
  max_output_tokens: e.max_output_tokens,
227
244
  limits_source: "datasheet",
228
245
  ...(priced
@@ -232,11 +249,17 @@ export function parseDatasheet(
232
249
  input: perMillion(e.input_cost_per_token),
233
250
  output: perMillion(e.output_cost_per_token),
234
251
  cache_read: perMillion(e.cache_read_input_token_cost),
235
- cache_write: perMillion(e.cache_write_input_token_cost),
252
+ cache_write: perMillion(
253
+ e.cache_write_input_token_cost ??
254
+ e.cache_creation_input_token_cost,
255
+ ),
236
256
  },
237
257
  }
238
258
  : {}),
239
259
  ...(e.supports_reasoning === true ? { reasoning: true } : {}),
260
+ ...(e.supports_image_input === true || e.supports_vision === true
261
+ ? { image_input: true }
262
+ : {}),
240
263
  });
241
264
  }
242
265
  return out;
package/src/index.test.ts CHANGED
@@ -309,6 +309,25 @@ describe("datasheet supplement gate", () => {
309
309
  });
310
310
  });
311
311
 
312
+ describe("image input", () => {
313
+ test("declares image modalities + attachment when the CLI advertises it", () => {
314
+ // OpenCode computes input.image and attachment from the config model and
315
+ // DEFAULTS BOTH TO FALSE for plugin-provided models. Without these
316
+ // fields OpenCode strips image parts for every Bifrost model.
317
+ const models = toConfigModels({ models: [{ ...NOVA, image_input: true }] });
318
+ const m = models["bedrock/amazon.nova-lite-v1:0"];
319
+ expect(m.modalities?.input).toContain("image");
320
+ expect(m.attachment).toBe(true);
321
+ });
322
+
323
+ test("stays silent for a text-only model so OpenCode's false default holds", () => {
324
+ const models = toConfigModels({ models: [NOVA] });
325
+ const m = models["bedrock/amazon.nova-lite-v1:0"];
326
+ expect(m.modalities).toBeUndefined();
327
+ expect(m.attachment).toBeUndefined();
328
+ });
329
+ });
330
+
312
331
  describe("unpriced models", () => {
313
332
  test("omits cost entirely rather than declaring zero", () => {
314
333
  // A zeroed rate card renders as free, which is worse than blank.
package/src/index.ts CHANGED
@@ -59,6 +59,12 @@ type ConfigModel = {
59
59
  reasoning?: boolean;
60
60
  /** Named per-effort variants; each body is a provider-options overlay. */
61
61
  variants?: Record<string, { reasoningEffort: string }>;
62
+ /** Whether the model accepts file/image attachments. OpenCode defaults
63
+ * this to false for config-provided models when absent. */
64
+ attachment?: boolean;
65
+ /** Input/output modalities. OpenCode reads input.image from here to
66
+ * decide whether image parts may be sent; absent defaults to false. */
67
+ modalities?: { input: string[] };
62
68
  /** Provider options passed on every request (e.g. a seeded default
63
69
  * reasoningEffort); a variant or agent override replaces these. */
64
70
  options?: Record<string, unknown>;
@@ -85,6 +91,10 @@ export type CliModel = {
85
91
  reasoning?: boolean;
86
92
  reasoning_efforts?: string[];
87
93
  reasoning_budget_min?: number;
94
+ /** True when the model accepts image content blocks (from the catalog's
95
+ * modalities.input). Absent means text-only, so a harness never guesses a
96
+ * capability from silence. */
97
+ image_input?: boolean;
88
98
  };
89
99
 
90
100
  export type CliModels = { models?: CliModel[] };
@@ -396,6 +406,11 @@ export function toConfigModels(
396
406
  name: m.cost ? m.name : `${m.name}${UNPRICED_SUFFIX}`,
397
407
  limit: { context: m.context_window, output: m.max_output_tokens },
398
408
  ...(m.cost ? { cost: m.cost } : {}),
409
+ // OpenCode defaults input.image and attachment to false for config
410
+ // models; both must come from the CLI or images are stripped.
411
+ ...(m.image_input
412
+ ? { attachment: true, modalities: { input: ["text", "image"] } }
413
+ : {}),
399
414
  };
400
415
  if (m.reasoning) {
401
416
  entry.reasoning = true;