@router-for-me/pi-cliproxyapi-provider 1.4.26 → 1.5.1
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 +17 -17
- package/extensions/codex-stream.ts +20 -18
- package/extensions/fast-footer.ts +21 -25
- package/extensions/fast.ts +15 -7
- package/extensions/index.ts +88 -78
- package/extensions/lib.ts +15 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
# pi-cliproxyapi-provider
|
|
2
2
|
|
|
3
|
-
Pi provider extension that discovers models from [CLIProxyAPI](https://github.com/router-for-me/CLIProxyAPI) and registers them for use in pi. It supports catalog-driven
|
|
3
|
+
Pi provider extension that discovers models from [CLIProxyAPI](https://github.com/router-for-me/CLIProxyAPI) and registers them for use in pi. It supports catalog-driven Fast and Ultra Fast modes and also ships a small TUI helper that shows elapsed runtime and a TPS summary after each agent turn.
|
|
4
4
|
|
|
5
5
|
## What it does
|
|
6
6
|
|
|
7
7
|
1. Registers a provider that always appears in `/login` (account sign-in path).
|
|
8
8
|
2. Interactive setup collects `baseUrl` + `apiKey` via `/login CLIProxyAPI` or `/login cliproxyapi`.
|
|
9
9
|
3. Fetches `{root}/v1/models?client_version=pi`.
|
|
10
|
-
4. Maps the CLIProxyAPI catalog into pi models, including
|
|
10
|
+
4. Maps the CLIProxyAPI catalog into pi models, including support for faster service tiers.
|
|
11
11
|
5. Registers inference against `{root}/backend-api/`.
|
|
12
|
-
6. Provides `/fast` to
|
|
12
|
+
6. Provides `/fast` and `/ultrafast` to select faster service tiers for supported models.
|
|
13
13
|
7. Caches the model catalog in `~/.pi/agent/cliproxyapi-models.json`, refreshes it in the background on startup, and provides `/cliproxyapi-refresh` to force a refresh.
|
|
14
14
|
8. In interactive TUI sessions, shows footer elapsed time during runs and a TPS / token usage toast when the agent settles.
|
|
15
15
|
9. After compaction, closes the reused Codex WebSocket for that session so CLIProxyAPI's server-side context resets with the compacted client messages.
|
|
@@ -98,7 +98,7 @@ Optional fields:
|
|
|
98
98
|
| `apiKey` | _(required unless set via /login or env)_ | Bearer token / CPA API key |
|
|
99
99
|
| `providerId` | `cliproxyapi` | Provider id shown in `/model` |
|
|
100
100
|
| `providerName` | `CLIProxyAPI` | Display name in `/login` and UI |
|
|
101
|
-
| `fast` | `false` | Persisted
|
|
101
|
+
| `fast` | `false` | Persisted speed preference: `false` (off), `true` (Fast), or `"ultrafast"` (Ultra Fast) |
|
|
102
102
|
| `pause` | `false` | Persisted request-pause preference; provider requests wait until it is cleared |
|
|
103
103
|
|
|
104
104
|
### Environment overrides
|
|
@@ -118,7 +118,7 @@ Resolution order for connection settings:
|
|
|
118
118
|
3. `/login` credentials in `auth.json`
|
|
119
119
|
4. Default baseUrl `http://127.0.0.1:8317`
|
|
120
120
|
|
|
121
|
-
|
|
121
|
+
At startup, `CLIPROXYAPI_FAST` overrides the persisted speed preference: a true value selects Fast, and a false value turns both modes off. The variable does not accept `ultrafast`. If unset, the provider uses `fast` from `cliproxyapi.json`, or defaults to off.
|
|
122
122
|
|
|
123
123
|
### baseUrl normalization
|
|
124
124
|
|
|
@@ -133,21 +133,20 @@ Preferred form is **host:port only**:
|
|
|
133
133
|
|
|
134
134
|
pi then sends inference traffic to `{inference}/codex/responses`.
|
|
135
135
|
|
|
136
|
-
## Fast
|
|
136
|
+
## Fast and Ultra Fast modes
|
|
137
137
|
|
|
138
|
-
|
|
138
|
+
Both modes are **off by default**. They request faster processing for supported models and may use more credits or incur higher costs.
|
|
139
139
|
|
|
140
|
-
|
|
140
|
+
| Command | Model status label | Request field |
|
|
141
|
+
| ------- | ------------------ | ------------- |
|
|
142
|
+
| `/fast` | `fast` | `service_tier: "priority"` |
|
|
143
|
+
| `/ultrafast` | `Ultra Fast` | `service_tier: "ultrafast"` |
|
|
141
144
|
|
|
142
|
-
|
|
143
|
-
/fast
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
Each invocation switches Fast between on and off and writes the result to `~/.pi/agent/cliproxyapi.json`. On the next startup, a persisted `true` value immediately enables Fast for catalog-supported models. Fast remains ineffective for unsupported models, so their requests are left unchanged. If `CLIPROXYAPI_FAST` is set, that environment variable still takes precedence on startup.
|
|
145
|
+
The modes are mutually exclusive. Run the active command again to turn it off, or run the other command to switch directly. Each change saves the global preference in `~/.pi/agent/cliproxyapi.json` and refreshes the provider's model pricing. The saved preference is restored at the next startup unless `CLIPROXYAPI_FAST` overrides it.
|
|
147
146
|
|
|
148
|
-
|
|
147
|
+
Both modes apply only to models whose CLIProxyAPI catalog entry has a non-empty `service_tiers` array. The provider ignores `additional_speed_tiers`. When a mode is effective, pi appends its yellow label to the bottom-right model status without a separate notification. On unsupported models, the commands still update the global preference and warn when enabling a mode, but the request and model status remain unchanged.
|
|
149
148
|
|
|
150
|
-
|
|
149
|
+
Both modes are independent of pi's reasoning level and use `experimental.modes.fast.cost` from `models.dev` when available. Otherwise, the registered model uses the standard price; the plugin does not guess prices from `-pro` or `-fast` model IDs.
|
|
151
150
|
|
|
152
151
|
## Pausing provider requests
|
|
153
152
|
|
|
@@ -207,7 +206,8 @@ From CPA catalog entry → pi model:
|
|
|
207
206
|
| `input_modalities` | `input` (`text` / `image`) |
|
|
208
207
|
| `supported_reasoning_levels[].effort` | `thinkingLevelMap` + `reasoning` |
|
|
209
208
|
| `supports_reasoning_effort_updates` | `compat.supportsMidConvoEffort` |
|
|
210
|
-
| `
|
|
209
|
+
| `supports_decisions: true` | Codemode classifier using `openai-decisions` |
|
|
210
|
+
| `visibility: "hide"` | skip chat model registration |
|
|
211
211
|
|
|
212
212
|
Unsupported pi thinking levels are set to `null` so they are hidden in the UI. When available, prices are matched against canonical model entries in `models.dev`; `cost.tiers[].tier.size` becomes pi's `inputTokensAbove`, including thresholds such as `272000`. The legacy `context_over_200k` field is used only when no explicit tiers are present. Ambiguous reseller prices are not selected arbitrarily and fall back to zero. These are catalog/list prices, not a guarantee of CPA's own markup or billing.
|
|
213
213
|
|
|
@@ -250,5 +250,5 @@ Disable just this helper via `pi config` if you only want the CLIProxyAPI provid
|
|
|
250
250
|
- HTTP 200 (including empty catalog) → credentials are persisted
|
|
251
251
|
- non-200 / network / invalid baseUrl → nothing is persisted; re-enter baseUrl + API key
|
|
252
252
|
- If CPA returns HTTP 200 with zero usable models: login still succeeds; re-run `/login CLIProxyAPI` later after models become available.
|
|
253
|
-
- If the selected model does not provide a non-empty `service_tiers` array: the request is left unchanged; `/fast` still
|
|
253
|
+
- If the selected model does not provide a non-empty `service_tiers` array: the request is left unchanged; `/fast` and `/ultrafast` still update the global preference and warn when enabling a mode.
|
|
254
254
|
- After `/compact`, threshold compaction, or overflow recovery, the provider closes the reused Codex WebSocket for the current session. CLIProxyAPI binds server-side context to the connection, so a reused socket would keep reporting a near-full `cacheRead` and retrigger proactive compaction even though the client context is now small. SSE is unaffected because it bills from the request body.
|
|
@@ -21,6 +21,7 @@ import { dirname, join, resolve } from "node:path";
|
|
|
21
21
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
22
22
|
import type { Api, AssistantMessageEventStream, Context, Model, SimpleStreamOptions } from "@earendil-works/pi-ai";
|
|
23
23
|
import { getPackageDir } from "@earendil-works/pi-coding-agent";
|
|
24
|
+
import type { FastServiceTier } from "./fast.ts";
|
|
24
25
|
|
|
25
26
|
export const CLIPROXYAPI_CODEX_API = "cliproxyapi-codex-responses" as const;
|
|
26
27
|
|
|
@@ -42,7 +43,7 @@ export type CliproxyCodexStreams = {
|
|
|
42
43
|
};
|
|
43
44
|
|
|
44
45
|
export interface CliproxyCodexStreamOptions {
|
|
45
|
-
|
|
46
|
+
resolveServiceTier?: (model: Model<Api>) => FastServiceTier | undefined;
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
type PayloadHook = NonNullable<SimpleStreamOptions["onPayload"]>;
|
|
@@ -248,38 +249,39 @@ function moveGptInstructionsToInput(
|
|
|
248
249
|
};
|
|
249
250
|
}
|
|
250
251
|
|
|
251
|
-
export function
|
|
252
|
+
export function withServiceTier(payload: unknown, tier: FastServiceTier): unknown {
|
|
252
253
|
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
253
254
|
return payload;
|
|
254
255
|
}
|
|
255
256
|
return {
|
|
256
257
|
...(payload as Record<string, unknown>),
|
|
257
|
-
service_tier:
|
|
258
|
+
service_tier: tier,
|
|
258
259
|
};
|
|
259
260
|
}
|
|
260
261
|
|
|
261
|
-
/** Apply
|
|
262
|
-
export async function
|
|
262
|
+
/** Apply the tier before pi's shared payload hooks so later extensions retain final control. */
|
|
263
|
+
export async function applyServiceTierPayloadHook(
|
|
263
264
|
payload: unknown,
|
|
264
265
|
model: Model<Api>,
|
|
266
|
+
tier: FastServiceTier,
|
|
265
267
|
onPayload?: PayloadHook,
|
|
266
268
|
): Promise<unknown> {
|
|
267
|
-
const
|
|
268
|
-
const nextPayload = await onPayload?.(
|
|
269
|
-
return nextPayload === undefined ?
|
|
269
|
+
const tierPayload = withServiceTier(payload, tier);
|
|
270
|
+
const nextPayload = await onPayload?.(tierPayload, model);
|
|
271
|
+
return nextPayload === undefined ? tierPayload : nextPayload;
|
|
270
272
|
}
|
|
271
273
|
|
|
272
|
-
export function
|
|
273
|
-
|
|
274
|
-
|
|
274
|
+
export function wrapStreamForServiceTier(
|
|
275
|
+
stream: CliproxyCodexStreamSimple,
|
|
276
|
+
resolveServiceTier?: (model: Model<Api>, options?: SimpleStreamOptions) => FastServiceTier | undefined,
|
|
275
277
|
): CliproxyCodexStreamSimple {
|
|
276
278
|
return (model, context, streamOptions) => {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
return streamSimple(model, context, {
|
|
279
|
+
const tier = resolveServiceTier?.(model, streamOptions);
|
|
280
|
+
if (!tier) return stream(model, context, streamOptions);
|
|
281
|
+
return stream(model, context, {
|
|
281
282
|
...streamOptions,
|
|
282
|
-
onPayload: (payload, payloadModel) =>
|
|
283
|
+
onPayload: (payload, payloadModel) =>
|
|
284
|
+
applyServiceTierPayloadHook(payload, payloadModel, tier, streamOptions?.onPayload),
|
|
283
285
|
});
|
|
284
286
|
};
|
|
285
287
|
}
|
|
@@ -1493,8 +1495,8 @@ export async function loadCliproxyCodexStreams(
|
|
|
1493
1495
|
return mod.stream(adaptModel(model), adaptContext(context), adaptOptions(context, streamOptions));
|
|
1494
1496
|
};
|
|
1495
1497
|
|
|
1496
|
-
const streamSimple =
|
|
1497
|
-
const stream =
|
|
1498
|
+
const streamSimple = wrapStreamForServiceTier(adaptedStreamSimple, options.resolveServiceTier);
|
|
1499
|
+
const stream = wrapStreamForServiceTier(adaptedStream, options.resolveServiceTier);
|
|
1498
1500
|
|
|
1499
1501
|
return {
|
|
1500
1502
|
api: CLIPROXYAPI_CODEX_API,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type ExtensionAPI, type ExtensionContext, FooterComponent } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import type { ProactiveCompactionSettings } from "./auto-compact.ts";
|
|
3
|
-
import type { FastModeController } from "./fast.ts";
|
|
3
|
+
import type { FastModeController, FastServiceTier } from "./fast.ts";
|
|
4
4
|
import { type PauseController, pauseController } from "./pause.ts";
|
|
5
5
|
|
|
6
6
|
const FAST_FOOTER_PATCH = Symbol.for("@router-for-me/pi-cliproxyapi-provider/fast-footer-patch");
|
|
@@ -43,19 +43,17 @@ export function formatFastModelStatus(
|
|
|
43
43
|
modelName: string,
|
|
44
44
|
supportsReasoning: boolean,
|
|
45
45
|
thinkingLevel: string,
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
paused = false,
|
|
49
|
-
pausedLabel = "paused",
|
|
46
|
+
fastLabel?: string,
|
|
47
|
+
pausedLabel?: string,
|
|
50
48
|
): string {
|
|
51
49
|
let status = modelName;
|
|
52
50
|
if (supportsReasoning) {
|
|
53
51
|
status += thinkingLevel === "off" ? " • thinking off" : ` • ${thinkingLevel}`;
|
|
54
52
|
}
|
|
55
|
-
if (
|
|
53
|
+
if (fastLabel) {
|
|
56
54
|
status += ` • ${fastLabel}`;
|
|
57
55
|
}
|
|
58
|
-
if (
|
|
56
|
+
if (pausedLabel) {
|
|
59
57
|
status += ` • ${pausedLabel}`;
|
|
60
58
|
}
|
|
61
59
|
return status;
|
|
@@ -96,13 +94,13 @@ function installFooterPatch(controller: FastFooterController): void {
|
|
|
96
94
|
const originalId = model.id;
|
|
97
95
|
const originalReasoning = model.reasoning;
|
|
98
96
|
const originalContextWindow = model.contextWindow;
|
|
99
|
-
const
|
|
100
|
-
if (
|
|
97
|
+
const tier = activeController.getServiceTierFor(model);
|
|
98
|
+
if (tier || activeController.isPaused()) {
|
|
101
99
|
model.id = activeController.formatModelStatus(
|
|
102
100
|
originalId,
|
|
103
101
|
originalReasoning,
|
|
104
102
|
session?.state.thinkingLevel ?? "off",
|
|
105
|
-
|
|
103
|
+
tier,
|
|
106
104
|
);
|
|
107
105
|
model.reasoning = false;
|
|
108
106
|
}
|
|
@@ -138,7 +136,7 @@ function removeFooterPatch(controller: FastFooterController): void {
|
|
|
138
136
|
delete prototype[FAST_FOOTER_PATCH];
|
|
139
137
|
}
|
|
140
138
|
|
|
141
|
-
/** Adds
|
|
139
|
+
/** Adds the active speed label to pi's built-in model status without replacing the footer. */
|
|
142
140
|
export class FastFooterController {
|
|
143
141
|
private activeContext: ExtensionContext | undefined;
|
|
144
142
|
private patchInstalled = false;
|
|
@@ -166,27 +164,25 @@ export class FastFooterController {
|
|
|
166
164
|
});
|
|
167
165
|
}
|
|
168
166
|
|
|
169
|
-
formatModelStatus(
|
|
167
|
+
formatModelStatus(
|
|
168
|
+
modelName: string,
|
|
169
|
+
supportsReasoning: boolean,
|
|
170
|
+
thinkingLevel: string,
|
|
171
|
+
tier?: FastServiceTier,
|
|
172
|
+
): string {
|
|
170
173
|
const theme = this.activeContext?.ui.theme;
|
|
171
|
-
const
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
supportsReasoning,
|
|
176
|
-
thinkingLevel,
|
|
177
|
-
fastEnabled,
|
|
178
|
-
fastLabel,
|
|
179
|
-
this.pauseMode.isEnabled(),
|
|
180
|
-
pausedLabel,
|
|
181
|
-
);
|
|
174
|
+
const label = tier === "ultrafast" ? "Ultra Fast" : "fast";
|
|
175
|
+
const fastLabel = tier ? (theme?.fg("warning", label) ?? label) : undefined;
|
|
176
|
+
const pausedLabel = this.isPaused() ? formatOrangeLabel(theme, "paused") : undefined;
|
|
177
|
+
return formatFastModelStatus(modelName, supportsReasoning, thinkingLevel, fastLabel, pausedLabel);
|
|
182
178
|
}
|
|
183
179
|
|
|
184
180
|
isProviderModel(model: MutableModel): boolean {
|
|
185
181
|
return model.provider === this.providerId;
|
|
186
182
|
}
|
|
187
183
|
|
|
188
|
-
|
|
189
|
-
return this.isProviderModel(model)
|
|
184
|
+
getServiceTierFor(model: MutableModel): FastServiceTier | undefined {
|
|
185
|
+
return this.isProviderModel(model) ? this.fastMode.getServiceTierFor(model.id) : undefined;
|
|
190
186
|
}
|
|
191
187
|
|
|
192
188
|
isPaused(): boolean {
|
package/extensions/fast.ts
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
export type FastPreference = boolean | "ultrafast";
|
|
2
|
+
export type FastServiceTier = "priority" | "ultrafast";
|
|
3
|
+
|
|
4
|
+
/** Global speed preference plus the capability set advertised by CPA. */
|
|
2
5
|
export class FastModeController {
|
|
3
6
|
private supportedModelIds = new Set<string>();
|
|
4
7
|
|
|
5
|
-
constructor(private
|
|
8
|
+
constructor(private preference: FastPreference) {}
|
|
9
|
+
|
|
10
|
+
getPreference(): FastPreference {
|
|
11
|
+
return this.preference;
|
|
12
|
+
}
|
|
6
13
|
|
|
7
|
-
|
|
8
|
-
this.
|
|
14
|
+
setPreference(preference: FastPreference): void {
|
|
15
|
+
this.preference = preference;
|
|
9
16
|
}
|
|
10
17
|
|
|
11
18
|
setSupportedModelIds(modelIds: Iterable<string>): void {
|
|
@@ -15,14 +22,15 @@ export class FastModeController {
|
|
|
15
22
|
}
|
|
16
23
|
|
|
17
24
|
isEnabled(): boolean {
|
|
18
|
-
return this.
|
|
25
|
+
return this.preference !== false;
|
|
19
26
|
}
|
|
20
27
|
|
|
21
28
|
isModelSupported(modelId: string): boolean {
|
|
22
29
|
return this.supportedModelIds.has(modelId.trim());
|
|
23
30
|
}
|
|
24
31
|
|
|
25
|
-
|
|
26
|
-
|
|
32
|
+
getServiceTierFor(modelId: string): FastServiceTier | undefined {
|
|
33
|
+
if (!this.isEnabled() || !this.isModelSupported(modelId)) return undefined;
|
|
34
|
+
return this.preference === "ultrafast" ? "ultrafast" : "priority";
|
|
27
35
|
}
|
|
28
36
|
}
|
package/extensions/index.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* 4. Final login step validates credentials via /v1/models?client_version=pi
|
|
11
11
|
* (HTTP 200 = success even if the catalog is empty; otherwise re-prompt).
|
|
12
12
|
* 5. On success, models/credentials are saved and registered immediately.
|
|
13
|
-
* 6. `/fast` globally
|
|
13
|
+
* 6. `/fast` and `/ultrafast` globally control catalog-driven service tier injection.
|
|
14
14
|
*
|
|
15
15
|
* Uses a patched openai-codex-responses implementation that does not require
|
|
16
16
|
* extracting chatgpt_account_id from the API key (plain CPA keys work).
|
|
@@ -26,15 +26,21 @@ import type {
|
|
|
26
26
|
SimpleStreamOptions,
|
|
27
27
|
StreamFunction,
|
|
28
28
|
} from "@earendil-works/pi-ai";
|
|
29
|
-
import {
|
|
29
|
+
import { builtinProviders } from "@earendil-works/pi-ai/providers/all";
|
|
30
|
+
import {
|
|
31
|
+
type ExtensionAPI,
|
|
32
|
+
type ExtensionContext,
|
|
33
|
+
getAgentDir,
|
|
34
|
+
type ProviderModelConfig,
|
|
35
|
+
} from "@earendil-works/pi-coding-agent";
|
|
30
36
|
import { ProactiveCompactionController } from "./auto-compact.ts";
|
|
31
37
|
import {
|
|
32
|
-
applyFastPayloadHook,
|
|
33
38
|
CLIPROXYAPI_CODEX_API,
|
|
34
39
|
type CliproxyCodexStreamSimple,
|
|
35
40
|
loadCliproxyCodexStreams,
|
|
41
|
+
wrapStreamForServiceTier,
|
|
36
42
|
} from "./codex-stream.ts";
|
|
37
|
-
import { FastModeController } from "./fast.ts";
|
|
43
|
+
import { FastModeController, type FastPreference } from "./fast.ts";
|
|
38
44
|
import { FastFooterController } from "./fast-footer.ts";
|
|
39
45
|
import {
|
|
40
46
|
CONFIG_FILE_NAME,
|
|
@@ -310,7 +316,6 @@ async function configureAndRegister(options: {
|
|
|
310
316
|
streamSimple: CliproxyCodexStreamSimple;
|
|
311
317
|
fastMode: FastModeController;
|
|
312
318
|
refreshCoordinator: ModelRefreshCoordinator;
|
|
313
|
-
onFastModeChange?: (enabled: boolean, ctx: ExtensionContext) => Promise<void>;
|
|
314
319
|
onRefreshOutcome?: (loaded: MappedModels) => void;
|
|
315
320
|
}): Promise<RefreshResult> {
|
|
316
321
|
const {
|
|
@@ -324,7 +329,6 @@ async function configureAndRegister(options: {
|
|
|
324
329
|
streamSimple,
|
|
325
330
|
fastMode,
|
|
326
331
|
refreshCoordinator,
|
|
327
|
-
onFastModeChange,
|
|
328
332
|
onRefreshOutcome,
|
|
329
333
|
} = options;
|
|
330
334
|
|
|
@@ -362,7 +366,6 @@ async function configureAndRegister(options: {
|
|
|
362
366
|
streamSimple,
|
|
363
367
|
fastMode,
|
|
364
368
|
refreshCoordinator,
|
|
365
|
-
onFastModeChange,
|
|
366
369
|
onRefreshOutcome,
|
|
367
370
|
});
|
|
368
371
|
fastMode.setSupportedModelIds(loaded.fastModelIds);
|
|
@@ -386,7 +389,6 @@ function createOAuthHandlers(options: {
|
|
|
386
389
|
streamSimple: CliproxyCodexStreamSimple;
|
|
387
390
|
fastMode: FastModeController;
|
|
388
391
|
refreshCoordinator: ModelRefreshCoordinator;
|
|
389
|
-
onFastModeChange?: (enabled: boolean, ctx: ExtensionContext) => Promise<void>;
|
|
390
392
|
onRefreshOutcome?: (loaded: MappedModels) => void;
|
|
391
393
|
}) {
|
|
392
394
|
const {
|
|
@@ -398,7 +400,6 @@ function createOAuthHandlers(options: {
|
|
|
398
400
|
streamSimple,
|
|
399
401
|
fastMode,
|
|
400
402
|
refreshCoordinator,
|
|
401
|
-
onFastModeChange,
|
|
402
403
|
onRefreshOutcome,
|
|
403
404
|
} = options;
|
|
404
405
|
|
|
@@ -429,7 +430,6 @@ function createOAuthHandlers(options: {
|
|
|
429
430
|
streamSimple,
|
|
430
431
|
fastMode,
|
|
431
432
|
refreshCoordinator,
|
|
432
|
-
onFastModeChange,
|
|
433
433
|
onRefreshOutcome,
|
|
434
434
|
});
|
|
435
435
|
|
|
@@ -494,7 +494,6 @@ function registerProvider(
|
|
|
494
494
|
streamSimple: CliproxyCodexStreamSimple;
|
|
495
495
|
fastMode: FastModeController;
|
|
496
496
|
refreshCoordinator?: ModelRefreshCoordinator;
|
|
497
|
-
onFastModeChange?: (enabled: boolean, ctx: ExtensionContext) => Promise<void>;
|
|
498
497
|
onRefreshOutcome?: (loaded: MappedModels) => void;
|
|
499
498
|
},
|
|
500
499
|
): void {
|
|
@@ -508,12 +507,30 @@ function registerProvider(
|
|
|
508
507
|
agentDir,
|
|
509
508
|
streamSimple,
|
|
510
509
|
fastMode,
|
|
511
|
-
onFastModeChange,
|
|
512
510
|
onRefreshOutcome,
|
|
513
511
|
} = options;
|
|
514
512
|
const refreshCoordinator = options.refreshCoordinator ?? new ModelRefreshCoordinator();
|
|
515
513
|
|
|
516
514
|
const endpoints = resolveEndpoints(baseUrlInput);
|
|
515
|
+
const classify = models?.some((model) => model.decisions === true)
|
|
516
|
+
? builtinProviders().find((provider) => provider.id === "openai")?.classify
|
|
517
|
+
: undefined;
|
|
518
|
+
const registeredModels = models?.flatMap<ProviderModelConfig>((model) => {
|
|
519
|
+
if (model.decisions !== true) return [model];
|
|
520
|
+
if (!classify) return [];
|
|
521
|
+
return [
|
|
522
|
+
{
|
|
523
|
+
type: "classifier",
|
|
524
|
+
api: "openai-decisions",
|
|
525
|
+
id: model.id,
|
|
526
|
+
name: model.name,
|
|
527
|
+
baseUrl: new URL(".", endpoints.modelsUrl).href,
|
|
528
|
+
input: model.input,
|
|
529
|
+
cost: model.cost,
|
|
530
|
+
contextWindow: model.contextWindow,
|
|
531
|
+
},
|
|
532
|
+
];
|
|
533
|
+
});
|
|
517
534
|
const oauth = createOAuthHandlers({
|
|
518
535
|
pi,
|
|
519
536
|
agentDir,
|
|
@@ -523,7 +540,6 @@ function registerProvider(
|
|
|
523
540
|
streamSimple,
|
|
524
541
|
fastMode,
|
|
525
542
|
refreshCoordinator,
|
|
526
|
-
onFastModeChange,
|
|
527
543
|
onRefreshOutcome,
|
|
528
544
|
});
|
|
529
545
|
|
|
@@ -541,7 +557,8 @@ function registerProvider(
|
|
|
541
557
|
// (config file / env). Never pass both for /login flows.
|
|
542
558
|
oauth,
|
|
543
559
|
...(apiKey ? { apiKey } : {}),
|
|
544
|
-
...(models
|
|
560
|
+
...(models?.length ? { models: registeredModels } : {}),
|
|
561
|
+
...(classify ? { classifiers: { "openai-decisions": { classify } } } : {}),
|
|
545
562
|
});
|
|
546
563
|
}
|
|
547
564
|
|
|
@@ -593,22 +610,22 @@ export function registerPauseGuard(options: { pi: ExtensionAPI; agentDir: string
|
|
|
593
610
|
});
|
|
594
611
|
}
|
|
595
612
|
|
|
596
|
-
export function
|
|
613
|
+
export function registerFastCommands(options: {
|
|
597
614
|
pi: ExtensionAPI;
|
|
598
615
|
agentDir: string;
|
|
599
616
|
providerId: string;
|
|
600
617
|
fastMode: FastModeController;
|
|
601
618
|
onStatusChange?: (ctx: ExtensionContext) => void;
|
|
602
|
-
onModeChange?: (
|
|
619
|
+
onModeChange?: (ctx: ExtensionContext) => Promise<void>;
|
|
603
620
|
}): void {
|
|
604
621
|
const { pi, agentDir, providerId, fastMode, onStatusChange, onModeChange } = options;
|
|
605
622
|
let modeChangeInProgress = false;
|
|
606
623
|
|
|
607
|
-
|
|
608
|
-
description:
|
|
609
|
-
handler: async (args, ctx) => {
|
|
624
|
+
const createCommand = (name: string, label: string, selected: Exclude<FastPreference, false>) => ({
|
|
625
|
+
description: `Toggle CLIProxyAPI ${label} mode globally.`,
|
|
626
|
+
handler: async (args: string, ctx: ExtensionContext) => {
|
|
610
627
|
if (args.trim()) {
|
|
611
|
-
ctx.ui.notify(
|
|
628
|
+
ctx.ui.notify(`Usage: /${name}`, "error");
|
|
612
629
|
return;
|
|
613
630
|
}
|
|
614
631
|
if (modeChangeInProgress) {
|
|
@@ -618,32 +635,33 @@ export function registerFastCommand(options: {
|
|
|
618
635
|
|
|
619
636
|
modeChangeInProgress = true;
|
|
620
637
|
try {
|
|
621
|
-
const
|
|
622
|
-
const
|
|
638
|
+
const previousPreference = fastMode.getPreference();
|
|
639
|
+
const preference = previousPreference === selected ? false : selected;
|
|
640
|
+
let previousSavedPreference: FastPreference | undefined;
|
|
623
641
|
try {
|
|
624
|
-
saveConfigFile(agentDir, { fast:
|
|
642
|
+
previousSavedPreference = saveConfigFile(agentDir, { fast: preference }).fast;
|
|
625
643
|
} catch (error) {
|
|
626
644
|
const message = error instanceof Error ? error.message : String(error);
|
|
627
|
-
ctx.ui.notify(`Failed to save
|
|
645
|
+
ctx.ui.notify(`Failed to save ${label} mode: ${message}`, "error");
|
|
628
646
|
return;
|
|
629
647
|
}
|
|
630
|
-
fastMode.
|
|
648
|
+
fastMode.setPreference(preference);
|
|
631
649
|
try {
|
|
632
|
-
await onModeChange?.(
|
|
650
|
+
await onModeChange?.(ctx);
|
|
633
651
|
} catch (error) {
|
|
634
652
|
// Restore all three views of the mode after a partial refresh:
|
|
635
653
|
// in-memory request behavior, persisted preference, and model metadata.
|
|
636
|
-
fastMode.
|
|
654
|
+
fastMode.setPreference(previousPreference);
|
|
637
655
|
const rollbackErrors: string[] = [];
|
|
638
656
|
try {
|
|
639
|
-
saveConfigFile(agentDir, { fast:
|
|
657
|
+
saveConfigFile(agentDir, { fast: previousSavedPreference });
|
|
640
658
|
} catch (rollbackError) {
|
|
641
659
|
rollbackErrors.push(
|
|
642
660
|
`config rollback failed: ${rollbackError instanceof Error ? rollbackError.message : String(rollbackError)}`,
|
|
643
661
|
);
|
|
644
662
|
}
|
|
645
663
|
try {
|
|
646
|
-
await onModeChange?.(
|
|
664
|
+
await onModeChange?.(ctx);
|
|
647
665
|
} catch (rollbackError) {
|
|
648
666
|
rollbackErrors.push(
|
|
649
667
|
`pricing rollback failed: ${rollbackError instanceof Error ? rollbackError.message : String(rollbackError)}`,
|
|
@@ -659,10 +677,13 @@ export function registerFastCommand(options: {
|
|
|
659
677
|
|
|
660
678
|
const currentModel = ctx.model;
|
|
661
679
|
if (!currentModel || currentModel.provider !== providerId || !fastMode.isModelSupported(currentModel.id)) {
|
|
662
|
-
if (
|
|
663
|
-
ctx.ui.notify(
|
|
680
|
+
if (preference !== false) {
|
|
681
|
+
ctx.ui.notify(
|
|
682
|
+
`${label} mode is enabled globally, but the current model does not support it.`,
|
|
683
|
+
"warning",
|
|
684
|
+
);
|
|
664
685
|
} else {
|
|
665
|
-
ctx.ui.notify(
|
|
686
|
+
ctx.ui.notify(`${label} mode is disabled globally.`, "info");
|
|
666
687
|
}
|
|
667
688
|
}
|
|
668
689
|
} finally {
|
|
@@ -670,6 +691,8 @@ export function registerFastCommand(options: {
|
|
|
670
691
|
}
|
|
671
692
|
},
|
|
672
693
|
});
|
|
694
|
+
pi.registerCommand("fast", createCommand("fast", "Fast", true));
|
|
695
|
+
pi.registerCommand("ultrafast", createCommand("ultrafast", "Ultra Fast", "ultrafast"));
|
|
673
696
|
}
|
|
674
697
|
|
|
675
698
|
export function registerRefreshCommand(options: {
|
|
@@ -786,14 +809,14 @@ export default async function (pi: ExtensionAPI): Promise<void> {
|
|
|
786
809
|
const proactiveCompaction = new ProactiveCompactionController(agentDir, identity.providerId);
|
|
787
810
|
proactiveCompaction.register(pi);
|
|
788
811
|
|
|
789
|
-
let
|
|
812
|
+
let fastPreference: FastPreference = false;
|
|
790
813
|
try {
|
|
791
|
-
|
|
814
|
+
fastPreference = resolveFastDefault(agentDir);
|
|
792
815
|
} catch (error) {
|
|
793
816
|
const message = error instanceof Error ? error.message : String(error);
|
|
794
817
|
logWarn(`invalid Fast configuration (${message}); using fast=false`);
|
|
795
818
|
}
|
|
796
|
-
const fastMode = new FastModeController(
|
|
819
|
+
const fastMode = new FastModeController(fastPreference);
|
|
797
820
|
const modelRefreshCoordinator = new ModelRefreshCoordinator();
|
|
798
821
|
|
|
799
822
|
let streamLoadError: string | undefined;
|
|
@@ -805,7 +828,8 @@ export default async function (pi: ExtensionAPI): Promise<void> {
|
|
|
805
828
|
};
|
|
806
829
|
try {
|
|
807
830
|
const streams = await loadCliproxyCodexStreams([identity.providerId, "cliproxyapi"], {
|
|
808
|
-
|
|
831
|
+
resolveServiceTier: (model) =>
|
|
832
|
+
model.provider === identity.providerId ? fastMode.getServiceTierFor(model.id) : undefined,
|
|
809
833
|
});
|
|
810
834
|
proactiveCompaction.setCloseWebSocketSessions(streams.closeOpenAICodexWebSocketSessions);
|
|
811
835
|
streamSimple = proactiveCompaction.wrapStreamSimple(streams.streamSimple);
|
|
@@ -834,46 +858,35 @@ export default async function (pi: ExtensionAPI): Promise<void> {
|
|
|
834
858
|
|
|
835
859
|
coordinator.stack.push(entry);
|
|
836
860
|
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
if (!active) {
|
|
857
|
-
throw new Error(
|
|
858
|
-
`No active provider streamSimple handler registered for provider: ${model.provider} (api: ${CLIPROXYAPI_CODEX_API})`,
|
|
859
|
-
);
|
|
860
|
-
}
|
|
861
|
-
const shouldFast = (options as any)?.serviceTier === "priority" || (options as any)?.fast === true;
|
|
862
|
-
if (shouldFast) {
|
|
863
|
-
return active.rawStreamSimple(model, context, {
|
|
864
|
-
...options,
|
|
865
|
-
onPayload: (payload, payloadModel) => applyFastPayloadHook(payload, payloadModel, options?.onPayload),
|
|
866
|
-
});
|
|
867
|
-
}
|
|
868
|
-
return active.rawStreamSimple(model, context, options);
|
|
869
|
-
};
|
|
861
|
+
// Compat calls use only per-request options, never the foreground speed preference.
|
|
862
|
+
const createCompatDispatch = (method: "stream" | "streamSimple") =>
|
|
863
|
+
wrapStreamForServiceTier(
|
|
864
|
+
(model, context, options) => {
|
|
865
|
+
const active = findActiveCompatEntry(coordinator.stack, model.provider);
|
|
866
|
+
if (!active) {
|
|
867
|
+
throw new Error(
|
|
868
|
+
`No active provider ${method} handler registered for provider: ${model.provider} (api: ${CLIPROXYAPI_CODEX_API})`,
|
|
869
|
+
);
|
|
870
|
+
}
|
|
871
|
+
return active[method === "stream" ? "rawStream" : "rawStreamSimple"](model, context, options);
|
|
872
|
+
},
|
|
873
|
+
(_model, options) => {
|
|
874
|
+
const explicit = options as { serviceTier?: string; fast?: boolean } | undefined;
|
|
875
|
+
const tier = explicit?.serviceTier;
|
|
876
|
+
if (tier === "ultrafast" || tier === "priority") return tier;
|
|
877
|
+
return explicit?.fast === true ? "priority" : undefined;
|
|
878
|
+
},
|
|
879
|
+
);
|
|
870
880
|
|
|
871
881
|
unregisterApiProviders(COMPAT_SOURCE_ID);
|
|
872
882
|
registerApiProvider(
|
|
873
883
|
{
|
|
874
884
|
api: CLIPROXYAPI_CODEX_API,
|
|
875
|
-
stream:
|
|
876
|
-
streamSimple:
|
|
885
|
+
stream: createCompatDispatch("stream") as StreamFunction<typeof CLIPROXYAPI_CODEX_API>,
|
|
886
|
+
streamSimple: createCompatDispatch("streamSimple") as StreamFunction<
|
|
887
|
+
typeof CLIPROXYAPI_CODEX_API,
|
|
888
|
+
SimpleStreamOptions
|
|
889
|
+
>,
|
|
877
890
|
},
|
|
878
891
|
COMPAT_SOURCE_ID,
|
|
879
892
|
);
|
|
@@ -901,16 +914,15 @@ export default async function (pi: ExtensionAPI): Promise<void> {
|
|
|
901
914
|
proactiveCompaction.getCompactionSettings(),
|
|
902
915
|
);
|
|
903
916
|
let refreshModelsForFast: ((ctx: ExtensionContext) => Promise<void>) | undefined;
|
|
904
|
-
|
|
905
|
-
await refreshModelsForFast?.(ctx);
|
|
906
|
-
};
|
|
907
|
-
registerFastCommand({
|
|
917
|
+
registerFastCommands({
|
|
908
918
|
pi,
|
|
909
919
|
agentDir,
|
|
910
920
|
providerId: identity.providerId,
|
|
911
921
|
fastMode,
|
|
912
922
|
onStatusChange: (ctx) => fastFooter.refresh(ctx),
|
|
913
|
-
onModeChange:
|
|
923
|
+
onModeChange: async (ctx) => {
|
|
924
|
+
await refreshModelsForFast?.(ctx);
|
|
925
|
+
},
|
|
914
926
|
});
|
|
915
927
|
fastFooter.register(pi);
|
|
916
928
|
|
|
@@ -950,7 +962,6 @@ export default async function (pi: ExtensionAPI): Promise<void> {
|
|
|
950
962
|
streamSimple,
|
|
951
963
|
fastMode,
|
|
952
964
|
refreshCoordinator: modelRefreshCoordinator,
|
|
953
|
-
onFastModeChange: onFastModeChange,
|
|
954
965
|
onRefreshOutcome: handleRefreshOutcome,
|
|
955
966
|
});
|
|
956
967
|
registerTransientNetworkErrorRetry(pi, identity.providerId);
|
|
@@ -1039,7 +1050,6 @@ export default async function (pi: ExtensionAPI): Promise<void> {
|
|
|
1039
1050
|
streamSimple,
|
|
1040
1051
|
fastMode,
|
|
1041
1052
|
refreshCoordinator: modelRefreshCoordinator,
|
|
1042
|
-
onFastModeChange,
|
|
1043
1053
|
onRefreshOutcome: handleRefreshOutcome,
|
|
1044
1054
|
});
|
|
1045
1055
|
|
package/extensions/lib.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
|
6
6
|
import { tmpdir } from "node:os";
|
|
7
7
|
import { dirname, join } from "node:path";
|
|
8
8
|
import { readStoredCredential } from "@earendil-works/pi-coding-agent";
|
|
9
|
+
import type { FastPreference } from "./fast.ts";
|
|
9
10
|
|
|
10
11
|
// Local shape matching pi ThinkingLevelMap; avoid hard runtime peer imports here.
|
|
11
12
|
export type ThinkingLevelMap = Partial<
|
|
@@ -41,7 +42,7 @@ export interface CliproxyConfigFile {
|
|
|
41
42
|
apiKey?: string;
|
|
42
43
|
providerId?: string;
|
|
43
44
|
providerName?: string;
|
|
44
|
-
fast?:
|
|
45
|
+
fast?: FastPreference;
|
|
45
46
|
pause?: boolean;
|
|
46
47
|
}
|
|
47
48
|
|
|
@@ -82,6 +83,7 @@ export interface CodexClientModel {
|
|
|
82
83
|
input_modalities?: string[];
|
|
83
84
|
supported_reasoning_levels?: CodexReasoningLevel[] | string[];
|
|
84
85
|
supports_reasoning_effort_updates?: boolean;
|
|
86
|
+
supports_decisions?: boolean;
|
|
85
87
|
default_service_tier?: string | null;
|
|
86
88
|
service_tiers?: Array<CodexServiceTier | string>;
|
|
87
89
|
additional_speed_tiers?: string[];
|
|
@@ -120,6 +122,7 @@ export interface PiProviderModel {
|
|
|
120
122
|
maxTokens: number;
|
|
121
123
|
thinkingLevelMap?: ThinkingLevelMap;
|
|
122
124
|
compat?: PiProviderModelCompat;
|
|
125
|
+
decisions?: true;
|
|
123
126
|
stale?: boolean;
|
|
124
127
|
lastSeenAt?: number;
|
|
125
128
|
staleSince?: number;
|
|
@@ -312,7 +315,8 @@ export function isModelReferencedAsDefault(
|
|
|
312
315
|
return false;
|
|
313
316
|
}
|
|
314
317
|
|
|
315
|
-
|
|
318
|
+
/** Merge the config update and return the previous values for callers that need to roll back. */
|
|
319
|
+
export function saveConfigFile(agentDir: string, config: CliproxyConfigFile): CliproxyConfigFile {
|
|
316
320
|
const configPath = join(agentDir, CONFIG_FILE_NAME);
|
|
317
321
|
mkdirSync(dirname(configPath), { recursive: true });
|
|
318
322
|
|
|
@@ -322,6 +326,7 @@ export function saveConfigFile(agentDir: string, config: CliproxyConfigFile): vo
|
|
|
322
326
|
...config,
|
|
323
327
|
};
|
|
324
328
|
writeFileSync(configPath, `${JSON.stringify(next, null, 2)}\n`, "utf8");
|
|
329
|
+
return existing;
|
|
325
330
|
}
|
|
326
331
|
|
|
327
332
|
export function loadModelsCache(agentDir: string, baseUrlInput: string): ModelsCacheFile | null {
|
|
@@ -397,8 +402,8 @@ export function parseBooleanSetting(value: string): boolean | undefined {
|
|
|
397
402
|
}
|
|
398
403
|
}
|
|
399
404
|
|
|
400
|
-
/** Resolve the
|
|
401
|
-
export function resolveFastDefault(agentDir: string):
|
|
405
|
+
/** Resolve the speed preference from the boolean env override, then config, then false. */
|
|
406
|
+
export function resolveFastDefault(agentDir: string): FastPreference {
|
|
402
407
|
const envValue = firstNonEmpty(process.env.CLIPROXYAPI_FAST);
|
|
403
408
|
if (envValue !== undefined) {
|
|
404
409
|
const parsed = parseBooleanSetting(envValue);
|
|
@@ -412,8 +417,8 @@ export function resolveFastDefault(agentDir: string): boolean {
|
|
|
412
417
|
if (file.fast === undefined) {
|
|
413
418
|
return false;
|
|
414
419
|
}
|
|
415
|
-
if (typeof file.fast !== "boolean") {
|
|
416
|
-
throw new Error(`${CONFIG_FILE_NAME} field "fast" must be a boolean`);
|
|
420
|
+
if (typeof file.fast !== "boolean" && file.fast !== "ultrafast") {
|
|
421
|
+
throw new Error(`${CONFIG_FILE_NAME} field "fast" must be a boolean or "ultrafast"`);
|
|
417
422
|
}
|
|
418
423
|
return file.fast;
|
|
419
424
|
}
|
|
@@ -517,7 +522,7 @@ export function codexModelId(model: CodexClientModel): string {
|
|
|
517
522
|
}
|
|
518
523
|
|
|
519
524
|
export function supportsFastServiceTier(model: CodexClientModel): boolean {
|
|
520
|
-
return Array.isArray(model.service_tiers) && model.service_tiers.length > 0;
|
|
525
|
+
return model.supports_decisions !== true && Array.isArray(model.service_tiers) && model.service_tiers.length > 0;
|
|
521
526
|
}
|
|
522
527
|
|
|
523
528
|
export function supportsReasoningEffortUpdates(model: CodexClientModel): boolean {
|
|
@@ -533,7 +538,8 @@ export function toPiModel(
|
|
|
533
538
|
if (!id) {
|
|
534
539
|
return null;
|
|
535
540
|
}
|
|
536
|
-
|
|
541
|
+
const decisions = model.supports_decisions === true;
|
|
542
|
+
if (!decisions && String(model.visibility ?? "").toLowerCase() === "hide") {
|
|
537
543
|
return null;
|
|
538
544
|
}
|
|
539
545
|
|
|
@@ -576,6 +582,7 @@ export function toPiModel(
|
|
|
576
582
|
maxTokens,
|
|
577
583
|
thinkingLevelMap: buildThinkingLevelMap(efforts),
|
|
578
584
|
...(hasReasoning && supportsReasoningEffortUpdates(model) ? { compat: { supportsMidConvoEffort: true } } : {}),
|
|
585
|
+
...(decisions ? { decisions } : {}),
|
|
579
586
|
};
|
|
580
587
|
}
|
|
581
588
|
|
package/package.json
CHANGED