pi-llama-cpp 0.8.1 → 0.8.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": "pi-llama-cpp",
3
- "version": "0.8.1",
3
+ "version": "0.8.2",
4
4
  "description": "Pi extension for llama.cpp integration. Supports router, single and legacy models. Supports multiple servers.",
5
5
  "keywords": [
6
6
  "pi",
@@ -36,8 +36,8 @@
36
36
  "@earendil-works/pi-tui": "*"
37
37
  },
38
38
  "devDependencies": {
39
- "@types/node": "^26.0.1",
39
+ "@types/node": "^26.1.1",
40
40
  "prettier-plugin-organize-imports": "^4.3.0",
41
- "vitest": "^4.1.9"
41
+ "vitest": "^4.1.10"
42
42
  }
43
43
  }
package/src/resolver.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
- AuthStorage,
3
2
  getAgentDir,
3
+ readStoredCredential,
4
4
  SettingsManager,
5
5
  } from "@earendil-works/pi-coding-agent";
6
6
  import { readFile } from "node:fs/promises";
@@ -16,7 +16,6 @@ export class ConfigResolver {
16
16
  private warnings: string[] = [];
17
17
 
18
18
  private cachedUrls: string[] = [];
19
- private authStorage = AuthStorage.create(join(getAgentDir(), "auth.json"));
20
19
  private settingsManager = SettingsManager.create(
21
20
  process.cwd(),
22
21
  getAgentDir(),
@@ -107,13 +106,11 @@ export class ConfigResolver {
107
106
  }
108
107
 
109
108
  /**
110
- * Resolves API key for the provider ID using Pi's AuthStorage
109
+ * Resolves API key for the provider ID using Pi's stored credentials
111
110
  */
112
- async resolveApiKey(providerId: string): Promise<string> {
113
- this.authStorage.reload();
114
- const apiKey = await this.authStorage.getApiKey(providerId);
115
-
116
- return apiKey ?? API_KEY_PLACEHOLDER;
111
+ resolveApiKey(providerId: string): string {
112
+ const credential = readStoredCredential(providerId);
113
+ return credential?.apiKey ?? API_KEY_PLACEHOLDER;
117
114
  }
118
115
 
119
116
  /**
@@ -5,22 +5,18 @@ import {
5
5
  } from "../src/constants";
6
6
 
7
7
  // Hoisted mock instances — survives vi.resetModules()
8
- const mockAuthStorage = vi.hoisted(() => ({
9
- reload: vi.fn(),
10
- getApiKey: vi.fn(),
11
- }));
8
+ const mockReadStoredCredential = vi.hoisted(() => vi.fn());
12
9
 
13
10
  const mockSettingsManager = vi.hoisted(() => ({
14
11
  getProjectSettings: vi.fn(),
15
12
  getGlobalSettings: vi.fn(),
16
13
  }));
17
14
 
18
- // Mock getAgentDir, AuthStorage, and SettingsManager before importing resolver
15
+ // Mock getAgentDir, readStoredCredential, and SettingsManager before importing resolver
19
16
  vi.mock("@earendil-works/pi-coding-agent", () => ({
20
17
  getAgentDir: vi.fn().mockReturnValue("/fake/agent/dir"),
21
- AuthStorage: {
22
- create: vi.fn().mockReturnValue(mockAuthStorage),
23
- },
18
+ readStoredCredential: (...args: unknown[]) =>
19
+ mockReadStoredCredential(...args),
24
20
  SettingsManager: {
25
21
  create: vi.fn().mockReturnValue(mockSettingsManager),
26
22
  },
@@ -145,50 +141,44 @@ describe("API key resolution", () => {
145
141
  beforeEach(() => {
146
142
  vi.clearAllMocks();
147
143
  mockGetAgentDir.mockReturnValue("/fake/agent/dir");
148
- mockAuthStorage.reload.mockReturnValue(undefined);
149
- mockAuthStorage.getApiKey.mockResolvedValue(undefined);
144
+ mockReadStoredCredential.mockReturnValue(undefined);
150
145
  });
151
146
 
152
- it("should return placeholder when auth file does not exist", async () => {
153
- mockAuthStorage.getApiKey.mockResolvedValue(undefined);
147
+ it("should return placeholder when credential is not found", () => {
148
+ mockReadStoredCredential.mockReturnValue(undefined);
154
149
 
155
150
  const resolver = new ConfigResolver();
156
- const result = await resolver.resolveApiKey(
157
- "llama-server=http://127.0.0.1:8080",
158
- );
151
+ const result = resolver.resolveApiKey("llama-server=http://127.0.0.1:8080");
159
152
 
160
153
  expect(result).toEqual(API_KEY_PLACEHOLDER);
161
154
  });
162
155
 
163
- it("should return placeholder when provider key is missing", async () => {
164
- mockAuthStorage.getApiKey.mockResolvedValue(undefined);
156
+ it("should return placeholder when apiKey is missing from credential", () => {
157
+ mockReadStoredCredential.mockReturnValue({});
165
158
 
166
159
  const resolver = new ConfigResolver();
167
- const result = await resolver.resolveApiKey(
168
- "llama-server=http://127.0.0.1:8080",
169
- );
160
+ const result = resolver.resolveApiKey("llama-server=http://127.0.0.1:8080");
170
161
 
171
162
  expect(result).toEqual(API_KEY_PLACEHOLDER);
172
163
  });
173
164
 
174
- it("should return the provider key when present", async () => {
175
- mockAuthStorage.getApiKey.mockResolvedValue("test-api-key");
165
+ it("should return the apiKey when present in credential", () => {
166
+ mockReadStoredCredential.mockReturnValue({ apiKey: "test-api-key" });
176
167
 
177
168
  const resolver = new ConfigResolver();
178
- const result = await resolver.resolveApiKey(
179
- "llama-server=http://127.0.0.1:8080",
180
- );
169
+ const result = resolver.resolveApiKey("llama-server=http://127.0.0.1:8080");
181
170
 
182
171
  expect(result).toEqual("test-api-key");
183
172
  });
184
173
 
185
- it("should call reload before each getApiKey", async () => {
186
- mockAuthStorage.getApiKey.mockResolvedValue("cached-key");
174
+ it("should call readStoredCredential with the provider ID", () => {
175
+ mockReadStoredCredential.mockReturnValue({ apiKey: "test-key" });
187
176
 
188
177
  const resolver = new ConfigResolver();
189
- await resolver.resolveApiKey("llama-server=http://127.0.0.1:8080");
190
- await resolver.resolveApiKey("llama-server=http://127.0.0.1:8080");
178
+ resolver.resolveApiKey("llama-server=http://127.0.0.1:8080");
191
179
 
192
- expect(mockAuthStorage.reload).toHaveBeenCalledTimes(2);
180
+ expect(mockReadStoredCredential).toHaveBeenCalledWith(
181
+ "llama-server=http://127.0.0.1:8080",
182
+ );
193
183
  });
194
184
  });