@firstpick/pi-package-webui 0.8.6 → 0.8.7
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 +558 -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 +1290 -82
- package/public/index.html +124 -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 +417 -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 +66 -0
- 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 +23 -21
- package/tests/open-issue-wizard-static.test.mjs +1 -1
- package/tests/optional-feature-migration-frontend.test.mjs +9 -5
- package/tests/persistent-ui-layout-static.test.mjs +13 -2
- 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"),
|
|
@@ -524,6 +544,7 @@ let tabAttachments = new Map();
|
|
|
524
544
|
let activeTextAttachmentEditor = null;
|
|
525
545
|
let activeSkillEditor = null;
|
|
526
546
|
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() };
|
|
547
|
+
let fileTreeLastRenderSignature = "";
|
|
527
548
|
let activeFileViewer = null;
|
|
528
549
|
let fileViewersByTab = new Map();
|
|
529
550
|
let fileViewerOpenRequestSerial = 0;
|
|
@@ -537,6 +558,7 @@ let fileViewerSearchTimer = null;
|
|
|
537
558
|
let fileViewerSearchHighlightElement = null;
|
|
538
559
|
let fileContextMenuState = null;
|
|
539
560
|
let sidePanelContextMenuState = null;
|
|
561
|
+
let gitFooterContextMenuState = null;
|
|
540
562
|
let sidePanelSectionPointerDrag = null;
|
|
541
563
|
let sidePanelSectionLastDragOverKey = "";
|
|
542
564
|
let sidePanelSectionSuppressClickUntil = 0;
|
|
@@ -785,6 +807,19 @@ let appRunnerSearchPathDraft = "";
|
|
|
785
807
|
let appRunnerSearchPathFeedback = { type: "", message: "" };
|
|
786
808
|
let appRunnerDirectoryBrowserState = { open: false, loading: false, path: "", data: null, error: "" };
|
|
787
809
|
let optionsMenuOpen = false;
|
|
810
|
+
const OPTIONS_SUBMENU_GROUP_SELECTOR = "[data-options-submenu]";
|
|
811
|
+
const OPTIONS_SUBMENU_TRIGGER_SELECTOR = "[data-options-submenu-trigger]";
|
|
812
|
+
const OPTIONS_SUBMENU_PANEL_SELECTOR = "[data-options-submenu-panel]";
|
|
813
|
+
const OPTIONS_SUBMENU_BACK_SELECTOR = "[data-options-submenu-back]";
|
|
814
|
+
const OPTIONS_SUBMENU_LEFT_CLASS = "opens-left";
|
|
815
|
+
const OPTIONS_SUBMENU_DRILL_IN_QUERY = "(hover: none), (pointer: coarse)";
|
|
816
|
+
const OPTIONS_MENU_LABEL_SELECTOR = '.composer-options-menu-item > span:not([aria-hidden="true"]):not(.composer-options-submenu-chevron)';
|
|
817
|
+
const OPTIONS_MENU_LABEL_FONT_SIZE_PROPERTY = "--options-menu-label-font-size";
|
|
818
|
+
const OPTIONS_MENU_LABEL_MIN_FONT_SIZE_PX = 12;
|
|
819
|
+
let openOptionsSubmenuGroup = null;
|
|
820
|
+
let optionsSubmenuObserver = null;
|
|
821
|
+
let optionsSubmenuSyncing = false;
|
|
822
|
+
let optionsMenuLabelFitFrame = 0;
|
|
788
823
|
let availableCommands = [];
|
|
789
824
|
let rawAvailableCommands = [];
|
|
790
825
|
const commandCatalogsByTab = new Map();
|
|
@@ -865,10 +900,20 @@ let subagentLaunchSlotRequestSerial = 0;
|
|
|
865
900
|
let subagentLaunchSlotReloadRequired = false;
|
|
866
901
|
const subagentLaunchSlotReloadTabs = new Set();
|
|
867
902
|
let subagentLaunchSlotFocusTarget = null;
|
|
903
|
+
let samplingParametersState = null;
|
|
904
|
+
let samplingParametersStateTabId = null;
|
|
905
|
+
const samplingParametersDrafts = new Map();
|
|
906
|
+
let samplingParametersLoading = false;
|
|
907
|
+
let samplingParametersBusy = false;
|
|
908
|
+
let samplingParametersError = "";
|
|
909
|
+
let samplingParametersNotice = "";
|
|
910
|
+
let samplingParametersFeedbackTabId = null;
|
|
911
|
+
let samplingParametersRequestSerial = 0;
|
|
868
912
|
let backendOffline = false;
|
|
869
913
|
let serverRestartInProgress = false;
|
|
870
914
|
let updateRequestInProgress = false;
|
|
871
915
|
let latestUpdateStatus = null;
|
|
916
|
+
let serverBootIdentity = "";
|
|
872
917
|
let updateStatusRefreshTimer = null;
|
|
873
918
|
let updateNotificationHideTimer = null;
|
|
874
919
|
let componentUpdatePollTimer = null;
|
|
@@ -985,6 +1030,7 @@ const TAB_STORAGE_KEY = "pi-webui-active-tab";
|
|
|
985
1030
|
const PATH_FAST_PICKS_STORAGE_KEY = "pi-webui-path-fast-picks";
|
|
986
1031
|
const AGENT_DONE_NOTIFICATIONS_STORAGE_KEY = "pi-webui-agent-done-notifications";
|
|
987
1032
|
const UPDATE_NOTIFICATION_DISMISS_STORAGE_KEY = "pi-webui-update-notification-dismissed";
|
|
1033
|
+
const OPTIONAL_FEATURE_MIGRATION_DISMISS_STORAGE_KEY = "pi-webui-optional-feature-migration-dismissed";
|
|
988
1034
|
const MOBILE_CONTINUITY_STORAGE_KEY = "pi-webui-mobile-continuity-v1";
|
|
989
1035
|
const MOBILE_INSTALL_EDUCATION_STORAGE_KEY = "pi-webui-mobile-install-education-v1";
|
|
990
1036
|
const MOBILE_CONTINUITY_MAX_SESSIONS = 24;
|
|
@@ -1742,6 +1788,7 @@ function mobileRenderMore() {
|
|
|
1742
1788
|
const page = mobileShellState.surfacePage || "root";
|
|
1743
1789
|
const topics = {
|
|
1744
1790
|
session: ["Session", ["sidePanelSectionSession"]],
|
|
1791
|
+
sampling: ["Sampling parameters", ["sidePanelSectionSampling"]],
|
|
1745
1792
|
usage: ["Usage", ["sidePanelSectionCodexUsage", "sidePanelSectionClaudeUsage"]],
|
|
1746
1793
|
extensions: ["Extensions", ["sidePanelSectionOptionalFeatures"]],
|
|
1747
1794
|
settings: ["Settings", ["sidePanelSectionControls"]],
|
|
@@ -1792,6 +1839,7 @@ function mobileRenderMore() {
|
|
|
1792
1839
|
title.textContent = topic[0];
|
|
1793
1840
|
back.hidden = false;
|
|
1794
1841
|
mobileCanonicalMountContent(host, topic[1], `more:${page}`);
|
|
1842
|
+
if (page === "sampling") ensureSamplingParametersLoaded();
|
|
1795
1843
|
if (page === "commands") mobileShellElement("commandSearchInput")?.focus({ preventScroll: true });
|
|
1796
1844
|
}
|
|
1797
1845
|
|
|
@@ -2347,6 +2395,7 @@ const optionalFeatureAvailability = {
|
|
|
2347
2395
|
releaseAur: false,
|
|
2348
2396
|
aurReview: false,
|
|
2349
2397
|
workflows: false,
|
|
2398
|
+
featureSystemPrompt: false,
|
|
2350
2399
|
safetyGuard: false,
|
|
2351
2400
|
statsCommand: false,
|
|
2352
2401
|
gitFooterStatus: false,
|
|
@@ -2419,6 +2468,13 @@ const OPTIONAL_FEATURES = [
|
|
|
2419
2468
|
capabilityLabel: "/workflow or workflow subprocess widget event",
|
|
2420
2469
|
description: "Modular workflow runner with live subprocess output shown in a non-blocking Web UI widget.",
|
|
2421
2470
|
},
|
|
2471
|
+
{
|
|
2472
|
+
id: "featureSystemPrompt",
|
|
2473
|
+
label: "Feature workflow routing",
|
|
2474
|
+
packageName: "@firstpick/pi-extension-feature-system-prompt",
|
|
2475
|
+
capabilityLabel: "feature-category or feature-decision-output status event",
|
|
2476
|
+
description: "Classify feature requests and show lightweight or complex routing decisions in the composer.",
|
|
2477
|
+
},
|
|
2422
2478
|
{
|
|
2423
2479
|
id: "safetyGuard",
|
|
2424
2480
|
label: "Safety guard",
|
|
@@ -2898,7 +2954,7 @@ const OPTIONAL_FEATURE_SECTIONS = [
|
|
|
2898
2954
|
id: "workflows-releases",
|
|
2899
2955
|
label: "Workflows & releases",
|
|
2900
2956
|
description: "Guided workflows, task runners, and publishing actions with visible execution state.",
|
|
2901
|
-
featureIds: ["gitWorkflow", "workflows", "releaseNpm", "releaseAur", "aurReview"],
|
|
2957
|
+
featureIds: ["gitWorkflow", "workflows", "featureSystemPrompt", "releaseNpm", "releaseAur", "aurReview"],
|
|
2902
2958
|
},
|
|
2903
2959
|
{
|
|
2904
2960
|
id: "safety-access",
|
|
@@ -3003,6 +3059,7 @@ let optionalFeatureMigrationRenderTimer = null;
|
|
|
3003
3059
|
let optionalFeatureMigrationReadyDismissTimer = null;
|
|
3004
3060
|
let optionalFeatureMigrationPendingReadyDismissKey = "";
|
|
3005
3061
|
let optionalFeatureMigrationDismissedReadyKey = "";
|
|
3062
|
+
let optionalFeatureMigrationDismissedCompletionKey = "";
|
|
3006
3063
|
let optionalFeatureMigrationDialogState = null;
|
|
3007
3064
|
let optionalFeatureMigrationLastPhase = "";
|
|
3008
3065
|
let optionalFeatureMigrationCompletionFocusKey = "";
|
|
@@ -3793,6 +3850,9 @@ function setSidePanelSectionVisible(record, visible, { persist = true } = {}) {
|
|
|
3793
3850
|
ensureGitPanelRepositoriesDiscovered({ retryUnavailable: true });
|
|
3794
3851
|
});
|
|
3795
3852
|
}
|
|
3853
|
+
if (visible && record.id === "sampling" && !record.section.classList.contains("collapsed")) {
|
|
3854
|
+
queueMicrotask(() => ensureSamplingParametersLoaded());
|
|
3855
|
+
}
|
|
3796
3856
|
if (persist) persistSidePanelSectionVisibility();
|
|
3797
3857
|
}
|
|
3798
3858
|
|
|
@@ -3816,6 +3876,9 @@ function setSidePanelSectionCollapsed(record, collapsed, { persist = true } = {}
|
|
|
3816
3876
|
ensureGitPanelRepositoriesDiscovered({ retryUnavailable: true });
|
|
3817
3877
|
});
|
|
3818
3878
|
}
|
|
3879
|
+
if (!collapsed && record.id === "sampling" && !record.section.hidden) {
|
|
3880
|
+
queueMicrotask(() => ensureSamplingParametersLoaded());
|
|
3881
|
+
}
|
|
3819
3882
|
if (persist) persistSidePanelSectionState();
|
|
3820
3883
|
}
|
|
3821
3884
|
|
|
@@ -5670,8 +5733,9 @@ function clearFeatureDecisionStateForTab(tabId, { render = false } = {}) {
|
|
|
5670
5733
|
function renderFeatureCategoryTag(tabId = activeTabId) {
|
|
5671
5734
|
const tag = elements.featureCategoryTag;
|
|
5672
5735
|
if (!tag) return;
|
|
5673
|
-
const
|
|
5674
|
-
const
|
|
5736
|
+
const enabled = isOptionalFeatureEnabled("featureSystemPrompt");
|
|
5737
|
+
const category = enabled ? normalizeFeatureCategory(featureCategoryByTab.get(tabId)) : "";
|
|
5738
|
+
const output = enabled ? featureDecisionOutputForTab(tabId) : "";
|
|
5675
5739
|
tag.hidden = !category;
|
|
5676
5740
|
tag.disabled = !output;
|
|
5677
5741
|
tag.textContent = category;
|
|
@@ -5683,18 +5747,22 @@ function renderFeatureCategoryTag(tabId = activeTabId) {
|
|
|
5683
5747
|
|
|
5684
5748
|
function handleFeatureDecisionOutputStatus(statusText, tabId = activeTabId) {
|
|
5685
5749
|
if (!tabId) return;
|
|
5750
|
+
optionalFeatureAvailability.featureSystemPrompt = true;
|
|
5686
5751
|
const decision = parseFeatureDecisionPayload(statusText);
|
|
5687
5752
|
if (decision) featureDecisionOutputByTab.set(tabId, decision);
|
|
5688
5753
|
else featureDecisionOutputByTab.delete(tabId);
|
|
5754
|
+
renderOptionalFeatureControls();
|
|
5689
5755
|
if (tabId === activeTabId) renderFeatureCategoryTag(tabId);
|
|
5690
5756
|
else if (featureDecisionDialogTabId === tabId) syncFeatureDecisionDialog();
|
|
5691
5757
|
}
|
|
5692
5758
|
|
|
5693
5759
|
function handleFeatureCategoryStatus(statusText, tabId = activeTabId) {
|
|
5694
5760
|
if (!tabId) return;
|
|
5761
|
+
optionalFeatureAvailability.featureSystemPrompt = true;
|
|
5695
5762
|
const category = normalizeFeatureCategory(statusText);
|
|
5696
5763
|
if (category) featureCategoryByTab.set(tabId, category);
|
|
5697
5764
|
else clearFeatureDecisionStateForTab(tabId);
|
|
5765
|
+
renderOptionalFeatureControls();
|
|
5698
5766
|
if (tabId === activeTabId) renderFeatureCategoryTag(tabId);
|
|
5699
5767
|
else if (featureDecisionDialogTabId === tabId) syncFeatureDecisionDialog();
|
|
5700
5768
|
}
|
|
@@ -7254,24 +7322,25 @@ async function confirmOpenWebuiNpmPage() {
|
|
|
7254
7322
|
async function openPiReleaseNotes() {
|
|
7255
7323
|
const dialog = elements.piReleaseNotesDialog;
|
|
7256
7324
|
if (!dialog) return;
|
|
7257
|
-
const
|
|
7258
|
-
const
|
|
7325
|
+
const installedVersion = piVersion;
|
|
7326
|
+
const availableVersion = latestUpdateStatus?.pi?.updateAvailable ? latestUpdateStatus.pi.latestVersion : "";
|
|
7327
|
+
const displayedVersion = availableVersion || installedVersion;
|
|
7328
|
+
const label = formatWebuiVersion(displayedVersion);
|
|
7259
7329
|
elements.piReleaseNotesTitle.textContent = label ? `Pi ${label} release notes` : "Pi release notes";
|
|
7260
7330
|
elements.piReleaseNotesStatus.textContent = "Loading release notes from GitHub…";
|
|
7261
7331
|
elements.piReleaseNotesBody.setAttribute("aria-busy", "true");
|
|
7262
7332
|
elements.piReleaseNotesBody.replaceChildren(make("p", "muted", "Loading…"));
|
|
7263
|
-
setPiReleaseNotesLink(piReleasePageUrl(
|
|
7333
|
+
setPiReleaseNotesLink(piReleasePageUrl(displayedVersion));
|
|
7264
7334
|
renderComponentUpdateDialogs();
|
|
7265
7335
|
if (!dialog.open) dialog.showModal();
|
|
7266
7336
|
refreshUpdateStatus({ notify: false }).catch((error) => addEvent(`Pi/Web UI update check failed: ${error.message || String(error)}`, "warn"));
|
|
7267
7337
|
|
|
7268
7338
|
try {
|
|
7269
7339
|
const response = await api("/api/pi-release-notes", { scoped: false });
|
|
7270
|
-
if (
|
|
7340
|
+
if (installedVersion !== piVersion) return;
|
|
7271
7341
|
const release = response.data || {};
|
|
7272
7342
|
const releaseVersion = String(release.version || "").trim().replace(/^v/i, "");
|
|
7273
|
-
|
|
7274
|
-
const releaseLabel = formatWebuiVersion(releaseVersion || requestedVersion);
|
|
7343
|
+
const releaseLabel = formatWebuiVersion(releaseVersion || displayedVersion);
|
|
7275
7344
|
elements.piReleaseNotesTitle.textContent = releaseLabel ? `Pi ${releaseLabel} release notes` : (release.title || "Pi release notes");
|
|
7276
7345
|
renderMarkdown(elements.piReleaseNotesBody, release.body || "No release notes were provided for this release.");
|
|
7277
7346
|
const published = formatPiReleaseDate(release.publishedAt);
|
|
@@ -7287,6 +7356,7 @@ async function openPiReleaseNotes() {
|
|
|
7287
7356
|
|
|
7288
7357
|
async function refreshWebuiVersion() {
|
|
7289
7358
|
const health = await api("/api/health", { scoped: false });
|
|
7359
|
+
if (health.bootIdentity) serverBootIdentity = health.bootIdentity;
|
|
7290
7360
|
setWebuiVersion(health.webuiVersion);
|
|
7291
7361
|
setPiVersion(health.piVersion);
|
|
7292
7362
|
setWebuiDevServer(isWebuiDevMetadata(health));
|
|
@@ -7361,15 +7431,15 @@ function renderUpdateNotification(status = latestUpdateStatus, { force = false }
|
|
|
7361
7431
|
if (elements.updateNotificationMessage) {
|
|
7362
7432
|
let message = "Updates are available. Direct Web UI updates are only enabled from localhost on the host machine.";
|
|
7363
7433
|
if (canRunUpdate) {
|
|
7364
|
-
if (hasPiUpdate && hasPackageUpdate) message = "
|
|
7365
|
-
else if (hasPackageUpdate) message = "
|
|
7366
|
-
else message = "
|
|
7434
|
+
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.";
|
|
7435
|
+
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.";
|
|
7436
|
+
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
7437
|
}
|
|
7368
7438
|
elements.updateNotificationMessage.textContent = message;
|
|
7369
7439
|
}
|
|
7370
7440
|
const details = [
|
|
7371
7441
|
items.join(" · "),
|
|
7372
|
-
latestUpdateStatus.webuiDev && latestUpdateStatus.webui?.updateAvailable ? "The current Web UI is a
|
|
7442
|
+
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
7443
|
latestUpdateStatus.packages?.note || "",
|
|
7374
7444
|
].filter(Boolean).join(" ");
|
|
7375
7445
|
if (elements.updateNotificationDetail) elements.updateNotificationDetail.textContent = details;
|
|
@@ -7393,6 +7463,7 @@ async function refreshUpdateStatus({ force = false, notify = true } = {}) {
|
|
|
7393
7463
|
const path = force ? "/api/update-status?refresh=1" : "/api/update-status";
|
|
7394
7464
|
const response = await api(path, { scoped: false });
|
|
7395
7465
|
latestUpdateStatus = response.data || null;
|
|
7466
|
+
if (latestUpdateStatus?.pi?.currentVersion) setPiVersion(latestUpdateStatus.pi.currentVersion);
|
|
7396
7467
|
if (notify) renderUpdateNotification(latestUpdateStatus);
|
|
7397
7468
|
renderComponentUpdateIndicators();
|
|
7398
7469
|
renderComponentUpdateDialogs();
|
|
@@ -7458,7 +7529,7 @@ function componentUpdateStatusText(target) {
|
|
|
7458
7529
|
if (job?.state === "succeeded") {
|
|
7459
7530
|
const activation = target === "pi"
|
|
7460
7531
|
? "New or reloaded Pi sessions use the update; already-running tabs keep their current runtime until restarted."
|
|
7461
|
-
: "
|
|
7532
|
+
: "The managed Web UI runtime was activated automatically; the browser reconnects after the verified restart.";
|
|
7462
7533
|
return { text: `${job.message || `${label} update completed.`} ${activation}`, level: "success" };
|
|
7463
7534
|
}
|
|
7464
7535
|
if (job?.state === "failed") {
|
|
@@ -7531,13 +7602,20 @@ function syncComponentUpdatePolling() {
|
|
|
7531
7602
|
}
|
|
7532
7603
|
}
|
|
7533
7604
|
|
|
7605
|
+
function separatePathPiPlanNotice(plan) {
|
|
7606
|
+
const identities = Array.isArray(plan?.identities) ? plan.identities : [];
|
|
7607
|
+
const activePi = identities.find((identity) => identity?.kind === "pi" && identity.source !== "path");
|
|
7608
|
+
const pathPi = identities.find((identity) => identity?.kind === "pi" && identity.source === "path" && identity.canonicalId !== activePi?.canonicalId);
|
|
7609
|
+
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.` : "";
|
|
7610
|
+
}
|
|
7611
|
+
|
|
7534
7612
|
function componentUpdateConfirmationText(target) {
|
|
7535
7613
|
const pkg = latestUpdateStatus?.[target] || {};
|
|
7536
7614
|
const versionText = pkg.updateAvailable ? `\n\nDetected update: ${packageUpdateText(componentUpdateLabel(target), pkg)}.` : "";
|
|
7537
7615
|
if (target === "pi") {
|
|
7538
|
-
return `
|
|
7616
|
+
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
7617
|
}
|
|
7540
|
-
return `
|
|
7618
|
+
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
7619
|
}
|
|
7542
7620
|
|
|
7543
7621
|
async function startComponentUpdate(target) {
|
|
@@ -7550,17 +7628,28 @@ async function startComponentUpdate(target) {
|
|
|
7550
7628
|
renderComponentUpdateDialogs();
|
|
7551
7629
|
return;
|
|
7552
7630
|
}
|
|
7553
|
-
|
|
7554
|
-
|
|
7555
|
-
|
|
7631
|
+
let plan;
|
|
7632
|
+
try {
|
|
7633
|
+
plan = (await api("/api/update/plan", { method: "POST", body: { targets: [target] }, scoped: false }))?.data?.plan;
|
|
7634
|
+
} catch (error) {
|
|
7635
|
+
addEvent(error.message || String(error), "error");
|
|
7636
|
+
return;
|
|
7637
|
+
}
|
|
7638
|
+
const planNotice = separatePathPiPlanNotice(plan);
|
|
7639
|
+
const confirmed = await appConfirmText(`${componentUpdateConfirmationText(target)}${planNotice ? `\n\n${planNotice}` : ""}\n\nExact plan digest: ${plan.digest}`, {
|
|
7640
|
+
affected: target === "pi" ? "The verified active Pi installation on the Web UI host" : "A side-by-side managed Web UI runtime",
|
|
7641
|
+
confirmLabel: job?.state === "failed" ? `Retry ${label} update` : `Apply exact ${label} plan`,
|
|
7556
7642
|
danger: false,
|
|
7557
7643
|
});
|
|
7558
7644
|
if (!confirmed) return;
|
|
7559
7645
|
componentUpdateStartInProgress = true;
|
|
7560
7646
|
renderComponentUpdateDialogs();
|
|
7561
7647
|
try {
|
|
7562
|
-
const response = await api("/api/
|
|
7563
|
-
const
|
|
7648
|
+
const response = await api("/api/update/apply", { method: "POST", body: { transactionId: plan.transactionId, planDigest: plan.digest }, scoped: false });
|
|
7649
|
+
const acceptedState = ["applying", "verifying", "activating"].includes(response?.data?.state)
|
|
7650
|
+
? "running"
|
|
7651
|
+
: response?.data?.outcome === "success" ? "succeeded" : "failed";
|
|
7652
|
+
const accepted = { target, state: acceptedState, canStart: false, message: `Exact ${label} update ${response?.data?.state || response?.data?.outcome || "accepted"}.`, receipts: response?.data?.receipts || [] };
|
|
7564
7653
|
if (accepted && typeof accepted === "object") {
|
|
7565
7654
|
latestUpdateStatus = {
|
|
7566
7655
|
...(latestUpdateStatus || {}),
|
|
@@ -7599,14 +7688,16 @@ function initializeUpdateNotifications() {
|
|
|
7599
7688
|
}, UPDATE_STATUS_INITIAL_DELAY_MS);
|
|
7600
7689
|
}
|
|
7601
7690
|
|
|
7602
|
-
function piUpdateConfirmationText({ all = false } = {}) {
|
|
7691
|
+
function piUpdateConfirmationText({ all = false, plan = null } = {}) {
|
|
7603
7692
|
const items = updateNotificationItems();
|
|
7604
7693
|
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
7694
|
const versionText = items.length ? `\n\nDetected update: ${items.join(" · ")}.` : "";
|
|
7606
|
-
const
|
|
7607
|
-
const
|
|
7608
|
-
const
|
|
7609
|
-
|
|
7695
|
+
const scope = all ? "the verified active Pi and Web UI targets" : "the verified active Pi target";
|
|
7696
|
+
const refusals = Array.isArray(plan?.refusals) && plan.refusals.length ? `\n\nRefused automatic targets: ${plan.refusals.map((item) => `${item.id}: ${item.guidance}`).join(" · ")}` : "";
|
|
7697
|
+
const separatePathPi = separatePathPiPlanNotice(plan);
|
|
7698
|
+
const pathNotice = separatePathPi ? `\n\n${separatePathPi}` : "";
|
|
7699
|
+
const digest = plan?.digest ? `\n\nExact immutable plan digest: ${plan.digest}` : "";
|
|
7700
|
+
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
7701
|
}
|
|
7611
7702
|
|
|
7612
7703
|
async function runPiUpdateAndRestart({ all = false } = {}) {
|
|
@@ -7616,16 +7707,23 @@ async function runPiUpdateAndRestart({ all = false } = {}) {
|
|
|
7616
7707
|
renderUpdateNotification(latestUpdateStatus, { force: true });
|
|
7617
7708
|
return;
|
|
7618
7709
|
}
|
|
7619
|
-
|
|
7710
|
+
let plan;
|
|
7711
|
+
try {
|
|
7712
|
+
plan = (await api("/api/update/plan", { method: "POST", body: { targets: all ? ["pi", "webui"] : ["pi"] }, scoped: false }))?.data?.plan;
|
|
7713
|
+
} catch (error) {
|
|
7714
|
+
addEvent(error.message || String(error), "error");
|
|
7715
|
+
return;
|
|
7716
|
+
}
|
|
7717
|
+
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
7718
|
|
|
7621
|
-
const updateLabel = all ? "Pi and
|
|
7719
|
+
const updateLabel = all ? "Pi and Web UI exact updates" : "Pi exact update";
|
|
7622
7720
|
updateRequestInProgress = true;
|
|
7623
7721
|
hideUpdateNotification();
|
|
7624
7722
|
setServerActionBusy("Updating…");
|
|
7625
7723
|
setServerActionStatus(`Running ${updateLabel}. The server will restart after the update completes…`, "warn");
|
|
7626
7724
|
setServerRestartOverlay(true, `Running ${updateLabel}. The server will restart after the update completes…`);
|
|
7627
7725
|
try {
|
|
7628
|
-
await api(
|
|
7726
|
+
await api("/api/update/apply", { method: "POST", body: { transactionId: plan.transactionId, planDigest: plan.digest }, scoped: false });
|
|
7629
7727
|
addEvent(`${updateLabel} completed; Pi Web UI server restart requested`, "warn");
|
|
7630
7728
|
} catch (error) {
|
|
7631
7729
|
if (!error?.backendOffline) {
|
|
@@ -7642,7 +7740,7 @@ async function runPiUpdateAndRestart({ all = false } = {}) {
|
|
|
7642
7740
|
}
|
|
7643
7741
|
|
|
7644
7742
|
setBackendOffline(true, new Error("update requested from side panel"));
|
|
7645
|
-
const restarted = await waitForServerRestart();
|
|
7743
|
+
const restarted = await waitForServerRestart(serverBootIdentity);
|
|
7646
7744
|
updateRequestInProgress = false;
|
|
7647
7745
|
resetServerActionControls();
|
|
7648
7746
|
if (restarted) {
|
|
@@ -8835,7 +8933,7 @@ function conversationModeCommandName() {
|
|
|
8835
8933
|
}
|
|
8836
8934
|
|
|
8837
8935
|
function conversationModeButtonLabel(mode = activeConversationMode()) {
|
|
8838
|
-
return mode.enabled ? "End Conversation" : "Start Conversation";
|
|
8936
|
+
return mode.enabled ? "End Conversation" : "Start Natural Conversation";
|
|
8839
8937
|
}
|
|
8840
8938
|
|
|
8841
8939
|
function conversationModePartialPreview(text = "") {
|
|
@@ -9461,6 +9559,12 @@ function setOptionalFeatureDisabled(featureId, disabled) {
|
|
|
9461
9559
|
clearGitFooterWebuiPayloadCache();
|
|
9462
9560
|
for (const tabId of new Set([...gitFooterPayloadStateByTab.keys(), ...gitFooterPayloadSettlementTimersByTab.keys(), ...gitFooterPayloadRefreshInFlightByTab])) clearGitFooterPayloadState(tabId);
|
|
9463
9561
|
}
|
|
9562
|
+
if (featureId === "featureSystemPrompt") {
|
|
9563
|
+
if (disabled) {
|
|
9564
|
+
for (const tabId of new Set([...featureCategoryByTab.keys(), ...featureDecisionOutputByTab.keys()])) clearFeatureDecisionStateForTab(tabId);
|
|
9565
|
+
}
|
|
9566
|
+
renderFeatureCategoryTag();
|
|
9567
|
+
}
|
|
9464
9568
|
if (featureId === "btwCommand") {
|
|
9465
9569
|
statusEntries.delete(BTW_WEBUI_STATUS_KEY);
|
|
9466
9570
|
widgets.delete(BTW_OUTPUT_WIDGET_KEY);
|
|
@@ -10572,6 +10676,7 @@ function resetFileTreeState() {
|
|
|
10572
10676
|
fileTreeSearchTimer = null;
|
|
10573
10677
|
fileTreeSearchRequestSerial += 1;
|
|
10574
10678
|
fileTreeState = emptyFileTreeState(fileTreeState.requestSerial + 1);
|
|
10679
|
+
fileTreeLastRenderSignature = "";
|
|
10575
10680
|
if (elements.fileTreeSearchInput) elements.fileTreeSearchInput.value = "";
|
|
10576
10681
|
updateFileTreeSearchControls();
|
|
10577
10682
|
renderFileTree();
|
|
@@ -10592,10 +10697,47 @@ function fileTreeControlKey(node) {
|
|
|
10592
10697
|
return node?.classList?.contains("file-tree-item") && path ? `file-tree:${path}` : "";
|
|
10593
10698
|
}
|
|
10594
10699
|
|
|
10700
|
+
function fileTreeEntryRenderSignature(entry = {}) {
|
|
10701
|
+
return [
|
|
10702
|
+
normalizeFileTreePath(entry.path || ""),
|
|
10703
|
+
String(entry.name || ""),
|
|
10704
|
+
String(entry.type || ""),
|
|
10705
|
+
entry.directory === true,
|
|
10706
|
+
String(entry.extension || ""),
|
|
10707
|
+
String(entry.error || ""),
|
|
10708
|
+
];
|
|
10709
|
+
}
|
|
10710
|
+
|
|
10711
|
+
function fileTreeRenderSignature() {
|
|
10712
|
+
const entriesByPath = [...fileTreeState.entriesByPath.entries()]
|
|
10713
|
+
.map(([path, entries]) => [normalizeFileTreePath(path), (Array.isArray(entries) ? entries : []).map(fileTreeEntryRenderSignature)])
|
|
10714
|
+
.sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
|
|
10715
|
+
const gitStatusByPath = [...fileTreeState.gitStatusByPath.entries()]
|
|
10716
|
+
.map(([path, status]) => [normalizeFileTreePath(path), normalizeFileTreeGitStatus(status)])
|
|
10717
|
+
.sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
|
|
10718
|
+
return JSON.stringify({
|
|
10719
|
+
context: `${activeTabId || ""}:${activeTabGeneration}`,
|
|
10720
|
+
root: fileTreeState.root || "",
|
|
10721
|
+
displayCwd: fileTreeState.root || latestWorkspace?.displayCwd || activeTab()?.cwd || "",
|
|
10722
|
+
entriesByPath,
|
|
10723
|
+
expanded: [...fileTreeState.expanded].map(normalizeFileTreePath).sort(),
|
|
10724
|
+
loading: [...fileTreeState.loading].map(normalizeFileTreePath).sort(),
|
|
10725
|
+
selectedPath: normalizeFileTreePath(fileTreeState.selectedPath || ""),
|
|
10726
|
+
searchQuery: fileTreeState.searchQuery || fileTreeSearchQueryText(),
|
|
10727
|
+
searchEntries: fileTreeState.searchEntries.map(fileTreeEntryRenderSignature),
|
|
10728
|
+
searchLoading: fileTreeState.searchLoading,
|
|
10729
|
+
gitStatusRoot: fileTreeState.gitStatusRoot || "",
|
|
10730
|
+
gitStatusByPath,
|
|
10731
|
+
});
|
|
10732
|
+
}
|
|
10733
|
+
|
|
10595
10734
|
function renderFileTree() {
|
|
10596
10735
|
if (deferUiRenderDuringPointerActivation("file-tree", renderFileTree)) return;
|
|
10597
10736
|
const root = elements.fileTreeRoot;
|
|
10598
10737
|
if (!root) return;
|
|
10738
|
+
const renderSignature = fileTreeRenderSignature();
|
|
10739
|
+
if (renderSignature === fileTreeLastRenderSignature) return;
|
|
10740
|
+
fileTreeLastRenderSignature = renderSignature;
|
|
10599
10741
|
const continuityContextKey = `${activeTabId || ""}:${activeTabGeneration}:${fileTreeState.root || ""}`;
|
|
10600
10742
|
const focusSnapshot = captureScopedControlContinuity(root, continuityContextKey, fileTreeControlKey);
|
|
10601
10743
|
const restoreFocus = () => restoreScopedControlContinuity(root, continuityContextKey, focusSnapshot, (key) => [...root.querySelectorAll(".file-tree-item[data-path]")].find((node) => fileTreeControlKey(node) === key));
|
|
@@ -10792,7 +10934,7 @@ function appendFileTreeEntry(parent, entry, depth = 0) {
|
|
|
10792
10934
|
parent.append(item);
|
|
10793
10935
|
}
|
|
10794
10936
|
|
|
10795
|
-
async function loadFileTreeDirectory(path = FILE_TREE_ROOT_PATH, { force = false } = {}) {
|
|
10937
|
+
async function loadFileTreeDirectory(path = FILE_TREE_ROOT_PATH, { force = false, renderResult = true } = {}) {
|
|
10796
10938
|
const normalized = normalizeFileTreePath(path);
|
|
10797
10939
|
if (!force && fileTreeState.entriesByPath.has(normalized)) return fileTreeState.entriesByPath.get(normalized);
|
|
10798
10940
|
const tabContext = activeTabContext();
|
|
@@ -10800,8 +10942,10 @@ async function loadFileTreeDirectory(path = FILE_TREE_ROOT_PATH, { force = false
|
|
|
10800
10942
|
const serial = ++fileTreeState.requestSerial;
|
|
10801
10943
|
const hadCachedEntries = fileTreeState.entriesByPath.has(normalized);
|
|
10802
10944
|
fileTreeState.loading.add(normalized);
|
|
10803
|
-
if (!hadCachedEntries)
|
|
10804
|
-
|
|
10945
|
+
if (!hadCachedEntries) {
|
|
10946
|
+
setFileTreeStatus(normalized ? `Loading ${normalized}…` : "Loading workspace files…");
|
|
10947
|
+
renderFileTree();
|
|
10948
|
+
}
|
|
10805
10949
|
try {
|
|
10806
10950
|
const response = await api(fileApiPath("/api/files", normalized), { tabId: tabContext.tabId });
|
|
10807
10951
|
if (!isCurrentTabContext(tabContext) || serial < fileTreeState.requestSerial) return [];
|
|
@@ -10826,7 +10970,7 @@ async function loadFileTreeDirectory(path = FILE_TREE_ROOT_PATH, { force = false
|
|
|
10826
10970
|
return [];
|
|
10827
10971
|
} finally {
|
|
10828
10972
|
fileTreeState.loading.delete(normalized);
|
|
10829
|
-
if (isCurrentTabContext(tabContext)) renderFileTree();
|
|
10973
|
+
if (renderResult && isCurrentTabContext(tabContext)) renderFileTree();
|
|
10830
10974
|
}
|
|
10831
10975
|
}
|
|
10832
10976
|
|
|
@@ -10847,7 +10991,7 @@ function clearFileTreeSearch({ focus = false } = {}) {
|
|
|
10847
10991
|
if (focus) elements.fileTreeSearchInput?.focus();
|
|
10848
10992
|
}
|
|
10849
10993
|
|
|
10850
|
-
async function runFileTreeSearch() {
|
|
10994
|
+
async function runFileTreeSearch({ background = false } = {}) {
|
|
10851
10995
|
clearTimeout(fileTreeSearchTimer);
|
|
10852
10996
|
fileTreeSearchTimer = null;
|
|
10853
10997
|
const query = fileTreeSearchQueryText();
|
|
@@ -10860,12 +11004,14 @@ async function runFileTreeSearch() {
|
|
|
10860
11004
|
const tabContext = activeTabContext();
|
|
10861
11005
|
if (!tabContext.tabId) return [];
|
|
10862
11006
|
fileTreeState.searchQuery = query;
|
|
10863
|
-
|
|
10864
|
-
|
|
10865
|
-
|
|
10866
|
-
|
|
10867
|
-
|
|
10868
|
-
|
|
11007
|
+
if (!background) {
|
|
11008
|
+
fileTreeState.searchLoading = true;
|
|
11009
|
+
fileTreeState.searchEntries = [];
|
|
11010
|
+
fileTreeState.searchTruncated = false;
|
|
11011
|
+
fileTreeState.searchTotal = 0;
|
|
11012
|
+
setFileTreeStatus(`Searching for “${query}”…`);
|
|
11013
|
+
renderFileTree();
|
|
11014
|
+
}
|
|
10869
11015
|
try {
|
|
10870
11016
|
const response = await api(fileSearchApiPath(query), { tabId: tabContext.tabId });
|
|
10871
11017
|
if (!isCurrentTabContext(tabContext) || serial !== fileTreeSearchRequestSerial) return [];
|
|
@@ -10882,8 +11028,10 @@ async function runFileTreeSearch() {
|
|
|
10882
11028
|
return entries;
|
|
10883
11029
|
} catch (error) {
|
|
10884
11030
|
if (isCurrentTabContext(tabContext) && serial === fileTreeSearchRequestSerial) {
|
|
10885
|
-
|
|
10886
|
-
|
|
11031
|
+
if (!background) {
|
|
11032
|
+
fileTreeState.searchLoading = false;
|
|
11033
|
+
fileTreeState.searchEntries = [];
|
|
11034
|
+
}
|
|
10887
11035
|
setFileTreeStatus(error.message || String(error), "error");
|
|
10888
11036
|
addEvent(`file search failed: ${error.message || String(error)}`, "error");
|
|
10889
11037
|
}
|
|
@@ -10930,7 +11078,7 @@ async function refreshLoadedFileTreeDirectories(tabContext = activeTabContext())
|
|
|
10930
11078
|
}
|
|
10931
11079
|
};
|
|
10932
11080
|
if (fileTreeState.loading.has(FILE_TREE_ROOT_PATH)) return true;
|
|
10933
|
-
await loadFileTreeDirectory(FILE_TREE_ROOT_PATH, { force: true });
|
|
11081
|
+
await loadFileTreeDirectory(FILE_TREE_ROOT_PATH, { force: true, renderResult: false });
|
|
10934
11082
|
if (!isCurrentTabContext(tabContext)) return false;
|
|
10935
11083
|
collectDirectories(FILE_TREE_ROOT_PATH);
|
|
10936
11084
|
const cachedDirectories = [...fileTreeState.entriesByPath.keys()]
|
|
@@ -10948,7 +11096,7 @@ async function refreshLoadedFileTreeDirectories(tabContext = activeTabContext())
|
|
|
10948
11096
|
collectDirectories(path);
|
|
10949
11097
|
continue;
|
|
10950
11098
|
}
|
|
10951
|
-
await loadFileTreeDirectory(path, { force: true });
|
|
11099
|
+
await loadFileTreeDirectory(path, { force: true, renderResult: false });
|
|
10952
11100
|
if (!isCurrentTabContext(tabContext)) return false;
|
|
10953
11101
|
collectDirectories(path);
|
|
10954
11102
|
}
|
|
@@ -10972,7 +11120,7 @@ async function refreshFileTreeLive(tabContext = activeTabContext()) {
|
|
|
10972
11120
|
while (refreshContext && isCurrentTabContext(refreshContext)) {
|
|
10973
11121
|
fileTreeLiveRefreshPendingContext = null;
|
|
10974
11122
|
let skippedLoadingDirectory = false;
|
|
10975
|
-
if (fileTreeSearchQueryText()) await runFileTreeSearch();
|
|
11123
|
+
if (fileTreeSearchQueryText()) await runFileTreeSearch({ background: true });
|
|
10976
11124
|
else skippedLoadingDirectory = await refreshLoadedFileTreeDirectories(refreshContext);
|
|
10977
11125
|
if (skippedLoadingDirectory && isCurrentTabContext(refreshContext)) retryContext = refreshContext;
|
|
10978
11126
|
refreshContext = fileTreeLiveRefreshPendingContext;
|
|
@@ -11476,6 +11624,7 @@ const UI_LAYOUT_SAVE_DEBOUNCE_MS = 250;
|
|
|
11476
11624
|
const UI_LAYOUT_MAX_CONFLICT_RETRIES = 1;
|
|
11477
11625
|
const UI_LAYOUT_FIELDS = ["sidePanel", "composerActions", "footerScopedModelOrder", "terminalTabs", "fileViewerWidth"];
|
|
11478
11626
|
const UI_LAYOUT_SIDE_PANEL_FIELDS = ["sectionOrder", "collapsedSectionIds", "hiddenSectionIds", "collapsed"];
|
|
11627
|
+
const REMOVED_SIDE_PANEL_SECTION_HEIGHT_STORAGE_KEY = "pi-webui-side-panel-section-heights-v1";
|
|
11479
11628
|
const UI_LAYOUT_COMPOSER_FIELDS = ["order", "grid"];
|
|
11480
11629
|
const UI_LAYOUT_TERMINAL_FIELDS = ["layout", "customGroups"];
|
|
11481
11630
|
const UI_LAYOUT_PENDING_STORAGE_PREFIX = "pi-webui-ui-layout-pending-v3:";
|
|
@@ -11711,6 +11860,19 @@ function removeDurableUiLayoutPendingMutation(key) {
|
|
|
11711
11860
|
}
|
|
11712
11861
|
}
|
|
11713
11862
|
|
|
11863
|
+
function clearRemovedSidePanelSectionHeightState() {
|
|
11864
|
+
try {
|
|
11865
|
+
localStorage.removeItem(REMOVED_SIDE_PANEL_SECTION_HEIGHT_STORAGE_KEY);
|
|
11866
|
+
} catch {
|
|
11867
|
+
// Removed layout state may remain when browser storage is unavailable.
|
|
11868
|
+
}
|
|
11869
|
+
for (const record of durableUiLayoutPendingMutationRecords()) {
|
|
11870
|
+
if (record.field === "sidePanel" && record.subfield === "sectionHeights") {
|
|
11871
|
+
removeDurableUiLayoutPendingMutation(record.key);
|
|
11872
|
+
}
|
|
11873
|
+
}
|
|
11874
|
+
}
|
|
11875
|
+
|
|
11714
11876
|
function clearAcknowledgedDurableUiLayoutPendingMutations(snapshot) {
|
|
11715
11877
|
for (const entry of snapshot.values()) {
|
|
11716
11878
|
if (entry.subfieldMutationIds?.size) {
|
|
@@ -11934,6 +12096,8 @@ function applyDurableUiLayoutSnapshot(data, { generations = null, readEpoch = 0
|
|
|
11934
12096
|
const subfields = durableUiLayoutSubFields(field);
|
|
11935
12097
|
const dirtySubfields = dirtyEntry?.subfields;
|
|
11936
12098
|
|
|
12099
|
+
if (field === "sidePanel" && durableUiLayoutInteractionActive(field)) continue;
|
|
12100
|
+
|
|
11937
12101
|
if (subfields && field !== "composerActions") {
|
|
11938
12102
|
const applicable = {};
|
|
11939
12103
|
let hasApplicable = false;
|
|
@@ -14902,6 +15066,7 @@ async function switchTab(tabId) {
|
|
|
14902
15066
|
} else {
|
|
14903
15067
|
renderSubagentLaunchSlots();
|
|
14904
15068
|
}
|
|
15069
|
+
refreshSamplingParametersForTabContext(tabContext);
|
|
14905
15070
|
}
|
|
14906
15071
|
|
|
14907
15072
|
function currentDirectoryForNewTab() {
|
|
@@ -15199,6 +15364,7 @@ async function initializeTabs() {
|
|
|
15199
15364
|
if (!subagentLaunchSlotDraftIsDirty() || subagentLaunchSlotConfigTabId !== activeTabId) {
|
|
15200
15365
|
loadSubagentLaunchSlotConfig().catch(() => {});
|
|
15201
15366
|
}
|
|
15367
|
+
refreshSamplingParametersForTabContext(tabContext);
|
|
15202
15368
|
await refreshThemeCatalog(tabContext).catch((error) => addEvent(`Custom theme catalog refresh failed: ${error.message || String(error)}`, "warn"));
|
|
15203
15369
|
}
|
|
15204
15370
|
}
|
|
@@ -16600,6 +16766,7 @@ function setGitFooterVisibilitySelection(checked) {
|
|
|
16600
16766
|
function openGitFooterVisibilityDialog() {
|
|
16601
16767
|
if (!elements.gitFooterVisibilityDialog) return;
|
|
16602
16768
|
setOptionsMenuOpen(false);
|
|
16769
|
+
closeGitFooterContextMenu({ returnFocus: false });
|
|
16603
16770
|
hideFooterTooltip();
|
|
16604
16771
|
gitFooterVisibilityDirty = false;
|
|
16605
16772
|
renderGitFooterVisibilityDialog();
|
|
@@ -16613,6 +16780,65 @@ function closeGitFooterVisibilityDialog() {
|
|
|
16613
16780
|
if (elements.gitFooterVisibilityDialog?.open) elements.gitFooterVisibilityDialog.close();
|
|
16614
16781
|
}
|
|
16615
16782
|
|
|
16783
|
+
function closeGitFooterContextMenu({ returnFocus = true } = {}) {
|
|
16784
|
+
const trigger = gitFooterContextMenuState?.trigger;
|
|
16785
|
+
gitFooterContextMenuState = null;
|
|
16786
|
+
if (elements.gitFooterContextMenu) elements.gitFooterContextMenu.hidden = true;
|
|
16787
|
+
if (returnFocus && trigger?.isConnected) queueMicrotask(() => trigger.focus?.({ preventScroll: true }));
|
|
16788
|
+
}
|
|
16789
|
+
|
|
16790
|
+
function showGitFooterContextMenu(event, chip, trigger) {
|
|
16791
|
+
const menu = elements.gitFooterContextMenu;
|
|
16792
|
+
const key = cleanStatusText(chip?.key);
|
|
16793
|
+
if (!menu || !key) return;
|
|
16794
|
+
event.preventDefault();
|
|
16795
|
+
event.stopPropagation();
|
|
16796
|
+
closeFileContextMenu({ returnFocus: false });
|
|
16797
|
+
closeGitPanelContextMenu({ returnFocus: false });
|
|
16798
|
+
closeSidePanelContextMenu({ returnFocus: false });
|
|
16799
|
+
closeGitFooterContextMenu({ returnFocus: false });
|
|
16800
|
+
hideFooterTooltip();
|
|
16801
|
+
|
|
16802
|
+
const label = cleanStatusText(chip?.label) || gitFooterVisibilityLabel(key);
|
|
16803
|
+
gitFooterContextMenuState = { key, label, trigger };
|
|
16804
|
+
const disableButton = menu.querySelector('[data-git-footer-menu-action="disable"]');
|
|
16805
|
+
if (disableButton) disableButton.textContent = `Disable ${label} box`;
|
|
16806
|
+
menu.hidden = false;
|
|
16807
|
+
const rect = menu.getBoundingClientRect();
|
|
16808
|
+
const left = Math.min(event.clientX, Math.max(8, window.innerWidth - rect.width - 8));
|
|
16809
|
+
const top = Math.min(event.clientY, Math.max(8, window.innerHeight - rect.height - 8));
|
|
16810
|
+
menu.style.left = `${Math.max(8, left)}px`;
|
|
16811
|
+
menu.style.top = `${Math.max(8, top)}px`;
|
|
16812
|
+
menu.querySelector('[role="menuitem"]')?.focus({ preventScroll: true });
|
|
16813
|
+
}
|
|
16814
|
+
|
|
16815
|
+
function bindGitFooterContextMenu(node, chip) {
|
|
16816
|
+
if (!node || !chip?.key) return node;
|
|
16817
|
+
node.setAttribute("aria-keyshortcuts", "ContextMenu Shift+F10");
|
|
16818
|
+
node.addEventListener("contextmenu", (event) => showGitFooterContextMenu(event, chip, node));
|
|
16819
|
+
node.addEventListener("keydown", (event) => {
|
|
16820
|
+
if (event.key !== "ContextMenu" && !(event.shiftKey && event.key === "F10")) return;
|
|
16821
|
+
const rect = node.getBoundingClientRect();
|
|
16822
|
+
showGitFooterContextMenu({
|
|
16823
|
+
preventDefault: () => event.preventDefault(),
|
|
16824
|
+
stopPropagation: () => event.stopPropagation(),
|
|
16825
|
+
clientX: rect.left + Math.min(rect.width, 24),
|
|
16826
|
+
clientY: rect.bottom,
|
|
16827
|
+
}, chip, node);
|
|
16828
|
+
});
|
|
16829
|
+
return node;
|
|
16830
|
+
}
|
|
16831
|
+
|
|
16832
|
+
async function disableGitFooterContextChip(key, label) {
|
|
16833
|
+
try {
|
|
16834
|
+
await runGitFooterVisibilityCommand("hide", [key]);
|
|
16835
|
+
addEvent(`Disabled the ${label || key} Git footer box.`, "success");
|
|
16836
|
+
requestGitFooterWebuiPayload(activeTabContext(), { force: true, allowDuringRun: true });
|
|
16837
|
+
} catch (error) {
|
|
16838
|
+
addEvent(error.message || String(error), "error");
|
|
16839
|
+
}
|
|
16840
|
+
}
|
|
16841
|
+
|
|
16616
16842
|
function cleanFooterPayloadText(value, fallback = "", maxLength = 240) {
|
|
16617
16843
|
const text = cleanStatusText(value).slice(0, maxLength);
|
|
16618
16844
|
return text || fallback;
|
|
@@ -17000,7 +17226,7 @@ function renderGitFooterPayloadMetric(chip, payload) {
|
|
|
17000
17226
|
const node = footerMetric(chip.icon || "•", chip.label, chip.value, chip.tone ? `tone-${chip.tone}` : "", options);
|
|
17001
17227
|
if (chip.contextUsage) applyFooterContextUsage(node, chip.contextUsage);
|
|
17002
17228
|
if (chip.usageWindows) applyFooterUsageWindows(node, chip.usageWindows);
|
|
17003
|
-
return node;
|
|
17229
|
+
return bindGitFooterContextMenu(node, chip);
|
|
17004
17230
|
}
|
|
17005
17231
|
|
|
17006
17232
|
function gitFooterSyncCounts(value) {
|
|
@@ -17168,7 +17394,7 @@ function renderGitFooterPayloadMeta(chip, tab, payload) {
|
|
|
17168
17394
|
}
|
|
17169
17395
|
if (chip.contextUsage) applyFooterContextUsage(node, chip.contextUsage);
|
|
17170
17396
|
if (chip.usageWindows) applyFooterUsageWindows(node, chip.usageWindows);
|
|
17171
|
-
return node;
|
|
17397
|
+
return bindGitFooterContextMenu(node, chip);
|
|
17172
17398
|
}
|
|
17173
17399
|
|
|
17174
17400
|
// Shape key for a footer chip with the frequently-changing fields removed, so
|
|
@@ -17312,6 +17538,7 @@ function renderGitFooterPayload(payload) {
|
|
|
17312
17538
|
return;
|
|
17313
17539
|
}
|
|
17314
17540
|
|
|
17541
|
+
closeGitFooterContextMenu({ returnFocus: false });
|
|
17315
17542
|
elements.statusBar.replaceChildren();
|
|
17316
17543
|
elements.statusBar.classList.remove("statusbar-tui-footer");
|
|
17317
17544
|
elements.statusBar.classList.add("statusbar-git-footer");
|
|
@@ -23412,6 +23639,499 @@ function initializeSubagentLaunchSlots() {
|
|
|
23412
23639
|
if (activeTabId) loadSubagentLaunchSlotConfig().catch(() => {});
|
|
23413
23640
|
}
|
|
23414
23641
|
|
|
23642
|
+
function samplingParametersPath(tabId) {
|
|
23643
|
+
return `/api/tabs/${encodeURIComponent(tabId)}/sampling-parameters`;
|
|
23644
|
+
}
|
|
23645
|
+
|
|
23646
|
+
const samplingParameterControlElements = new Map();
|
|
23647
|
+
let samplingParameterTooltipDismissalInstalled = false;
|
|
23648
|
+
|
|
23649
|
+
function samplingParameterTooltipBoundary(row) {
|
|
23650
|
+
const viewportHeight = globalThis.innerHeight || document.documentElement?.clientHeight || 0;
|
|
23651
|
+
const clippingRects = [row?.closest?.(".side-panel-section-content"), row?.closest?.(".side-panel-body")]
|
|
23652
|
+
.map((node) => node?.getBoundingClientRect?.())
|
|
23653
|
+
.filter(Boolean);
|
|
23654
|
+
return {
|
|
23655
|
+
top: Math.max(8, ...clippingRects.map((rect) => rect.top)),
|
|
23656
|
+
bottom: Math.min(viewportHeight - 8, ...clippingRects.map((rect) => rect.bottom)),
|
|
23657
|
+
};
|
|
23658
|
+
}
|
|
23659
|
+
|
|
23660
|
+
function updateSamplingParameterTooltipPlacement(row, tooltip) {
|
|
23661
|
+
if (!row?.classList.contains("unsupported") || tooltip?.hidden || !row.getBoundingClientRect || !tooltip.getBoundingClientRect) return;
|
|
23662
|
+
tooltip.classList.remove("sampling-tooltip-below");
|
|
23663
|
+
tooltip.style?.removeProperty("--sampling-tooltip-max-height");
|
|
23664
|
+
const rowRect = row.getBoundingClientRect();
|
|
23665
|
+
const naturalHeight = Math.max(tooltip.scrollHeight || 0, tooltip.getBoundingClientRect().height || 0);
|
|
23666
|
+
const boundary = samplingParameterTooltipBoundary(row);
|
|
23667
|
+
const spaceAbove = Math.max(0, rowRect.top - boundary.top - 6);
|
|
23668
|
+
const spaceBelow = Math.max(0, boundary.bottom - rowRect.bottom - 6);
|
|
23669
|
+
const placeBelow = spaceAbove < naturalHeight && spaceBelow > spaceAbove;
|
|
23670
|
+
const availableHeight = placeBelow ? spaceBelow : spaceAbove;
|
|
23671
|
+
tooltip.classList.toggle("sampling-tooltip-below", placeBelow);
|
|
23672
|
+
tooltip.style?.setProperty("--sampling-tooltip-max-height", `${Math.floor(availableHeight)}px`);
|
|
23673
|
+
}
|
|
23674
|
+
|
|
23675
|
+
function resetSamplingParameterTooltip(row, tooltip) {
|
|
23676
|
+
row?.classList.remove("sampling-tooltip-dismissed");
|
|
23677
|
+
updateSamplingParameterTooltipPlacement(row, tooltip);
|
|
23678
|
+
}
|
|
23679
|
+
|
|
23680
|
+
function dismissSamplingParameterTooltip(row, event) {
|
|
23681
|
+
if (!row?.classList.contains("unsupported") || row.classList.contains("sampling-tooltip-dismissed")) return false;
|
|
23682
|
+
row.classList.add("sampling-tooltip-dismissed");
|
|
23683
|
+
event?.preventDefault?.();
|
|
23684
|
+
event?.stopPropagation?.();
|
|
23685
|
+
return true;
|
|
23686
|
+
}
|
|
23687
|
+
|
|
23688
|
+
function initializeSamplingParameterTooltipDismissal() {
|
|
23689
|
+
if (samplingParameterTooltipDismissalInstalled || typeof document.addEventListener !== "function") return;
|
|
23690
|
+
samplingParameterTooltipDismissalInstalled = true;
|
|
23691
|
+
document.addEventListener("keydown", (event) => {
|
|
23692
|
+
if (event.key !== "Escape" || event.target?.closest?.(".sampling-parameter-control.unsupported")) return;
|
|
23693
|
+
const hovered = document.querySelector?.(".sampling-parameter-control.unsupported:hover:not(.sampling-tooltip-dismissed)");
|
|
23694
|
+
if (hovered) dismissSamplingParameterTooltip(hovered, event);
|
|
23695
|
+
});
|
|
23696
|
+
}
|
|
23697
|
+
|
|
23698
|
+
function cloneSamplingControlDraft(draft) {
|
|
23699
|
+
return draft ? JSON.parse(JSON.stringify(draft)) : null;
|
|
23700
|
+
}
|
|
23701
|
+
|
|
23702
|
+
function samplingParametersBaseDraft(tabId = activeTabId) {
|
|
23703
|
+
if (!tabId || samplingParametersStateTabId !== tabId || !samplingParametersState) return null;
|
|
23704
|
+
return createSamplingControlDraft(samplingParametersState.session || {}, {
|
|
23705
|
+
defaults: samplingParametersState.defaults || {},
|
|
23706
|
+
});
|
|
23707
|
+
}
|
|
23708
|
+
|
|
23709
|
+
function samplingParametersDraft(tabId = activeTabId) {
|
|
23710
|
+
return tabId ? samplingParametersDrafts.get(tabId) ?? null : null;
|
|
23711
|
+
}
|
|
23712
|
+
|
|
23713
|
+
function setSamplingParametersDraft(draft, tabId = activeTabId) {
|
|
23714
|
+
if (!tabId) return;
|
|
23715
|
+
if (draft === null) samplingParametersDrafts.delete(tabId);
|
|
23716
|
+
else samplingParametersDrafts.set(tabId, cloneSamplingControlDraft(draft));
|
|
23717
|
+
}
|
|
23718
|
+
|
|
23719
|
+
function samplingParametersEditableDraft(tabId = activeTabId) {
|
|
23720
|
+
return samplingParametersDraft(tabId) || samplingParametersBaseDraft(tabId);
|
|
23721
|
+
}
|
|
23722
|
+
|
|
23723
|
+
// Drafts are keyed by Pi tab so background refreshes and tab switches cannot
|
|
23724
|
+
// overwrite or expose another session's unsaved controls.
|
|
23725
|
+
function samplingParametersDraftIsDirty(tabId = activeTabId) {
|
|
23726
|
+
const draft = samplingParametersDraft(tabId);
|
|
23727
|
+
if (!draft) return false;
|
|
23728
|
+
const baseline = samplingParametersBaseDraft(tabId);
|
|
23729
|
+
return !baseline || !samplingControlDraftEquals(draft, baseline);
|
|
23730
|
+
}
|
|
23731
|
+
|
|
23732
|
+
function samplingParametersSectionRecord() {
|
|
23733
|
+
return sidePanelSectionRecords().find(({ id }) => id === "sampling") || null;
|
|
23734
|
+
}
|
|
23735
|
+
|
|
23736
|
+
function samplingParametersSectionActive() {
|
|
23737
|
+
const record = samplingParametersSectionRecord();
|
|
23738
|
+
return !!record && !record.section.hidden && !record.section.classList.contains("collapsed");
|
|
23739
|
+
}
|
|
23740
|
+
|
|
23741
|
+
function samplingParametersSupportText() {
|
|
23742
|
+
const state = samplingParametersStateTabId === activeTabId ? samplingParametersState : null;
|
|
23743
|
+
const support = state?.support;
|
|
23744
|
+
if (!support) return samplingParametersLoading ? "Loading sampling support…" : "Select a running Pi tab to load sampling parameters.";
|
|
23745
|
+
const modelLabel = support.model?.provider && support.model?.id ? `(${support.model.provider}) ${support.model.id}` : "unknown model";
|
|
23746
|
+
const apiLabel = support.api || "unknown API";
|
|
23747
|
+
if (support.supported) return `${modelLabel} · ${apiLabel} · ${support.message || "Sampling parameters apply to subsequent provider requests."}`;
|
|
23748
|
+
const compatible = Array.isArray(support.compatibleApis) && support.compatibleApis.length
|
|
23749
|
+
? ` Sampling-capable APIs: ${support.compatibleApis.join(", ")}.`
|
|
23750
|
+
: "";
|
|
23751
|
+
return `${modelLabel} · ${apiLabel} · ${support.message || "Sampling parameters are stored but not applied."}${compatible}`;
|
|
23752
|
+
}
|
|
23753
|
+
|
|
23754
|
+
// Success and error text describes one tab's last action, so it is suppressed as soon
|
|
23755
|
+
// as another tab becomes active instead of leaking into the new tab's status line.
|
|
23756
|
+
function samplingParametersFeedbackIsCurrent() {
|
|
23757
|
+
return samplingParametersFeedbackTabId === activeTabId;
|
|
23758
|
+
}
|
|
23759
|
+
|
|
23760
|
+
function setSamplingParametersFeedback({ error = "", notice = "" } = {}) {
|
|
23761
|
+
samplingParametersError = error;
|
|
23762
|
+
samplingParametersNotice = notice;
|
|
23763
|
+
samplingParametersFeedbackTabId = error || notice ? activeTabId : null;
|
|
23764
|
+
}
|
|
23765
|
+
|
|
23766
|
+
function samplingParametersStatusText({ dirty, unsupported, validation, loadedForActiveTab }) {
|
|
23767
|
+
const feedbackCurrent = samplingParametersFeedbackIsCurrent();
|
|
23768
|
+
if (samplingParametersError && feedbackCurrent) return samplingParametersError;
|
|
23769
|
+
if (samplingParametersBusy) return "Applying sampling parameters…";
|
|
23770
|
+
if (samplingParametersLoading) return "Loading session sampling parameters…";
|
|
23771
|
+
if (!activeTabId) return "Select a running Pi tab to edit sampling parameters.";
|
|
23772
|
+
if (samplingParametersNotice && feedbackCurrent) return samplingParametersNotice;
|
|
23773
|
+
if (!loadedForActiveTab) return "Sampling parameters are not loaded for this tab.";
|
|
23774
|
+
if (!validation.valid) return Object.values(validation.errors)[0] || "Correct invalid sampling values before applying.";
|
|
23775
|
+
if (unsupported) return "This model has no verified sampling parameters, so applying them is disabled.";
|
|
23776
|
+
if (dirty) return "Unsaved controls · Apply stores enabled values for this session only.";
|
|
23777
|
+
return "Saved for this Pi session · unchecked parameters inherit model defaults.";
|
|
23778
|
+
}
|
|
23779
|
+
|
|
23780
|
+
function samplingParameterCapabilities(state) {
|
|
23781
|
+
return Object.fromEntries(SAMPLING_PARAMETER_CATALOG.map(({ key }) => [
|
|
23782
|
+
key,
|
|
23783
|
+
samplingParameterCapability(state?.support?.parameters, key),
|
|
23784
|
+
]));
|
|
23785
|
+
}
|
|
23786
|
+
|
|
23787
|
+
function samplingParameterDomId(key, suffix) {
|
|
23788
|
+
return `samplingParameter${key.split("_").map((part) => part[0].toUpperCase() + part.slice(1)).join("")}${suffix}`;
|
|
23789
|
+
}
|
|
23790
|
+
|
|
23791
|
+
function samplingParameterDisplayValue(parameters, key) {
|
|
23792
|
+
if (!parameters || typeof parameters !== "object" || !Object.hasOwn(parameters, key)) return "Inherited";
|
|
23793
|
+
const value = parameters[key];
|
|
23794
|
+
return typeof value === "number" && Number.isFinite(value) ? String(value) : "Invalid or unsupported value";
|
|
23795
|
+
}
|
|
23796
|
+
|
|
23797
|
+
function updateSamplingParameterControl(key, mutate) {
|
|
23798
|
+
const baseline = samplingParametersEditableDraft();
|
|
23799
|
+
if (!baseline || samplingParametersStateTabId !== activeTabId) return;
|
|
23800
|
+
const next = cloneSamplingControlDraft(baseline);
|
|
23801
|
+
mutate(next.controls[key]);
|
|
23802
|
+
setSamplingParametersDraft(next);
|
|
23803
|
+
setSamplingParametersFeedback();
|
|
23804
|
+
renderSamplingParameters();
|
|
23805
|
+
}
|
|
23806
|
+
|
|
23807
|
+
function initializeSamplingParameterControls() {
|
|
23808
|
+
if (!elements.samplingParametersControls || samplingParameterControlElements.size) return;
|
|
23809
|
+
initializeSamplingParameterTooltipDismissal();
|
|
23810
|
+
const groups = new Map();
|
|
23811
|
+
for (const [name, label] of [["core", "OpenAI-compatible controls"], ["server-extension", "Server extensions"]]) {
|
|
23812
|
+
const section = document.createElement("section");
|
|
23813
|
+
section.className = "sampling-parameter-group";
|
|
23814
|
+
section.dataset.samplingParameterGroup = name;
|
|
23815
|
+
const heading = document.createElement("h3");
|
|
23816
|
+
heading.textContent = label;
|
|
23817
|
+
section.append(heading);
|
|
23818
|
+
elements.samplingParametersControls.append(section);
|
|
23819
|
+
groups.set(name, section);
|
|
23820
|
+
}
|
|
23821
|
+
|
|
23822
|
+
for (const definition of SAMPLING_PARAMETER_CATALOG) {
|
|
23823
|
+
const row = document.createElement("div");
|
|
23824
|
+
row.className = "sampling-parameter-control";
|
|
23825
|
+
row.dataset.samplingParameter = definition.key;
|
|
23826
|
+
row.setAttribute("role", "group");
|
|
23827
|
+
|
|
23828
|
+
const enableId = samplingParameterDomId(definition.key, "Enabled");
|
|
23829
|
+
const valueId = samplingParameterDomId(definition.key, "Value");
|
|
23830
|
+
const rangeId = samplingParameterDomId(definition.key, "Range");
|
|
23831
|
+
const descriptionId = samplingParameterDomId(definition.key, "Description");
|
|
23832
|
+
const errorId = samplingParameterDomId(definition.key, "Error");
|
|
23833
|
+
const tooltipId = samplingParameterDomId(definition.key, "UnsupportedReason");
|
|
23834
|
+
row.setAttribute("aria-labelledby", `${enableId}Label`);
|
|
23835
|
+
|
|
23836
|
+
const header = document.createElement("div");
|
|
23837
|
+
header.className = "sampling-parameter-control-header";
|
|
23838
|
+
const enable = document.createElement("input");
|
|
23839
|
+
enable.id = enableId;
|
|
23840
|
+
enable.type = "checkbox";
|
|
23841
|
+
const label = document.createElement("label");
|
|
23842
|
+
label.id = `${enableId}Label`;
|
|
23843
|
+
label.htmlFor = enableId;
|
|
23844
|
+
label.textContent = definition.label;
|
|
23845
|
+
const scope = document.createElement("span");
|
|
23846
|
+
scope.className = "sampling-parameter-scope";
|
|
23847
|
+
scope.textContent = definition.scopeLabel;
|
|
23848
|
+
header.append(enable, label, scope);
|
|
23849
|
+
|
|
23850
|
+
const description = document.createElement("p");
|
|
23851
|
+
description.id = descriptionId;
|
|
23852
|
+
description.className = "sampling-parameter-description";
|
|
23853
|
+
description.textContent = definition.description;
|
|
23854
|
+
|
|
23855
|
+
const editor = document.createElement("div");
|
|
23856
|
+
editor.className = "sampling-parameter-editor";
|
|
23857
|
+
const number = document.createElement("input");
|
|
23858
|
+
number.id = valueId;
|
|
23859
|
+
number.className = "sampling-parameter-number";
|
|
23860
|
+
number.type = "number";
|
|
23861
|
+
number.inputMode = definition.kind === "integer" ? "numeric" : "decimal";
|
|
23862
|
+
number.step = String(definition.step);
|
|
23863
|
+
if (definition.min !== undefined && !definition.minExclusive) number.min = String(definition.min);
|
|
23864
|
+
if (definition.max !== undefined) number.max = String(definition.max);
|
|
23865
|
+
number.setAttribute("aria-label", `${definition.label} exact value`);
|
|
23866
|
+
number.setAttribute("aria-describedby", `${descriptionId} ${errorId}`);
|
|
23867
|
+
const range = document.createElement("input");
|
|
23868
|
+
range.id = rangeId;
|
|
23869
|
+
range.className = "sampling-parameter-range";
|
|
23870
|
+
range.type = "range";
|
|
23871
|
+
range.min = String(definition.slider.min);
|
|
23872
|
+
range.max = String(definition.slider.max);
|
|
23873
|
+
range.step = String(definition.slider.step);
|
|
23874
|
+
range.setAttribute("aria-label", `${definition.label} common-range slider`);
|
|
23875
|
+
range.setAttribute("aria-describedby", descriptionId);
|
|
23876
|
+
editor.append(number, range);
|
|
23877
|
+
|
|
23878
|
+
const context = document.createElement("dl");
|
|
23879
|
+
context.className = "sampling-parameter-context";
|
|
23880
|
+
const defaultTerm = document.createElement("dt");
|
|
23881
|
+
defaultTerm.textContent = "Model default";
|
|
23882
|
+
const defaultValue = document.createElement("dd");
|
|
23883
|
+
const effectiveTerm = document.createElement("dt");
|
|
23884
|
+
effectiveTerm.textContent = "Effective";
|
|
23885
|
+
const effectiveValue = document.createElement("dd");
|
|
23886
|
+
context.append(defaultTerm, defaultValue, effectiveTerm, effectiveValue);
|
|
23887
|
+
|
|
23888
|
+
const error = document.createElement("p");
|
|
23889
|
+
error.id = errorId;
|
|
23890
|
+
error.className = "sampling-parameter-error";
|
|
23891
|
+
error.setAttribute("aria-live", "polite");
|
|
23892
|
+
|
|
23893
|
+
const tooltip = document.createElement("p");
|
|
23894
|
+
tooltip.id = tooltipId;
|
|
23895
|
+
tooltip.className = "sampling-parameter-unsupported-tooltip";
|
|
23896
|
+
tooltip.setAttribute("role", "tooltip");
|
|
23897
|
+
|
|
23898
|
+
enable.addEventListener("change", () => updateSamplingParameterControl(definition.key, (control) => {
|
|
23899
|
+
control.enabled = enable.checked;
|
|
23900
|
+
}));
|
|
23901
|
+
number.addEventListener("input", () => updateSamplingParameterControl(definition.key, (control) => {
|
|
23902
|
+
control.value = number.value;
|
|
23903
|
+
}));
|
|
23904
|
+
range.addEventListener("input", () => updateSamplingParameterControl(definition.key, (control) => {
|
|
23905
|
+
control.value = range.value;
|
|
23906
|
+
}));
|
|
23907
|
+
row.addEventListener("keydown", (event) => {
|
|
23908
|
+
if (event.key === "Escape") dismissSamplingParameterTooltip(row, event);
|
|
23909
|
+
});
|
|
23910
|
+
row.addEventListener("pointerenter", () => resetSamplingParameterTooltip(row, tooltip));
|
|
23911
|
+
row.addEventListener("focusin", () => resetSamplingParameterTooltip(row, tooltip));
|
|
23912
|
+
row.addEventListener("focusout", (event) => {
|
|
23913
|
+
if (!row.contains?.(event.relatedTarget) && !row.matches?.(":hover")) row.classList.remove("sampling-tooltip-dismissed");
|
|
23914
|
+
});
|
|
23915
|
+
|
|
23916
|
+
row.append(header, description, editor, context, error, tooltip);
|
|
23917
|
+
groups.get(definition.group)?.append(row);
|
|
23918
|
+
samplingParameterControlElements.set(definition.key, { row, enable, number, range, defaultValue, effectiveValue, error, tooltip });
|
|
23919
|
+
}
|
|
23920
|
+
}
|
|
23921
|
+
|
|
23922
|
+
function renderSamplingParameters() {
|
|
23923
|
+
initializeSamplingParameterControls();
|
|
23924
|
+
const loadedForActiveTab = !!samplingParametersState && samplingParametersStateTabId === activeTabId;
|
|
23925
|
+
const activeState = loadedForActiveTab ? samplingParametersState : null;
|
|
23926
|
+
const editableDraft = samplingParametersEditableDraft()
|
|
23927
|
+
|| createSamplingControlDraft({}, { defaults: activeState?.defaults || {} });
|
|
23928
|
+
const validation = validateSamplingControlDraft(editableDraft);
|
|
23929
|
+
const dirty = samplingParametersDraftIsDirty();
|
|
23930
|
+
const capabilities = samplingParameterCapabilities(activeState);
|
|
23931
|
+
const unsupported = !Object.values(capabilities).some(({ supported }) => supported);
|
|
23932
|
+
const feedbackError = !!samplingParametersError && samplingParametersFeedbackIsCurrent();
|
|
23933
|
+
const showError = feedbackError || !validation.valid;
|
|
23934
|
+
const defaults = splitSamplingParameters(activeState?.defaults || {}).known;
|
|
23935
|
+
const effective = splitSamplingParameters(activeState?.effective || {}).known;
|
|
23936
|
+
const controlsDisabled = samplingParametersBusy || samplingParametersLoading || !activeTabId || !loadedForActiveTab;
|
|
23937
|
+
|
|
23938
|
+
for (const definition of SAMPLING_PARAMETER_CATALOG) {
|
|
23939
|
+
const refs = samplingParameterControlElements.get(definition.key);
|
|
23940
|
+
if (!refs) continue;
|
|
23941
|
+
const control = editableDraft.controls[definition.key];
|
|
23942
|
+
const capability = capabilities[definition.key];
|
|
23943
|
+
const parameterUnsupported = !capability.supported;
|
|
23944
|
+
const error = validation.errors[definition.key] || "";
|
|
23945
|
+
const valueText = typeof control.value === "number" || typeof control.value === "string" ? String(control.value) : "";
|
|
23946
|
+
const tooltipId = samplingParameterDomId(definition.key, "UnsupportedReason");
|
|
23947
|
+
refs.enable.checked = control.enabled;
|
|
23948
|
+
refs.enable.disabled = controlsDisabled || parameterUnsupported;
|
|
23949
|
+
refs.number.disabled = controlsDisabled || parameterUnsupported || !control.enabled;
|
|
23950
|
+
refs.range.disabled = controlsDisabled || parameterUnsupported || !control.enabled;
|
|
23951
|
+
if (refs.number.value !== valueText) refs.number.value = valueText;
|
|
23952
|
+
refs.range.value = String(samplingParameterSliderValue(definition.key, control.value));
|
|
23953
|
+
refs.number.setAttribute("aria-invalid", error ? "true" : "false");
|
|
23954
|
+
refs.row.classList.toggle("enabled", control.enabled);
|
|
23955
|
+
refs.row.classList.toggle("invalid", !!error);
|
|
23956
|
+
refs.row.classList.toggle("unsupported", parameterUnsupported);
|
|
23957
|
+
refs.row.tabIndex = parameterUnsupported ? 0 : -1;
|
|
23958
|
+
if (parameterUnsupported) {
|
|
23959
|
+
refs.row.setAttribute("aria-disabled", "true");
|
|
23960
|
+
refs.row.setAttribute("aria-describedby", tooltipId);
|
|
23961
|
+
refs.enable.setAttribute("aria-describedby", tooltipId);
|
|
23962
|
+
} else {
|
|
23963
|
+
refs.row.removeAttribute("aria-disabled");
|
|
23964
|
+
refs.row.removeAttribute("aria-describedby");
|
|
23965
|
+
refs.enable.removeAttribute("aria-describedby");
|
|
23966
|
+
refs.row.classList.remove("sampling-tooltip-dismissed");
|
|
23967
|
+
}
|
|
23968
|
+
refs.defaultValue.textContent = samplingParameterDisplayValue(defaults, definition.key);
|
|
23969
|
+
refs.effectiveValue.textContent = samplingParameterDisplayValue(effective, definition.key);
|
|
23970
|
+
refs.error.textContent = error;
|
|
23971
|
+
refs.error.hidden = !error;
|
|
23972
|
+
refs.tooltip.hidden = !parameterUnsupported;
|
|
23973
|
+
refs.tooltip.textContent = parameterUnsupported ? capability.reason : "";
|
|
23974
|
+
}
|
|
23975
|
+
|
|
23976
|
+
if (elements.samplingParametersSupport) {
|
|
23977
|
+
elements.samplingParametersSupport.textContent = samplingParametersSupportText();
|
|
23978
|
+
elements.samplingParametersSupport.classList.toggle("warning", unsupported);
|
|
23979
|
+
}
|
|
23980
|
+
if (elements.samplingParametersPreserved) {
|
|
23981
|
+
elements.samplingParametersPreserved.textContent = loadedForActiveTab
|
|
23982
|
+
? summarizePreservedSamplingParameters(editableDraft.preservedUnknown).text
|
|
23983
|
+
: samplingParametersLoading ? "Loading additional parameter state…" : "Additional parameter state is not loaded for this tab.";
|
|
23984
|
+
}
|
|
23985
|
+
if (elements.applySamplingParametersButton) {
|
|
23986
|
+
elements.applySamplingParametersButton.disabled = samplingParametersBusy
|
|
23987
|
+
|| samplingParametersLoading
|
|
23988
|
+
|| !activeTabId
|
|
23989
|
+
|| !loadedForActiveTab
|
|
23990
|
+
|| unsupported
|
|
23991
|
+
|| !validation.valid;
|
|
23992
|
+
elements.applySamplingParametersButton.textContent = samplingParametersBusy ? "Applying…" : "Apply";
|
|
23993
|
+
}
|
|
23994
|
+
if (elements.resetSamplingParametersButton) {
|
|
23995
|
+
elements.resetSamplingParametersButton.disabled = samplingParametersBusy
|
|
23996
|
+
|| samplingParametersLoading
|
|
23997
|
+
|| !activeTabId
|
|
23998
|
+
|| !loadedForActiveTab;
|
|
23999
|
+
}
|
|
24000
|
+
if (elements.reloadSamplingParametersButton) {
|
|
24001
|
+
elements.reloadSamplingParametersButton.disabled = samplingParametersBusy || samplingParametersLoading || !activeTabId;
|
|
24002
|
+
}
|
|
24003
|
+
if (elements.samplingParametersStatus) {
|
|
24004
|
+
elements.samplingParametersStatus.textContent = samplingParametersStatusText({ dirty, unsupported, validation, loadedForActiveTab });
|
|
24005
|
+
elements.samplingParametersStatus.classList.toggle("error", showError);
|
|
24006
|
+
elements.samplingParametersStatus.classList.toggle("warning", !showError && unsupported);
|
|
24007
|
+
}
|
|
24008
|
+
}
|
|
24009
|
+
|
|
24010
|
+
function applySamplingParametersResponse(data, tabId) {
|
|
24011
|
+
const existingDraft = samplingParametersDraft(tabId);
|
|
24012
|
+
samplingParametersState = data || null;
|
|
24013
|
+
samplingParametersStateTabId = tabId;
|
|
24014
|
+
if (existingDraft) {
|
|
24015
|
+
const loadedDraft = samplingParametersBaseDraft(tabId);
|
|
24016
|
+
existingDraft.preservedUnknown = cloneSamplingControlDraft(loadedDraft)?.preservedUnknown || {};
|
|
24017
|
+
setSamplingParametersDraft(existingDraft, tabId);
|
|
24018
|
+
}
|
|
24019
|
+
if (!samplingParametersDraftIsDirty(tabId)) setSamplingParametersDraft(null, tabId);
|
|
24020
|
+
}
|
|
24021
|
+
|
|
24022
|
+
async function loadSamplingParameters({ tabId = activeTabId, force = false } = {}) {
|
|
24023
|
+
if (!tabId) {
|
|
24024
|
+
samplingParametersState = null;
|
|
24025
|
+
samplingParametersStateTabId = null;
|
|
24026
|
+
renderSamplingParameters();
|
|
24027
|
+
return;
|
|
24028
|
+
}
|
|
24029
|
+
// Structured drafts are stored separately from loaded state, so a background
|
|
24030
|
+
// refresh can update support/default/hidden-key context without discarding edits.
|
|
24031
|
+
if (force) setSamplingParametersDraft(null, tabId);
|
|
24032
|
+
const requestSerial = ++samplingParametersRequestSerial;
|
|
24033
|
+
samplingParametersLoading = true;
|
|
24034
|
+
setSamplingParametersFeedback();
|
|
24035
|
+
renderSamplingParameters();
|
|
24036
|
+
try {
|
|
24037
|
+
const response = await api(samplingParametersPath(tabId), { scoped: false });
|
|
24038
|
+
if (requestSerial !== samplingParametersRequestSerial || tabId !== activeTabId) return;
|
|
24039
|
+
applySamplingParametersResponse(response.data, tabId);
|
|
24040
|
+
} catch (error) {
|
|
24041
|
+
if (requestSerial !== samplingParametersRequestSerial || tabId !== activeTabId) return;
|
|
24042
|
+
setSamplingParametersFeedback({ error: `Could not load sampling parameters: ${error.message || String(error)}` });
|
|
24043
|
+
} finally {
|
|
24044
|
+
if (requestSerial === samplingParametersRequestSerial) {
|
|
24045
|
+
samplingParametersLoading = false;
|
|
24046
|
+
renderSamplingParameters();
|
|
24047
|
+
}
|
|
24048
|
+
}
|
|
24049
|
+
}
|
|
24050
|
+
|
|
24051
|
+
// Background refresh for tab and model changes. It stays quiet until the section has
|
|
24052
|
+
// been opened once, so collapsed panels never pay for helper round-trips.
|
|
24053
|
+
function refreshSamplingParametersForTabContext(tabContext = activeTabContext()) {
|
|
24054
|
+
if (!tabContext.tabId) return;
|
|
24055
|
+
if (!samplingParametersState && !samplingParametersSectionActive()) return;
|
|
24056
|
+
return loadSamplingParameters({ tabId: tabContext.tabId }).catch(() => {});
|
|
24057
|
+
}
|
|
24058
|
+
|
|
24059
|
+
async function writeSamplingParameters(samplingParams, { successNotice }) {
|
|
24060
|
+
const tabId = activeTabId;
|
|
24061
|
+
if (!tabId) return;
|
|
24062
|
+
const requestSerial = ++samplingParametersRequestSerial;
|
|
24063
|
+
samplingParametersBusy = true;
|
|
24064
|
+
setSamplingParametersFeedback();
|
|
24065
|
+
renderSamplingParameters();
|
|
24066
|
+
try {
|
|
24067
|
+
const response = await api(samplingParametersPath(tabId), { method: "PUT", body: samplingParams, scoped: false });
|
|
24068
|
+
setSamplingParametersDraft(null, tabId);
|
|
24069
|
+
if (requestSerial !== samplingParametersRequestSerial || tabId !== activeTabId) return;
|
|
24070
|
+
applySamplingParametersResponse(response.data, tabId);
|
|
24071
|
+
setSamplingParametersFeedback({ notice: successNotice });
|
|
24072
|
+
} catch (error) {
|
|
24073
|
+
if (requestSerial !== samplingParametersRequestSerial || tabId !== activeTabId) return;
|
|
24074
|
+
setSamplingParametersFeedback({ error: `Could not save sampling parameters: ${error.message || String(error)}` });
|
|
24075
|
+
} finally {
|
|
24076
|
+
// Writes are serialized by the busy guard. A tab/model refresh may supersede
|
|
24077
|
+
// the response serial, but it must never strand the section in a busy state.
|
|
24078
|
+
samplingParametersBusy = false;
|
|
24079
|
+
renderSamplingParameters();
|
|
24080
|
+
}
|
|
24081
|
+
}
|
|
24082
|
+
|
|
24083
|
+
async function applySamplingParameters() {
|
|
24084
|
+
if (!activeTabId || samplingParametersBusy) return;
|
|
24085
|
+
if (!samplingParametersState || samplingParametersStateTabId !== activeTabId) {
|
|
24086
|
+
setSamplingParametersFeedback({ error: "Wait for this tab's sampling parameters to load before applying changes." });
|
|
24087
|
+
renderSamplingParameters();
|
|
24088
|
+
return;
|
|
24089
|
+
}
|
|
24090
|
+
const capabilities = samplingParameterCapabilities(samplingParametersState);
|
|
24091
|
+
if (!Object.values(capabilities).some(({ supported }) => supported)) {
|
|
24092
|
+
setSamplingParametersFeedback({ error: "This model has no verified sampling parameters, so nothing was sent." });
|
|
24093
|
+
renderSamplingParameters();
|
|
24094
|
+
return;
|
|
24095
|
+
}
|
|
24096
|
+
const draft = samplingParametersEditableDraft();
|
|
24097
|
+
const validation = validateSamplingControlDraft(draft);
|
|
24098
|
+
if (!validation.valid) {
|
|
24099
|
+
setSamplingParametersFeedback({ error: Object.values(validation.errors)[0] || "Correct invalid sampling values before applying." });
|
|
24100
|
+
renderSamplingParameters();
|
|
24101
|
+
return;
|
|
24102
|
+
}
|
|
24103
|
+
const samplingParams = buildSamplingParametersFromDraft(draft);
|
|
24104
|
+
await writeSamplingParameters(samplingParams, {
|
|
24105
|
+
successNotice: Object.keys(samplingParams).length
|
|
24106
|
+
? "Applied to this Pi session · affects subsequent provider requests."
|
|
24107
|
+
: "Session override cleared · model defaults apply.",
|
|
24108
|
+
});
|
|
24109
|
+
}
|
|
24110
|
+
|
|
24111
|
+
async function resetSamplingParameters() {
|
|
24112
|
+
if (!activeTabId || samplingParametersBusy) return;
|
|
24113
|
+
if (!samplingParametersState || samplingParametersStateTabId !== activeTabId) {
|
|
24114
|
+
setSamplingParametersFeedback({ error: "Wait for this tab's sampling parameters to load before resetting them." });
|
|
24115
|
+
renderSamplingParameters();
|
|
24116
|
+
return;
|
|
24117
|
+
}
|
|
24118
|
+
await writeSamplingParameters({}, { successNotice: "Session override cleared · model defaults apply." });
|
|
24119
|
+
}
|
|
24120
|
+
|
|
24121
|
+
// Lazy loader for surfaces that reveal the section (side-panel expand/visibility,
|
|
24122
|
+
// mobile canonical mount) after the initial page load.
|
|
24123
|
+
function ensureSamplingParametersLoaded() {
|
|
24124
|
+
if (!activeTabId || samplingParametersLoading || samplingParametersBusy) return;
|
|
24125
|
+
if (samplingParametersState && samplingParametersStateTabId === activeTabId) return;
|
|
24126
|
+
loadSamplingParameters().catch(() => {});
|
|
24127
|
+
}
|
|
24128
|
+
|
|
24129
|
+
function initializeSamplingParameters() {
|
|
24130
|
+
initializeSamplingParameterControls();
|
|
24131
|
+
renderSamplingParameters();
|
|
24132
|
+
if (samplingParametersSectionActive()) ensureSamplingParametersLoaded();
|
|
24133
|
+
}
|
|
24134
|
+
|
|
23415
24135
|
function sessionCopyButton(label, value) {
|
|
23416
24136
|
const button = make("button", "session-copy-button", "Copy");
|
|
23417
24137
|
button.type = "button";
|
|
@@ -34435,6 +35155,7 @@ function clearChatTouchIntent() {
|
|
|
34435
35155
|
|
|
34436
35156
|
function isChatScrollAwayIntent(event) {
|
|
34437
35157
|
if (event?.type === "wheel") return event.deltaY < 0;
|
|
35158
|
+
if (event?.type === "middle-drag") return event.deltaY > 0;
|
|
34438
35159
|
if (event?.type === "touchmove") {
|
|
34439
35160
|
const clientY = Number(event?.touches?.[0]?.clientY);
|
|
34440
35161
|
const scrollAway = !Number.isFinite(clientY) || chatLastTouchClientY === null || clientY > chatLastTouchClientY;
|
|
@@ -34631,10 +35352,285 @@ function setOptionsMenuOpen(open) {
|
|
|
34631
35352
|
elements.optionsMenuButton.setAttribute("aria-expanded", optionsMenuOpen ? "true" : "false");
|
|
34632
35353
|
elements.optionsMenuButton.classList.toggle("menu-open", optionsMenuOpen);
|
|
34633
35354
|
elements.optionsMenuButton.parentElement?.classList.toggle("open", optionsMenuOpen);
|
|
35355
|
+
if (optionsMenuOpen) syncOptionsSubmenuAvailability();
|
|
35356
|
+
else closeOptionsSubmenus();
|
|
35357
|
+
if (optionsMenuOpen) scheduleOptionsMenuLabelFit();
|
|
34634
35358
|
scheduleMobileDropdownScrollBoundsUpdate();
|
|
34635
35359
|
if (!optionsMenuOpen) scheduleDeferredUiFlushAfterDropdownClose();
|
|
34636
35360
|
}
|
|
34637
35361
|
|
|
35362
|
+
function optionsSubmenuGroups() {
|
|
35363
|
+
if (!elements.optionsMenu) return [];
|
|
35364
|
+
return Array.from(elements.optionsMenu.querySelectorAll(OPTIONS_SUBMENU_GROUP_SELECTOR));
|
|
35365
|
+
}
|
|
35366
|
+
|
|
35367
|
+
function optionsSubmenuTrigger(group) {
|
|
35368
|
+
if (!group?.querySelector) return null;
|
|
35369
|
+
return group.querySelector(OPTIONS_SUBMENU_TRIGGER_SELECTOR) || group.querySelector('button[aria-haspopup="menu"]');
|
|
35370
|
+
}
|
|
35371
|
+
|
|
35372
|
+
function optionsSubmenuPanel(group) {
|
|
35373
|
+
if (!group?.querySelector) return null;
|
|
35374
|
+
const controlledId = optionsSubmenuTrigger(group)?.getAttribute("aria-controls");
|
|
35375
|
+
const controlled = controlledId ? document.getElementById(controlledId) : null;
|
|
35376
|
+
if (controlled) return controlled;
|
|
35377
|
+
return group.querySelector(OPTIONS_SUBMENU_PANEL_SELECTOR) || group.querySelector('[role="menu"]');
|
|
35378
|
+
}
|
|
35379
|
+
|
|
35380
|
+
function optionsSubmenuBackButton(group) {
|
|
35381
|
+
return optionsSubmenuPanel(group)?.querySelector(OPTIONS_SUBMENU_BACK_SELECTOR) || null;
|
|
35382
|
+
}
|
|
35383
|
+
|
|
35384
|
+
function isOptionsSubmenuPanelItem(item) {
|
|
35385
|
+
const panel = item?.closest?.(OPTIONS_SUBMENU_PANEL_SELECTOR);
|
|
35386
|
+
return !!panel && !!elements.optionsMenu?.contains(panel);
|
|
35387
|
+
}
|
|
35388
|
+
|
|
35389
|
+
function isVisibleOptionsMenuItem(item) {
|
|
35390
|
+
if (!item || item.hidden || item.disabled) return false;
|
|
35391
|
+
if (item.getAttribute?.("aria-hidden") === "true") return false;
|
|
35392
|
+
return !item.closest?.("[hidden]");
|
|
35393
|
+
}
|
|
35394
|
+
|
|
35395
|
+
function optionsSubmenuActionItems(group) {
|
|
35396
|
+
const panel = optionsSubmenuPanel(group);
|
|
35397
|
+
if (!panel) return [];
|
|
35398
|
+
const back = optionsSubmenuBackButton(group);
|
|
35399
|
+
return Array.from(panel.querySelectorAll('[role="menuitem"]')).filter((item) => item !== back);
|
|
35400
|
+
}
|
|
35401
|
+
|
|
35402
|
+
function optionsSubmenuHasVisibleActions(group) {
|
|
35403
|
+
return optionsSubmenuActionItems(group).some((item) => !item.hidden && !item.disabled && item.getAttribute("aria-hidden") !== "true");
|
|
35404
|
+
}
|
|
35405
|
+
|
|
35406
|
+
function optionsSubmenuItems(group) {
|
|
35407
|
+
const panel = optionsSubmenuPanel(group);
|
|
35408
|
+
if (!panel) return [];
|
|
35409
|
+
const back = optionsSubmenuBackButton(group);
|
|
35410
|
+
return Array.from(panel.querySelectorAll('[role="menuitem"]')).filter((item) => item !== back && !item.hidden && !item.disabled && item.getAttribute("aria-hidden") !== "true");
|
|
35411
|
+
}
|
|
35412
|
+
|
|
35413
|
+
function optionsMenuRootItems() {
|
|
35414
|
+
if (!elements.optionsMenu) return [];
|
|
35415
|
+
return Array.from(elements.optionsMenu.querySelectorAll('[role="menuitem"]'))
|
|
35416
|
+
.filter((item) => !isOptionsSubmenuPanelItem(item) && isVisibleOptionsMenuItem(item));
|
|
35417
|
+
}
|
|
35418
|
+
|
|
35419
|
+
function focusOptionsMenuItem(item) {
|
|
35420
|
+
item?.focus?.({ preventScroll: true });
|
|
35421
|
+
}
|
|
35422
|
+
|
|
35423
|
+
function optionsSubmenuUsesDrillIn() {
|
|
35424
|
+
if (isMobileView()) return true;
|
|
35425
|
+
return window.matchMedia?.(OPTIONS_SUBMENU_DRILL_IN_QUERY)?.matches === true;
|
|
35426
|
+
}
|
|
35427
|
+
|
|
35428
|
+
function syncOptionsSubmenuAvailability() {
|
|
35429
|
+
if (optionsSubmenuSyncing) return;
|
|
35430
|
+
optionsSubmenuSyncing = true;
|
|
35431
|
+
try {
|
|
35432
|
+
for (const group of optionsSubmenuGroups()) {
|
|
35433
|
+
const available = optionsSubmenuHasVisibleActions(group);
|
|
35434
|
+
const unavailable = !available;
|
|
35435
|
+
const trigger = optionsSubmenuTrigger(group);
|
|
35436
|
+
if (group.hidden !== unavailable) group.hidden = unavailable;
|
|
35437
|
+
if (trigger) {
|
|
35438
|
+
if (trigger.hidden !== unavailable) trigger.hidden = unavailable;
|
|
35439
|
+
if (trigger.disabled !== unavailable) trigger.disabled = unavailable;
|
|
35440
|
+
}
|
|
35441
|
+
if (!available && openOptionsSubmenuGroup === group) setOptionsSubmenuOpen(group, false);
|
|
35442
|
+
}
|
|
35443
|
+
} finally {
|
|
35444
|
+
optionsSubmenuSyncing = false;
|
|
35445
|
+
}
|
|
35446
|
+
}
|
|
35447
|
+
|
|
35448
|
+
function fitOptionsMenuLabels() {
|
|
35449
|
+
if (!elements.optionsMenu) return;
|
|
35450
|
+
const labels = elements.optionsMenu.querySelectorAll(OPTIONS_MENU_LABEL_SELECTOR);
|
|
35451
|
+
for (const label of labels) {
|
|
35452
|
+
label.style.removeProperty(OPTIONS_MENU_LABEL_FONT_SIZE_PROPERTY);
|
|
35453
|
+
label.removeAttribute("data-options-menu-label-fitted");
|
|
35454
|
+
const availableWidth = label.clientWidth;
|
|
35455
|
+
const requiredWidth = label.scrollWidth;
|
|
35456
|
+
if (availableWidth <= 0 || requiredWidth <= availableWidth + 0.5) continue;
|
|
35457
|
+
const baseFontSize = Number.parseFloat(window.getComputedStyle(label).fontSize);
|
|
35458
|
+
if (!Number.isFinite(baseFontSize) || baseFontSize <= 0) continue;
|
|
35459
|
+
const fittedFontSize = Math.max(
|
|
35460
|
+
OPTIONS_MENU_LABEL_MIN_FONT_SIZE_PX,
|
|
35461
|
+
Math.floor(baseFontSize * (availableWidth / requiredWidth) * 98) / 100,
|
|
35462
|
+
);
|
|
35463
|
+
if (fittedFontSize >= baseFontSize) continue;
|
|
35464
|
+
label.style.setProperty(OPTIONS_MENU_LABEL_FONT_SIZE_PROPERTY, `${fittedFontSize}px`);
|
|
35465
|
+
label.setAttribute("data-options-menu-label-fitted", "");
|
|
35466
|
+
}
|
|
35467
|
+
}
|
|
35468
|
+
|
|
35469
|
+
function scheduleOptionsMenuLabelFit() {
|
|
35470
|
+
if (!elements.optionsMenu) return;
|
|
35471
|
+
if (optionsMenuLabelFitFrame) window.cancelAnimationFrame(optionsMenuLabelFitFrame);
|
|
35472
|
+
optionsMenuLabelFitFrame = window.requestAnimationFrame(() => {
|
|
35473
|
+
optionsMenuLabelFitFrame = 0;
|
|
35474
|
+
fitOptionsMenuLabels();
|
|
35475
|
+
});
|
|
35476
|
+
}
|
|
35477
|
+
|
|
35478
|
+
function updateOptionsSubmenuPlacement(group) {
|
|
35479
|
+
const panel = optionsSubmenuPanel(group);
|
|
35480
|
+
if (!group || !panel) return;
|
|
35481
|
+
if (optionsSubmenuUsesDrillIn()) {
|
|
35482
|
+
group.classList.remove(OPTIONS_SUBMENU_LEFT_CLASS);
|
|
35483
|
+
panel.classList.remove(OPTIONS_SUBMENU_LEFT_CLASS);
|
|
35484
|
+
return;
|
|
35485
|
+
}
|
|
35486
|
+
const anchorRect = (optionsSubmenuTrigger(group) || group).getBoundingClientRect?.();
|
|
35487
|
+
if (!anchorRect) return;
|
|
35488
|
+
const viewportWidth = window.innerWidth || document.documentElement.clientWidth || 0;
|
|
35489
|
+
const panelWidth = panel.offsetWidth || panel.getBoundingClientRect?.().width || 0;
|
|
35490
|
+
const spaceRight = viewportWidth - anchorRect.right;
|
|
35491
|
+
const flipLeft = panelWidth > 0 && spaceRight < panelWidth && anchorRect.left > spaceRight;
|
|
35492
|
+
group.classList.toggle(OPTIONS_SUBMENU_LEFT_CLASS, flipLeft);
|
|
35493
|
+
panel.classList.toggle(OPTIONS_SUBMENU_LEFT_CLASS, flipLeft);
|
|
35494
|
+
}
|
|
35495
|
+
|
|
35496
|
+
function setOptionsSubmenuOpen(group, open, { focusFirstItem = false, restoreFocus = false } = {}) {
|
|
35497
|
+
if (!group) return;
|
|
35498
|
+
const trigger = optionsSubmenuTrigger(group);
|
|
35499
|
+
const panel = optionsSubmenuPanel(group);
|
|
35500
|
+
const shouldOpen = !!open && !trigger?.disabled && !trigger?.hidden && !group.hidden;
|
|
35501
|
+
if (shouldOpen) {
|
|
35502
|
+
for (const sibling of optionsSubmenuGroups()) {
|
|
35503
|
+
if (sibling !== group) setOptionsSubmenuOpen(sibling, false);
|
|
35504
|
+
}
|
|
35505
|
+
}
|
|
35506
|
+
if (shouldOpen) openOptionsSubmenuGroup = group;
|
|
35507
|
+
else if (openOptionsSubmenuGroup === group) openOptionsSubmenuGroup = null;
|
|
35508
|
+
group.classList.toggle("open", shouldOpen);
|
|
35509
|
+
trigger?.setAttribute("aria-expanded", shouldOpen ? "true" : "false");
|
|
35510
|
+
trigger?.classList.toggle("menu-open", shouldOpen);
|
|
35511
|
+
if (panel) panel.hidden = !shouldOpen;
|
|
35512
|
+
if (elements.optionsMenu) {
|
|
35513
|
+
elements.optionsMenu.classList.toggle("submenu-open", !!openOptionsSubmenuGroup);
|
|
35514
|
+
const openGroupId = openOptionsSubmenuGroup?.dataset?.optionsSubmenu || "";
|
|
35515
|
+
if (openGroupId) elements.optionsMenu.dataset.openGroup = openGroupId;
|
|
35516
|
+
else delete elements.optionsMenu.dataset.openGroup;
|
|
35517
|
+
}
|
|
35518
|
+
if (shouldOpen) updateOptionsSubmenuPlacement(group);
|
|
35519
|
+
else {
|
|
35520
|
+
group.classList.remove(OPTIONS_SUBMENU_LEFT_CLASS);
|
|
35521
|
+
panel?.classList.remove(OPTIONS_SUBMENU_LEFT_CLASS);
|
|
35522
|
+
}
|
|
35523
|
+
if (shouldOpen && focusFirstItem) focusOptionsMenuItem(optionsSubmenuItems(group)[0]);
|
|
35524
|
+
if (!shouldOpen && restoreFocus) focusOptionsMenuItem(trigger);
|
|
35525
|
+
if (shouldOpen) scheduleOptionsMenuLabelFit();
|
|
35526
|
+
scheduleMobileDropdownScrollBoundsUpdate();
|
|
35527
|
+
}
|
|
35528
|
+
|
|
35529
|
+
function closeOptionsSubmenus({ restoreFocus = false } = {}) {
|
|
35530
|
+
const previous = openOptionsSubmenuGroup;
|
|
35531
|
+
for (const group of optionsSubmenuGroups()) setOptionsSubmenuOpen(group, false);
|
|
35532
|
+
openOptionsSubmenuGroup = null;
|
|
35533
|
+
if (restoreFocus && previous) focusOptionsMenuItem(optionsSubmenuTrigger(previous));
|
|
35534
|
+
}
|
|
35535
|
+
|
|
35536
|
+
function moveOptionsMenuFocus(items, currentIndex, offset) {
|
|
35537
|
+
if (!items.length) return;
|
|
35538
|
+
const nextIndex = currentIndex < 0
|
|
35539
|
+
? (offset > 0 ? 0 : items.length - 1)
|
|
35540
|
+
: (currentIndex + offset + items.length) % items.length;
|
|
35541
|
+
focusOptionsMenuItem(items[nextIndex]);
|
|
35542
|
+
}
|
|
35543
|
+
|
|
35544
|
+
function handleOptionsMenuKeydown(event) {
|
|
35545
|
+
const target = event.target;
|
|
35546
|
+
if (!target?.closest || !elements.optionsMenu?.contains(target)) return;
|
|
35547
|
+
const panelGroup = isOptionsSubmenuPanelItem(target) ? target.closest(OPTIONS_SUBMENU_GROUP_SELECTOR) : null;
|
|
35548
|
+
const items = panelGroup ? optionsSubmenuItems(panelGroup) : optionsMenuRootItems();
|
|
35549
|
+
const index = items.indexOf(target);
|
|
35550
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
35551
|
+
event.preventDefault();
|
|
35552
|
+
moveOptionsMenuFocus(items, index, event.key === "ArrowDown" ? 1 : -1);
|
|
35553
|
+
return;
|
|
35554
|
+
}
|
|
35555
|
+
if (event.key === "Home" || event.key === "End") {
|
|
35556
|
+
event.preventDefault();
|
|
35557
|
+
focusOptionsMenuItem(event.key === "Home" ? items[0] : items[items.length - 1]);
|
|
35558
|
+
return;
|
|
35559
|
+
}
|
|
35560
|
+
if (event.key === "ArrowRight") {
|
|
35561
|
+
const group = panelGroup ? null : target.closest(OPTIONS_SUBMENU_GROUP_SELECTOR);
|
|
35562
|
+
if (group && optionsSubmenuTrigger(group) === target) {
|
|
35563
|
+
event.preventDefault();
|
|
35564
|
+
setOptionsSubmenuOpen(group, true, { focusFirstItem: true });
|
|
35565
|
+
}
|
|
35566
|
+
return;
|
|
35567
|
+
}
|
|
35568
|
+
if (event.key === "ArrowLeft") {
|
|
35569
|
+
if (!panelGroup) return;
|
|
35570
|
+
event.preventDefault();
|
|
35571
|
+
setOptionsSubmenuOpen(panelGroup, false, { restoreFocus: true });
|
|
35572
|
+
return;
|
|
35573
|
+
}
|
|
35574
|
+
if (event.key !== "Escape") return;
|
|
35575
|
+
if (panelGroup || openOptionsSubmenuGroup) {
|
|
35576
|
+
// Escape closes only the deepest open level; the root menu stays open.
|
|
35577
|
+
event.preventDefault();
|
|
35578
|
+
event.stopPropagation();
|
|
35579
|
+
if (panelGroup) setOptionsSubmenuOpen(panelGroup, false, { restoreFocus: true });
|
|
35580
|
+
else closeOptionsSubmenus({ restoreFocus: true });
|
|
35581
|
+
return;
|
|
35582
|
+
}
|
|
35583
|
+
closeOptionsSubmenus();
|
|
35584
|
+
focusOptionsMenuItem(elements.optionsMenuButton);
|
|
35585
|
+
}
|
|
35586
|
+
|
|
35587
|
+
function handleOptionsSubmenuClick(event) {
|
|
35588
|
+
const back = event.target?.closest?.(OPTIONS_SUBMENU_BACK_SELECTOR);
|
|
35589
|
+
if (back && elements.optionsMenu?.contains(back)) {
|
|
35590
|
+
event.preventDefault();
|
|
35591
|
+
event.stopPropagation();
|
|
35592
|
+
setOptionsSubmenuOpen(back.closest(OPTIONS_SUBMENU_GROUP_SELECTOR), false, { restoreFocus: true });
|
|
35593
|
+
return;
|
|
35594
|
+
}
|
|
35595
|
+
const trigger = event.target?.closest?.(OPTIONS_SUBMENU_TRIGGER_SELECTOR);
|
|
35596
|
+
if (!trigger || !elements.optionsMenu?.contains(trigger)) return;
|
|
35597
|
+
event.preventDefault();
|
|
35598
|
+
event.stopPropagation();
|
|
35599
|
+
const group = trigger.closest(OPTIONS_SUBMENU_GROUP_SELECTOR);
|
|
35600
|
+
const shouldOpen = openOptionsSubmenuGroup !== group;
|
|
35601
|
+
setOptionsSubmenuOpen(group, shouldOpen, { focusFirstItem: shouldOpen });
|
|
35602
|
+
}
|
|
35603
|
+
|
|
35604
|
+
function initializeOptionsSubmenus() {
|
|
35605
|
+
const groups = optionsSubmenuGroups();
|
|
35606
|
+
if (!elements.optionsMenu || !groups.length) return;
|
|
35607
|
+
for (const group of groups) {
|
|
35608
|
+
group.addEventListener("pointerenter", (event) => {
|
|
35609
|
+
if (event.pointerType === "touch" || optionsSubmenuUsesDrillIn()) return;
|
|
35610
|
+
setOptionsSubmenuOpen(group, true);
|
|
35611
|
+
});
|
|
35612
|
+
group.addEventListener("pointerleave", (event) => {
|
|
35613
|
+
if (event.pointerType === "touch" || optionsSubmenuUsesDrillIn()) return;
|
|
35614
|
+
if (group.contains(document.activeElement)) return;
|
|
35615
|
+
setOptionsSubmenuOpen(group, false);
|
|
35616
|
+
});
|
|
35617
|
+
}
|
|
35618
|
+
const rootMenuContainer = elements.optionsMenu.parentElement;
|
|
35619
|
+
rootMenuContainer?.addEventListener("pointerenter", scheduleOptionsMenuLabelFit);
|
|
35620
|
+
rootMenuContainer?.addEventListener("focusin", scheduleOptionsMenuLabelFit);
|
|
35621
|
+
elements.optionsMenu.addEventListener("click", handleOptionsSubmenuClick);
|
|
35622
|
+
elements.optionsMenu.addEventListener("keydown", handleOptionsMenuKeydown);
|
|
35623
|
+
optionsSubmenuObserver?.disconnect();
|
|
35624
|
+
optionsSubmenuObserver = new MutationObserver(() => syncOptionsSubmenuAvailability());
|
|
35625
|
+
optionsSubmenuObserver.observe(elements.optionsMenu, { subtree: true, attributes: true, attributeFilter: ["hidden", "disabled", "aria-hidden"] });
|
|
35626
|
+
window.addEventListener("resize", () => {
|
|
35627
|
+
if (openOptionsSubmenuGroup) updateOptionsSubmenuPlacement(openOptionsSubmenuGroup);
|
|
35628
|
+
scheduleOptionsMenuLabelFit();
|
|
35629
|
+
});
|
|
35630
|
+
closeOptionsSubmenus();
|
|
35631
|
+
syncOptionsSubmenuAvailability();
|
|
35632
|
+
}
|
|
35633
|
+
|
|
34638
35634
|
function optionalFeatureIdForCommand(name) {
|
|
34639
35635
|
const baseName = commandBaseName(name);
|
|
34640
35636
|
if (OPTIONAL_COMMAND_FEATURES.has(baseName)) return OPTIONAL_COMMAND_FEATURES.get(baseName);
|
|
@@ -34979,8 +35975,10 @@ function applyOptionalFeatureProgressStates(snapshot) {
|
|
|
34979
35975
|
}
|
|
34980
35976
|
if (progress.restartDeferred === true) {
|
|
34981
35977
|
optionalFeatureRestartNotice = { autoRestarted: false, restartDeferred: true, tabId: activeTabId };
|
|
34982
|
-
} else if (progress.autoRestarted === true) {
|
|
35978
|
+
} else if (progress.autoRestarted === true && !optionalFeatureMigrationCompletionIsDismissed(snapshot)) {
|
|
34983
35979
|
optionalFeatureRestartNotice = { autoRestarted: true, restartDeferred: false, tabId: activeTabId };
|
|
35980
|
+
} else if (optionalFeatureMigrationCompletionIsDismissed(snapshot)) {
|
|
35981
|
+
optionalFeatureRestartNotice = null;
|
|
34984
35982
|
}
|
|
34985
35983
|
optionalFeatureBatchState = {
|
|
34986
35984
|
phase: progress.phase === "migrating" ? "running" : progress.phase === "partial" ? "failed" : "done",
|
|
@@ -35027,6 +36025,41 @@ function optionalFeatureReadyDismissKey(snapshot = optionalFeatureMigrationSnaps
|
|
|
35027
36025
|
return snapshot.phase === "ready" ? String(snapshot.revision || "pending") : "";
|
|
35028
36026
|
}
|
|
35029
36027
|
|
|
36028
|
+
function optionalFeatureMigrationCompletionKey(snapshot = optionalFeatureMigrationSnapshot) {
|
|
36029
|
+
if (snapshot.phase !== "complete") return "";
|
|
36030
|
+
const completedAt = String(snapshot.progress?.completedAt || snapshot.completedAt || "");
|
|
36031
|
+
return completedAt ? `${snapshot.revision || "pending"}:${completedAt}` : "";
|
|
36032
|
+
}
|
|
36033
|
+
|
|
36034
|
+
function storedDismissedOptionalFeatureMigrationKey() {
|
|
36035
|
+
try {
|
|
36036
|
+
return localStorage.getItem(OPTIONAL_FEATURE_MIGRATION_DISMISS_STORAGE_KEY) || "";
|
|
36037
|
+
} catch {
|
|
36038
|
+
return "";
|
|
36039
|
+
}
|
|
36040
|
+
}
|
|
36041
|
+
|
|
36042
|
+
function optionalFeatureMigrationCompletionIsDismissed(snapshot = optionalFeatureMigrationSnapshot) {
|
|
36043
|
+
const key = optionalFeatureMigrationCompletionKey(snapshot);
|
|
36044
|
+
return Boolean(key && (optionalFeatureMigrationDismissedCompletionKey === key || storedDismissedOptionalFeatureMigrationKey() === key));
|
|
36045
|
+
}
|
|
36046
|
+
|
|
36047
|
+
function rememberDismissedOptionalFeatureMigration(key) {
|
|
36048
|
+
if (!key) return;
|
|
36049
|
+
optionalFeatureMigrationDismissedCompletionKey = key;
|
|
36050
|
+
try {
|
|
36051
|
+
localStorage.setItem(OPTIONAL_FEATURE_MIGRATION_DISMISS_STORAGE_KEY, key);
|
|
36052
|
+
} catch {
|
|
36053
|
+
// Keep the dismissal page-local when browser storage is unavailable.
|
|
36054
|
+
}
|
|
36055
|
+
}
|
|
36056
|
+
|
|
36057
|
+
function dismissOptionalFeatureMigrationCompletion() {
|
|
36058
|
+
rememberDismissedOptionalFeatureMigration(optionalFeatureMigrationCompletionKey());
|
|
36059
|
+
optionalFeatureRestartNotice = null;
|
|
36060
|
+
renderOptionalFeatureMigrationSurface();
|
|
36061
|
+
}
|
|
36062
|
+
|
|
35030
36063
|
function scheduleOptionalFeatureReadyDismiss(key) {
|
|
35031
36064
|
if (!key) {
|
|
35032
36065
|
clearOptionalFeatureReadyDismissTimer();
|
|
@@ -35103,6 +36136,14 @@ function renderOptionalFeatureMigrationSurface() {
|
|
|
35103
36136
|
const progress = snapshot.progress;
|
|
35104
36137
|
const readyDismissKey = optionalFeatureReadyDismissKey(snapshot);
|
|
35105
36138
|
const readyCanAutoDismiss = Boolean(readyDismissKey && !optionalFeatureRestartNotice);
|
|
36139
|
+
if (optionalFeatureMigrationCompletionIsDismissed(snapshot)) {
|
|
36140
|
+
clearOptionalFeatureReadyDismissTimer();
|
|
36141
|
+
optionalFeatureRestartNotice = null;
|
|
36142
|
+
surface.replaceChildren();
|
|
36143
|
+
surface.hidden = true;
|
|
36144
|
+
ensureOptionalFeatureMigrationRenderTimer();
|
|
36145
|
+
return;
|
|
36146
|
+
}
|
|
35106
36147
|
if (readyCanAutoDismiss && optionalFeatureMigrationDismissedReadyKey === readyDismissKey) {
|
|
35107
36148
|
surface.replaceChildren();
|
|
35108
36149
|
surface.hidden = true;
|
|
@@ -35135,6 +36176,7 @@ function renderOptionalFeatureMigrationSurface() {
|
|
|
35135
36176
|
} else if (snapshot.phase === "complete") {
|
|
35136
36177
|
title.textContent = "Optional feature migration complete";
|
|
35137
36178
|
detail.textContent = optionalFeatureMigrationProgressText(progress) || `${summary.ready || 0} optional features ready`;
|
|
36179
|
+
if (!optionalFeatureRestartNotice) actions.append(optionalFeatureMigrationAction("Dismiss", dismissOptionalFeatureMigrationCompletion));
|
|
35138
36180
|
} else if (snapshot.phase === "action-required") {
|
|
35139
36181
|
title.textContent = conflicts.length ? "Optional feature conflicts were safely excluded" : "Previous optional features need migration";
|
|
35140
36182
|
detail.textContent = conflicts.length
|
|
@@ -35179,10 +36221,7 @@ function renderOptionalFeatureMigrationSurface() {
|
|
|
35179
36221
|
if (optionalFeatureRestartNotice.restartDeferred) {
|
|
35180
36222
|
notice.append(optionalFeatureMigrationAction("Restart tab", () => restartOptionalFeatureTab(), "primary"));
|
|
35181
36223
|
} else {
|
|
35182
|
-
notice.append(optionalFeatureMigrationAction("Dismiss",
|
|
35183
|
-
optionalFeatureRestartNotice = null;
|
|
35184
|
-
renderOptionalFeatureMigrationSurface();
|
|
35185
|
-
}));
|
|
36224
|
+
notice.append(optionalFeatureMigrationAction("Dismiss", dismissOptionalFeatureMigrationCompletion));
|
|
35186
36225
|
}
|
|
35187
36226
|
card.append(notice);
|
|
35188
36227
|
}
|
|
@@ -37229,9 +38268,9 @@ const SAFETY_GUARD_CATEGORY_LABELS = Object.freeze({
|
|
|
37229
38268
|
async function openNativeSafetyGuardSetupDialog() {
|
|
37230
38269
|
openNativeCommandDialog({
|
|
37231
38270
|
title: "/safety-guard-setup",
|
|
37232
|
-
message: "Configure persistent command categories, protected-path checks,
|
|
38271
|
+
message: "Configure persistent command categories, protected-path checks, preview context, and optional model auto-review.",
|
|
37233
38272
|
});
|
|
37234
|
-
renderNativeLoading("Loading safety guard setup…");
|
|
38273
|
+
renderNativeLoading("Loading safety guard setup and authenticated models…");
|
|
37235
38274
|
|
|
37236
38275
|
let data;
|
|
37237
38276
|
try {
|
|
@@ -37245,6 +38284,7 @@ async function openNativeSafetyGuardSetupDialog() {
|
|
|
37245
38284
|
|
|
37246
38285
|
const config = data.config || {};
|
|
37247
38286
|
const defaults = data.defaults || {};
|
|
38287
|
+
const models = Array.isArray(data.models) ? data.models : [];
|
|
37248
38288
|
const categories = Array.isArray(data.categories) && data.categories.length
|
|
37249
38289
|
? data.categories
|
|
37250
38290
|
: Object.keys(SAFETY_GUARD_CATEGORY_LABELS);
|
|
@@ -37254,6 +38294,17 @@ async function openNativeSafetyGuardSetupDialog() {
|
|
|
37254
38294
|
{ length: Math.max(1, maximumContext - minimumContext + 1) },
|
|
37255
38295
|
(_, index) => String(index + minimumContext),
|
|
37256
38296
|
);
|
|
38297
|
+
const modelKey = (model) => model?.provider && model?.id ? `${model.provider}/${model.id}` : "";
|
|
38298
|
+
const configuredModelKey = config.autoReview?.model?.provider && config.autoReview?.model?.modelId
|
|
38299
|
+
? `${config.autoReview.model.provider}/${config.autoReview.model.modelId}`
|
|
38300
|
+
: "";
|
|
38301
|
+
const modelOptions = [
|
|
38302
|
+
{ value: "", label: models.length ? "Select an authenticated model" : "No authenticated models available" },
|
|
38303
|
+
...models.map((model) => ({
|
|
38304
|
+
value: modelKey(model),
|
|
38305
|
+
label: `${modelKey(model)}${model.name && model.name !== model.id ? ` · ${model.name}` : ""}`,
|
|
38306
|
+
})),
|
|
38307
|
+
];
|
|
37257
38308
|
const categoryControls = Object.fromEntries(categories.map((category) => [
|
|
37258
38309
|
category,
|
|
37259
38310
|
nativeSettingToggle(
|
|
@@ -37265,38 +38316,105 @@ async function openNativeSafetyGuardSetupDialog() {
|
|
|
37265
38316
|
]));
|
|
37266
38317
|
const controls = {
|
|
37267
38318
|
enabled: nativeSettingToggle("Safety guard enabled", config.enabled !== false, "Master switch for command and protected-path guards.", { label: "global", tone: "safety" }),
|
|
38319
|
+
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" }),
|
|
38320
|
+
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" }),
|
|
38321
|
+
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
38322
|
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
38323
|
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
38324
|
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
38325
|
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
38326
|
};
|
|
37273
|
-
|
|
37274
|
-
|
|
37275
|
-
|
|
37276
|
-
|
|
37277
|
-
|
|
37278
|
-
|
|
37279
|
-
|
|
37280
|
-
|
|
37281
|
-
|
|
37282
|
-
|
|
37283
|
-
|
|
37284
|
-
|
|
37285
|
-
|
|
37286
|
-
|
|
38327
|
+
controls.autoReviewModel.select.options[0].disabled = true;
|
|
38328
|
+
if (configuredModelKey && !models.some((model) => modelKey(model) === configuredModelKey)) {
|
|
38329
|
+
const unavailable = make("option", undefined, `Unavailable: ${configuredModelKey}`);
|
|
38330
|
+
unavailable.value = configuredModelKey;
|
|
38331
|
+
unavailable.disabled = true;
|
|
38332
|
+
controls.autoReviewModel.select.append(unavailable);
|
|
38333
|
+
controls.autoReviewModel.select.value = configuredModelKey;
|
|
38334
|
+
}
|
|
38335
|
+
|
|
38336
|
+
const autoReviewAvailability = nativeSettingsNote("Auto-review availability", "");
|
|
38337
|
+
const autoReviewAvailabilityText = autoReviewAvailability.querySelector("span");
|
|
38338
|
+
const thinkingLevelsForModel = (selectedModelKey) => {
|
|
38339
|
+
const levels = data.modelThinkingLevels?.[selectedModelKey];
|
|
38340
|
+
return Array.isArray(levels) && levels.length ? levels : [];
|
|
38341
|
+
};
|
|
38342
|
+
const syncAutoReviewControls = ({ preferredThinking, preserveUnavailable = false } = {}) => {
|
|
38343
|
+
const enabled = controls.autoReview.input.checked;
|
|
38344
|
+
const selectedModelKey = controls.autoReviewModel.select.value;
|
|
38345
|
+
const selectedAvailable = models.some((model) => modelKey(model) === selectedModelKey);
|
|
38346
|
+
const levels = thinkingLevelsForModel(selectedModelKey);
|
|
38347
|
+
const preferred = preferredThinking ?? controls.autoReviewThinking.select.value ?? "off";
|
|
38348
|
+
replaceNativeSettingSelectOptions(controls.autoReviewThinking.select, levels.length ? levels : ["off"], preferred);
|
|
38349
|
+
if (preserveUnavailable && preferred && !levels.includes(preferred) && preferred !== "off") {
|
|
38350
|
+
const unavailable = make("option", undefined, `Unavailable: ${preferred}`);
|
|
38351
|
+
unavailable.value = preferred;
|
|
38352
|
+
unavailable.disabled = true;
|
|
38353
|
+
controls.autoReviewThinking.select.append(unavailable);
|
|
38354
|
+
controls.autoReviewThinking.select.value = preferred;
|
|
38355
|
+
}
|
|
38356
|
+
controls.autoReviewModel.select.disabled = !models.length;
|
|
38357
|
+
controls.autoReviewThinking.select.disabled = !selectedAvailable;
|
|
38358
|
+
autoReviewAvailability.classList.toggle("warning", enabled && (!selectedAvailable || !levels.includes(controls.autoReviewThinking.select.value)));
|
|
38359
|
+
autoReviewAvailabilityText.textContent = !enabled
|
|
38360
|
+
? "Off. Matched operations use the existing interactive prompt; model and thinking can still be preselected before enabling auto-review."
|
|
38361
|
+
: !models.length
|
|
38362
|
+
? "Unavailable: no authenticated Pi models are available. Run /login or configure a provider before enabling auto-review."
|
|
38363
|
+
: !selectedAvailable
|
|
38364
|
+
? "Unavailable: select one of the authenticated models from this active tab."
|
|
38365
|
+
: `Ready: ${selectedModelKey} supports ${levels.join(", ")} thinking.`;
|
|
38366
|
+
};
|
|
38367
|
+
controls.autoReview.input.addEventListener("change", () => syncAutoReviewControls());
|
|
38368
|
+
controls.autoReviewModel.select.addEventListener("change", () => syncAutoReviewControls({ preferredThinking: "off" }));
|
|
38369
|
+
syncAutoReviewControls({ preferredThinking: config.autoReview?.model?.thinkingLevel || "off", preserveUnavailable: true });
|
|
38370
|
+
|
|
38371
|
+
const collectConfig = () => {
|
|
38372
|
+
const selectedModelKey = controls.autoReviewModel.select.value;
|
|
38373
|
+
const selectedModel = models.find((model) => modelKey(model) === selectedModelKey);
|
|
38374
|
+
const persistedModel = selectedModelKey === configuredModelKey ? config.autoReview?.model : null;
|
|
38375
|
+
return {
|
|
38376
|
+
version: data.version || 1,
|
|
38377
|
+
enabled: controls.enabled.input.checked,
|
|
38378
|
+
categories: Object.fromEntries(categories.map((category) => [category, categoryControls[category].input.checked])),
|
|
38379
|
+
protectedPaths: {
|
|
38380
|
+
write: controls.protectedWrite.input.checked,
|
|
38381
|
+
edit: controls.protectedEdit.input.checked,
|
|
38382
|
+
},
|
|
38383
|
+
contextLines: {
|
|
38384
|
+
before: Number.parseInt(controls.before.select.value, 10),
|
|
38385
|
+
after: Number.parseInt(controls.after.select.value, 10),
|
|
38386
|
+
},
|
|
38387
|
+
autoReview: {
|
|
38388
|
+
enabled: controls.autoReview.input.checked,
|
|
38389
|
+
model: {
|
|
38390
|
+
provider: selectedModel?.provider || persistedModel?.provider || "",
|
|
38391
|
+
modelId: selectedModel?.id || persistedModel?.modelId || "",
|
|
38392
|
+
thinkingLevel: controls.autoReviewThinking.select.value || "off",
|
|
38393
|
+
},
|
|
38394
|
+
},
|
|
38395
|
+
};
|
|
38396
|
+
};
|
|
37287
38397
|
const applyConfig = (value) => {
|
|
37288
38398
|
controls.enabled.input.checked = value?.enabled !== false;
|
|
37289
38399
|
controls.before.select.value = String(value?.contextLines?.before ?? 3);
|
|
37290
38400
|
controls.after.select.value = String(value?.contextLines?.after ?? 3);
|
|
37291
38401
|
controls.protectedWrite.input.checked = value?.protectedPaths?.write !== false;
|
|
37292
38402
|
controls.protectedEdit.input.checked = value?.protectedPaths?.edit !== false;
|
|
38403
|
+
controls.autoReview.input.checked = value?.autoReview?.enabled === true;
|
|
38404
|
+
const nextModelKey = value?.autoReview?.model?.provider && value?.autoReview?.model?.modelId
|
|
38405
|
+
? `${value.autoReview.model.provider}/${value.autoReview.model.modelId}`
|
|
38406
|
+
: "";
|
|
38407
|
+
controls.autoReviewModel.select.value = [...controls.autoReviewModel.select.options].some((option) => option.value === nextModelKey) ? nextModelKey : "";
|
|
37293
38408
|
for (const category of categories) categoryControls[category].input.checked = value?.categories?.[category] !== false;
|
|
38409
|
+
syncAutoReviewControls({ preferredThinking: value?.autoReview?.model?.thinkingLevel || "off", preserveUnavailable: true });
|
|
37294
38410
|
};
|
|
37295
38411
|
|
|
37296
38412
|
const body = make("div", "native-settings-panel");
|
|
37297
38413
|
body.append(
|
|
37298
38414
|
nativeSettingsNote("Persistence", `Saved globally in ${data.path || "~/.pi/agent/safety-guard.json"}. Changes are reloaded before guard checks.`),
|
|
37299
38415
|
nativeSettingsSection("General", "Enable or disable all guard behavior.", [controls.enabled], { open: true }),
|
|
38416
|
+
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 }),
|
|
38417
|
+
autoReviewAvailability,
|
|
37300
38418
|
nativeSettingsSection("Command preview", "Choose independent context limits before and after each dangerous matched line.", [controls.before, controls.after], { open: true }),
|
|
37301
38419
|
nativeSettingsSection("Command categories", "Disable only categories you intentionally do not want guarded.", categories.map((category) => categoryControls[category]), { open: true }),
|
|
37302
38420
|
nativeSettingsSection("Protected paths", "Control write/edit prompts for secret-bearing files and credential paths.", [controls.protectedWrite, controls.protectedEdit], { open: true }),
|
|
@@ -37313,16 +38431,28 @@ async function openNativeSafetyGuardSetupDialog() {
|
|
|
37313
38431
|
setNativeActionBusy(save, true, "Saving…");
|
|
37314
38432
|
setNativeCommandError("");
|
|
37315
38433
|
try {
|
|
38434
|
+
const submitted = collectConfig();
|
|
38435
|
+
const selectedModelKey = controls.autoReviewModel.select.value;
|
|
38436
|
+
const supportedLevels = thinkingLevelsForModel(selectedModelKey);
|
|
38437
|
+
if (submitted.autoReview.enabled && !models.some((model) => modelKey(model) === selectedModelKey)) {
|
|
38438
|
+
throw new Error("Select an authenticated auto-review model from this active tab.");
|
|
38439
|
+
}
|
|
38440
|
+
if (submitted.autoReview.enabled && !supportedLevels.includes(submitted.autoReview.model.thinkingLevel)) {
|
|
38441
|
+
throw new Error(`${selectedModelKey} does not support thinking level ${submitted.autoReview.model.thinkingLevel}.`);
|
|
38442
|
+
}
|
|
37316
38443
|
const response = await nativeCommandApi("/api/safety-guard/config", {
|
|
37317
38444
|
method: "POST",
|
|
37318
|
-
body: { config:
|
|
38445
|
+
body: { config: submitted },
|
|
37319
38446
|
});
|
|
37320
|
-
const saved = response.data?.config ||
|
|
38447
|
+
const saved = response.data?.config || submitted;
|
|
37321
38448
|
const activeCategories = categories.filter((category) => saved.categories?.[category]).length;
|
|
38449
|
+
const autoReviewSummary = saved.autoReview?.enabled
|
|
38450
|
+
? `auto-review ${saved.autoReview.model.provider}/${saved.autoReview.model.modelId} at ${saved.autoReview.model.thinkingLevel}`
|
|
38451
|
+
: "auto-review off";
|
|
37322
38452
|
addTransientMessage({
|
|
37323
38453
|
role: "native",
|
|
37324
38454
|
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.`,
|
|
38455
|
+
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
38456
|
level: saved.enabled ? "info" : "warn",
|
|
37327
38457
|
});
|
|
37328
38458
|
closeNativeCommandDialog();
|
|
@@ -39357,6 +40487,11 @@ async function refreshState(tabContext = activeTabContext()) {
|
|
|
39357
40487
|
renderStatus();
|
|
39358
40488
|
if (mobilePhoneExperienceInstalled && isMobileShellV2Active()) renderMobilePhoneExperience();
|
|
39359
40489
|
requestGitFooterWebuiPayload(tabContext, { force: shouldRefreshGitFooter });
|
|
40490
|
+
// Sampling support and effective values depend on the active model, so refresh
|
|
40491
|
+
// them whenever the session reports a different model.
|
|
40492
|
+
if (modelStateKey(previousState?.model) !== modelStateKey(currentState?.model)) {
|
|
40493
|
+
refreshSamplingParametersForTabContext(tabContext);
|
|
40494
|
+
}
|
|
39360
40495
|
}
|
|
39361
40496
|
|
|
39362
40497
|
async function refreshStats(tabContext = activeTabContext()) {
|
|
@@ -40744,8 +41879,8 @@ function updateServerActionButton() {
|
|
|
40744
41879
|
button.textContent = action === "restart" ? "Restart" : action === "update" || action === "update-all" ? "Update" : action === "stop" ? "Stop" : "Run";
|
|
40745
41880
|
button.classList.toggle("danger", action === "stop");
|
|
40746
41881
|
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
|
|
41882
|
+
else if (action === "update") setServerActionStatus("Ready to create and confirm an exact Pi-only update plan.", "info");
|
|
41883
|
+
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
41884
|
else if (action === "stop") setServerActionStatus("Ready to stop the Web UI server.", "info");
|
|
40750
41885
|
else setServerActionStatus();
|
|
40751
41886
|
}
|
|
@@ -40766,19 +41901,25 @@ function resetServerActionControls() {
|
|
|
40766
41901
|
updateServerActionButton();
|
|
40767
41902
|
}
|
|
40768
41903
|
|
|
40769
|
-
async function waitForServerRestart() {
|
|
40770
|
-
|
|
40771
|
-
|
|
40772
|
-
|
|
41904
|
+
async function waitForServerRestart(previousBootIdentity = serverBootIdentity) {
|
|
41905
|
+
const deadline = Date.now() + 90_000;
|
|
41906
|
+
let attempt = 0;
|
|
41907
|
+
while (Date.now() < deadline) {
|
|
41908
|
+
attempt += 1;
|
|
41909
|
+
await delay(attempt === 1 ? 900 : 500);
|
|
41910
|
+
const remainingSeconds = Math.max(0, Math.ceil((deadline - Date.now()) / 1000));
|
|
41911
|
+
const message = `Restarting… waiting for changed server identity (${remainingSeconds}s remaining)`;
|
|
40773
41912
|
setServerActionStatus(message, "warn");
|
|
40774
41913
|
setServerRestartOverlay(true, message);
|
|
40775
41914
|
try {
|
|
40776
|
-
await api("/api/health", { scoped: false });
|
|
41915
|
+
const health = await api("/api/health", { scoped: false });
|
|
41916
|
+
if (!health.bootIdentity || health.bootIdentity === previousBootIdentity) continue;
|
|
41917
|
+
serverBootIdentity = health.bootIdentity;
|
|
40777
41918
|
setBackendOffline(false);
|
|
40778
41919
|
await initializeTabs();
|
|
40779
41920
|
setServerRestartOverlay(false);
|
|
40780
41921
|
setServerActionStatus("Server restarted and reconnected.", "success");
|
|
40781
|
-
addEvent("Pi Web UI server restarted", "warn");
|
|
41922
|
+
addEvent("Pi Web UI server restarted with a changed boot identity", "warn");
|
|
40782
41923
|
return true;
|
|
40783
41924
|
} catch (error) {
|
|
40784
41925
|
setBackendOffline(true, error);
|
|
@@ -40818,7 +41959,7 @@ async function restartServer() {
|
|
|
40818
41959
|
}
|
|
40819
41960
|
|
|
40820
41961
|
setBackendOffline(true, new Error("restart requested from side panel"));
|
|
40821
|
-
const restarted = await waitForServerRestart();
|
|
41962
|
+
const restarted = await waitForServerRestart(serverBootIdentity);
|
|
40822
41963
|
if (elements.serverActionSelect) {
|
|
40823
41964
|
elements.serverActionSelect.disabled = false;
|
|
40824
41965
|
elements.serverActionSelect.value = "";
|
|
@@ -42607,6 +43748,17 @@ optionsMenuContainer?.addEventListener("focusout", () => {
|
|
|
42607
43748
|
if (!optionsMenuContainer?.contains(document.activeElement)) setOptionsMenuOpen(false);
|
|
42608
43749
|
}, 0);
|
|
42609
43750
|
});
|
|
43751
|
+
elements.optionsMenuButton.addEventListener("keydown", (event) => {
|
|
43752
|
+
if (event.key !== "ArrowDown" && event.key !== "ArrowUp") return;
|
|
43753
|
+
event.preventDefault();
|
|
43754
|
+
setPublishMenuOpen(false);
|
|
43755
|
+
setNativeCommandMenuOpen(false);
|
|
43756
|
+
setAppRunnerMenuOpen(false);
|
|
43757
|
+
setOptionsMenuOpen(true);
|
|
43758
|
+
const items = optionsMenuRootItems();
|
|
43759
|
+
focusOptionsMenuItem(event.key === "ArrowDown" ? items[0] : items[items.length - 1]);
|
|
43760
|
+
});
|
|
43761
|
+
initializeOptionsSubmenus();
|
|
42610
43762
|
elements.releaseNpmButton.addEventListener("click", () => runPublishWorkflow("/release-npm"));
|
|
42611
43763
|
elements.releaseAurButton.addEventListener("click", () => runPublishWorkflow("/release-aur"));
|
|
42612
43764
|
elements.nativeSkillsButton.addEventListener("click", () => runNativeCommandMenu("/skills"));
|
|
@@ -43287,6 +44439,24 @@ elements.subagentLaunchSlotsLater?.addEventListener("click", () => {
|
|
|
43287
44439
|
setSubagentLaunchSlotAnnouncement("Agent models are saved. Reload this tab later before relying on them for future launches.");
|
|
43288
44440
|
renderSubagentLaunchSlots();
|
|
43289
44441
|
});
|
|
44442
|
+
elements.applySamplingParametersButton?.addEventListener("click", () => {
|
|
44443
|
+
applySamplingParameters().catch((error) => {
|
|
44444
|
+
setSamplingParametersFeedback({ error: error.message || String(error) });
|
|
44445
|
+
renderSamplingParameters();
|
|
44446
|
+
});
|
|
44447
|
+
});
|
|
44448
|
+
elements.resetSamplingParametersButton?.addEventListener("click", () => {
|
|
44449
|
+
resetSamplingParameters().catch((error) => {
|
|
44450
|
+
setSamplingParametersFeedback({ error: error.message || String(error) });
|
|
44451
|
+
renderSamplingParameters();
|
|
44452
|
+
});
|
|
44453
|
+
});
|
|
44454
|
+
elements.reloadSamplingParametersButton?.addEventListener("click", () => {
|
|
44455
|
+
loadSamplingParameters({ force: true }).catch((error) => {
|
|
44456
|
+
setSamplingParametersFeedback({ error: error.message || String(error) });
|
|
44457
|
+
renderSamplingParameters();
|
|
44458
|
+
});
|
|
44459
|
+
});
|
|
43290
44460
|
elements.subagentTerminalCopyButton?.addEventListener("click", () => copySubagentTerminalOutput());
|
|
43291
44461
|
elements.subagentTerminalRefreshButton?.addEventListener("click", () => {
|
|
43292
44462
|
refreshSubagentTerminalView(activeSubagentTerminalId, { showLoading: true }).finally(() => scheduleSubagentTerminalRefresh());
|
|
@@ -43403,6 +44573,9 @@ document.addEventListener("pointerdown", (event) => {
|
|
|
43403
44573
|
if (elements.sidePanelContextMenu && !elements.sidePanelContextMenu.hidden && !event.target?.closest?.(".side-panel-context-menu")) {
|
|
43404
44574
|
closeSidePanelContextMenu();
|
|
43405
44575
|
}
|
|
44576
|
+
if (elements.gitFooterContextMenu && !elements.gitFooterContextMenu.hidden && !event.target?.closest?.(".git-footer-context-menu")) {
|
|
44577
|
+
closeGitFooterContextMenu();
|
|
44578
|
+
}
|
|
43406
44579
|
}, { passive: true });
|
|
43407
44580
|
document.addEventListener("pointermove", (event) => {
|
|
43408
44581
|
if (openTerminalTabGroupKey && !event.target?.closest?.(".terminal-tab-group")) {
|
|
@@ -43615,6 +44788,10 @@ window.addEventListener("offline", () => {
|
|
|
43615
44788
|
window.addEventListener("beforeunload", persistMobileContinuityState);
|
|
43616
44789
|
window.addEventListener("storage", (event) => {
|
|
43617
44790
|
if (event.key === OPTIONAL_FEATURES_STORAGE_KEY) reconcileDisabledOptionalFeaturesFromStorage();
|
|
44791
|
+
if (event.key === OPTIONAL_FEATURE_MIGRATION_DISMISS_STORAGE_KEY && optionalFeatureMigrationCompletionIsDismissed()) {
|
|
44792
|
+
optionalFeatureRestartNotice = null;
|
|
44793
|
+
renderOptionalFeatureMigrationSurface();
|
|
44794
|
+
}
|
|
43618
44795
|
if (event.key === SIDE_PANEL_SECTION_VISIBILITY_STORAGE_KEY) restoreSidePanelSectionVisibility();
|
|
43619
44796
|
if (event.key === SIDE_PANEL_SECTION_ORDER_STORAGE_KEY) restoreSidePanelSectionOrder();
|
|
43620
44797
|
if (event.key === COMPOSER_ACTION_ORDER_STORAGE_KEY) restoreComposerActionOrder();
|
|
@@ -43845,6 +45022,30 @@ elements.sidePanelContextMenu?.addEventListener("keydown", (event) => {
|
|
|
43845
45022
|
items[event.key === "Home" ? 0 : items.length - 1]?.focus({ preventScroll: true });
|
|
43846
45023
|
}
|
|
43847
45024
|
});
|
|
45025
|
+
elements.gitFooterContextMenu?.addEventListener("keydown", (event) => {
|
|
45026
|
+
const items = [...elements.gitFooterContextMenu.querySelectorAll('[role="menuitem"]:not([disabled])')];
|
|
45027
|
+
const index = items.indexOf(document.activeElement);
|
|
45028
|
+
if (event.key === "Escape") {
|
|
45029
|
+
event.preventDefault();
|
|
45030
|
+
closeGitFooterContextMenu();
|
|
45031
|
+
} else if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
45032
|
+
event.preventDefault();
|
|
45033
|
+
const direction = event.key === "ArrowDown" ? 1 : -1;
|
|
45034
|
+
items[(Math.max(0, index) + direction + items.length) % items.length]?.focus({ preventScroll: true });
|
|
45035
|
+
} else if (event.key === "Home" || event.key === "End") {
|
|
45036
|
+
event.preventDefault();
|
|
45037
|
+
items[event.key === "Home" ? 0 : items.length - 1]?.focus({ preventScroll: true });
|
|
45038
|
+
}
|
|
45039
|
+
});
|
|
45040
|
+
elements.gitFooterContextMenu?.addEventListener("click", (event) => {
|
|
45041
|
+
const button = event.target?.closest?.("[data-git-footer-menu-action]");
|
|
45042
|
+
const state = gitFooterContextMenuState;
|
|
45043
|
+
if (!button || !state) return;
|
|
45044
|
+
const action = button.dataset.gitFooterMenuAction;
|
|
45045
|
+
closeGitFooterContextMenu({ returnFocus: action !== "visibility" });
|
|
45046
|
+
if (action === "disable") void disableGitFooterContextChip(state.key, state.label);
|
|
45047
|
+
else if (action === "visibility") openGitFooterVisibilityDialog();
|
|
45048
|
+
});
|
|
43848
45049
|
elements.fileContextMenu?.addEventListener("click", (event) => {
|
|
43849
45050
|
const button = event.target?.closest?.("[data-file-menu-action]");
|
|
43850
45051
|
if (!button) return;
|
|
@@ -44040,8 +45241,14 @@ elements.optionalFeatureMigrationDialog?.addEventListener("cancel", (event) => {
|
|
|
44040
45241
|
});
|
|
44041
45242
|
|
|
44042
45243
|
installModalPrimitives();
|
|
45244
|
+
installMiddleButtonDragScroll({
|
|
45245
|
+
onDirection: ({ target, offsetY }) => {
|
|
45246
|
+
if (target === elements.chat) noteChatUserScrollIntent({ type: "middle-drag", deltaY: offsetY });
|
|
45247
|
+
},
|
|
45248
|
+
});
|
|
44043
45249
|
initializeIssueWizard();
|
|
44044
45250
|
resizePromptInput();
|
|
45251
|
+
clearRemovedSidePanelSectionHeightState();
|
|
44045
45252
|
restoreDurableUiLayoutPendingJournal();
|
|
44046
45253
|
restoreSidePanelWidthPreference();
|
|
44047
45254
|
restoreFileViewerWidthPreference();
|
|
@@ -44085,6 +45292,7 @@ initializeCodexUsage();
|
|
|
44085
45292
|
initializeClaudeUsage();
|
|
44086
45293
|
initializeSubagents();
|
|
44087
45294
|
initializeSubagentLaunchSlots();
|
|
45295
|
+
initializeSamplingParameters();
|
|
44088
45296
|
initializeUpdateNotifications();
|
|
44089
45297
|
bindMobileViewChanges();
|
|
44090
45298
|
bindSidePanelOverlayViewChanges();
|