@stablekernel/pi-bifrost 0.2.0 → 0.2.1

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.1",
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 = {
@@ -161,6 +164,19 @@ export default async function (pi: ExtensionAPI): Promise<void> {
161
164
  apiKey: `!${CLI} key print`,
162
165
  api: surface.api,
163
166
  models,
167
+ // Attribution and gateway-routing headers come from the same resolve
168
+ // output every other harness honors; pi drops them silently otherwise.
169
+ // An empty map is treated as absent: Go's mergeHeaders returns nil for
170
+ // an empty merge and the JSON tag omits it, so the plugin only ever
171
+ // sees a real map or nothing.
172
+ //
173
+ // Config-trust note: a header named Authorization or x-api-key here
174
+ // would override the credential pi injects, but only toward the
175
+ // already-allowlisted gateway origin (isAllowedGatewayUrl), which is
176
+ // where the key goes anyway.
177
+ ...(info.headers && Object.keys(info.headers).length > 0
178
+ ? { headers: info.headers }
179
+ : {}),
164
180
  });
165
181
  }
166
182
  }
@@ -134,6 +134,46 @@ describe("provider registration", () => {
134
134
  expect(calls).toContain("models --wire=openai --all");
135
135
  });
136
136
 
137
+ test("passes the resolved gateway headers onto both providers", async () => {
138
+ mockCLI(OK_CLI);
139
+ const registered = await runExtension();
140
+ expect(registered.length).toBeGreaterThan(0);
141
+ for (const r of registered) {
142
+ expect(r.config.headers).toEqual(RESOLUTION.headers);
143
+ }
144
+ });
145
+
146
+ test("treats an empty header map the same as no headers", async () => {
147
+ // Go-side mergeHeaders returns nil for an empty merge and the JSON tag
148
+ // omits it, so `{}` cannot reach the plugin in practice. This pins the
149
+ // behavior anyway so a future CLI change cannot quietly flip it.
150
+ mockCLI({
151
+ "resolve --json": JSON.stringify({ ...RESOLUTION, headers: {} }),
152
+ "models --wire=anthropic --all": cliPayload([HAIKU]),
153
+ "models --wire=openai --all": cliPayload([NOVA]),
154
+ });
155
+ const registered = await runExtension();
156
+ expect(registered.length).toBeGreaterThan(0);
157
+ for (const r of registered) {
158
+ expect(r.config.headers).toBeUndefined();
159
+ }
160
+ });
161
+
162
+ test("omits headers when resolve reports none", async () => {
163
+ const noHeaders: Record<string, unknown> = { ...RESOLUTION };
164
+ delete noHeaders.headers;
165
+ mockCLI({
166
+ "resolve --json": JSON.stringify(noHeaders),
167
+ "models --wire=anthropic --all": cliPayload([HAIKU]),
168
+ "models --wire=openai --all": cliPayload([NOVA]),
169
+ });
170
+ const registered = await runExtension();
171
+ expect(registered.length).toBeGreaterThan(0);
172
+ for (const r of registered) {
173
+ expect(r.config.headers).toBeUndefined();
174
+ }
175
+ });
176
+
137
177
  test("never reads the key: model discovery goes through the CLI", async () => {
138
178
  // The CLI holds the credential and returns only non-secret metadata, so
139
179
  // `key print` must not be invoked at startup at all.