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 +3 -3
- package/src/resolver.ts +5 -8
- package/tests/resolver.test.ts +20 -30
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-llama-cpp",
|
|
3
|
-
"version": "0.8.
|
|
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.
|
|
39
|
+
"@types/node": "^26.1.1",
|
|
40
40
|
"prettier-plugin-organize-imports": "^4.3.0",
|
|
41
|
-
"vitest": "^4.1.
|
|
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
|
|
109
|
+
* Resolves API key for the provider ID using Pi's stored credentials
|
|
111
110
|
*/
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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
|
/**
|
package/tests/resolver.test.ts
CHANGED
|
@@ -5,22 +5,18 @@ import {
|
|
|
5
5
|
} from "../src/constants";
|
|
6
6
|
|
|
7
7
|
// Hoisted mock instances — survives vi.resetModules()
|
|
8
|
-
const
|
|
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,
|
|
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
|
-
|
|
22
|
-
|
|
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
|
-
|
|
149
|
-
mockAuthStorage.getApiKey.mockResolvedValue(undefined);
|
|
144
|
+
mockReadStoredCredential.mockReturnValue(undefined);
|
|
150
145
|
});
|
|
151
146
|
|
|
152
|
-
it("should return placeholder when
|
|
153
|
-
|
|
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 =
|
|
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
|
|
164
|
-
|
|
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 =
|
|
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
|
|
175
|
-
|
|
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 =
|
|
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
|
|
186
|
-
|
|
174
|
+
it("should call readStoredCredential with the provider ID", () => {
|
|
175
|
+
mockReadStoredCredential.mockReturnValue({ apiKey: "test-key" });
|
|
187
176
|
|
|
188
177
|
const resolver = new ConfigResolver();
|
|
189
|
-
|
|
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(
|
|
180
|
+
expect(mockReadStoredCredential).toHaveBeenCalledWith(
|
|
181
|
+
"llama-server=http://127.0.0.1:8080",
|
|
182
|
+
);
|
|
193
183
|
});
|
|
194
184
|
});
|