@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
|
@@ -1,855 +0,0 @@
|
|
|
1
|
-
import { createTextNode as _$createTextNode } from "opentui:runtime-module:%40opentui%2Fsolid";
|
|
2
|
-
import { memo as _$memo } from "opentui:runtime-module:%40opentui%2Fsolid";
|
|
3
|
-
import { insertNode as _$insertNode } from "opentui:runtime-module:%40opentui%2Fsolid";
|
|
4
|
-
import { insert as _$insert } from "opentui:runtime-module:%40opentui%2Fsolid";
|
|
5
|
-
import { setProp as _$setProp } from "opentui:runtime-module:%40opentui%2Fsolid";
|
|
6
|
-
import { createElement as _$createElement } from "opentui:runtime-module:%40opentui%2Fsolid";
|
|
7
|
-
import { createComponent as _$createComponent } from "opentui:runtime-module:%40opentui%2Fsolid";
|
|
8
|
-
/** @jsxImportSource @opentui/solid */
|
|
9
|
-
|
|
10
|
-
import { errorMessage, openUrl } from "../shared/internal.ts";
|
|
11
|
-
import { createLogger } from "./logger.ts";
|
|
12
|
-
import { getCollapsedQuotaSummary, getSidebarState, resolveSessionSidebarRouting } from "./sidebar-state.ts";
|
|
13
|
-
const log = createLogger('rpc-tui');
|
|
14
|
-
export function buildCachekeepDialogOptions(payload) {
|
|
15
|
-
const enabled = payload.knobs.enabled === true;
|
|
16
|
-
const subagents = payload.knobs.subagents === true;
|
|
17
|
-
const sustain = payload.knobs.sustain === true;
|
|
18
|
-
const running = payload.knobs.running === true;
|
|
19
|
-
const tracked = Number(payload.knobs.tracked ?? 0);
|
|
20
|
-
const generatedAt = Number(payload.knobs.generatedAt ?? Date.now());
|
|
21
|
-
const lastWarmAt = Number(payload.knobs.lastWarmAt ?? 0);
|
|
22
|
-
const maxIdleWarmMs = Number(payload.knobs.maxIdleWarmMs ?? 60 * 60 * 1000);
|
|
23
|
-
const maxSubagentIdleMs = Number(payload.knobs.maxSubagentIdleMs ?? 30 * 60 * 1000);
|
|
24
|
-
const windowKnob = payload.knobs.window;
|
|
25
|
-
const windowLabel = windowKnob ? `${String(windowKnob.startHour).padStart(2, '0')}-${String(windowKnob.endHour).padStart(2, '0')}` : 'always (no window)';
|
|
26
|
-
const lastWarm = lastWarmAt ? `${Math.ceil((generatedAt - lastWarmAt) / 1000)}s ago` : 'none yet';
|
|
27
|
-
const idleWindow = Math.round(maxIdleWarmMs / 60_000);
|
|
28
|
-
const subIdleWindow = Math.round(maxSubagentIdleMs / 60_000);
|
|
29
|
-
const statusParts = [enabled ? '● Enabled' : '○ Disabled', `timer ${running ? 'armed' : 'idle'}`, `${tracked} tracked`, `last warm ${lastWarm}`, `window ${windowLabel}`, `${idleWindow}m idle cap`, `sustain ${sustain ? 'on' : 'off'}`, `subagent idle ${subIdleWindow}m`].filter(part => part.length > 0);
|
|
30
|
-
return [{
|
|
31
|
-
title: statusParts.join(' | '),
|
|
32
|
-
value: 'status',
|
|
33
|
-
description: 'Current cachekeep state'
|
|
34
|
-
}, {
|
|
35
|
-
title: enabled ? 'Turn off' : 'Turn on',
|
|
36
|
-
value: enabled ? 'off' : 'on',
|
|
37
|
-
description: enabled ? 'Stop capturing and warming prompt-cache prefixes' : 'Persistently enable capture; the timer self-arms on request capture'
|
|
38
|
-
}, {
|
|
39
|
-
title: subagents ? 'Subagent warming: on' : 'Subagent warming: off',
|
|
40
|
-
value: subagents ? 'subagents off' : 'subagents on',
|
|
41
|
-
description: subagents ? `Warm subagent sessions (${subIdleWindow}m idle cap). Disable to skip subagents.` : `Skip subagent sessions. Enable to warm them too (${subIdleWindow}m idle cap).`
|
|
42
|
-
}, {
|
|
43
|
-
title: sustain ? 'Sustain main sessions: on' : 'Sustain main sessions: off',
|
|
44
|
-
value: sustain ? 'sustain off' : 'sustain on',
|
|
45
|
-
description: 'main-only, idle-cap only; the configured clock window still applies.'
|
|
46
|
-
}, {
|
|
47
|
-
title: windowKnob ? `Warm window: ${windowLabel}` : 'Set warm window…',
|
|
48
|
-
value: 'set_window',
|
|
49
|
-
description: windowKnob ? `Currently only warming between ${windowLabel} local hours — pick to change` : 'Restrict capture + warm to a clock-hour window, e.g. 9-18 or 22-6'
|
|
50
|
-
}, {
|
|
51
|
-
title: 'Clear warm window',
|
|
52
|
-
value: 'clear_window',
|
|
53
|
-
description: windowKnob ? 'Remove the clock-hour restriction — return to always-warm (within idle caps)' : 'No clock-hour window is currently set'
|
|
54
|
-
}, {
|
|
55
|
-
title: 'Refresh status',
|
|
56
|
-
value: 'refresh',
|
|
57
|
-
description: 'Re-read cachekeep status'
|
|
58
|
-
}, {
|
|
59
|
-
title: 'Close',
|
|
60
|
-
value: 'close',
|
|
61
|
-
description: 'Close this dialog'
|
|
62
|
-
}];
|
|
63
|
-
}
|
|
64
|
-
function resetAccountOptions(payload) {
|
|
65
|
-
const accounts = Array.isArray(payload.knobs.accounts) ? payload.knobs.accounts : [];
|
|
66
|
-
return [...accounts.map(account => {
|
|
67
|
-
const used = account.usedPercent === undefined ? 'quota unavailable' : `${account.usedPercent}%`;
|
|
68
|
-
const counts = `${account.applicableAvailableCount === undefined ? '?' : account.applicableAvailableCount}/${account.availableCount ?? '?'}`;
|
|
69
|
-
const status = account.eligible ? 'eligible' : account.reason ?? 'unavailable';
|
|
70
|
-
const details = `${used} · ${counts}`;
|
|
71
|
-
const shortDate = account.selectedCreditExpiresAt?.slice(0, 10) ?? 'unknown';
|
|
72
|
-
return {
|
|
73
|
-
title: `${account.label} — ${status}`,
|
|
74
|
-
value: `account:${account.accountKey}`,
|
|
75
|
-
description: account.eligible ? `${details} · exp ${shortDate}` : details
|
|
76
|
-
};
|
|
77
|
-
}), {
|
|
78
|
-
title: 'Refresh',
|
|
79
|
-
value: 'refresh',
|
|
80
|
-
description: 'Re-check account quota and reset credits'
|
|
81
|
-
}, {
|
|
82
|
-
title: 'Close',
|
|
83
|
-
value: 'close',
|
|
84
|
-
description: 'Close this dialog'
|
|
85
|
-
}];
|
|
86
|
-
}
|
|
87
|
-
function resetResultOptions(payload) {
|
|
88
|
-
const accountKey = typeof payload.knobs.accountKey === 'string' ? payload.knobs.accountKey : undefined;
|
|
89
|
-
const chatgptAccountId = typeof payload.knobs.chatgptAccountId === 'string' ? payload.knobs.chatgptAccountId : undefined;
|
|
90
|
-
const code = typeof payload.knobs.code === 'string' ? payload.knobs.code : '';
|
|
91
|
-
const retrySafe = (code === 'ambiguous' || code === 'http_error' || code === 'expired_unreconciled' || payload.knobs.stateWriteFailed === true) && typeof payload.knobs.retryGuidance === 'string' && accountKey !== undefined && chatgptAccountId !== undefined;
|
|
92
|
-
return [{
|
|
93
|
-
title: payload.text,
|
|
94
|
-
value: 'result',
|
|
95
|
-
description: 'Command result'
|
|
96
|
-
}, ...(retrySafe ? [{
|
|
97
|
-
title: 'Retry',
|
|
98
|
-
value: 'retry',
|
|
99
|
-
description: 'Reuse the bound request and credit identifiers for this uncertain outcome'
|
|
100
|
-
}] : []), {
|
|
101
|
-
title: 'Refresh',
|
|
102
|
-
value: 'refresh',
|
|
103
|
-
description: 'Re-check account quota and reset credits'
|
|
104
|
-
}, {
|
|
105
|
-
title: 'Close',
|
|
106
|
-
value: 'close',
|
|
107
|
-
description: 'Close this dialog'
|
|
108
|
-
}];
|
|
109
|
-
}
|
|
110
|
-
function openResetDialog(api, payload, apply) {
|
|
111
|
-
let applyGeneration = 0;
|
|
112
|
-
const render = state => {
|
|
113
|
-
const applyAndRender = args => {
|
|
114
|
-
const generation = ++applyGeneration;
|
|
115
|
-
log.debug('reset dialog apply', {
|
|
116
|
-
args,
|
|
117
|
-
generation
|
|
118
|
-
});
|
|
119
|
-
void apply('openai-reset', args).then(result => {
|
|
120
|
-
log.debug('reset dialog apply result', {
|
|
121
|
-
generation,
|
|
122
|
-
currentGeneration: applyGeneration,
|
|
123
|
-
stage: result.knobs?.stage,
|
|
124
|
-
accountRows: Array.isArray(result.knobs?.accounts) ? result.knobs.accounts.length : undefined
|
|
125
|
-
});
|
|
126
|
-
if (generation !== applyGeneration) return;
|
|
127
|
-
if (typeof result.knobs?.stage !== 'string') {
|
|
128
|
-
render({
|
|
129
|
-
command: 'openai-reset',
|
|
130
|
-
text: 'The reset request is still completing or returned no result. Choose Refresh to check the current state — do NOT re-confirm.',
|
|
131
|
-
knobs: {
|
|
132
|
-
stage: 'result',
|
|
133
|
-
code: 'unknown'
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
render({
|
|
139
|
-
command: 'openai-reset',
|
|
140
|
-
text: result.text,
|
|
141
|
-
knobs: result.knobs
|
|
142
|
-
});
|
|
143
|
-
}).catch(error => {
|
|
144
|
-
if (generation !== applyGeneration) return;
|
|
145
|
-
log.warn('reset dialog apply rejected', {
|
|
146
|
-
error: errorMessage(error)
|
|
147
|
-
});
|
|
148
|
-
render({
|
|
149
|
-
command: 'openai-reset',
|
|
150
|
-
text: 'Command failed — the plugin could not complete the request; the plugin log has details.',
|
|
151
|
-
knobs: {
|
|
152
|
-
stage: 'result',
|
|
153
|
-
code: 'error'
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
};
|
|
158
|
-
const stage = state.knobs.stage;
|
|
159
|
-
log.debug('reset dialog render', {
|
|
160
|
-
stage,
|
|
161
|
-
accountRows: Array.isArray(state.knobs.accounts) ? state.knobs.accounts.length : undefined,
|
|
162
|
-
knobKeys: Object.keys(state.knobs)
|
|
163
|
-
});
|
|
164
|
-
api.ui.dialog.setSize('xlarge');
|
|
165
|
-
if (stage === 'confirm') {
|
|
166
|
-
const preview = state.knobs.preview;
|
|
167
|
-
const accountKey = preview?.accountKey;
|
|
168
|
-
const chatgptAccountId = preview?.chatgptAccountId;
|
|
169
|
-
const availableCount = preview?.availableCount ?? 'unknown';
|
|
170
|
-
const DialogConfirm = api.ui.DialogConfirm;
|
|
171
|
-
api.ui.dialog.replace(() => _$createComponent(DialogConfirm, {
|
|
172
|
-
title: "Reset quota window",
|
|
173
|
-
get message() {
|
|
174
|
-
return `${state.text}\n\nThis SPENDS 1 of ${availableCount} reset credits — irreversible.\n\nChoose Reset to continue or Cancel to return.\n\nEnter = Cancel (host default). Press Tab then Enter to Reset.`;
|
|
175
|
-
},
|
|
176
|
-
onConfirm: () => {
|
|
177
|
-
if (!accountKey || !chatgptAccountId) return;
|
|
178
|
-
applyAndRender(`confirm ${encodeURIComponent(accountKey)} ${encodeURIComponent(chatgptAccountId)}`);
|
|
179
|
-
},
|
|
180
|
-
onCancel: () => applyAndRender('refresh')
|
|
181
|
-
}));
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
const DialogSelect = api.ui.DialogSelect;
|
|
185
|
-
const options = stage === 'result' ? resetResultOptions(state) : resetAccountOptions(state);
|
|
186
|
-
api.ui.dialog.replace(() => _$createComponent(DialogSelect, {
|
|
187
|
-
title: stage === 'result' ? 'OpenAI reset result' : 'OpenAI reset credits',
|
|
188
|
-
options: options,
|
|
189
|
-
onSelect: option => {
|
|
190
|
-
if (option.disabled) return;
|
|
191
|
-
if (option.value === 'result') return;
|
|
192
|
-
if (option.value === 'close') {
|
|
193
|
-
applyGeneration += 1;
|
|
194
|
-
api.ui.dialog.clear();
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
if (option.value === 'refresh') {
|
|
198
|
-
applyAndRender('refresh');
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
if (option.value === 'retry') {
|
|
202
|
-
const accountKey = state.knobs.accountKey;
|
|
203
|
-
const chatgptAccountId = state.knobs.chatgptAccountId;
|
|
204
|
-
if (typeof accountKey !== 'string' || typeof chatgptAccountId !== 'string') {
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
applyAndRender(`retry ${encodeURIComponent(accountKey)} ${encodeURIComponent(chatgptAccountId)}`);
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
if (!option.value.startsWith('account:')) return;
|
|
211
|
-
const accountKey = option.value.slice('account:'.length);
|
|
212
|
-
applyAndRender(`select ${encodeURIComponent(accountKey)}`);
|
|
213
|
-
}
|
|
214
|
-
}));
|
|
215
|
-
};
|
|
216
|
-
render(payload);
|
|
217
|
-
}
|
|
218
|
-
function showText(api, text) {
|
|
219
|
-
api.ui.dialog.setSize('xlarge');
|
|
220
|
-
api.ui.dialog.replace(() => (() => {
|
|
221
|
-
var _el$ = _$createElement("box"),
|
|
222
|
-
_el$2 = _$createElement("text");
|
|
223
|
-
_$insertNode(_el$, _el$2);
|
|
224
|
-
_$setProp(_el$, "flexDirection", 'column');
|
|
225
|
-
_$setProp(_el$, "padding", 1);
|
|
226
|
-
_$setProp(_el$, "width", '100%');
|
|
227
|
-
_$insert(_el$2, text);
|
|
228
|
-
return _el$;
|
|
229
|
-
})());
|
|
230
|
-
}
|
|
231
|
-
function showSetCachekeepWindowPrompt(api, apply, state, render) {
|
|
232
|
-
const DialogPrompt = api.ui.DialogPrompt;
|
|
233
|
-
const knobWindow = state.knobs.window;
|
|
234
|
-
const seed = knobWindow ? `${knobWindow.startHour}-${knobWindow.endHour}` : '';
|
|
235
|
-
api.ui.dialog.setSize('xlarge');
|
|
236
|
-
api.ui.dialog.replace(() => _$createComponent(DialogPrompt, {
|
|
237
|
-
title: "Cachekeep warm window",
|
|
238
|
-
description: () => (() => {
|
|
239
|
-
var _el$3 = _$createElement("text");
|
|
240
|
-
_$insert(_el$3, () => state.text);
|
|
241
|
-
return _el$3;
|
|
242
|
-
})(),
|
|
243
|
-
placeholder: "HH-HH (e.g. 9-18 or 22-6)",
|
|
244
|
-
value: seed,
|
|
245
|
-
onConfirm: value => {
|
|
246
|
-
const trimmed = value.trim();
|
|
247
|
-
if (!trimmed) {
|
|
248
|
-
render(state);
|
|
249
|
-
return;
|
|
250
|
-
}
|
|
251
|
-
void apply('openai-cachekeep', trimmed).then(r => {
|
|
252
|
-
api.ui.toast({
|
|
253
|
-
message: r.text
|
|
254
|
-
});
|
|
255
|
-
render({
|
|
256
|
-
command: 'openai-cachekeep',
|
|
257
|
-
text: r.text,
|
|
258
|
-
knobs: r.knobs
|
|
259
|
-
});
|
|
260
|
-
});
|
|
261
|
-
},
|
|
262
|
-
onCancel: () => render(state)
|
|
263
|
-
}));
|
|
264
|
-
}
|
|
265
|
-
export function openCommandDialog(api, payload, apply, sessionId) {
|
|
266
|
-
if (payload.command === 'openai-reset') {
|
|
267
|
-
openResetDialog(api, payload, apply);
|
|
268
|
-
return;
|
|
269
|
-
}
|
|
270
|
-
if (payload.command === 'openai-routing') {
|
|
271
|
-
const current = payload.knobs.mode ?? 'main-first';
|
|
272
|
-
const DialogSelect = api.ui.DialogSelect;
|
|
273
|
-
api.ui.dialog.setSize('xlarge');
|
|
274
|
-
api.ui.dialog.replace(() => _$createComponent(DialogSelect, {
|
|
275
|
-
title: "OpenAI routing",
|
|
276
|
-
current: current,
|
|
277
|
-
options: [{
|
|
278
|
-
title: 'Main first',
|
|
279
|
-
value: 'main-first',
|
|
280
|
-
description: 'Use the main account until exhausted'
|
|
281
|
-
}, {
|
|
282
|
-
title: 'Fallback first',
|
|
283
|
-
value: 'fallback-first',
|
|
284
|
-
description: 'Prefer fallback accounts, preserve main'
|
|
285
|
-
}, {
|
|
286
|
-
title: 'Sticky balanced',
|
|
287
|
-
value: 'sticky-balanced',
|
|
288
|
-
description: 'Keep each session on one account while balancing new sessions'
|
|
289
|
-
}, {
|
|
290
|
-
title: "Reset this session's pin",
|
|
291
|
-
value: 'reset',
|
|
292
|
-
description: 'Unpin this session; the next request may still choose the same account'
|
|
293
|
-
}],
|
|
294
|
-
onSelect: option => {
|
|
295
|
-
void apply('openai-routing', String(option.value)).then(r => {
|
|
296
|
-
api.ui.toast({
|
|
297
|
-
message: r.text
|
|
298
|
-
});
|
|
299
|
-
api.ui.dialog.clear();
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
}));
|
|
303
|
-
return;
|
|
304
|
-
}
|
|
305
|
-
if (payload.command === 'openai-dump') {
|
|
306
|
-
const enabled = payload.knobs.enabled === true;
|
|
307
|
-
const DialogConfirm = api.ui.DialogConfirm;
|
|
308
|
-
api.ui.dialog.setSize('xlarge');
|
|
309
|
-
api.ui.dialog.replace(() => _$createComponent(DialogConfirm, {
|
|
310
|
-
title: "OpenAI request dump",
|
|
311
|
-
get message() {
|
|
312
|
-
return `${payload.text}\n\n${enabled ? 'Disable' : 'Enable'} request dump?`;
|
|
313
|
-
},
|
|
314
|
-
onConfirm: () => {
|
|
315
|
-
void apply('openai-dump', enabled ? 'off' : 'on').then(r => {
|
|
316
|
-
api.ui.toast({
|
|
317
|
-
message: r.text
|
|
318
|
-
});
|
|
319
|
-
api.ui.dialog.clear();
|
|
320
|
-
});
|
|
321
|
-
},
|
|
322
|
-
onCancel: () => api.ui.dialog.clear()
|
|
323
|
-
}));
|
|
324
|
-
return;
|
|
325
|
-
}
|
|
326
|
-
if (payload.command === 'openai-killswitch') {
|
|
327
|
-
const config = payload.knobs.config ?? {};
|
|
328
|
-
const accountIds = payload.knobs.accountIds ?? [];
|
|
329
|
-
const enabled = config.enabled === true;
|
|
330
|
-
const readT = t => {
|
|
331
|
-
const fh = t?.primary ?? t?.['5h'] ?? 5;
|
|
332
|
-
const sd = t?.secondary ?? t?.['1w'] ?? 10;
|
|
333
|
-
return {
|
|
334
|
-
fh,
|
|
335
|
-
sd
|
|
336
|
-
};
|
|
337
|
-
};
|
|
338
|
-
const mainT = readT(config.main);
|
|
339
|
-
const seedParts = [`main:${mainT.fh},${mainT.sd}`];
|
|
340
|
-
for (const id of accountIds) {
|
|
341
|
-
const t = readT(config.accounts?.[id] ?? config.main);
|
|
342
|
-
seedParts.push(`${id}:${t.fh},${t.sd}`);
|
|
343
|
-
}
|
|
344
|
-
const seed = seedParts.join(' ');
|
|
345
|
-
const openEdit = () => {
|
|
346
|
-
const DialogPrompt = api.ui.DialogPrompt;
|
|
347
|
-
api.ui.dialog.setSize('xlarge');
|
|
348
|
-
api.ui.dialog.replace(() => _$createComponent(DialogPrompt, {
|
|
349
|
-
title: "Killswitch thresholds",
|
|
350
|
-
description: () => (() => {
|
|
351
|
-
var _el$4 = _$createElement("text");
|
|
352
|
-
_$insert(_el$4, () => payload.text);
|
|
353
|
-
return _el$4;
|
|
354
|
-
})(),
|
|
355
|
-
placeholder: "main:5,10 work-alt:5,10",
|
|
356
|
-
value: seed,
|
|
357
|
-
onConfirm: value => {
|
|
358
|
-
void apply('openai-killswitch', `set ${value.trim()}`).then(r => {
|
|
359
|
-
api.ui.toast({
|
|
360
|
-
message: r.text
|
|
361
|
-
});
|
|
362
|
-
api.ui.dialog.clear();
|
|
363
|
-
});
|
|
364
|
-
},
|
|
365
|
-
onCancel: () => api.ui.dialog.clear()
|
|
366
|
-
}));
|
|
367
|
-
};
|
|
368
|
-
const DialogSelect = api.ui.DialogSelect;
|
|
369
|
-
api.ui.dialog.setSize('xlarge');
|
|
370
|
-
api.ui.dialog.replace(() => _$createComponent(DialogSelect, {
|
|
371
|
-
title: "OpenAI killswitch",
|
|
372
|
-
options: [{
|
|
373
|
-
title: enabled ? 'Disable killswitch' : 'Enable killswitch',
|
|
374
|
-
value: enabled ? 'off' : 'on',
|
|
375
|
-
description: enabled ? 'Stop hard-blocking on low quota' : 'Hard-block requests when quota drops below thresholds'
|
|
376
|
-
}, {
|
|
377
|
-
title: 'Edit thresholds\u2026',
|
|
378
|
-
value: 'edit',
|
|
379
|
-
description: 'Set per-account primary,secondary cutoffs'
|
|
380
|
-
}],
|
|
381
|
-
onSelect: option => {
|
|
382
|
-
if (option.value === 'edit') {
|
|
383
|
-
openEdit();
|
|
384
|
-
return;
|
|
385
|
-
}
|
|
386
|
-
void apply('openai-killswitch', String(option.value)).then(r => {
|
|
387
|
-
api.ui.toast({
|
|
388
|
-
message: r.text
|
|
389
|
-
});
|
|
390
|
-
api.ui.dialog.clear();
|
|
391
|
-
});
|
|
392
|
-
}
|
|
393
|
-
}));
|
|
394
|
-
return;
|
|
395
|
-
}
|
|
396
|
-
if (payload.command === 'openai-logging') {
|
|
397
|
-
const current = payload.knobs.level ?? 'info';
|
|
398
|
-
const levels = ['error', 'warn', 'info', 'debug', 'trace'];
|
|
399
|
-
const DialogSelect = api.ui.DialogSelect;
|
|
400
|
-
api.ui.dialog.setSize('xlarge');
|
|
401
|
-
api.ui.dialog.replace(() => _$createComponent(DialogSelect, {
|
|
402
|
-
title: "OpenAI logging",
|
|
403
|
-
current: current,
|
|
404
|
-
get options() {
|
|
405
|
-
return levels.map(level => ({
|
|
406
|
-
title: level,
|
|
407
|
-
value: level,
|
|
408
|
-
description: level === current ? 'currently active' : `Set log level to ${level}`
|
|
409
|
-
}));
|
|
410
|
-
},
|
|
411
|
-
onSelect: option => {
|
|
412
|
-
void apply('openai-logging', String(option.value)).then(r => {
|
|
413
|
-
api.ui.toast({
|
|
414
|
-
message: r.text
|
|
415
|
-
});
|
|
416
|
-
api.ui.dialog.clear();
|
|
417
|
-
});
|
|
418
|
-
}
|
|
419
|
-
}));
|
|
420
|
-
return;
|
|
421
|
-
}
|
|
422
|
-
if (payload.command === 'openai-cachekeep') {
|
|
423
|
-
const render = state => {
|
|
424
|
-
const options = buildCachekeepDialogOptions(state);
|
|
425
|
-
const DialogSelect = api.ui.DialogSelect;
|
|
426
|
-
api.ui.dialog.setSize('xlarge');
|
|
427
|
-
api.ui.dialog.replace(() => _$createComponent(DialogSelect, {
|
|
428
|
-
title: "OpenAI cachekeep",
|
|
429
|
-
current: "status",
|
|
430
|
-
options: options,
|
|
431
|
-
onSelect: option => {
|
|
432
|
-
if (option.value === 'close') {
|
|
433
|
-
api.ui.dialog.clear();
|
|
434
|
-
return;
|
|
435
|
-
}
|
|
436
|
-
if (option.value === 'set_window') {
|
|
437
|
-
showSetCachekeepWindowPrompt(api, apply, state, render);
|
|
438
|
-
return;
|
|
439
|
-
}
|
|
440
|
-
if (option.value === 'clear_window') {
|
|
441
|
-
// The option label is `clear_window`, but executeCachekeepCommand
|
|
442
|
-
// matches on `window clear` — forward the canonical form or the
|
|
443
|
-
// command falls through to the usage-text branch and the window
|
|
444
|
-
// is never cleared.
|
|
445
|
-
void apply('openai-cachekeep', 'window clear').then(r => {
|
|
446
|
-
render({
|
|
447
|
-
command: 'openai-cachekeep',
|
|
448
|
-
text: r.text,
|
|
449
|
-
knobs: r.knobs
|
|
450
|
-
});
|
|
451
|
-
});
|
|
452
|
-
return;
|
|
453
|
-
}
|
|
454
|
-
const args = option.value === 'refresh' ? 'status' : String(option.value);
|
|
455
|
-
void apply('openai-cachekeep', args).then(r => {
|
|
456
|
-
render({
|
|
457
|
-
command: 'openai-cachekeep',
|
|
458
|
-
text: r.text,
|
|
459
|
-
knobs: r.knobs
|
|
460
|
-
});
|
|
461
|
-
});
|
|
462
|
-
}
|
|
463
|
-
}));
|
|
464
|
-
};
|
|
465
|
-
render(payload);
|
|
466
|
-
return;
|
|
467
|
-
}
|
|
468
|
-
if (payload.command === 'openai-account') {
|
|
469
|
-
openAccountDialog(api, apply, sessionId, payload);
|
|
470
|
-
return;
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
// fallback for quota (display-only)
|
|
474
|
-
showText(api, payload.text);
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
// -- Accounts dialog ---------------------------------------------------------
|
|
478
|
-
|
|
479
|
-
export function formatQuotaWindows(quota) {
|
|
480
|
-
const windowSummary = getCollapsedQuotaSummary(quota ?? null).text;
|
|
481
|
-
if (windowSummary) return windowSummary;
|
|
482
|
-
if (quota?.resetCreditsAvailable !== undefined) {
|
|
483
|
-
return `resets: ${quota.resetCreditsAvailable}`;
|
|
484
|
-
}
|
|
485
|
-
return 'no quota data';
|
|
486
|
-
}
|
|
487
|
-
function osc52Copy(api, text) {
|
|
488
|
-
try {
|
|
489
|
-
const renderer = api.renderer;
|
|
490
|
-
if (renderer && typeof renderer.copyToClipboardOSC52 === 'function') {
|
|
491
|
-
return renderer.copyToClipboardOSC52(text);
|
|
492
|
-
}
|
|
493
|
-
} catch {
|
|
494
|
-
// best-effort
|
|
495
|
-
}
|
|
496
|
-
return false;
|
|
497
|
-
}
|
|
498
|
-
export function buildAccountDialogRows(state, sessionId) {
|
|
499
|
-
const activeId = resolveSessionSidebarRouting(state, sessionId).activeId;
|
|
500
|
-
return [{
|
|
501
|
-
title: `main${activeId === 'main' ? ' \u2022 active' : ''}`,
|
|
502
|
-
value: 'main',
|
|
503
|
-
description: formatQuotaWindows(state.main.quota)
|
|
504
|
-
}, ...state.fallbacks.map(fb => ({
|
|
505
|
-
title: `${fb.label ?? fb.id}${activeId === fb.id ? ' \u2022 active' : ''}${!fb.enabled ? ' (disabled)' : ''}`,
|
|
506
|
-
value: fb.id,
|
|
507
|
-
description: formatQuotaWindows(fb.quota)
|
|
508
|
-
}))];
|
|
509
|
-
}
|
|
510
|
-
export function accountDialogModeOption(mode) {
|
|
511
|
-
const claustrum = mode === 'claustrum';
|
|
512
|
-
return {
|
|
513
|
-
title: claustrum ? 'Leave Claustrum' : 'Enter Claustrum',
|
|
514
|
-
value: claustrum ? '__local__' : '__claustrum__',
|
|
515
|
-
description: claustrum ? 'Require fresh local logins before local refresh resumes' : 'Verify every enabled account before custody takes over'
|
|
516
|
-
};
|
|
517
|
-
}
|
|
518
|
-
export function buildFallbackAccountOptions(input) {
|
|
519
|
-
const name = input.label ?? input.id;
|
|
520
|
-
const options = [{
|
|
521
|
-
title: input.enabled ? 'Disable' : 'Enable',
|
|
522
|
-
value: input.enabled ? 'disable' : 'enable',
|
|
523
|
-
description: `${input.enabled ? 'Disable' : 'Enable'} ${name}`
|
|
524
|
-
}, {
|
|
525
|
-
title: 'Remove',
|
|
526
|
-
value: 'remove',
|
|
527
|
-
description: `Remove ${name}`
|
|
528
|
-
}];
|
|
529
|
-
if (input.index > 0) {
|
|
530
|
-
options.push({
|
|
531
|
-
title: 'Move up',
|
|
532
|
-
value: 'move_up',
|
|
533
|
-
description: 'Swap with the preceding fallback'
|
|
534
|
-
});
|
|
535
|
-
}
|
|
536
|
-
if (input.index < input.count - 1) {
|
|
537
|
-
options.push({
|
|
538
|
-
title: 'Move down',
|
|
539
|
-
value: 'move_down',
|
|
540
|
-
description: 'Swap with the following fallback'
|
|
541
|
-
});
|
|
542
|
-
}
|
|
543
|
-
options.push({
|
|
544
|
-
title: 'Back',
|
|
545
|
-
value: 'back',
|
|
546
|
-
description: 'Return to account list'
|
|
547
|
-
});
|
|
548
|
-
return options;
|
|
549
|
-
}
|
|
550
|
-
function openAccountDialog(api, apply, sessionId, payload) {
|
|
551
|
-
const DialogConfirm = api.ui.DialogConfirm;
|
|
552
|
-
let claustrumMode = payload?.knobs.claustrumMode;
|
|
553
|
-
function showL1() {
|
|
554
|
-
void getSidebarState().then(state => {
|
|
555
|
-
const DialogSelectInner = api.ui.DialogSelect;
|
|
556
|
-
api.ui.dialog.setSize('xlarge');
|
|
557
|
-
api.ui.dialog.replace(() => _$createComponent(DialogSelectInner, {
|
|
558
|
-
title: "OpenAI Accounts",
|
|
559
|
-
get options() {
|
|
560
|
-
return [accountDialogModeOption(claustrumMode), ...buildAccountDialogRows(state, sessionId), {
|
|
561
|
-
title: 'Add account\u2026',
|
|
562
|
-
value: '__add__',
|
|
563
|
-
description: 'Sign in to a new OpenAI account'
|
|
564
|
-
}];
|
|
565
|
-
},
|
|
566
|
-
onSelect: option => {
|
|
567
|
-
if (option.value === '__claustrum__' || option.value === '__local__') {
|
|
568
|
-
const args = option.value === '__claustrum__' ? 'claustrum' : 'local';
|
|
569
|
-
void apply('openai-account', args).then(r => {
|
|
570
|
-
api.ui.toast({
|
|
571
|
-
message: r.text
|
|
572
|
-
});
|
|
573
|
-
claustrumMode = r.knobs.claustrumMode;
|
|
574
|
-
showL1();
|
|
575
|
-
});
|
|
576
|
-
return;
|
|
577
|
-
}
|
|
578
|
-
if (option.value === '__add__') {
|
|
579
|
-
showAddFlow();
|
|
580
|
-
return;
|
|
581
|
-
}
|
|
582
|
-
// Main has no per-account actions: it is not removable or reorderable,
|
|
583
|
-
// regardless of whether the active session uses mode or sticky routing.
|
|
584
|
-
if (option.value === 'main') return;
|
|
585
|
-
showL2Fallback(option.value);
|
|
586
|
-
}
|
|
587
|
-
}));
|
|
588
|
-
});
|
|
589
|
-
}
|
|
590
|
-
function showL2Fallback(id) {
|
|
591
|
-
void getSidebarState().then(state => {
|
|
592
|
-
const DialogSelectInner = api.ui.DialogSelect;
|
|
593
|
-
const fbIndex = state.fallbacks.findIndex(f => f.id === id);
|
|
594
|
-
const fb = state.fallbacks[fbIndex];
|
|
595
|
-
if (!fb) {
|
|
596
|
-
showL1();
|
|
597
|
-
return;
|
|
598
|
-
}
|
|
599
|
-
const options = buildFallbackAccountOptions({
|
|
600
|
-
id: fb.id,
|
|
601
|
-
label: fb.label,
|
|
602
|
-
enabled: fb.enabled,
|
|
603
|
-
index: fbIndex,
|
|
604
|
-
count: state.fallbacks.length
|
|
605
|
-
});
|
|
606
|
-
api.ui.dialog.setSize('xlarge');
|
|
607
|
-
api.ui.dialog.replace(() => _$createComponent(DialogSelectInner, {
|
|
608
|
-
get title() {
|
|
609
|
-
return fb.label ?? fb.id;
|
|
610
|
-
},
|
|
611
|
-
options: options,
|
|
612
|
-
onSelect: option => {
|
|
613
|
-
if (option.value === 'remove') {
|
|
614
|
-
api.ui.dialog.setSize('xlarge');
|
|
615
|
-
api.ui.dialog.replace(() => _$createComponent(DialogConfirm, {
|
|
616
|
-
title: "Remove account",
|
|
617
|
-
get message() {
|
|
618
|
-
return `Remove ${fb.label ?? fb.id}?`;
|
|
619
|
-
},
|
|
620
|
-
onConfirm: () => {
|
|
621
|
-
void apply('openai-account', `remove ${id}`).then(r => {
|
|
622
|
-
api.ui.toast({
|
|
623
|
-
message: r.text
|
|
624
|
-
});
|
|
625
|
-
showL1();
|
|
626
|
-
});
|
|
627
|
-
},
|
|
628
|
-
onCancel: () => showL2Fallback(id)
|
|
629
|
-
}));
|
|
630
|
-
return;
|
|
631
|
-
}
|
|
632
|
-
if (option.value === 'enable' || option.value === 'disable') {
|
|
633
|
-
void apply('openai-account', `${option.value} ${id}`).then(r => {
|
|
634
|
-
api.ui.toast({
|
|
635
|
-
message: r.text
|
|
636
|
-
});
|
|
637
|
-
showL1();
|
|
638
|
-
});
|
|
639
|
-
return;
|
|
640
|
-
}
|
|
641
|
-
if (option.value === 'move_up') {
|
|
642
|
-
const neighbor = state.fallbacks[fbIndex - 1];
|
|
643
|
-
if (neighbor) {
|
|
644
|
-
void apply('openai-account', `order ${id} ${neighbor.id}`).then(r => {
|
|
645
|
-
api.ui.toast({
|
|
646
|
-
message: r.text
|
|
647
|
-
});
|
|
648
|
-
showL1();
|
|
649
|
-
});
|
|
650
|
-
}
|
|
651
|
-
return;
|
|
652
|
-
}
|
|
653
|
-
if (option.value === 'move_down') {
|
|
654
|
-
const neighbor = state.fallbacks[fbIndex + 1];
|
|
655
|
-
if (neighbor) {
|
|
656
|
-
void apply('openai-account', `order ${id} ${neighbor.id}`).then(r => {
|
|
657
|
-
api.ui.toast({
|
|
658
|
-
message: r.text
|
|
659
|
-
});
|
|
660
|
-
showL1();
|
|
661
|
-
});
|
|
662
|
-
}
|
|
663
|
-
return;
|
|
664
|
-
}
|
|
665
|
-
showL1();
|
|
666
|
-
}
|
|
667
|
-
}));
|
|
668
|
-
});
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
// -- Add flow ---------------------------------------------------------------
|
|
672
|
-
|
|
673
|
-
function showAddFlow() {
|
|
674
|
-
const DialogSelectInner = api.ui.DialogSelect;
|
|
675
|
-
api.ui.dialog.setSize('xlarge');
|
|
676
|
-
api.ui.dialog.replace(() => _$createComponent(DialogSelectInner, {
|
|
677
|
-
title: "Add account",
|
|
678
|
-
options: [{
|
|
679
|
-
title: 'Browser sign-in (local)',
|
|
680
|
-
value: 'browser',
|
|
681
|
-
description: 'Opens a browser window for OAuth on this machine'
|
|
682
|
-
}, {
|
|
683
|
-
title: 'Device code (remote / no browser)',
|
|
684
|
-
value: 'device',
|
|
685
|
-
description: 'Enter a code on another device to authorize'
|
|
686
|
-
}, {
|
|
687
|
-
title: 'Back',
|
|
688
|
-
value: 'back',
|
|
689
|
-
description: 'Return to account list'
|
|
690
|
-
}],
|
|
691
|
-
onSelect: option => {
|
|
692
|
-
if (option.value === 'browser') {
|
|
693
|
-
showLabelPrompt('browser');
|
|
694
|
-
return;
|
|
695
|
-
}
|
|
696
|
-
if (option.value === 'device') {
|
|
697
|
-
showLabelPrompt('device');
|
|
698
|
-
return;
|
|
699
|
-
}
|
|
700
|
-
showL1();
|
|
701
|
-
}
|
|
702
|
-
}));
|
|
703
|
-
}
|
|
704
|
-
function showLabelPrompt(mode) {
|
|
705
|
-
const DialogPromptInner = api.ui.DialogPrompt;
|
|
706
|
-
api.ui.dialog.setSize('xlarge');
|
|
707
|
-
api.ui.dialog.replace(() => _$createComponent(DialogPromptInner, {
|
|
708
|
-
title: "Label (optional)",
|
|
709
|
-
description: () => (() => {
|
|
710
|
-
var _el$5 = _$createElement("text");
|
|
711
|
-
_$insertNode(_el$5, _$createTextNode(`Give this account a name (e.g. "work", "personal"). Leave empty to auto-detect.`));
|
|
712
|
-
return _el$5;
|
|
713
|
-
})(),
|
|
714
|
-
placeholder: "e.g. work",
|
|
715
|
-
value: "",
|
|
716
|
-
onConfirm: label => {
|
|
717
|
-
if (mode === 'browser') {
|
|
718
|
-
startBrowserAdd(label.trim() || undefined);
|
|
719
|
-
} else {
|
|
720
|
-
startDeviceAdd(label.trim() || undefined);
|
|
721
|
-
}
|
|
722
|
-
},
|
|
723
|
-
onCancel: () => showAddFlow()
|
|
724
|
-
}));
|
|
725
|
-
}
|
|
726
|
-
function startBrowserAdd(label) {
|
|
727
|
-
const args = label ? `add ${label}` : 'add';
|
|
728
|
-
void apply('openai-account', args).then(r => {
|
|
729
|
-
const url = r.knobs.url;
|
|
730
|
-
const instructions = r.knobs.instructions;
|
|
731
|
-
if (!url) {
|
|
732
|
-
api.ui.toast({
|
|
733
|
-
message: 'Failed to get auth URL',
|
|
734
|
-
variant: 'warning'
|
|
735
|
-
});
|
|
736
|
-
showL1();
|
|
737
|
-
return;
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
// Auto-open the browser (best-effort)
|
|
741
|
-
try {
|
|
742
|
-
openUrl(url);
|
|
743
|
-
} catch {
|
|
744
|
-
// best-effort
|
|
745
|
-
}
|
|
746
|
-
showBrowserAuthScreen(url, instructions);
|
|
747
|
-
});
|
|
748
|
-
}
|
|
749
|
-
function showBrowserAuthScreen(url, _instructions) {
|
|
750
|
-
const DialogSelectInner = api.ui.DialogSelect;
|
|
751
|
-
api.ui.dialog.setSize('xlarge');
|
|
752
|
-
api.ui.dialog.replace(() => _$createComponent(DialogSelectInner, {
|
|
753
|
-
title: "Browser sign-in",
|
|
754
|
-
options: [{
|
|
755
|
-
title: 'Copy auth URL',
|
|
756
|
-
value: 'copy_url',
|
|
757
|
-
description: url
|
|
758
|
-
}, {
|
|
759
|
-
title: 'Open in browser',
|
|
760
|
-
value: 'open',
|
|
761
|
-
description: 'Try to open the URL in your browser'
|
|
762
|
-
}, {
|
|
763
|
-
title: "Done / I've authorized",
|
|
764
|
-
value: 'done',
|
|
765
|
-
description: 'Return to account list'
|
|
766
|
-
}, {
|
|
767
|
-
title: 'Cancel',
|
|
768
|
-
value: 'cancel',
|
|
769
|
-
description: 'Return to account list without adding'
|
|
770
|
-
}],
|
|
771
|
-
skipFilter: true,
|
|
772
|
-
onSelect: option => {
|
|
773
|
-
if (option.value === 'copy_url') {
|
|
774
|
-
const ok = osc52Copy(api, url);
|
|
775
|
-
api.ui.toast({
|
|
776
|
-
message: ok ? 'Auth URL copied' : 'Copy unsupported — select the URL text manually',
|
|
777
|
-
variant: ok ? 'success' : 'warning'
|
|
778
|
-
});
|
|
779
|
-
return;
|
|
780
|
-
}
|
|
781
|
-
if (option.value === 'open') {
|
|
782
|
-
try {
|
|
783
|
-
openUrl(url);
|
|
784
|
-
} catch {
|
|
785
|
-
// best-effort
|
|
786
|
-
}
|
|
787
|
-
return;
|
|
788
|
-
}
|
|
789
|
-
showL1();
|
|
790
|
-
}
|
|
791
|
-
}));
|
|
792
|
-
}
|
|
793
|
-
function startDeviceAdd(label) {
|
|
794
|
-
const args = label ? `add --headless ${label}` : 'add --headless';
|
|
795
|
-
void apply('openai-account', args).then(r => {
|
|
796
|
-
const verificationUrl = r.knobs.verificationUrl;
|
|
797
|
-
const userCode = r.knobs.userCode;
|
|
798
|
-
const instructions = r.knobs.instructions;
|
|
799
|
-
if (!verificationUrl) {
|
|
800
|
-
api.ui.toast({
|
|
801
|
-
message: 'Failed to get device code',
|
|
802
|
-
variant: 'warning'
|
|
803
|
-
});
|
|
804
|
-
showL1();
|
|
805
|
-
return;
|
|
806
|
-
}
|
|
807
|
-
showDeviceCodeScreen(verificationUrl, userCode, instructions);
|
|
808
|
-
});
|
|
809
|
-
}
|
|
810
|
-
function showDeviceCodeScreen(verificationUrl, userCode, _instructions) {
|
|
811
|
-
const DialogSelectInner = api.ui.DialogSelect;
|
|
812
|
-
api.ui.dialog.setSize('xlarge');
|
|
813
|
-
api.ui.dialog.replace(() => _$createComponent(DialogSelectInner, {
|
|
814
|
-
title: "Device code",
|
|
815
|
-
options: [{
|
|
816
|
-
title: userCode ? `Copy code: ${userCode}` : 'Copy code',
|
|
817
|
-
value: 'copy_code',
|
|
818
|
-
description: 'Copy the user code to clipboard'
|
|
819
|
-
}, {
|
|
820
|
-
title: 'Copy URL',
|
|
821
|
-
value: 'copy_url',
|
|
822
|
-
description: verificationUrl
|
|
823
|
-
}, {
|
|
824
|
-
title: "Done / I've authorized",
|
|
825
|
-
value: 'done',
|
|
826
|
-
description: 'Return to account list'
|
|
827
|
-
}, {
|
|
828
|
-
title: 'Cancel',
|
|
829
|
-
value: 'cancel',
|
|
830
|
-
description: 'Return to account list without adding'
|
|
831
|
-
}],
|
|
832
|
-
skipFilter: true,
|
|
833
|
-
onSelect: option => {
|
|
834
|
-
if (option.value === 'copy_code' && userCode) {
|
|
835
|
-
const ok = osc52Copy(api, userCode);
|
|
836
|
-
api.ui.toast({
|
|
837
|
-
message: ok ? 'Code copied' : 'Copy unsupported — enter the code manually',
|
|
838
|
-
variant: ok ? 'success' : 'warning'
|
|
839
|
-
});
|
|
840
|
-
return;
|
|
841
|
-
}
|
|
842
|
-
if (option.value === 'copy_url') {
|
|
843
|
-
const ok = osc52Copy(api, verificationUrl);
|
|
844
|
-
api.ui.toast({
|
|
845
|
-
message: ok ? 'URL copied' : 'Copy unsupported — enter the URL manually',
|
|
846
|
-
variant: ok ? 'success' : 'warning'
|
|
847
|
-
});
|
|
848
|
-
return;
|
|
849
|
-
}
|
|
850
|
-
showL1();
|
|
851
|
-
}
|
|
852
|
-
}));
|
|
853
|
-
}
|
|
854
|
-
void showL1();
|
|
855
|
-
}
|