@vtstech/pi-api 1.2.0 → 1.2.2
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/api.js +46 -46
- package/package.json +3 -3
package/api.js
CHANGED
|
@@ -73,16 +73,16 @@ function api_temp_default(pi) {
|
|
|
73
73
|
].join("\n");
|
|
74
74
|
pi.registerCommand("api", {
|
|
75
75
|
description: "View and switch API modes, base URLs, thinking, and compat flags",
|
|
76
|
-
handler: async (args,
|
|
76
|
+
handler: async (args, ctx) => {
|
|
77
77
|
const parts = args.trim().split(/\s+/);
|
|
78
78
|
const sub = parts[0]?.toLowerCase() || "";
|
|
79
79
|
const rest = parts.slice(1).join(" ");
|
|
80
80
|
const config = readModelsJson();
|
|
81
81
|
if (sub !== "provider" && sub !== "providers") {
|
|
82
|
-
const currentProvider = getCurrentSessionProvider(
|
|
82
|
+
const currentProvider = getCurrentSessionProvider(ctx);
|
|
83
83
|
const provider = resolveProvider(config, void 0, currentProvider);
|
|
84
84
|
if (!provider) {
|
|
85
|
-
|
|
85
|
+
ctx.ui.notify("No providers found in models.json", "error");
|
|
86
86
|
return;
|
|
87
87
|
}
|
|
88
88
|
switch (sub) {
|
|
@@ -90,23 +90,23 @@ function api_temp_default(pi) {
|
|
|
90
90
|
case "show":
|
|
91
91
|
return showConfig(provider, currentProvider);
|
|
92
92
|
case "mode":
|
|
93
|
-
return setMode(
|
|
93
|
+
return setMode(ctx, provider.name, rest);
|
|
94
94
|
case "url":
|
|
95
|
-
return setUrl(
|
|
95
|
+
return setUrl(ctx, provider.name, rest);
|
|
96
96
|
case "think":
|
|
97
|
-
return setThink(
|
|
97
|
+
return setThink(ctx, provider.name, rest);
|
|
98
98
|
case "compat":
|
|
99
|
-
return handleCompat(
|
|
99
|
+
return handleCompat(ctx, provider.name, rest);
|
|
100
100
|
case "reload":
|
|
101
|
-
return reloadConfig(
|
|
101
|
+
return reloadConfig(ctx);
|
|
102
102
|
case "modes":
|
|
103
|
-
return listModes();
|
|
103
|
+
return listModes(ctx);
|
|
104
104
|
default:
|
|
105
|
-
|
|
105
|
+
ctx.ui.notify(`Unknown sub-command: "${sub}". Use: mode, url, think, compat, reload, modes, provider, providers`, "error");
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
if (sub === "provider" || sub === "providers") {
|
|
109
|
-
return handleProvider(
|
|
109
|
+
return handleProvider(ctx, config, rest);
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
112
|
});
|
|
@@ -144,9 +144,9 @@ function api_temp_default(pi) {
|
|
|
144
144
|
display: { type: "content", content: lines.join("\n") }
|
|
145
145
|
});
|
|
146
146
|
}
|
|
147
|
-
async function setMode(
|
|
147
|
+
async function setMode(ctx, providerName, mode) {
|
|
148
148
|
if (!mode) {
|
|
149
|
-
|
|
149
|
+
ctx.ui.notify("Usage: /api mode <mode>. Use /api modes to list available modes.", "error");
|
|
150
150
|
return;
|
|
151
151
|
}
|
|
152
152
|
const modeLower = mode.toLowerCase();
|
|
@@ -155,7 +155,7 @@ function api_temp_default(pi) {
|
|
|
155
155
|
matched = Object.keys(API_MODES).find((m) => m.includes(modeLower));
|
|
156
156
|
}
|
|
157
157
|
if (!matched) {
|
|
158
|
-
|
|
158
|
+
ctx.ui.notify(`Unknown API mode: "${mode}". Use /api modes to list available modes.`, "error");
|
|
159
159
|
return;
|
|
160
160
|
}
|
|
161
161
|
let oldMode = "(not set)";
|
|
@@ -167,7 +167,7 @@ function api_temp_default(pi) {
|
|
|
167
167
|
return config;
|
|
168
168
|
});
|
|
169
169
|
if (!written) {
|
|
170
|
-
|
|
170
|
+
ctx.ui.notify(`Provider "${providerName}" not found in models.json`, "error");
|
|
171
171
|
return;
|
|
172
172
|
}
|
|
173
173
|
const lines = [branding];
|
|
@@ -182,11 +182,11 @@ function api_temp_default(pi) {
|
|
|
182
182
|
content: lines.join("\n"),
|
|
183
183
|
display: { type: "content", content: lines.join("\n") }
|
|
184
184
|
});
|
|
185
|
-
|
|
185
|
+
ctx.ui.notify(`API mode set to ${matched}`, "success");
|
|
186
186
|
}
|
|
187
|
-
async function setUrl(
|
|
187
|
+
async function setUrl(ctx, providerName, url) {
|
|
188
188
|
if (!url) {
|
|
189
|
-
|
|
189
|
+
ctx.ui.notify("Usage: /api url <base-url>", "error");
|
|
190
190
|
return;
|
|
191
191
|
}
|
|
192
192
|
let normalizedUrl = url.trim();
|
|
@@ -196,7 +196,7 @@ function api_temp_default(pi) {
|
|
|
196
196
|
try {
|
|
197
197
|
new URL(normalizedUrl);
|
|
198
198
|
} catch {
|
|
199
|
-
|
|
199
|
+
ctx.ui.notify(`Invalid URL: "${url}"`, "error");
|
|
200
200
|
return;
|
|
201
201
|
}
|
|
202
202
|
let oldUrl = "(not set)";
|
|
@@ -212,7 +212,7 @@ function api_temp_default(pi) {
|
|
|
212
212
|
return config;
|
|
213
213
|
});
|
|
214
214
|
if (!written) {
|
|
215
|
-
|
|
215
|
+
ctx.ui.notify(`Provider "${providerName}" not found in models.json`, "error");
|
|
216
216
|
return;
|
|
217
217
|
}
|
|
218
218
|
const lines = [branding];
|
|
@@ -226,11 +226,11 @@ function api_temp_default(pi) {
|
|
|
226
226
|
content: lines.join("\n"),
|
|
227
227
|
display: { type: "content", content: lines.join("\n") }
|
|
228
228
|
});
|
|
229
|
-
|
|
229
|
+
ctx.ui.notify(`Base URL set to ${normalizedUrl}`, "success");
|
|
230
230
|
}
|
|
231
|
-
async function setThink(
|
|
231
|
+
async function setThink(ctx, providerName, value) {
|
|
232
232
|
if (!value) {
|
|
233
|
-
|
|
233
|
+
ctx.ui.notify("Usage: /api think <on|off|auto>", "error");
|
|
234
234
|
return;
|
|
235
235
|
}
|
|
236
236
|
const valLower = value.toLowerCase();
|
|
@@ -262,11 +262,11 @@ function api_temp_default(pi) {
|
|
|
262
262
|
return config;
|
|
263
263
|
});
|
|
264
264
|
if (!written) {
|
|
265
|
-
|
|
265
|
+
ctx.ui.notify(`Provider "${providerName}" not found in models.json`, "error");
|
|
266
266
|
return;
|
|
267
267
|
}
|
|
268
268
|
if (models.length === 0) {
|
|
269
|
-
|
|
269
|
+
ctx.ui.notify(`No models found in provider "${providerName}"`, "error");
|
|
270
270
|
return;
|
|
271
271
|
}
|
|
272
272
|
const lines = [branding];
|
|
@@ -283,16 +283,16 @@ function api_temp_default(pi) {
|
|
|
283
283
|
content: lines.join("\n"),
|
|
284
284
|
display: { type: "content", content: lines.join("\n") }
|
|
285
285
|
});
|
|
286
|
-
|
|
286
|
+
ctx.ui.notify(`Thinking set to ${valLower} for ${models.length} model(s)`, "success");
|
|
287
287
|
}
|
|
288
|
-
async function handleCompat(
|
|
288
|
+
async function handleCompat(ctx, providerName, args) {
|
|
289
289
|
const parts = args.split(/\s+/);
|
|
290
290
|
const key = parts[0];
|
|
291
291
|
const value = parts.slice(1).join(" ");
|
|
292
292
|
if (!key) {
|
|
293
293
|
const provider = findProvider(providerName);
|
|
294
294
|
if (!provider) {
|
|
295
|
-
|
|
295
|
+
ctx.ui.notify(`Provider "${providerName}" not found`, "error");
|
|
296
296
|
return;
|
|
297
297
|
}
|
|
298
298
|
const compat = provider.compat || {};
|
|
@@ -321,11 +321,11 @@ function api_temp_default(pi) {
|
|
|
321
321
|
if (!value) {
|
|
322
322
|
const provider = findProvider(providerName);
|
|
323
323
|
if (!provider) {
|
|
324
|
-
|
|
324
|
+
ctx.ui.notify(`Provider "${providerName}" not found`, "error");
|
|
325
325
|
return;
|
|
326
326
|
}
|
|
327
327
|
const current = provider.compat?.[key];
|
|
328
|
-
|
|
328
|
+
ctx.ui.notify(`${key} = ${current !== void 0 ? JSON.stringify(current) : "(not set)"}`, "info");
|
|
329
329
|
return;
|
|
330
330
|
}
|
|
331
331
|
let parsedValue = value;
|
|
@@ -348,7 +348,7 @@ function api_temp_default(pi) {
|
|
|
348
348
|
return config;
|
|
349
349
|
});
|
|
350
350
|
if (!written) {
|
|
351
|
-
|
|
351
|
+
ctx.ui.notify(`Provider "${providerName}" not found`, "error");
|
|
352
352
|
return;
|
|
353
353
|
}
|
|
354
354
|
const lines = [branding];
|
|
@@ -363,9 +363,9 @@ function api_temp_default(pi) {
|
|
|
363
363
|
content: lines.join("\n"),
|
|
364
364
|
display: { type: "content", content: lines.join("\n") }
|
|
365
365
|
});
|
|
366
|
-
|
|
366
|
+
ctx.ui.notify(`Compat flag ${key} set to ${JSON.stringify(parsedValue)}`, "success");
|
|
367
367
|
}
|
|
368
|
-
function reloadConfig(
|
|
368
|
+
function reloadConfig(ctx) {
|
|
369
369
|
const lines = [branding];
|
|
370
370
|
lines.push(section("RELOAD"));
|
|
371
371
|
lines.push(ok("models.json has been modified"));
|
|
@@ -377,9 +377,9 @@ function api_temp_default(pi) {
|
|
|
377
377
|
content: lines.join("\n"),
|
|
378
378
|
display: { type: "content", content: lines.join("\n") }
|
|
379
379
|
});
|
|
380
|
-
|
|
380
|
+
ctx.ui.notify("Run /reload to apply models.json changes", "info");
|
|
381
381
|
}
|
|
382
|
-
function listModes() {
|
|
382
|
+
function listModes(ctx) {
|
|
383
383
|
const lines = [branding];
|
|
384
384
|
lines.push(section("SUPPORTED API MODES"));
|
|
385
385
|
const config = readModelsJson();
|
|
@@ -399,7 +399,7 @@ function api_temp_default(pi) {
|
|
|
399
399
|
display: { type: "content", content: lines.join("\n") }
|
|
400
400
|
});
|
|
401
401
|
}
|
|
402
|
-
function handleProvider(
|
|
402
|
+
function handleProvider(ctx, config, arg) {
|
|
403
403
|
const parts = arg.trim().split(/\s+/);
|
|
404
404
|
const sub = parts[0]?.toLowerCase() || "";
|
|
405
405
|
const rest = parts.slice(1).join(" ");
|
|
@@ -483,13 +483,13 @@ function api_temp_default(pi) {
|
|
|
483
483
|
content: lines2.join("\n"),
|
|
484
484
|
display: { type: "content", content: lines2.join("\n") }
|
|
485
485
|
});
|
|
486
|
-
|
|
486
|
+
ctx.ui.notify("Specify a provider name: /api provider set <name>", "info");
|
|
487
487
|
return;
|
|
488
488
|
}
|
|
489
489
|
const isBuiltin = targetName in BUILTIN_PROVIDERS;
|
|
490
490
|
if (!config.providers[targetName] && !isBuiltin) {
|
|
491
491
|
const allNames = [...providerNames, ...Object.keys(BUILTIN_PROVIDERS).filter((n) => !providerNames.includes(n))];
|
|
492
|
-
|
|
492
|
+
ctx.ui.notify(`Provider "${targetName}" not found. Available: ${allNames.join(", ")}`, "error");
|
|
493
493
|
return;
|
|
494
494
|
}
|
|
495
495
|
const settings = readSettings();
|
|
@@ -521,20 +521,20 @@ function api_temp_default(pi) {
|
|
|
521
521
|
content: lines.join("\n"),
|
|
522
522
|
display: { type: "content", content: lines.join("\n") }
|
|
523
523
|
});
|
|
524
|
-
|
|
524
|
+
ctx.ui.notify(`Default provider set to ${targetName}`, "success");
|
|
525
525
|
return;
|
|
526
526
|
}
|
|
527
527
|
if (providerNames.includes(sub) || sub in BUILTIN_PROVIDERS) {
|
|
528
|
-
return handleProvider(
|
|
528
|
+
return handleProvider(ctx, config, `set ${sub}`);
|
|
529
529
|
}
|
|
530
|
-
|
|
530
|
+
ctx.ui.notify(`Unknown sub-command: "${sub}". Use: show, set, list, or a provider name`, "error");
|
|
531
531
|
}
|
|
532
|
-
function getCurrentSessionProvider(
|
|
533
|
-
if (
|
|
534
|
-
return
|
|
532
|
+
function getCurrentSessionProvider(ctx) {
|
|
533
|
+
if (ctx.session?.state?.provider) {
|
|
534
|
+
return ctx.session.state.provider;
|
|
535
535
|
}
|
|
536
|
-
if (
|
|
537
|
-
return
|
|
536
|
+
if (ctx.state?.provider) {
|
|
537
|
+
return ctx.state.provider;
|
|
538
538
|
}
|
|
539
539
|
try {
|
|
540
540
|
const settings = readSettings();
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vtstech/pi-api",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"description": "API Mode Switcher extension for Pi Coding Agent",
|
|
5
5
|
"main": "api.js",
|
|
6
|
-
"keywords": ["pi-extensions"],
|
|
6
|
+
"keywords": ["pi-package", "pi", "pi-coding-agent", "pi-extensions"],
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"access": "public",
|
|
9
9
|
"type": "module",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"url": "https://github.com/VTSTech/pi-coding-agent"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@vtstech/pi-shared": "1.2.
|
|
17
|
+
"@vtstech/pi-shared": "1.2.2"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
20
|
"@mariozechner/pi-coding-agent": ">=0.66"
|