@firstpick/pi-package-webui 0.10.9 → 0.11.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/DEVELOPMENT.md +42 -2
- package/README.md +9 -3
- package/TECHNICAL.md +23 -1
- package/bin/pi-webui.mjs +72 -25
- package/lib/codex-cli-usage.mjs +232 -0
- package/lib/codex-usage-auth.mjs +39 -3
- package/lib/codex-usage-source.mjs +36 -0
- package/package.json +14 -8
- package/public/app.js +56 -24
- package/public/codex-speed-mode.mjs +36 -0
- package/public/index.html +6 -5
- package/public/service-worker.js +2 -1
- package/public/theme-contract.mjs +1 -1
- package/tests/boot-failure-diagnostics.test.mjs +2 -2
- package/tests/codex-cli-usage.test.mjs +189 -0
- package/tests/codex-fast-mode-static.test.mjs +12 -11
- package/tests/codex-speed-mode-browser-state.test.mjs +149 -0
- package/tests/codex-speed-mode.test.mjs +36 -0
- package/tests/codex-usage-auth.test.mjs +168 -9
- package/tests/codex-usage-http.test.mjs +124 -0
- package/tests/codex-usage-source.test.mjs +145 -0
- package/tests/composer-action-grid-reorder-static.test.mjs +2 -2
- package/tests/control-visibility-static.test.mjs +2 -2
- package/tests/controls-layout-static.test.mjs +2 -2
- package/tests/events-tree-context-menu-static.test.mjs +2 -2
- package/tests/fast-mode-client-static.test.mjs +1 -1
- package/tests/feature-decision-output-popup-static.test.mjs +1 -1
- package/tests/file-viewer-image-static.test.mjs +2 -2
- package/tests/fixtures/fake-codex-app-server.mjs +61 -0
- package/tests/fixtures/fake-pi.mjs +18 -8
- package/tests/guided-git-activation-static.test.mjs +2 -2
- package/tests/guided-git-fallback-ui-static.test.mjs +2 -2
- package/tests/host-peer-dependencies.test.mjs +24 -0
- package/tests/http-endpoints-harness.test.mjs +60 -0
- package/tests/intercom-conversation-viewer-static.test.mjs +2 -2
- package/tests/main-output-loading-static.test.mjs +2 -2
- package/tests/middle-button-drag-scroll-static.test.mjs +2 -2
- package/tests/mobile-continuity-tablet-static.test.mjs +2 -2
- package/tests/mobile-foundation-static.test.mjs +2 -2
- package/tests/mobile-phone-experience-static.test.mjs +1 -1
- package/tests/open-issue-wizard-static.test.mjs +1 -1
- package/tests/optional-feature-prompt-impact-static.test.mjs +2 -2
- package/tests/persistent-ui-layout-static.test.mjs +2 -2
- package/tests/prompt-input-vertical-scroll-static.test.mjs +2 -2
- package/tests/questionnaire-dialog.test.mjs +2 -2
- package/tests/session-sampling-ui-static.test.mjs +2 -2
- package/tests/side-panel-section-height-removal-static.test.mjs +2 -2
- package/tests/subagent-observability-static.test.mjs +2 -2
- package/tests/syntax-highlighting-static.test.mjs +2 -2
- package/tests/theme-contract.test.mjs +10 -3
- package/tests/theme-customizer-static.test.mjs +1 -1
- package/tests/windows-drive-cwd-picker-static.test.mjs +2 -2
package/lib/codex-usage-auth.mjs
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
export const CODEX_TOKEN_REFRESH_SKEW_MS = 5 * 60 * 1000;
|
|
2
|
+
export const CODEX_USAGE_DIRECT_TOKEN_MESSAGE = "Your ChatGPT login is configured, but Codex usage reporting is unavailable for Pi's Sign in with ChatGPT authentication. Check https://chatgpt.com/settings/usage. Logging in again will not enable this panel.";
|
|
3
|
+
|
|
4
|
+
function isDirectChatGPTCredential(credential) {
|
|
5
|
+
return credential?.type === "oauth" && Array.isArray(credential.scopes) && credential.scopes.includes("chatgpt.tokens.use.direct");
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function unsupportedDirectAuth(providerId, credential) {
|
|
9
|
+
return { providerId, credential, accessToken: undefined, refreshed: false, unsupportedReason: "chatgpt-direct-token" };
|
|
10
|
+
}
|
|
2
11
|
|
|
3
12
|
function privateCredentialStore(modelRuntime) {
|
|
4
13
|
// Compatibility adapter: ModelRuntime intentionally does not expose a
|
|
@@ -11,12 +20,34 @@ function privateCredentialStore(modelRuntime) {
|
|
|
11
20
|
return credentials;
|
|
12
21
|
}
|
|
13
22
|
|
|
23
|
+
export function codexUsageLoginGuidance(modelRuntime) {
|
|
24
|
+
return modelRuntime.getProvider("openai")?.auth?.oauth?.isSubscription === true
|
|
25
|
+
? "Run /login, choose OpenAI, then Sign in with ChatGPT."
|
|
26
|
+
: "Run /login and choose ChatGPT Plus/Pro (Codex Subscription).";
|
|
27
|
+
}
|
|
28
|
+
|
|
14
29
|
export async function resolveCodexUsageAuth(modelRuntime, providerId, options = {}) {
|
|
15
30
|
const now = options.now ?? Date.now();
|
|
16
31
|
const forceRefresh = options.forceRefresh === true;
|
|
17
32
|
const credentials = privateCredentialStore(modelRuntime);
|
|
18
|
-
|
|
33
|
+
let provider = modelRuntime.getProvider(providerId);
|
|
19
34
|
let stored = await credentials.read(providerId);
|
|
35
|
+
// Newer Pi versions store ChatGPT OAuth under the unified OpenAI provider.
|
|
36
|
+
// Only select that alias when the runtime supports subscription OAuth.
|
|
37
|
+
if (providerId === "openai-codex" && (stored?.type !== "oauth" || !provider?.auth?.oauth)) {
|
|
38
|
+
const openai = modelRuntime.getProvider("openai");
|
|
39
|
+
if (openai?.auth?.oauth?.isSubscription === true) {
|
|
40
|
+
const current = await credentials.read("openai");
|
|
41
|
+
if (current?.type === "oauth" || !provider?.auth?.oauth) {
|
|
42
|
+
providerId = "openai";
|
|
43
|
+
provider = openai;
|
|
44
|
+
stored = current;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// Sign in with ChatGPT tokens target api.openai.com, not the legacy Codex
|
|
49
|
+
// usage endpoint. Do not refresh or forward them just to report this limit.
|
|
50
|
+
if (isDirectChatGPTCredential(stored)) return unsupportedDirectAuth(providerId, stored);
|
|
20
51
|
let refreshed = false;
|
|
21
52
|
|
|
22
53
|
if (stored?.type === "oauth") {
|
|
@@ -28,7 +59,7 @@ export async function resolveCodexUsageAuth(modelRuntime, providerId, options =
|
|
|
28
59
|
|
|
29
60
|
if (shouldRefresh) {
|
|
30
61
|
await credentials.modify(providerId, async (current) => {
|
|
31
|
-
if (current?.type !== "oauth") return undefined;
|
|
62
|
+
if (current?.type !== "oauth" || isDirectChatGPTCredential(current)) return undefined;
|
|
32
63
|
// Another process may have refreshed while this caller waited for the
|
|
33
64
|
// auth-file lock. Reuse that newer token rather than refreshing twice.
|
|
34
65
|
if (forceRefresh && current.access !== rejectedAccess) return undefined;
|
|
@@ -42,18 +73,23 @@ export async function resolveCodexUsageAuth(modelRuntime, providerId, options =
|
|
|
42
73
|
stored = await credentials.read(providerId);
|
|
43
74
|
}
|
|
44
75
|
|
|
76
|
+
if (isDirectChatGPTCredential(stored)) return unsupportedDirectAuth(providerId, stored);
|
|
45
77
|
if (forceRefresh && stored?.type === "oauth" && stored.access === rejectedAccess) {
|
|
46
78
|
throw new Error("Codex OAuth refresh returned the rejected credential.");
|
|
47
79
|
}
|
|
48
80
|
return {
|
|
81
|
+
providerId,
|
|
49
82
|
accessToken: stored?.type === "oauth" ? stored.access : undefined,
|
|
50
83
|
credential: stored,
|
|
51
84
|
refreshed: refreshed || (forceRefresh && stored?.type === "oauth" && stored.access !== rejectedAccess),
|
|
52
85
|
};
|
|
53
86
|
}
|
|
54
87
|
|
|
55
|
-
|
|
88
|
+
// OpenAI API keys are not ChatGPT subscription credentials. Never resolve
|
|
89
|
+
// the unified provider's API key or environment fallback for usage requests.
|
|
90
|
+
const resolved = providerId === "openai" ? undefined : await modelRuntime.getAuth(providerId);
|
|
56
91
|
return {
|
|
92
|
+
providerId,
|
|
57
93
|
accessToken: resolved?.auth?.apiKey,
|
|
58
94
|
credential: stored,
|
|
59
95
|
refreshed: false,
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { CodexCliUsageError } from "./codex-cli-usage.mjs";
|
|
2
|
+
|
|
3
|
+
export const CODEX_USAGE_CACHE_MS = 30_000;
|
|
4
|
+
|
|
5
|
+
/** Coalesce browser polls and cache only successful snapshots, never credentials or failures. */
|
|
6
|
+
export function createCodexUsageReader({ readCli, readLegacy, cacheMs = CODEX_USAGE_CACHE_MS, now = Date.now }) {
|
|
7
|
+
let cached;
|
|
8
|
+
let cachedAt = 0;
|
|
9
|
+
let inFlight;
|
|
10
|
+
return async function read(options = {}) {
|
|
11
|
+
if (inFlight) return inFlight;
|
|
12
|
+
if (!options.forceRefresh && cached && now() - cachedAt < cacheMs) return cached;
|
|
13
|
+
inFlight = (async () => {
|
|
14
|
+
let cliError;
|
|
15
|
+
try {
|
|
16
|
+
const result = await readCli();
|
|
17
|
+
cached = result;
|
|
18
|
+
cachedAt = now();
|
|
19
|
+
return result;
|
|
20
|
+
} catch (error) {
|
|
21
|
+
cliError = error instanceof CodexCliUsageError ? error : new CodexCliUsageError("CODEX_CLI_FAILED", "Codex CLI usage is unavailable.");
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
const result = await readLegacy(options);
|
|
25
|
+
cached = { ...result, sourceNotice: "Codex CLI usage is unavailable. Showing usage from Pi's legacy Codex login." };
|
|
26
|
+
cachedAt = now();
|
|
27
|
+
return cached;
|
|
28
|
+
} catch {
|
|
29
|
+
// Do not expose raw CLI diagnostics, Pi auth errors, account details,
|
|
30
|
+
// stack traces or upstream response bodies when both readers fail.
|
|
31
|
+
throw new CodexCliUsageError(cliError.code, `${cliError.message} Pi's legacy Codex usage fallback also could not provide usage. Check https://chatgpt.com/settings/usage.`, cliError.statusCode);
|
|
32
|
+
}
|
|
33
|
+
})();
|
|
34
|
+
try { return await inFlight; } finally { inFlight = undefined; }
|
|
35
|
+
};
|
|
36
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@firstpick/pi-package-webui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"description": "Pi Web UI companion package with a local browser UI CLI plus /webui-start and /webui-status commands.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/Firstp1ck/pi-coding-agent-forge/tree/main/pi-package-webui#readme",
|
|
@@ -30,17 +30,19 @@
|
|
|
30
30
|
"pi-webui": "./bin/pi-webui-launcher.mjs"
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
|
-
"check": "node --check public/app.js && node --check lib/app-runner-terminal.mjs && node --check public/middle-button-drag-scroll.mjs && node --check public/stream-output-controller.mjs && node --check public/theme-contract.mjs && node --check public/transcript-renderer.mjs && node --check public/syntax-highlight.mjs && node --check public/mobile-shell-state.mjs && node --check public/issue-wizard-state.mjs && node --check public/issue-bot-client.mjs && node --check public/workflow-status-stack.mjs && node --check public/fast-output-live.mjs && node --check public/subagent-launch-slot-state.mjs && node --check public/subagent-gate-visibility.mjs && node --check public/voice-conversation.mjs && node --check public/aur-review-payload.mjs && node --check public/guided-git-command-state.mjs && node --check public/guided-git-review-state.mjs && node --check bin/pi-webui.mjs && node --check bin/pi-webui-launcher.mjs && node --check bin/pi-webui-native-update-runner.mjs && node --check bin/pi-webui-update-context.mjs && node --check lib/update/coordination.mjs && node --check lib/update/native-jobs.mjs && node --check lib/update/discovery.mjs && node --check lib/update/native-targets.mjs && node --check lib/update/path-pi.mjs && node --check lib/update/migration.mjs && node --check lib/update/supervisor.mjs && node --check bin/pi-webui-rpc-supervisor.mjs && node --check lib/rpc-supervisor-protocol.mjs && node --check lib/rpc-supervisor-state.mjs && node --check lib/rpc-supervisor-client.mjs && node --check webui-rpc-helper.mjs && node --check lib/subagent-launch-slots.mjs && node --check lib/git-live-watcher.mjs && node --check lib/workspace-files-live-watcher.mjs && node --check lib/git-message-artifacts.mjs && node --check lib/trust-boundaries.mjs && node --check lib/native-command-adapter.mjs && node --check lib/session-actions.mjs && node --check lib/auth-actions.mjs && node --check lib/temp-artifacts.mjs && node tests/run-all.mjs",
|
|
33
|
+
"check": "node --check public/app.js && node --check public/codex-speed-mode.mjs && node --check lib/app-runner-terminal.mjs && node --check public/middle-button-drag-scroll.mjs && node --check public/stream-output-controller.mjs && node --check public/theme-contract.mjs && node --check public/transcript-renderer.mjs && node --check public/syntax-highlight.mjs && node --check public/mobile-shell-state.mjs && node --check public/issue-wizard-state.mjs && node --check public/issue-bot-client.mjs && node --check public/workflow-status-stack.mjs && node --check public/fast-output-live.mjs && node --check public/subagent-launch-slot-state.mjs && node --check public/subagent-gate-visibility.mjs && node --check public/voice-conversation.mjs && node --check public/aur-review-payload.mjs && node --check public/guided-git-command-state.mjs && node --check public/guided-git-review-state.mjs && node --check bin/pi-webui.mjs && node --check bin/pi-webui-launcher.mjs && node --check bin/pi-webui-native-update-runner.mjs && node --check bin/pi-webui-update-context.mjs && node --check lib/update/coordination.mjs && node --check lib/update/native-jobs.mjs && node --check lib/update/discovery.mjs && node --check lib/update/native-targets.mjs && node --check lib/update/path-pi.mjs && node --check lib/update/migration.mjs && node --check lib/update/supervisor.mjs && node --check bin/pi-webui-rpc-supervisor.mjs && node --check lib/rpc-supervisor-protocol.mjs && node --check lib/rpc-supervisor-state.mjs && node --check lib/rpc-supervisor-client.mjs && node --check webui-rpc-helper.mjs && node --check lib/subagent-launch-slots.mjs && node --check lib/git-live-watcher.mjs && node --check lib/workspace-files-live-watcher.mjs && node --check lib/git-message-artifacts.mjs && node --check lib/trust-boundaries.mjs && node --check lib/native-command-adapter.mjs && node --check lib/session-actions.mjs && node --check lib/auth-actions.mjs && node --check lib/codex-cli-usage.mjs && node --check lib/codex-usage-source.mjs && node --check lib/temp-artifacts.mjs && node tests/run-all.mjs",
|
|
34
34
|
"test": "node tests/run-all.mjs",
|
|
35
35
|
"test:browser": "playwright test"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@earendil-works/pi-ai": "^0.83.0",
|
|
39
|
-
"@earendil-works/pi-coding-agent": "^0.87.0",
|
|
40
|
-
"@earendil-works/pi-tui": "^0.83.0",
|
|
41
38
|
"@firstpick/pi-utils": "^0.2.5",
|
|
42
|
-
"mermaid": "^11.15.0"
|
|
43
|
-
|
|
39
|
+
"mermaid": "^11.15.0"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"@earendil-works/pi-ai": "*",
|
|
43
|
+
"@earendil-works/pi-coding-agent": "*",
|
|
44
|
+
"@earendil-works/pi-tui": "*",
|
|
45
|
+
"typebox": "*"
|
|
44
46
|
},
|
|
45
47
|
"optionalDependencies": {
|
|
46
48
|
"node-pty": "^1.1.0"
|
|
@@ -72,6 +74,10 @@
|
|
|
72
74
|
},
|
|
73
75
|
"devDependencies": {
|
|
74
76
|
"@axe-core/playwright": "4.12.1",
|
|
75
|
-
"@
|
|
77
|
+
"@earendil-works/pi-ai": "^0.83.0",
|
|
78
|
+
"@earendil-works/pi-coding-agent": "^1.0.0",
|
|
79
|
+
"@earendil-works/pi-tui": "^0.83.0",
|
|
80
|
+
"@playwright/test": "1.62.1",
|
|
81
|
+
"typebox": "^1.3.6"
|
|
76
82
|
}
|
|
77
83
|
}
|
package/public/app.js
CHANGED
|
@@ -2,6 +2,7 @@ import { aurReviewSafePath as parsedAurReviewSafePath, parseAurReviewPayload as
|
|
|
2
2
|
import { GUIDED_GIT_START_STATUS_KEY, createGuidedGitActivationController, createGuidedGitLaunchPermitController, guidedGitLaunchBlockedReason, guidedGitLaunchModeForTabCatalog, guidedGitReviewAvailableForTabCatalog, guidedGitWorkflowCommandForTabCatalog, resolveCommandForTabCatalog, resolveRpcSlashCommandForTabCatalog } from "./guided-git-command-state.mjs";
|
|
3
3
|
import { guidedGitReviewCanRequestStagedContent, guidedGitReviewHasApprovedBinding, guidedGitReviewProcessNavigationAllowed, guidedGitReviewProcessSelectionPatch, guidedGitReviewTransition, guidedGitReviewWidgetRemovalTransition } from "./guided-git-review-state.mjs";
|
|
4
4
|
import { createFastOutputLiveState, createSustainedFlushScheduler, fastOutputLiveTextAndThinking, reduceFastOutputLiveEvent, seedFastOutputLiveState, shouldConsumeFastOutputLiveEvent } from "./fast-output-live.mjs";
|
|
5
|
+
import { codexSpeedModeFromData, codexSpeedModeFromStatus, codexSpeedModeLabel, isCodexSpeedMode } from "./codex-speed-mode.mjs";
|
|
5
6
|
import { addLaunchSlot, cloneLaunchSlotRoles, launchSlotRolesEqual, removeLaunchSlot, subagentLaunchSlotSaveState, updateLaunchSlot } from "./subagent-launch-slot-state.mjs";
|
|
6
7
|
import { pruneDismissedSubagentGateKeys, subagentGateIsTerminal, subagentGateKey, ungatedSubagentRuns, visibleSubagentGates } from "./subagent-gate-visibility.mjs";
|
|
7
8
|
import { groupConsecutiveWorkflowStatusItems, isCompletedWorkflowStatusExecution, workflowStatusSnapshot } from "./workflow-status-stack.mjs";
|
|
@@ -11396,7 +11397,7 @@ function setOptionalFeatureDisabled(featureId, disabled) {
|
|
|
11396
11397
|
if (featureId === "codexFastMode") {
|
|
11397
11398
|
if (disabled) {
|
|
11398
11399
|
statusEntries.delete(CODEX_FAST_MODE_STATUS_KEY);
|
|
11399
|
-
codexFastModeState = { ...codexFastModeState, available: false, enabled: false, statusKnown: false, busy: false };
|
|
11400
|
+
codexFastModeState = { ...codexFastModeState, available: false, enabled: false, mode: null, statusKnown: false, busy: false };
|
|
11400
11401
|
codexFastModeNotice = "";
|
|
11401
11402
|
renderCodexFastModeControl();
|
|
11402
11403
|
} else {
|
|
@@ -19130,7 +19131,10 @@ function applyOptimisticModelSelection(model, tabContext = activeTabContext()) {
|
|
|
19130
19131
|
const changed = modelStateKey(currentState.model) !== modelStateKey(nextModel);
|
|
19131
19132
|
currentState = { ...currentState, model: nextModel };
|
|
19132
19133
|
renderStatus();
|
|
19133
|
-
if (changed)
|
|
19134
|
+
if (changed) {
|
|
19135
|
+
requestGitFooterWebuiPayload(tabContext, { force: true });
|
|
19136
|
+
refreshCodexFastMode(tabContext).catch(() => null);
|
|
19137
|
+
}
|
|
19134
19138
|
return nextModel;
|
|
19135
19139
|
}
|
|
19136
19140
|
|
|
@@ -25296,6 +25300,8 @@ function codexUsageStructureSignature() {
|
|
|
25296
25300
|
return JSON.stringify({
|
|
25297
25301
|
state: "data",
|
|
25298
25302
|
plan: formatCodexPlanType(latestCodexUsage.planType),
|
|
25303
|
+
source: latestCodexUsage.source || "",
|
|
25304
|
+
sourceNotice: latestCodexUsage.sourceNotice || "",
|
|
25299
25305
|
buckets: codexUsageBuckets(latestCodexUsage).map((bucket) => [bucket.key, bucket.label]),
|
|
25300
25306
|
rateLimitReachedType: latestCodexUsage.rateLimitReachedType || "",
|
|
25301
25307
|
error: codexUsageError?.message || String(codexUsageError || ""),
|
|
@@ -25363,6 +25369,12 @@ function renderCodexUsage() {
|
|
|
25363
25369
|
make("span", "codex-usage-fetched", latestCodexUsage.fetchedAt ? `updated ${formatDurationParts(Date.now() - new Date(latestCodexUsage.fetchedAt).getTime())} ago` : "updated now"),
|
|
25364
25370
|
);
|
|
25365
25371
|
box.append(header);
|
|
25372
|
+
if (latestCodexUsage.source === "codex-cli") {
|
|
25373
|
+
box.append(make("div", "codex-usage-detail", "Source: Codex CLI account. Its login is separate from Pi; these limits may differ from Pi's ChatGPT-plan allowance."));
|
|
25374
|
+
} else {
|
|
25375
|
+
box.append(make("div", "codex-usage-detail", "Source: Pi's legacy Codex login."));
|
|
25376
|
+
}
|
|
25377
|
+
if (latestCodexUsage.sourceNotice) box.append(make("div", "codex-usage-detail", latestCodexUsage.sourceNotice));
|
|
25366
25378
|
|
|
25367
25379
|
if (buckets.length === 0) {
|
|
25368
25380
|
box.append(make("div", "codex-usage-detail", "No Codex rate-limit windows were returned."));
|
|
@@ -25414,7 +25426,7 @@ async function refreshCodexUsage({ forceAuthRefresh = false } = {}) {
|
|
|
25414
25426
|
// Codex subscription Fast mode is owned by the optional pi-extension-codex-fast-mode package. The
|
|
25415
25427
|
// browser only reads the sanitized tab-scoped server snapshot and asks the server to run the
|
|
25416
25428
|
// package-owned /fast-mode command; it never sees ChatGPT credentials or request payloads.
|
|
25417
|
-
let codexFastModeState = { available: false, enabled: false, statusKnown: false, busy: false, model: null, modelEligible: false, unavailableReason: "", creditNotice: "" };
|
|
25429
|
+
let codexFastModeState = { available: false, enabled: false, mode: null, statusKnown: false, busy: false, model: null, modelEligible: false, ultrafastModelEligible: false, unavailableReason: "", creditNotice: "" };
|
|
25418
25430
|
let codexFastModeLoaded = false;
|
|
25419
25431
|
let codexFastModeBusy = false;
|
|
25420
25432
|
let codexFastModeNotice = "";
|
|
@@ -25434,23 +25446,28 @@ function codexFastModeStatusText() {
|
|
|
25434
25446
|
if (!codexFastModeLoaded) return "Checking…";
|
|
25435
25447
|
if (!codexFastModeState.available) return codexFastModeState.unavailableReason || optionalFeatureUnavailableMessage("codexFastMode");
|
|
25436
25448
|
if (!codexFastModeState.statusKnown) return "Status unknown · This tab";
|
|
25437
|
-
|
|
25438
|
-
if (codexFastModeState.
|
|
25439
|
-
|
|
25449
|
+
const label = codexSpeedModeLabel(codexFastModeState.mode);
|
|
25450
|
+
if (codexFastModeState.busy) return `${label} · Busy`;
|
|
25451
|
+
const eligible = codexFastModeState.mode === "ultrafast" ? codexFastModeState.ultrafastModelEligible : codexFastModeState.modelEligible;
|
|
25452
|
+
if (codexFastModeState.enabled && codexFastModeState.model && !eligible) {
|
|
25453
|
+
return `${label} · Inactive for current model`;
|
|
25440
25454
|
}
|
|
25441
|
-
return `${
|
|
25455
|
+
return `${label} · This tab`;
|
|
25442
25456
|
}
|
|
25443
25457
|
|
|
25444
25458
|
function renderCodexFastModeControl({ syncSelection = true } = {}) {
|
|
25445
25459
|
if (!elements.codexFastModeSelect || !elements.setCodexFastModeButton || !elements.codexFastModeStatus) return;
|
|
25446
25460
|
if (syncSelection) {
|
|
25447
|
-
codexFastModeSelection = codexFastModeState.
|
|
25461
|
+
codexFastModeSelection = codexFastModeState.mode || "normal";
|
|
25448
25462
|
elements.codexFastModeSelect.value = codexFastModeSelection;
|
|
25449
25463
|
}
|
|
25450
25464
|
const controlDisabled = codexFastModeControlDisabled();
|
|
25465
|
+
const ultrafastOption = elements.codexFastModeSelect.querySelector('option[value="ultrafast"]');
|
|
25466
|
+
if (ultrafastOption) ultrafastOption.disabled = !codexFastModeState.ultrafastModelEligible;
|
|
25451
25467
|
elements.codexFastModeSelect.disabled = controlDisabled;
|
|
25452
25468
|
elements.setCodexFastModeButton.disabled = controlDisabled
|
|
25453
|
-
|| elements.codexFastModeSelect.value ===
|
|
25469
|
+
|| elements.codexFastModeSelect.value === codexFastModeState.mode
|
|
25470
|
+
|| (elements.codexFastModeSelect.value === "ultrafast" && !codexFastModeState.ultrafastModelEligible);
|
|
25454
25471
|
elements.setCodexFastModeButton.textContent = codexFastModeBusy ? "Applying…" : "Apply";
|
|
25455
25472
|
elements.codexFastModeStatus.textContent = codexFastModeStatusText();
|
|
25456
25473
|
const warn = !!codexFastModeNotice
|
|
@@ -25461,13 +25478,16 @@ function renderCodexFastModeControl({ syncSelection = true } = {}) {
|
|
|
25461
25478
|
}
|
|
25462
25479
|
|
|
25463
25480
|
function applyCodexFastModeData(data) {
|
|
25481
|
+
const mode = codexSpeedModeFromData(data);
|
|
25464
25482
|
codexFastModeState = {
|
|
25465
25483
|
available: data?.available === true,
|
|
25466
|
-
|
|
25484
|
+
mode,
|
|
25485
|
+
enabled: mode !== null && mode !== "normal",
|
|
25467
25486
|
statusKnown: data?.statusKnown === true,
|
|
25468
25487
|
busy: data?.busy === true,
|
|
25469
25488
|
model: data?.model || null,
|
|
25470
25489
|
modelEligible: data?.modelEligible === true,
|
|
25490
|
+
ultrafastModelEligible: data?.ultrafastModelEligible === true,
|
|
25471
25491
|
unavailableReason: data?.unavailableReason || "",
|
|
25472
25492
|
creditNotice: data?.creditNotice || "",
|
|
25473
25493
|
};
|
|
@@ -25475,22 +25495,23 @@ function applyCodexFastModeData(data) {
|
|
|
25475
25495
|
}
|
|
25476
25496
|
|
|
25477
25497
|
function codexFastModeConfirmedOff(data) {
|
|
25478
|
-
return data?.statusKnown === true && data
|
|
25498
|
+
return data?.statusKnown === true && codexSpeedModeFromData(data) === "normal";
|
|
25479
25499
|
}
|
|
25480
25500
|
|
|
25481
25501
|
function applyCodexFastModeStatus(statusText) {
|
|
25482
|
-
const
|
|
25483
|
-
if (
|
|
25502
|
+
const mode = codexSpeedModeFromStatus(statusText);
|
|
25503
|
+
if (mode === null) return false;
|
|
25484
25504
|
codexFastModeState = {
|
|
25485
25505
|
...codexFastModeState,
|
|
25486
25506
|
available: true,
|
|
25487
|
-
|
|
25507
|
+
mode,
|
|
25508
|
+
enabled: mode !== "normal",
|
|
25488
25509
|
statusKnown: true,
|
|
25489
25510
|
};
|
|
25490
25511
|
codexFastModeLoaded = true;
|
|
25491
25512
|
codexFastModeNotice = "";
|
|
25492
25513
|
renderCodexFastModeControl();
|
|
25493
|
-
if (
|
|
25514
|
+
if (mode !== "normal" && !isOptionalFeatureEnabled("codexFastMode")) {
|
|
25494
25515
|
const tabContext = activeTabContext();
|
|
25495
25516
|
queueMicrotask(() => refreshCodexFastMode(tabContext).catch((error) => {
|
|
25496
25517
|
if (isCurrentTabContext(tabContext)) addEvent(`Disabled Codex Fast mode could not be disarmed: ${error.message || String(error)}`, "error");
|
|
@@ -25530,21 +25551,32 @@ async function refreshCodexFastMode(tabContext = activeTabContext()) {
|
|
|
25530
25551
|
}
|
|
25531
25552
|
|
|
25532
25553
|
async function applyCodexFastMode() {
|
|
25533
|
-
if (!elements.codexFastModeSelect ||
|
|
25554
|
+
if (!elements.codexFastModeSelect || codexFastModeControlDisabled()) return;
|
|
25534
25555
|
const tabContext = activeTabContext();
|
|
25535
25556
|
if (!tabContext.tabId) return;
|
|
25536
|
-
const
|
|
25537
|
-
if (
|
|
25557
|
+
const mode = elements.codexFastModeSelect.value;
|
|
25558
|
+
if (!isCodexSpeedMode(mode) || mode === codexFastModeState.mode) return;
|
|
25559
|
+
if (mode === "ultrafast" && !codexFastModeState.ultrafastModelEligible) return;
|
|
25538
25560
|
codexFastModeBusy = true;
|
|
25539
25561
|
codexFastModeNotice = "";
|
|
25540
25562
|
renderCodexFastModeControl({ syncSelection: false });
|
|
25541
25563
|
try {
|
|
25542
|
-
|
|
25564
|
+
if (mode === "ultrafast") {
|
|
25565
|
+
const confirmed = await appConfirm({
|
|
25566
|
+
title: "Use Codex Ultrafast?",
|
|
25567
|
+
summary: "Ultrafast uses 8x Standard included usage or 6x purchased-credit/pay-as-you-go usage. It requires GPT-6 Astra and Pro $500 or eligible Enterprise/Edu access; workspace terms may differ.",
|
|
25568
|
+
affected: "This tab's session branch. Future requests may cost more.",
|
|
25569
|
+
undoable: true,
|
|
25570
|
+
confirmLabel: "Use Ultrafast",
|
|
25571
|
+
});
|
|
25572
|
+
if (!confirmed || !isCurrentTabContext(tabContext) || !isOptionalFeatureEnabled("codexFastMode")) return;
|
|
25573
|
+
}
|
|
25574
|
+
const response = await api("/api/codex-fast-mode", { method: "PUT", body: { mode }, tabId: tabContext.tabId });
|
|
25543
25575
|
if (!isCurrentTabContext(tabContext)) return;
|
|
25544
25576
|
applyCodexFastModeData(response.data);
|
|
25545
|
-
addEvent(
|
|
25546
|
-
? "Codex
|
|
25547
|
-
:
|
|
25577
|
+
addEvent(mode === "normal"
|
|
25578
|
+
? "Codex speed override turned off for this session; requests keep their existing service tier."
|
|
25579
|
+
: `Codex ${codexSpeedModeLabel(mode)} requested for this session. ${codexFastModeState.creditNotice} This preference does not confirm upstream acceptance.`, "info");
|
|
25548
25580
|
} catch (error) {
|
|
25549
25581
|
if (!isCurrentTabContext(tabContext)) return;
|
|
25550
25582
|
codexFastModeNotice = `Failed to change Codex Fast mode: ${error.message || String(error)}. You can retry.`;
|
|
@@ -46134,10 +46166,10 @@ async function refreshState(tabContext = activeTabContext()) {
|
|
|
46134
46166
|
renderStatus();
|
|
46135
46167
|
if (mobilePhoneExperienceInstalled && isMobileShellV2Active()) renderMobilePhoneExperience();
|
|
46136
46168
|
requestGitFooterWebuiPayload(tabContext, { force: shouldRefreshGitFooter });
|
|
46137
|
-
// Sampling support and
|
|
46138
|
-
// them whenever the session reports a different model.
|
|
46169
|
+
// Sampling support and speed-tier eligibility depend on the active model.
|
|
46139
46170
|
if (modelStateKey(previousState?.model) !== modelStateKey(currentState?.model)) {
|
|
46140
46171
|
refreshSamplingParametersForTabContext(tabContext);
|
|
46172
|
+
refreshCodexFastMode(tabContext).catch(() => null);
|
|
46141
46173
|
}
|
|
46142
46174
|
}
|
|
46143
46175
|
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export function isCodexSpeedMode(value) {
|
|
2
|
+
return value === "normal" || value === "fast" || value === "ultrafast";
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function codexSpeedModeFromStatus(value) {
|
|
6
|
+
const status = String(value || "").trim().toLowerCase();
|
|
7
|
+
if (status === "off") return "normal";
|
|
8
|
+
if (status === "on") return "fast";
|
|
9
|
+
if (status === "ultrafast") return "ultrafast";
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function codexSpeedModeFromData(data) {
|
|
14
|
+
if (Object.hasOwn(data || {}, "mode")) return isCodexSpeedMode(data.mode) ? data.mode : null;
|
|
15
|
+
return data?.statusKnown === true ? (data.enabled === true ? "fast" : "normal") : null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Legacy boolean writes select Normal or Fast; an explicit mode must not contradict them. */
|
|
19
|
+
export function codexSpeedModeFromIntent(body) {
|
|
20
|
+
if (Object.hasOwn(body || {}, "mode")) {
|
|
21
|
+
if (!isCodexSpeedMode(body.mode)) throw new TypeError("Codex speed requires mode normal, fast, or ultrafast");
|
|
22
|
+
if (Object.hasOwn(body, "enabled") && (typeof body.enabled !== "boolean" || body.enabled !== (body.mode !== "normal"))) {
|
|
23
|
+
throw new TypeError("Codex speed mode and enabled must agree");
|
|
24
|
+
}
|
|
25
|
+
return body.mode;
|
|
26
|
+
}
|
|
27
|
+
if (typeof body?.enabled !== "boolean") throw new TypeError("Codex speed requires an explicit mode or enabled boolean");
|
|
28
|
+
return body.enabled ? "fast" : "normal";
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function codexSpeedModeLabel(mode) {
|
|
32
|
+
if (mode === "normal") return "Normal";
|
|
33
|
+
if (mode === "fast") return "Fast";
|
|
34
|
+
if (mode === "ultrafast") return "Ultrafast";
|
|
35
|
+
return "Unknown";
|
|
36
|
+
}
|
package/public/index.html
CHANGED
|
@@ -1051,14 +1051,15 @@
|
|
|
1051
1051
|
<div id="codexUsageBox" class="codex-usage-box muted">Checking Codex usage…</div>
|
|
1052
1052
|
<div class="control-field codex-fast-mode-control" aria-labelledby="codexFastModeLabel">
|
|
1053
1053
|
<div class="codex-fast-mode-row">
|
|
1054
|
-
<label id="codexFastModeLabel" for="codexFastModeSelect" title="Fast
|
|
1055
|
-
<select id="codexFastModeSelect" title="
|
|
1054
|
+
<label id="codexFastModeLabel" for="codexFastModeSelect" title="Normal, Fast, or Ultrafast for subscription-backed Codex requests on this tab">Speed mode</label>
|
|
1055
|
+
<select id="codexFastModeSelect" title="Ultrafast requires GPT-6 Astra and eligible plan access; it uses 8x included usage or 6x purchased credits" aria-describedby="codexFastModeStatus" disabled>
|
|
1056
1056
|
<option value="normal">Normal</option>
|
|
1057
1057
|
<option value="fast">Fast</option>
|
|
1058
|
+
<option value="ultrafast" disabled>Ultrafast</option>
|
|
1058
1059
|
</select>
|
|
1059
|
-
<button id="setCodexFastModeButton" class="control-apply-button" type="button" aria-label="Apply selected Codex
|
|
1060
|
+
<button id="setCodexFastModeButton" class="control-apply-button" type="button" aria-label="Apply selected Codex speed mode" disabled>Apply</button>
|
|
1060
1061
|
</div>
|
|
1061
|
-
<div id="codexFastModeStatus" class="toggle-control-hint" role="status" aria-live="polite">Checking Codex
|
|
1062
|
+
<div id="codexFastModeStatus" class="toggle-control-hint" role="status" aria-live="polite">Checking Codex speed mode…</div>
|
|
1062
1063
|
</div>
|
|
1063
1064
|
</div>
|
|
1064
1065
|
</section>
|
|
@@ -1897,7 +1898,7 @@
|
|
|
1897
1898
|
</form>
|
|
1898
1899
|
</dialog>
|
|
1899
1900
|
|
|
1900
|
-
<script id="webuiBootLoader" data-app-src="/app.js?v=
|
|
1901
|
+
<script id="webuiBootLoader" data-app-src="/app.js?v=185">
|
|
1901
1902
|
(() => {
|
|
1902
1903
|
"use strict";
|
|
1903
1904
|
|
package/public/service-worker.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const CACHE_NAME = "pi-webui-pwa-
|
|
1
|
+
const CACHE_NAME = "pi-webui-pwa-v156";
|
|
2
2
|
const APP_SHELL = [
|
|
3
3
|
"/",
|
|
4
4
|
"/index.html",
|
|
@@ -11,6 +11,7 @@ const APP_SHELL = [
|
|
|
11
11
|
"/guided-git-command-state.mjs",
|
|
12
12
|
"/guided-git-review-state.mjs",
|
|
13
13
|
"/fast-output-live.mjs",
|
|
14
|
+
"/codex-speed-mode.mjs",
|
|
14
15
|
"/stream-output-controller.mjs",
|
|
15
16
|
"/stream-derived-output.mjs",
|
|
16
17
|
"/stream-markdown-tail.mjs",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const PI_THEME_SCHEMA_URL = "https://
|
|
1
|
+
export const PI_THEME_SCHEMA_URL = "https://pi.dev/schemas/theme.schema.json";
|
|
2
2
|
|
|
3
3
|
export const THEME_TOKEN_GROUPS = Object.freeze([
|
|
4
4
|
{ id: "core", label: "Core UI", tokens: [
|
|
@@ -84,7 +84,7 @@ function makeEnvironment({
|
|
|
84
84
|
removeEventListener(name) { listeners.delete(name); },
|
|
85
85
|
};
|
|
86
86
|
const document = {
|
|
87
|
-
currentScript: new FakeElement({ dataset: { appSrc: "/app.js?v=
|
|
87
|
+
currentScript: new FakeElement({ dataset: { appSrc: "/app.js?v=185" } }),
|
|
88
88
|
readyState: "complete",
|
|
89
89
|
querySelector(selector) {
|
|
90
90
|
return {
|
|
@@ -232,7 +232,7 @@ for (const moduleName of startupModuleNames) {
|
|
|
232
232
|
assert.ok(serviceWorker.includes(`"/${moduleName}"`), `the PWA app shell should include every app.js startup module: ${moduleName}`);
|
|
233
233
|
}
|
|
234
234
|
assert.match(serviceWorker, /pi-webui-pwa-v\d+/, "the app-shell cache should retain a versioned identity");
|
|
235
|
-
assert.ok(html.indexOf('id="webuiBootLoader"') < html.indexOf("/app.js?v=
|
|
235
|
+
assert.ok(html.indexOf('id="webuiBootLoader"') < html.indexOf("/app.js?v=185"), "the inline loader should own app module startup");
|
|
236
236
|
assert.doesNotMatch(html, /<script type="module" src="\/app\.js/, "the app module should not bypass the guarded loader");
|
|
237
237
|
|
|
238
238
|
console.log("boot-failure-diagnostics.test.mjs passed");
|