@router-for-me/pi-cliproxyapi-provider 1.2.2 → 1.4.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 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 `/cpa-fast on|off|status` to request OpenAI priority processing for supported models.
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
@@ -112,7 +112,7 @@ Optional fields:
112
112
  | `apiKey` | _(required unless set via /login or env)_ | Bearer token / CPA API key |
113
113
  | `providerId` | `cliproxyapi` | Provider id shown in `/model` |
114
114
  | `providerName` | `CLIProxyAPI` | Display name in `/login` and UI |
115
- | `fast` | `false` | Default Fast mode for new sessions; only applies to catalog-supported models |
115
+ | `fast` | `false` | Persisted Fast mode preference; only applies to catalog-supported models |
116
116
 
117
117
  ### Environment overrides
118
118
 
@@ -131,7 +131,7 @@ Resolution order for connection settings:
131
131
  3. `/login` credentials in `auth.json`
132
132
  4. Default baseUrl `http://127.0.0.1:8317`
133
133
 
134
- Fast defaults resolve separately as `CLIPROXYAPI_FAST` → `cliproxyapi.json` → `false`.
134
+ The Fast preference resolves separately as `CLIPROXYAPI_FAST` → `cliproxyapi.json` → `false`.
135
135
 
136
136
  ### baseUrl normalization
137
137
 
@@ -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**. Control it for the current pi session with:
153
+ Fast is **off by default**. Toggle the global preference with:
154
154
 
155
155
  ```text
156
- /cpa-fast on
157
- /cpa-fast off
158
- /cpa-fast status
156
+ /fast
159
157
  ```
160
158
 
