@router-for-me/pi-cliproxyapi-provider 1.4.24 → 1.4.26

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
@@ -211,6 +211,10 @@ From CPA catalog entry → pi model:
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
 
214
+ ## GPT Responses prompt caching
215
+
216
+ For `gpt-` model IDs (ignoring case and surrounding whitespace), the provider sends the base prompt as the first `developer` input message instead of top-level `instructions`. Nonblank text is kept verbatim; blank text defaults to `You are a helpful assistant.` Existing input items stay in order, tools and `prompt_cache_key` are unchanged, and other models keep their existing request shape. This applies to HTTP and WebSocket requests, including Pi background streams that use this provider. A changed developer prefix or model sends the full input instead of a WebSocket continuation delta.
217
+
214
218
  ## Cache-preserving thinking level changes
215
219
 
216
220
  Models whose catalog entry sets `supports_reasoning_effort_updates` (GPT-6 on CLIProxyAPI) get pi's cache-preserving mid-session thinking level changes, matching the behavior pi >=1.3.0 ships for the OpenAI provider, with placement following the OpenAI documentation: the effort of the first turn becomes the fixed request-level `reasoning.effort`, and each later change is carried by a `configuration_update` input item placed immediately before the user message it applies to, so switching levels mid-session keeps the prompt prefix — and the upstream prompt cache — intact instead of rewriting it. WebSocket `previous_response_id` continuation also survives level changes. Histories lacking initial recorded levels (for example, sessions started before this support landed) may still need one full-context request while the baseline is being established. The behavior requires a pi >=1.3.0 host (its shared Responses converter); on older hosts the plugin detects the missing support and falls back to the classic request-level effort.
@@ -6,6 +6,7 @@
6
6
  * - chatgpt-account-id header is omitted when account id is unavailable
7
7
  * - provider id(s) are added to CODEX_TOOL_CALL_PROVIDERS for tool-call id handling
8
8
  * - model/message api id uses cliproxyapi-codex-responses
9
+ * - GPT base instructions become the first developer input item
9
10
  *
10
11
  * The patched module is derived at runtime from the installed
11
12
  * @earendil-works/pi-ai openai-codex-responses implementation so we track
@@ -19,6 +20,7 @@ import { homedir, tmpdir } from "node:os";
19
20
  import { dirname, join, resolve } from "node:path";
20
21
  import { fileURLToPath, pathToFileURL } from "node:url";
21
22
  import type { Api, AssistantMessageEventStream, Context, Model, SimpleStreamOptions } from "@earendil-works/pi-ai";
23
+ import { getPackageDir } from "@earendil-works/pi-coding-agent";
22
24
 
23
25
  export const CLIPROXYAPI_CODEX_API = "cliproxyapi-codex-responses" as const;
24
26
 
@@ -54,14 +56,17 @@ interface TranscriptMessage {
54
56
  [key: string]: unknown;
55
57
  }
56
58
 
