@mcowger/oh-my-pi-plexus 1.3.9 → 1.3.10
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 +21 -7
- package/package.json +1 -1
package/dist/extension.js
CHANGED
|
@@ -109536,22 +109536,28 @@ function detectOpenAICompletionsCompat(providerName, baseUrl) {
|
|
|
109536
109536
|
return compat;
|
|
109537
109537
|
}
|
|
109538
109538
|
var DEFAULT_MODELS_FETCH_TIMEOUT_MS = 1e4;
|
|
109539
|
-
async function fetchPlexusModels(apiKey, modelsUrl, timeoutMs = DEFAULT_MODELS_FETCH_TIMEOUT_MS) {
|
|
109539
|
+
async function fetchPlexusModels(apiKey, modelsUrl, timeoutMs = DEFAULT_MODELS_FETCH_TIMEOUT_MS, etag) {
|
|
109540
109540
|
const controller = new AbortController;
|
|
109541
109541
|
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
109542
109542
|
try {
|
|
109543
109543
|
const headers = { Accept: "application/json" };
|
|
109544
109544
|
if (apiKey)
|
|
109545
109545
|
headers.Authorization = `Bearer ${apiKey}`;
|
|
109546
|
+
if (etag)
|
|
109547
|
+
headers["If-None-Match"] = etag;
|
|
109546
109548
|
const res = await fetch(modelsUrl, {
|
|
109547
109549
|
headers,
|
|
109548
109550
|
signal: controller.signal
|
|
109549
109551
|
});
|
|
109552
|
+
if (res.status === 304) {
|
|
109553
|
+
return { models: [], notModified: true };
|
|
109554
|
+
}
|
|
109550
109555
|
if (!res.ok) {
|
|
109551
109556
|
throw new Error(`Plexus models fetch failed: ${res.status} ${res.statusText}`);
|
|
109552
109557
|
}
|
|
109553
109558
|
const raw = await res.json();
|
|
109554
|
-
|
|
109559
|
+
const responseEtag = res.headers.get("etag") ?? undefined;
|
|
109560
|
+
return { models: raw.data ?? [], raw, etag: responseEtag };
|
|
109555
109561
|
} catch (err) {
|
|
109556
109562
|
if (err instanceof Error && err.name === "AbortError") {
|
|
109557
109563
|
throw new Error(`Plexus models fetch timed out after ${timeoutMs}ms`);
|
|
@@ -109710,7 +109716,8 @@ function parseCacheData(raw) {
|
|
|
109710
109716
|
return null;
|
|
109711
109717
|
return {
|
|
109712
109718
|
models: obj["models"],
|
|
109713
|
-
timestamp: typeof obj["timestamp"] === "number" ? obj["timestamp"] : 0
|
|
109719
|
+
timestamp: typeof obj["timestamp"] === "number" ? obj["timestamp"] : 0,
|
|
109720
|
+
etag: typeof obj["etag"] === "string" ? obj["etag"] : undefined
|
|
109714
109721
|
};
|
|
109715
109722
|
} catch {
|
|
109716
109723
|
return null;
|
|
@@ -109726,9 +109733,9 @@ function readCachedModelsSync() {
|
|
|
109726
109733
|
return null;
|
|
109727
109734
|
}
|
|
109728
109735
|
}
|
|
109729
|
-
async function writeCachedModels(models) {
|
|
109736
|
+
async function writeCachedModels(models, etag) {
|
|
109730
109737
|
await mkdir2(getCacheDir(), { recursive: true });
|
|
109731
|
-
const payload = { models, timestamp: Date.now() };
|
|
109738
|
+
const payload = { models, timestamp: Date.now(), etag };
|
|
109732
109739
|
await writeFile2(getModelsCachePath(), `${JSON.stringify(payload, null, 2)}
|
|
109733
109740
|
`, "utf8");
|
|
109734
109741
|
}
|
|
@@ -129529,11 +129536,18 @@ async function doRefresh(pi, apiKey, ctx) {
|
|
|
129529
129536
|
return;
|
|
129530
129537
|
}
|
|
129531
129538
|
try {
|
|
129532
|
-
const
|
|
129539
|
+
const cached3 = readCachedModelsSync();
|
|
129540
|
+
const { models: apiModels, raw, etag, notModified } = await fetchPlexusModels(apiKey, modelsUrl, undefined, cached3?.etag);
|
|
129541
|
+
if (notModified) {
|
|
129542
|
+
log("doRefresh: not modified", { etag: cached3?.etag });
|
|
129543
|
+
if (ctx)
|
|
129544
|
+
ctx.ui.notify(`Refreshed ${currentModels.length} Plexus models (not modified)`, "info");
|
|
129545
|
+
return;
|
|
129546
|
+
}
|
|
129533
129547
|
const suppressPatterns = getSuppressedModels();
|
|
129534
129548
|
const descriptors3 = convertDescriptors(apiModels, baseUrl, suppressPatterns);
|
|
129535
129549
|
const ohMyPiModels = descriptors3.map(descriptorToOhMyPiModel);
|
|
129536
|
-
await Promise.all([writeCachedModels(descriptors3), writeRawResponse(raw)]);
|
|
129550
|
+
await Promise.all([writeCachedModels(descriptors3, etag), raw ? writeRawResponse(raw) : Promise.resolve()]);
|
|
129537
129551
|
currentModels = ohMyPiModels;
|
|
129538
129552
|
pi.registerProvider(PROVIDER_NAME, {
|
|
129539
129553
|
api: "openai-completions",
|