@narumitw/pi-btw 0.49.2 → 0.49.5

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": "@narumitw/pi-btw",
3
- "version": "0.49.2",
3
+ "version": "0.49.5",
4
4
  "description": "Pi extension that adds a /btw side-question command.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -28,7 +28,7 @@
28
28
  "typecheck": "tsc --noEmit"
29
29
  },
30
30
  "devDependencies": {
31
- "@biomejs/biome": "2.5.6",
31
+ "@biomejs/biome": "2.5.7",
32
32
  "@earendil-works/pi-ai": "0.83.0",
33
33
  "@earendil-works/pi-coding-agent": "0.83.0",
34
34
  "@earendil-works/pi-tui": "0.83.0",
package/src/btw.ts CHANGED
@@ -3,6 +3,7 @@ import {
3
3
  clampThinkingLevel,
4
4
  getSupportedThinkingLevels,
5
5
  type Model,
6
+ type ProviderHeaders,
6
7
  } from "@earendil-works/pi-ai";
7
8
  import {
8
9
  BorderedLoader,
@@ -76,15 +77,10 @@ interface LoadBtwThinkingLevelOptions {
76
77
  warn?: (message: string) => void;
77
78
  }
78
79
 
79
- interface BtwModelRegistry {
80
- find(provider: string, modelId: string): Model<Api> | undefined;
81
- getApiKeyAndHeaders(
82
- model: Model<Api>,
83
- ): Promise<
84
- | { ok: true; apiKey?: string; headers?: Record<string, string>; env?: Record<string, string> }
85
- | { ok: false; error: string }
86
- >;
87
- }
80
+ type BtwModelRegistry = Pick<
81
+ ExtensionCommandContext["modelRegistry"],
82
+ "find" | "getApiKeyAndHeaders"
83
+ >;
88
84
 
89
85
  interface ResolveBtwModelOptions {
90
86
  settings: BtwSettings;
@@ -154,11 +150,15 @@ export async function resolveBtwModel({
154
150
  function hasRequestAuth(auth: SideQuestionAuth): boolean {
155
151
  return Boolean(
156
152
  auth.apiKey ||
157
- (auth.headers && Object.keys(auth.headers).length > 0) ||
153
+ providerHeadersHaveValue(auth.headers) ||
158
154
  (auth.env && Object.keys(auth.env).length > 0),
159
155
  );
160
156
  }
161
157
 
158
+ function providerHeadersHaveValue(headers: ProviderHeaders | undefined): boolean {
159
+ return headers !== undefined && Object.values(headers).some((value) => value !== null);
160
+ }
161
+
162
162
  export async function loadBtwThinkingLevel(
163
163
  currentThinkingLevel: BtwThinkingLevel,
164
164
  options: LoadBtwThinkingLevelOptions = {},
@@ -4,6 +4,7 @@ import type {
4
4
  Context,
5
5
  Message,
6
6
  Model,
7
+ ProviderHeaders,
7
8
  SimpleStreamOptions,
8
9
  UserMessage,
9
10
  } from "@earendil-works/pi-ai";
@@ -22,7 +23,7 @@ export type BtwThinkingLevel = (typeof BTW_THINKING_LEVELS)[number];
22
23
 
23
24
  export interface SideQuestionAuth {
24
25
  apiKey?: string;
25
- headers?: Record<string, string>;
26
+ headers?: ProviderHeaders;
26
27
  env?: Record<string, string>;
27
28
  }
28
29