57
- function extractContentText(content: unknown): string {
58
- if (typeof content === "string") return content.trim();
59
+ function isGptModelId(id: unknown): boolean {
60
+ return typeof id === "string" && id.trim().toLowerCase().startsWith("gpt-");
61
+ }
62
+
63
+ function extractContentText(content: unknown, preserveWhitespace: boolean): string {
64
+ if (typeof content === "string") return preserveWhitespace ? content : content.trim();
59
65
  if (Array.isArray(content)) {
60
- return content
66
+ const parts = content
61
67
  .filter((b) => b && typeof b === "object" && b.type === "text" && typeof b.text === "string")
62
- .map((b) => b.text.trim())
63
- .filter(Boolean)
64
- .join("\n");
68
+ .map((b) => b.text as string);
69
+ return (preserveWhitespace ? parts : parts.map((text) => text.trim()).filter(Boolean)).join("\n");
65
70
  }
66
71
  return "";
67
72
  }
@@ -74,7 +79,10 @@ function extractContentText(content: unknown): string {
74
79
  * Classic openai-codex-responses expects context.systemPrompt and context.tools, and fails when
75
80
  * encountering system messages inside context.messages during token estimation or payload generation.
76
81
  */
77
- export function adaptTranscriptContext(context: Context | { messages?: unknown[]; [key: string]: unknown }): Context {
82
+ export function adaptTranscriptContext(
83
+ context: Context | { messages?: unknown[]; [key: string]: unknown },
84
+ preserveSystemWhitespace = false,
85
+ ): Context {
78
86
  if (!context || !Array.isArray(context.messages)) {
79
87
  return context as Context;
80
88
  }
@@ -104,7 +112,7 @@ export function adaptTranscriptContext(context: Context | { messages?: unknown[]
104
112
  if (!msg || typeof msg !== "object") continue;
105
113
 
106
114
  if (msg.role === "system") {
107
- const text = extractContentText(msg.content);
115
+ const text = extractContentText(msg.content, preserveSystemWhitespace);
108
116
  if (text) {
109
117
  leadingText = leadingText ? `${leadingText}\n\n${text}` : text;
110
118
  }
@@ -112,8 +120,9 @@ export function adaptTranscriptContext(context: Context | { messages?: unknown[]
112
120
  for (const [name, sectionText] of Object.entries(msg.sections)) {
113
121
  if (sectionText === null || sectionText === undefined) {
114
122
  sections.delete(name);
115
- } else if (typeof sectionText === "string" && sectionText.trim()) {
116
- sections.set(name, sectionText.trim());
123
+ } else if (typeof sectionText === "string") {
124
+ const section = preserveSystemWhitespace ? sectionText : sectionText.trim();
125
+ if (section) sections.set(name, section);
117
126
  }
118
127
  }
119
128
  }
@@ -193,6 +202,52 @@ export function adaptContextForModule(
193
202
  return supportsTranscript ? ensureTranscriptContext(context) : adaptTranscriptContext(context);
194
203
  }
195
204
 
205
+ function matchesInputText(content: unknown, text: string): boolean {
206
+ if (typeof content === "string") return content === text;
207
+ return (
208
+ Array.isArray(content) &&
209
+ content.every((part) => part?.type === "input_text" && typeof part.text === "string") &&
210
+ content.map((part) => part.text).join("") === text
211
+ );
212
+ }
213
+
214
+ function moveGptInstructionsToInput(
215
+ body: Record<string, unknown>,
216
+ builtInstructions: unknown,
217
+ legacyContext?: Context,
218
+ ): Record<string, unknown> {
219
+ if (!isGptModelId(body.model)) return body;
220
+
221
+ const { input, instructions, ...rest } = body;
222
+ if (input !== undefined && typeof input !== "string" && !Array.isArray(input)) return body;
223
+ const messages =
224
+ typeof input === "string" ? [{ role: "user", content: [{ type: "input_text", text: input }] }] : (input ?? []);
225
+ let prompt = instructions === undefined ? builtInstructions : instructions;
226
+ if (legacyContext && (instructions === undefined || instructions === builtInstructions)) {
227
+ // Recover whitespace only for the outgoing GPT prompt, not the classic context or hook replacements.
228
+ const legacyPrompt = adaptTranscriptContext(legacyContext, true).systemPrompt;
229
+ if (legacyPrompt?.trim()) prompt = legacyPrompt;
230
+ }
231
+ const text = typeof prompt === "string" && prompt.trim() ? prompt : "You are a helpful assistant.";
232
+
233
+ // An unrelated leading developer message must not replace the base prompt.
234
+ const first = messages[0];
235
+ if (
236
+ instructions === undefined &&
237
+ first?.role === "developer" &&
238
+ (first.type === undefined || first.type === "message") &&
239
+ (typeof first.content === "string" || Array.isArray(first.content)) &&
240
+ (builtInstructions === undefined || matchesInputText(first.content, text))
241
+ ) {
242
+ return body;
243
+ }
244
+
245
+ return {
246
+ ...rest,
247
+ input: [{ type: "message", role: "developer", content: [{ type: "input_text", text }] }, ...messages],
248
+ };
249
+ }
250
+
196
251
  export function withPriorityServiceTier(payload: unknown): unknown {
197
252
  if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
198
253
  return payload;
@@ -788,6 +843,19 @@ const CODEX_MODULE_RELATIVE = join(
788
843
  "openai-codex-responses.js",
789
844
  );
790
845
 
846
+ const CODEX_MODULE_FLAT_RELATIVE = join(
847
+ "node_modules",
848
+ "@earendil-works",
849
+ "pi-ai",
850
+ "dist",
851
+ "openai-codex-responses.js",
852
+ );
853
+
854
+ const CODEX_DIST_SUBPATHS = [
855
+ join("dist", "api", "openai-codex-responses.js"),
856
+ join("dist", "openai-codex-responses.js"),
857
+ ] as const;
858
+
791
859
  /**
792
860
  * Well-known filesystem locations for openai-codex-responses.js on bundled hosts.
793
861
  *
@@ -817,6 +885,26 @@ export function wellKnownCodexModuleCandidates(homeDirectory: string): string[]
817
885
  "pi-coding-agent",
818
886
  CODEX_MODULE_RELATIVE,
819
887
  ),
888
+ join(homeDirectory, ".pi", "runtime", CODEX_MODULE_RELATIVE),
889
+ join(homeDirectory, ".pi", "runtime", CODEX_MODULE_FLAT_RELATIVE),
890
+ join(
891
+ homeDirectory,
892
+ ".pi",
893
+ "runtime",
894
+ "node_modules",
895
+ "@earendil-works",
896
+ "pi-coding-agent",
897
+ CODEX_MODULE_RELATIVE,
898
+ ),
899
+ join(
900
+ homeDirectory,
901
+ ".pi",
902
+ "runtime",
903
+ "node_modules",
904
+ "@earendil-works",
905
+ "pi-coding-agent",
906
+ CODEX_MODULE_FLAT_RELATIVE,
907
+ ),
820
908
  join(homeDirectory, ".bun", "install", "global", CODEX_MODULE_RELATIVE),
821
909
  join(
822
910
  homeDirectory,
@@ -1047,16 +1135,33 @@ export function resolveCodexModuleFromNodeEntry(entryPath: string): string | und
1047
1135
  const real = realpathSync(current);
1048
1136
  const require = createRequire(pathToFileURL(real));
1049
1137
  for (const nodeModulesDir of require.resolve.paths("@earendil-works/pi-ai") ?? []) {
1050
- const candidate = join(
1051
- nodeModulesDir,
1052
- "@earendil-works",
1053
- "pi-ai",
1054
- "dist",
1055
- "api",
1056
- "openai-codex-responses.js",
1057
- );
1058
- if (existsSync(candidate)) {
1059
- return candidate;
1138
+ for (const distSubpath of CODEX_DIST_SUBPATHS) {
1139
+ const directCandidate = join(nodeModulesDir, "@earendil-works", "pi-ai", distSubpath);
1140
+ if (existsSync(directCandidate)) {
1141
+ return directCandidate;
1142
+ }
1143
+ const nestedCandidate = join(
1144
+ nodeModulesDir,
1145
+ "@earendil-works",
1146
+ "pi-coding-agent",
1147
+ "node_modules",
1148
+ "@earendil-works",
1149
+ "pi-ai",
1150
+ distSubpath,
1151
+ );
1152
+ if (existsSync(nestedCandidate)) {
1153
+ return nestedCandidate;
1154
+ }
1155
+ }
1156
+ }
1157
+
1158
+ // Managed Pi launcher (<agentDir>/bin/pi -> <agentDir>/install/releases/<version>)
1159
+ const managedInstallDir = join(dirname(dirname(real)), "install");
1160
+ const managedCurrentVersionPath = join(managedInstallDir, "current-version");
1161
+ if (existsSync(managedCurrentVersionPath)) {
1162
+ const currentVersion = readFileSync(managedCurrentVersionPath, "utf8").trim();
1163
+ if (currentVersion) {
1164
+ queue.push(join(managedInstallDir, "releases", currentVersion, "package.json"));
1060
1165
  }
1061
1166
  }
1062
1167
 
@@ -1071,12 +1176,32 @@ export function resolveCodexModuleFromNodeEntry(entryPath: string): string | und
1071
1176
  queue.push(resolve(dirname(real), ref));
1072
1177
  }
1073
1178
  }
1074
- const homeJoinMatch = content.match(
1075
- /join\s*\(\s*(?:homedir\(\)|process\.env\.HOME)[^)]*["']([^"']+)["']\s*\)/,
1076
- );
1077
- if (homeJoinMatch) {
1078
- const home = process.env.HOME || process.env.USERPROFILE || homedir();
1079
- queue.push(join(home, homeJoinMatch[1]));
1179
+ const defaultHome = process.env.HOME || process.env.USERPROFILE || homedir();
1180
+ for (const homeJoinMatch of content.matchAll(
1181
+ /join\s*\(\s*(homedir\(\)|process\.env\.HOME\b|process\.env\.USERPROFILE\b)\s*,([^)]*)\)/g,
1182
+ )) {
1183
+ const baseExpr = homeJoinMatch[1] ?? "";
1184
+ const baseHomes =
1185
+ baseExpr === "process.env.USERPROFILE"
1186
+ ? [process.env.USERPROFILE || defaultHome]
1187
+ : baseExpr === "process.env.HOME"
1188
+ ? [process.env.HOME || defaultHome]
1189
+ : Array.from(new Set([homedir(), defaultHome].filter(Boolean)));
1190
+ const argsText = homeJoinMatch[2] ?? "";
1191
+ const segments = [...argsText.matchAll(/["'`]([^"'`\r\n]+)["'`]/g)]
1192
+ .map((m) => m[1]?.trim())
1193
+ .filter((s): s is string => Boolean(s));
1194
+ if (segments.length > 0) {
1195
+ for (const baseHome of baseHomes) {
1196
+ queue.push(join(baseHome, ...segments));
1197
+ }
1198
+ }
1199
+ }
1200
+ for (const shellHomeMatch of content.matchAll(/["'`]?(?:~|\$HOME|\$\{HOME\})([\\/][^"'`\s\r\n]+)["'`]?/g)) {
1201
+ const rel = shellHomeMatch[1]?.trim();
1202
+ if (rel) {
1203
+ queue.push(join(defaultHome, rel.replace(/^[\\/]+/, "")));
1204
+ }
1080
1205
  }
1081
1206
  }
1082
1207
  } catch {
@@ -1086,6 +1211,38 @@ export function resolveCodexModuleFromNodeEntry(entryPath: string): string | und
1086
1211
  return undefined;
1087
1212
  }
1088
1213
 
1214
+ function resolveManagedInstallCandidates(homeDirectory: string): string[] {
1215
+ const installDirs = [join(homeDirectory, ".pi", "agent", "install")];
1216
+ const candidates: string[] = [];
1217
+ for (const installDir of installDirs) {
1218
+ try {
1219
+ const currentVersionPath = join(installDir, "current-version");
1220
+ if (!existsSync(currentVersionPath)) continue;
1221
+ const currentVersion = readFileSync(currentVersionPath, "utf8").trim();
1222
+ if (!currentVersion) continue;
1223
+ const releaseDir = join(installDir, "releases", currentVersion);
1224
+ candidates.push(
1225
+ join(releaseDir, CODEX_MODULE_RELATIVE),
1226
+ join(releaseDir, CODEX_MODULE_FLAT_RELATIVE),
1227
+ join(releaseDir, "node_modules", "@earendil-works", "pi-coding-agent", CODEX_MODULE_RELATIVE),
1228
+ join(releaseDir, "node_modules", "@earendil-works", "pi-coding-agent", CODEX_MODULE_FLAT_RELATIVE),
1229
+ );
1230
+ } catch {
1231
+ // Ignore unreadable managed install state.
1232
+ }
1233
+ }
1234
+ return candidates;
1235
+ }
1236
+
1237
+ function expandCodexCandidateVariants(candidate: string): string[] {
1238
+ const apiSuffix = join("dist", "api", "openai-codex-responses.js");
1239
+ if (candidate.endsWith(apiSuffix)) {
1240
+ const flatCandidate = `${candidate.slice(0, -apiSuffix.length)}${join("dist", "openai-codex-responses.js")}`;
1241
+ return [candidate, flatCandidate];
1242
+ }
1243
+ return [candidate];
1244
+ }
1245
+
1089
1246
  export function computePatchedModuleCachePath(
1090
1247
  originalPath: string,
1091
1248
  patchedSource: string,
@@ -1143,9 +1300,30 @@ export function resolveOriginalCodexModulePath(options: ResolveOriginalCodexModu
1143
1300
  }
1144
1301
  }
1145
1302
 
1146
- // Also check well-known CLI binaries if nodeEntry wasn't explicitly provided in options
1303
+ // Also check the active pi-coding-agent package root and well-known CLI binaries
1304
+ // if nodeEntry wasn't explicitly provided in options (e.g. inside subagent runners).
1305
+ if (!("nodeEntry" in options) && !("resolveSpecifier" in options)) {
1306
+ try {
1307
+ if (typeof getPackageDir === "function") {
1308
+ const packageDir = getPackageDir();
1309
+ if (packageDir) {
1310
+ const bundledHostModule = resolveCodexModuleFromNodeEntry(join(packageDir, "package.json"));
1311
+ if (bundledHostModule && existsSync(bundledHostModule)) {
1312
+ return { path: bundledHostModule, dir: dirname(bundledHostModule) };
1313
+ }
1314
+ }
1315
+ }
1316
+ } catch {
1317
+ // Ignore when host does not expose a resolvable package directory.
1318
+ }
1319
+ }
1320
+
1147
1321
  if (!("nodeEntry" in options) && homeDirectory) {
1148
1322
  const wellKnownEntries = [
1323
+ join(homeDirectory, ".pi", "bin", "pi"),
1324
+ join(homeDirectory, ".pi", "agent", "bin", "pi"),
1325
+ join(homeDirectory, ".pi", "runtime", "bin", "pi"),
1326
+ join(homeDirectory, ".pi", "runtime", "node_modules", ".bin", "pi"),
1149
1327
  join(homeDirectory, ".bun", "bin", "pi"),
1150
1328
  join(homeDirectory, ".local", "bin", "pi"),
1151
1329
  join(homeDirectory, ".npm-global", "bin", "pi"),
@@ -1172,19 +1350,45 @@ export function resolveOriginalCodexModulePath(options: ResolveOriginalCodexModu
1172
1350
  try {
1173
1351
  const main = fileURLToPath(resolveSpecifier("@earendil-works/pi-ai"));
1174
1352
  const distDir = dirname(main);
1175
- candidates.push(join(distDir, "api/openai-codex-responses.js"));
1176
- candidates.push(join(distDir, "openai-codex-responses.js"));
1353
+ const directCandidates = [
1354
+ join(distDir, "api/openai-codex-responses.js"),
1355
+ join(distDir, "openai-codex-responses.js"),
1356
+ ];
1357
+ candidates.push(...directCandidates);
1358
+ // Pi >=1.5 maps @earendil-works/pi-ai to pi-coding-agent's extension view
1359
+ // rather than pi-ai/dist. Resolve the physical pi-ai module from that host entry.
1360
+ if (!directCandidates.some((candidate) => existsSync(candidate))) {
1361
+ const hostModule = resolveCodexModuleFromNodeEntry(main);
1362
+ if (hostModule) {
1363
+ candidates.push(hostModule);
1364
+ }
1365
+ }
1177
1366
  } catch {
1178
1367
  // ignore
1179
1368
  }
1180
1369
 
1370
+ if (!candidates.some((candidate) => candidate && existsSync(candidate))) {
1371
+ try {
1372
+ const hostEntry = fileURLToPath(resolveSpecifier("@earendil-works/pi-coding-agent"));
1373
+ const hostModule = resolveCodexModuleFromNodeEntry(hostEntry);
1374
+ if (hostModule) {
1375
+ candidates.push(hostModule);
1376
+ }
1377
+ } catch {
1378
+ // ignore
1379
+ }
1380
+ }
1381
+
1181
1382
  if (homeDirectory) {
1383
+ candidates.push(...resolveManagedInstallCandidates(homeDirectory));
1182
1384
  candidates.push(...wellKnownCodexModuleCandidates(homeDirectory));
1183
1385
  }
1184
1386
 
1185
- for (const path of candidates) {
1186
- if (path && existsSync(path)) {
1187
- return { path, dir: dirname(path) };
1387
+ for (const candidate of candidates) {
1388
+ for (const path of expandCodexCandidateVariants(candidate)) {
1389
+ if (path && existsSync(path)) {
1390
+ return { path, dir: dirname(path) };
1391
+ }
1188
1392
  }
1189
1393
  }
1190
1394
 
@@ -1203,11 +1407,19 @@ export async function loadCliproxyCodexStreams(
1203
1407
  // older hosts keep the classic request-level effort instead of pinning it
1204
1408
  // to the baseline without carrying the real level.
1205
1409
  const sharedSource = (() => {
1206
- try {
1207
- return readFileSync(join(dirname(originalPath), "openai-responses-shared.js"), "utf8");
1208
- } catch {
1209
- return "";
1410
+ for (const candidate of [
1411
+ join(dirname(originalPath), "openai-responses-shared.js"),
1412
+ join(dirname(originalPath), "api", "openai-responses-shared.js"),
1413
+ ]) {
1414
+ try {
1415
+ if (existsSync(candidate)) {
1416
+ return readFileSync(candidate, "utf8");
1417
+ }
1418
+ } catch {
1419
+ // try next
1420
+ }
1210
1421
  }
1422
+ return "";
1211
1423
  })();
1212
1424
  const supportsConfigurationUpdate = sharedSupportsConfigurationUpdate(sharedSource);
1213
1425
  const patched = patchCodexSource(originalSource, providerIds, { supportsConfigurationUpdate });
@@ -1255,25 +1467,30 @@ export async function loadCliproxyCodexStreams(
1255
1467
  // follows pi's converter layout; reshape payloads to the documented layout
1256
1468
  // in the wrapper instead of inside the patched module.
1257
1469
  const nativeMidConvoEffort = hasNativeMidConvoEffort(originalSource);
1258
- const adaptOptions = (streamOptions?: SimpleStreamOptions): SimpleStreamOptions | undefined => {
1259
- if (!nativeMidConvoEffort) {
1260
- return streamOptions;
1261
- }
1262
- return {
1263
- ...streamOptions,
1264
- onPayload: async (payload, payloadModel) => {
1265
- const nextPayload = await streamOptions?.onPayload?.(payload, payloadModel);
1266
- const effective = (nextPayload === undefined ? payload : nextPayload) as Record<string, unknown>;
1267
- return effective && typeof effective === "object" ? reshapeConfigurationUpdates(effective) : effective;
1268
- },
1269
- };
1270
- };
1470
+ const adaptOptions = (context: Context, streamOptions?: SimpleStreamOptions): SimpleStreamOptions => ({
1471
+ ...streamOptions,
1472
+ onPayload: async (payload, payloadModel) => {
1473
+ const builtInstructions =
1474
+ payload && typeof payload === "object" && "instructions" in payload ? payload.instructions : undefined;
1475
+ const nextPayload = await streamOptions?.onPayload?.(payload, payloadModel);
1476
+ const effective = nextPayload === undefined ? payload : nextPayload;
1477
+ if (!effective || typeof effective !== "object" || Array.isArray(effective)) return effective;
1478
+
1479
+ const body = effective as Record<string, unknown>;
1480
+ // Prefix the final full body before either transport, including WebSocket delta detection.
1481
+ return moveGptInstructionsToInput(
1482
+ nativeMidConvoEffort ? reshapeConfigurationUpdates(body) : body,
1483
+ builtInstructions,
1484
+ supportsTranscript ? undefined : context,
1485
+ );
1486
+ },
1487
+ });
1271
1488
 
1272
1489
  const adaptedStreamSimple: CliproxyCodexStreamSimple = (model, context, streamOptions) => {
1273
- return mod.streamSimple(adaptModel(model), adaptContext(context), adaptOptions(streamOptions));
1490
+ return mod.streamSimple(adaptModel(model), adaptContext(context), adaptOptions(context, streamOptions));
1274
1491
  };
1275
1492
  const adaptedStream: CliproxyCodexStreamSimple = (model, context, streamOptions) => {
1276
- return mod.stream(adaptModel(model), adaptContext(context), adaptOptions(streamOptions));
1493
+ return mod.stream(adaptModel(model), adaptContext(context), adaptOptions(context, streamOptions));
1277
1494
  };
1278
1495
 
1279
1496
  const streamSimple = wrapStreamSimpleForFast(adaptedStreamSimple, options.shouldUseFast);
@@ -796,9 +796,11 @@ export default async function (pi: ExtensionAPI): Promise<void> {
796
796
  const fastMode = new FastModeController(fastEnabled);
797
797
  const modelRefreshCoordinator = new ModelRefreshCoordinator();
798
798
 
799
+ let streamLoadError: string | undefined;
799
800
  let streamSimple: CliproxyCodexStreamSimple = () => {
801
+ const suffix = streamLoadError ? `: ${streamLoadError}` : "";
800
802
  throw new Error(
801
- `Codex protocol stream is unavailable for provider: ${identity.providerId} (api: ${CLIPROXYAPI_CODEX_API})`,
803
+ `Codex protocol stream is unavailable for provider: ${identity.providerId} (api: ${CLIPROXYAPI_CODEX_API})${suffix}`,
802
804
  );
803
805
  };
804
806
  try {
@@ -891,6 +893,7 @@ export default async function (pi: ExtensionAPI): Promise<void> {
891
893
  }
892
894
  } catch (error) {
893
895
  const message = error instanceof Error ? error.message : String(error);
896
+ streamLoadError = message;
894
897
  logWarn(`failed to load patched codex protocol: ${message}`);
895
898
  }
896
899
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@router-for-me/pi-cliproxyapi-provider",
3
- "version": "1.4.24",
3
+ "version": "1.4.26",
4
4
  "description": "Pi provider extension that auto-registers CLIProxyAPI models, plus TUI elapsed/TPS status",
5
5
  "type": "module",
6
6
  "keywords": [