@mcowger/pi-plexus 0.8.2 → 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.
Files changed (2) hide show
  1. package/dist/extension.js +41 -15
  2. package/package.json +1 -1
package/dist/extension.js CHANGED
@@ -162,18 +162,31 @@ function detectOpenAICompletionsCompat(providerName, baseUrl) {
162
162
  }
163
163
  return compat;
164
164
  }
165
- async function fetchPlexusModels(apiKey, modelsUrl) {
166
- const res = await fetch(modelsUrl, {
167
- headers: {
168
- Authorization: `Bearer ${apiKey}`,
169
- Accept: "application/json"
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}`);
170
179
  }
171
- });
172
- if (!res.ok) {
173
- throw new Error(`Plexus models fetch failed: ${res.status} ${res.statusText}`);
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);
174
189
  }
175
- const raw = await res.json();
176
- return { models: raw.data ?? [], raw };
177
190
  }
178
191
  // src/config.ts
179
192
  import { existsSync, readFileSync } from "fs";
@@ -183,13 +196,18 @@ import { getAgentDir } from "@earendil-works/pi-coding-agent";
183
196
  var getConfigDir = () => join(getAgentDir(), "extensions", "plexus");
184
197
  var getConfigPath = () => join(getConfigDir(), "config.json");
185
198
  var normalizeRoot = (raw) => raw.replace(/\/+$/, "");
199
+ var cachedConfig = null;
186
200
  function getConfigSync() {
201
+ if (cachedConfig)
202
+ return cachedConfig;
187
203
  try {
188
204
  if (existsSync(getConfigPath())) {
189
- return JSON.parse(readFileSync(getConfigPath(), "utf8"));
205
+ cachedConfig = JSON.parse(readFileSync(getConfigPath(), "utf8"));
206
+ return cachedConfig;
190
207
  }
191
208
  } catch {}
192
- return {};
209
+ cachedConfig = {};
210
+ return cachedConfig;
193
211
  }
194
212
  async function saveBaseUrl(baseUrl, defaultModel) {
195
213
  await mkdir(getConfigDir(), { recursive: true });
@@ -201,6 +219,7 @@ async function saveBaseUrl(baseUrl, defaultModel) {
201
219
  };
202
220
  await writeFile(getConfigPath(), `${JSON.stringify(config, null, 2)}
203
221
  `, "utf8");
222
+ cachedConfig = config;
204
223
  }
205
224
  function getRawBaseUrl() {
206
225
  const config = getConfigSync();
@@ -267,19 +286,26 @@ async function writeRawResponse(data) {
267
286
  }
268
287
 
269
288
  // src/log.ts
270
- import { appendFileSync, mkdirSync } from "fs";
289
+ import { mkdir as mkdir3, appendFile } from "fs/promises";
271
290
  import { join as join3 } from "path";
272
291
  import { getAgentDir as getAgentDir3 } from "@earendil-works/pi-coding-agent";
273
292
  var getCacheDir2 = () => join3(getAgentDir3(), "extensions", "plexus");
274
293
  var getLogPath = () => join3(getCacheDir2(), "plexus.log");
294
+ var dirEnsured = false;
275
295
  function log(message, data) {
296
+ writeLogLine(message, data);
297
+ }
298
+ async function writeLogLine(message, data) {
276
299
  try {
277
- mkdirSync(getCacheDir2(), { recursive: true });
300
+ if (!dirEnsured) {
301
+ await mkdir3(getCacheDir2(), { recursive: true });
302
+ dirEnsured = true;
303
+ }
278
304
  const ts = new Date().toISOString();
279
305
  const line = data !== undefined ? `${ts} ${message} ${JSON.stringify(data)}
280
306
  ` : `${ts} ${message}
281
307
  `;
282
- appendFileSync(getLogPath(), line, "utf8");
308
+ await appendFile(getLogPath(), line, "utf8");
283
309
  } catch {}
284
310
  }
285
311
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcowger/pi-plexus",
3
- "version": "0.8.2",
3
+ "version": "0.8.3",
4
4
  "description": "Plexus AI proxy plugin for the pi coding agent",
5
5
  "type": "module",
6
6
  "files": [