@mcowger/pi-plexus 0.5.4 → 0.6.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.
- package/README.md +63 -49
- package/dist/extension.js +157 -148
- package/package.json +5 -7
package/README.md
CHANGED
|
@@ -2,100 +2,114 @@
|
|
|
2
2
|
|
|
3
3
|
Exposes models from a self-hosted [Plexus](https://github.com/mcowger/plexus) AI proxy as a first-class provider inside AI coding agents. Models appear in the agent's model picker with correct wire-protocol behavior, as if they were natively supported providers.
|
|
4
4
|
|
|
5
|
-
Supported hosts:
|
|
6
|
-
|
|
7
|
-
- **oh-my-pi** (`can1357/oh-my-pi`) — via `plexus-pi` (the legacy-pi shim handles scope remapping automatically)
|
|
8
|
-
- **pi** (`earendil-works/pi`) — via `plexus-pi`
|
|
9
|
-
|
|
10
5
|
## Prerequisites
|
|
11
6
|
|
|
12
|
-
- [Bun](https://bun.sh) ≥ 1.1
|
|
13
7
|
- A running Plexus instance
|
|
14
|
-
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
The built `dist/extension.js` is committed to the repo, so no build step is needed for any install method.
|
|
12
|
+
|
|
13
|
+
### Option 1 — npm (recommended)
|
|
15
14
|
|
|
16
15
|
```sh
|
|
17
|
-
|
|
16
|
+
cd ~/.pi/agent/extensions
|
|
17
|
+
npm install @mcowger/pi-plexus
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
## Installation
|
|
20
|
+
pi auto-discovers packages under `~/.pi/agent/extensions/` that have a `pi.extensions` field in their `package.json`.
|
|
23
21
|
|
|
24
|
-
###
|
|
22
|
+
### Option 2 — git clone into the extensions directory
|
|
25
23
|
|
|
26
24
|
```sh
|
|
27
|
-
git clone https://github.com/mcowger/plexus-agent-plugins
|
|
28
|
-
cd plexus-agent-plugins
|
|
29
|
-
bun install
|
|
30
|
-
bun run --cwd packages/plexus-pi build.ts
|
|
31
|
-
omp plugin link packages/plexus-pi
|
|
25
|
+
git clone https://github.com/mcowger/plexus-agent-plugins ~/.pi/agent/extensions/plexus-agent-plugins
|
|
32
26
|
```
|
|
33
27
|
|
|
34
|
-
|
|
28
|
+
pi will find `packages/plexus-pi/` inside that directory and load `dist/extension.js`.
|
|
29
|
+
|
|
30
|
+
### Option 3 — git clone anywhere + settings.json
|
|
35
31
|
|
|
36
32
|
```sh
|
|
37
|
-
git clone https://github.com/mcowger/plexus-agent-plugins
|
|
38
|
-
cd plexus-agent-plugins
|
|
39
|
-
bun install
|
|
40
|
-
bun run --cwd packages/plexus-pi build.ts
|
|
33
|
+
git clone https://github.com/mcowger/plexus-agent-plugins ~/code/plexus-agent-plugins
|
|
41
34
|
```
|
|
42
35
|
|
|
43
|
-
Then
|
|
36
|
+
Then register the path in `~/.pi/agent/settings.json`:
|
|
44
37
|
|
|
45
|
-
|
|
38
|
+
```json
|
|
39
|
+
{
|
|
40
|
+
"extensions": [
|
|
41
|
+
"~/code/plexus-agent-plugins/packages/plexus-pi"
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
```
|
|
46
45
|
|
|
47
|
-
|
|
46
|
+
## First-time setup
|
|
47
|
+
|
|
48
|
+
On first use, run the login command inside pi:
|
|
48
49
|
|
|
49
50
|
```
|
|
50
51
|
/plexus login
|
|
51
52
|
```
|
|
52
53
|
|
|
53
54
|
You will be prompted for:
|
|
55
|
+
|
|
54
56
|
- **Plexus base URL** — e.g. `https://plexus.example.com`
|
|
57
|
+
- **Plexus API key**
|
|
55
58
|
- **Default model** (optional)
|
|
56
59
|
|
|
57
|
-
|
|
60
|
+
Credentials are stored in pi's standard `auth.json` (API key) and a small `config.json` (base URL). Models are fetched immediately and cached for fast startup.
|
|
61
|
+
|
|
62
|
+
After login, models appear in the model picker and refresh automatically on every new session.
|
|
58
63
|
|
|
59
|
-
To force a refresh:
|
|
64
|
+
To force a refresh at any time:
|
|
60
65
|
|
|
61
66
|
```
|
|
62
67
|
/plexus refresh
|
|
63
68
|
```
|
|
64
69
|
|
|
65
|
-
## Configuration
|
|
70
|
+
## Configuration files
|
|
66
71
|
|
|
67
|
-
|
|
68
|
-
|---|---|
|
|
69
|
-
| API key | `PLEXUS_API_KEY` environment variable (required) |
|
|
70
|
-
| Base URL | Set via `/plexus login`, stored at `~/.{omp,pi}/agent/extensions/plexus/config.json` |
|
|
71
|
-
| Default model | Optionally set during `/plexus login` |
|
|
72
|
-
|
|
73
|
-
Config, cache, and logs are written under the agent's data directory:
|
|
72
|
+
All files live under the agent's data directory:
|
|
74
73
|
|
|
75
74
|
```
|
|
76
|
-
~/.
|
|
77
|
-
config.json # base URL and default model
|
|
78
|
-
plexus-models-cache.json # last-fetched model list
|
|
75
|
+
~/.pi/agent/extensions/plexus/
|
|
76
|
+
config.json # base URL and optional default model
|
|
77
|
+
plexus-models-cache.json # last-fetched model list (startup cache)
|
|
79
78
|
plexus-models-response.json # raw API response (diagnostics)
|
|
80
79
|
plexus.log # extension activity log
|
|
81
80
|
```
|
|
82
81
|
|
|
83
|
-
|
|
82
|
+
The API key is stored in pi's own `~/.pi/agent/auth.json` alongside all other provider credentials — it is never written to a separate file.
|
|
84
83
|
|
|
85
|
-
|
|
84
|
+
## Package layout
|
|
86
85
|
|
|
87
|
-
```
|
|
88
|
-
|
|
86
|
+
```
|
|
87
|
+
packages/
|
|
88
|
+
plexus-models/ # host-agnostic data layer
|
|
89
|
+
src/
|
|
90
|
+
types.ts # wire types (PlexusApiModel, PlexusModelDescriptor, etc.)
|
|
91
|
+
convert.ts # model fetching, conversion, compat detection
|
|
92
|
+
index.ts # barrel export
|
|
93
|
+
plexus-pi/ # pi host adapter
|
|
94
|
+
src/
|
|
95
|
+
extension.ts # entry point: commands, session refresh, auth flow
|
|
96
|
+
mapper.ts # PlexusModelDescriptor → pi ProviderModelConfig
|
|
97
|
+
config.ts # base URL / default model config I/O
|
|
98
|
+
cache.ts # model cache I/O
|
|
99
|
+
log.ts # append-only log
|
|
100
|
+
package.json # declares pi.extensions entry point
|
|
89
101
|
```
|
|
90
102
|
|
|
91
|
-
|
|
103
|
+
`plexus-models` has zero imports from any agent framework. `plexus-pi` imports it via a relative path.
|
|
92
104
|
|
|
93
|
-
##
|
|
105
|
+
## Development
|
|
94
106
|
|
|
107
|
+
After cloning, install dependencies to set up the pre-commit hook:
|
|
108
|
+
|
|
109
|
+
```sh
|
|
110
|
+
bun install
|
|
95
111
|
```
|
|
96
|
-
packages/
|
|
97
|
-
plexus-models/ # host-agnostic data layer (fetch, parse, cache, config)
|
|
98
|
-
plexus-pi/ # host adapter + extension entry point
|
|
99
|
-
```
|
|
100
112
|
|
|
101
|
-
|
|
113
|
+
The pre-commit hook (via lefthook) rebuilds `dist/extension.js` automatically whenever source files change, so the committed artifact stays in sync. After committing, reload the extension in pi with `/reload` or restart the agent.
|
|
114
|
+
|
|
115
|
+
To add support for a new host agent, see [AGENTS.md](AGENTS.md).
|
package/dist/extension.js
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
// src/extension.ts
|
|
3
|
-
import * as os from "os";
|
|
4
|
-
import * as path4 from "path";
|
|
5
|
-
|
|
6
2
|
// ../plexus-models/src/convert.ts
|
|
7
3
|
var REASONING_PARAMS = new Set(["reasoning", "include_reasoning", "reasoning_effort"]);
|
|
8
4
|
var API_DIALECT_MAP = {
|
|
@@ -175,68 +171,59 @@ async function fetchPlexusModels(apiKey, modelsUrl) {
|
|
|
175
171
|
const raw = await res.json();
|
|
176
172
|
return { models: raw.data ?? [], raw };
|
|
177
173
|
}
|
|
178
|
-
//
|
|
179
|
-
import
|
|
180
|
-
import
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
function getConfigSync(
|
|
174
|
+
// src/config.ts
|
|
175
|
+
import { existsSync, readFileSync } from "fs";
|
|
176
|
+
import { mkdir, writeFile } from "fs/promises";
|
|
177
|
+
import { join } from "path";
|
|
178
|
+
import { getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
179
|
+
var getConfigDir = () => join(getAgentDir(), "extensions", "plexus");
|
|
180
|
+
var getConfigPath = () => join(getConfigDir(), "config.json");
|
|
181
|
+
var normalizeRoot = (raw) => raw.replace(/\/+$/, "");
|
|
182
|
+
function getConfigSync() {
|
|
187
183
|
try {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
191
|
-
return parsed;
|
|
184
|
+
if (existsSync(getConfigPath())) {
|
|
185
|
+
return JSON.parse(readFileSync(getConfigPath(), "utf8"));
|
|
192
186
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
return {};
|
|
196
|
-
}
|
|
187
|
+
} catch {}
|
|
188
|
+
return {};
|
|
197
189
|
}
|
|
198
|
-
async function saveBaseUrl(
|
|
199
|
-
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
const existing = getConfigSync(agentDir);
|
|
203
|
-
const updated = {
|
|
190
|
+
async function saveBaseUrl(baseUrl, defaultModel) {
|
|
191
|
+
await mkdir(getConfigDir(), { recursive: true });
|
|
192
|
+
const existing = getConfigSync();
|
|
193
|
+
const config = {
|
|
204
194
|
...existing,
|
|
205
|
-
baseUrl: baseUrl
|
|
195
|
+
baseUrl: normalizeRoot(baseUrl),
|
|
196
|
+
...defaultModel !== undefined && { defaultModel }
|
|
206
197
|
};
|
|
207
|
-
|
|
208
|
-
updated.defaultModel = defaultModel;
|
|
209
|
-
}
|
|
210
|
-
await fs.promises.writeFile(configPath, JSON.stringify(updated, null, 2) + `
|
|
198
|
+
await writeFile(getConfigPath(), `${JSON.stringify(config, null, 2)}
|
|
211
199
|
`, "utf8");
|
|
212
200
|
}
|
|
213
|
-
function getRawBaseUrl(
|
|
214
|
-
const
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
return raw.replace(/\/+$/, "");
|
|
219
|
-
}
|
|
220
|
-
function getBaseUrl(agentDir) {
|
|
221
|
-
const raw = getRawBaseUrl(agentDir);
|
|
222
|
-
return raw ? `${raw}/v1` : null;
|
|
201
|
+
function getRawBaseUrl() {
|
|
202
|
+
const config = getConfigSync();
|
|
203
|
+
if (config.baseUrl)
|
|
204
|
+
return config.baseUrl;
|
|
205
|
+
return process.env["PLEXUS_BASE_URL"] ?? null;
|
|
223
206
|
}
|
|
224
|
-
function getModelsUrl(
|
|
225
|
-
const raw = getRawBaseUrl(
|
|
226
|
-
return raw ? `${raw}/v1/models` : null;
|
|
207
|
+
function getModelsUrl() {
|
|
208
|
+
const raw = getRawBaseUrl();
|
|
209
|
+
return raw ? `${normalizeRoot(raw)}/v1/models` : null;
|
|
227
210
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
var PLEXUS_DIR2 = "extensions/plexus";
|
|
232
|
-
var CACHE_FILE = "plexus-models-cache.json";
|
|
233
|
-
var RAW_RESPONSE_FILE = "plexus-models-response.json";
|
|
234
|
-
function getCachePath(agentDir) {
|
|
235
|
-
return path2.join(agentDir, PLEXUS_DIR2, CACHE_FILE);
|
|
211
|
+
function getBaseUrl() {
|
|
212
|
+
const raw = getRawBaseUrl();
|
|
213
|
+
return raw ? `${normalizeRoot(raw)}/v1` : null;
|
|
236
214
|
}
|
|
237
|
-
function
|
|
238
|
-
return
|
|
215
|
+
function getDefaultModel() {
|
|
216
|
+
return getConfigSync().defaultModel ?? null;
|
|
239
217
|
}
|
|
218
|
+
|
|
219
|
+
// src/cache.ts
|
|
220
|
+
import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
|
|
221
|
+
import { mkdir as mkdir2, writeFile as writeFile2 } from "fs/promises";
|
|
222
|
+
import { join as join2 } from "path";
|
|
223
|
+
import { getAgentDir as getAgentDir2 } from "@earendil-works/pi-coding-agent";
|
|
224
|
+
var getCacheDir = () => join2(getAgentDir2(), "extensions", "plexus");
|
|
225
|
+
var getModelsCachePath = () => join2(getCacheDir(), "plexus-models-cache.json");
|
|
226
|
+
var getRawResponsePath = () => join2(getCacheDir(), "plexus-models-response.json");
|
|
240
227
|
function parseCacheData(raw) {
|
|
241
228
|
try {
|
|
242
229
|
const parsed = JSON.parse(raw);
|
|
@@ -253,44 +240,45 @@ function parseCacheData(raw) {
|
|
|
253
240
|
return null;
|
|
254
241
|
}
|
|
255
242
|
}
|
|
256
|
-
function readCachedModelsSync(
|
|
243
|
+
function readCachedModelsSync() {
|
|
257
244
|
try {
|
|
258
|
-
const
|
|
259
|
-
|
|
245
|
+
const p = getModelsCachePath();
|
|
246
|
+
if (!existsSync2(p))
|
|
247
|
+
return null;
|
|
248
|
+
return parseCacheData(readFileSync2(p, "utf8"));
|
|
260
249
|
} catch {
|
|
261
250
|
return null;
|
|
262
251
|
}
|
|
263
252
|
}
|
|
264
|
-
async function writeCachedModels(
|
|
265
|
-
|
|
266
|
-
await fs2.promises.mkdir(path2.dirname(cachePath), { recursive: true });
|
|
253
|
+
async function writeCachedModels(models) {
|
|
254
|
+
await mkdir2(getCacheDir(), { recursive: true });
|
|
267
255
|
const payload = { models, timestamp: Date.now() };
|
|
268
|
-
await
|
|
256
|
+
await writeFile2(getModelsCachePath(), `${JSON.stringify(payload, null, 2)}
|
|
269
257
|
`, "utf8");
|
|
270
258
|
}
|
|
271
|
-
async function writeRawResponse(
|
|
272
|
-
|
|
273
|
-
await
|
|
274
|
-
await fs2.promises.writeFile(rawPath, JSON.stringify(data, null, 2) + `
|
|
259
|
+
async function writeRawResponse(data) {
|
|
260
|
+
await mkdir2(getCacheDir(), { recursive: true });
|
|
261
|
+
await writeFile2(getRawResponsePath(), `${JSON.stringify(data, null, 2)}
|
|
275
262
|
`, "utf8");
|
|
276
263
|
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
import
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
264
|
+
|
|
265
|
+
// src/log.ts
|
|
266
|
+
import { appendFileSync, mkdirSync } from "fs";
|
|
267
|
+
import { join as join3 } from "path";
|
|
268
|
+
import { getAgentDir as getAgentDir3 } from "@earendil-works/pi-coding-agent";
|
|
269
|
+
var getCacheDir2 = () => join3(getAgentDir3(), "extensions", "plexus");
|
|
270
|
+
var getLogPath = () => join3(getCacheDir2(), "plexus.log");
|
|
271
|
+
function log(message, data) {
|
|
283
272
|
try {
|
|
284
|
-
|
|
285
|
-
const dir = path3.dirname(logPath);
|
|
286
|
-
fs3.mkdirSync(dir, { recursive: true });
|
|
273
|
+
mkdirSync(getCacheDir2(), { recursive: true });
|
|
287
274
|
const ts = new Date().toISOString();
|
|
288
275
|
const line = data !== undefined ? `${ts} ${message} ${JSON.stringify(data)}
|
|
289
276
|
` : `${ts} ${message}
|
|
290
277
|
`;
|
|
291
|
-
|
|
278
|
+
appendFileSync(getLogPath(), line, "utf8");
|
|
292
279
|
} catch {}
|
|
293
280
|
}
|
|
281
|
+
|
|
294
282
|
// src/mapper.ts
|
|
295
283
|
function descriptorToPiModel(descriptor) {
|
|
296
284
|
const cost = {
|
|
@@ -323,106 +311,127 @@ function descriptorToPiModel(descriptor) {
|
|
|
323
311
|
|
|
324
312
|
// src/extension.ts
|
|
325
313
|
var PROVIDER_NAME = "plexus";
|
|
326
|
-
|
|
327
|
-
const override = process.env["PI_CODING_AGENT_DIR"];
|
|
328
|
-
if (override)
|
|
329
|
-
return path4.resolve(override);
|
|
330
|
-
const configDir = process.env["PI_CONFIG_DIR"] || ".pi";
|
|
331
|
-
return path4.join(os.homedir(), configDir, "agent");
|
|
332
|
-
}
|
|
333
|
-
function getApiKey() {
|
|
334
|
-
return process.env["PLEXUS_API_KEY"];
|
|
335
|
-
}
|
|
314
|
+
var currentModels = [];
|
|
336
315
|
function plexusExtension(pi) {
|
|
337
|
-
const
|
|
338
|
-
const
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
316
|
+
const cached = readCachedModelsSync();
|
|
317
|
+
const startupBaseUrl = getBaseUrl() ?? "http://localhost/v1";
|
|
318
|
+
const startupModels = cached?.models.map(descriptorToPiModel) ?? [];
|
|
319
|
+
log("startup", {
|
|
320
|
+
cachedModelCount: startupModels.length,
|
|
321
|
+
startupBaseUrl
|
|
322
|
+
});
|
|
323
|
+
pi.registerProvider(PROVIDER_NAME, {
|
|
324
|
+
api: "openai-completions",
|
|
325
|
+
apiKey: PROVIDER_NAME,
|
|
326
|
+
authHeader: true,
|
|
327
|
+
baseUrl: startupBaseUrl,
|
|
328
|
+
models: startupModels
|
|
329
|
+
});
|
|
330
|
+
currentModels = startupModels;
|
|
331
|
+
pi.on("session_start", async (_event, ctx) => {
|
|
332
|
+
const apiKey = await ctx.modelRegistry.authStorage.getApiKey(PROVIDER_NAME);
|
|
333
|
+
const baseUrl = getBaseUrl();
|
|
334
|
+
log("session_start", { hasApiKey: !!apiKey, baseUrl });
|
|
335
|
+
if (!apiKey || !baseUrl) {
|
|
336
|
+
log("session_start: no auth configured, skipping refresh");
|
|
337
|
+
await trySetDefaultModel(pi, startupModels);
|
|
338
|
+
return;
|
|
353
339
|
}
|
|
354
|
-
|
|
355
|
-
pi.on("session_start", async () => {
|
|
356
|
-
await doRefresh(pi, agentDir, null);
|
|
340
|
+
await doRefresh(pi, apiKey, ctx, true);
|
|
357
341
|
});
|
|
358
342
|
pi.registerCommand("plexus", {
|
|
359
|
-
description: "
|
|
360
|
-
|
|
343
|
+
description: "Plexus provider commands: login, refresh",
|
|
344
|
+
getArgumentCompletions: () => [
|
|
345
|
+
{ value: "login", label: "login", description: "Configure Plexus base URL and API key" },
|
|
346
|
+
{ value: "refresh", label: "refresh", description: "Refresh Plexus models from the API" }
|
|
347
|
+
],
|
|
348
|
+
handler: async (args, ctx) => {
|
|
361
349
|
const sub = args.trim().toLowerCase();
|
|
362
350
|
if (sub === "login" || sub === "") {
|
|
363
|
-
await handleLogin(pi, ctx
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
351
|
+
await handleLogin(pi, ctx);
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
if (sub === "refresh") {
|
|
355
|
+
await handleRefresh(pi, ctx);
|
|
356
|
+
return;
|
|
368
357
|
}
|
|
358
|
+
ctx.ui.notify(`Unknown sub-command: "${args}". Use: /plexus login | /plexus refresh`, "warning");
|
|
369
359
|
}
|
|
370
360
|
});
|
|
371
361
|
}
|
|
372
|
-
async function handleLogin(pi, ctx
|
|
373
|
-
if (!getApiKey()) {
|
|
374
|
-
ctx.ui.notify("PLEXUS_API_KEY env var is not set. Set it and restart omp.", "error");
|
|
375
|
-
return;
|
|
376
|
-
}
|
|
362
|
+
async function handleLogin(pi, ctx) {
|
|
377
363
|
const baseUrlInput = await ctx.ui.input("Plexus base URL", "https://plexus.example.com");
|
|
378
364
|
if (!baseUrlInput) {
|
|
379
365
|
ctx.ui.notify("Login cancelled.", "info");
|
|
380
366
|
return;
|
|
381
367
|
}
|
|
368
|
+
const apiKeyInput = await ctx.ui.input("Plexus API key");
|
|
369
|
+
if (!apiKeyInput) {
|
|
370
|
+
ctx.ui.notify("Login cancelled.", "info");
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
382
373
|
const defaultModelInput = await ctx.ui.input("Default model (optional \u2014 Enter to skip)", "");
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
await doRefresh(pi, agentDir, ctx);
|
|
374
|
+
const defaultModel = defaultModelInput?.trim() || undefined;
|
|
375
|
+
await saveBaseUrl(baseUrlInput.trim(), defaultModel);
|
|
376
|
+
ctx.modelRegistry.authStorage.set(PROVIDER_NAME, { type: "api_key", key: apiKeyInput.trim() });
|
|
377
|
+
log("login: saved", { baseUrl: baseUrlInput.trim(), defaultModel });
|
|
378
|
+
ctx.ui.notify("Plexus credentials saved. Refreshing models\u2026", "info");
|
|
379
|
+
await doRefresh(pi, apiKeyInput.trim(), ctx, false);
|
|
390
380
|
}
|
|
391
|
-
async function
|
|
392
|
-
const
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
if (!key) {
|
|
396
|
-
if (notify)
|
|
397
|
-
notify.ui.notify("PLEXUS_API_KEY env var is not set.", "error");
|
|
381
|
+
async function handleRefresh(pi, ctx) {
|
|
382
|
+
const apiKey = await ctx.modelRegistry.authStorage.getApiKey(PROVIDER_NAME);
|
|
383
|
+
if (!apiKey) {
|
|
384
|
+
ctx.ui.notify("No Plexus API key configured. Run /plexus login first.", "error");
|
|
398
385
|
return;
|
|
399
386
|
}
|
|
387
|
+
ctx.ui.notify("Refreshing Plexus models\u2026", "info");
|
|
388
|
+
await doRefresh(pi, apiKey, ctx, true);
|
|
389
|
+
}
|
|
390
|
+
async function doRefresh(pi, apiKey, ctx, setDefault) {
|
|
391
|
+
const modelsUrl = getModelsUrl();
|
|
392
|
+
const baseUrl = getBaseUrl();
|
|
400
393
|
if (!modelsUrl || !baseUrl) {
|
|
401
|
-
if (
|
|
402
|
-
|
|
394
|
+
if (ctx)
|
|
395
|
+
ctx.ui.notify("Plexus base URL not configured. Run /plexus login first.", "warning");
|
|
396
|
+
log("doRefresh: no base URL configured");
|
|
403
397
|
return;
|
|
404
398
|
}
|
|
405
399
|
try {
|
|
406
|
-
const { models:
|
|
407
|
-
const descriptors = convertDescriptors(
|
|
408
|
-
|
|
409
|
-
await
|
|
400
|
+
const { models: apiModels, raw } = await fetchPlexusModels(apiKey, modelsUrl);
|
|
401
|
+
const descriptors = convertDescriptors(apiModels, baseUrl);
|
|
402
|
+
const piModels = descriptors.map(descriptorToPiModel);
|
|
403
|
+
await Promise.all([writeCachedModels(descriptors), writeRawResponse(raw)]);
|
|
404
|
+
currentModels = piModels;
|
|
410
405
|
pi.registerProvider(PROVIDER_NAME, {
|
|
411
|
-
baseUrl,
|
|
412
|
-
apiKey: key,
|
|
413
406
|
api: "openai-completions",
|
|
407
|
+
apiKey: PROVIDER_NAME,
|
|
414
408
|
authHeader: true,
|
|
415
|
-
|
|
409
|
+
baseUrl,
|
|
410
|
+
models: piModels
|
|
416
411
|
});
|
|
417
|
-
log(
|
|
418
|
-
if (
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
412
|
+
log("doRefresh: registered", { count: piModels.length });
|
|
413
|
+
if (ctx)
|
|
414
|
+
ctx.ui.notify(`Refreshed ${piModels.length} Plexus models`, "info");
|
|
415
|
+
if (setDefault)
|
|
416
|
+
await trySetDefaultModel(pi, piModels);
|
|
417
|
+
} catch (error) {
|
|
418
|
+
log("doRefresh: failed", { error: String(error) });
|
|
419
|
+
if (ctx) {
|
|
420
|
+
ctx.ui.notify(`Refresh failed: ${error instanceof Error ? error.message : String(error)}`, "error");
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
async function trySetDefaultModel(pi, models) {
|
|
425
|
+
const defaultModelId = getDefaultModel();
|
|
426
|
+
if (!defaultModelId)
|
|
427
|
+
return;
|
|
428
|
+
const model = models.find((m) => m.id === defaultModelId);
|
|
429
|
+
if (!model) {
|
|
430
|
+
log("trySetDefaultModel: model not found", { defaultModelId });
|
|
431
|
+
return;
|
|
425
432
|
}
|
|
433
|
+
const ok = await pi.setModel(model);
|
|
434
|
+
log("trySetDefaultModel", { defaultModelId, ok });
|
|
426
435
|
}
|
|
427
436
|
export {
|
|
428
437
|
plexusExtension as default
|
package/package.json
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mcowger/pi-plexus",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Plexus AI proxy plugin for
|
|
3
|
+
"version": "0.6.0",
|
|
4
|
+
"description": "Plexus AI proxy plugin for the pi coding agent",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "./dist/extension.js",
|
|
7
6
|
"files": [
|
|
8
7
|
"dist/extension.js",
|
|
9
8
|
"package.json",
|
|
@@ -12,8 +11,6 @@
|
|
|
12
11
|
"keywords": [
|
|
13
12
|
"plexus",
|
|
14
13
|
"pi",
|
|
15
|
-
"omp",
|
|
16
|
-
"oh-my-pi",
|
|
17
14
|
"ai",
|
|
18
15
|
"coding-agent",
|
|
19
16
|
"extension",
|
|
@@ -27,8 +24,9 @@
|
|
|
27
24
|
"scripts": {
|
|
28
25
|
"build": "bun run build.ts"
|
|
29
26
|
},
|
|
30
|
-
"
|
|
31
|
-
"
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"@earendil-works/pi-ai": "*",
|
|
29
|
+
"@earendil-works/pi-coding-agent": "*"
|
|
32
30
|
},
|
|
33
31
|
"devDependencies": {
|
|
34
32
|
"@types/bun": "latest"
|