mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-19 06:45:15 +00:00
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a012702b79 | ||
|
|
093866a3f0 | ||
|
|
5b99f85213 | ||
|
|
5e964a3847 |
@@ -163,16 +163,8 @@ override a scroll away because they can arrive after the action that requested t
|
||||
|
||||
### Draw distance
|
||||
|
||||
The native timeline starts with one window-height of draw distance, up to 2000 px. This keeps
|
||||
nearby rows ready for a fling during placement. Once the chat is placed, history is visible, and
|
||||
the sidebar has settled, the timeline schedules expansion to 2000 px through two frame callbacks.
|
||||
The callbacks leave time for the reveal to paint. Verify the actual reveal on the device.
|
||||
A drag cancels a pending expansion and uses the existing buffer as the window moves. Expansion
|
||||
resumes when the gesture settles, including momentum. In an Android emulator capture, expanding
|
||||
the full buffer during the first fling changed the measured content height and returned the chat
|
||||
to the end mid-fling.
|
||||
A fling over rows that were never measured blanks the viewport
|
||||
until LegendList renders and measures them. Twelve flings over a chat with a
|
||||
`drawDistance` is 2000 px on each side of the viewport. A fling over rows that were never measured
|
||||
blanks the viewport until LegendList renders and measures them. Twelve flings over a chat with a
|
||||
15,000 px turn expanded, Android emulator, dev build:
|
||||
|
||||
| List | Blank viewport | Janky frames | p50 / p90 / p99 |
|
||||
@@ -187,8 +179,9 @@ With every turn collapsed, flinging from a cold open into history did not blank
|
||||
|
||||
### LegendList patch
|
||||
|
||||
`patches/@legendapp+list+3.7.1.patch` lists its changes by purpose.
|
||||
[legend-list #593](https://github.com/LegendApp/legend-list/issues/593) reports the first twelve.
|
||||
`patches/@legendapp+list+3.7.1.patch` carries twelve changes for the timeline. Its header lists
|
||||
them by purpose, and
|
||||
[legend-list #593](https://github.com/LegendApp/legend-list/issues/593) reports each upstream.
|
||||
Drop a hunk when the installed LegendList ships its fix.
|
||||
|
||||
### Scroll view corrections
|
||||
|
||||
@@ -2,11 +2,9 @@ import type { Locator } from "@playwright/test";
|
||||
import { expect, test, type Page } from "../support/fixtures";
|
||||
import { expectAgentIdle, expectAgentReadyToInterrupt } from "../support/helpers/agent-stream";
|
||||
import {
|
||||
blurComposerInput,
|
||||
cancelAgent,
|
||||
fillComposerDraft,
|
||||
expectComposerDraft,
|
||||
expectComposerNotFocused,
|
||||
expectComposerVisible,
|
||||
submitMessage,
|
||||
} from "../support/helpers/composer";
|
||||
@@ -73,7 +71,6 @@ test.describe("Agent message rewind", () => {
|
||||
minDistanceFromBottom: 300,
|
||||
});
|
||||
await fillComposerDraft(page, preservedDraft);
|
||||
await blurComposerInput(page);
|
||||
rewindCompletion.clearTimelineStreamCount();
|
||||
|
||||
const rewind = rewindConversation(page, userMessage, rewoundPrompt);
|
||||
@@ -87,7 +84,6 @@ test.describe("Agent message rewind", () => {
|
||||
0,
|
||||
);
|
||||
await expectComposerDraft(page, preservedDraft);
|
||||
await expectComposerNotFocused(page);
|
||||
await expectNearBottom(page);
|
||||
} finally {
|
||||
await agent.cleanup();
|
||||
|
||||
@@ -26,7 +26,7 @@ test.use({
|
||||
},
|
||||
});
|
||||
|
||||
// The Speed icon highlights any explicit tier other than Normal.
|
||||
// Rendered light-theme colors: palette yellow 400 for Fast and Ultrafast, muted foreground for Normal.
|
||||
const ACTIVE_SPEED_COLOR = "rgb(251, 191, 36)";
|
||||
const NORMAL_SPEED_COLOR = "rgb(113, 113, 122)";
|
||||
|
||||
@@ -63,7 +63,7 @@ async function expectSpeedIconColor(page: Page, color: string): Promise<void> {
|
||||
}
|
||||
|
||||
async function expectSpeedChoices(page: Page, choices: string[]): Promise<void> {
|
||||
for (const choice of ["Normal", "Flex", "Fast", "Ultrafast"]) {
|
||||
for (const choice of ["Normal", "Fast", "Ultrafast"]) {
|
||||
const option = page.getByText(choice, { exact: true }).last();
|
||||
if (choices.includes(choice)) {
|
||||
await expect(option).toBeVisible();
|
||||
@@ -115,24 +115,21 @@ for (const viewport of [
|
||||
await expectSpeedIconColor(page, ACTIVE_SPEED_COLOR);
|
||||
await page.screenshot({ path: testInfo.outputPath(`${viewport.name}-fast-selected.png`) });
|
||||
await openSpeedSelector(page);
|
||||
await expectSpeedChoices(page, ["Normal", "Flex", "Fast", "Ultrafast"]);
|
||||
await expectSpeedChoices(page, ["Normal", "Fast", "Ultrafast"]);
|
||||
await page.screenshot({ path: testInfo.outputPath(`${viewport.name}-speed-options.png`) });
|
||||
await selectSpeed(page, "Ultrafast");
|
||||
await expectSpeedIconColor(page, ACTIVE_SPEED_COLOR);
|
||||
await openSpeedSelector(page);
|
||||
await expectSpeedChoices(page, ["Normal", "Flex", "Fast", "Ultrafast"]);
|
||||
await expectSpeedChoices(page, ["Normal", "Fast", "Ultrafast"]);
|
||||
await page.screenshot({
|
||||
path: testInfo.outputPath(`${viewport.name}-ultrafast-selected.png`),
|
||||
});
|
||||
await selectSpeed(page, "Flex");
|
||||
await expectSpeedIconColor(page, ACTIVE_SPEED_COLOR);
|
||||
await openSpeedSelector(page);
|
||||
await selectSpeed(page, "Normal");
|
||||
await expectSpeedIconColor(page, NORMAL_SPEED_COLOR);
|
||||
if (viewport.name === "desktop") {
|
||||
await switchAgentModel(agent.id, "gpt-6-sol");
|
||||
await openSpeedSelector(page);
|
||||
await expectSpeedChoices(page, ["Normal", "Flex", "Fast"]);
|
||||
await expectSpeedChoices(page, ["Normal", "Fast"]);
|
||||
await page.screenshot({ path: testInfo.outputPath("desktop-fast-only.png") });
|
||||
}
|
||||
} finally {
|
||||
|
||||
@@ -1,17 +1,6 @@
|
||||
import { expect, test } from "../support/fixtures";
|
||||
import type { FormPreferences } from "@/create-agent-preferences/preferences";
|
||||
import {
|
||||
closeCommandCenter,
|
||||
openCommandCenter,
|
||||
openCommandCenterWithShortcut,
|
||||
} from "../support/helpers/command-center";
|
||||
import {
|
||||
enterComposerFullscreen,
|
||||
exitComposerFullscreen,
|
||||
expectComposerVisible,
|
||||
fillComposerDraft,
|
||||
resizeComposerViewport,
|
||||
} from "../support/helpers/composer";
|
||||
import { closeCommandCenter, openCommandCenter } from "../support/helpers/command-center";
|
||||
import {
|
||||
applyCommandCenterAgentControls,
|
||||
chooseCommandCenterAgentControl,
|
||||
@@ -25,18 +14,8 @@ import {
|
||||
} from "../support/helpers/command-center-agent-controls";
|
||||
import { clickNewChat, gotoWorkspace } from "../support/helpers/launcher";
|
||||
import { openAgentRoute, seedMockAgentWorkspace } from "../support/helpers/mock-agent";
|
||||
import {
|
||||
assertNewWorkspaceSidebarAndHeader,
|
||||
connectNewWorkspaceDaemonClient,
|
||||
openGlobalNewWorkspaceComposer,
|
||||
selectNewWorkspaceProject,
|
||||
selectWorkspaceIsolation,
|
||||
submitNewWorkspacePrompt,
|
||||
} from "../support/helpers/new-workspace";
|
||||
import { getServerId } from "../support/helpers/server-id";
|
||||
import { expectAppRoute } from "../support/helpers/route-assertions";
|
||||
import { seedWorkspace } from "../support/helpers/seed-client";
|
||||
import { closeMobileAgentSidebar, openMobileAgentSidebar } from "../support/helpers/sidebar";
|
||||
import { buildSchedulesRoute } from "@/utils/host-routes";
|
||||
|
||||
const CREATE_AGENT_PREFERENCES_KEY = "@paseo:create-agent-preferences";
|
||||
@@ -51,7 +30,7 @@ async function seedMockDraftPreferences(page: import("@playwright/test").Page):
|
||||
providerPreferences: {
|
||||
mock: {
|
||||
model: "five-minute-stream",
|
||||
mode: "approval-test",
|
||||
mode: "load-test",
|
||||
},
|
||||
},
|
||||
} satisfies FormPreferences),
|
||||
@@ -242,94 +221,6 @@ test.describe("Command Center agent controls", () => {
|
||||
await workspace.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test("applies New workspace model and mode choices before the first message", async ({
|
||||
page,
|
||||
}) => {
|
||||
const workspace = await seedWorkspace({ repoPrefix: "command-center-new-workspace-controls-" });
|
||||
await seedMockDraftPreferences(page);
|
||||
const client = await connectNewWorkspaceDaemonClient();
|
||||
|
||||
try {
|
||||
const backgroundAgent = await workspace.client.createAgent({
|
||||
provider: "mock",
|
||||
cwd: workspace.repoPath,
|
||||
workspaceId: workspace.workspaceId,
|
||||
title: "Background agent",
|
||||
model: "five-minute-stream",
|
||||
modeId: "approval-test",
|
||||
});
|
||||
await openAgentRoute(page, {
|
||||
workspaceId: workspace.workspaceId,
|
||||
agentId: backgroundAgent.id,
|
||||
});
|
||||
await openGlobalNewWorkspaceComposer(page);
|
||||
await selectNewWorkspaceProject(page, workspace);
|
||||
await selectWorkspaceIsolation(page, "local");
|
||||
|
||||
await applyCommandCenterAgentControls(page, DRAFT_AGENT_CONTROL_CHOICES);
|
||||
await closeCommandCenter(page);
|
||||
await submitNewWorkspacePrompt(page, "Create with Command Center choices");
|
||||
const created = await assertNewWorkspaceSidebarAndHeader(page, {
|
||||
serverId: getServerId(),
|
||||
client,
|
||||
previousWorkspaceId: workspace.workspaceId,
|
||||
projectDisplayName: workspace.projectDisplayName,
|
||||
});
|
||||
|
||||
await expectWorkspaceAgentConfiguration(
|
||||
{ client: workspace.client, workspaceId: created.workspaceId },
|
||||
{ provider: "mock", model: "ten-second-stream", modeId: "load-test" },
|
||||
);
|
||||
await expectWorkspaceAgentConfiguration(workspace, {
|
||||
id: backgroundAgent.id,
|
||||
provider: "mock",
|
||||
model: "five-minute-stream",
|
||||
modeId: "approval-test",
|
||||
});
|
||||
} finally {
|
||||
await client.close().catch(() => undefined);
|
||||
await workspace.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test("keeps draft settings searchable from the compact sidebar and fullscreen editor", async ({
|
||||
page,
|
||||
}) => {
|
||||
const workspace = await seedWorkspace({ repoPrefix: "command-center-fullscreen-draft-" });
|
||||
await seedMockDraftPreferences(page);
|
||||
|
||||
try {
|
||||
await openDraftComposer(page, workspace.workspaceId);
|
||||
await resizeComposerViewport(page, "portrait");
|
||||
await applyCompactComposerSettings(page);
|
||||
} finally {
|
||||
await workspace.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test("applies compact sidebar and fullscreen settings to the running agent", async ({ page }) => {
|
||||
const workspace = await seedMockAgentWorkspace({
|
||||
repoPrefix: "command-center-fullscreen-agent-",
|
||||
title: "Compact Command Center settings",
|
||||
model: "five-minute-stream",
|
||||
modeId: "approval-test",
|
||||
});
|
||||
|
||||
try {
|
||||
await resizeComposerViewport(page, "portrait");
|
||||
await openAgentRoute(page, workspace);
|
||||
await applyCompactComposerSettings(page);
|
||||
await expectWorkspaceAgentConfiguration(workspace, {
|
||||
id: workspace.agentId,
|
||||
provider: "mock",
|
||||
model: "ten-second-stream",
|
||||
modeId: "load-test",
|
||||
});
|
||||
} finally {
|
||||
await workspace.cleanup();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const DRAFT_AGENT_CONTROL_CHOICES = [
|
||||
@@ -342,22 +233,3 @@ async function openDraftComposer(page: import("@playwright/test").Page, workspac
|
||||
await clickNewChat(page);
|
||||
await waitForDraftComposer(page);
|
||||
}
|
||||
|
||||
async function applyCompactComposerSettings(page: import("@playwright/test").Page): Promise<void> {
|
||||
const [model, mode] = DRAFT_AGENT_CONTROL_CHOICES;
|
||||
await expectComposerVisible(page);
|
||||
await openMobileAgentSidebar(page);
|
||||
await openCommandCenter(page);
|
||||
await chooseCommandCenterAgentControl({ page, ...mode });
|
||||
await closeMobileAgentSidebar(page);
|
||||
|
||||
await fillComposerDraft(page, "First line\nSecond line\nThird line");
|
||||
await enterComposerFullscreen(page);
|
||||
await openCommandCenterWithShortcut(page);
|
||||
await chooseCommandCenterAgentControl({ page, ...model });
|
||||
await exitComposerFullscreen(page);
|
||||
|
||||
await openCommandCenterWithShortcut(page);
|
||||
await expectCommandCenterAgentControlSelected({ page, ...model });
|
||||
await expectCommandCenterAgentControlSelected({ page, ...mode });
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { test, expect, type Page } from "../support/fixtures";
|
||||
import { test, expect } from "../support/fixtures";
|
||||
import { openWorkspaceWithAgents } from "../support/helpers/archive-tab";
|
||||
import {
|
||||
composerLocator,
|
||||
@@ -311,86 +311,3 @@ test.describe("Composer trailing disc on a new chat", () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const SHORTCUT_MOD = process.platform === "darwin" ? "Meta" : "Control";
|
||||
|
||||
async function toggleModelPickerFromComposer(page: Page) {
|
||||
await composerLocator(page).focus();
|
||||
await page.keyboard.press(`${SHORTCUT_MOD}+Slash`);
|
||||
}
|
||||
|
||||
async function expectModelPickerClosesFromSearch(page: Page) {
|
||||
const search = page.getByPlaceholder(/Search (all )?models/);
|
||||
await expect(search).toBeVisible();
|
||||
await search.focus();
|
||||
await page.keyboard.press(`${SHORTCUT_MOD}+Slash`);
|
||||
await expect(search).toBeHidden();
|
||||
}
|
||||
|
||||
async function cycleComposerEffort(page: Page) {
|
||||
await composerLocator(page).focus();
|
||||
await page.keyboard.press(`${SHORTCUT_MOD}+Shift+Slash`);
|
||||
}
|
||||
|
||||
function modelControl(page: Page) {
|
||||
return page.getByRole("button", { name: "Select model (Ten second stream)", exact: true });
|
||||
}
|
||||
|
||||
function thinkingControl(page: Page, effort: string) {
|
||||
return page.getByRole("button", { name: `Select thinking option (${effort})`, exact: true });
|
||||
}
|
||||
|
||||
async function expectShortcutHint(
|
||||
page: Page,
|
||||
control: ReturnType<typeof modelControl>,
|
||||
label: string,
|
||||
) {
|
||||
await control.hover();
|
||||
const tooltip = page.getByRole("tooltip").filter({ hasText: label });
|
||||
await expect(tooltip).toContainText("/");
|
||||
}
|
||||
|
||||
test.describe("Composer model and effort shortcuts", () => {
|
||||
test("opens and closes the model picker and wraps effort in toolbar order", async ({ page }) => {
|
||||
const agent = await seedMockAgentWorkspace({
|
||||
repoPrefix: "composer-shortcuts-",
|
||||
title: "Composer shortcuts",
|
||||
model: "ten-second-stream",
|
||||
thinkingOptionId: "high",
|
||||
});
|
||||
try {
|
||||
await openAgentRoute(page, agent);
|
||||
await expectComposerVisible(page);
|
||||
await expect(thinkingControl(page, "High")).toBeVisible();
|
||||
|
||||
await test.step("Show both shortcuts in the toolbar tooltips", async () => {
|
||||
await expectShortcutHint(page, modelControl(page), "Change model");
|
||||
await expectShortcutHint(page, thinkingControl(page, "High"), "Thinking mode");
|
||||
});
|
||||
|
||||
await test.step("Toggle the picker with its search field focused", async () => {
|
||||
await toggleModelPickerFromComposer(page);
|
||||
await expectModelPickerClosesFromSearch(page);
|
||||
});
|
||||
|
||||
await test.step("Wrap from High to Low and advance to Medium", async () => {
|
||||
await cycleComposerEffort(page);
|
||||
await expect(thinkingControl(page, "Low")).toBeVisible();
|
||||
await cycleComposerEffort(page);
|
||||
await expect(thinkingControl(page, "Medium")).toBeVisible();
|
||||
});
|
||||
|
||||
await test.step("Toggle the folded picker and cycle effort in a compact window", async () => {
|
||||
await page.setViewportSize({ width: 480, height: 844 });
|
||||
const effortLabel = page.getByTestId("combined-model-selector-thinking-label");
|
||||
await expect(effortLabel).toHaveText("Medium");
|
||||
await toggleModelPickerFromComposer(page);
|
||||
await expectModelPickerClosesFromSearch(page);
|
||||
await cycleComposerEffort(page);
|
||||
await expect(effortLabel).toHaveText("High");
|
||||
});
|
||||
} finally {
|
||||
await agent.cleanup();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -513,37 +513,3 @@ test("compact file sheets cover Explorer and return to its retained file list",
|
||||
await workspace.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
async function toggleCommentInMainEditor(page: Parameters<typeof ensureExplorerSidebar>[0]) {
|
||||
const editor = page.getByLabel("Source editor for comment.cs").getByRole("textbox");
|
||||
await expect(editor).toBeVisible();
|
||||
await editor.press(process.platform === "darwin" ? "Meta+Slash" : "Control+Slash");
|
||||
await expect(editor).toHaveText("// public class Example {}");
|
||||
}
|
||||
|
||||
test("keeps the comment shortcut in the editor beside an Explorer agent", async ({ page }) => {
|
||||
const workspace = await seedMockAgentWorkspace({
|
||||
repoPrefix: "explorer-comment-shortcut-",
|
||||
title: "Chat beside the editor",
|
||||
model: "ten-second-stream",
|
||||
});
|
||||
try {
|
||||
await writeFile(`${workspace.cwd}/comment.cs`, "public class Example {}");
|
||||
await openAgentRoute(page, workspace);
|
||||
await expect(
|
||||
page.getByRole("button", { name: "Select model (Ten second stream)" }),
|
||||
).toBeVisible();
|
||||
await ensureExplorerSidebar(page);
|
||||
await dragTabIntoExplorer(page, `agent_${workspace.agentId}`);
|
||||
await expect(
|
||||
explorerSidebar(page).getByRole("button", { name: "Select model (Ten second stream)" }),
|
||||
).toBeVisible();
|
||||
await openFilesPanel(page);
|
||||
await openFileFromExplorer(page, "comment.cs");
|
||||
await explorerSidebar(page).getByTestId(`workspace-tab-agent_${workspace.agentId}`).click();
|
||||
await toggleCommentInMainEditor(page);
|
||||
await expect(page.getByPlaceholder(/Search (all )?models/)).toBeHidden();
|
||||
} finally {
|
||||
await workspace.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -16,13 +16,6 @@ import {
|
||||
expectComposerFullscreenControls,
|
||||
} from "../support/helpers/composer";
|
||||
import { waitForSidebarHydration } from "../support/helpers/workspace-ui";
|
||||
import {
|
||||
seedTerminalProfiles,
|
||||
selectLaunchOption,
|
||||
terminalPromptInput,
|
||||
} from "../support/helpers/new-workspace-launch";
|
||||
|
||||
test.use({ channel: "chromium", launchOptions: { args: ["--use-fake-device-for-media-stream"] } });
|
||||
|
||||
type WebSocketMessage = string | Buffer;
|
||||
|
||||
@@ -261,82 +254,3 @@ test("dictation shortcut leaves retained fullscreen and exposes recording contro
|
||||
await agent.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
async function controlMicrophonePermission(page: Page) {
|
||||
const cdp = await page.context().newCDPSession(page);
|
||||
const { targetInfo } = await cdp.send("Target.getTargetInfo");
|
||||
const origin = new URL(page.url()).origin;
|
||||
return async (setting: "denied" | "granted") => {
|
||||
await cdp.send("Browser.setPermission", {
|
||||
permission: { name: "microphone" },
|
||||
setting,
|
||||
origin,
|
||||
browserContextId: targetInfo.browserContextId,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
function startDictationByMic(page: Page) {
|
||||
return page.getByRole("button", { name: "Start dictation", exact: true }).click();
|
||||
}
|
||||
|
||||
function expectDictationPermissionError(page: Page) {
|
||||
return expect(page.getByTestId("message-input-root").getByRole("alert")).toHaveText(
|
||||
"Allow microphone access and try again.",
|
||||
);
|
||||
}
|
||||
|
||||
test("keeps the draft and retries from the mic after access is restored", async ({ page }) => {
|
||||
const agent = await seedMockAgentWorkspace({
|
||||
repoPrefix: "dictation-permission-",
|
||||
title: "Dictation permission",
|
||||
});
|
||||
const draft = "Keep my draft";
|
||||
await installDictationFailureHarness(page);
|
||||
try {
|
||||
await openAgentRoute(page, agent);
|
||||
await expectComposerVisible(page);
|
||||
await fillComposerDraft(page, draft);
|
||||
|
||||
const setMicrophonePermission = await controlMicrophonePermission(page);
|
||||
await setMicrophonePermission("denied");
|
||||
await startDictationByMic(page);
|
||||
await expectDictationPermissionError(page);
|
||||
await expect(composerLocator(page)).toHaveValue(draft);
|
||||
|
||||
await setMicrophonePermission("granted");
|
||||
await startDictationByMic(page);
|
||||
await expect(page.getByRole("button", { name: "Cancel dictation", exact: true })).toBeVisible();
|
||||
await expect(page.getByText("Allow microphone access and try again.")).toHaveCount(0);
|
||||
await page.getByRole("button", { name: "Cancel dictation", exact: true }).click();
|
||||
await expect(composerLocator(page)).toHaveValue(draft);
|
||||
} finally {
|
||||
await agent.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test("shows dictation failure when the terminal prompt starts it by shortcut", async ({ page }) => {
|
||||
const workspace = await seedWorkspace({ repoPrefix: "terminal-dictation-permission-" });
|
||||
const profile = {
|
||||
id: "echo-prompt",
|
||||
name: "Echo prompt",
|
||||
command: "echo",
|
||||
args: ["{{{prompt}}}"],
|
||||
};
|
||||
const profiles = await seedTerminalProfiles([profile]);
|
||||
await installDictationFailureHarness(page);
|
||||
try {
|
||||
await gotoAppShell(page);
|
||||
await waitForSidebarHydration(page);
|
||||
await openNewWorkspaceComposer(page, workspace);
|
||||
await selectLaunchOption(page, profile.id);
|
||||
|
||||
const setMicrophonePermission = await controlMicrophonePermission(page);
|
||||
await setMicrophonePermission("denied");
|
||||
await terminalPromptInput(page).press("Control+d");
|
||||
await expectDictationPermissionError(page);
|
||||
} finally {
|
||||
await profiles.restore();
|
||||
await workspace.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,29 +1,16 @@
|
||||
import type { Locator } from "@playwright/test";
|
||||
import { expect, test, type Page } from "../support/fixtures";
|
||||
import { openAgentRoute, seedMockAgentWorkspace } from "../support/helpers/mock-agent";
|
||||
import {
|
||||
closeCommandCenter,
|
||||
openCommandCenter,
|
||||
selectCommandCenterTab,
|
||||
} from "../support/helpers/command-center";
|
||||
import { installDaemonWebSocketGate } from "../support/helpers/daemon-websocket-gate";
|
||||
import { scrollChatAwayFromBottom } from "../support/helpers/agent-bottom-anchor";
|
||||
import {
|
||||
attachComposerTestImage,
|
||||
composerLocator,
|
||||
expectComposerDraft,
|
||||
expectComposerFocused,
|
||||
expectComposerNotFocused,
|
||||
expectComposerVisible,
|
||||
fillComposerDraft,
|
||||
submitMessage,
|
||||
submitMessageWithButton,
|
||||
} from "../support/helpers/composer";
|
||||
import { readReplicaCache, writeReplicaCache } from "../support/helpers/replica-cache-storage";
|
||||
import {
|
||||
disconnectViewedTimeline,
|
||||
releaseHeldCatchUp,
|
||||
restoreViewedTimelineHoldingCatchUp,
|
||||
} from "../support/helpers/timeline-resume";
|
||||
|
||||
// UI plumbing contract against the dev mock provider. Real-provider behavior is tested in `daemon-e2e/*-rewind.real.e2e.test.ts`.
|
||||
|
||||
@@ -46,17 +33,6 @@ async function selectRewindOption(page: Page, name: string): Promise<void> {
|
||||
await option.click();
|
||||
}
|
||||
|
||||
async function searchRewindActions(page: Page): Promise<Locator> {
|
||||
const palette = await openCommandCenter(page);
|
||||
await selectCommandCenterTab(palette, "Actions");
|
||||
await palette.getByRole("textbox").fill("rewind last turn");
|
||||
return palette;
|
||||
}
|
||||
|
||||
function rewindAction(palette: Locator, name: string): Locator {
|
||||
return palette.getByRole("button", { name: `${name} This action cannot be undone`, exact: true });
|
||||
}
|
||||
|
||||
async function rewriteCachedMessageAsLegacyRow(
|
||||
page: Page,
|
||||
input: { prompt: string; agentId: string; workspaceId: string },
|
||||
@@ -223,6 +199,10 @@ test.describe("Rewind sheet", () => {
|
||||
await expectUserMessageCount(page, 2);
|
||||
await session.client.waitForFinish(session.agentId);
|
||||
|
||||
await scrollChatAwayFromBottom(page, {
|
||||
deltaY: -900,
|
||||
minDistanceFromBottom: 300,
|
||||
});
|
||||
await userMessage(page, firstPrompt).hover();
|
||||
await page.getByTestId("rewind-menu-trigger").first().click();
|
||||
const rewindSheet = page.getByTestId("rewind-menu-content");
|
||||
@@ -237,7 +217,6 @@ test.describe("Rewind sheet", () => {
|
||||
await expect(page.getByText("Cycle 1", { exact: true })).toHaveCount(0);
|
||||
await expectUserMessageCount(page, 1);
|
||||
await expectComposerDraft(page, firstPrompt);
|
||||
await expectComposerFocused(page);
|
||||
|
||||
await submitMessage(page, replacementPrompt);
|
||||
await expectUserMessageVisible(page, replacementPrompt);
|
||||
@@ -253,7 +232,17 @@ test.describe("Rewind sheet", () => {
|
||||
await selectRewindOption(page, "Rewind files");
|
||||
await expect(page.getByTestId("rewind-menu-content")).toHaveCount(0);
|
||||
await expectComposerDraft(page, "");
|
||||
await expectComposerNotFocused(page);
|
||||
await expectUserMessageCount(page, 2);
|
||||
|
||||
const preservedDraft = "Keep this human draft after rewind.";
|
||||
await fillComposerDraft(page, preservedDraft);
|
||||
await composerLocator(page).evaluate((element) => element.blur());
|
||||
await userMessage(page, replacementPrompt).hover();
|
||||
await page.getByTestId("rewind-menu-trigger").last().click();
|
||||
await expect(page.getByTestId("rewind-menu-content")).toBeVisible();
|
||||
await selectRewindOption(page, "Rewind files");
|
||||
await expect(page.getByTestId("rewind-menu-content")).toHaveCount(0);
|
||||
await expectComposerDraft(page, preservedDraft);
|
||||
await expectUserMessageCount(page, 2);
|
||||
|
||||
await fillComposerDraft(page, "");
|
||||
@@ -264,109 +253,12 @@ test.describe("Rewind sheet", () => {
|
||||
await selectRewindOption(page, "Rewind conversation and files");
|
||||
await expect(page.getByTestId("rewind-menu-content")).toHaveCount(0);
|
||||
await expectComposerDraft(page, replacementPrompt);
|
||||
await expectComposerFocused(page);
|
||||
await expectUserMessageCount(page, 1);
|
||||
} finally {
|
||||
await session.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test("rewinds the latest turn from the Command Center", async ({ page }) => {
|
||||
const firstPrompt = "Keep this earlier turn.";
|
||||
const latestPrompt = "Edit this latest turn.";
|
||||
const session = await seedMockAgentWorkspace({
|
||||
repoPrefix: "rewind-command-center-e2e-",
|
||||
title: "Command Center rewind",
|
||||
initialPrompt: firstPrompt,
|
||||
});
|
||||
|
||||
try {
|
||||
await openAgentRoute(page, session);
|
||||
await expectComposerVisible(page);
|
||||
await submitMessage(page, latestPrompt);
|
||||
await expectUserMessageVisible(page, latestPrompt);
|
||||
await session.client.waitForFinish(session.agentId);
|
||||
|
||||
const palette = await searchRewindActions(page);
|
||||
await expect(rewindAction(palette, "Rewind files")).toBeVisible();
|
||||
await expect(rewindAction(palette, "Rewind conversation and files")).toBeVisible();
|
||||
await rewindAction(palette, "Rewind conversation").click();
|
||||
|
||||
await expectUserMessageVisible(page, firstPrompt);
|
||||
await expect(userMessage(page, latestPrompt)).toHaveCount(0);
|
||||
await expectComposerDraft(page, latestPrompt);
|
||||
await expectComposerFocused(page);
|
||||
} finally {
|
||||
await session.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test("waits for the latest prompt before offering Command Center rewind after reconnect", async ({
|
||||
page,
|
||||
}) => {
|
||||
const cachedPrompt = "Keep the prompt that was visible before reconnect.";
|
||||
const latestPrompt = "Rewind the prompt sent while the app was disconnected.";
|
||||
const gate = await installDaemonWebSocketGate(page);
|
||||
const session = await seedMockAgentWorkspace({
|
||||
repoPrefix: "rewind-reconnect-e2e-",
|
||||
title: "Rewind after reconnect",
|
||||
initialPrompt: cachedPrompt,
|
||||
});
|
||||
|
||||
try {
|
||||
await openAgentRoute(page, session);
|
||||
await expectUserMessageVisible(page, cachedPrompt);
|
||||
const initialPalette = await searchRewindActions(page);
|
||||
await expect(rewindAction(initialPalette, "Rewind conversation")).toBeVisible();
|
||||
await closeCommandCenter(page);
|
||||
|
||||
await disconnectViewedTimeline(page, gate);
|
||||
await session.client.sendAgentMessage(session.agentId, latestPrompt);
|
||||
await session.client.waitForFinish(session.agentId);
|
||||
await restoreViewedTimelineHoldingCatchUp(page, gate);
|
||||
|
||||
const palette = await searchRewindActions(page);
|
||||
await expect(palette.getByText("No matches", { exact: true })).toBeVisible();
|
||||
await releaseHeldCatchUp(page, gate);
|
||||
await rewindAction(palette, "Rewind conversation").click();
|
||||
|
||||
await expectUserMessageVisible(page, cachedPrompt);
|
||||
await expectComposerDraft(page, latestPrompt);
|
||||
} finally {
|
||||
gate.restore();
|
||||
await session.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test("hides rewind when the latest prompt only contains an attachment", async ({ page }) => {
|
||||
const session = await seedMockAgentWorkspace({
|
||||
repoPrefix: "rewind-image-only-e2e-",
|
||||
title: "Rewind image-only prompt",
|
||||
initialPrompt: "Earlier text prompt.",
|
||||
});
|
||||
|
||||
try {
|
||||
await openAgentRoute(page, session);
|
||||
await expectComposerVisible(page);
|
||||
const palette = await searchRewindActions(page);
|
||||
await expect(rewindAction(palette, "Rewind conversation")).toBeVisible();
|
||||
await closeCommandCenter(page);
|
||||
|
||||
await attachComposerTestImage(page);
|
||||
await submitMessageWithButton(page, "");
|
||||
const imagePrompt = page.getByTestId("user-message").filter({
|
||||
has: page.getByRole("button", { name: "Open image attachment" }),
|
||||
});
|
||||
await expect(imagePrompt).toHaveAttribute("aria-busy", "false");
|
||||
await session.client.waitForFinish(session.agentId);
|
||||
|
||||
const reopened = await searchRewindActions(page);
|
||||
await expect(reopened.getByText("No matches", { exact: true })).toBeVisible();
|
||||
} finally {
|
||||
await session.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test("surfaces rewind failures without crashing the page", async ({ page }) => {
|
||||
const firstPrompt = "emit 1 coalesced agent stream updates for failed rewind turn.";
|
||||
const rewindError = "No file checkpoint found for message rewind-failure-e2e.";
|
||||
@@ -385,10 +277,6 @@ test.describe("Rewind sheet", () => {
|
||||
|
||||
await expectUserMessageVisible(page, firstPrompt);
|
||||
|
||||
const palette = await searchRewindActions(page);
|
||||
await rewindAction(palette, "Rewind conversation").click();
|
||||
await expect(page.getByTestId("app-toast-message")).toHaveText(rewindError);
|
||||
|
||||
await userMessage(page, firstPrompt).hover();
|
||||
await page.getByTestId("rewind-menu-trigger").first().click();
|
||||
const rewindSheet = page.getByTestId("rewind-menu-content");
|
||||
|
||||
@@ -24,7 +24,7 @@ function send(message) {
|
||||
function respond(method, params) {
|
||||
switch (method) {
|
||||
case "initialize":
|
||||
return { userAgent: "codex/0.159.0" };
|
||||
return {};
|
||||
case "model/list":
|
||||
return { data: models };
|
||||
case "config/read":
|
||||
|
||||
@@ -23,11 +23,6 @@ export async function openCommandCenter(page: Page): Promise<Locator> {
|
||||
return panel;
|
||||
}
|
||||
|
||||
export async function openCommandCenterWithShortcut(page: Page): Promise<void> {
|
||||
await page.keyboard.press("ControlOrMeta+k");
|
||||
await expect(page.getByTestId("command-center-panel")).toBeVisible();
|
||||
}
|
||||
|
||||
export async function closeCommandCenter(page: Page): Promise<void> {
|
||||
await page.keyboard.press("Escape");
|
||||
await expect(page.getByTestId("command-center-panel")).not.toBeVisible();
|
||||
|
||||
@@ -2,7 +2,6 @@ import { buildSettingsHostSectionRoute } from "@/utils/host-routes";
|
||||
import { expect, type Page } from "../fixtures";
|
||||
import { getServerId } from "./server-id";
|
||||
import { expectAppRoute } from "./route-assertions";
|
||||
import { escapeRegex } from "./regex";
|
||||
|
||||
/**
|
||||
* Settings → Host → Plugins: the Installed and Browse tabs, the page menu, the install sheet and a
|
||||
@@ -29,17 +28,8 @@ function pluginSwitch(page: Page, name: string, action: "Disable" | "Enable") {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* A toast that times out stays in the page while it fades, so the next toast can share the screen
|
||||
* with it, even when both have the same text. The pattern matches case, so "Installed x" does not
|
||||
* match "Uninstalled x".
|
||||
*/
|
||||
export async function expectToast(page: Page, message: string): Promise<void> {
|
||||
const toast = page
|
||||
.getByTestId("app-toast-message")
|
||||
.filter({ hasText: new RegExp(escapeRegex(message)) })
|
||||
.first();
|
||||
await expect(toast).toBeVisible();
|
||||
await expect(page.getByTestId("app-toast-message")).toContainText(message);
|
||||
}
|
||||
|
||||
// Tabs and search
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
apply plugin: 'com.android.library'
|
||||
|
||||
group = 'sh.paseo.pressfeedback'
|
||||
version = '0.1.0'
|
||||
|
||||
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
|
||||
apply from: expoModulesCorePlugin
|
||||
applyKotlinExpoModulesCorePlugin()
|
||||
useCoreDependencies()
|
||||
useExpoPublishing()
|
||||
useDefaultAndroidSdkVersions()
|
||||
|
||||
android {
|
||||
namespace "sh.paseo.pressfeedback"
|
||||
defaultConfig {
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" />
|
||||
-39
@@ -1,39 +0,0 @@
|
||||
package sh.paseo.pressfeedback
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Color
|
||||
import android.graphics.Paint
|
||||
import expo.modules.kotlin.AppContext
|
||||
import expo.modules.kotlin.modules.Module
|
||||
import expo.modules.kotlin.modules.ModuleDefinition
|
||||
import expo.modules.kotlin.types.ColorCompat
|
||||
import expo.modules.kotlin.views.ExpoView
|
||||
|
||||
class PaseoPressFeedbackModule : Module() {
|
||||
override fun definition() = ModuleDefinition {
|
||||
Name("PaseoPressFeedback")
|
||||
View(PaseoPressFeedbackView::class) {
|
||||
Prop("tint") { view: PaseoPressFeedbackView, color: Color -> view.paint.color = ColorCompat.toArgb(color) }
|
||||
Prop("radius") { view: PaseoPressFeedbackView, radius: Double -> view.radius = radius.toFloat() * view.resources.displayMetrics.density }
|
||||
Prop("resetKey") { view: PaseoPressFeedbackView, key: String -> view.reset(key) }
|
||||
AsyncFunction("acknowledge") { view: PaseoPressFeedbackView -> view.acknowledge() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class PaseoPressFeedbackView(context: Context, appContext: AppContext) : ExpoView(context, appContext) {
|
||||
val paint = Paint(Paint.ANTI_ALIAS_FLAG)
|
||||
var radius = 0f
|
||||
private var acknowledged = false
|
||||
private var resetKey = ""
|
||||
init { setWillNotDraw(false); importantForAccessibility = IMPORTANT_FOR_ACCESSIBILITY_NO }
|
||||
fun acknowledge() { acknowledged = true; invalidate() }
|
||||
fun reset(key: String) {
|
||||
if (key != resetKey) { resetKey = key; acknowledged = false; invalidate() }
|
||||
}
|
||||
override fun onDraw(canvas: Canvas) {
|
||||
super.onDraw(canvas)
|
||||
if (acknowledged) canvas.drawRoundRect(0f, 0f, width.toFloat(), height.toFloat(), radius, radius, paint)
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"platforms": ["android", "ios"],
|
||||
"android": { "modules": ["sh.paseo.pressfeedback.PaseoPressFeedbackModule"] },
|
||||
"ios": { "modules": ["PaseoPressFeedbackModule"] }
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
export { useWorkspaceRowPress } from "./src/ui";
|
||||
@@ -1,22 +0,0 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'PaseoPressFeedback'
|
||||
s.version = '0.1.0'
|
||||
s.summary = 'Native accepted press feedback for Paseo'
|
||||
s.description = 'Paints accepted press feedback independently of React commits'
|
||||
s.license = 'Apache-2.0'
|
||||
s.author = 'Paseo'
|
||||
s.homepage = 'https://paseo.sh'
|
||||
s.platforms = { :ios => '15.1' }
|
||||
s.swift_version = '5.4'
|
||||
s.source = { :path => '.' }
|
||||
s.static_framework = true
|
||||
|
||||
s.dependency 'ExpoModulesCore'
|
||||
|
||||
s.pod_target_xcconfig = {
|
||||
'DEFINES_MODULE' => 'YES',
|
||||
'SWIFT_COMPILATION_MODE' => 'wholemodule'
|
||||
}
|
||||
|
||||
s.source_files = "**/*.{h,m,swift}"
|
||||
end
|
||||
@@ -1,33 +0,0 @@
|
||||
import ExpoModulesCore
|
||||
import UIKit
|
||||
|
||||
public class PaseoPressFeedbackModule: Module {
|
||||
public func definition() -> ModuleDefinition {
|
||||
Name("PaseoPressFeedback")
|
||||
View(PaseoPressFeedbackView.self) {
|
||||
Prop("tint") { (view: PaseoPressFeedbackView, color: UIColor) in view.tint = color }
|
||||
Prop("radius") { (view: PaseoPressFeedbackView, radius: Double) in view.radius = radius }
|
||||
Prop("resetKey") { (view: PaseoPressFeedbackView, key: String) in view.reset(key) }
|
||||
AsyncFunction("acknowledge") { (view: PaseoPressFeedbackView) in view.acknowledge() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final class PaseoPressFeedbackView: ExpoView {
|
||||
var tint = UIColor.clear
|
||||
var radius: Double = 0
|
||||
private var acknowledged = false
|
||||
private var resetKey = ""
|
||||
required init(appContext: AppContext? = nil) {
|
||||
super.init(appContext: appContext)
|
||||
isOpaque = false
|
||||
isUserInteractionEnabled = false
|
||||
}
|
||||
func acknowledge() { acknowledged = true; setNeedsDisplay() }
|
||||
func reset(_ key: String) {
|
||||
if key != resetKey { resetKey = key; acknowledged = false; setNeedsDisplay() }
|
||||
}
|
||||
override func draw(_ rect: CGRect) {
|
||||
if acknowledged { tint.setFill(); UIBezierPath(roundedRect: bounds, cornerRadius: radius).fill() }
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"name": "paseo-press-feedback",
|
||||
"version": "0.1.0",
|
||||
"private": true
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
import { expect, it } from "vitest";
|
||||
import { acceptWorkspaceRowPress, type WorkspaceRowPress } from "./accept";
|
||||
|
||||
function rowPress(overrides: Partial<WorkspaceRowPress> = {}) {
|
||||
const visible: string[] = [];
|
||||
const press: WorkspaceRowPress = {
|
||||
cancelled: false,
|
||||
native: true,
|
||||
selected: false,
|
||||
sidebar: "overlay",
|
||||
target: "agent-list",
|
||||
acknowledge: () => visible.push("row"),
|
||||
navigate: () => visible.push("workspace"),
|
||||
...overrides,
|
||||
};
|
||||
return { press, visible };
|
||||
}
|
||||
|
||||
it("acknowledges an accepted row before navigation starts", () => {
|
||||
const { press, visible } = rowPress();
|
||||
expect(acceptWorkspaceRowPress(press)).toBe(true);
|
||||
expect(visible).toEqual(["row", "workspace"]);
|
||||
});
|
||||
|
||||
it("does not acknowledge or navigate after scrolling or a long press claims the touch", () => {
|
||||
const { press, visible } = rowPress({ cancelled: true });
|
||||
expect(acceptWorkspaceRowPress(press)).toBe(false);
|
||||
expect(visible).toEqual([]);
|
||||
});
|
||||
|
||||
it("accepts only the first row while its selection closes the sidebar", () => {
|
||||
const { press, visible } = rowPress();
|
||||
press.navigate = () => {
|
||||
press.target = "agent";
|
||||
visible.push("workspace B");
|
||||
};
|
||||
expect(acceptWorkspaceRowPress(press)).toBe(true);
|
||||
expect(acceptWorkspaceRowPress(press)).toBe(false);
|
||||
expect(visible).toEqual(["row", "workspace B"]);
|
||||
});
|
||||
|
||||
it.each([
|
||||
{
|
||||
name: "open phone or tablet overlay",
|
||||
sidebar: "overlay",
|
||||
target: "agent-list",
|
||||
native: true,
|
||||
accepted: true,
|
||||
},
|
||||
{ name: "closing overlay", sidebar: "overlay", target: "agent", native: true, accepted: false },
|
||||
{
|
||||
name: "explorer covering an overlay",
|
||||
sidebar: "overlay",
|
||||
target: "file-explorer",
|
||||
native: true,
|
||||
accepted: false,
|
||||
},
|
||||
{ name: "docked sidebar", sidebar: "dock", target: "agent", native: true, accepted: true },
|
||||
{
|
||||
name: "docked sidebar beside explorer",
|
||||
sidebar: "dock",
|
||||
target: "file-explorer",
|
||||
native: true,
|
||||
accepted: true,
|
||||
},
|
||||
{ name: "hidden sidebar", sidebar: "hidden", target: "agent", native: true, accepted: false },
|
||||
{
|
||||
name: "suspended open overlay",
|
||||
sidebar: "suspended",
|
||||
target: "agent-list",
|
||||
native: true,
|
||||
accepted: true,
|
||||
},
|
||||
{
|
||||
name: "suspended closed overlay",
|
||||
sidebar: "suspended",
|
||||
target: "agent",
|
||||
native: true,
|
||||
accepted: false,
|
||||
},
|
||||
{
|
||||
name: "web sidebar independent of native panel target",
|
||||
sidebar: "overlay",
|
||||
target: "agent",
|
||||
native: false,
|
||||
accepted: true,
|
||||
},
|
||||
] as const)("uses the panel state for $name", ({ accepted, name: _, ...state }) => {
|
||||
const { press, visible } = rowPress(state);
|
||||
expect(acceptWorkspaceRowPress(press)).toBe(accepted);
|
||||
expect(visible).toEqual(accepted ? ["row", "workspace"] : []);
|
||||
});
|
||||
|
||||
it("does not leave an acknowledgement over an already selected docked row", () => {
|
||||
const { press, visible } = rowPress({ selected: true, sidebar: "dock", target: "agent" });
|
||||
expect(acceptWorkspaceRowPress(press)).toBe(true);
|
||||
expect(visible).toEqual(["workspace"]);
|
||||
});
|
||||
|
||||
it("still acknowledges a selected overlay row before the sidebar leaves", () => {
|
||||
const { press, visible } = rowPress({ selected: true });
|
||||
expect(acceptWorkspaceRowPress(press)).toBe(true);
|
||||
expect(visible).toEqual(["row", "workspace"]);
|
||||
});
|
||||
@@ -1,20 +0,0 @@
|
||||
import type { LeftSidebarPresentation, MobilePanelView } from "@/stores/panel-store";
|
||||
|
||||
export interface WorkspaceRowPress {
|
||||
cancelled: boolean;
|
||||
native: boolean;
|
||||
selected: boolean;
|
||||
sidebar: LeftSidebarPresentation;
|
||||
target: MobilePanelView;
|
||||
acknowledge(): void;
|
||||
navigate(): void;
|
||||
}
|
||||
|
||||
export function acceptWorkspaceRowPress(press: WorkspaceRowPress): boolean {
|
||||
if (press.cancelled) return false;
|
||||
if (press.native && press.sidebar !== "dock" && press.target !== "agent-list") return false;
|
||||
// A selected docked row neither changes selection nor leaves the screen to clear the fill.
|
||||
if (!press.selected || press.sidebar !== "dock") press.acknowledge();
|
||||
press.navigate();
|
||||
return true;
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
import { requireNativeView } from "expo";
|
||||
import { type Ref } from "react";
|
||||
import { usePanelStore } from "@/stores/panel-store";
|
||||
import { withUnistyles } from "react-native-unistyles";
|
||||
import { View, StyleSheet, type ViewProps } from "react-native";
|
||||
|
||||
export interface RowFeedbackHandle {
|
||||
acknowledge(): Promise<void>;
|
||||
}
|
||||
interface FeedbackProps extends ViewProps {
|
||||
ref?: Ref<RowFeedbackHandle>;
|
||||
resetKey: string;
|
||||
tint?: string;
|
||||
radius?: number;
|
||||
}
|
||||
const NativeFeedback = withUnistyles(requireNativeView<FeedbackProps>("PaseoPressFeedback"));
|
||||
const mapTheme = (theme: import("@/styles/theme").Theme) => ({
|
||||
tint: theme.colors.interactionHighlight,
|
||||
radius: theme.borderRadius.lg,
|
||||
});
|
||||
export function RowFeedback({
|
||||
ref,
|
||||
selected,
|
||||
}: {
|
||||
ref?: Ref<RowFeedbackHandle>;
|
||||
selected: boolean;
|
||||
}) {
|
||||
const revision = usePanelStore((state) => state.mobilePanel.revision);
|
||||
// Selection takes over the fill; a new panel transition clears it before reopening.
|
||||
const resetKey = `${selected}:${revision}`;
|
||||
return (
|
||||
<View pointerEvents="none" style={styles.overlay}>
|
||||
<NativeFeedback
|
||||
ref={ref}
|
||||
resetKey={resetKey}
|
||||
pointerEvents="none"
|
||||
style={styles.fill}
|
||||
uniProps={mapTheme}
|
||||
/>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
overlay: { position: "absolute", top: 0, right: 0, bottom: 0, left: 0 },
|
||||
fill: { flex: 1 },
|
||||
});
|
||||
@@ -1,7 +0,0 @@
|
||||
import type { Ref } from "react";
|
||||
export interface RowFeedbackHandle {
|
||||
acknowledge(): Promise<void>;
|
||||
}
|
||||
export function RowFeedback(_props: { ref?: Ref<RowFeedbackHandle>; selected: boolean }) {
|
||||
return null;
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
import { useCallback, useRef, type RefObject } from "react";
|
||||
import { isNative } from "@/constants/platform";
|
||||
import { usePanelStore } from "@/stores/panel-store";
|
||||
import { acceptWorkspaceRowPress } from "../accept";
|
||||
import { RowFeedback, type RowFeedbackHandle } from "./feedback";
|
||||
|
||||
export function useWorkspaceRowPress({
|
||||
didLongPressRef,
|
||||
onPress,
|
||||
selected,
|
||||
}: {
|
||||
didLongPressRef?: RefObject<boolean>;
|
||||
onPress(): void;
|
||||
selected: boolean;
|
||||
}) {
|
||||
const feedback = useRef<RowFeedbackHandle>(null);
|
||||
const handlePress = useCallback(() => {
|
||||
const cancelled = didLongPressRef?.current ?? false;
|
||||
if (didLongPressRef) didLongPressRef.current = false;
|
||||
const panel = usePanelStore.getState();
|
||||
acceptWorkspaceRowPress({
|
||||
cancelled,
|
||||
native: isNative,
|
||||
selected,
|
||||
sidebar: panel.layout.leftSidebar,
|
||||
target: panel.mobilePanel.target,
|
||||
// Paint on the native UI thread before navigation occupies JS; never wait for paint.
|
||||
acknowledge: () => {
|
||||
void feedback.current?.acknowledge();
|
||||
},
|
||||
navigate: onPress,
|
||||
});
|
||||
}, [didLongPressRef, onPress, selected]);
|
||||
return {
|
||||
onPress: handlePress,
|
||||
feedback: <RowFeedback ref={feedback} selected={selected} />,
|
||||
};
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
import { expect, it } from "vitest";
|
||||
import { createInitialDrawDistanceExpansion } from "./initial-draw-distance";
|
||||
|
||||
function mountInitialBuffer() {
|
||||
let nextId = 0;
|
||||
const pending = new Map<number, () => void>();
|
||||
const expansions: string[] = [];
|
||||
const buffer = createInitialDrawDistanceExpansion(
|
||||
{
|
||||
requestFrame(callback) {
|
||||
const id = ++nextId;
|
||||
pending.set(id, callback);
|
||||
return id;
|
||||
},
|
||||
cancelFrame(id) {
|
||||
pending.delete(id);
|
||||
},
|
||||
},
|
||||
() => expansions.push("full draw distance"),
|
||||
);
|
||||
function advanceFrame() {
|
||||
const callbacks = [...pending.values()];
|
||||
pending.clear();
|
||||
for (const callback of callbacks) callback();
|
||||
}
|
||||
return { buffer, expansions, advanceFrame };
|
||||
}
|
||||
|
||||
it("requests the full draw distance after two frame callbacks once the reveal is eligible", () => {
|
||||
const { buffer, expansions, advanceFrame } = mountInitialBuffer();
|
||||
buffer.schedule();
|
||||
advanceFrame();
|
||||
expect(expansions).toEqual([]);
|
||||
advanceFrame();
|
||||
expect(expansions).toEqual(["full draw distance"]);
|
||||
});
|
||||
|
||||
it.each([0, 1])(
|
||||
"leaves initial draw distance in place during a gesture after %i frames",
|
||||
(elapsed) => {
|
||||
const { buffer, expansions, advanceFrame } = mountInitialBuffer();
|
||||
buffer.schedule();
|
||||
if (elapsed === 1) advanceFrame();
|
||||
|
||||
buffer.pauseForScroll();
|
||||
advanceFrame();
|
||||
advanceFrame();
|
||||
expect(expansions).toEqual([]);
|
||||
|
||||
buffer.resumeAfterScroll();
|
||||
advanceFrame();
|
||||
expect(expansions).toEqual([]);
|
||||
advanceFrame();
|
||||
expect(expansions).toEqual(["full draw distance"]);
|
||||
},
|
||||
);
|
||||
|
||||
it("cancels a covered reveal and schedules again when it is eligible", () => {
|
||||
const { buffer, expansions, advanceFrame } = mountInitialBuffer();
|
||||
const cancel = buffer.schedule();
|
||||
advanceFrame();
|
||||
cancel();
|
||||
advanceFrame();
|
||||
expect(expansions).toEqual([]);
|
||||
|
||||
buffer.schedule();
|
||||
advanceFrame();
|
||||
advanceFrame();
|
||||
expect(expansions).toEqual(["full draw distance"]);
|
||||
});
|
||||
|
||||
it("keeps a covered list at its initial draw distance when a gesture ends", () => {
|
||||
const { buffer, expansions, advanceFrame } = mountInitialBuffer();
|
||||
buffer.pauseForScroll();
|
||||
const cover = buffer.schedule();
|
||||
advanceFrame();
|
||||
advanceFrame();
|
||||
expect(expansions).toEqual([]);
|
||||
|
||||
cover();
|
||||
buffer.resumeAfterScroll();
|
||||
advanceFrame();
|
||||
advanceFrame();
|
||||
expect(expansions).toEqual([]);
|
||||
});
|
||||
@@ -1,50 +0,0 @@
|
||||
interface InitialDrawDistanceFrames {
|
||||
requestFrame(callback: () => void): number;
|
||||
cancelFrame(id: number): void;
|
||||
}
|
||||
|
||||
export function createInitialDrawDistanceExpansion(
|
||||
frames: InitialDrawDistanceFrames,
|
||||
expand: () => void,
|
||||
) {
|
||||
let frame: number | null = null;
|
||||
let eligible = false;
|
||||
let scrolling = false;
|
||||
let expanded = false;
|
||||
|
||||
function cancel() {
|
||||
if (frame === null) return;
|
||||
frames.cancelFrame(frame);
|
||||
frame = null;
|
||||
}
|
||||
|
||||
function scheduleIfIdle() {
|
||||
if (!eligible || scrolling || expanded || frame !== null) return;
|
||||
frame = frames.requestFrame(() => {
|
||||
frame = frames.requestFrame(() => {
|
||||
frame = null;
|
||||
expanded = true;
|
||||
expand();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
schedule() {
|
||||
eligible = true;
|
||||
scheduleIfIdle();
|
||||
return () => {
|
||||
eligible = false;
|
||||
cancel();
|
||||
};
|
||||
},
|
||||
pauseForScroll() {
|
||||
scrolling = true;
|
||||
cancel();
|
||||
},
|
||||
resumeAfterScroll() {
|
||||
scrolling = false;
|
||||
scheduleIfIdle();
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -40,7 +40,6 @@ function wait(ms: number): Promise<void> {
|
||||
}
|
||||
|
||||
const LIST_STYLE = { flex: 1 };
|
||||
const ESTIMATED_LIST_SIZE = { width: 300, height: VIEWPORT_HEIGHT };
|
||||
const rowStyles = new Map<number, { height: number }>();
|
||||
|
||||
function rowStyle(height: number) {
|
||||
@@ -90,10 +89,6 @@ function keyExtractor(item: Row) {
|
||||
return item.id;
|
||||
}
|
||||
|
||||
function estimateRowSize(item: Row) {
|
||||
return item.height;
|
||||
}
|
||||
|
||||
function mountList(heldRowId: string) {
|
||||
const listRef = React.createRef<LegendListRef>();
|
||||
const maintainVisibleContentPosition = holdOnly(heldRowId);
|
||||
@@ -269,49 +264,3 @@ it("keeps measured row sizes while the list is not laid out", async () => {
|
||||
|
||||
expect(rows.map((row) => list.rowSize(row.id))).toEqual([40, 40, 40]);
|
||||
});
|
||||
|
||||
it("expands the draw distance of a placed end-anchored list without moving its bottom row", async () => {
|
||||
const rows: Row[] = Array.from({ length: 99 }, (_, index) => ({
|
||||
id: `row-${index}`,
|
||||
height: index % 2 === 0 ? 20 : 60,
|
||||
}));
|
||||
const lastRow = { id: "last-row", height: 180 };
|
||||
rows.push(lastRow);
|
||||
const listRef = React.createRef<LegendListRef>();
|
||||
|
||||
function render(drawDistance: number) {
|
||||
act(() => {
|
||||
root.render(
|
||||
<LegendList
|
||||
ref={listRef}
|
||||
data={rows}
|
||||
renderItem={renderRow}
|
||||
keyExtractor={keyExtractor}
|
||||
estimatedListSize={ESTIMATED_LIST_SIZE}
|
||||
recycleItems={false}
|
||||
getEstimatedItemSize={estimateRowSize}
|
||||
drawDistance={drawDistance}
|
||||
alignItemsAtEnd
|
||||
initialScrollAtEnd
|
||||
style={LIST_STYLE}
|
||||
/>,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
render(50);
|
||||
await wait(300);
|
||||
const initial = listRef.current?.getState();
|
||||
const lastRowTop = initial?.positionByKey(lastRow.id);
|
||||
expect(initial?.sizes.get(lastRow.id)).toBe(lastRow.height);
|
||||
expect(initial?.sizes.size).toBeLessThan(8);
|
||||
expect(initial?.scroll).toBe(Number(lastRowTop) + lastRow.height - VIEWPORT_HEIGHT);
|
||||
|
||||
render(1000);
|
||||
await wait(150);
|
||||
|
||||
const expanded = listRef.current?.getState();
|
||||
expect(expanded?.sizes.size).toBeGreaterThan(20);
|
||||
expect(expanded?.scroll).toBe(initial?.scroll);
|
||||
expect(expanded?.positionByKey(lastRow.id)).toBe(lastRowTop);
|
||||
});
|
||||
|
||||
@@ -9,7 +9,6 @@ import {
|
||||
useState,
|
||||
} from "react";
|
||||
import {
|
||||
Dimensions,
|
||||
View,
|
||||
type LayoutChangeEvent,
|
||||
type NativeScrollEvent,
|
||||
@@ -32,7 +31,6 @@ import { useTranslation } from "react-i18next";
|
||||
import type { StreamItem } from "@/types/stream";
|
||||
import type { Theme } from "@/styles/theme";
|
||||
import { useStableEvent } from "@/hooks/use-stable-event";
|
||||
import { useIsMobilePanelActive } from "@/mobile-panels/provider";
|
||||
import { shouldAnimateNativeScrollToBottom } from "./native-scroll-animation";
|
||||
import { useRevisedHistoryRows } from "./history-row-revision";
|
||||
import { useBottomAnchorController } from "./bottom-anchor-controller";
|
||||
@@ -45,7 +43,6 @@ import {
|
||||
} from "./native-disclosure-hold";
|
||||
import { EndPinnedScrollView } from "./native-end-pin";
|
||||
import { createNewRowEstimates } from "./new-row-estimates";
|
||||
import { createInitialDrawDistanceExpansion } from "./initial-draw-distance";
|
||||
import type {
|
||||
DisclosureTriggerEdge,
|
||||
StreamRenderInput,
|
||||
@@ -135,14 +132,6 @@ function keyExtractor(item: { id: string }): string {
|
||||
return item.id;
|
||||
}
|
||||
|
||||
function InitialDrawDistanceExpansion({ schedule }: { schedule: () => () => void }) {
|
||||
const isSidebarActive = useIsMobilePanelActive("agent-list");
|
||||
useLayoutEffect(() => {
|
||||
if (!isSidebarActive) return schedule();
|
||||
}, [schedule, isSidebarActive]);
|
||||
return null;
|
||||
}
|
||||
|
||||
function NativeStreamViewport(props: StreamRenderInput & { strategy: StreamStrategy }) {
|
||||
const {
|
||||
agentId,
|
||||
@@ -168,16 +157,6 @@ function NativeStreamViewport(props: StreamRenderInput & { strategy: StreamStrat
|
||||
strategy,
|
||||
} = props;
|
||||
const isActive = useRetainedPanelActive();
|
||||
// Keep a screenful in reserve for a fling that starts before the full buffer mounts.
|
||||
const [drawDistance, setDrawDistance] = useState(() =>
|
||||
Math.min(Dimensions.get("window").height, NATIVE_STREAM_DRAW_DISTANCE),
|
||||
);
|
||||
const [drawDistanceExpansion] = useState(() =>
|
||||
createInitialDrawDistanceExpansion(
|
||||
{ requestFrame: requestAnimationFrame, cancelFrame: cancelAnimationFrame },
|
||||
() => setDrawDistance(NATIVE_STREAM_DRAW_DISTANCE),
|
||||
),
|
||||
);
|
||||
const { t } = useTranslation();
|
||||
const { renderHistoryMountedRow, renderLiveHeadRow, renderLiveAuxiliary } = renderers;
|
||||
const listRef = useRef<LegendListRef>(null);
|
||||
@@ -590,9 +569,6 @@ function NativeStreamViewport(props: StreamRenderInput & { strategy: StreamStrat
|
||||
cancelDisclosureHold();
|
||||
bottomAnchorController.beginUserScroll();
|
||||
historyStartPagination.rearm();
|
||||
// The reserve follows the gesture. Expanding the buffer here shifted the measured
|
||||
// content and returned the viewport to the end during an Android fling.
|
||||
drawDistanceExpansion.pauseForScroll();
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
@@ -615,7 +591,6 @@ function NativeStreamViewport(props: StreamRenderInput & { strategy: StreamStrat
|
||||
bottomAnchorController.endUserScroll({
|
||||
isAtEnd: isReleasedAtEndRef.current || isAtEnd(),
|
||||
});
|
||||
drawDistanceExpansion.resumeAfterScroll();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -635,7 +610,6 @@ function NativeStreamViewport(props: StreamRenderInput & { strategy: StreamStrat
|
||||
bottomAnchorController.endUserScroll({
|
||||
isAtEnd: isReleasedAtEndRef.current || isScrollEventAtEnd(event),
|
||||
});
|
||||
drawDistanceExpansion.resumeAfterScroll();
|
||||
},
|
||||
);
|
||||
|
||||
@@ -758,11 +732,6 @@ function NativeStreamViewport(props: StreamRenderInput & { strategy: StreamStrat
|
||||
);
|
||||
}, [historyStartPaginationState, hasOlderHistory, retryHistoryStart, t]);
|
||||
|
||||
const canExpandDrawDistance =
|
||||
drawDistance < NATIVE_STREAM_DRAW_DISTANCE &&
|
||||
isActive &&
|
||||
isListPlaced &&
|
||||
historyStartPaginationState.visible;
|
||||
return (
|
||||
<View style={viewportStyle}>
|
||||
<LegendList<StreamItem>
|
||||
@@ -795,14 +764,11 @@ function NativeStreamViewport(props: StreamRenderInput & { strategy: StreamStrat
|
||||
recycleItems={false}
|
||||
alignItemsAtEnd
|
||||
initialScrollAtEnd
|
||||
drawDistance={drawDistance}
|
||||
drawDistance={NATIVE_STREAM_DRAW_DISTANCE}
|
||||
getEstimatedItemSize={getEstimatedItemSize}
|
||||
scrollEnabled={scrollEnabled}
|
||||
showsVerticalScrollIndicator
|
||||
/>
|
||||
{canExpandDrawDistance ? (
|
||||
<InitialDrawDistanceExpansion schedule={drawDistanceExpansion.schedule} />
|
||||
) : null}
|
||||
{!historyStartPaginationState.visible ? (
|
||||
<View pointerEvents="none" testID="agent-initial-fill" style={initialFillStyle}>
|
||||
<ThemedLoadingSpinner size="large" uniProps={foregroundMutedColorMapping} />
|
||||
|
||||
@@ -3,6 +3,7 @@ export interface AudioEngineCallbacks {
|
||||
onVolumeLevel(level: number): void;
|
||||
onInterruption?(): void;
|
||||
onCaptureAvailabilityChange?(available: boolean): void;
|
||||
onError?(error: Error): void;
|
||||
}
|
||||
|
||||
export interface AudioPlaybackSource {
|
||||
@@ -30,21 +31,3 @@ export interface AudioEngineOptions {
|
||||
traceLabel?: string;
|
||||
captureMode?: "conversation" | "dictation";
|
||||
}
|
||||
|
||||
export type AudioCaptureStartFailure =
|
||||
| "permissionDenied"
|
||||
| "insecureContext"
|
||||
| "unsupported"
|
||||
| "noMicrophone"
|
||||
| "startFailed";
|
||||
|
||||
export class AudioCaptureStartError extends Error {
|
||||
constructor(
|
||||
readonly reason: AudioCaptureStartFailure,
|
||||
message: string,
|
||||
options?: ErrorOptions,
|
||||
) {
|
||||
super(message, options);
|
||||
this.name = "AudioCaptureStartError";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,60 +1,239 @@
|
||||
import type { AudioEngine, AudioEngineCallbacks, AudioEngineOptions } from "./audio-engine-types";
|
||||
import type {
|
||||
AudioEngine,
|
||||
AudioEngineCallbacks,
|
||||
AudioEngineOptions,
|
||||
AudioPlaybackSource,
|
||||
} from "./audio-engine-types";
|
||||
|
||||
import { createAudioPlayer, setAudioModeAsync } from "expo-audio";
|
||||
import { File, Paths } from "expo-file-system";
|
||||
import { createPlaybackQueue } from "./playback";
|
||||
import { playFile } from "./file-playback";
|
||||
import { createNativeAudioEngine, type NativeAudioEngineDeps } from "./native-audio-engine";
|
||||
|
||||
// AVPlayer needs a file extension to recognize local encoded audio on iOS.
|
||||
const FILE_EXTENSIONS: Record<string, string> = {
|
||||
"audio/wav": "wav",
|
||||
"audio/x-wav": "wav",
|
||||
"audio/wave": "wav",
|
||||
"audio/mpeg": "mp3",
|
||||
"audio/mp3": "mp3",
|
||||
"audio/mp4": "m4a",
|
||||
"audio/aac": "aac",
|
||||
"audio/ogg": "ogg",
|
||||
"audio/flac": "flac",
|
||||
};
|
||||
|
||||
let nextFileId = 0;
|
||||
|
||||
async function playEncodedAudio(
|
||||
bytes: Uint8Array,
|
||||
mimeType: string,
|
||||
signal: AbortSignal,
|
||||
context: { isCaptureActive(): boolean },
|
||||
): Promise<number> {
|
||||
// Capture owns its audio session while active. File playback alone must not
|
||||
// initialize the microphone or the native two-way engine.
|
||||
if (!context.isCaptureActive()) {
|
||||
await setAudioModeAsync({
|
||||
playsInSilentMode: true,
|
||||
allowsRecording: false,
|
||||
interruptionMode: "duckOthers",
|
||||
interruptionModeAndroid: "duckOthers",
|
||||
});
|
||||
}
|
||||
if (signal.aborted) throw new Error("Playback stopped");
|
||||
const extension = FILE_EXTENSIONS[mimeType.split(";")[0].trim()] ?? "audio";
|
||||
const file = new File(Paths.cache, `paseo-audio-${Date.now()}-${nextFileId++}.${extension}`);
|
||||
try {
|
||||
file.write(bytes);
|
||||
const player = createAudioPlayer(file.uri, {
|
||||
updateInterval: 100,
|
||||
keepAudioSessionActive: context.isCaptureActive(),
|
||||
});
|
||||
return await playFile(player, signal);
|
||||
} finally {
|
||||
if (file.exists) file.delete();
|
||||
}
|
||||
}
|
||||
import { playPcm16 } from "./pcm";
|
||||
|
||||
export function createAudioEngine(
|
||||
callbacks: AudioEngineCallbacks,
|
||||
options?: AudioEngineOptions,
|
||||
): AudioEngine {
|
||||
const native: NativeAudioEngineDeps["native"] = require("@getpaseo/expo-two-way-audio");
|
||||
return createNativeAudioEngine({ native, playEncodedAudio }, callbacks, options);
|
||||
const native = require("@getpaseo/expo-two-way-audio");
|
||||
|
||||
const refs: {
|
||||
initialized: boolean;
|
||||
captureActive: boolean;
|
||||
muted: boolean;
|
||||
destroyed: boolean;
|
||||
} = {
|
||||
initialized: false,
|
||||
captureActive: false,
|
||||
muted: false,
|
||||
destroyed: false,
|
||||
};
|
||||
|
||||
const microphoneSubscription = native.addExpoTwoWayAudioEventListener(
|
||||
"onMicrophoneData",
|
||||
(event: { data: Uint8Array }) => {
|
||||
if (!refs.captureActive || refs.muted) {
|
||||
return;
|
||||
}
|
||||
const pcm = event.data;
|
||||
callbacks.onCaptureData(pcm);
|
||||
},
|
||||
);
|
||||
const volumeSubscription = native.addExpoTwoWayAudioEventListener(
|
||||
"onInputVolumeLevelData",
|
||||
(event: { data: number }) => {
|
||||
if (!refs.captureActive) {
|
||||
return;
|
||||
}
|
||||
const level = refs.muted ? 0 : event.data;
|
||||
callbacks.onVolumeLevel(level);
|
||||
},
|
||||
);
|
||||
const interruptionSubscription = native.addExpoTwoWayAudioEventListener(
|
||||
"onAudioInterruption",
|
||||
(event: { data: string }) => {
|
||||
if (event.data === "capture_paused" || event.data === "capture_resumed") {
|
||||
if (refs.captureActive) {
|
||||
callbacks.onCaptureAvailabilityChange?.(event.data === "capture_resumed");
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (event.data !== "blocked") {
|
||||
return;
|
||||
}
|
||||
const wasCaptureActive = refs.captureActive;
|
||||
refs.captureActive = false;
|
||||
refs.muted = false;
|
||||
callbacks.onVolumeLevel(0);
|
||||
if (wasCaptureActive) {
|
||||
callbacks.onInterruption?.();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
async function ensureInitialized(): Promise<void> {
|
||||
if (refs.initialized) {
|
||||
return;
|
||||
}
|
||||
const success = await native.initialize();
|
||||
if (!success) {
|
||||
throw new Error("expo-two-way-audio: native initialize() returned false");
|
||||
}
|
||||
refs.initialized = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Release the OS audio session as soon as we are neither capturing nor playing.
|
||||
* Holding it keeps the user's background music paused — on iOS the non-mixing
|
||||
* `.playAndRecord` category survives backgrounding and is re-asserted on every
|
||||
* foreground, so an unreleased session means their music never comes back.
|
||||
*/
|
||||
function releaseSessionIfIdle(): void {
|
||||
if (!refs.initialized || refs.destroyed) {
|
||||
return;
|
||||
}
|
||||
if (refs.captureActive || playback.isPlaying()) {
|
||||
return;
|
||||
}
|
||||
// The wrapper no-ops on binaries whose native module predates this function.
|
||||
native.releaseAudioSession();
|
||||
}
|
||||
|
||||
async function ensureMicrophonePermission(): Promise<void> {
|
||||
let permission = await native.getMicrophonePermissionsAsync().catch(() => null);
|
||||
if (!permission?.granted) {
|
||||
permission = await native.requestMicrophonePermissionsAsync().catch(() => null);
|
||||
}
|
||||
if (!permission?.granted) {
|
||||
throw new Error(
|
||||
"Microphone permission is required to capture audio. Please enable microphone access in system settings.",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
let nextFileId = 0;
|
||||
async function playAudio(audio: AudioPlaybackSource, signal: AbortSignal): Promise<number> {
|
||||
const bytes = new Uint8Array(await audio.arrayBuffer());
|
||||
if (signal.aborted) throw new Error("Playback stopped");
|
||||
if (audio.type.startsWith("audio/pcm")) {
|
||||
await ensureInitialized();
|
||||
return playPcm16(bytes, audio.type, signal, native);
|
||||
}
|
||||
// Capture owns its audio session while active. File playback alone must not
|
||||
// initialize the microphone or the native two-way engine.
|
||||
if (!refs.captureActive) {
|
||||
await setAudioModeAsync({
|
||||
playsInSilentMode: true,
|
||||
allowsRecording: false,
|
||||
interruptionMode: "duckOthers",
|
||||
interruptionModeAndroid: "duckOthers",
|
||||
});
|
||||
}
|
||||
if (signal.aborted) throw new Error("Playback stopped");
|
||||
// AVPlayer needs a file extension to recognize local encoded audio on iOS.
|
||||
const extension =
|
||||
{
|
||||
"audio/wav": "wav",
|
||||
"audio/x-wav": "wav",
|
||||
"audio/wave": "wav",
|
||||
"audio/mpeg": "mp3",
|
||||
"audio/mp3": "mp3",
|
||||
"audio/mp4": "m4a",
|
||||
"audio/aac": "aac",
|
||||
"audio/ogg": "ogg",
|
||||
"audio/flac": "flac",
|
||||
}[audio.type.split(";")[0].trim()] ?? "audio";
|
||||
const file = new File(Paths.cache, `paseo-audio-${Date.now()}-${nextFileId++}.${extension}`);
|
||||
try {
|
||||
file.write(bytes);
|
||||
const player = createAudioPlayer(file.uri, {
|
||||
updateInterval: 100,
|
||||
keepAudioSessionActive: refs.captureActive,
|
||||
});
|
||||
return await playFile(player, signal);
|
||||
} finally {
|
||||
if (file.exists) file.delete();
|
||||
}
|
||||
}
|
||||
const playback = createPlaybackQueue(playAudio, releaseSessionIfIdle);
|
||||
|
||||
return {
|
||||
async initialize() {
|
||||
await ensureInitialized();
|
||||
},
|
||||
|
||||
async destroy() {
|
||||
if (refs.destroyed) {
|
||||
return;
|
||||
}
|
||||
refs.destroyed = true;
|
||||
playback.destroy();
|
||||
if (refs.captureActive) {
|
||||
native.toggleRecording(false);
|
||||
refs.captureActive = false;
|
||||
}
|
||||
refs.muted = false;
|
||||
callbacks.onVolumeLevel(0);
|
||||
if (refs.initialized) {
|
||||
native.tearDown();
|
||||
refs.initialized = false;
|
||||
}
|
||||
microphoneSubscription.remove();
|
||||
volumeSubscription.remove();
|
||||
interruptionSubscription.remove();
|
||||
},
|
||||
|
||||
async startCapture() {
|
||||
if (refs.captureActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await ensureMicrophonePermission();
|
||||
await ensureInitialized();
|
||||
const isRecording =
|
||||
options?.captureMode === "dictation"
|
||||
? native.startDictation()
|
||||
: native.toggleRecording(true);
|
||||
if (!isRecording) {
|
||||
throw new Error(
|
||||
"Microphone capture could not start because Android audio focus is unavailable.",
|
||||
);
|
||||
}
|
||||
refs.captureActive = true;
|
||||
} catch (error) {
|
||||
const wrapped = error instanceof Error ? error : new Error(String(error));
|
||||
callbacks.onError?.(wrapped);
|
||||
throw wrapped;
|
||||
}
|
||||
},
|
||||
|
||||
async stopCapture() {
|
||||
if (refs.captureActive) {
|
||||
native.toggleRecording(false);
|
||||
}
|
||||
refs.captureActive = false;
|
||||
refs.muted = false;
|
||||
callbacks.onVolumeLevel(0);
|
||||
callbacks.onCaptureAvailabilityChange?.(true);
|
||||
releaseSessionIfIdle();
|
||||
},
|
||||
|
||||
toggleMute() {
|
||||
refs.muted = !refs.muted;
|
||||
if (refs.muted) {
|
||||
callbacks.onVolumeLevel(0);
|
||||
}
|
||||
return refs.muted;
|
||||
},
|
||||
|
||||
isMuted() {
|
||||
return refs.muted;
|
||||
},
|
||||
|
||||
play: playback.play,
|
||||
stop: playback.stop,
|
||||
clearQueue: playback.clearQueue,
|
||||
isPlaying: playback.isPlaying,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -292,7 +292,9 @@ export function createAudioEngine(
|
||||
refs.gain = gain;
|
||||
} catch (error) {
|
||||
await stopCapture();
|
||||
throw error;
|
||||
const wrapped = error instanceof Error ? error : new Error(String(error));
|
||||
callbacks.onError?.(wrapped);
|
||||
throw wrapped;
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
export { createAudioEngine } from "./audio-engine";
|
||||
export type { AudioEngine, AudioEngineCallbacks, AudioPlaybackSource } from "./audio-engine-types";
|
||||
export { createPlayAudio } from "./play-audio";
|
||||
export { AudioCaptureStartError, type AudioCaptureStartFailure } from "./audio-engine-types";
|
||||
|
||||
@@ -1,188 +0,0 @@
|
||||
import { expect, test } from "vitest";
|
||||
import type { AudioEngineCallbacks } from "./audio-engine-types";
|
||||
import { createNativeAudioEngine, type NativeAudioEngineDeps } from "./native-audio-engine";
|
||||
|
||||
// In-memory stand-in for `@getpaseo/expo-two-way-audio`, matching its iOS and Android modules:
|
||||
// one native engine per app, `initialize()` reuses it, `tearDown()` frees it, and
|
||||
// `toggleRecording(true)` / `startDictation()` return false while no engine exists.
|
||||
// Session handling follows iOS: recording activates the OS audio session, stopping does not
|
||||
// deactivate it, and `releaseAudioSession()` deactivates it only while nothing is recording.
|
||||
function fakeTwoWayAudio({
|
||||
captureAvailable = true,
|
||||
permissionRequestError,
|
||||
}: { captureAvailable?: boolean; permissionRequestError?: Error } = {}) {
|
||||
let engine: { recording: boolean; sessionActive: boolean } | null = null;
|
||||
const calls = { initialize: 0, tearDown: 0 };
|
||||
const native: NativeAudioEngineDeps["native"] = {
|
||||
async initialize() {
|
||||
calls.initialize += 1;
|
||||
engine ??= { recording: false, sessionActive: false };
|
||||
return true;
|
||||
},
|
||||
tearDown() {
|
||||
calls.tearDown += 1;
|
||||
engine = null;
|
||||
},
|
||||
toggleRecording(value: boolean) {
|
||||
if (!engine) return false;
|
||||
engine.recording = value;
|
||||
if (value) engine.sessionActive = true;
|
||||
return value;
|
||||
},
|
||||
startDictation() {
|
||||
if (!engine || !captureAvailable) return false;
|
||||
engine.recording = true;
|
||||
engine.sessionActive = true;
|
||||
return true;
|
||||
},
|
||||
releaseAudioSession() {
|
||||
if (engine && !engine.recording) engine.sessionActive = false;
|
||||
},
|
||||
playPCMData() {},
|
||||
resumePlayback() {},
|
||||
stopPlayback() {},
|
||||
async getMicrophonePermissionsAsync() {
|
||||
return { granted: !permissionRequestError };
|
||||
},
|
||||
async requestMicrophonePermissionsAsync() {
|
||||
if (permissionRequestError) throw permissionRequestError;
|
||||
return { granted: true };
|
||||
},
|
||||
addExpoTwoWayAudioEventListener() {
|
||||
return { remove() {} };
|
||||
},
|
||||
};
|
||||
return {
|
||||
native,
|
||||
calls,
|
||||
hasEngine: () => engine !== null,
|
||||
sessionActive: () => engine?.sessionActive ?? false,
|
||||
};
|
||||
}
|
||||
|
||||
const recordingCallbacks: AudioEngineCallbacks = {
|
||||
onCaptureData() {},
|
||||
onVolumeLevel() {},
|
||||
};
|
||||
|
||||
function deps(native: NativeAudioEngineDeps["native"]): NativeAudioEngineDeps {
|
||||
return {
|
||||
native,
|
||||
playEncodedAudio: async () => 0,
|
||||
};
|
||||
}
|
||||
|
||||
// Issue #4147: on iPhone, voice mode failed with "Android audio focus is unavailable"
|
||||
// after the dictation engine was destroyed.
|
||||
test("voice capture starts after the dictation engine is destroyed", async () => {
|
||||
const fake = fakeTwoWayAudio();
|
||||
const voiceEngine = createNativeAudioEngine(deps(fake.native), recordingCallbacks);
|
||||
await voiceEngine.initialize();
|
||||
|
||||
const dictationEngine = createNativeAudioEngine(deps(fake.native), recordingCallbacks, {
|
||||
captureMode: "dictation",
|
||||
});
|
||||
await dictationEngine.startCapture();
|
||||
await dictationEngine.stopCapture();
|
||||
await dictationEngine.destroy();
|
||||
|
||||
await expect(voiceEngine.startCapture()).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
test("destroying dictation while voice is capturing keeps the native engine", async () => {
|
||||
const fake = fakeTwoWayAudio();
|
||||
const voiceEngine = createNativeAudioEngine(deps(fake.native), recordingCallbacks);
|
||||
await voiceEngine.startCapture();
|
||||
|
||||
const dictationEngine = createNativeAudioEngine(deps(fake.native), recordingCallbacks, {
|
||||
captureMode: "dictation",
|
||||
});
|
||||
await dictationEngine.initialize();
|
||||
await dictationEngine.destroy();
|
||||
|
||||
expect(fake.hasEngine()).toBe(true);
|
||||
expect(fake.calls.tearDown).toBe(0);
|
||||
});
|
||||
|
||||
// Review on #9051: with voice holding the engine, destroying an active dictation engine must
|
||||
// still hand back the idle OS audio session so background music resumes (#2866).
|
||||
test("destroying active dictation releases the idle audio session while voice keeps the engine", async () => {
|
||||
const fake = fakeTwoWayAudio();
|
||||
const voiceEngine = createNativeAudioEngine(deps(fake.native), recordingCallbacks);
|
||||
await voiceEngine.initialize();
|
||||
|
||||
const dictationEngine = createNativeAudioEngine(deps(fake.native), recordingCallbacks, {
|
||||
captureMode: "dictation",
|
||||
});
|
||||
await dictationEngine.startCapture();
|
||||
await dictationEngine.destroy();
|
||||
|
||||
expect(fake.hasEngine()).toBe(true);
|
||||
expect(fake.sessionActive()).toBe(false);
|
||||
});
|
||||
|
||||
test("destroying dictation does not release the session while voice is recording", async () => {
|
||||
const fake = fakeTwoWayAudio();
|
||||
const voiceEngine = createNativeAudioEngine(deps(fake.native), recordingCallbacks);
|
||||
await voiceEngine.startCapture();
|
||||
|
||||
const dictationEngine = createNativeAudioEngine(deps(fake.native), recordingCallbacks, {
|
||||
captureMode: "dictation",
|
||||
});
|
||||
await dictationEngine.initialize();
|
||||
await dictationEngine.destroy();
|
||||
|
||||
expect(fake.sessionActive()).toBe(true);
|
||||
});
|
||||
|
||||
test("destroying the last engine tears the native engine down", async () => {
|
||||
const fake = fakeTwoWayAudio();
|
||||
const voiceEngine = createNativeAudioEngine(deps(fake.native), recordingCallbacks);
|
||||
const dictationEngine = createNativeAudioEngine(deps(fake.native), recordingCallbacks, {
|
||||
captureMode: "dictation",
|
||||
});
|
||||
await voiceEngine.initialize();
|
||||
await dictationEngine.initialize();
|
||||
|
||||
await dictationEngine.destroy();
|
||||
await voiceEngine.destroy();
|
||||
|
||||
expect(fake.calls.tearDown).toBe(1);
|
||||
expect(fake.hasEngine()).toBe(false);
|
||||
});
|
||||
|
||||
test("an engine destroyed while initializing does not keep the native engine", async () => {
|
||||
const fake = fakeTwoWayAudio();
|
||||
const engine = createNativeAudioEngine(deps(fake.native), recordingCallbacks);
|
||||
|
||||
const initializing = expect(engine.initialize()).rejects.toThrow("Audio engine destroyed");
|
||||
await engine.destroy();
|
||||
await initializing;
|
||||
|
||||
expect(fake.hasEngine()).toBe(false);
|
||||
});
|
||||
|
||||
test("a failed native recording start rejects with a platform-neutral error", async () => {
|
||||
const fake = fakeTwoWayAudio({ captureAvailable: false });
|
||||
const engine = createNativeAudioEngine(deps(fake.native), recordingCallbacks, {
|
||||
captureMode: "dictation",
|
||||
});
|
||||
|
||||
await expect(engine.startCapture()).rejects.toThrow(/^Microphone capture could not start\.$/);
|
||||
await engine.destroy();
|
||||
});
|
||||
|
||||
test("a failed native permission request retains the permission reason and original error", async () => {
|
||||
const permissionRequestError = new Error("The current activity is not available.");
|
||||
const fake = fakeTwoWayAudio({ permissionRequestError });
|
||||
const engine = createNativeAudioEngine(deps(fake.native), recordingCallbacks, {
|
||||
captureMode: "dictation",
|
||||
});
|
||||
|
||||
await expect(engine.startCapture()).rejects.toMatchObject({
|
||||
reason: "permissionDenied",
|
||||
cause: permissionRequestError,
|
||||
});
|
||||
expect(fake.hasEngine()).toBe(false);
|
||||
await engine.destroy();
|
||||
});
|
||||
@@ -1,292 +0,0 @@
|
||||
import type {
|
||||
AudioEngine,
|
||||
AudioEngineCallbacks,
|
||||
AudioEngineOptions,
|
||||
AudioPlaybackSource,
|
||||
} from "./audio-engine-types";
|
||||
|
||||
import { AudioCaptureStartError } from "./audio-engine-types";
|
||||
import { createNativeEngineLease, type NativeEngineLease } from "./native-engine-lease";
|
||||
import { createPlaybackQueue } from "./playback";
|
||||
import { playPcm16 } from "./pcm";
|
||||
|
||||
interface NativeSubscription {
|
||||
remove(): void;
|
||||
}
|
||||
|
||||
interface MicrophonePermission {
|
||||
granted: boolean;
|
||||
}
|
||||
|
||||
/** The surface of `@getpaseo/expo-two-way-audio` the engine drives. */
|
||||
export interface TwoWayAudioModule {
|
||||
initialize(): Promise<boolean>;
|
||||
tearDown(): void;
|
||||
toggleRecording(value: boolean): boolean;
|
||||
startDictation(): boolean;
|
||||
releaseAudioSession(): void;
|
||||
playPCMData(data: Uint8Array): void;
|
||||
getMicrophonePermissionsAsync(): Promise<MicrophonePermission>;
|
||||
requestMicrophonePermissionsAsync(): Promise<MicrophonePermission>;
|
||||
addExpoTwoWayAudioEventListener(
|
||||
event: "onMicrophoneData",
|
||||
listener: (event: { data: Uint8Array }) => void,
|
||||
): NativeSubscription;
|
||||
addExpoTwoWayAudioEventListener(
|
||||
event: "onInputVolumeLevelData",
|
||||
listener: (event: { data: number }) => void,
|
||||
): NativeSubscription;
|
||||
addExpoTwoWayAudioEventListener(
|
||||
event: "onAudioInterruption",
|
||||
listener: (event: { data: string }) => void,
|
||||
): NativeSubscription;
|
||||
}
|
||||
|
||||
export interface NativeAudioEngineDeps {
|
||||
native: TwoWayAudioModule & Parameters<typeof playPcm16>[3];
|
||||
/** Plays encoded audio (wav, mp3, ...) through the platform player. */
|
||||
playEncodedAudio(
|
||||
bytes: Uint8Array,
|
||||
mimeType: string,
|
||||
signal: AbortSignal,
|
||||
context: { isCaptureActive(): boolean },
|
||||
): Promise<number>;
|
||||
}
|
||||
|
||||
// Voice mode and dictation each create an engine, but the native module holds a single engine
|
||||
// per app. Every JS engine on the same module shares one lease, so one engine's teardown
|
||||
// cannot free the native engine another still uses (#4147).
|
||||
const leases = new WeakMap<TwoWayAudioModule, NativeEngineLease>();
|
||||
|
||||
function leaseFor(native: TwoWayAudioModule): NativeEngineLease {
|
||||
let lease = leases.get(native);
|
||||
if (!lease) {
|
||||
lease = createNativeEngineLease(native);
|
||||
leases.set(native, lease);
|
||||
}
|
||||
return lease;
|
||||
}
|
||||
|
||||
export function createNativeAudioEngine(
|
||||
deps: NativeAudioEngineDeps,
|
||||
callbacks: AudioEngineCallbacks,
|
||||
options?: AudioEngineOptions,
|
||||
): AudioEngine {
|
||||
const { native } = deps;
|
||||
const lease = leaseFor(native);
|
||||
|
||||
const refs: {
|
||||
initialized: boolean;
|
||||
captureActive: boolean;
|
||||
muted: boolean;
|
||||
destroyed: boolean;
|
||||
} = {
|
||||
initialized: false,
|
||||
captureActive: false,
|
||||
muted: false,
|
||||
destroyed: false,
|
||||
};
|
||||
|
||||
const microphoneSubscription = native.addExpoTwoWayAudioEventListener(
|
||||
"onMicrophoneData",
|
||||
(event: { data: Uint8Array }) => {
|
||||
if (!refs.captureActive || refs.muted) {
|
||||
return;
|
||||
}
|
||||
const pcm = event.data;
|
||||
callbacks.onCaptureData(pcm);
|
||||
},
|
||||
);
|
||||
const volumeSubscription = native.addExpoTwoWayAudioEventListener(
|
||||
"onInputVolumeLevelData",
|
||||
(event: { data: number }) => {
|
||||
if (!refs.captureActive) {
|
||||
return;
|
||||
}
|
||||
const level = refs.muted ? 0 : event.data;
|
||||
callbacks.onVolumeLevel(level);
|
||||
},
|
||||
);
|
||||
const interruptionSubscription = native.addExpoTwoWayAudioEventListener(
|
||||
"onAudioInterruption",
|
||||
(event: { data: string }) => {
|
||||
if (event.data === "capture_paused" || event.data === "capture_resumed") {
|
||||
if (refs.captureActive) {
|
||||
callbacks.onCaptureAvailabilityChange?.(event.data === "capture_resumed");
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (event.data !== "blocked") {
|
||||
return;
|
||||
}
|
||||
const wasCaptureActive = refs.captureActive;
|
||||
refs.captureActive = false;
|
||||
refs.muted = false;
|
||||
callbacks.onVolumeLevel(0);
|
||||
if (wasCaptureActive) {
|
||||
callbacks.onInterruption?.();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
let initializing: Promise<void> | null = null;
|
||||
async function ensureInitialized(): Promise<void> {
|
||||
if (refs.destroyed) {
|
||||
throw new Error("Audio engine destroyed");
|
||||
}
|
||||
if (refs.initialized) {
|
||||
return;
|
||||
}
|
||||
initializing ??= (async () => {
|
||||
try {
|
||||
await lease.acquire();
|
||||
if (refs.destroyed) {
|
||||
releaseNativeEngine();
|
||||
throw new Error("Audio engine destroyed");
|
||||
}
|
||||
refs.initialized = true;
|
||||
} finally {
|
||||
initializing = null;
|
||||
}
|
||||
})();
|
||||
await initializing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Release the OS audio session as soon as we are neither capturing nor playing.
|
||||
* Holding it keeps the user's background music paused — on iOS the non-mixing
|
||||
* `.playAndRecord` category survives backgrounding and is re-asserted on every
|
||||
* foreground, so an unreleased session means their music never comes back.
|
||||
*/
|
||||
function releaseSessionIfIdle(): void {
|
||||
if (!refs.initialized || refs.destroyed) {
|
||||
return;
|
||||
}
|
||||
if (refs.captureActive || playback.isPlaying()) {
|
||||
return;
|
||||
}
|
||||
// The wrapper no-ops on binaries whose native module predates this function.
|
||||
native.releaseAudioSession();
|
||||
}
|
||||
|
||||
async function ensureMicrophonePermission(): Promise<void> {
|
||||
const permission = await native.getMicrophonePermissionsAsync().catch(() => null);
|
||||
if (permission?.granted) return;
|
||||
|
||||
let cause: unknown;
|
||||
try {
|
||||
if ((await native.requestMicrophonePermissionsAsync()).granted) return;
|
||||
} catch (error) {
|
||||
cause = error;
|
||||
}
|
||||
throw new AudioCaptureStartError(
|
||||
"permissionDenied",
|
||||
"Allow microphone access in system settings and try again.",
|
||||
{ cause },
|
||||
);
|
||||
}
|
||||
|
||||
function releaseNativeEngine(): void {
|
||||
try {
|
||||
// Native keeps the session active while any wrapper is capturing or playing.
|
||||
native.releaseAudioSession();
|
||||
} finally {
|
||||
lease.release();
|
||||
}
|
||||
}
|
||||
|
||||
async function playAudio(audio: AudioPlaybackSource, signal: AbortSignal): Promise<number> {
|
||||
const bytes = new Uint8Array(await audio.arrayBuffer());
|
||||
if (signal.aborted) throw new Error("Playback stopped");
|
||||
if (audio.type.startsWith("audio/pcm")) {
|
||||
await ensureInitialized();
|
||||
if (signal.aborted) throw new Error("Playback stopped");
|
||||
return playPcm16(bytes, audio.type, signal, native);
|
||||
}
|
||||
return deps.playEncodedAudio(bytes, audio.type, signal, {
|
||||
isCaptureActive: () => refs.captureActive,
|
||||
});
|
||||
}
|
||||
const playback = createPlaybackQueue(playAudio, releaseSessionIfIdle);
|
||||
|
||||
return {
|
||||
async initialize() {
|
||||
await ensureInitialized();
|
||||
},
|
||||
|
||||
async destroy() {
|
||||
if (refs.destroyed) {
|
||||
return;
|
||||
}
|
||||
refs.destroyed = true;
|
||||
try {
|
||||
playback.destroy();
|
||||
if (refs.captureActive) {
|
||||
refs.captureActive = false;
|
||||
native.toggleRecording(false);
|
||||
}
|
||||
refs.muted = false;
|
||||
callbacks.onVolumeLevel(0);
|
||||
} finally {
|
||||
microphoneSubscription.remove();
|
||||
volumeSubscription.remove();
|
||||
interruptionSubscription.remove();
|
||||
if (refs.initialized) {
|
||||
refs.initialized = false;
|
||||
releaseNativeEngine();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
async startCapture() {
|
||||
if (refs.captureActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
await ensureMicrophonePermission();
|
||||
await ensureInitialized();
|
||||
if (refs.destroyed) {
|
||||
throw new Error("Audio engine destroyed");
|
||||
}
|
||||
if (refs.captureActive) {
|
||||
return;
|
||||
}
|
||||
const isRecording =
|
||||
options?.captureMode === "dictation"
|
||||
? native.startDictation()
|
||||
: native.toggleRecording(true);
|
||||
if (!isRecording) {
|
||||
throw new Error("Microphone capture could not start.");
|
||||
}
|
||||
refs.captureActive = true;
|
||||
},
|
||||
|
||||
async stopCapture() {
|
||||
if (refs.captureActive) {
|
||||
native.toggleRecording(false);
|
||||
}
|
||||
refs.captureActive = false;
|
||||
refs.muted = false;
|
||||
callbacks.onVolumeLevel(0);
|
||||
callbacks.onCaptureAvailabilityChange?.(true);
|
||||
releaseSessionIfIdle();
|
||||
},
|
||||
|
||||
toggleMute() {
|
||||
refs.muted = !refs.muted;
|
||||
if (refs.muted) {
|
||||
callbacks.onVolumeLevel(0);
|
||||
}
|
||||
return refs.muted;
|
||||
},
|
||||
|
||||
isMuted() {
|
||||
return refs.muted;
|
||||
},
|
||||
|
||||
play: playback.play,
|
||||
stop: playback.stop,
|
||||
clearQueue: playback.clearQueue,
|
||||
isPlaying: playback.isPlaying,
|
||||
};
|
||||
}
|
||||
@@ -1,116 +0,0 @@
|
||||
import { expect, test } from "vitest";
|
||||
import { createNativeEngineLease, type NativeAudioEngineLifecycle } from "./native-engine-lease";
|
||||
|
||||
// Mirrors the iOS and Android modules: one engine per app, `initialize()` reuses it,
|
||||
// `tearDown()` frees it, and `toggleRecording(true)` returns false once it is gone.
|
||||
function fakeNativeModule(options: { initializeResult?: boolean } = {}) {
|
||||
let engine: object | null = null;
|
||||
const calls = { initialize: 0, tearDown: 0 };
|
||||
let finishInitialize: (() => void) | null = null;
|
||||
let deferInitialize = false;
|
||||
const native: NativeAudioEngineLifecycle & {
|
||||
toggleRecording(value: boolean): boolean;
|
||||
} = {
|
||||
initialize() {
|
||||
calls.initialize += 1;
|
||||
const complete = () => {
|
||||
if (options.initializeResult === false) {
|
||||
return false;
|
||||
}
|
||||
engine ??= {};
|
||||
return true;
|
||||
};
|
||||
if (!deferInitialize) {
|
||||
return Promise.resolve(complete());
|
||||
}
|
||||
return new Promise<boolean>((resolve) => {
|
||||
finishInitialize = () => resolve(complete());
|
||||
});
|
||||
},
|
||||
tearDown() {
|
||||
calls.tearDown += 1;
|
||||
engine = null;
|
||||
},
|
||||
toggleRecording(value: boolean) {
|
||||
return engine !== null && value;
|
||||
},
|
||||
};
|
||||
return {
|
||||
native,
|
||||
calls,
|
||||
deferNextInitialize() {
|
||||
deferInitialize = true;
|
||||
},
|
||||
finishInitialize() {
|
||||
finishInitialize?.();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
test("dictation releasing the engine keeps it for voice mode", async () => {
|
||||
const fake = fakeNativeModule();
|
||||
const lease = createNativeEngineLease(fake.native);
|
||||
|
||||
await lease.acquire(); // voice mode
|
||||
await lease.acquire(); // dictation
|
||||
lease.release(); // dictation unmounts
|
||||
|
||||
expect(fake.calls.tearDown).toBe(0);
|
||||
expect(fake.native.toggleRecording(true)).toBe(true);
|
||||
});
|
||||
|
||||
test("the last release tears the native engine down and the next acquire rebuilds it", async () => {
|
||||
const fake = fakeNativeModule();
|
||||
const lease = createNativeEngineLease(fake.native);
|
||||
|
||||
await lease.acquire();
|
||||
lease.release();
|
||||
expect(fake.calls.tearDown).toBe(1);
|
||||
expect(fake.native.toggleRecording(true)).toBe(false);
|
||||
|
||||
await lease.acquire();
|
||||
expect(fake.calls.initialize).toBe(2);
|
||||
expect(fake.native.toggleRecording(true)).toBe(true);
|
||||
});
|
||||
|
||||
test("concurrent acquires share one native initialize", async () => {
|
||||
const fake = fakeNativeModule();
|
||||
fake.deferNextInitialize();
|
||||
const lease = createNativeEngineLease(fake.native);
|
||||
|
||||
const first = lease.acquire();
|
||||
const second = lease.acquire();
|
||||
fake.finishInitialize();
|
||||
await Promise.all([first, second]);
|
||||
|
||||
expect(fake.calls.initialize).toBe(1);
|
||||
lease.release();
|
||||
expect(fake.calls.tearDown).toBe(0);
|
||||
lease.release();
|
||||
expect(fake.calls.tearDown).toBe(1);
|
||||
});
|
||||
|
||||
test("a failed initialize is not counted as a holder and can be retried", async () => {
|
||||
const fake = fakeNativeModule({ initializeResult: false });
|
||||
const lease = createNativeEngineLease(fake.native);
|
||||
|
||||
await expect(lease.acquire()).rejects.toThrow("native initialize() returned false");
|
||||
lease.release();
|
||||
expect(fake.calls.tearDown).toBe(0);
|
||||
|
||||
await expect(lease.acquire()).rejects.toThrow();
|
||||
expect(fake.calls.initialize).toBe(2);
|
||||
});
|
||||
|
||||
test("a release with no holders is a no-op", async () => {
|
||||
const fake = fakeNativeModule();
|
||||
const lease = createNativeEngineLease(fake.native);
|
||||
|
||||
await lease.acquire();
|
||||
lease.release();
|
||||
lease.release();
|
||||
await lease.acquire();
|
||||
lease.release();
|
||||
|
||||
expect(fake.calls.tearDown).toBe(2);
|
||||
});
|
||||
@@ -1,57 +0,0 @@
|
||||
/**
|
||||
* The part of `@getpaseo/expo-two-way-audio` that owns the native engine's lifetime.
|
||||
* Each platform keeps a single engine per app: `initialize()` reuses it, `tearDown()` frees it.
|
||||
*/
|
||||
export interface NativeAudioEngineLifecycle {
|
||||
initialize(): Promise<boolean>;
|
||||
tearDown(): void;
|
||||
}
|
||||
|
||||
export interface NativeEngineLease {
|
||||
/** Ensure the native engine exists and count the caller as a holder. */
|
||||
acquire(): Promise<void>;
|
||||
/** Drop one holder; the native engine is torn down when the last holder releases. */
|
||||
release(): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Voice mode and dictation each create their own JS audio engine, but both drive the one
|
||||
* native engine. Counting holders keeps one consumer's teardown from freeing the engine
|
||||
* the other still uses (issue #4147: voice mode on iOS could not start after dictation).
|
||||
*/
|
||||
export function createNativeEngineLease(native: NativeAudioEngineLifecycle): NativeEngineLease {
|
||||
let holders = 0;
|
||||
let ready: Promise<void> | null = null;
|
||||
|
||||
async function initialize(): Promise<void> {
|
||||
const success = await native.initialize();
|
||||
if (!success) {
|
||||
throw new Error("expo-two-way-audio: native initialize() returned false");
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
async acquire() {
|
||||
holders += 1;
|
||||
ready ??= initialize();
|
||||
try {
|
||||
await ready;
|
||||
} catch (error) {
|
||||
holders -= 1;
|
||||
ready = null;
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
release() {
|
||||
if (holders === 0) {
|
||||
return;
|
||||
}
|
||||
holders -= 1;
|
||||
if (holders === 0) {
|
||||
ready = null;
|
||||
native.tearDown();
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import { useTranslation } from "react-i18next";
|
||||
import {
|
||||
CalendarClock,
|
||||
CircleDashed,
|
||||
Copy,
|
||||
Folder,
|
||||
FolderPlus,
|
||||
History,
|
||||
@@ -18,8 +17,6 @@ import {
|
||||
} from "lucide-react-native";
|
||||
import { withUnistyles } from "react-native-unistyles";
|
||||
import { useIsCompactFormFactor } from "@/constants/layout";
|
||||
import { useToast } from "@/contexts/toast-context";
|
||||
import { getDesktopHost } from "@/desktop/host";
|
||||
import { useKeyboardShortcutOverrides } from "@/hooks/use-keyboard-shortcut-overrides";
|
||||
import { useOpenAddProject } from "@/hooks/use-open-add-project";
|
||||
import { useImportSession } from "@/hooks/use-import-session";
|
||||
@@ -30,7 +27,6 @@ import { useKeyboardShortcutsStore } from "@/stores/keyboard-shortcuts-store";
|
||||
import { usePanelStore } from "@/stores/panel-store";
|
||||
import { useSidebarViewStore } from "@/stores/sidebar-view-store";
|
||||
import { clearCommandCenterFocusRestoreElement } from "@/utils/command-center-focus-restore";
|
||||
import { copyToClipboard } from "@/utils/copy-to-clipboard";
|
||||
import {
|
||||
buildOpenProjectRoute,
|
||||
buildSchedulesRoute,
|
||||
@@ -39,7 +35,6 @@ import {
|
||||
} from "@/utils/host-routes";
|
||||
import { getShortcutOs } from "@/utils/shortcut-platform";
|
||||
import type { CommandCenterContribution, CommandCenterIconProps } from "./contributions";
|
||||
import { getCommandCenterIcon } from "./icon";
|
||||
import { useCommandCenterActions } from "./provider";
|
||||
import { buildGroupingContribution } from "./root-contributions";
|
||||
|
||||
@@ -68,7 +63,6 @@ const ThemedCircleDashed = withUnistyles(CircleDashed, (theme) => ({
|
||||
const ThemedPanelLeft = withUnistyles(PanelLeft, (theme) => ({
|
||||
color: theme.colors.foregroundMuted,
|
||||
}));
|
||||
const BrowserHostCopyIcon = getCommandCenterIcon(Copy);
|
||||
|
||||
function PlusIcon({ size }: CommandCenterIconProps) {
|
||||
return <ThemedPlus size={size} strokeWidth={2.4} />;
|
||||
@@ -117,8 +111,6 @@ function PanelLeftIcon({ size }: CommandCenterIconProps) {
|
||||
export function CommandCenterRootActions() {
|
||||
const keyboardActionDispatcher = useKeyboardActionDispatcher();
|
||||
const { t } = useTranslation();
|
||||
const toast = useToast();
|
||||
const browserHostLabel = getDesktopHost()?.browserHostLabel;
|
||||
const { overrides } = useKeyboardShortcutOverrides();
|
||||
const shortcutsAvailable = useHardwareKeyboardPresent();
|
||||
const openAddProject = useOpenAddProject();
|
||||
@@ -304,32 +296,6 @@ export function CommandCenterRootActions() {
|
||||
},
|
||||
];
|
||||
|
||||
if (browserHostLabel) {
|
||||
availableActions.push({
|
||||
id: "copy-browser-host-name",
|
||||
group: "actions",
|
||||
groupRank: 0,
|
||||
rank: 9,
|
||||
keywords: ["browser", "host", "window", browserHostLabel],
|
||||
visibility: "query",
|
||||
run: async () => {
|
||||
try {
|
||||
await copyToClipboard(browserHostLabel);
|
||||
toast.copied();
|
||||
} catch {
|
||||
toast.error(t("common.errors.unableToCopy"));
|
||||
}
|
||||
},
|
||||
presentation: {
|
||||
kind: "action",
|
||||
title: t("shell.commandCenter.copyBrowserHostName"),
|
||||
subtitle: browserHostLabel,
|
||||
sectionTitle: t("shell.commandCenter.actions"),
|
||||
icon: BrowserHostCopyIcon,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (shortcutsAvailable) {
|
||||
availableActions.push({
|
||||
id: "keyboard-shortcuts",
|
||||
@@ -366,7 +332,6 @@ export function CommandCenterRootActions() {
|
||||
|
||||
return availableActions;
|
||||
}, [
|
||||
browserHostLabel,
|
||||
groupMode,
|
||||
homeRoute,
|
||||
keyboardActionDispatcher,
|
||||
@@ -381,7 +346,6 @@ export function CommandCenterRootActions() {
|
||||
shortcutPlatform,
|
||||
shortcutsAvailable,
|
||||
t,
|
||||
toast,
|
||||
toggleAgentList,
|
||||
]);
|
||||
|
||||
|
||||
@@ -19,8 +19,6 @@ import {
|
||||
type ToolbarGlyph,
|
||||
} from "@/components/ui/control-geometry";
|
||||
|
||||
import { useKeyboardToggle, type KeyboardToggleAction } from "@/hooks/use-keyboard-toggle";
|
||||
|
||||
const EMPTY_COMBOBOX_OPTIONS: ComboboxOption[] = [];
|
||||
const ThemedLoadingSpinner = withUnistyles(LoadingSpinner);
|
||||
|
||||
@@ -49,7 +47,6 @@ interface CombinedModelSelectorProps {
|
||||
hovered: boolean;
|
||||
pressed: boolean;
|
||||
}) => React.ReactNode;
|
||||
toggleAction?: KeyboardToggleAction;
|
||||
onOpen?: () => void;
|
||||
onClose?: () => void;
|
||||
onRetryProvider?: (provider: AgentProvider) => void;
|
||||
@@ -85,7 +82,6 @@ export function CombinedModelSelector({
|
||||
onCreateProfile,
|
||||
onEditProfile,
|
||||
renderTrigger,
|
||||
toggleAction,
|
||||
onOpen,
|
||||
onClose,
|
||||
onRetryProvider,
|
||||
@@ -151,14 +147,6 @@ export function CombinedModelSelector({
|
||||
handleOpenChange(!isOpen);
|
||||
}, [handleOpenChange, isOpen]);
|
||||
|
||||
useKeyboardToggle({
|
||||
action: toggleAction,
|
||||
disabled,
|
||||
open: isOpen,
|
||||
searchFocused: browser.isSearchFocused,
|
||||
onToggle: handleTriggerPress,
|
||||
});
|
||||
|
||||
const triggerStyle = useCallback(
|
||||
({ pressed, hovered }: PressableStateCallbackType & { hovered?: boolean }) => {
|
||||
if (triggerFill) {
|
||||
|
||||
@@ -11,12 +11,8 @@ import {
|
||||
} from "@/components/attachment-pill";
|
||||
import { MarkdownRenderer } from "@/components/markdown/renderer";
|
||||
import { useRetainedPanelActive } from "@/components/retained-panel";
|
||||
import {
|
||||
isRewindableMessage,
|
||||
RewindMenu,
|
||||
useRewindAgentMutation,
|
||||
type RewindMode,
|
||||
} from "@/components/rewind";
|
||||
import { RewindMenu, type RewindMode } from "@/components/rewind/rewind-menu";
|
||||
import { useRewindAgentMutation } from "@/components/rewind/use-rewind-agent-mutation";
|
||||
import { TaskListRow } from "@/components/task-list-row";
|
||||
import { LoadingSpinner } from "@/components/ui/loading-spinner";
|
||||
import { useIsCompactFormFactor } from "@/constants/layout";
|
||||
@@ -534,7 +530,7 @@ export const UserMessage = memo(function UserMessage({
|
||||
<Text style={userMessageStylesheet.timestampText} testID="user-message-timestamp">
|
||||
{formattedTimestamp}
|
||||
</Text>
|
||||
{capabilities && isRewindableMessage(messageId, message) ? (
|
||||
{capabilities && messageId ? (
|
||||
<RewindMenu
|
||||
capabilities={capabilities}
|
||||
isPending={rewindMutation.isPending}
|
||||
|
||||
@@ -1,91 +0,0 @@
|
||||
import { useMemo } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Undo2 } from "lucide-react-native";
|
||||
import type { AgentCapabilityFlags } from "@getpaseo/protocol/agent-types";
|
||||
import type { CommandCenterContribution } from "@/command-center/contributions";
|
||||
import { getCommandCenterIcon } from "@/command-center/icon";
|
||||
import { useCommandCenterActions } from "@/command-center/provider";
|
||||
import { hasActiveMessageSubmission } from "@/composer/submission/model";
|
||||
import { useToast } from "@/contexts/toast-context";
|
||||
import type { AgentScreenReadySyncState } from "@/hooks/use-agent-screen-state-machine";
|
||||
import { selectAgentTimelineState, useSessionStore } from "@/stores/session-store";
|
||||
import { useRewindAgentMutation } from "./use-rewind-agent-mutation";
|
||||
import { isRewindableMessage, useRewindMenuItems } from "./use-rewind-capabilities";
|
||||
|
||||
export function RewindCommandCenterRegistration({
|
||||
serverId,
|
||||
agentId,
|
||||
capabilities,
|
||||
timelineSync,
|
||||
enabled,
|
||||
}: {
|
||||
serverId: string;
|
||||
agentId: string;
|
||||
capabilities: AgentCapabilityFlags | null | undefined;
|
||||
timelineSync: AgentScreenReadySyncState | null;
|
||||
enabled: boolean;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const toast = useToast();
|
||||
const canSelectLatestMessage = enabled && timelineSync?.status === "idle";
|
||||
const client = useSessionStore((state) => state.sessions[serverId]?.client);
|
||||
const message = useSessionStore((state) => {
|
||||
const session = state.sessions[serverId];
|
||||
if (
|
||||
!canSelectLatestMessage ||
|
||||
!session ||
|
||||
hasActiveMessageSubmission(session.messageSubmissions.get(agentId))
|
||||
) {
|
||||
return undefined;
|
||||
}
|
||||
const timeline = selectAgentTimelineState(session, agentId);
|
||||
if (timeline.status !== "synced" || timeline.newer === "available") {
|
||||
return undefined;
|
||||
}
|
||||
return (
|
||||
session.agentStreamHead.get(agentId)?.findLast((item) => item.kind === "user_message") ??
|
||||
timeline.items.findLast((item) => item.kind === "user_message")
|
||||
);
|
||||
});
|
||||
const { rewindAgent, isPending } = useRewindAgentMutation({
|
||||
serverId,
|
||||
agentId,
|
||||
client,
|
||||
messageId: message?.messageId,
|
||||
});
|
||||
const items = useRewindMenuItems(capabilities);
|
||||
const actions = useMemo<CommandCenterContribution[]>(() => {
|
||||
if (!message || !isRewindableMessage(message.messageId, message.text)) return [];
|
||||
return items.map((item, rank) => ({
|
||||
id: `rewind:${item.mode}`,
|
||||
group: "rewind",
|
||||
groupRank: 1.5,
|
||||
rank,
|
||||
visibility: "query",
|
||||
keywords: ["rewind last turn", ...(item.mode === "files" ? [] : ["rewind chat"])],
|
||||
presentation: {
|
||||
kind: "action",
|
||||
title: item.label,
|
||||
subtitle: t("rewind.warning"),
|
||||
icon: getCommandCenterIcon(Undo2),
|
||||
},
|
||||
run: async () => {
|
||||
const dismiss = toast.show(`${item.label}…`, { durationMs: null });
|
||||
try {
|
||||
await rewindAgent({ mode: item.mode, rewoundText: message.text });
|
||||
} catch {
|
||||
// The mutation reports the failure through the app toast.
|
||||
} finally {
|
||||
dismiss();
|
||||
}
|
||||
},
|
||||
}));
|
||||
}, [items, message, rewindAgent, t, toast]);
|
||||
|
||||
useCommandCenterActions({
|
||||
sourceId: `rewind:${serverId}:${agentId}`,
|
||||
enabled: canSelectLatestMessage && Boolean(client) && !isPending,
|
||||
actions,
|
||||
});
|
||||
return null;
|
||||
}
|
||||
@@ -8,7 +8,7 @@ interface RewindComposerRestoreContextValue {
|
||||
interface RewindComposerRestoreProviderProps {
|
||||
textSource: ComposerTextSource;
|
||||
setText: (text: string) => void;
|
||||
onRewindComplete: (restoredComposerText: boolean) => void;
|
||||
onRewindComplete: () => void;
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
@@ -37,11 +37,10 @@ export function RewindComposerRestoreProvider({
|
||||
currentText: currentText,
|
||||
rewoundText,
|
||||
});
|
||||
const restoredComposerText = nextText !== currentText;
|
||||
if (restoredComposerText) {
|
||||
if (nextText !== currentText) {
|
||||
setText(nextText);
|
||||
}
|
||||
onRewindComplete(restoredComposerText);
|
||||
onRewindComplete();
|
||||
},
|
||||
[onRewindComplete, setText, textSource],
|
||||
);
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
export { RewindCommandCenterRegistration } from "./command-center-registration";
|
||||
export { RewindComposerRestoreProvider } from "./composer-restore";
|
||||
export { RewindMenu } from "./rewind-menu";
|
||||
export { useRewindAgentMutation } from "./use-rewind-agent-mutation";
|
||||
export { isRewindableMessage, type RewindMode } from "./use-rewind-capabilities";
|
||||
@@ -11,9 +11,11 @@ import {
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
|
||||
import { type RewindMode, useRewindMenuItems } from "./use-rewind-capabilities";
|
||||
import { type RewindMode, useRewindCapabilities } from "./use-rewind-capabilities";
|
||||
import type { AgentCapabilityFlags } from "@getpaseo/protocol/agent-types";
|
||||
|
||||
export type { RewindMode };
|
||||
|
||||
interface RewindMenuProps {
|
||||
capabilities: AgentCapabilityFlags;
|
||||
rewoundText: string;
|
||||
@@ -42,7 +44,15 @@ export const RewindMenu = memo(function RewindMenu({
|
||||
}: RewindMenuProps) {
|
||||
const { theme } = useUnistyles();
|
||||
const { t } = useTranslation();
|
||||
const items = useRewindMenuItems(capabilities);
|
||||
const rewindLabels = useMemo(
|
||||
() => ({
|
||||
conversation: t("rewind.actions.conversation"),
|
||||
files: t("rewind.actions.files"),
|
||||
both: t("rewind.actions.both"),
|
||||
}),
|
||||
[t],
|
||||
);
|
||||
const items = useRewindCapabilities(capabilities, rewindLabels);
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const [pendingMode, setPendingMode] = useState<RewindMode | null>(null);
|
||||
const isLocked = isPendingProp || pendingMode !== null;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { planTimelineTailFetch } from "@/timeline/timeline-sync-plan";
|
||||
import { useCallback, useMemo } from "react";
|
||||
import { useCallback } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useIsMutating, useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
import { useToast } from "@/contexts/toast-context";
|
||||
import type { DaemonClient } from "@getpaseo/client/internal/daemon-client";
|
||||
import type { RewindMode } from "./use-rewind-capabilities";
|
||||
@@ -29,14 +29,7 @@ export function useRewindAgentMutation(input: UseRewindAgentMutationInput): {
|
||||
const toast = useToast();
|
||||
const { t } = useTranslation();
|
||||
const composerRestore = useRewindComposerRestore();
|
||||
const queryClient = useQueryClient();
|
||||
const mutationKey = useMemo(
|
||||
() => ["agent-rewind", input.serverId, input.agentId],
|
||||
[input.serverId, input.agentId],
|
||||
);
|
||||
const isPending = useIsMutating({ mutationKey, exact: true }) > 0;
|
||||
const { mutateAsync } = useMutation({
|
||||
mutationKey,
|
||||
const { isPending, mutateAsync } = useMutation({
|
||||
mutationFn: async ({ mode }: RewindAgentInput) => {
|
||||
if (!input.client || !input.agentId || !input.messageId) {
|
||||
throw new Error(t("common.errors.daemonClientUnavailable"));
|
||||
@@ -68,12 +61,12 @@ export function useRewindAgentMutation(input: UseRewindAgentMutationInput): {
|
||||
|
||||
const rewindAgent = useCallback(
|
||||
async (rewindInput: RewindAgentInput) => {
|
||||
if (queryClient.isMutating({ mutationKey, exact: true }) > 0) {
|
||||
if (isPending) {
|
||||
return;
|
||||
}
|
||||
await mutateAsync(rewindInput);
|
||||
},
|
||||
[mutateAsync, mutationKey, queryClient],
|
||||
[isPending, mutateAsync],
|
||||
);
|
||||
|
||||
return {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { useMemo } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type { AgentCapabilityFlags } from "@getpaseo/protocol/agent-types";
|
||||
|
||||
export type RewindMode = "conversation" | "files" | "both";
|
||||
@@ -22,10 +21,6 @@ const DEFAULT_REWIND_MENU_LABELS: RewindMenuLabels = {
|
||||
both: "Rewind conversation and files",
|
||||
};
|
||||
|
||||
export function isRewindableMessage(messageId: string | undefined, text: string): boolean {
|
||||
return Boolean(messageId) && text.trim().length > 0;
|
||||
}
|
||||
|
||||
export function resolveRewindMenuItems(
|
||||
capabilities:
|
||||
| Pick<
|
||||
@@ -65,17 +60,9 @@ export function resolveRewindMenuItems(
|
||||
return items;
|
||||
}
|
||||
|
||||
export function useRewindMenuItems(
|
||||
export function useRewindCapabilities(
|
||||
capabilities: Parameters<typeof resolveRewindMenuItems>[0],
|
||||
labels?: Partial<RewindMenuLabels>,
|
||||
): RewindMenuItem[] {
|
||||
const { t } = useTranslation();
|
||||
return useMemo(
|
||||
() =>
|
||||
resolveRewindMenuItems(capabilities, {
|
||||
conversation: t("rewind.actions.conversation"),
|
||||
files: t("rewind.actions.files"),
|
||||
both: t("rewind.actions.both"),
|
||||
}),
|
||||
[capabilities, t],
|
||||
);
|
||||
return useMemo(() => resolveRewindMenuItems(capabilities, labels), [capabilities, labels]);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { useWorkspaceRowPress } from "../../modules/paseo-press-feedback";
|
||||
import { PressHighlight as Pressable } from "@/components/ui/press-highlight";
|
||||
import { LoadingSpinner } from "@/components/ui/loading-spinner";
|
||||
import {
|
||||
@@ -1092,11 +1091,13 @@ function WorkspaceRowInner({
|
||||
...dragAttributes
|
||||
} = dragHandleProps?.attributes ?? {};
|
||||
|
||||
const { onPress: handlePress, feedback } = useWorkspaceRowPress({
|
||||
didLongPressRef: interaction.didLongPressRef,
|
||||
onPress,
|
||||
selected,
|
||||
});
|
||||
const handlePress = useCallback(() => {
|
||||
if (interaction.didLongPressRef.current) {
|
||||
interaction.didLongPressRef.current = false;
|
||||
return;
|
||||
}
|
||||
onPress();
|
||||
}, [interaction.didLongPressRef, onPress]);
|
||||
|
||||
const accessibilityState = useMemo(() => ({ selected }), [selected]);
|
||||
const isEditingTitle = titleEditor !== null;
|
||||
@@ -1191,7 +1192,6 @@ function WorkspaceRowInner({
|
||||
onTogglePin={onTogglePin}
|
||||
/>
|
||||
</SidebarWorkspaceRowContent>
|
||||
{feedback}
|
||||
</SidebarWorkspaceContextMenu>
|
||||
</View>
|
||||
);
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { useWorkspaceRowPress } from "../../../modules/paseo-press-feedback";
|
||||
import { PressHighlight as Pressable } from "@/components/ui/press-highlight";
|
||||
import {
|
||||
memo,
|
||||
@@ -849,11 +848,13 @@ function StatusWorkspaceRowInnerContent({
|
||||
const startDragPress = dragInteraction?.handlePressIn;
|
||||
const moveDragPress = dragInteraction?.handleTouchMove;
|
||||
const endDragPress = dragInteraction?.handlePressOut;
|
||||
const { onPress: handlePress, feedback } = useWorkspaceRowPress({
|
||||
didLongPressRef,
|
||||
onPress,
|
||||
selected,
|
||||
});
|
||||
const handlePress = useCallback(() => {
|
||||
if (didLongPressRef?.current) {
|
||||
didLongPressRef.current = false;
|
||||
return;
|
||||
}
|
||||
onPress();
|
||||
}, [didLongPressRef, onPress]);
|
||||
|
||||
return (
|
||||
<SidebarWorkspaceRowFrame
|
||||
@@ -966,7 +967,6 @@ function StatusWorkspaceRowInnerContent({
|
||||
/>
|
||||
) : null}
|
||||
</SidebarWorkspaceRowContent>
|
||||
{feedback}
|
||||
</SidebarWorkspaceContextMenu>
|
||||
</View>
|
||||
);
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
import React, { act } from "react";
|
||||
import { createRoot, type Root } from "react-dom/client";
|
||||
import { SafeAreaProvider } from "react-native-safe-area-context";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { ToastViewport, useToastHost, type ToastApi } from "@/components/toast-host";
|
||||
|
||||
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });
|
||||
|
||||
let root: Root | null = null;
|
||||
let container: HTMLDivElement | null = null;
|
||||
|
||||
afterEach(() => {
|
||||
act(() => root?.unmount());
|
||||
container?.remove();
|
||||
root = null;
|
||||
container = null;
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
function mountToastHost(): ToastApi {
|
||||
let api: ToastApi | null = null;
|
||||
function Host() {
|
||||
const host = useToastHost();
|
||||
api = host.api;
|
||||
return <ToastViewport toast={host.toast} onDismiss={host.dismiss} placement="sidebar" />;
|
||||
}
|
||||
container = document.createElement("div");
|
||||
document.body.appendChild(container);
|
||||
root = createRoot(container);
|
||||
act(() =>
|
||||
root?.render(
|
||||
<SafeAreaProvider>
|
||||
<Host />
|
||||
</SafeAreaProvider>,
|
||||
),
|
||||
);
|
||||
if (!api) throw new Error("The toast host did not render");
|
||||
return api;
|
||||
}
|
||||
|
||||
function shownMessage(): string | null {
|
||||
return document.querySelector('[data-testid="app-toast-message"]')?.textContent ?? null;
|
||||
}
|
||||
|
||||
describe("ToastViewport", () => {
|
||||
it("keeps a new toast when the toast it replaced times out before the next render", () => {
|
||||
vi.useFakeTimers();
|
||||
const toast = mountToastHost();
|
||||
act(() => {
|
||||
toast.show("Installed review");
|
||||
});
|
||||
act(() => {
|
||||
vi.advanceTimersByTime(2199);
|
||||
});
|
||||
|
||||
// The new toast is in state, but React has not rendered it, so the old toast's timer is
|
||||
// still scheduled when it expires.
|
||||
act(() => {
|
||||
toast.show("Reloaded review");
|
||||
vi.advanceTimersByTime(1);
|
||||
});
|
||||
|
||||
expect(shownMessage()).toBe("Reloaded review");
|
||||
act(() => {
|
||||
vi.advanceTimersByTime(2199);
|
||||
});
|
||||
expect(shownMessage()).toBe("Reloaded review");
|
||||
});
|
||||
});
|
||||
@@ -53,12 +53,6 @@ export interface ToastState {
|
||||
/** Dismisses the toast it was returned for; a no-op once another toast replaced it. */
|
||||
export type DismissToast = () => void;
|
||||
|
||||
/**
|
||||
* Dismisses the toast with this ID, and does nothing once another toast replaced it. Without an
|
||||
* ID, it dismisses whichever toast is shown.
|
||||
*/
|
||||
export type DismissToastById = (id?: number) => void;
|
||||
|
||||
export interface ToastApi {
|
||||
show: (content: ReactNode, options?: ToastShowOptions) => DismissToast;
|
||||
copied: (label?: string) => void;
|
||||
@@ -87,7 +81,7 @@ const errorIcon = (theme: Theme) => ({ color: theme.colors.destructive });
|
||||
export function useToastHost(): {
|
||||
api: ToastApi;
|
||||
toast: ToastState | null;
|
||||
dismiss: DismissToastById;
|
||||
dismiss: () => void;
|
||||
} {
|
||||
const { t } = useTranslation();
|
||||
const [toast, setToastState] = useState<ToastState | null>(null);
|
||||
@@ -102,13 +96,6 @@ export function useToastHost(): {
|
||||
previous?.onDismiss?.();
|
||||
}, []);
|
||||
|
||||
const dismiss = useCallback<DismissToastById>(
|
||||
(id) => {
|
||||
if (id === undefined || toastRef.current?.id === id) setToast(null);
|
||||
},
|
||||
[setToast],
|
||||
);
|
||||
|
||||
const show = useCallback(
|
||||
(content: ReactNode, options?: ToastShowOptions): DismissToast => {
|
||||
const nativeMessage = typeof content === "string" ? content.trim() : null;
|
||||
@@ -140,9 +127,11 @@ export function useToastHost(): {
|
||||
testID: options?.testID,
|
||||
onDismiss: options?.onDismiss,
|
||||
});
|
||||
return () => dismiss(id);
|
||||
return () => {
|
||||
if (toastRef.current?.id === id) setToast(null);
|
||||
};
|
||||
},
|
||||
[dismiss, setToast],
|
||||
[setToast],
|
||||
);
|
||||
|
||||
const api = useMemo<ToastApi>(
|
||||
@@ -158,6 +147,10 @@ export function useToastHost(): {
|
||||
[show, t],
|
||||
);
|
||||
|
||||
const dismiss = useCallback(() => {
|
||||
setToast(null);
|
||||
}, [setToast]);
|
||||
|
||||
return { api, toast, dismiss };
|
||||
}
|
||||
|
||||
@@ -168,8 +161,7 @@ export function ToastViewport({
|
||||
onBottomCoverageChange,
|
||||
}: {
|
||||
toast: ToastState | null;
|
||||
/** Called with the ID of the toast that timed out. */
|
||||
onDismiss: (id: number) => void;
|
||||
onDismiss: () => void;
|
||||
placement?: ToastViewportPlacement;
|
||||
/** Sidebar placement: reports the distance from the region's bottom edge to the toast's top. */
|
||||
onBottomCoverageChange?: (coverage: number) => void;
|
||||
@@ -188,7 +180,7 @@ export function ToastViewport({
|
||||
}, []);
|
||||
|
||||
const scheduleDismiss = useCallback(
|
||||
(id: number, durationMs: number | null) => {
|
||||
(durationMs: number | null) => {
|
||||
clearTimer();
|
||||
if (durationMs === null) {
|
||||
remainingDurationRef.current = 0;
|
||||
@@ -198,10 +190,8 @@ export function ToastViewport({
|
||||
const nextDurationMs = Math.max(0, durationMs);
|
||||
remainingDurationRef.current = nextDurationMs;
|
||||
dismissDeadlineRef.current = Date.now() + nextDurationMs;
|
||||
// A replacing toast is in the host before this viewport renders it and reschedules, so the
|
||||
// timer names its own toast rather than dismissing whichever one is current.
|
||||
timeoutRef.current = setTimeout(() => {
|
||||
onDismiss(id);
|
||||
onDismiss();
|
||||
}, nextDurationMs);
|
||||
},
|
||||
[onDismiss, clearTimer],
|
||||
@@ -219,14 +209,13 @@ export function ToastViewport({
|
||||
if (!toast || toast.durationMs === null) {
|
||||
return;
|
||||
}
|
||||
scheduleDismiss(toast.id, remainingDurationRef.current || toast.durationMs);
|
||||
scheduleDismiss(remainingDurationRef.current || toast.durationMs);
|
||||
}, [scheduleDismiss, toast]);
|
||||
|
||||
const toastId = toast?.id;
|
||||
const durationMs = toast?.durationMs ?? null;
|
||||
useEffect(() => {
|
||||
if (toastId === undefined) return;
|
||||
scheduleDismiss(toastId, durationMs);
|
||||
scheduleDismiss(durationMs);
|
||||
return clearTimer;
|
||||
}, [clearTimer, durationMs, scheduleDismiss, toastId]);
|
||||
|
||||
|
||||
@@ -3,15 +3,7 @@ import { createRoot, type Root } from "react-dom/client";
|
||||
import { Text, View } from "react-native";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { page } from "vitest/browser";
|
||||
import {
|
||||
MenuItem,
|
||||
MenuRoot,
|
||||
MenuSubTrigger,
|
||||
MenuSurface,
|
||||
MenuTrigger,
|
||||
type MenuPageDefinition,
|
||||
type Size,
|
||||
} from "./index";
|
||||
import { MenuRoot, MenuSurface, MenuTrigger, type Size } from "./index";
|
||||
|
||||
// App sources compile against the classic JSX runtime, which expects React on the global.
|
||||
beforeEach(() => vi.stubGlobal("React", React));
|
||||
@@ -130,65 +122,3 @@ describe("anchored menu surface on web", () => {
|
||||
expect(panel.width).toBeGreaterThanOrEqual(body.width);
|
||||
});
|
||||
});
|
||||
|
||||
const SUB_PAGES: MenuPageDefinition[] = [
|
||||
{
|
||||
id: "show",
|
||||
title: "Show",
|
||||
content: (
|
||||
<MenuItem testID="show-option" closeOnSelect={false}>
|
||||
Archived
|
||||
</MenuItem>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
/** Past the grace a flyout is given after the pointer leaves, so a queued close has landed. */
|
||||
const HOVER_CLOSE_SETTLED_MS = 600;
|
||||
|
||||
/**
|
||||
* A tap as the browser reports it: the finger enters the row as it lands and leaves it as it
|
||||
* lifts, and only then does the click arrive.
|
||||
*/
|
||||
function tap(target: HTMLElement): void {
|
||||
const pointer = (type: string) =>
|
||||
target.dispatchEvent(
|
||||
new PointerEvent(type, { bubbles: true, pointerType: "touch", isPrimary: true }),
|
||||
);
|
||||
act(() => {
|
||||
pointer("pointerover");
|
||||
pointer("pointerdown");
|
||||
pointer("pointerup");
|
||||
pointer("pointerout");
|
||||
target.click();
|
||||
});
|
||||
}
|
||||
|
||||
describe("submenu flyout on a touch screen", () => {
|
||||
beforeEach(async () => {
|
||||
await page.viewport(1280, 900);
|
||||
});
|
||||
|
||||
it("stays open after a tap on its row, and after a tap inside it", async () => {
|
||||
mount(
|
||||
<MenuRoot>
|
||||
<MenuTrigger testID="pill" accessibilityLabel="Open menu">
|
||||
<Text>Open menu</Text>
|
||||
</MenuTrigger>
|
||||
<MenuSurface pages={SUB_PAGES} testID="panel">
|
||||
<MenuSubTrigger id="show" testID="show-row">
|
||||
Show
|
||||
</MenuSubTrigger>
|
||||
</MenuSurface>
|
||||
</MenuRoot>,
|
||||
);
|
||||
act(() => element("pill").click());
|
||||
|
||||
tap(element("show-row"));
|
||||
await wait(HOVER_CLOSE_SETTLED_MS);
|
||||
tap(element("show-option"));
|
||||
await wait(HOVER_CLOSE_SETTLED_MS);
|
||||
|
||||
expect(document.querySelector('[data-testid="show-option"]')).not.toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -18,7 +18,6 @@ import {
|
||||
Platform,
|
||||
Pressable,
|
||||
View,
|
||||
type PointerEvent,
|
||||
type StyleProp,
|
||||
type ViewStyle,
|
||||
} from "react-native";
|
||||
@@ -218,8 +217,8 @@ export interface AnchoredSurfaceProps {
|
||||
* Hover tracking for the surface box, per docs/hover.md: plain View, pointer events, never
|
||||
* a Pressable. Web-only by nature, which is all a flyout needs.
|
||||
*/
|
||||
onPointerEnter?: (event: PointerEvent) => void;
|
||||
onPointerLeave?: (event: PointerEvent) => void;
|
||||
onPointerEnter?: () => void;
|
||||
onPointerLeave?: () => void;
|
||||
testID?: string;
|
||||
keyboardFocusScope?: KeyboardFocusScope;
|
||||
children: ReactElement;
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
import type { PointerEvent } from "react-native";
|
||||
|
||||
/**
|
||||
* Whether a pointer event came from something that can rest on a row without pressing it.
|
||||
*
|
||||
* A finger cannot, but the browser still reports one entering a row as the tap lands and leaving
|
||||
* as it lifts. Read as hover, that leave queues a close just as the tap's own press opens the
|
||||
* submenu, and the flyout vanishes a moment after it appears. A touch screen can have a mouse
|
||||
* attached too, so this has to be asked of each event, not of the device.
|
||||
*/
|
||||
export function isHoverPointer(event: PointerEvent): boolean {
|
||||
return event.nativeEvent.pointerType !== "touch";
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
type PropsWithChildren,
|
||||
type ReactElement,
|
||||
} from "react";
|
||||
import { Text, View, type PointerEvent } from "react-native";
|
||||
import { Text, View } from "react-native";
|
||||
import { StyleSheet, withUnistyles } from "react-native-unistyles";
|
||||
import { ChevronRight } from "lucide-react-native";
|
||||
import type { Theme } from "@/styles/theme";
|
||||
@@ -14,7 +14,6 @@ import { useMenuContext, useMenuDepth } from "./menu-context";
|
||||
import { isSubPageOpen } from "./menu-navigation";
|
||||
import { useMenuSurface } from "./menu-surface";
|
||||
import { MenuItem } from "./menu-item";
|
||||
import { isHoverPointer } from "./menu-pointer";
|
||||
|
||||
const ThemedChevronRight = withUnistyles(ChevronRight);
|
||||
const mutedIconMapping = (theme: Theme) => ({ color: theme.colors.foregroundMuted });
|
||||
@@ -26,8 +25,7 @@ const mutedIconMapping = (theme: Theme) => ({ color: theme.colors.foregroundMute
|
||||
*
|
||||
* Hover lives on a plain `View` wrapping the item's `Pressable`, per docs/hover.md — a
|
||||
* `Pressable` tracking its own hover would fight the one inside it. Hover only fires on web,
|
||||
* which is exactly where flyouts exist; every other platform opens the page by pressing. So does
|
||||
* a finger on the web, whose taps arrive as pointer events but are not hover.
|
||||
* which is exactly where flyouts exist; every other platform opens the page by pressing.
|
||||
*/
|
||||
export function MenuSubTrigger({
|
||||
id,
|
||||
@@ -70,22 +68,14 @@ export function MenuSubTrigger({
|
||||
menu.openSub({ id, depth });
|
||||
}, [menu, id, depth]);
|
||||
|
||||
const handlePointerEnter = useCallback(
|
||||
(event: PointerEvent) => {
|
||||
if (!isHoverPointer(event)) return;
|
||||
cancelHoverClose();
|
||||
hoverOpen({ id, depth });
|
||||
},
|
||||
[cancelHoverClose, hoverOpen, id, depth],
|
||||
);
|
||||
const handlePointerEnter = useCallback(() => {
|
||||
cancelHoverClose();
|
||||
hoverOpen({ id, depth });
|
||||
}, [cancelHoverClose, hoverOpen, id, depth]);
|
||||
|
||||
const handlePointerLeave = useCallback(
|
||||
(event: PointerEvent) => {
|
||||
if (!isHoverPointer(event)) return;
|
||||
hoverClose(depth);
|
||||
},
|
||||
[hoverClose, depth],
|
||||
);
|
||||
const handlePointerLeave = useCallback(() => {
|
||||
hoverClose(depth);
|
||||
}, [hoverClose, depth]);
|
||||
|
||||
const trailing = useMemo(
|
||||
() => <MenuSubTrailing value={value} indicator={indicator} />,
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
type ReactNode,
|
||||
} from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Pressable, Text, View, useWindowDimensions, type PointerEvent } from "react-native";
|
||||
import { Pressable, Text, View, useWindowDimensions } from "react-native";
|
||||
import { StyleSheet, withUnistyles } from "react-native-unistyles";
|
||||
import { BottomSheetScrollView } from "@gorhom/bottom-sheet";
|
||||
import { ChevronLeft } from "lucide-react-native";
|
||||
@@ -30,7 +30,6 @@ import { useMenuContext, MenuContextProvider } from "./menu-context";
|
||||
import { MenuPage } from "./menu-item";
|
||||
import { currentPageId, isSubPageOpen } from "./menu-navigation";
|
||||
import { AnchoredSurface, MenuOverlay } from "./menu-overlay";
|
||||
import { isHoverPointer } from "./menu-pointer";
|
||||
import { getMenuSheetBottomPadding } from "./menu-sheet-layout";
|
||||
import type { Alignment, Placement } from "../anchor";
|
||||
import type { KeyboardFocusScope } from "@/keyboard/actions";
|
||||
@@ -328,19 +327,7 @@ function MenuFlyout({
|
||||
const menu = useMenuContext("MenuFlyout");
|
||||
const { hoverClose, cancelHoverClose } = useMenuSurface("MenuFlyout");
|
||||
const handleClose = useCallback(() => menu.setOpen(false), [menu]);
|
||||
const handleHoverIn = useCallback(
|
||||
(event: PointerEvent) => {
|
||||
if (isHoverPointer(event)) cancelHoverClose();
|
||||
},
|
||||
[cancelHoverClose],
|
||||
);
|
||||
// A tap inside the flyout ends with the finger leaving it, which is not the pointer walking off.
|
||||
const handleHoverOut = useCallback(
|
||||
(event: PointerEvent) => {
|
||||
if (isHoverPointer(event)) hoverClose(depth);
|
||||
},
|
||||
[hoverClose, depth],
|
||||
);
|
||||
const handleHoverOut = useCallback(() => hoverClose(depth), [hoverClose, depth]);
|
||||
|
||||
if (!anchorRef) return null;
|
||||
|
||||
@@ -357,7 +344,7 @@ function MenuFlyout({
|
||||
maxHeight={maxHeight}
|
||||
scrollable={scrollable}
|
||||
backdrop={false}
|
||||
onPointerEnter={handleHoverIn}
|
||||
onPointerEnter={cancelHoverClose}
|
||||
onPointerLeave={handleHoverOut}
|
||||
testID={testID}
|
||||
>
|
||||
|
||||
@@ -21,8 +21,6 @@ import { ICON_SIZE } from "@/styles/theme";
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
|
||||
import { AgentControlTrigger } from "@/composer/agent-controls/control";
|
||||
import { useToast } from "@/contexts/toast-api-context";
|
||||
import { Shortcut } from "@/components/ui/shortcut";
|
||||
import type { ShortcutKey } from "@/utils/format-shortcut";
|
||||
import { toErrorMessage } from "@/utils/error-messages";
|
||||
|
||||
interface ComposerControlBase {
|
||||
@@ -108,7 +106,6 @@ interface ComposerControlProps {
|
||||
disabled?: boolean;
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
shortcutKeys?: ShortcutKey[][] | null;
|
||||
/** Runs after a toolbar toggle or action, so the composer can take focus back. */
|
||||
onActionComplete?: () => void;
|
||||
}
|
||||
@@ -220,7 +217,6 @@ export function ComposerControl({
|
||||
open,
|
||||
onOpenChange,
|
||||
onActionComplete,
|
||||
shortcutKeys,
|
||||
}: ComposerControlProps) {
|
||||
const { t } = useTranslation();
|
||||
const anchorRef = useRef<View>(null);
|
||||
@@ -283,7 +279,7 @@ export function ComposerControl({
|
||||
{trigger}
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="top" align="center" offset={8}>
|
||||
<ControlTooltipHint label={view.tooltip} shortcutKeys={shortcutKeys} />
|
||||
<Text style={styles.tooltipText}>{view.tooltip}</Text>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
)}
|
||||
@@ -353,7 +349,6 @@ interface ComposerControlsProps {
|
||||
items: readonly ComposerControlItem[];
|
||||
surface: ComposerControlSurface;
|
||||
disabled?: boolean;
|
||||
shortcutKeys?: ShortcutKey[][] | null;
|
||||
/** The id of the item whose list is open. */
|
||||
openId: string | null;
|
||||
onOpenIdChange: (id: string | null) => void;
|
||||
@@ -395,27 +390,7 @@ function ComposerControlSlot({
|
||||
return <ComposerControl item={item} open={open} onOpenChange={handleOpenChange} {...rest} />;
|
||||
}
|
||||
|
||||
export function ControlTooltipHint({
|
||||
label,
|
||||
shortcutKeys,
|
||||
}: {
|
||||
label: string;
|
||||
shortcutKeys?: ShortcutKey[][] | null;
|
||||
}) {
|
||||
return (
|
||||
<View style={styles.tooltipRow}>
|
||||
<Text style={styles.tooltipText}>{label}</Text>
|
||||
{shortcutKeys ? <Shortcut chord={shortcutKeys} /> : null}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create((theme) => ({
|
||||
tooltipRow: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
gap: theme.spacing[2],
|
||||
},
|
||||
fieldIcon: { color: theme.colors.foregroundMuted },
|
||||
blue: { color: theme.colors.palette.blue[400] },
|
||||
purple: { color: theme.colors.palette.purple[500] },
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useId, useMemo } from "react";
|
||||
import { useMemo } from "react";
|
||||
import type { TFunction } from "i18next";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { DensityIcon } from "@/components/ui/density-icon";
|
||||
@@ -19,12 +19,6 @@ import {
|
||||
import type { ComposerControlPresentation } from "@/composer/agent-controls/layout";
|
||||
import { getAgentControlHintKey, getFeatureHighlightColor } from "@/composer/agent-controls/utils";
|
||||
|
||||
import { useKeyboardActionHandler } from "@/hooks/use-keyboard-action-handler";
|
||||
import { useShortcutKeys } from "@/hooks/use-shortcut-keys";
|
||||
import { useComposerInput } from "@/composer/session";
|
||||
import { useComposerKeyboardScope } from "@/composer/keyboard-scope";
|
||||
import { resolveNextChoiceId } from "./mode";
|
||||
|
||||
const SEARCH_THRESHOLD = 6;
|
||||
|
||||
function getFeatureHighlight(
|
||||
@@ -83,41 +77,6 @@ interface ThinkingControl {
|
||||
displayLabel: string;
|
||||
}
|
||||
|
||||
export function useModelPickerShortcut(disabled: boolean) {
|
||||
const { isActiveComposer } = useComposerKeyboardScope();
|
||||
const input = useComposerInput();
|
||||
const action =
|
||||
isActiveComposer && !disabled && input
|
||||
? {
|
||||
id: "message-input.model-toggle" as const,
|
||||
canOpen: input.isFocused,
|
||||
}
|
||||
: undefined;
|
||||
const keys = useShortcutKeys(action ? "toggle-model-picker" : null);
|
||||
return { action, keys };
|
||||
}
|
||||
|
||||
export function useEffortCycleShortcut(thinking: ThinkingControl | null, disabled: boolean) {
|
||||
const { isActiveComposer } = useComposerKeyboardScope();
|
||||
const input = useComposerInput();
|
||||
const effortHandlerId = useId();
|
||||
const nextEffortId = resolveNextChoiceId(thinking?.options ?? [], thinking?.selectedId);
|
||||
const canCycleEffort = isActiveComposer && !disabled && nextEffortId !== null && input !== null;
|
||||
useKeyboardActionHandler({
|
||||
handlerId: effortHandlerId,
|
||||
actions: ["message-input.effort-cycle"],
|
||||
enabled: canCycleEffort,
|
||||
isActive: input?.isFocused,
|
||||
priority: 200,
|
||||
handle: () => {
|
||||
if (!thinking || nextEffortId === null) return false;
|
||||
thinking.onSelect(nextEffortId);
|
||||
return true;
|
||||
},
|
||||
});
|
||||
return useShortcutKeys(canCycleEffort ? "cycle-effort" : null);
|
||||
}
|
||||
|
||||
/** The thinking select and the option controls, as the data `ComposerControl` draws. */
|
||||
export function useAgentControlItems({
|
||||
surface,
|
||||
|
||||
@@ -3,6 +3,7 @@ import { useTranslation } from "react-i18next";
|
||||
import { router } from "expo-router";
|
||||
import {
|
||||
View,
|
||||
Text,
|
||||
Pressable,
|
||||
Keyboard,
|
||||
useWindowDimensions,
|
||||
@@ -61,7 +62,6 @@ import {
|
||||
useAgentControlCommandCenterActions,
|
||||
type AgentControlCommandCenterSource,
|
||||
} from "@/command-center/agent-control-registration";
|
||||
import { useShortcutKeys } from "@/hooks/use-shortcut-keys";
|
||||
import { useComposerKeyboardScope } from "@/composer/keyboard-scope";
|
||||
import {
|
||||
composerToolbarGeometry,
|
||||
@@ -74,14 +74,9 @@ import { ComposerControlLayoutProvider } from "@/composer/agent-controls/layout-
|
||||
import { ComposerToolbarGlyph } from "@/composer/agent-controls/glyph";
|
||||
import {
|
||||
ComposerControls,
|
||||
ControlTooltipHint,
|
||||
type ComposerControlItem,
|
||||
} from "@/composer/agent-controls/composer-control";
|
||||
import {
|
||||
useAgentControlItems,
|
||||
useEffortCycleShortcut,
|
||||
useModelPickerShortcut,
|
||||
} from "@/composer/agent-controls/control-items";
|
||||
import { useAgentControlItems } from "@/composer/agent-controls/control-items";
|
||||
import { CompactModelSheet } from "@/composer/agent-controls/model-sheet";
|
||||
import { useComposerSheetBridge } from "@/composer/agent-controls/sheet-bridge";
|
||||
import { draftComposerAgent } from "@/composer/draft/composer-agent";
|
||||
@@ -148,7 +143,6 @@ export interface DraftAgentControlsProps {
|
||||
onSelectMode: (modeId: string) => void;
|
||||
models: AgentModelDefinition[];
|
||||
selectedModel: string;
|
||||
effectiveModelId: string;
|
||||
onSelectModel: (modelId: string) => void;
|
||||
isModelLoading: boolean;
|
||||
modelSelectorProviders: ProviderSelectorProvider[];
|
||||
@@ -179,7 +173,6 @@ export interface DraftAgentControlsProps {
|
||||
}
|
||||
|
||||
interface AgentControlsProps {
|
||||
showToolbar: boolean;
|
||||
agentId: string;
|
||||
serverId: string;
|
||||
onDropdownClose?: () => void;
|
||||
@@ -195,10 +188,10 @@ function AgentControlCommandCenterRegistration({
|
||||
enabled: boolean;
|
||||
controls: AgentControlCommandCenterSource;
|
||||
}) {
|
||||
const { isCommandCenterTarget } = useComposerKeyboardScope();
|
||||
const { isActiveComposer } = useComposerKeyboardScope();
|
||||
useAgentControlCommandCenterActions({
|
||||
sourceId,
|
||||
enabled: enabled && isCommandCenterTarget,
|
||||
enabled: enabled && isActiveComposer,
|
||||
controls,
|
||||
});
|
||||
return null;
|
||||
@@ -590,7 +583,6 @@ function ControlledAgentControls({
|
||||
selectedThinkingOptionId,
|
||||
],
|
||||
);
|
||||
const effortKeys = useEffortCycleShortcut(thinking, disabled);
|
||||
const items = useAgentControlItems({
|
||||
surface: presentation.foldControls ? "sheet" : "toolbar",
|
||||
presentation,
|
||||
@@ -653,7 +645,6 @@ function ControlledAgentControls({
|
||||
provider={provider}
|
||||
selectedModelId={selectedModelId}
|
||||
thinkingItems={items.thinking}
|
||||
effortKeys={effortKeys}
|
||||
featureItems={items.features}
|
||||
onApplyAgentProfile={onApplyAgentProfile}
|
||||
onEditAgentProfiles={onEditAgentProfiles}
|
||||
@@ -686,7 +677,6 @@ function ControlledAgentControls({
|
||||
provider={provider}
|
||||
selectedModelId={selectedModelId}
|
||||
thinkingItems={items.thinking}
|
||||
effortKeys={effortKeys}
|
||||
featureItems={items.features}
|
||||
onApplyAgentProfile={onApplyAgentProfile}
|
||||
onEditAgentProfiles={onEditAgentProfiles}
|
||||
@@ -729,7 +719,6 @@ interface AgentControlsContentProps {
|
||||
provider: string;
|
||||
selectedModelId?: string;
|
||||
thinkingItems: ComposerControlItem[];
|
||||
effortKeys: ReturnType<typeof useShortcutKeys>;
|
||||
featureItems: ComposerControlItem[];
|
||||
onApplyAgentProfile?: (profileId: string) => void;
|
||||
onEditAgentProfiles?: () => void;
|
||||
@@ -769,7 +758,6 @@ function DesktopAgentControlsContent(props: DesktopAgentControlsContentProps) {
|
||||
provider,
|
||||
selectedModelId,
|
||||
thinkingItems,
|
||||
effortKeys,
|
||||
featureItems,
|
||||
onApplyAgentProfile,
|
||||
onEditAgentProfiles,
|
||||
@@ -797,7 +785,6 @@ function DesktopAgentControlsContent(props: DesktopAgentControlsContentProps) {
|
||||
handleCloseSheet,
|
||||
modelSelectorServerId,
|
||||
} = props;
|
||||
const { action: toggleAction, keys: modelKeys } = useModelPickerShortcut(disabled);
|
||||
const modelToolbar = useMemo(
|
||||
() => ({ glyph: glyphs.label, showCaret: presentation.showCarets }),
|
||||
[glyphs, presentation.showCarets],
|
||||
@@ -826,7 +813,6 @@ function DesktopAgentControlsContent(props: DesktopAgentControlsContentProps) {
|
||||
onEditProfile={onEditAgentProfile}
|
||||
isLoading={isModelLoading}
|
||||
disabled={disabled}
|
||||
toggleAction={toggleAction}
|
||||
onOpen={onModelSelectorOpen}
|
||||
onClose={onDropdownClose}
|
||||
onRetryProvider={onRetryModelProvider}
|
||||
@@ -839,17 +825,13 @@ function DesktopAgentControlsContent(props: DesktopAgentControlsContentProps) {
|
||||
</View>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="top" align="center" offset={8}>
|
||||
<ControlTooltipHint
|
||||
label={t(getAgentControlHintKey("model"))}
|
||||
shortcutKeys={modelKeys}
|
||||
/>
|
||||
<Text style={styles.tooltipText}>{t(getAgentControlHintKey("model"))}</Text>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
) : null}
|
||||
|
||||
<ComposerControls
|
||||
items={thinkingItems}
|
||||
shortcutKeys={effortKeys}
|
||||
surface="toolbar"
|
||||
disabled={disabled}
|
||||
openId={openSelector}
|
||||
@@ -920,7 +902,6 @@ function SheetAgentControlsContent(props: SheetAgentControlsContentProps) {
|
||||
provider,
|
||||
selectedModelId,
|
||||
thinkingItems,
|
||||
effortKeys,
|
||||
featureItems,
|
||||
onApplyAgentProfile,
|
||||
onEditAgentProfiles,
|
||||
@@ -975,7 +956,6 @@ function SheetAgentControlsContent(props: SheetAgentControlsContentProps) {
|
||||
selectedProvider={provider}
|
||||
selectedModel={selectedModelId ?? ""}
|
||||
thinkingLabel={displayThinking}
|
||||
effortKeys={effortKeys}
|
||||
onSelect={handleSheetModelSelect}
|
||||
profiles={agentProfiles}
|
||||
onApplyProfile={onApplyAgentProfile}
|
||||
@@ -1012,7 +992,6 @@ function useAgentOptionControls(
|
||||
}
|
||||
|
||||
export const AgentControls = memo(function AgentControls({
|
||||
showToolbar,
|
||||
agentId,
|
||||
serverId,
|
||||
onDropdownClose,
|
||||
@@ -1272,44 +1251,37 @@ export const AgentControls = memo(function AgentControls({
|
||||
return (
|
||||
<ComposerModelProvider value={composer}>
|
||||
{commandCenterRegistration}
|
||||
{showToolbar ? (
|
||||
<>
|
||||
{profileEditor.element}
|
||||
<ControlledAgentControls
|
||||
provider={agent.provider}
|
||||
modelSelectorProviders={agentModelSelectorProviders}
|
||||
modelOptions={modelOptions}
|
||||
selectedModelId={modelSelection.activeModelId ?? undefined}
|
||||
onSelectModel={handleSelectModel}
|
||||
agentProfiles={agentProfiles}
|
||||
onApplyAgentProfile={agentProfiles?.applyProfile}
|
||||
onEditAgentProfiles={handleEditAgentProfiles}
|
||||
onCreateAgentProfile={profileActions.create}
|
||||
onEditAgentProfile={profileActions.edit}
|
||||
thinkingOptions={thinkingOptions.length > 0 ? thinkingOptions : undefined}
|
||||
selectedThinkingOptionId={modelSelection.selectedThinkingId ?? undefined}
|
||||
onSelectThinkingOption={handleSelectThinkingOption}
|
||||
optionControls={agentOptionControls}
|
||||
isModelLoading={snapshotIsLoading || selectedProviderIsLoading}
|
||||
onModelSelectorOpen={handleModelSelectorOpen}
|
||||
onRetryModelProvider={handleRetryModelProvider}
|
||||
isRetryingModelProvider={snapshotIsRefreshing}
|
||||
onDropdownClose={onDropdownClose}
|
||||
disabled={!client}
|
||||
modeControl={modeControl}
|
||||
modelSelectorServerId={serverId}
|
||||
isCompactLayout={isCompactLayout}
|
||||
/>
|
||||
</>
|
||||
) : null}
|
||||
{profileEditor.element}
|
||||
<ControlledAgentControls
|
||||
provider={agent.provider}
|
||||
modelSelectorProviders={agentModelSelectorProviders}
|
||||
modelOptions={modelOptions}
|
||||
selectedModelId={modelSelection.activeModelId ?? undefined}
|
||||
onSelectModel={handleSelectModel}
|
||||
agentProfiles={agentProfiles}
|
||||
onApplyAgentProfile={agentProfiles?.applyProfile}
|
||||
onEditAgentProfiles={handleEditAgentProfiles}
|
||||
onCreateAgentProfile={profileActions.create}
|
||||
onEditAgentProfile={profileActions.edit}
|
||||
thinkingOptions={thinkingOptions.length > 0 ? thinkingOptions : undefined}
|
||||
selectedThinkingOptionId={modelSelection.selectedThinkingId ?? undefined}
|
||||
onSelectThinkingOption={handleSelectThinkingOption}
|
||||
optionControls={agentOptionControls}
|
||||
isModelLoading={snapshotIsLoading || selectedProviderIsLoading}
|
||||
onModelSelectorOpen={handleModelSelectorOpen}
|
||||
onRetryModelProvider={handleRetryModelProvider}
|
||||
isRetryingModelProvider={snapshotIsRefreshing}
|
||||
onDropdownClose={onDropdownClose}
|
||||
disabled={!client}
|
||||
modeControl={modeControl}
|
||||
modelSelectorServerId={serverId}
|
||||
isCompactLayout={isCompactLayout}
|
||||
/>
|
||||
</ComposerModelProvider>
|
||||
);
|
||||
});
|
||||
|
||||
export function DraftAgentControls({
|
||||
showToolbar,
|
||||
draftId,
|
||||
serverId,
|
||||
providerDefinitions,
|
||||
selectedProvider,
|
||||
modeOptions,
|
||||
@@ -1317,7 +1289,6 @@ export function DraftAgentControls({
|
||||
onSelectMode,
|
||||
models,
|
||||
selectedModel,
|
||||
effectiveModelId,
|
||||
onSelectModel,
|
||||
isModelLoading: _isModelLoading,
|
||||
modelSelectorProviders,
|
||||
@@ -1340,7 +1311,7 @@ export function DraftAgentControls({
|
||||
context = "draft",
|
||||
metadata,
|
||||
onSetMetadata,
|
||||
}: DraftAgentControlsProps & { draftId: string; serverId: string; showToolbar: boolean }) {
|
||||
}: DraftAgentControlsProps) {
|
||||
const mappedThinkingOptions = useMemo<AgentControlOption[]>(() => {
|
||||
return toThinkingControlOptions(thinkingOptions);
|
||||
}, [thinkingOptions]);
|
||||
@@ -1448,83 +1419,36 @@ export function DraftAgentControls({
|
||||
[composerAgent, composerInput],
|
||||
);
|
||||
|
||||
const commandCenterControls = useMemo<AgentControlCommandCenterSource>(
|
||||
() => ({
|
||||
serverId,
|
||||
ownerKey: draftId,
|
||||
provider: selectedProvider,
|
||||
providerDefinitions,
|
||||
models: {
|
||||
providers: modelSelectorProviders,
|
||||
selectedProvider,
|
||||
selectedModelId: effectiveModelId,
|
||||
select: (provider, modelId) => {
|
||||
onSelectProviderAndModel(provider, modelId);
|
||||
},
|
||||
},
|
||||
thinking: {
|
||||
options: thinkingOptions,
|
||||
selectedId: selectedThinkingOptionId,
|
||||
select: onSelectThinkingOption,
|
||||
},
|
||||
modes: toCommandCenterModes(modeControl),
|
||||
optionControls: optionControls ?? null,
|
||||
}),
|
||||
[
|
||||
serverId,
|
||||
draftId,
|
||||
selectedProvider,
|
||||
providerDefinitions,
|
||||
modelSelectorProviders,
|
||||
effectiveModelId,
|
||||
onSelectProviderAndModel,
|
||||
thinkingOptions,
|
||||
selectedThinkingOptionId,
|
||||
onSelectThinkingOption,
|
||||
modeControl,
|
||||
optionControls,
|
||||
],
|
||||
);
|
||||
|
||||
return (
|
||||
<ComposerAgentProvider value={composerAgent}>
|
||||
<ComposerModelProvider value={composerModel}>
|
||||
<AgentControlCommandCenterRegistration
|
||||
sourceId={`draft:${serverId}:${draftId}`}
|
||||
enabled={!disabled}
|
||||
controls={commandCenterControls}
|
||||
{profileEditor.element}
|
||||
<ControlledAgentControls
|
||||
provider={selectedProvider ?? ""}
|
||||
modelSelectorProviders={modelSelectorProviders}
|
||||
modelOptions={modelOptions}
|
||||
selectedModelId={selectedModel}
|
||||
onSelectModel={onSelectModel}
|
||||
onSelectProviderAndModel={onSelectProviderAndModel}
|
||||
isModelLoading={isAllModelsLoading}
|
||||
agentProfiles={agentProfiles}
|
||||
onApplyAgentProfile={agentProfiles?.applyProfile}
|
||||
onEditAgentProfiles={handleEditAgentProfiles}
|
||||
onCreateAgentProfile={profileActions.create}
|
||||
onEditAgentProfile={profileActions.edit}
|
||||
thinkingOptions={mappedThinkingOptions.length > 0 ? mappedThinkingOptions : undefined}
|
||||
selectedThinkingOptionId={effectiveSelectedThinkingOption}
|
||||
onSelectThinkingOption={onSelectThinkingOption}
|
||||
optionControls={optionControls}
|
||||
onDropdownClose={onDropdownClose}
|
||||
onModelSelectorOpen={onModelSelectorOpen}
|
||||
onRetryModelProvider={onRetryModelProvider}
|
||||
isRetryingModelProvider={isRetryingModelProvider}
|
||||
disabled={disabled}
|
||||
modeControl={modeControl}
|
||||
modelSelectorServerId={modelSelectorServerId}
|
||||
isCompactLayout={isCompactLayout}
|
||||
/>
|
||||
{showToolbar ? (
|
||||
<>
|
||||
{profileEditor.element}
|
||||
<ControlledAgentControls
|
||||
provider={selectedProvider ?? ""}
|
||||
modelSelectorProviders={modelSelectorProviders}
|
||||
modelOptions={modelOptions}
|
||||
selectedModelId={selectedModel}
|
||||
onSelectModel={onSelectModel}
|
||||
onSelectProviderAndModel={onSelectProviderAndModel}
|
||||
isModelLoading={isAllModelsLoading}
|
||||
agentProfiles={agentProfiles}
|
||||
onApplyAgentProfile={agentProfiles?.applyProfile}
|
||||
onEditAgentProfiles={handleEditAgentProfiles}
|
||||
onCreateAgentProfile={profileActions.create}
|
||||
onEditAgentProfile={profileActions.edit}
|
||||
thinkingOptions={mappedThinkingOptions.length > 0 ? mappedThinkingOptions : undefined}
|
||||
selectedThinkingOptionId={effectiveSelectedThinkingOption}
|
||||
onSelectThinkingOption={onSelectThinkingOption}
|
||||
optionControls={optionControls}
|
||||
onDropdownClose={onDropdownClose}
|
||||
onModelSelectorOpen={onModelSelectorOpen}
|
||||
onRetryModelProvider={onRetryModelProvider}
|
||||
isRetryingModelProvider={isRetryingModelProvider}
|
||||
disabled={disabled}
|
||||
modeControl={modeControl}
|
||||
modelSelectorServerId={modelSelectorServerId}
|
||||
isCompactLayout={isCompactLayout}
|
||||
/>
|
||||
</>
|
||||
) : null}
|
||||
</ComposerModelProvider>
|
||||
</ComposerAgentProvider>
|
||||
);
|
||||
@@ -1554,6 +1478,11 @@ const styles = StyleSheet.create((theme) => ({
|
||||
backgroundColor: "transparent",
|
||||
borderRadius: theme.borderRadius.full,
|
||||
},
|
||||
tooltipText: {
|
||||
color: theme.colors.foreground,
|
||||
fontSize: theme.fontSize.base,
|
||||
lineHeight: theme.fontSize.base * 1.4,
|
||||
},
|
||||
combinedSheetControls: {
|
||||
gap: theme.spacing[1],
|
||||
},
|
||||
|
||||
@@ -25,7 +25,6 @@ describe("resolveAgentControlsMode", () => {
|
||||
onSelectMode: () => undefined,
|
||||
models: [],
|
||||
selectedModel: "",
|
||||
effectiveModelId: "",
|
||||
onSelectModel: () => true,
|
||||
isModelLoading: false,
|
||||
modelSelectorProviders: [],
|
||||
|
||||
@@ -8,18 +8,12 @@ export function resolveNextAgentModeId({
|
||||
modeOptions: readonly AgentMode[];
|
||||
selectedMode: string | null | undefined;
|
||||
}): string | null {
|
||||
return resolveNextChoiceId(modeOptions, selectedMode);
|
||||
}
|
||||
if (modeOptions.length < 2) return null;
|
||||
|
||||
export function resolveNextChoiceId(
|
||||
options: readonly { id: string }[],
|
||||
selectedId: string | null | undefined,
|
||||
): string | null {
|
||||
if (options.length < 2) return null;
|
||||
|
||||
const selectedIndex = options.findIndex((option) => option.id === selectedId);
|
||||
const selectedIndex = modeOptions.findIndex((mode) => mode.id === selectedMode);
|
||||
const currentIndex = selectedIndex >= 0 ? selectedIndex : 0;
|
||||
return options[(currentIndex + 1) % options.length].id;
|
||||
const nextIndex = (currentIndex + 1) % modeOptions.length;
|
||||
return modeOptions[nextIndex]?.id ?? null;
|
||||
}
|
||||
|
||||
export function resolveAgentControlsMode(agentControls?: DraftAgentControlsProps) {
|
||||
|
||||
@@ -31,12 +31,7 @@ import {
|
||||
toolbarSlot,
|
||||
type ToolbarGlyphs,
|
||||
} from "@/components/ui/control-geometry";
|
||||
import { getAgentControlHintKey, shortModelLabel } from "./utils";
|
||||
import { useShortcutKeys } from "@/hooks/use-shortcut-keys";
|
||||
import { useKeyboardToggle } from "@/hooks/use-keyboard-toggle";
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
|
||||
import { ControlTooltipHint } from "./composer-control";
|
||||
import { useModelPickerShortcut } from "./control-items";
|
||||
import { shortModelLabel } from "./utils";
|
||||
|
||||
const SNAP_POINTS = ["80%", "90%"];
|
||||
const MODEL_LIST_TOP_INSET = 4;
|
||||
@@ -50,7 +45,6 @@ interface CompactModelSheetProps {
|
||||
selectedProvider: string;
|
||||
selectedModel: string;
|
||||
thinkingLabel: string | null;
|
||||
effortKeys: ReturnType<typeof useShortcutKeys>;
|
||||
onSelect: (provider: string, modelId: string) => void;
|
||||
isLoading: boolean;
|
||||
profiles?: AgentProfilePicker | null;
|
||||
@@ -139,7 +133,6 @@ export function CompactModelSheet({
|
||||
selectedProvider,
|
||||
selectedModel,
|
||||
thinkingLabel,
|
||||
effortKeys,
|
||||
onSelect,
|
||||
isLoading,
|
||||
profiles = null,
|
||||
@@ -323,13 +316,11 @@ export function CompactModelSheet({
|
||||
glyphs={glyphs}
|
||||
iconOnly={!showLabels && hasSelectedProvider}
|
||||
isOpen={isOpen}
|
||||
searchFocused={rootBrowser.isSearchFocused || modelBrowser.isSearchFocused}
|
||||
disabled={disabled}
|
||||
onPress={toggle}
|
||||
accessibilityLabel={t("modelSelector.selectedModel", {
|
||||
model: rootBrowser.selectedModelLabel,
|
||||
})}
|
||||
effortKeys={effortKeys}
|
||||
/>
|
||||
|
||||
<AdaptiveModalSheet
|
||||
@@ -418,21 +409,6 @@ export function CompactModelSheet({
|
||||
* The folded model control in the toolbar: the provider glyph, then the model and thinking
|
||||
* labels for as long as they fit.
|
||||
*/
|
||||
interface ModelSheetTriggerProps {
|
||||
/** The selected provider's glyph, or null before a provider is selected. */
|
||||
ModelIcon: ReturnType<typeof useProviderIcon> | null;
|
||||
modelLabel: string;
|
||||
thinkingLabel: string | null;
|
||||
glyphs: ToolbarGlyphs;
|
||||
iconOnly: boolean;
|
||||
isOpen: boolean;
|
||||
searchFocused: boolean;
|
||||
disabled: boolean;
|
||||
onPress: () => void;
|
||||
accessibilityLabel: string;
|
||||
effortKeys: ReturnType<typeof useShortcutKeys>;
|
||||
}
|
||||
|
||||
function ModelSheetTrigger({
|
||||
ModelIcon,
|
||||
modelLabel,
|
||||
@@ -440,22 +416,21 @@ function ModelSheetTrigger({
|
||||
glyphs,
|
||||
iconOnly,
|
||||
isOpen,
|
||||
searchFocused,
|
||||
disabled,
|
||||
onPress,
|
||||
accessibilityLabel,
|
||||
effortKeys,
|
||||
}: ModelSheetTriggerProps) {
|
||||
const { t } = useTranslation();
|
||||
const { action: toggleAction, keys: modelKeys } = useModelPickerShortcut(disabled);
|
||||
useKeyboardToggle({
|
||||
action: toggleAction,
|
||||
disabled,
|
||||
open: isOpen,
|
||||
searchFocused,
|
||||
onToggle: onPress,
|
||||
});
|
||||
|
||||
}: {
|
||||
/** The selected provider's glyph, or null before a provider is selected. */
|
||||
ModelIcon: ReturnType<typeof useProviderIcon> | null;
|
||||
modelLabel: string;
|
||||
thinkingLabel: string | null;
|
||||
glyphs: ToolbarGlyphs;
|
||||
iconOnly: boolean;
|
||||
isOpen: boolean;
|
||||
disabled: boolean;
|
||||
onPress: () => void;
|
||||
accessibilityLabel: string;
|
||||
}) {
|
||||
const glyphRole = iconOnly ? "icon" : "label";
|
||||
const glyph = glyphs[glyphRole];
|
||||
const triggerLabels = useModelTriggerLabels({
|
||||
@@ -476,7 +451,7 @@ function ModelSheetTrigger({
|
||||
[disabled, iconOnly, isOpen],
|
||||
);
|
||||
|
||||
const trigger = (
|
||||
return (
|
||||
<View style={styles.triggerFrame} onLayout={triggerLabels.onFrameLayout}>
|
||||
<ComboboxTrigger
|
||||
collapsable={false}
|
||||
@@ -546,23 +521,6 @@ function ModelSheetTrigger({
|
||||
) : null}
|
||||
</View>
|
||||
);
|
||||
|
||||
return (
|
||||
<Tooltip delayDuration={0} enabledOnDesktop enabledOnMobile={false}>
|
||||
<TooltipTrigger asChild triggerRefProp="ref">
|
||||
{trigger}
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="top" align="center" offset={8}>
|
||||
<ControlTooltipHint label={t(getAgentControlHintKey("model"))} shortcutKeys={modelKeys} />
|
||||
{effortKeys ? (
|
||||
<ControlTooltipHint
|
||||
label={t("settings.shortcuts.help.cycleEffort")}
|
||||
shortcutKeys={effortKeys}
|
||||
/>
|
||||
) : null}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create((theme) => ({
|
||||
|
||||
@@ -21,7 +21,6 @@ export function resolveDraftKey(input: {
|
||||
|
||||
export function buildDraftAgentControls(input: {
|
||||
formState: UseAgentFormStateResult;
|
||||
effectiveModelId: string;
|
||||
optionControls?: DraftAgentControlsProps["optionControls"];
|
||||
options: DraftAgentControlsProps["options"];
|
||||
onSetOption: DraftAgentControlsProps["onSetOption"];
|
||||
@@ -50,7 +49,6 @@ export function buildDraftAgentControls(input: {
|
||||
onSelectMode: formState.setModeFromUser,
|
||||
models: formState.availableModels,
|
||||
selectedModel: formState.selectedModel,
|
||||
effectiveModelId: input.effectiveModelId,
|
||||
onSelectModel: formState.setModelFromUser,
|
||||
isModelLoading: formState.isModelLoading,
|
||||
modelSelectorProviders: formState.modelSelectorProviders,
|
||||
|
||||
@@ -357,7 +357,6 @@ export function useAgentInputDraft(input: UseAgentInputDraftInput): AgentInputDr
|
||||
metadata,
|
||||
agentControls: buildDraftAgentControls({
|
||||
formState: draftForm,
|
||||
effectiveModelId,
|
||||
optionControls: draftOptionControls,
|
||||
options: draftShownOptions,
|
||||
onSetOption: setDraftOption,
|
||||
|
||||
@@ -21,6 +21,7 @@ import { useCreateFlowStore } from "@/stores/create-flow-store";
|
||||
import type { Agent } from "@/stores/session-store";
|
||||
import { useWorkspaceFields } from "@/stores/session-store-hooks";
|
||||
import { useWorkspaceDraftSubmissionStore } from "@/stores/workspace-draft-submission-store";
|
||||
import { useAgentControlCommandCenterActions } from "@/command-center/agent-control-registration";
|
||||
import { encodeImages } from "@/utils/encode-images";
|
||||
import { shouldAutoFocusWorkspaceDraftComposer } from "@/screens/workspace/workspace-draft-pane-focus";
|
||||
import {
|
||||
@@ -329,6 +330,16 @@ export function WorkspaceDraftComposer({
|
||||
throw new Error("Workspace draft composer state is required");
|
||||
}
|
||||
|
||||
const draftProvider = composerState.selectedProvider;
|
||||
const draftProviderDefinitions = composerState.providerDefinitions;
|
||||
const draftThinkingOptions = composerState.availableThinkingOptions;
|
||||
const draftSelectedThinkingId = composerState.selectedThinkingOptionId;
|
||||
const draftSetThinkingOption = composerState.setThinkingOptionFromUser;
|
||||
const draftModeOptions = composerState.modeOptions;
|
||||
const draftSelectedMode = composerState.selectedMode;
|
||||
const draftSetMode = composerState.setModeFromUser;
|
||||
const draftOptionControls = composerState.agentControls.optionControls;
|
||||
|
||||
const clearDraftInput = draftInput.clear;
|
||||
const replaceDraftText = draftInput.replaceText;
|
||||
const setDraftAttachments = draftInput.setAttachments;
|
||||
@@ -460,6 +471,35 @@ export function WorkspaceDraftComposer({
|
||||
onCreated(result);
|
||||
},
|
||||
});
|
||||
useAgentControlCommandCenterActions({
|
||||
sourceId: `draft:${serverId}:${tabId}`,
|
||||
enabled: isPaneFocused && !isSubmitting,
|
||||
controls: {
|
||||
serverId,
|
||||
ownerKey: tabId,
|
||||
provider: draftProvider,
|
||||
providerDefinitions: draftProviderDefinitions,
|
||||
models: {
|
||||
providers: composerState.modelSelectorProviders,
|
||||
selectedProvider: draftProvider,
|
||||
selectedModelId: composerState.effectiveModelId,
|
||||
select: (provider, modelId) => {
|
||||
composerState.setProviderAndModelFromUser(provider, modelId);
|
||||
},
|
||||
},
|
||||
thinking: {
|
||||
options: draftThinkingOptions,
|
||||
selectedId: draftSelectedThinkingId,
|
||||
select: draftSetThinkingOption,
|
||||
},
|
||||
modes: {
|
||||
options: draftModeOptions,
|
||||
selectedId: draftSelectedMode,
|
||||
select: draftSetMode,
|
||||
},
|
||||
optionControls: draftOptionControls ?? null,
|
||||
},
|
||||
});
|
||||
const isReadyForPendingAutoSubmit = Boolean(
|
||||
pendingAutoSubmit &&
|
||||
draftInput.isHydrated &&
|
||||
|
||||
@@ -45,9 +45,6 @@ export class ComposerEditingSession {
|
||||
if (this.editor === editor) this.editor = null;
|
||||
};
|
||||
}
|
||||
focus() {
|
||||
this.editor?.focus();
|
||||
}
|
||||
insertCommand(command: string) {
|
||||
const editor = this.editor;
|
||||
if (!editor) return;
|
||||
|
||||
@@ -313,22 +313,13 @@ interface RenderLeftContentArgs {
|
||||
focusInput: () => void;
|
||||
isCompactLayout: boolean;
|
||||
showAgentControls: boolean;
|
||||
showToolbar: boolean;
|
||||
}
|
||||
|
||||
function renderLeftContent(args: RenderLeftContentArgs): ReactElement | null {
|
||||
const { agentControls, agentId, serverId, focusInput, isCompactLayout, showToolbar } = args;
|
||||
const { agentControls, agentId, serverId, focusInput, isCompactLayout } = args;
|
||||
if (!args.showAgentControls) return null;
|
||||
if (resolveAgentControlsMode(agentControls) === "draft" && agentControls) {
|
||||
return (
|
||||
<DraftAgentControls
|
||||
{...agentControls}
|
||||
draftId={agentId}
|
||||
serverId={serverId}
|
||||
isCompactLayout={isCompactLayout}
|
||||
showToolbar={showToolbar}
|
||||
/>
|
||||
);
|
||||
return <DraftAgentControls {...agentControls} isCompactLayout={isCompactLayout} />;
|
||||
}
|
||||
return (
|
||||
<AgentControls
|
||||
@@ -336,7 +327,6 @@ function renderLeftContent(args: RenderLeftContentArgs): ReactElement | null {
|
||||
serverId={serverId}
|
||||
onDropdownClose={focusInput}
|
||||
isCompactLayout={isCompactLayout}
|
||||
showToolbar={showToolbar}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -1253,17 +1243,14 @@ export function Composer({ isPaneFocused, ...props }: ComposerProps) {
|
||||
// user's own pane: closing the panel does not bring focus back.
|
||||
const isCompact = useIsCompactFormFactor();
|
||||
const paneHost = usePaneHost();
|
||||
const mobilePanelTarget = usePanelStore((state) => state.mobilePanel.target);
|
||||
const coveredByOverlayPanel = isCompact && isMobilePanelCoveringHost(mobilePanelTarget, paneHost);
|
||||
// Search from the sidebar uses the center pane as its context.
|
||||
const commandCenterPanel = mobilePanelTarget === "agent-list" ? "agent" : mobilePanelTarget;
|
||||
const coveredForCommandCenter =
|
||||
isCompact && isMobilePanelCoveringHost(commandCenterPanel, paneHost);
|
||||
const overlayPanelRequested = usePanelStore((state) =>
|
||||
isMobilePanelCoveringHost(state.mobilePanel.target, paneHost),
|
||||
);
|
||||
const coveredByOverlayPanel = isCompact && overlayPanelRequested;
|
||||
return (
|
||||
<ComposerKeyboardScopeProvider
|
||||
isPaneFocused={isPaneFocused}
|
||||
isActiveComposer={isPaneFocused && !coveredByOverlayPanel}
|
||||
isCommandCenterTarget={isPaneFocused && !coveredForCommandCenter}
|
||||
>
|
||||
<OverlayDismissalScope>
|
||||
<RenderProfile id="ComposerContent">
|
||||
@@ -1527,7 +1514,6 @@ function ComposerContentImpl({
|
||||
isLive: isInputLive,
|
||||
revealed: inputRevealed,
|
||||
isRevealed: isInputRevealed,
|
||||
isFocused: () => messageInputRef.current?.isFocused() ?? false,
|
||||
focus: takeInputFocus,
|
||||
textSource,
|
||||
setText: replaceUserInput,
|
||||
@@ -2359,7 +2345,6 @@ function ComposerContentImpl({
|
||||
focusInput,
|
||||
isCompactLayout,
|
||||
showAgentControls: mode.showAgentControls,
|
||||
showToolbar: !isFullscreen,
|
||||
});
|
||||
return controls ? (
|
||||
<ComposerInputProvider value={composerInput}>{controls}</ComposerInputProvider>
|
||||
@@ -2370,7 +2355,6 @@ function ComposerContentImpl({
|
||||
composerInput,
|
||||
focusInput,
|
||||
isCompactLayout,
|
||||
isFullscreen,
|
||||
mode.showAgentControls,
|
||||
serverId,
|
||||
]);
|
||||
|
||||
@@ -1624,8 +1624,6 @@ export const MessageInput = forwardRef<MessageInputRef, MessageInputProps>(
|
||||
volume: dictationVolume,
|
||||
duration: dictationDuration,
|
||||
error: dictationError,
|
||||
startError: dictationStartError,
|
||||
clearStartError: clearDictationStartError,
|
||||
status: dictationStatus,
|
||||
startDictation,
|
||||
cancelDictation,
|
||||
@@ -1662,29 +1660,17 @@ export const MessageInput = forwardRef<MessageInputRef, MessageInputProps>(
|
||||
sendAfterTranscriptRef.current = false;
|
||||
}, [dictationStatus, isDictating, isDictationProcessing]);
|
||||
|
||||
useEffect(() => {
|
||||
if (showRealtimeOverlay) {
|
||||
clearDictationStartError();
|
||||
}
|
||||
}, [showRealtimeOverlay, clearDictationStartError]);
|
||||
|
||||
const startDictationIfAvailable = useCallback(() => {
|
||||
clearDictationStartError();
|
||||
return startDictationIfAvailableImpl({
|
||||
dictationUnavailableMessage,
|
||||
canStartDictation,
|
||||
toast,
|
||||
startDictation,
|
||||
exitFullscreen,
|
||||
});
|
||||
}, [
|
||||
canStartDictation,
|
||||
clearDictationStartError,
|
||||
dictationUnavailableMessage,
|
||||
startDictation,
|
||||
toast,
|
||||
exitFullscreen,
|
||||
]);
|
||||
const startDictationIfAvailable = useCallback(
|
||||
() =>
|
||||
startDictationIfAvailableImpl({
|
||||
dictationUnavailableMessage,
|
||||
canStartDictation,
|
||||
toast,
|
||||
startDictation,
|
||||
exitFullscreen,
|
||||
}),
|
||||
[canStartDictation, dictationUnavailableMessage, startDictation, toast, exitFullscreen],
|
||||
);
|
||||
|
||||
const handleVoicePress = useCallback(
|
||||
() =>
|
||||
@@ -2238,54 +2224,42 @@ export const MessageInput = forwardRef<MessageInputRef, MessageInputProps>(
|
||||
);
|
||||
const toolbar = useMemo(
|
||||
() => (
|
||||
<>
|
||||
{!isFullscreen && !showOverlay && dictationStartError ? (
|
||||
<Text accessibilityRole="alert" style={styles.dictationStartError}>
|
||||
{t(`message.dictation.${dictationStartError}`)}
|
||||
</Text>
|
||||
) : null}
|
||||
<View style={isFullscreen ? styles.hiddenToolbar : buttonRowStyle}>
|
||||
{/* Toolbar left: attachment button + agent controls */}
|
||||
<View style={styles.leftButtonGroup}>
|
||||
{!isFullscreen && (
|
||||
<AttachmentDropdown
|
||||
visible={mode.showAttachments}
|
||||
isConnected={isConnected}
|
||||
disabled={disabled}
|
||||
attachButtonStyle={attachButtonStyle}
|
||||
renderAttachButtonIcon={renderAttachButtonIcon}
|
||||
attachmentMenuItems={attachmentMenuItems}
|
||||
addAttachmentLabel={t("composer.input.addAttachment")}
|
||||
/>
|
||||
)}
|
||||
{leftContent}
|
||||
</View>
|
||||
|
||||
{/* Right: dictation, then the trailing action (voice mode, send or stop) */}
|
||||
{!isFullscreen && (
|
||||
<View style={styles.rightButtonGroup}>
|
||||
{beforeVoiceContent}
|
||||
<VoiceButtonTooltip
|
||||
visible={mode.showVoice}
|
||||
onVoicePress={handleVoicePress}
|
||||
isDictationStartEnabled={isDictationStartEnabled}
|
||||
voiceButtonAccessibilityLabel={voiceButtonAccessibilityLabel}
|
||||
voiceButtonStyle={voiceButtonStyle}
|
||||
renderVoiceButtonIcon={renderVoiceButtonIcon}
|
||||
voiceTooltipText={voiceTooltipText}
|
||||
isRealtimeVoiceForCurrentAgent={isRealtimeVoiceForCurrentAgent}
|
||||
voiceMuteToggleKeys={voiceMuteToggleKeys}
|
||||
dictationToggleKeys={dictationToggleKeys}
|
||||
/>
|
||||
<View style={styles.trailingDisc}>{sendButton}</View>
|
||||
</View>
|
||||
)}
|
||||
<View style={buttonRowStyle}>
|
||||
{/* Toolbar left: attachment button + agent controls */}
|
||||
<View style={styles.leftButtonGroup}>
|
||||
<AttachmentDropdown
|
||||
visible={mode.showAttachments}
|
||||
isConnected={isConnected}
|
||||
disabled={disabled}
|
||||
attachButtonStyle={attachButtonStyle}
|
||||
renderAttachButtonIcon={renderAttachButtonIcon}
|
||||
attachmentMenuItems={attachmentMenuItems}
|
||||
addAttachmentLabel={t("composer.input.addAttachment")}
|
||||
/>
|
||||
{leftContent}
|
||||
</View>
|
||||
</>
|
||||
|
||||
{/* Right: dictation, then the trailing action (voice mode, send or stop) */}
|
||||
<View style={styles.rightButtonGroup}>
|
||||
{beforeVoiceContent}
|
||||
<VoiceButtonTooltip
|
||||
visible={mode.showVoice}
|
||||
onVoicePress={handleVoicePress}
|
||||
isDictationStartEnabled={isDictationStartEnabled}
|
||||
voiceButtonAccessibilityLabel={voiceButtonAccessibilityLabel}
|
||||
voiceButtonStyle={voiceButtonStyle}
|
||||
renderVoiceButtonIcon={renderVoiceButtonIcon}
|
||||
voiceTooltipText={voiceTooltipText}
|
||||
isRealtimeVoiceForCurrentAgent={isRealtimeVoiceForCurrentAgent}
|
||||
voiceMuteToggleKeys={voiceMuteToggleKeys}
|
||||
dictationToggleKeys={dictationToggleKeys}
|
||||
/>
|
||||
<View style={styles.trailingDisc}>{sendButton}</View>
|
||||
</View>
|
||||
</View>
|
||||
),
|
||||
[
|
||||
buttonRowStyle,
|
||||
isFullscreen,
|
||||
mode.showAttachments,
|
||||
isConnected,
|
||||
disabled,
|
||||
@@ -2296,8 +2270,6 @@ export const MessageInput = forwardRef<MessageInputRef, MessageInputProps>(
|
||||
leftContent,
|
||||
beforeVoiceContent,
|
||||
mode.showVoice,
|
||||
showOverlay,
|
||||
dictationStartError,
|
||||
handleVoicePress,
|
||||
isDictationStartEnabled,
|
||||
voiceButtonAccessibilityLabel,
|
||||
@@ -2491,7 +2463,6 @@ const styles = StyleSheet.create((theme: Theme) => ({
|
||||
minHeight: MIN_INPUT_HEIGHT,
|
||||
color: theme.colors.foregroundMuted,
|
||||
},
|
||||
hiddenToolbar: { display: "none" },
|
||||
// The row keeps a full touch target's height; its disc-sized controls centre in it.
|
||||
buttonRow: {
|
||||
minHeight: TOOLBAR_CONTROL_HEIGHT,
|
||||
@@ -2500,12 +2471,6 @@ const styles = StyleSheet.create((theme: Theme) => ({
|
||||
alignItems: "center",
|
||||
justifyContent: "space-between",
|
||||
},
|
||||
dictationStartError: {
|
||||
alignSelf: "flex-end",
|
||||
textAlign: "right",
|
||||
color: theme.colors.destructive,
|
||||
fontSize: theme.fontSize.sm,
|
||||
},
|
||||
leftButtonGroup: {
|
||||
minWidth: 0,
|
||||
flexShrink: 1,
|
||||
|
||||
@@ -126,8 +126,7 @@ export function ComposerInputPresentation({
|
||||
</Button>
|
||||
) : null}
|
||||
</View>
|
||||
{/* Keep the agent controls mounted for composer commands in fullscreen. */}
|
||||
{toolbar}
|
||||
{fullscreen ? null : toolbar}
|
||||
</View>
|
||||
</ComposerFullscreenBody>
|
||||
{fullscreen ? (
|
||||
|
||||
@@ -18,25 +18,21 @@ interface ComposerKeyboardScopeValue {
|
||||
* pane, which does not take pane focus.
|
||||
*/
|
||||
isActiveComposer: boolean;
|
||||
/** The composer whose settings appear in Command Center. */
|
||||
isCommandCenterTarget: boolean;
|
||||
}
|
||||
|
||||
const ComposerKeyboardScopeContext = createContext<ComposerKeyboardScopeValue>({
|
||||
isPaneFocused: false,
|
||||
isActiveComposer: false,
|
||||
isCommandCenterTarget: false,
|
||||
});
|
||||
|
||||
export function ComposerKeyboardScopeProvider({
|
||||
isPaneFocused,
|
||||
isActiveComposer,
|
||||
isCommandCenterTarget,
|
||||
children,
|
||||
}: PropsWithChildren<ComposerKeyboardScopeValue>): ReactElement {
|
||||
const value = useMemo(
|
||||
() => ({ isPaneFocused, isActiveComposer, isCommandCenterTarget }),
|
||||
[isPaneFocused, isActiveComposer, isCommandCenterTarget],
|
||||
() => ({ isPaneFocused, isActiveComposer }),
|
||||
[isPaneFocused, isActiveComposer],
|
||||
);
|
||||
return (
|
||||
<ComposerKeyboardScopeContext.Provider value={value}>
|
||||
|
||||
@@ -25,7 +25,6 @@ export interface ComposerInput {
|
||||
*/
|
||||
revealed: boolean;
|
||||
isRevealed: () => boolean;
|
||||
isFocused: () => boolean;
|
||||
focus: (options?: ComposerFocusOptions) => Promise<void>;
|
||||
textSource: ComposerTextSource;
|
||||
setText: (text: string) => void;
|
||||
|
||||
@@ -130,6 +130,9 @@ export function VoiceProvider({ children }: VoiceProviderProps) {
|
||||
console.error("[VoiceEngine] Failed to stop after audio interruption:", error);
|
||||
});
|
||||
},
|
||||
onError: (error) => {
|
||||
console.error("[VoiceEngine] Capture error:", error);
|
||||
},
|
||||
});
|
||||
|
||||
runtime = createVoiceRuntime({
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { BROWSER_AUTOMATION_COMMAND_NAMES } from "@getpaseo/protocol/browser-automation/rpc-schemas";
|
||||
import type { DaemonClient } from "@getpaseo/client/internal/daemon-client";
|
||||
import type { SessionInboundMessage, SessionOutboundMessage } from "@getpaseo/protocol/messages";
|
||||
import { getDesktopHost, type DesktopHostBridge } from "@/desktop/host";
|
||||
import {
|
||||
@@ -27,7 +26,6 @@ type BrowserAutomationExecuteResponse = Extract<
|
||||
type BrowserAutomationResponsePayload = BrowserAutomationExecuteResponse["payload"];
|
||||
type BrowserAutomationFailurePayload = Extract<BrowserAutomationResponsePayload, { ok: false }>;
|
||||
type BrowserAutomationErrorCode = BrowserAutomationFailurePayload["error"]["code"];
|
||||
type BrowserHostRegistration = Parameters<DaemonClient["registerBrowserHost"]>[0];
|
||||
|
||||
interface BrowserAutomationClient {
|
||||
on(
|
||||
@@ -71,24 +69,14 @@ export function mountBrowserAutomationHandler(
|
||||
};
|
||||
}
|
||||
|
||||
export function getDesktopBrowserHostRegistration(): BrowserHostRegistration | null {
|
||||
const desktop = getDesktopHost();
|
||||
if (typeof desktop?.browser?.executeAutomationCommand !== "function") return null;
|
||||
|
||||
return {
|
||||
hostKind: "desktop app",
|
||||
label: desktop.browserHostLabel,
|
||||
instanceId: desktop.browserHostInstanceId,
|
||||
supportedCommands: [...BROWSER_AUTOMATION_COMMAND_NAMES],
|
||||
};
|
||||
}
|
||||
|
||||
export function mountBrowserAutomationDaemonClientHandler(
|
||||
client: DaemonClient,
|
||||
registration: BrowserHostRegistration,
|
||||
client: import("@getpaseo/client/internal/daemon-client").DaemonClient,
|
||||
options?: { serverId?: string },
|
||||
): () => void {
|
||||
const observation = client.registerBrowserHost(registration);
|
||||
const observation = client.registerBrowserHost({
|
||||
hostKind: "desktop app",
|
||||
supportedCommands: [...BROWSER_AUTOMATION_COMMAND_NAMES],
|
||||
});
|
||||
const unmount = mountBrowserAutomationHandler({
|
||||
client: {
|
||||
on: (_type, handler) =>
|
||||
|
||||
@@ -175,8 +175,6 @@ export interface DesktopInvokeBridge {
|
||||
export interface DesktopHostBridge {
|
||||
platform?: string;
|
||||
windowChromeMode?: string;
|
||||
browserHostLabel?: string;
|
||||
browserHostInstanceId?: string;
|
||||
invoke?: DesktopInvokeBridge["invoke"];
|
||||
getPendingOpenProject?: () => Promise<string | null>;
|
||||
agentNavigation?: DesktopAgentNavigationBridge;
|
||||
|
||||
@@ -11,6 +11,7 @@ import type {
|
||||
|
||||
export function useDictationAudioSource(config: DictationAudioSourceConfig): DictationAudioSource {
|
||||
const onPcmSegmentRef = useRef(config.onPcmSegment);
|
||||
const onErrorRef = useRef(config.onError);
|
||||
const onInterruptionRef = useRef(config.onInterruption);
|
||||
const [volume, setVolume] = useState(0);
|
||||
const [isPaused, setIsPaused] = useState(false);
|
||||
@@ -29,6 +30,9 @@ export function useDictationAudioSource(config: DictationAudioSourceConfig): Dic
|
||||
onVolumeLevel: (level) => {
|
||||
setVolume(level);
|
||||
},
|
||||
onError: (error) => {
|
||||
onErrorRef.current?.(error);
|
||||
},
|
||||
onInterruption: () => {
|
||||
onInterruptionRef.current?.();
|
||||
},
|
||||
@@ -41,11 +45,14 @@ export function useDictationAudioSource(config: DictationAudioSourceConfig): Dic
|
||||
|
||||
useEffect(() => {
|
||||
onPcmSegmentRef.current = config.onPcmSegment;
|
||||
onErrorRef.current = config.onError;
|
||||
onInterruptionRef.current = config.onInterruption;
|
||||
}, [config.onPcmSegment, config.onInterruption]);
|
||||
}, [config.onPcmSegment, config.onError, config.onInterruption]);
|
||||
|
||||
const start = useCallback(async () => {
|
||||
await getOrCreateEngine().startCapture();
|
||||
const engine = getOrCreateEngine();
|
||||
await engine.initialize();
|
||||
await engine.startCapture();
|
||||
}, [getOrCreateEngine]);
|
||||
|
||||
const stop = useCallback(async () => {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { AudioCaptureStartError } from "@/audio";
|
||||
import { resampleToPcm16 } from "@/audio/pcm";
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { parsePcm16Wav } from "@/utils/pcm16-wav";
|
||||
@@ -134,32 +133,6 @@ async function finalizeRecorderStoppedPromise(input: {
|
||||
}
|
||||
}
|
||||
|
||||
async function requestMicrophone(): Promise<MediaStream> {
|
||||
try {
|
||||
return await navigator.mediaDevices.getUserMedia({
|
||||
audio: {
|
||||
channelCount: 1,
|
||||
noiseSuppression: true,
|
||||
echoCancellation: true,
|
||||
autoGainControl: true,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
if (error instanceof DOMException) {
|
||||
if (error.name === "NotAllowedError") {
|
||||
throw new AudioCaptureStartError("permissionDenied", error.message, { cause: error });
|
||||
}
|
||||
if (error.name === "NotFoundError") {
|
||||
throw new AudioCaptureStartError("noMicrophone", error.message, { cause: error });
|
||||
}
|
||||
if (error.name === "NotSupportedError") {
|
||||
throw new AudioCaptureStartError("unsupported", error.message, { cause: error });
|
||||
}
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export function useDictationAudioSource(config: DictationAudioSourceConfig): DictationAudioSource {
|
||||
const [volume, setVolume] = useState(0);
|
||||
|
||||
@@ -227,19 +200,50 @@ export function useDictationAudioSource(config: DictationAudioSourceConfig): Dic
|
||||
}, []);
|
||||
|
||||
const start = useCallback(async () => {
|
||||
if (!window.isSecureContext && !isElectronRuntime()) {
|
||||
throw new AudioCaptureStartError(
|
||||
"insecureContext",
|
||||
`Microphone access requires HTTPS or localhost. Current origin: ${window.location.origin}`,
|
||||
const missingNavigator =
|
||||
typeof navigator === "undefined" ||
|
||||
!navigator.mediaDevices ||
|
||||
typeof navigator.mediaDevices.getUserMedia !== "function";
|
||||
|
||||
const secureContext =
|
||||
typeof window !== "undefined" && typeof window.isSecureContext === "boolean"
|
||||
? window.isSecureContext
|
||||
: true;
|
||||
const currentOrigin =
|
||||
typeof window !== "undefined" && window.location ? window.location.origin : "unknown";
|
||||
const isDesktopApp = isElectronRuntime();
|
||||
|
||||
if (missingNavigator) {
|
||||
throw new Error("Microphone capture is not supported in this environment");
|
||||
}
|
||||
if (!secureContext && !isDesktopApp) {
|
||||
throw new Error(
|
||||
`Microphone access requires HTTPS or localhost. Current origin: ${currentOrigin}`,
|
||||
);
|
||||
}
|
||||
if (!secureContext && isDesktopApp) {
|
||||
console.warn(
|
||||
"[DictationAudio][Web] Insecure context reported under Desktop; attempting getUserMedia anyway",
|
||||
{ currentOrigin },
|
||||
);
|
||||
}
|
||||
|
||||
const AudioContextCtor = getAudioContextCtor();
|
||||
if (!navigator.mediaDevices?.getUserMedia || !AudioContextCtor) {
|
||||
throw new AudioCaptureStartError("unsupported", "Browser audio capture is unavailable.");
|
||||
if (!AudioContextCtor) {
|
||||
throw new Error("AudioContext unavailable");
|
||||
}
|
||||
|
||||
const stream = await requestMicrophone();
|
||||
const rawStream = await navigator.mediaDevices.getUserMedia({
|
||||
audio: {
|
||||
channelCount: 1,
|
||||
noiseSuppression: true,
|
||||
echoCancellation: true,
|
||||
autoGainControl: true,
|
||||
},
|
||||
});
|
||||
|
||||
const stream = rawStream;
|
||||
|
||||
const context = new AudioContextCtor();
|
||||
|
||||
try {
|
||||
@@ -427,7 +431,15 @@ export function useDictationAudioSource(config: DictationAudioSourceConfig): Dic
|
||||
|
||||
return useMemo(
|
||||
() => ({
|
||||
start,
|
||||
start: async () => {
|
||||
try {
|
||||
await start();
|
||||
} catch (err) {
|
||||
const normalized = err instanceof Error ? err : new Error(String(err));
|
||||
onErrorRef.current?.(normalized);
|
||||
throw normalized;
|
||||
}
|
||||
},
|
||||
stop,
|
||||
volume,
|
||||
isPaused: false,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import type { AudioCaptureStartFailure } from "@/audio";
|
||||
import { i18n } from "@/i18n/i18next";
|
||||
|
||||
export type DictationStatus = "idle" | "recording" | "paused" | "uploading" | "failed";
|
||||
@@ -22,8 +21,6 @@ export interface UseDictationResult {
|
||||
volume: number;
|
||||
duration: number;
|
||||
error: string | null;
|
||||
startError: AudioCaptureStartFailure | null;
|
||||
clearStartError: () => void;
|
||||
status: DictationStatus;
|
||||
startDictation: () => Promise<void>;
|
||||
cancelDictation: () => Promise<void>;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { AudioCaptureStartError, type AudioCaptureStartFailure } from "@/audio";
|
||||
import { DictationStreamSender } from "@/dictation/dictation-stream-sender";
|
||||
import { useDictationAudioSource } from "@/hooks/use-dictation-audio-source";
|
||||
import { generateMessageId } from "@/types/stream";
|
||||
@@ -33,8 +32,6 @@ export function useDictation(options: UseDictationOptions): UseDictationResult {
|
||||
const [partialTranscript, setPartialTranscript] = useState("");
|
||||
const [duration, setDuration] = useState(0);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [startError, setStartError] = useState<AudioCaptureStartFailure | null>(null);
|
||||
const clearStartError = useCallback(() => setStartError(null), []);
|
||||
const [status, setStatus] = useState<DictationStatus>("idle");
|
||||
const latestPartialTranscriptRef = useRef("");
|
||||
|
||||
@@ -268,17 +265,14 @@ export function useDictation(options: UseDictationOptions): UseDictationResult {
|
||||
|
||||
actionGateRef.current.starting = true;
|
||||
setError(null);
|
||||
setStartError(null);
|
||||
setPartialTranscript("");
|
||||
setDuration(0);
|
||||
setIsProcessing(false);
|
||||
setStatus("recording");
|
||||
clearStreamingState();
|
||||
|
||||
let captureStarted = false;
|
||||
try {
|
||||
await audio.start();
|
||||
captureStarted = true;
|
||||
isRecordingRef.current = true;
|
||||
setIsRecording(true);
|
||||
if (enableDuration) {
|
||||
@@ -293,12 +287,7 @@ export function useDictation(options: UseDictationOptions): UseDictationResult {
|
||||
isRecordingRef.current = false;
|
||||
setIsRecording(false);
|
||||
setStatus("idle");
|
||||
if (captureStarted) {
|
||||
reportError(err, "Failed to start dictation stream");
|
||||
} else {
|
||||
console.error("[useDictation] Failed to start dictation capture", err);
|
||||
setStartError(err instanceof AudioCaptureStartError ? err.reason : "startFailed");
|
||||
}
|
||||
reportError(err, "Failed to start dictation");
|
||||
} finally {
|
||||
actionGateRef.current.starting = false;
|
||||
}
|
||||
@@ -449,7 +438,6 @@ export function useDictation(options: UseDictationOptions): UseDictationResult {
|
||||
stopDurationTracking();
|
||||
setDuration(0);
|
||||
setError(null);
|
||||
setStartError(null);
|
||||
setStatus("idle");
|
||||
clearStreamingState();
|
||||
}, [clearStreamingState, stopDurationTracking]);
|
||||
@@ -473,8 +461,6 @@ export function useDictation(options: UseDictationOptions): UseDictationResult {
|
||||
volume: audio.volume,
|
||||
duration,
|
||||
error,
|
||||
startError,
|
||||
clearStartError,
|
||||
status: status === "recording" && audio.isPaused ? "paused" : status,
|
||||
startDictation,
|
||||
cancelDictation,
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
import { useId } from "react";
|
||||
import { hasFocusedTextInput } from "@/keyboard";
|
||||
import type { KeyboardActionId } from "@/keyboard/keyboard-action-dispatcher";
|
||||
import { useKeyboardActionHandler } from "@/hooks/use-keyboard-action-handler";
|
||||
|
||||
export interface KeyboardToggleAction {
|
||||
id: KeyboardActionId;
|
||||
canOpen: () => boolean;
|
||||
}
|
||||
|
||||
/** Lets a trigger share its toggle with a keyboard action. */
|
||||
export function useKeyboardToggle({
|
||||
action,
|
||||
disabled,
|
||||
open,
|
||||
searchFocused,
|
||||
onToggle,
|
||||
}: {
|
||||
action: KeyboardToggleAction | undefined;
|
||||
disabled: boolean;
|
||||
open: boolean;
|
||||
searchFocused: boolean;
|
||||
onToggle: () => void;
|
||||
}) {
|
||||
const handlerId = useId();
|
||||
useKeyboardActionHandler({
|
||||
handlerId,
|
||||
actions: action ? [action.id] : [],
|
||||
enabled: action !== undefined && !disabled,
|
||||
priority: 200,
|
||||
isActive: () =>
|
||||
action?.canOpen() === true || (open && (searchFocused || !hasFocusedTextInput())),
|
||||
handle: () => {
|
||||
onToggle();
|
||||
return true;
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -115,7 +115,6 @@ export const ar: TranslationResources = {
|
||||
home: "بيت",
|
||||
groupByProject: "تجميع حسب المشروع",
|
||||
groupByStatus: "تجميع حسب الحالة",
|
||||
copyBrowserHostName: "نسخ اسم مضيف المتصفح",
|
||||
modelGroupLabel: "النموذج",
|
||||
modelSearchKeywords: "تبديل النموذج تغيير النموذج تعيين النموذج اختيار النموذج",
|
||||
thinkingGroupLabel: "التفكير",
|
||||
@@ -378,11 +377,6 @@ export const ar: TranslationResources = {
|
||||
details: "تفاصيل",
|
||||
},
|
||||
dictation: {
|
||||
insecureContext: "افتح Paseo عبر HTTPS أو localhost لاستخدام الميكروفون.",
|
||||
unsupported: "الإملاء غير متاح في هذا المتصفح.",
|
||||
noMicrophone: "صِل ميكروفونًا وحاول مرة أخرى.",
|
||||
permissionDenied: "اسمح بالوصول إلى الميكروفون وحاول مرة أخرى.",
|
||||
startFailed: "تعذر بدء الإملاء. حاول مرة أخرى.",
|
||||
paused: "تمت مقاطعة الميكروفون. في انتظار الاستئناف…",
|
||||
start: "بدء الإملاء الصوتي",
|
||||
cancel: "إلغاء الإملاء",
|
||||
@@ -2756,8 +2750,6 @@ export const ar: TranslationResources = {
|
||||
toggleFocusMode: "تبديل وضع التركيز",
|
||||
cycleTheme: "موضوع الدورة",
|
||||
focusMessageInput: "التركيز على إدخال الرسالة",
|
||||
toggleModelPicker: "فتح منتقي النموذج أو إغلاقه",
|
||||
cycleEffort: "التنقل بين مستويات الجهد",
|
||||
cycleAgentMode: "تبديل وضع الوكيل",
|
||||
toggleVoiceMode: "تبديل الوضع الصوتي",
|
||||
startStopDictation: "بدء إملاء /stop",
|
||||
|
||||
@@ -113,7 +113,6 @@ export const en = {
|
||||
home: "Home",
|
||||
groupByProject: "Group by project",
|
||||
groupByStatus: "Group by status",
|
||||
copyBrowserHostName: "Copy browser host name",
|
||||
modelGroupLabel: "Model",
|
||||
modelSearchKeywords: "switch model change model set model select model",
|
||||
thinkingGroupLabel: "Thinking",
|
||||
@@ -377,11 +376,6 @@ export const en = {
|
||||
details: "Details",
|
||||
},
|
||||
dictation: {
|
||||
insecureContext: "Open Paseo over HTTPS or localhost to use the microphone.",
|
||||
unsupported: "Dictation is unavailable in this browser.",
|
||||
noMicrophone: "Connect a microphone and try again.",
|
||||
permissionDenied: "Allow microphone access and try again.",
|
||||
startFailed: "Could not start dictation. Try again.",
|
||||
paused: "Microphone interrupted. Waiting to resume…",
|
||||
start: "Start voice dictation",
|
||||
cancel: "Cancel dictation",
|
||||
@@ -2850,8 +2844,6 @@ export const en = {
|
||||
toggleFocusMode: "Toggle focus mode",
|
||||
cycleTheme: "Cycle theme",
|
||||
focusMessageInput: "Focus message input",
|
||||
toggleModelPicker: "Toggle model picker",
|
||||
cycleEffort: "Cycle effort",
|
||||
cycleAgentMode: "Cycle agent mode",
|
||||
toggleVoiceMode: "Toggle voice mode",
|
||||
startStopDictation: "Start/stop dictation",
|
||||
|
||||
@@ -116,7 +116,6 @@ export const es: TranslationResources = {
|
||||
home: "Hogar",
|
||||
groupByProject: "Agrupar por proyecto",
|
||||
groupByStatus: "Agrupar por estado",
|
||||
copyBrowserHostName: "Copiar el nombre del host del navegador",
|
||||
modelGroupLabel: "Modelo",
|
||||
modelSearchKeywords: "cambiar modelo modificar modelo establecer modelo seleccionar modelo",
|
||||
thinkingGroupLabel: "Razonamiento",
|
||||
@@ -383,11 +382,6 @@ export const es: TranslationResources = {
|
||||
details: "Detalles",
|
||||
},
|
||||
dictation: {
|
||||
insecureContext: "Abre Paseo por HTTPS o en localhost para usar el micrófono.",
|
||||
unsupported: "El dictado no está disponible en este navegador.",
|
||||
noMicrophone: "Conecta un micrófono e inténtalo de nuevo.",
|
||||
permissionDenied: "Permite el acceso al micrófono e inténtalo de nuevo.",
|
||||
startFailed: "No se pudo iniciar el dictado. Inténtalo de nuevo.",
|
||||
paused: "Micrófono interrumpido. Esperando para reanudar…",
|
||||
start: "Iniciar dictado de voz",
|
||||
cancel: "Cancelar dictado",
|
||||
@@ -2779,8 +2773,6 @@ export const es: TranslationResources = {
|
||||
toggleFocusMode: "Alternar modo de enfoque",
|
||||
cycleTheme: "Tema del ciclo",
|
||||
focusMessageInput: "Entrada de mensaje de enfoque",
|
||||
toggleModelPicker: "Abrir o cerrar el selector de modelos",
|
||||
cycleEffort: "Alternar el nivel de esfuerzo",
|
||||
cycleAgentMode: "Alternar modo del agente",
|
||||
toggleVoiceMode: "Alternar modo de voz",
|
||||
startStopDictation: "Iniciar dictado/stop",
|
||||
|
||||
@@ -116,7 +116,6 @@ export const fr: TranslationResources = {
|
||||
home: "Accueil",
|
||||
groupByProject: "Grouper par projet",
|
||||
groupByStatus: "Grouper par statut",
|
||||
copyBrowserHostName: "Copier le nom de l’hôte du navigateur",
|
||||
modelGroupLabel: "Modèle",
|
||||
modelSearchKeywords:
|
||||
"changer de modèle modifier le modèle définir le modèle sélectionner le modèle model",
|
||||
@@ -383,11 +382,6 @@ export const fr: TranslationResources = {
|
||||
details: "Détails",
|
||||
},
|
||||
dictation: {
|
||||
insecureContext: "Ouvrez Paseo via HTTPS ou sur localhost pour utiliser le microphone.",
|
||||
unsupported: "La dictée est indisponible dans ce navigateur.",
|
||||
noMicrophone: "Connectez un microphone, puis réessayez.",
|
||||
permissionDenied: "Autorisez l’accès au microphone, puis réessayez.",
|
||||
startFailed: "Impossible de lancer la dictée. Réessayez.",
|
||||
paused: "Microphone interrompu. En attente de reprise…",
|
||||
start: "Démarrer la dictée vocale",
|
||||
cancel: "Annuler la dictée",
|
||||
@@ -2781,8 +2775,6 @@ export const fr: TranslationResources = {
|
||||
toggleFocusMode: "Activer/désactiver le mode focus",
|
||||
cycleTheme: "Parcourir les thèmes",
|
||||
focusMessageInput: "Aller à la zone de saisie",
|
||||
toggleModelPicker: "Ouvrir ou fermer le sélecteur de modèle",
|
||||
cycleEffort: "Parcourir les niveaux d’effort",
|
||||
cycleAgentMode: "Parcourir les modes de l’agent",
|
||||
toggleVoiceMode: "Activer/désactiver le mode vocal",
|
||||
startStopDictation: "Démarrer/arrêter la dictée",
|
||||
|
||||
@@ -116,7 +116,6 @@ export const ja: TranslationResources = {
|
||||
home: "ホーム",
|
||||
groupByProject: "プロジェクトでグループ化",
|
||||
groupByStatus: "ステータスでグループ化",
|
||||
copyBrowserHostName: "ブラウザホスト名をコピー",
|
||||
modelGroupLabel: "モデル",
|
||||
modelSearchKeywords: "モデルを切り替え モデルを変更 モデルを設定 モデルを選択",
|
||||
thinkingGroupLabel: "思考",
|
||||
@@ -383,11 +382,6 @@ export const ja: TranslationResources = {
|
||||
details: "詳細",
|
||||
},
|
||||
dictation: {
|
||||
insecureContext: "マイクを使用するには、HTTPS または localhost で Paseo を開いてください。",
|
||||
unsupported: "このブラウザーでは音声入力を利用できません。",
|
||||
noMicrophone: "マイクを接続して、もう一度お試しください。",
|
||||
permissionDenied: "マイクへのアクセスを許可して、もう一度お試しください。",
|
||||
startFailed: "音声入力を開始できませんでした。もう一度お試しください。",
|
||||
paused: "マイクが中断されました。再開を待っています…",
|
||||
start: "音声入力を開始",
|
||||
cancel: "音声入力をキャンセル",
|
||||
@@ -2745,8 +2739,6 @@ export const ja: TranslationResources = {
|
||||
toggleFocusMode: "フォーカスモードを切り替え",
|
||||
cycleTheme: "テーマを順に切り替え",
|
||||
focusMessageInput: "メッセージ入力にフォーカス",
|
||||
toggleModelPicker: "モデル選択を開く/閉じる",
|
||||
cycleEffort: "推論の強度を順に切り替え",
|
||||
cycleAgentMode: "エージェントモードを順に切り替え",
|
||||
toggleVoiceMode: "音声モードを切り替え",
|
||||
startStopDictation: "音声入力を開始/停止",
|
||||
|
||||
@@ -115,7 +115,6 @@ export const ko: TranslationResources = {
|
||||
home: "홈",
|
||||
groupByProject: "프로젝트별 그룹화",
|
||||
groupByStatus: "상태별 그룹화",
|
||||
copyBrowserHostName: "브라우저 호스트 이름 복사",
|
||||
modelGroupLabel: "모델",
|
||||
modelSearchKeywords: "모델 전환 모델 변경 모델 설정 모델 선택",
|
||||
thinkingGroupLabel: "추론",
|
||||
@@ -379,11 +378,6 @@ export const ko: TranslationResources = {
|
||||
details: "세부 정보",
|
||||
},
|
||||
dictation: {
|
||||
insecureContext: "마이크를 사용하려면 HTTPS 또는 localhost에서 Paseo를 여세요.",
|
||||
unsupported: "이 브라우저에서는 받아쓰기를 사용할 수 없습니다.",
|
||||
noMicrophone: "마이크를 연결한 후 다시 시도하세요.",
|
||||
permissionDenied: "마이크 접근을 허용한 후 다시 시도하세요.",
|
||||
startFailed: "받아쓰기를 시작할 수 없습니다. 다시 시도하세요.",
|
||||
paused: "마이크가 중단되었습니다. 재개를 기다리는 중…",
|
||||
start: "음성 받아쓰기 시작",
|
||||
cancel: "받아쓰기 취소",
|
||||
@@ -2734,8 +2728,6 @@ export const ko: TranslationResources = {
|
||||
toggleFocusMode: "집중 모드 토글",
|
||||
cycleTheme: "테마 순환",
|
||||
focusMessageInput: "메시지 입력란에 포커스",
|
||||
toggleModelPicker: "모델 선택기 열기 또는 닫기",
|
||||
cycleEffort: "추론 강도 순환",
|
||||
cycleAgentMode: "에이전트 모드 전환",
|
||||
toggleVoiceMode: "음성 모드 토글",
|
||||
startStopDictation: "받아쓰기 시작/중지",
|
||||
|
||||
@@ -116,7 +116,6 @@ export const ptBR: TranslationResources = {
|
||||
home: "Início",
|
||||
groupByProject: "Agrupar por projeto",
|
||||
groupByStatus: "Agrupar por status",
|
||||
copyBrowserHostName: "Copiar o nome do host do navegador",
|
||||
modelGroupLabel: "Modelo",
|
||||
modelSearchKeywords: "trocar modelo mudar modelo definir modelo selecionar modelo",
|
||||
thinkingGroupLabel: "Raciocínio",
|
||||
@@ -382,11 +381,6 @@ export const ptBR: TranslationResources = {
|
||||
details: "Detalhes",
|
||||
},
|
||||
dictation: {
|
||||
insecureContext: "Abra o Paseo por HTTPS ou em localhost para usar o microfone.",
|
||||
unsupported: "O ditado não está disponível neste navegador.",
|
||||
noMicrophone: "Conecte um microfone e tente novamente.",
|
||||
permissionDenied: "Permita o acesso ao microfone e tente novamente.",
|
||||
startFailed: "Não foi possível iniciar o ditado. Tente novamente.",
|
||||
paused: "Microfone interrompido. Aguardando para retomar…",
|
||||
start: "Iniciar ditado por voz",
|
||||
cancel: "Cancelar ditado",
|
||||
@@ -2759,8 +2753,6 @@ export const ptBR: TranslationResources = {
|
||||
toggleFocusMode: "Alternar modo de foco",
|
||||
cycleTheme: "Alternar tema",
|
||||
focusMessageInput: "Focar entrada de mensagem",
|
||||
toggleModelPicker: "Abrir ou fechar o seletor de modelos",
|
||||
cycleEffort: "Alternar o nível de esforço",
|
||||
cycleAgentMode: "Alternar modo do agente",
|
||||
toggleVoiceMode: "Alternar modo de voz",
|
||||
startStopDictation: "Iniciar/parar ditado",
|
||||
|
||||
@@ -116,7 +116,6 @@ export const ru: TranslationResources = {
|
||||
home: "Главная",
|
||||
groupByProject: "Группировать по проекту",
|
||||
groupByStatus: "Группировать по статусу",
|
||||
copyBrowserHostName: "Скопировать имя хоста браузера",
|
||||
modelGroupLabel: "Модель",
|
||||
modelSearchKeywords: "Сменить, изменить, выбрать или установить модель",
|
||||
thinkingGroupLabel: "Мышление",
|
||||
@@ -382,11 +381,6 @@ export const ru: TranslationResources = {
|
||||
details: "Подробности",
|
||||
},
|
||||
dictation: {
|
||||
insecureContext: "Чтобы использовать микрофон, откройте Paseo по HTTPS или на localhost.",
|
||||
unsupported: "Диктовка недоступна в этом браузере.",
|
||||
noMicrophone: "Подключите микрофон и попробуйте снова.",
|
||||
permissionDenied: "Разрешите доступ к микрофону и попробуйте снова.",
|
||||
startFailed: "Не удалось начать диктовку. Попробуйте снова.",
|
||||
paused: "Микрофон прерван. Ожидание возобновления…",
|
||||
start: "Начать диктовку голосом",
|
||||
cancel: "Отменить диктовку",
|
||||
@@ -2767,8 +2761,6 @@ export const ru: TranslationResources = {
|
||||
toggleFocusMode: "Переключить режим фокусировки",
|
||||
cycleTheme: "Переключить тему",
|
||||
focusMessageInput: "Перейти к полю ввода сообщения",
|
||||
toggleModelPicker: "Открыть или закрыть выбор модели",
|
||||
cycleEffort: "Переключить уровень усилий",
|
||||
cycleAgentMode: "Переключить режим агента",
|
||||
toggleVoiceMode: "Переключить голосовой режим",
|
||||
startStopDictation: "Начать/остановить диктовку",
|
||||
|
||||
@@ -115,7 +115,6 @@ export const zhCN: TranslationResources = {
|
||||
home: "首页",
|
||||
groupByProject: "按项目分组",
|
||||
groupByStatus: "按状态分组",
|
||||
copyBrowserHostName: "复制浏览器宿主名称",
|
||||
modelGroupLabel: "模型",
|
||||
modelSearchKeywords: "切换模型 更改模型 设置模型 选择模型",
|
||||
thinkingGroupLabel: "思考",
|
||||
@@ -378,11 +377,6 @@ export const zhCN: TranslationResources = {
|
||||
details: "详情",
|
||||
},
|
||||
dictation: {
|
||||
insecureContext: "请通过 HTTPS 或 localhost 打开 Paseo,以使用麦克风。",
|
||||
unsupported: "此浏览器无法使用听写。",
|
||||
noMicrophone: "请连接麦克风,然后重试。",
|
||||
permissionDenied: "请允许访问麦克风,然后重试。",
|
||||
startFailed: "无法开始听写。请重试。",
|
||||
paused: "麦克风已中断,正在等待恢复…",
|
||||
start: "开始语音听写",
|
||||
cancel: "取消听写",
|
||||
@@ -2690,8 +2684,6 @@ export const zhCN: TranslationResources = {
|
||||
toggleFocusMode: "切换专注模式",
|
||||
cycleTheme: "循环切换主题",
|
||||
focusMessageInput: "聚焦消息输入框",
|
||||
toggleModelPicker: "打开或关闭模型选择器",
|
||||
cycleEffort: "循环切换推理强度",
|
||||
cycleAgentMode: "循环切换代理模式",
|
||||
toggleVoiceMode: "切换语音模式",
|
||||
startStopDictation: "开始/停止听写",
|
||||
|
||||
@@ -14,9 +14,7 @@ export type MessageInputKeyboardActionKind =
|
||||
| "dictation-confirm"
|
||||
| "voice-toggle"
|
||||
| "voice-mute-toggle"
|
||||
| "mode-cycle"
|
||||
| "model-toggle"
|
||||
| "effort-cycle";
|
||||
| "mode-cycle";
|
||||
|
||||
export type KeyboardActionId =
|
||||
| "agent.interrupt"
|
||||
|
||||
@@ -7,7 +7,6 @@ export {
|
||||
getTopOverlayLayer,
|
||||
subscribeOverlays,
|
||||
} from "./internal/overlay-dispatch";
|
||||
export { hasFocusedTextInput } from "./internal/focused-text-input";
|
||||
export { useKeyboardFocusSurface } from "./internal/use-focus-surface";
|
||||
export { subscribeHardwareKeyboard } from "./internal/sources/hardware";
|
||||
export type { HardwareKeyboardEvent } from "./internal/sources/hardware";
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
import { resolveKeyboardFocusScope } from "../focus-scope";
|
||||
|
||||
export function hasFocusedTextInput(): boolean {
|
||||
const scope = resolveKeyboardFocusScope({ target: null, commandCenterOpen: false });
|
||||
return scope === "editable" || scope === "message-input";
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -13,8 +13,6 @@ export type KeyboardActionId =
|
||||
| "message-input.voice-toggle"
|
||||
| "message-input.voice-mute-toggle"
|
||||
| "message-input.mode-cycle"
|
||||
| "message-input.model-toggle"
|
||||
| "message-input.effort-cycle"
|
||||
| "workspace.agent.new"
|
||||
| "workspace.tab.menu.open"
|
||||
| "workspace.tab.target.agent"
|
||||
@@ -69,8 +67,6 @@ export type KeyboardActionDefinition =
|
||||
| { id: "message-input.voice-toggle"; scope: KeyboardActionScope }
|
||||
| { id: "message-input.voice-mute-toggle"; scope: KeyboardActionScope }
|
||||
| { id: "message-input.mode-cycle"; scope: KeyboardActionScope }
|
||||
| { id: "message-input.model-toggle"; scope: KeyboardActionScope }
|
||||
| { id: "message-input.effort-cycle"; scope: KeyboardActionScope }
|
||||
| { id: "workspace.agent.new"; scope: KeyboardActionScope }
|
||||
| { id: "workspace.tab.menu.open"; scope: KeyboardActionScope }
|
||||
| { id: "workspace.tab.target.agent"; scope: KeyboardActionScope }
|
||||
|
||||
@@ -337,27 +337,6 @@ describe("keyboard-shortcuts", () => {
|
||||
action: "message-input.action",
|
||||
payload: { kind: "dictation-toggle" },
|
||||
},
|
||||
{
|
||||
name: "toggles the model picker from the composer",
|
||||
event: { key: "/", code: "Slash", metaKey: true },
|
||||
context: { isMac: true, focusScope: "message-input" },
|
||||
action: "message-input.action",
|
||||
payload: { kind: "model-toggle" },
|
||||
},
|
||||
{
|
||||
name: "toggles the model picker while its search field has focus",
|
||||
event: { key: "/", code: "Slash", metaKey: true },
|
||||
context: { isMac: true, focusScope: "editable" },
|
||||
action: "message-input.action",
|
||||
payload: { kind: "model-toggle" },
|
||||
},
|
||||
{
|
||||
name: "cycles effort with the shifted slash character",
|
||||
event: { key: "?", code: "Slash", metaKey: true, shiftKey: true },
|
||||
context: { isMac: true, focusScope: "message-input" },
|
||||
action: "message-input.action",
|
||||
payload: { kind: "effort-cycle" },
|
||||
},
|
||||
{
|
||||
name: "routes Shift+Tab to cycle agent mode from the message input",
|
||||
event: { key: "Tab", code: "Tab", shiftKey: true },
|
||||
@@ -772,8 +751,6 @@ describe("keyboard-shortcut help sections", () => {
|
||||
"workspace-pane-split-right": ["mod", "\\"],
|
||||
"workspace-pane-close": ["mod", "shift", "W"],
|
||||
"cycle-agent-mode": ["shift", "Tab"],
|
||||
"toggle-model-picker": ["mod", "/"],
|
||||
"cycle-effort": ["mod", "shift", "/"],
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
@@ -197,8 +197,6 @@ export const SHORTCUT_HELP_ROW_ORDER: Record<ShortcutSectionId, readonly string[
|
||||
layout: ["toggle-left-sidebar", "toggle-right-sidebar", "toggle-both-sidebars", "toggle-focus"],
|
||||
"agent-input": [
|
||||
"focus-message-input",
|
||||
"toggle-model-picker",
|
||||
"cycle-effort",
|
||||
"cycle-agent-mode",
|
||||
"voice-toggle",
|
||||
"dictation-toggle",
|
||||
@@ -246,8 +244,6 @@ const SHORTCUT_HELP_LABEL_KEYS: Record<string, string> = {
|
||||
"toggle-focus": "settings.shortcuts.help.toggleFocusMode",
|
||||
"cycle-theme": "settings.shortcuts.help.cycleTheme",
|
||||
"focus-message-input": "settings.shortcuts.help.focusMessageInput",
|
||||
"toggle-model-picker": "settings.shortcuts.help.toggleModelPicker",
|
||||
"cycle-effort": "settings.shortcuts.help.cycleEffort",
|
||||
"cycle-agent-mode": "settings.shortcuts.help.cycleAgentMode",
|
||||
"voice-toggle": "settings.shortcuts.help.toggleVoiceMode",
|
||||
"dictation-toggle": "settings.shortcuts.help.startStopDictation",
|
||||
@@ -1153,33 +1149,6 @@ const SHORTCUT_BINDINGS: readonly ShortcutBinding[] = [
|
||||
label: "Focus message input",
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "message-input-model-toggle-mod-slash",
|
||||
action: "message-input.action",
|
||||
combo: "Mod+/",
|
||||
repeat: false,
|
||||
// The handler checks that its composer or its own picker has focus.
|
||||
when: { commandCenter: false, focusScope: ["message-input", "editable", "other"] },
|
||||
payload: { type: "message-input", kind: "model-toggle" },
|
||||
help: {
|
||||
id: "toggle-model-picker",
|
||||
section: "agent-input",
|
||||
label: "Toggle model picker",
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "message-input-effort-cycle-mod-shift-slash",
|
||||
action: "message-input.action",
|
||||
combo: "Mod+Shift+/",
|
||||
repeat: false,
|
||||
when: { commandCenter: false, focusScope: "message-input" },
|
||||
payload: { type: "message-input", kind: "effort-cycle" },
|
||||
help: {
|
||||
id: "cycle-effort",
|
||||
section: "agent-input",
|
||||
label: "Cycle effort",
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "message-input-mode-cycle-shift-tab",
|
||||
action: "message-input.action",
|
||||
|
||||
@@ -304,8 +304,6 @@ describe("routeKeyboardShortcut — message-input.action", () => {
|
||||
["dictation-confirm", "message-input.dictation-confirm"],
|
||||
["voice-toggle", "message-input.voice-toggle"],
|
||||
["voice-mute-toggle", "message-input.voice-mute-toggle"],
|
||||
["model-toggle", "message-input.model-toggle"],
|
||||
["effort-cycle", "message-input.effort-cycle"],
|
||||
["mode-cycle", "message-input.mode-cycle"],
|
||||
] as const)("kind=%s → dispatch %s", (kind, id) => {
|
||||
expect(
|
||||
|
||||
@@ -85,8 +85,6 @@ const MESSAGE_INPUT_DISPATCH: Record<
|
||||
"dictation-confirm": { id: "message-input.dictation-confirm", scope: "message-input" },
|
||||
"voice-toggle": { id: "message-input.voice-toggle", scope: "message-input" },
|
||||
"voice-mute-toggle": { id: "message-input.voice-mute-toggle", scope: "message-input" },
|
||||
"model-toggle": { id: "message-input.model-toggle", scope: "message-input" },
|
||||
"effort-cycle": { id: "message-input.effort-cycle", scope: "message-input" },
|
||||
"mode-cycle": { id: "message-input.mode-cycle", scope: "message-input" },
|
||||
};
|
||||
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
import React, { act } from "react";
|
||||
import { createRoot } from "react-dom/client";
|
||||
import { expect, it } from "vitest";
|
||||
import { usePanelStore } from "@/stores/panel-store";
|
||||
import { MobilePanelsProvider, useIsMobilePanelActive } from "./provider";
|
||||
|
||||
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });
|
||||
|
||||
it("renders a panel subscriber only when that panel settles or stops being settled", async () => {
|
||||
const initial = usePanelStore.getState();
|
||||
const host = document.createElement("div");
|
||||
document.body.appendChild(host);
|
||||
const root = createRoot(host);
|
||||
const explorerStates: boolean[] = [];
|
||||
|
||||
function ExplorerSubscriber() {
|
||||
explorerStates.push(useIsMobilePanelActive("file-explorer"));
|
||||
return null;
|
||||
}
|
||||
|
||||
function AgentSubscriber() {
|
||||
const active = useIsMobilePanelActive("agent");
|
||||
return <span>{active ? "Agent settled" : "Agent covered"}</span>;
|
||||
}
|
||||
|
||||
async function showPanel(target: "agent" | "agent-list" | "file-explorer") {
|
||||
await act(async () => {
|
||||
usePanelStore.setState((state) => ({
|
||||
mobilePanel: { target, revision: state.mobilePanel.revision + 1 },
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
await showPanel("agent-list");
|
||||
await act(async () => {
|
||||
root.render(
|
||||
<MobilePanelsProvider>
|
||||
<ExplorerSubscriber />
|
||||
<AgentSubscriber />
|
||||
</MobilePanelsProvider>,
|
||||
);
|
||||
});
|
||||
|
||||
await showPanel("agent");
|
||||
expect(host.textContent).toBe("Agent covered");
|
||||
await expect.poll(() => host.textContent).toBe("Agent settled");
|
||||
expect(explorerStates).toEqual([false]);
|
||||
|
||||
await showPanel("file-explorer");
|
||||
expect(explorerStates).toEqual([false]);
|
||||
await expect.poll(() => explorerStates).toEqual([false, true]);
|
||||
await showPanel("agent");
|
||||
await expect.poll(() => explorerStates).toEqual([false, true, false]);
|
||||
} finally {
|
||||
await act(async () => root.unmount());
|
||||
host.remove();
|
||||
usePanelStore.setState(initial, true);
|
||||
}
|
||||
});
|
||||
@@ -13,7 +13,6 @@ import {
|
||||
type ReactNode,
|
||||
type RefObject,
|
||||
} from "react";
|
||||
import { createStore, useStore } from "zustand";
|
||||
import { Keyboard, useWindowDimensions } from "react-native";
|
||||
import type { GestureType } from "react-native-gesture-handler";
|
||||
import {
|
||||
@@ -74,11 +73,7 @@ interface FinishGestureInput {
|
||||
}
|
||||
|
||||
const MobilePanelsContext = createContext<MobilePanelsRuntime | null>(null);
|
||||
function createSettledPanelStore(panel: MobilePanelView) {
|
||||
return createStore(() => panel);
|
||||
}
|
||||
|
||||
const SettledPanelContext = createContext(createSettledPanelStore("agent"));
|
||||
const MobilePanelActiveContext = createContext<MobilePanelView>("agent");
|
||||
|
||||
/**
|
||||
* The left sidebar's width: the full window for the compact drawer, the saved sidebar width
|
||||
@@ -118,7 +113,7 @@ export function MobilePanelsProvider({ children }: { children: ReactNode }) {
|
||||
const leftOpenGestureRef = useRef<GestureType | undefined>(undefined);
|
||||
const leftCloseGestureRef = useRef<GestureType | undefined>(undefined);
|
||||
const rightOpenGestureRef = useRef<GestureType | undefined>(undefined);
|
||||
const [settledPanel] = useState(() => createSettledPanelStore(initialSelection.target));
|
||||
const [activePanel, setActivePanel] = useState(initialSelection.target);
|
||||
|
||||
const setOpenGestureBlocked = useCallback(
|
||||
(owner: symbol, blocked: boolean) => {
|
||||
@@ -132,19 +127,16 @@ export function MobilePanelsProvider({ children }: { children: ReactNode }) {
|
||||
[openGesturesBlocked],
|
||||
);
|
||||
|
||||
const publishActivePanel = useCallback(
|
||||
(panel: MobilePanelView, revision: number) => {
|
||||
const selection = usePanelStore.getState().mobilePanel;
|
||||
if (selection.revision !== revision || selection.target !== panel) {
|
||||
return;
|
||||
}
|
||||
if (isNative && panel !== "agent") {
|
||||
Keyboard.dismiss();
|
||||
}
|
||||
settledPanel.setState(panel);
|
||||
},
|
||||
[settledPanel],
|
||||
);
|
||||
const publishActivePanel = useCallback((panel: MobilePanelView, revision: number) => {
|
||||
const selection = usePanelStore.getState().mobilePanel;
|
||||
if (selection.revision !== revision || selection.target !== panel) {
|
||||
return;
|
||||
}
|
||||
if (isNative && panel !== "agent") {
|
||||
Keyboard.dismiss();
|
||||
}
|
||||
setActivePanel(panel);
|
||||
}, []);
|
||||
|
||||
useAnimatedReaction(
|
||||
() => ({ motionState: motionState.value, position: position.value }),
|
||||
@@ -287,7 +279,9 @@ export function MobilePanelsProvider({ children }: { children: ReactNode }) {
|
||||
|
||||
return (
|
||||
<MobilePanelsContext.Provider value={value}>
|
||||
<SettledPanelContext.Provider value={settledPanel}>{children}</SettledPanelContext.Provider>
|
||||
<MobilePanelActiveContext.Provider value={activePanel}>
|
||||
{children}
|
||||
</MobilePanelActiveContext.Provider>
|
||||
</MobilePanelsContext.Provider>
|
||||
);
|
||||
}
|
||||
@@ -307,7 +301,7 @@ export function useLeftPanelWidth(): number {
|
||||
}
|
||||
|
||||
export function useIsMobilePanelActive(panel: MobilePanelView): boolean {
|
||||
return useStore(useContext(SettledPanelContext), (settledPanel) => settledPanel === panel);
|
||||
return useContext(MobilePanelActiveContext) === panel;
|
||||
}
|
||||
|
||||
export function useBlockMobilePanelOpenGestures(blocked: boolean): void {
|
||||
|
||||
@@ -39,17 +39,9 @@ import {
|
||||
resolveComposerTrackTailClearance,
|
||||
} from "@/composer/pill-styles";
|
||||
import { getActiveMessageSubmissions } from "@/composer/submission/model";
|
||||
import {
|
||||
RewindCommandCenterRegistration,
|
||||
RewindComposerRestoreProvider,
|
||||
} from "@/components/rewind";
|
||||
import { RewindComposerRestoreProvider } from "@/components/rewind/composer-restore";
|
||||
import { useAgentDescriptor } from "@/agent-presentation";
|
||||
import {
|
||||
useToastHost,
|
||||
type DismissToastById,
|
||||
type ToastApi,
|
||||
type ToastState,
|
||||
} from "@/components/toast-host";
|
||||
import { useToastHost, type ToastApi, type ToastState } from "@/components/toast-host";
|
||||
import type { WorkspaceComposerAttachment } from "@/attachments/types";
|
||||
import { useWorkspaceAttachmentScopeKey } from "@/attachments/workspace-attachments-store";
|
||||
import { COMPACT_CONTENT_WIDTH, useIsCompactFormFactor } from "@/constants/layout";
|
||||
@@ -65,7 +57,6 @@ import {
|
||||
type AgentScreenReadySyncState,
|
||||
} from "@/hooks/use-agent-screen-state-machine";
|
||||
import { useArchiveAgent } from "@/hooks/use-archive-agent";
|
||||
import { useStableEvent } from "@/hooks/use-stable-event";
|
||||
import { useContainerWidthBelow } from "@/hooks/use-container-width";
|
||||
import { reconcileMissingAgentStateWithPresentAgent } from "@/panels/agent-panel-load-state";
|
||||
import { TimelineSyncStatus } from "@/timeline/sync-status";
|
||||
@@ -873,6 +864,10 @@ function ChatAgentContent({
|
||||
streamViewRef.current?.scrollToBottom("message-sent");
|
||||
}, [agentId]);
|
||||
|
||||
const handleRewindComplete = useCallback(() => {
|
||||
streamViewRef.current?.scrollToBottom("rewind");
|
||||
}, []);
|
||||
|
||||
const retryAgentLoad = useCallback(() => {
|
||||
setMissingAgentState({ kind: "idle" });
|
||||
if (!agentId || !viewedTimelineSync) return;
|
||||
@@ -1027,6 +1022,7 @@ function ChatAgentContent({
|
||||
streamViewRef={streamViewRef}
|
||||
handleComposerHeightChange={handleComposerHeightChange}
|
||||
handleMessageSent={handleMessageSent}
|
||||
handleRewindComplete={handleRewindComplete}
|
||||
timelineSync={isPaneVisible && viewState.tag === "ready" ? viewState.sync : null}
|
||||
showHistorySyncOverlay={showHistorySyncOverlay}
|
||||
showHistorySyncError={showHistorySyncError}
|
||||
@@ -1058,6 +1054,7 @@ const ChatAgentReadyContent = memo(function ChatAgentReadyContent({
|
||||
streamViewRef,
|
||||
handleComposerHeightChange,
|
||||
handleMessageSent,
|
||||
handleRewindComplete,
|
||||
timelineSync,
|
||||
showHistorySyncOverlay,
|
||||
showHistorySyncError,
|
||||
@@ -1082,10 +1079,11 @@ const ChatAgentReadyContent = memo(function ChatAgentReadyContent({
|
||||
hasCachedHistory: boolean;
|
||||
toastApi: ToastApi;
|
||||
toast: ToastState | null;
|
||||
dismiss: DismissToastById;
|
||||
dismiss: () => void;
|
||||
streamViewRef: React.RefObject<AgentStreamViewHandle | null>;
|
||||
handleComposerHeightChange: (height: number) => void;
|
||||
handleMessageSent: () => void;
|
||||
handleRewindComplete: () => void;
|
||||
timelineSync: AgentScreenReadySyncState | null;
|
||||
showHistorySyncOverlay: boolean;
|
||||
showHistorySyncError: boolean;
|
||||
@@ -1104,22 +1102,6 @@ const ChatAgentReadyContent = memo(function ChatAgentReadyContent({
|
||||
const composerEditingSession = useComposerEditingSession("chat");
|
||||
const isComposerFullscreen = useComposerFullscreen(composerEditingSession);
|
||||
const hasActiveComposer = !agentState.archivedAt && !isArchivingCurrentAgent;
|
||||
const focusRestoredComposer = useStableEvent(() => {
|
||||
if (isPaneFocused && showsComposer && hasActiveComposer) {
|
||||
composerEditingSession.focus();
|
||||
}
|
||||
});
|
||||
const handleRewindComplete = useCallback(
|
||||
(restoredComposerText: boolean) => {
|
||||
streamViewRef.current?.scrollToBottom("rewind");
|
||||
if (restoredComposerText) {
|
||||
// Defer focus so the editor can apply the restored draft and the menu can start closing.
|
||||
requestAnimationFrame(focusRestoredComposer);
|
||||
}
|
||||
},
|
||||
[focusRestoredComposer, streamViewRef],
|
||||
);
|
||||
const hasAgentComposer = showsComposer && hasActiveComposer && !draft;
|
||||
const parentAgentId = useParentAgentId(serverId, agentId);
|
||||
// With a composer the parent is a pill above it; without one, the box takes the composer's place.
|
||||
const parentPillAgentId = showsComposer ? parentAgentId : null;
|
||||
@@ -1280,15 +1262,6 @@ const ChatAgentReadyContent = memo(function ChatAgentReadyContent({
|
||||
setText={agentInputDraft.replaceText}
|
||||
onRewindComplete={handleRewindComplete}
|
||||
>
|
||||
{hasAgentComposer ? (
|
||||
<RewindCommandCenterRegistration
|
||||
serverId={serverId}
|
||||
agentId={agentId}
|
||||
capabilities={agentState.capabilities}
|
||||
timelineSync={timelineSync}
|
||||
enabled={isPaneFocused}
|
||||
/>
|
||||
) : null}
|
||||
<View style={styles.root}>
|
||||
{dock}
|
||||
|
||||
@@ -1303,7 +1276,7 @@ const ChatAgentReadyContent = memo(function ChatAgentReadyContent({
|
||||
</RewindComposerRestoreProvider>
|
||||
);
|
||||
return wrapAgentCommandProvider({
|
||||
enabled: hasAgentComposer,
|
||||
enabled: showsComposer && hasActiveComposer && !draft,
|
||||
serverId,
|
||||
agentId,
|
||||
editingSession: composerEditingSession,
|
||||
|
||||
@@ -106,7 +106,6 @@ function fakeInput(initial: UserComposerAttachment[] = [], locked = false) {
|
||||
isLive: () => true,
|
||||
revealed: true,
|
||||
isRevealed: () => view.revealed,
|
||||
isFocused: () => false,
|
||||
focus: async (options) => {
|
||||
view.focused.push(options);
|
||||
},
|
||||
|
||||
@@ -55,8 +55,10 @@ import {
|
||||
buildDesktopDaemonTransportUrl,
|
||||
createDesktopDaemonTransportFactory,
|
||||
} from "@/desktop/daemon/desktop-daemon-transport";
|
||||
import { getDesktopHost } from "@/desktop/host";
|
||||
import { readDesktopManagedLocalCredential } from "@/desktop/daemon/local-credential";
|
||||
import { CLIENT_CAPS } from "@getpaseo/protocol/client-capabilities";
|
||||
import { BROWSER_AUTOMATION_COMMAND_NAMES } from "@getpaseo/protocol/browser-automation/rpc-schemas";
|
||||
import {
|
||||
useSessionStore,
|
||||
toDaemonServerInfo,
|
||||
@@ -72,10 +74,7 @@ import {
|
||||
invalidateServerDataQueriesAfterReconnect,
|
||||
mountServerDataPushRouter,
|
||||
} from "@/data/push-router";
|
||||
import {
|
||||
getDesktopBrowserHostRegistration,
|
||||
mountBrowserAutomationDaemonClientHandler,
|
||||
} from "@/desktop/browser/automation/handler";
|
||||
import { mountBrowserAutomationDaemonClientHandler } from "@/desktop/browser/automation/handler";
|
||||
import { schedulesQueryBaseKey } from "@/schedules/aggregated-schedules";
|
||||
import { dispatchComposerAgentMessage, sendQueuedComposerMessageNow } from "@/composer/actions";
|
||||
import { createMessageSubmissionWriter } from "@/composer/submission/writer";
|
||||
@@ -567,10 +566,19 @@ function probeIntervalForConnection(
|
||||
function createDefaultDeps(
|
||||
resolveOrigin: (serverId: string) => DaemonClient | null = () => null,
|
||||
): HostRuntimeControllerDeps {
|
||||
const browserHostRegistration = getDesktopBrowserHostRegistration();
|
||||
const appCapabilities = browserHostRegistration
|
||||
? { [CLIENT_CAPS.browserHost]: browserHostRegistration }
|
||||
: {};
|
||||
const browserHostAvailable =
|
||||
typeof getDesktopHost()?.browser?.executeAutomationCommand === "function";
|
||||
const browserAutomationCapabilities = browserHostAvailable
|
||||
? {
|
||||
[CLIENT_CAPS.browserHost]: {
|
||||
supportedCommands: [...BROWSER_AUTOMATION_COMMAND_NAMES],
|
||||
hostKind: "desktop app",
|
||||
},
|
||||
}
|
||||
: undefined;
|
||||
const appCapabilities = {
|
||||
...browserAutomationCapabilities,
|
||||
};
|
||||
|
||||
return {
|
||||
createClient: ({ host, connection, clientId, runtimeGeneration }) => {
|
||||
@@ -694,14 +702,12 @@ function createDefaultDeps(
|
||||
queryClient,
|
||||
serverId: host.serverId,
|
||||
});
|
||||
if (!browserHostRegistration) {
|
||||
if (!browserAutomationCapabilities) {
|
||||
return unmountServerData;
|
||||
}
|
||||
const unmountBrowserAutomation = mountBrowserAutomationDaemonClientHandler(
|
||||
client,
|
||||
browserHostRegistration,
|
||||
{ serverId: host.serverId },
|
||||
);
|
||||
const unmountBrowserAutomation = mountBrowserAutomationDaemonClientHandler(client, {
|
||||
serverId: host.serverId,
|
||||
});
|
||||
return () => {
|
||||
unmountBrowserAutomation();
|
||||
unmountServerData();
|
||||
|
||||
@@ -1,94 +0,0 @@
|
||||
import React, { act } from "react";
|
||||
import { createRoot } from "react-dom/client";
|
||||
import { PortalProvider } from "@gorhom/portal";
|
||||
import { afterEach, expect, it, vi } from "vitest";
|
||||
import { page } from "vitest/browser";
|
||||
import { WindowLayoutContext } from "@/window-layout/context";
|
||||
import { WindowLayoutActionsHost } from "@/window-layout";
|
||||
import { usePanelStore } from "@/stores/panel-store";
|
||||
import { CompactWorkspaceHeader } from ".";
|
||||
import { i18n } from "@/i18n/i18next";
|
||||
import type { WindowLayout } from "@/window-layout";
|
||||
void i18n;
|
||||
|
||||
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
|
||||
const container = document.createElement("div");
|
||||
document.body.appendChild(container);
|
||||
const root = createRoot(container);
|
||||
const initialPanel = usePanelStore.getState();
|
||||
afterEach(async () => {
|
||||
await act(async () => root.render(null));
|
||||
usePanelStore.setState(initialPanel, true);
|
||||
});
|
||||
const noop = () => {};
|
||||
const explorerState = { expanded: false };
|
||||
const geometry: WindowLayout = {
|
||||
bounds: { x: 0, y: 0, width: window.innerWidth, height: window.innerHeight },
|
||||
verticalBarEdge: "trailing",
|
||||
verticalBar: { x: 20, y: 20, width: 44, height: 400 },
|
||||
divisions: [],
|
||||
};
|
||||
|
||||
it("updates compact header actions on panel changes without rendering the workspace owner", async () => {
|
||||
let ownerRenders = 0;
|
||||
function WorkspaceOwner({ focused = true, compact = true }) {
|
||||
ownerRenders++;
|
||||
return (
|
||||
<CompactWorkspaceHeader
|
||||
isRouteFocused={focused}
|
||||
isCompact={compact}
|
||||
serverId="test"
|
||||
isLoading={false}
|
||||
title="Workspace"
|
||||
subtitle="Project"
|
||||
isSubtitleDistinct
|
||||
onToggleExplorer={noop}
|
||||
explorerToggleLabel="Explorer"
|
||||
explorerToggleAccessibilityState={explorerState}
|
||||
tabSwitcher={null}
|
||||
headerVariant="full"
|
||||
>
|
||||
<button type="button">Workspace menu</button>
|
||||
</CompactWorkspaceHeader>
|
||||
);
|
||||
}
|
||||
async function renderWorkspace(focused = true, compact = true) {
|
||||
await act(async () =>
|
||||
root.render(
|
||||
<PortalProvider>
|
||||
<WindowLayoutContext.Provider value={geometry}>
|
||||
<WindowLayoutActionsHost />
|
||||
<WorkspaceOwner focused={focused} compact={compact} />
|
||||
</WindowLayoutContext.Provider>
|
||||
</PortalProvider>,
|
||||
),
|
||||
);
|
||||
}
|
||||
async function showPanel(target: "agent" | "agent-list" | "file-explorer") {
|
||||
await act(async () =>
|
||||
usePanelStore.setState((state) => ({
|
||||
mobilePanel: { ...state.mobilePanel, target, revision: state.mobilePanel.revision + 1 },
|
||||
})),
|
||||
);
|
||||
}
|
||||
const menu = page.getByRole("button", {
|
||||
name: "Workspace menu",
|
||||
exact: true,
|
||||
includeHidden: true,
|
||||
});
|
||||
await showPanel("agent");
|
||||
await renderWorkspace();
|
||||
await expect.element(menu).toBeVisible();
|
||||
const rendersBeforePanelChanges = ownerRenders;
|
||||
await showPanel("agent-list");
|
||||
await expect.element(menu).not.toBeVisible();
|
||||
await showPanel("agent");
|
||||
await expect.element(menu).toBeVisible();
|
||||
await showPanel("file-explorer");
|
||||
await expect.element(menu).not.toBeVisible();
|
||||
expect(ownerRenders).toBe(rendersBeforePanelChanges);
|
||||
await renderWorkspace(true, false);
|
||||
await expect.element(menu).toBeVisible();
|
||||
await renderWorkspace(false, false);
|
||||
await expect.element(menu).not.toBeVisible();
|
||||
});
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user