@cortexkit/opencode-openai-auth 0.11.0 → 1.0.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 +15 -26
- package/dist/index-766sfrh5.js +1 -0
- package/dist/index-8kj7sa1p.js +12 -0
- package/dist/index-8rqfbhfw.js +221 -0
- package/dist/index-b3q3j39x.js +2 -0
- package/dist/index-bmd7x5aq.js +2 -0
- package/dist/index-eqh53k8v.js +2 -0
- package/dist/{index-sdt2d2ra.js → index-hy9030jh.js} +1 -1
- package/dist/index-jyr8y8k4.js +7 -0
- package/dist/index-rv08jmd4.js +2 -0
- package/dist/index.d.ts +578 -145
- package/dist/index.js +1 -110
- package/dist/pool-lifecycle-DbDmgabd.d.ts +2430 -0
- package/dist/port-file-Do3lQIEk.d.ts +29 -0
- package/dist/protocol-BOBdkqqm.d.ts +198 -0
- package/dist/rpc/port-file.d.ts +4 -17
- package/dist/rpc/port-file.js +1 -1
- package/dist/rpc/protocol.d.ts +2 -2
- package/dist/rpc/protocol.js +1 -0
- package/dist/rpc/rpc-client.d.ts +5 -4
- package/dist/rpc/rpc-client.js +1 -1
- package/dist/rpc/rpc-dir.d.ts +2 -0
- package/dist/rpc/rpc-dir.js +1 -1
- package/dist/sidebar-state-D6cUKgkm.d.ts +385 -0
- package/dist/sidebar-state.d.ts +2 -2
- package/dist/sidebar-state.js +1 -1
- package/dist/token-util-wdza526f.js +1 -0
- package/dist/{token-9823y0pc.js → token-ypk61xj0.js} +1 -1
- package/dist/tui-preferences.js +5 -2
- package/dist/tui.d.ts +9 -4
- package/dist/v2/server.d.ts +54 -0
- package/dist/v2/server.js +4 -0
- package/package.json +21 -9
- package/src/tui/entry.mjs +26 -25
- package/src/tui-compiled/raw/logger.js +24 -0
- package/src/tui-compiled/raw/rpc/protocol.js +3 -0
- package/src/tui-compiled/raw/rpc/rpc-client.js +7 -0
- package/src/tui-compiled/raw/rpc/rpc-dir.js +27 -0
- package/src/tui-compiled/raw/selector.js +21 -0
- package/src/tui-compiled/raw/shared/0332701351b3eeec-format.js +138 -0
- package/src/tui-compiled/raw/shared/04a6357627de5ed0-errors.js +38 -0
- package/src/tui-compiled/raw/shared/053cc17b5419261e-codec.js +12 -0
- package/src/tui-compiled/raw/shared/0766d78c6f481f18-watcher.js +157 -0
- package/src/tui-compiled/raw/shared/08eef45626a94992-reserved.js +13 -0
- package/src/tui-compiled/raw/shared/39c3cb05738fcf6d-projection.js +134 -0
- package/src/tui-compiled/raw/shared/3c2d4169d00f907e-tui-support.js +5 -0
- package/src/tui-compiled/raw/shared/3e7d45a77c6ad4d5-index.js +4 -0
- package/src/tui-compiled/raw/shared/415792e85d80819e-capture-sink.js +13 -0
- package/src/tui-compiled/raw/shared/42ae93ab554fcec2-open-url.js +28 -0
- package/src/tui-compiled/raw/shared/43fc9e6b994519c7-refresh-lock.js +136 -0
- package/src/tui-compiled/raw/shared/458b934e92490331-mutate.js +500 -0
- package/src/tui-compiled/raw/shared/45bf5343bbbf9add-admission.js +142 -0
- package/src/tui-compiled/raw/shared/46f3dff1266160e8-client.js +2 -0
- package/src/tui-compiled/raw/shared/4825e03209d6ae3e-with-lock.js +48 -0
- package/src/tui-compiled/raw/shared/4f36d333d081d040-merge.js +162 -0
- package/src/tui-compiled/raw/shared/54eba94fd64c8c3c-index.js +7 -0
- package/src/tui-compiled/raw/shared/7211cfec06a298bc-atomic-write.js +80 -0
- package/src/tui-compiled/raw/shared/754d6017f8e419cf-builtins.js +534 -0
- package/src/tui-compiled/raw/shared/75bd8c3bd63b315f-identity.js +79 -0
- package/src/tui-compiled/raw/shared/7a91bb630e6f4804-index.js +1 -0
- package/src/tui-compiled/raw/shared/826342a4b6a8b89b-model.js +16 -0
- package/src/tui-compiled/raw/shared/83068c0dbe8a6f13-publication.js +304 -0
- package/src/tui-compiled/raw/shared/836fc615de6afbd9-settings.js +120 -0
- package/src/tui-compiled/raw/shared/83bc3ba9d0fe2761-runtime.js +68 -0
- package/src/tui-compiled/raw/shared/8a18abe4fa2977c8-menu.js +300 -0
- package/src/tui-compiled/raw/shared/901e149c5a0dbbff-sticky.js +339 -0
- package/src/tui-compiled/raw/shared/9020c407ce64f672-ordered.js +58 -0
- package/src/tui-compiled/raw/shared/905bffc0220f43d0-map.js +105 -0
- package/src/tui-compiled/raw/shared/94820e324f2b4c09-seam.js +301 -0
- package/src/tui-compiled/raw/shared/97484d9bb98c705b-provider-state.js +226 -0
- package/src/tui-compiled/raw/shared/9968e3cade6969a1-index.js +2 -0
- package/src/tui-compiled/raw/shared/9b4da614c45f9cd0-lock-constants.js +14 -0
- package/src/tui-compiled/raw/shared/9d3fc9e37456504e-refresh.js +225 -0
- package/src/tui-compiled/raw/shared/9deae3c4da4fd63b-hooks.js +34 -0
- package/src/tui-compiled/raw/shared/a09b6a533c11858f-tui-preferences.js +77 -0
- package/src/tui-compiled/raw/shared/a62a27a204266acd-attribution.js +60 -0
- package/src/tui-compiled/raw/shared/a910277ac43a8626-pull.js +143 -0
- package/src/tui-compiled/raw/shared/b85c5301fddcb98a-paths.js +5 -0
- package/src/tui-compiled/raw/shared/c14988621dc60a75-port-file.js +217 -0
- package/src/tui-compiled/raw/shared/c64d7afbc14ca125-sidebar-file.js +157 -0
- package/src/tui-compiled/raw/shared/c6b176708c446d6d-pins.js +34 -0
- package/src/tui-compiled/raw/shared/c7d252bedee01600-pi.js +206 -0
- package/src/tui-compiled/raw/shared/c852a15cfe489d12-pool.js +120 -0
- package/src/tui-compiled/raw/shared/cc9e0702a752cea7-index.js +3 -0
- package/src/tui-compiled/raw/shared/cd94316a888b0a8e-schema.js +754 -0
- package/src/tui-compiled/raw/shared/d319517e3ea6ad70-redact.js +83 -0
- package/src/tui-compiled/raw/shared/d5a8f1061ee2f114-index.js +5 -0
- package/src/tui-compiled/raw/shared/d669d72c40e9e116-logger.js +19 -0
- package/src/tui-compiled/raw/shared/d7dcba96fea1685c-engine.js +246 -0
- package/src/tui-compiled/raw/shared/dbef697d1df1cd84-index.js +5 -0
- package/src/tui-compiled/raw/shared/e4acc4cb713f300c-protocol.js +3 -0
- package/src/tui-compiled/raw/shared/e8cd4929507508d8-refresh-file-lock.js +501 -0
- package/src/tui-compiled/raw/shared/ec971142548df90e-index.js +6 -0
- package/src/tui-compiled/raw/shared/f37fcefc7aedbf25-error.js +11 -0
- package/src/tui-compiled/raw/shared/fbcdcd0f925e74c0-rpc-client.js +253 -0
- package/src/tui-compiled/raw/shared/fd45e82f2f9c0a0d-torn.js +294 -0
- package/src/tui-compiled/raw/shared/fe02abeadc535f77-rows.js +1258 -0
- package/src/tui-compiled/raw/sidebar-state.js +960 -0
- package/src/tui-compiled/raw/tui/command-dialogs.tsx +424 -0
- package/src/tui-compiled/raw/tui-preferences.js +135 -0
- package/src/tui-compiled/raw/tui.tsx +135 -143
- package/src/tui-compiled/runtime/logger.js +24 -0
- package/src/tui-compiled/runtime/rpc/protocol.js +3 -0
- package/src/tui-compiled/runtime/rpc/rpc-client.js +7 -0
- package/src/tui-compiled/runtime/rpc/rpc-dir.js +27 -0
- package/src/tui-compiled/runtime/selector.js +21 -0
- package/src/tui-compiled/runtime/shared/0332701351b3eeec-format.js +138 -0
- package/src/tui-compiled/runtime/shared/04a6357627de5ed0-errors.js +38 -0
- package/src/tui-compiled/runtime/shared/053cc17b5419261e-codec.js +12 -0
- package/src/tui-compiled/runtime/shared/0766d78c6f481f18-watcher.js +157 -0
- package/src/tui-compiled/runtime/shared/08eef45626a94992-reserved.js +13 -0
- package/src/tui-compiled/runtime/shared/39c3cb05738fcf6d-projection.js +134 -0
- package/src/tui-compiled/runtime/shared/3c2d4169d00f907e-tui-support.js +5 -0
- package/src/tui-compiled/runtime/shared/3e7d45a77c6ad4d5-index.js +4 -0
- package/src/tui-compiled/runtime/shared/415792e85d80819e-capture-sink.js +13 -0
- package/src/tui-compiled/runtime/shared/42ae93ab554fcec2-open-url.js +28 -0
- package/src/tui-compiled/runtime/shared/43fc9e6b994519c7-refresh-lock.js +136 -0
- package/src/tui-compiled/runtime/shared/458b934e92490331-mutate.js +500 -0
- package/src/tui-compiled/runtime/shared/45bf5343bbbf9add-admission.js +142 -0
- package/src/tui-compiled/runtime/shared/46f3dff1266160e8-client.js +2 -0
- package/src/tui-compiled/runtime/shared/4825e03209d6ae3e-with-lock.js +48 -0
- package/src/tui-compiled/runtime/shared/4f36d333d081d040-merge.js +162 -0
- package/src/tui-compiled/runtime/shared/54eba94fd64c8c3c-index.js +7 -0
- package/src/tui-compiled/runtime/shared/7211cfec06a298bc-atomic-write.js +80 -0
- package/src/tui-compiled/runtime/shared/754d6017f8e419cf-builtins.js +534 -0
- package/src/tui-compiled/runtime/shared/75bd8c3bd63b315f-identity.js +79 -0
- package/src/tui-compiled/runtime/shared/7a91bb630e6f4804-index.js +1 -0
- package/src/tui-compiled/runtime/shared/826342a4b6a8b89b-model.js +16 -0
- package/src/tui-compiled/runtime/shared/83068c0dbe8a6f13-publication.js +304 -0
- package/src/tui-compiled/runtime/shared/836fc615de6afbd9-settings.js +120 -0
- package/src/tui-compiled/runtime/shared/83bc3ba9d0fe2761-runtime.js +68 -0
- package/src/tui-compiled/runtime/shared/8a18abe4fa2977c8-menu.js +300 -0
- package/src/tui-compiled/runtime/shared/901e149c5a0dbbff-sticky.js +339 -0
- package/src/tui-compiled/runtime/shared/9020c407ce64f672-ordered.js +58 -0
- package/src/tui-compiled/runtime/shared/905bffc0220f43d0-map.js +105 -0
- package/src/tui-compiled/runtime/shared/94820e324f2b4c09-seam.js +301 -0
- package/src/tui-compiled/runtime/shared/97484d9bb98c705b-provider-state.js +226 -0
- package/src/tui-compiled/runtime/shared/9968e3cade6969a1-index.js +2 -0
- package/src/tui-compiled/runtime/shared/9b4da614c45f9cd0-lock-constants.js +14 -0
- package/src/tui-compiled/runtime/shared/9d3fc9e37456504e-refresh.js +225 -0
- package/src/tui-compiled/runtime/shared/9deae3c4da4fd63b-hooks.js +34 -0
- package/src/tui-compiled/runtime/shared/a09b6a533c11858f-tui-preferences.js +77 -0
- package/src/tui-compiled/runtime/shared/a62a27a204266acd-attribution.js +60 -0
- package/src/tui-compiled/runtime/shared/a910277ac43a8626-pull.js +143 -0
- package/src/tui-compiled/runtime/shared/b85c5301fddcb98a-paths.js +5 -0
- package/src/tui-compiled/runtime/shared/c14988621dc60a75-port-file.js +217 -0
- package/src/tui-compiled/runtime/shared/c64d7afbc14ca125-sidebar-file.js +157 -0
- package/src/tui-compiled/runtime/shared/c6b176708c446d6d-pins.js +34 -0
- package/src/tui-compiled/runtime/shared/c7d252bedee01600-pi.js +206 -0
- package/src/tui-compiled/runtime/shared/c852a15cfe489d12-pool.js +120 -0
- package/src/tui-compiled/runtime/shared/cc9e0702a752cea7-index.js +3 -0
- package/src/tui-compiled/runtime/shared/cd94316a888b0a8e-schema.js +754 -0
- package/src/tui-compiled/runtime/shared/d319517e3ea6ad70-redact.js +83 -0
- package/src/tui-compiled/runtime/shared/d5a8f1061ee2f114-index.js +5 -0
- package/src/tui-compiled/runtime/shared/d669d72c40e9e116-logger.js +19 -0
- package/src/tui-compiled/runtime/shared/d7dcba96fea1685c-engine.js +246 -0
- package/src/tui-compiled/runtime/shared/dbef697d1df1cd84-index.js +5 -0
- package/src/tui-compiled/runtime/shared/e4acc4cb713f300c-protocol.js +3 -0
- package/src/tui-compiled/runtime/shared/e8cd4929507508d8-refresh-file-lock.js +501 -0
- package/src/tui-compiled/runtime/shared/ec971142548df90e-index.js +6 -0
- package/src/tui-compiled/runtime/shared/f37fcefc7aedbf25-error.js +11 -0
- package/src/tui-compiled/runtime/shared/fbcdcd0f925e74c0-rpc-client.js +253 -0
- package/src/tui-compiled/runtime/shared/fd45e82f2f9c0a0d-torn.js +294 -0
- package/src/tui-compiled/runtime/shared/fe02abeadc535f77-rows.js +1258 -0
- package/src/tui-compiled/runtime/sidebar-state.js +960 -0
- package/src/tui-compiled/runtime/tui/command-dialogs.js +378 -0
- package/src/tui-compiled/runtime/tui-preferences.js +135 -0
- package/src/tui-compiled/runtime/{tui.tsx → tui.js} +288 -316
- package/dist/index-4effjmr6.js +0 -2
- package/dist/index-9ehhb051.js +0 -2
- package/dist/index-g3hsdjh4.js +0 -2
- package/dist/index-hh52v8sb.js +0 -2
- package/dist/index-jwn4r3sw.js +0 -1
- package/dist/index-sq36b120.js +0 -211
- package/dist/internal-BTndPmW2.d.ts +0 -914
- package/dist/quota-normalize-08hpp51v.js +0 -1
- package/dist/sidebar-state-CoKYKcLn.d.ts +0 -220
- package/dist/token-util-ypgz7rge.js +0 -1
- package/src/tui-compiled/raw/core-account-paths.ts +0 -114
- package/src/tui-compiled/raw/core-custody-state.ts +0 -243
- package/src/tui-compiled/raw/logger.ts +0 -53
- package/src/tui-compiled/raw/rpc-port-file.ts +0 -177
- package/src/tui-compiled/raw/rpc-protocol.ts +0 -12
- package/src/tui-compiled/raw/rpc-rpc-client.ts +0 -82
- package/src/tui-compiled/raw/rpc-rpc-dir.ts +0 -46
- package/src/tui-compiled/raw/sidebar-state.ts +0 -1659
- package/src/tui-compiled/raw/tui-command-dialogs.tsx +0 -1096
- package/src/tui-compiled/raw/tui-preferences.ts +0 -328
- package/src/tui-compiled/runtime/core-account-paths.ts +0 -114
- package/src/tui-compiled/runtime/core-custody-state.ts +0 -243
- package/src/tui-compiled/runtime/logger.ts +0 -53
- package/src/tui-compiled/runtime/rpc-port-file.ts +0 -177
- package/src/tui-compiled/runtime/rpc-protocol.ts +0 -12
- package/src/tui-compiled/runtime/rpc-rpc-client.ts +0 -82
- package/src/tui-compiled/runtime/rpc-rpc-dir.ts +0 -46
- package/src/tui-compiled/runtime/sidebar-state.ts +0 -1659
- package/src/tui-compiled/runtime/tui-command-dialogs.tsx +0 -855
- package/src/tui-compiled/runtime/tui-preferences.ts +0 -328
- package/src/tui-compiled/shared/internal.ts +0 -6
- package/src/tui-compiled/shared/logger.ts +0 -264
- package/src/tui-compiled/shared/paths.ts +0 -33
- package/src/tui-compiled/shared/refresh-file-lock.ts +0 -384
- package/src/tui-compiled/shared/util/error.ts +0 -9
- package/src/tui-compiled/shared/util/open-url.ts +0 -30
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ The plugin registers the built-in `openai` provider id. OpenCode loads external
|
|
|
10
10
|
|
|
11
11
|
```json
|
|
12
12
|
{
|
|
13
|
-
"plugin": ["@cortexkit/opencode-openai-auth@0.
|
|
13
|
+
"plugin": ["@cortexkit/opencode-openai-auth@1.0.0"]
|
|
14
14
|
}
|
|
15
15
|
```
|
|
16
16
|
|
|
@@ -20,6 +20,16 @@ Restart OpenCode after changing plugin config, then authenticate:
|
|
|
20
20
|
/login openai
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
+
If this OpenCode host is already enrolled in the Claustrum vault, choose **ChatGPT accounts in the vault** instead of signing in to ChatGPT. This no-browser activation creates no local account and gives OpenCode only a non-routable placeholder. OpenCode 1 refuses to replace any existing `openai` record in `auth.json`, and refuses malformed or unreadable files without changing them; a missing file is allowed on a fresh install. Enrollment is checked again before activation completes.
|
|
24
|
+
|
|
25
|
+
## OpenCode 2
|
|
26
|
+
|
|
27
|
+
On OpenCode 2 (`@opencode/cli`, tested on 2.0.22) list the same package under `plugins`; OpenCode 2 loads its `./server` entry. OpenCode 2's own OpenAI driver sends the requests, and the plugin chooses the account from the shared account pool and sets its credential through OpenCode 2's session hooks. Signing in with one of the plugin's pool methods (`opencode auth login openai`, then **ChatGPT (openai-auth pool, …)**) puts the login in the pool, and OpenCode 2 keeps only a placeholder; OpenCode 2's own ChatGPT login and API keys pass through untouched. The `/openai` menu, the sidebar, keep-warm and OpenCode 1's Codex request shaping are not available there yet. See the [repository README](https://github.com/cortexkit/openai-auth#opencode-2) for the details.
|
|
28
|
+
|
|
29
|
+
Choose **ChatGPT (openai-auth pool, browser)** or **ChatGPT (openai-auth pool, headless)** in `opencode auth login openai` to use the pool. The plugin serves a request only when the host-prepared Authorization bearer equals its pool placeholder exactly. API keys, environment keys and OpenCode's own ChatGPT logins pass through unchanged, without pool quota or attribution; switching connections takes effect on the next request. A placeholder with no usable pool account is refused locally, never sent upstream. Existing host ChatGPT logins are never copied into the pool: choose a pool login to obtain a separate OAuth token family, leaving the host's login and refresh methods intact.
|
|
30
|
+
|
|
31
|
+
For vault-only use on OpenCode 2, choose **ChatGPT accounts in the vault**, or run `opencode2 auth login openai --method openai-auth-vault` (substitute the name of your OpenCode 2 executable). Activation requires enrollment under `openai-auth-opencode`, shared with OpenCode 1, performs no OAuth and writes no account to the pool. The host receives only the placeholder under this method's ID.
|
|
32
|
+
|
|
23
33
|
## Features
|
|
24
34
|
|
|
25
35
|
- ChatGPT Plus/Pro OAuth login (browser and headless device flows), plus a manual API-key fallback.
|
|
@@ -29,35 +39,14 @@ Restart OpenCode after changing plugin config, then authenticate:
|
|
|
29
39
|
- Per-turn quota tracking (5-hour + weekly windows) on both transports, with a sidebar readout and an explicit all-accounts refresh.
|
|
30
40
|
- Idle prompt-cache keep-warm, with an optional subagent mode and main-only sustain mode.
|
|
31
41
|
- Leveled, secret-redacting, rotating log file.
|
|
32
|
-
-
|
|
42
|
+
- One interactive `/openai` menu in the TUI, including account management and headless device-code authentication.
|
|
33
43
|
- Optional OpenAI Responses WebSocket transport (HTTP is the default).
|
|
34
44
|
|
|
35
45
|
## Commands
|
|
36
46
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
| Command | Arguments | Purpose |
|
|
40
|
-
| --- | --- | --- |
|
|
41
|
-
| `/openai-quota` | — | Show 5h + weekly quota for all accounts. |
|
|
42
|
-
| `/openai-account` | `add [label]` · `remove <id>` · `order <a> <b>` | Manage main + fallback accounts. |
|
|
43
|
-
| `/openai-routing` | `main-first` · `fallback-first` · `sticky-balanced` · `reset` | Routing order, sticky balanced session pins, or clear the current pin. |
|
|
44
|
-
| `/openai-killswitch` | `on` · `off` · `set <acct>:<5h>,<1w> ...` | Hard-block accounts below quota thresholds. |
|
|
45
|
-
| `/openai-cachekeep` | `on` · `off` · `subagents on` · `subagents off` · `sustain on` · `sustain off` | Idle prompt-cache keep-warm; sustain bypasses only main idle pruning. |
|
|
46
|
-
| `/openai-reset` | Modal only | Spend one applicable reset credit for an exhausted account after explicit confirmation. |
|
|
47
|
-
| `/openai-logging` | `<level>` | Set log level live. |
|
|
48
|
-
| `/openai-dump` | `on` · `off` | Toggle transport request dumps. |
|
|
49
|
-
|
|
50
|
-
Account management (fallback accounts; the main account comes from `/login openai`):
|
|
51
|
-
|
|
52
|
-
```text
|
|
53
|
-
/openai-account add [--headless] [label]
|
|
54
|
-
/openai-account
|
|
55
|
-
/openai-account remove <id>
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
All account operations can also be performed interactively via the `/openai-account` TUI dialog.
|
|
47
|
+
One command, `/openai`, opens one menu in the TUI: Accounts (add with browser or device-code sign-in, disable, enable, move, remove), Quota, Routing, Limits (the killswitch and per-account floors), Cache (keep-warm), Diagnostics (request dumps, log level), Reset credits, This session (the sticky pin) and Vault (connect this host to the Claustrum vault, whose OpenAI accounts then serve in place of yours until you disconnect; disable or enable each vault account). The menu works on the account pool; until the accounts have moved to it, `/openai` shows only that notice and the processes holding the move back. The earlier per-feature commands (`/openai-account`, `/openai-quota`, `/openai-routing`, `/openai-killswitch`, `/openai-cachekeep`, `/openai-dump`, `/openai-logging`, `/openai-reset`) are gone.
|
|
59
48
|
|
|
60
|
-
On a headless machine, where
|
|
49
|
+
On a headless machine, where `/openai` is out of reach, `opencode auth login` offers the account actions — add, re-authenticate, remove, enable or disable, check quotas, the auth doctor, connect to the Claustrum vault (it prints the `ck auth enroll approve` and `ck auth grant` commands to run, and waits for the approval), or delete every account except `main`. It prints `Failed to authorize` on return even when the action succeeded, because the menu writes its own changes and reports none of them as a sign-in; confirm with `/openai`.
|
|
61
50
|
|
|
62
51
|
## Configuration
|
|
63
52
|
|
|
@@ -76,7 +65,7 @@ See the [repository README](https://github.com/cortexkit/openai-auth#readme) for
|
|
|
76
65
|
|
|
77
66
|
`sticky-balanced` places a cold session by least projected quota pressure, then keeps its SHA-256-keyed sidebar-state pin for up to seven days. It does not rebalance mid-session or use a Retry-After hold; it migrates only after confirmed exhaustion or permanent auth failure. Stale or unknown quota is excluded from weighted placement; when the killswitch is enabled, accounts below their per-account threshold are also excluded from both weighted placement AND the mode-fallback fail-open branch — that branch otherwise orders by `resetCreditsApplicable` first, then configured order, then account id. Subagents have separate pins and reuse them when resumed.
|
|
78
67
|
|
|
79
|
-
`/openai
|
|
68
|
+
Sustain (the Cache section of `/openai`) defaults off, applies only to main sessions, remains subject to the clock window and memory/LRU caps, and never warms non-active accounts. It costs about two GPT-5.6 warms per hour per session (about 1K output tokens/hour at about 99.4% cache hit); non-5.6 sessions warm about twelve times per hour. Before enabling it for a main-session model, preserve existing entries in `~/.config/cortexkit/magic-context.jsonc` and set that model's `cache_ttl` to `"never"`; Magic Context does not run in subagents. `sustain` means bypass main idle pruning, unlike the sibling anthropic plugin's `always`, which means ignore the clock schedule.
|
|
80
69
|
|
|
81
70
|
## License
|
|
82
71
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createHash as B}from"node:crypto";import{homedir as G,tmpdir as W}from"node:os";import{dirname as J,join as w,resolve as z}from"node:path";var A="OPENCODE_OPENAI_AUTH_RPC_DIR",K="openai-auth-";function L(k){return B("sha256").update(k).digest("hex").slice(0,16)}function M(){let k=process.env.XDG_STATE_HOME||w(G(),".local","state");return w(k,"cortexkit","openai-auth","rpc")}function Q(k){let q=process.env[A]?.trim();if(q)return z(k,q);return w(M(),`${K}${L(k)}`)}async function $(k){let q=process.env[A]?.trim();if(q)return{dir:z(k,q),secureDir:!1};let x=Q(k);return{dir:x,secureDir:!0,sweepRoot:J(x)}}export{W as oc,K as pc,Q as qc,$ as rc};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import{createHash as Qz,randomUUID as a}from"node:crypto";import{chmod as s,mkdir as d,open as n,readdir as S,readFile as P,rename as i,rmdir as o,stat as r,unlink as _}from"node:fs/promises";import{join as E,resolve as B}from"node:path";function v(z){return typeof z==="number"&&Number.isSafeInteger(z)&&z>0}function j(z){if(!v(z))return!1;try{return process.kill(z,0),!0}catch(J){return J.code==="EPERM"}}function Xz(z){return(J)=>t(J,z)}function t(z,J){if(/^[0-9a-f]{16}$/.test(z))return!0;return z.startsWith(J)&&/^[0-9a-f]{16}$/.test(z.slice(J.length))}function e(z){let J=/^port-(\d+)\.json$/.exec(z);return J?Number(J[1]):void 0}function k(z,J){if(z===null||typeof z!=="object"||Array.isArray(z))return!1;let{pid:W,port:N,token:Q}=z;return v(W)&&e(J)===W&&typeof N==="number"&&Number.isInteger(N)&&N>=1&&N<=65535&&typeof Q==="string"&&Q.length>0}async function x(z,J){J?.debug("rpc corrupt port file",{pid:process.pid,portFile:z}),await _(z).catch(()=>{})}async function Yz(z,J,W={}){let N=async()=>{if(await d(z,{recursive:!0,mode:W.secureDir?448:void 0}),W.secureDir)await s(z,448);await W.beforeWrite?.();let Q={...J,startedAt:Date.now()},V=E(z,`port-${J.pid}.json`),X=`${V}.${(W.stageName??a)()}.tmp`,K,G=!1;try{K=await n(X,"wx",384),G=!0,await K.writeFile(JSON.stringify(Q),"utf8"),await K.chmod(384),await K.close(),K=void 0,await i(X,V),G=!1}finally{if(await K?.close().catch(()=>{}),G)await _(X).catch(()=>{})}return V};try{return await N()}catch(Q){if(Q.code==="ENOENT")return await N();throw Q}}async function Zz(z,J,W,N){let Q;try{Q=await S(z,{withFileTypes:!0})}catch(X){if(X.code==="ENOENT")return;throw X}let V=B(J);for(let X of Q){if(!X.isDirectory()||!W(X.name))continue;let K=E(z,X.name),G;try{G=await S(K)}catch(Y){if(Y.code==="ENOENT")continue;throw Y}for(let Y of G){if(!Y.startsWith("port-")||!Y.endsWith(".json"))continue;let $=E(K,Y),Z;try{Z=await P($,"utf8")}catch{continue}if(Z===void 0)continue;let H;try{H=JSON.parse(Z)}catch{await x($,N);continue}if(!k(H,Y)){await x($,N);continue}if(!j(H.pid))await _($).catch(()=>{})}if(B(K)!==V)await o(K).catch(()=>{})}}async function u(z,J){if(!j(J.pid))return null;let W=E(B(z),`port-${J.pid}.json`);try{let N=await r(W);return`${W}:${N.dev}:${N.ino}:${N.mtimeMs}:${N.size}`}catch{return null}}async function h(z,J,W={}){let N;try{N=await S(z)}catch{return null}let Q=[];for(let G of N){if(!G.startsWith("port-")||!G.endsWith(".json"))continue;try{let Y=JSON.parse(await P(E(z,G),"utf8"));if(k(Y,G))if(j(Y.pid))Q.push(Y);else await _(E(z,G)).catch(()=>{})}catch{}}if(Q.length===0)return null;let V=J!==void 0&&J>=1?Q.filter((G)=>G.pid===J):[];if(W.exactPid===!0&&V.length===0)return null;let X=V.length>0?V:Q,K=(G)=>typeof G.startedAt==="number"&&Number.isFinite(G.startedAt)?G.startedAt:-1/0;return X.sort((G,Y)=>K(Y)-K(G))[0]??null}import{open as zz}from"node:fs/promises";import{connect as Gz}from"node:net";import{join as Jz,resolve as p}from"node:path";var c=2000,w=new Map,R=new Map;async function Kz(z,J){let W=Jz(p(z),`port-${J.pid}.json`),N;try{N=await zz(W,"r");let Q=await N.stat(),V=JSON.parse(await N.readFile("utf8"));if(V.pid!==J.pid||V.port!==J.port||V.token!==J.token)return null;return`${W}:${Q.dev}:${Q.ino}:${Q.mtimeMs}:${Q.size}`}catch{return null}finally{await N?.close().catch(()=>{})}}async function m(z,J,W,N){let Q=w.get(z);if(Q&&await u(J,Q.entry)===Q.identity)return Q;w.delete(z);let V=R.get(z);if(V)return V;let X=(async()=>{let K=await(N.discover??h)(J,W,N);if(!K)return null;let G=await Kz(J,K);if(!G)return{entry:K,identity:""};let Y={entry:K,identity:G};return w.set(z,Y),Y})();R.set(z,X);try{return await X}finally{if(R.get(z)===X)R.delete(z)}}async function y(z,J,W,N=c){return new Promise((Q)=>{let V,X=!1,K=!1,G=($,Z=!1)=>{if(X)return;X=!0,clearTimeout(Y),V?.destroy(),Q({value:$,stale:Z})},Y=setTimeout(()=>G(null),N);try{let $=JSON.stringify(W);V=Gz({host:"127.0.0.1",port:z.port}),V.on("connect",()=>{K=!0,V?.write(`POST /rpc/${J} HTTP/1.0\r
|
|
2
|
+
Host: 127.0.0.1:${z.port}\r
|
|
3
|
+
Connection: close\r
|
|
4
|
+
Content-Type: application/json\r
|
|
5
|
+
Content-Length: ${Buffer.byteLength($)}\r
|
|
6
|
+
Authorization: Bearer ${z.token}\r
|
|
7
|
+
\r
|
|
8
|
+
`+$)});let Z=[],H=0,q,C,A=Buffer.alloc(0),D=()=>{if(q===void 0)return G(null);try{let O=Buffer.concat(Z).subarray(q);G(JSON.parse(O.toString("utf8")))}catch{G(null)}};V.on("data",(O)=>{if(X)return;if(H+=O.length,Z.push(O),q===void 0){A=Buffer.concat([A,O]);let U=A.indexOf(`\r
|
|
9
|
+
\r
|
|
10
|
+
`);if(U>=0)q=U+4;if((q??A.length)>16384)return G(null);if(q!==void 0){let M=A.subarray(0,U).toString("latin1").split(`\r
|
|
11
|
+
`),F=/^HTTP\/1\.[01] (\d{3})(?: |$)/.exec(M[0]??"");if(!F)return G(null);let I=Number(F[1]);if(I<200||I>=300)return G(null,[401,403,404,410].includes(I));for(let L of M.slice(1)){let b=L.indexOf(":"),g=L.slice(0,b).toLowerCase(),f=L.slice(b+1).trim();if(g==="transfer-encoding")return G(null);if(g==="content-length"){if(C!==void 0||!/^\d+$/.test(f))return G(null);if(C=Number(f),!Number.isSafeInteger(C)||C>8388608)return G(null)}}A=Buffer.alloc(0)}}let T=H-(q??H);if(T>8388608)return G(null);if(C!==void 0){if(T>C)return G(null);if(T===C)D()}}),V.on("end",()=>{if(C!==void 0&&H-(q??0)!==C)return G(null);D()}),V.on("error",()=>G(null,!K)),V.on("close",()=>G(null))}catch{G(null,!K)}})}async function l(z,J,W,N,Q,V,X=c){let K=JSON.stringify([p(z),J??null,W.exactPid===!0]),G=await m(K,z,J,W);if(N(G?.entry??null),!G)return null;let Y=Date.now()+X,$=await y(G.entry,Q,V,X);if(!$.stale)return $.value;if(w.get(K)===G)w.delete(K);let Z=await m(K,z,J,W);if(!Z||Date.now()>=Y)return null;if(Z.entry.port===G.entry.port&&Z.entry.pid===G.entry.pid&&Z.entry.token===G.entry.token){if(w.get(K)===Z)w.delete(K);return null}let H=await y(Z.entry,Q,V,Y-Date.now());if(H.stale&&w.get(K)===Z)w.delete(K);return H.value}function Az(z,J,W,N={}){let Q={exactPid:N.exactPid,discover:N.discover},V=!1,X=(K)=>{if(V)return;W?.(K),V=!0};return{async pending(K,G,Y){return(await l(z,J,Q,X,"pending-notifications",{lastReceivedId:K,sessionId:G},Y))?.messages??[]},async apply(K,G){return await l(z,J,Q,X,"apply",{...K},G)??{text:"apply failed",knobs:{}}}}}
|
|
12
|
+
export{Xz as Zb,Yz as _b,Zz as $b,h as ac,c as bc,Az as cc};
|