@mcowger/oh-my-pi-plexus 1.3.9 → 1.4.0

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.
Files changed (2) hide show
  1. package/dist/extension.js +25 -8
  2. package/package.json +1 -1
package/dist/extension.js CHANGED
@@ -109536,23 +109536,32 @@ 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, signal) {
109540
109540
  const controller = new AbortController;
109541
109541
  const timer = setTimeout(() => controller.abort(), timeoutMs);
109542
+ const requestSignal = signal ? AbortSignal.any([signal, controller.signal]) : controller.signal;
109542
109543
  try {
109543
109544
  const headers = { Accept: "application/json" };
109544
109545
  if (apiKey)
109545
109546
  headers.Authorization = `Bearer ${apiKey}`;
109547
+ if (etag)
109548
+ headers["If-None-Match"] = etag;
109546
109549
  const res = await fetch(modelsUrl, {
109547
109550
  headers,
109548
- signal: controller.signal
109551
+ signal: requestSignal
109549
109552
  });
109553
+ if (res.status === 304) {
109554
+ return { models: [], notModified: true };
109555
+ }
109550
109556
  if (!res.ok) {
109551
109557
  throw new Error(`Plexus models fetch failed: ${res.status} ${res.statusText}`);
109552
109558
  }
109553
109559
  const raw = await res.json();
109554
- return { models: raw.data ?? [], raw };
109560
+ const responseEtag = res.headers.get("etag") ?? undefined;
109561
+ return { models: raw.data ?? [], raw, etag: responseEtag };
109555
109562
  } catch (err) {
109563
+ if (signal?.aborted)
109564
+ throw err;
109556
109565
  if (err instanceof Error && err.name === "AbortError") {
109557
109566
  throw new Error(`Plexus models fetch timed out after ${timeoutMs}ms`);
109558
109567
  }
@@ -109710,7 +109719,8 @@ function parseCacheData(raw) {
109710
109719
  return null;
109711
109720
  return {
109712
109721
  models: obj["models"],
109713
- timestamp: typeof obj["timestamp"] === "number" ? obj["timestamp"] : 0
109722
+ timestamp: typeof obj["timestamp"] === "number" ? obj["timestamp"] : 0,
109723
+ etag: typeof obj["etag"] === "string" ? obj["etag"] : undefined
109714
109724
  };
109715
109725
  } catch {
109716
109726
  return null;
@@ -109726,9 +109736,9 @@ function readCachedModelsSync() {
109726
109736
  return null;
109727
109737
  }
109728
109738
  }
109729
- async function writeCachedModels(models) {
109739
+ async function writeCachedModels(models, etag) {
109730
109740
  await mkdir2(getCacheDir(), { recursive: true });
109731
- const payload = { models, timestamp: Date.now() };
109741
+ const payload = { models, timestamp: Date.now(), etag };
109732
109742
  await writeFile2(getModelsCachePath(), `${JSON.stringify(payload, null, 2)}
109733
109743
  `, "utf8");
109734
109744
  }
@@ -129529,11 +129539,18 @@ async function doRefresh(pi, apiKey, ctx) {
129529
129539
  return;
129530
129540
  }
129531
129541
  try {
129532
- const { models: apiModels, raw } = await fetchPlexusModels(apiKey, modelsUrl);
129542
+ const cached3 = readCachedModelsSync();
129543
+ const { models: apiModels, raw, etag, notModified } = await fetchPlexusModels(apiKey, modelsUrl, undefined, cached3?.etag);
129544
+ if (notModified) {
129545
+ log("doRefresh: not modified", { etag: cached3?.etag });
129546
+ if (ctx)
129547
+ ctx.ui.notify(`Refreshed ${currentModels.length} Plexus models (not modified)`, "info");
129548
+ return;
129549
+ }
129533
129550
  const suppressPatterns = getSuppressedModels();
129534
129551
  const descriptors3 = convertDescriptors(apiModels, baseUrl, suppressPatterns);
129535
129552
  const ohMyPiModels = descriptors3.map(descriptorToOhMyPiModel);
129536
- await Promise.all([writeCachedModels(descriptors3), writeRawResponse(raw)]);
129553
+ await Promise.all([writeCachedModels(descriptors3, etag), raw ? writeRawResponse(raw) : Promise.resolve()]);
129537
129554
  currentModels = ohMyPiModels;
129538
129555
  pi.registerProvider(PROVIDER_NAME, {
129539
129556
  api: "openai-completions",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcowger/oh-my-pi-plexus",
3
- "version": "1.3.9",
3
+ "version": "1.4.0",
4
4
  "description": "Plexus AI proxy plugin for the Oh My Pi coding agent",
5
5
  "type": "module",
6
6
  "files": [