@firstpick/pi-package-webui 0.8.6 → 0.8.8
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 +18 -606
- package/bin/pi-webui-launcher.mjs +22 -0
- package/bin/pi-webui-update-supervisor.mjs +86 -0
- package/bin/pi-webui.mjs +562 -524
- package/index.ts +8 -5
- package/lib/component-update-state.mjs +21 -0
- package/lib/git-workflow-preferences.mjs +17 -2
- package/lib/optional-feature-catalog.mjs +1 -0
- package/lib/sampling-parameter-capabilities.mjs +160 -0
- package/lib/session-summary-preferences.mjs +16 -1
- package/lib/subagent-launch-slots.mjs +14 -2
- package/lib/trust-boundaries.mjs +3 -0
- package/lib/update/executor.mjs +99 -0
- package/lib/update/journal.mjs +175 -0
- package/lib/update/owners.mjs +70 -0
- package/lib/update/plan.mjs +134 -0
- package/lib/update/resolver.mjs +168 -0
- package/lib/update/supervisor.mjs +238 -0
- package/lib/update/verify.mjs +52 -0
- package/lib/update-commands.mjs +25 -13
- package/lib/webui-workspaces.mjs +17 -1
- package/package.json +4 -4
- package/public/app.js +1543 -109
- package/public/index.html +146 -48
- package/public/middle-button-drag-scroll.mjs +154 -0
- package/public/sampling-parameter-controls.mjs +361 -0
- package/public/service-worker.js +3 -1
- package/public/styles.css +512 -1
- package/tests/boot-failure-diagnostics.test.mjs +3 -3
- package/tests/browser/control-deck-component-updates.spec.mjs +20 -22
- package/tests/browser/middle-button-drag-scroll.spec.mjs +145 -0
- package/tests/browser/persistent-ui-layout.spec.mjs +68 -23
- package/tests/browser/sampling-tooltip.spec.mjs +228 -0
- package/tests/browser/update-reconnect.spec.mjs +92 -0
- package/tests/codex-fast-mode-static.test.mjs +2 -2
- package/tests/common-options-submenus-interaction-static.test.mjs +172 -0
- package/tests/common-options-submenus-markup-static.test.mjs +152 -0
- package/tests/component-update-api-static.test.mjs +22 -61
- package/tests/composer-action-grid-reorder-static.test.mjs +3 -3
- package/tests/control-deck-component-updates-static.test.mjs +13 -237
- package/tests/durable-rpc-supervisor-harness.test.mjs +3 -1
- package/tests/fast-mode-client-static.test.mjs +1 -1
- package/tests/feature-decision-output-popup-static.test.mjs +2 -2
- package/tests/feature-system-prompt-optional-feature-static.test.mjs +49 -0
- package/tests/fixtures/fake-pi.mjs +68 -1
- package/tests/fixtures/update/tree-timeout-descendant.mjs +6 -0
- package/tests/fixtures/update/tree-timeout-parent.mjs +11 -0
- package/tests/git-footer-context-menu-static.test.mjs +58 -0
- package/tests/http-endpoints-harness.test.mjs +68 -18
- package/tests/middle-button-drag-scroll-static.test.mjs +24 -0
- package/tests/middle-button-drag-scroll.test.mjs +170 -0
- package/tests/mobile-continuity-tablet-static.test.mjs +3 -3
- package/tests/mobile-foundation-static.test.mjs +4 -4
- package/tests/mobile-phone-experience-static.test.mjs +1 -1
- package/tests/mobile-static.test.mjs +217 -24
- package/tests/open-issue-wizard-static.test.mjs +1 -1
- package/tests/optional-feature-migration-frontend.test.mjs +13 -5
- package/tests/persistent-ui-layout-static.test.mjs +13 -2
- package/tests/prompt-routing-tab-status.test.mjs +8 -0
- package/tests/questionnaire-dialog.test.mjs +3 -3
- package/tests/remote-auth-settings-harness.test.mjs +34 -0
- package/tests/rpc-supervisor-host.test.mjs +11 -2
- package/tests/safety-guard-auto-review-harness.test.mjs +117 -0
- package/tests/safety-guard-auto-review-static.test.mjs +34 -0
- package/tests/sampling-native-controls-user-flow.test.mjs +752 -0
- package/tests/sampling-parameter-capabilities.test.mjs +167 -0
- package/tests/sampling-parameter-controls.test.mjs +241 -0
- package/tests/session-sampling-helper.test.mjs +228 -0
- package/tests/session-sampling-http.test.mjs +168 -0
- package/tests/session-sampling-ui-static.test.mjs +370 -0
- package/tests/session-summary-core.test.mjs +24 -11
- package/tests/side-panel-section-height-removal-static.test.mjs +34 -0
- package/tests/side-panel-section-reorder-static.test.mjs +3 -3
- package/tests/staged-content-hash-contract.test.mjs +52 -11
- package/tests/subagent-launch-slots.test.mjs +18 -1
- package/tests/theme-customizer-static.test.mjs +1 -1
- package/tests/ui-layout-settings.test.mjs +18 -1
- package/tests/update-api-harness.test.mjs +111 -0
- package/tests/update-commands.test.mjs +15 -45
- package/tests/update-executor-process-tree-harness.test.mjs +22 -0
- package/tests/update-journal-harness.test.mjs +59 -0
- package/tests/update-lock-multiprocess-harness.test.mjs +46 -0
- package/tests/update-owners.test.mjs +27 -0
- package/tests/update-plan.test.mjs +58 -0
- package/tests/update-resolver.test.mjs +56 -0
- package/tests/update-supervisor-harness.test.mjs +57 -0
- package/tests/update-tab-restore-harness.test.mjs +24 -0
- package/tests/update-verify.test.mjs +31 -0
- package/tests/workspace-files-live-updates-static.test.mjs +13 -4
- package/webui-rpc-helper.mjs +119 -0
package/public/app.js
CHANGED
|
@@ -10,7 +10,19 @@ import { createIssueBotClient, readIssueBotRuntimeConfig } from "./issue-bot-cli
|
|
|
10
10
|
import { MOBILE_SHELL_STORAGE_KEY, TABLET_SHELL_STORAGE_KEY, createMobileShellState, isMobileShellV2Enabled, mobileNavigationTargetFromSearch, normalizeMobileNavigationTarget, reduceMobileShellState, resolveMobileShellFeatureMode, resolveTabletShellFeatureMode } from "./mobile-shell-state.mjs";
|
|
11
11
|
import { createTranscriptRenderer } from "./transcript-renderer.mjs";
|
|
12
12
|
import { createStreamOutputController } from "./stream-output-controller.mjs";
|
|
13
|
+
import { installMiddleButtonDragScroll } from "./middle-button-drag-scroll.mjs";
|
|
13
14
|
import { PI_THEME_EXPORT_FIELDS, THEME_TOKEN_GROUPS, canonicalizeTheme, serializeTheme, themeColorToRgb, validateTheme } from "./theme-contract.mjs";
|
|
15
|
+
import {
|
|
16
|
+
SAMPLING_PARAMETER_CATALOG,
|
|
17
|
+
buildSamplingParametersFromDraft,
|
|
18
|
+
createSamplingControlDraft,
|
|
19
|
+
samplingControlDraftEquals,
|
|
20
|
+
samplingParameterCapability,
|
|
21
|
+
samplingParameterSliderValue,
|
|
22
|
+
splitSamplingParameters,
|
|
23
|
+
summarizePreservedSamplingParameters,
|
|
24
|
+
validateSamplingControlDraft,
|
|
25
|
+
} from "./sampling-parameter-controls.mjs";
|
|
14
26
|
|
|
15
27
|
const $ = (selector) => document.querySelector(selector);
|
|
16
28
|
|
|
@@ -315,6 +327,7 @@ const elements = {
|
|
|
315
327
|
fileSelectionSendButton: $("#fileSelectionSendButton"),
|
|
316
328
|
fileContextMenu: $("#fileContextMenu"),
|
|
317
329
|
sidePanelContextMenu: $("#sidePanelContextMenu"),
|
|
330
|
+
gitFooterContextMenu: $("#gitFooterContextMenu"),
|
|
318
331
|
sidePanelResizeHandle: $("#sidePanelResizeHandle"),
|
|
319
332
|
toggleSidePanelButton: $("#toggleSidePanelButton"),
|
|
320
333
|
sidePanelExpandButton: $("#sidePanelExpandButton"),
|
|
@@ -339,6 +352,13 @@ const elements = {
|
|
|
339
352
|
issueWizardBotButton: $("#issueWizardBotButton"),
|
|
340
353
|
issueWizardBotHint: $("#issueWizardBotHint"),
|
|
341
354
|
stateDetails: $("#stateDetails"),
|
|
355
|
+
samplingParametersSupport: $("#samplingParametersSupport"),
|
|
356
|
+
samplingParametersControls: $("#samplingParametersControls"),
|
|
357
|
+
samplingParametersPreserved: $("#samplingParametersPreserved"),
|
|
358
|
+
applySamplingParametersButton: $("#applySamplingParametersButton"),
|
|
359
|
+
resetSamplingParametersButton: $("#resetSamplingParametersButton"),
|
|
360
|
+
reloadSamplingParametersButton: $("#reloadSamplingParametersButton"),
|
|
361
|
+
samplingParametersStatus: $("#samplingParametersStatus"),
|
|
342
362
|
subagentsStatus: $("#subagentsStatus"),
|
|
343
363
|
subagentsAutoClearButton: $("#subagentsAutoClearButton"),
|
|
344
364
|
subagentsClearFinishedButton: $("#subagentsClearFinishedButton"),
|
|
@@ -410,6 +430,17 @@ const elements = {
|
|
|
410
430
|
confirmationUndo: $("#confirmationUndo"),
|
|
411
431
|
confirmationCancelButton: $("#confirmationCancelButton"),
|
|
412
432
|
confirmationConfirmButton: $("#confirmationConfirmButton"),
|
|
433
|
+
gitPullErrorDialog: $("#gitPullErrorDialog"),
|
|
434
|
+
gitPullErrorDialogTitle: $("#gitPullErrorDialogTitle"),
|
|
435
|
+
gitPullErrorDialogDescription: $("#gitPullErrorDialogDescription"),
|
|
436
|
+
gitPullErrorOutput: $("#gitPullErrorOutput"),
|
|
437
|
+
gitPullErrorStatus: $("#gitPullErrorStatus"),
|
|
438
|
+
gitPullErrorRecovery: $("#gitPullErrorRecovery"),
|
|
439
|
+
gitPullErrorMergeButton: $("#gitPullErrorMergeButton"),
|
|
440
|
+
gitPullErrorRebaseButton: $("#gitPullErrorRebaseButton"),
|
|
441
|
+
gitPullErrorReviewButton: $("#gitPullErrorReviewButton"),
|
|
442
|
+
gitPullErrorCopyButton: $("#gitPullErrorCopyButton"),
|
|
443
|
+
gitPullErrorCloseButton: $("#gitPullErrorCloseButton"),
|
|
413
444
|
workspaceLoadDialog: $("#workspaceLoadDialog"),
|
|
414
445
|
workspaceLoadDialogCloseButton: $("#workspaceLoadDialogCloseButton"),
|
|
415
446
|
workspaceLoadDialogStatus: $("#workspaceLoadDialogStatus"),
|
|
@@ -524,6 +555,7 @@ let tabAttachments = new Map();
|
|
|
524
555
|
let activeTextAttachmentEditor = null;
|
|
525
556
|
let activeSkillEditor = null;
|
|
526
557
|
let fileTreeState = { root: "", entriesByPath: new Map(), expanded: new Set(), loading: new Set(), selectedPath: "", requestSerial: 0, searchQuery: "", searchEntries: [], searchLoading: false, searchTruncated: false, searchTotal: 0, gitStatusRoot: "", gitStatusByPath: new Map() };
|
|
558
|
+
let fileTreeLastRenderSignature = "";
|
|
527
559
|
let activeFileViewer = null;
|
|
528
560
|
let fileViewersByTab = new Map();
|
|
529
561
|
let fileViewerOpenRequestSerial = 0;
|
|
@@ -537,6 +569,7 @@ let fileViewerSearchTimer = null;
|
|
|
537
569
|
let fileViewerSearchHighlightElement = null;
|
|
538
570
|
let fileContextMenuState = null;
|
|
539
571
|
let sidePanelContextMenuState = null;
|
|
572
|
+
let gitFooterContextMenuState = null;
|
|
540
573
|
let sidePanelSectionPointerDrag = null;
|
|
541
574
|
let sidePanelSectionLastDragOverKey = "";
|
|
542
575
|
let sidePanelSectionSuppressClickUntil = 0;
|
|
@@ -785,6 +818,19 @@ let appRunnerSearchPathDraft = "";
|
|
|
785
818
|
let appRunnerSearchPathFeedback = { type: "", message: "" };
|
|
786
819
|
let appRunnerDirectoryBrowserState = { open: false, loading: false, path: "", data: null, error: "" };
|
|
787
820
|
let optionsMenuOpen = false;
|
|
821
|
+
const OPTIONS_SUBMENU_GROUP_SELECTOR = "[data-options-submenu]";
|
|
822
|
+
const OPTIONS_SUBMENU_TRIGGER_SELECTOR = "[data-options-submenu-trigger]";
|
|
823
|
+
const OPTIONS_SUBMENU_PANEL_SELECTOR = "[data-options-submenu-panel]";
|
|
824
|
+
const OPTIONS_SUBMENU_BACK_SELECTOR = "[data-options-submenu-back]";
|
|
825
|
+
const OPTIONS_SUBMENU_LEFT_CLASS = "opens-left";
|
|
826
|
+
const OPTIONS_SUBMENU_DRILL_IN_QUERY = "(hover: none), (pointer: coarse)";
|
|
827
|
+
const OPTIONS_MENU_LABEL_SELECTOR = '.composer-options-menu-item > span:not([aria-hidden="true"]):not(.composer-options-submenu-chevron)';
|
|
828
|
+
const OPTIONS_MENU_LABEL_FONT_SIZE_PROPERTY = "--options-menu-label-font-size";
|
|
829
|
+
const OPTIONS_MENU_LABEL_MIN_FONT_SIZE_PX = 12;
|
|
830
|
+
let openOptionsSubmenuGroup = null;
|
|
831
|
+
let optionsSubmenuObserver = null;
|
|
832
|
+
let optionsSubmenuSyncing = false;
|
|
833
|
+
let optionsMenuLabelFitFrame = 0;
|
|
788
834
|
let availableCommands = [];
|
|
789
835
|
let rawAvailableCommands = [];
|
|
790
836
|
const commandCatalogsByTab = new Map();
|
|
@@ -865,10 +911,20 @@ let subagentLaunchSlotRequestSerial = 0;
|
|
|
865
911
|
let subagentLaunchSlotReloadRequired = false;
|
|
866
912
|
const subagentLaunchSlotReloadTabs = new Set();
|
|
867
913
|
let subagentLaunchSlotFocusTarget = null;
|
|
914
|
+
let samplingParametersState = null;
|
|
915
|
+
let samplingParametersStateTabId = null;
|
|
916
|
+
const samplingParametersDrafts = new Map();
|
|
917
|
+
let samplingParametersLoading = false;
|
|
918
|
+
let samplingParametersBusy = false;
|
|
919
|
+
let samplingParametersError = "";
|
|
920
|
+
let samplingParametersNotice = "";
|
|
921
|
+
let samplingParametersFeedbackTabId = null;
|
|
922
|
+
let samplingParametersRequestSerial = 0;
|
|
868
923
|
let backendOffline = false;
|
|
869
924
|
let serverRestartInProgress = false;
|
|
870
925
|
let updateRequestInProgress = false;
|
|
871
926
|
let latestUpdateStatus = null;
|
|
927
|
+
let serverBootIdentity = "";
|
|
872
928
|
let updateStatusRefreshTimer = null;
|
|
873
929
|
let updateNotificationHideTimer = null;
|
|
874
930
|
let componentUpdatePollTimer = null;
|
|
@@ -985,6 +1041,7 @@ const TAB_STORAGE_KEY = "pi-webui-active-tab";
|
|
|
985
1041
|
const PATH_FAST_PICKS_STORAGE_KEY = "pi-webui-path-fast-picks";
|
|
986
1042
|
const AGENT_DONE_NOTIFICATIONS_STORAGE_KEY = "pi-webui-agent-done-notifications";
|
|
987
1043
|
const UPDATE_NOTIFICATION_DISMISS_STORAGE_KEY = "pi-webui-update-notification-dismissed";
|
|
1044
|
+
const OPTIONAL_FEATURE_MIGRATION_DISMISS_STORAGE_KEY = "pi-webui-optional-feature-migration-dismissed";
|
|
988
1045
|
const MOBILE_CONTINUITY_STORAGE_KEY = "pi-webui-mobile-continuity-v1";
|
|
989
1046
|
const MOBILE_INSTALL_EDUCATION_STORAGE_KEY = "pi-webui-mobile-install-education-v1";
|
|
990
1047
|
const MOBILE_CONTINUITY_MAX_SESSIONS = 24;
|
|
@@ -1742,6 +1799,7 @@ function mobileRenderMore() {
|
|
|
1742
1799
|
const page = mobileShellState.surfacePage || "root";
|
|
1743
1800
|
const topics = {
|
|
1744
1801
|
session: ["Session", ["sidePanelSectionSession"]],
|
|
1802
|
+
sampling: ["Sampling parameters", ["sidePanelSectionSampling"]],
|
|
1745
1803
|
usage: ["Usage", ["sidePanelSectionCodexUsage", "sidePanelSectionClaudeUsage"]],
|
|
1746
1804
|
extensions: ["Extensions", ["sidePanelSectionOptionalFeatures"]],
|
|
1747
1805
|
settings: ["Settings", ["sidePanelSectionControls"]],
|
|
@@ -1792,6 +1850,7 @@ function mobileRenderMore() {
|
|
|
1792
1850
|
title.textContent = topic[0];
|
|
1793
1851
|
back.hidden = false;
|
|
1794
1852
|
mobileCanonicalMountContent(host, topic[1], `more:${page}`);
|
|
1853
|
+
if (page === "sampling") ensureSamplingParametersLoaded();
|
|
1795
1854
|
if (page === "commands") mobileShellElement("commandSearchInput")?.focus({ preventScroll: true });
|
|
1796
1855
|
}
|
|
1797
1856
|
|
|
@@ -2347,6 +2406,7 @@ const optionalFeatureAvailability = {
|
|
|
2347
2406
|
releaseAur: false,
|
|
2348
2407
|
aurReview: false,
|
|
2349
2408
|
workflows: false,
|
|
2409
|
+
featureSystemPrompt: false,
|
|
2350
2410
|
safetyGuard: false,
|
|
2351
2411
|
statsCommand: false,
|
|
2352
2412
|
gitFooterStatus: false,
|
|
@@ -2419,6 +2479,13 @@ const OPTIONAL_FEATURES = [
|
|
|
2419
2479
|
capabilityLabel: "/workflow or workflow subprocess widget event",
|
|
2420
2480
|
description: "Modular workflow runner with live subprocess output shown in a non-blocking Web UI widget.",
|
|
2421
2481
|
},
|
|
2482
|
+
{
|
|
2483
|
+
id: "featureSystemPrompt",
|
|
2484
|
+
label: "Feature workflow routing",
|
|
2485
|
+
packageName: "@firstpick/pi-extension-feature-system-prompt",
|
|
2486
|
+
capabilityLabel: "feature-category or feature-decision-output status event",
|
|
2487
|
+
description: "Classify feature requests and show lightweight or complex routing decisions in the composer.",
|
|
2488
|
+
},
|
|
2422
2489
|
{
|
|
2423
2490
|
id: "safetyGuard",
|
|
2424
2491
|
label: "Safety guard",
|
|
@@ -2898,7 +2965,7 @@ const OPTIONAL_FEATURE_SECTIONS = [
|
|
|
2898
2965
|
id: "workflows-releases",
|
|
2899
2966
|
label: "Workflows & releases",
|
|
2900
2967
|
description: "Guided workflows, task runners, and publishing actions with visible execution state.",
|
|
2901
|
-
featureIds: ["gitWorkflow", "workflows", "releaseNpm", "releaseAur", "aurReview"],
|
|
2968
|
+
featureIds: ["gitWorkflow", "workflows", "featureSystemPrompt", "releaseNpm", "releaseAur", "aurReview"],
|
|
2902
2969
|
},
|
|
2903
2970
|
{
|
|
2904
2971
|
id: "safety-access",
|
|
@@ -3003,6 +3070,8 @@ let optionalFeatureMigrationRenderTimer = null;
|
|
|
3003
3070
|
let optionalFeatureMigrationReadyDismissTimer = null;
|
|
3004
3071
|
let optionalFeatureMigrationPendingReadyDismissKey = "";
|
|
3005
3072
|
let optionalFeatureMigrationDismissedReadyKey = "";
|
|
3073
|
+
let optionalFeatureMigrationDismissedCompletionKey = "";
|
|
3074
|
+
let optionalFeatureMigrationDismissedNoticeKey = "";
|
|
3006
3075
|
let optionalFeatureMigrationDialogState = null;
|
|
3007
3076
|
let optionalFeatureMigrationLastPhase = "";
|
|
3008
3077
|
let optionalFeatureMigrationCompletionFocusKey = "";
|
|
@@ -3014,6 +3083,8 @@ const gitFooterPayloadStateByTab = new Map();
|
|
|
3014
3083
|
const gitFooterPayloadSettlementTimersByTab = new Map();
|
|
3015
3084
|
const gitFooterPayloadRequestSerialByTab = new Map();
|
|
3016
3085
|
const gitFooterSyncInFlightByTab = new Set();
|
|
3086
|
+
let gitPullErrorText = "";
|
|
3087
|
+
let gitPullErrorContext = { code: "", tabId: null, syncValue: "", busy: false, requestId: 0 };
|
|
3017
3088
|
const gitFooterPiCalibrationInFlightByTab = new Set();
|
|
3018
3089
|
let gitFooterVisibilityApplyInFlight = false;
|
|
3019
3090
|
let gitFooterVisibilityDirty = false;
|
|
@@ -3793,6 +3864,9 @@ function setSidePanelSectionVisible(record, visible, { persist = true } = {}) {
|
|
|
3793
3864
|
ensureGitPanelRepositoriesDiscovered({ retryUnavailable: true });
|
|
3794
3865
|
});
|
|
3795
3866
|
}
|
|
3867
|
+
if (visible && record.id === "sampling" && !record.section.classList.contains("collapsed")) {
|
|
3868
|
+
queueMicrotask(() => ensureSamplingParametersLoaded());
|
|
3869
|
+
}
|
|
3796
3870
|
if (persist) persistSidePanelSectionVisibility();
|
|
3797
3871
|
}
|
|
3798
3872
|
|
|
@@ -3816,6 +3890,9 @@ function setSidePanelSectionCollapsed(record, collapsed, { persist = true } = {}
|
|
|
3816
3890
|
ensureGitPanelRepositoriesDiscovered({ retryUnavailable: true });
|
|
3817
3891
|
});
|
|
3818
3892
|
}
|
|
3893
|
+
if (!collapsed && record.id === "sampling" && !record.section.hidden) {
|
|
3894
|
+
queueMicrotask(() => ensureSamplingParametersLoaded());
|
|
3895
|
+
}
|
|
3819
3896
|
if (persist) persistSidePanelSectionState();
|
|
3820
3897
|
}
|
|
3821
3898
|
|
|
@@ -5670,8 +5747,9 @@ function clearFeatureDecisionStateForTab(tabId, { render = false } = {}) {
|
|
|
5670
5747
|
function renderFeatureCategoryTag(tabId = activeTabId) {
|
|
5671
5748
|
const tag = elements.featureCategoryTag;
|
|
5672
5749
|
if (!tag) return;
|
|
5673
|
-
const
|
|
5674
|
-
const
|
|
5750
|
+
const enabled = isOptionalFeatureEnabled("featureSystemPrompt");
|
|
5751
|
+
const category = enabled ? normalizeFeatureCategory(featureCategoryByTab.get(tabId)) : "";
|
|
5752
|
+
const output = enabled ? featureDecisionOutputForTab(tabId) : "";
|
|
5675
5753
|
tag.hidden = !category;
|
|
5676
5754
|
tag.disabled = !output;
|
|
5677
5755
|
tag.textContent = category;
|
|
@@ -5683,18 +5761,22 @@ function renderFeatureCategoryTag(tabId = activeTabId) {
|
|
|
5683
5761
|
|
|
5684
5762
|
function handleFeatureDecisionOutputStatus(statusText, tabId = activeTabId) {
|
|
5685
5763
|
if (!tabId) return;
|
|
5764
|
+
optionalFeatureAvailability.featureSystemPrompt = true;
|
|
5686
5765
|
const decision = parseFeatureDecisionPayload(statusText);
|
|
5687
5766
|
if (decision) featureDecisionOutputByTab.set(tabId, decision);
|
|
5688
5767
|
else featureDecisionOutputByTab.delete(tabId);
|
|
5768
|
+
renderOptionalFeatureControls();
|
|
5689
5769
|
if (tabId === activeTabId) renderFeatureCategoryTag(tabId);
|
|
5690
5770
|
else if (featureDecisionDialogTabId === tabId) syncFeatureDecisionDialog();
|
|
5691
5771
|
}
|
|
5692
5772
|
|
|
5693
5773
|
function handleFeatureCategoryStatus(statusText, tabId = activeTabId) {
|
|
5694
5774
|
if (!tabId) return;
|
|
5775
|
+
optionalFeatureAvailability.featureSystemPrompt = true;
|
|
5695
5776
|
const category = normalizeFeatureCategory(statusText);
|
|
5696
5777
|
if (category) featureCategoryByTab.set(tabId, category);
|
|
5697
5778
|
else clearFeatureDecisionStateForTab(tabId);
|
|
5779
|
+
renderOptionalFeatureControls();
|
|
5698
5780
|
if (tabId === activeTabId) renderFeatureCategoryTag(tabId);
|
|
5699
5781
|
else if (featureDecisionDialogTabId === tabId) syncFeatureDecisionDialog();
|
|
5700
5782
|
}
|
|
@@ -7254,24 +7336,25 @@ async function confirmOpenWebuiNpmPage() {
|
|
|
7254
7336
|
async function openPiReleaseNotes() {
|
|
7255
7337
|
const dialog = elements.piReleaseNotesDialog;
|
|
7256
7338
|
if (!dialog) return;
|
|
7257
|
-
const
|
|
7258
|
-
const
|
|
7339
|
+
const installedVersion = piVersion;
|
|
7340
|
+
const availableVersion = latestUpdateStatus?.pi?.updateAvailable ? latestUpdateStatus.pi.latestVersion : "";
|
|
7341
|
+
const displayedVersion = availableVersion || installedVersion;
|
|
7342
|
+
const label = formatWebuiVersion(displayedVersion);
|
|
7259
7343
|
elements.piReleaseNotesTitle.textContent = label ? `Pi ${label} release notes` : "Pi release notes";
|
|
7260
7344
|
elements.piReleaseNotesStatus.textContent = "Loading release notes from GitHub…";
|
|
7261
7345
|
elements.piReleaseNotesBody.setAttribute("aria-busy", "true");
|
|
7262
7346
|
elements.piReleaseNotesBody.replaceChildren(make("p", "muted", "Loading…"));
|
|
7263
|
-
setPiReleaseNotesLink(piReleasePageUrl(
|
|
7347
|
+
setPiReleaseNotesLink(piReleasePageUrl(displayedVersion));
|
|
7264
7348
|
renderComponentUpdateDialogs();
|
|
7265
7349
|
if (!dialog.open) dialog.showModal();
|
|
7266
7350
|
refreshUpdateStatus({ notify: false }).catch((error) => addEvent(`Pi/Web UI update check failed: ${error.message || String(error)}`, "warn"));
|
|
7267
7351
|
|
|
7268
7352
|
try {
|
|
7269
7353
|
const response = await api("/api/pi-release-notes", { scoped: false });
|
|
7270
|
-
if (
|
|
7354
|
+
if (installedVersion !== piVersion) return;
|
|
7271
7355
|
const release = response.data || {};
|
|
7272
7356
|
const releaseVersion = String(release.version || "").trim().replace(/^v/i, "");
|
|
7273
|
-
|
|
7274
|
-
const releaseLabel = formatWebuiVersion(releaseVersion || requestedVersion);
|
|
7357
|
+
const releaseLabel = formatWebuiVersion(releaseVersion || displayedVersion);
|
|
7275
7358
|
elements.piReleaseNotesTitle.textContent = releaseLabel ? `Pi ${releaseLabel} release notes` : (release.title || "Pi release notes");
|
|
7276
7359
|
renderMarkdown(elements.piReleaseNotesBody, release.body || "No release notes were provided for this release.");
|
|
7277
7360
|
const published = formatPiReleaseDate(release.publishedAt);
|
|
@@ -7287,6 +7370,7 @@ async function openPiReleaseNotes() {
|
|
|
7287
7370
|
|
|
7288
7371
|
async function refreshWebuiVersion() {
|
|
7289
7372
|
const health = await api("/api/health", { scoped: false });
|
|
7373
|
+
if (health.bootIdentity) serverBootIdentity = health.bootIdentity;
|
|
7290
7374
|
setWebuiVersion(health.webuiVersion);
|
|
7291
7375
|
setPiVersion(health.piVersion);
|
|
7292
7376
|
setWebuiDevServer(isWebuiDevMetadata(health));
|
|
@@ -7361,15 +7445,15 @@ function renderUpdateNotification(status = latestUpdateStatus, { force = false }
|
|
|
7361
7445
|
if (elements.updateNotificationMessage) {
|
|
7362
7446
|
let message = "Updates are available. Direct Web UI updates are only enabled from localhost on the host machine.";
|
|
7363
7447
|
if (canRunUpdate) {
|
|
7364
|
-
if (hasPiUpdate && hasPackageUpdate) message = "
|
|
7365
|
-
else if (hasPackageUpdate) message = "
|
|
7366
|
-
else message = "
|
|
7448
|
+
if (hasPiUpdate && hasPackageUpdate) message = "Create and confirm an exact combined update plan for eligible Pi, Web UI, and Pi-owned Optional Features; managed runtimes are staged, verified, activated, and restarted with rollback protection.";
|
|
7449
|
+
else if (hasPackageUpdate) message = "Create and confirm an exact package update plan; managed Web UI runtimes are staged, verified, activated, and restarted with rollback protection.";
|
|
7450
|
+
else message = "Create and confirm an exact Pi update plan; bundled Pi is staged with the Web UI, while an independent Pi executable is delegated to and verified.";
|
|
7367
7451
|
}
|
|
7368
7452
|
elements.updateNotificationMessage.textContent = message;
|
|
7369
7453
|
}
|
|
7370
7454
|
const details = [
|
|
7371
7455
|
items.join(" · "),
|
|
7372
|
-
latestUpdateStatus.webuiDev && latestUpdateStatus.webui?.updateAvailable ? "The current Web UI is a
|
|
7456
|
+
latestUpdateStatus.webuiDev && latestUpdateStatus.webui?.updateAvailable ? "The current Web UI is a source checkout and remains untouched; only separately verified, eligible targets can enter the exact update plan." : "",
|
|
7373
7457
|
latestUpdateStatus.packages?.note || "",
|
|
7374
7458
|
].filter(Boolean).join(" ");
|
|
7375
7459
|
if (elements.updateNotificationDetail) elements.updateNotificationDetail.textContent = details;
|
|
@@ -7393,6 +7477,7 @@ async function refreshUpdateStatus({ force = false, notify = true } = {}) {
|
|
|
7393
7477
|
const path = force ? "/api/update-status?refresh=1" : "/api/update-status";
|
|
7394
7478
|
const response = await api(path, { scoped: false });
|
|
7395
7479
|
latestUpdateStatus = response.data || null;
|
|
7480
|
+
if (latestUpdateStatus?.pi?.currentVersion) setPiVersion(latestUpdateStatus.pi.currentVersion);
|
|
7396
7481
|
if (notify) renderUpdateNotification(latestUpdateStatus);
|
|
7397
7482
|
renderComponentUpdateIndicators();
|
|
7398
7483
|
renderComponentUpdateDialogs();
|
|
@@ -7458,7 +7543,7 @@ function componentUpdateStatusText(target) {
|
|
|
7458
7543
|
if (job?.state === "succeeded") {
|
|
7459
7544
|
const activation = target === "pi"
|
|
7460
7545
|
? "New or reloaded Pi sessions use the update; already-running tabs keep their current runtime until restarted."
|
|
7461
|
-
: "
|
|
7546
|
+
: "The managed Web UI runtime was activated automatically; the browser reconnects after the verified restart.";
|
|
7462
7547
|
return { text: `${job.message || `${label} update completed.`} ${activation}`, level: "success" };
|
|
7463
7548
|
}
|
|
7464
7549
|
if (job?.state === "failed") {
|
|
@@ -7531,13 +7616,20 @@ function syncComponentUpdatePolling() {
|
|
|
7531
7616
|
}
|
|
7532
7617
|
}
|
|
7533
7618
|
|
|
7619
|
+
function separatePathPiPlanNotice(plan) {
|
|
7620
|
+
const identities = Array.isArray(plan?.identities) ? plan.identities : [];
|
|
7621
|
+
const activePi = identities.find((identity) => identity?.kind === "pi" && identity.source !== "path");
|
|
7622
|
+
const pathPi = identities.find((identity) => identity?.kind === "pi" && identity.source === "path" && identity.canonicalId !== activePi?.canonicalId);
|
|
7623
|
+
return pathPi ? `PATH Pi${pathPi.version ? ` v${pathPi.version}` : ""} is a separate installation and will remain untouched. Run pi update in a terminal to update it.` : "";
|
|
7624
|
+
}
|
|
7625
|
+
|
|
7534
7626
|
function componentUpdateConfirmationText(target) {
|
|
7535
7627
|
const pkg = latestUpdateStatus?.[target] || {};
|
|
7536
7628
|
const versionText = pkg.updateAvailable ? `\n\nDetected update: ${packageUpdateText(componentUpdateLabel(target), pkg)}.` : "";
|
|
7537
7629
|
if (target === "pi") {
|
|
7538
|
-
return `
|
|
7630
|
+
return `Create and apply an exact Pi update plan now?${versionText}\n\nBundled Pi updates are staged with the current Web UI in a side-by-side managed runtime and activated with a health-gated restart. A verified independent Pi executable delegates to that exact executable and is rejected if it cannot reach the confirmed version.`;
|
|
7539
7631
|
}
|
|
7540
|
-
return `
|
|
7632
|
+
return `Create and apply an exact Web UI update plan now?${versionText}\n\nThe confirmed Web UI and Pi versions are staged outside the live installation, probed, and activated through the stable launcher. Activation restarts the Web UI automatically and rolls back the runtime pointer if health verification fails.`;
|
|
7541
7633
|
}
|
|
7542
7634
|
|
|
7543
7635
|
async function startComponentUpdate(target) {
|
|
@@ -7550,17 +7642,28 @@ async function startComponentUpdate(target) {
|
|
|
7550
7642
|
renderComponentUpdateDialogs();
|
|
7551
7643
|
return;
|
|
7552
7644
|
}
|
|
7553
|
-
|
|
7554
|
-
|
|
7555
|
-
|
|
7645
|
+
let plan;
|
|
7646
|
+
try {
|
|
7647
|
+
plan = (await api("/api/update/plan", { method: "POST", body: { targets: [target] }, scoped: false }))?.data?.plan;
|
|
7648
|
+
} catch (error) {
|
|
7649
|
+
addEvent(error.message || String(error), "error");
|
|
7650
|
+
return;
|
|
7651
|
+
}
|
|
7652
|
+
const planNotice = separatePathPiPlanNotice(plan);
|
|
7653
|
+
const confirmed = await appConfirmText(`${componentUpdateConfirmationText(target)}${planNotice ? `\n\n${planNotice}` : ""}\n\nExact plan digest: ${plan.digest}`, {
|
|
7654
|
+
affected: target === "pi" ? "The verified active Pi installation on the Web UI host" : "A side-by-side managed Web UI runtime",
|
|
7655
|
+
confirmLabel: job?.state === "failed" ? `Retry ${label} update` : `Apply exact ${label} plan`,
|
|
7556
7656
|
danger: false,
|
|
7557
7657
|
});
|
|
7558
7658
|
if (!confirmed) return;
|
|
7559
7659
|
componentUpdateStartInProgress = true;
|
|
7560
7660
|
renderComponentUpdateDialogs();
|
|
7561
7661
|
try {
|
|
7562
|
-
const response = await api("/api/
|
|
7563
|
-
const
|
|
7662
|
+
const response = await api("/api/update/apply", { method: "POST", body: { transactionId: plan.transactionId, planDigest: plan.digest }, scoped: false });
|
|
7663
|
+
const acceptedState = ["applying", "verifying", "activating"].includes(response?.data?.state)
|
|
7664
|
+
? "running"
|
|
7665
|
+
: response?.data?.outcome === "success" ? "succeeded" : "failed";
|
|
7666
|
+
const accepted = { target, state: acceptedState, canStart: false, message: `Exact ${label} update ${response?.data?.state || response?.data?.outcome || "accepted"}.`, receipts: response?.data?.receipts || [] };
|
|
7564
7667
|
if (accepted && typeof accepted === "object") {
|
|
7565
7668
|
latestUpdateStatus = {
|
|
7566
7669
|
...(latestUpdateStatus || {}),
|
|
@@ -7599,14 +7702,16 @@ function initializeUpdateNotifications() {
|
|
|
7599
7702
|
}, UPDATE_STATUS_INITIAL_DELAY_MS);
|
|
7600
7703
|
}
|
|
7601
7704
|
|
|
7602
|
-
function piUpdateConfirmationText({ all = false } = {}) {
|
|
7705
|
+
function piUpdateConfirmationText({ all = false, plan = null } = {}) {
|
|
7603
7706
|
const items = updateNotificationItems();
|
|
7604
7707
|
const workingWarning = hasWorkingTab() ? "\n\nOne or more Pi tabs look busy or blocked. Finish or abort in-flight work before updating if you need to preserve it." : "";
|
|
7605
7708
|
const versionText = items.length ? `\n\nDetected update: ${items.join(" · ")}.` : "";
|
|
7606
|
-
const
|
|
7607
|
-
const
|
|
7608
|
-
const
|
|
7609
|
-
|
|
7709
|
+
const scope = all ? "the verified active Pi and Web UI targets" : "the verified active Pi target";
|
|
7710
|
+
const refusals = Array.isArray(plan?.refusals) && plan.refusals.length ? `\n\nRefused automatic targets: ${plan.refusals.map((item) => `${item.id}: ${item.guidance}`).join(" · ")}` : "";
|
|
7711
|
+
const separatePathPi = separatePathPiPlanNotice(plan);
|
|
7712
|
+
const pathNotice = separatePathPi ? `\n\n${separatePathPi}` : "";
|
|
7713
|
+
const digest = plan?.digest ? `\n\nExact immutable plan digest: ${plan.digest}` : "";
|
|
7714
|
+
return `Apply ${scope} now?${versionText}${refusals}${pathNotice}${digest}\n\nThe server will use only this persisted exact-target plan; it will not re-resolve latest or scan package roots. Managed Web UI activation is health-gated and automatically rolls back on failure.${workingWarning}`;
|
|
7610
7715
|
}
|
|
7611
7716
|
|
|
7612
7717
|
async function runPiUpdateAndRestart({ all = false } = {}) {
|
|
@@ -7616,16 +7721,23 @@ async function runPiUpdateAndRestart({ all = false } = {}) {
|
|
|
7616
7721
|
renderUpdateNotification(latestUpdateStatus, { force: true });
|
|
7617
7722
|
return;
|
|
7618
7723
|
}
|
|
7619
|
-
|
|
7724
|
+
let plan;
|
|
7725
|
+
try {
|
|
7726
|
+
plan = (await api("/api/update/plan", { method: "POST", body: { targets: all ? ["pi", "webui"] : ["pi"] }, scoped: false }))?.data?.plan;
|
|
7727
|
+
} catch (error) {
|
|
7728
|
+
addEvent(error.message || String(error), "error");
|
|
7729
|
+
return;
|
|
7730
|
+
}
|
|
7731
|
+
if (!(await appConfirmText(piUpdateConfirmationText({ all, plan }), { affected: "Only targets accepted by the exact server-owned plan", confirmLabel: all ? "Apply exact update plan" : "Apply exact Pi plan" }))) return;
|
|
7620
7732
|
|
|
7621
|
-
const updateLabel = all ? "Pi and
|
|
7733
|
+
const updateLabel = all ? "Pi and Web UI exact updates" : "Pi exact update";
|
|
7622
7734
|
updateRequestInProgress = true;
|
|
7623
7735
|
hideUpdateNotification();
|
|
7624
7736
|
setServerActionBusy("Updating…");
|
|
7625
7737
|
setServerActionStatus(`Running ${updateLabel}. The server will restart after the update completes…`, "warn");
|
|
7626
7738
|
setServerRestartOverlay(true, `Running ${updateLabel}. The server will restart after the update completes…`);
|
|
7627
7739
|
try {
|
|
7628
|
-
await api(
|
|
7740
|
+
await api("/api/update/apply", { method: "POST", body: { transactionId: plan.transactionId, planDigest: plan.digest }, scoped: false });
|
|
7629
7741
|
addEvent(`${updateLabel} completed; Pi Web UI server restart requested`, "warn");
|
|
7630
7742
|
} catch (error) {
|
|
7631
7743
|
if (!error?.backendOffline) {
|
|
@@ -7642,7 +7754,7 @@ async function runPiUpdateAndRestart({ all = false } = {}) {
|
|
|
7642
7754
|
}
|
|
7643
7755
|
|
|
7644
7756
|
setBackendOffline(true, new Error("update requested from side panel"));
|
|
7645
|
-
const restarted = await waitForServerRestart();
|
|
7757
|
+
const restarted = await waitForServerRestart(serverBootIdentity);
|
|
7646
7758
|
updateRequestInProgress = false;
|
|
7647
7759
|
resetServerActionControls();
|
|
7648
7760
|
if (restarted) {
|
|
@@ -8835,7 +8947,7 @@ function conversationModeCommandName() {
|
|
|
8835
8947
|
}
|
|
8836
8948
|
|
|
8837
8949
|
function conversationModeButtonLabel(mode = activeConversationMode()) {
|
|
8838
|
-
return mode.enabled ? "End Conversation" : "Start Conversation";
|
|
8950
|
+
return mode.enabled ? "End Conversation" : "Start Natural Conversation";
|
|
8839
8951
|
}
|
|
8840
8952
|
|
|
8841
8953
|
function conversationModePartialPreview(text = "") {
|
|
@@ -9461,6 +9573,12 @@ function setOptionalFeatureDisabled(featureId, disabled) {
|
|
|
9461
9573
|
clearGitFooterWebuiPayloadCache();
|
|
9462
9574
|
for (const tabId of new Set([...gitFooterPayloadStateByTab.keys(), ...gitFooterPayloadSettlementTimersByTab.keys(), ...gitFooterPayloadRefreshInFlightByTab])) clearGitFooterPayloadState(tabId);
|
|
9463
9575
|
}
|
|
9576
|
+
if (featureId === "featureSystemPrompt") {
|
|
9577
|
+
if (disabled) {
|
|
9578
|
+
for (const tabId of new Set([...featureCategoryByTab.keys(), ...featureDecisionOutputByTab.keys()])) clearFeatureDecisionStateForTab(tabId);
|
|
9579
|
+
}
|
|
9580
|
+
renderFeatureCategoryTag();
|
|
9581
|
+
}
|
|
9464
9582
|
if (featureId === "btwCommand") {
|
|
9465
9583
|
statusEntries.delete(BTW_WEBUI_STATUS_KEY);
|
|
9466
9584
|
widgets.delete(BTW_OUTPUT_WIDGET_KEY);
|
|
@@ -10572,6 +10690,7 @@ function resetFileTreeState() {
|
|
|
10572
10690
|
fileTreeSearchTimer = null;
|
|
10573
10691
|
fileTreeSearchRequestSerial += 1;
|
|
10574
10692
|
fileTreeState = emptyFileTreeState(fileTreeState.requestSerial + 1);
|
|
10693
|
+
fileTreeLastRenderSignature = "";
|
|
10575
10694
|
if (elements.fileTreeSearchInput) elements.fileTreeSearchInput.value = "";
|
|
10576
10695
|
updateFileTreeSearchControls();
|
|
10577
10696
|
renderFileTree();
|
|
@@ -10592,10 +10711,47 @@ function fileTreeControlKey(node) {
|
|
|
10592
10711
|
return node?.classList?.contains("file-tree-item") && path ? `file-tree:${path}` : "";
|
|
10593
10712
|
}
|
|
10594
10713
|
|
|
10714
|
+
function fileTreeEntryRenderSignature(entry = {}) {
|
|
10715
|
+
return [
|
|
10716
|
+
normalizeFileTreePath(entry.path || ""),
|
|
10717
|
+
String(entry.name || ""),
|
|
10718
|
+
String(entry.type || ""),
|
|
10719
|
+
entry.directory === true,
|
|
10720
|
+
String(entry.extension || ""),
|
|
10721
|
+
String(entry.error || ""),
|
|
10722
|
+
];
|
|
10723
|
+
}
|
|
10724
|
+
|
|
10725
|
+
function fileTreeRenderSignature() {
|
|
10726
|
+
const entriesByPath = [...fileTreeState.entriesByPath.entries()]
|
|
10727
|
+
.map(([path, entries]) => [normalizeFileTreePath(path), (Array.isArray(entries) ? entries : []).map(fileTreeEntryRenderSignature)])
|
|
10728
|
+
.sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
|
|
10729
|
+
const gitStatusByPath = [...fileTreeState.gitStatusByPath.entries()]
|
|
10730
|
+
.map(([path, status]) => [normalizeFileTreePath(path), normalizeFileTreeGitStatus(status)])
|
|
10731
|
+
.sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
|
|
10732
|
+
return JSON.stringify({
|
|
10733
|
+
context: `${activeTabId || ""}:${activeTabGeneration}`,
|
|
10734
|
+
root: fileTreeState.root || "",
|
|
10735
|
+
displayCwd: fileTreeState.root || latestWorkspace?.displayCwd || activeTab()?.cwd || "",
|
|
10736
|
+
entriesByPath,
|
|
10737
|
+
expanded: [...fileTreeState.expanded].map(normalizeFileTreePath).sort(),
|
|
10738
|
+
loading: [...fileTreeState.loading].map(normalizeFileTreePath).sort(),
|
|
10739
|
+
selectedPath: normalizeFileTreePath(fileTreeState.selectedPath || ""),
|
|
10740
|
+
searchQuery: fileTreeState.searchQuery || fileTreeSearchQueryText(),
|
|
10741
|
+
searchEntries: fileTreeState.searchEntries.map(fileTreeEntryRenderSignature),
|
|
10742
|
+
searchLoading: fileTreeState.searchLoading,
|
|
10743
|
+
gitStatusRoot: fileTreeState.gitStatusRoot || "",
|
|
10744
|
+
gitStatusByPath,
|
|
10745
|
+
});
|
|
10746
|
+
}
|
|
10747
|
+
|
|
10595
10748
|
function renderFileTree() {
|
|
10596
10749
|
if (deferUiRenderDuringPointerActivation("file-tree", renderFileTree)) return;
|
|
10597
10750
|
const root = elements.fileTreeRoot;
|
|
10598
10751
|
if (!root) return;
|
|
10752
|
+
const renderSignature = fileTreeRenderSignature();
|
|
10753
|
+
if (renderSignature === fileTreeLastRenderSignature) return;
|
|
10754
|
+
fileTreeLastRenderSignature = renderSignature;
|
|
10599
10755
|
const continuityContextKey = `${activeTabId || ""}:${activeTabGeneration}:${fileTreeState.root || ""}`;
|
|
10600
10756
|
const focusSnapshot = captureScopedControlContinuity(root, continuityContextKey, fileTreeControlKey);
|
|
10601
10757
|
const restoreFocus = () => restoreScopedControlContinuity(root, continuityContextKey, focusSnapshot, (key) => [...root.querySelectorAll(".file-tree-item[data-path]")].find((node) => fileTreeControlKey(node) === key));
|
|
@@ -10792,7 +10948,7 @@ function appendFileTreeEntry(parent, entry, depth = 0) {
|
|
|
10792
10948
|
parent.append(item);
|
|
10793
10949
|
}
|
|
10794
10950
|
|
|
10795
|
-
async function loadFileTreeDirectory(path = FILE_TREE_ROOT_PATH, { force = false } = {}) {
|
|
10951
|
+
async function loadFileTreeDirectory(path = FILE_TREE_ROOT_PATH, { force = false, renderResult = true } = {}) {
|
|
10796
10952
|
const normalized = normalizeFileTreePath(path);
|
|
10797
10953
|
if (!force && fileTreeState.entriesByPath.has(normalized)) return fileTreeState.entriesByPath.get(normalized);
|
|
10798
10954
|
const tabContext = activeTabContext();
|
|
@@ -10800,8 +10956,10 @@ async function loadFileTreeDirectory(path = FILE_TREE_ROOT_PATH, { force = false
|
|
|
10800
10956
|
const serial = ++fileTreeState.requestSerial;
|
|
10801
10957
|
const hadCachedEntries = fileTreeState.entriesByPath.has(normalized);
|
|
10802
10958
|
fileTreeState.loading.add(normalized);
|
|
10803
|
-
if (!hadCachedEntries)
|
|
10804
|
-
|
|
10959
|
+
if (!hadCachedEntries) {
|
|
10960
|
+
setFileTreeStatus(normalized ? `Loading ${normalized}…` : "Loading workspace files…");
|
|
10961
|
+
renderFileTree();
|
|
10962
|
+
}
|
|
10805
10963
|
try {
|
|
10806
10964
|
const response = await api(fileApiPath("/api/files", normalized), { tabId: tabContext.tabId });
|
|
10807
10965
|
if (!isCurrentTabContext(tabContext) || serial < fileTreeState.requestSerial) return [];
|
|
@@ -10826,7 +10984,7 @@ async function loadFileTreeDirectory(path = FILE_TREE_ROOT_PATH, { force = false
|
|
|
10826
10984
|
return [];
|
|
10827
10985
|
} finally {
|
|
10828
10986
|
fileTreeState.loading.delete(normalized);
|
|
10829
|
-
if (isCurrentTabContext(tabContext)) renderFileTree();
|
|
10987
|
+
if (renderResult && isCurrentTabContext(tabContext)) renderFileTree();
|
|
10830
10988
|
}
|
|
10831
10989
|
}
|
|
10832
10990
|
|
|
@@ -10847,7 +11005,7 @@ function clearFileTreeSearch({ focus = false } = {}) {
|
|
|
10847
11005
|
if (focus) elements.fileTreeSearchInput?.focus();
|
|
10848
11006
|
}
|
|
10849
11007
|
|
|
10850
|
-
async function runFileTreeSearch() {
|
|
11008
|
+
async function runFileTreeSearch({ background = false } = {}) {
|
|
10851
11009
|
clearTimeout(fileTreeSearchTimer);
|
|
10852
11010
|
fileTreeSearchTimer = null;
|
|
10853
11011
|
const query = fileTreeSearchQueryText();
|
|
@@ -10860,12 +11018,14 @@ async function runFileTreeSearch() {
|
|
|
10860
11018
|
const tabContext = activeTabContext();
|
|
10861
11019
|
if (!tabContext.tabId) return [];
|
|
10862
11020
|
fileTreeState.searchQuery = query;
|
|
10863
|
-
|
|
10864
|
-
|
|
10865
|
-
|
|
10866
|
-
|
|
10867
|
-
|
|
10868
|
-
|
|
11021
|
+
if (!background) {
|
|
11022
|
+
fileTreeState.searchLoading = true;
|
|
11023
|
+
fileTreeState.searchEntries = [];
|
|
11024
|
+
fileTreeState.searchTruncated = false;
|
|
11025
|
+
fileTreeState.searchTotal = 0;
|
|
11026
|
+
setFileTreeStatus(`Searching for “${query}”…`);
|
|
11027
|
+
renderFileTree();
|
|
11028
|
+
}
|
|
10869
11029
|
try {
|
|
10870
11030
|
const response = await api(fileSearchApiPath(query), { tabId: tabContext.tabId });
|
|
10871
11031
|
if (!isCurrentTabContext(tabContext) || serial !== fileTreeSearchRequestSerial) return [];
|
|
@@ -10882,8 +11042,10 @@ async function runFileTreeSearch() {
|
|
|
10882
11042
|
return entries;
|
|
10883
11043
|
} catch (error) {
|
|
10884
11044
|
if (isCurrentTabContext(tabContext) && serial === fileTreeSearchRequestSerial) {
|
|
10885
|
-
|
|
10886
|
-
|
|
11045
|
+
if (!background) {
|
|
11046
|
+
fileTreeState.searchLoading = false;
|
|
11047
|
+
fileTreeState.searchEntries = [];
|
|
11048
|
+
}
|
|
10887
11049
|
setFileTreeStatus(error.message || String(error), "error");
|
|
10888
11050
|
addEvent(`file search failed: ${error.message || String(error)}`, "error");
|
|
10889
11051
|
}
|
|
@@ -10930,7 +11092,7 @@ async function refreshLoadedFileTreeDirectories(tabContext = activeTabContext())
|
|
|
10930
11092
|
}
|
|
10931
11093
|
};
|
|
10932
11094
|
if (fileTreeState.loading.has(FILE_TREE_ROOT_PATH)) return true;
|
|
10933
|
-
await loadFileTreeDirectory(FILE_TREE_ROOT_PATH, { force: true });
|
|
11095
|
+
await loadFileTreeDirectory(FILE_TREE_ROOT_PATH, { force: true, renderResult: false });
|
|
10934
11096
|
if (!isCurrentTabContext(tabContext)) return false;
|
|
10935
11097
|
collectDirectories(FILE_TREE_ROOT_PATH);
|
|
10936
11098
|
const cachedDirectories = [...fileTreeState.entriesByPath.keys()]
|
|
@@ -10948,7 +11110,7 @@ async function refreshLoadedFileTreeDirectories(tabContext = activeTabContext())
|
|
|
10948
11110
|
collectDirectories(path);
|
|
10949
11111
|
continue;
|
|
10950
11112
|
}
|
|
10951
|
-
await loadFileTreeDirectory(path, { force: true });
|
|
11113
|
+
await loadFileTreeDirectory(path, { force: true, renderResult: false });
|
|
10952
11114
|
if (!isCurrentTabContext(tabContext)) return false;
|
|
10953
11115
|
collectDirectories(path);
|
|
10954
11116
|
}
|
|
@@ -10972,7 +11134,7 @@ async function refreshFileTreeLive(tabContext = activeTabContext()) {
|
|
|
10972
11134
|
while (refreshContext && isCurrentTabContext(refreshContext)) {
|
|
10973
11135
|
fileTreeLiveRefreshPendingContext = null;
|
|
10974
11136
|
let skippedLoadingDirectory = false;
|
|
10975
|
-
if (fileTreeSearchQueryText()) await runFileTreeSearch();
|
|
11137
|
+
if (fileTreeSearchQueryText()) await runFileTreeSearch({ background: true });
|
|
10976
11138
|
else skippedLoadingDirectory = await refreshLoadedFileTreeDirectories(refreshContext);
|
|
10977
11139
|
if (skippedLoadingDirectory && isCurrentTabContext(refreshContext)) retryContext = refreshContext;
|
|
10978
11140
|
refreshContext = fileTreeLiveRefreshPendingContext;
|
|
@@ -11476,6 +11638,7 @@ const UI_LAYOUT_SAVE_DEBOUNCE_MS = 250;
|
|
|
11476
11638
|
const UI_LAYOUT_MAX_CONFLICT_RETRIES = 1;
|
|
11477
11639
|
const UI_LAYOUT_FIELDS = ["sidePanel", "composerActions", "footerScopedModelOrder", "terminalTabs", "fileViewerWidth"];
|
|
11478
11640
|
const UI_LAYOUT_SIDE_PANEL_FIELDS = ["sectionOrder", "collapsedSectionIds", "hiddenSectionIds", "collapsed"];
|
|
11641
|
+
const REMOVED_SIDE_PANEL_SECTION_HEIGHT_STORAGE_KEY = "pi-webui-side-panel-section-heights-v1";
|
|
11479
11642
|
const UI_LAYOUT_COMPOSER_FIELDS = ["order", "grid"];
|
|
11480
11643
|
const UI_LAYOUT_TERMINAL_FIELDS = ["layout", "customGroups"];
|
|
11481
11644
|
const UI_LAYOUT_PENDING_STORAGE_PREFIX = "pi-webui-ui-layout-pending-v3:";
|
|
@@ -11711,6 +11874,19 @@ function removeDurableUiLayoutPendingMutation(key) {
|
|
|
11711
11874
|
}
|
|
11712
11875
|
}
|
|
11713
11876
|
|
|
11877
|
+
function clearRemovedSidePanelSectionHeightState() {
|
|
11878
|
+
try {
|
|
11879
|
+
localStorage.removeItem(REMOVED_SIDE_PANEL_SECTION_HEIGHT_STORAGE_KEY);
|
|
11880
|
+
} catch {
|
|
11881
|
+
// Removed layout state may remain when browser storage is unavailable.
|
|
11882
|
+
}
|
|
11883
|
+
for (const record of durableUiLayoutPendingMutationRecords()) {
|
|
11884
|
+
if (record.field === "sidePanel" && record.subfield === "sectionHeights") {
|
|
11885
|
+
removeDurableUiLayoutPendingMutation(record.key);
|
|
11886
|
+
}
|
|
11887
|
+
}
|
|
11888
|
+
}
|
|
11889
|
+
|
|
11714
11890
|
function clearAcknowledgedDurableUiLayoutPendingMutations(snapshot) {
|
|
11715
11891
|
for (const entry of snapshot.values()) {
|
|
11716
11892
|
if (entry.subfieldMutationIds?.size) {
|
|
@@ -11934,6 +12110,8 @@ function applyDurableUiLayoutSnapshot(data, { generations = null, readEpoch = 0
|
|
|
11934
12110
|
const subfields = durableUiLayoutSubFields(field);
|
|
11935
12111
|
const dirtySubfields = dirtyEntry?.subfields;
|
|
11936
12112
|
|
|
12113
|
+
if (field === "sidePanel" && durableUiLayoutInteractionActive(field)) continue;
|
|
12114
|
+
|
|
11937
12115
|
if (subfields && field !== "composerActions") {
|
|
11938
12116
|
const applicable = {};
|
|
11939
12117
|
let hasApplicable = false;
|
|
@@ -14902,6 +15080,7 @@ async function switchTab(tabId) {
|
|
|
14902
15080
|
} else {
|
|
14903
15081
|
renderSubagentLaunchSlots();
|
|
14904
15082
|
}
|
|
15083
|
+
refreshSamplingParametersForTabContext(tabContext);
|
|
14905
15084
|
}
|
|
14906
15085
|
|
|
14907
15086
|
function currentDirectoryForNewTab() {
|
|
@@ -15199,6 +15378,7 @@ async function initializeTabs() {
|
|
|
15199
15378
|
if (!subagentLaunchSlotDraftIsDirty() || subagentLaunchSlotConfigTabId !== activeTabId) {
|
|
15200
15379
|
loadSubagentLaunchSlotConfig().catch(() => {});
|
|
15201
15380
|
}
|
|
15381
|
+
refreshSamplingParametersForTabContext(tabContext);
|
|
15202
15382
|
await refreshThemeCatalog(tabContext).catch((error) => addEvent(`Custom theme catalog refresh failed: ${error.message || String(error)}`, "warn"));
|
|
15203
15383
|
}
|
|
15204
15384
|
}
|
|
@@ -16600,6 +16780,7 @@ function setGitFooterVisibilitySelection(checked) {
|
|
|
16600
16780
|
function openGitFooterVisibilityDialog() {
|
|
16601
16781
|
if (!elements.gitFooterVisibilityDialog) return;
|
|
16602
16782
|
setOptionsMenuOpen(false);
|
|
16783
|
+
closeGitFooterContextMenu({ returnFocus: false });
|
|
16603
16784
|
hideFooterTooltip();
|
|
16604
16785
|
gitFooterVisibilityDirty = false;
|
|
16605
16786
|
renderGitFooterVisibilityDialog();
|
|
@@ -16613,6 +16794,65 @@ function closeGitFooterVisibilityDialog() {
|
|
|
16613
16794
|
if (elements.gitFooterVisibilityDialog?.open) elements.gitFooterVisibilityDialog.close();
|
|
16614
16795
|
}
|
|
16615
16796
|
|
|
16797
|
+
function closeGitFooterContextMenu({ returnFocus = true } = {}) {
|
|
16798
|
+
const trigger = gitFooterContextMenuState?.trigger;
|
|
16799
|
+
gitFooterContextMenuState = null;
|
|
16800
|
+
if (elements.gitFooterContextMenu) elements.gitFooterContextMenu.hidden = true;
|
|
16801
|
+
if (returnFocus && trigger?.isConnected) queueMicrotask(() => trigger.focus?.({ preventScroll: true }));
|
|
16802
|
+
}
|
|
16803
|
+
|
|
16804
|
+
function showGitFooterContextMenu(event, chip, trigger) {
|
|
16805
|
+
const menu = elements.gitFooterContextMenu;
|
|
16806
|
+
const key = cleanStatusText(chip?.key);
|
|
16807
|
+
if (!menu || !key) return;
|
|
16808
|
+
event.preventDefault();
|
|
16809
|
+
event.stopPropagation();
|
|
16810
|
+
closeFileContextMenu({ returnFocus: false });
|
|
16811
|
+
closeGitPanelContextMenu({ returnFocus: false });
|
|
16812
|
+
closeSidePanelContextMenu({ returnFocus: false });
|
|
16813
|
+
closeGitFooterContextMenu({ returnFocus: false });
|
|
16814
|
+
hideFooterTooltip();
|
|
16815
|
+
|
|
16816
|
+
const label = cleanStatusText(chip?.label) || gitFooterVisibilityLabel(key);
|
|
16817
|
+
gitFooterContextMenuState = { key, label, trigger };
|
|
16818
|
+
const disableButton = menu.querySelector('[data-git-footer-menu-action="disable"]');
|
|
16819
|
+
if (disableButton) disableButton.textContent = `Disable ${label} box`;
|
|
16820
|
+
menu.hidden = false;
|
|
16821
|
+
const rect = menu.getBoundingClientRect();
|
|
16822
|
+
const left = Math.min(event.clientX, Math.max(8, window.innerWidth - rect.width - 8));
|
|
16823
|
+
const top = Math.min(event.clientY, Math.max(8, window.innerHeight - rect.height - 8));
|
|
16824
|
+
menu.style.left = `${Math.max(8, left)}px`;
|
|
16825
|
+
menu.style.top = `${Math.max(8, top)}px`;
|
|
16826
|
+
menu.querySelector('[role="menuitem"]')?.focus({ preventScroll: true });
|
|
16827
|
+
}
|
|
16828
|
+
|
|
16829
|
+
function bindGitFooterContextMenu(node, chip) {
|
|
16830
|
+
if (!node || !chip?.key) return node;
|
|
16831
|
+
node.setAttribute("aria-keyshortcuts", "ContextMenu Shift+F10");
|
|
16832
|
+
node.addEventListener("contextmenu", (event) => showGitFooterContextMenu(event, chip, node));
|
|
16833
|
+
node.addEventListener("keydown", (event) => {
|
|
16834
|
+
if (event.key !== "ContextMenu" && !(event.shiftKey && event.key === "F10")) return;
|
|
16835
|
+
const rect = node.getBoundingClientRect();
|
|
16836
|
+
showGitFooterContextMenu({
|
|
16837
|
+
preventDefault: () => event.preventDefault(),
|
|
16838
|
+
stopPropagation: () => event.stopPropagation(),
|
|
16839
|
+
clientX: rect.left + Math.min(rect.width, 24),
|
|
16840
|
+
clientY: rect.bottom,
|
|
16841
|
+
}, chip, node);
|
|
16842
|
+
});
|
|
16843
|
+
return node;
|
|
16844
|
+
}
|
|
16845
|
+
|
|
16846
|
+
async function disableGitFooterContextChip(key, label) {
|
|
16847
|
+
try {
|
|
16848
|
+
await runGitFooterVisibilityCommand("hide", [key]);
|
|
16849
|
+
addEvent(`Disabled the ${label || key} Git footer box.`, "success");
|
|
16850
|
+
requestGitFooterWebuiPayload(activeTabContext(), { force: true, allowDuringRun: true });
|
|
16851
|
+
} catch (error) {
|
|
16852
|
+
addEvent(error.message || String(error), "error");
|
|
16853
|
+
}
|
|
16854
|
+
}
|
|
16855
|
+
|
|
16616
16856
|
function cleanFooterPayloadText(value, fallback = "", maxLength = 240) {
|
|
16617
16857
|
const text = cleanStatusText(value).slice(0, maxLength);
|
|
16618
16858
|
return text || fallback;
|
|
@@ -17000,7 +17240,7 @@ function renderGitFooterPayloadMetric(chip, payload) {
|
|
|
17000
17240
|
const node = footerMetric(chip.icon || "•", chip.label, chip.value, chip.tone ? `tone-${chip.tone}` : "", options);
|
|
17001
17241
|
if (chip.contextUsage) applyFooterContextUsage(node, chip.contextUsage);
|
|
17002
17242
|
if (chip.usageWindows) applyFooterUsageWindows(node, chip.usageWindows);
|
|
17003
|
-
return node;
|
|
17243
|
+
return bindGitFooterContextMenu(node, chip);
|
|
17004
17244
|
}
|
|
17005
17245
|
|
|
17006
17246
|
function gitFooterSyncCounts(value) {
|
|
@@ -17016,7 +17256,8 @@ function gitFooterSyncCounts(value) {
|
|
|
17016
17256
|
function gitFooterSyncAction(chip) {
|
|
17017
17257
|
if (chip?.key !== "sync") return "";
|
|
17018
17258
|
const { ahead, behind } = gitFooterSyncCounts(chip.value);
|
|
17019
|
-
if (behind > 0 && ahead
|
|
17259
|
+
if (behind > 0 && ahead > 0) return "pull-push";
|
|
17260
|
+
if (behind > 0) return "pull";
|
|
17020
17261
|
if (ahead > 0) return "push";
|
|
17021
17262
|
return "";
|
|
17022
17263
|
}
|
|
@@ -17027,8 +17268,172 @@ function gitFooterCurrentBranch() {
|
|
|
17027
17268
|
return value && value !== "no repo" ? cleanFooterPayloadText(gitChip.value, "") : "";
|
|
17028
17269
|
}
|
|
17029
17270
|
|
|
17030
|
-
|
|
17031
|
-
|
|
17271
|
+
function gitFailureDisplayText(response, fallback = "Git operation failed") {
|
|
17272
|
+
const errorText = String(response?.error || "").trim();
|
|
17273
|
+
const hintText = String(response?.hint || "").trim();
|
|
17274
|
+
const result = response?.data && typeof response.data === "object" ? { ...response.data } : null;
|
|
17275
|
+
if (result && errorText) {
|
|
17276
|
+
if (String(result.stderr || "").trim() === errorText) result.stderr = "";
|
|
17277
|
+
if (String(result.stdout || "").trim() === errorText) result.stdout = "";
|
|
17278
|
+
}
|
|
17279
|
+
const parts = [errorText || fallback, hintText, formatGitCommandResult(result)].map((part) => String(part || "").trim()).filter(Boolean);
|
|
17280
|
+
const seen = new Set();
|
|
17281
|
+
return parts.filter((part) => {
|
|
17282
|
+
const key = part.replace(/\r\n/g, "\n");
|
|
17283
|
+
if (seen.has(key)) return false;
|
|
17284
|
+
seen.add(key);
|
|
17285
|
+
return true;
|
|
17286
|
+
}).join("\n\n");
|
|
17287
|
+
}
|
|
17288
|
+
|
|
17289
|
+
function setGitPullErrorBusy(busy) {
|
|
17290
|
+
gitPullErrorContext = { ...gitPullErrorContext, busy: !!busy };
|
|
17291
|
+
for (const button of [elements.gitPullErrorMergeButton, elements.gitPullErrorRebaseButton, elements.gitPullErrorReviewButton, elements.gitPullErrorCloseButton]) {
|
|
17292
|
+
if (button) button.disabled = !!busy;
|
|
17293
|
+
}
|
|
17294
|
+
if (elements.gitPullErrorDialog) elements.gitPullErrorDialog.setAttribute("aria-busy", busy ? "true" : "false");
|
|
17295
|
+
}
|
|
17296
|
+
|
|
17297
|
+
function closeGitPullErrorDialog() {
|
|
17298
|
+
if (gitPullErrorContext.busy) return;
|
|
17299
|
+
if (elements.gitPullErrorDialog?.open) elements.gitPullErrorDialog.close();
|
|
17300
|
+
}
|
|
17301
|
+
|
|
17302
|
+
function openGitPullErrorDialog(message, { code = "", tabId = null, syncValue = "" } = {}) {
|
|
17303
|
+
const text = String(message || "git pull from origin failed").trim();
|
|
17304
|
+
const diverged = code === "DIVERGED";
|
|
17305
|
+
gitPullErrorText = text;
|
|
17306
|
+
gitPullErrorContext = {
|
|
17307
|
+
code,
|
|
17308
|
+
tabId: typeof tabId === "string" && tabId ? tabId : null,
|
|
17309
|
+
syncValue: String(syncValue || ""),
|
|
17310
|
+
busy: false,
|
|
17311
|
+
requestId: gitPullErrorContext.requestId + 1,
|
|
17312
|
+
};
|
|
17313
|
+
if (!elements.gitPullErrorDialog?.showModal || !elements.gitPullErrorOutput) {
|
|
17314
|
+
window.alert(`${diverged ? "Branches diverged" : "Git pull failed"}\n\n${text}`);
|
|
17315
|
+
return;
|
|
17316
|
+
}
|
|
17317
|
+
if (elements.gitPullErrorDialogTitle) elements.gitPullErrorDialogTitle.textContent = diverged ? "Branches diverged" : "Git pull failed";
|
|
17318
|
+
if (elements.gitPullErrorDialogDescription) {
|
|
17319
|
+
elements.gitPullErrorDialogDescription.textContent = diverged
|
|
17320
|
+
? "Local and remote contain unique commits. This does not mean conflicts exist; conflicts are known only after a merge or rebase is attempted."
|
|
17321
|
+
: "The repository was not changed by the failed pull. Review or copy the complete error output below.";
|
|
17322
|
+
}
|
|
17323
|
+
elements.gitPullErrorOutput.textContent = text;
|
|
17324
|
+
if (elements.gitPullErrorRecovery) elements.gitPullErrorRecovery.hidden = !diverged;
|
|
17325
|
+
elements.gitPullErrorCloseButton?.classList.toggle("primary", !diverged);
|
|
17326
|
+
if (elements.gitPullErrorStatus) {
|
|
17327
|
+
elements.gitPullErrorStatus.textContent = diverged
|
|
17328
|
+
? "Review the incoming changes, merge them, or rebase your local commits. No integration runs without confirmation."
|
|
17329
|
+
: "Select the output or use Copy error output.";
|
|
17330
|
+
elements.gitPullErrorStatus.classList.remove("error", "success");
|
|
17331
|
+
}
|
|
17332
|
+
setGitPullErrorBusy(false);
|
|
17333
|
+
if (!elements.gitPullErrorDialog.open) elements.gitPullErrorDialog.showModal();
|
|
17334
|
+
queueMicrotask(() => (diverged ? elements.gitPullErrorReviewButton : elements.gitPullErrorCopyButton)?.focus({ preventScroll: true }));
|
|
17335
|
+
}
|
|
17336
|
+
|
|
17337
|
+
async function copyGitPullErrorOutput() {
|
|
17338
|
+
if (!gitPullErrorText) return;
|
|
17339
|
+
if (elements.gitPullErrorCopyButton) elements.gitPullErrorCopyButton.disabled = true;
|
|
17340
|
+
try {
|
|
17341
|
+
await copyText(gitPullErrorText);
|
|
17342
|
+
if (elements.gitPullErrorStatus) {
|
|
17343
|
+
elements.gitPullErrorStatus.textContent = "Error output copied to the clipboard.";
|
|
17344
|
+
elements.gitPullErrorStatus.classList.add("success");
|
|
17345
|
+
elements.gitPullErrorStatus.classList.remove("error");
|
|
17346
|
+
}
|
|
17347
|
+
addEvent("copied Git pull error output", "info");
|
|
17348
|
+
} catch (error) {
|
|
17349
|
+
const message = `Copy failed: ${error.message || String(error)}`;
|
|
17350
|
+
if (elements.gitPullErrorStatus) {
|
|
17351
|
+
elements.gitPullErrorStatus.textContent = message;
|
|
17352
|
+
elements.gitPullErrorStatus.classList.add("error");
|
|
17353
|
+
elements.gitPullErrorStatus.classList.remove("success");
|
|
17354
|
+
}
|
|
17355
|
+
addEvent(`Git pull error output copy failed: ${error.message || String(error)}`, "error");
|
|
17356
|
+
} finally {
|
|
17357
|
+
if (elements.gitPullErrorCopyButton) elements.gitPullErrorCopyButton.disabled = false;
|
|
17358
|
+
}
|
|
17359
|
+
}
|
|
17360
|
+
|
|
17361
|
+
function reviewGitPullDivergence() {
|
|
17362
|
+
if (gitPullErrorContext.code !== "DIVERGED" || !gitPullErrorContext.tabId || gitPullErrorContext.busy) return;
|
|
17363
|
+
const tabId = gitPullErrorContext.tabId;
|
|
17364
|
+
closeGitPullErrorDialog();
|
|
17365
|
+
openGitChangesDialog(tabId);
|
|
17366
|
+
}
|
|
17367
|
+
|
|
17368
|
+
async function integrateGitPullDivergence(mode) {
|
|
17369
|
+
if (!["merge", "rebase"].includes(mode) || gitPullErrorContext.code !== "DIVERGED" || !gitPullErrorContext.tabId || gitPullErrorContext.busy) return false;
|
|
17370
|
+
const { tabId, syncValue, requestId } = gitPullErrorContext;
|
|
17371
|
+
const targetTab = tabs.find((tab) => tab.id === tabId);
|
|
17372
|
+
const activeBranch = tabId === activeTabId ? gitFooterCurrentBranch() : "";
|
|
17373
|
+
const target = activeBranch || targetTab?.title || targetTab?.cwd || "the selected branch";
|
|
17374
|
+
const merge = mode === "merge";
|
|
17375
|
+
const confirmed = await appConfirmText([
|
|
17376
|
+
`${merge ? "Merge upstream changes into" : "Rebase local commits onto the upstream of"} ${target}?`,
|
|
17377
|
+
"",
|
|
17378
|
+
merge
|
|
17379
|
+
? "This preserves both histories and may create a merge commit. Conflicts are possible but are not currently known."
|
|
17380
|
+
: "This replays local commits on top of upstream and rewrites their commit IDs. Conflicts are possible but are not currently known.",
|
|
17381
|
+
].join("\n"), {
|
|
17382
|
+
affected: `Git history for ${target}`,
|
|
17383
|
+
confirmLabel: merge ? "Merge changes" : "Rebase commits",
|
|
17384
|
+
danger: !merge,
|
|
17385
|
+
});
|
|
17386
|
+
if (!confirmed || gitPullErrorContext.requestId !== requestId) return false;
|
|
17387
|
+
|
|
17388
|
+
const tabContext = activeTabContext(tabId);
|
|
17389
|
+
let pushSyncValue = "";
|
|
17390
|
+
setGitPullErrorBusy(true);
|
|
17391
|
+
gitFooterSyncInFlightByTab.add(tabId);
|
|
17392
|
+
if (isCurrentTabContext(tabContext)) renderFooter();
|
|
17393
|
+
if (elements.gitPullErrorStatus) elements.gitPullErrorStatus.textContent = merge ? "Merging upstream changes…" : "Rebasing local commits…";
|
|
17394
|
+
try {
|
|
17395
|
+
const response = await api("/api/git-changes/integrate", { method: "POST", body: { mode, confirmed: true }, tabId });
|
|
17396
|
+
if (gitPullErrorContext.requestId !== requestId) return false;
|
|
17397
|
+
if (!response.ok) {
|
|
17398
|
+
const message = gitFailureDisplayText(response, `git ${mode} failed`);
|
|
17399
|
+
addEvent(message, "error");
|
|
17400
|
+
setGitPullErrorBusy(false);
|
|
17401
|
+
if (response.code === "CONFLICTS") {
|
|
17402
|
+
closeGitPullErrorDialog();
|
|
17403
|
+
openGitChangesDialog(tabId);
|
|
17404
|
+
return false;
|
|
17405
|
+
}
|
|
17406
|
+
openGitPullErrorDialog(message, { code: response.code || "", tabId, syncValue });
|
|
17407
|
+
return false;
|
|
17408
|
+
}
|
|
17409
|
+
setGitPullErrorBusy(false);
|
|
17410
|
+
closeGitPullErrorDialog();
|
|
17411
|
+
addEvent(`${merge ? "Merged" : "Rebased"} upstream changes.`, "success");
|
|
17412
|
+
requestGitFooterWebuiPayload(tabContext, { force: true });
|
|
17413
|
+
const freshAheadValue = response.data?.changes?.summary?.ahead;
|
|
17414
|
+
const freshAhead = Number(freshAheadValue);
|
|
17415
|
+
if (freshAheadValue !== undefined) {
|
|
17416
|
+
if (Number.isFinite(freshAhead) && freshAhead > 0) pushSyncValue = `⇡${freshAhead}`;
|
|
17417
|
+
} else if (gitFooterSyncCounts(syncValue).ahead > 0) {
|
|
17418
|
+
pushSyncValue = syncValue;
|
|
17419
|
+
}
|
|
17420
|
+
} catch (error) {
|
|
17421
|
+
if (gitPullErrorContext.requestId !== requestId) return false;
|
|
17422
|
+
const message = error.message || String(error);
|
|
17423
|
+
addEvent(message, "error");
|
|
17424
|
+
setGitPullErrorBusy(false);
|
|
17425
|
+
openGitPullErrorDialog(message, { tabId, syncValue });
|
|
17426
|
+
return false;
|
|
17427
|
+
} finally {
|
|
17428
|
+
gitFooterSyncInFlightByTab.delete(tabId);
|
|
17429
|
+
if (isCurrentTabContext(tabContext)) renderFooter();
|
|
17430
|
+
}
|
|
17431
|
+
if (pushSyncValue) await pushGitFooterSync(tabId, pushSyncValue);
|
|
17432
|
+
return true;
|
|
17433
|
+
}
|
|
17434
|
+
|
|
17435
|
+
async function pullGitFooterSync(tabId = activeTabId, { syncValue = "" } = {}) {
|
|
17436
|
+
if (!tabId || gitFooterSyncInFlightByTab.has(tabId)) return false;
|
|
17032
17437
|
const tabContext = activeTabContext(tabId);
|
|
17033
17438
|
hideFooterTooltip();
|
|
17034
17439
|
gitFooterSyncInFlightByTab.add(tabId);
|
|
@@ -17036,23 +17441,36 @@ async function pullGitFooterSync(tabId = activeTabId) {
|
|
|
17036
17441
|
try {
|
|
17037
17442
|
const response = await api("/api/git-changes/pull", { method: "POST", body: { remote: "origin" }, tabId });
|
|
17038
17443
|
if (!response.ok) {
|
|
17039
|
-
const
|
|
17040
|
-
|
|
17444
|
+
const message = gitFailureDisplayText(response, "git pull from origin failed");
|
|
17445
|
+
addEvent(message, "error");
|
|
17446
|
+
openGitPullErrorDialog(message, { code: response.code || "", tabId, syncValue });
|
|
17447
|
+
return false;
|
|
17041
17448
|
}
|
|
17042
17449
|
addEvent("Pulled Git changes from origin.", "success");
|
|
17043
17450
|
requestGitFooterWebuiPayload(tabContext, { force: true });
|
|
17451
|
+
return true;
|
|
17044
17452
|
} catch (error) {
|
|
17045
|
-
|
|
17453
|
+
const message = error.message || String(error);
|
|
17454
|
+
addEvent(message, "error");
|
|
17455
|
+
openGitPullErrorDialog(message, { code: error?.code || "", tabId, syncValue });
|
|
17456
|
+
return false;
|
|
17046
17457
|
} finally {
|
|
17047
17458
|
gitFooterSyncInFlightByTab.delete(tabId);
|
|
17048
17459
|
if (isCurrentTabContext(tabContext)) renderFooter();
|
|
17049
17460
|
}
|
|
17050
17461
|
}
|
|
17051
17462
|
|
|
17463
|
+
async function pullThenPushGitFooterSync(tabId = activeTabId, syncValue = "") {
|
|
17464
|
+
const pulled = await pullGitFooterSync(tabId, { syncValue });
|
|
17465
|
+
if (!pulled) return;
|
|
17466
|
+
await pushGitFooterSync(tabId, syncValue);
|
|
17467
|
+
}
|
|
17468
|
+
|
|
17052
17469
|
async function pushGitFooterSync(tabId = activeTabId, syncValue = "") {
|
|
17053
17470
|
if (!tabId || gitFooterSyncInFlightByTab.has(tabId)) return;
|
|
17054
17471
|
const outgoing = gitFooterSyncCounts(syncValue).ahead;
|
|
17055
17472
|
if (outgoing <= 0) return;
|
|
17473
|
+
let recoverWithPullFirst = false;
|
|
17056
17474
|
const tabContext = activeTabContext(tabId);
|
|
17057
17475
|
const tab = tabs.find((item) => item.id === tabId);
|
|
17058
17476
|
const target = tab?.title || tab?.cwd || "this tab";
|
|
@@ -17080,34 +17498,25 @@ async function pushGitFooterSync(tabId = activeTabId, syncValue = "") {
|
|
|
17080
17498
|
throw new Error([response.error, response.hint].filter(Boolean).join("\n"));
|
|
17081
17499
|
}
|
|
17082
17500
|
if (response.code === "NON_FAST_FORWARD") {
|
|
17083
|
-
|
|
17084
|
-
|
|
17085
|
-
|
|
17086
|
-
|
|
17087
|
-
"",
|
|
17088
|
-
"Recommended: open the Git Changes dialog, fetch, and review the incoming diff first.",
|
|
17089
|
-
`DANGER: force-push ${branch || "the current branch"} with --force-with-lease instead? This rewrites the remote branch (but still refuses if the remote moved past what you fetched).`,
|
|
17090
|
-
].join("\n"));
|
|
17091
|
-
if (forcePush) {
|
|
17092
|
-
const forceResponse = await api("/api/git-workflow/push", { method: "POST", body: { forceWithLease: true, confirmed: true }, tabId });
|
|
17093
|
-
if (!forceResponse.ok) throw new Error([forceResponse.error, forceResponse.hint].filter(Boolean).join("\n"));
|
|
17094
|
-
addEvent("Force-pushed with --force-with-lease.", "success");
|
|
17095
|
-
requestGitFooterWebuiPayload(tabContext, { force: true });
|
|
17096
|
-
return;
|
|
17097
|
-
}
|
|
17098
|
-
throw new Error([response.error, response.hint].filter(Boolean).join("\n"));
|
|
17501
|
+
recoverWithPullFirst = true;
|
|
17502
|
+
} else {
|
|
17503
|
+
const detail = [response.error, response.hint, formatGitCommandResult(response.data)].filter(Boolean).join("\n\n").trim();
|
|
17504
|
+
throw new Error(detail || "git push failed");
|
|
17099
17505
|
}
|
|
17100
|
-
|
|
17101
|
-
|
|
17506
|
+
} else {
|
|
17507
|
+
addEvent(`Pushed ${outgoing} outgoing commit${outgoing === 1 ? "" : "s"}.`, "success");
|
|
17508
|
+
requestGitFooterWebuiPayload(tabContext, { force: true });
|
|
17102
17509
|
}
|
|
17103
|
-
addEvent(`Pushed ${outgoing} outgoing commit${outgoing === 1 ? "" : "s"}.`, "success");
|
|
17104
|
-
requestGitFooterWebuiPayload(tabContext, { force: true });
|
|
17105
17510
|
} catch (error) {
|
|
17106
17511
|
addEvent(error.message || String(error), "error");
|
|
17107
17512
|
} finally {
|
|
17108
17513
|
gitFooterSyncInFlightByTab.delete(tabId);
|
|
17109
17514
|
if (isCurrentTabContext(tabContext)) renderFooter();
|
|
17110
17515
|
}
|
|
17516
|
+
if (recoverWithPullFirst) {
|
|
17517
|
+
addEvent("Push found incoming commits. Starting pull-first recovery.", "info");
|
|
17518
|
+
await pullThenPushGitFooterSync(tabId, syncValue);
|
|
17519
|
+
}
|
|
17111
17520
|
}
|
|
17112
17521
|
|
|
17113
17522
|
function renderGitFooterPayloadMeta(chip, tab, payload) {
|
|
@@ -17133,6 +17542,9 @@ function renderGitFooterPayloadMeta(chip, tab, payload) {
|
|
|
17133
17542
|
if (syncAction === "pull") {
|
|
17134
17543
|
options.onClick = () => pullGitFooterSync(tabId);
|
|
17135
17544
|
action = inFlight ? "Pulling from origin." : "Click to pull from origin with fast-forward only.";
|
|
17545
|
+
} else if (syncAction === "pull-push") {
|
|
17546
|
+
options.onClick = () => pullThenPushGitFooterSync(tabId, chip.value);
|
|
17547
|
+
action = inFlight ? "Pulling from origin before pushing local commits." : "Click to pull from origin with fast-forward only, then push if the pull succeeds.";
|
|
17136
17548
|
} else if (syncAction === "push") {
|
|
17137
17549
|
options.onClick = () => pushGitFooterSync(tabId, chip.value);
|
|
17138
17550
|
action = inFlight ? "Pushing local commits to the configured remote." : "Click to push local commits to the configured remote.";
|
|
@@ -17168,7 +17580,7 @@ function renderGitFooterPayloadMeta(chip, tab, payload) {
|
|
|
17168
17580
|
}
|
|
17169
17581
|
if (chip.contextUsage) applyFooterContextUsage(node, chip.contextUsage);
|
|
17170
17582
|
if (chip.usageWindows) applyFooterUsageWindows(node, chip.usageWindows);
|
|
17171
|
-
return node;
|
|
17583
|
+
return bindGitFooterContextMenu(node, chip);
|
|
17172
17584
|
}
|
|
17173
17585
|
|
|
17174
17586
|
// Shape key for a footer chip with the frequently-changing fields removed, so
|
|
@@ -17312,6 +17724,7 @@ function renderGitFooterPayload(payload) {
|
|
|
17312
17724
|
return;
|
|
17313
17725
|
}
|
|
17314
17726
|
|
|
17727
|
+
closeGitFooterContextMenu({ returnFocus: false });
|
|
17315
17728
|
elements.statusBar.replaceChildren();
|
|
17316
17729
|
elements.statusBar.classList.remove("statusbar-tui-footer");
|
|
17317
17730
|
elements.statusBar.classList.add("statusbar-git-footer");
|
|
@@ -23412,6 +23825,499 @@ function initializeSubagentLaunchSlots() {
|
|
|
23412
23825
|
if (activeTabId) loadSubagentLaunchSlotConfig().catch(() => {});
|
|
23413
23826
|
}
|
|
23414
23827
|
|
|
23828
|
+
function samplingParametersPath(tabId) {
|
|
23829
|
+
return `/api/tabs/${encodeURIComponent(tabId)}/sampling-parameters`;
|
|
23830
|
+
}
|
|
23831
|
+
|
|
23832
|
+
const samplingParameterControlElements = new Map();
|
|
23833
|
+
let samplingParameterTooltipDismissalInstalled = false;
|
|
23834
|
+
|
|
23835
|
+
function samplingParameterTooltipBoundary(row) {
|
|
23836
|
+
const viewportHeight = globalThis.innerHeight || document.documentElement?.clientHeight || 0;
|
|
23837
|
+
const clippingRects = [row?.closest?.(".side-panel-section-content"), row?.closest?.(".side-panel-body")]
|
|
23838
|
+
.map((node) => node?.getBoundingClientRect?.())
|
|
23839
|
+
.filter(Boolean);
|
|
23840
|
+
return {
|
|
23841
|
+
top: Math.max(8, ...clippingRects.map((rect) => rect.top)),
|
|
23842
|
+
bottom: Math.min(viewportHeight - 8, ...clippingRects.map((rect) => rect.bottom)),
|
|
23843
|
+
};
|
|
23844
|
+
}
|
|
23845
|
+
|
|
23846
|
+
function updateSamplingParameterTooltipPlacement(row, tooltip) {
|
|
23847
|
+
if (!row?.classList.contains("unsupported") || tooltip?.hidden || !row.getBoundingClientRect || !tooltip.getBoundingClientRect) return;
|
|
23848
|
+
tooltip.classList.remove("sampling-tooltip-below");
|
|
23849
|
+
tooltip.style?.removeProperty("--sampling-tooltip-max-height");
|
|
23850
|
+
const rowRect = row.getBoundingClientRect();
|
|
23851
|
+
const naturalHeight = Math.max(tooltip.scrollHeight || 0, tooltip.getBoundingClientRect().height || 0);
|
|
23852
|
+
const boundary = samplingParameterTooltipBoundary(row);
|
|
23853
|
+
const spaceAbove = Math.max(0, rowRect.top - boundary.top - 6);
|
|
23854
|
+
const spaceBelow = Math.max(0, boundary.bottom - rowRect.bottom - 6);
|
|
23855
|
+
const placeBelow = spaceAbove < naturalHeight && spaceBelow > spaceAbove;
|
|
23856
|
+
const availableHeight = placeBelow ? spaceBelow : spaceAbove;
|
|
23857
|
+
tooltip.classList.toggle("sampling-tooltip-below", placeBelow);
|
|
23858
|
+
tooltip.style?.setProperty("--sampling-tooltip-max-height", `${Math.floor(availableHeight)}px`);
|
|
23859
|
+
}
|
|
23860
|
+
|
|
23861
|
+
function resetSamplingParameterTooltip(row, tooltip) {
|
|
23862
|
+
row?.classList.remove("sampling-tooltip-dismissed");
|
|
23863
|
+
updateSamplingParameterTooltipPlacement(row, tooltip);
|
|
23864
|
+
}
|
|
23865
|
+
|
|
23866
|
+
function dismissSamplingParameterTooltip(row, event) {
|
|
23867
|
+
if (!row?.classList.contains("unsupported") || row.classList.contains("sampling-tooltip-dismissed")) return false;
|
|
23868
|
+
row.classList.add("sampling-tooltip-dismissed");
|
|
23869
|
+
event?.preventDefault?.();
|
|
23870
|
+
event?.stopPropagation?.();
|
|
23871
|
+
return true;
|
|
23872
|
+
}
|
|
23873
|
+
|
|
23874
|
+
function initializeSamplingParameterTooltipDismissal() {
|
|
23875
|
+
if (samplingParameterTooltipDismissalInstalled || typeof document.addEventListener !== "function") return;
|
|
23876
|
+
samplingParameterTooltipDismissalInstalled = true;
|
|
23877
|
+
document.addEventListener("keydown", (event) => {
|
|
23878
|
+
if (event.key !== "Escape" || event.target?.closest?.(".sampling-parameter-control.unsupported")) return;
|
|
23879
|
+
const hovered = document.querySelector?.(".sampling-parameter-control.unsupported:hover:not(.sampling-tooltip-dismissed)");
|
|
23880
|
+
if (hovered) dismissSamplingParameterTooltip(hovered, event);
|
|
23881
|
+
});
|
|
23882
|
+
}
|
|
23883
|
+
|
|
23884
|
+
function cloneSamplingControlDraft(draft) {
|
|
23885
|
+
return draft ? JSON.parse(JSON.stringify(draft)) : null;
|
|
23886
|
+
}
|
|
23887
|
+
|
|
23888
|
+
function samplingParametersBaseDraft(tabId = activeTabId) {
|
|
23889
|
+
if (!tabId || samplingParametersStateTabId !== tabId || !samplingParametersState) return null;
|
|
23890
|
+
return createSamplingControlDraft(samplingParametersState.session || {}, {
|
|
23891
|
+
defaults: samplingParametersState.defaults || {},
|
|
23892
|
+
});
|
|
23893
|
+
}
|
|
23894
|
+
|
|
23895
|
+
function samplingParametersDraft(tabId = activeTabId) {
|
|
23896
|
+
return tabId ? samplingParametersDrafts.get(tabId) ?? null : null;
|
|
23897
|
+
}
|
|
23898
|
+
|
|
23899
|
+
function setSamplingParametersDraft(draft, tabId = activeTabId) {
|
|
23900
|
+
if (!tabId) return;
|
|
23901
|
+
if (draft === null) samplingParametersDrafts.delete(tabId);
|
|
23902
|
+
else samplingParametersDrafts.set(tabId, cloneSamplingControlDraft(draft));
|
|
23903
|
+
}
|
|
23904
|
+
|
|
23905
|
+
function samplingParametersEditableDraft(tabId = activeTabId) {
|
|
23906
|
+
return samplingParametersDraft(tabId) || samplingParametersBaseDraft(tabId);
|
|
23907
|
+
}
|
|
23908
|
+
|
|
23909
|
+
// Drafts are keyed by Pi tab so background refreshes and tab switches cannot
|
|
23910
|
+
// overwrite or expose another session's unsaved controls.
|
|
23911
|
+
function samplingParametersDraftIsDirty(tabId = activeTabId) {
|
|
23912
|
+
const draft = samplingParametersDraft(tabId);
|
|
23913
|
+
if (!draft) return false;
|
|
23914
|
+
const baseline = samplingParametersBaseDraft(tabId);
|
|
23915
|
+
return !baseline || !samplingControlDraftEquals(draft, baseline);
|
|
23916
|
+
}
|
|
23917
|
+
|
|
23918
|
+
function samplingParametersSectionRecord() {
|
|
23919
|
+
return sidePanelSectionRecords().find(({ id }) => id === "sampling") || null;
|
|
23920
|
+
}
|
|
23921
|
+
|
|
23922
|
+
function samplingParametersSectionActive() {
|
|
23923
|
+
const record = samplingParametersSectionRecord();
|
|
23924
|
+
return !!record && !record.section.hidden && !record.section.classList.contains("collapsed");
|
|
23925
|
+
}
|
|
23926
|
+
|
|
23927
|
+
function samplingParametersSupportText() {
|
|
23928
|
+
const state = samplingParametersStateTabId === activeTabId ? samplingParametersState : null;
|
|
23929
|
+
const support = state?.support;
|
|
23930
|
+
if (!support) return samplingParametersLoading ? "Loading sampling support…" : "Select a running Pi tab to load sampling parameters.";
|
|
23931
|
+
const modelLabel = support.model?.provider && support.model?.id ? `(${support.model.provider}) ${support.model.id}` : "unknown model";
|
|
23932
|
+
const apiLabel = support.api || "unknown API";
|
|
23933
|
+
if (support.supported) return `${modelLabel} · ${apiLabel} · ${support.message || "Sampling parameters apply to subsequent provider requests."}`;
|
|
23934
|
+
const compatible = Array.isArray(support.compatibleApis) && support.compatibleApis.length
|
|
23935
|
+
? ` Sampling-capable APIs: ${support.compatibleApis.join(", ")}.`
|
|
23936
|
+
: "";
|
|
23937
|
+
return `${modelLabel} · ${apiLabel} · ${support.message || "Sampling parameters are stored but not applied."}${compatible}`;
|
|
23938
|
+
}
|
|
23939
|
+
|
|
23940
|
+
// Success and error text describes one tab's last action, so it is suppressed as soon
|
|
23941
|
+
// as another tab becomes active instead of leaking into the new tab's status line.
|
|
23942
|
+
function samplingParametersFeedbackIsCurrent() {
|
|
23943
|
+
return samplingParametersFeedbackTabId === activeTabId;
|
|
23944
|
+
}
|
|
23945
|
+
|
|
23946
|
+
function setSamplingParametersFeedback({ error = "", notice = "" } = {}) {
|
|
23947
|
+
samplingParametersError = error;
|
|
23948
|
+
samplingParametersNotice = notice;
|
|
23949
|
+
samplingParametersFeedbackTabId = error || notice ? activeTabId : null;
|
|
23950
|
+
}
|
|
23951
|
+
|
|
23952
|
+
function samplingParametersStatusText({ dirty, unsupported, validation, loadedForActiveTab }) {
|
|
23953
|
+
const feedbackCurrent = samplingParametersFeedbackIsCurrent();
|
|
23954
|
+
if (samplingParametersError && feedbackCurrent) return samplingParametersError;
|
|
23955
|
+
if (samplingParametersBusy) return "Applying sampling parameters…";
|
|
23956
|
+
if (samplingParametersLoading) return "Loading session sampling parameters…";
|
|
23957
|
+
if (!activeTabId) return "Select a running Pi tab to edit sampling parameters.";
|
|
23958
|
+
if (samplingParametersNotice && feedbackCurrent) return samplingParametersNotice;
|
|
23959
|
+
if (!loadedForActiveTab) return "Sampling parameters are not loaded for this tab.";
|
|
23960
|
+
if (!validation.valid) return Object.values(validation.errors)[0] || "Correct invalid sampling values before applying.";
|
|
23961
|
+
if (unsupported) return "This model has no verified sampling parameters, so applying them is disabled.";
|
|
23962
|
+
if (dirty) return "Unsaved controls · Apply stores enabled values for this session only.";
|
|
23963
|
+
return "Saved for this Pi session · unchecked parameters inherit model defaults.";
|
|
23964
|
+
}
|
|
23965
|
+
|
|
23966
|
+
function samplingParameterCapabilities(state) {
|
|
23967
|
+
return Object.fromEntries(SAMPLING_PARAMETER_CATALOG.map(({ key }) => [
|
|
23968
|
+
key,
|
|
23969
|
+
samplingParameterCapability(state?.support?.parameters, key),
|
|
23970
|
+
]));
|
|
23971
|
+
}
|
|
23972
|
+
|
|
23973
|
+
function samplingParameterDomId(key, suffix) {
|
|
23974
|
+
return `samplingParameter${key.split("_").map((part) => part[0].toUpperCase() + part.slice(1)).join("")}${suffix}`;
|
|
23975
|
+
}
|
|
23976
|
+
|
|
23977
|
+
function samplingParameterDisplayValue(parameters, key) {
|
|
23978
|
+
if (!parameters || typeof parameters !== "object" || !Object.hasOwn(parameters, key)) return "Inherited";
|
|
23979
|
+
const value = parameters[key];
|
|
23980
|
+
return typeof value === "number" && Number.isFinite(value) ? String(value) : "Invalid or unsupported value";
|
|
23981
|
+
}
|
|
23982
|
+
|
|
23983
|
+
function updateSamplingParameterControl(key, mutate) {
|
|
23984
|
+
const baseline = samplingParametersEditableDraft();
|
|
23985
|
+
if (!baseline || samplingParametersStateTabId !== activeTabId) return;
|
|
23986
|
+
const next = cloneSamplingControlDraft(baseline);
|
|
23987
|
+
mutate(next.controls[key]);
|
|
23988
|
+
setSamplingParametersDraft(next);
|
|
23989
|
+
setSamplingParametersFeedback();
|
|
23990
|
+
renderSamplingParameters();
|
|
23991
|
+
}
|
|
23992
|
+
|
|
23993
|
+
function initializeSamplingParameterControls() {
|
|
23994
|
+
if (!elements.samplingParametersControls || samplingParameterControlElements.size) return;
|
|
23995
|
+
initializeSamplingParameterTooltipDismissal();
|
|
23996
|
+
const groups = new Map();
|
|
23997
|
+
for (const [name, label] of [["core", "OpenAI-compatible controls"], ["server-extension", "Server extensions"]]) {
|
|
23998
|
+
const section = document.createElement("section");
|
|
23999
|
+
section.className = "sampling-parameter-group";
|
|
24000
|
+
section.dataset.samplingParameterGroup = name;
|
|
24001
|
+
const heading = document.createElement("h3");
|
|
24002
|
+
heading.textContent = label;
|
|
24003
|
+
section.append(heading);
|
|
24004
|
+
elements.samplingParametersControls.append(section);
|
|
24005
|
+
groups.set(name, section);
|
|
24006
|
+
}
|
|
24007
|
+
|
|
24008
|
+
for (const definition of SAMPLING_PARAMETER_CATALOG) {
|
|
24009
|
+
const row = document.createElement("div");
|
|
24010
|
+
row.className = "sampling-parameter-control";
|
|
24011
|
+
row.dataset.samplingParameter = definition.key;
|
|
24012
|
+
row.setAttribute("role", "group");
|
|
24013
|
+
|
|
24014
|
+
const enableId = samplingParameterDomId(definition.key, "Enabled");
|
|
24015
|
+
const valueId = samplingParameterDomId(definition.key, "Value");
|
|
24016
|
+
const rangeId = samplingParameterDomId(definition.key, "Range");
|
|
24017
|
+
const descriptionId = samplingParameterDomId(definition.key, "Description");
|
|
24018
|
+
const errorId = samplingParameterDomId(definition.key, "Error");
|
|
24019
|
+
const tooltipId = samplingParameterDomId(definition.key, "UnsupportedReason");
|
|
24020
|
+
row.setAttribute("aria-labelledby", `${enableId}Label`);
|
|
24021
|
+
|
|
24022
|
+
const header = document.createElement("div");
|
|
24023
|
+
header.className = "sampling-parameter-control-header";
|
|
24024
|
+
const enable = document.createElement("input");
|
|
24025
|
+
enable.id = enableId;
|
|
24026
|
+
enable.type = "checkbox";
|
|
24027
|
+
const label = document.createElement("label");
|
|
24028
|
+
label.id = `${enableId}Label`;
|
|
24029
|
+
label.htmlFor = enableId;
|
|
24030
|
+
label.textContent = definition.label;
|
|
24031
|
+
const scope = document.createElement("span");
|
|
24032
|
+
scope.className = "sampling-parameter-scope";
|
|
24033
|
+
scope.textContent = definition.scopeLabel;
|
|
24034
|
+
header.append(enable, label, scope);
|
|
24035
|
+
|
|
24036
|
+
const description = document.createElement("p");
|
|
24037
|
+
description.id = descriptionId;
|
|
24038
|
+
description.className = "sampling-parameter-description";
|
|
24039
|
+
description.textContent = definition.description;
|
|
24040
|
+
|
|
24041
|
+
const editor = document.createElement("div");
|
|
24042
|
+
editor.className = "sampling-parameter-editor";
|
|
24043
|
+
const number = document.createElement("input");
|
|
24044
|
+
number.id = valueId;
|
|
24045
|
+
number.className = "sampling-parameter-number";
|
|
24046
|
+
number.type = "number";
|
|
24047
|
+
number.inputMode = definition.kind === "integer" ? "numeric" : "decimal";
|
|
24048
|
+
number.step = String(definition.step);
|
|
24049
|
+
if (definition.min !== undefined && !definition.minExclusive) number.min = String(definition.min);
|
|
24050
|
+
if (definition.max !== undefined) number.max = String(definition.max);
|
|
24051
|
+
number.setAttribute("aria-label", `${definition.label} exact value`);
|
|
24052
|
+
number.setAttribute("aria-describedby", `${descriptionId} ${errorId}`);
|
|
24053
|
+
const range = document.createElement("input");
|
|
24054
|
+
range.id = rangeId;
|
|
24055
|
+
range.className = "sampling-parameter-range";
|
|
24056
|
+
range.type = "range";
|
|
24057
|
+
range.min = String(definition.slider.min);
|
|
24058
|
+
range.max = String(definition.slider.max);
|
|
24059
|
+
range.step = String(definition.slider.step);
|
|
24060
|
+
range.setAttribute("aria-label", `${definition.label} common-range slider`);
|
|
24061
|
+
range.setAttribute("aria-describedby", descriptionId);
|
|
24062
|
+
editor.append(number, range);
|
|
24063
|
+
|
|
24064
|
+
const context = document.createElement("dl");
|
|
24065
|
+
context.className = "sampling-parameter-context";
|
|
24066
|
+
const defaultTerm = document.createElement("dt");
|
|
24067
|
+
defaultTerm.textContent = "Model default";
|
|
24068
|
+
const defaultValue = document.createElement("dd");
|
|
24069
|
+
const effectiveTerm = document.createElement("dt");
|
|
24070
|
+
effectiveTerm.textContent = "Effective";
|
|
24071
|
+
const effectiveValue = document.createElement("dd");
|
|
24072
|
+
context.append(defaultTerm, defaultValue, effectiveTerm, effectiveValue);
|
|
24073
|
+
|
|
24074
|
+
const error = document.createElement("p");
|
|
24075
|
+
error.id = errorId;
|
|
24076
|
+
error.className = "sampling-parameter-error";
|
|
24077
|
+
error.setAttribute("aria-live", "polite");
|
|
24078
|
+
|
|
24079
|
+
const tooltip = document.createElement("p");
|
|
24080
|
+
tooltip.id = tooltipId;
|
|
24081
|
+
tooltip.className = "sampling-parameter-unsupported-tooltip";
|
|
24082
|
+
tooltip.setAttribute("role", "tooltip");
|
|
24083
|
+
|
|
24084
|
+
enable.addEventListener("change", () => updateSamplingParameterControl(definition.key, (control) => {
|
|
24085
|
+
control.enabled = enable.checked;
|
|
24086
|
+
}));
|
|
24087
|
+
number.addEventListener("input", () => updateSamplingParameterControl(definition.key, (control) => {
|
|
24088
|
+
control.value = number.value;
|
|
24089
|
+
}));
|
|
24090
|
+
range.addEventListener("input", () => updateSamplingParameterControl(definition.key, (control) => {
|
|
24091
|
+
control.value = range.value;
|
|
24092
|
+
}));
|
|
24093
|
+
row.addEventListener("keydown", (event) => {
|
|
24094
|
+
if (event.key === "Escape") dismissSamplingParameterTooltip(row, event);
|
|
24095
|
+
});
|
|
24096
|
+
row.addEventListener("pointerenter", () => resetSamplingParameterTooltip(row, tooltip));
|
|
24097
|
+
row.addEventListener("focusin", () => resetSamplingParameterTooltip(row, tooltip));
|
|
24098
|
+
row.addEventListener("focusout", (event) => {
|
|
24099
|
+
if (!row.contains?.(event.relatedTarget) && !row.matches?.(":hover")) row.classList.remove("sampling-tooltip-dismissed");
|
|
24100
|
+
});
|
|
24101
|
+
|
|
24102
|
+
row.append(header, description, editor, context, error, tooltip);
|
|
24103
|
+
groups.get(definition.group)?.append(row);
|
|
24104
|
+
samplingParameterControlElements.set(definition.key, { row, enable, number, range, defaultValue, effectiveValue, error, tooltip });
|
|
24105
|
+
}
|
|
24106
|
+
}
|
|
24107
|
+
|
|
24108
|
+
function renderSamplingParameters() {
|
|
24109
|
+
initializeSamplingParameterControls();
|
|
24110
|
+
const loadedForActiveTab = !!samplingParametersState && samplingParametersStateTabId === activeTabId;
|
|
24111
|
+
const activeState = loadedForActiveTab ? samplingParametersState : null;
|
|
24112
|
+
const editableDraft = samplingParametersEditableDraft()
|
|
24113
|
+
|| createSamplingControlDraft({}, { defaults: activeState?.defaults || {} });
|
|
24114
|
+
const validation = validateSamplingControlDraft(editableDraft);
|
|
24115
|
+
const dirty = samplingParametersDraftIsDirty();
|
|
24116
|
+
const capabilities = samplingParameterCapabilities(activeState);
|
|
24117
|
+
const unsupported = !Object.values(capabilities).some(({ supported }) => supported);
|
|
24118
|
+
const feedbackError = !!samplingParametersError && samplingParametersFeedbackIsCurrent();
|
|
24119
|
+
const showError = feedbackError || !validation.valid;
|
|
24120
|
+
const defaults = splitSamplingParameters(activeState?.defaults || {}).known;
|
|
24121
|
+
const effective = splitSamplingParameters(activeState?.effective || {}).known;
|
|
24122
|
+
const controlsDisabled = samplingParametersBusy || samplingParametersLoading || !activeTabId || !loadedForActiveTab;
|
|
24123
|
+
|
|
24124
|
+
for (const definition of SAMPLING_PARAMETER_CATALOG) {
|
|
24125
|
+
const refs = samplingParameterControlElements.get(definition.key);
|
|
24126
|
+
if (!refs) continue;
|
|
24127
|
+
const control = editableDraft.controls[definition.key];
|
|
24128
|
+
const capability = capabilities[definition.key];
|
|
24129
|
+
const parameterUnsupported = !capability.supported;
|
|
24130
|
+
const error = validation.errors[definition.key] || "";
|
|
24131
|
+
const valueText = typeof control.value === "number" || typeof control.value === "string" ? String(control.value) : "";
|
|
24132
|
+
const tooltipId = samplingParameterDomId(definition.key, "UnsupportedReason");
|
|
24133
|
+
refs.enable.checked = control.enabled;
|
|
24134
|
+
refs.enable.disabled = controlsDisabled || parameterUnsupported;
|
|
24135
|
+
refs.number.disabled = controlsDisabled || parameterUnsupported || !control.enabled;
|
|
24136
|
+
refs.range.disabled = controlsDisabled || parameterUnsupported || !control.enabled;
|
|
24137
|
+
if (refs.number.value !== valueText) refs.number.value = valueText;
|
|
24138
|
+
refs.range.value = String(samplingParameterSliderValue(definition.key, control.value));
|
|
24139
|
+
refs.number.setAttribute("aria-invalid", error ? "true" : "false");
|
|
24140
|
+
refs.row.classList.toggle("enabled", control.enabled);
|
|
24141
|
+
refs.row.classList.toggle("invalid", !!error);
|
|
24142
|
+
refs.row.classList.toggle("unsupported", parameterUnsupported);
|
|
24143
|
+
refs.row.tabIndex = parameterUnsupported ? 0 : -1;
|
|
24144
|
+
if (parameterUnsupported) {
|
|
24145
|
+
refs.row.setAttribute("aria-disabled", "true");
|
|
24146
|
+
refs.row.setAttribute("aria-describedby", tooltipId);
|
|
24147
|
+
refs.enable.setAttribute("aria-describedby", tooltipId);
|
|
24148
|
+
} else {
|
|
24149
|
+
refs.row.removeAttribute("aria-disabled");
|
|
24150
|
+
refs.row.removeAttribute("aria-describedby");
|
|
24151
|
+
refs.enable.removeAttribute("aria-describedby");
|
|
24152
|
+
refs.row.classList.remove("sampling-tooltip-dismissed");
|
|
24153
|
+
}
|
|
24154
|
+
refs.defaultValue.textContent = samplingParameterDisplayValue(defaults, definition.key);
|
|
24155
|
+
refs.effectiveValue.textContent = samplingParameterDisplayValue(effective, definition.key);
|
|
24156
|
+
refs.error.textContent = error;
|
|
24157
|
+
refs.error.hidden = !error;
|
|
24158
|
+
refs.tooltip.hidden = !parameterUnsupported;
|
|
24159
|
+
refs.tooltip.textContent = parameterUnsupported ? capability.reason : "";
|
|
24160
|
+
}
|
|
24161
|
+
|
|
24162
|
+
if (elements.samplingParametersSupport) {
|
|
24163
|
+
elements.samplingParametersSupport.textContent = samplingParametersSupportText();
|
|
24164
|
+
elements.samplingParametersSupport.classList.toggle("warning", unsupported);
|
|
24165
|
+
}
|
|
24166
|
+
if (elements.samplingParametersPreserved) {
|
|
24167
|
+
elements.samplingParametersPreserved.textContent = loadedForActiveTab
|
|
24168
|
+
? summarizePreservedSamplingParameters(editableDraft.preservedUnknown).text
|
|
24169
|
+
: samplingParametersLoading ? "Loading additional parameter state…" : "Additional parameter state is not loaded for this tab.";
|
|
24170
|
+
}
|
|
24171
|
+
if (elements.applySamplingParametersButton) {
|
|
24172
|
+
elements.applySamplingParametersButton.disabled = samplingParametersBusy
|
|
24173
|
+
|| samplingParametersLoading
|
|
24174
|
+
|| !activeTabId
|
|
24175
|
+
|| !loadedForActiveTab
|
|
24176
|
+
|| unsupported
|
|
24177
|
+
|| !validation.valid;
|
|
24178
|
+
elements.applySamplingParametersButton.textContent = samplingParametersBusy ? "Applying…" : "Apply";
|
|
24179
|
+
}
|
|
24180
|
+
if (elements.resetSamplingParametersButton) {
|
|
24181
|
+
elements.resetSamplingParametersButton.disabled = samplingParametersBusy
|
|
24182
|
+
|| samplingParametersLoading
|
|
24183
|
+
|| !activeTabId
|
|
24184
|
+
|| !loadedForActiveTab;
|
|
24185
|
+
}
|
|
24186
|
+
if (elements.reloadSamplingParametersButton) {
|
|
24187
|
+
elements.reloadSamplingParametersButton.disabled = samplingParametersBusy || samplingParametersLoading || !activeTabId;
|
|
24188
|
+
}
|
|
24189
|
+
if (elements.samplingParametersStatus) {
|
|
24190
|
+
elements.samplingParametersStatus.textContent = samplingParametersStatusText({ dirty, unsupported, validation, loadedForActiveTab });
|
|
24191
|
+
elements.samplingParametersStatus.classList.toggle("error", showError);
|
|
24192
|
+
elements.samplingParametersStatus.classList.toggle("warning", !showError && unsupported);
|
|
24193
|
+
}
|
|
24194
|
+
}
|
|
24195
|
+
|
|
24196
|
+
function applySamplingParametersResponse(data, tabId) {
|
|
24197
|
+
const existingDraft = samplingParametersDraft(tabId);
|
|
24198
|
+
samplingParametersState = data || null;
|
|
24199
|
+
samplingParametersStateTabId = tabId;
|
|
24200
|
+
if (existingDraft) {
|
|
24201
|
+
const loadedDraft = samplingParametersBaseDraft(tabId);
|
|
24202
|
+
existingDraft.preservedUnknown = cloneSamplingControlDraft(loadedDraft)?.preservedUnknown || {};
|
|
24203
|
+
setSamplingParametersDraft(existingDraft, tabId);
|
|
24204
|
+
}
|
|
24205
|
+
if (!samplingParametersDraftIsDirty(tabId)) setSamplingParametersDraft(null, tabId);
|
|
24206
|
+
}
|
|
24207
|
+
|
|
24208
|
+
async function loadSamplingParameters({ tabId = activeTabId, force = false } = {}) {
|
|
24209
|
+
if (!tabId) {
|
|
24210
|
+
samplingParametersState = null;
|
|
24211
|
+
samplingParametersStateTabId = null;
|
|
24212
|
+
renderSamplingParameters();
|
|
24213
|
+
return;
|
|
24214
|
+
}
|
|
24215
|
+
// Structured drafts are stored separately from loaded state, so a background
|
|
24216
|
+
// refresh can update support/default/hidden-key context without discarding edits.
|
|
24217
|
+
if (force) setSamplingParametersDraft(null, tabId);
|
|
24218
|
+
const requestSerial = ++samplingParametersRequestSerial;
|
|
24219
|
+
samplingParametersLoading = true;
|
|
24220
|
+
setSamplingParametersFeedback();
|
|
24221
|
+
renderSamplingParameters();
|
|
24222
|
+
try {
|
|
24223
|
+
const response = await api(samplingParametersPath(tabId), { scoped: false });
|
|
24224
|
+
if (requestSerial !== samplingParametersRequestSerial || tabId !== activeTabId) return;
|
|
24225
|
+
applySamplingParametersResponse(response.data, tabId);
|
|
24226
|
+
} catch (error) {
|
|
24227
|
+
if (requestSerial !== samplingParametersRequestSerial || tabId !== activeTabId) return;
|
|
24228
|
+
setSamplingParametersFeedback({ error: `Could not load sampling parameters: ${error.message || String(error)}` });
|
|
24229
|
+
} finally {
|
|
24230
|
+
if (requestSerial === samplingParametersRequestSerial) {
|
|
24231
|
+
samplingParametersLoading = false;
|
|
24232
|
+
renderSamplingParameters();
|
|
24233
|
+
}
|
|
24234
|
+
}
|
|
24235
|
+
}
|
|
24236
|
+
|
|
24237
|
+
// Background refresh for tab and model changes. It stays quiet until the section has
|
|
24238
|
+
// been opened once, so collapsed panels never pay for helper round-trips.
|
|
24239
|
+
function refreshSamplingParametersForTabContext(tabContext = activeTabContext()) {
|
|
24240
|
+
if (!tabContext.tabId) return;
|
|
24241
|
+
if (!samplingParametersState && !samplingParametersSectionActive()) return;
|
|
24242
|
+
return loadSamplingParameters({ tabId: tabContext.tabId }).catch(() => {});
|
|
24243
|
+
}
|
|
24244
|
+
|
|
24245
|
+
async function writeSamplingParameters(samplingParams, { successNotice }) {
|
|
24246
|
+
const tabId = activeTabId;
|
|
24247
|
+
if (!tabId) return;
|
|
24248
|
+
const requestSerial = ++samplingParametersRequestSerial;
|
|
24249
|
+
samplingParametersBusy = true;
|
|
24250
|
+
setSamplingParametersFeedback();
|
|
24251
|
+
renderSamplingParameters();
|
|
24252
|
+
try {
|
|
24253
|
+
const response = await api(samplingParametersPath(tabId), { method: "PUT", body: samplingParams, scoped: false });
|
|
24254
|
+
setSamplingParametersDraft(null, tabId);
|
|
24255
|
+
if (requestSerial !== samplingParametersRequestSerial || tabId !== activeTabId) return;
|
|
24256
|
+
applySamplingParametersResponse(response.data, tabId);
|
|
24257
|
+
setSamplingParametersFeedback({ notice: successNotice });
|
|
24258
|
+
} catch (error) {
|
|
24259
|
+
if (requestSerial !== samplingParametersRequestSerial || tabId !== activeTabId) return;
|
|
24260
|
+
setSamplingParametersFeedback({ error: `Could not save sampling parameters: ${error.message || String(error)}` });
|
|
24261
|
+
} finally {
|
|
24262
|
+
// Writes are serialized by the busy guard. A tab/model refresh may supersede
|
|
24263
|
+
// the response serial, but it must never strand the section in a busy state.
|
|
24264
|
+
samplingParametersBusy = false;
|
|
24265
|
+
renderSamplingParameters();
|
|
24266
|
+
}
|
|
24267
|
+
}
|
|
24268
|
+
|
|
24269
|
+
async function applySamplingParameters() {
|
|
24270
|
+
if (!activeTabId || samplingParametersBusy) return;
|
|
24271
|
+
if (!samplingParametersState || samplingParametersStateTabId !== activeTabId) {
|
|
24272
|
+
setSamplingParametersFeedback({ error: "Wait for this tab's sampling parameters to load before applying changes." });
|
|
24273
|
+
renderSamplingParameters();
|
|
24274
|
+
return;
|
|
24275
|
+
}
|
|
24276
|
+
const capabilities = samplingParameterCapabilities(samplingParametersState);
|
|
24277
|
+
if (!Object.values(capabilities).some(({ supported }) => supported)) {
|
|
24278
|
+
setSamplingParametersFeedback({ error: "This model has no verified sampling parameters, so nothing was sent." });
|
|
24279
|
+
renderSamplingParameters();
|
|
24280
|
+
return;
|
|
24281
|
+
}
|
|
24282
|
+
const draft = samplingParametersEditableDraft();
|
|
24283
|
+
const validation = validateSamplingControlDraft(draft);
|
|
24284
|
+
if (!validation.valid) {
|
|
24285
|
+
setSamplingParametersFeedback({ error: Object.values(validation.errors)[0] || "Correct invalid sampling values before applying." });
|
|
24286
|
+
renderSamplingParameters();
|
|
24287
|
+
return;
|
|
24288
|
+
}
|
|
24289
|
+
const samplingParams = buildSamplingParametersFromDraft(draft);
|
|
24290
|
+
await writeSamplingParameters(samplingParams, {
|
|
24291
|
+
successNotice: Object.keys(samplingParams).length
|
|
24292
|
+
? "Applied to this Pi session · affects subsequent provider requests."
|
|
24293
|
+
: "Session override cleared · model defaults apply.",
|
|
24294
|
+
});
|
|
24295
|
+
}
|
|
24296
|
+
|
|
24297
|
+
async function resetSamplingParameters() {
|
|
24298
|
+
if (!activeTabId || samplingParametersBusy) return;
|
|
24299
|
+
if (!samplingParametersState || samplingParametersStateTabId !== activeTabId) {
|
|
24300
|
+
setSamplingParametersFeedback({ error: "Wait for this tab's sampling parameters to load before resetting them." });
|
|
24301
|
+
renderSamplingParameters();
|
|
24302
|
+
return;
|
|
24303
|
+
}
|
|
24304
|
+
await writeSamplingParameters({}, { successNotice: "Session override cleared · model defaults apply." });
|
|
24305
|
+
}
|
|
24306
|
+
|
|
24307
|
+
// Lazy loader for surfaces that reveal the section (side-panel expand/visibility,
|
|
24308
|
+
// mobile canonical mount) after the initial page load.
|
|
24309
|
+
function ensureSamplingParametersLoaded() {
|
|
24310
|
+
if (!activeTabId || samplingParametersLoading || samplingParametersBusy) return;
|
|
24311
|
+
if (samplingParametersState && samplingParametersStateTabId === activeTabId) return;
|
|
24312
|
+
loadSamplingParameters().catch(() => {});
|
|
24313
|
+
}
|
|
24314
|
+
|
|
24315
|
+
function initializeSamplingParameters() {
|
|
24316
|
+
initializeSamplingParameterControls();
|
|
24317
|
+
renderSamplingParameters();
|
|
24318
|
+
if (samplingParametersSectionActive()) ensureSamplingParametersLoaded();
|
|
24319
|
+
}
|
|
24320
|
+
|
|
23415
24321
|
function sessionCopyButton(label, value) {
|
|
23416
24322
|
const button = make("button", "session-copy-button", "Copy");
|
|
23417
24323
|
button.type = "button";
|
|
@@ -34435,6 +35341,7 @@ function clearChatTouchIntent() {
|
|
|
34435
35341
|
|
|
34436
35342
|
function isChatScrollAwayIntent(event) {
|
|
34437
35343
|
if (event?.type === "wheel") return event.deltaY < 0;
|
|
35344
|
+
if (event?.type === "middle-drag") return event.deltaY > 0;
|
|
34438
35345
|
if (event?.type === "touchmove") {
|
|
34439
35346
|
const clientY = Number(event?.touches?.[0]?.clientY);
|
|
34440
35347
|
const scrollAway = !Number.isFinite(clientY) || chatLastTouchClientY === null || clientY > chatLastTouchClientY;
|
|
@@ -34631,10 +35538,285 @@ function setOptionsMenuOpen(open) {
|
|
|
34631
35538
|
elements.optionsMenuButton.setAttribute("aria-expanded", optionsMenuOpen ? "true" : "false");
|
|
34632
35539
|
elements.optionsMenuButton.classList.toggle("menu-open", optionsMenuOpen);
|
|
34633
35540
|
elements.optionsMenuButton.parentElement?.classList.toggle("open", optionsMenuOpen);
|
|
35541
|
+
if (optionsMenuOpen) syncOptionsSubmenuAvailability();
|
|
35542
|
+
else closeOptionsSubmenus();
|
|
35543
|
+
if (optionsMenuOpen) scheduleOptionsMenuLabelFit();
|
|
34634
35544
|
scheduleMobileDropdownScrollBoundsUpdate();
|
|
34635
35545
|
if (!optionsMenuOpen) scheduleDeferredUiFlushAfterDropdownClose();
|
|
34636
35546
|
}
|
|
34637
35547
|
|
|
35548
|
+
function optionsSubmenuGroups() {
|
|
35549
|
+
if (!elements.optionsMenu) return [];
|
|
35550
|
+
return Array.from(elements.optionsMenu.querySelectorAll(OPTIONS_SUBMENU_GROUP_SELECTOR));
|
|
35551
|
+
}
|
|
35552
|
+
|
|
35553
|
+
function optionsSubmenuTrigger(group) {
|
|
35554
|
+
if (!group?.querySelector) return null;
|
|
35555
|
+
return group.querySelector(OPTIONS_SUBMENU_TRIGGER_SELECTOR) || group.querySelector('button[aria-haspopup="menu"]');
|
|
35556
|
+
}
|
|
35557
|
+
|
|
35558
|
+
function optionsSubmenuPanel(group) {
|
|
35559
|
+
if (!group?.querySelector) return null;
|
|
35560
|
+
const controlledId = optionsSubmenuTrigger(group)?.getAttribute("aria-controls");
|
|
35561
|
+
const controlled = controlledId ? document.getElementById(controlledId) : null;
|
|
35562
|
+
if (controlled) return controlled;
|
|
35563
|
+
return group.querySelector(OPTIONS_SUBMENU_PANEL_SELECTOR) || group.querySelector('[role="menu"]');
|
|
35564
|
+
}
|
|
35565
|
+
|
|
35566
|
+
function optionsSubmenuBackButton(group) {
|
|
35567
|
+
return optionsSubmenuPanel(group)?.querySelector(OPTIONS_SUBMENU_BACK_SELECTOR) || null;
|
|
35568
|
+
}
|
|
35569
|
+
|
|
35570
|
+
function isOptionsSubmenuPanelItem(item) {
|
|
35571
|
+
const panel = item?.closest?.(OPTIONS_SUBMENU_PANEL_SELECTOR);
|
|
35572
|
+
return !!panel && !!elements.optionsMenu?.contains(panel);
|
|
35573
|
+
}
|
|
35574
|
+
|
|
35575
|
+
function isVisibleOptionsMenuItem(item) {
|
|
35576
|
+
if (!item || item.hidden || item.disabled) return false;
|
|
35577
|
+
if (item.getAttribute?.("aria-hidden") === "true") return false;
|
|
35578
|
+
return !item.closest?.("[hidden]");
|
|
35579
|
+
}
|
|
35580
|
+
|
|
35581
|
+
function optionsSubmenuActionItems(group) {
|
|
35582
|
+
const panel = optionsSubmenuPanel(group);
|
|
35583
|
+
if (!panel) return [];
|
|
35584
|
+
const back = optionsSubmenuBackButton(group);
|
|
35585
|
+
return Array.from(panel.querySelectorAll('[role="menuitem"]')).filter((item) => item !== back);
|
|
35586
|
+
}
|
|
35587
|
+
|
|
35588
|
+
function optionsSubmenuHasVisibleActions(group) {
|
|
35589
|
+
return optionsSubmenuActionItems(group).some((item) => !item.hidden && !item.disabled && item.getAttribute("aria-hidden") !== "true");
|
|
35590
|
+
}
|
|
35591
|
+
|
|
35592
|
+
function optionsSubmenuItems(group) {
|
|
35593
|
+
const panel = optionsSubmenuPanel(group);
|
|
35594
|
+
if (!panel) return [];
|
|
35595
|
+
const back = optionsSubmenuBackButton(group);
|
|
35596
|
+
return Array.from(panel.querySelectorAll('[role="menuitem"]')).filter((item) => item !== back && !item.hidden && !item.disabled && item.getAttribute("aria-hidden") !== "true");
|
|
35597
|
+
}
|
|
35598
|
+
|
|
35599
|
+
function optionsMenuRootItems() {
|
|
35600
|
+
if (!elements.optionsMenu) return [];
|
|
35601
|
+
return Array.from(elements.optionsMenu.querySelectorAll('[role="menuitem"]'))
|
|
35602
|
+
.filter((item) => !isOptionsSubmenuPanelItem(item) && isVisibleOptionsMenuItem(item));
|
|
35603
|
+
}
|
|
35604
|
+
|
|
35605
|
+
function focusOptionsMenuItem(item) {
|
|
35606
|
+
item?.focus?.({ preventScroll: true });
|
|
35607
|
+
}
|
|
35608
|
+
|
|
35609
|
+
function optionsSubmenuUsesDrillIn() {
|
|
35610
|
+
if (isMobileView()) return true;
|
|
35611
|
+
return window.matchMedia?.(OPTIONS_SUBMENU_DRILL_IN_QUERY)?.matches === true;
|
|
35612
|
+
}
|
|
35613
|
+
|
|
35614
|
+
function syncOptionsSubmenuAvailability() {
|
|
35615
|
+
if (optionsSubmenuSyncing) return;
|
|
35616
|
+
optionsSubmenuSyncing = true;
|
|
35617
|
+
try {
|
|
35618
|
+
for (const group of optionsSubmenuGroups()) {
|
|
35619
|
+
const available = optionsSubmenuHasVisibleActions(group);
|
|
35620
|
+
const unavailable = !available;
|
|
35621
|
+
const trigger = optionsSubmenuTrigger(group);
|
|
35622
|
+
if (group.hidden !== unavailable) group.hidden = unavailable;
|
|
35623
|
+
if (trigger) {
|
|
35624
|
+
if (trigger.hidden !== unavailable) trigger.hidden = unavailable;
|
|
35625
|
+
if (trigger.disabled !== unavailable) trigger.disabled = unavailable;
|
|
35626
|
+
}
|
|
35627
|
+
if (!available && openOptionsSubmenuGroup === group) setOptionsSubmenuOpen(group, false);
|
|
35628
|
+
}
|
|
35629
|
+
} finally {
|
|
35630
|
+
optionsSubmenuSyncing = false;
|
|
35631
|
+
}
|
|
35632
|
+
}
|
|
35633
|
+
|
|
35634
|
+
function fitOptionsMenuLabels() {
|
|
35635
|
+
if (!elements.optionsMenu) return;
|
|
35636
|
+
const labels = elements.optionsMenu.querySelectorAll(OPTIONS_MENU_LABEL_SELECTOR);
|
|
35637
|
+
for (const label of labels) {
|
|
35638
|
+
label.style.removeProperty(OPTIONS_MENU_LABEL_FONT_SIZE_PROPERTY);
|
|
35639
|
+
label.removeAttribute("data-options-menu-label-fitted");
|
|
35640
|
+
const availableWidth = label.clientWidth;
|
|
35641
|
+
const requiredWidth = label.scrollWidth;
|
|
35642
|
+
if (availableWidth <= 0 || requiredWidth <= availableWidth + 0.5) continue;
|
|
35643
|
+
const baseFontSize = Number.parseFloat(window.getComputedStyle(label).fontSize);
|
|
35644
|
+
if (!Number.isFinite(baseFontSize) || baseFontSize <= 0) continue;
|
|
35645
|
+
const fittedFontSize = Math.max(
|
|
35646
|
+
OPTIONS_MENU_LABEL_MIN_FONT_SIZE_PX,
|
|
35647
|
+
Math.floor(baseFontSize * (availableWidth / requiredWidth) * 98) / 100,
|
|
35648
|
+
);
|
|
35649
|
+
if (fittedFontSize >= baseFontSize) continue;
|
|
35650
|
+
label.style.setProperty(OPTIONS_MENU_LABEL_FONT_SIZE_PROPERTY, `${fittedFontSize}px`);
|
|
35651
|
+
label.setAttribute("data-options-menu-label-fitted", "");
|
|
35652
|
+
}
|
|
35653
|
+
}
|
|
35654
|
+
|
|
35655
|
+
function scheduleOptionsMenuLabelFit() {
|
|
35656
|
+
if (!elements.optionsMenu) return;
|
|
35657
|
+
if (optionsMenuLabelFitFrame) window.cancelAnimationFrame(optionsMenuLabelFitFrame);
|
|
35658
|
+
optionsMenuLabelFitFrame = window.requestAnimationFrame(() => {
|
|
35659
|
+
optionsMenuLabelFitFrame = 0;
|
|
35660
|
+
fitOptionsMenuLabels();
|
|
35661
|
+
});
|
|
35662
|
+
}
|
|
35663
|
+
|
|
35664
|
+
function updateOptionsSubmenuPlacement(group) {
|
|
35665
|
+
const panel = optionsSubmenuPanel(group);
|
|
35666
|
+
if (!group || !panel) return;
|
|
35667
|
+
if (optionsSubmenuUsesDrillIn()) {
|
|
35668
|
+
group.classList.remove(OPTIONS_SUBMENU_LEFT_CLASS);
|
|
35669
|
+
panel.classList.remove(OPTIONS_SUBMENU_LEFT_CLASS);
|
|
35670
|
+
return;
|
|
35671
|
+
}
|
|
35672
|
+
const anchorRect = (optionsSubmenuTrigger(group) || group).getBoundingClientRect?.();
|
|
35673
|
+
if (!anchorRect) return;
|
|
35674
|
+
const viewportWidth = window.innerWidth || document.documentElement.clientWidth || 0;
|
|
35675
|
+
const panelWidth = panel.offsetWidth || panel.getBoundingClientRect?.().width || 0;
|
|
35676
|
+
const spaceRight = viewportWidth - anchorRect.right;
|
|
35677
|
+
const flipLeft = panelWidth > 0 && spaceRight < panelWidth && anchorRect.left > spaceRight;
|
|
35678
|
+
group.classList.toggle(OPTIONS_SUBMENU_LEFT_CLASS, flipLeft);
|
|
35679
|
+
panel.classList.toggle(OPTIONS_SUBMENU_LEFT_CLASS, flipLeft);
|
|
35680
|
+
}
|
|
35681
|
+
|
|
35682
|
+
function setOptionsSubmenuOpen(group, open, { focusFirstItem = false, restoreFocus = false } = {}) {
|
|
35683
|
+
if (!group) return;
|
|
35684
|
+
const trigger = optionsSubmenuTrigger(group);
|
|
35685
|
+
const panel = optionsSubmenuPanel(group);
|
|
35686
|
+
const shouldOpen = !!open && !trigger?.disabled && !trigger?.hidden && !group.hidden;
|
|
35687
|
+
if (shouldOpen) {
|
|
35688
|
+
for (const sibling of optionsSubmenuGroups()) {
|
|
35689
|
+
if (sibling !== group) setOptionsSubmenuOpen(sibling, false);
|
|
35690
|
+
}
|
|
35691
|
+
}
|
|
35692
|
+
if (shouldOpen) openOptionsSubmenuGroup = group;
|
|
35693
|
+
else if (openOptionsSubmenuGroup === group) openOptionsSubmenuGroup = null;
|
|
35694
|
+
group.classList.toggle("open", shouldOpen);
|
|
35695
|
+
trigger?.setAttribute("aria-expanded", shouldOpen ? "true" : "false");
|
|
35696
|
+
trigger?.classList.toggle("menu-open", shouldOpen);
|
|
35697
|
+
if (panel) panel.hidden = !shouldOpen;
|
|
35698
|
+
if (elements.optionsMenu) {
|
|
35699
|
+
elements.optionsMenu.classList.toggle("submenu-open", !!openOptionsSubmenuGroup);
|
|
35700
|
+
const openGroupId = openOptionsSubmenuGroup?.dataset?.optionsSubmenu || "";
|
|
35701
|
+
if (openGroupId) elements.optionsMenu.dataset.openGroup = openGroupId;
|
|
35702
|
+
else delete elements.optionsMenu.dataset.openGroup;
|
|
35703
|
+
}
|
|
35704
|
+
if (shouldOpen) updateOptionsSubmenuPlacement(group);
|
|
35705
|
+
else {
|
|
35706
|
+
group.classList.remove(OPTIONS_SUBMENU_LEFT_CLASS);
|
|
35707
|
+
panel?.classList.remove(OPTIONS_SUBMENU_LEFT_CLASS);
|
|
35708
|
+
}
|
|
35709
|
+
if (shouldOpen && focusFirstItem) focusOptionsMenuItem(optionsSubmenuItems(group)[0]);
|
|
35710
|
+
if (!shouldOpen && restoreFocus) focusOptionsMenuItem(trigger);
|
|
35711
|
+
if (shouldOpen) scheduleOptionsMenuLabelFit();
|
|
35712
|
+
scheduleMobileDropdownScrollBoundsUpdate();
|
|
35713
|
+
}
|
|
35714
|
+
|
|
35715
|
+
function closeOptionsSubmenus({ restoreFocus = false } = {}) {
|
|
35716
|
+
const previous = openOptionsSubmenuGroup;
|
|
35717
|
+
for (const group of optionsSubmenuGroups()) setOptionsSubmenuOpen(group, false);
|
|
35718
|
+
openOptionsSubmenuGroup = null;
|
|
35719
|
+
if (restoreFocus && previous) focusOptionsMenuItem(optionsSubmenuTrigger(previous));
|
|
35720
|
+
}
|
|
35721
|
+
|
|
35722
|
+
function moveOptionsMenuFocus(items, currentIndex, offset) {
|
|
35723
|
+
if (!items.length) return;
|
|
35724
|
+
const nextIndex = currentIndex < 0
|
|
35725
|
+
? (offset > 0 ? 0 : items.length - 1)
|
|
35726
|
+
: (currentIndex + offset + items.length) % items.length;
|
|
35727
|
+
focusOptionsMenuItem(items[nextIndex]);
|
|
35728
|
+
}
|
|
35729
|
+
|
|
35730
|
+
function handleOptionsMenuKeydown(event) {
|
|
35731
|
+
const target = event.target;
|
|
35732
|
+
if (!target?.closest || !elements.optionsMenu?.contains(target)) return;
|
|
35733
|
+
const panelGroup = isOptionsSubmenuPanelItem(target) ? target.closest(OPTIONS_SUBMENU_GROUP_SELECTOR) : null;
|
|
35734
|
+
const items = panelGroup ? optionsSubmenuItems(panelGroup) : optionsMenuRootItems();
|
|
35735
|
+
const index = items.indexOf(target);
|
|
35736
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
35737
|
+
event.preventDefault();
|
|
35738
|
+
moveOptionsMenuFocus(items, index, event.key === "ArrowDown" ? 1 : -1);
|
|
35739
|
+
return;
|
|
35740
|
+
}
|
|
35741
|
+
if (event.key === "Home" || event.key === "End") {
|
|
35742
|
+
event.preventDefault();
|
|
35743
|
+
focusOptionsMenuItem(event.key === "Home" ? items[0] : items[items.length - 1]);
|
|
35744
|
+
return;
|
|
35745
|
+
}
|
|
35746
|
+
if (event.key === "ArrowRight") {
|
|
35747
|
+
const group = panelGroup ? null : target.closest(OPTIONS_SUBMENU_GROUP_SELECTOR);
|
|
35748
|
+
if (group && optionsSubmenuTrigger(group) === target) {
|
|
35749
|
+
event.preventDefault();
|
|
35750
|
+
setOptionsSubmenuOpen(group, true, { focusFirstItem: true });
|
|
35751
|
+
}
|
|
35752
|
+
return;
|
|
35753
|
+
}
|
|
35754
|
+
if (event.key === "ArrowLeft") {
|
|
35755
|
+
if (!panelGroup) return;
|
|
35756
|
+
event.preventDefault();
|
|
35757
|
+
setOptionsSubmenuOpen(panelGroup, false, { restoreFocus: true });
|
|
35758
|
+
return;
|
|
35759
|
+
}
|
|
35760
|
+
if (event.key !== "Escape") return;
|
|
35761
|
+
if (panelGroup || openOptionsSubmenuGroup) {
|
|
35762
|
+
// Escape closes only the deepest open level; the root menu stays open.
|
|
35763
|
+
event.preventDefault();
|
|
35764
|
+
event.stopPropagation();
|
|
35765
|
+
if (panelGroup) setOptionsSubmenuOpen(panelGroup, false, { restoreFocus: true });
|
|
35766
|
+
else closeOptionsSubmenus({ restoreFocus: true });
|
|
35767
|
+
return;
|
|
35768
|
+
}
|
|
35769
|
+
closeOptionsSubmenus();
|
|
35770
|
+
focusOptionsMenuItem(elements.optionsMenuButton);
|
|
35771
|
+
}
|
|
35772
|
+
|
|
35773
|
+
function handleOptionsSubmenuClick(event) {
|
|
35774
|
+
const back = event.target?.closest?.(OPTIONS_SUBMENU_BACK_SELECTOR);
|
|
35775
|
+
if (back && elements.optionsMenu?.contains(back)) {
|
|
35776
|
+
event.preventDefault();
|
|
35777
|
+
event.stopPropagation();
|
|
35778
|
+
setOptionsSubmenuOpen(back.closest(OPTIONS_SUBMENU_GROUP_SELECTOR), false, { restoreFocus: true });
|
|
35779
|
+
return;
|
|
35780
|
+
}
|
|
35781
|
+
const trigger = event.target?.closest?.(OPTIONS_SUBMENU_TRIGGER_SELECTOR);
|
|
35782
|
+
if (!trigger || !elements.optionsMenu?.contains(trigger)) return;
|
|
35783
|
+
event.preventDefault();
|
|
35784
|
+
event.stopPropagation();
|
|
35785
|
+
const group = trigger.closest(OPTIONS_SUBMENU_GROUP_SELECTOR);
|
|
35786
|
+
const shouldOpen = openOptionsSubmenuGroup !== group;
|
|
35787
|
+
setOptionsSubmenuOpen(group, shouldOpen, { focusFirstItem: shouldOpen });
|
|
35788
|
+
}
|
|
35789
|
+
|
|
35790
|
+
function initializeOptionsSubmenus() {
|
|
35791
|
+
const groups = optionsSubmenuGroups();
|
|
35792
|
+
if (!elements.optionsMenu || !groups.length) return;
|
|
35793
|
+
for (const group of groups) {
|
|
35794
|
+
group.addEventListener("pointerenter", (event) => {
|
|
35795
|
+
if (event.pointerType === "touch" || optionsSubmenuUsesDrillIn()) return;
|
|
35796
|
+
setOptionsSubmenuOpen(group, true);
|
|
35797
|
+
});
|
|
35798
|
+
group.addEventListener("pointerleave", (event) => {
|
|
35799
|
+
if (event.pointerType === "touch" || optionsSubmenuUsesDrillIn()) return;
|
|
35800
|
+
if (group.contains(document.activeElement)) return;
|
|
35801
|
+
setOptionsSubmenuOpen(group, false);
|
|
35802
|
+
});
|
|
35803
|
+
}
|
|
35804
|
+
const rootMenuContainer = elements.optionsMenu.parentElement;
|
|
35805
|
+
rootMenuContainer?.addEventListener("pointerenter", scheduleOptionsMenuLabelFit);
|
|
35806
|
+
rootMenuContainer?.addEventListener("focusin", scheduleOptionsMenuLabelFit);
|
|
35807
|
+
elements.optionsMenu.addEventListener("click", handleOptionsSubmenuClick);
|
|
35808
|
+
elements.optionsMenu.addEventListener("keydown", handleOptionsMenuKeydown);
|
|
35809
|
+
optionsSubmenuObserver?.disconnect();
|
|
35810
|
+
optionsSubmenuObserver = new MutationObserver(() => syncOptionsSubmenuAvailability());
|
|
35811
|
+
optionsSubmenuObserver.observe(elements.optionsMenu, { subtree: true, attributes: true, attributeFilter: ["hidden", "disabled", "aria-hidden"] });
|
|
35812
|
+
window.addEventListener("resize", () => {
|
|
35813
|
+
if (openOptionsSubmenuGroup) updateOptionsSubmenuPlacement(openOptionsSubmenuGroup);
|
|
35814
|
+
scheduleOptionsMenuLabelFit();
|
|
35815
|
+
});
|
|
35816
|
+
closeOptionsSubmenus();
|
|
35817
|
+
syncOptionsSubmenuAvailability();
|
|
35818
|
+
}
|
|
35819
|
+
|
|
34638
35820
|
function optionalFeatureIdForCommand(name) {
|
|
34639
35821
|
const baseName = commandBaseName(name);
|
|
34640
35822
|
if (OPTIONAL_COMMAND_FEATURES.has(baseName)) return OPTIONAL_COMMAND_FEATURES.get(baseName);
|
|
@@ -34979,8 +36161,10 @@ function applyOptionalFeatureProgressStates(snapshot) {
|
|
|
34979
36161
|
}
|
|
34980
36162
|
if (progress.restartDeferred === true) {
|
|
34981
36163
|
optionalFeatureRestartNotice = { autoRestarted: false, restartDeferred: true, tabId: activeTabId };
|
|
34982
|
-
} else if (progress.autoRestarted === true) {
|
|
36164
|
+
} else if (progress.autoRestarted === true && !optionalFeatureMigrationCompletionIsDismissed(snapshot)) {
|
|
34983
36165
|
optionalFeatureRestartNotice = { autoRestarted: true, restartDeferred: false, tabId: activeTabId };
|
|
36166
|
+
} else if (optionalFeatureMigrationCompletionIsDismissed(snapshot)) {
|
|
36167
|
+
optionalFeatureRestartNotice = null;
|
|
34984
36168
|
}
|
|
34985
36169
|
optionalFeatureBatchState = {
|
|
34986
36170
|
phase: progress.phase === "migrating" ? "running" : progress.phase === "partial" ? "failed" : "done",
|
|
@@ -35027,6 +36211,54 @@ function optionalFeatureReadyDismissKey(snapshot = optionalFeatureMigrationSnaps
|
|
|
35027
36211
|
return snapshot.phase === "ready" ? String(snapshot.revision || "pending") : "";
|
|
35028
36212
|
}
|
|
35029
36213
|
|
|
36214
|
+
function optionalFeatureMigrationCompletionKey(snapshot = optionalFeatureMigrationSnapshot) {
|
|
36215
|
+
if (snapshot.phase !== "complete") return "";
|
|
36216
|
+
const completedAt = String(snapshot.progress?.completedAt || snapshot.completedAt || "");
|
|
36217
|
+
return completedAt ? `${snapshot.revision || "pending"}:${completedAt}` : "";
|
|
36218
|
+
}
|
|
36219
|
+
|
|
36220
|
+
function optionalFeatureMigrationNoticeDismissKey(snapshot = optionalFeatureMigrationSnapshot) {
|
|
36221
|
+
if (snapshot.phase !== "degraded") return "";
|
|
36222
|
+
return JSON.stringify([snapshot.revision || "pending", snapshot.diagnostic?.message || ""]);
|
|
36223
|
+
}
|
|
36224
|
+
|
|
36225
|
+
function storedDismissedOptionalFeatureMigrationKey() {
|
|
36226
|
+
try {
|
|
36227
|
+
return localStorage.getItem(OPTIONAL_FEATURE_MIGRATION_DISMISS_STORAGE_KEY) || "";
|
|
36228
|
+
} catch {
|
|
36229
|
+
return "";
|
|
36230
|
+
}
|
|
36231
|
+
}
|
|
36232
|
+
|
|
36233
|
+
function optionalFeatureMigrationCompletionIsDismissed(snapshot = optionalFeatureMigrationSnapshot) {
|
|
36234
|
+
const key = optionalFeatureMigrationCompletionKey(snapshot);
|
|
36235
|
+
return Boolean(key && (optionalFeatureMigrationDismissedCompletionKey === key || storedDismissedOptionalFeatureMigrationKey() === key));
|
|
36236
|
+
}
|
|
36237
|
+
|
|
36238
|
+
function rememberDismissedOptionalFeatureMigration(key) {
|
|
36239
|
+
if (!key) return;
|
|
36240
|
+
optionalFeatureMigrationDismissedCompletionKey = key;
|
|
36241
|
+
try {
|
|
36242
|
+
localStorage.setItem(OPTIONAL_FEATURE_MIGRATION_DISMISS_STORAGE_KEY, key);
|
|
36243
|
+
} catch {
|
|
36244
|
+
// Keep the dismissal page-local when browser storage is unavailable.
|
|
36245
|
+
}
|
|
36246
|
+
}
|
|
36247
|
+
|
|
36248
|
+
function dismissOptionalFeatureMigrationCompletion() {
|
|
36249
|
+
rememberDismissedOptionalFeatureMigration(optionalFeatureMigrationCompletionKey());
|
|
36250
|
+
optionalFeatureRestartNotice = null;
|
|
36251
|
+
renderOptionalFeatureMigrationSurface();
|
|
36252
|
+
}
|
|
36253
|
+
|
|
36254
|
+
function dismissOptionalFeatureMigrationNotice() {
|
|
36255
|
+
const key = optionalFeatureMigrationNoticeDismissKey();
|
|
36256
|
+
if (!key) return;
|
|
36257
|
+
optionalFeatureMigrationDismissedNoticeKey = key;
|
|
36258
|
+
clearOptionalFeatureReadyDismissTimer();
|
|
36259
|
+
renderOptionalFeatureMigrationSurface();
|
|
36260
|
+
}
|
|
36261
|
+
|
|
35030
36262
|
function scheduleOptionalFeatureReadyDismiss(key) {
|
|
35031
36263
|
if (!key) {
|
|
35032
36264
|
clearOptionalFeatureReadyDismissTimer();
|
|
@@ -35102,13 +36334,28 @@ function renderOptionalFeatureMigrationSurface() {
|
|
|
35102
36334
|
const conflicts = (snapshot.features || []).filter((feature) => feature.state === "conflict");
|
|
35103
36335
|
const progress = snapshot.progress;
|
|
35104
36336
|
const readyDismissKey = optionalFeatureReadyDismissKey(snapshot);
|
|
36337
|
+
const noticeDismissKey = optionalFeatureMigrationNoticeDismissKey(snapshot);
|
|
35105
36338
|
const readyCanAutoDismiss = Boolean(readyDismissKey && !optionalFeatureRestartNotice);
|
|
36339
|
+
if (optionalFeatureMigrationCompletionIsDismissed(snapshot)) {
|
|
36340
|
+
clearOptionalFeatureReadyDismissTimer();
|
|
36341
|
+
optionalFeatureRestartNotice = null;
|
|
36342
|
+
surface.replaceChildren();
|
|
36343
|
+
surface.hidden = true;
|
|
36344
|
+
ensureOptionalFeatureMigrationRenderTimer();
|
|
36345
|
+
return;
|
|
36346
|
+
}
|
|
35106
36347
|
if (readyCanAutoDismiss && optionalFeatureMigrationDismissedReadyKey === readyDismissKey) {
|
|
35107
36348
|
surface.replaceChildren();
|
|
35108
36349
|
surface.hidden = true;
|
|
35109
36350
|
ensureOptionalFeatureMigrationRenderTimer();
|
|
35110
36351
|
return;
|
|
35111
36352
|
}
|
|
36353
|
+
if (noticeDismissKey && optionalFeatureMigrationDismissedNoticeKey === noticeDismissKey) {
|
|
36354
|
+
surface.replaceChildren();
|
|
36355
|
+
surface.hidden = true;
|
|
36356
|
+
ensureOptionalFeatureMigrationRenderTimer();
|
|
36357
|
+
return;
|
|
36358
|
+
}
|
|
35112
36359
|
const card = make("div", `optional-feature-migration-card phase-${snapshot.phase}`);
|
|
35113
36360
|
const copy = make("div", "optional-feature-migration-copy");
|
|
35114
36361
|
const title = make("strong", "optional-feature-migration-title");
|
|
@@ -35135,6 +36382,7 @@ function renderOptionalFeatureMigrationSurface() {
|
|
|
35135
36382
|
} else if (snapshot.phase === "complete") {
|
|
35136
36383
|
title.textContent = "Optional feature migration complete";
|
|
35137
36384
|
detail.textContent = optionalFeatureMigrationProgressText(progress) || `${summary.ready || 0} optional features ready`;
|
|
36385
|
+
if (!optionalFeatureRestartNotice) actions.append(optionalFeatureMigrationAction("Dismiss", dismissOptionalFeatureMigrationCompletion));
|
|
35138
36386
|
} else if (snapshot.phase === "action-required") {
|
|
35139
36387
|
title.textContent = conflicts.length ? "Optional feature conflicts were safely excluded" : "Previous optional features need migration";
|
|
35140
36388
|
detail.textContent = conflicts.length
|
|
@@ -35156,6 +36404,12 @@ function renderOptionalFeatureMigrationSurface() {
|
|
|
35156
36404
|
copy.append(title, detail);
|
|
35157
36405
|
card.append(copy);
|
|
35158
36406
|
if (actions.childElementCount) card.append(actions);
|
|
36407
|
+
if (noticeDismissKey) {
|
|
36408
|
+
const dismissButton = optionalFeatureMigrationAction("×", dismissOptionalFeatureMigrationNotice, "optional-feature-migration-dismiss");
|
|
36409
|
+
dismissButton.setAttribute("aria-label", "Close optional feature startup notice");
|
|
36410
|
+
dismissButton.title = "Close";
|
|
36411
|
+
card.append(dismissButton);
|
|
36412
|
+
}
|
|
35159
36413
|
|
|
35160
36414
|
if (conflicts.length) {
|
|
35161
36415
|
const alert = make("div", "optional-feature-migration-alert sr-only", "Optional feature conflict detected; duplicate top-level resources were safely excluded.");
|
|
@@ -35179,10 +36433,7 @@ function renderOptionalFeatureMigrationSurface() {
|
|
|
35179
36433
|
if (optionalFeatureRestartNotice.restartDeferred) {
|
|
35180
36434
|
notice.append(optionalFeatureMigrationAction("Restart tab", () => restartOptionalFeatureTab(), "primary"));
|
|
35181
36435
|
} else {
|
|
35182
|
-
notice.append(optionalFeatureMigrationAction("Dismiss",
|
|
35183
|
-
optionalFeatureRestartNotice = null;
|
|
35184
|
-
renderOptionalFeatureMigrationSurface();
|
|
35185
|
-
}));
|
|
36436
|
+
notice.append(optionalFeatureMigrationAction("Dismiss", dismissOptionalFeatureMigrationCompletion));
|
|
35186
36437
|
}
|
|
35187
36438
|
card.append(notice);
|
|
35188
36439
|
}
|
|
@@ -37229,9 +38480,9 @@ const SAFETY_GUARD_CATEGORY_LABELS = Object.freeze({
|
|
|
37229
38480
|
async function openNativeSafetyGuardSetupDialog() {
|
|
37230
38481
|
openNativeCommandDialog({
|
|
37231
38482
|
title: "/safety-guard-setup",
|
|
37232
|
-
message: "Configure persistent command categories, protected-path checks,
|
|
38483
|
+
message: "Configure persistent command categories, protected-path checks, preview context, and optional model auto-review.",
|
|
37233
38484
|
});
|
|
37234
|
-
renderNativeLoading("Loading safety guard setup…");
|
|
38485
|
+
renderNativeLoading("Loading safety guard setup and authenticated models…");
|
|
37235
38486
|
|
|
37236
38487
|
let data;
|
|
37237
38488
|
try {
|
|
@@ -37245,6 +38496,7 @@ async function openNativeSafetyGuardSetupDialog() {
|
|
|
37245
38496
|
|
|
37246
38497
|
const config = data.config || {};
|
|
37247
38498
|
const defaults = data.defaults || {};
|
|
38499
|
+
const models = Array.isArray(data.models) ? data.models : [];
|
|
37248
38500
|
const categories = Array.isArray(data.categories) && data.categories.length
|
|
37249
38501
|
? data.categories
|
|
37250
38502
|
: Object.keys(SAFETY_GUARD_CATEGORY_LABELS);
|
|
@@ -37254,6 +38506,17 @@ async function openNativeSafetyGuardSetupDialog() {
|
|
|
37254
38506
|
{ length: Math.max(1, maximumContext - minimumContext + 1) },
|
|
37255
38507
|
(_, index) => String(index + minimumContext),
|
|
37256
38508
|
);
|
|
38509
|
+
const modelKey = (model) => model?.provider && model?.id ? `${model.provider}/${model.id}` : "";
|
|
38510
|
+
const configuredModelKey = config.autoReview?.model?.provider && config.autoReview?.model?.modelId
|
|
38511
|
+
? `${config.autoReview.model.provider}/${config.autoReview.model.modelId}`
|
|
38512
|
+
: "";
|
|
38513
|
+
const modelOptions = [
|
|
38514
|
+
{ value: "", label: models.length ? "Select an authenticated model" : "No authenticated models available" },
|
|
38515
|
+
...models.map((model) => ({
|
|
38516
|
+
value: modelKey(model),
|
|
38517
|
+
label: `${modelKey(model)}${model.name && model.name !== model.id ? ` · ${model.name}` : ""}`,
|
|
38518
|
+
})),
|
|
38519
|
+
];
|
|
37257
38520
|
const categoryControls = Object.fromEntries(categories.map((category) => [
|
|
37258
38521
|
category,
|
|
37259
38522
|
nativeSettingToggle(
|
|
@@ -37265,38 +38528,105 @@ async function openNativeSafetyGuardSetupDialog() {
|
|
|
37265
38528
|
]));
|
|
37266
38529
|
const controls = {
|
|
37267
38530
|
enabled: nativeSettingToggle("Safety guard enabled", config.enabled !== false, "Master switch for command and protected-path guards.", { label: "global", tone: "safety" }),
|
|
38531
|
+
autoReview: nativeSettingToggle("Automatic model review", config.autoReview?.enabled === true, "Off by default. When enabled, matched operations wait for this model's allow/block verdict; failures return to the existing prompt.", { label: "opt-in", tone: "safety" }),
|
|
38532
|
+
autoReviewModel: nativeSettingSelect("Review model", configuredModelKey, modelOptions, "Authenticated provider/model used only for safety preflight. There is no provider fallback.", { label: "required when on", tone: "safety" }),
|
|
38533
|
+
autoReviewThinking: nativeSettingSelect("Review thinking", config.autoReview?.model?.thinkingLevel || "off", data.thinkingLevels || SETTINGS_THINKING_OPTIONS, "Only levels supported by the selected model are offered.", { label: "required when on", tone: "safety" }),
|
|
37268
38534
|
before: nativeSettingSelect("Lines before a match", config.contextLines?.before ?? 3, contextOptions, "Number of command lines shown before each matched line.", { label: "preview", tone: "browser" }),
|
|
37269
38535
|
after: nativeSettingSelect("Lines after a match", config.contextLines?.after ?? 3, contextOptions, "Number of command lines shown after each matched line.", { label: "preview", tone: "browser" }),
|
|
37270
38536
|
protectedWrite: nativeSettingToggle("Guard protected-path writes", config.protectedPaths?.write !== false, "Prompt before write calls target credentials, private keys, or environment files.", { label: "write", tone: "safety" }),
|
|
37271
38537
|
protectedEdit: nativeSettingToggle("Guard protected-path edits", config.protectedPaths?.edit !== false, "Prompt before edit calls target credentials, private keys, or environment files.", { label: "edit", tone: "safety" }),
|
|
37272
38538
|
};
|
|
37273
|
-
|
|
37274
|
-
|
|
37275
|
-
|
|
37276
|
-
|
|
37277
|
-
|
|
37278
|
-
|
|
37279
|
-
|
|
37280
|
-
|
|
37281
|
-
|
|
37282
|
-
|
|
37283
|
-
|
|
37284
|
-
|
|
37285
|
-
|
|
37286
|
-
|
|
38539
|
+
controls.autoReviewModel.select.options[0].disabled = true;
|
|
38540
|
+
if (configuredModelKey && !models.some((model) => modelKey(model) === configuredModelKey)) {
|
|
38541
|
+
const unavailable = make("option", undefined, `Unavailable: ${configuredModelKey}`);
|
|
38542
|
+
unavailable.value = configuredModelKey;
|
|
38543
|
+
unavailable.disabled = true;
|
|
38544
|
+
controls.autoReviewModel.select.append(unavailable);
|
|
38545
|
+
controls.autoReviewModel.select.value = configuredModelKey;
|
|
38546
|
+
}
|
|
38547
|
+
|
|
38548
|
+
const autoReviewAvailability = nativeSettingsNote("Auto-review availability", "");
|
|
38549
|
+
const autoReviewAvailabilityText = autoReviewAvailability.querySelector("span");
|
|
38550
|
+
const thinkingLevelsForModel = (selectedModelKey) => {
|
|
38551
|
+
const levels = data.modelThinkingLevels?.[selectedModelKey];
|
|
38552
|
+
return Array.isArray(levels) && levels.length ? levels : [];
|
|
38553
|
+
};
|
|
38554
|
+
const syncAutoReviewControls = ({ preferredThinking, preserveUnavailable = false } = {}) => {
|
|
38555
|
+
const enabled = controls.autoReview.input.checked;
|
|
38556
|
+
const selectedModelKey = controls.autoReviewModel.select.value;
|
|
38557
|
+
const selectedAvailable = models.some((model) => modelKey(model) === selectedModelKey);
|
|
38558
|
+
const levels = thinkingLevelsForModel(selectedModelKey);
|
|
38559
|
+
const preferred = preferredThinking ?? controls.autoReviewThinking.select.value ?? "off";
|
|
38560
|
+
replaceNativeSettingSelectOptions(controls.autoReviewThinking.select, levels.length ? levels : ["off"], preferred);
|
|
38561
|
+
if (preserveUnavailable && preferred && !levels.includes(preferred) && preferred !== "off") {
|
|
38562
|
+
const unavailable = make("option", undefined, `Unavailable: ${preferred}`);
|
|
38563
|
+
unavailable.value = preferred;
|
|
38564
|
+
unavailable.disabled = true;
|
|
38565
|
+
controls.autoReviewThinking.select.append(unavailable);
|
|
38566
|
+
controls.autoReviewThinking.select.value = preferred;
|
|
38567
|
+
}
|
|
38568
|
+
controls.autoReviewModel.select.disabled = !models.length;
|
|
38569
|
+
controls.autoReviewThinking.select.disabled = !selectedAvailable;
|
|
38570
|
+
autoReviewAvailability.classList.toggle("warning", enabled && (!selectedAvailable || !levels.includes(controls.autoReviewThinking.select.value)));
|
|
38571
|
+
autoReviewAvailabilityText.textContent = !enabled
|
|
38572
|
+
? "Off. Matched operations use the existing interactive prompt; model and thinking can still be preselected before enabling auto-review."
|
|
38573
|
+
: !models.length
|
|
38574
|
+
? "Unavailable: no authenticated Pi models are available. Run /login or configure a provider before enabling auto-review."
|
|
38575
|
+
: !selectedAvailable
|
|
38576
|
+
? "Unavailable: select one of the authenticated models from this active tab."
|
|
38577
|
+
: `Ready: ${selectedModelKey} supports ${levels.join(", ")} thinking.`;
|
|
38578
|
+
};
|
|
38579
|
+
controls.autoReview.input.addEventListener("change", () => syncAutoReviewControls());
|
|
38580
|
+
controls.autoReviewModel.select.addEventListener("change", () => syncAutoReviewControls({ preferredThinking: "off" }));
|
|
38581
|
+
syncAutoReviewControls({ preferredThinking: config.autoReview?.model?.thinkingLevel || "off", preserveUnavailable: true });
|
|
38582
|
+
|
|
38583
|
+
const collectConfig = () => {
|
|
38584
|
+
const selectedModelKey = controls.autoReviewModel.select.value;
|
|
38585
|
+
const selectedModel = models.find((model) => modelKey(model) === selectedModelKey);
|
|
38586
|
+
const persistedModel = selectedModelKey === configuredModelKey ? config.autoReview?.model : null;
|
|
38587
|
+
return {
|
|
38588
|
+
version: data.version || 1,
|
|
38589
|
+
enabled: controls.enabled.input.checked,
|
|
38590
|
+
categories: Object.fromEntries(categories.map((category) => [category, categoryControls[category].input.checked])),
|
|
38591
|
+
protectedPaths: {
|
|
38592
|
+
write: controls.protectedWrite.input.checked,
|
|
38593
|
+
edit: controls.protectedEdit.input.checked,
|
|
38594
|
+
},
|
|
38595
|
+
contextLines: {
|
|
38596
|
+
before: Number.parseInt(controls.before.select.value, 10),
|
|
38597
|
+
after: Number.parseInt(controls.after.select.value, 10),
|
|
38598
|
+
},
|
|
38599
|
+
autoReview: {
|
|
38600
|
+
enabled: controls.autoReview.input.checked,
|
|
38601
|
+
model: {
|
|
38602
|
+
provider: selectedModel?.provider || persistedModel?.provider || "",
|
|
38603
|
+
modelId: selectedModel?.id || persistedModel?.modelId || "",
|
|
38604
|
+
thinkingLevel: controls.autoReviewThinking.select.value || "off",
|
|
38605
|
+
},
|
|
38606
|
+
},
|
|
38607
|
+
};
|
|
38608
|
+
};
|
|
37287
38609
|
const applyConfig = (value) => {
|
|
37288
38610
|
controls.enabled.input.checked = value?.enabled !== false;
|
|
37289
38611
|
controls.before.select.value = String(value?.contextLines?.before ?? 3);
|
|
37290
38612
|
controls.after.select.value = String(value?.contextLines?.after ?? 3);
|
|
37291
38613
|
controls.protectedWrite.input.checked = value?.protectedPaths?.write !== false;
|
|
37292
38614
|
controls.protectedEdit.input.checked = value?.protectedPaths?.edit !== false;
|
|
38615
|
+
controls.autoReview.input.checked = value?.autoReview?.enabled === true;
|
|
38616
|
+
const nextModelKey = value?.autoReview?.model?.provider && value?.autoReview?.model?.modelId
|
|
38617
|
+
? `${value.autoReview.model.provider}/${value.autoReview.model.modelId}`
|
|
38618
|
+
: "";
|
|
38619
|
+
controls.autoReviewModel.select.value = [...controls.autoReviewModel.select.options].some((option) => option.value === nextModelKey) ? nextModelKey : "";
|
|
37293
38620
|
for (const category of categories) categoryControls[category].input.checked = value?.categories?.[category] !== false;
|
|
38621
|
+
syncAutoReviewControls({ preferredThinking: value?.autoReview?.model?.thinkingLevel || "off", preserveUnavailable: true });
|
|
37294
38622
|
};
|
|
37295
38623
|
|
|
37296
38624
|
const body = make("div", "native-settings-panel");
|
|
37297
38625
|
body.append(
|
|
37298
38626
|
nativeSettingsNote("Persistence", `Saved globally in ${data.path || "~/.pi/agent/safety-guard.json"}. Changes are reloaded before guard checks.`),
|
|
37299
38627
|
nativeSettingsSection("General", "Enable or disable all guard behavior.", [controls.enabled], { open: true }),
|
|
38628
|
+
nativeSettingsSection("Automatic review", "Opt in to a dedicated authenticated model for non-modal allow/block preflight. Provider failures and invalid verdicts return to the existing prompt.", [controls.autoReview, controls.autoReviewModel, controls.autoReviewThinking], { open: true }),
|
|
38629
|
+
autoReviewAvailability,
|
|
37300
38630
|
nativeSettingsSection("Command preview", "Choose independent context limits before and after each dangerous matched line.", [controls.before, controls.after], { open: true }),
|
|
37301
38631
|
nativeSettingsSection("Command categories", "Disable only categories you intentionally do not want guarded.", categories.map((category) => categoryControls[category]), { open: true }),
|
|
37302
38632
|
nativeSettingsSection("Protected paths", "Control write/edit prompts for secret-bearing files and credential paths.", [controls.protectedWrite, controls.protectedEdit], { open: true }),
|
|
@@ -37313,16 +38643,28 @@ async function openNativeSafetyGuardSetupDialog() {
|
|
|
37313
38643
|
setNativeActionBusy(save, true, "Saving…");
|
|
37314
38644
|
setNativeCommandError("");
|
|
37315
38645
|
try {
|
|
38646
|
+
const submitted = collectConfig();
|
|
38647
|
+
const selectedModelKey = controls.autoReviewModel.select.value;
|
|
38648
|
+
const supportedLevels = thinkingLevelsForModel(selectedModelKey);
|
|
38649
|
+
if (submitted.autoReview.enabled && !models.some((model) => modelKey(model) === selectedModelKey)) {
|
|
38650
|
+
throw new Error("Select an authenticated auto-review model from this active tab.");
|
|
38651
|
+
}
|
|
38652
|
+
if (submitted.autoReview.enabled && !supportedLevels.includes(submitted.autoReview.model.thinkingLevel)) {
|
|
38653
|
+
throw new Error(`${selectedModelKey} does not support thinking level ${submitted.autoReview.model.thinkingLevel}.`);
|
|
38654
|
+
}
|
|
37316
38655
|
const response = await nativeCommandApi("/api/safety-guard/config", {
|
|
37317
38656
|
method: "POST",
|
|
37318
|
-
body: { config:
|
|
38657
|
+
body: { config: submitted },
|
|
37319
38658
|
});
|
|
37320
|
-
const saved = response.data?.config ||
|
|
38659
|
+
const saved = response.data?.config || submitted;
|
|
37321
38660
|
const activeCategories = categories.filter((category) => saved.categories?.[category]).length;
|
|
38661
|
+
const autoReviewSummary = saved.autoReview?.enabled
|
|
38662
|
+
? `auto-review ${saved.autoReview.model.provider}/${saved.autoReview.model.modelId} at ${saved.autoReview.model.thinkingLevel}`
|
|
38663
|
+
: "auto-review off";
|
|
37322
38664
|
addTransientMessage({
|
|
37323
38665
|
role: "native",
|
|
37324
38666
|
title: "/safety-guard-setup",
|
|
37325
|
-
content: `Safety guard ${saved.enabled ? "enabled" : "disabled"}; ${activeCategories}/${categories.length} command categories active; preview ${saved.contextLines?.before ?? 3} before and ${saved.contextLines?.after ?? 3} after.`,
|
|
38667
|
+
content: `Safety guard ${saved.enabled ? "enabled" : "disabled"}; ${activeCategories}/${categories.length} command categories active; ${autoReviewSummary}; preview ${saved.contextLines?.before ?? 3} before and ${saved.contextLines?.after ?? 3} after.`,
|
|
37326
38668
|
level: saved.enabled ? "info" : "warn",
|
|
37327
38669
|
});
|
|
37328
38670
|
closeNativeCommandDialog();
|
|
@@ -39357,6 +40699,11 @@ async function refreshState(tabContext = activeTabContext()) {
|
|
|
39357
40699
|
renderStatus();
|
|
39358
40700
|
if (mobilePhoneExperienceInstalled && isMobileShellV2Active()) renderMobilePhoneExperience();
|
|
39359
40701
|
requestGitFooterWebuiPayload(tabContext, { force: shouldRefreshGitFooter });
|
|
40702
|
+
// Sampling support and effective values depend on the active model, so refresh
|
|
40703
|
+
// them whenever the session reports a different model.
|
|
40704
|
+
if (modelStateKey(previousState?.model) !== modelStateKey(currentState?.model)) {
|
|
40705
|
+
refreshSamplingParametersForTabContext(tabContext);
|
|
40706
|
+
}
|
|
39360
40707
|
}
|
|
39361
40708
|
|
|
39362
40709
|
async function refreshStats(tabContext = activeTabContext()) {
|
|
@@ -40744,8 +42091,8 @@ function updateServerActionButton() {
|
|
|
40744
42091
|
button.textContent = action === "restart" ? "Restart" : action === "update" || action === "update-all" ? "Update" : action === "stop" ? "Stop" : "Run";
|
|
40745
42092
|
button.classList.toggle("danger", action === "stop");
|
|
40746
42093
|
if (action === "restart") setServerActionStatus("Ready to restart the Web UI server.", "info");
|
|
40747
|
-
else if (action === "update") setServerActionStatus("Ready to
|
|
40748
|
-
else if (action === "update-all") setServerActionStatus("Ready to
|
|
42094
|
+
else if (action === "update") setServerActionStatus("Ready to create and confirm an exact Pi-only update plan.", "info");
|
|
42095
|
+
else if (action === "update-all") setServerActionStatus("Ready to create and confirm an exact combined update plan for eligible Pi, Web UI, and Pi-owned Optional Features.", "info");
|
|
40749
42096
|
else if (action === "stop") setServerActionStatus("Ready to stop the Web UI server.", "info");
|
|
40750
42097
|
else setServerActionStatus();
|
|
40751
42098
|
}
|
|
@@ -40766,19 +42113,25 @@ function resetServerActionControls() {
|
|
|
40766
42113
|
updateServerActionButton();
|
|
40767
42114
|
}
|
|
40768
42115
|
|
|
40769
|
-
async function waitForServerRestart() {
|
|
40770
|
-
|
|
40771
|
-
|
|
40772
|
-
|
|
42116
|
+
async function waitForServerRestart(previousBootIdentity = serverBootIdentity) {
|
|
42117
|
+
const deadline = Date.now() + 90_000;
|
|
42118
|
+
let attempt = 0;
|
|
42119
|
+
while (Date.now() < deadline) {
|
|
42120
|
+
attempt += 1;
|
|
42121
|
+
await delay(attempt === 1 ? 900 : 500);
|
|
42122
|
+
const remainingSeconds = Math.max(0, Math.ceil((deadline - Date.now()) / 1000));
|
|
42123
|
+
const message = `Restarting… waiting for changed server identity (${remainingSeconds}s remaining)`;
|
|
40773
42124
|
setServerActionStatus(message, "warn");
|
|
40774
42125
|
setServerRestartOverlay(true, message);
|
|
40775
42126
|
try {
|
|
40776
|
-
await api("/api/health", { scoped: false });
|
|
42127
|
+
const health = await api("/api/health", { scoped: false });
|
|
42128
|
+
if (!health.bootIdentity || health.bootIdentity === previousBootIdentity) continue;
|
|
42129
|
+
serverBootIdentity = health.bootIdentity;
|
|
40777
42130
|
setBackendOffline(false);
|
|
40778
42131
|
await initializeTabs();
|
|
40779
42132
|
setServerRestartOverlay(false);
|
|
40780
42133
|
setServerActionStatus("Server restarted and reconnected.", "success");
|
|
40781
|
-
addEvent("Pi Web UI server restarted", "warn");
|
|
42134
|
+
addEvent("Pi Web UI server restarted with a changed boot identity", "warn");
|
|
40782
42135
|
return true;
|
|
40783
42136
|
} catch (error) {
|
|
40784
42137
|
setBackendOffline(true, error);
|
|
@@ -40818,7 +42171,7 @@ async function restartServer() {
|
|
|
40818
42171
|
}
|
|
40819
42172
|
|
|
40820
42173
|
setBackendOffline(true, new Error("restart requested from side panel"));
|
|
40821
|
-
const restarted = await waitForServerRestart();
|
|
42174
|
+
const restarted = await waitForServerRestart(serverBootIdentity);
|
|
40822
42175
|
if (elements.serverActionSelect) {
|
|
40823
42176
|
elements.serverActionSelect.disabled = false;
|
|
40824
42177
|
elements.serverActionSelect.value = "";
|
|
@@ -41202,10 +42555,13 @@ async function sendPrompt(kind = "prompt", explicitMessage, { targetTabId = acti
|
|
|
41202
42555
|
response = await api("/api/prompt", { method: "POST", body, tabId: targetTabId });
|
|
41203
42556
|
}
|
|
41204
42557
|
applyResponseTab(response);
|
|
42558
|
+
// A successful RPC response ends prompt-routing ownership even when an
|
|
42559
|
+
// extension command handled the input without starting an agent turn.
|
|
42560
|
+
// Canonical streaming state keeps real agent runs active after this handoff.
|
|
42561
|
+
if (startsRun) promptRoutingTabs.delete(targetTabId);
|
|
41205
42562
|
if (response?.command === "native_slash_command" && /^\/new(?:\s|$)/.test(message)) forgetLastUserPrompt(targetTabId);
|
|
41206
42563
|
const targetStillActive = isCurrentTabContext(tabContext);
|
|
41207
42564
|
if (startsRun && response?.command === "native_slash_command") {
|
|
41208
|
-
promptRoutingTabs.delete(targetTabId);
|
|
41209
42565
|
discardOptimisticUserPrompt(optimisticPromptId);
|
|
41210
42566
|
markTabIdleLocally(targetTabId);
|
|
41211
42567
|
if (targetStillActive) clearRunIndicatorActivity();
|
|
@@ -42607,6 +43963,17 @@ optionsMenuContainer?.addEventListener("focusout", () => {
|
|
|
42607
43963
|
if (!optionsMenuContainer?.contains(document.activeElement)) setOptionsMenuOpen(false);
|
|
42608
43964
|
}, 0);
|
|
42609
43965
|
});
|
|
43966
|
+
elements.optionsMenuButton.addEventListener("keydown", (event) => {
|
|
43967
|
+
if (event.key !== "ArrowDown" && event.key !== "ArrowUp") return;
|
|
43968
|
+
event.preventDefault();
|
|
43969
|
+
setPublishMenuOpen(false);
|
|
43970
|
+
setNativeCommandMenuOpen(false);
|
|
43971
|
+
setAppRunnerMenuOpen(false);
|
|
43972
|
+
setOptionsMenuOpen(true);
|
|
43973
|
+
const items = optionsMenuRootItems();
|
|
43974
|
+
focusOptionsMenuItem(event.key === "ArrowDown" ? items[0] : items[items.length - 1]);
|
|
43975
|
+
});
|
|
43976
|
+
initializeOptionsSubmenus();
|
|
42610
43977
|
elements.releaseNpmButton.addEventListener("click", () => runPublishWorkflow("/release-npm"));
|
|
42611
43978
|
elements.releaseAurButton.addEventListener("click", () => runPublishWorkflow("/release-aur"));
|
|
42612
43979
|
elements.nativeSkillsButton.addEventListener("click", () => runNativeCommandMenu("/skills"));
|
|
@@ -42754,6 +44121,14 @@ elements.undoToastButton?.addEventListener("click", () => runOfferedUndo());
|
|
|
42754
44121
|
elements.undoToastDismissButton?.addEventListener("click", dismissUndoToast);
|
|
42755
44122
|
elements.confirmationCancelButton?.addEventListener("click", () => finishApplicationConfirmation(false));
|
|
42756
44123
|
elements.confirmationConfirmButton?.addEventListener("click", () => finishApplicationConfirmation(true));
|
|
44124
|
+
elements.gitPullErrorMergeButton?.addEventListener("click", () => integrateGitPullDivergence("merge"));
|
|
44125
|
+
elements.gitPullErrorRebaseButton?.addEventListener("click", () => integrateGitPullDivergence("rebase"));
|
|
44126
|
+
elements.gitPullErrorReviewButton?.addEventListener("click", reviewGitPullDivergence);
|
|
44127
|
+
elements.gitPullErrorCopyButton?.addEventListener("click", () => copyGitPullErrorOutput());
|
|
44128
|
+
elements.gitPullErrorCloseButton?.addEventListener("click", closeGitPullErrorDialog);
|
|
44129
|
+
elements.gitPullErrorDialog?.addEventListener("cancel", (event) => {
|
|
44130
|
+
if (gitPullErrorContext.busy) event.preventDefault();
|
|
44131
|
+
});
|
|
42757
44132
|
elements.confirmationDialog?.addEventListener("cancel", (event) => {
|
|
42758
44133
|
event.preventDefault();
|
|
42759
44134
|
finishApplicationConfirmation(false);
|
|
@@ -42977,6 +44352,9 @@ async function abortActiveRun({ source = "button" } = {}) {
|
|
|
42977
44352
|
}
|
|
42978
44353
|
if (hadActiveRun) setRunIndicatorActivity(`Abort requested${source === "escape" ? " from Esc" : source === "long-press" ? " from long-press" : ""}; checking whether Pi stopped…`);
|
|
42979
44354
|
await api("/api/abort", { method: "POST", body: {}, tabId: tabContext.tabId });
|
|
44355
|
+
// Abort also terminates an in-flight local routing handoff. Without this,
|
|
44356
|
+
// canonical idle state cannot clear a stale extension-command indicator.
|
|
44357
|
+
promptRoutingTabs.delete(tabContext.tabId);
|
|
42980
44358
|
if (!isCurrentTabContext(tabContext)) return;
|
|
42981
44359
|
addAbortTranscriptNotice({ activeRun: hadActiveRun });
|
|
42982
44360
|
scheduleAbortStateChecks(tabContext);
|
|
@@ -43287,6 +44665,24 @@ elements.subagentLaunchSlotsLater?.addEventListener("click", () => {
|
|
|
43287
44665
|
setSubagentLaunchSlotAnnouncement("Agent models are saved. Reload this tab later before relying on them for future launches.");
|
|
43288
44666
|
renderSubagentLaunchSlots();
|
|
43289
44667
|
});
|
|
44668
|
+
elements.applySamplingParametersButton?.addEventListener("click", () => {
|
|
44669
|
+
applySamplingParameters().catch((error) => {
|
|
44670
|
+
setSamplingParametersFeedback({ error: error.message || String(error) });
|
|
44671
|
+
renderSamplingParameters();
|
|
44672
|
+
});
|
|
44673
|
+
});
|
|
44674
|
+
elements.resetSamplingParametersButton?.addEventListener("click", () => {
|
|
44675
|
+
resetSamplingParameters().catch((error) => {
|
|
44676
|
+
setSamplingParametersFeedback({ error: error.message || String(error) });
|
|
44677
|
+
renderSamplingParameters();
|
|
44678
|
+
});
|
|
44679
|
+
});
|
|
44680
|
+
elements.reloadSamplingParametersButton?.addEventListener("click", () => {
|
|
44681
|
+
loadSamplingParameters({ force: true }).catch((error) => {
|
|
44682
|
+
setSamplingParametersFeedback({ error: error.message || String(error) });
|
|
44683
|
+
renderSamplingParameters();
|
|
44684
|
+
});
|
|
44685
|
+
});
|
|
43290
44686
|
elements.subagentTerminalCopyButton?.addEventListener("click", () => copySubagentTerminalOutput());
|
|
43291
44687
|
elements.subagentTerminalRefreshButton?.addEventListener("click", () => {
|
|
43292
44688
|
refreshSubagentTerminalView(activeSubagentTerminalId, { showLoading: true }).finally(() => scheduleSubagentTerminalRefresh());
|
|
@@ -43403,6 +44799,9 @@ document.addEventListener("pointerdown", (event) => {
|
|
|
43403
44799
|
if (elements.sidePanelContextMenu && !elements.sidePanelContextMenu.hidden && !event.target?.closest?.(".side-panel-context-menu")) {
|
|
43404
44800
|
closeSidePanelContextMenu();
|
|
43405
44801
|
}
|
|
44802
|
+
if (elements.gitFooterContextMenu && !elements.gitFooterContextMenu.hidden && !event.target?.closest?.(".git-footer-context-menu")) {
|
|
44803
|
+
closeGitFooterContextMenu();
|
|
44804
|
+
}
|
|
43406
44805
|
}, { passive: true });
|
|
43407
44806
|
document.addEventListener("pointermove", (event) => {
|
|
43408
44807
|
if (openTerminalTabGroupKey && !event.target?.closest?.(".terminal-tab-group")) {
|
|
@@ -43615,6 +45014,10 @@ window.addEventListener("offline", () => {
|
|
|
43615
45014
|
window.addEventListener("beforeunload", persistMobileContinuityState);
|
|
43616
45015
|
window.addEventListener("storage", (event) => {
|
|
43617
45016
|
if (event.key === OPTIONAL_FEATURES_STORAGE_KEY) reconcileDisabledOptionalFeaturesFromStorage();
|
|
45017
|
+
if (event.key === OPTIONAL_FEATURE_MIGRATION_DISMISS_STORAGE_KEY && optionalFeatureMigrationCompletionIsDismissed()) {
|
|
45018
|
+
optionalFeatureRestartNotice = null;
|
|
45019
|
+
renderOptionalFeatureMigrationSurface();
|
|
45020
|
+
}
|
|
43618
45021
|
if (event.key === SIDE_PANEL_SECTION_VISIBILITY_STORAGE_KEY) restoreSidePanelSectionVisibility();
|
|
43619
45022
|
if (event.key === SIDE_PANEL_SECTION_ORDER_STORAGE_KEY) restoreSidePanelSectionOrder();
|
|
43620
45023
|
if (event.key === COMPOSER_ACTION_ORDER_STORAGE_KEY) restoreComposerActionOrder();
|
|
@@ -43845,6 +45248,30 @@ elements.sidePanelContextMenu?.addEventListener("keydown", (event) => {
|
|
|
43845
45248
|
items[event.key === "Home" ? 0 : items.length - 1]?.focus({ preventScroll: true });
|
|
43846
45249
|
}
|
|
43847
45250
|
});
|
|
45251
|
+
elements.gitFooterContextMenu?.addEventListener("keydown", (event) => {
|
|
45252
|
+
const items = [...elements.gitFooterContextMenu.querySelectorAll('[role="menuitem"]:not([disabled])')];
|
|
45253
|
+
const index = items.indexOf(document.activeElement);
|
|
45254
|
+
if (event.key === "Escape") {
|
|
45255
|
+
event.preventDefault();
|
|
45256
|
+
closeGitFooterContextMenu();
|
|
45257
|
+
} else if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
45258
|
+
event.preventDefault();
|
|
45259
|
+
const direction = event.key === "ArrowDown" ? 1 : -1;
|
|
45260
|
+
items[(Math.max(0, index) + direction + items.length) % items.length]?.focus({ preventScroll: true });
|
|
45261
|
+
} else if (event.key === "Home" || event.key === "End") {
|
|
45262
|
+
event.preventDefault();
|
|
45263
|
+
items[event.key === "Home" ? 0 : items.length - 1]?.focus({ preventScroll: true });
|
|
45264
|
+
}
|
|
45265
|
+
});
|
|
45266
|
+
elements.gitFooterContextMenu?.addEventListener("click", (event) => {
|
|
45267
|
+
const button = event.target?.closest?.("[data-git-footer-menu-action]");
|
|
45268
|
+
const state = gitFooterContextMenuState;
|
|
45269
|
+
if (!button || !state) return;
|
|
45270
|
+
const action = button.dataset.gitFooterMenuAction;
|
|
45271
|
+
closeGitFooterContextMenu({ returnFocus: action !== "visibility" });
|
|
45272
|
+
if (action === "disable") void disableGitFooterContextChip(state.key, state.label);
|
|
45273
|
+
else if (action === "visibility") openGitFooterVisibilityDialog();
|
|
45274
|
+
});
|
|
43848
45275
|
elements.fileContextMenu?.addEventListener("click", (event) => {
|
|
43849
45276
|
const button = event.target?.closest?.("[data-file-menu-action]");
|
|
43850
45277
|
if (!button) return;
|
|
@@ -44040,8 +45467,14 @@ elements.optionalFeatureMigrationDialog?.addEventListener("cancel", (event) => {
|
|
|
44040
45467
|
});
|
|
44041
45468
|
|
|
44042
45469
|
installModalPrimitives();
|
|
45470
|
+
installMiddleButtonDragScroll({
|
|
45471
|
+
onDirection: ({ target, offsetY }) => {
|
|
45472
|
+
if (target === elements.chat) noteChatUserScrollIntent({ type: "middle-drag", deltaY: offsetY });
|
|
45473
|
+
},
|
|
45474
|
+
});
|
|
44043
45475
|
initializeIssueWizard();
|
|
44044
45476
|
resizePromptInput();
|
|
45477
|
+
clearRemovedSidePanelSectionHeightState();
|
|
44045
45478
|
restoreDurableUiLayoutPendingJournal();
|
|
44046
45479
|
restoreSidePanelWidthPreference();
|
|
44047
45480
|
restoreFileViewerWidthPreference();
|
|
@@ -44085,6 +45518,7 @@ initializeCodexUsage();
|
|
|
44085
45518
|
initializeClaudeUsage();
|
|
44086
45519
|
initializeSubagents();
|
|
44087
45520
|
initializeSubagentLaunchSlots();
|
|
45521
|
+
initializeSamplingParameters();
|
|
44088
45522
|
initializeUpdateNotifications();
|
|
44089
45523
|
bindMobileViewChanges();
|
|
44090
45524
|
bindSidePanelOverlayViewChanges();
|