@henryqw/pi-multi-codex 3.1.2 → 3.1.3
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 +2 -2
- package/extensions/multi-codex.ts +9 -22
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -54,9 +54,9 @@ Package-owned: `~/.pi/agent/config/pi-multi-codex/config.json`
|
|
|
54
54
|
|
|
55
55
|
| Name | Description | Values | Default |
|
|
56
56
|
| --- | --- | --- | --- |
|
|
57
|
-
| `autoSwitchOn429` | Switches to another eligible slot after an HTTP 429. | Boolean. | `true`
|
|
57
|
+
| `autoSwitchOn429` | Switches to another eligible slot after an HTTP 429. | Boolean. | `true` |
|
|
58
58
|
|
|
59
|
-
Edit this file yourself. The extension does not create or write it. A missing file uses the default `true`, and config changes take effect at the next session start. Set `autoSwitchOn429` to `false` to disable automatic switching.
|
|
59
|
+
Edit this file yourself. The extension does not create or write it. A missing file uses the default `true`, and config changes take effect at the next session start. Set `autoSwitchOn429` to `false` to disable automatic switching. At session start, the extension shows a warning with the file path for an unknown key, malformed JSON, or a value that is not a boolean. It ignores an unknown key. When `autoSwitchOn429` is not a boolean or is misspelled (for example, `autoswitchOn429`), or when the file has malformed JSON, invalid UTF-8, more than 64 KiB, a read error, or a non-object root, automatic switching stays off for that session. The extension keeps the file unchanged. Fix the file and start a new session to recover.
|
|
60
60
|
|
|
61
61
|
## State and storage
|
|
62
62
|
|
|
@@ -3,7 +3,7 @@ import { readFileSync } from "node:fs";
|
|
|
3
3
|
import { mkdir, readFile } from "node:fs/promises";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { setTimeout as delay } from "node:timers/promises";
|
|
6
|
-
import { createConfigStore, extensionConfigDir, writePrivateTextFileAtomically } from "@henryqw/pi-config-store";
|
|
6
|
+
import { createConfigStore, extensionConfigDir, field, parsers, registerConfigReporting, writePrivateTextFileAtomically } from "@henryqw/pi-config-store";
|
|
7
7
|
import { lock } from "proper-lockfile";
|
|
8
8
|
import {
|
|
9
9
|
createAssistantMessageEventStream,
|
|
@@ -76,7 +76,6 @@ type UsageState = {
|
|
|
76
76
|
};
|
|
77
77
|
|
|
78
78
|
type ParsedUsage = { remaining: number; reset: number; fiveHourReset?: number; limitedUntil?: number; tier?: string };
|
|
79
|
-
type Config = { autoSwitchOn429: boolean };
|
|
80
79
|
|
|
81
80
|
const NATIVE_PROVIDER_ID = "openai-codex";
|
|
82
81
|
const CODEX_ALIAS_PATTERN = /^openai-codex-([2-9]|[1-9]\d+)$/;
|
|
@@ -92,13 +91,6 @@ const CLEANUP_TIMEOUT_MS = 250;
|
|
|
92
91
|
const cachePath = () => join(extensionConfigDir("pi-multi-codex"), "usage.json");
|
|
93
92
|
const cacheMutexPath = () => `${cachePath()}.mutex`;
|
|
94
93
|
|
|
95
|
-
function parseConfig(value: unknown): Config {
|
|
96
|
-
if (!isRecord(value) || Object.keys(value).length !== 1 || typeof value.autoSwitchOn429 !== "boolean") {
|
|
97
|
-
throw new Error("Config must contain only autoSwitchOn429:boolean.");
|
|
98
|
-
}
|
|
99
|
-
return { autoSwitchOn429: value.autoSwitchOn429 };
|
|
100
|
-
}
|
|
101
|
-
|
|
102
94
|
function isRecord(value: unknown): value is JsonRecord {
|
|
103
95
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
104
96
|
}
|
|
@@ -820,11 +812,11 @@ export default function multiCodex(pi: ExtensionAPI): void {
|
|
|
820
812
|
const native = builtinProviders().find((provider) => provider.id === NATIVE_PROVIDER_ID) as CodexProvider | undefined;
|
|
821
813
|
if (!native) return;
|
|
822
814
|
const quota = new CodexQuotaStatus();
|
|
823
|
-
const configStore = createConfigStore
|
|
815
|
+
const configStore = createConfigStore({
|
|
824
816
|
extensionId: "pi-multi-codex",
|
|
825
|
-
|
|
826
|
-
parse: parseConfig,
|
|
817
|
+
fields: { autoSwitchOn429: field(parsers.boolean(), true) },
|
|
827
818
|
});
|
|
819
|
+
registerConfigReporting(pi, [configStore]);
|
|
828
820
|
const registered = new Map<number, CodexProvider>();
|
|
829
821
|
const triedSlots = new Set<number>();
|
|
830
822
|
let sessionContext: ExtensionContext | undefined;
|
|
@@ -833,7 +825,6 @@ export default function multiCodex(pi: ExtensionAPI): void {
|
|
|
833
825
|
let preserveModelChoice = false;
|
|
834
826
|
let selectingAutomatically = false;
|
|
835
827
|
let autoSwitchOn429 = true;
|
|
836
|
-
let configWarned = false;
|
|
837
828
|
let providerRequest: { provider?: string; status?: number } | undefined;
|
|
838
829
|
|
|
839
830
|
const registerSlot = (slot: number): void => {
|
|
@@ -949,15 +940,11 @@ export default function multiCodex(pi: ExtensionAPI): void {
|
|
|
949
940
|
triedSlots.clear();
|
|
950
941
|
providerRequest = undefined;
|
|
951
942
|
preserveModelChoice = false;
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
configWarned = true;
|
|
958
|
-
ctx.ui.notify("Pi Multi Codex config is invalid. Automatic 429 switching is disabled; the file was left unchanged.", "warning");
|
|
959
|
-
}
|
|
960
|
-
}
|
|
943
|
+
// registerConfigReporting shows any issues. A file-level problem or an invalid or misspelled
|
|
944
|
+
// `autoSwitchOn429` keeps switching off; a missing file uses the default.
|
|
945
|
+
const config = configStore.loadSync();
|
|
946
|
+
autoSwitchOn429 = config.status === "ok" && config.value.autoSwitchOn429
|
|
947
|
+
&& !config.issues.some(({ key }) => key === "" || key === "autoSwitchOn429");
|
|
961
948
|
automaticOpen = isManagedModel(ctx.model) && !sessionHasAgentWork(ctx);
|
|
962
949
|
automaticCandidate = ctx.model;
|
|
963
950
|
// Cache-only ranking happens before background refresh starts.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@henryqw/pi-multi-codex",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.3",
|
|
4
4
|
"description": "Use multiple ChatGPT Codex OAuth accounts in Pi.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"image": "https://raw.githubusercontent.com/HenryQW/pi-harness/main/extensions/pi-multi-codex/example.png"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@henryqw/pi-config-store": "^
|
|
50
|
+
"@henryqw/pi-config-store": "^4.0.0",
|
|
51
51
|
"proper-lockfile": "^4.1.2"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|