@luxass/pi-personal 0.2.0 → 0.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luxass/pi-personal",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Personal Pi extensions collected in one package, tuned to a single workflow.",
5
5
  "keywords": [
6
6
  "personal",
@@ -6,6 +6,8 @@
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
+ * - rate-limit errors preserve proxy messages instead of assuming a ChatGPT plan
10
+ * - model cooldown errors include the retry delay and absolute UTC retry time
9
11
  *
10
12
  * The patched module is derived at runtime from the installed
11
13
  * @earendil-works/pi-ai openai-codex-responses implementation so we track
@@ -496,6 +498,45 @@ export function patchCodexSource(source: string, providerIds: string[]): string
496
498
  `const CODEX_TOOL_CALL_PROVIDERS = new Set([${existing}${extras ? `, ${extras}` : ""}]);`,
497
499
  );
498
500
 
501
+ // Crow can route non-OpenAI models. Preserve the proxy's error instead of
502
+ // letting the Codex transport replace every 429 with a ChatGPT-plan warning.
503
+ const usageLimitMessage =
504
+ "friendlyMessage = `You have hit your ChatGPT usage limit${plan}.${when}`.trim();";
505
+ if (!src.includes(usageLimitMessage)) {
506
+ throw new Error("openai-codex-responses source no longer defines the usage-limit message");
507
+ }
508
+ src = src.replace(
509
+ usageLimitMessage,
510
+ "friendlyMessage = err.message || `CLIProxyAPI rate limit or quota exceeded.${when}`.trim();",
511
+ );
512
+ src = src.replace(/^\s*const plan = err\.plan_type \? `[^\n]+` : "";\n/m, "");
513
+
514
+ const errorMessageAssignment = "message = err.message || friendlyMessage || message;";
515
+ if (!src.includes(errorMessageAssignment)) {
516
+ throw new Error("openai-codex-responses source no longer assigns the parsed error message");
517
+ }
518
+ src = src.replace(
519
+ errorMessageAssignment,
520
+ `${errorMessageAssignment}
521
+ if (err.code === "model_cooldown" && typeof err.reset_seconds === "number" && Number.isFinite(err.reset_seconds) && err.reset_seconds >= 0) {
522
+ const seconds = Math.ceil(err.reset_seconds);
523
+ const retryAt = new Date(Date.now() + seconds * 1000);
524
+ if (Number.isFinite(retryAt.getTime())) {
525
+ const hours = Math.floor(seconds / 3600);
526
+ const minutes = Math.floor((seconds % 3600) / 60);
527
+ const remainingSeconds = seconds % 60;
528
+ const duration = [
529
+ hours > 0 ? hours + "h" : "",
530
+ minutes > 0 ? minutes + "m" : "",
531
+ remainingSeconds > 0 || seconds === 0 ? remainingSeconds + "s" : "",
532
+ ].filter(Boolean).join(" ");
533
+ const utc = retryAt.toISOString().replace("T", " ").replace(/\\.\\d{3}Z$/, " UTC");
534
+ message += "\\nNext retry allowed in " + duration + " (" + utc + ").";
535
+ friendlyMessage = message;
536
+ }
537
+ }`,
538
+ );
539
+
499
540
  // Keep assistant message api metadata aligned with the registered custom api id.
500
541
  src = src.replaceAll(
501
542
  `api: "openai-codex-responses"`,