161
- The command 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`.
159
+ 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.
162
160
 
163
- Fast capability is catalog-driven: the plugin only injects `service_tier: "priority"` when the selected CLIProxyAPI model advertises `priority` in `service_tiers` or `fast` in `additional_speed_tiers`. Unsupported models are left unchanged, and `/cpa-fast status` reports whether Fast is effective for the current model. Fast is independent from pi's reasoning/thinking level.
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 or the selected model is unsupported, the original model status remains unchanged. Supported models do not produce a separate status notification. Running `/fast` with an unsupported model still updates the global preference; enabling it warns that the current model cannot use Fast.
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 Fast is enabled for a model that does not advertise Fast capability: the request is left unchanged and `/cpa-fast` reports a warning.
209
+ - If the selected model does not provide a non-empty `service_tiers` array: the request is left unchanged; `/fast` still updates the global preference and warns when enabling it.
@@ -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
+ }
@@ -1,26 +1,11 @@
1
- export type FastModeSource = "configured-default" | "session-override";
2
-
3
- export const FAST_MODE_ENTRY_TYPE = "cliproxyapi-fast-mode";
4
-
5
- export interface FastModeSessionEntry {
6
- type: string;
7
- customType?: string;
8
- data?: unknown;
9
- }
10
-
11
- /** Session-scoped Fast preference plus the capability set advertised by CPA. */
1
+ /** Global Fast preference plus the capability set advertised by CPA. */
12
2
  export class FastModeController {
13
- private sessionOverride: boolean | undefined;
14
3
  private supportedModelIds = new Set<string>();
15
4
 
16
- constructor(private readonly defaultEnabled: boolean) {}
17
-
18
- setSessionEnabled(enabled: boolean): void {
19
- this.sessionOverride = enabled;
20
- }
5
+ constructor(private enabled: boolean) {}
21
6
 
22
- clearSessionOverride(): void {
23
- this.sessionOverride = undefined;
7
+ setEnabled(enabled: boolean): void {
8
+ this.enabled = enabled;
24
9
  }
25
10
 
26
11
  setSupportedModelIds(modelIds: Iterable<string>): void {
@@ -30,11 +15,7 @@ export class FastModeController {
30
15
  }
31
16
 
32
17
  isEnabled(): boolean {
33
- return this.sessionOverride ?? this.defaultEnabled;
34
- }
35
-
36
- getSource(): FastModeSource {
37
- return this.sessionOverride === undefined ? "configured-default" : "session-override";
18
+ return this.enabled;
38
19
  }
39
20
 
40
21
  isModelSupported(modelId: string): boolean {
@@ -42,22 +23,6 @@ export class FastModeController {
42
23
  }
43
24
 
44
25
  isEffectiveFor(modelId: string): boolean {
45
- return this.isEnabled() && this.isModelSupported(modelId);
46
- }
47
- }
48
-
49
- export function restoreFastModeFromEntries(
50
- fastMode: FastModeController,
51
- entries: Iterable<FastModeSessionEntry>,
52
- ): void {
53
- fastMode.clearSessionOverride();
54
- for (const entry of entries) {
55
- if (entry.type !== "custom" || entry.customType !== FAST_MODE_ENTRY_TYPE) {
56
- continue;
57
- }
58
- const data = entry.data;
59
- if (data && typeof data === "object" && typeof (data as { enabled?: unknown }).enabled === "boolean") {
60
- fastMode.setSessionEnabled((data as { enabled: boolean }).enabled);
61
- }
26
+ return this.enabled && this.isModelSupported(modelId);
62
27
  }
63
28
  }
@@ -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. `/cpa-fast` controls catalog-driven priority service tier injection per session.
14
+ * 7. `/fast` globally controls catalog-driven priority service tier injection.
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 { type ExtensionAPI, type ExtensionCommandContext, getAgentDir } from "@earendil-works/pi-coding-agent";
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
- import { FAST_MODE_ENTRY_TYPE, FastModeController, restoreFastModeFromEntries } from "./fast.ts";
30
+ import { FastModeController } from "./fast.ts";
31
+ import { FastFooterController } from "./fast-footer.ts";
26
32
  import {
27
33
  CONFIG_FILE_NAME,
28
34
  CREDENTIAL_TTL_MS,
@@ -49,6 +55,14 @@ interface SetupCommandsController {
49
55
  isVisible(): boolean;
50
56
  }
51
57
 
58
+ class ConfigPersistenceError extends Error {
59
+ constructor(cause: unknown) {
60
+ const message = cause instanceof Error ? cause.message : String(cause);
61
+ super(`Failed to save ${CONFIG_FILE_NAME}: ${message}`, { cause });
62
+ this.name = "ConfigPersistenceError";
63
+ }
64
+ }
65
+
52
66
  function logWarn(message: string): void {
53
67
  console.warn(`[pi-cliproxyapi-provider] ${message}`);
54
68
  }
@@ -144,14 +158,17 @@ async function configureAndRegister(options: {
144
158
  } = options;
145
159
 
146
160
  const loaded = await loadMappedModels(baseUrlInput, apiKey);
147
- fastMode.setSupportedModelIds(loaded.fastModelIds);
148
161
 
149
- saveConfigFile(agentDir, {
150
- baseUrl: baseUrlInput,
151
- apiKey,
152
- providerId,
153
- providerName,
154
- });
162
+ try {
163
+ saveConfigFile(agentDir, {
164
+ baseUrl: baseUrlInput,
165
+ apiKey,
166
+ providerId,
167
+ providerName,
168
+ });
169
+ } catch (error) {
170
+ throw new ConfigPersistenceError(error);
171
+ }
155
172
 
156
173
  registerProvider(pi, {
157
174
  providerId,
@@ -165,6 +182,7 @@ async function configureAndRegister(options: {
165
182
  setupCommands,
166
183
  fastMode,
167
184
  });
185
+ fastMode.setSupportedModelIds(loaded.fastModelIds);
168
186
 
169
187
  // Login succeeded — hide dedicated setup commands from the slash menu.
170
188
  setupCommands.hide();
@@ -217,6 +235,10 @@ function createOAuthHandlers(options: {
217
235
  } catch (error) {
218
236
  const message = error instanceof Error ? error.message : String(error);
219
237
  logWarn(`login validation failed: ${message}`);
238
+ if (error instanceof ConfigPersistenceError) {
239
+ callbacks.onProgress?.(message);
240
+ throw error;
241
+ }
220
242
  // Auth failures should keep setup commands available for reconfiguration.
221
243
  if (isUnauthorizedModelsError(error)) {
222
244
  setupCommands.show();
@@ -440,6 +462,10 @@ function createSetupCommandsController(options: {
440
462
  } catch (error) {
441
463
  const message = error instanceof Error ? error.message : String(error);
442
464
  logWarn(`command setup failed: ${message}`);
465
+ if (error instanceof ConfigPersistenceError) {
466
+ ctx.ui.notify(message, "error");
467
+ return;
468
+ }
443
469
  if (isUnauthorizedModelsError(error)) {
444
470
  setupCommands.show();
445
471
  }
@@ -555,63 +581,42 @@ function createSetupCommandsController(options: {
555
581
  return setupCommands;
556
582
  }
557
583
 
558
- function registerFastCommand(options: {
584
+ export function registerFastCommand(options: {
559
585
  pi: ExtensionAPI;
586
+ agentDir: string;
560
587
  providerId: string;
561
- providerName: string;
562
588
  fastMode: FastModeController;
589
+ onStatusChange?: (ctx: ExtensionContext) => void;
563
590
  }): void {
564
- const { pi, providerId, providerName, fastMode } = options;
565
- const actions = ["on", "off", "status"] as const;
566
-
567
- pi.on("session_start", (_event, ctx) => {
568
- restoreFastModeFromEntries(fastMode, ctx.sessionManager.getBranch());
569
- });
570
- pi.on("session_tree", (_event, ctx) => {
571
- restoreFastModeFromEntries(fastMode, ctx.sessionManager.getBranch());
572
- });
591
+ const { pi, agentDir, providerId, fastMode, onStatusChange } = options;
573
592
 
574
- pi.registerCommand("cpa-fast", {
575
- description: "Control CLIProxyAPI Fast mode for this session: on, off, or status.",
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
- },
593
+ pi.registerCommand("fast", {
594
+ description: "Toggle CLIProxyAPI Fast mode globally.",
581
595
  handler: async (args, ctx) => {
582
- const action = args.trim().toLowerCase() || "status";
583
- if (action !== "on" && action !== "off" && action !== "status") {
584
- ctx.ui.notify("Usage: /cpa-fast on|off|status", "error");
596
+ if (args.trim()) {
597
+ ctx.ui.notify("Usage: /fast", "error");
585
598
  return;
586
599
  }
587
600
 
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"}`);
601
+ const enabled = !fastMode.isEnabled();
602
+ try {
603
+ saveConfigFile(agentDir, { fast: enabled });
604
+ } catch (error) {
605
+ const message = error instanceof Error ? error.message : String(error);
606
+ ctx.ui.notify(`Failed to save Fast mode: ${message}`, "error");
607
+ return;
593
608
  }
