@stablekernel/pi-bifrost 0.2.0 → 0.2.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/pi-bifrost",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Pi extension that registers the Bifrost gateway as a model provider, resolving per-project virtual keys via gateway-cli.",
5
5
  "type": "module",
6
6
  "files": [
package/src/index.ts CHANGED
@@ -47,6 +47,9 @@ type ProviderConfig = {
47
47
  apiKey: string;
48
48
  api: "anthropic-messages" | "openai-completions";
49
49
  models: ProviderModelConfig[];
50
+ /** Custom headers sent on every request; per docs/custom-provider.md,
51
+ * values use the same resolution syntax as apiKey. */
52
+ headers?: Record<string, string>;
50
53
  };
51
54
 
52
55
  type ExtensionAPI = {
@@ -98,6 +101,9 @@ type CliModel = {
98
101
  };
99
102
  limits_source: string;
100
103
  cost_source?: string;
104
+ /** True when the gateway lists the model but it rejects completion on
105
+ * this key (not entitled, needs provisioned throughput, retired). */
106
+ disabled?: boolean;
101
107
  reasoning?: boolean;
102
108
  reasoning_efforts?: string[];
103
109
  reasoning_budget_min?: number;
@@ -161,6 +167,19 @@ export default async function (pi: ExtensionAPI): Promise<void> {
161
167
  apiKey: `!${CLI} key print`,
162
168
  api: surface.api,
163
169
  models,
170
+ // Attribution and gateway-routing headers come from the same resolve
171
+ // output every other harness honors; pi drops them silently otherwise.
172
+ // An empty map is treated as absent: Go's mergeHeaders returns nil for
173
+ // an empty merge and the JSON tag omits it, so the plugin only ever
174
+ // sees a real map or nothing.
175
+ //
176
+ // Config-trust note: a header named Authorization or x-api-key here
177
+ // would override the credential pi injects, but only toward the
178
+ // already-allowlisted gateway origin (isAllowedGatewayUrl), which is
179
+ // where the key goes anyway.
180
+ ...(info.headers && Object.keys(info.headers).length > 0
181
+ ? { headers: info.headers }
182
+ : {}),
164
183
  });
165
184
  }
166
185
  }
@@ -179,6 +198,7 @@ export function toPiModels(
179
198
  const out: ProviderModelConfig[] = [];
180
199
  for (const m of payload?.models ?? []) {
181
200
  if (!m?.id) continue;
201
+ if (m.disabled) continue; // unavailable on this key: never offer it
182
202
  const priced = m.cost !== undefined;
183
203
  const reasoning = !!m.reasoning;
184
204
  const model: ProviderModelConfig = {
@@ -23,6 +23,9 @@ type CliModel = {
23
23
  };
24
24
  limits_source: string;
25
25
  cost_source?: string;
26
+ /** True when the gateway lists the model but it rejects completion on
27
+ * this key (not entitled, needs provisioned throughput, retired). */
28
+ disabled?: boolean;
26
29
  /** Reasoning capability and applicable efforts, from the catalog. */
27
30
  reasoning?: boolean;
28
31
  reasoning_efforts?: string[];
@@ -134,6 +137,46 @@ describe("provider registration", () => {
134
137
  expect(calls).toContain("models --wire=openai --all");
135
138
  });
136
139
 
140
+ test("passes the resolved gateway headers onto both providers", async () => {
141
+ mockCLI(OK_CLI);
142
+ const registered = await runExtension();
143
+ expect(registered.length).toBeGreaterThan(0);
144
+ for (const r of registered) {
145
+ expect(r.config.headers).toEqual(RESOLUTION.headers);
146
+ }
147
+ });
148
+
149
+ test("treats an empty header map the same as no headers", async () => {
150
+ // Go-side mergeHeaders returns nil for an empty merge and the JSON tag
151
+ // omits it, so `{}` cannot reach the plugin in practice. This pins the
152
+ // behavior anyway so a future CLI change cannot quietly flip it.
153
+ mockCLI({
154
+ "resolve --json": JSON.stringify({ ...RESOLUTION, headers: {} }),
155
+ "models --wire=anthropic --all": cliPayload([HAIKU]),
156
+ "models --wire=openai --all": cliPayload([NOVA]),
157
+ });
158
+ const registered = await runExtension();
159
+ expect(registered.length).toBeGreaterThan(0);
160
+ for (const r of registered) {
161
+ expect(r.config.headers).toBeUndefined();
162
+ }
163
+ });
164
+
165
+ test("omits headers when resolve reports none", async () => {
166
+ const noHeaders: Record<string, unknown> = { ...RESOLUTION };
167
+ delete noHeaders.headers;
168
+ mockCLI({
169
+ "resolve --json": JSON.stringify(noHeaders),
170
+ "models --wire=anthropic --all": cliPayload([HAIKU]),
171
+ "models --wire=openai --all": cliPayload([NOVA]),
172
+ });
173
+ const registered = await runExtension();
174
+ expect(registered.length).toBeGreaterThan(0);
175
+ for (const r of registered) {
176
+ expect(r.config.headers).toBeUndefined();
177
+ }
178
+ });
179
+
137
180
  test("never reads the key: model discovery goes through the CLI", async () => {
138
181
  // The CLI holds the credential and returns only non-secret metadata, so
139
182
  // `key print` must not be invoked at startup at all.
@@ -231,6 +274,23 @@ describe("unpriced models", () => {
231
274
  });
232
275
  });
233
276
 
277
+ describe("disabled models", () => {
278
+ test("omits models the CLI marks disabled", async () => {
279
+ const { toPiModels } = await import("./index.js");
280
+ const [model] = toPiModels(
281
+ { models: [{ ...NOVA, disabled: true }] },
282
+ "openai-completions",
283
+ );
284
+ expect(model).toBeUndefined();
285
+ });
286
+
287
+ test("keeps models the CLI does not mark disabled", async () => {
288
+ const { toPiModels } = await import("./index.js");
289
+ const [model] = toPiModels({ models: [NOVA] }, "openai-completions");
290
+ expect(model?.id).toBe("bedrock/amazon.nova-lite-v1:0");
291
+ });
292
+ });
293
+
234
294
  describe("reasoning", () => {
235
295
  const KIMI: CliModel = {
236
296
  id: "fireworks/models/kimi-k3",