@firstpick/pi-package-webui 0.5.8 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -0
- package/bin/pi-webui.mjs +857 -12
- package/lib/git-worktrees.mjs +5 -1
- package/package.json +2 -2
- package/public/app.js +1090 -45
- package/public/index.html +20 -4
- package/public/service-worker.js +2 -1
- package/public/styles.css +368 -5
- package/public/voice-conversation.mjs +466 -0
- package/tests/compaction-resume-harness.test.mjs +114 -0
- package/tests/compaction-static.test.mjs +25 -0
- package/tests/fixtures/compacting-pi.mjs +115 -0
- package/tests/fixtures/fake-pi.mjs +220 -2
- package/tests/http-endpoints-harness.test.mjs +194 -2
- package/tests/mobile-static.test.mjs +82 -8
- package/tests/voice-conversation.test.mjs +361 -0
package/public/app.js
CHANGED
|
@@ -52,6 +52,7 @@ const elements = {
|
|
|
52
52
|
busyPromptBehaviorTag: $("#busyPromptBehaviorTag"),
|
|
53
53
|
busyPromptBehaviorMenu: $("#busyPromptBehaviorMenu"),
|
|
54
54
|
sessionSkillTags: $("#sessionSkillTags"),
|
|
55
|
+
conversationModeChip: $("#conversationModeChip"),
|
|
55
56
|
skillEditorDialog: $("#skillEditorDialog"),
|
|
56
57
|
skillEditorTitle: $("#skillEditorTitle"),
|
|
57
58
|
skillEditorMeta: $("#skillEditorMeta"),
|
|
@@ -68,6 +69,14 @@ const elements = {
|
|
|
68
69
|
steerButton: $("#steerButton"),
|
|
69
70
|
followUpButton: $("#followUpButton"),
|
|
70
71
|
abortButton: $("#abortButton"),
|
|
72
|
+
conversationModeEndButton: $("#conversationModeEndButton"),
|
|
73
|
+
conversationVoiceMenu: $("#conversationVoiceMenu"),
|
|
74
|
+
conversationVoiceButton: $("#conversationVoiceButton"),
|
|
75
|
+
conversationVoiceButtonLabel: $("#conversationVoiceButtonLabel"),
|
|
76
|
+
conversationVoiceMenuPanel: $("#conversationVoiceMenuPanel"),
|
|
77
|
+
remoteMicStreamingConsent: $("#remoteMicStreamingConsent"),
|
|
78
|
+
remoteMicStreamingConsentText: $("#remoteMicStreamingConsentText"),
|
|
79
|
+
remoteMicStreamingConsentButton: $("#remoteMicStreamingConsentButton"),
|
|
71
80
|
newSessionButton: $("#newSessionButton"),
|
|
72
81
|
compactButton: $("#compactButton"),
|
|
73
82
|
gitWorkflowButton: $("#gitWorkflowButton"),
|
|
@@ -86,6 +95,7 @@ const elements = {
|
|
|
86
95
|
optionsMenuButton: $("#optionsMenuButton"),
|
|
87
96
|
optionsMenu: $("#optionsMenu"),
|
|
88
97
|
optionsCommandPaletteButton: $("#optionsCommandPaletteButton"),
|
|
98
|
+
optionsConversationModeButton: $("#optionsConversationModeButton"),
|
|
89
99
|
optionsResumeButton: $("#optionsResumeButton"),
|
|
90
100
|
optionsReloadButton: $("#optionsReloadButton"),
|
|
91
101
|
optionsRemoteButton: $("#optionsRemoteButton"),
|
|
@@ -142,6 +152,7 @@ const elements = {
|
|
|
142
152
|
remoteAuthToggle: $("#remoteAuthToggle"),
|
|
143
153
|
remoteAuthStatus: $("#remoteAuthStatus"),
|
|
144
154
|
openNetworkButton: $("#openNetworkButton"),
|
|
155
|
+
showRemoteQrButton: $("#showRemoteQrButton"),
|
|
145
156
|
remoteQrDialog: $("#remoteQrDialog"),
|
|
146
157
|
remoteQrMessage: $("#remoteQrMessage"),
|
|
147
158
|
remoteQrBody: $("#remoteQrBody"),
|
|
@@ -295,7 +306,7 @@ let foregroundReconcileTimer = null;
|
|
|
295
306
|
let eventSource = null;
|
|
296
307
|
let activeDialog = null;
|
|
297
308
|
let activeGitPrDialogResolve = null;
|
|
298
|
-
let gitChangesState = { loading: false, pulling: false, error: "", message: "", data: null, tabId: null };
|
|
309
|
+
let gitChangesState = { loading: false, pulling: false, error: "", message: "", pullResult: null, data: null, tabId: null };
|
|
299
310
|
let gitChangesRequestSerial = 0;
|
|
300
311
|
const gitChangesUntrackedContentRequests = new Set();
|
|
301
312
|
let nativeCommandTabId = null;
|
|
@@ -484,6 +495,8 @@ const GIT_INIT_STACK_STORAGE_KEY = "pi-webui-git-init-stack";
|
|
|
484
495
|
const STATS_WEBUI_STATUS_KEY = "stats-webui";
|
|
485
496
|
const STATS_WEBUI_PAYLOAD_TYPE = "firstpick.pi-extension-stats.overlay";
|
|
486
497
|
const STATS_WEBUI_PAYLOAD_VERSION = 1;
|
|
498
|
+
const NATURAL_CONVERSATION_STATUS_KEY = "natural-conversation";
|
|
499
|
+
const NATURAL_CONVERSATION_COMMAND_NAMES = ["talk", "voice", "conversation"];
|
|
487
500
|
const REMOTE_WEBUI_CONTROLS_STATUS_KEY = "pi-remote-webui:controls";
|
|
488
501
|
const REMOTE_WEBUI_CONTROLS_PAYLOAD_TYPE = "firstpick.pi-package-remote-webui.controls";
|
|
489
502
|
const REMOTE_WEBUI_CONTROLS_PAYLOAD_VERSION = 1;
|
|
@@ -496,6 +509,7 @@ const WORKFLOW_WIDGET_PAYLOAD_PREFIX = "WORKFLOW_WEBUI_PAYLOAD ";
|
|
|
496
509
|
const WORKFLOW_SUBPROCESS_PAYLOAD_TYPE = "firstpick.pi-extension-workflows.subprocess";
|
|
497
510
|
const WORKFLOW_SUBPROCESS_PAYLOAD_VERSION = 1;
|
|
498
511
|
const GIT_CHANGES_RENDER_ROW_LIMIT = 4000;
|
|
512
|
+
const GIT_PULL_RESULT_FILE_LIMIT = 48;
|
|
499
513
|
const LAST_USER_PROMPT_STORAGE_KEY = "pi-webui-last-user-prompts";
|
|
500
514
|
const PROMPT_HISTORY_STORAGE_KEY = "pi-webui-prompt-history";
|
|
501
515
|
const PROMPT_LIST_STORAGE_KEY = "pi-webui-prompt-lists";
|
|
@@ -567,6 +581,7 @@ const todoProgressGoalByTab = new Map();
|
|
|
567
581
|
const todoProgressSignatureByTab = new Map();
|
|
568
582
|
const releaseNpmOutputExpandedByTab = new Map();
|
|
569
583
|
const appRunnerDataByTab = new Map();
|
|
584
|
+
const conversationModeByTab = new Map();
|
|
570
585
|
const appRunnerInputDraftByRun = new Map();
|
|
571
586
|
const appRunnerContextLineDraftByRun = new Map();
|
|
572
587
|
const liveToolRuns = new Map();
|
|
@@ -589,6 +604,7 @@ const optionalFeatureAvailability = {
|
|
|
589
604
|
todoProgressWidget: false,
|
|
590
605
|
tuiToolsCommand: false,
|
|
591
606
|
remoteWebui: false,
|
|
607
|
+
naturalConversation: false,
|
|
592
608
|
themeBundle: false,
|
|
593
609
|
};
|
|
594
610
|
const APP_RUNNER_CONTEXT_DEFAULT_LINES = 80;
|
|
@@ -664,6 +680,13 @@ const OPTIONAL_FEATURES = [
|
|
|
664
680
|
capabilityLabel: "/remote",
|
|
665
681
|
description: "Trusted-LAN QR helper for opening the Web UI from mobile browsers.",
|
|
666
682
|
},
|
|
683
|
+
{
|
|
684
|
+
id: "naturalConversation",
|
|
685
|
+
label: "Natural Conversation",
|
|
686
|
+
packageName: "@firstpick/pi-package-natural-conversation",
|
|
687
|
+
capabilityLabel: "/talk, /voice, or /conversation",
|
|
688
|
+
description: "Per-tab conversation-mode shell that delegates safety constraints to the standalone package and reserves WebUI audio for later phases.",
|
|
689
|
+
},
|
|
667
690
|
{
|
|
668
691
|
id: "gitFooterStatus",
|
|
669
692
|
label: "Git footer status",
|
|
@@ -702,6 +725,9 @@ const OPTIONAL_COMMAND_FEATURES = new Map([
|
|
|
702
725
|
["skills", "tuiSkillsCommand"],
|
|
703
726
|
["tools", "tuiToolsCommand"],
|
|
704
727
|
["remote", "remoteWebui"],
|
|
728
|
+
["talk", "naturalConversation"],
|
|
729
|
+
["voice", "naturalConversation"],
|
|
730
|
+
["conversation", "naturalConversation"],
|
|
705
731
|
["stats", "statsCommand"],
|
|
706
732
|
["git-footer-refresh", "gitFooterStatus"],
|
|
707
733
|
["todo-progress-status", "todoProgressWidget"],
|
|
@@ -733,6 +759,7 @@ const optionalFeatureInstallInProgress = new Set();
|
|
|
733
759
|
const optionalFeaturePackageStatuses = new Map();
|
|
734
760
|
const optionalFeatureInstallMessages = new Map();
|
|
735
761
|
const gitFooterPayloadRefreshInFlightByTab = new Set();
|
|
762
|
+
const gitFooterSyncPushInFlightByTab = new Set();
|
|
736
763
|
const gitFooterPiCalibrationInFlightByTab = new Set();
|
|
737
764
|
|
|
738
765
|
function createGitWorkflowActionsDone(patch = {}) {
|
|
@@ -1006,6 +1033,7 @@ function isInteractiveDropdownOpen() {
|
|
|
1006
1033
|
|| nativeCommandMenuOpen
|
|
1007
1034
|
|| appRunnerMenuOpen
|
|
1008
1035
|
|| optionsMenuOpen
|
|
1036
|
+
|| conversationVoiceMenuOpen
|
|
1009
1037
|
|| busyPromptBehaviorMenuOpen
|
|
1010
1038
|
|| newTabMenuOpen
|
|
1011
1039
|
|| isFooterPickerOpen()
|
|
@@ -1097,6 +1125,7 @@ function mobileDropdownConfigs() {
|
|
|
1097
1125
|
{ menu: elements.nativeCommandMenuButton?.parentElement, button: elements.nativeCommandMenuButton, panel: elements.nativeCommandMenuButton?.parentElement?.querySelector(".composer-publish-menu-panel") },
|
|
1098
1126
|
{ menu: elements.optionsMenuButton?.parentElement, button: elements.optionsMenuButton, panel: elements.optionsMenu },
|
|
1099
1127
|
{ menu: elements.appRunnerMenu, button: elements.appRunnerMenuButton, panel: elements.appRunnerMenuPanel },
|
|
1128
|
+
{ menu: elements.conversationVoiceMenu, button: elements.conversationVoiceButton, panel: elements.conversationVoiceMenuPanel },
|
|
1100
1129
|
];
|
|
1101
1130
|
}
|
|
1102
1131
|
|
|
@@ -2160,7 +2189,7 @@ function isUserBashRunningOrQueued(tabId = activeTabId) {
|
|
|
2160
2189
|
}
|
|
2161
2190
|
|
|
2162
2191
|
function isRunActive() {
|
|
2163
|
-
return !!currentState?.isStreaming || isUserBashRunningOrQueued() ||
|
|
2192
|
+
return !!currentState?.isStreaming || !!currentState?.isCompacting || isUserBashRunningOrQueued() || runIndicatorLocallyActive;
|
|
2164
2193
|
}
|
|
2165
2194
|
|
|
2166
2195
|
function isAbortAvailable() {
|
|
@@ -4031,6 +4060,670 @@ function isOptionalFeatureEnabled(featureId) {
|
|
|
4031
4060
|
return isOptionalFeatureDetected(featureId) && !isOptionalFeatureDisabled(featureId);
|
|
4032
4061
|
}
|
|
4033
4062
|
|
|
4063
|
+
function defaultConversationModeState(patch = {}) {
|
|
4064
|
+
return {
|
|
4065
|
+
featureId: "naturalConversation",
|
|
4066
|
+
available: false,
|
|
4067
|
+
enabled: false,
|
|
4068
|
+
uiState: "off",
|
|
4069
|
+
statusText: "",
|
|
4070
|
+
partialTranscript: "",
|
|
4071
|
+
allowedTools: ["read", "grep", "find", "ls"],
|
|
4072
|
+
provider: "browser-shell",
|
|
4073
|
+
startedAt: null,
|
|
4074
|
+
packageInstalled: false,
|
|
4075
|
+
loadedCommands: [],
|
|
4076
|
+
updatedAt: "",
|
|
4077
|
+
...patch,
|
|
4078
|
+
};
|
|
4079
|
+
}
|
|
4080
|
+
|
|
4081
|
+
function normalizeConversationModeState(value = {}) {
|
|
4082
|
+
const source = value && typeof value === "object" ? value : {};
|
|
4083
|
+
const enabled = source.enabled === true;
|
|
4084
|
+
return defaultConversationModeState({
|
|
4085
|
+
...source,
|
|
4086
|
+
available: source.available === true,
|
|
4087
|
+
enabled,
|
|
4088
|
+
uiState: enabled ? cleanStatusText(source.uiState || "listening").toLowerCase() || "listening" : "off",
|
|
4089
|
+
statusText: cleanStatusText(source.statusText || ""),
|
|
4090
|
+
partialTranscript: cleanStatusText(source.partialTranscript || ""),
|
|
4091
|
+
allowedTools: Array.isArray(source.allowedTools) && source.allowedTools.length ? source.allowedTools.map((name) => String(name)).filter(Boolean) : ["read", "grep", "find", "ls"],
|
|
4092
|
+
packageInstalled: source.packageInstalled === true,
|
|
4093
|
+
loadedCommands: Array.isArray(source.loadedCommands) ? source.loadedCommands.map((name) => String(name)).filter(Boolean) : [],
|
|
4094
|
+
});
|
|
4095
|
+
}
|
|
4096
|
+
|
|
4097
|
+
function updateConversationModeForTab(tabId = activeTabId, mode = {}, { render = true, voiceLoop = false } = {}) {
|
|
4098
|
+
if (!tabId) return normalizeConversationModeState(mode);
|
|
4099
|
+
const previous = conversationModeByTab.get(tabId) || tabs.find((tab) => tab.id === tabId)?.conversationMode || {};
|
|
4100
|
+
let patch = mode && typeof mode === "object" ? mode : {};
|
|
4101
|
+
if (!voiceLoop && patch.enabled !== false && voiceConversationActiveFor(tabId)) {
|
|
4102
|
+
// While the browser voice loop runs, it owns uiState/statusText; server
|
|
4103
|
+
// snapshots would otherwise reset "speaking"/"transcribing" to "listening".
|
|
4104
|
+
patch = { ...patch };
|
|
4105
|
+
delete patch.uiState;
|
|
4106
|
+
delete patch.statusText;
|
|
4107
|
+
}
|
|
4108
|
+
const next = normalizeConversationModeState({ ...previous, ...patch });
|
|
4109
|
+
conversationModeByTab.set(tabId, next);
|
|
4110
|
+
if (tabId === activeTabId && render) renderConversationModeControls();
|
|
4111
|
+
return next;
|
|
4112
|
+
}
|
|
4113
|
+
|
|
4114
|
+
function activeConversationMode() {
|
|
4115
|
+
return normalizeConversationModeState(conversationModeByTab.get(activeTabId) || activeTab()?.conversationMode || {});
|
|
4116
|
+
}
|
|
4117
|
+
|
|
4118
|
+
function conversationModeCommandName() {
|
|
4119
|
+
for (const name of NATURAL_CONVERSATION_COMMAND_NAMES) {
|
|
4120
|
+
const resolved = resolveAvailableCommandName(name, { rpcOnly: true });
|
|
4121
|
+
if (resolved) return resolved;
|
|
4122
|
+
}
|
|
4123
|
+
return "";
|
|
4124
|
+
}
|
|
4125
|
+
|
|
4126
|
+
function conversationModeButtonLabel(mode = activeConversationMode()) {
|
|
4127
|
+
return mode.enabled ? "End Conversation" : "Start Conversation";
|
|
4128
|
+
}
|
|
4129
|
+
|
|
4130
|
+
function conversationModePartialPreview(text = "") {
|
|
4131
|
+
const normalized = cleanStatusText(text || "");
|
|
4132
|
+
if (!normalized) return "";
|
|
4133
|
+
return normalized.length > 42 ? `${normalized.slice(0, 39)}…` : normalized;
|
|
4134
|
+
}
|
|
4135
|
+
|
|
4136
|
+
// Declared before renderConversationModeControls ever runs (it is called
|
|
4137
|
+
// during initial render passes) so the voice-menu block never hits a TDZ.
|
|
4138
|
+
let conversationVoiceSwitching = false;
|
|
4139
|
+
let conversationVoicesLoadedForTab = null;
|
|
4140
|
+
let conversationVoiceMenuOpen = false;
|
|
4141
|
+
let conversationVoiceLastData = null;
|
|
4142
|
+
let conversationVoicePending = null;
|
|
4143
|
+
|
|
4144
|
+
// Same open/close contract as the Common-Pi-options menu: click toggles the
|
|
4145
|
+
// panel (hover/focus-within still work on desktop via CSS), so it also works
|
|
4146
|
+
// on touch devices where :hover never fires.
|
|
4147
|
+
function setConversationVoiceMenuOpen(open) {
|
|
4148
|
+
conversationVoiceMenuOpen = !!open;
|
|
4149
|
+
elements.conversationVoiceButton?.setAttribute("aria-expanded", conversationVoiceMenuOpen ? "true" : "false");
|
|
4150
|
+
elements.conversationVoiceButton?.classList.toggle("menu-open", conversationVoiceMenuOpen);
|
|
4151
|
+
elements.conversationVoiceMenu?.classList.toggle("open", conversationVoiceMenuOpen);
|
|
4152
|
+
scheduleMobileDropdownScrollBoundsUpdate();
|
|
4153
|
+
}
|
|
4154
|
+
|
|
4155
|
+
function conversationModeDisplayText(mode = activeConversationMode()) {
|
|
4156
|
+
if (!mode.enabled) return "Voice: off";
|
|
4157
|
+
// Voice-switch progress ("downloading de_DE-thorsten-high 42%", "testing …")
|
|
4158
|
+
// arrives via the package status text; show it verbatim instead of the bare state.
|
|
4159
|
+
const progressDetail = /^voice\s*:\s*((?:downloading|testing)\s.+)$/i.exec(mode.statusText || "")?.[1];
|
|
4160
|
+
const uiState = progressDetail || mode.uiState || "listening";
|
|
4161
|
+
const provider = nativeConversationAudioEngaged() ? "native audio" : voiceConversationVisibleProviderLabel();
|
|
4162
|
+
const prefix = provider ? `Voice: ${uiState} · ${provider}` : `Voice: ${uiState}`;
|
|
4163
|
+
const partial = uiState === "transcribing" ? conversationModePartialPreview(mode.partialTranscript) : "";
|
|
4164
|
+
return partial ? `${prefix} — “${partial}”` : prefix;
|
|
4165
|
+
}
|
|
4166
|
+
|
|
4167
|
+
function conversationModeUnavailableText() {
|
|
4168
|
+
return optionalFeatureUnavailableMessage("naturalConversation");
|
|
4169
|
+
}
|
|
4170
|
+
|
|
4171
|
+
function renderConversationModeControls() {
|
|
4172
|
+
const mode = activeConversationMode();
|
|
4173
|
+
const commandName = conversationModeCommandName();
|
|
4174
|
+
const commandAvailable = !!commandName && isOptionalFeatureEnabled("naturalConversation");
|
|
4175
|
+
const active = mode.enabled === true;
|
|
4176
|
+
document.body.classList.toggle("conversation-mode-active", active);
|
|
4177
|
+
elements.composer?.classList.toggle("conversation-mode-active", active);
|
|
4178
|
+
|
|
4179
|
+
if (elements.optionsConversationModeButton) {
|
|
4180
|
+
elements.optionsConversationModeButton.hidden = !commandAvailable && !active;
|
|
4181
|
+
elements.optionsConversationModeButton.disabled = !commandName;
|
|
4182
|
+
elements.optionsConversationModeButton.classList.toggle("active", active);
|
|
4183
|
+
elements.optionsConversationModeButton.querySelector("span").textContent = conversationModeButtonLabel(mode);
|
|
4184
|
+
const tooltip = commandName
|
|
4185
|
+
? `${active ? "End" : "Start"} Natural Conversation Mode for this Pi tab via /${commandName}. Safety is owned by @firstpick/pi-package-natural-conversation.`
|
|
4186
|
+
: conversationModeUnavailableText();
|
|
4187
|
+
elements.optionsConversationModeButton.title = tooltip;
|
|
4188
|
+
elements.optionsConversationModeButton.setAttribute("data-tooltip", tooltip);
|
|
4189
|
+
elements.optionsConversationModeButton.setAttribute("aria-pressed", active ? "true" : "false");
|
|
4190
|
+
}
|
|
4191
|
+
|
|
4192
|
+
if (elements.conversationModeChip) {
|
|
4193
|
+
elements.conversationModeChip.hidden = !active;
|
|
4194
|
+
elements.conversationModeChip.textContent = conversationModeDisplayText(mode);
|
|
4195
|
+
elements.conversationModeChip.setAttribute("data-voice-state", active ? mode.uiState || "listening" : "off");
|
|
4196
|
+
const chipAction = mode.uiState === "paused" ? "Click to resume browser listening." : "Click to pause browser listening; use End conversation to leave the safe mode.";
|
|
4197
|
+
elements.conversationModeChip.title = `Natural Conversation Mode is active in this tab (${voiceConversationProviderLabel()}). Thinking is forced off; tools are limited to ${mode.allowedTools.join(", ")}. ${chipAction}`;
|
|
4198
|
+
elements.conversationModeChip.setAttribute("aria-label", `Natural Conversation Mode ${mode.uiState || "listening"}. ${chipAction}`);
|
|
4199
|
+
}
|
|
4200
|
+
|
|
4201
|
+
if (elements.conversationModeEndButton) {
|
|
4202
|
+
elements.conversationModeEndButton.hidden = !active;
|
|
4203
|
+
elements.conversationModeEndButton.disabled = !commandName;
|
|
4204
|
+
elements.conversationModeEndButton.title = commandName ? `End Natural Conversation Mode with /${commandName} off.` : conversationModeUnavailableText();
|
|
4205
|
+
}
|
|
4206
|
+
|
|
4207
|
+
if (elements.conversationVoiceMenu) {
|
|
4208
|
+
elements.conversationVoiceMenu.hidden = !active;
|
|
4209
|
+
if (!active && conversationVoiceMenuOpen) setConversationVoiceMenuOpen(false);
|
|
4210
|
+
if (elements.conversationVoiceButton) elements.conversationVoiceButton.disabled = conversationVoiceSwitching || !commandName;
|
|
4211
|
+
if (active && commandName && conversationVoicesLoadedForTab !== activeTabId) void loadConversationVoices();
|
|
4212
|
+
}
|
|
4213
|
+
|
|
4214
|
+
const awaitingRemoteMicConsent = active && !remoteMicConsentGranted(activeTabId);
|
|
4215
|
+
if (elements.remoteMicStreamingConsent) {
|
|
4216
|
+
elements.remoteMicStreamingConsent.hidden = !awaitingRemoteMicConsent;
|
|
4217
|
+
if (awaitingRemoteMicConsent && elements.remoteMicStreamingConsentText) {
|
|
4218
|
+
elements.remoteMicStreamingConsentText.textContent = remoteMicConsentDisclosureText();
|
|
4219
|
+
}
|
|
4220
|
+
}
|
|
4221
|
+
if (elements.remoteMicStreamingConsentButton) {
|
|
4222
|
+
// The consent button stays disabled unless its disclosure is visible.
|
|
4223
|
+
elements.remoteMicStreamingConsentButton.disabled = !awaitingRemoteMicConsent;
|
|
4224
|
+
}
|
|
4225
|
+
|
|
4226
|
+
syncVoiceConversationLoop();
|
|
4227
|
+
}
|
|
4228
|
+
|
|
4229
|
+
function handleNaturalConversationStatus(statusText, tabId = activeTabId) {
|
|
4230
|
+
const text = cleanStatusText(statusText || "");
|
|
4231
|
+
const match = text.match(/voice\s*:\s*([a-z0-9_-]+)/i);
|
|
4232
|
+
updateConversationModeForTab(tabId, {
|
|
4233
|
+
available: true,
|
|
4234
|
+
enabled: !!text,
|
|
4235
|
+
uiState: text ? (match?.[1] || "listening").toLowerCase() : "off",
|
|
4236
|
+
statusText: text,
|
|
4237
|
+
loadedCommands: NATURAL_CONVERSATION_COMMAND_NAMES.filter((name) => hasLoadedRpcCommand(name)),
|
|
4238
|
+
});
|
|
4239
|
+
}
|
|
4240
|
+
|
|
4241
|
+
async function refreshNaturalConversationMode(tabContext = activeTabContext()) {
|
|
4242
|
+
if (!tabContext.tabId) return;
|
|
4243
|
+
try {
|
|
4244
|
+
const response = await api("/api/conversation-mode", { tabId: tabContext.tabId });
|
|
4245
|
+
if (!isCurrentTabContext(tabContext)) return;
|
|
4246
|
+
updateConversationModeForTab(tabContext.tabId, response.data?.mode || {}, { render: true });
|
|
4247
|
+
if (response.data?.available) optionalFeatureAvailability.naturalConversation = true;
|
|
4248
|
+
} catch (error) {
|
|
4249
|
+
if (isCurrentTabContext(tabContext)) addEvent(`natural conversation status check failed: ${error.message || String(error)}`, "warn");
|
|
4250
|
+
}
|
|
4251
|
+
}
|
|
4252
|
+
|
|
4253
|
+
async function setNaturalConversationModeEnabled(enabled) {
|
|
4254
|
+
const tabContext = activeTabContext();
|
|
4255
|
+
if (!tabContext.tabId) return;
|
|
4256
|
+
const commandName = conversationModeCommandName();
|
|
4257
|
+
if (!commandName) {
|
|
4258
|
+
addEvent(conversationModeUnavailableText(), "warn");
|
|
4259
|
+
await Promise.allSettled([refreshCommands(tabContext), refreshOptionalFeaturePackageStatuses()]);
|
|
4260
|
+
return;
|
|
4261
|
+
}
|
|
4262
|
+
try {
|
|
4263
|
+
const response = await api("/api/conversation-mode", { method: "POST", body: { enabled: enabled === true }, tabId: tabContext.tabId });
|
|
4264
|
+
if (enabled !== true) {
|
|
4265
|
+
stopVoiceConversationLoop();
|
|
4266
|
+
remoteMicConsentTabs.delete(tabContext.tabId);
|
|
4267
|
+
}
|
|
4268
|
+
applyResponseTab(response);
|
|
4269
|
+
if (!isCurrentTabContext(tabContext)) return;
|
|
4270
|
+
updateConversationModeForTab(tabContext.tabId, response.data?.mode || {}, { render: true });
|
|
4271
|
+
addEvent(enabled ? "Natural Conversation Mode started." : "Natural Conversation Mode ended.", "info");
|
|
4272
|
+
if (enabled) addTransientMessage({ role: "native", title: "/talk", content: "Natural Conversation Mode is active. Thinking is off; write/shell workflows are blocked by the package safety controller.", level: "info" });
|
|
4273
|
+
await Promise.allSettled([refreshState(tabContext), refreshCommands(tabContext)]);
|
|
4274
|
+
} catch (error) {
|
|
4275
|
+
if (isCurrentTabContext(tabContext)) addEvent(error.message || String(error), "error");
|
|
4276
|
+
}
|
|
4277
|
+
}
|
|
4278
|
+
|
|
4279
|
+
function toggleNaturalConversationMode() {
|
|
4280
|
+
const mode = activeConversationMode();
|
|
4281
|
+
return setNaturalConversationModeEnabled(!mode.enabled);
|
|
4282
|
+
}
|
|
4283
|
+
|
|
4284
|
+
// --- Conversation voice dropdown (native Piper voices via /talk voice) -------
|
|
4285
|
+
// The list comes from GET /api/conversation-voices (server reads voice.json
|
|
4286
|
+
// and the piper voice directory); switching posts to /api/conversation-voice,
|
|
4287
|
+
// which runs `/talk voice <id>` in the package over RPC. Missing voices are
|
|
4288
|
+
// downloaded by the package; progress streams back through the voice chip's
|
|
4289
|
+
// status text ("Voice: downloading <id> <pct>%").
|
|
4290
|
+
|
|
4291
|
+
function conversationVoiceLanguageLabel(voiceId) {
|
|
4292
|
+
const locale = String(voiceId || "").split("-", 1)[0] || "";
|
|
4293
|
+
const language = locale.split("_")[0]?.toUpperCase() || "";
|
|
4294
|
+
return ["DE", "EN"].includes(language) ? language : language;
|
|
4295
|
+
}
|
|
4296
|
+
|
|
4297
|
+
function conversationVoiceGenderLabel(voiceId) {
|
|
4298
|
+
const id = String(voiceId || "").toLowerCase();
|
|
4299
|
+
if (id.includes("thorsten")) return "M";
|
|
4300
|
+
if (id.includes("lessac") || id.includes("alba")) return "F";
|
|
4301
|
+
return "";
|
|
4302
|
+
}
|
|
4303
|
+
|
|
4304
|
+
function conversationVoiceShortLabel(voiceId) {
|
|
4305
|
+
// "de_DE-thorsten-medium" → "DE M Thorsten med" keeps the controls compact.
|
|
4306
|
+
const text = String(voiceId || "").trim();
|
|
4307
|
+
if (!text) return "Voice";
|
|
4308
|
+
const parts = text.split("-").filter(Boolean);
|
|
4309
|
+
const language = conversationVoiceLanguageLabel(text);
|
|
4310
|
+
const gender = conversationVoiceGenderLabel(text);
|
|
4311
|
+
const quality = parts.at(-1) || "";
|
|
4312
|
+
const qualityLabel = quality === "medium" ? "med" : quality === "high" ? "high" : quality;
|
|
4313
|
+
const nameParts = parts.length >= 3 ? parts.slice(1, -1) : parts.slice(1);
|
|
4314
|
+
const name = nameParts.join(" ").replace(/\b\w/g, (char) => char.toUpperCase());
|
|
4315
|
+
return [language, gender, name, qualityLabel].filter(Boolean).join(" ") || text;
|
|
4316
|
+
}
|
|
4317
|
+
|
|
4318
|
+
function conversationVoiceById(data, voiceId) {
|
|
4319
|
+
const wanted = String(voiceId || "").trim();
|
|
4320
|
+
const voices = Array.isArray(data?.voices) ? data.voices : [];
|
|
4321
|
+
return voices.find((voice) => voice?.id === wanted) || null;
|
|
4322
|
+
}
|
|
4323
|
+
|
|
4324
|
+
function conversationVoiceDownloadSizeText(voice) {
|
|
4325
|
+
const sizeMb = Number(voice?.sizeMb);
|
|
4326
|
+
return Number.isFinite(sizeMb) && sizeMb > 0 ? ` (${sizeMb} MB)` : "";
|
|
4327
|
+
}
|
|
4328
|
+
|
|
4329
|
+
function conversationVoiceStartMessage(voice, voiceId) {
|
|
4330
|
+
const wanted = String(voiceId || voice?.id || "voice").trim();
|
|
4331
|
+
if (voice?.downloaded) return `Selecting conversation voice ${wanted}…`;
|
|
4332
|
+
return `Downloading conversation voice ${wanted}${conversationVoiceDownloadSizeText(voice)}, then selecting it…`;
|
|
4333
|
+
}
|
|
4334
|
+
|
|
4335
|
+
function showConversationVoiceFeedback(message, level = "info") {
|
|
4336
|
+
const text = cleanStatusText(message || "");
|
|
4337
|
+
if (!text) return;
|
|
4338
|
+
addEvent(text, level);
|
|
4339
|
+
addTransientMessage({ role: level === "error" ? "error" : "native", title: "/talk voice", content: text, level });
|
|
4340
|
+
}
|
|
4341
|
+
|
|
4342
|
+
function renderConversationVoicePanelNotice(message, level = "info") {
|
|
4343
|
+
const panel = elements.conversationVoiceMenuPanel;
|
|
4344
|
+
if (!panel) return;
|
|
4345
|
+
panel.innerHTML = "";
|
|
4346
|
+
const notice = document.createElement("div");
|
|
4347
|
+
notice.className = "composer-publish-menu-item composer-conversation-voice-item composer-conversation-voice-notice";
|
|
4348
|
+
notice.classList.toggle("error", level === "error");
|
|
4349
|
+
notice.setAttribute("role", level === "error" ? "alert" : "status");
|
|
4350
|
+
notice.textContent = message;
|
|
4351
|
+
panel.appendChild(notice);
|
|
4352
|
+
}
|
|
4353
|
+
|
|
4354
|
+
function renderConversationVoiceOptions(data = conversationVoiceLastData) {
|
|
4355
|
+
const panel = elements.conversationVoiceMenuPanel;
|
|
4356
|
+
if (!panel) return;
|
|
4357
|
+
const source = data || conversationVoiceLastData || {};
|
|
4358
|
+
conversationVoiceLastData = source;
|
|
4359
|
+
const voices = Array.isArray(source?.voices) ? source.voices : [];
|
|
4360
|
+
panel.innerHTML = "";
|
|
4361
|
+
if (elements.conversationVoiceButtonLabel) {
|
|
4362
|
+
elements.conversationVoiceButtonLabel.textContent = source?.current ? conversationVoiceShortLabel(source.current) : "Voice";
|
|
4363
|
+
}
|
|
4364
|
+
if (conversationVoicePending) {
|
|
4365
|
+
const pending = document.createElement("div");
|
|
4366
|
+
pending.className = "composer-publish-menu-item composer-conversation-voice-item composer-conversation-voice-notice pending";
|
|
4367
|
+
pending.setAttribute("role", "status");
|
|
4368
|
+
pending.setAttribute("aria-live", "polite");
|
|
4369
|
+
pending.textContent = conversationVoicePending.message;
|
|
4370
|
+
panel.appendChild(pending);
|
|
4371
|
+
}
|
|
4372
|
+
if (voices.length === 0) {
|
|
4373
|
+
const empty = document.createElement("button");
|
|
4374
|
+
empty.className = "composer-publish-menu-item composer-conversation-voice-item";
|
|
4375
|
+
empty.type = "button";
|
|
4376
|
+
empty.disabled = true;
|
|
4377
|
+
empty.textContent = "No Piper voices — run /talk setup";
|
|
4378
|
+
panel.appendChild(empty);
|
|
4379
|
+
return;
|
|
4380
|
+
}
|
|
4381
|
+
for (const voice of voices) {
|
|
4382
|
+
const item = document.createElement("button");
|
|
4383
|
+
const pendingForItem = conversationVoicePending?.voiceId === voice.id;
|
|
4384
|
+
item.className = "composer-publish-menu-item composer-conversation-voice-item";
|
|
4385
|
+
item.type = "button";
|
|
4386
|
+
item.setAttribute("role", "menuitem");
|
|
4387
|
+
item.dataset.voiceId = voice.id;
|
|
4388
|
+
item.classList.toggle("active", voice.current === true);
|
|
4389
|
+
item.classList.toggle("pending", pendingForItem);
|
|
4390
|
+
const label = conversationVoiceShortLabel(voice.id);
|
|
4391
|
+
item.textContent = pendingForItem
|
|
4392
|
+
? conversationVoicePending.message
|
|
4393
|
+
: voice.current
|
|
4394
|
+
? `${label} ✓`
|
|
4395
|
+
: voice.downloaded
|
|
4396
|
+
? label
|
|
4397
|
+
: `${label} ↓${conversationVoiceDownloadSizeText(voice)}`;
|
|
4398
|
+
item.title = voice.current
|
|
4399
|
+
? `${voice.note || voice.id} — current voice`
|
|
4400
|
+
: voice.downloaded
|
|
4401
|
+
? `${voice.note || voice.id} — select this installed Piper voice`
|
|
4402
|
+
: `${voice.note || voice.id} — download and select with /talk voice ${voice.id}`;
|
|
4403
|
+
if (!voice.current) {
|
|
4404
|
+
item.setAttribute("aria-label", voice.downloaded ? `Select conversation voice ${voice.id}` : `Download and select conversation voice ${voice.id}`);
|
|
4405
|
+
}
|
|
4406
|
+
item.disabled = conversationVoiceSwitching || voice.current === true;
|
|
4407
|
+
let pointerActivated = false;
|
|
4408
|
+
const chooseVoice = (event) => {
|
|
4409
|
+
event.preventDefault();
|
|
4410
|
+
event.stopPropagation();
|
|
4411
|
+
void switchConversationVoice(voice.id);
|
|
4412
|
+
};
|
|
4413
|
+
item.addEventListener("pointerdown", (event) => {
|
|
4414
|
+
pointerActivated = true;
|
|
4415
|
+
chooseVoice(event);
|
|
4416
|
+
});
|
|
4417
|
+
item.addEventListener("click", (event) => {
|
|
4418
|
+
if (pointerActivated) {
|
|
4419
|
+
pointerActivated = false;
|
|
4420
|
+
event.preventDefault();
|
|
4421
|
+
event.stopPropagation();
|
|
4422
|
+
return;
|
|
4423
|
+
}
|
|
4424
|
+
chooseVoice(event);
|
|
4425
|
+
});
|
|
4426
|
+
panel.appendChild(item);
|
|
4427
|
+
}
|
|
4428
|
+
}
|
|
4429
|
+
|
|
4430
|
+
async function loadConversationVoices(tabContext = activeTabContext()) {
|
|
4431
|
+
if (!tabContext.tabId) return;
|
|
4432
|
+
try {
|
|
4433
|
+
const response = await api("/api/conversation-voices", { tabId: tabContext.tabId });
|
|
4434
|
+
if (!isCurrentTabContext(tabContext)) return;
|
|
4435
|
+
conversationVoicesLoadedForTab = tabContext.tabId;
|
|
4436
|
+
conversationVoiceLastData = response.data;
|
|
4437
|
+
renderConversationVoiceOptions(response.data);
|
|
4438
|
+
} catch (error) {
|
|
4439
|
+
if (isCurrentTabContext(tabContext)) {
|
|
4440
|
+
conversationVoicesLoadedForTab = null;
|
|
4441
|
+
const message = `conversation voice list failed: ${error.message || String(error)}`;
|
|
4442
|
+
addEvent(message, "warn");
|
|
4443
|
+
renderConversationVoicePanelNotice(message, "error");
|
|
4444
|
+
}
|
|
4445
|
+
}
|
|
4446
|
+
}
|
|
4447
|
+
|
|
4448
|
+
async function switchConversationVoice(voiceId) {
|
|
4449
|
+
const wanted = String(voiceId || "").trim();
|
|
4450
|
+
if (!wanted) return;
|
|
4451
|
+
if (conversationVoiceSwitching) {
|
|
4452
|
+
if (conversationVoicePending?.voiceId === wanted) return;
|
|
4453
|
+
addEvent(`Already switching conversation voice to ${conversationVoicePending?.voiceId || "another voice"}; wait for it to finish.`, "warn");
|
|
4454
|
+
return;
|
|
4455
|
+
}
|
|
4456
|
+
const tabContext = activeTabContext();
|
|
4457
|
+
if (!tabContext.tabId) return;
|
|
4458
|
+
const voice = conversationVoiceById(conversationVoiceLastData, wanted);
|
|
4459
|
+
const downloading = voice?.downloaded !== true;
|
|
4460
|
+
const startMessage = conversationVoiceStartMessage(voice, wanted);
|
|
4461
|
+
conversationVoiceSwitching = true;
|
|
4462
|
+
const label = conversationVoiceShortLabel(wanted);
|
|
4463
|
+
conversationVoicePending = { voiceId: wanted, phase: downloading ? "downloading" : "selecting", message: downloading ? `${label} ↓${conversationVoiceDownloadSizeText(voice)}…` : `${label}…` };
|
|
4464
|
+
setConversationVoiceMenuOpen(true);
|
|
4465
|
+
renderConversationVoiceOptions();
|
|
4466
|
+
if (elements.conversationVoiceButton) elements.conversationVoiceButton.disabled = true;
|
|
4467
|
+
if (elements.conversationVoiceButtonLabel) elements.conversationVoiceButtonLabel.textContent = `→ ${conversationVoiceShortLabel(wanted)}…`;
|
|
4468
|
+
updateConversationModeForTab(tabContext.tabId, {
|
|
4469
|
+
uiState: downloading ? "downloading" : "testing",
|
|
4470
|
+
statusText: downloading ? `Voice: downloading ${wanted} starting` : `Voice: testing ${wanted}`,
|
|
4471
|
+
}, { render: true, voiceLoop: true });
|
|
4472
|
+
showConversationVoiceFeedback(`${startMessage} Progress appears on the Voice chip.`, "info");
|
|
4473
|
+
try {
|
|
4474
|
+
const response = await api("/api/conversation-voice", { method: "POST", body: { voice: wanted }, tabId: tabContext.tabId });
|
|
4475
|
+
if (isCurrentTabContext(tabContext)) {
|
|
4476
|
+
applyResponseTab(response);
|
|
4477
|
+
conversationVoiceLastData = response.data;
|
|
4478
|
+
conversationVoicesLoadedForTab = tabContext.tabId;
|
|
4479
|
+
const current = response.data?.current || wanted;
|
|
4480
|
+
const output = cleanStatusText(response.data?.response?.data?.output || response.data?.response?.data?.message || "");
|
|
4481
|
+
renderConversationVoiceOptions(response.data);
|
|
4482
|
+
showConversationVoiceFeedback(`${downloading ? "Downloaded and selected" : "Selected"} conversation voice ${current}.${output ? ` ${output}` : ""}`, "info");
|
|
4483
|
+
setConversationVoiceMenuOpen(false);
|
|
4484
|
+
}
|
|
4485
|
+
} catch (error) {
|
|
4486
|
+
if (isCurrentTabContext(tabContext)) {
|
|
4487
|
+
updateConversationModeForTab(tabContext.tabId, { uiState: "error", statusText: "Voice: error" }, { render: true, voiceLoop: true });
|
|
4488
|
+
showConversationVoiceFeedback(`Voice switch failed: ${error.message || String(error)}`, "error");
|
|
4489
|
+
await loadConversationVoices(tabContext);
|
|
4490
|
+
}
|
|
4491
|
+
} finally {
|
|
4492
|
+
conversationVoiceSwitching = false;
|
|
4493
|
+
conversationVoicePending = null;
|
|
4494
|
+
if (isCurrentTabContext(tabContext)) {
|
|
4495
|
+
if (elements.conversationVoiceButton) elements.conversationVoiceButton.disabled = false;
|
|
4496
|
+
renderConversationVoiceOptions();
|
|
4497
|
+
renderConversationModeControls();
|
|
4498
|
+
}
|
|
4499
|
+
}
|
|
4500
|
+
}
|
|
4501
|
+
|
|
4502
|
+
// --- Natural Conversation browser voice loop (Phase 3) -----------------------
|
|
4503
|
+
// Browser Web Speech STT/TTS drives the active tab's conversation mode. The
|
|
4504
|
+
// controller logic lives in voice-conversation.mjs (dynamically imported so
|
|
4505
|
+
// app.js stays parseable as a plain script) and is tab-scoped: switching tabs
|
|
4506
|
+
// or disabling the mode tears the loop down.
|
|
4507
|
+
|
|
4508
|
+
const remoteMicConsentTabs = new Set();
|
|
4509
|
+
const VOICE_CONVERSATION_SILENCE_TIMEOUT_MS = 8000;
|
|
4510
|
+
let voiceConversation = null;
|
|
4511
|
+
let voiceConversationTabId = null;
|
|
4512
|
+
let voiceConversationStartToken = 0;
|
|
4513
|
+
let voiceConversationStartingForTab = null;
|
|
4514
|
+
let voiceConversationModulePromise = null;
|
|
4515
|
+
|
|
4516
|
+
function isLocalhostWebui() {
|
|
4517
|
+
const hostname = String(location.hostname || "").toLowerCase();
|
|
4518
|
+
return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "[::1]" || hostname === "::1";
|
|
4519
|
+
}
|
|
4520
|
+
|
|
4521
|
+
function remoteMicConsentGranted(tabId = activeTabId) {
|
|
4522
|
+
if (isLocalhostWebui()) return true;
|
|
4523
|
+
return !!tabId && remoteMicConsentTabs.has(tabId);
|
|
4524
|
+
}
|
|
4525
|
+
|
|
4526
|
+
function remoteMicConsentDisclosureText() {
|
|
4527
|
+
const host = location.host || "this Pi host";
|
|
4528
|
+
const provider = browserSpeechRecognitionCtor() ? "your browser's speech service" : "a browser speech service (unavailable in this browser)";
|
|
4529
|
+
return `Remote session: enabling the microphone captures audio in this browser tab and transcribes it with ${provider}; audio snippets may leave this device to your browser vendor. Only the resulting text transcripts are sent to Pi at ${host} — raw audio is never streamed to the Pi host. Consent applies to this tab only and ends with the conversation. Use End conversation to stop capture at any time.`;
|
|
4530
|
+
}
|
|
4531
|
+
|
|
4532
|
+
function browserSpeechRecognitionCtor() {
|
|
4533
|
+
return window.SpeechRecognition || window.webkitSpeechRecognition || null;
|
|
4534
|
+
}
|
|
4535
|
+
|
|
4536
|
+
function voiceConversationProviderLabel() {
|
|
4537
|
+
const stt = browserSpeechRecognitionCtor() ? "browser mic" : "no browser STT";
|
|
4538
|
+
const tts = window.speechSynthesis ? "browser voice" : "no browser TTS";
|
|
4539
|
+
return `${stt}, ${tts}`;
|
|
4540
|
+
}
|
|
4541
|
+
|
|
4542
|
+
function voiceConversationVisibleProviderLabel() {
|
|
4543
|
+
const hasStt = !!browserSpeechRecognitionCtor();
|
|
4544
|
+
const hasTts = !!window.speechSynthesis;
|
|
4545
|
+
if (hasStt && hasTts) return "browser STT/TTS";
|
|
4546
|
+
if (hasStt) return "browser STT";
|
|
4547
|
+
if (hasTts) return "browser TTS only";
|
|
4548
|
+
return "speech unsupported";
|
|
4549
|
+
}
|
|
4550
|
+
|
|
4551
|
+
function voiceConversationActiveFor(tabId = activeTabId) {
|
|
4552
|
+
return !!voiceConversation && !!tabId && voiceConversationTabId === tabId && voiceConversation.isActive();
|
|
4553
|
+
}
|
|
4554
|
+
|
|
4555
|
+
function updateVoiceConversationModeFromController(tabId = voiceConversationTabId) {
|
|
4556
|
+
if (!tabId || !voiceConversation) return;
|
|
4557
|
+
const state = voiceConversation.getState?.() || {};
|
|
4558
|
+
const uiState = state.uiState || "listening";
|
|
4559
|
+
updateConversationModeForTab(tabId, { uiState, statusText: `Voice: ${uiState}`, partialTranscript: state.partialTranscript || "" }, { render: true, voiceLoop: true });
|
|
4560
|
+
}
|
|
4561
|
+
|
|
4562
|
+
function toggleVoiceConversationPaused() {
|
|
4563
|
+
if (!activeTabId || !activeConversationMode().enabled) return;
|
|
4564
|
+
if (!voiceConversationActiveFor(activeTabId)) {
|
|
4565
|
+
if (!remoteMicConsentGranted(activeTabId)) {
|
|
4566
|
+
addEvent("Remote Web UI session: allow remote microphone streaming before resuming the browser voice loop.", "warn");
|
|
4567
|
+
renderConversationModeControls();
|
|
4568
|
+
return;
|
|
4569
|
+
}
|
|
4570
|
+
void startVoiceConversationLoop(activeTabId);
|
|
4571
|
+
return;
|
|
4572
|
+
}
|
|
4573
|
+
const next = voiceConversation.togglePaused?.();
|
|
4574
|
+
updateVoiceConversationModeFromController(activeTabId);
|
|
4575
|
+
addEvent(next?.userPaused ? "Browser voice loop paused; Natural Conversation safety remains active." : "Browser voice loop resumed.", "info");
|
|
4576
|
+
}
|
|
4577
|
+
|
|
4578
|
+
function loadVoiceConversationModule() {
|
|
4579
|
+
if (!voiceConversationModulePromise) {
|
|
4580
|
+
voiceConversationModulePromise = import("./voice-conversation.mjs?v=1");
|
|
4581
|
+
voiceConversationModulePromise.catch(() => {
|
|
4582
|
+
voiceConversationModulePromise = null;
|
|
4583
|
+
});
|
|
4584
|
+
}
|
|
4585
|
+
return voiceConversationModulePromise;
|
|
4586
|
+
}
|
|
4587
|
+
|
|
4588
|
+
function speakableTextFromMarkdown(text) {
|
|
4589
|
+
return String(text || "")
|
|
4590
|
+
.replace(/```[\s\S]*?```/g, " Code block omitted. ")
|
|
4591
|
+
.replace(/`([^`\n]+)`/g, "$1")
|
|
4592
|
+
.replace(/!\[([^\]]*)\]\([^)]*\)/g, "$1")
|
|
4593
|
+
.replace(/\[([^\]]+)\]\([^)]*\)/g, "$1")
|
|
4594
|
+
.replace(/^#{1,6}\s+/gm, "")
|
|
4595
|
+
.replace(/^\s*[-*+]\s+/gm, "")
|
|
4596
|
+
.replace(/(\*\*|__|\*|_|~~)(\S(?:[^*_~]*\S)?)\1/g, "$2")
|
|
4597
|
+
.replace(/\s+/g, " ")
|
|
4598
|
+
.trim();
|
|
4599
|
+
}
|
|
4600
|
+
|
|
4601
|
+
function latestAssistantSpokenText() {
|
|
4602
|
+
for (let index = latestMessages.length - 1; index >= 0; index -= 1) {
|
|
4603
|
+
const message = latestMessages[index];
|
|
4604
|
+
if (message?.role !== "assistant") continue;
|
|
4605
|
+
const finalMessage = assistantDisplayMessages(message).find((item) => item?.title === "final output");
|
|
4606
|
+
return finalMessage ? textFromContent(finalMessage.content) : "";
|
|
4607
|
+
}
|
|
4608
|
+
return "";
|
|
4609
|
+
}
|
|
4610
|
+
|
|
4611
|
+
function assistantTextAsksQuestion(text) {
|
|
4612
|
+
const lines = String(text || "").trim().split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
|
|
4613
|
+
const lastLine = lines[lines.length - 1] || "";
|
|
4614
|
+
return /\?["')\]]*$/.test(lastLine);
|
|
4615
|
+
}
|
|
4616
|
+
|
|
4617
|
+
async function startVoiceConversationLoop(tabId = activeTabId) {
|
|
4618
|
+
if (!tabId || voiceConversationActiveFor(tabId) || voiceConversationStartingForTab === tabId) return;
|
|
4619
|
+
if (voiceConversation) stopVoiceConversationLoop();
|
|
4620
|
+
if (!remoteMicConsentGranted(tabId)) {
|
|
4621
|
+
const mode = normalizeConversationModeState(conversationModeByTab.get(tabId) || {});
|
|
4622
|
+
if (mode.uiState !== "paused") {
|
|
4623
|
+
updateConversationModeForTab(tabId, { uiState: "paused", statusText: "Voice: paused" }, { render: true, voiceLoop: true });
|
|
4624
|
+
addEvent("Remote Web UI session: the microphone stays off until you allow remote microphone streaming for this tab.", "warn");
|
|
4625
|
+
}
|
|
4626
|
+
return;
|
|
4627
|
+
}
|
|
4628
|
+
const token = ++voiceConversationStartToken;
|
|
4629
|
+
voiceConversationStartingForTab = tabId;
|
|
4630
|
+
let module = null;
|
|
4631
|
+
try {
|
|
4632
|
+
module = await loadVoiceConversationModule();
|
|
4633
|
+
} catch (error) {
|
|
4634
|
+
addEvent(`failed to load the voice conversation module: ${error?.message || String(error)}`, "error");
|
|
4635
|
+
return;
|
|
4636
|
+
} finally {
|
|
4637
|
+
voiceConversationStartingForTab = null;
|
|
4638
|
+
}
|
|
4639
|
+
if (token !== voiceConversationStartToken || tabId !== activeTabId) return;
|
|
4640
|
+
if (!activeConversationMode().enabled) return;
|
|
4641
|
+
const controller = module.createVoiceConversationController({
|
|
4642
|
+
recognitionFactory: () => {
|
|
4643
|
+
const Recognition = browserSpeechRecognitionCtor();
|
|
4644
|
+
if (!Recognition) return null;
|
|
4645
|
+
try {
|
|
4646
|
+
const recognition = new Recognition();
|
|
4647
|
+
recognition.lang = navigator.language || "en-US";
|
|
4648
|
+
return recognition;
|
|
4649
|
+
} catch {
|
|
4650
|
+
return null;
|
|
4651
|
+
}
|
|
4652
|
+
},
|
|
4653
|
+
synthesis: window.speechSynthesis || null,
|
|
4654
|
+
utteranceFactory: (text) => new SpeechSynthesisUtterance(text),
|
|
4655
|
+
sendTranscript: async (text, { reason } = {}) => {
|
|
4656
|
+
if (!voiceConversationActiveFor(tabId) || tabId !== activeTabId) return;
|
|
4657
|
+
if (reason === "interrupt" && currentState?.isStreaming) {
|
|
4658
|
+
await sendPrompt("steer", `[Voice interruption: the user started speaking over the current answer.] ${text}`, { targetTabId: tabId, throwOnError: true });
|
|
4659
|
+
return;
|
|
4660
|
+
}
|
|
4661
|
+
await sendPrompt("prompt", text, { targetTabId: tabId, throwOnError: true });
|
|
4662
|
+
},
|
|
4663
|
+
sendSilenceEvent: async ({ silentSeconds } = {}) => {
|
|
4664
|
+
if (!voiceConversationActiveFor(tabId) || tabId !== activeTabId) return;
|
|
4665
|
+
await sendPrompt("prompt", module.voiceSilenceEventMessage(silentSeconds), { targetTabId: tabId, throwOnError: true });
|
|
4666
|
+
},
|
|
4667
|
+
onPartialTranscript: (partialTranscript) => {
|
|
4668
|
+
if (voiceConversationTabId !== tabId) return;
|
|
4669
|
+
updateConversationModeForTab(tabId, { uiState: partialTranscript ? "transcribing" : undefined, partialTranscript }, { render: true, voiceLoop: true });
|
|
4670
|
+
},
|
|
4671
|
+
onStateChange: (uiState, state = {}) => {
|
|
4672
|
+
if (voiceConversationTabId !== tabId || uiState === "off") return;
|
|
4673
|
+
updateConversationModeForTab(tabId, { uiState, statusText: `Voice: ${uiState}`, partialTranscript: state.partialTranscript || "" }, { render: true, voiceLoop: true });
|
|
4674
|
+
},
|
|
4675
|
+
onEvent: (message, level = "info") => addEvent(message, level),
|
|
4676
|
+
bargeInEnabled: false,
|
|
4677
|
+
silenceTimeoutMs: VOICE_CONVERSATION_SILENCE_TIMEOUT_MS,
|
|
4678
|
+
});
|
|
4679
|
+
voiceConversation = controller;
|
|
4680
|
+
voiceConversationTabId = tabId;
|
|
4681
|
+
controller.start();
|
|
4682
|
+
}
|
|
4683
|
+
|
|
4684
|
+
function stopVoiceConversationLoop() {
|
|
4685
|
+
voiceConversationStartToken += 1;
|
|
4686
|
+
const controller = voiceConversation;
|
|
4687
|
+
voiceConversation = null;
|
|
4688
|
+
voiceConversationTabId = null;
|
|
4689
|
+
if (controller) {
|
|
4690
|
+
try {
|
|
4691
|
+
controller.stop();
|
|
4692
|
+
} catch {
|
|
4693
|
+
// Tearing down a broken speech engine must not break the UI.
|
|
4694
|
+
}
|
|
4695
|
+
}
|
|
4696
|
+
}
|
|
4697
|
+
|
|
4698
|
+
// The package's native audio loop (mic + Piper TTS on the Pi host) announces
|
|
4699
|
+
// itself through its "natural-conversation-audio" widget. While it is armed —
|
|
4700
|
+
// listening or paused — the browser Web Speech loop must stand down entirely,
|
|
4701
|
+
// otherwise both loops transcribe the same speech and speak every answer twice
|
|
4702
|
+
// (native Piper voice + browser voice).
|
|
4703
|
+
function nativeConversationAudioEngaged() {
|
|
4704
|
+
return widgets.has("natural-conversation-audio");
|
|
4705
|
+
}
|
|
4706
|
+
|
|
4707
|
+
function syncVoiceConversationLoop() {
|
|
4708
|
+
const mode = activeConversationMode();
|
|
4709
|
+
const shouldRun = mode.enabled === true && !!activeTabId && !nativeConversationAudioEngaged();
|
|
4710
|
+
if (voiceConversation && (!shouldRun || voiceConversationTabId !== activeTabId)) stopVoiceConversationLoop();
|
|
4711
|
+
if (shouldRun && !voiceConversationActiveFor(activeTabId)) void startVoiceConversationLoop(activeTabId);
|
|
4712
|
+
}
|
|
4713
|
+
|
|
4714
|
+
async function handleVoiceConversationTurnEnd(tabContext = activeTabContext()) {
|
|
4715
|
+
const tabId = tabContext.tabId;
|
|
4716
|
+
if (!voiceConversationActiveFor(tabId)) return;
|
|
4717
|
+
try {
|
|
4718
|
+
await refreshMessages(tabContext);
|
|
4719
|
+
} catch {
|
|
4720
|
+
// Speak whatever transcript state we already have.
|
|
4721
|
+
}
|
|
4722
|
+
if (!isCurrentTabContext(tabContext) || !voiceConversationActiveFor(tabId)) return;
|
|
4723
|
+
const spoken = speakableTextFromMarkdown(latestAssistantSpokenText());
|
|
4724
|
+
voiceConversation.handleAssistantTurnEnd(spoken, { askedQuestion: assistantTextAsksQuestion(spoken) });
|
|
4725
|
+
}
|
|
4726
|
+
|
|
4034
4727
|
function renderOptionalFeatureDependentDisplays() {
|
|
4035
4728
|
renderOptionalFeatureControls();
|
|
4036
4729
|
renderThemeSelect();
|
|
@@ -4070,6 +4763,10 @@ function setOptionalFeatureDisabled(featureId, disabled) {
|
|
|
4070
4763
|
statusEntries.delete("pi-remote-webui");
|
|
4071
4764
|
widgets.delete("pi-remote-webui");
|
|
4072
4765
|
}
|
|
4766
|
+
if (featureId === "naturalConversation" && disabled && !activeConversationMode().enabled) {
|
|
4767
|
+
statusEntries.delete(NATURAL_CONVERSATION_STATUS_KEY);
|
|
4768
|
+
updateConversationModeForTab(activeTabId, { available: false, enabled: false, uiState: "off", statusText: "" }, { render: false });
|
|
4769
|
+
}
|
|
4073
4770
|
storeDisabledOptionalFeatures();
|
|
4074
4771
|
renderOptionalFeatureDependentDisplays();
|
|
4075
4772
|
const tabContext = activeTabContext();
|
|
@@ -4500,6 +5197,7 @@ function syncTabMetadata(nextTabs = []) {
|
|
|
4500
5197
|
liveIds.add(tab.id);
|
|
4501
5198
|
setTabActivity(tab.id, tab.activity);
|
|
4502
5199
|
if (Object.prototype.hasOwnProperty.call(tab, "appRunner")) setAppRunnerData(tab.id, { activeRun: tab.appRunner });
|
|
5200
|
+
if (Object.prototype.hasOwnProperty.call(tab, "conversationMode")) updateConversationModeForTab(tab.id, tab.conversationMode, { render: false });
|
|
4503
5201
|
}
|
|
4504
5202
|
for (const tabId of tabActivities.keys()) {
|
|
4505
5203
|
if (!liveIds.has(tabId)) {
|
|
@@ -4512,6 +5210,9 @@ function syncTabMetadata(nextTabs = []) {
|
|
|
4512
5210
|
tabMessagesCache.delete(tabId);
|
|
4513
5211
|
widgetsByTab.delete(tabId);
|
|
4514
5212
|
appRunnerDataByTab.delete(tabId);
|
|
5213
|
+
conversationModeByTab.delete(tabId);
|
|
5214
|
+
remoteMicConsentTabs.delete(tabId);
|
|
5215
|
+
if (voiceConversationTabId === tabId) stopVoiceConversationLoop();
|
|
4515
5216
|
clearGitWorkflowForTab(tabId);
|
|
4516
5217
|
}
|
|
4517
5218
|
}
|
|
@@ -4527,6 +5228,8 @@ function applyTabMetadata(tab) {
|
|
|
4527
5228
|
if (index === -1) tabs.push(tab);
|
|
4528
5229
|
else tabs[index] = { ...tabs[index], ...tab };
|
|
4529
5230
|
if (tab.activity) setTabActivity(tab.id, tab.activity);
|
|
5231
|
+
if (Object.prototype.hasOwnProperty.call(tab, "conversationMode")) updateConversationModeForTab(tab.id, tab.conversationMode, { render: false });
|
|
5232
|
+
renderConversationModeControls();
|
|
4530
5233
|
renderTabs();
|
|
4531
5234
|
return true;
|
|
4532
5235
|
}
|
|
@@ -4853,6 +5556,9 @@ function setWidgetForTab(tabId, widgetKey, request) {
|
|
|
4853
5556
|
if (targetTabId === activeTabId) {
|
|
4854
5557
|
if (hasLines) widgets.set(widgetKey, request);
|
|
4855
5558
|
else widgets.delete(widgetKey);
|
|
5559
|
+
// Native audio starting/stopping must immediately re-arbitrate which
|
|
5560
|
+
// voice loop (native vs. browser Web Speech) owns this conversation.
|
|
5561
|
+
if (widgetKey === "natural-conversation-audio") queueMicrotask(() => renderConversationModeControls());
|
|
4856
5562
|
}
|
|
4857
5563
|
|
|
4858
5564
|
return true;
|
|
@@ -5033,17 +5739,34 @@ function terminalAppRunnerTooltip(run) {
|
|
|
5033
5739
|
return appRunnerIsRunning(run) ? ` · ${terminalAppRunnerLabel(run)}` : "";
|
|
5034
5740
|
}
|
|
5035
5741
|
|
|
5742
|
+
function tabConversationMode(tab) {
|
|
5743
|
+
if (!tab?.id) return normalizeConversationModeState(tab?.conversationMode || {});
|
|
5744
|
+
return normalizeConversationModeState(conversationModeByTab.get(tab.id) || tab.conversationMode || {});
|
|
5745
|
+
}
|
|
5746
|
+
|
|
5747
|
+
function tabConversationModeActive(tab) {
|
|
5748
|
+
return tabConversationMode(tab).enabled === true;
|
|
5749
|
+
}
|
|
5750
|
+
|
|
5751
|
+
function terminalConversationModeTooltip(tab) {
|
|
5752
|
+
const mode = tabConversationMode(tab);
|
|
5753
|
+
return mode.enabled ? ` · natural conversation: ${mode.uiState || "listening"}` : "";
|
|
5754
|
+
}
|
|
5755
|
+
|
|
5036
5756
|
function terminalTabMeta(tab, indicator) {
|
|
5037
|
-
const
|
|
5038
|
-
|
|
5757
|
+
const parts = [tab.running ? `${indicator.meta} · pid ${tab.pid || "…"}` : "stopped"];
|
|
5758
|
+
if (tabAppRunnerRunningRun(tab)) parts.push("app runner");
|
|
5759
|
+
if (tabConversationModeActive(tab)) parts.push("voice");
|
|
5760
|
+
return parts.join(" · ");
|
|
5039
5761
|
}
|
|
5040
5762
|
|
|
5041
|
-
function appendTerminalTabContent(button, { title, indicator, meta, count = null, appRunnerRun = null }) {
|
|
5763
|
+
function appendTerminalTabContent(button, { title, indicator, meta, count = null, appRunnerRun = null, conversationModeActive = false }) {
|
|
5042
5764
|
const titleRow = make("span", "terminal-tab-title-row");
|
|
5043
5765
|
const indicatorDot = make("span", "terminal-tab-activity-indicator");
|
|
5044
5766
|
indicatorDot.setAttribute("aria-hidden", "true");
|
|
5045
5767
|
titleRow.append(indicatorDot, make("span", "terminal-tab-title", title));
|
|
5046
5768
|
if (appRunnerIsRunning(appRunnerRun)) titleRow.append(make("span", "terminal-tab-app-runner-indicator", "app"));
|
|
5769
|
+
if (conversationModeActive) titleRow.append(make("span", "terminal-tab-conversation-indicator", "voice"));
|
|
5047
5770
|
if (count !== null) titleRow.append(make("span", "terminal-tab-group-count", String(count)));
|
|
5048
5771
|
button.append(titleRow, make("span", "terminal-tab-meta", meta));
|
|
5049
5772
|
}
|
|
@@ -5053,7 +5776,9 @@ function renderTerminalTab(tab) {
|
|
|
5053
5776
|
const indicator = tabIndicator(tab);
|
|
5054
5777
|
const appRunnerRun = tabAppRunnerRunningRun(tab);
|
|
5055
5778
|
const appRunnerLabel = appRunnerRun ? terminalAppRunnerLabel(appRunnerRun) : "";
|
|
5056
|
-
const
|
|
5779
|
+
const conversationModeActive = tabConversationModeActive(tab);
|
|
5780
|
+
const conversationLabel = conversationModeActive ? `, natural conversation ${tabConversationMode(tab).uiState || "listening"}` : "";
|
|
5781
|
+
const wrapper = make("div", `terminal-tab activity-${indicator.state}${isActive ? " active" : ""}${tab.running ? "" : " stopped"}${appRunnerRun ? " app-runner-running" : ""}${conversationModeActive ? " conversation-mode-running" : ""}`);
|
|
5057
5782
|
wrapper.dataset.tabId = tab.id;
|
|
5058
5783
|
bindTerminalTabDragAndDrop(wrapper, { sourceTabId: tab.id, target: { type: "tab", tabId: tab.id } });
|
|
5059
5784
|
const button = make("button", "terminal-tab-button");
|
|
@@ -5061,10 +5786,10 @@ function renderTerminalTab(tab) {
|
|
|
5061
5786
|
button.draggable = false;
|
|
5062
5787
|
button.setAttribute("role", "tab");
|
|
5063
5788
|
button.setAttribute("aria-selected", isActive ? "true" : "false");
|
|
5064
|
-
button.setAttribute("aria-label", `${tab.title}: ${indicator.label}${appRunnerLabel ? `, ${appRunnerLabel}` : ""}`);
|
|
5065
|
-
const tooltip = `${tab.title} · ${indicator.label}${tab.running ? ` · pid ${tab.pid || "starting"}` : " · stopped"}${terminalAppRunnerTooltip(appRunnerRun)} · drag onto another tab or group to group`;
|
|
5789
|
+
button.setAttribute("aria-label", `${tab.title}: ${indicator.label}${appRunnerLabel ? `, ${appRunnerLabel}` : ""}${conversationLabel}`);
|
|
5790
|
+
const tooltip = `${tab.title} · ${indicator.label}${tab.running ? ` · pid ${tab.pid || "starting"}` : " · stopped"}${terminalAppRunnerTooltip(appRunnerRun)}${terminalConversationModeTooltip(tab)} · drag onto another tab or group to group`;
|
|
5066
5791
|
applyStyledTooltip(button, tooltip, { ariaLabel: false });
|
|
5067
|
-
appendTerminalTabContent(button, { title: tab.title, indicator, meta: terminalTabMeta(tab, indicator), appRunnerRun });
|
|
5792
|
+
appendTerminalTabContent(button, { title: tab.title, indicator, meta: terminalTabMeta(tab, indicator), appRunnerRun, conversationModeActive });
|
|
5068
5793
|
button.addEventListener("click", () => switchTab(tab.id));
|
|
5069
5794
|
wrapper.append(button);
|
|
5070
5795
|
|
|
@@ -5089,7 +5814,9 @@ function renderTerminalTabGroupItem(tab, group) {
|
|
|
5089
5814
|
const indicator = tabIndicator(tab);
|
|
5090
5815
|
const appRunnerRun = tabAppRunnerRunningRun(tab);
|
|
5091
5816
|
const appRunnerLabel = appRunnerRun ? terminalAppRunnerLabel(appRunnerRun) : "";
|
|
5092
|
-
const
|
|
5817
|
+
const conversationModeActive = tabConversationModeActive(tab);
|
|
5818
|
+
const conversationLabel = conversationModeActive ? `, natural conversation ${tabConversationMode(tab).uiState || "listening"}` : "";
|
|
5819
|
+
const item = make("div", `terminal-tab-group-item activity-${indicator.state}${isActive ? " active" : ""}${tab.running ? "" : " stopped"}${appRunnerRun ? " app-runner-running" : ""}${conversationModeActive ? " conversation-mode-running" : ""}`);
|
|
5093
5820
|
item.dataset.tabId = tab.id;
|
|
5094
5821
|
bindTerminalTabDragAndDrop(item, { sourceTabId: tab.id, target: group?.custom ? { type: "group", group } : { type: "tab", tabId: tab.id } });
|
|
5095
5822
|
const button = make("button", "terminal-tab-button terminal-tab-group-item-button");
|
|
@@ -5097,10 +5824,10 @@ function renderTerminalTabGroupItem(tab, group) {
|
|
|
5097
5824
|
button.draggable = false;
|
|
5098
5825
|
button.setAttribute("role", "tab");
|
|
5099
5826
|
button.setAttribute("aria-selected", isActive ? "true" : "false");
|
|
5100
|
-
button.setAttribute("aria-label", `${tab.title}: ${indicator.label}${appRunnerLabel ? `, ${appRunnerLabel}` : ""}`);
|
|
5101
|
-
const tooltip = `${tab.title} · ${indicator.label}${tab.running ? ` · pid ${tab.pid || "starting"}` : " · stopped"}${terminalAppRunnerTooltip(appRunnerRun)} · drag onto another tab or group to group`;
|
|
5827
|
+
button.setAttribute("aria-label", `${tab.title}: ${indicator.label}${appRunnerLabel ? `, ${appRunnerLabel}` : ""}${conversationLabel}`);
|
|
5828
|
+
const tooltip = `${tab.title} · ${indicator.label}${tab.running ? ` · pid ${tab.pid || "starting"}` : " · stopped"}${terminalAppRunnerTooltip(appRunnerRun)}${terminalConversationModeTooltip(tab)} · drag onto another tab or group to group`;
|
|
5102
5829
|
applyStyledTooltip(button, tooltip, { ariaLabel: false });
|
|
5103
|
-
appendTerminalTabContent(button, { title: tab.title, indicator, meta: terminalTabMeta(tab, indicator), appRunnerRun });
|
|
5830
|
+
appendTerminalTabContent(button, { title: tab.title, indicator, meta: terminalTabMeta(tab, indicator), appRunnerRun, conversationModeActive });
|
|
5104
5831
|
button.addEventListener("click", (event) => {
|
|
5105
5832
|
event.stopPropagation();
|
|
5106
5833
|
switchTab(tab.id);
|
|
@@ -5331,6 +6058,7 @@ async function switchTab(tabId) {
|
|
|
5331
6058
|
cacheMessagesForTab(activeTabId);
|
|
5332
6059
|
cacheWidgetsForTab(activeTabId);
|
|
5333
6060
|
const tabContext = setActiveTabId(tabId, { remember: true });
|
|
6061
|
+
if (voiceConversation && voiceConversationTabId !== tabId) stopVoiceConversationLoop();
|
|
5334
6062
|
resetActiveTabUi();
|
|
5335
6063
|
renderTabs();
|
|
5336
6064
|
restoreActiveDraft();
|
|
@@ -6422,6 +7150,10 @@ function footerMeta(label, value, className = "", options = {}) {
|
|
|
6422
7150
|
node.addEventListener("click", options.onClick);
|
|
6423
7151
|
if (options.ariaPressed !== undefined) node.setAttribute("aria-pressed", options.ariaPressed ? "true" : "false");
|
|
6424
7152
|
if (options.ariaBusy) node.setAttribute("aria-busy", "true");
|
|
7153
|
+
if (options.disabled) {
|
|
7154
|
+
node.disabled = true;
|
|
7155
|
+
node.setAttribute("aria-disabled", "true");
|
|
7156
|
+
}
|
|
6425
7157
|
}
|
|
6426
7158
|
node.append(make("span", "footer-meta-label", label), make("span", "footer-meta-value", value));
|
|
6427
7159
|
return applyFooterTooltip(node, options.title || `${label}: ${value}`, { align: options.tooltipAlign });
|
|
@@ -6460,7 +7192,7 @@ const GIT_FOOTER_TOOLTIP_COPY = {
|
|
|
6460
7192
|
cwd: "Active working directory for this Web UI tab.",
|
|
6461
7193
|
git: "Current Git branch. detached means HEAD is not on a branch; no repo means the cwd is outside a Git work tree.",
|
|
6462
7194
|
"git-state": "Active Git operation or detached state. Finish or abort rebase/merge/cherry-pick/revert/bisect before normal commits.",
|
|
6463
|
-
sync: "Remote tracking divergence. ↑ means local commits ahead; ↓ means remote commits to pull.",
|
|
7195
|
+
sync: "Remote tracking divergence. ↑ means local commits ahead; ↓ means remote commits to pull. Click when ↑ appears to run git push for this tab.",
|
|
6464
7196
|
changes: "Working tree and fetched remote summary. 🟢 staged, ✏️ modified unstaged, ➕ untracked, ⚠️ conflicted; ⬇️ means fetched remote commits to pull; 🔄/✓/⚠️ fetch shows the tab git fetch state; ✅ means no changes.",
|
|
6465
7197
|
"git-extra": "Extra Git signals. 📦 stash, 🧩 dirty submodules, 🌳 worktrees, 🏷️ tag at HEAD, 🕒 last commit age, 🔓 signing mismatch.",
|
|
6466
7198
|
worktree: "Git worktree checkout for this tab. Use branch worktrees to work on branches in parallel without switching this checkout.",
|
|
@@ -6801,6 +7533,43 @@ function renderGitFooterPayloadMetric(chip) {
|
|
|
6801
7533
|
return chip.contextUsage ? applyFooterContextUsage(node, chip.contextUsage) : node;
|
|
6802
7534
|
}
|
|
6803
7535
|
|
|
7536
|
+
function gitFooterSyncOutgoingCount(value) {
|
|
7537
|
+
const match = String(value || "").match(/[↑⇡]\s*(\d+)/u);
|
|
7538
|
+
return match ? Number.parseInt(match[1] || "0", 10) || 0 : 0;
|
|
7539
|
+
}
|
|
7540
|
+
|
|
7541
|
+
function gitFooterSyncChipHasOutgoing(chip) {
|
|
7542
|
+
return chip?.key === "sync" && gitFooterSyncOutgoingCount(chip.value) > 0;
|
|
7543
|
+
}
|
|
7544
|
+
|
|
7545
|
+
async function pushGitFooterSync(tabId = activeTabId, syncValue = "") {
|
|
7546
|
+
if (!tabId || gitFooterSyncPushInFlightByTab.has(tabId)) return;
|
|
7547
|
+
const outgoing = gitFooterSyncOutgoingCount(syncValue);
|
|
7548
|
+
if (outgoing <= 0) return;
|
|
7549
|
+
const tabContext = activeTabContext(tabId);
|
|
7550
|
+
const tab = tabs.find((item) => item.id === tabId);
|
|
7551
|
+
const target = tab?.title || tab?.cwd || "this tab";
|
|
7552
|
+
hideFooterTooltip();
|
|
7553
|
+
if (!window.confirm(`Run git push for ${outgoing} outgoing commit${outgoing === 1 ? "" : "s"} in ${target}?`)) return;
|
|
7554
|
+
|
|
7555
|
+
gitFooterSyncPushInFlightByTab.add(tabId);
|
|
7556
|
+
if (isCurrentTabContext(tabContext)) renderFooter();
|
|
7557
|
+
try {
|
|
7558
|
+
const response = await api("/api/git-workflow/push", { method: "POST", body: {}, tabId });
|
|
7559
|
+
if (!response.ok) {
|
|
7560
|
+
const detail = [response.error, formatGitCommandResult(response.data)].filter(Boolean).join("\n\n").trim();
|
|
7561
|
+
throw new Error(detail || "git push failed");
|
|
7562
|
+
}
|
|
7563
|
+
addEvent(`Pushed ${outgoing} outgoing commit${outgoing === 1 ? "" : "s"}.`, "success");
|
|
7564
|
+
requestGitFooterWebuiPayload(tabContext, { force: true });
|
|
7565
|
+
} catch (error) {
|
|
7566
|
+
addEvent(error.message || String(error), "error");
|
|
7567
|
+
} finally {
|
|
7568
|
+
gitFooterSyncPushInFlightByTab.delete(tabId);
|
|
7569
|
+
if (isCurrentTabContext(tabContext)) renderFooter();
|
|
7570
|
+
}
|
|
7571
|
+
}
|
|
7572
|
+
|
|
6804
7573
|
function renderGitFooterPayloadMeta(chip, tab) {
|
|
6805
7574
|
const options = {};
|
|
6806
7575
|
let action = "";
|
|
@@ -6816,6 +7585,13 @@ function renderGitFooterPayloadMeta(chip, tab) {
|
|
|
6816
7585
|
} else if (chip.key === "worktree") {
|
|
6817
7586
|
options.onClick = () => setFooterBranchPickerOpen(!footerBranchPickerOpen);
|
|
6818
7587
|
action = "Click to manage branch worktrees for this repository.";
|
|
7588
|
+
} else if (chip.key === "sync" && gitFooterSyncChipHasOutgoing(chip)) {
|
|
7589
|
+
const tabId = tab?.id || activeTabId;
|
|
7590
|
+
const inFlight = tabId ? gitFooterSyncPushInFlightByTab.has(tabId) : false;
|
|
7591
|
+
options.onClick = () => pushGitFooterSync(tabId, chip.value);
|
|
7592
|
+
options.ariaBusy = inFlight;
|
|
7593
|
+
options.disabled = inFlight;
|
|
7594
|
+
action = inFlight ? "Pushing local commits to the configured remote." : "Click to push local commits to the configured remote.";
|
|
6819
7595
|
} else if (chip.key === "changes") {
|
|
6820
7596
|
options.onClick = openGitChangesDialog;
|
|
6821
7597
|
action = "Click to view the current git diff.";
|
|
@@ -6857,8 +7633,9 @@ function gitFooterChipShapeKey(chip) {
|
|
|
6857
7633
|
function gitFooterPickerStateKey() {
|
|
6858
7634
|
const tabContext = activeTabContext();
|
|
6859
7635
|
const refreshInFlight = tabContext.tabId ? gitFooterPayloadRefreshInFlightByTab.has(tabContext.tabId) : false;
|
|
7636
|
+
const syncPushInFlight = tabContext.tabId ? gitFooterSyncPushInFlightByTab.has(tabContext.tabId) : false;
|
|
6860
7637
|
const refreshAvailable = hasLoadedRpcCommand("git-footer-refresh");
|
|
6861
|
-
return `${footerModelPickerOpen ? 1 : 0}|${footerThinkingPickerOpen ? 1 : 0}|${footerBranchPickerOpen ? 1 : 0}|${mobileFooterExpanded ? 1 : 0}|${refreshInFlight ? 1 : 0}|${refreshAvailable ? 1 : 0}`;
|
|
7638
|
+
return `${footerModelPickerOpen ? 1 : 0}|${footerThinkingPickerOpen ? 1 : 0}|${footerBranchPickerOpen ? 1 : 0}|${mobileFooterExpanded ? 1 : 0}|${refreshInFlight ? 1 : 0}|${syncPushInFlight ? 1 : 0}|${refreshAvailable ? 1 : 0}`;
|
|
6862
7639
|
}
|
|
6863
7640
|
|
|
6864
7641
|
function updateGitFooterChipNodeValue(node, chip, valueSelector) {
|
|
@@ -7363,9 +8140,148 @@ function gitChangesGeneratedLabel(data) {
|
|
|
7363
8140
|
return `Updated ${new Date(timestamp).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit", second: "2-digit" })}`;
|
|
7364
8141
|
}
|
|
7365
8142
|
|
|
8143
|
+
function gitPullOutputLines(result = {}) {
|
|
8144
|
+
return [result.stdout, result.stderr]
|
|
8145
|
+
.map((value) => stripAnsi(value || "").trim())
|
|
8146
|
+
.filter(Boolean)
|
|
8147
|
+
.join("\n")
|
|
8148
|
+
.split(/\r?\n/)
|
|
8149
|
+
.map((line) => line.trimEnd())
|
|
8150
|
+
.filter((line) => line.trim());
|
|
8151
|
+
}
|
|
8152
|
+
|
|
8153
|
+
function parseGitPullSummaryLine(line) {
|
|
8154
|
+
const text = String(line || "").trim();
|
|
8155
|
+
if (!/\bfiles? changed\b|\binsertions?\(\+\)|\bdeletions?\(-\)/.test(text)) return null;
|
|
8156
|
+
const numberFrom = (regex) => {
|
|
8157
|
+
const match = text.match(regex);
|
|
8158
|
+
return match ? Number.parseInt(String(match[1] || "0").replace(/,/g, ""), 10) || 0 : 0;
|
|
8159
|
+
};
|
|
8160
|
+
return {
|
|
8161
|
+
summaryLine: text,
|
|
8162
|
+
totalFiles: numberFrom(/([\d,]+)\s+files? changed/),
|
|
8163
|
+
insertions: numberFrom(/([\d,]+)\s+insertions?\(\+\)/),
|
|
8164
|
+
deletions: numberFrom(/([\d,]+)\s+deletions?\(-\)/),
|
|
8165
|
+
};
|
|
8166
|
+
}
|
|
8167
|
+
|
|
8168
|
+
function parseGitPullFileStatLine(line) {
|
|
8169
|
+
const match = String(line || "").match(/^(.+?)\s+\|\s+(.+)$/);
|
|
8170
|
+
if (!match) return null;
|
|
8171
|
+
const path = match[1].trim();
|
|
8172
|
+
const stats = match[2].trim();
|
|
8173
|
+
if (!path || !stats) return null;
|
|
8174
|
+
const tone = stats.includes("-") && !stats.includes("+") ? "danger" : stats.includes("+") ? "success" : "muted";
|
|
8175
|
+
return { path, stats, tone };
|
|
8176
|
+
}
|
|
8177
|
+
|
|
8178
|
+
function normalizeGitPullResult(result = {}) {
|
|
8179
|
+
const outputLines = gitPullOutputLines(result);
|
|
8180
|
+
const changedFiles = [];
|
|
8181
|
+
const modeLines = [];
|
|
8182
|
+
let updateRange = "";
|
|
8183
|
+
let strategy = "";
|
|
8184
|
+
let summary = null;
|
|
8185
|
+
let alreadyUpToDate = false;
|
|
8186
|
+
|
|
8187
|
+
for (const line of outputLines) {
|
|
8188
|
+
const text = line.trim();
|
|
8189
|
+
const rangeMatch = text.match(/^Updating\s+([0-9a-f]+)\.\.([0-9a-f]+)/i);
|
|
8190
|
+
if (!updateRange && rangeMatch) updateRange = `${rangeMatch[1]}…${rangeMatch[2]}`;
|
|
8191
|
+
if (!strategy && (/^Fast-forward$/i.test(text) || /^Merge made by\b/i.test(text))) strategy = text;
|
|
8192
|
+
if (/^Already up to date\.?$/i.test(text)) {
|
|
8193
|
+
alreadyUpToDate = true;
|
|
8194
|
+
strategy = text.replace(/\.?$/, ".");
|
|
8195
|
+
}
|
|
8196
|
+
const summaryLine = parseGitPullSummaryLine(text);
|
|
8197
|
+
if (summaryLine) summary = summaryLine;
|
|
8198
|
+
const stat = parseGitPullFileStatLine(text);
|
|
8199
|
+
if (stat) changedFiles.push(stat);
|
|
8200
|
+
if (/^(create|delete) mode\s+|^(rename|copy) (from|to)\s+/i.test(text)) modeLines.push(text);
|
|
8201
|
+
}
|
|
8202
|
+
|
|
8203
|
+
return {
|
|
8204
|
+
command: result.command || "git pull --ff-only",
|
|
8205
|
+
outputLines,
|
|
8206
|
+
changedFiles,
|
|
8207
|
+
modeLines,
|
|
8208
|
+
updateRange,
|
|
8209
|
+
strategy,
|
|
8210
|
+
alreadyUpToDate,
|
|
8211
|
+
summaryLine: summary?.summaryLine || "",
|
|
8212
|
+
totalFiles: summary?.totalFiles || changedFiles.length || 0,
|
|
8213
|
+
insertions: summary?.insertions || 0,
|
|
8214
|
+
deletions: summary?.deletions || 0,
|
|
8215
|
+
};
|
|
8216
|
+
}
|
|
8217
|
+
|
|
8218
|
+
function gitPullResultStatus(result) {
|
|
8219
|
+
if (!result) return "";
|
|
8220
|
+
if (result.alreadyUpToDate) return "Already up to date.";
|
|
8221
|
+
const totalFiles = Number(result.totalFiles || 0) || 0;
|
|
8222
|
+
const insertions = Number(result.insertions || 0) || 0;
|
|
8223
|
+
const deletions = Number(result.deletions || 0) || 0;
|
|
8224
|
+
if (totalFiles > 0) {
|
|
8225
|
+
const parts = [`${totalFiles.toLocaleString()} file${totalFiles === 1 ? "" : "s"} changed`];
|
|
8226
|
+
if (insertions > 0) parts.push(`+${insertions.toLocaleString()}`);
|
|
8227
|
+
if (deletions > 0) parts.push(`−${deletions.toLocaleString()}`);
|
|
8228
|
+
return `Pulled remote changes: ${parts.join(" · ")}.`;
|
|
8229
|
+
}
|
|
8230
|
+
if (result.summaryLine) return `Pulled remote changes: ${result.summaryLine}.`;
|
|
8231
|
+
if (result.strategy) return `Pulled remote changes (${result.strategy}).`;
|
|
8232
|
+
return "Pulled remote changes successfully.";
|
|
8233
|
+
}
|
|
8234
|
+
|
|
8235
|
+
function renderGitPullResultPanel(result) {
|
|
8236
|
+
if (!result) return null;
|
|
8237
|
+
const panel = make("section", "git-pull-result-panel");
|
|
8238
|
+
const header = make("div", "git-pull-result-header");
|
|
8239
|
+
const copy = make("div", "git-pull-result-copy");
|
|
8240
|
+
copy.append(
|
|
8241
|
+
make("span", "git-pull-result-kicker", "Pull result"),
|
|
8242
|
+
make("strong", undefined, gitPullResultStatus(result)),
|
|
8243
|
+
make("span", "git-pull-result-meta", [result.updateRange, result.strategy, result.command].filter(Boolean).join(" · ")),
|
|
8244
|
+
);
|
|
8245
|
+
header.append(copy);
|
|
8246
|
+
panel.append(header);
|
|
8247
|
+
|
|
8248
|
+
const metrics = make("div", "git-pull-result-metrics");
|
|
8249
|
+
metrics.append(
|
|
8250
|
+
gitChangesChip("changed", result.totalFiles || result.changedFiles.length || 0, (result.totalFiles || result.changedFiles.length) ? "warning" : "muted"),
|
|
8251
|
+
gitChangesChip("insertions", result.insertions > 0 ? `+${result.insertions.toLocaleString()}` : 0, result.insertions > 0 ? "success" : "muted"),
|
|
8252
|
+
gitChangesChip("deletions", result.deletions > 0 ? `−${result.deletions.toLocaleString()}` : 0, result.deletions > 0 ? "danger" : "muted"),
|
|
8253
|
+
gitChangesChip("mode ops", result.modeLines.length || 0, result.modeLines.length ? "warning" : "muted"),
|
|
8254
|
+
);
|
|
8255
|
+
panel.append(metrics);
|
|
8256
|
+
|
|
8257
|
+
if (result.changedFiles.length) {
|
|
8258
|
+
const list = make("div", "git-pull-file-list");
|
|
8259
|
+
list.append(make("span", "git-pull-file-list-label", `${result.changedFiles.length} pulled file${result.changedFiles.length === 1 ? "" : "s"}`));
|
|
8260
|
+
for (const file of result.changedFiles.slice(0, GIT_PULL_RESULT_FILE_LIMIT)) {
|
|
8261
|
+
const row = make("div", `git-pull-file ${file.tone || ""}`.trim());
|
|
8262
|
+
row.append(make("span", "git-pull-file-path", file.path), make("span", "git-pull-file-stats", file.stats));
|
|
8263
|
+
list.append(row);
|
|
8264
|
+
}
|
|
8265
|
+
const remaining = result.changedFiles.length - GIT_PULL_RESULT_FILE_LIMIT;
|
|
8266
|
+
if (remaining > 0) list.append(make("div", "git-pull-result-more", `${remaining} more file${remaining === 1 ? "" : "s"}; expand command output for the full git stat.`));
|
|
8267
|
+
panel.append(list);
|
|
8268
|
+
}
|
|
8269
|
+
|
|
8270
|
+
if (result.modeLines.length) {
|
|
8271
|
+
const details = make("details", "git-pull-output-details git-pull-mode-details");
|
|
8272
|
+
details.append(make("summary", undefined, `Mode changes (${result.modeLines.length})`), make("pre", undefined, result.modeLines.join("\n")));
|
|
8273
|
+
panel.append(details);
|
|
8274
|
+
}
|
|
8275
|
+
|
|
8276
|
+
const details = make("details", "git-pull-output-details");
|
|
8277
|
+
details.append(make("summary", undefined, "Command output"), make("pre", undefined, result.outputLines.join("\n") || "No command output."));
|
|
8278
|
+
panel.append(details);
|
|
8279
|
+
return panel;
|
|
8280
|
+
}
|
|
8281
|
+
|
|
7366
8282
|
function renderGitChangesDialog() {
|
|
7367
8283
|
if (!elements.gitChangesDialog || !elements.gitChangesBody) return;
|
|
7368
|
-
const { loading, pulling, error, message, data } = gitChangesState;
|
|
8284
|
+
const { loading, pulling, error, message, pullResult, data } = gitChangesState;
|
|
7369
8285
|
const behind = Number(data?.remote?.behind ?? data?.summary?.behind ?? 0) || 0;
|
|
7370
8286
|
const canPull = behind > 0 && data?.remote?.canPull !== false;
|
|
7371
8287
|
const remoteNotice = !error && data?.remote?.error ? `Incoming diff unavailable: ${data.remote.error}` : "";
|
|
@@ -7405,6 +8321,7 @@ function renderGitChangesDialog() {
|
|
|
7405
8321
|
return;
|
|
7406
8322
|
}
|
|
7407
8323
|
|
|
8324
|
+
if (pullResult) body.append(renderGitPullResultPanel(pullResult));
|
|
7408
8325
|
body.append(renderGitChangesOverview(data));
|
|
7409
8326
|
const parsedSections = (Array.isArray(data.sections) ? data.sections : [])
|
|
7410
8327
|
.map((section) => ({ section, files: parseGitUnifiedDiff(section.diff || "") }))
|
|
@@ -7428,13 +8345,13 @@ function renderGitChangesDialog() {
|
|
|
7428
8345
|
async function loadGitChangesDialog(tabContext = activeTabContext()) {
|
|
7429
8346
|
const requestSerial = ++gitChangesRequestSerial;
|
|
7430
8347
|
gitChangesUntrackedContentRequests.clear();
|
|
7431
|
-
gitChangesState = { ...gitChangesState, loading: true, error: "", message: "", tabId: tabContext.tabId || activeTabId };
|
|
8348
|
+
gitChangesState = { ...gitChangesState, loading: true, error: "", message: "", pullResult: null, tabId: tabContext.tabId || activeTabId };
|
|
7432
8349
|
renderGitChangesDialog();
|
|
7433
8350
|
try {
|
|
7434
8351
|
const response = await api("/api/git-changes", { tabId: tabContext.tabId });
|
|
7435
8352
|
if (requestSerial !== gitChangesRequestSerial) return;
|
|
7436
8353
|
if (!response.ok) throw new Error(response.error || "Failed to load git changes");
|
|
7437
|
-
gitChangesState = { loading: false, pulling: false, error: "", message: "", data: response.data || null, tabId: tabContext.tabId || activeTabId };
|
|
8354
|
+
gitChangesState = { loading: false, pulling: false, error: "", message: "", pullResult: null, data: response.data || null, tabId: tabContext.tabId || activeTabId };
|
|
7438
8355
|
} catch (error) {
|
|
7439
8356
|
if (requestSerial !== gitChangesRequestSerial) return;
|
|
7440
8357
|
gitChangesState = { ...gitChangesState, loading: false, error: error.message || String(error) };
|
|
@@ -7447,7 +8364,7 @@ function openGitChangesDialog() {
|
|
|
7447
8364
|
hideFooterTooltip();
|
|
7448
8365
|
const tabContext = activeTabContext();
|
|
7449
8366
|
const tabId = tabContext.tabId || activeTabId;
|
|
7450
|
-
gitChangesState = { loading: true, pulling: false, error: "", message: "", data: gitChangesState.tabId === tabId ? gitChangesState.data : null, tabId };
|
|
8367
|
+
gitChangesState = { loading: true, pulling: false, error: "", message: "", pullResult: null, data: gitChangesState.tabId === tabId ? gitChangesState.data : null, tabId };
|
|
7451
8368
|
renderGitChangesDialog();
|
|
7452
8369
|
if (!elements.gitChangesDialog.open) elements.gitChangesDialog.showModal();
|
|
7453
8370
|
loadGitChangesDialog(tabContext).catch((error) => addEvent(error.message || String(error), "error"));
|
|
@@ -7466,7 +8383,7 @@ async function pullGitChangesDialog() {
|
|
|
7466
8383
|
if (!window.confirm(`Run git pull --ff-only in ${root}?`)) return;
|
|
7467
8384
|
|
|
7468
8385
|
const requestSerial = ++gitChangesRequestSerial;
|
|
7469
|
-
gitChangesState = { ...gitChangesState, pulling: true, loading: false, error: "", message: "", tabId: tabContext.tabId };
|
|
8386
|
+
gitChangesState = { ...gitChangesState, pulling: true, loading: false, error: "", message: "", pullResult: null, tabId: tabContext.tabId };
|
|
7470
8387
|
renderGitChangesDialog();
|
|
7471
8388
|
try {
|
|
7472
8389
|
const response = await api("/api/git-changes/pull", { method: "POST", body: {}, tabId: tabContext.tabId });
|
|
@@ -7475,12 +8392,13 @@ async function pullGitChangesDialog() {
|
|
|
7475
8392
|
const detail = [response.error, response.data?.stderr || response.data?.stdout].filter(Boolean).join("\n").trim();
|
|
7476
8393
|
throw new Error(detail || "Failed to pull git changes");
|
|
7477
8394
|
}
|
|
7478
|
-
const
|
|
8395
|
+
const pullResult = normalizeGitPullResult(response.data || {});
|
|
7479
8396
|
gitChangesState = {
|
|
7480
8397
|
loading: false,
|
|
7481
8398
|
pulling: false,
|
|
7482
8399
|
error: "",
|
|
7483
|
-
message:
|
|
8400
|
+
message: gitPullResultStatus(pullResult),
|
|
8401
|
+
pullResult,
|
|
7484
8402
|
data: response.data?.changes || gitChangesState.data,
|
|
7485
8403
|
tabId: tabContext.tabId,
|
|
7486
8404
|
};
|
|
@@ -11384,14 +12302,16 @@ function base64UrlEncodeUtf8(value) {
|
|
|
11384
12302
|
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
|
|
11385
12303
|
}
|
|
11386
12304
|
|
|
11387
|
-
function btwTransferPayload(payload) {
|
|
12305
|
+
function btwTransferPayload(payload, { transferMode = "full" } = {}) {
|
|
11388
12306
|
return {
|
|
11389
12307
|
question: payload?.question || "",
|
|
11390
12308
|
answer: payload?.answer || payload?.error || "",
|
|
12309
|
+
summary: payload?.summary || "",
|
|
11391
12310
|
status: payload?.status || "done",
|
|
11392
12311
|
model: payload?.model || "",
|
|
11393
12312
|
generatedAt: payload?.generatedAt || 0,
|
|
11394
12313
|
updatedAt: payload?.updatedAt || Date.now(),
|
|
12314
|
+
transferMode: transferMode === "summary" ? "summary" : "full",
|
|
11395
12315
|
};
|
|
11396
12316
|
}
|
|
11397
12317
|
|
|
@@ -11426,23 +12346,40 @@ function makeBtwTransferIcon() {
|
|
|
11426
12346
|
return svg;
|
|
11427
12347
|
}
|
|
11428
12348
|
|
|
11429
|
-
async function transferBtwContextToMain(button) {
|
|
12349
|
+
async function transferBtwContextToMain(button, { transferMode = "full" } = {}) {
|
|
11430
12350
|
const payload = currentBtwWidgetPayload();
|
|
11431
|
-
const
|
|
12351
|
+
const normalizedMode = transferMode === "summary" ? "summary" : "full";
|
|
12352
|
+
const transferPayload = btwTransferPayload(payload, { transferMode: normalizedMode });
|
|
11432
12353
|
if (!transferPayload.question && !transferPayload.answer) return;
|
|
11433
12354
|
const targetTabId = activeTabId;
|
|
11434
12355
|
const liveSteer = !!currentState?.isStreaming;
|
|
11435
|
-
const
|
|
12356
|
+
const label = button?.querySelector(".btw-action-label") || button?.querySelector("span");
|
|
12357
|
+
const original = label?.textContent || button?.textContent || (normalizedMode === "summary" ? "Summarize & Steer" : "Transfer Context");
|
|
11436
12358
|
const encoded = base64UrlEncodeUtf8(JSON.stringify(transferPayload));
|
|
12359
|
+
if (label) label.textContent = normalizedMode === "summary" ? "Summarizing…" : "Steering…";
|
|
12360
|
+
else if (button) button.textContent = normalizedMode === "summary" ? "Summarizing…" : "Steering…";
|
|
12361
|
+
if (button) button.disabled = true;
|
|
11437
12362
|
try {
|
|
11438
|
-
await sendPrompt("prompt", `/btw-transfer ${encoded}`, { targetTabId, throwOnError: true, streamingBehavior:
|
|
11439
|
-
const
|
|
11440
|
-
if (label) label.textContent =
|
|
11441
|
-
|
|
11442
|
-
|
|
11443
|
-
|
|
11444
|
-
|
|
12363
|
+
await sendPrompt("prompt", `/btw-transfer ${encoded}`, { targetTabId, throwOnError: true, streamingBehavior: "steer" });
|
|
12364
|
+
const doneLabel = normalizedMode === "summary" ? "Summary Sent" : (liveSteer ? "Steered" : "Transferred");
|
|
12365
|
+
if (label) label.textContent = doneLabel;
|
|
12366
|
+
else if (button) button.textContent = doneLabel;
|
|
12367
|
+
addEvent(normalizedMode === "summary"
|
|
12368
|
+
? (liveSteer
|
|
12369
|
+
? "/btw summary sent as live steering; it will be injected after the next agent action"
|
|
12370
|
+
: "/btw summary transferred as steering context")
|
|
12371
|
+
: (liveSteer
|
|
12372
|
+
? "/btw context sent as live steering; it will be injected after the next agent action"
|
|
12373
|
+
: "/btw context transferred as steering context"), "info");
|
|
12374
|
+
setTimeout(() => {
|
|
12375
|
+
if (label) label.textContent = original;
|
|
12376
|
+
else if (button) button.textContent = original;
|
|
12377
|
+
if (button) button.disabled = false;
|
|
12378
|
+
}, 1800);
|
|
11445
12379
|
} catch {
|
|
12380
|
+
if (label) label.textContent = original;
|
|
12381
|
+
else if (button) button.textContent = original;
|
|
12382
|
+
if (button) button.disabled = false;
|
|
11446
12383
|
// sendPrompt already reports the error.
|
|
11447
12384
|
}
|
|
11448
12385
|
}
|
|
@@ -11509,14 +12446,22 @@ function renderBtwOutputWidget() {
|
|
|
11509
12446
|
if (payload?.model) meta.append(make("span", "release-npm-pill", payload.model));
|
|
11510
12447
|
|
|
11511
12448
|
const actions = make("div", "release-npm-actions");
|
|
12449
|
+
const hasTransferContent = !!payload && !!(payload.answer || payload.error || payload.question);
|
|
11512
12450
|
const transferButton = btwWidgetActionButton("", transferBtwContextToMain, "btw-transfer-action");
|
|
11513
12451
|
transferButton.title = currentState?.isStreaming
|
|
11514
12452
|
? "Transfer this /btw question and answer as live steering after the next agent action"
|
|
11515
|
-
: "Transfer this /btw question and answer
|
|
11516
|
-
transferButton.append(makeBtwTransferIcon(), make("span",
|
|
11517
|
-
transferButton.disabled = !
|
|
12453
|
+
: "Transfer this /btw question and answer as steering context in the main conversation";
|
|
12454
|
+
transferButton.append(makeBtwTransferIcon(), make("span", "btw-action-label", "Transfer Context"));
|
|
12455
|
+
transferButton.disabled = !hasTransferContent;
|
|
12456
|
+
const summaryTransferButton = btwWidgetActionButton("", (button) => transferBtwContextToMain(button, { transferMode: "summary" }), "btw-transfer-action btw-transfer-summary-action");
|
|
12457
|
+
summaryTransferButton.title = currentState?.isStreaming
|
|
12458
|
+
? "Summarize this /btw side thread, then send the summary as live steering after the next agent action"
|
|
12459
|
+
: "Summarize this /btw side thread, then transfer the summary as steering context";
|
|
12460
|
+
summaryTransferButton.append(makeBtwTransferIcon(), make("span", "btw-action-label", "Summarize & Steer"));
|
|
12461
|
+
summaryTransferButton.disabled = !hasTransferContent;
|
|
11518
12462
|
actions.append(
|
|
11519
12463
|
transferButton,
|
|
12464
|
+
summaryTransferButton,
|
|
11520
12465
|
btwWidgetActionButton("Copy", copyBtwWidgetAnswer),
|
|
11521
12466
|
btwWidgetActionButton("Close", closeBtwOutputWidget),
|
|
11522
12467
|
);
|
|
@@ -11533,7 +12478,7 @@ function renderBtwOutputWidget() {
|
|
|
11533
12478
|
|
|
11534
12479
|
const note = payload?.status === "error"
|
|
11535
12480
|
? "The side request failed. The main conversation was not changed."
|
|
11536
|
-
: "Ephemeral answer ·
|
|
12481
|
+
: "Ephemeral answer · use Transfer Context for the full side thread or Summarize & Steer for a concise steering summary.";
|
|
11537
12482
|
const controls = make("div", "release-npm-controls btw-controls", note);
|
|
11538
12483
|
const outputDetails = renderReleaseNpmOutputDetails(`btw:${payload?.id || "composer"}`, streamHeader, terminal, controls);
|
|
11539
12484
|
node.append(header, question, outputDetails, renderBtwComposerForm());
|
|
@@ -11693,11 +12638,35 @@ function isLocalWebuiBrowserOrigin() {
|
|
|
11693
12638
|
return host === "localhost" || host === "127.0.0.1" || host === "::1" || host === "[::1]";
|
|
11694
12639
|
}
|
|
11695
12640
|
|
|
12641
|
+
function remoteWebuiUniqueUrls(values = []) {
|
|
12642
|
+
const urls = [];
|
|
12643
|
+
const seen = new Set();
|
|
12644
|
+
const addUrl = (value) => {
|
|
12645
|
+
if (Array.isArray(value)) {
|
|
12646
|
+
for (const item of value) addUrl(item);
|
|
12647
|
+
return;
|
|
12648
|
+
}
|
|
12649
|
+
const href = remoteWebuiLineUrl(value);
|
|
12650
|
+
if (!href || seen.has(href)) return;
|
|
12651
|
+
seen.add(href);
|
|
12652
|
+
urls.push(href);
|
|
12653
|
+
};
|
|
12654
|
+
addUrl(values);
|
|
12655
|
+
return urls;
|
|
12656
|
+
}
|
|
12657
|
+
|
|
12658
|
+
function remoteWebuiQrUrlsFromData(data = {}) {
|
|
12659
|
+
const network = data.network || latestNetwork || {};
|
|
12660
|
+
const networkUrls = Array.isArray(network.networkUrls) ? network.networkUrls : [];
|
|
12661
|
+
const urls = remoteWebuiUniqueUrls([data.url, networkUrls]);
|
|
12662
|
+
return urls.length ? urls : remoteWebuiUniqueUrls([network.localUrl]);
|
|
12663
|
+
}
|
|
12664
|
+
|
|
11696
12665
|
function remoteWebuiQrLinesFromData(data = {}) {
|
|
11697
12666
|
const network = data.network || latestNetwork || {};
|
|
11698
12667
|
const auth = network.auth || {};
|
|
11699
|
-
const
|
|
11700
|
-
const displayUrl =
|
|
12668
|
+
const urls = remoteWebuiQrUrlsFromData(data);
|
|
12669
|
+
const displayUrl = urls[0] || "";
|
|
11701
12670
|
const qrLines = Array.isArray(data.qrLines) ? data.qrLines.map((line) => String(line ?? "")) : [];
|
|
11702
12671
|
const hasAutoAuthQr = !!(auth.enabled && auth.pin && data.qrUrl && displayUrl && data.qrUrl !== displayUrl);
|
|
11703
12672
|
const authLine = auth.enabled ? `Remote PIN auth: on${auth.pin ? ` · PIN ${auth.pin}` : ""}` : "Remote PIN auth: off";
|
|
@@ -11714,6 +12683,7 @@ function remoteWebuiQrLinesFromData(data = {}) {
|
|
|
11714
12683
|
...qrLines,
|
|
11715
12684
|
"",
|
|
11716
12685
|
displayUrl,
|
|
12686
|
+
...urls.slice(1),
|
|
11717
12687
|
authLine,
|
|
11718
12688
|
"",
|
|
11719
12689
|
warningLine,
|
|
@@ -11806,11 +12776,12 @@ function openRemoteWebuiQrPopup(lines = []) {
|
|
|
11806
12776
|
}
|
|
11807
12777
|
|
|
11808
12778
|
const details = make("div", "remote-qr-details");
|
|
11809
|
-
|
|
12779
|
+
const urls = remoteWebuiUniqueUrls([url, cleanLines]);
|
|
12780
|
+
for (const [index, href] of urls.entries()) {
|
|
11810
12781
|
const urlRow = make("div", "remote-qr-url-row");
|
|
11811
|
-
const urlLabel = make("span", "remote-qr-url-label", "URL");
|
|
11812
|
-
const link = make("a", "remote-qr-url",
|
|
11813
|
-
link.href =
|
|
12782
|
+
const urlLabel = make("span", "remote-qr-url-label", index === 0 ? "URL" : "LAN");
|
|
12783
|
+
const link = make("a", "remote-qr-url", href);
|
|
12784
|
+
link.href = href;
|
|
11814
12785
|
link.target = "_blank";
|
|
11815
12786
|
link.rel = "noopener noreferrer";
|
|
11816
12787
|
urlRow.append(urlLabel, link);
|
|
@@ -16958,6 +17929,7 @@ function updateOptionalFeatureAvailability() {
|
|
|
16958
17929
|
optionalFeatureAvailability.todoProgressWidget = hasAvailableCommand("todo-progress-status") || optionalFeatureAvailability.todoProgressWidget || widgets.has("todo-progress");
|
|
16959
17930
|
optionalFeatureAvailability.tuiToolsCommand = hasLoadedRpcCommand("tools");
|
|
16960
17931
|
optionalFeatureAvailability.remoteWebui = hasAvailableCommand("remote") || optionalFeatureAvailability.remoteWebui || statusEntries.has("pi-remote-webui") || statusEntries.has(REMOTE_WEBUI_CONTROLS_STATUS_KEY) || widgets.has("pi-remote-webui");
|
|
17932
|
+
optionalFeatureAvailability.naturalConversation = NATURAL_CONVERSATION_COMMAND_NAMES.some((name) => hasAvailableCommand(name)) || optionalFeatureAvailability.naturalConversation || statusEntries.has(NATURAL_CONVERSATION_STATUS_KEY) || activeConversationMode().available;
|
|
16961
17933
|
optionalFeatureAvailability.themeBundle = availableThemes.length > 0;
|
|
16962
17934
|
requestGitFooterWebuiPayload();
|
|
16963
17935
|
renderOptionalFeatureControls();
|
|
@@ -17110,6 +18082,12 @@ function renderOptionalFeatureControls() {
|
|
|
17110
18082
|
);
|
|
17111
18083
|
}
|
|
17112
18084
|
|
|
18085
|
+
const hasNaturalConversation = isOptionalFeatureEnabled("naturalConversation") || activeConversationMode().enabled;
|
|
18086
|
+
if (elements.optionsConversationModeButton) {
|
|
18087
|
+
elements.optionsConversationModeButton.hidden = !hasNaturalConversation;
|
|
18088
|
+
}
|
|
18089
|
+
renderConversationModeControls();
|
|
18090
|
+
|
|
17113
18091
|
const hasRemoteWebuiCommand = isOptionalFeatureEnabled("remoteWebui") && hasAvailableCommand("remote");
|
|
17114
18092
|
if (elements.optionsRemoteButton) {
|
|
17115
18093
|
elements.optionsRemoteButton.hidden = !hasRemoteWebuiCommand;
|
|
@@ -18776,6 +19754,11 @@ function renderNetworkStatus() {
|
|
|
18776
19754
|
: "Off";
|
|
18777
19755
|
elements.openNetworkButton.disabled = rebinding;
|
|
18778
19756
|
elements.openNetworkButton.textContent = opening ? "Opening…" : closing ? "Closing…" : open ? "Close for network" : "Open to network";
|
|
19757
|
+
if (elements.showRemoteQrButton) {
|
|
19758
|
+
elements.showRemoteQrButton.hidden = !open;
|
|
19759
|
+
elements.showRemoteQrButton.disabled = rebinding || !open;
|
|
19760
|
+
elements.showRemoteQrButton.textContent = "Show QR code";
|
|
19761
|
+
}
|
|
18779
19762
|
}
|
|
18780
19763
|
|
|
18781
19764
|
async function refreshNetworkStatus() {
|
|
@@ -19708,6 +20691,7 @@ async function refreshAll(tabContext = activeTabContext()) {
|
|
|
19708
20691
|
refreshMessages(tabContext),
|
|
19709
20692
|
refreshModels(tabContext),
|
|
19710
20693
|
refreshCommands(tabContext),
|
|
20694
|
+
refreshNaturalConversationMode(tabContext),
|
|
19711
20695
|
refreshStats(tabContext),
|
|
19712
20696
|
refreshWorkspace(tabContext),
|
|
19713
20697
|
refreshAppRunners(tabContext),
|
|
@@ -20098,6 +21082,7 @@ async function sendPrompt(kind = "prompt", explicitMessage, { targetTabId = acti
|
|
|
20098
21082
|
const rawMessage = usesPromptInput ? elements.promptInput.value : explicitMessage;
|
|
20099
21083
|
const originalMessage = String(rawMessage || "").trim();
|
|
20100
21084
|
if (!targetTabId) return;
|
|
21085
|
+
if (voiceConversationActiveFor(targetTabId)) voiceConversation.handleUserActivity();
|
|
20101
21086
|
const tabContext = activeTabContext(targetTabId);
|
|
20102
21087
|
const attachments = usesPromptInput ? [...attachmentsForTab(targetTabId)] : [];
|
|
20103
21088
|
if (!originalMessage && attachments.length === 0) return;
|
|
@@ -20109,8 +21094,10 @@ async function sendPrompt(kind = "prompt", explicitMessage, { targetTabId = acti
|
|
|
20109
21094
|
}
|
|
20110
21095
|
|
|
20111
21096
|
const targetWasStreaming = !!currentState?.isStreaming;
|
|
21097
|
+
const targetWasCompacting = !!currentState?.isCompacting;
|
|
21098
|
+
const targetWasBusy = targetWasStreaming || targetWasCompacting;
|
|
20112
21099
|
const busyBehavior = normalizeBusyPromptBehavior(busyPromptBehavior);
|
|
20113
|
-
const startsRun = kind === "prompt" && !
|
|
21100
|
+
const startsRun = kind === "prompt" && !targetWasBusy;
|
|
20114
21101
|
autoFollowChat = true;
|
|
20115
21102
|
updateJumpToLatestButton();
|
|
20116
21103
|
setComposerActionsOpen(false);
|
|
@@ -20139,7 +21126,7 @@ async function sendPrompt(kind = "prompt", explicitMessage, { targetTabId = acti
|
|
|
20139
21126
|
response = await api("/api/follow-up", { method: "POST", body: bodyBase, tabId: targetTabId });
|
|
20140
21127
|
} else {
|
|
20141
21128
|
const body = { ...bodyBase };
|
|
20142
|
-
if (
|
|
21129
|
+
if (targetWasBusy) body.streamingBehavior = streamingBehavior || busyBehavior;
|
|
20143
21130
|
response = await api("/api/prompt", { method: "POST", body, tabId: targetTabId });
|
|
20144
21131
|
}
|
|
20145
21132
|
applyResponseTab(response);
|
|
@@ -20148,6 +21135,9 @@ async function sendPrompt(kind = "prompt", explicitMessage, { targetTabId = acti
|
|
|
20148
21135
|
if (startsRun && response?.command === "native_slash_command") {
|
|
20149
21136
|
markTabIdleLocally(targetTabId);
|
|
20150
21137
|
if (targetStillActive) clearRunIndicatorActivity();
|
|
21138
|
+
} else if (targetStillActive && response?.data?.queuedFor === "compaction") {
|
|
21139
|
+
setRunIndicatorActivity("Prompt queued; Pi will resume automatically after compaction…");
|
|
21140
|
+
addEvent("prompt queued until compaction finishes");
|
|
20151
21141
|
} else if (targetStillActive && kind === "steer" && currentState?.isStreaming) {
|
|
20152
21142
|
setRunIndicatorActivity("Steering sent; waiting for the next output or action…");
|
|
20153
21143
|
} else if (targetStillActive && kind === "follow-up" && currentState?.isStreaming) {
|
|
@@ -20225,6 +21215,7 @@ function handleExtensionUiRequest(request) {
|
|
|
20225
21215
|
}
|
|
20226
21216
|
if (statusKey === STATS_WEBUI_STATUS_KEY) handleStatsWebuiStatus(request.statusText);
|
|
20227
21217
|
if (statusKey === BTW_WEBUI_STATUS_KEY) handleBtwWebuiStatus(request.statusText);
|
|
21218
|
+
if (statusKey === NATURAL_CONVERSATION_STATUS_KEY) handleNaturalConversationStatus(request.statusText, request.tabId || activeTabId);
|
|
20228
21219
|
if (statusKey === "pi-remote-webui") handleRemoteWebuiStatus(request.statusText);
|
|
20229
21220
|
updateOptionalFeatureAvailability();
|
|
20230
21221
|
if (statusKey === GIT_FOOTER_WEBUI_STATUS_KEY) {
|
|
@@ -20507,8 +21498,26 @@ function handleEvent(event) {
|
|
|
20507
21498
|
renderQueue(event);
|
|
20508
21499
|
scheduleRefreshState();
|
|
20509
21500
|
break;
|
|
21501
|
+
case "webui_compaction_queue_update":
|
|
21502
|
+
renderQueue(event);
|
|
21503
|
+
if (currentState) currentState = { ...currentState, pendingMessageCount: Number(event.pendingMessageCount ?? event.queueLength ?? currentState.pendingMessageCount ?? 0) };
|
|
21504
|
+
if (event.error) {
|
|
21505
|
+
addEvent(`queued compaction prompt resume failed: ${event.error}`, "error");
|
|
21506
|
+
} else if (event.drained) {
|
|
21507
|
+
addEvent("queued compaction prompt sent; Pi is resuming");
|
|
21508
|
+
} else if (event.draining) {
|
|
21509
|
+
setRunIndicatorActivity("Sending queued prompt after compaction…");
|
|
21510
|
+
addEvent("sending queued compaction prompt after compaction");
|
|
21511
|
+
} else if (event.queuedId) {
|
|
21512
|
+
setRunIndicatorActivity("Prompt queued; Pi will resume automatically after compaction…");
|
|
21513
|
+
addEvent("prompt queued until compaction finishes");
|
|
21514
|
+
}
|
|
21515
|
+
renderStatus();
|
|
21516
|
+
scheduleRefreshState();
|
|
21517
|
+
break;
|
|
20510
21518
|
case "agent_start":
|
|
20511
21519
|
if (currentState) currentState = { ...currentState, isStreaming: true };
|
|
21520
|
+
if (voiceConversationActiveFor(event.tabId || activeTabId)) voiceConversation.setAssistantActivity({ streaming: true });
|
|
20512
21521
|
setRunIndicatorActivity("Agent run started; waiting for first output or action…");
|
|
20513
21522
|
addEvent("agent started");
|
|
20514
21523
|
scheduleRefreshState();
|
|
@@ -20521,6 +21530,10 @@ function handleEvent(event) {
|
|
|
20521
21530
|
notifyAgentDone(event.tabId || activeTabId, { activity: event.tabActivity, tabTitle: event.tabTitle });
|
|
20522
21531
|
clearContextUsageUnknownAfterCompaction(event.tabId || activeTabId);
|
|
20523
21532
|
if (currentState) currentState = { ...currentState, isStreaming: false };
|
|
21533
|
+
// handleAssistantTurnEnd resets the controller's streaming/tool flags and
|
|
21534
|
+
// flushes queued interruptions itself; calling setAssistantActivity here
|
|
21535
|
+
// first would flush the queue and then speak the interrupted answer.
|
|
21536
|
+
if (voiceConversationActiveFor(event.tabId || activeTabId)) void handleVoiceConversationTurnEnd(tabContext);
|
|
20524
21537
|
clearRunIndicatorActivity();
|
|
20525
21538
|
markTabOutputSeen();
|
|
20526
21539
|
requestGitFooterWebuiPayload(tabContext, { force: true });
|
|
@@ -20560,6 +21573,7 @@ function handleEvent(event) {
|
|
|
20560
21573
|
break;
|
|
20561
21574
|
case "tool_execution_start":
|
|
20562
21575
|
streamToolCallSeen = true;
|
|
21576
|
+
if (voiceConversationActiveFor(event.tabId || activeTabId)) voiceConversation.setAssistantActivity({ toolRunning: true });
|
|
20563
21577
|
suppressStreamingAssistantTextBeforeToolCall();
|
|
20564
21578
|
removeStreamingToolCallCard();
|
|
20565
21579
|
handleToolExecutionStart(event);
|
|
@@ -20571,6 +21585,7 @@ function handleEvent(event) {
|
|
|
20571
21585
|
setRunIndicatorActivity(`Running tool: ${runIndicatorToolName(event.toolName)}…`, { scroll: false });
|
|
20572
21586
|
break;
|
|
20573
21587
|
case "tool_execution_end":
|
|
21588
|
+
if (voiceConversationActiveFor(event.tabId || activeTabId)) voiceConversation.setAssistantActivity({ toolRunning: false });
|
|
20574
21589
|
handleToolExecutionEnd(event);
|
|
20575
21590
|
setRunIndicatorActivity(`Tool ${runIndicatorToolName(event.toolName)} ${event.isError ? "failed" : "finished"}; waiting for the agent's next step…`);
|
|
20576
21591
|
addEvent(`tool ${event.toolName} ${event.isError ? "failed" : "finished"}`, event.isError ? "error" : "info");
|
|
@@ -20963,6 +21978,28 @@ elements.releaseAurButton.addEventListener("click", () => runPublishWorkflow("/r
|
|
|
20963
21978
|
elements.nativeSkillsButton.addEventListener("click", () => runNativeCommandMenu("/skills"));
|
|
20964
21979
|
elements.nativeToolsButton.addEventListener("click", () => runNativeCommandMenu("/tools"));
|
|
20965
21980
|
elements.optionsCommandPaletteButton.addEventListener("click", () => openCommandPalette());
|
|
21981
|
+
elements.optionsConversationModeButton?.addEventListener("click", () => toggleNaturalConversationMode());
|
|
21982
|
+
elements.conversationModeChip?.addEventListener("click", () => toggleVoiceConversationPaused());
|
|
21983
|
+
elements.conversationModeEndButton?.addEventListener("click", () => setNaturalConversationModeEnabled(false));
|
|
21984
|
+
// The voice menu opens on click (and on hover/focus via CSS on desktop);
|
|
21985
|
+
// refresh the voice list whenever it is opened so download states stay fresh.
|
|
21986
|
+
elements.conversationVoiceButton?.addEventListener("click", () => {
|
|
21987
|
+
setConversationVoiceMenuOpen(!conversationVoiceMenuOpen);
|
|
21988
|
+
if (conversationVoiceMenuOpen && !conversationVoiceSwitching) void loadConversationVoices();
|
|
21989
|
+
});
|
|
21990
|
+
elements.conversationVoiceMenu?.addEventListener("pointerenter", () => {
|
|
21991
|
+
if (!conversationVoiceSwitching) void loadConversationVoices();
|
|
21992
|
+
});
|
|
21993
|
+
elements.conversationVoiceMenu?.addEventListener("pointerleave", () => setConversationVoiceMenuOpen(false));
|
|
21994
|
+
elements.conversationVoiceMenu?.addEventListener("focusin", () => {
|
|
21995
|
+
if (!conversationVoiceSwitching) void loadConversationVoices();
|
|
21996
|
+
});
|
|
21997
|
+
elements.remoteMicStreamingConsentButton?.addEventListener("click", () => {
|
|
21998
|
+
if (!activeTabId) return;
|
|
21999
|
+
remoteMicConsentTabs.add(activeTabId);
|
|
22000
|
+
addEvent("Remote microphone streaming allowed for this tab. Consent ends with the conversation or the tab.", "info");
|
|
22001
|
+
renderConversationModeControls();
|
|
22002
|
+
});
|
|
20966
22003
|
elements.optionsResumeButton.addEventListener("click", () => runNativeCommandMenu("/resume"));
|
|
20967
22004
|
elements.optionsReloadButton.addEventListener("click", () => runNativeCommandMenu("/reload"));
|
|
20968
22005
|
elements.optionsRemoteButton.addEventListener("click", () => runNativeCommandMenu("/remote"));
|
|
@@ -21380,6 +22417,7 @@ if (elements.backgroundClearButton) {
|
|
|
21380
22417
|
}
|
|
21381
22418
|
elements.remoteAuthToggle.addEventListener("change", () => toggleRemoteAuth().catch((error) => addEvent(error.message || String(error), "error")));
|
|
21382
22419
|
elements.openNetworkButton.addEventListener("click", openToNetwork);
|
|
22420
|
+
elements.showRemoteQrButton?.addEventListener("click", () => showRemoteWebuiQrPopupFromNetwork().catch((error) => addEvent(error.message || String(error), "error")));
|
|
21383
22421
|
elements.remoteQrCopyButton?.addEventListener("click", () => copyRemoteWebuiQrUrl().catch((error) => addEvent(error.message || String(error), "error")));
|
|
21384
22422
|
elements.remoteQrOpenButton?.addEventListener("click", openRemoteWebuiQrUrl);
|
|
21385
22423
|
elements.remoteQrCloseButton?.addEventListener("click", closeRemoteWebuiQrPopup);
|
|
@@ -21460,6 +22498,9 @@ document.addEventListener("pointerdown", (event) => {
|
|
|
21460
22498
|
if (optionsMenuOpen && !event.target?.closest?.(".composer-options-menu")) {
|
|
21461
22499
|
setOptionsMenuOpen(false);
|
|
21462
22500
|
}
|
|
22501
|
+
if (conversationVoiceMenuOpen && !event.target?.closest?.(".composer-conversation-voice-menu")) {
|
|
22502
|
+
setConversationVoiceMenuOpen(false);
|
|
22503
|
+
}
|
|
21463
22504
|
if (busyPromptBehaviorMenuOpen && !event.target?.closest?.(".composer-context-tags, .composer-busy-mode-menu")) {
|
|
21464
22505
|
setBusyPromptBehaviorMenuOpen(false);
|
|
21465
22506
|
}
|
|
@@ -21686,6 +22727,10 @@ window.addEventListener("keydown", (event) => {
|
|
|
21686
22727
|
setOptionsMenuOpen(false);
|
|
21687
22728
|
return;
|
|
21688
22729
|
}
|
|
22730
|
+
if (conversationVoiceMenuOpen) {
|
|
22731
|
+
setConversationVoiceMenuOpen(false);
|
|
22732
|
+
return;
|
|
22733
|
+
}
|
|
21689
22734
|
if (busyPromptBehaviorMenuOpen) {
|
|
21690
22735
|
setBusyPromptBehaviorMenuOpen(false);
|
|
21691
22736
|
elements.busyPromptBehaviorTag?.focus({ preventScroll: true });
|