@mcowger/pi-plexus 0.8.1 → 0.8.3
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/dist/extension.js +43 -15
- package/package.json +1 -1
package/dist/extension.js
CHANGED
|
@@ -25,6 +25,8 @@ function mapPreferredApi(raw) {
|
|
|
25
25
|
function adjustBaseUrl(baseUrl, preferredApi) {
|
|
26
26
|
const stripped = baseUrl.replace(/\/+$/, "");
|
|
27
27
|
switch (preferredApi) {
|
|
28
|
+
case "anthropic-messages":
|
|
29
|
+
return stripped.endsWith("/v1") ? stripped.slice(0, -3) : stripped;
|
|
28
30
|
case "google-generative-ai":
|
|
29
31
|
return stripped.endsWith("/v1") ? `${stripped.slice(0, -3)}/v1beta` : stripped;
|
|
30
32
|
default:
|
|
@@ -160,18 +162,31 @@ function detectOpenAICompletionsCompat(providerName, baseUrl) {
|
|
|
160
162
|
}
|
|
161
163
|
return compat;
|
|
162
164
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
165
|
+
var DEFAULT_MODELS_FETCH_TIMEOUT_MS = 1e4;
|
|
166
|
+
async function fetchPlexusModels(apiKey, modelsUrl, timeoutMs = DEFAULT_MODELS_FETCH_TIMEOUT_MS) {
|
|
167
|
+
const controller = new AbortController;
|
|
168
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
169
|
+
try {
|
|
170
|
+
const res = await fetch(modelsUrl, {
|
|
171
|
+
headers: {
|
|
172
|
+
Authorization: `Bearer ${apiKey}`,
|
|
173
|
+
Accept: "application/json"
|
|
174
|
+
},
|
|
175
|
+
signal: controller.signal
|
|
176
|
+
});
|
|
177
|
+
if (!res.ok) {
|
|
178
|
+
throw new Error(`Plexus models fetch failed: ${res.status} ${res.statusText}`);
|
|
168
179
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
180
|
+
const raw = await res.json();
|
|
181
|
+
return { models: raw.data ?? [], raw };
|
|
182
|
+
} catch (err) {
|
|
183
|
+
if (err instanceof Error && err.name === "AbortError") {
|
|
184
|
+
throw new Error(`Plexus models fetch timed out after ${timeoutMs}ms`);
|
|
185
|
+
}
|
|
186
|
+
throw err;
|
|
187
|
+
} finally {
|
|
188
|
+
clearTimeout(timer);
|
|
172
189
|
}
|
|
173
|
-
const raw = await res.json();
|
|
174
|
-
return { models: raw.data ?? [], raw };
|
|
175
190
|
}
|
|
176
191
|
// src/config.ts
|
|
177
192
|
import { existsSync, readFileSync } from "fs";
|
|
@@ -181,13 +196,18 @@ import { getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
|
181
196
|
var getConfigDir = () => join(getAgentDir(), "extensions", "plexus");
|
|
182
197
|
var getConfigPath = () => join(getConfigDir(), "config.json");
|
|
183
198
|
var normalizeRoot = (raw) => raw.replace(/\/+$/, "");
|
|
199
|
+
var cachedConfig = null;
|
|
184
200
|
function getConfigSync() {
|
|
201
|
+
if (cachedConfig)
|
|
202
|
+
return cachedConfig;
|
|
185
203
|
try {
|
|
186
204
|
if (existsSync(getConfigPath())) {
|
|
187
|
-
|
|
205
|
+
cachedConfig = JSON.parse(readFileSync(getConfigPath(), "utf8"));
|
|
206
|
+
return cachedConfig;
|
|
188
207
|
}
|
|
189
208
|
} catch {}
|
|
190
|
-
|
|
209
|
+
cachedConfig = {};
|
|
210
|
+
return cachedConfig;
|
|
191
211
|
}
|
|
192
212
|
async function saveBaseUrl(baseUrl, defaultModel) {
|
|
193
213
|
await mkdir(getConfigDir(), { recursive: true });
|
|
@@ -199,6 +219,7 @@ async function saveBaseUrl(baseUrl, defaultModel) {
|
|
|
199
219
|
};
|
|
200
220
|
await writeFile(getConfigPath(), `${JSON.stringify(config, null, 2)}
|
|
201
221
|
`, "utf8");
|
|
222
|
+
cachedConfig = config;
|
|
202
223
|
}
|
|
203
224
|
function getRawBaseUrl() {
|
|
204
225
|
const config = getConfigSync();
|
|
@@ -265,19 +286,26 @@ async function writeRawResponse(data) {
|
|
|
265
286
|
}
|
|
266
287
|
|
|
267
288
|
// src/log.ts
|
|
268
|
-
import {
|
|
289
|
+
import { mkdir as mkdir3, appendFile } from "fs/promises";
|
|
269
290
|
import { join as join3 } from "path";
|
|
270
291
|
import { getAgentDir as getAgentDir3 } from "@earendil-works/pi-coding-agent";
|
|
271
292
|
var getCacheDir2 = () => join3(getAgentDir3(), "extensions", "plexus");
|
|
272
293
|
var getLogPath = () => join3(getCacheDir2(), "plexus.log");
|
|
294
|
+
var dirEnsured = false;
|
|
273
295
|
function log(message, data) {
|
|
296
|
+
writeLogLine(message, data);
|
|
297
|
+
}
|
|
298
|
+
async function writeLogLine(message, data) {
|
|
274
299
|
try {
|
|
275
|
-
|
|
300
|
+
if (!dirEnsured) {
|
|
301
|
+
await mkdir3(getCacheDir2(), { recursive: true });
|
|
302
|
+
dirEnsured = true;
|
|
303
|
+
}
|
|
276
304
|
const ts = new Date().toISOString();
|
|
277
305
|
const line = data !== undefined ? `${ts} ${message} ${JSON.stringify(data)}
|
|
278
306
|
` : `${ts} ${message}
|
|
279
307
|
`;
|
|
280
|
-
|
|
308
|
+
await appendFile(getLogPath(), line, "utf8");
|
|
281
309
|
} catch {}
|
|
282
310
|
}
|
|
283
311
|
|