609
+ fastMode.setEnabled(enabled);
610
+ onStatusChange?.(ctx);
594
611
 
595
- const enabled = fastMode.isEnabled();
596
- const source = fastMode.getSource() === "session-override" ? "session override" : "configured default";
597
612
  const currentModel = ctx.model;
598
- let detail: string;
599
- let severity: "info" | "warning" = "info";
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.`;
613
+ if (!currentModel || currentModel.provider !== providerId || !fastMode.isModelSupported(currentModel.id)) {
614
+ if (enabled) {
615
+ ctx.ui.notify("Fast mode is enabled globally, but the current model does not support it.", "warning");
616
+ } else {
617
+ ctx.ui.notify("Fast mode is disabled globally.", "info");
618
+ }
612
619
  }
613
-
614
- ctx.ui.notify(`${providerName} Fast is ${enabled ? "on" : "off"} (${source}). ${detail}`, severity);
615
620
  },
616
621
  });
617
622
  }
@@ -624,14 +629,14 @@ export default async function (pi: ExtensionAPI): Promise<void> {
624
629
  const identity = resolveIdentity(agentDir);
625
630
  const defaultBaseUrl = resolveDefaultBaseUrl(agentDir, identity.providerId);
626
631
 
627
- let fastDefault = false;
632
+ let fastEnabled = false;
628
633
  try {
629
- fastDefault = resolveFastDefault(agentDir);
634
+ fastEnabled = resolveFastDefault(agentDir);
630
635
  } catch (error) {
631
636
  const message = error instanceof Error ? error.message : String(error);
632
637
  logWarn(`invalid Fast configuration (${message}); using fast=false`);
633
638
  }
634
- const fastMode = new FastModeController(fastDefault);
639
+ const fastMode = new FastModeController(fastEnabled);
635
640
 
636
641
  let streamSimple: CliproxyCodexStreamSimple;
637
642
  try {
@@ -645,12 +650,15 @@ export default async function (pi: ExtensionAPI): Promise<void> {
645
650
  return;
646
651
  }
647
652
 
653
+ const fastFooter = new FastFooterController(identity.providerId, fastMode);
648
654
  registerFastCommand({
649
655
  pi,
656
+ agentDir,
650
657
  providerId: identity.providerId,
651
- providerName: identity.providerName,
652
658
  fastMode,
659
+ onStatusChange: (ctx) => fastFooter.refresh(ctx),
653
660
  });
661
+ fastFooter.register(pi);
654
662
 
655
663
  const setupCommands = createSetupCommandsController({
656
664
  pi,
package/extensions/lib.ts CHANGED
@@ -172,8 +172,11 @@ export function loadConfigFile(agentDir: string): CliproxyConfigFile {
172
172
  const configPath = join(agentDir, CONFIG_FILE_NAME);
173
173
  try {
174
174
  const raw = readFileSync(configPath, "utf8");
175
- const parsed = JSON.parse(raw) as CliproxyConfigFile;
176
- return parsed && typeof parsed === "object" ? parsed : {};
175
+ const parsed: unknown = JSON.parse(raw);
176
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
177
+ throw new Error(`${CONFIG_FILE_NAME} must contain a JSON object`);
178
+ }
179
+ return parsed as CliproxyConfigFile;
177
180
  } catch (error) {
178
181
  const err = error as NodeJS.ErrnoException;
179
182
  if (err.code !== "ENOENT") {
@@ -187,13 +190,7 @@ export function saveConfigFile(agentDir: string, config: CliproxyConfigFile): vo
187
190
  const configPath = join(agentDir, CONFIG_FILE_NAME);
188
191
  mkdirSync(dirname(configPath), { recursive: true });
189
192
 
190
- let existing: CliproxyConfigFile = {};
191
- try {
192
- existing = loadConfigFile(agentDir);
193
- } catch {
194
- existing = {};
195
- }
196
-
193
+ const existing = loadConfigFile(agentDir);
197
194
  const next: CliproxyConfigFile = {
198
195
  ...existing,
199
196
  ...config,
@@ -262,7 +259,7 @@ export function parseBooleanSetting(value: string): boolean | undefined {
262
259
  }
263
260
  }
264
261
 
265
- /** Resolve the Fast default from env, then cliproxyapi.json, then false. */
262
+ /** Resolve the Fast preference from env, then cliproxyapi.json, then false. */
266
263
  export function resolveFastDefault(agentDir: string): boolean {
267
264
  const envValue = firstNonEmpty(process.env.CLIPROXYAPI_FAST);
268
265
  if (envValue !== undefined) {
@@ -370,20 +367,7 @@ export function codexModelId(model: CodexClientModel): string {
370
367
  }
371
368
 
372
369
  export function supportsFastServiceTier(model: CodexClientModel): boolean {
373
- const serviceTiers = Array.isArray(model.service_tiers) ? model.service_tiers : [];
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");
370
+ return Array.isArray(model.service_tiers) && model.service_tiers.length > 0;
387
371
  }
388
372
 
389
373
  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.2.2",
3
+ "version": "1.4.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": ">=20"
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",