mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-19 06:45:15 +00:00
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b495d33414 | ||
|
|
dd1c0424f4 | ||
|
|
68511b285a | ||
|
|
ee6aaf25d2 |
@@ -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
|
||||
|
||||
@@ -777,7 +777,9 @@ test.describe("CodeMirror workspace file editing", () => {
|
||||
await replaceEditorText(page, "# Saved from source\n");
|
||||
await expect(page.getByTestId("workspace-tab-modified-file_notes.md")).toBeVisible();
|
||||
await selectFileView(page, "Preview");
|
||||
await expect(visibleFilePane.getByText("Saved from source", { exact: true })).toBeVisible();
|
||||
await expect(
|
||||
visibleFilePane.getByRole("heading", { name: "Saved from source", exact: true }),
|
||||
).toBeVisible();
|
||||
await expect(toolbar.getByLabel("Line 1, column 1")).toHaveCount(0);
|
||||
await expect.poll(() => readFile(markdownPath, "utf8")).toBe("# Saved from source\n");
|
||||
await expect(page.getByTestId("workspace-tab-modified-file_notes.md")).not.toBeVisible();
|
||||
@@ -864,7 +866,7 @@ test.describe("CodeMirror workspace file editing", () => {
|
||||
|
||||
await selectFileView(page, "Source");
|
||||
await expect(page.getByTestId("file-source-editor")).toBeVisible();
|
||||
await expect(preview.host).toHaveCount(0);
|
||||
await expect(preview.host).toBeHidden();
|
||||
await selectFileView(page, "Preview");
|
||||
await expect(preview.host).toBeVisible();
|
||||
});
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { expect, test, type Page } from "../support/fixtures";
|
||||
import { openFileExplorer, openFileFromExplorer } from "../support/helpers/file-explorer";
|
||||
|
||||
// Switching a file tab between Preview and Source returns to where each view was left.
|
||||
|
||||
const sections = Array.from({ length: 200 }, (_, index) => index);
|
||||
const LONG_MARKDOWN = sections.map((i) => `## Section ${i}\n\nParagraph ${i}.\n`).join("\n");
|
||||
const LONG_HTML = `<!doctype html><html><body>${sections
|
||||
.map((i) => `<h2>Section ${i}</h2><p>Paragraph ${i}</p>`)
|
||||
.join("")}</body></html>`;
|
||||
|
||||
type FileView = "markdown preview" | "html preview" | "source";
|
||||
|
||||
function htmlPreviewFrame(page: Page) {
|
||||
const frame = page.frames().find((candidate) => candidate.url().startsWith("data:text/html"));
|
||||
if (!frame) throw new Error("The HTML preview frame is not loaded.");
|
||||
return frame;
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the view's visible scroller to `offset` when given, and returns its offset. The
|
||||
* scroller is Markdown's scroll view, CodeMirror's scroller, or the HTML page itself.
|
||||
*/
|
||||
async function viewScroll(page: Page, view: FileView, offset?: number): Promise<number> {
|
||||
if (view === "html preview") {
|
||||
return htmlPreviewFrame(page).evaluate((target) => {
|
||||
if (target !== undefined) window.scrollTo(0, target);
|
||||
return window.scrollY;
|
||||
}, offset);
|
||||
}
|
||||
return page.evaluate(
|
||||
(input) => {
|
||||
const visible = (element: HTMLElement) => element.offsetParent !== null;
|
||||
let scroller: HTMLElement | null;
|
||||
if (input.view === "source") {
|
||||
scroller =
|
||||
[...document.querySelectorAll<HTMLElement>(".cm-scroller")].find(visible) ?? null;
|
||||
} else {
|
||||
scroller =
|
||||
[
|
||||
...document.querySelectorAll<HTMLElement>('[data-testid="markdown-preview-frame"]'),
|
||||
].find(visible) ?? null;
|
||||
while (scroller && !(scroller.scrollHeight > scroller.clientHeight + 10)) {
|
||||
scroller = scroller.parentElement;
|
||||
}
|
||||
}
|
||||
if (!scroller) throw new Error(`No visible scroller for the ${input.view}.`);
|
||||
if (input.offset !== undefined) scroller.scrollTop = input.offset;
|
||||
return scroller.scrollTop;
|
||||
},
|
||||
{ view, offset },
|
||||
);
|
||||
}
|
||||
|
||||
async function openLongFile(
|
||||
page: Page,
|
||||
withWorkspace: (options?: { prefix?: string }) => Promise<{
|
||||
repoPath: string;
|
||||
navigateTo(): Promise<void>;
|
||||
}>,
|
||||
name: string,
|
||||
content: string,
|
||||
): Promise<void> {
|
||||
const workspace = await withWorkspace({ prefix: "file-view-scroll-" });
|
||||
await writeFile(path.join(workspace.repoPath, name), content);
|
||||
await workspace.navigateTo();
|
||||
await openFileExplorer(page);
|
||||
await openFileFromExplorer(page, name);
|
||||
await expect(page.getByTestId("file-mode-preview")).toBeVisible({ timeout: 30_000 });
|
||||
}
|
||||
|
||||
async function showView(page: Page, view: "preview" | "source"): Promise<void> {
|
||||
await page.getByTestId(`file-mode-${view}`).click();
|
||||
}
|
||||
|
||||
/** Scrolls the view past the first screen and returns where it settled. */
|
||||
async function scrollDown(page: Page, view: FileView): Promise<number> {
|
||||
await expect(async () => {
|
||||
expect(await viewScroll(page, view, 1200)).toBeGreaterThan(1000);
|
||||
}).toPass({ timeout: 15_000 });
|
||||
// CodeMirror can adjust the offset once after a scroll; read it after that settles.
|
||||
await page.waitForTimeout(300);
|
||||
return viewScroll(page, view);
|
||||
}
|
||||
|
||||
async function expectOffsetKept(page: Page, view: FileView, offset: number): Promise<void> {
|
||||
await expect.poll(() => viewScroll(page, view), { timeout: 5_000 }).toBe(offset);
|
||||
}
|
||||
|
||||
test("Markdown preview keeps its scroll offset after showing Source", async ({
|
||||
page,
|
||||
withWorkspace,
|
||||
}) => {
|
||||
await openLongFile(page, withWorkspace, "long.md", LONG_MARKDOWN);
|
||||
const offset = await scrollDown(page, "markdown preview");
|
||||
|
||||
await showView(page, "source");
|
||||
await expect(page.getByTestId("file-source-editor")).toBeVisible();
|
||||
await showView(page, "preview");
|
||||
|
||||
await expectOffsetKept(page, "markdown preview", offset);
|
||||
});
|
||||
|
||||
test("HTML preview keeps its scroll offset after showing Source", async ({
|
||||
page,
|
||||
withWorkspace,
|
||||
}) => {
|
||||
await openLongFile(page, withWorkspace, "long.html", LONG_HTML);
|
||||
const offset = await scrollDown(page, "html preview");
|
||||
|
||||
await showView(page, "source");
|
||||
await expect(page.getByTestId("file-source-editor")).toBeVisible();
|
||||
await showView(page, "preview");
|
||||
|
||||
await expectOffsetKept(page, "html preview", offset);
|
||||
});
|
||||
|
||||
test("Source keeps its scroll offset after showing Preview", async ({ page, withWorkspace }) => {
|
||||
await openLongFile(page, withWorkspace, "long.md", LONG_MARKDOWN);
|
||||
await showView(page, "source");
|
||||
const offset = await scrollDown(page, "source");
|
||||
|
||||
await showView(page, "preview");
|
||||
await expect(page.getByTestId("markdown-preview-frame")).toBeVisible();
|
||||
await showView(page, "source");
|
||||
|
||||
await expectOffsetKept(page, "source", offset);
|
||||
});
|
||||
@@ -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} />
|
||||
|
||||
@@ -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,
|
||||
]);
|
||||
|
||||
|
||||
@@ -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>
|
||||
);
|
||||
|
||||
@@ -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}
|
||||
>
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
// @vitest-environment jsdom
|
||||
|
||||
import { renderHook } from "@testing-library/react";
|
||||
import type { ReactNode } from "react";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { RetainedPanelActivity } from "@/components/retained-panel";
|
||||
import { useHtmlPreviewNavigationGuard } from "./html-preview-navigation";
|
||||
|
||||
const DOCUMENT = "<html><body>report</body></html>";
|
||||
|
||||
function renderGuard(initialActive: boolean) {
|
||||
let active = initialActive;
|
||||
const view = renderHook(() => useHtmlPreviewNavigationGuard(DOCUMENT), {
|
||||
wrapper: ({ children }: { children: ReactNode }) => (
|
||||
<RetainedPanelActivity active={active}>{children}</RetainedPanelActivity>
|
||||
),
|
||||
});
|
||||
return {
|
||||
navigate: (url: string) => view.result.current({ url }),
|
||||
setActive(next: boolean) {
|
||||
active = next;
|
||||
view.rerender();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
describe("useHtmlPreviewNavigationGuard", () => {
|
||||
it("loads the document once and refuses the page loading it again", () => {
|
||||
const guard = renderGuard(true);
|
||||
|
||||
expect(guard.navigate("about:blank")).toBe(true);
|
||||
expect(guard.navigate("about:blank")).toBe(false);
|
||||
expect(guard.navigate("https://example.com/leak")).toBe(false);
|
||||
expect(guard.navigate("about:blank#section")).toBe(true);
|
||||
});
|
||||
|
||||
it("loads the document again in the WebView that shows after the panel was hidden", () => {
|
||||
const guard = renderGuard(true);
|
||||
expect(guard.navigate("about:blank")).toBe(true);
|
||||
|
||||
// iOS destroys the native WebView of a hidden panel and makes a new one when it shows.
|
||||
guard.setActive(false);
|
||||
guard.setActive(true);
|
||||
|
||||
expect(guard.navigate("about:blank")).toBe(true);
|
||||
expect(guard.navigate("about:blank")).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -1,3 +1,6 @@
|
||||
import { useCallback, useEffect, useRef } from "react";
|
||||
import { useRetainedPanelActive } from "@/components/retained-panel";
|
||||
|
||||
export type HtmlPreviewNavigationKind = "initialDocument" | "fragment" | "blocked";
|
||||
|
||||
const INITIAL_DOCUMENT_URLS = new Set(["about:blank", "about:srcdoc", ""]);
|
||||
@@ -7,3 +10,35 @@ export function htmlPreviewNavigationKind(url: string): HtmlPreviewNavigationKin
|
||||
if (url.startsWith("about:blank#") || url.startsWith("about:srcdoc#")) return "fragment";
|
||||
return "blocked";
|
||||
}
|
||||
|
||||
/**
|
||||
* Decides each navigation the native WebView asks about: the document loads once, a fragment
|
||||
* moves within it, and anything else is refused.
|
||||
*/
|
||||
export function useHtmlPreviewNavigationGuard(
|
||||
document: string,
|
||||
): (request: { url: string }) => boolean {
|
||||
// Latched per document rather than once for the lifetime of the WebView: the
|
||||
// file pane re-renders with new content on every live-file refresh, and each of
|
||||
// those is a fresh initial load that has to be allowed through.
|
||||
const loadedDocumentRef = useRef<string | null>(null);
|
||||
// The latch belongs to one native WebView, not to this component. iOS destroys the WebView of a
|
||||
// hidden retained panel and makes a new one when the panel shows, and that one loads the
|
||||
// document again. Releasing the latch while hidden lets that load through; a page on a kept
|
||||
// WebView gains at most a load of an inert initial URL.
|
||||
const active = useRetainedPanelActive();
|
||||
useEffect(() => {
|
||||
if (!active) loadedDocumentRef.current = null;
|
||||
}, [active]);
|
||||
return useCallback(
|
||||
({ url }: { url: string }) => {
|
||||
const navigationKind = htmlPreviewNavigationKind(url);
|
||||
if (navigationKind === "fragment") return true;
|
||||
if (navigationKind === "blocked") return false;
|
||||
if (loadedDocumentRef.current === document) return false;
|
||||
loadedDocumentRef.current = document;
|
||||
return true;
|
||||
},
|
||||
[document],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { useCallback, useMemo, useRef } from "react";
|
||||
import { useMemo } from "react";
|
||||
import { StyleSheet } from "react-native-unistyles";
|
||||
import { WebView } from "react-native-webview";
|
||||
import { withPreviewCsp } from "./html-preview-csp";
|
||||
import { htmlPreviewNavigationKind } from "./html-preview-navigation";
|
||||
import { useHtmlPreviewNavigationGuard } from "./html-preview-navigation";
|
||||
|
||||
// A preview is a viewer, not a browser. Only the document Paseo hands the WebView
|
||||
// loads; navigations the page attempts afterwards are refused, so a link, a
|
||||
@@ -35,21 +35,7 @@ const BASE_URL = "about:blank";
|
||||
export function FileHtmlPreview({ html, testID }: { html: string; testID?: string }) {
|
||||
const document = useMemo(() => withPreviewCsp(html), [html]);
|
||||
const source = useMemo(() => ({ html: document, baseUrl: BASE_URL }), [document]);
|
||||
// Latched per document rather than once for the lifetime of the WebView: the
|
||||
// file pane re-renders with new content on every live-file refresh, and each of
|
||||
// those is a fresh initial load that has to be allowed through.
|
||||
const loadedDocumentRef = useRef<string | null>(null);
|
||||
const allowOnlyInitialDocument = useCallback(
|
||||
({ url }: { url: string }) => {
|
||||
const navigationKind = htmlPreviewNavigationKind(url);
|
||||
if (navigationKind === "fragment") return true;
|
||||
if (navigationKind === "blocked") return false;
|
||||
if (loadedDocumentRef.current === document) return false;
|
||||
loadedDocumentRef.current = document;
|
||||
return true;
|
||||
},
|
||||
[document],
|
||||
);
|
||||
const allowOnlyInitialDocument = useHtmlPreviewNavigationGuard(document);
|
||||
|
||||
return (
|
||||
<WebView
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
useSyncExternalStore,
|
||||
type ComponentProps,
|
||||
type ComponentType,
|
||||
type ReactNode,
|
||||
} from "react";
|
||||
import {
|
||||
useFileText,
|
||||
@@ -15,6 +16,7 @@ import {
|
||||
import { Text, View } from "react-native";
|
||||
import { StyleSheet, withUnistyles } from "react-native-unistyles";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { RetainedPanel } from "@/components/retained-panel";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { isWeb } from "@/constants/platform";
|
||||
import { useAppSettings } from "@/hooks/use-settings";
|
||||
@@ -67,7 +69,9 @@ type TextFilePanelProps = PluginFilePanelProps & {
|
||||
/**
|
||||
* What the Markdown, HTML and Source panels share: a toolbar over the file's Source view and, when
|
||||
* the panel passes one, its Preview. Both views show the one read of the file and, while editing, the one editor buffer, so switching
|
||||
* between them neither re-reads nor loses edits. Edits files up to 1 MiB on web; shows larger files
|
||||
* between them neither re-reads nor loses edits. Each view stays mounted once shown, so switching
|
||||
* back also returns to where it was scrolled. The exception is the HTML Preview on iOS: iOS
|
||||
* replaces the WebView of a hidden view, so the page loads again from the top. Edits files up to 1 MiB on web; shows larger files
|
||||
* and every file on native read-only, and refuses files above the display budget before reading.
|
||||
*/
|
||||
export function TextFilePanel(props: TextFilePanelProps) {
|
||||
@@ -139,9 +143,17 @@ function ReadonlyTextFile({
|
||||
view={Preview ? view : undefined}
|
||||
onViewChange={Preview ? setView : undefined}
|
||||
/>
|
||||
{showPreview ? (
|
||||
<Preview text={text.text} params={params} workspaceId={workspaceId} host={host} />
|
||||
) : (
|
||||
{Preview ? (
|
||||
<RetainedPreview
|
||||
active={showPreview}
|
||||
preview={Preview}
|
||||
text={text.text}
|
||||
params={params}
|
||||
workspaceId={workspaceId}
|
||||
host={host}
|
||||
/>
|
||||
) : null}
|
||||
<RetainedView active={!showPreview}>
|
||||
<ThemedFileSourceView
|
||||
content={text.text}
|
||||
filename={params.path}
|
||||
@@ -149,7 +161,7 @@ function ReadonlyTextFile({
|
||||
navigationRevision={revision}
|
||||
presentation={presentation}
|
||||
/>
|
||||
)}
|
||||
</RetainedView>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@@ -237,9 +249,17 @@ function EditableTextFile({
|
||||
vimMode={showPreview ? null : vimMode}
|
||||
conflict={conflict}
|
||||
/>
|
||||
{showPreview ? (
|
||||
<Preview text={snapshot.content} params={params} workspaceId={workspaceId} host={host} />
|
||||
) : (
|
||||
{Preview ? (
|
||||
<RetainedPreview
|
||||
active={showPreview}
|
||||
preview={Preview}
|
||||
text={snapshot.content}
|
||||
params={params}
|
||||
workspaceId={workspaceId}
|
||||
host={host}
|
||||
/>
|
||||
) : null}
|
||||
<RetainedView active={!showPreview}>
|
||||
<SourceEditor
|
||||
model={model}
|
||||
filename={params.path}
|
||||
@@ -249,11 +269,48 @@ function EditableTextFile({
|
||||
onCursorChange={setCursor}
|
||||
onVimModeChange={setVimMode}
|
||||
/>
|
||||
)}
|
||||
</RetainedView>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* A view of the panel that stays mounted, hidden, while the other view shows, so switching back
|
||||
* returns to the same scroll offset. It mounts the first time it shows.
|
||||
*/
|
||||
function RetainedView({ active, children }: { active: boolean; children: ReactNode }) {
|
||||
const [shown, setShown] = useState(active);
|
||||
if (active && !shown) setShown(true);
|
||||
if (!shown) return null;
|
||||
return (
|
||||
<RetainedPanel active={active} style={styles.view}>
|
||||
{children}
|
||||
</RetainedPanel>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The Preview, retained like the Source. While hidden it keeps the text it last showed, so
|
||||
* editing in Source does not render the hidden Preview on every change.
|
||||
*/
|
||||
function RetainedPreview({
|
||||
active,
|
||||
preview: Preview,
|
||||
text,
|
||||
params,
|
||||
workspaceId,
|
||||
host,
|
||||
}: TextFilePreviewProps & { active: boolean; preview: ComponentType<TextFilePreviewProps> }) {
|
||||
const [shownText, setShownText] = useState(text);
|
||||
if (active && shownText !== text) setShownText(text);
|
||||
const previewText = active ? text : shownText;
|
||||
const preview = useMemo(
|
||||
() => <Preview text={previewText} params={params} workspaceId={workspaceId} host={host} />,
|
||||
[Preview, previewText, params, workspaceId, host],
|
||||
);
|
||||
return <RetainedView active={active}>{preview}</RetainedView>;
|
||||
}
|
||||
|
||||
/** The editor over the panel's buffer. Each mount shows Loading until the editor shows the text. */
|
||||
function SourceEditor(props: Omit<ComponentProps<typeof ThemedFileEditorView>, "onReady">) {
|
||||
const [ready, setReady] = useState(false);
|
||||
@@ -268,6 +325,7 @@ function SourceEditor(props: Omit<ComponentProps<typeof ThemedFileEditorView>, "
|
||||
|
||||
const styles = StyleSheet.create((theme) => ({
|
||||
container: { flex: 1, minHeight: 0 },
|
||||
view: { minHeight: 0 },
|
||||
editor: { flex: 1, minHeight: 0 },
|
||||
centerState: {
|
||||
flex: 1,
|
||||
|
||||
@@ -115,7 +115,6 @@ export const ar: TranslationResources = {
|
||||
home: "بيت",
|
||||
groupByProject: "تجميع حسب المشروع",
|
||||
groupByStatus: "تجميع حسب الحالة",
|
||||
copyBrowserHostName: "نسخ اسم مضيف المتصفح",
|
||||
modelGroupLabel: "النموذج",
|
||||
modelSearchKeywords: "تبديل النموذج تغيير النموذج تعيين النموذج اختيار النموذج",
|
||||
thinkingGroupLabel: "التفكير",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -116,7 +116,6 @@ export const ja: TranslationResources = {
|
||||
home: "ホーム",
|
||||
groupByProject: "プロジェクトでグループ化",
|
||||
groupByStatus: "ステータスでグループ化",
|
||||
copyBrowserHostName: "ブラウザホスト名をコピー",
|
||||
modelGroupLabel: "モデル",
|
||||
modelSearchKeywords: "モデルを切り替え モデルを変更 モデルを設定 モデルを選択",
|
||||
thinkingGroupLabel: "思考",
|
||||
|
||||
@@ -115,7 +115,6 @@ export const ko: TranslationResources = {
|
||||
home: "홈",
|
||||
groupByProject: "프로젝트별 그룹화",
|
||||
groupByStatus: "상태별 그룹화",
|
||||
copyBrowserHostName: "브라우저 호스트 이름 복사",
|
||||
modelGroupLabel: "모델",
|
||||
modelSearchKeywords: "모델 전환 모델 변경 모델 설정 모델 선택",
|
||||
thinkingGroupLabel: "추론",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -116,7 +116,6 @@ export const ru: TranslationResources = {
|
||||
home: "Главная",
|
||||
groupByProject: "Группировать по проекту",
|
||||
groupByStatus: "Группировать по статусу",
|
||||
copyBrowserHostName: "Скопировать имя хоста браузера",
|
||||
modelGroupLabel: "Модель",
|
||||
modelSearchKeywords: "Сменить, изменить, выбрать или установить модель",
|
||||
thinkingGroupLabel: "Мышление",
|
||||
|
||||
@@ -115,7 +115,6 @@ export const zhCN: TranslationResources = {
|
||||
home: "首页",
|
||||
groupByProject: "按项目分组",
|
||||
groupByStatus: "按状态分组",
|
||||
copyBrowserHostName: "复制浏览器宿主名称",
|
||||
modelGroupLabel: "模型",
|
||||
modelSearchKeywords: "切换模型 更改模型 设置模型 选择模型",
|
||||
thinkingGroupLabel: "思考",
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
@@ -1,6 +1,5 @@
|
||||
import { Fragment, useMemo, type ReactNode } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { usePanelStore } from "@/stores/panel-store";
|
||||
import { CompactHeader } from "@/components/headers/compact-header";
|
||||
import {
|
||||
EXPLORER_TOGGLE_KEYS,
|
||||
@@ -30,8 +29,7 @@ interface CompactWorkspaceHeaderProps {
|
||||
/** Workspace overflow menu. */
|
||||
children: ReactNode;
|
||||
headerVariant: "compact" | "full";
|
||||
isRouteFocused: boolean;
|
||||
isCompact: boolean;
|
||||
actionsActive: boolean;
|
||||
}
|
||||
|
||||
/** The compact header with the workspace's project row and controls. */
|
||||
@@ -47,8 +45,7 @@ export function CompactWorkspaceHeader({
|
||||
tabSwitcher,
|
||||
serverId,
|
||||
headerVariant,
|
||||
isRouteFocused,
|
||||
isCompact,
|
||||
actionsActive,
|
||||
}: CompactWorkspaceHeaderProps) {
|
||||
const { t } = useTranslation();
|
||||
const actionsInBar = resolveWorkspaceActionPlacement(useWindowLayout()) === "vertical-bar";
|
||||
@@ -92,26 +89,7 @@ export function CompactWorkspaceHeader({
|
||||
actions={actionsInBar ? undefined : actions}
|
||||
/>
|
||||
) : null}
|
||||
<WorkspaceWindowActions isRouteFocused={isRouteFocused} isCompact={isCompact}>
|
||||
{actions}
|
||||
</WorkspaceWindowActions>
|
||||
<WindowLayoutActions active={actionsActive}>{actions}</WindowLayoutActions>
|
||||
</IconButtonChromeProvider>
|
||||
);
|
||||
}
|
||||
|
||||
// Panel changes only affect the portaled controls. Keep their subscription below the
|
||||
// workspace and header so opening a sidebar does not render the chat or rebuild its actions.
|
||||
function WorkspaceWindowActions({
|
||||
isRouteFocused,
|
||||
isCompact,
|
||||
children,
|
||||
}: {
|
||||
isRouteFocused: boolean;
|
||||
isCompact: boolean;
|
||||
children: ReactNode;
|
||||
}) {
|
||||
const active = usePanelStore(
|
||||
(state) => isRouteFocused && (!isCompact || state.mobilePanel.target === "agent"),
|
||||
);
|
||||
return <WindowLayoutActions active={active}>{children}</WindowLayoutActions>;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ export interface ExplorerFrameProps {
|
||||
children: ReactNode;
|
||||
presentation: "overlay" | "dock";
|
||||
persistenceKey: string;
|
||||
containerWidth: number;
|
||||
isOpen: boolean;
|
||||
isWorkspaceActive: boolean;
|
||||
surfaceColor?: string;
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
import React, { act } from "react";
|
||||
import { createRoot } from "react-dom/client";
|
||||
import { View } from "react-native";
|
||||
import { expect, it } from "vitest";
|
||||
import { MobilePanelsProvider } from "@/mobile-panels/provider";
|
||||
import { ExplorerFrame } from "./frame";
|
||||
|
||||
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });
|
||||
|
||||
const WORKSPACE_STYLE = { flexDirection: "row", height: 200 } as const;
|
||||
const FILL = { flex: 1 };
|
||||
|
||||
it("measures dock allocation independently of the workspace owner", async () => {
|
||||
const host = document.createElement("div");
|
||||
host.style.width = "900px";
|
||||
document.body.appendChild(host);
|
||||
const root = createRoot(host);
|
||||
let workspaceRenders = 0;
|
||||
|
||||
function Workspace() {
|
||||
workspaceRenders++;
|
||||
return (
|
||||
<View style={WORKSPACE_STYLE}>
|
||||
<View role="main" style={FILL} />
|
||||
<ExplorerFrame presentation="dock" isWorkspaceActive isOpen persistenceKey="workspace">
|
||||
<View role="complementary" style={FILL} />
|
||||
</ExplorerFrame>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
function dockWidth() {
|
||||
return host.querySelector('[role="complementary"]')?.getBoundingClientRect().width;
|
||||
}
|
||||
|
||||
try {
|
||||
await act(async () => {
|
||||
root.render(
|
||||
<MobilePanelsProvider>
|
||||
<Workspace />
|
||||
</MobilePanelsProvider>,
|
||||
);
|
||||
});
|
||||
await expect.poll(dockWidth).toBe(320);
|
||||
const initialRenderCount = workspaceRenders;
|
||||
const dock = host.querySelector('[role="complementary"]');
|
||||
host.style.width = "620px";
|
||||
await expect.poll(dockWidth).toBe(260);
|
||||
expect(workspaceRenders).toBe(initialRenderCount);
|
||||
expect(host.querySelector('[role="complementary"]')).toBe(dock);
|
||||
} finally {
|
||||
await act(async () => root.unmount());
|
||||
host.remove();
|
||||
}
|
||||
});
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useCallback, useState } from "react";
|
||||
import { View, type LayoutChangeEvent } from "react-native";
|
||||
import { useCallback } from "react";
|
||||
import { View } from "react-native";
|
||||
import { StyleSheet, withUnistyles } from "react-native-unistyles";
|
||||
import {
|
||||
FileExplorerCloseGestureContext,
|
||||
@@ -20,12 +20,8 @@ function ExplorerFrameBase({
|
||||
isOpen,
|
||||
isWorkspaceActive,
|
||||
persistenceKey,
|
||||
containerWidth,
|
||||
}: ExplorerFrameProps) {
|
||||
const [containerWidth, setContainerWidth] = useState(0);
|
||||
const measureContainer = useCallback(({ nativeEvent }: LayoutChangeEvent) => {
|
||||
const { width, height } = nativeEvent.layout;
|
||||
if (width > 0 && height > 0) setContainerWidth(width);
|
||||
}, []);
|
||||
const overlay = presentation === "overlay";
|
||||
const settledOpen = useIsMobilePanelActive("file-explorer");
|
||||
const active = isWorkspaceActive && (overlay ? settledOpen : isOpen);
|
||||
@@ -63,15 +59,10 @@ function ExplorerFrameBase({
|
||||
</View>
|
||||
</MobilePanelOverlay>
|
||||
</FileExplorerCloseGestureContext>
|
||||
<View pointerEvents="none" style={styles.measurement} onLayout={measureContainer} />
|
||||
</RetainedPanelActivity>
|
||||
);
|
||||
}
|
||||
export const ExplorerFrame = withUnistyles(ExplorerFrameBase, (theme) => ({
|
||||
surfaceColor: theme.colors.surfaceSidebar,
|
||||
}));
|
||||
const styles = StyleSheet.create({
|
||||
content: { flex: 1, minHeight: 0 },
|
||||
// Measure the workspace row even when the dock is closed. The gesture host stays in its slot.
|
||||
measurement: { position: "absolute", top: 0, right: 0, bottom: 0, left: 0 },
|
||||
});
|
||||
const styles = StyleSheet.create({ content: { flex: 1, minHeight: 0 } });
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
import { useFileExplorerActions } from "@/hooks/use-file-explorer-actions";
|
||||
import { useWindowLayout, resolveWorkspaceActionPlacement } from "@/window-layout";
|
||||
import { revealWorkspaceTab } from "@/workspace-tabs/navigation";
|
||||
import type { LayoutChangeEvent } from "react-native";
|
||||
import { ExplorerSidebarDock } from "@/screens/workspace/explorer-sidebar";
|
||||
import { ForgeShorthandProvider } from "@/git/forge-shorthand";
|
||||
import { ExplorerFrame } from "./explorer-sidebar/frame";
|
||||
@@ -804,7 +805,9 @@ function WorkspacePanelSurface({
|
||||
children,
|
||||
tabIds,
|
||||
workspaceKey,
|
||||
onLayout,
|
||||
}: {
|
||||
onLayout: (event: LayoutChangeEvent) => void;
|
||||
workspaceKey: string;
|
||||
launcher: NewTabLauncher;
|
||||
children: ReactNode;
|
||||
@@ -815,7 +818,9 @@ function WorkspacePanelSurface({
|
||||
<WorkspaceComposerEditingSessionsProvider workspaceKey={workspaceKey} tabIds={tabIds}>
|
||||
<NewTabLauncherProvider value={launcher}>
|
||||
<SheetHostScope enabled={!isCompact}>
|
||||
<View style={styles.threePaneRow}>{children}</View>
|
||||
<View style={styles.threePaneRow} onLayout={onLayout}>
|
||||
{children}
|
||||
</View>
|
||||
</SheetHostScope>
|
||||
</NewTabLauncherProvider>
|
||||
</WorkspaceComposerEditingSessionsProvider>
|
||||
@@ -1056,6 +1061,7 @@ function WorkspaceScreenContent({
|
||||
resolveWorkspaceActionPlacement(useWindowLayout()) === "vertical-bar";
|
||||
const toast = useToast();
|
||||
const isMobile = useIsCompactFormFactor();
|
||||
const workspacePanelActive = usePanelStore((state) => state.mobilePanel.target === "agent");
|
||||
const canRenderDesktopPaneSplits = supportsDesktopPaneSplits();
|
||||
const layoutMode = useWorkspaceLayoutStore((state) => state.layoutMode);
|
||||
const hasMacTrafficLights = useHasWindowChromeObstruction("top-left");
|
||||
@@ -3457,8 +3463,7 @@ function WorkspaceScreenContent({
|
||||
return (
|
||||
<CompactWorkspaceHeader
|
||||
headerVariant={actionsOnly ? "full" : "compact"}
|
||||
isRouteFocused={isRouteFocused}
|
||||
isCompact={isMobile}
|
||||
actionsActive={isRouteFocused && (!isMobile || workspacePanelActive)}
|
||||
tabSwitcher={tabSwitcher}
|
||||
isLoading={isWorkspaceHeaderLoading}
|
||||
title={workspaceHeaderTitle}
|
||||
@@ -3519,6 +3524,7 @@ function WorkspaceScreenContent({
|
||||
workspaceDirectory,
|
||||
workspaceHeaderSubtitle,
|
||||
workspaceHeaderTitle,
|
||||
workspacePanelActive,
|
||||
],
|
||||
);
|
||||
const workspaceCompactHeaderTabs = {
|
||||
@@ -3704,6 +3710,11 @@ function WorkspaceScreenContent({
|
||||
</DesktopCenterColumnChrome>
|
||||
);
|
||||
|
||||
const [workspaceViewportWidth, setWorkspaceViewportWidth] = useState(0);
|
||||
const measureWorkspaceWidth = useCallback(
|
||||
(event: LayoutChangeEvent) => setWorkspaceViewportWidth(event.nativeEvent.layout.width),
|
||||
[],
|
||||
);
|
||||
const sharedExplorer = useMemo(() => {
|
||||
if (!workspaceLayout || !explorerSidebarPaneId || !persistenceKey) return null;
|
||||
const explorerPane = findPaneById(workspaceLayout.root, explorerSidebarPaneId);
|
||||
@@ -3742,6 +3753,7 @@ function WorkspaceScreenContent({
|
||||
presentation={isMobile ? "overlay" : "dock"}
|
||||
isWorkspaceActive={isRouteFocused}
|
||||
persistenceKey={persistenceKey}
|
||||
containerWidth={workspaceViewportWidth}
|
||||
isOpen={isExplorerSidebarShowing && !desktopFocusModeEnabled}
|
||||
>
|
||||
{dock}
|
||||
@@ -3776,6 +3788,7 @@ function WorkspaceScreenContent({
|
||||
handleReorderTabsInPane,
|
||||
buildDesktopPaneContentModel,
|
||||
renderExplorerSidebarHeaderAction,
|
||||
workspaceViewportWidth,
|
||||
desktopFocusModeEnabled,
|
||||
]);
|
||||
|
||||
@@ -3833,6 +3846,7 @@ function WorkspaceScreenContent({
|
||||
isRouteFocused={isRouteFocused}
|
||||
/>
|
||||
<WorkspacePanelSurface
|
||||
onLayout={measureWorkspaceWidth}
|
||||
launcher={newTabLauncher}
|
||||
workspaceKey={workspacePanelKey}
|
||||
tabIds={workspacePanelTabIds}
|
||||
|
||||
@@ -74,7 +74,6 @@ export const MoreVertical = StubIcon;
|
||||
export const MousePointer2 = StubIcon;
|
||||
export const PackagePlus = StubIcon;
|
||||
export const PanelLeft = StubIcon;
|
||||
export const PanelRight = StubIcon;
|
||||
export const PanelsTopLeft = StubIcon;
|
||||
export const Paperclip = StubIcon;
|
||||
export const Pencil = StubIcon;
|
||||
@@ -133,10 +132,3 @@ export const MicVocal = StubIcon;
|
||||
export const Scissors = StubIcon;
|
||||
export const Sparkles = StubIcon;
|
||||
export const TriangleAlertIcon = StubIcon;
|
||||
export const ArrowRightToLine = StubIcon;
|
||||
export const Columns2 = StubIcon;
|
||||
export const CopyX = StubIcon;
|
||||
export const Ellipsis = StubIcon;
|
||||
export const Maximize = StubIcon;
|
||||
export const Minimize = StubIcon;
|
||||
export const Rows2 = StubIcon;
|
||||
|
||||
@@ -338,86 +338,6 @@ async function callBrowserTool(client, name, args = {}) {
|
||||
return mcpPayload(await client.callTool({ name, args }), name);
|
||||
}
|
||||
|
||||
async function connectBrowserToolClient(daemonPort, callerAgentId) {
|
||||
const transport = new StreamableHTTPClientTransport(
|
||||
new URL(
|
||||
`http://127.0.0.1:${daemonPort}/mcp/agents?callerAgentId=${encodeURIComponent(callerAgentId)}`,
|
||||
),
|
||||
);
|
||||
return experimental_createMCPClient({ transport });
|
||||
}
|
||||
|
||||
async function openBrowserWorkspace(page, workspaceKey) {
|
||||
await page.getByTestId(`sidebar-workspace-row-${workspaceKey}`).click({ timeout: timeoutMs });
|
||||
await expect(page.getByTestId(`workspace-deck-entry-${workspaceKey}`)).toBeVisible();
|
||||
}
|
||||
|
||||
async function openSecondDesktopWindow(page) {
|
||||
const nextWindow = page.context().waitForEvent("page", { timeout: timeoutMs });
|
||||
await page.evaluate(() => window.paseoDesktop.window.openNew());
|
||||
return nextWindow;
|
||||
}
|
||||
|
||||
async function listBrowserHosts(client) {
|
||||
const reply = await client.callTool({ name: "browser_list_hosts", args: {} });
|
||||
assert(Array.isArray(reply.structuredContent?.browserHosts), JSON.stringify(reply));
|
||||
return reply.structuredContent.browserHosts;
|
||||
}
|
||||
|
||||
async function expectBrowserHostNameInCommandCenter(page, name) {
|
||||
await page.getByTestId("sidebar-search").click();
|
||||
const search = page.getByTestId("command-center-input");
|
||||
await search.fill("Copy browser host name");
|
||||
const action = page.getByRole("button", { name: /Copy browser host name/ });
|
||||
await expect(action).toContainText(name);
|
||||
await action.click();
|
||||
await expect(search).toBeHidden();
|
||||
await expect(page.getByText("Copied", { exact: true })).toBeVisible();
|
||||
}
|
||||
|
||||
async function verifyBrowserHostRouting({ page, client, targetUrl, workspaceKey }) {
|
||||
await openBrowserWorkspace(page, workspaceKey);
|
||||
await expect.poll(async () => (await listBrowserHosts(client)).length).toBe(1);
|
||||
const [firstHost] = await listBrowserHosts(client);
|
||||
await expectBrowserHostNameInCommandCenter(page, firstHost.label);
|
||||
const secondWindow = await openSecondDesktopWindow(page);
|
||||
|
||||
try {
|
||||
await openBrowserWorkspace(secondWindow, workspaceKey);
|
||||
await expect.poll(async () => (await listBrowserHosts(client)).length).toBe(2);
|
||||
const secondHost = (await listBrowserHosts(client)).find(
|
||||
(host) => host.browserHostId !== firstHost.browserHostId,
|
||||
);
|
||||
assert(secondHost?.label && secondHost.label !== firstHost.label, "Windows share a host label");
|
||||
await expectBrowserHostNameInCommandCenter(secondWindow, secondHost.label);
|
||||
|
||||
const ambiguous = await client.callTool({ name: "browser_new_tab", args: { url: targetUrl } });
|
||||
expect(ambiguous.structuredContent).toMatchObject({
|
||||
ok: false,
|
||||
error: { code: "browser_host_ambiguous", browserHosts: [firstHost, secondHost] },
|
||||
});
|
||||
expect((await callBrowserTool(client, "browser_list_tabs")).tabs).toEqual([]);
|
||||
|
||||
const { browserId, browserHost } = await callBrowserTool(client, "browser_new_tab", {
|
||||
url: targetUrl,
|
||||
browserHostId: firstHost.browserHostId,
|
||||
});
|
||||
expect(browserHost).toEqual(firstHost);
|
||||
// Only the tab's test ID carries the exact ID returned by the agent tool.
|
||||
await expect(page.getByTestId(`workspace-tab-browser_${browserId}`)).toBeVisible();
|
||||
await expect(secondWindow.getByTestId(`workspace-tab-browser_${browserId}`)).toHaveCount(0);
|
||||
expect((await callBrowserTool(client, "browser_list_tabs")).tabs).toMatchObject([
|
||||
{ browserId, browserHost: firstHost, isActive: false },
|
||||
]);
|
||||
await callBrowserTool(client, "browser_wait", { browserId, text: "Bridge target" });
|
||||
await callBrowserTool(client, "browser_close_tab", { browserId });
|
||||
} finally {
|
||||
await secondWindow.close();
|
||||
}
|
||||
|
||||
await expect.poll(() => listBrowserHosts(client)).toEqual([firstHost]);
|
||||
}
|
||||
|
||||
async function waitForGuestSelector(client, browserId) {
|
||||
const deadline = Date.now() + 5_000;
|
||||
while (Date.now() < deadline) {
|
||||
@@ -1493,7 +1413,12 @@ async function main() {
|
||||
workspaceId: workspaceIds.at(-1),
|
||||
agentId: await createCallerAgent(daemonPort, workspaceIds.at(-1)),
|
||||
};
|
||||
client = await connectBrowserToolClient(daemonPort, callerAgentId);
|
||||
const transport = new StreamableHTTPClientTransport(
|
||||
new URL(
|
||||
`http://127.0.0.1:${daemonPort}/mcp/agents?callerAgentId=${encodeURIComponent(callerAgentId)}`,
|
||||
),
|
||||
);
|
||||
client = await experimental_createMCPClient({ transport });
|
||||
const report = await runRegression({
|
||||
page,
|
||||
client,
|
||||
@@ -1505,23 +1430,11 @@ async function main() {
|
||||
artifactDir,
|
||||
});
|
||||
const pluginLinks = await checkPluginLinks();
|
||||
const routingClient = await connectBrowserToolClient(daemonPort, typingAgent.agentId);
|
||||
try {
|
||||
await verifyBrowserHostRouting({
|
||||
page,
|
||||
client: routingClient,
|
||||
targetUrl: target.url,
|
||||
workspaceKey: `${status.serverId}:${typingAgent.workspaceId}`,
|
||||
});
|
||||
} finally {
|
||||
await routingClient.close();
|
||||
}
|
||||
writeJson(path.join(artifactDir, "result.json"), {
|
||||
...report,
|
||||
settingsMemory,
|
||||
pluginLinks,
|
||||
adaptiveTheme,
|
||||
browserHostRouting: "passed",
|
||||
});
|
||||
console.log(
|
||||
`Browser desktop browser E2E passed: WebContents ${report.originalWebContentsId} remained ${report.finalWebContentsId}; viewport, inactive capture, focus continuity, list, snapshot, click, local-page selectors passed.`,
|
||||
|
||||
@@ -10,8 +10,6 @@ log.initialize({ spyRendererConsole: true });
|
||||
import { inheritLoginShellEnv } from "./login-shell-env.js";
|
||||
|
||||
import path from "node:path";
|
||||
import { randomBytes, randomUUID } from "node:crypto";
|
||||
import { hostname } from "node:os";
|
||||
import { pathToFileURL } from "node:url";
|
||||
import { existsSync } from "node:fs";
|
||||
import { execFileSync } from "node:child_process";
|
||||
@@ -670,14 +668,6 @@ function getWorkAreasPrimaryFirst(): Electron.Rectangle[] {
|
||||
return [primary, ...others].map((display) => display.workArea);
|
||||
}
|
||||
|
||||
const browserHostComputerName =
|
||||
hostname()
|
||||
.replace(/\.local$/i, "")
|
||||
.trim()
|
||||
.slice(0, 120) || "Desktop";
|
||||
const browserHostSessionCode = randomBytes(3).toString("hex").toUpperCase();
|
||||
let browserHostWindowNumber = 0;
|
||||
|
||||
async function createWindow(
|
||||
options: {
|
||||
initialRoute?: string | null;
|
||||
@@ -703,7 +693,6 @@ async function createWindow(
|
||||
: null;
|
||||
|
||||
const title = devWorktreeName ? `${APP_NAME} (${devWorktreeName})` : APP_NAME;
|
||||
const browserHostLabel = `${browserHostComputerName} · Window ${++browserHostWindowNumber} (${browserHostSessionCode})`;
|
||||
const mainWindow = new BrowserWindow({
|
||||
title,
|
||||
...resolveWindowBounds(restoredWindowState),
|
||||
@@ -715,11 +704,7 @@ async function createWindow(
|
||||
}),
|
||||
webPreferences: {
|
||||
preload: getPreloadPath(),
|
||||
additionalArguments: [
|
||||
windowChromeModeArgument(DESKTOP_WINDOW_CHROME_MODE),
|
||||
`--paseo-browser-host-label=${browserHostLabel}`,
|
||||
`--paseo-browser-host-instance-id=${randomUUID()}`,
|
||||
],
|
||||
additionalArguments: [windowChromeModeArgument(DESKTOP_WINDOW_CHROME_MODE)],
|
||||
contextIsolation: true,
|
||||
nodeIntegration: false,
|
||||
webviewTag: true,
|
||||
|
||||
@@ -12,10 +12,6 @@ const PASEO_BROWSER_PROFILE_PARTITION = "persist:paseo-browser";
|
||||
|
||||
type EventHandler = (payload: unknown) => void;
|
||||
|
||||
function readArgValue(prefix: string): string | undefined {
|
||||
return process.argv.find((argument) => argument.startsWith(prefix))?.slice(prefix.length);
|
||||
}
|
||||
|
||||
function readWindowChromeMode(): DesktopWindowChromeMode {
|
||||
const prefix = "--paseo-window-chrome-mode=";
|
||||
const value = process.argv.find((argument) => argument.startsWith(prefix))?.slice(prefix.length);
|
||||
@@ -36,8 +32,6 @@ interface AttachedBrowserRegistration {
|
||||
contextBridge.exposeInMainWorld("paseoDesktop", {
|
||||
platform: process.platform,
|
||||
windowChromeMode: readWindowChromeMode(),
|
||||
browserHostLabel: readArgValue("--paseo-browser-host-label="),
|
||||
browserHostInstanceId: readArgValue("--paseo-browser-host-instance-id="),
|
||||
invoke: (command: string, args?: Record<string, unknown>) =>
|
||||
ipcRenderer.invoke("paseo:invoke", command, args),
|
||||
getPendingOpenProject: () =>
|
||||
|
||||
@@ -31,8 +31,6 @@ export const BrowserAutomationHostCapabilitySchema = z
|
||||
return supportedCommands;
|
||||
}),
|
||||
hostKind: z.string().min(1).default("browser host"),
|
||||
label: z.string().min(1).max(160).optional(),
|
||||
instanceId: z.uuid().optional(),
|
||||
})
|
||||
.passthrough();
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
describe("browser automation protocol integration", () => {
|
||||
const browserId = "11111111-1111-4111-8111-111111111111";
|
||||
|
||||
test("browser host capability parses supported commands and a label in hello", () => {
|
||||
test("browser host capability parses supported commands in hello", () => {
|
||||
expect(
|
||||
WSHelloMessageSchema.parse({
|
||||
type: "hello",
|
||||
@@ -24,7 +24,6 @@ describe("browser automation protocol integration", () => {
|
||||
[CLIENT_CAPS.browserHost]: {
|
||||
supportedCommands: [...BROWSER_AUTOMATION_COMMAND_NAMES],
|
||||
hostKind: "desktop app",
|
||||
label: "MacBook Pro · Window 2",
|
||||
},
|
||||
},
|
||||
}).capabilities,
|
||||
@@ -32,7 +31,6 @@ describe("browser automation protocol integration", () => {
|
||||
[CLIENT_CAPS.browserHost]: {
|
||||
supportedCommands: [...BROWSER_AUTOMATION_COMMAND_NAMES],
|
||||
hostKind: "desktop app",
|
||||
label: "MacBook Pro · Window 2",
|
||||
},
|
||||
});
|
||||
});
|
||||
@@ -135,23 +133,6 @@ describe("browser automation protocol integration", () => {
|
||||
).toBeUndefined();
|
||||
});
|
||||
|
||||
test("browser host registration accepts window identity and remains valid without it", () => {
|
||||
const request = {
|
||||
type: "browser.host.register.request",
|
||||
requestId: "register-browser",
|
||||
hostKind: "desktop app",
|
||||
supportedCommands: ["new_tab"],
|
||||
};
|
||||
const label = "MacBook Pro · Window 2";
|
||||
const instanceId = "33333333-3333-4333-8333-333333333333";
|
||||
expect(SessionInboundMessageSchema.parse(request)).toEqual(request);
|
||||
expect(SessionInboundMessageSchema.parse({ ...request, label, instanceId })).toEqual({
|
||||
...request,
|
||||
label,
|
||||
instanceId,
|
||||
});
|
||||
});
|
||||
|
||||
test("daemon to browser host execute request is an outbound session message", () => {
|
||||
const parsed = SessionOutboundMessageSchema.parse({
|
||||
type: "browser.automation.execute.request",
|
||||
|
||||
@@ -3493,8 +3493,6 @@ export const BrowserHostRegisterRequestSchema = z.object({
|
||||
type: z.literal("browser.host.register.request"),
|
||||
requestId: z.string(),
|
||||
hostKind: z.string().min(1),
|
||||
label: z.string().min(1).max(160).optional(),
|
||||
instanceId: z.uuid().optional(),
|
||||
supportedCommands: z.array(z.enum(BROWSER_AUTOMATION_COMMAND_NAMES)).min(1),
|
||||
});
|
||||
export const BrowserHostRegisterResponseSchema = z.object({
|
||||
|
||||
@@ -390,7 +390,6 @@ export const PASEO_TOOL_CATALOG = {
|
||||
},
|
||||
|
||||
// Browser
|
||||
browser_list_hosts: browser("List browser hosts", "Listed browser hosts"),
|
||||
browser_list_tabs: browser("List browser tabs", "Listed browser tabs"),
|
||||
browser_new_tab: browser("Open browser tab", "Opened browser tab", field("url")),
|
||||
browser_close_tab: browser("Close browser tab", "Closed browser tab", field("browserId")),
|
||||
|
||||
@@ -8,10 +8,6 @@ import { AgentManager, type AgentManagerEvent } from "./agent-manager.js";
|
||||
import { AGENT_STREAM_COALESCE_DEFAULT_WINDOW_MS } from "./agent-stream-coalescer.js";
|
||||
import { limitAgentTimelineItemContent } from "./agent-timeline-content.js";
|
||||
import type { AgentTimelineRow } from "./agent-timeline-store-types.js";
|
||||
import { OmpAgentClient } from "./providers/omp/agent.js";
|
||||
import { FakeOmp } from "./providers/omp/test-utils/fake-omp.js";
|
||||
import { PiRpcAgentClient } from "./providers/pi/agent.js";
|
||||
import { FakePi } from "./providers/pi/test-utils/fake-pi.js";
|
||||
import { projectTimelineRows } from "./timeline-projection.js";
|
||||
import type {
|
||||
AgentCapabilityFlags,
|
||||
@@ -398,235 +394,6 @@ afterEach(() => {
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
describe("live notification turns", () => {
|
||||
test.each([
|
||||
{ sequence: "while idle", agentStarted: false, emptyCycle: false },
|
||||
{ sequence: "between agent_start and turn_start", agentStarted: true, emptyCycle: false },
|
||||
{ sequence: "after an empty cycle", agentStarted: true, emptyCycle: true },
|
||||
])(
|
||||
"keeps OMP replies in separate turns with a notice $sequence",
|
||||
async ({ agentStarted, emptyCycle }) => {
|
||||
const runtime = new FakeOmp();
|
||||
const provider = "omp";
|
||||
const logger = createTestLogger();
|
||||
const manager = new AgentManager({
|
||||
clients: {
|
||||
omp: new OmpAgentClient({
|
||||
runtime,
|
||||
logger,
|
||||
runtimeSettings: { command: { mode: "replace", argv: [process.execPath] } },
|
||||
}),
|
||||
},
|
||||
logger,
|
||||
});
|
||||
const workdir = mkdtempSync(join(tmpdir(), "omp-live-turns-"));
|
||||
const events: AgentManagerEvent[] = [];
|
||||
manager.subscribe((event) => events.push(event), { replayState: false });
|
||||
const { id } = await manager.createAgent({ provider, cwd: workdir }, undefined, {
|
||||
workspaceId: undefined,
|
||||
});
|
||||
try {
|
||||
const session = runtime.latestSession();
|
||||
const finishReply = async (text: string) => {
|
||||
const completed = () =>
|
||||
getStreamEvents(events, id).filter(
|
||||
(event) => event.type === "agent_stream" && event.event.type === "turn_completed",
|
||||
).length;
|
||||
const before = completed();
|
||||
session.streamAssistantText(text, text);
|
||||
session.finishTurn({ role: "assistant", content: [] });
|
||||
await vi.waitFor(() => {
|
||||
expect(completed()).toBe(before + 1);
|
||||
});
|
||||
};
|
||||
const notice = (message: string) => {
|
||||
session.emit({ type: "extension_ui_request", id: message, method: "notify", message });
|
||||
};
|
||||
session.beginTurn();
|
||||
await finishReply("First reply");
|
||||
|
||||
if (agentStarted) session.emit({ type: "agent_start" });
|
||||
if (emptyCycle) session.emit({ type: "agent_end", messages: [] });
|
||||
notice("Idle notice");
|
||||
session.beginTurn();
|
||||
session.acceptCustomMessage("<system-notice>Completion</system-notice>");
|
||||
notice("Running notice");
|
||||
await finishReply("Second reply");
|
||||
|
||||
const page = await manager.fetchTimeline(id, { wholeTurns: true, limit: 0 });
|
||||
const ids = page.rows.map((row) => row.turnId);
|
||||
expect(
|
||||
page.rows.map(({ item }) => {
|
||||
if (item.type === "assistant_message") return item.text;
|
||||
if (item.type === "notification") return item.message;
|
||||
return item.type;
|
||||
}),
|
||||
).toEqual(["First reply", "Idle notice", "Completion", "Running notice", "Second reply"]);
|
||||
const [first, idle, wake] = ids;
|
||||
expect(ids).toEqual([
|
||||
expect.any(String),
|
||||
expect.any(String),
|
||||
expect.any(String),
|
||||
wake,
|
||||
wake,
|
||||
]);
|
||||
expect(new Set([first, idle, wake]).size).toBe(3);
|
||||
expect(
|
||||
getTimelineStreamEvents(events, id).map((event) =>
|
||||
event.type === "agent_stream" && event.event.type === "timeline"
|
||||
? event.event.turnId
|
||||
: null,
|
||||
),
|
||||
).toEqual(ids);
|
||||
expect(
|
||||
(await manager.fetchTimeline(id, { wholeTurns: true, limit: 1 })).rows.map(
|
||||
(row) => row.turnId,
|
||||
),
|
||||
).toEqual([wake, wake, wake]);
|
||||
} finally {
|
||||
await manager.closeAgent(id);
|
||||
rmSync(workdir, { recursive: true, force: true });
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
test("keeps a Claude completion with the run it wakes after an independent notice", async () => {
|
||||
const harness = createHarness({ provider: "claude" });
|
||||
try {
|
||||
const { agentId, session } = await createManagedSession(harness);
|
||||
session.pushEvent(assistant("First reply", "claude", "first"));
|
||||
session.pushEvent(
|
||||
timelineEvent({ type: "notification", level: "info", message: "Idle" }, "claude"),
|
||||
);
|
||||
const completion = { ...toolCall({ status: "completed" }), name: "task_notification" };
|
||||
session.pushEvent(
|
||||
timelineEvent({ ...completion, callId: "stopped-task" }, "claude", "stopped"),
|
||||
);
|
||||
session.pushEvent(timelineEvent(completion, "claude", "wake"));
|
||||
session.pushEvent({ type: "turn_started", provider: "claude", turnId: "wake" });
|
||||
session.pushEvent(assistant("Second reply", "claude", "wake"));
|
||||
session.pushEvent({ type: "turn_completed", provider: "claude", turnId: "wake" });
|
||||
await vi.waitFor(() => {
|
||||
expect(getStreamEvents(harness.events, agentId).at(-1)).toMatchObject({
|
||||
event: { type: "turn_completed", turnId: "wake" },
|
||||
});
|
||||
});
|
||||
const page = await harness.manager.fetchTimeline(agentId, { wholeTurns: true, limit: 0 });
|
||||
expect(page.rows.map((row) => row.turnId)).toEqual([
|
||||
"first",
|
||||
expect.any(String),
|
||||
"stopped",
|
||||
"wake",
|
||||
"wake",
|
||||
]);
|
||||
expect(page.rows[1]?.turnId).not.toBe("first");
|
||||
expect(page.rows[1]?.turnId).not.toBe("wake");
|
||||
expect(
|
||||
getStreamEvents(harness.events, agentId).filter(
|
||||
(event) => event.type === "agent_stream" && event.event.type === "turn_started",
|
||||
),
|
||||
).toEqual([
|
||||
expect.objectContaining({
|
||||
event: { type: "turn_started", provider: "claude", turnId: "wake" },
|
||||
}),
|
||||
]);
|
||||
expect(
|
||||
(await harness.manager.fetchTimeline(agentId, { wholeTurns: true, limit: 1 })).rows.map(
|
||||
(row) => row.item,
|
||||
),
|
||||
).toEqual([completion, { type: "assistant_message", text: "Second reply" }]);
|
||||
} finally {
|
||||
harness.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test("an OMP runtime notice during a foreground turn reaches the run caller", async () => {
|
||||
const runtime = new FakeOmp();
|
||||
const logger = createTestLogger();
|
||||
const manager = new AgentManager({
|
||||
clients: {
|
||||
omp: new OmpAgentClient({
|
||||
runtime,
|
||||
logger,
|
||||
runtimeSettings: { command: { mode: "replace", argv: [process.execPath] } },
|
||||
}),
|
||||
},
|
||||
logger,
|
||||
});
|
||||
const workdir = mkdtempSync(join(tmpdir(), "omp-foreground-notice-"));
|
||||
const agent = await manager.createAgent({ provider: "omp", cwd: workdir }, undefined, {
|
||||
workspaceId: undefined,
|
||||
});
|
||||
const session = runtime.latestSession();
|
||||
try {
|
||||
const result = manager.runAgent(agent.id, "Work");
|
||||
await vi.waitFor(() => expect(session.prompts).toHaveLength(1));
|
||||
session.beginTurn();
|
||||
session.emit({
|
||||
type: "notice",
|
||||
level: "info",
|
||||
message: "Working",
|
||||
});
|
||||
session.streamAssistantText("Done");
|
||||
session.finishTurn({ role: "assistant", content: [] });
|
||||
const item = { type: "notification", level: "info", message: "Working" };
|
||||
expect((await result).timeline).toContainEqual(item);
|
||||
const rows = (await manager.fetchTimeline(agent.id, { wholeTurns: true, limit: 0 })).rows;
|
||||
expect(rows.find((row) => row.item.type === "notification")?.turnId).toEqual(
|
||||
expect.any(String),
|
||||
);
|
||||
expect(rows.find((row) => row.item.type === "notification")?.turnId).toEqual(
|
||||
rows.find((row) => row.item.type === "assistant_message")?.turnId,
|
||||
);
|
||||
} finally {
|
||||
await manager.closeAgent(agent.id);
|
||||
rmSync(workdir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("an idle Pi UI notice gets its own turn without starting a run", async () => {
|
||||
const runtime = new FakePi();
|
||||
const logger = createTestLogger();
|
||||
const manager = new AgentManager({
|
||||
clients: {
|
||||
pi: new PiRpcAgentClient({
|
||||
runtime,
|
||||
logger,
|
||||
runtimeSettings: { command: { mode: "replace", argv: [process.execPath] } },
|
||||
}),
|
||||
},
|
||||
logger,
|
||||
});
|
||||
const workdir = mkdtempSync(join(tmpdir(), "pi-idle-notice-"));
|
||||
const events: AgentManagerEvent[] = [];
|
||||
manager.subscribe((event) => events.push(event), { replayState: false });
|
||||
const { id } = await manager.createAgent({ provider: "pi", cwd: workdir }, undefined, {
|
||||
workspaceId: undefined,
|
||||
});
|
||||
try {
|
||||
runtime.latestSession().emit({
|
||||
type: "extension_ui_request",
|
||||
id: "notice",
|
||||
method: "notify",
|
||||
message: "Idle",
|
||||
});
|
||||
await vi.waitFor(() => expect(getTimelineStreamEvents(events, id)).toHaveLength(1));
|
||||
const { rows } = await manager.fetchTimeline(id, { wholeTurns: true, limit: 1 });
|
||||
const item = { type: "notification", level: "info", message: "Idle" };
|
||||
expect(rows).toEqual([expect.objectContaining({ item, turnId: expect.any(String) })]);
|
||||
expect(getStreamEvents(events, id)).toEqual([
|
||||
expect.objectContaining({
|
||||
event: { type: "timeline", provider: "pi", item, turnId: rows[0]?.turnId },
|
||||
}),
|
||||
]);
|
||||
expect(manager.getAgent(id)?.lifecycle).toBe("idle");
|
||||
} finally {
|
||||
await manager.closeAgent(id);
|
||||
rmSync(workdir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("target coalesced behavior", () => {
|
||||
test("bounds tool output before persisting and streaming it", async () => {
|
||||
const harness = createHarness();
|
||||
|
||||
@@ -608,11 +608,9 @@ function attachManagedTurnIdentity(
|
||||
return turnId ? { event: { ...event, turnId }, turnId } : { event, turnId };
|
||||
}
|
||||
case "timeline": {
|
||||
// A notice with no open run is a display turn of its own.
|
||||
const turnId =
|
||||
agent.activeForegroundTurnId ??
|
||||
agent.activeTurnId ??
|
||||
(event.item.type === "notification" ? randomUUID() : undefined);
|
||||
// Live provider items belong to the foreground turn that owns their dispatch.
|
||||
// Provider history deliberately keeps absent IDs because it has no daemon turn identity.
|
||||
const turnId = agent.activeForegroundTurnId ?? agent.activeTurnId ?? undefined;
|
||||
return turnId ? { event: { ...event, turnId }, turnId } : { event, turnId };
|
||||
}
|
||||
default:
|
||||
@@ -4827,10 +4825,6 @@ export class AgentManager {
|
||||
this.publishBackgroundWork(agent.id, items);
|
||||
return;
|
||||
}
|
||||
// Resolve notice membership before selecting the foreground run's waiters.
|
||||
if (event.type === "timeline" && event.item.type === "notification") {
|
||||
event = attachManagedTurnIdentity(agent, event, false).event;
|
||||
}
|
||||
const turnId = getAgentStreamEventTurnId(event);
|
||||
const matchingWaiters = this.runs.getMatchingWaiters(agent, turnId);
|
||||
this.logger.trace(
|
||||
|
||||
@@ -1583,6 +1583,7 @@ export class OmpAgentSession implements AgentSession {
|
||||
this.emit({
|
||||
type: "timeline",
|
||||
provider: this.provider,
|
||||
turnId: this.currentTurnIdForEvent(),
|
||||
item: {
|
||||
type: "notification",
|
||||
level:
|
||||
|
||||
@@ -2074,6 +2074,7 @@ export class PiRpcAgentSession implements AgentSession {
|
||||
this.emit({
|
||||
type: "timeline",
|
||||
provider: this.provider,
|
||||
turnId: this.currentTurnIdForEvent(),
|
||||
item: {
|
||||
type: "notification",
|
||||
level: toNotificationLevel(event.notifyType),
|
||||
|
||||
@@ -14,8 +14,6 @@ const SECOND_BROWSER_ID = "22222222-2222-4222-8222-222222222222";
|
||||
class FakeBrowserHostClient implements BrowserHostClient {
|
||||
public readonly receivedRequests: BrowserAutomationExecuteRequest[] = [];
|
||||
public readonly hostKind: string;
|
||||
public readonly label?: string;
|
||||
public readonly instanceId?: string;
|
||||
public readonly supportedCommands: readonly BrowserAutomationCommandName[];
|
||||
|
||||
public constructor(
|
||||
@@ -23,13 +21,9 @@ class FakeBrowserHostClient implements BrowserHostClient {
|
||||
options: {
|
||||
hostKind?: string;
|
||||
supportedCommands?: readonly BrowserAutomationCommandName[];
|
||||
label?: string;
|
||||
instanceId?: string;
|
||||
} = {},
|
||||
) {
|
||||
this.hostKind = options.hostKind ?? "desktop app";
|
||||
this.label = options.label;
|
||||
this.instanceId = options.instanceId;
|
||||
this.supportedCommands = options.supportedCommands ?? [...BROWSER_AUTOMATION_COMMAND_NAMES];
|
||||
}
|
||||
|
||||
@@ -176,7 +170,6 @@ describe("BrowserToolsBroker", () => {
|
||||
title: "Example",
|
||||
isActive: false,
|
||||
isLoading: false,
|
||||
browserHost: broker.listBrowserHosts()[0],
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -236,31 +229,20 @@ describe("BrowserToolsBroker", () => {
|
||||
});
|
||||
});
|
||||
|
||||
test("new tabs require a choice with multiple hosts and tab commands stay with the chosen host", async () => {
|
||||
test("new tabs target the most recently registered host and tab commands stay with that host", async () => {
|
||||
const broker = createBroker();
|
||||
const firstHost = new FakeBrowserHostClient("host-1", { label: "MacBook Pro · Window 1" });
|
||||
const firstHost = new FakeBrowserHostClient("host-1");
|
||||
const recentHost = new FakeBrowserHostClient("host-2");
|
||||
broker.registerClient(firstHost);
|
||||
broker.registerClient(recentHost);
|
||||
|
||||
const input = {
|
||||
const newTabPromise = broker.execute({
|
||||
command: { command: "new_tab", args: { url: "https://example.com" } },
|
||||
workspaceId: "workspace-1",
|
||||
} as const;
|
||||
const [selectedHost, otherHost] = broker.listBrowserHosts();
|
||||
expect(selectedHost.label).toBe("MacBook Pro · Window 1");
|
||||
expect(otherHost.label).toBe("desktop app · Connection 2");
|
||||
await expect(broker.execute(input)).resolves.toMatchObject({
|
||||
ok: false,
|
||||
error: { code: "browser_host_ambiguous", browserHosts: [selectedHost, otherHost] },
|
||||
});
|
||||
|
||||
expect(firstHost.receivedRequests).toEqual([]);
|
||||
expect(recentHost.receivedRequests).toEqual([]);
|
||||
|
||||
const newTabPromise = broker.execute({ ...input, browserHostId: selectedHost.browserHostId });
|
||||
|
||||
expect(recentHost.receivedRequests).toEqual([]);
|
||||
expect(firstHost.receivedRequests).toEqual([
|
||||
expect(recentHost.receivedRequests).toEqual([
|
||||
{
|
||||
type: "browser.automation.execute.request",
|
||||
requestId: "req-1",
|
||||
@@ -269,7 +251,7 @@ describe("BrowserToolsBroker", () => {
|
||||
},
|
||||
]);
|
||||
|
||||
firstHost.resolveLatestWith(broker, {
|
||||
recentHost.resolveLatestWith(broker, {
|
||||
requestId: "req-1",
|
||||
ok: true,
|
||||
result: {
|
||||
@@ -282,7 +264,7 @@ describe("BrowserToolsBroker", () => {
|
||||
|
||||
await expect(newTabPromise).resolves.toMatchObject({
|
||||
ok: true,
|
||||
result: { command: "new_tab", browserId: BROWSER_ID, browserHost: selectedHost },
|
||||
result: { command: "new_tab", browserId: BROWSER_ID },
|
||||
});
|
||||
|
||||
const snapshotPromise = broker.execute({
|
||||
@@ -290,15 +272,15 @@ describe("BrowserToolsBroker", () => {
|
||||
workspaceId: "workspace-1",
|
||||
});
|
||||
|
||||
expect(recentHost.receivedRequests).toEqual([]);
|
||||
expect(firstHost.receivedRequests.at(-1)).toEqual({
|
||||
expect(firstHost.receivedRequests).toEqual([]);
|
||||
expect(recentHost.receivedRequests.at(-1)).toEqual({
|
||||
type: "browser.automation.execute.request",
|
||||
requestId: "req-1",
|
||||
workspaceId: "workspace-1",
|
||||
command: { command: "snapshot", args: { browserId: BROWSER_ID } },
|
||||
});
|
||||
|
||||
firstHost.resolveLatestWith(broker, {
|
||||
recentHost.resolveLatestWith(broker, {
|
||||
requestId: "req-1",
|
||||
ok: true,
|
||||
result: {
|
||||
@@ -320,102 +302,6 @@ describe("BrowserToolsBroker", () => {
|
||||
});
|
||||
});
|
||||
|
||||
test("a disconnected selection stays invalid and the sole eligible host is automatic", async () => {
|
||||
const broker = createBroker();
|
||||
const formerHost = new FakeBrowserHostClient("former", { label: "Mac Mini · Window 1" });
|
||||
const remainingHost = new FakeBrowserHostClient("remaining");
|
||||
const inventoryHost = new FakeBrowserHostClient("inventory", {
|
||||
supportedCommands: ["list_tabs"],
|
||||
});
|
||||
const unregister = broker.registerClient(formerHost);
|
||||
broker.registerClient(remainingHost);
|
||||
broker.registerClient(inventoryHost);
|
||||
const [previous, remaining, inventoryOnly] = broker.listBrowserHosts();
|
||||
expect(inventoryOnly.canOpenTabs).toBe(false);
|
||||
unregister();
|
||||
expect(broker.listBrowserHosts()).toEqual([remaining, inventoryOnly]);
|
||||
|
||||
const input = {
|
||||
command: { command: "new_tab", args: {} },
|
||||
workspaceId: "workspace-1",
|
||||
} as const;
|
||||
await expect(
|
||||
broker.execute({ ...input, browserHostId: previous.browserHostId }),
|
||||
).resolves.toMatchObject({ ok: false, error: { code: "browser_no_host" } });
|
||||
await expect(
|
||||
broker.execute({ ...input, browserHostId: inventoryOnly.browserHostId }),
|
||||
).resolves.toMatchObject({ ok: false, error: { code: "browser_unsupported" } });
|
||||
expect(remainingHost.receivedRequests).toEqual([]);
|
||||
expect(inventoryHost.receivedRequests).toEqual([]);
|
||||
|
||||
const creation = broker.execute(input);
|
||||
remainingHost.resolveLatestWith(broker, {
|
||||
requestId: "req-1",
|
||||
ok: true,
|
||||
result: {
|
||||
command: "new_tab",
|
||||
browserId: BROWSER_ID,
|
||||
workspaceId: "workspace-1",
|
||||
url: "https://example.com",
|
||||
},
|
||||
});
|
||||
await expect(creation).resolves.toMatchObject({
|
||||
ok: true,
|
||||
result: { browserHost: remaining },
|
||||
});
|
||||
expect(inventoryHost.receivedRequests).toEqual([]);
|
||||
|
||||
broker.registerClient(new FakeBrowserHostClient("reconnected", { label: previous.label }));
|
||||
const reconnected = broker.listBrowserHosts().find(({ label }) => label === previous.label);
|
||||
expect(reconnected).toBeDefined();
|
||||
expect(reconnected?.browserHostId).not.toBe(previous.browserHostId);
|
||||
await expect(
|
||||
broker.execute({ ...input, browserHostId: previous.browserHostId }),
|
||||
).resolves.toMatchObject({ ok: false, error: { code: "browser_no_host" } });
|
||||
expect(formerHost.receivedRequests).toEqual([]);
|
||||
});
|
||||
|
||||
test("a reconnect replaces the old connection for the same browser host", async () => {
|
||||
const broker = createBroker();
|
||||
const identity = {
|
||||
instanceId: "33333333-3333-4333-8333-333333333333",
|
||||
label: "Desktop · Window 1",
|
||||
};
|
||||
const oldConnection = new FakeBrowserHostClient("old", identity);
|
||||
const releaseOld = broker.registerClient(oldConnection);
|
||||
const [target] = broker.listBrowserHosts();
|
||||
const pending = broker.execute({ command: { command: "new_tab", args: {} } });
|
||||
|
||||
const newConnection = new FakeBrowserHostClient("new", identity);
|
||||
broker.registerClient(newConnection);
|
||||
expect(broker.listBrowserHosts()).toEqual([target]);
|
||||
await expect(pending).resolves.toMatchObject({
|
||||
ok: false,
|
||||
error: { code: "browser_no_host" },
|
||||
});
|
||||
releaseOld();
|
||||
|
||||
const creation = broker.execute({
|
||||
command: { command: "new_tab", args: {} },
|
||||
browserHostId: target.browserHostId,
|
||||
});
|
||||
newConnection.resolveLatestWith(broker, {
|
||||
requestId: "req-1",
|
||||
ok: true,
|
||||
result: {
|
||||
command: "new_tab",
|
||||
browserId: BROWSER_ID,
|
||||
workspaceId: "workspace-1",
|
||||
url: "https://example.com",
|
||||
},
|
||||
});
|
||||
await expect(creation).resolves.toMatchObject({
|
||||
ok: true,
|
||||
result: { browserHost: target },
|
||||
});
|
||||
expect(oldConnection.receivedRequests).toHaveLength(1);
|
||||
});
|
||||
|
||||
test("list tabs aggregates all hosts and seeds browser id affinity", async () => {
|
||||
const broker = createBroker();
|
||||
const firstHost = new FakeBrowserHostClient("host-1");
|
||||
@@ -489,7 +375,6 @@ describe("BrowserToolsBroker", () => {
|
||||
title: "One",
|
||||
isActive: false,
|
||||
isLoading: false,
|
||||
browserHost: broker.listBrowserHosts()[0],
|
||||
},
|
||||
{
|
||||
browserId: SECOND_BROWSER_ID,
|
||||
@@ -498,7 +383,6 @@ describe("BrowserToolsBroker", () => {
|
||||
title: "Two",
|
||||
isActive: false,
|
||||
isLoading: false,
|
||||
browserHost: broker.listBrowserHosts()[1],
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -595,11 +479,7 @@ describe("BrowserToolsBroker", () => {
|
||||
broker.registerClient(other);
|
||||
broker.registerClient(owner);
|
||||
|
||||
const [, selectedHost] = broker.listBrowserHosts();
|
||||
const newTabPromise = broker.execute({
|
||||
command: { command: "new_tab", args: {} },
|
||||
browserHostId: selectedHost.browserHostId,
|
||||
});
|
||||
const newTabPromise = broker.execute({ command: { command: "new_tab", args: {} } });
|
||||
owner.resolveLatestWith(broker, {
|
||||
requestId: "req-1",
|
||||
ok: true,
|
||||
@@ -641,11 +521,7 @@ describe("BrowserToolsBroker", () => {
|
||||
broker.registerClient(other);
|
||||
broker.registerClient(owner);
|
||||
|
||||
const [, selectedHost] = broker.listBrowserHosts();
|
||||
const newTabPromise = broker.execute({
|
||||
command: { command: "new_tab", args: {} },
|
||||
browserHostId: selectedHost.browserHostId,
|
||||
});
|
||||
const newTabPromise = broker.execute({ command: { command: "new_tab", args: {} } });
|
||||
owner.resolveLatestWith(broker, {
|
||||
requestId: "req-1",
|
||||
ok: true,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { createHmac, randomBytes, randomUUID } from "node:crypto";
|
||||
import { randomUUID } from "node:crypto";
|
||||
import {
|
||||
BrowserAutomationExecuteRequestSchema,
|
||||
BrowserAutomationExecuteResponseSchema,
|
||||
@@ -7,17 +7,11 @@ import {
|
||||
type BrowserAutomationExecuteRequest,
|
||||
type BrowserAutomationExecuteResponse,
|
||||
} from "@getpaseo/protocol/browser-automation/rpc-schemas";
|
||||
import {
|
||||
browserToolsFailure,
|
||||
type BrowserHostTarget,
|
||||
type BrowserToolsResponsePayload,
|
||||
} from "./errors.js";
|
||||
import { browserToolsFailure, type BrowserToolsResponsePayload } from "./errors.js";
|
||||
|
||||
export interface BrowserHostClient {
|
||||
id: string;
|
||||
hostKind: string;
|
||||
label?: string;
|
||||
instanceId?: string;
|
||||
supportedCommands: readonly BrowserAutomationCommandName[];
|
||||
sendBrowserAutomationRequest(request: BrowserAutomationExecuteRequest): void | Promise<void>;
|
||||
}
|
||||
@@ -29,11 +23,10 @@ export interface BrowserToolsExecuteInput {
|
||||
workspaceId?: string;
|
||||
requestId?: string;
|
||||
timeoutMs?: number;
|
||||
browserHostId?: string;
|
||||
}
|
||||
|
||||
interface PendingBrowserToolsRequest {
|
||||
host: RegisteredBrowserHost;
|
||||
clientId: string;
|
||||
rememberAffinity: boolean;
|
||||
timeout: ReturnType<typeof setTimeout>;
|
||||
resolve: (payload: BrowserToolsResponsePayload) => void;
|
||||
@@ -41,15 +34,10 @@ interface PendingBrowserToolsRequest {
|
||||
|
||||
interface RegisteredBrowserHost {
|
||||
client: BrowserHostClient;
|
||||
target: BrowserHostTarget;
|
||||
registeredAt: number;
|
||||
supportedCommands: ReadonlySet<BrowserAutomationCommandName>;
|
||||
}
|
||||
|
||||
type HostSelection =
|
||||
| { ok: true; value: RegisteredBrowserHost }
|
||||
| { ok: false; payload: BrowserToolsResponsePayload };
|
||||
|
||||
export interface BrowserToolsBrokerOptions {
|
||||
defaultTimeoutMs?: number;
|
||||
createRequestId?: () => string;
|
||||
@@ -63,7 +51,7 @@ export class BrowserToolsBroker {
|
||||
private readonly clients = new Map<string, RegisteredBrowserHost>();
|
||||
private readonly pending = new Map<string, PendingBrowserToolsRequest>();
|
||||
private readonly browserHostByBrowserId = new Map<string, string>();
|
||||
private readonly hostIdKey = randomBytes(32);
|
||||
private readonly strandedBrowserHostByBrowserId = new Map<string, string>();
|
||||
private registrationSequence = 0;
|
||||
|
||||
public constructor(options: BrowserToolsBrokerOptions) {
|
||||
@@ -72,36 +60,35 @@ export class BrowserToolsBroker {
|
||||
}
|
||||
|
||||
public registerClient(client: BrowserHostClient): () => void {
|
||||
// The discovery ID must not allow another connection to claim this window.
|
||||
const browserHostId = createHmac("sha256", this.hostIdKey)
|
||||
.update(client.instanceId ? `instance:${client.instanceId}` : `connection:${client.id}`)
|
||||
.digest("hex");
|
||||
this.unregisterHost(browserHostId);
|
||||
this.unregisterClient(client.id);
|
||||
const registeredAt = ++this.registrationSequence;
|
||||
const label = client.label?.trim() || `${client.hostKind} · Connection ${registeredAt}`;
|
||||
const supportedCommands = new Set(client.supportedCommands);
|
||||
this.clients.set(browserHostId, {
|
||||
this.clients.set(client.id, {
|
||||
client,
|
||||
target: Object.freeze({
|
||||
browserHostId,
|
||||
label,
|
||||
canOpenTabs: supportedCommands.has("new_tab"),
|
||||
}),
|
||||
registeredAt,
|
||||
supportedCommands,
|
||||
supportedCommands: new Set(client.supportedCommands),
|
||||
});
|
||||
return () => this.unregisterHost(browserHostId, registeredAt);
|
||||
return () => this.unregisterClient(client.id, registeredAt);
|
||||
}
|
||||
|
||||
private unregisterHost(browserHostId: string, registeredAt?: number): void {
|
||||
const current = this.clients.get(browserHostId);
|
||||
public unregisterClient(clientId: string, registeredAt?: number): void {
|
||||
const current = this.clients.get(clientId);
|
||||
if (!current || (registeredAt !== undefined && current.registeredAt !== registeredAt)) {
|
||||
return;
|
||||
}
|
||||
this.clients.delete(browserHostId);
|
||||
this.clients.delete(clientId);
|
||||
|
||||
for (const [browserId, ownerClientId] of this.browserHostByBrowserId) {
|
||||
if (ownerClientId !== clientId) {
|
||||
continue;
|
||||
}
|
||||
this.browserHostByBrowserId.delete(browserId);
|
||||
this.strandedBrowserHostByBrowserId.set(browserId, clientId);
|
||||
}
|
||||
|
||||
for (const [requestId, pending] of this.pending) {
|
||||
if (pending.host !== current) continue;
|
||||
if (pending.clientId !== clientId) {
|
||||
continue;
|
||||
}
|
||||
this.pending.delete(requestId);
|
||||
clearTimeout(pending.timeout);
|
||||
pending.resolve(
|
||||
@@ -123,10 +110,6 @@ export class BrowserToolsBroker {
|
||||
return this.clients.size;
|
||||
}
|
||||
|
||||
public listBrowserHosts(): BrowserHostTarget[] {
|
||||
return Array.from(this.clients.values(), ({ target }) => target);
|
||||
}
|
||||
|
||||
public async execute(input: BrowserToolsExecuteInput): Promise<BrowserToolsResponsePayload> {
|
||||
const requestId = input.requestId ?? this.createRequestId();
|
||||
|
||||
@@ -154,11 +137,7 @@ export class BrowserToolsBroker {
|
||||
});
|
||||
}
|
||||
|
||||
const command = request.data.command;
|
||||
const host =
|
||||
command.command === "new_tab"
|
||||
? this.selectHostForNewTab(requestId, input.browserHostId)
|
||||
: this.selectHostForTab(command.args.browserId, requestId);
|
||||
const host = this.selectHostForCommand(request.data.command, requestId);
|
||||
if (!host.ok) {
|
||||
return host.payload;
|
||||
}
|
||||
@@ -191,7 +170,7 @@ export class BrowserToolsBroker {
|
||||
}
|
||||
|
||||
const pending = this.pending.get(requestId);
|
||||
if (!pending || (clientIds && !clientIds.includes(pending.host.client.id))) {
|
||||
if (!pending || (clientIds && !clientIds.includes(pending.clientId))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -208,16 +187,16 @@ export class BrowserToolsBroker {
|
||||
}
|
||||
|
||||
const pending = this.pending.get(parsed.data.payload.requestId);
|
||||
if (!pending || (clientIds && !clientIds.includes(pending.host.client.id))) {
|
||||
if (!pending || (clientIds && !clientIds.includes(pending.clientId))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.pending.delete(parsed.data.payload.requestId);
|
||||
clearTimeout(pending.timeout);
|
||||
if (pending.rememberAffinity && parsed.data.payload.ok) {
|
||||
this.rememberBrowserHostForPayload(pending.host.target.browserHostId, parsed.data.payload);
|
||||
if (pending.rememberAffinity) {
|
||||
this.rememberBrowserHostForPayload(pending.clientId, parsed.data.payload);
|
||||
}
|
||||
pending.resolve(attachBrowserHost(parsed.data.payload, pending.host.target));
|
||||
pending.resolve(parsed.data.payload);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -270,9 +249,7 @@ export class BrowserToolsBroker {
|
||||
}
|
||||
|
||||
for (const { host, payload } of hostResponses) {
|
||||
if (payload.ok && this.clients.get(host.target.browserHostId) === host) {
|
||||
this.rememberBrowserHostForPayload(host.target.browserHostId, payload);
|
||||
}
|
||||
this.rememberBrowserHostForPayload(host.client.id, payload);
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -287,60 +264,63 @@ export class BrowserToolsBroker {
|
||||
};
|
||||
}
|
||||
|
||||
private selectHostForNewTab(requestId: string, browserHostId: string | undefined): HostSelection {
|
||||
if (browserHostId !== undefined) {
|
||||
const host = this.clients.get(browserHostId);
|
||||
if (host) return { ok: true, value: host };
|
||||
return {
|
||||
ok: false,
|
||||
payload: browserToolsFailure({
|
||||
requestId,
|
||||
code: "browser_no_host",
|
||||
message:
|
||||
"The selected browser host is not connected. Call browser_list_hosts to choose a connected host.",
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
if (this.clients.size === 0)
|
||||
return { ok: false, payload: this.noBrowserHostFailure(requestId) };
|
||||
const eligible = Array.from(this.clients.values()).filter(({ target }) => target.canOpenTabs);
|
||||
if (eligible.length === 1) return { ok: true, value: eligible[0] };
|
||||
if (eligible.length === 0) {
|
||||
return {
|
||||
ok: false,
|
||||
payload: browserToolsFailure({
|
||||
requestId,
|
||||
code: "browser_unsupported",
|
||||
message: "None of the connected browser hosts support opening tabs.",
|
||||
}),
|
||||
};
|
||||
}
|
||||
return {
|
||||
ok: false,
|
||||
payload: browserToolsFailure({
|
||||
requestId,
|
||||
code: "browser_host_ambiguous",
|
||||
message: "Choose a browser host and retry with its browserHostId.",
|
||||
browserHosts: eligible.map(({ target }) => target),
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
private selectHostForTab(browserId: string, requestId: string): HostSelection {
|
||||
const browserHostId = this.browserHostByBrowserId.get(browserId);
|
||||
if (browserHostId) {
|
||||
const host = this.clients.get(browserHostId);
|
||||
private selectHostForCommand(
|
||||
command: BrowserAutomationCommand,
|
||||
requestId: string,
|
||||
):
|
||||
| { ok: true; value: RegisteredBrowserHost }
|
||||
| { ok: false; payload: BrowserToolsResponsePayload } {
|
||||
if (command.command === "new_tab") {
|
||||
const host = this.selectMostRecentlyRegisteredHost();
|
||||
return host
|
||||
? { ok: true, value: host }
|
||||
: { ok: false, payload: this.strandedBrowserTabFailure({ requestId, browserId }) };
|
||||
: { ok: false, payload: this.noBrowserHostFailure(requestId) };
|
||||
}
|
||||
|
||||
const firstHost = this.clients.values().next().value;
|
||||
if (!firstHost) {
|
||||
const browserId = getBrowserIdForCommand(command);
|
||||
if (!browserId) {
|
||||
const host = this.selectMostRecentlyRegisteredHost();
|
||||
return host
|
||||
? { ok: true, value: host }
|
||||
: { ok: false, payload: this.noBrowserHostFailure(requestId) };
|
||||
}
|
||||
|
||||
const ownerClientId = this.browserHostByBrowserId.get(browserId);
|
||||
if (ownerClientId) {
|
||||
const host = this.clients.get(ownerClientId);
|
||||
if (host) {
|
||||
return { ok: true, value: host };
|
||||
}
|
||||
return {
|
||||
ok: false,
|
||||
payload: this.strandedBrowserTabFailure({ requestId, browserId }),
|
||||
};
|
||||
}
|
||||
|
||||
const strandedOwnerClientId = this.strandedBrowserHostByBrowserId.get(browserId);
|
||||
if (strandedOwnerClientId) {
|
||||
const reconnectedHost = this.clients.get(strandedOwnerClientId);
|
||||
if (reconnectedHost) {
|
||||
this.strandedBrowserHostByBrowserId.delete(browserId);
|
||||
this.browserHostByBrowserId.set(browserId, strandedOwnerClientId);
|
||||
return { ok: true, value: reconnectedHost };
|
||||
}
|
||||
return {
|
||||
ok: false,
|
||||
payload: this.strandedBrowserTabFailure({ requestId, browserId }),
|
||||
};
|
||||
}
|
||||
|
||||
if (this.clients.size === 1) {
|
||||
const host = this.selectMostRecentlyRegisteredHost();
|
||||
if (host) {
|
||||
return { ok: true, value: host };
|
||||
}
|
||||
}
|
||||
|
||||
if (this.clients.size === 0) {
|
||||
return { ok: false, payload: this.noBrowserHostFailure(requestId) };
|
||||
}
|
||||
if (this.clients.size === 1) return { ok: true, value: firstHost };
|
||||
|
||||
return {
|
||||
ok: false,
|
||||
@@ -352,6 +332,14 @@ export class BrowserToolsBroker {
|
||||
};
|
||||
}
|
||||
|
||||
private selectMostRecentlyRegisteredHost(): RegisteredBrowserHost | null {
|
||||
let selected: RegisteredBrowserHost | null = null;
|
||||
for (const host of this.clients.values()) {
|
||||
selected = host;
|
||||
}
|
||||
return selected;
|
||||
}
|
||||
|
||||
private unsupportedCommandFailure(params: {
|
||||
host: RegisteredBrowserHost;
|
||||
commandName: BrowserAutomationCommandName;
|
||||
@@ -389,23 +377,30 @@ export class BrowserToolsBroker {
|
||||
}
|
||||
|
||||
private rememberBrowserHostForPayload(
|
||||
browserHostId: string,
|
||||
payload: Extract<BrowserAutomationExecuteResponse["payload"], { ok: true }>,
|
||||
clientId: string,
|
||||
payload: BrowserToolsResponsePayload,
|
||||
): void {
|
||||
if (!payload.ok) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (payload.result.command === "list_tabs") {
|
||||
for (const tab of payload.result.tabs) {
|
||||
this.browserHostByBrowserId.set(tab.browserId, browserHostId);
|
||||
this.browserHostByBrowserId.set(tab.browserId, clientId);
|
||||
this.strandedBrowserHostByBrowserId.delete(tab.browserId);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (payload.result.command === "close_tab") {
|
||||
this.browserHostByBrowserId.delete(payload.result.browserId);
|
||||
this.strandedBrowserHostByBrowserId.delete(payload.result.browserId);
|
||||
return;
|
||||
}
|
||||
|
||||
if ("browserId" in payload.result) {
|
||||
this.browserHostByBrowserId.set(payload.result.browserId, browserHostId);
|
||||
this.browserHostByBrowserId.set(payload.result.browserId, clientId);
|
||||
this.strandedBrowserHostByBrowserId.delete(payload.result.browserId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -434,7 +429,7 @@ export class BrowserToolsBroker {
|
||||
}, timeoutMs);
|
||||
|
||||
this.pending.set(request.requestId, {
|
||||
host,
|
||||
clientId: client.id,
|
||||
rememberAffinity: params.rememberAffinity ?? true,
|
||||
timeout,
|
||||
resolve,
|
||||
@@ -463,20 +458,11 @@ export class BrowserToolsBroker {
|
||||
}
|
||||
}
|
||||
|
||||
function attachBrowserHost(
|
||||
payload: BrowserAutomationExecuteResponse["payload"],
|
||||
target: BrowserHostTarget,
|
||||
): BrowserToolsResponsePayload {
|
||||
if (!payload.ok) return payload;
|
||||
const result = payload.result;
|
||||
if (result.command === "new_tab") {
|
||||
return { ...payload, result: { ...result, browserHost: target } };
|
||||
function getBrowserIdForCommand(command: BrowserAutomationCommand): string | null {
|
||||
if (command.command === "list_tabs" || command.command === "new_tab") {
|
||||
return null;
|
||||
}
|
||||
if (result.command === "list_tabs") {
|
||||
const tabs = result.tabs.map((tab) => ({ ...tab, browserHost: target }));
|
||||
return { ...payload, result: { ...result, tabs } };
|
||||
}
|
||||
return { ...payload, result };
|
||||
return command.args.browserId;
|
||||
}
|
||||
|
||||
function describeBrowserHost(host: RegisteredBrowserHost): string {
|
||||
|
||||
@@ -3,40 +3,14 @@ import type {
|
||||
BrowserAutomationExecuteResponse,
|
||||
} from "@getpaseo/protocol/browser-automation/rpc-schemas";
|
||||
|
||||
export interface BrowserHostTarget {
|
||||
readonly browserHostId: string;
|
||||
readonly label: string;
|
||||
readonly canOpenTabs: boolean;
|
||||
}
|
||||
|
||||
type BrowserHostResponse = BrowserAutomationExecuteResponse["payload"];
|
||||
type BrowserHostSuccess = Extract<BrowserHostResponse, { ok: true }>;
|
||||
type BrowserHostResult = BrowserHostSuccess["result"];
|
||||
type NewTabResult = Extract<BrowserHostResult, { command: "new_tab" }>;
|
||||
type ListTabsResult = Extract<BrowserHostResult, { command: "list_tabs" }>;
|
||||
type BrowserHostFailure = Extract<BrowserHostResponse, { ok: false }>;
|
||||
|
||||
export type BrowserToolsErrorPayload = Omit<BrowserHostFailure["error"], "code"> & {
|
||||
code: BrowserAutomationErrorCode | "browser_host_ambiguous";
|
||||
browserHosts?: BrowserHostTarget[];
|
||||
};
|
||||
|
||||
export type BrowserToolsResponsePayload =
|
||||
| (Omit<BrowserHostSuccess, "result"> & {
|
||||
result:
|
||||
| Exclude<BrowserHostResult, NewTabResult | ListTabsResult>
|
||||
| (NewTabResult & { browserHost: BrowserHostTarget })
|
||||
| (Omit<ListTabsResult, "tabs"> & {
|
||||
tabs: (ListTabsResult["tabs"][number] & { browserHost: BrowserHostTarget })[];
|
||||
});
|
||||
})
|
||||
| (Omit<BrowserHostFailure, "error"> & { error: BrowserToolsErrorPayload });
|
||||
export type BrowserToolsResponsePayload = BrowserAutomationExecuteResponse["payload"];
|
||||
export type BrowserToolsErrorPayload = Extract<BrowserToolsResponsePayload, { ok: false }>["error"];
|
||||
|
||||
export class BrowserToolsRequestError extends Error {
|
||||
public readonly code: BrowserAutomationErrorCode;
|
||||
public readonly retryable: boolean;
|
||||
|
||||
public constructor(error: BrowserHostFailure["error"]) {
|
||||
public constructor(error: BrowserToolsErrorPayload) {
|
||||
super(error.message);
|
||||
this.name = "BrowserToolsRequestError";
|
||||
this.code = error.code;
|
||||
@@ -46,10 +20,9 @@ export class BrowserToolsRequestError extends Error {
|
||||
|
||||
export function browserToolsFailure(params: {
|
||||
requestId: string;
|
||||
code: BrowserToolsErrorPayload["code"];
|
||||
code: BrowserAutomationErrorCode;
|
||||
message: string;
|
||||
retryable?: boolean;
|
||||
browserHosts?: BrowserHostTarget[];
|
||||
}): BrowserToolsResponsePayload {
|
||||
return {
|
||||
requestId: params.requestId,
|
||||
@@ -58,7 +31,6 @@ export function browserToolsFailure(params: {
|
||||
code: params.code,
|
||||
message: params.message,
|
||||
retryable: params.retryable ?? false,
|
||||
...(params.browserHosts ? { browserHosts: params.browserHosts } : {}),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
import { z } from "zod";
|
||||
import type { BrowserToolsExecuteInput } from "./broker.js";
|
||||
import type { BrowserToolsBroker, BrowserToolsExecuteInput } from "./broker.js";
|
||||
import type { BrowserToolsResponsePayload } from "./errors.js";
|
||||
import { registerBrowserTools, type RegisterBrowserToolsOptions } from "./tools.js";
|
||||
import type {
|
||||
@@ -10,11 +10,6 @@ import type {
|
||||
} from "../agent/tools/types.js";
|
||||
|
||||
const BROWSER_ID = "11111111-1111-4111-8111-111111111111";
|
||||
const BROWSER_HOST = {
|
||||
browserHostId: "22222222-2222-4222-8222-222222222222",
|
||||
label: "MacBook Pro · Window 1",
|
||||
canOpenTabs: true,
|
||||
};
|
||||
const BROWSER_ID_MESSAGE =
|
||||
"browserId must be a real id returned by browser_new_tab or browser_list_tabs";
|
||||
const WAIT_CONDITION_MESSAGE = "browser_wait requires exactly one of text or url";
|
||||
@@ -32,10 +27,6 @@ class FakeBrowserBroker {
|
||||
|
||||
public constructor(private response: BrowserToolsResponsePayload = listTabsPayload()) {}
|
||||
|
||||
public listBrowserHosts() {
|
||||
return [BROWSER_HOST];
|
||||
}
|
||||
|
||||
public setResponse(response: BrowserToolsResponsePayload): void {
|
||||
this.response = response;
|
||||
}
|
||||
@@ -62,7 +53,7 @@ class BrowserToolHarness {
|
||||
registerTool: (name, config, handler) => {
|
||||
this.tools.set(name, { config, handler });
|
||||
},
|
||||
broker: this.broker,
|
||||
broker: this.broker as Pick<BrowserToolsBroker, "execute">,
|
||||
...(this.callerAgentId ? { callerAgentId: this.callerAgentId } : {}),
|
||||
resolveCallerAgent: () => this.callerAgent,
|
||||
});
|
||||
@@ -109,7 +100,6 @@ function listTabsPayload(): Extract<BrowserToolsResponsePayload, { ok: true }> {
|
||||
tabs: [
|
||||
{
|
||||
browserId: BROWSER_ID,
|
||||
browserHost: BROWSER_HOST,
|
||||
url: "https://example.com",
|
||||
title: "Example",
|
||||
isActive: true,
|
||||
@@ -127,7 +117,6 @@ function newTabPayload(): Extract<BrowserToolsResponsePayload, { ok: true }> {
|
||||
result: {
|
||||
command: "new_tab",
|
||||
browserId: BROWSER_ID,
|
||||
browserHost: BROWSER_HOST,
|
||||
workspaceId: "wks_workspace_a",
|
||||
url: "https://example.com",
|
||||
},
|
||||
@@ -576,7 +565,6 @@ describe("registerBrowserTools", () => {
|
||||
const harness = new BrowserToolHarness();
|
||||
|
||||
expect(harness.toolNames()).toEqual([
|
||||
"browser_list_hosts",
|
||||
"browser_list_tabs",
|
||||
"browser_new_tab",
|
||||
"browser_snapshot",
|
||||
@@ -618,7 +606,7 @@ describe("registerBrowserTools", () => {
|
||||
expect(response.content).toEqual([
|
||||
{
|
||||
type: "text",
|
||||
text: `Found 1 Paseo browser tab. Use these browserId values for tab-scoped browser tools.\n- browserId=${BROWSER_ID} active title="Example" url=https://example.com host="${BROWSER_HOST.label}"`,
|
||||
text: `Found 1 Paseo browser tab. Use these browserId values for tab-scoped browser tools.\n- browserId=${BROWSER_ID} active title="Example" url=https://example.com`,
|
||||
},
|
||||
]);
|
||||
});
|
||||
@@ -640,48 +628,11 @@ describe("registerBrowserTools", () => {
|
||||
expect(response.content).toEqual([
|
||||
{
|
||||
type: "text",
|
||||
text: `Created browser tab browserId=${BROWSER_ID} url=https://example.com on ${BROWSER_HOST.label}. Use this browserId for tab-scoped browser tools.`,
|
||||
text: `Created browser tab browserId=${BROWSER_ID} url=https://example.com. Use this browserId for tab-scoped browser tools.`,
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
test("lists labeled browser hosts and passes the selected ID for new tabs", async () => {
|
||||
const harness = new BrowserToolHarness();
|
||||
const [host] = harness.broker.listBrowserHosts();
|
||||
const hosts = await harness.execute("browser_list_hosts", {});
|
||||
expect(hosts.structuredContent).toEqual({ browserHosts: [host] });
|
||||
expect(hosts.content).toEqual([
|
||||
{ type: "text", text: `Connected browser hosts\n- ${host.label} (${host.browserHostId})` },
|
||||
]);
|
||||
expect(harness.broker.calls).toEqual([]);
|
||||
|
||||
harness.broker.setResponse({
|
||||
requestId: "ambiguous",
|
||||
ok: false,
|
||||
error: {
|
||||
code: "browser_host_ambiguous",
|
||||
message: "Choose a browser host.",
|
||||
retryable: false,
|
||||
browserHosts: [host],
|
||||
},
|
||||
});
|
||||
const ambiguous = await harness.execute("browser_new_tab", {});
|
||||
expect(ambiguous.structuredContent).toMatchObject({
|
||||
ok: false,
|
||||
error: { code: "browser_host_ambiguous", browserHosts: [host] },
|
||||
});
|
||||
expect(ambiguous.content).toEqual([
|
||||
{ type: "text", text: `Choose a browser host.\n- ${host.label} (${host.browserHostId})` },
|
||||
]);
|
||||
|
||||
harness.broker.setResponse(newTabPayload());
|
||||
await harness.execute("browser_new_tab", { browserHostId: host.browserHostId });
|
||||
expect(harness.broker.calls.at(-1)).toMatchObject({
|
||||
browserHostId: host.browserHostId,
|
||||
command: { command: "new_tab", args: {} },
|
||||
});
|
||||
});
|
||||
|
||||
test.each([
|
||||
{
|
||||
name: "navigate accepts localhost without a scheme as http",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { z } from "zod";
|
||||
import { BrowserAutomationBrowserIdSchema } from "@getpaseo/protocol/browser-automation/rpc-schemas";
|
||||
import type { BrowserToolsBroker } from "./broker.js";
|
||||
import type { BrowserHostTarget, BrowserToolsResponsePayload } from "./errors.js";
|
||||
import type { BrowserToolsResponsePayload } from "./errors.js";
|
||||
import type {
|
||||
PaseoToolConfig,
|
||||
PaseoToolExecutionContext,
|
||||
@@ -24,7 +24,7 @@ export interface RegisterBrowserToolsOptions {
|
||||
context: PaseoToolExecutionContext,
|
||||
) => Promise<PaseoToolResult>,
|
||||
) => void;
|
||||
broker: Pick<BrowserToolsBroker, "execute" | "listBrowserHosts">;
|
||||
broker: Pick<BrowserToolsBroker, "execute">;
|
||||
callerAgentId?: string;
|
||||
resolveCallerAgent: () => CallerAgentContext | null;
|
||||
}
|
||||
@@ -64,24 +64,6 @@ const BrowserWaitInputSchema = z
|
||||
});
|
||||
|
||||
export function registerBrowserTools(options: RegisterBrowserToolsOptions): void {
|
||||
options.registerTool(
|
||||
"browser_list_hosts",
|
||||
{
|
||||
title: "List browser hosts",
|
||||
description:
|
||||
"List connected Paseo browser hosts, including hosts with no tabs. Use a browserHostId from this list to choose where browser_new_tab opens.",
|
||||
inputSchema: {},
|
||||
},
|
||||
async () => {
|
||||
const browserHosts = options.broker.listBrowserHosts();
|
||||
const text =
|
||||
browserHosts.length > 0
|
||||
? ["Connected browser hosts", ...browserHosts.map(formatBrowserHost)].join("\n")
|
||||
: "No browser hosts are connected.";
|
||||
return { content: [{ type: "text", text }], structuredContent: { browserHosts } };
|
||||
},
|
||||
);
|
||||
|
||||
options.registerTool(
|
||||
"browser_list_tabs",
|
||||
{
|
||||
@@ -114,20 +96,12 @@ export function registerBrowserTools(options: RegisterBrowserToolsOptions): void
|
||||
{
|
||||
title: "Create browser tab",
|
||||
description:
|
||||
"Open a background browser tab in this agent's workspace. Choose a browserHostId when multiple browser hosts can open tabs. Use the returned browserId for tab commands.",
|
||||
"Create a new Paseo browser tab in this agent's workspace on the most recently connected browser automation host, opened in the background without switching the user's view. Pass an http(s) URL or a scheme-less host URL, which is treated as http; the returned browserId is used by tab-scoped tools.",
|
||||
inputSchema: {
|
||||
url: BrowserHttpUrlInputSchema.optional().describe(
|
||||
"An HTTP or HTTPS URL. A URL without a scheme uses HTTP.",
|
||||
),
|
||||
browserHostId: z
|
||||
.string()
|
||||
.min(1)
|
||||
.max(128)
|
||||
.optional()
|
||||
.describe("Destination ID from browser_list_hosts."),
|
||||
url: BrowserHttpUrlInputSchema.optional(),
|
||||
},
|
||||
},
|
||||
async ({ url, browserHostId }) => {
|
||||
async ({ url }) => {
|
||||
const context = resolveBrowserToolContext(options);
|
||||
const missingWorkspace = requireWorkspaceContext(context);
|
||||
if (missingWorkspace) {
|
||||
@@ -137,7 +111,6 @@ export function registerBrowserTools(options: RegisterBrowserToolsOptions): void
|
||||
agentId: context.agentId,
|
||||
cwd: context.cwd,
|
||||
...(context.workspaceId ? { workspaceId: context.workspaceId } : {}),
|
||||
...(browserHostId ? { browserHostId } : {}),
|
||||
command: {
|
||||
command: "new_tab",
|
||||
args: url ? { url } : {},
|
||||
@@ -902,7 +875,7 @@ function summarizeBrowserSuccess(
|
||||
}
|
||||
const tabLines = payload.result.tabs.map((tab) => {
|
||||
const active = tab.isActive ? " active" : "";
|
||||
return `- browserId=${tab.browserId}${active} title=${JSON.stringify(tab.title || "Untitled")} url=${tab.url} host=${JSON.stringify(tab.browserHost.label)}`;
|
||||
return `- browserId=${tab.browserId}${active} title=${JSON.stringify(tab.title || "Untitled")} url=${tab.url}`;
|
||||
});
|
||||
return withDialogs(
|
||||
[
|
||||
@@ -914,7 +887,7 @@ function summarizeBrowserSuccess(
|
||||
|
||||
if (payload.result.command === "new_tab") {
|
||||
return withDialogs(
|
||||
`Created browser tab browserId=${payload.result.browserId} url=${payload.result.url} on ${payload.result.browserHost.label}. Use this browserId for tab-scoped browser tools.`,
|
||||
`Created browser tab browserId=${payload.result.browserId} url=${payload.result.url}. Use this browserId for tab-scoped browser tools.`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1068,14 +1041,7 @@ function summarizeBrowserError(
|
||||
return "Browser tools are disabled. Enable browser tools on the host, then try again.";
|
||||
case "browser_stale_ref":
|
||||
return "That browser element reference is stale. Take a new browser snapshot and try again.";
|
||||
case "browser_host_ambiguous":
|
||||
return [error.message, ...(error.browserHosts ?? []).map(formatBrowserHost)].join("\n");
|
||||
default:
|
||||
return error.message;
|
||||
}
|
||||
}
|
||||
|
||||
function formatBrowserHost(host: BrowserHostTarget): string {
|
||||
const capability = host.canOpenTabs ? "" : " (cannot open tabs)";
|
||||
return `- ${host.label} (${host.browserHostId})${capability}`;
|
||||
}
|
||||
|
||||
@@ -1407,8 +1407,6 @@ export class Session {
|
||||
type: "browser.host.register.request" as const,
|
||||
requestId: uuidv4(),
|
||||
hostKind: host.data.hostKind,
|
||||
label: host.data.label,
|
||||
instanceId: host.data.instanceId,
|
||||
supportedCommands: host.data.supportedCommands,
|
||||
};
|
||||
void this.delivery
|
||||
@@ -2573,8 +2571,6 @@ export class Session {
|
||||
unregister = this.browserToolsBroker.registerClient({
|
||||
id: owner.id,
|
||||
hostKind: request.hostKind,
|
||||
label: request.label,
|
||||
instanceId: request.instanceId,
|
||||
supportedCommands: request.supportedCommands,
|
||||
sendBrowserAutomationRequest: (message) => owner.emit(message),
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# LegendList 3.7.1 for the native chat timeline (docs/agent-stream-disclosure.md).
|
||||
# Upstream: https://github.com/LegendApp/legend-list/issues/593 covers changes 1–12 below.
|
||||
# Upstream: https://github.com/LegendApp/legend-list/issues/593 covers every change below.
|
||||
# react-native.js and react-native.mjs carry the same hunks; each has a "Paseo patch" comment.
|
||||
#
|
||||
# 1. getEstimatedItemSize (react-native.d.ts, getItemSize, LegendListInner props): a per-item
|
||||
@@ -34,8 +34,6 @@
|
||||
# of a shrink past the end from the new end, assuming the scroll view clamped first. The app's
|
||||
# scroll view clamps after the adjustment on both platforms (modules/paseo-scroll), so a
|
||||
# bottom-edge disclosure collapsing near the end landed at the end instead of in place.
|
||||
# 13. Recalculate the rendered range when drawDistance changes (LegendListInner). Chat uses
|
||||
# a small window for initial placement and schedules expansion after initial reveal.
|
||||
#
|
||||
# Upgrading: drop each hunk whose fix the new version ships, regenerate with
|
||||
# `npx patch-package @legendapp/list`, and copy this header back on top.
|
||||
@@ -56,7 +54,7 @@ index 983e937..970ba51 100644
|
||||
* Returns a stable item type used for pooling and size estimation.
|
||||
*/
|
||||
diff --git a/node_modules/@legendapp/list/react-native.js b/node_modules/@legendapp/list/react-native.js
|
||||
index eeb3fb0..33d6241 100644
|
||||
index eeb3fb0..5ebd8e9 100644
|
||||
--- a/node_modules/@legendapp/list/react-native.js
|
||||
+++ b/node_modules/@legendapp/list/react-native.js
|
||||
@@ -1497,7 +1497,15 @@ function getItemSize(ctx, key, index, data, useAverageSize, preferCachedSize, no
|
||||
@@ -346,24 +344,8 @@ index eeb3fb0..33d6241 100644
|
||||
getFixedItemSize: useWrapIfItem(getFixedItemSize),
|
||||
getItemType: useWrapIfItem(getItemType),
|
||||
hasExternalScroll,
|
||||
@@ -8549,6 +8618,15 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
||||
doMaintainScrollAtEnd(ctx);
|
||||
}
|
||||
}, [!!maintainScrollAtEndConfig]);
|
||||
+ // Paseo patch: the chat fills its offscreen buffer after its initial reveal.
|
||||
+ const previousDrawDistance = React2.useRef(drawDistance);
|
||||
+ React2.useLayoutEffect(() => {
|
||||
+ if (previousDrawDistance.current !== drawDistance) {
|
||||
+ previousDrawDistance.current = drawDistance;
|
||||
+ state.scrollForNextCalculateItemsInView = void 0;
|
||||
+ calculateItemsInView(ctx);
|
||||
+ }
|
||||
+ }, [drawDistance]);
|
||||
const previousAlwaysRenderIndices = React2.useRef(alwaysRenderIndices);
|
||||
React2.useLayoutEffect(() => {
|
||||
const previousPins = previousAlwaysRenderIndices.current;
|
||||
diff --git a/node_modules/@legendapp/list/react-native.mjs b/node_modules/@legendapp/list/react-native.mjs
|
||||
index fe5f415..8219839 100644
|
||||
index fe5f415..9788ce6 100644
|
||||
--- a/node_modules/@legendapp/list/react-native.mjs
|
||||
+++ b/node_modules/@legendapp/list/react-native.mjs
|
||||
@@ -1476,7 +1476,15 @@ function getItemSize(ctx, key, index, data, useAverageSize, preferCachedSize, no
|
||||
@@ -653,19 +635,3 @@ index fe5f415..8219839 100644
|
||||
getFixedItemSize: useWrapIfItem(getFixedItemSize),
|
||||
getItemType: useWrapIfItem(getItemType),
|
||||
hasExternalScroll,
|
||||
@@ -8528,6 +8597,15 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
|
||||
doMaintainScrollAtEnd(ctx);
|
||||
}
|
||||
}, [!!maintainScrollAtEndConfig]);
|
||||
+ // Paseo patch: the chat fills its offscreen buffer after its initial reveal.
|
||||
+ const previousDrawDistance = useRef(drawDistance);
|
||||
+ useLayoutEffect(() => {
|
||||
+ if (previousDrawDistance.current !== drawDistance) {
|
||||
+ previousDrawDistance.current = drawDistance;
|
||||
+ state.scrollForNextCalculateItemsInView = void 0;
|
||||
+ calculateItemsInView(ctx);
|
||||
+ }
|
||||
+ }, [drawDistance]);
|
||||
const previousAlwaysRenderIndices = useRef(alwaysRenderIndices);
|
||||
useLayoutEffect(() => {
|
||||
const previousPins = previousAlwaysRenderIndices.current;
|
||||
|
||||
@@ -20,15 +20,12 @@ Arguments marked `?` are optional.
|
||||
|
||||
## Tabs
|
||||
|
||||
| Tool | Arguments | Purpose |
|
||||
| -------------------- | -------------------------- | -------------------------------------------------------------------------- |
|
||||
| `browser_list_hosts` | — | List connected browser hosts by name and ID, including hosts with no tabs. |
|
||||
| `browser_list_tabs` | — | List workspace tabs and their browser hosts. |
|
||||
| `browser_new_tab` | `url?, browserHostId?` | Open a background tab and return its `browserId` and browser host. |
|
||||
| `browser_close_tab` | `browserId` | Close a tab and clean up its webview. |
|
||||
| `browser_resize` | `browserId, width, height` | Resize the tab's viewport — check a layout at phone or tablet dimensions. |
|
||||
|
||||
With one host that can open tabs, omit `browserHostId`. With several, pass an ID from `browser_list_hosts`. In Paseo Desktop, search for **Copy browser host name** in the Command Center. The result shows the same name the agent sees. Select it to copy the name. If the selected host is unavailable, list hosts again.
|
||||
| Tool | Arguments | Purpose |
|
||||
| ------------------- | -------------------------- | ------------------------------------------------------------------------- |
|
||||
| `browser_list_tabs` | — | List open tabs in the agent's workspace across connected hosts. |
|
||||
| `browser_new_tab` | `url?` | Open a tab in the background and return its `browserId`. |
|
||||
| `browser_close_tab` | `browserId` | Close a tab and clean up its webview. |
|
||||
| `browser_resize` | `browserId, width, height` | Resize the tab's viewport — check a layout at phone or tablet dimensions. |
|
||||
|
||||
## Reading the page
|
||||
|
||||
@@ -72,11 +69,10 @@ With one host that can open tabs, omit `browserHostId`. With several, pass an ID
|
||||
|
||||
Tools return structured errors rather than failing silently. The ones agents see most:
|
||||
|
||||
| Code | Meaning |
|
||||
| ------------------------ | ------------------------------------------------------------------------------- |
|
||||
| `browser_disabled` | Browser tools are turned off on this host. |
|
||||
| `browser_no_host` | There is no connected browser host, or the selected host disconnected. |
|
||||
| `browser_host_ambiguous` | Several hosts can open tabs. Choose one from the error and retry with its ID. |
|
||||
| `browser_stale_ref` | The ref no longer matches the page — take a new snapshot. |
|
||||
| `browser_timeout` | The element never became actionable, or the wait condition never held. |
|
||||
| `browser_denied` | The action isn't allowed — e.g. a non-`http(s)` URL, or no history to navigate. |
|
||||
| Code | Meaning |
|
||||
| ------------------- | ------------------------------------------------------------------------------- |
|
||||
| `browser_disabled` | Browser tools are turned off on this host. |
|
||||
| `browser_no_host` | No browser host (desktop app) is connected. Retryable. |
|
||||
| `browser_stale_ref` | The ref no longer matches the page — take a new snapshot. |
|
||||
| `browser_timeout` | The element never became actionable, or the wait condition never held. |
|
||||
| `browser_denied` | The action isn't allowed — e.g. a non-`http(s)` URL, or no history to navigate. |
|
||||
|
||||
@@ -18,15 +18,12 @@ nav: 工具参考
|
||||
|
||||
## 标签页 {#tabs}
|
||||
|
||||
| 工具 | 参数 | 用途 |
|
||||
| -------------------- | -------------------------- | -------------------------------------------------------------- |
|
||||
| `browser_list_hosts` | — | 按名称和 ID 列出已连接的浏览器宿主,包括尚未打开标签页的宿主。 |
|
||||
| `browser_list_tabs` | — | 列出工作区中的标签页及其浏览器宿主。 |
|
||||
| `browser_new_tab` | `url?, browserHostId?` | 在后台打开标签页,并返回它的 `browserId` 和浏览器宿主。 |
|
||||
| `browser_close_tab` | `browserId` | 关闭标签页并清理它的 webview。 |
|
||||
| `browser_resize` | `browserId, width, height` | 调整标签页视口大小,用手机或平板的尺寸检查布局。 |
|
||||
|
||||
如果只有一个宿主支持打开标签页,可以省略 `browserHostId`。如果有多个,请传入 `browser_list_hosts` 返回的 ID。在 Paseo Desktop 的命令中心搜索 **复制浏览器宿主名称**。结果会显示 Agent 看到的名称,选择该结果即可复制名称。如果选定的宿主不可用,请重新列出宿主。
|
||||
| 工具 | 参数 | 用途 |
|
||||
| ------------------- | -------------------------- | ------------------------------------------------- |
|
||||
| `browser_list_tabs` | — | 列出 Agent 工作区在所有已连接宿主上打开的标签页。 |
|
||||
| `browser_new_tab` | `url?` | 在后台打开一个标签页并返回它的 `browserId`。 |
|
||||
| `browser_close_tab` | `browserId` | 关闭标签页并清理它的 webview。 |
|
||||
| `browser_resize` | `browserId, width, height` | 调整标签页视口大小,用手机或平板的尺寸检查布局。 |
|
||||
|
||||
## 读取页面 {#reading-the-page}
|
||||
|
||||
@@ -70,11 +67,10 @@ nav: 工具参考
|
||||
|
||||
工具会返回结构化的错误,而不是静默失败。Agent 最常遇到的错误:
|
||||
|
||||
| 错误码 | 含义 |
|
||||
| ------------------------ | ------------------------------------------------------------------------------ |
|
||||
| `browser_disabled` | 该主机上的浏览器工具已关闭。 |
|
||||
| `browser_no_host` | 没有已连接的浏览器宿主,或选定的宿主已断开连接。 |
|
||||
| `browser_host_ambiguous` | 多个宿主支持打开标签页。请从错误返回的列表中选择一个宿主,并使用它的 ID 重试。 |
|
||||
| `browser_stale_ref` | 引用与页面不再匹配,请重新获取快照。 |
|
||||
| `browser_timeout` | 元素始终无法操作,或等待条件始终未满足。 |
|
||||
| `browser_denied` | 不允许该操作,例如非 `http(s)` 的 URL,或没有可导航的历史记录。 |
|
||||
| 错误码 | 含义 |
|
||||
| ------------------- | --------------------------------------------------------------- |
|
||||
| `browser_disabled` | 该主机上的浏览器工具已关闭。 |
|
||||
| `browser_no_host` | 没有已连接的浏览器宿主(桌面应用)。可以重试。 |
|
||||
| `browser_stale_ref` | 引用与页面不再匹配,请重新获取快照。 |
|
||||
| `browser_timeout` | 元素始终无法操作,或等待条件始终未满足。 |
|
||||
| `browser_denied` | 不允许该操作,例如非 `http(s)` 的 URL,或没有可导航的历史记录。 |
|
||||
|
||||
Reference in New Issue
Block a user