@router-for-me/pi-cliproxyapi-provider 1.2.2 → 1.3.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 +8 -8
- package/extensions/fast-footer.ts +149 -0
- package/extensions/fast.ts +6 -0
- package/extensions/index.ts +25 -41
- package/extensions/lib.ts +1 -14
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ Pi provider extension that discovers models from [CLIProxyAPI](https://github.co
|
|
|
9
9
|
3. Fetches `{root}/v1/models?client_version=pi`.
|
|
10
10
|
4. Maps the CLIProxyAPI catalog into pi models, including Fast service-tier capability.
|
|
11
11
|
5. Registers inference against `{root}/backend-api/`.
|
|
12
|
-
6. Provides `/
|
|
12
|
+
6. Provides `/fast` to toggle OpenAI priority processing for supported models.
|
|
13
13
|
7. In interactive TUI sessions, shows footer elapsed time during runs and a TPS / token usage toast when the agent settles.
|
|
14
14
|
|
|
15
15
|
## Install
|
|
@@ -150,17 +150,17 @@ pi then sends inference traffic to `{inference}/codex/responses`.
|
|
|
150
150
|
|
|
151
151
|
OpenAI Fast mode requests the priority service tier. It can reduce latency for supported models, but consumes more OpenAI/Codex credits or incurs priority-processing pricing.
|
|
152
152
|
|
|
153
|
-
Fast is **off by default**.
|
|
153
|
+
Fast is **off by default**. Toggle it for the current pi session with:
|
|
154
154
|
|
|
155
155
|
```text
|
|
156
|
-
/
|
|
157
|
-
/cpa-fast off
|
|
158
|
-
/cpa-fast status
|
|
156
|
+
/fast
|
|
159
157
|
```
|
|
160
158
|
|
|
161
|
-
The
|
|
159
|
+
Each invocation switches Fast between on and off. The setting is stored with the current pi session and restored when that session is resumed; it does not change the global default. To choose the default for new sessions, set `"fast": true` in `cliproxyapi.json` or set `CLIPROXYAPI_FAST=true`.
|
|
162
160
|
|
|
163
|
-
Fast
|
|
161
|
+
When Fast is effective, pi's model status appends a yellow lowercase `fast`, for example `gpt-5.6-sol • xhigh • fast`. When Fast is off, the original model status remains unchanged. Supported models do not produce a separate status notification; selecting an unsupported model and running `/fast` shows `This model does not support Fast mode.`
|
|
162
|
+
|
|
163
|
+
Fast capability is catalog-driven: the plugin considers a CLIProxyAPI model Fast-capable when its `service_tiers` field is a non-empty array. The `additional_speed_tiers` field is ignored. For supported models, Fast injects `service_tier: "priority"`; unsupported models are left unchanged. Fast is independent from pi's reasoning/thinking level.
|
|
164
164
|
|
|
165
165
|
## Model mapping
|
|
166
166
|
|
|
@@ -206,4 +206,4 @@ Disable just this helper via `pi config` if you only want the CLIProxyAPI provid
|
|
|
206
206
|
- HTTP 200 (including empty catalog) → credentials are persisted; setup commands hidden
|
|
207
207
|
- non-200 / network / invalid baseUrl → nothing is persisted; re-enter baseUrl + API key
|
|
208
208
|
- If CPA returns HTTP 200 with zero usable models: login still succeeds; re-run setup later after models become available.
|
|
209
|
-
- If
|
|
209
|
+
- If the selected model does not provide a non-empty `service_tiers` array: the request is left unchanged and `/fast` reports `This model does not support Fast mode.`
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { type ExtensionAPI, type ExtensionContext, FooterComponent } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import type { FastModeController } from "./fast.ts";
|
|
3
|
+
|
|
4
|
+
const FAST_FOOTER_PATCH = Symbol.for("@router-for-me/pi-cliproxyapi-provider/fast-footer-patch");
|
|
5
|
+
const FAST_REFRESH_STATUS_KEY = "cliproxyapi-fast-refresh";
|
|
6
|
+
|
|
7
|
+
interface MutableModel {
|
|
8
|
+
id: string;
|
|
9
|
+
provider: string;
|
|
10
|
+
reasoning: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface FooterSessionLike {
|
|
14
|
+
state: {
|
|
15
|
+
model?: MutableModel;
|
|
16
|
+
thinkingLevel?: string;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface FooterComponentLike {
|
|
21
|
+
session?: FooterSessionLike;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface FooterPatchState {
|
|
25
|
+
controllers: Set<FastFooterController>;
|
|
26
|
+
originalRender: FooterComponent["render"];
|
|
27
|
+
patchedRender: FooterComponent["render"];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
type PatchableFooterPrototype = FooterComponent & {
|
|
31
|
+
[FAST_FOOTER_PATCH]?: FooterPatchState;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export function formatFastModelStatus(
|
|
35
|
+
modelName: string,
|
|
36
|
+
supportsReasoning: boolean,
|
|
37
|
+
thinkingLevel: string,
|
|
38
|
+
fastEnabled: boolean,
|
|
39
|
+
fastLabel = "fast",
|
|
40
|
+
): string {
|
|
41
|
+
let status = modelName;
|
|
42
|
+
if (supportsReasoning) {
|
|
43
|
+
status += thinkingLevel === "off" ? " • thinking off" : ` • ${thinkingLevel}`;
|
|
44
|
+
}
|
|
45
|
+
if (fastEnabled) {
|
|
46
|
+
status += ` • ${fastLabel}`;
|
|
47
|
+
}
|
|
48
|
+
return status;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function installFooterPatch(controller: FastFooterController): void {
|
|
52
|
+
const prototype = FooterComponent.prototype as PatchableFooterPrototype;
|
|
53
|
+
let patchState = prototype[FAST_FOOTER_PATCH];
|
|
54
|
+
if (!patchState) {
|
|
55
|
+
const originalRender = prototype.render;
|
|
56
|
+
patchState = {
|
|
57
|
+
controllers: new Set(),
|
|
58
|
+
originalRender,
|
|
59
|
+
patchedRender(this: FooterComponent, width: number): string[] {
|
|
60
|
+
const session = (this as unknown as FooterComponentLike).session;
|
|
61
|
+
const model = session?.state.model;
|
|
62
|
+
let activeController: FastFooterController | undefined;
|
|
63
|
+
if (model) {
|
|
64
|
+
for (const candidate of patchState?.controllers ?? []) {
|
|
65
|
+
if (candidate.isEffectiveFor(model)) {
|
|
66
|
+
activeController = candidate;
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (!model || !activeController) {
|
|
72
|
+
return originalRender.call(this, width);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const originalId = model.id;
|
|
76
|
+
const originalReasoning = model.reasoning;
|
|
77
|
+
model.id = activeController.formatModelStatus(
|
|
78
|
+
originalId,
|
|
79
|
+
originalReasoning,
|
|
80
|
+
session?.state.thinkingLevel ?? "off",
|
|
81
|
+
);
|
|
82
|
+
model.reasoning = false;
|
|
83
|
+
try {
|
|
84
|
+
return originalRender.call(this, width);
|
|
85
|
+
} finally {
|
|
86
|
+
model.id = originalId;
|
|
87
|
+
model.reasoning = originalReasoning;
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
prototype[FAST_FOOTER_PATCH] = patchState;
|
|
92
|
+
prototype.render = patchState.patchedRender;
|
|
93
|
+
}
|
|
94
|
+
patchState.controllers.add(controller);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function removeFooterPatch(controller: FastFooterController): void {
|
|
98
|
+
const prototype = FooterComponent.prototype as PatchableFooterPrototype;
|
|
99
|
+
const patchState = prototype[FAST_FOOTER_PATCH];
|
|
100
|
+
if (!patchState) return;
|
|
101
|
+
|
|
102
|
+
patchState.controllers.delete(controller);
|
|
103
|
+
if (patchState.controllers.size > 0) return;
|
|
104
|
+
if (prototype.render === patchState.patchedRender) {
|
|
105
|
+
prototype.render = patchState.originalRender;
|
|
106
|
+
}
|
|
107
|
+
delete prototype[FAST_FOOTER_PATCH];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Adds Fast to pi's built-in model status without replacing the footer. */
|
|
111
|
+
export class FastFooterController {
|
|
112
|
+
private activeContext: ExtensionContext | undefined;
|
|
113
|
+
private patchInstalled = false;
|
|
114
|
+
|
|
115
|
+
constructor(
|
|
116
|
+
private readonly providerId: string,
|
|
117
|
+
private readonly fastMode: FastModeController,
|
|
118
|
+
) {}
|
|
119
|
+
|
|
120
|
+
register(pi: ExtensionAPI): void {
|
|
121
|
+
pi.on("session_start", (_event, ctx) => {
|
|
122
|
+
if (ctx.mode !== "tui") return;
|
|
123
|
+
this.activeContext = ctx;
|
|
124
|
+
if (this.patchInstalled) return;
|
|
125
|
+
installFooterPatch(this);
|
|
126
|
+
this.patchInstalled = true;
|
|
127
|
+
});
|
|
128
|
+
pi.on("session_shutdown", () => {
|
|
129
|
+
this.activeContext = undefined;
|
|
130
|
+
if (!this.patchInstalled) return;
|
|
131
|
+
removeFooterPatch(this);
|
|
132
|
+
this.patchInstalled = false;
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
formatModelStatus(modelName: string, supportsReasoning: boolean, thinkingLevel: string): string {
|
|
137
|
+
const fastLabel = this.activeContext?.ui.theme.fg("warning", "fast") ?? "fast";
|
|
138
|
+
return formatFastModelStatus(modelName, supportsReasoning, thinkingLevel, true, fastLabel);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
isEffectiveFor(model: MutableModel): boolean {
|
|
142
|
+
return model.provider === this.providerId && this.fastMode.isEffectiveFor(model.id);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
refresh(ctx: ExtensionContext): void {
|
|
146
|
+
if (ctx.mode !== "tui") return;
|
|
147
|
+
ctx.ui.setStatus(FAST_REFRESH_STATUS_KEY, undefined);
|
|
148
|
+
}
|
|
149
|
+
}
|
package/extensions/fast.ts
CHANGED
|
@@ -19,6 +19,12 @@ export class FastModeController {
|
|
|
19
19
|
this.sessionOverride = enabled;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
toggleSessionEnabled(): boolean {
|
|
23
|
+
const enabled = !this.isEnabled();
|
|
24
|
+
this.setSessionEnabled(enabled);
|
|
25
|
+
return enabled;
|
|
26
|
+
}
|
|
27
|
+
|
|
22
28
|
clearSessionOverride(): void {
|
|
23
29
|
this.sessionOverride = undefined;
|
|
24
30
|
}
|
package/extensions/index.ts
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* (HTTP 200 = success even if the catalog is empty; otherwise re-prompt).
|
|
12
12
|
* 5. On success, models/credentials are saved and `/cliproxyapi` `/cpa` are hidden.
|
|
13
13
|
* 6. Setup commands reappear after `/logout` or when a models request returns HTTP 401.
|
|
14
|
-
* 7. `/
|
|
14
|
+
* 7. `/fast` controls catalog-driven priority service tier injection per session.
|
|
15
15
|
*
|
|
16
16
|
* Uses a patched openai-codex-responses implementation that does not require
|
|
17
17
|
* extracting chatgpt_account_id from the API key (plain CPA keys work).
|
|
@@ -20,9 +20,15 @@
|
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
22
|
import type { Api, Model, OAuthCredentials, OAuthLoginCallbacks } from "@earendil-works/pi-ai";
|
|
23
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
type ExtensionAPI,
|
|
25
|
+
type ExtensionCommandContext,
|
|
26
|
+
type ExtensionContext,
|
|
27
|
+
getAgentDir,
|
|
28
|
+
} from "@earendil-works/pi-coding-agent";
|
|
24
29
|
import { CLIPROXYAPI_CODEX_API, type CliproxyCodexStreamSimple, loadCliproxyCodexStreams } from "./codex-stream.ts";
|
|
25
30
|
import { FAST_MODE_ENTRY_TYPE, FastModeController, restoreFastModeFromEntries } from "./fast.ts";
|
|
31
|
+
import { FastFooterController } from "./fast-footer.ts";
|
|
26
32
|
import {
|
|
27
33
|
CONFIG_FILE_NAME,
|
|
28
34
|
CREDENTIAL_TTL_MS,
|
|
@@ -555,63 +561,39 @@ function createSetupCommandsController(options: {
|
|
|
555
561
|
return setupCommands;
|
|
556
562
|
}
|
|
557
563
|
|
|
558
|
-
function registerFastCommand(options: {
|
|
564
|
+
export function registerFastCommand(options: {
|
|
559
565
|
pi: ExtensionAPI;
|
|
560
566
|
providerId: string;
|
|
561
|
-
providerName: string;
|
|
562
567
|
fastMode: FastModeController;
|
|
568
|
+
onStatusChange?: (ctx: ExtensionContext) => void;
|
|
563
569
|
}): void {
|
|
564
|
-
const { pi, providerId,
|
|
565
|
-
const actions = ["on", "off", "status"] as const;
|
|
570
|
+
const { pi, providerId, fastMode, onStatusChange } = options;
|
|
566
571
|
|
|
567
572
|
pi.on("session_start", (_event, ctx) => {
|
|
568
573
|
restoreFastModeFromEntries(fastMode, ctx.sessionManager.getBranch());
|
|
569
574
|
});
|
|
570
575
|
pi.on("session_tree", (_event, ctx) => {
|
|
571
576
|
restoreFastModeFromEntries(fastMode, ctx.sessionManager.getBranch());
|
|
577
|
+
onStatusChange?.(ctx);
|
|
572
578
|
});
|
|
573
579
|
|
|
574
|
-
pi.registerCommand("
|
|
575
|
-
description: "
|
|
576
|
-
getArgumentCompletions: (prefix) => {
|
|
577
|
-
const normalizedPrefix = prefix.trim().toLowerCase();
|
|
578
|
-
const matches = actions.filter((action) => action.startsWith(normalizedPrefix));
|
|
579
|
-
return matches.length > 0 ? matches.map((action) => ({ value: action, label: action })) : null;
|
|
580
|
-
},
|
|
580
|
+
pi.registerCommand("fast", {
|
|
581
|
+
description: "Toggle CLIProxyAPI Fast mode for this session.",
|
|
581
582
|
handler: async (args, ctx) => {
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
ctx.ui.notify("Usage: /cpa-fast on|off|status", "error");
|
|
583
|
+
if (args.trim()) {
|
|
584
|
+
ctx.ui.notify("Usage: /fast", "error");
|
|
585
585
|
return;
|
|
586
586
|
}
|
|
587
587
|
|
|
588
|
-
if (action === "on" || action === "off") {
|
|
589
|
-
const enabled = action === "on";
|
|
590
|
-
fastMode.setSessionEnabled(enabled);
|
|
591
|
-
pi.appendEntry(FAST_MODE_ENTRY_TYPE, { enabled });
|
|
592
|
-
logInfo(`Fast session override ${enabled ? "enabled" : "disabled"}`);
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
const enabled = fastMode.isEnabled();
|
|
596
|
-
const source = fastMode.getSource() === "session-override" ? "session override" : "configured default";
|
|
597
588
|
const currentModel = ctx.model;
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
if (!currentModel) {
|
|
602
|
-
detail = "No model is currently selected.";
|
|
603
|
-
} else if (currentModel.provider !== providerId) {
|
|
604
|
-
detail = `Current model ${currentModel.provider}/${currentModel.id} is not provided by ${providerName}.`;
|
|
605
|
-
} else if (!fastMode.isModelSupported(currentModel.id)) {
|
|
606
|
-
detail = `Current model ${providerId}/${currentModel.id} does not advertise Fast; requests remain unchanged.`;
|
|
607
|
-
if (enabled) severity = "warning";
|
|
608
|
-
} else if (enabled) {
|
|
609
|
-
detail = `Current model ${providerId}/${currentModel.id} will request service_tier=priority.`;
|
|
610
|
-
} else {
|
|
611
|
-
detail = `Current model ${providerId}/${currentModel.id} supports Fast; priority injection is off.`;
|
|
589
|
+
if (!currentModel || currentModel.provider !== providerId || !fastMode.isModelSupported(currentModel.id)) {
|
|
590
|
+
ctx.ui.notify("This model does not support Fast mode.", "warning");
|
|
591
|
+
return;
|
|
612
592
|
}
|
|
613
593
|
|
|
614
|
-
|
|
594
|
+
const enabled = fastMode.toggleSessionEnabled();
|
|
595
|
+
pi.appendEntry(FAST_MODE_ENTRY_TYPE, { enabled });
|
|
596
|
+
onStatusChange?.(ctx);
|
|
615
597
|
},
|
|
616
598
|
});
|
|
617
599
|
}
|
|
@@ -645,12 +627,14 @@ export default async function (pi: ExtensionAPI): Promise<void> {
|
|
|
645
627
|
return;
|
|
646
628
|
}
|
|
647
629
|
|
|
630
|
+
const fastFooter = new FastFooterController(identity.providerId, fastMode);
|
|
648
631
|
registerFastCommand({
|
|
649
632
|
pi,
|
|
650
633
|
providerId: identity.providerId,
|
|
651
|
-
providerName: identity.providerName,
|
|
652
634
|
fastMode,
|
|
635
|
+
onStatusChange: (ctx) => fastFooter.refresh(ctx),
|
|
653
636
|
});
|
|
637
|
+
fastFooter.register(pi);
|
|
654
638
|
|
|
655
639
|
const setupCommands = createSetupCommandsController({
|
|
656
640
|
pi,
|
package/extensions/lib.ts
CHANGED
|
@@ -370,20 +370,7 @@ export function codexModelId(model: CodexClientModel): string {
|
|
|
370
370
|
}
|
|
371
371
|
|
|
372
372
|
export function supportsFastServiceTier(model: CodexClientModel): boolean {
|
|
373
|
-
|
|
374
|
-
for (const tier of serviceTiers) {
|
|
375
|
-
const id =
|
|
376
|
-
typeof tier === "string"
|
|
377
|
-
? tier
|
|
378
|
-
: tier && typeof tier === "object" && typeof tier.id === "string"
|
|
379
|
-
? tier.id
|
|
380
|
-
: undefined;
|
|
381
|
-
if (id?.trim().toLowerCase() === "priority") {
|
|
382
|
-
return true;
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
const speedTiers = Array.isArray(model.additional_speed_tiers) ? model.additional_speed_tiers : [];
|
|
386
|
-
return speedTiers.some((tier) => typeof tier === "string" && tier.trim().toLowerCase() === "fast");
|
|
373
|
+
return Array.isArray(model.service_tiers) && model.service_tiers.length > 0;
|
|
387
374
|
}
|
|
388
375
|
|
|
389
376
|
export function toPiModel(model: CodexClientModel): PiProviderModel | null {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@router-for-me/pi-cliproxyapi-provider",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Pi provider extension that auto-registers CLIProxyAPI models, plus TUI elapsed/TPS status",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"access": "public"
|
|
23
23
|
},
|
|
24
24
|
"engines": {
|
|
25
|
-
"node": ">=
|
|
25
|
+
"node": ">=22.19.0"
|
|
26
26
|
},
|
|
27
27
|
"scripts": {
|
|
28
28
|
"test": "vitest run",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"@earendil-works/pi-ai": "*",
|
|
42
|
-
"@earendil-works/pi-coding-agent": "
|
|
42
|
+
"@earendil-works/pi-coding-agent": ">=0.80.6 <0.81.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@biomejs/biome": "2.5.3",
|