mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-19 06:45:15 +00:00
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0ad43e42c0 | ||
|
|
b72bdb6ab6 | ||
|
|
bbed041d64 | ||
|
|
41198e6a2c |
@@ -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
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ provider icon map. You do not need a core manifest entry or provider factory.
|
||||
|
||||
| Provider | Transport | Setup and limitations |
|
||||
| ----------- | ------------------------------------------ | ---------------------------------------------------------------- |
|
||||
| Antigravity | Installed `agy` CLI | [Antigravity](../public-docs/supported-providers/antigravity.md) |
|
||||
| Antigravity | ACP over the installed `agy acp` CLI | [Antigravity](../public-docs/supported-providers/antigravity.md) |
|
||||
| Muse Code | MSP over one `muse serve` host per session | [Muse Code](../public-docs/supported-providers/muse-code.md) |
|
||||
|
||||
## Provider-native session options
|
||||
|
||||
@@ -16,13 +16,6 @@ import {
|
||||
expectComposerFullscreenControls,
|
||||
} from "../support/helpers/composer";
|
||||
import { waitForSidebarHydration } from "../support/helpers/workspace-ui";
|
||||
import {
|
||||
seedTerminalProfiles,
|
||||
selectLaunchOption,
|
||||
terminalPromptInput,
|
||||
} from "../support/helpers/new-workspace-launch";
|
||||
|
||||
test.use({ channel: "chromium", launchOptions: { args: ["--use-fake-device-for-media-stream"] } });
|
||||
|
||||
type WebSocketMessage = string | Buffer;
|
||||
|
||||
@@ -261,82 +254,3 @@ test("dictation shortcut leaves retained fullscreen and exposes recording contro
|
||||
await agent.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
async function controlMicrophonePermission(page: Page) {
|
||||
const cdp = await page.context().newCDPSession(page);
|
||||
const { targetInfo } = await cdp.send("Target.getTargetInfo");
|
||||
const origin = new URL(page.url()).origin;
|
||||
return async (setting: "denied" | "granted") => {
|
||||
await cdp.send("Browser.setPermission", {
|
||||
permission: { name: "microphone" },
|
||||
setting,
|
||||
origin,
|
||||
browserContextId: targetInfo.browserContextId,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
function startDictationByMic(page: Page) {
|
||||
return page.getByRole("button", { name: "Start dictation", exact: true }).click();
|
||||
}
|
||||
|
||||
function expectDictationPermissionError(page: Page) {
|
||||
return expect(page.getByTestId("message-input-root").getByRole("alert")).toHaveText(
|
||||
"Allow microphone access and try again.",
|
||||
);
|
||||
}
|
||||
|
||||
test("keeps the draft and retries from the mic after access is restored", async ({ page }) => {
|
||||
const agent = await seedMockAgentWorkspace({
|
||||
repoPrefix: "dictation-permission-",
|
||||
title: "Dictation permission",
|
||||
});
|
||||
const draft = "Keep my draft";
|
||||
await installDictationFailureHarness(page);
|
||||
try {
|
||||
await openAgentRoute(page, agent);
|
||||
await expectComposerVisible(page);
|
||||
await fillComposerDraft(page, draft);
|
||||
|
||||
const setMicrophonePermission = await controlMicrophonePermission(page);
|
||||
await setMicrophonePermission("denied");
|
||||
await startDictationByMic(page);
|
||||
await expectDictationPermissionError(page);
|
||||
await expect(composerLocator(page)).toHaveValue(draft);
|
||||
|
||||
await setMicrophonePermission("granted");
|
||||
await startDictationByMic(page);
|
||||
await expect(page.getByRole("button", { name: "Cancel dictation", exact: true })).toBeVisible();
|
||||
await expect(page.getByText("Allow microphone access and try again.")).toHaveCount(0);
|
||||
await page.getByRole("button", { name: "Cancel dictation", exact: true }).click();
|
||||
await expect(composerLocator(page)).toHaveValue(draft);
|
||||
} finally {
|
||||
await agent.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test("shows dictation failure when the terminal prompt starts it by shortcut", async ({ page }) => {
|
||||
const workspace = await seedWorkspace({ repoPrefix: "terminal-dictation-permission-" });
|
||||
const profile = {
|
||||
id: "echo-prompt",
|
||||
name: "Echo prompt",
|
||||
command: "echo",
|
||||
args: ["{{{prompt}}}"],
|
||||
};
|
||||
const profiles = await seedTerminalProfiles([profile]);
|
||||
await installDictationFailureHarness(page);
|
||||
try {
|
||||
await gotoAppShell(page);
|
||||
await waitForSidebarHydration(page);
|
||||
await openNewWorkspaceComposer(page, workspace);
|
||||
await selectLaunchOption(page, profile.id);
|
||||
|
||||
const setMicrophonePermission = await controlMicrophonePermission(page);
|
||||
await setMicrophonePermission("denied");
|
||||
await terminalPromptInput(page).press("Control+d");
|
||||
await expectDictationPermissionError(page);
|
||||
} finally {
|
||||
await profiles.restore();
|
||||
await workspace.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
apply plugin: 'com.android.library'
|
||||
|
||||
group = 'sh.paseo.pressfeedback'
|
||||
version = '0.1.0'
|
||||
|
||||
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
|
||||
apply from: expoModulesCorePlugin
|
||||
applyKotlinExpoModulesCorePlugin()
|
||||
useCoreDependencies()
|
||||
useExpoPublishing()
|
||||
useDefaultAndroidSdkVersions()
|
||||
|
||||
android {
|
||||
namespace "sh.paseo.pressfeedback"
|
||||
defaultConfig {
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" />
|
||||
-39
@@ -1,39 +0,0 @@
|
||||
package sh.paseo.pressfeedback
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Color
|
||||
import android.graphics.Paint
|
||||
import expo.modules.kotlin.AppContext
|
||||
import expo.modules.kotlin.modules.Module
|
||||
import expo.modules.kotlin.modules.ModuleDefinition
|
||||
import expo.modules.kotlin.types.ColorCompat
|
||||
import expo.modules.kotlin.views.ExpoView
|
||||
|
||||
class PaseoPressFeedbackModule : Module() {
|
||||
override fun definition() = ModuleDefinition {
|
||||
Name("PaseoPressFeedback")
|
||||
View(PaseoPressFeedbackView::class) {
|
||||
Prop("tint") { view: PaseoPressFeedbackView, color: Color -> view.paint.color = ColorCompat.toArgb(color) }
|
||||
Prop("radius") { view: PaseoPressFeedbackView, radius: Double -> view.radius = radius.toFloat() * view.resources.displayMetrics.density }
|
||||
Prop("resetKey") { view: PaseoPressFeedbackView, key: String -> view.reset(key) }
|
||||
AsyncFunction("acknowledge") { view: PaseoPressFeedbackView -> view.acknowledge() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class PaseoPressFeedbackView(context: Context, appContext: AppContext) : ExpoView(context, appContext) {
|
||||
val paint = Paint(Paint.ANTI_ALIAS_FLAG)
|
||||
var radius = 0f
|
||||
private var acknowledged = false
|
||||
private var resetKey = ""
|
||||
init { setWillNotDraw(false); importantForAccessibility = IMPORTANT_FOR_ACCESSIBILITY_NO }
|
||||
fun acknowledge() { acknowledged = true; invalidate() }
|
||||
fun reset(key: String) {
|
||||
if (key != resetKey) { resetKey = key; acknowledged = false; invalidate() }
|
||||
}
|
||||
override fun onDraw(canvas: Canvas) {
|
||||
super.onDraw(canvas)
|
||||
if (acknowledged) canvas.drawRoundRect(0f, 0f, width.toFloat(), height.toFloat(), radius, radius, paint)
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"platforms": ["android", "ios"],
|
||||
"android": { "modules": ["sh.paseo.pressfeedback.PaseoPressFeedbackModule"] },
|
||||
"ios": { "modules": ["PaseoPressFeedbackModule"] }
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
export { useWorkspaceRowPress } from "./src/ui";
|
||||
@@ -1,22 +0,0 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'PaseoPressFeedback'
|
||||
s.version = '0.1.0'
|
||||
s.summary = 'Native accepted press feedback for Paseo'
|
||||
s.description = 'Paints accepted press feedback independently of React commits'
|
||||
s.license = 'Apache-2.0'
|
||||
s.author = 'Paseo'
|
||||
s.homepage = 'https://paseo.sh'
|
||||
s.platforms = { :ios => '15.1' }
|
||||
s.swift_version = '5.4'
|
||||
s.source = { :path => '.' }
|
||||
s.static_framework = true
|
||||
|
||||
s.dependency 'ExpoModulesCore'
|
||||
|
||||
s.pod_target_xcconfig = {
|
||||
'DEFINES_MODULE' => 'YES',
|
||||
'SWIFT_COMPILATION_MODE' => 'wholemodule'
|
||||
}
|
||||
|
||||
s.source_files = "**/*.{h,m,swift}"
|
||||
end
|
||||
@@ -1,33 +0,0 @@
|
||||
import ExpoModulesCore
|
||||
import UIKit
|
||||
|
||||
public class PaseoPressFeedbackModule: Module {
|
||||
public func definition() -> ModuleDefinition {
|
||||
Name("PaseoPressFeedback")
|
||||
View(PaseoPressFeedbackView.self) {
|
||||
Prop("tint") { (view: PaseoPressFeedbackView, color: UIColor) in view.tint = color }
|
||||
Prop("radius") { (view: PaseoPressFeedbackView, radius: Double) in view.radius = radius }
|
||||
Prop("resetKey") { (view: PaseoPressFeedbackView, key: String) in view.reset(key) }
|
||||
AsyncFunction("acknowledge") { (view: PaseoPressFeedbackView) in view.acknowledge() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final class PaseoPressFeedbackView: ExpoView {
|
||||
var tint = UIColor.clear
|
||||
var radius: Double = 0
|
||||
private var acknowledged = false
|
||||
private var resetKey = ""
|
||||
required init(appContext: AppContext? = nil) {
|
||||
super.init(appContext: appContext)
|
||||
isOpaque = false
|
||||
isUserInteractionEnabled = false
|
||||
}
|
||||
func acknowledge() { acknowledged = true; setNeedsDisplay() }
|
||||
func reset(_ key: String) {
|
||||
if key != resetKey { resetKey = key; acknowledged = false; setNeedsDisplay() }
|
||||
}
|
||||
override func draw(_ rect: CGRect) {
|
||||
if acknowledged { tint.setFill(); UIBezierPath(roundedRect: bounds, cornerRadius: radius).fill() }
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"name": "paseo-press-feedback",
|
||||
"version": "0.1.0",
|
||||
"private": true
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
import { expect, it } from "vitest";
|
||||
import { acceptWorkspaceRowPress, type WorkspaceRowPress } from "./accept";
|
||||
|
||||
function rowPress(overrides: Partial<WorkspaceRowPress> = {}) {
|
||||
const visible: string[] = [];
|
||||
const press: WorkspaceRowPress = {
|
||||
cancelled: false,
|
||||
native: true,
|
||||
selected: false,
|
||||
sidebar: "overlay",
|
||||
target: "agent-list",
|
||||
acknowledge: () => visible.push("row"),
|
||||
navigate: () => visible.push("workspace"),
|
||||
...overrides,
|
||||
};
|
||||
return { press, visible };
|
||||
}
|
||||
|
||||
it("acknowledges an accepted row before navigation starts", () => {
|
||||
const { press, visible } = rowPress();
|
||||
expect(acceptWorkspaceRowPress(press)).toBe(true);
|
||||
expect(visible).toEqual(["row", "workspace"]);
|
||||
});
|
||||
|
||||
it("does not acknowledge or navigate after scrolling or a long press claims the touch", () => {
|
||||
const { press, visible } = rowPress({ cancelled: true });
|
||||
expect(acceptWorkspaceRowPress(press)).toBe(false);
|
||||
expect(visible).toEqual([]);
|
||||
});
|
||||
|
||||
it("accepts only the first row while its selection closes the sidebar", () => {
|
||||
const { press, visible } = rowPress();
|
||||
press.navigate = () => {
|
||||
press.target = "agent";
|
||||
visible.push("workspace B");
|
||||
};
|
||||
expect(acceptWorkspaceRowPress(press)).toBe(true);
|
||||
expect(acceptWorkspaceRowPress(press)).toBe(false);
|
||||
expect(visible).toEqual(["row", "workspace B"]);
|
||||
});
|
||||
|
||||
it.each([
|
||||
{
|
||||
name: "open phone or tablet overlay",
|
||||
sidebar: "overlay",
|
||||
target: "agent-list",
|
||||
native: true,
|
||||
accepted: true,
|
||||
},
|
||||
{ name: "closing overlay", sidebar: "overlay", target: "agent", native: true, accepted: false },
|
||||
{
|
||||
name: "explorer covering an overlay",
|
||||
sidebar: "overlay",
|
||||
target: "file-explorer",
|
||||
native: true,
|
||||
accepted: false,
|
||||
},
|
||||
{ name: "docked sidebar", sidebar: "dock", target: "agent", native: true, accepted: true },
|
||||
{
|
||||
name: "docked sidebar beside explorer",
|
||||
sidebar: "dock",
|
||||
target: "file-explorer",
|
||||
native: true,
|
||||
accepted: true,
|
||||
},
|
||||
{ name: "hidden sidebar", sidebar: "hidden", target: "agent", native: true, accepted: false },
|
||||
{
|
||||
name: "suspended open overlay",
|
||||
sidebar: "suspended",
|
||||
target: "agent-list",
|
||||
native: true,
|
||||
accepted: true,
|
||||
},
|
||||
{
|
||||
name: "suspended closed overlay",
|
||||
sidebar: "suspended",
|
||||
target: "agent",
|
||||
native: true,
|
||||
accepted: false,
|
||||
},
|
||||
{
|
||||
name: "web sidebar independent of native panel target",
|
||||
sidebar: "overlay",
|
||||
target: "agent",
|
||||
native: false,
|
||||
accepted: true,
|
||||
},
|
||||
] as const)("uses the panel state for $name", ({ accepted, name: _, ...state }) => {
|
||||
const { press, visible } = rowPress(state);
|
||||
expect(acceptWorkspaceRowPress(press)).toBe(accepted);
|
||||
expect(visible).toEqual(accepted ? ["row", "workspace"] : []);
|
||||
});
|
||||
|
||||
it("does not leave an acknowledgement over an already selected docked row", () => {
|
||||
const { press, visible } = rowPress({ selected: true, sidebar: "dock", target: "agent" });
|
||||
expect(acceptWorkspaceRowPress(press)).toBe(true);
|
||||
expect(visible).toEqual(["workspace"]);
|
||||
});
|
||||
|
||||
it("still acknowledges a selected overlay row before the sidebar leaves", () => {
|
||||
const { press, visible } = rowPress({ selected: true });
|
||||
expect(acceptWorkspaceRowPress(press)).toBe(true);
|
||||
expect(visible).toEqual(["row", "workspace"]);
|
||||
});
|
||||
@@ -1,20 +0,0 @@
|
||||
import type { LeftSidebarPresentation, MobilePanelView } from "@/stores/panel-store";
|
||||
|
||||
export interface WorkspaceRowPress {
|
||||
cancelled: boolean;
|
||||
native: boolean;
|
||||
selected: boolean;
|
||||
sidebar: LeftSidebarPresentation;
|
||||
target: MobilePanelView;
|
||||
acknowledge(): void;
|
||||
navigate(): void;
|
||||
}
|
||||
|
||||
export function acceptWorkspaceRowPress(press: WorkspaceRowPress): boolean {
|
||||
if (press.cancelled) return false;
|
||||
if (press.native && press.sidebar !== "dock" && press.target !== "agent-list") return false;
|
||||
// A selected docked row neither changes selection nor leaves the screen to clear the fill.
|
||||
if (!press.selected || press.sidebar !== "dock") press.acknowledge();
|
||||
press.navigate();
|
||||
return true;
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
import { requireNativeView } from "expo";
|
||||
import { type Ref } from "react";
|
||||
import { usePanelStore } from "@/stores/panel-store";
|
||||
import { withUnistyles } from "react-native-unistyles";
|
||||
import { View, StyleSheet, type ViewProps } from "react-native";
|
||||
|
||||
export interface RowFeedbackHandle {
|
||||
acknowledge(): Promise<void>;
|
||||
}
|
||||
interface FeedbackProps extends ViewProps {
|
||||
ref?: Ref<RowFeedbackHandle>;
|
||||
resetKey: string;
|
||||
tint?: string;
|
||||
radius?: number;
|
||||
}
|
||||
const NativeFeedback = withUnistyles(requireNativeView<FeedbackProps>("PaseoPressFeedback"));
|
||||
const mapTheme = (theme: import("@/styles/theme").Theme) => ({
|
||||
tint: theme.colors.interactionHighlight,
|
||||
radius: theme.borderRadius.lg,
|
||||
});
|
||||
export function RowFeedback({
|
||||
ref,
|
||||
selected,
|
||||
}: {
|
||||
ref?: Ref<RowFeedbackHandle>;
|
||||
selected: boolean;
|
||||
}) {
|
||||
const revision = usePanelStore((state) => state.mobilePanel.revision);
|
||||
// Selection takes over the fill; a new panel transition clears it before reopening.
|
||||
const resetKey = `${selected}:${revision}`;
|
||||
return (
|
||||
<View pointerEvents="none" style={styles.overlay}>
|
||||
<NativeFeedback
|
||||
ref={ref}
|
||||
resetKey={resetKey}
|
||||
pointerEvents="none"
|
||||
style={styles.fill}
|
||||
uniProps={mapTheme}
|
||||
/>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
overlay: { position: "absolute", top: 0, right: 0, bottom: 0, left: 0 },
|
||||
fill: { flex: 1 },
|
||||
});
|
||||
@@ -1,7 +0,0 @@
|
||||
import type { Ref } from "react";
|
||||
export interface RowFeedbackHandle {
|
||||
acknowledge(): Promise<void>;
|
||||
}
|
||||
export function RowFeedback(_props: { ref?: Ref<RowFeedbackHandle>; selected: boolean }) {
|
||||
return null;
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
import { useCallback, useRef, type RefObject } from "react";
|
||||
import { isNative } from "@/constants/platform";
|
||||
import { usePanelStore } from "@/stores/panel-store";
|
||||
import { acceptWorkspaceRowPress } from "../accept";
|
||||
import { RowFeedback, type RowFeedbackHandle } from "./feedback";
|
||||
|
||||
export function useWorkspaceRowPress({
|
||||
didLongPressRef,
|
||||
onPress,
|
||||
selected,
|
||||
}: {
|
||||
didLongPressRef?: RefObject<boolean>;
|
||||
onPress(): void;
|
||||
selected: boolean;
|
||||
}) {
|
||||
const feedback = useRef<RowFeedbackHandle>(null);
|
||||
const handlePress = useCallback(() => {
|
||||
const cancelled = didLongPressRef?.current ?? false;
|
||||
if (didLongPressRef) didLongPressRef.current = false;
|
||||
const panel = usePanelStore.getState();
|
||||
acceptWorkspaceRowPress({
|
||||
cancelled,
|
||||
native: isNative,
|
||||
selected,
|
||||
sidebar: panel.layout.leftSidebar,
|
||||
target: panel.mobilePanel.target,
|
||||
// Paint on the native UI thread before navigation occupies JS; never wait for paint.
|
||||
acknowledge: () => {
|
||||
void feedback.current?.acknowledge();
|
||||
},
|
||||
navigate: onPress,
|
||||
});
|
||||
}, [didLongPressRef, onPress, selected]);
|
||||
return {
|
||||
onPress: handlePress,
|
||||
feedback: <RowFeedback ref={feedback} selected={selected} />,
|
||||
};
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
import { expect, it } from "vitest";
|
||||
import { createInitialDrawDistanceExpansion } from "./initial-draw-distance";
|
||||
|
||||
function mountInitialBuffer() {
|
||||
let nextId = 0;
|
||||
const pending = new Map<number, () => void>();
|
||||
const expansions: string[] = [];
|
||||
const buffer = createInitialDrawDistanceExpansion(
|
||||
{
|
||||
requestFrame(callback) {
|
||||
const id = ++nextId;
|
||||
pending.set(id, callback);
|
||||
return id;
|
||||
},
|
||||
cancelFrame(id) {
|
||||
pending.delete(id);
|
||||
},
|
||||
},
|
||||
() => expansions.push("full draw distance"),
|
||||
);
|
||||
function advanceFrame() {
|
||||
const callbacks = [...pending.values()];
|
||||
pending.clear();
|
||||
for (const callback of callbacks) callback();
|
||||
}
|
||||
return { buffer, expansions, advanceFrame };
|
||||
}
|
||||
|
||||
it("requests the full draw distance after two frame callbacks once the reveal is eligible", () => {
|
||||
const { buffer, expansions, advanceFrame } = mountInitialBuffer();
|
||||
buffer.schedule();
|
||||
advanceFrame();
|
||||
expect(expansions).toEqual([]);
|
||||
advanceFrame();
|
||||
expect(expansions).toEqual(["full draw distance"]);
|
||||
});
|
||||
|
||||
it.each([0, 1])(
|
||||
"leaves initial draw distance in place during a gesture after %i frames",
|
||||
(elapsed) => {
|
||||
const { buffer, expansions, advanceFrame } = mountInitialBuffer();
|
||||
buffer.schedule();
|
||||
if (elapsed === 1) advanceFrame();
|
||||
|
||||
buffer.pauseForScroll();
|
||||
advanceFrame();
|
||||
advanceFrame();
|
||||
expect(expansions).toEqual([]);
|
||||
|
||||
buffer.resumeAfterScroll();
|
||||
advanceFrame();
|
||||
expect(expansions).toEqual([]);
|
||||
advanceFrame();
|
||||
expect(expansions).toEqual(["full draw distance"]);
|
||||
},
|
||||
);
|
||||
|
||||
it("cancels a covered reveal and schedules again when it is eligible", () => {
|
||||
const { buffer, expansions, advanceFrame } = mountInitialBuffer();
|
||||
const cancel = buffer.schedule();
|
||||
advanceFrame();
|
||||
cancel();
|
||||
advanceFrame();
|
||||
expect(expansions).toEqual([]);
|
||||
|
||||
buffer.schedule();
|
||||
advanceFrame();
|
||||
advanceFrame();
|
||||
expect(expansions).toEqual(["full draw distance"]);
|
||||
});
|
||||
|
||||
it("keeps a covered list at its initial draw distance when a gesture ends", () => {
|
||||
const { buffer, expansions, advanceFrame } = mountInitialBuffer();
|
||||
buffer.pauseForScroll();
|
||||
const cover = buffer.schedule();
|
||||
advanceFrame();
|
||||
advanceFrame();
|
||||
expect(expansions).toEqual([]);
|
||||
|
||||
cover();
|
||||
buffer.resumeAfterScroll();
|
||||
advanceFrame();
|
||||
advanceFrame();
|
||||
expect(expansions).toEqual([]);
|
||||
});
|
||||
@@ -1,50 +0,0 @@
|
||||
interface InitialDrawDistanceFrames {
|
||||
requestFrame(callback: () => void): number;
|
||||
cancelFrame(id: number): void;
|
||||
}
|
||||
|
||||
export function createInitialDrawDistanceExpansion(
|
||||
frames: InitialDrawDistanceFrames,
|
||||
expand: () => void,
|
||||
) {
|
||||
let frame: number | null = null;
|
||||
let eligible = false;
|
||||
let scrolling = false;
|
||||
let expanded = false;
|
||||
|
||||
function cancel() {
|
||||
if (frame === null) return;
|
||||
frames.cancelFrame(frame);
|
||||
frame = null;
|
||||
}
|
||||
|
||||
function scheduleIfIdle() {
|
||||
if (!eligible || scrolling || expanded || frame !== null) return;
|
||||
frame = frames.requestFrame(() => {
|
||||
frame = frames.requestFrame(() => {
|
||||
frame = null;
|
||||
expanded = true;
|
||||
expand();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
schedule() {
|
||||
eligible = true;
|
||||
scheduleIfIdle();
|
||||
return () => {
|
||||
eligible = false;
|
||||
cancel();
|
||||
};
|
||||
},
|
||||
pauseForScroll() {
|
||||
scrolling = true;
|
||||
cancel();
|
||||
},
|
||||
resumeAfterScroll() {
|
||||
scrolling = false;
|
||||
scheduleIfIdle();
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -40,7 +40,6 @@ function wait(ms: number): Promise<void> {
|
||||
}
|
||||
|
||||
const LIST_STYLE = { flex: 1 };
|
||||
const ESTIMATED_LIST_SIZE = { width: 300, height: VIEWPORT_HEIGHT };
|
||||
const rowStyles = new Map<number, { height: number }>();
|
||||
|
||||
function rowStyle(height: number) {
|
||||
@@ -90,10 +89,6 @@ function keyExtractor(item: Row) {
|
||||
return item.id;
|
||||
}
|
||||
|
||||
function estimateRowSize(item: Row) {
|
||||
return item.height;
|
||||
}
|
||||
|
||||
function mountList(heldRowId: string) {
|
||||
const listRef = React.createRef<LegendListRef>();
|
||||
const maintainVisibleContentPosition = holdOnly(heldRowId);
|
||||
@@ -269,49 +264,3 @@ it("keeps measured row sizes while the list is not laid out", async () => {
|
||||
|
||||
expect(rows.map((row) => list.rowSize(row.id))).toEqual([40, 40, 40]);
|
||||
});
|
||||
|
||||
it("expands the draw distance of a placed end-anchored list without moving its bottom row", async () => {
|
||||
const rows: Row[] = Array.from({ length: 99 }, (_, index) => ({
|
||||
id: `row-${index}`,
|
||||
height: index % 2 === 0 ? 20 : 60,
|
||||
}));
|
||||
const lastRow = { id: "last-row", height: 180 };
|
||||
rows.push(lastRow);
|
||||
const listRef = React.createRef<LegendListRef>();
|
||||
|
||||
function render(drawDistance: number) {
|
||||
act(() => {
|
||||
root.render(
|
||||
<LegendList
|
||||
ref={listRef}
|
||||
data={rows}
|
||||
renderItem={renderRow}
|
||||
keyExtractor={keyExtractor}
|
||||
estimatedListSize={ESTIMATED_LIST_SIZE}
|
||||
recycleItems={false}
|
||||
getEstimatedItemSize={estimateRowSize}
|
||||
drawDistance={drawDistance}
|
||||
alignItemsAtEnd
|
||||
initialScrollAtEnd
|
||||
style={LIST_STYLE}
|
||||
/>,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
render(50);
|
||||
await wait(300);
|
||||
const initial = listRef.current?.getState();
|
||||
const lastRowTop = initial?.positionByKey(lastRow.id);
|
||||
expect(initial?.sizes.get(lastRow.id)).toBe(lastRow.height);
|
||||
expect(initial?.sizes.size).toBeLessThan(8);
|
||||
expect(initial?.scroll).toBe(Number(lastRowTop) + lastRow.height - VIEWPORT_HEIGHT);
|
||||
|
||||
render(1000);
|
||||
await wait(150);
|
||||
|
||||
const expanded = listRef.current?.getState();
|
||||
expect(expanded?.sizes.size).toBeGreaterThan(20);
|
||||
expect(expanded?.scroll).toBe(initial?.scroll);
|
||||
expect(expanded?.positionByKey(lastRow.id)).toBe(lastRowTop);
|
||||
});
|
||||
|
||||
@@ -9,7 +9,6 @@ import {
|
||||
useState,
|
||||
} from "react";
|
||||
import {
|
||||
Dimensions,
|
||||
View,
|
||||
type LayoutChangeEvent,
|
||||
type NativeScrollEvent,
|
||||
@@ -32,7 +31,6 @@ import { useTranslation } from "react-i18next";
|
||||
import type { StreamItem } from "@/types/stream";
|
||||
import type { Theme } from "@/styles/theme";
|
||||
import { useStableEvent } from "@/hooks/use-stable-event";
|
||||
import { useIsMobilePanelActive } from "@/mobile-panels/provider";
|
||||
import { shouldAnimateNativeScrollToBottom } from "./native-scroll-animation";
|
||||
import { useRevisedHistoryRows } from "./history-row-revision";
|
||||
import { useBottomAnchorController } from "./bottom-anchor-controller";
|
||||
@@ -45,7 +43,6 @@ import {
|
||||
} from "./native-disclosure-hold";
|
||||
import { EndPinnedScrollView } from "./native-end-pin";
|
||||
import { createNewRowEstimates } from "./new-row-estimates";
|
||||
import { createInitialDrawDistanceExpansion } from "./initial-draw-distance";
|
||||
import type {
|
||||
DisclosureTriggerEdge,
|
||||
StreamRenderInput,
|
||||
@@ -135,14 +132,6 @@ function keyExtractor(item: { id: string }): string {
|
||||
return item.id;
|
||||
}
|
||||
|
||||
function InitialDrawDistanceExpansion({ schedule }: { schedule: () => () => void }) {
|
||||
const isSidebarActive = useIsMobilePanelActive("agent-list");
|
||||
useLayoutEffect(() => {
|
||||
if (!isSidebarActive) return schedule();
|
||||
}, [schedule, isSidebarActive]);
|
||||
return null;
|
||||
}
|
||||
|
||||
function NativeStreamViewport(props: StreamRenderInput & { strategy: StreamStrategy }) {
|
||||
const {
|
||||
agentId,
|
||||
@@ -168,16 +157,6 @@ function NativeStreamViewport(props: StreamRenderInput & { strategy: StreamStrat
|
||||
strategy,
|
||||
} = props;
|
||||
const isActive = useRetainedPanelActive();
|
||||
// Keep a screenful in reserve for a fling that starts before the full buffer mounts.
|
||||
const [drawDistance, setDrawDistance] = useState(() =>
|
||||
Math.min(Dimensions.get("window").height, NATIVE_STREAM_DRAW_DISTANCE),
|
||||
);
|
||||
const [drawDistanceExpansion] = useState(() =>
|
||||
createInitialDrawDistanceExpansion(
|
||||
{ requestFrame: requestAnimationFrame, cancelFrame: cancelAnimationFrame },
|
||||
() => setDrawDistance(NATIVE_STREAM_DRAW_DISTANCE),
|
||||
),
|
||||
);
|
||||
const { t } = useTranslation();
|
||||
const { renderHistoryMountedRow, renderLiveHeadRow, renderLiveAuxiliary } = renderers;
|
||||
const listRef = useRef<LegendListRef>(null);
|
||||
@@ -590,9 +569,6 @@ function NativeStreamViewport(props: StreamRenderInput & { strategy: StreamStrat
|
||||
cancelDisclosureHold();
|
||||
bottomAnchorController.beginUserScroll();
|
||||
historyStartPagination.rearm();
|
||||
// The reserve follows the gesture. Expanding the buffer here shifted the measured
|
||||
// content and returned the viewport to the end during an Android fling.
|
||||
drawDistanceExpansion.pauseForScroll();
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
@@ -615,7 +591,6 @@ function NativeStreamViewport(props: StreamRenderInput & { strategy: StreamStrat
|
||||
bottomAnchorController.endUserScroll({
|
||||
isAtEnd: isReleasedAtEndRef.current || isAtEnd(),
|
||||
});
|
||||
drawDistanceExpansion.resumeAfterScroll();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -635,7 +610,6 @@ function NativeStreamViewport(props: StreamRenderInput & { strategy: StreamStrat
|
||||
bottomAnchorController.endUserScroll({
|
||||
isAtEnd: isReleasedAtEndRef.current || isScrollEventAtEnd(event),
|
||||
});
|
||||
drawDistanceExpansion.resumeAfterScroll();
|
||||
},
|
||||
);
|
||||
|
||||
@@ -758,11 +732,6 @@ function NativeStreamViewport(props: StreamRenderInput & { strategy: StreamStrat
|
||||
);
|
||||
}, [historyStartPaginationState, hasOlderHistory, retryHistoryStart, t]);
|
||||
|
||||
const canExpandDrawDistance =
|
||||
drawDistance < NATIVE_STREAM_DRAW_DISTANCE &&
|
||||
isActive &&
|
||||
isListPlaced &&
|
||||
historyStartPaginationState.visible;
|
||||
return (
|
||||
<View style={viewportStyle}>
|
||||
<LegendList<StreamItem>
|
||||
@@ -795,14 +764,11 @@ function NativeStreamViewport(props: StreamRenderInput & { strategy: StreamStrat
|
||||
recycleItems={false}
|
||||
alignItemsAtEnd
|
||||
initialScrollAtEnd
|
||||
drawDistance={drawDistance}
|
||||
drawDistance={NATIVE_STREAM_DRAW_DISTANCE}
|
||||
getEstimatedItemSize={getEstimatedItemSize}
|
||||
scrollEnabled={scrollEnabled}
|
||||
showsVerticalScrollIndicator
|
||||
/>
|
||||
{canExpandDrawDistance ? (
|
||||
<InitialDrawDistanceExpansion schedule={drawDistanceExpansion.schedule} />
|
||||
) : null}
|
||||
{!historyStartPaginationState.visible ? (
|
||||
<View pointerEvents="none" testID="agent-initial-fill" style={initialFillStyle}>
|
||||
<ThemedLoadingSpinner size="large" uniProps={foregroundMutedColorMapping} />
|
||||
|
||||
@@ -3,6 +3,7 @@ export interface AudioEngineCallbacks {
|
||||
onVolumeLevel(level: number): void;
|
||||
onInterruption?(): void;
|
||||
onCaptureAvailabilityChange?(available: boolean): void;
|
||||
onError?(error: Error): void;
|
||||
}
|
||||
|
||||
export interface AudioPlaybackSource {
|
||||
@@ -30,21 +31,3 @@ export interface AudioEngineOptions {
|
||||
traceLabel?: string;
|
||||
captureMode?: "conversation" | "dictation";
|
||||
}
|
||||
|
||||
export type AudioCaptureStartFailure =
|
||||
| "permissionDenied"
|
||||
| "insecureContext"
|
||||
| "unsupported"
|
||||
| "noMicrophone"
|
||||
| "startFailed";
|
||||
|
||||
export class AudioCaptureStartError extends Error {
|
||||
constructor(
|
||||
readonly reason: AudioCaptureStartFailure,
|
||||
message: string,
|
||||
options?: ErrorOptions,
|
||||
) {
|
||||
super(message, options);
|
||||
this.name = "AudioCaptureStartError";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,60 +1,239 @@
|
||||
import type { AudioEngine, AudioEngineCallbacks, AudioEngineOptions } from "./audio-engine-types";
|
||||
import type {
|
||||
AudioEngine,
|
||||
AudioEngineCallbacks,
|
||||
AudioEngineOptions,
|
||||
AudioPlaybackSource,
|
||||
} from "./audio-engine-types";
|
||||
|
||||
import { createAudioPlayer, setAudioModeAsync } from "expo-audio";
|
||||
import { File, Paths } from "expo-file-system";
|
||||
import { createPlaybackQueue } from "./playback";
|
||||
import { playFile } from "./file-playback";
|
||||
import { createNativeAudioEngine, type NativeAudioEngineDeps } from "./native-audio-engine";
|
||||
|
||||
// AVPlayer needs a file extension to recognize local encoded audio on iOS.
|
||||
const FILE_EXTENSIONS: Record<string, string> = {
|
||||
"audio/wav": "wav",
|
||||
"audio/x-wav": "wav",
|
||||
"audio/wave": "wav",
|
||||
"audio/mpeg": "mp3",
|
||||
"audio/mp3": "mp3",
|
||||
"audio/mp4": "m4a",
|
||||
"audio/aac": "aac",
|
||||
"audio/ogg": "ogg",
|
||||
"audio/flac": "flac",
|
||||
};
|
||||
|
||||
let nextFileId = 0;
|
||||
|
||||
async function playEncodedAudio(
|
||||
bytes: Uint8Array,
|
||||
mimeType: string,
|
||||
signal: AbortSignal,
|
||||
context: { isCaptureActive(): boolean },
|
||||
): Promise<number> {
|
||||
// Capture owns its audio session while active. File playback alone must not
|
||||
// initialize the microphone or the native two-way engine.
|
||||
if (!context.isCaptureActive()) {
|
||||
await setAudioModeAsync({
|
||||
playsInSilentMode: true,
|
||||
allowsRecording: false,
|
||||
interruptionMode: "duckOthers",
|
||||
interruptionModeAndroid: "duckOthers",
|
||||
});
|
||||
}
|
||||
if (signal.aborted) throw new Error("Playback stopped");
|
||||
const extension = FILE_EXTENSIONS[mimeType.split(";")[0].trim()] ?? "audio";
|
||||
const file = new File(Paths.cache, `paseo-audio-${Date.now()}-${nextFileId++}.${extension}`);
|
||||
try {
|
||||
file.write(bytes);
|
||||
const player = createAudioPlayer(file.uri, {
|
||||
updateInterval: 100,
|
||||
keepAudioSessionActive: context.isCaptureActive(),
|
||||
});
|
||||
return await playFile(player, signal);
|
||||
} finally {
|
||||
if (file.exists) file.delete();
|
||||
}
|
||||
}
|
||||
import { playPcm16 } from "./pcm";
|
||||
|
||||
export function createAudioEngine(
|
||||
callbacks: AudioEngineCallbacks,
|
||||
options?: AudioEngineOptions,
|
||||
): AudioEngine {
|
||||
const native: NativeAudioEngineDeps["native"] = require("@getpaseo/expo-two-way-audio");
|
||||
return createNativeAudioEngine({ native, playEncodedAudio }, callbacks, options);
|
||||
const native = require("@getpaseo/expo-two-way-audio");
|
||||
|
||||
const refs: {
|
||||
initialized: boolean;
|
||||
captureActive: boolean;
|
||||
muted: boolean;
|
||||
destroyed: boolean;
|
||||
} = {
|
||||
initialized: false,
|
||||
captureActive: false,
|
||||
muted: false,
|
||||
destroyed: false,
|
||||
};
|
||||
|
||||
const microphoneSubscription = native.addExpoTwoWayAudioEventListener(
|
||||
"onMicrophoneData",
|
||||
(event: { data: Uint8Array }) => {
|
||||
if (!refs.captureActive || refs.muted) {
|
||||
return;
|
||||
}
|
||||
const pcm = event.data;
|
||||
callbacks.onCaptureData(pcm);
|
||||
},
|
||||
);
|
||||
const volumeSubscription = native.addExpoTwoWayAudioEventListener(
|
||||
"onInputVolumeLevelData",
|
||||
(event: { data: number }) => {
|
||||
if (!refs.captureActive) {
|
||||
return;
|
||||
}
|
||||
const level = refs.muted ? 0 : event.data;
|
||||
callbacks.onVolumeLevel(level);
|
||||
},
|
||||
);
|
||||
const interruptionSubscription = native.addExpoTwoWayAudioEventListener(
|
||||
"onAudioInterruption",
|
||||
(event: { data: string }) => {
|
||||
if (event.data === "capture_paused" || event.data === "capture_resumed") {
|
||||
if (refs.captureActive) {
|
||||
callbacks.onCaptureAvailabilityChange?.(event.data === "capture_resumed");
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (event.data !== "blocked") {
|
||||
return;
|
||||
}
|
||||
const wasCaptureActive = refs.captureActive;
|
||||
refs.captureActive = false;
|
||||
refs.muted = false;
|
||||
callbacks.onVolumeLevel(0);
|
||||
if (wasCaptureActive) {
|
||||
callbacks.onInterruption?.();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
async function ensureInitialized(): Promise<void> {
|
||||
if (refs.initialized) {
|
||||
return;
|
||||
}
|
||||
const success = await native.initialize();
|
||||
if (!success) {
|
||||
throw new Error("expo-two-way-audio: native initialize() returned false");
|
||||
}
|
||||
refs.initialized = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Release the OS audio session as soon as we are neither capturing nor playing.
|
||||
* Holding it keeps the user's background music paused — on iOS the non-mixing
|
||||
* `.playAndRecord` category survives backgrounding and is re-asserted on every
|
||||
* foreground, so an unreleased session means their music never comes back.
|
||||
*/
|
||||
function releaseSessionIfIdle(): void {
|
||||
if (!refs.initialized || refs.destroyed) {
|
||||
return;
|
||||
}
|
||||
if (refs.captureActive || playback.isPlaying()) {
|
||||
return;
|
||||
}
|
||||
// The wrapper no-ops on binaries whose native module predates this function.
|
||||
native.releaseAudioSession();
|
||||
}
|
||||
|
||||
async function ensureMicrophonePermission(): Promise<void> {
|
||||
let permission = await native.getMicrophonePermissionsAsync().catch(() => null);
|
||||
if (!permission?.granted) {
|
||||
permission = await native.requestMicrophonePermissionsAsync().catch(() => null);
|
||||
}
|
||||
if (!permission?.granted) {
|
||||
throw new Error(
|
||||
"Microphone permission is required to capture audio. Please enable microphone access in system settings.",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
let nextFileId = 0;
|
||||
async function playAudio(audio: AudioPlaybackSource, signal: AbortSignal): Promise<number> {
|
||||
const bytes = new Uint8Array(await audio.arrayBuffer());
|
||||
if (signal.aborted) throw new Error("Playback stopped");
|
||||
if (audio.type.startsWith("audio/pcm")) {
|
||||
await ensureInitialized();
|
||||
return playPcm16(bytes, audio.type, signal, native);
|
||||
}
|
||||
// Capture owns its audio session while active. File playback alone must not
|
||||
// initialize the microphone or the native two-way engine.
|
||||
if (!refs.captureActive) {
|
||||
await setAudioModeAsync({
|
||||
playsInSilentMode: true,
|
||||
allowsRecording: false,
|
||||
interruptionMode: "duckOthers",
|
||||
interruptionModeAndroid: "duckOthers",
|
||||
});
|
||||
}
|
||||
if (signal.aborted) throw new Error("Playback stopped");
|
||||
// AVPlayer needs a file extension to recognize local encoded audio on iOS.
|
||||
const extension =
|
||||
{
|
||||
"audio/wav": "wav",
|
||||
"audio/x-wav": "wav",
|
||||
"audio/wave": "wav",
|
||||
"audio/mpeg": "mp3",
|
||||
"audio/mp3": "mp3",
|
||||
"audio/mp4": "m4a",
|
||||
"audio/aac": "aac",
|
||||
"audio/ogg": "ogg",
|
||||
"audio/flac": "flac",
|
||||
}[audio.type.split(";")[0].trim()] ?? "audio";
|
||||
const file = new File(Paths.cache, `paseo-audio-${Date.now()}-${nextFileId++}.${extension}`);
|
||||
try {
|
||||
file.write(bytes);
|
||||
const player = createAudioPlayer(file.uri, {
|
||||
updateInterval: 100,
|
||||
keepAudioSessionActive: refs.captureActive,
|
||||
});
|
||||
return await playFile(player, signal);
|
||||
} finally {
|
||||
if (file.exists) file.delete();
|
||||
}
|
||||
}
|
||||
const playback = createPlaybackQueue(playAudio, releaseSessionIfIdle);
|
||||
|
||||
return {
|
||||
async initialize() {
|
||||
await ensureInitialized();
|
||||
},
|
||||
|
||||
async destroy() {
|
||||
if (refs.destroyed) {
|
||||
return;
|
||||
}
|
||||
refs.destroyed = true;
|
||||
playback.destroy();
|
||||
if (refs.captureActive) {
|
||||
native.toggleRecording(false);
|
||||
refs.captureActive = false;
|
||||
}
|
||||
refs.muted = false;
|
||||
callbacks.onVolumeLevel(0);
|
||||
if (refs.initialized) {
|
||||
native.tearDown();
|
||||
refs.initialized = false;
|
||||
}
|
||||
microphoneSubscription.remove();
|
||||
volumeSubscription.remove();
|
||||
interruptionSubscription.remove();
|
||||
},
|
||||
|
||||
async startCapture() {
|
||||
if (refs.captureActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await ensureMicrophonePermission();
|
||||
await ensureInitialized();
|
||||
const isRecording =
|
||||
options?.captureMode === "dictation"
|
||||
? native.startDictation()
|
||||
: native.toggleRecording(true);
|
||||
if (!isRecording) {
|
||||
throw new Error(
|
||||
"Microphone capture could not start because Android audio focus is unavailable.",
|
||||
);
|
||||
}
|
||||
refs.captureActive = true;
|
||||
} catch (error) {
|
||||
const wrapped = error instanceof Error ? error : new Error(String(error));
|
||||
callbacks.onError?.(wrapped);
|
||||
throw wrapped;
|
||||
}
|
||||
},
|
||||
|
||||
async stopCapture() {
|
||||
if (refs.captureActive) {
|
||||
native.toggleRecording(false);
|
||||
}
|
||||
refs.captureActive = false;
|
||||
refs.muted = false;
|
||||
callbacks.onVolumeLevel(0);
|
||||
callbacks.onCaptureAvailabilityChange?.(true);
|
||||
releaseSessionIfIdle();
|
||||
},
|
||||
|
||||
toggleMute() {
|
||||
refs.muted = !refs.muted;
|
||||
if (refs.muted) {
|
||||
callbacks.onVolumeLevel(0);
|
||||
}
|
||||
return refs.muted;
|
||||
},
|
||||
|
||||
isMuted() {
|
||||
return refs.muted;
|
||||
},
|
||||
|
||||
play: playback.play,
|
||||
stop: playback.stop,
|
||||
clearQueue: playback.clearQueue,
|
||||
isPlaying: playback.isPlaying,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -292,7 +292,9 @@ export function createAudioEngine(
|
||||
refs.gain = gain;
|
||||
} catch (error) {
|
||||
await stopCapture();
|
||||
throw error;
|
||||
const wrapped = error instanceof Error ? error : new Error(String(error));
|
||||
callbacks.onError?.(wrapped);
|
||||
throw wrapped;
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
export { createAudioEngine } from "./audio-engine";
|
||||
export type { AudioEngine, AudioEngineCallbacks, AudioPlaybackSource } from "./audio-engine-types";
|
||||
export { createPlayAudio } from "./play-audio";
|
||||
export { AudioCaptureStartError, type AudioCaptureStartFailure } from "./audio-engine-types";
|
||||
|
||||
@@ -1,188 +0,0 @@
|
||||
import { expect, test } from "vitest";
|
||||
import type { AudioEngineCallbacks } from "./audio-engine-types";
|
||||
import { createNativeAudioEngine, type NativeAudioEngineDeps } from "./native-audio-engine";
|
||||
|
||||
// In-memory stand-in for `@getpaseo/expo-two-way-audio`, matching its iOS and Android modules:
|
||||
// one native engine per app, `initialize()` reuses it, `tearDown()` frees it, and
|
||||
// `toggleRecording(true)` / `startDictation()` return false while no engine exists.
|
||||
// Session handling follows iOS: recording activates the OS audio session, stopping does not
|
||||
// deactivate it, and `releaseAudioSession()` deactivates it only while nothing is recording.
|
||||
function fakeTwoWayAudio({
|
||||
captureAvailable = true,
|
||||
permissionRequestError,
|
||||
}: { captureAvailable?: boolean; permissionRequestError?: Error } = {}) {
|
||||
let engine: { recording: boolean; sessionActive: boolean } | null = null;
|
||||
const calls = { initialize: 0, tearDown: 0 };
|
||||
const native: NativeAudioEngineDeps["native"] = {
|
||||
async initialize() {
|
||||
calls.initialize += 1;
|
||||
engine ??= { recording: false, sessionActive: false };
|
||||
return true;
|
||||
},
|
||||
tearDown() {
|
||||
calls.tearDown += 1;
|
||||
engine = null;
|
||||
},
|
||||
toggleRecording(value: boolean) {
|
||||
if (!engine) return false;
|
||||
engine.recording = value;
|
||||
if (value) engine.sessionActive = true;
|
||||
return value;
|
||||
},
|
||||
startDictation() {
|
||||
if (!engine || !captureAvailable) return false;
|
||||
engine.recording = true;
|
||||
engine.sessionActive = true;
|
||||
return true;
|
||||
},
|
||||
releaseAudioSession() {
|
||||
if (engine && !engine.recording) engine.sessionActive = false;
|
||||
},
|
||||
playPCMData() {},
|
||||
resumePlayback() {},
|
||||
stopPlayback() {},
|
||||
async getMicrophonePermissionsAsync() {
|
||||
return { granted: !permissionRequestError };
|
||||
},
|
||||
async requestMicrophonePermissionsAsync() {
|
||||
if (permissionRequestError) throw permissionRequestError;
|
||||
return { granted: true };
|
||||
},
|
||||
addExpoTwoWayAudioEventListener() {
|
||||
return { remove() {} };
|
||||
},
|
||||
};
|
||||
return {
|
||||
native,
|
||||
calls,
|
||||
hasEngine: () => engine !== null,
|
||||
sessionActive: () => engine?.sessionActive ?? false,
|
||||
};
|
||||
}
|
||||
|
||||
const recordingCallbacks: AudioEngineCallbacks = {
|
||||
onCaptureData() {},
|
||||
onVolumeLevel() {},
|
||||
};
|
||||
|
||||
function deps(native: NativeAudioEngineDeps["native"]): NativeAudioEngineDeps {
|
||||
return {
|
||||
native,
|
||||
playEncodedAudio: async () => 0,
|
||||
};
|
||||
}
|
||||
|
||||
// Issue #4147: on iPhone, voice mode failed with "Android audio focus is unavailable"
|
||||
// after the dictation engine was destroyed.
|
||||
test("voice capture starts after the dictation engine is destroyed", async () => {
|
||||
const fake = fakeTwoWayAudio();
|
||||
const voiceEngine = createNativeAudioEngine(deps(fake.native), recordingCallbacks);
|
||||
await voiceEngine.initialize();
|
||||
|
||||
const dictationEngine = createNativeAudioEngine(deps(fake.native), recordingCallbacks, {
|
||||
captureMode: "dictation",
|
||||
});
|
||||
await dictationEngine.startCapture();
|
||||
await dictationEngine.stopCapture();
|
||||
await dictationEngine.destroy();
|
||||
|
||||
await expect(voiceEngine.startCapture()).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
test("destroying dictation while voice is capturing keeps the native engine", async () => {
|
||||
const fake = fakeTwoWayAudio();
|
||||
const voiceEngine = createNativeAudioEngine(deps(fake.native), recordingCallbacks);
|
||||
await voiceEngine.startCapture();
|
||||
|
||||
const dictationEngine = createNativeAudioEngine(deps(fake.native), recordingCallbacks, {
|
||||
captureMode: "dictation",
|
||||
});
|
||||
await dictationEngine.initialize();
|
||||
await dictationEngine.destroy();
|
||||
|
||||
expect(fake.hasEngine()).toBe(true);
|
||||
expect(fake.calls.tearDown).toBe(0);
|
||||
});
|
||||
|
||||
// Review on #9051: with voice holding the engine, destroying an active dictation engine must
|
||||
// still hand back the idle OS audio session so background music resumes (#2866).
|
||||
test("destroying active dictation releases the idle audio session while voice keeps the engine", async () => {
|
||||
const fake = fakeTwoWayAudio();
|
||||
const voiceEngine = createNativeAudioEngine(deps(fake.native), recordingCallbacks);
|
||||
await voiceEngine.initialize();
|
||||
|
||||
const dictationEngine = createNativeAudioEngine(deps(fake.native), recordingCallbacks, {
|
||||
captureMode: "dictation",
|
||||
});
|
||||
await dictationEngine.startCapture();
|
||||
await dictationEngine.destroy();
|
||||
|
||||
expect(fake.hasEngine()).toBe(true);
|
||||
expect(fake.sessionActive()).toBe(false);
|
||||
});
|
||||
|
||||
test("destroying dictation does not release the session while voice is recording", async () => {
|
||||
const fake = fakeTwoWayAudio();
|
||||
const voiceEngine = createNativeAudioEngine(deps(fake.native), recordingCallbacks);
|
||||
await voiceEngine.startCapture();
|
||||
|
||||
const dictationEngine = createNativeAudioEngine(deps(fake.native), recordingCallbacks, {
|
||||
captureMode: "dictation",
|
||||
});
|
||||
await dictationEngine.initialize();
|
||||
await dictationEngine.destroy();
|
||||
|
||||
expect(fake.sessionActive()).toBe(true);
|
||||
});
|
||||
|
||||
test("destroying the last engine tears the native engine down", async () => {
|
||||
const fake = fakeTwoWayAudio();
|
||||
const voiceEngine = createNativeAudioEngine(deps(fake.native), recordingCallbacks);
|
||||
const dictationEngine = createNativeAudioEngine(deps(fake.native), recordingCallbacks, {
|
||||
captureMode: "dictation",
|
||||
});
|
||||
await voiceEngine.initialize();
|
||||
await dictationEngine.initialize();
|
||||
|
||||
await dictationEngine.destroy();
|
||||
await voiceEngine.destroy();
|
||||
|
||||
expect(fake.calls.tearDown).toBe(1);
|
||||
expect(fake.hasEngine()).toBe(false);
|
||||
});
|
||||
|
||||
test("an engine destroyed while initializing does not keep the native engine", async () => {
|
||||
const fake = fakeTwoWayAudio();
|
||||
const engine = createNativeAudioEngine(deps(fake.native), recordingCallbacks);
|
||||
|
||||
const initializing = expect(engine.initialize()).rejects.toThrow("Audio engine destroyed");
|
||||
await engine.destroy();
|
||||
await initializing;
|
||||
|
||||
expect(fake.hasEngine()).toBe(false);
|
||||
});
|
||||
|
||||
test("a failed native recording start rejects with a platform-neutral error", async () => {
|
||||
const fake = fakeTwoWayAudio({ captureAvailable: false });
|
||||
const engine = createNativeAudioEngine(deps(fake.native), recordingCallbacks, {
|
||||
captureMode: "dictation",
|
||||
});
|
||||
|
||||
await expect(engine.startCapture()).rejects.toThrow(/^Microphone capture could not start\.$/);
|
||||
await engine.destroy();
|
||||
});
|
||||
|
||||
test("a failed native permission request retains the permission reason and original error", async () => {
|
||||
const permissionRequestError = new Error("The current activity is not available.");
|
||||
const fake = fakeTwoWayAudio({ permissionRequestError });
|
||||
const engine = createNativeAudioEngine(deps(fake.native), recordingCallbacks, {
|
||||
captureMode: "dictation",
|
||||
});
|
||||
|
||||
await expect(engine.startCapture()).rejects.toMatchObject({
|
||||
reason: "permissionDenied",
|
||||
cause: permissionRequestError,
|
||||
});
|
||||
expect(fake.hasEngine()).toBe(false);
|
||||
await engine.destroy();
|
||||
});
|
||||
@@ -1,292 +0,0 @@
|
||||
import type {
|
||||
AudioEngine,
|
||||
AudioEngineCallbacks,
|
||||
AudioEngineOptions,
|
||||
AudioPlaybackSource,
|
||||
} from "./audio-engine-types";
|
||||
|
||||
import { AudioCaptureStartError } from "./audio-engine-types";
|
||||
import { createNativeEngineLease, type NativeEngineLease } from "./native-engine-lease";
|
||||
import { createPlaybackQueue } from "./playback";
|
||||
import { playPcm16 } from "./pcm";
|
||||
|
||||
interface NativeSubscription {
|
||||
remove(): void;
|
||||
}
|
||||
|
||||
interface MicrophonePermission {
|
||||
granted: boolean;
|
||||
}
|
||||
|
||||
/** The surface of `@getpaseo/expo-two-way-audio` the engine drives. */
|
||||
export interface TwoWayAudioModule {
|
||||
initialize(): Promise<boolean>;
|
||||
tearDown(): void;
|
||||
toggleRecording(value: boolean): boolean;
|
||||
startDictation(): boolean;
|
||||
releaseAudioSession(): void;
|
||||
playPCMData(data: Uint8Array): void;
|
||||
getMicrophonePermissionsAsync(): Promise<MicrophonePermission>;
|
||||
requestMicrophonePermissionsAsync(): Promise<MicrophonePermission>;
|
||||
addExpoTwoWayAudioEventListener(
|
||||
event: "onMicrophoneData",
|
||||
listener: (event: { data: Uint8Array }) => void,
|
||||
): NativeSubscription;
|
||||
addExpoTwoWayAudioEventListener(
|
||||
event: "onInputVolumeLevelData",
|
||||
listener: (event: { data: number }) => void,
|
||||
): NativeSubscription;
|
||||
addExpoTwoWayAudioEventListener(
|
||||
event: "onAudioInterruption",
|
||||
listener: (event: { data: string }) => void,
|
||||
): NativeSubscription;
|
||||
}
|
||||
|
||||
export interface NativeAudioEngineDeps {
|
||||
native: TwoWayAudioModule & Parameters<typeof playPcm16>[3];
|
||||
/** Plays encoded audio (wav, mp3, ...) through the platform player. */
|
||||
playEncodedAudio(
|
||||
bytes: Uint8Array,
|
||||
mimeType: string,
|
||||
signal: AbortSignal,
|
||||
context: { isCaptureActive(): boolean },
|
||||
): Promise<number>;
|
||||
}
|
||||
|
||||
// Voice mode and dictation each create an engine, but the native module holds a single engine
|
||||
// per app. Every JS engine on the same module shares one lease, so one engine's teardown
|
||||
// cannot free the native engine another still uses (#4147).
|
||||
const leases = new WeakMap<TwoWayAudioModule, NativeEngineLease>();
|
||||
|
||||
function leaseFor(native: TwoWayAudioModule): NativeEngineLease {
|
||||
let lease = leases.get(native);
|
||||
if (!lease) {
|
||||
lease = createNativeEngineLease(native);
|
||||
leases.set(native, lease);
|
||||
}
|
||||
return lease;
|
||||
}
|
||||
|
||||
export function createNativeAudioEngine(
|
||||
deps: NativeAudioEngineDeps,
|
||||
callbacks: AudioEngineCallbacks,
|
||||
options?: AudioEngineOptions,
|
||||
): AudioEngine {
|
||||
const { native } = deps;
|
||||
const lease = leaseFor(native);
|
||||
|
||||
const refs: {
|
||||
initialized: boolean;
|
||||
captureActive: boolean;
|
||||
muted: boolean;
|
||||
destroyed: boolean;
|
||||
} = {
|
||||
initialized: false,
|
||||
captureActive: false,
|
||||
muted: false,
|
||||
destroyed: false,
|
||||
};
|
||||
|
||||
const microphoneSubscription = native.addExpoTwoWayAudioEventListener(
|
||||
"onMicrophoneData",
|
||||
(event: { data: Uint8Array }) => {
|
||||
if (!refs.captureActive || refs.muted) {
|
||||
return;
|
||||
}
|
||||
const pcm = event.data;
|
||||
callbacks.onCaptureData(pcm);
|
||||
},
|
||||
);
|
||||
const volumeSubscription = native.addExpoTwoWayAudioEventListener(
|
||||
"onInputVolumeLevelData",
|
||||
(event: { data: number }) => {
|
||||
if (!refs.captureActive) {
|
||||
return;
|
||||
}
|
||||
const level = refs.muted ? 0 : event.data;
|
||||
callbacks.onVolumeLevel(level);
|
||||
},
|
||||
);
|
||||
const interruptionSubscription = native.addExpoTwoWayAudioEventListener(
|
||||
"onAudioInterruption",
|
||||
(event: { data: string }) => {
|
||||
if (event.data === "capture_paused" || event.data === "capture_resumed") {
|
||||
if (refs.captureActive) {
|
||||
callbacks.onCaptureAvailabilityChange?.(event.data === "capture_resumed");
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (event.data !== "blocked") {
|
||||
return;
|
||||
}
|
||||
const wasCaptureActive = refs.captureActive;
|
||||
refs.captureActive = false;
|
||||
refs.muted = false;
|
||||
callbacks.onVolumeLevel(0);
|
||||
if (wasCaptureActive) {
|
||||
callbacks.onInterruption?.();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
let initializing: Promise<void> | null = null;
|
||||
async function ensureInitialized(): Promise<void> {
|
||||
if (refs.destroyed) {
|
||||
throw new Error("Audio engine destroyed");
|
||||
}
|
||||
if (refs.initialized) {
|
||||
return;
|
||||
}
|
||||
initializing ??= (async () => {
|
||||
try {
|
||||
await lease.acquire();
|
||||
if (refs.destroyed) {
|
||||
releaseNativeEngine();
|
||||
throw new Error("Audio engine destroyed");
|
||||
}
|
||||
refs.initialized = true;
|
||||
} finally {
|
||||
initializing = null;
|
||||
}
|
||||
})();
|
||||
await initializing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Release the OS audio session as soon as we are neither capturing nor playing.
|
||||
* Holding it keeps the user's background music paused — on iOS the non-mixing
|
||||
* `.playAndRecord` category survives backgrounding and is re-asserted on every
|
||||
* foreground, so an unreleased session means their music never comes back.
|
||||
*/
|
||||
function releaseSessionIfIdle(): void {
|
||||
if (!refs.initialized || refs.destroyed) {
|
||||
return;
|
||||
}
|
||||
if (refs.captureActive || playback.isPlaying()) {
|
||||
return;
|
||||
}
|
||||
// The wrapper no-ops on binaries whose native module predates this function.
|
||||
native.releaseAudioSession();
|
||||
}
|
||||
|
||||
async function ensureMicrophonePermission(): Promise<void> {
|
||||
const permission = await native.getMicrophonePermissionsAsync().catch(() => null);
|
||||
if (permission?.granted) return;
|
||||
|
||||
let cause: unknown;
|
||||
try {
|
||||
if ((await native.requestMicrophonePermissionsAsync()).granted) return;
|
||||
} catch (error) {
|
||||
cause = error;
|
||||
}
|
||||
throw new AudioCaptureStartError(
|
||||
"permissionDenied",
|
||||
"Allow microphone access in system settings and try again.",
|
||||
{ cause },
|
||||
);
|
||||
}
|
||||
|
||||
function releaseNativeEngine(): void {
|
||||
try {
|
||||
// Native keeps the session active while any wrapper is capturing or playing.
|
||||
native.releaseAudioSession();
|
||||
} finally {
|
||||
lease.release();
|
||||
}
|
||||
}
|
||||
|
||||
async function playAudio(audio: AudioPlaybackSource, signal: AbortSignal): Promise<number> {
|
||||
const bytes = new Uint8Array(await audio.arrayBuffer());
|
||||
if (signal.aborted) throw new Error("Playback stopped");
|
||||
if (audio.type.startsWith("audio/pcm")) {
|
||||
await ensureInitialized();
|
||||
if (signal.aborted) throw new Error("Playback stopped");
|
||||
return playPcm16(bytes, audio.type, signal, native);
|
||||
}
|
||||
return deps.playEncodedAudio(bytes, audio.type, signal, {
|
||||
isCaptureActive: () => refs.captureActive,
|
||||
});
|
||||
}
|
||||
const playback = createPlaybackQueue(playAudio, releaseSessionIfIdle);
|
||||
|
||||
return {
|
||||
async initialize() {
|
||||
await ensureInitialized();
|
||||
},
|
||||
|
||||
async destroy() {
|
||||
if (refs.destroyed) {
|
||||
return;
|
||||
}
|
||||
refs.destroyed = true;
|
||||
try {
|
||||
playback.destroy();
|
||||
if (refs.captureActive) {
|
||||
refs.captureActive = false;
|
||||
native.toggleRecording(false);
|
||||
}
|
||||
refs.muted = false;
|
||||
callbacks.onVolumeLevel(0);
|
||||
} finally {
|
||||
microphoneSubscription.remove();
|
||||
volumeSubscription.remove();
|
||||
interruptionSubscription.remove();
|
||||
if (refs.initialized) {
|
||||
refs.initialized = false;
|
||||
releaseNativeEngine();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
async startCapture() {
|
||||
if (refs.captureActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
await ensureMicrophonePermission();
|
||||
await ensureInitialized();
|
||||
if (refs.destroyed) {
|
||||
throw new Error("Audio engine destroyed");
|
||||
}
|
||||
if (refs.captureActive) {
|
||||
return;
|
||||
}
|
||||
const isRecording =
|
||||
options?.captureMode === "dictation"
|
||||
? native.startDictation()
|
||||
: native.toggleRecording(true);
|
||||
if (!isRecording) {
|
||||
throw new Error("Microphone capture could not start.");
|
||||
}
|
||||
refs.captureActive = true;
|
||||
},
|
||||
|
||||
async stopCapture() {
|
||||
if (refs.captureActive) {
|
||||
native.toggleRecording(false);
|
||||
}
|
||||
refs.captureActive = false;
|
||||
refs.muted = false;
|
||||
callbacks.onVolumeLevel(0);
|
||||
callbacks.onCaptureAvailabilityChange?.(true);
|
||||
releaseSessionIfIdle();
|
||||
},
|
||||
|
||||
toggleMute() {
|
||||
refs.muted = !refs.muted;
|
||||
if (refs.muted) {
|
||||
callbacks.onVolumeLevel(0);
|
||||
}
|
||||
return refs.muted;
|
||||
},
|
||||
|
||||
isMuted() {
|
||||
return refs.muted;
|
||||
},
|
||||
|
||||
play: playback.play,
|
||||
stop: playback.stop,
|
||||
clearQueue: playback.clearQueue,
|
||||
isPlaying: playback.isPlaying,
|
||||
};
|
||||
}
|
||||
@@ -1,116 +0,0 @@
|
||||
import { expect, test } from "vitest";
|
||||
import { createNativeEngineLease, type NativeAudioEngineLifecycle } from "./native-engine-lease";
|
||||
|
||||
// Mirrors the iOS and Android modules: one engine per app, `initialize()` reuses it,
|
||||
// `tearDown()` frees it, and `toggleRecording(true)` returns false once it is gone.
|
||||
function fakeNativeModule(options: { initializeResult?: boolean } = {}) {
|
||||
let engine: object | null = null;
|
||||
const calls = { initialize: 0, tearDown: 0 };
|
||||
let finishInitialize: (() => void) | null = null;
|
||||
let deferInitialize = false;
|
||||
const native: NativeAudioEngineLifecycle & {
|
||||
toggleRecording(value: boolean): boolean;
|
||||
} = {
|
||||
initialize() {
|
||||
calls.initialize += 1;
|
||||
const complete = () => {
|
||||
if (options.initializeResult === false) {
|
||||
return false;
|
||||
}
|
||||
engine ??= {};
|
||||
return true;
|
||||
};
|
||||
if (!deferInitialize) {
|
||||
return Promise.resolve(complete());
|
||||
}
|
||||
return new Promise<boolean>((resolve) => {
|
||||
finishInitialize = () => resolve(complete());
|
||||
});
|
||||
},
|
||||
tearDown() {
|
||||
calls.tearDown += 1;
|
||||
engine = null;
|
||||
},
|
||||
toggleRecording(value: boolean) {
|
||||
return engine !== null && value;
|
||||
},
|
||||
};
|
||||
return {
|
||||
native,
|
||||
calls,
|
||||
deferNextInitialize() {
|
||||
deferInitialize = true;
|
||||
},
|
||||
finishInitialize() {
|
||||
finishInitialize?.();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
test("dictation releasing the engine keeps it for voice mode", async () => {
|
||||
const fake = fakeNativeModule();
|
||||
const lease = createNativeEngineLease(fake.native);
|
||||
|
||||
await lease.acquire(); // voice mode
|
||||
await lease.acquire(); // dictation
|
||||
lease.release(); // dictation unmounts
|
||||
|
||||
expect(fake.calls.tearDown).toBe(0);
|
||||
expect(fake.native.toggleRecording(true)).toBe(true);
|
||||
});
|
||||
|
||||
test("the last release tears the native engine down and the next acquire rebuilds it", async () => {
|
||||
const fake = fakeNativeModule();
|
||||
const lease = createNativeEngineLease(fake.native);
|
||||
|
||||
await lease.acquire();
|
||||
lease.release();
|
||||
expect(fake.calls.tearDown).toBe(1);
|
||||
expect(fake.native.toggleRecording(true)).toBe(false);
|
||||
|
||||
await lease.acquire();
|
||||
expect(fake.calls.initialize).toBe(2);
|
||||
expect(fake.native.toggleRecording(true)).toBe(true);
|
||||
});
|
||||
|
||||
test("concurrent acquires share one native initialize", async () => {
|
||||
const fake = fakeNativeModule();
|
||||
fake.deferNextInitialize();
|
||||
const lease = createNativeEngineLease(fake.native);
|
||||
|
||||
const first = lease.acquire();
|
||||
const second = lease.acquire();
|
||||
fake.finishInitialize();
|
||||
await Promise.all([first, second]);
|
||||
|
||||
expect(fake.calls.initialize).toBe(1);
|
||||
lease.release();
|
||||
expect(fake.calls.tearDown).toBe(0);
|
||||
lease.release();
|
||||
expect(fake.calls.tearDown).toBe(1);
|
||||
});
|
||||
|
||||
test("a failed initialize is not counted as a holder and can be retried", async () => {
|
||||
const fake = fakeNativeModule({ initializeResult: false });
|
||||
const lease = createNativeEngineLease(fake.native);
|
||||
|
||||
await expect(lease.acquire()).rejects.toThrow("native initialize() returned false");
|
||||
lease.release();
|
||||
expect(fake.calls.tearDown).toBe(0);
|
||||
|
||||
await expect(lease.acquire()).rejects.toThrow();
|
||||
expect(fake.calls.initialize).toBe(2);
|
||||
});
|
||||
|
||||
test("a release with no holders is a no-op", async () => {
|
||||
const fake = fakeNativeModule();
|
||||
const lease = createNativeEngineLease(fake.native);
|
||||
|
||||
await lease.acquire();
|
||||
lease.release();
|
||||
lease.release();
|
||||
await lease.acquire();
|
||||
lease.release();
|
||||
|
||||
expect(fake.calls.tearDown).toBe(2);
|
||||
});
|
||||
@@ -1,57 +0,0 @@
|
||||
/**
|
||||
* The part of `@getpaseo/expo-two-way-audio` that owns the native engine's lifetime.
|
||||
* Each platform keeps a single engine per app: `initialize()` reuses it, `tearDown()` frees it.
|
||||
*/
|
||||
export interface NativeAudioEngineLifecycle {
|
||||
initialize(): Promise<boolean>;
|
||||
tearDown(): void;
|
||||
}
|
||||
|
||||
export interface NativeEngineLease {
|
||||
/** Ensure the native engine exists and count the caller as a holder. */
|
||||
acquire(): Promise<void>;
|
||||
/** Drop one holder; the native engine is torn down when the last holder releases. */
|
||||
release(): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Voice mode and dictation each create their own JS audio engine, but both drive the one
|
||||
* native engine. Counting holders keeps one consumer's teardown from freeing the engine
|
||||
* the other still uses (issue #4147: voice mode on iOS could not start after dictation).
|
||||
*/
|
||||
export function createNativeEngineLease(native: NativeAudioEngineLifecycle): NativeEngineLease {
|
||||
let holders = 0;
|
||||
let ready: Promise<void> | null = null;
|
||||
|
||||
async function initialize(): Promise<void> {
|
||||
const success = await native.initialize();
|
||||
if (!success) {
|
||||
throw new Error("expo-two-way-audio: native initialize() returned false");
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
async acquire() {
|
||||
holders += 1;
|
||||
ready ??= initialize();
|
||||
try {
|
||||
await ready;
|
||||
} catch (error) {
|
||||
holders -= 1;
|
||||
ready = null;
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
release() {
|
||||
if (holders === 0) {
|
||||
return;
|
||||
}
|
||||
holders -= 1;
|
||||
if (holders === 0) {
|
||||
ready = null;
|
||||
native.tearDown();
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import { useTranslation } from "react-i18next";
|
||||
import {
|
||||
CalendarClock,
|
||||
CircleDashed,
|
||||
Copy,
|
||||
Folder,
|
||||
FolderPlus,
|
||||
History,
|
||||
@@ -18,8 +17,6 @@ import {
|
||||
} from "lucide-react-native";
|
||||
import { withUnistyles } from "react-native-unistyles";
|
||||
import { useIsCompactFormFactor } from "@/constants/layout";
|
||||
import { useToast } from "@/contexts/toast-context";
|
||||
import { getDesktopHost } from "@/desktop/host";
|
||||
import { useKeyboardShortcutOverrides } from "@/hooks/use-keyboard-shortcut-overrides";
|
||||
import { useOpenAddProject } from "@/hooks/use-open-add-project";
|
||||
import { useImportSession } from "@/hooks/use-import-session";
|
||||
@@ -30,7 +27,6 @@ import { useKeyboardShortcutsStore } from "@/stores/keyboard-shortcuts-store";
|
||||
import { usePanelStore } from "@/stores/panel-store";
|
||||
import { useSidebarViewStore } from "@/stores/sidebar-view-store";
|
||||
import { clearCommandCenterFocusRestoreElement } from "@/utils/command-center-focus-restore";
|
||||
import { copyToClipboard } from "@/utils/copy-to-clipboard";
|
||||
import {
|
||||
buildOpenProjectRoute,
|
||||
buildSchedulesRoute,
|
||||
@@ -39,7 +35,6 @@ import {
|
||||
} from "@/utils/host-routes";
|
||||
import { getShortcutOs } from "@/utils/shortcut-platform";
|
||||
import type { CommandCenterContribution, CommandCenterIconProps } from "./contributions";
|
||||
import { getCommandCenterIcon } from "./icon";
|
||||
import { useCommandCenterActions } from "./provider";
|
||||
import { buildGroupingContribution } from "./root-contributions";
|
||||
|
||||
@@ -68,7 +63,6 @@ const ThemedCircleDashed = withUnistyles(CircleDashed, (theme) => ({
|
||||
const ThemedPanelLeft = withUnistyles(PanelLeft, (theme) => ({
|
||||
color: theme.colors.foregroundMuted,
|
||||
}));
|
||||
const BrowserHostCopyIcon = getCommandCenterIcon(Copy);
|
||||
|
||||
function PlusIcon({ size }: CommandCenterIconProps) {
|
||||
return <ThemedPlus size={size} strokeWidth={2.4} />;
|
||||
@@ -117,8 +111,6 @@ function PanelLeftIcon({ size }: CommandCenterIconProps) {
|
||||
export function CommandCenterRootActions() {
|
||||
const keyboardActionDispatcher = useKeyboardActionDispatcher();
|
||||
const { t } = useTranslation();
|
||||
const toast = useToast();
|
||||
const browserHostLabel = getDesktopHost()?.browserHostLabel;
|
||||
const { overrides } = useKeyboardShortcutOverrides();
|
||||
const shortcutsAvailable = useHardwareKeyboardPresent();
|
||||
const openAddProject = useOpenAddProject();
|
||||
@@ -304,32 +296,6 @@ export function CommandCenterRootActions() {
|
||||
},
|
||||
];
|
||||
|
||||
if (browserHostLabel) {
|
||||
availableActions.push({
|
||||
id: "copy-browser-host-name",
|
||||
group: "actions",
|
||||
groupRank: 0,
|
||||
rank: 9,
|
||||
keywords: ["browser", "host", "window", browserHostLabel],
|
||||
visibility: "query",
|
||||
run: async () => {
|
||||
try {
|
||||
await copyToClipboard(browserHostLabel);
|
||||
toast.copied();
|
||||
} catch {
|
||||
toast.error(t("common.errors.unableToCopy"));
|
||||
}
|
||||
},
|
||||
presentation: {
|
||||
kind: "action",
|
||||
title: t("shell.commandCenter.copyBrowserHostName"),
|
||||
subtitle: browserHostLabel,
|
||||
sectionTitle: t("shell.commandCenter.actions"),
|
||||
icon: BrowserHostCopyIcon,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (shortcutsAvailable) {
|
||||
availableActions.push({
|
||||
id: "keyboard-shortcuts",
|
||||
@@ -366,7 +332,6 @@ export function CommandCenterRootActions() {
|
||||
|
||||
return availableActions;
|
||||
}, [
|
||||
browserHostLabel,
|
||||
groupMode,
|
||||
homeRoute,
|
||||
keyboardActionDispatcher,
|
||||
@@ -381,7 +346,6 @@ export function CommandCenterRootActions() {
|
||||
shortcutPlatform,
|
||||
shortcutsAvailable,
|
||||
t,
|
||||
toast,
|
||||
toggleAgentList,
|
||||
]);
|
||||
|
||||
|
||||
@@ -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}
|
||||
>
|
||||
|
||||
@@ -1624,8 +1624,6 @@ export const MessageInput = forwardRef<MessageInputRef, MessageInputProps>(
|
||||
volume: dictationVolume,
|
||||
duration: dictationDuration,
|
||||
error: dictationError,
|
||||
startError: dictationStartError,
|
||||
clearStartError: clearDictationStartError,
|
||||
status: dictationStatus,
|
||||
startDictation,
|
||||
cancelDictation,
|
||||
@@ -1662,29 +1660,17 @@ export const MessageInput = forwardRef<MessageInputRef, MessageInputProps>(
|
||||
sendAfterTranscriptRef.current = false;
|
||||
}, [dictationStatus, isDictating, isDictationProcessing]);
|
||||
|
||||
useEffect(() => {
|
||||
if (showRealtimeOverlay) {
|
||||
clearDictationStartError();
|
||||
}
|
||||
}, [showRealtimeOverlay, clearDictationStartError]);
|
||||
|
||||
const startDictationIfAvailable = useCallback(() => {
|
||||
clearDictationStartError();
|
||||
return startDictationIfAvailableImpl({
|
||||
dictationUnavailableMessage,
|
||||
canStartDictation,
|
||||
toast,
|
||||
startDictation,
|
||||
exitFullscreen,
|
||||
});
|
||||
}, [
|
||||
canStartDictation,
|
||||
clearDictationStartError,
|
||||
dictationUnavailableMessage,
|
||||
startDictation,
|
||||
toast,
|
||||
exitFullscreen,
|
||||
]);
|
||||
const startDictationIfAvailable = useCallback(
|
||||
() =>
|
||||
startDictationIfAvailableImpl({
|
||||
dictationUnavailableMessage,
|
||||
canStartDictation,
|
||||
toast,
|
||||
startDictation,
|
||||
exitFullscreen,
|
||||
}),
|
||||
[canStartDictation, dictationUnavailableMessage, startDictation, toast, exitFullscreen],
|
||||
);
|
||||
|
||||
const handleVoicePress = useCallback(
|
||||
() =>
|
||||
@@ -2238,50 +2224,43 @@ export const MessageInput = forwardRef<MessageInputRef, MessageInputProps>(
|
||||
);
|
||||
const toolbar = useMemo(
|
||||
() => (
|
||||
<>
|
||||
{!isFullscreen && !showOverlay && dictationStartError ? (
|
||||
<Text accessibilityRole="alert" style={styles.dictationStartError}>
|
||||
{t(`message.dictation.${dictationStartError}`)}
|
||||
</Text>
|
||||
) : null}
|
||||
<View style={isFullscreen ? styles.hiddenToolbar : buttonRowStyle}>
|
||||
{/* Toolbar left: attachment button + agent controls */}
|
||||
<View style={styles.leftButtonGroup}>
|
||||
{!isFullscreen && (
|
||||
<AttachmentDropdown
|
||||
visible={mode.showAttachments}
|
||||
isConnected={isConnected}
|
||||
disabled={disabled}
|
||||
attachButtonStyle={attachButtonStyle}
|
||||
renderAttachButtonIcon={renderAttachButtonIcon}
|
||||
attachmentMenuItems={attachmentMenuItems}
|
||||
addAttachmentLabel={t("composer.input.addAttachment")}
|
||||
/>
|
||||
)}
|
||||
{leftContent}
|
||||
</View>
|
||||
|
||||
{/* Right: dictation, then the trailing action (voice mode, send or stop) */}
|
||||
<View style={isFullscreen ? styles.hiddenToolbar : buttonRowStyle}>
|
||||
{/* Toolbar left: attachment button + agent controls */}
|
||||
<View style={styles.leftButtonGroup}>
|
||||
{!isFullscreen && (
|
||||
<View style={styles.rightButtonGroup}>
|
||||
{beforeVoiceContent}
|
||||
<VoiceButtonTooltip
|
||||
visible={mode.showVoice}
|
||||
onVoicePress={handleVoicePress}
|
||||
isDictationStartEnabled={isDictationStartEnabled}
|
||||
voiceButtonAccessibilityLabel={voiceButtonAccessibilityLabel}
|
||||
voiceButtonStyle={voiceButtonStyle}
|
||||
renderVoiceButtonIcon={renderVoiceButtonIcon}
|
||||
voiceTooltipText={voiceTooltipText}
|
||||
isRealtimeVoiceForCurrentAgent={isRealtimeVoiceForCurrentAgent}
|
||||
voiceMuteToggleKeys={voiceMuteToggleKeys}
|
||||
dictationToggleKeys={dictationToggleKeys}
|
||||
/>
|
||||
<View style={styles.trailingDisc}>{sendButton}</View>
|
||||
</View>
|
||||
<AttachmentDropdown
|
||||
visible={mode.showAttachments}
|
||||
isConnected={isConnected}
|
||||
disabled={disabled}
|
||||
attachButtonStyle={attachButtonStyle}
|
||||
renderAttachButtonIcon={renderAttachButtonIcon}
|
||||
attachmentMenuItems={attachmentMenuItems}
|
||||
addAttachmentLabel={t("composer.input.addAttachment")}
|
||||
/>
|
||||
)}
|
||||
{leftContent}
|
||||
</View>
|
||||
</>
|
||||
|
||||
{/* Right: dictation, then the trailing action (voice mode, send or stop) */}
|
||||
{!isFullscreen && (
|
||||
<View style={styles.rightButtonGroup}>
|
||||
{beforeVoiceContent}
|
||||
<VoiceButtonTooltip
|
||||
visible={mode.showVoice}
|
||||
onVoicePress={handleVoicePress}
|
||||
isDictationStartEnabled={isDictationStartEnabled}
|
||||
voiceButtonAccessibilityLabel={voiceButtonAccessibilityLabel}
|
||||
voiceButtonStyle={voiceButtonStyle}
|
||||
renderVoiceButtonIcon={renderVoiceButtonIcon}
|
||||
voiceTooltipText={voiceTooltipText}
|
||||
isRealtimeVoiceForCurrentAgent={isRealtimeVoiceForCurrentAgent}
|
||||
voiceMuteToggleKeys={voiceMuteToggleKeys}
|
||||
dictationToggleKeys={dictationToggleKeys}
|
||||
/>
|
||||
<View style={styles.trailingDisc}>{sendButton}</View>
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
),
|
||||
[
|
||||
buttonRowStyle,
|
||||
@@ -2296,8 +2275,6 @@ export const MessageInput = forwardRef<MessageInputRef, MessageInputProps>(
|
||||
leftContent,
|
||||
beforeVoiceContent,
|
||||
mode.showVoice,
|
||||
showOverlay,
|
||||
dictationStartError,
|
||||
handleVoicePress,
|
||||
isDictationStartEnabled,
|
||||
voiceButtonAccessibilityLabel,
|
||||
@@ -2500,12 +2477,6 @@ const styles = StyleSheet.create((theme: Theme) => ({
|
||||
alignItems: "center",
|
||||
justifyContent: "space-between",
|
||||
},
|
||||
dictationStartError: {
|
||||
alignSelf: "flex-end",
|
||||
textAlign: "right",
|
||||
color: theme.colors.destructive,
|
||||
fontSize: theme.fontSize.sm,
|
||||
},
|
||||
leftButtonGroup: {
|
||||
minWidth: 0,
|
||||
flexShrink: 1,
|
||||
|
||||
@@ -130,6 +130,9 @@ export function VoiceProvider({ children }: VoiceProviderProps) {
|
||||
console.error("[VoiceEngine] Failed to stop after audio interruption:", error);
|
||||
});
|
||||
},
|
||||
onError: (error) => {
|
||||
console.error("[VoiceEngine] Capture error:", error);
|
||||
},
|
||||
});
|
||||
|
||||
runtime = createVoiceRuntime({
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { BROWSER_AUTOMATION_COMMAND_NAMES } from "@getpaseo/protocol/browser-automation/rpc-schemas";
|
||||
import type { DaemonClient } from "@getpaseo/client/internal/daemon-client";
|
||||
import type { SessionInboundMessage, SessionOutboundMessage } from "@getpaseo/protocol/messages";
|
||||
import { getDesktopHost, type DesktopHostBridge } from "@/desktop/host";
|
||||
import {
|
||||
@@ -27,7 +26,6 @@ type BrowserAutomationExecuteResponse = Extract<
|
||||
type BrowserAutomationResponsePayload = BrowserAutomationExecuteResponse["payload"];
|
||||
type BrowserAutomationFailurePayload = Extract<BrowserAutomationResponsePayload, { ok: false }>;
|
||||
type BrowserAutomationErrorCode = BrowserAutomationFailurePayload["error"]["code"];
|
||||
type BrowserHostRegistration = Parameters<DaemonClient["registerBrowserHost"]>[0];
|
||||
|
||||
interface BrowserAutomationClient {
|
||||
on(
|
||||
@@ -71,24 +69,14 @@ export function mountBrowserAutomationHandler(
|
||||
};
|
||||
}
|
||||
|
||||
export function getDesktopBrowserHostRegistration(): BrowserHostRegistration | null {
|
||||
const desktop = getDesktopHost();
|
||||
if (typeof desktop?.browser?.executeAutomationCommand !== "function") return null;
|
||||
|
||||
return {
|
||||
hostKind: "desktop app",
|
||||
label: desktop.browserHostLabel,
|
||||
instanceId: desktop.browserHostInstanceId,
|
||||
supportedCommands: [...BROWSER_AUTOMATION_COMMAND_NAMES],
|
||||
};
|
||||
}
|
||||
|
||||
export function mountBrowserAutomationDaemonClientHandler(
|
||||
client: DaemonClient,
|
||||
registration: BrowserHostRegistration,
|
||||
client: import("@getpaseo/client/internal/daemon-client").DaemonClient,
|
||||
options?: { serverId?: string },
|
||||
): () => void {
|
||||
const observation = client.registerBrowserHost(registration);
|
||||
const observation = client.registerBrowserHost({
|
||||
hostKind: "desktop app",
|
||||
supportedCommands: [...BROWSER_AUTOMATION_COMMAND_NAMES],
|
||||
});
|
||||
const unmount = mountBrowserAutomationHandler({
|
||||
client: {
|
||||
on: (_type, handler) =>
|
||||
|
||||
@@ -175,8 +175,6 @@ export interface DesktopInvokeBridge {
|
||||
export interface DesktopHostBridge {
|
||||
platform?: string;
|
||||
windowChromeMode?: string;
|
||||
browserHostLabel?: string;
|
||||
browserHostInstanceId?: string;
|
||||
invoke?: DesktopInvokeBridge["invoke"];
|
||||
getPendingOpenProject?: () => Promise<string | null>;
|
||||
agentNavigation?: DesktopAgentNavigationBridge;
|
||||
|
||||
@@ -11,6 +11,7 @@ import type {
|
||||
|
||||
export function useDictationAudioSource(config: DictationAudioSourceConfig): DictationAudioSource {
|
||||
const onPcmSegmentRef = useRef(config.onPcmSegment);
|
||||
const onErrorRef = useRef(config.onError);
|
||||
const onInterruptionRef = useRef(config.onInterruption);
|
||||
const [volume, setVolume] = useState(0);
|
||||
const [isPaused, setIsPaused] = useState(false);
|
||||
@@ -29,6 +30,9 @@ export function useDictationAudioSource(config: DictationAudioSourceConfig): Dic
|
||||
onVolumeLevel: (level) => {
|
||||
setVolume(level);
|
||||
},
|
||||
onError: (error) => {
|
||||
onErrorRef.current?.(error);
|
||||
},
|
||||
onInterruption: () => {
|
||||
onInterruptionRef.current?.();
|
||||
},
|
||||
@@ -41,11 +45,14 @@ export function useDictationAudioSource(config: DictationAudioSourceConfig): Dic
|
||||
|
||||
useEffect(() => {
|
||||
onPcmSegmentRef.current = config.onPcmSegment;
|
||||
onErrorRef.current = config.onError;
|
||||
onInterruptionRef.current = config.onInterruption;
|
||||
}, [config.onPcmSegment, config.onInterruption]);
|
||||
}, [config.onPcmSegment, config.onError, config.onInterruption]);
|
||||
|
||||
const start = useCallback(async () => {
|
||||
await getOrCreateEngine().startCapture();
|
||||
const engine = getOrCreateEngine();
|
||||
await engine.initialize();
|
||||
await engine.startCapture();
|
||||
}, [getOrCreateEngine]);
|
||||
|
||||
const stop = useCallback(async () => {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { AudioCaptureStartError } from "@/audio";
|
||||
import { resampleToPcm16 } from "@/audio/pcm";
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { parsePcm16Wav } from "@/utils/pcm16-wav";
|
||||
@@ -134,32 +133,6 @@ async function finalizeRecorderStoppedPromise(input: {
|
||||
}
|
||||
}
|
||||
|
||||
async function requestMicrophone(): Promise<MediaStream> {
|
||||
try {
|
||||
return await navigator.mediaDevices.getUserMedia({
|
||||
audio: {
|
||||
channelCount: 1,
|
||||
noiseSuppression: true,
|
||||
echoCancellation: true,
|
||||
autoGainControl: true,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
if (error instanceof DOMException) {
|
||||
if (error.name === "NotAllowedError") {
|
||||
throw new AudioCaptureStartError("permissionDenied", error.message, { cause: error });
|
||||
}
|
||||
if (error.name === "NotFoundError") {
|
||||
throw new AudioCaptureStartError("noMicrophone", error.message, { cause: error });
|
||||
}
|
||||
if (error.name === "NotSupportedError") {
|
||||
throw new AudioCaptureStartError("unsupported", error.message, { cause: error });
|
||||
}
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export function useDictationAudioSource(config: DictationAudioSourceConfig): DictationAudioSource {
|
||||
const [volume, setVolume] = useState(0);
|
||||
|
||||
@@ -227,19 +200,50 @@ export function useDictationAudioSource(config: DictationAudioSourceConfig): Dic
|
||||
}, []);
|
||||
|
||||
const start = useCallback(async () => {
|
||||
if (!window.isSecureContext && !isElectronRuntime()) {
|
||||
throw new AudioCaptureStartError(
|
||||
"insecureContext",
|
||||
`Microphone access requires HTTPS or localhost. Current origin: ${window.location.origin}`,
|
||||
const missingNavigator =
|
||||
typeof navigator === "undefined" ||
|
||||
!navigator.mediaDevices ||
|
||||
typeof navigator.mediaDevices.getUserMedia !== "function";
|
||||
|
||||
const secureContext =
|
||||
typeof window !== "undefined" && typeof window.isSecureContext === "boolean"
|
||||
? window.isSecureContext
|
||||
: true;
|
||||
const currentOrigin =
|
||||
typeof window !== "undefined" && window.location ? window.location.origin : "unknown";
|
||||
const isDesktopApp = isElectronRuntime();
|
||||
|
||||
if (missingNavigator) {
|
||||
throw new Error("Microphone capture is not supported in this environment");
|
||||
}
|
||||
if (!secureContext && !isDesktopApp) {
|
||||
throw new Error(
|
||||
`Microphone access requires HTTPS or localhost. Current origin: ${currentOrigin}`,
|
||||
);
|
||||
}
|
||||
if (!secureContext && isDesktopApp) {
|
||||
console.warn(
|
||||
"[DictationAudio][Web] Insecure context reported under Desktop; attempting getUserMedia anyway",
|
||||
{ currentOrigin },
|
||||
);
|
||||
}
|
||||
|
||||
const AudioContextCtor = getAudioContextCtor();
|
||||
if (!navigator.mediaDevices?.getUserMedia || !AudioContextCtor) {
|
||||
throw new AudioCaptureStartError("unsupported", "Browser audio capture is unavailable.");
|
||||
if (!AudioContextCtor) {
|
||||
throw new Error("AudioContext unavailable");
|
||||
}
|
||||
|
||||
const stream = await requestMicrophone();
|
||||
const rawStream = await navigator.mediaDevices.getUserMedia({
|
||||
audio: {
|
||||
channelCount: 1,
|
||||
noiseSuppression: true,
|
||||
echoCancellation: true,
|
||||
autoGainControl: true,
|
||||
},
|
||||
});
|
||||
|
||||
const stream = rawStream;
|
||||
|
||||
const context = new AudioContextCtor();
|
||||
|
||||
try {
|
||||
@@ -427,7 +431,15 @@ export function useDictationAudioSource(config: DictationAudioSourceConfig): Dic
|
||||
|
||||
return useMemo(
|
||||
() => ({
|
||||
start,
|
||||
start: async () => {
|
||||
try {
|
||||
await start();
|
||||
} catch (err) {
|
||||
const normalized = err instanceof Error ? err : new Error(String(err));
|
||||
onErrorRef.current?.(normalized);
|
||||
throw normalized;
|
||||
}
|
||||
},
|
||||
stop,
|
||||
volume,
|
||||
isPaused: false,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import type { AudioCaptureStartFailure } from "@/audio";
|
||||
import { i18n } from "@/i18n/i18next";
|
||||
|
||||
export type DictationStatus = "idle" | "recording" | "paused" | "uploading" | "failed";
|
||||
@@ -22,8 +21,6 @@ export interface UseDictationResult {
|
||||
volume: number;
|
||||
duration: number;
|
||||
error: string | null;
|
||||
startError: AudioCaptureStartFailure | null;
|
||||
clearStartError: () => void;
|
||||
status: DictationStatus;
|
||||
startDictation: () => Promise<void>;
|
||||
cancelDictation: () => Promise<void>;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { AudioCaptureStartError, type AudioCaptureStartFailure } from "@/audio";
|
||||
import { DictationStreamSender } from "@/dictation/dictation-stream-sender";
|
||||
import { useDictationAudioSource } from "@/hooks/use-dictation-audio-source";
|
||||
import { generateMessageId } from "@/types/stream";
|
||||
@@ -33,8 +32,6 @@ export function useDictation(options: UseDictationOptions): UseDictationResult {
|
||||
const [partialTranscript, setPartialTranscript] = useState("");
|
||||
const [duration, setDuration] = useState(0);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [startError, setStartError] = useState<AudioCaptureStartFailure | null>(null);
|
||||
const clearStartError = useCallback(() => setStartError(null), []);
|
||||
const [status, setStatus] = useState<DictationStatus>("idle");
|
||||
const latestPartialTranscriptRef = useRef("");
|
||||
|
||||
@@ -268,17 +265,14 @@ export function useDictation(options: UseDictationOptions): UseDictationResult {
|
||||
|
||||
actionGateRef.current.starting = true;
|
||||
setError(null);
|
||||
setStartError(null);
|
||||
setPartialTranscript("");
|
||||
setDuration(0);
|
||||
setIsProcessing(false);
|
||||
setStatus("recording");
|
||||
clearStreamingState();
|
||||
|
||||
let captureStarted = false;
|
||||
try {
|
||||
await audio.start();
|
||||
captureStarted = true;
|
||||
isRecordingRef.current = true;
|
||||
setIsRecording(true);
|
||||
if (enableDuration) {
|
||||
@@ -293,12 +287,7 @@ export function useDictation(options: UseDictationOptions): UseDictationResult {
|
||||
isRecordingRef.current = false;
|
||||
setIsRecording(false);
|
||||
setStatus("idle");
|
||||
if (captureStarted) {
|
||||
reportError(err, "Failed to start dictation stream");
|
||||
} else {
|
||||
console.error("[useDictation] Failed to start dictation capture", err);
|
||||
setStartError(err instanceof AudioCaptureStartError ? err.reason : "startFailed");
|
||||
}
|
||||
reportError(err, "Failed to start dictation");
|
||||
} finally {
|
||||
actionGateRef.current.starting = false;
|
||||
}
|
||||
@@ -449,7 +438,6 @@ export function useDictation(options: UseDictationOptions): UseDictationResult {
|
||||
stopDurationTracking();
|
||||
setDuration(0);
|
||||
setError(null);
|
||||
setStartError(null);
|
||||
setStatus("idle");
|
||||
clearStreamingState();
|
||||
}, [clearStreamingState, stopDurationTracking]);
|
||||
@@ -473,8 +461,6 @@ export function useDictation(options: UseDictationOptions): UseDictationResult {
|
||||
volume: audio.volume,
|
||||
duration,
|
||||
error,
|
||||
startError,
|
||||
clearStartError,
|
||||
status: status === "recording" && audio.isPaused ? "paused" : status,
|
||||
startDictation,
|
||||
cancelDictation,
|
||||
|
||||
@@ -115,7 +115,6 @@ export const ar: TranslationResources = {
|
||||
home: "بيت",
|
||||
groupByProject: "تجميع حسب المشروع",
|
||||
groupByStatus: "تجميع حسب الحالة",
|
||||
copyBrowserHostName: "نسخ اسم مضيف المتصفح",
|
||||
modelGroupLabel: "النموذج",
|
||||
modelSearchKeywords: "تبديل النموذج تغيير النموذج تعيين النموذج اختيار النموذج",
|
||||
thinkingGroupLabel: "التفكير",
|
||||
@@ -378,11 +377,6 @@ export const ar: TranslationResources = {
|
||||
details: "تفاصيل",
|
||||
},
|
||||
dictation: {
|
||||
insecureContext: "افتح Paseo عبر HTTPS أو localhost لاستخدام الميكروفون.",
|
||||
unsupported: "الإملاء غير متاح في هذا المتصفح.",
|
||||
noMicrophone: "صِل ميكروفونًا وحاول مرة أخرى.",
|
||||
permissionDenied: "اسمح بالوصول إلى الميكروفون وحاول مرة أخرى.",
|
||||
startFailed: "تعذر بدء الإملاء. حاول مرة أخرى.",
|
||||
paused: "تمت مقاطعة الميكروفون. في انتظار الاستئناف…",
|
||||
start: "بدء الإملاء الصوتي",
|
||||
cancel: "إلغاء الإملاء",
|
||||
|
||||
@@ -113,7 +113,6 @@ export const en = {
|
||||
home: "Home",
|
||||
groupByProject: "Group by project",
|
||||
groupByStatus: "Group by status",
|
||||
copyBrowserHostName: "Copy browser host name",
|
||||
modelGroupLabel: "Model",
|
||||
modelSearchKeywords: "switch model change model set model select model",
|
||||
thinkingGroupLabel: "Thinking",
|
||||
@@ -377,11 +376,6 @@ export const en = {
|
||||
details: "Details",
|
||||
},
|
||||
dictation: {
|
||||
insecureContext: "Open Paseo over HTTPS or localhost to use the microphone.",
|
||||
unsupported: "Dictation is unavailable in this browser.",
|
||||
noMicrophone: "Connect a microphone and try again.",
|
||||
permissionDenied: "Allow microphone access and try again.",
|
||||
startFailed: "Could not start dictation. Try again.",
|
||||
paused: "Microphone interrupted. Waiting to resume…",
|
||||
start: "Start voice dictation",
|
||||
cancel: "Cancel dictation",
|
||||
|
||||
@@ -116,7 +116,6 @@ export const es: TranslationResources = {
|
||||
home: "Hogar",
|
||||
groupByProject: "Agrupar por proyecto",
|
||||
groupByStatus: "Agrupar por estado",
|
||||
copyBrowserHostName: "Copiar el nombre del host del navegador",
|
||||
modelGroupLabel: "Modelo",
|
||||
modelSearchKeywords: "cambiar modelo modificar modelo establecer modelo seleccionar modelo",
|
||||
thinkingGroupLabel: "Razonamiento",
|
||||
@@ -383,11 +382,6 @@ export const es: TranslationResources = {
|
||||
details: "Detalles",
|
||||
},
|
||||
dictation: {
|
||||
insecureContext: "Abre Paseo por HTTPS o en localhost para usar el micrófono.",
|
||||
unsupported: "El dictado no está disponible en este navegador.",
|
||||
noMicrophone: "Conecta un micrófono e inténtalo de nuevo.",
|
||||
permissionDenied: "Permite el acceso al micrófono e inténtalo de nuevo.",
|
||||
startFailed: "No se pudo iniciar el dictado. Inténtalo de nuevo.",
|
||||
paused: "Micrófono interrumpido. Esperando para reanudar…",
|
||||
start: "Iniciar dictado de voz",
|
||||
cancel: "Cancelar dictado",
|
||||
|
||||
@@ -116,7 +116,6 @@ export const fr: TranslationResources = {
|
||||
home: "Accueil",
|
||||
groupByProject: "Grouper par projet",
|
||||
groupByStatus: "Grouper par statut",
|
||||
copyBrowserHostName: "Copier le nom de l’hôte du navigateur",
|
||||
modelGroupLabel: "Modèle",
|
||||
modelSearchKeywords:
|
||||
"changer de modèle modifier le modèle définir le modèle sélectionner le modèle model",
|
||||
@@ -383,11 +382,6 @@ export const fr: TranslationResources = {
|
||||
details: "Détails",
|
||||
},
|
||||
dictation: {
|
||||
insecureContext: "Ouvrez Paseo via HTTPS ou sur localhost pour utiliser le microphone.",
|
||||
unsupported: "La dictée est indisponible dans ce navigateur.",
|
||||
noMicrophone: "Connectez un microphone, puis réessayez.",
|
||||
permissionDenied: "Autorisez l’accès au microphone, puis réessayez.",
|
||||
startFailed: "Impossible de lancer la dictée. Réessayez.",
|
||||
paused: "Microphone interrompu. En attente de reprise…",
|
||||
start: "Démarrer la dictée vocale",
|
||||
cancel: "Annuler la dictée",
|
||||
|
||||
@@ -116,7 +116,6 @@ export const ja: TranslationResources = {
|
||||
home: "ホーム",
|
||||
groupByProject: "プロジェクトでグループ化",
|
||||
groupByStatus: "ステータスでグループ化",
|
||||
copyBrowserHostName: "ブラウザホスト名をコピー",
|
||||
modelGroupLabel: "モデル",
|
||||
modelSearchKeywords: "モデルを切り替え モデルを変更 モデルを設定 モデルを選択",
|
||||
thinkingGroupLabel: "思考",
|
||||
@@ -383,11 +382,6 @@ export const ja: TranslationResources = {
|
||||
details: "詳細",
|
||||
},
|
||||
dictation: {
|
||||
insecureContext: "マイクを使用するには、HTTPS または localhost で Paseo を開いてください。",
|
||||
unsupported: "このブラウザーでは音声入力を利用できません。",
|
||||
noMicrophone: "マイクを接続して、もう一度お試しください。",
|
||||
permissionDenied: "マイクへのアクセスを許可して、もう一度お試しください。",
|
||||
startFailed: "音声入力を開始できませんでした。もう一度お試しください。",
|
||||
paused: "マイクが中断されました。再開を待っています…",
|
||||
start: "音声入力を開始",
|
||||
cancel: "音声入力をキャンセル",
|
||||
|
||||
@@ -115,7 +115,6 @@ export const ko: TranslationResources = {
|
||||
home: "홈",
|
||||
groupByProject: "프로젝트별 그룹화",
|
||||
groupByStatus: "상태별 그룹화",
|
||||
copyBrowserHostName: "브라우저 호스트 이름 복사",
|
||||
modelGroupLabel: "모델",
|
||||
modelSearchKeywords: "모델 전환 모델 변경 모델 설정 모델 선택",
|
||||
thinkingGroupLabel: "추론",
|
||||
@@ -379,11 +378,6 @@ export const ko: TranslationResources = {
|
||||
details: "세부 정보",
|
||||
},
|
||||
dictation: {
|
||||
insecureContext: "마이크를 사용하려면 HTTPS 또는 localhost에서 Paseo를 여세요.",
|
||||
unsupported: "이 브라우저에서는 받아쓰기를 사용할 수 없습니다.",
|
||||
noMicrophone: "마이크를 연결한 후 다시 시도하세요.",
|
||||
permissionDenied: "마이크 접근을 허용한 후 다시 시도하세요.",
|
||||
startFailed: "받아쓰기를 시작할 수 없습니다. 다시 시도하세요.",
|
||||
paused: "마이크가 중단되었습니다. 재개를 기다리는 중…",
|
||||
start: "음성 받아쓰기 시작",
|
||||
cancel: "받아쓰기 취소",
|
||||
|
||||
@@ -116,7 +116,6 @@ export const ptBR: TranslationResources = {
|
||||
home: "Início",
|
||||
groupByProject: "Agrupar por projeto",
|
||||
groupByStatus: "Agrupar por status",
|
||||
copyBrowserHostName: "Copiar o nome do host do navegador",
|
||||
modelGroupLabel: "Modelo",
|
||||
modelSearchKeywords: "trocar modelo mudar modelo definir modelo selecionar modelo",
|
||||
thinkingGroupLabel: "Raciocínio",
|
||||
@@ -382,11 +381,6 @@ export const ptBR: TranslationResources = {
|
||||
details: "Detalhes",
|
||||
},
|
||||
dictation: {
|
||||
insecureContext: "Abra o Paseo por HTTPS ou em localhost para usar o microfone.",
|
||||
unsupported: "O ditado não está disponível neste navegador.",
|
||||
noMicrophone: "Conecte um microfone e tente novamente.",
|
||||
permissionDenied: "Permita o acesso ao microfone e tente novamente.",
|
||||
startFailed: "Não foi possível iniciar o ditado. Tente novamente.",
|
||||
paused: "Microfone interrompido. Aguardando para retomar…",
|
||||
start: "Iniciar ditado por voz",
|
||||
cancel: "Cancelar ditado",
|
||||
|
||||
@@ -116,7 +116,6 @@ export const ru: TranslationResources = {
|
||||
home: "Главная",
|
||||
groupByProject: "Группировать по проекту",
|
||||
groupByStatus: "Группировать по статусу",
|
||||
copyBrowserHostName: "Скопировать имя хоста браузера",
|
||||
modelGroupLabel: "Модель",
|
||||
modelSearchKeywords: "Сменить, изменить, выбрать или установить модель",
|
||||
thinkingGroupLabel: "Мышление",
|
||||
@@ -382,11 +381,6 @@ export const ru: TranslationResources = {
|
||||
details: "Подробности",
|
||||
},
|
||||
dictation: {
|
||||
insecureContext: "Чтобы использовать микрофон, откройте Paseo по HTTPS или на localhost.",
|
||||
unsupported: "Диктовка недоступна в этом браузере.",
|
||||
noMicrophone: "Подключите микрофон и попробуйте снова.",
|
||||
permissionDenied: "Разрешите доступ к микрофону и попробуйте снова.",
|
||||
startFailed: "Не удалось начать диктовку. Попробуйте снова.",
|
||||
paused: "Микрофон прерван. Ожидание возобновления…",
|
||||
start: "Начать диктовку голосом",
|
||||
cancel: "Отменить диктовку",
|
||||
|
||||
@@ -115,7 +115,6 @@ export const zhCN: TranslationResources = {
|
||||
home: "首页",
|
||||
groupByProject: "按项目分组",
|
||||
groupByStatus: "按状态分组",
|
||||
copyBrowserHostName: "复制浏览器宿主名称",
|
||||
modelGroupLabel: "模型",
|
||||
modelSearchKeywords: "切换模型 更改模型 设置模型 选择模型",
|
||||
thinkingGroupLabel: "思考",
|
||||
@@ -378,11 +377,6 @@ export const zhCN: TranslationResources = {
|
||||
details: "详情",
|
||||
},
|
||||
dictation: {
|
||||
insecureContext: "请通过 HTTPS 或 localhost 打开 Paseo,以使用麦克风。",
|
||||
unsupported: "此浏览器无法使用听写。",
|
||||
noMicrophone: "请连接麦克风,然后重试。",
|
||||
permissionDenied: "请允许访问麦克风,然后重试。",
|
||||
startFailed: "无法开始听写。请重试。",
|
||||
paused: "麦克风已中断,正在等待恢复…",
|
||||
start: "开始语音听写",
|
||||
cancel: "取消听写",
|
||||
|
||||
@@ -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: () =>
|
||||
|
||||
@@ -207,9 +207,11 @@ async function dispatch(input: ProviderInput, state: AcpConnectionState): Promis
|
||||
case "session.open":
|
||||
await openSession(input, state);
|
||||
return;
|
||||
case "session.prompt":
|
||||
await requireSession(state, input.sessionId).runtime.prompt(input);
|
||||
case "session.prompt": {
|
||||
const session = requireSession(state, input.sessionId);
|
||||
await mutateSession(session, () => session.runtime.prompt(input));
|
||||
return;
|
||||
}
|
||||
case "session.interrupt":
|
||||
await requireSession(state, input.sessionId).runtime.interrupt();
|
||||
state.emit({ type: "request.completed", requestId: input.requestId });
|
||||
@@ -253,6 +255,7 @@ async function discover(
|
||||
options: state.options,
|
||||
launch: state.launch,
|
||||
boundarySessionId: "catalog",
|
||||
cwd: input.cwd,
|
||||
env: {},
|
||||
emit: state.emit,
|
||||
});
|
||||
@@ -309,6 +312,7 @@ async function openSession(
|
||||
options: state.options,
|
||||
launch: state.launch,
|
||||
boundarySessionId: input.sessionId,
|
||||
cwd: input.config.cwd,
|
||||
env: input.config.env,
|
||||
emit: state.emit,
|
||||
});
|
||||
@@ -323,6 +327,7 @@ async function openSession(
|
||||
capabilities,
|
||||
mutationLane: Promise.resolve(),
|
||||
});
|
||||
state.emit({ type: "session.ready", requestId: input.requestId, sessionId: input.sessionId });
|
||||
} catch (error) {
|
||||
await runtime.close();
|
||||
throw error;
|
||||
@@ -348,10 +353,17 @@ interface StartRuntimeOptions {
|
||||
launch?: ProviderLaunch;
|
||||
options: RunAcpProviderOptions;
|
||||
boundarySessionId: string;
|
||||
cwd?: string;
|
||||
env: Readonly<Record<string, string>>;
|
||||
emit(event: ProviderEvent): void;
|
||||
}
|
||||
|
||||
interface PendingPermission {
|
||||
request: RequestPermissionRequest;
|
||||
turnId: string | undefined;
|
||||
resolve(response: RequestPermissionResponse): void;
|
||||
}
|
||||
|
||||
class AcpRuntime {
|
||||
readonly connection: ClientSideConnection;
|
||||
agentCapabilities: AgentCapabilities = {};
|
||||
@@ -363,14 +375,12 @@ class AcpRuntime {
|
||||
// Running tool rows published by transformers; the turn's terminal closes any left open.
|
||||
private readonly vendorToolCalls = new Map<string, ToolCallTimelineItem>();
|
||||
private readonly pendingCompactions = new Set<string>();
|
||||
private readonly permissions = new Map<
|
||||
string,
|
||||
{ request: RequestPermissionRequest; resolve(response: RequestPermissionResponse): void }
|
||||
>();
|
||||
private readonly permissions = new Map<string, PendingPermission>();
|
||||
private readonly transformers: readonly AcpTransformer[];
|
||||
private configOptions: SessionConfigOption[] = [];
|
||||
private modes: NewSessionResponse["modes"] = null;
|
||||
private commandWaiter: (() => void) | null = null;
|
||||
private receivedInitialCommands = false;
|
||||
private messageSequence = 0;
|
||||
/**
|
||||
* Fallback ids for streamed chunks that carry no `messageId`, one per
|
||||
@@ -383,19 +393,20 @@ class AcpRuntime {
|
||||
string
|
||||
>();
|
||||
/**
|
||||
* Active while a persisted session loads. ACP agents replay the loaded
|
||||
* session's updates before session/load resolves; the value follows the
|
||||
* open request's history contract.
|
||||
* Replay updates count as history until the session reports ready.
|
||||
* Once ready, suppress late replay rows until the first prompt.
|
||||
*/
|
||||
private replayWindow: "replay" | "skip" | null = null;
|
||||
private lastLoadUpdateAt = 0;
|
||||
private closing = false;
|
||||
private processFailed = false;
|
||||
private configTransaction = false;
|
||||
private stagedTransformerConfig: ProviderConfigState | null = null;
|
||||
private readonly closeConnector: () => Promise<void>;
|
||||
private notificationLane: Promise<void> = Promise.resolve();
|
||||
private promptLane: Promise<void> = Promise.resolve();
|
||||
private activePrompt: { turnId: string; settled: Promise<void> } | null = null;
|
||||
private autoAccept = false;
|
||||
private activePrompt: { turnId: string; settled: Promise<void>; cancelling: boolean } | null =
|
||||
null;
|
||||
private lastUsage: ProviderUsage = {};
|
||||
|
||||
static async start(options: StartRuntimeOptions): Promise<AcpRuntime> {
|
||||
@@ -412,6 +423,7 @@ class AcpRuntime {
|
||||
env: process.env,
|
||||
};
|
||||
child = spawnProcess(launch.command, launch.args, {
|
||||
cwd: options.cwd,
|
||||
env: { ...launch.env, ...options.env },
|
||||
stdio: "pipe",
|
||||
});
|
||||
@@ -496,8 +508,8 @@ class AcpRuntime {
|
||||
connectionCapabilities: readonly ProviderCapability[],
|
||||
): Promise<readonly ProviderCapability[]> {
|
||||
const mcpServers = toAcpMcpServers(input.config);
|
||||
const nativeSessionId = readNativeSessionId(input.persistence);
|
||||
const metadata = {
|
||||
let nativeSessionId = readNativeSessionId(input.persistence);
|
||||
const metadata: Record<string, unknown> = {
|
||||
_paseo: {
|
||||
systemPrompt: input.config.systemPrompt,
|
||||
providerOptions: input.config.providerOptions,
|
||||
@@ -505,25 +517,31 @@ class AcpRuntime {
|
||||
persist: input.config.persist,
|
||||
},
|
||||
};
|
||||
for (const transformer of this.transformers) {
|
||||
const prepared = transformer.sessionOpen?.({
|
||||
persistence: input.persistence,
|
||||
systemPrompt: input.config.systemPrompt,
|
||||
agentMetadata: jsonValue(this.agentCapabilities._meta ?? null),
|
||||
});
|
||||
nativeSessionId ??= prepared?.sessionId ?? null;
|
||||
Object.assign(metadata, prepared?.metadata);
|
||||
}
|
||||
let response: Pick<NewSessionResponse, "modes" | "configOptions">;
|
||||
if (nativeSessionId) {
|
||||
// ACP agents replay the loaded session's updates before session/load resolves,
|
||||
// so the native id must be registered first for them to pass the session filter.
|
||||
this.nativeSessionId = nativeSessionId;
|
||||
this.replayWindow = input.history === "replay" ? "replay" : "skip";
|
||||
try {
|
||||
response = await this.call(
|
||||
this.connection.loadSession({
|
||||
sessionId: nativeSessionId,
|
||||
cwd: input.config.cwd,
|
||||
mcpServers,
|
||||
_meta: metadata,
|
||||
}),
|
||||
);
|
||||
await this.drainNotifications();
|
||||
} finally {
|
||||
this.replayWindow = null;
|
||||
}
|
||||
response = await this.call(
|
||||
this.connection.loadSession({
|
||||
sessionId: nativeSessionId,
|
||||
cwd: input.config.cwd,
|
||||
mcpServers,
|
||||
_meta: metadata,
|
||||
}),
|
||||
);
|
||||
await this.drainNotifications();
|
||||
if (!this.options.options.acpOptions?.loadReplayQuietPeriodMs) this.replayWindow = null;
|
||||
} else {
|
||||
const newSession = await this.call(
|
||||
this.connection.newSession({
|
||||
@@ -535,12 +553,13 @@ class AcpRuntime {
|
||||
response = newSession;
|
||||
this.nativeSessionId = newSession.sessionId;
|
||||
}
|
||||
this.modes = response.modes;
|
||||
this.modes = response.modes ?? null;
|
||||
this.configOptions = response.configOptions ?? [];
|
||||
await this.applyInitialConfig(input.config);
|
||||
const sessionCapabilities = connectionCapabilities.filter(
|
||||
(capability) =>
|
||||
capability !== "session.configure" ||
|
||||
this.options.options.acpOptions?.autoAcceptMode !== undefined ||
|
||||
this.modes !== null ||
|
||||
this.configOptions.length > 0 ||
|
||||
this.transformers.some((transformer) => transformer.configure !== undefined),
|
||||
@@ -559,7 +578,11 @@ class AcpRuntime {
|
||||
if (this.options.options.acpOptions?.waitForInitialCommands) {
|
||||
await this.waitForInitialCommands();
|
||||
}
|
||||
this.emit({ type: "session.ready", requestId: input.requestId, sessionId: input.sessionId });
|
||||
const quietPeriod = this.options.options.acpOptions?.loadReplayQuietPeriodMs;
|
||||
if (this.replayWindow && quietPeriod && quietPeriod > 0) {
|
||||
await this.waitForLoadReplay(quietPeriod);
|
||||
this.replayWindow = "skip";
|
||||
}
|
||||
return sessionCapabilities;
|
||||
}
|
||||
|
||||
@@ -571,26 +594,26 @@ class AcpRuntime {
|
||||
this.connection.newSession({ cwd: cwd ?? process.cwd(), mcpServers: [] }),
|
||||
);
|
||||
this.nativeSessionId = response.sessionId;
|
||||
this.modes = response.modes;
|
||||
this.modes = response.modes ?? null;
|
||||
this.configOptions = response.configOptions ?? [];
|
||||
return toProviderCatalog(response.modes, response.configOptions ?? []);
|
||||
const catalog = toProviderCatalog(this.modes, this.configOptions);
|
||||
const autoAcceptMode = this.options.options.acpOptions?.autoAcceptMode;
|
||||
if (!autoAcceptMode) return catalog;
|
||||
return {
|
||||
...catalog,
|
||||
modes: [...catalog.modes, { ...autoAcceptMode.mode, isUnattended: true }],
|
||||
defaultMode: autoAcceptMode.default ? autoAcceptMode.mode.id : catalog.defaultMode,
|
||||
};
|
||||
}
|
||||
|
||||
prompt(input: Extract<ProviderInput, { type: "session.prompt" }>): Promise<void> {
|
||||
const admission = this.promptLane.then(() => this.admitPrompt(input));
|
||||
this.promptLane = admission.catch(() => undefined);
|
||||
return admission;
|
||||
}
|
||||
|
||||
private async admitPrompt(
|
||||
input: Extract<ProviderInput, { type: "session.prompt" }>,
|
||||
): Promise<void> {
|
||||
async prompt(input: Extract<ProviderInput, { type: "session.prompt" }>): Promise<void> {
|
||||
const active = this.activePrompt;
|
||||
if (active) {
|
||||
await this.interrupt();
|
||||
await active.settled;
|
||||
}
|
||||
const prompt = toAcpPrompt(input.prompt);
|
||||
this.replayWindow = null;
|
||||
const turnId = `acp:${input.prompt.clientMessageId}`;
|
||||
this.fallbackChunkIds.clear();
|
||||
this.emit({
|
||||
@@ -642,6 +665,7 @@ class AcpRuntime {
|
||||
const state = response.stopReason === "cancelled" ? "canceled" : "completed";
|
||||
this.fallbackChunkIds.clear();
|
||||
this.terminalizeTransientItems(state);
|
||||
this.finishTurnPermissions(turnId);
|
||||
this.emit({
|
||||
type: "session.turn",
|
||||
sessionId: this.options.boundarySessionId,
|
||||
@@ -654,6 +678,7 @@ class AcpRuntime {
|
||||
await this.drainNotifications();
|
||||
this.fallbackChunkIds.clear();
|
||||
this.terminalizeTransientItems("failed");
|
||||
this.finishTurnPermissions(turnId);
|
||||
this.emit({
|
||||
type: "session.turn",
|
||||
sessionId: this.options.boundarySessionId,
|
||||
@@ -664,14 +689,21 @@ class AcpRuntime {
|
||||
return undefined;
|
||||
},
|
||||
);
|
||||
this.activePrompt = { turnId, settled };
|
||||
this.activePrompt = { turnId, settled, cancelling: false };
|
||||
void settled.finally(() => {
|
||||
if (this.activePrompt?.turnId === turnId) this.activePrompt = null;
|
||||
});
|
||||
}
|
||||
|
||||
interrupt(): Promise<void> {
|
||||
return this.call(this.connection.cancel({ sessionId: this.nativeSessionId }));
|
||||
async interrupt(): Promise<void> {
|
||||
const active = this.activePrompt;
|
||||
if (active) active.cancelling = true;
|
||||
try {
|
||||
await this.call(this.connection.cancel({ sessionId: this.nativeSessionId }));
|
||||
} finally {
|
||||
// An agent may wait for its outstanding permission replies before ending the prompt.
|
||||
if (active) this.finishTurnPermissions(active.turnId);
|
||||
}
|
||||
}
|
||||
|
||||
listSessions(cwd?: string) {
|
||||
@@ -688,19 +720,37 @@ class AcpRuntime {
|
||||
response: Extract<ProviderInput, { type: "session.permission" }>["response"],
|
||||
): void {
|
||||
const pending = this.permissions.get(permissionId);
|
||||
if (!pending) throw new Error(`Unknown ACP permission: ${permissionId}`);
|
||||
if (!pending) return;
|
||||
const active = this.activePrompt;
|
||||
if (active?.cancelling && pending.turnId === active.turnId) return;
|
||||
const selected = selectPermissionOption(pending.request.options, response);
|
||||
if (response.selectedActionId !== undefined && !selected) {
|
||||
throw new Error(
|
||||
`ACP permission action '${response.selectedActionId}' does not exist or does not match '${response.behavior}' behavior`,
|
||||
);
|
||||
}
|
||||
this.permissions.delete(permissionId);
|
||||
pending.resolve({
|
||||
this.resolvePermission(permissionId, pending, {
|
||||
outcome: selected
|
||||
? { outcome: "selected", optionId: selected.optionId }
|
||||
: { outcome: "cancelled" },
|
||||
});
|
||||
}
|
||||
|
||||
private finishTurnPermissions(turnId: string): void {
|
||||
for (const [permissionId, pending] of this.permissions) {
|
||||
if (pending.turnId === turnId) {
|
||||
this.resolvePermission(permissionId, pending, { outcome: { outcome: "cancelled" } });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private resolvePermission(
|
||||
permissionId: string,
|
||||
pending: PendingPermission,
|
||||
response: RequestPermissionResponse,
|
||||
): void {
|
||||
this.permissions.delete(permissionId);
|
||||
pending.resolve(response);
|
||||
this.emit({
|
||||
type: "session.permission_resolved",
|
||||
sessionId: this.options.boundarySessionId,
|
||||
@@ -711,6 +761,17 @@ class AcpRuntime {
|
||||
async configure(
|
||||
changes: Extract<ProviderInput, { type: "session.configure" }>["changes"],
|
||||
): Promise<void> {
|
||||
const autoAcceptMode = this.options.options.acpOptions?.autoAcceptMode;
|
||||
if (
|
||||
autoAcceptMode &&
|
||||
changes.mode !== undefined &&
|
||||
(changes.mode === autoAcceptMode.mode.id) !== this.autoAccept &&
|
||||
(this.activePrompt || this.permissions.size > 0)
|
||||
) {
|
||||
throw new Error(
|
||||
`Finish or stop the current turn before switching to or from ${autoAcceptMode.mode.label}.`,
|
||||
);
|
||||
}
|
||||
const requested: AcpConfigChange[] = [];
|
||||
if (changes.model !== undefined) requested.push({ target: "model", value: changes.model });
|
||||
if (changes.mode !== undefined) requested.push({ target: "mode", value: changes.mode });
|
||||
@@ -721,6 +782,7 @@ class AcpRuntime {
|
||||
requested.push({ target: "setting", id, value });
|
||||
}
|
||||
const ordered = this.inAgentOrder(requested);
|
||||
const previousAutoAccept = this.autoAccept;
|
||||
const previousModes = this.modes ? structuredClone(this.modes) : null;
|
||||
const previousOptions = structuredClone(this.configOptions);
|
||||
this.configTransaction = true;
|
||||
@@ -746,6 +808,7 @@ class AcpRuntime {
|
||||
await this.close();
|
||||
throw failure;
|
||||
}
|
||||
this.autoAccept = previousAutoAccept;
|
||||
this.modes = previousModes;
|
||||
this.configOptions = previousOptions;
|
||||
this.stagedTransformerConfig = null;
|
||||
@@ -788,7 +851,9 @@ class AcpRuntime {
|
||||
private async applyInitialConfig(config: ProviderSessionConfig): Promise<void> {
|
||||
const requested: AcpConfigChange[] = [];
|
||||
if (config.model) requested.push({ target: "model", value: config.model });
|
||||
if (config.mode) requested.push({ target: "mode", value: config.mode });
|
||||
const autoAcceptMode = this.options.options.acpOptions?.autoAcceptMode;
|
||||
const mode = config.mode ?? (autoAcceptMode?.default ? autoAcceptMode.mode.id : undefined);
|
||||
if (mode) requested.push({ target: "mode", value: mode });
|
||||
if (config.thinkingOption) {
|
||||
requested.push({ target: "thinking", value: config.thinkingOption });
|
||||
}
|
||||
@@ -815,23 +880,47 @@ class AcpRuntime {
|
||||
if (change.target === "thinking") {
|
||||
return this.configOptions.find((option) => option.category === "thought_level")?.id;
|
||||
}
|
||||
return this.configOptions.find((option) => option.category === "mode")?.id;
|
||||
return modeOption(this.configOptions)?.id;
|
||||
}
|
||||
|
||||
private async applyConfigChange(change: AcpConfigChange): Promise<void> {
|
||||
const autoAcceptMode = this.options.options.acpOptions?.autoAcceptMode;
|
||||
if (
|
||||
change.target === "mode" &&
|
||||
autoAcceptMode &&
|
||||
(this.autoAccept || change.value === autoAcceptMode.mode.id)
|
||||
) {
|
||||
const enableAutoAccept = change.value === autoAcceptMode.mode.id;
|
||||
const nativeMode = enableAutoAccept ? autoAcceptMode.nativeMode : change.value;
|
||||
this.autoAccept = false;
|
||||
if (nativeMode !== this.nativeModeId()) {
|
||||
await this.applyNativeConfigChange({ target: "mode", value: nativeMode });
|
||||
}
|
||||
if (nativeMode !== this.nativeModeId()) {
|
||||
throw new Error(`ACP agent did not switch to mode '${nativeMode}'`);
|
||||
}
|
||||
this.autoAccept = enableAutoAccept;
|
||||
return;
|
||||
}
|
||||
const access = this.configAccess();
|
||||
for (const transformer of this.transformers) {
|
||||
if (
|
||||
(await transformer.configure?.(change, {
|
||||
sessionId: this.options.boundarySessionId,
|
||||
config: access,
|
||||
catalog: () => toProviderCatalog(this.modes, this.configOptions),
|
||||
apply: (nativeChange) => this.applyNativeConfigChange(nativeChange),
|
||||
})) === "handled"
|
||||
) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (change.target === "mode") {
|
||||
if (!change.value || !this.modes) {
|
||||
await this.applyNativeConfigChange(change);
|
||||
}
|
||||
|
||||
private async applyNativeConfigChange(change: AcpConfigChange): Promise<void> {
|
||||
if (change.target === "mode" && this.modes && !modeOption(this.configOptions)) {
|
||||
if (!change.value) {
|
||||
throw new Error("ACP session does not expose mode configuration");
|
||||
}
|
||||
await this.call(
|
||||
@@ -886,7 +975,20 @@ class AcpRuntime {
|
||||
this.emitConfigSnapshot(toProviderConfigState(this.modes, this.configOptions));
|
||||
}
|
||||
|
||||
private nativeModeId(): string | undefined {
|
||||
return selectedValue(modeOption(this.configOptions)) ?? this.modes?.currentModeId;
|
||||
}
|
||||
|
||||
private emitConfigSnapshot(config: ProviderConfigState): void {
|
||||
const autoAcceptMode = this.options.options.acpOptions?.autoAcceptMode;
|
||||
if (autoAcceptMode) {
|
||||
if (this.nativeModeId() !== autoAcceptMode.nativeMode) this.autoAccept = false;
|
||||
config = {
|
||||
...config,
|
||||
mode: this.autoAccept ? autoAcceptMode.mode.id : config.mode,
|
||||
modes: [...config.modes, { ...autoAcceptMode.mode, isUnattended: true }],
|
||||
};
|
||||
}
|
||||
this.emit({
|
||||
type: "session.config",
|
||||
sessionId: this.options.boundarySessionId,
|
||||
@@ -898,7 +1000,11 @@ class AcpRuntime {
|
||||
modes: NewSessionResponse["modes"],
|
||||
options: readonly SessionConfigOption[],
|
||||
): Promise<void> {
|
||||
if (modes?.currentModeId && this.modes?.currentModeId !== modes.currentModeId) {
|
||||
if (
|
||||
!modeOption(options) &&
|
||||
modes?.currentModeId &&
|
||||
this.modes?.currentModeId !== modes.currentModeId
|
||||
) {
|
||||
await this.call(
|
||||
this.connection.setSessionMode({
|
||||
sessionId: this.nativeSessionId,
|
||||
@@ -920,10 +1026,30 @@ class AcpRuntime {
|
||||
}
|
||||
}
|
||||
|
||||
private requestPermission(request: RequestPermissionRequest): Promise<RequestPermissionResponse> {
|
||||
private async requestPermission(
|
||||
request: RequestPermissionRequest,
|
||||
): Promise<RequestPermissionResponse> {
|
||||
await this.notificationLane;
|
||||
if (this.closing || this.processFailed || this.activePrompt?.cancelling) {
|
||||
return { outcome: { outcome: "cancelled" } };
|
||||
}
|
||||
if (
|
||||
this.autoAccept &&
|
||||
request.sessionId === this.nativeSessionId &&
|
||||
this.nativeModeId() === this.options.options.acpOptions?.autoAcceptMode?.nativeMode
|
||||
) {
|
||||
const allowOptions = request.options.filter((option) => option.kind.startsWith("allow"));
|
||||
const allowOnce = allowOptions.find((option) => option.kind === "allow_once");
|
||||
if (
|
||||
allowOnce &&
|
||||
new Set(allowOptions.map((option) => option.kind)).size === allowOptions.length
|
||||
) {
|
||||
return { outcome: { outcome: "selected", optionId: allowOnce.optionId } };
|
||||
}
|
||||
}
|
||||
const permissionId = `permission:${request.toolCall.toolCallId}`;
|
||||
return new Promise((resolve) => {
|
||||
this.permissions.set(permissionId, { request, resolve });
|
||||
this.permissions.set(permissionId, { request, resolve, turnId: this.activePrompt?.turnId });
|
||||
this.emit({
|
||||
type: "session.permission",
|
||||
sessionId: this.options.boundarySessionId,
|
||||
@@ -945,7 +1071,19 @@ class AcpRuntime {
|
||||
|
||||
private sessionUpdate(notification: SessionNotification): void {
|
||||
if (notification.sessionId !== this.nativeSessionId) return;
|
||||
if (this.replayWindow === "skip") return;
|
||||
if (this.replayWindow) this.lastLoadUpdateAt = performance.now();
|
||||
if (this.replayWindow === "skip") {
|
||||
const update = notification.update;
|
||||
if (
|
||||
update.sessionUpdate === "available_commands_update" ||
|
||||
update.sessionUpdate === "config_option_update" ||
|
||||
update.sessionUpdate === "current_mode_update" ||
|
||||
update.sessionUpdate === "usage_update"
|
||||
) {
|
||||
this.reduceStateUpdate(update);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (
|
||||
this.replayWindow === "replay" &&
|
||||
notification.update.sessionUpdate === "user_message_chunk"
|
||||
@@ -1067,11 +1205,17 @@ class AcpRuntime {
|
||||
argumentHint: command.input?.hint,
|
||||
}));
|
||||
this.emit({ type: "session.commands", sessionId: this.options.boundarySessionId, commands });
|
||||
this.receivedInitialCommands = true;
|
||||
this.commandWaiter?.();
|
||||
this.commandWaiter = null;
|
||||
return;
|
||||
}
|
||||
if (update.sessionUpdate === "current_mode_update") {
|
||||
const option = modeOption(this.configOptions);
|
||||
if (option?.type === "select") {
|
||||
this.configOptions = this.configOptions.map((candidate) =>
|
||||
candidate === option ? { ...option, currentValue: update.currentModeId } : candidate,
|
||||
);
|
||||
}
|
||||
if (this.modes) this.modes = { ...this.modes, currentModeId: update.currentModeId };
|
||||
this.emitConfig();
|
||||
return;
|
||||
@@ -1236,16 +1380,28 @@ class AcpRuntime {
|
||||
}
|
||||
|
||||
private waitForInitialCommands(): Promise<void> {
|
||||
if (this.receivedInitialCommands) return Promise.resolve();
|
||||
const timeoutMs = this.options.options.acpOptions?.initialCommandsTimeoutMs ?? 1_000;
|
||||
const commands = new Promise<void>((resolve) => {
|
||||
this.commandWaiter = resolve;
|
||||
});
|
||||
const timeout = new Promise<void>((resolve) => {
|
||||
setTimeout(resolve, timeoutMs);
|
||||
});
|
||||
return Promise.race([commands, timeout]).finally(() => {
|
||||
this.commandWaiter = null;
|
||||
});
|
||||
return withTimeout(commands, timeoutMs, "ACP agent did not publish initial commands")
|
||||
.catch(() => undefined)
|
||||
.finally(() => {
|
||||
this.commandWaiter = null;
|
||||
});
|
||||
}
|
||||
|
||||
private async waitForLoadReplay(quietPeriod: number): Promise<void> {
|
||||
const start = performance.now();
|
||||
const deadline = start + 5 * quietPeriod;
|
||||
while (!this.closing && !this.processFailed) {
|
||||
const idleAt = Math.max(start, this.lastLoadUpdateAt) + quietPeriod;
|
||||
const remaining = Math.min(deadline, idleAt) - performance.now();
|
||||
if (remaining <= 0) return;
|
||||
await new Promise<void>((resolve) => setTimeout(resolve, remaining));
|
||||
await this.notificationLane;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1412,17 +1568,23 @@ function toProviderConfigState(
|
||||
): ProviderConfigState {
|
||||
const model = modelOption(options);
|
||||
const thinking = options.find((option) => option.category === "thought_level");
|
||||
const modeConfig = modeOption(options);
|
||||
return {
|
||||
model: selectedValue(model),
|
||||
mode: modes?.currentModeId,
|
||||
mode: selectedValue(modeConfig) ?? modes?.currentModeId,
|
||||
thinkingOption: selectedValue(thinking),
|
||||
models: selectOptions(model).map((option) => ({ id: option.value, label: option.label })),
|
||||
modes:
|
||||
modes?.availableModes.map((mode) => ({
|
||||
id: mode.id,
|
||||
label: mode.name,
|
||||
description: mode.description ?? undefined,
|
||||
})) ?? [],
|
||||
modes: modeConfig
|
||||
? selectOptions(modeConfig).map((option) => ({
|
||||
id: option.value,
|
||||
label: option.label,
|
||||
description: option.description,
|
||||
}))
|
||||
: (modes?.availableModes.map((mode) => ({
|
||||
id: mode.id,
|
||||
label: mode.name,
|
||||
description: mode.description ?? undefined,
|
||||
})) ?? []),
|
||||
thinkingOptions: selectOptions(thinking).map((option) => ({
|
||||
id: option.value,
|
||||
label: option.label,
|
||||
@@ -1430,9 +1592,7 @@ function toProviderConfigState(
|
||||
settings: options
|
||||
.filter(
|
||||
(option) =>
|
||||
option !== model &&
|
||||
option.category !== "thought_level" &&
|
||||
!(modes && option.category === "mode"),
|
||||
option !== model && option.category !== "thought_level" && option !== modeConfig,
|
||||
)
|
||||
.map(toProviderSetting),
|
||||
};
|
||||
@@ -1445,6 +1605,10 @@ function modelOption(options: readonly SessionConfigOption[]): SessionConfigOpti
|
||||
return candidates.find((option) => option.id === "model") ?? candidates[0];
|
||||
}
|
||||
|
||||
function modeOption(options: readonly SessionConfigOption[]): SessionConfigOption | undefined {
|
||||
return options.find((option) => option.category === "mode" && option.type === "select");
|
||||
}
|
||||
|
||||
function toProviderCatalog(
|
||||
modes: NewSessionResponse["modes"],
|
||||
options: readonly SessionConfigOption[],
|
||||
@@ -1476,18 +1640,28 @@ function toProviderSetting(option: SessionConfigOption): ProviderSetting {
|
||||
label: option.name,
|
||||
description: option.description ?? undefined,
|
||||
value: option.currentValue,
|
||||
options: selectOptions(option),
|
||||
options: selectOptions(option).map(({ label, value }) => ({ label, value })),
|
||||
};
|
||||
}
|
||||
|
||||
function selectOptions(
|
||||
option: SessionConfigOption | undefined,
|
||||
): Array<{ label: string; value: string }> {
|
||||
): Array<{ label: string; value: string; description?: string }> {
|
||||
if (!option || option.type === "boolean") return [];
|
||||
return option.options.flatMap((candidate) =>
|
||||
"group" in candidate
|
||||
? candidate.options.map((nested) => ({ label: nested.name, value: nested.value }))
|
||||
: [{ label: candidate.name, value: candidate.value }],
|
||||
? candidate.options.map((nested) => ({
|
||||
label: nested.name,
|
||||
value: nested.value,
|
||||
description: nested.description ?? undefined,
|
||||
}))
|
||||
: [
|
||||
{
|
||||
label: candidate.name,
|
||||
value: candidate.value,
|
||||
description: candidate.description ?? undefined,
|
||||
},
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1506,16 +1680,18 @@ type ToolCallTimelineItem = Extract<ProviderTimelineItem, { type: "tool_call" }>
|
||||
function toolTimelineItem(snapshot: AcpToolCallSnapshot): ToolCallTimelineItem {
|
||||
const input = jsonRecord(snapshot.input);
|
||||
const isEdit = snapshot.kind === "edit" || snapshot.name?.toLowerCase().includes("edit") === true;
|
||||
const detail = isEdit
|
||||
? {
|
||||
type: "edit" as const,
|
||||
filePath:
|
||||
typeof input.filePath === "string" ? input.filePath : (snapshot.locations[0] ?? ""),
|
||||
oldString: typeof input.oldString === "string" ? input.oldString : undefined,
|
||||
newString: typeof input.newString === "string" ? input.newString : undefined,
|
||||
unifiedDiff: typeof input.unifiedDiff === "string" ? input.unifiedDiff : undefined,
|
||||
}
|
||||
: { type: "unknown" as const, input: snapshot.input, output: snapshot.output };
|
||||
const detail =
|
||||
snapshot.detail ??
|
||||
(isEdit
|
||||
? {
|
||||
type: "edit" as const,
|
||||
filePath:
|
||||
typeof input.filePath === "string" ? input.filePath : (snapshot.locations[0] ?? ""),
|
||||
oldString: typeof input.oldString === "string" ? input.oldString : undefined,
|
||||
newString: typeof input.newString === "string" ? input.newString : undefined,
|
||||
unifiedDiff: typeof input.unifiedDiff === "string" ? input.unifiedDiff : undefined,
|
||||
}
|
||||
: { type: "unknown" as const, input: snapshot.input, output: snapshot.output });
|
||||
const status =
|
||||
snapshot.status === "in_progress" || snapshot.status === "pending"
|
||||
? "running"
|
||||
|
||||
@@ -52,7 +52,7 @@ function openInput(
|
||||
type: "session.open",
|
||||
requestId: "open-1",
|
||||
sessionId: "session-1",
|
||||
config: { cwd: "/repo", env: {}, mcpServers: {}, settings, persist: true },
|
||||
config: { cwd: process.cwd(), env: {}, mcpServers: {}, settings, persist: true },
|
||||
history: "skip",
|
||||
};
|
||||
}
|
||||
@@ -226,6 +226,306 @@ lines.on("line", (line) => {
|
||||
});`;
|
||||
|
||||
describe("runAcpProvider", () => {
|
||||
it.each(["replay", "skip"] as const)(
|
||||
"handles trailing load updates with %s history",
|
||||
async (history) => {
|
||||
const sessionId = "connector-session";
|
||||
const notifyUpdate = (runtime: ConnectorInstance, update: unknown) =>
|
||||
runtime.notify("session/update", { sessionId, update });
|
||||
const { connector, instances } = connectorHarness({
|
||||
capabilities: { loadSession: true },
|
||||
handleRequest(runtime, request) {
|
||||
if (request.method !== "session/load") return false;
|
||||
notifyUpdate(runtime, {
|
||||
sessionUpdate: "available_commands_update",
|
||||
availableCommands: [{ name: "help", description: "Help" }],
|
||||
});
|
||||
runtime.respond(request, { configOptions: [] });
|
||||
setTimeout(() => {
|
||||
notifyUpdate(runtime, {
|
||||
sessionUpdate: "user_message_chunk",
|
||||
content: { type: "text", text: "previous question" },
|
||||
});
|
||||
notifyUpdate(runtime, {
|
||||
sessionUpdate: "agent_message_chunk",
|
||||
content: { type: "text", text: "previous answer" },
|
||||
});
|
||||
}, 100);
|
||||
return true;
|
||||
},
|
||||
});
|
||||
const connection = await runAcpProvider({
|
||||
id: "load",
|
||||
label: "Load",
|
||||
connector,
|
||||
acpOptions: {
|
||||
waitForInitialCommands: true,
|
||||
initialCommandsTimeoutMs: 10_000,
|
||||
loadReplayQuietPeriodMs: 200,
|
||||
},
|
||||
}).connect({ versions: [1], capabilities: ["prompt.message", "session.persistence"] });
|
||||
const events: ProviderEvent[] = [];
|
||||
connection.onEvent((event) => events.push(event));
|
||||
try {
|
||||
await connection.send({
|
||||
...openInput(),
|
||||
history,
|
||||
persistence: { version: 1, data: { sessionId } },
|
||||
});
|
||||
await waitForEvent(events, (event) => event.type === "session.ready");
|
||||
notifyUpdate(instances[1], {
|
||||
sessionUpdate: "agent_message_chunk",
|
||||
content: { type: "text", text: "stale history outside the replay window" },
|
||||
});
|
||||
notifyUpdate(instances[1], {
|
||||
sessionUpdate: "available_commands_update",
|
||||
availableCommands: [{ name: "different", description: "Different" }],
|
||||
});
|
||||
await waitForEvent(
|
||||
events,
|
||||
(event) => event.type === "session.commands" && event.commands[0]?.name === "different",
|
||||
);
|
||||
const items = events
|
||||
.filter((event) => event.type === "timeline.item")
|
||||
.map((event) => event.item);
|
||||
expect(items).toEqual(
|
||||
history === "skip"
|
||||
? []
|
||||
: [
|
||||
expect.objectContaining({ type: "user_message", text: "previous question" }),
|
||||
expect.objectContaining({ type: "assistant_message", text: "previous answer" }),
|
||||
],
|
||||
);
|
||||
expect(events.some((event) => event.type === "session.turn")).toBe(false);
|
||||
} finally {
|
||||
await connection.close();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
it("auto-accepts ordinary permissions only in the unattended mode and refuses to switch while busy", async () => {
|
||||
const modeConfig = {
|
||||
id: "mode",
|
||||
name: "Mode",
|
||||
category: "mode",
|
||||
type: "select",
|
||||
currentValue: "default",
|
||||
options: [
|
||||
{ value: "default", name: "Default" },
|
||||
{ value: "plan", name: "Plan" },
|
||||
],
|
||||
};
|
||||
const approval = {
|
||||
sessionId: "connector-session",
|
||||
toolCall: { toolCallId: "tool", title: "Write a file", rawInput: {} },
|
||||
options: [
|
||||
{ optionId: "always", name: "Always allow", kind: "allow_always" },
|
||||
{ optionId: "once", name: "Allow once", kind: "allow_once" },
|
||||
{ optionId: "deny", name: "Deny", kind: "reject_once" },
|
||||
],
|
||||
};
|
||||
let finishPrompt: (() => void) | undefined;
|
||||
let stopping = false;
|
||||
const outcomes: unknown[] = [];
|
||||
const { connector } = connectorHarness({
|
||||
configOptions: [modeConfig],
|
||||
handleMessage(_runtime, message) {
|
||||
if (!("method" in message) || message.method !== "session/cancel") return false;
|
||||
stopping = true;
|
||||
return true;
|
||||
},
|
||||
handleRequest(runtime, request) {
|
||||
if (request.method !== "session/prompt") return false;
|
||||
void runtime.request("session/request_permission", approval).then((outcome) => {
|
||||
outcomes.push(outcome);
|
||||
if (stopping) {
|
||||
stopping = false;
|
||||
runtime.respond(request, { stopReason: "cancelled" });
|
||||
} else {
|
||||
finishPrompt = () => runtime.respond(request, { stopReason: "end_turn" });
|
||||
}
|
||||
return undefined;
|
||||
});
|
||||
return true;
|
||||
},
|
||||
});
|
||||
const connection = await runAcpProvider({
|
||||
id: "unattended",
|
||||
label: "Unattended",
|
||||
connector,
|
||||
acpOptions: {
|
||||
autoAcceptMode: {
|
||||
mode: { id: "full-access", label: "Full access" },
|
||||
nativeMode: "default",
|
||||
default: true,
|
||||
},
|
||||
},
|
||||
}).connect({
|
||||
versions: [1],
|
||||
capabilities: ["prompt.message", "session.configure", "permission"],
|
||||
});
|
||||
const events: ProviderEvent[] = [];
|
||||
connection.onEvent((event) => events.push(event));
|
||||
const configure = async (requestId: string, mode: string) => {
|
||||
await connection.send({
|
||||
type: "session.configure",
|
||||
requestId,
|
||||
sessionId: "session-1",
|
||||
changes: { mode },
|
||||
});
|
||||
return waitForEvent(events, (event) => "requestId" in event && event.requestId === requestId);
|
||||
};
|
||||
const prompt = (id: string) =>
|
||||
connection.send({
|
||||
type: "session.prompt",
|
||||
sessionId: "session-1",
|
||||
prompt: {
|
||||
clientMessageId: id,
|
||||
delivery: "auto",
|
||||
input: { type: "message", content: [{ type: "text", text: id }] },
|
||||
},
|
||||
});
|
||||
try {
|
||||
await connection.send({ type: "catalog", requestId: "catalog" });
|
||||
expect(await waitForEvent(events, (event) => event.type === "catalog")).toMatchObject({
|
||||
catalog: {
|
||||
defaultMode: "full-access",
|
||||
modes: expect.arrayContaining([
|
||||
{ id: "full-access", label: "Full access", isUnattended: true },
|
||||
]),
|
||||
},
|
||||
});
|
||||
await connection.send(openInput());
|
||||
await waitForEvent(events, (event) => event.type === "session.ready");
|
||||
await prompt("unattended");
|
||||
await expect
|
||||
.poll(() => outcomes[0])
|
||||
.toEqual({ outcome: { outcome: "selected", optionId: "once" } });
|
||||
expect(events.some((event) => event.type === "session.permission")).toBe(false);
|
||||
expect(await configure("busy", "plan")).toMatchObject({ type: "request.failed" });
|
||||
finishPrompt!();
|
||||
await waitForEvent(
|
||||
events,
|
||||
(event) => event.type === "session.turn" && event.state === "completed",
|
||||
);
|
||||
expect(await configure("leave", "default")).toMatchObject({ type: "request.completed" });
|
||||
|
||||
await prompt("interactive");
|
||||
await waitForEvent(events, (event) => event.type === "session.permission");
|
||||
expect(await configure("pending", "full-access")).toMatchObject({ type: "request.failed" });
|
||||
expect(outcomes).toHaveLength(1);
|
||||
await connection.send({
|
||||
type: "session.interrupt",
|
||||
requestId: "stop",
|
||||
sessionId: "session-1",
|
||||
});
|
||||
await waitForEvent(
|
||||
events,
|
||||
(event) =>
|
||||
event.type === "session.turn" &&
|
||||
event.turnId === "acp:interactive" &&
|
||||
event.state === "canceled",
|
||||
);
|
||||
await expect.poll(() => outcomes[1]).toEqual({ outcome: { outcome: "cancelled" } });
|
||||
await connection.send({
|
||||
type: "session.permission",
|
||||
sessionId: "session-1",
|
||||
permissionId: "permission:tool",
|
||||
response: { behavior: "allow" },
|
||||
});
|
||||
expect(await configure("enter", "full-access")).toMatchObject({ type: "request.completed" });
|
||||
expect(events.some((event) => event.type === "session.runtime_failed")).toBe(false);
|
||||
expect(
|
||||
events.filter((event) => event.type === "session.config").map((event) => event.config.mode),
|
||||
).toEqual(["full-access", "default", "full-access"]);
|
||||
} finally {
|
||||
await connection.close();
|
||||
}
|
||||
});
|
||||
|
||||
it("accepts a prompt as soon as the session reports ready", async () => {
|
||||
const { connector } = connectorHarness();
|
||||
const connection = await runAcpProvider({
|
||||
id: "ready-acp",
|
||||
label: "Ready ACP",
|
||||
connector,
|
||||
}).connect({ versions: [1], capabilities: ["prompt.message"] });
|
||||
try {
|
||||
const prompted = Promise.withResolvers<void>();
|
||||
connection.onEvent((event) => {
|
||||
if (event.type !== "session.ready") return;
|
||||
void connection
|
||||
.send({
|
||||
type: "session.prompt",
|
||||
sessionId: event.sessionId!,
|
||||
prompt: {
|
||||
clientMessageId: "first",
|
||||
delivery: "auto",
|
||||
input: { type: "message", content: [{ type: "text", text: "Hi" }] },
|
||||
},
|
||||
})
|
||||
.then(prompted.resolve, prompted.reject);
|
||||
});
|
||||
await connection.send(openInput());
|
||||
await prompted.promise;
|
||||
} finally {
|
||||
await connection.close();
|
||||
}
|
||||
});
|
||||
|
||||
it("uses config options for mode selection when the agent exposes no legacy modes", async () => {
|
||||
const { connector } = connectorHarness({
|
||||
configOptions: [
|
||||
{
|
||||
id: "permissions",
|
||||
category: "mode",
|
||||
name: "Permissions",
|
||||
type: "select",
|
||||
currentValue: "default",
|
||||
options: [
|
||||
{ value: "default", name: "Default" },
|
||||
{ value: "edit", name: "Accept edits" },
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
const connection = await runAcpProvider({ id: "modes", label: "Modes", connector }).connect({
|
||||
versions: [1],
|
||||
capabilities: ["session.configure"],
|
||||
});
|
||||
const events: ProviderEvent[] = [];
|
||||
connection.onEvent((event) => events.push(event));
|
||||
try {
|
||||
const input = openInput();
|
||||
input.config.mode = "edit";
|
||||
await connection.send(input);
|
||||
expect(
|
||||
await waitForEvent(
|
||||
events,
|
||||
(event) => event.type === "session.config" || event.type === "request.failed",
|
||||
),
|
||||
).toMatchObject({
|
||||
type: "session.config",
|
||||
config: { mode: "edit", modes: [{ id: "default" }, { id: "edit" }], settings: [] },
|
||||
});
|
||||
await waitForEvent(events, (event) => event.type === "session.ready");
|
||||
await connection.send({
|
||||
type: "session.configure",
|
||||
requestId: "default",
|
||||
sessionId: input.sessionId,
|
||||
changes: { mode: "default" },
|
||||
});
|
||||
expect(
|
||||
await waitForEvent(
|
||||
events,
|
||||
(event) => event.type === "session.config" && event.config.mode === "default",
|
||||
),
|
||||
).toBeDefined();
|
||||
} finally {
|
||||
await connection.close();
|
||||
}
|
||||
});
|
||||
|
||||
it("spawns the daemon-resolved launch for probes, catalogues, listing, and sessions", async () => {
|
||||
const executable = await fakeAcp(`
|
||||
if (process.env.LAUNCH_TOKEN !== "resolved" || process.env.CLAUDECODE || process.env.PASEO_NODE_ENV) process.exit(1);
|
||||
@@ -236,7 +536,7 @@ lines.on("line", (line) => {
|
||||
const message = JSON.parse(line);
|
||||
let result;
|
||||
if (message.method === "initialize") result = { protocolVersion: message.params.protocolVersion, agentCapabilities: { sessionCapabilities: { list: {} } } };
|
||||
else if (message.method === "session/new") result = { sessionId: "native", configOptions: [{ id: "model", name: "Model", category: "model", type: "select", currentValue: "resolved", options: [{ value: "resolved", name: process.env.SESSION_TOKEN || "probe" }] }] };
|
||||
else if (message.method === "session/new") result = { sessionId: "native", configOptions: [{ id: "model", name: "Model", category: "model", type: "select", currentValue: "resolved", options: [{ value: "resolved", name: require("node:fs").realpathSync(message.params.cwd) === process.cwd() ? (process.env.SESSION_TOKEN || "probe") : "wrong cwd" }] }] };
|
||||
else if (message.method === "session/list") result = { sessions: [] };
|
||||
else return;
|
||||
send({ jsonrpc: "2.0", id: message.id, result });
|
||||
@@ -254,7 +554,11 @@ lines.on("line", (line) => {
|
||||
const events: ProviderEvent[] = [];
|
||||
connection.onEvent((event) => events.push(event));
|
||||
try {
|
||||
await connection.send({ type: "catalog", requestId: "catalog" });
|
||||
await connection.send({
|
||||
type: "catalog",
|
||||
requestId: "catalog",
|
||||
cwd: path.dirname(executable),
|
||||
});
|
||||
expect(await waitForEvent(events, (event) => event.type === "catalog")).toMatchObject({
|
||||
catalog: { models: [{ id: "resolved", label: "probe" }] },
|
||||
});
|
||||
@@ -264,6 +568,7 @@ lines.on("line", (line) => {
|
||||
});
|
||||
const input = openInput();
|
||||
input.config.env = { SESSION_TOKEN: "session" };
|
||||
input.config.cwd = path.dirname(executable);
|
||||
await connection.send(input);
|
||||
expect(await waitForEvent(events, (event) => event.type === "session.config")).toMatchObject({
|
||||
config: { models: [{ id: "resolved", label: "session" }] },
|
||||
|
||||
@@ -3,9 +3,12 @@ import type {
|
||||
ProviderCatalog,
|
||||
ProviderCommand,
|
||||
ProviderConfigState,
|
||||
ProviderMode,
|
||||
ProviderNotice,
|
||||
ProviderPersistence,
|
||||
ProviderRegistration,
|
||||
ProviderTimelineItem,
|
||||
ProviderToolCallDetail,
|
||||
} from "./provider.js";
|
||||
import { createAcpProviderConnection } from "./acp-internal/connection.js";
|
||||
|
||||
@@ -48,6 +51,14 @@ export interface AcpOptions {
|
||||
workspaceOnlyCatalog?: boolean;
|
||||
waitForInitialCommands?: boolean;
|
||||
initialCommandsTimeoutMs?: number;
|
||||
/** Allow delayed session/load updates before publishing the session as ready. */
|
||||
loadReplayQuietPeriodMs?: number;
|
||||
/** An unattended mode that approves ACP allow-once requests in the specified native mode. */
|
||||
autoAcceptMode?: {
|
||||
mode: Omit<ProviderMode, "isUnattended">;
|
||||
nativeMode: string;
|
||||
default?: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
export interface AcpContext {
|
||||
@@ -65,6 +76,8 @@ export interface AcpDiscoveryContext extends AcpContext {
|
||||
|
||||
export interface AcpConfigureContext extends AcpContext {
|
||||
config: AcpConfigAccess;
|
||||
catalog(): ProviderCatalog;
|
||||
apply(change: AcpConfigChange): Promise<void>;
|
||||
}
|
||||
|
||||
export type AcpConfigChange =
|
||||
@@ -82,6 +95,7 @@ export interface AcpToolCallSnapshot {
|
||||
input: JsonValue;
|
||||
output: JsonValue;
|
||||
locations: readonly string[];
|
||||
detail?: ProviderToolCallDetail;
|
||||
}
|
||||
|
||||
export type AcpVendorUpdate =
|
||||
@@ -91,6 +105,13 @@ export type AcpVendorUpdate =
|
||||
| { type: "notice"; notice: ProviderNotice };
|
||||
|
||||
export interface AcpTransformer {
|
||||
/** Decode an older saved session and supply extension metadata for session/new or session/load. */
|
||||
sessionOpen?(context: {
|
||||
persistence?: ProviderPersistence;
|
||||
systemPrompt?: string;
|
||||
agentMetadata: JsonValue;
|
||||
}): { sessionId?: string; metadata?: Readonly<Record<string, JsonValue>> };
|
||||
|
||||
discover?(
|
||||
catalog: ProviderCatalog,
|
||||
context: AcpDiscoveryContext,
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -101,33 +101,6 @@ describe("V2Runtime against an external server", () => {
|
||||
expect(requests).toHaveLength(1);
|
||||
});
|
||||
|
||||
test("reports the external server as exited once it stops accepting connections", async () => {
|
||||
server = createServer((request, response) => {
|
||||
if (request.url !== "/api/info") {
|
||||
response.writeHead(404);
|
||||
response.end();
|
||||
return;
|
||||
}
|
||||
response.writeHead(200, { "content-type": "application/json" });
|
||||
response.end(JSON.stringify({ version: "2.0.10", pid: 1, urls: [], paths: { tmp: "/tmp" } }));
|
||||
});
|
||||
const port = await listen(server);
|
||||
const runtime = new V2Runtime({
|
||||
logger: createTestLogger(),
|
||||
externalServer: { url: `http://127.0.0.1:${port}` },
|
||||
});
|
||||
const connection = await runtime.acquire();
|
||||
const exited = connection.exited.then((error) => error.message);
|
||||
|
||||
await close(server);
|
||||
server = undefined;
|
||||
await expect(connection.client.server.info()).rejects.toThrow();
|
||||
|
||||
await expect(exited).resolves.toContain(`OpenCode server at http://127.0.0.1:${port} stopped`);
|
||||
await connection.release();
|
||||
await runtime.shutdown();
|
||||
});
|
||||
|
||||
test("selects the external server from provider environment", async () => {
|
||||
const paths: Array<string | undefined> = [];
|
||||
server = createServer((request, response) => {
|
||||
|
||||
@@ -53,14 +53,7 @@ export async function connectSharedService(
|
||||
const signal = init?.signal
|
||||
? AbortSignal.any([init.signal, lifetime.signal])
|
||||
: lifetime.signal;
|
||||
let response: Response;
|
||||
try {
|
||||
response = await fetch(request, { ...init, signal });
|
||||
} catch (error) {
|
||||
// Paseo does not own this process, so a refused connection is its only exit signal.
|
||||
if (isConnectionRefused(error)) markExited(error);
|
||||
throw error;
|
||||
}
|
||||
const response = await fetch(request, { ...init, signal });
|
||||
const html = response.headers.get("content-type")?.includes("text/html") ?? false;
|
||||
if (!response.ok || html) {
|
||||
const requestUrl = request instanceof Request ? request.url : String(request);
|
||||
@@ -69,15 +62,6 @@ export async function connectSharedService(
|
||||
return response;
|
||||
},
|
||||
});
|
||||
const markExited = (cause: unknown) => {
|
||||
if (lifetime.signal.aborted) return;
|
||||
const error = new Error(`OpenCode server at ${server.url} stopped accepting connections`, {
|
||||
cause,
|
||||
});
|
||||
logger.warn({ url: server.url }, "OpenCode v2 server stopped accepting connections");
|
||||
lifetime.abort(error);
|
||||
resolveExited(error);
|
||||
};
|
||||
let info: Awaited<ReturnType<typeof client.server.info>>;
|
||||
try {
|
||||
info = await client.server.info({
|
||||
@@ -133,13 +117,6 @@ export async function connectSharedService(
|
||||
return generation;
|
||||
}
|
||||
|
||||
function isConnectionRefused(error: unknown): boolean {
|
||||
const cause = error instanceof Error ? error.cause : undefined;
|
||||
return Boolean(
|
||||
cause && typeof cause === "object" && "code" in cause && cause.code === "ECONNREFUSED",
|
||||
);
|
||||
}
|
||||
|
||||
function validateBridgeAddress(
|
||||
selection: Extract<OpenCodeServiceSelection, { kind: "explicit" | "discovered" }>,
|
||||
bridge: OpenCodeBridge | undefined,
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1 +1 @@
|
||||
{ "id": "antigravity-provider", "requirements": { "paseo": ">=0.10.0" } }
|
||||
{ "id": "antigravity-provider", "requirements": { "paseo": ">=0.16.2" } }
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
import type {
|
||||
ProviderCatalog,
|
||||
ProviderLaunch,
|
||||
ProviderModel,
|
||||
ProviderMode,
|
||||
ProviderStatus,
|
||||
} from "@getpaseo/plugin/server/provider";
|
||||
import { probe } from "./process.js";
|
||||
import { AntigravityError } from "./wire.js";
|
||||
|
||||
const modes: readonly ProviderMode[] = [
|
||||
{
|
||||
id: "full-access",
|
||||
icon: "ShieldOff",
|
||||
colorTier: "dangerous",
|
||||
label: "Full access",
|
||||
description:
|
||||
"Antigravity cannot ask for permission when another app drives it. Paseo starts it with --dangerously-skip-permissions.",
|
||||
isUnattended: true,
|
||||
},
|
||||
];
|
||||
|
||||
export async function getCatalog(launch: ProviderLaunch, cwd?: string): Promise<ProviderCatalog> {
|
||||
const output = await probe({ launch, args: ["models"], cwd });
|
||||
const models: ProviderModel[] = [];
|
||||
for (const line of output.trim().split(/\r?\n/)) {
|
||||
const [id, label, ...extra] = line.split("\t");
|
||||
if (!id || !label || extra.length > 0)
|
||||
throw new AntigravityError("Invalid `agy models` output", "INVALID_CATALOG");
|
||||
if (models.some((model) => model.id === id))
|
||||
throw new AntigravityError(`Duplicate Antigravity model: ${id}`, "INVALID_CATALOG");
|
||||
models.push({ id, label });
|
||||
}
|
||||
return { models, modes, thinkingOptions: [], defaultMode: "full-access" };
|
||||
}
|
||||
|
||||
export async function getStatus(launch: ProviderLaunch): Promise<ProviderStatus> {
|
||||
try {
|
||||
const version = (await probe({ launch, args: ["--version"] })).trim();
|
||||
const match = /^(\d+)\.(\d+)\.(\d+)$/.exec(version);
|
||||
if (!match)
|
||||
return {
|
||||
available: false,
|
||||
diagnostic: "Could not read the Antigravity version. Update `agy` to 1.1.15 or later.",
|
||||
};
|
||||
const [, major, minor, patch] = match.map(Number);
|
||||
const supported = major > 1 || (major === 1 && (minor > 1 || (minor === 1 && patch >= 15)));
|
||||
if (!supported)
|
||||
return {
|
||||
available: false,
|
||||
diagnostic: `Antigravity ${version} is unsupported. Update \`agy\` to 1.1.15 or later.`,
|
||||
};
|
||||
await getCatalog(launch);
|
||||
return { available: true };
|
||||
} catch (error) {
|
||||
if (!(error instanceof AntigravityError)) throw error;
|
||||
return { available: false, diagnostic: error.message };
|
||||
}
|
||||
}
|
||||
|
||||
export function validateSelection(
|
||||
config: { model?: string; mode?: string; thinkingOption?: string },
|
||||
catalog: ProviderCatalog,
|
||||
): void {
|
||||
if (config.model && !catalog.models.some((model) => model.id === config.model))
|
||||
throw new AntigravityError(`Unknown Antigravity model: ${config.model}`, "INVALID_MODEL");
|
||||
if (config.mode && !catalog.modes.some((mode) => mode.id === config.mode))
|
||||
throw new AntigravityError(`Unknown Antigravity mode: ${config.mode}`, "INVALID_MODE");
|
||||
if (config.thinkingOption)
|
||||
throw new AntigravityError(
|
||||
"Antigravity effort is selected through the model ID",
|
||||
"UNSUPPORTED_THINKING",
|
||||
);
|
||||
}
|
||||
@@ -1,224 +0,0 @@
|
||||
import type { ChildProcessWithoutNullStreams } from "node:child_process";
|
||||
import { spawnProcess } from "@getpaseo/plugin/server";
|
||||
import { signalProcess } from "./signals.js";
|
||||
import { createInterface } from "node:readline";
|
||||
import type { ProviderLaunch, ProviderSessionConfig } from "@getpaseo/plugin/server/provider";
|
||||
import {
|
||||
AntigravityError,
|
||||
decodeFrame,
|
||||
diagnostic,
|
||||
encodePrompt,
|
||||
type Frame,
|
||||
type Init,
|
||||
} from "./wire.js";
|
||||
|
||||
interface DriverOptions {
|
||||
launch: ProviderLaunch;
|
||||
config: ProviderSessionConfig;
|
||||
conversationId: string | null;
|
||||
onFrame(frame: Frame): void;
|
||||
onExit(error: AntigravityError): void;
|
||||
}
|
||||
|
||||
export interface Driver {
|
||||
ready: Promise<Init>;
|
||||
selection: string;
|
||||
prompt(text: string): Promise<void>;
|
||||
stop(reason: "interrupt" | "close"): Promise<void>;
|
||||
}
|
||||
|
||||
export function selection(config: ProviderSessionConfig): string {
|
||||
return JSON.stringify([config.model, config.mode]);
|
||||
}
|
||||
|
||||
function driverArgs(options: DriverOptions): string[] {
|
||||
const { config, conversationId } = options;
|
||||
const args = [
|
||||
...options.launch.args,
|
||||
"--input-format",
|
||||
"stream-json",
|
||||
"--output-format",
|
||||
"stream-json",
|
||||
"--add-dir",
|
||||
config.cwd,
|
||||
"--disable-slash-commands",
|
||||
"--dangerously-skip-permissions",
|
||||
];
|
||||
if (config.model) args.push("--model", config.model);
|
||||
if (conversationId) args.push("--conversation", conversationId);
|
||||
return args;
|
||||
}
|
||||
|
||||
export function startDriver(options: DriverOptions): Driver {
|
||||
const child = spawnProcess(options.launch.command, driverArgs(options), {
|
||||
cwd: options.config.cwd,
|
||||
env: { ...options.launch.env, ...options.config.env },
|
||||
detached: process.platform !== "win32",
|
||||
stdio: "pipe",
|
||||
});
|
||||
const lines = createInterface({ input: child.stdout });
|
||||
let cleanup = Promise.resolve();
|
||||
let stderr = "";
|
||||
let state: "starting" | "ready" | "stopping" | "exited" = "starting";
|
||||
let resolveReady: (init: Init) => void;
|
||||
let rejectReady: (error: Error) => void;
|
||||
const ready = new Promise<Init>((resolve, reject) => {
|
||||
resolveReady = resolve;
|
||||
rejectReady = reject;
|
||||
});
|
||||
let resolveExit: () => void;
|
||||
const exited = new Promise<void>((resolve) => {
|
||||
resolveExit = resolve;
|
||||
});
|
||||
const startupDeadline = setTimeout(
|
||||
() =>
|
||||
fail(
|
||||
new AntigravityError("Antigravity did not initialize within 30 seconds", "STARTUP_TIMEOUT"),
|
||||
),
|
||||
30_000,
|
||||
);
|
||||
child.stderr.on("data", (chunk: Buffer) => {
|
||||
stderr = (stderr + chunk.toString()).slice(-8192);
|
||||
});
|
||||
child.stdin.on("error", (error: Error) =>
|
||||
fail(new AntigravityError(error.message, "STDIN_ERROR")),
|
||||
);
|
||||
child.on("error", (error: Error) => fail(new AntigravityError(error.message, "SPAWN_ERROR")));
|
||||
child.on("close", (code, signal) => {
|
||||
clearTimeout(startupDeadline);
|
||||
lines.close();
|
||||
const error = new AntigravityError(
|
||||
diagnostic(stderr.trim() || `Antigravity exited (${signal || code})`),
|
||||
"PROCESS_EXIT",
|
||||
);
|
||||
if (state === "starting") rejectReady(error);
|
||||
if (state === "ready") options.onExit(error);
|
||||
state = "exited";
|
||||
resolveExit();
|
||||
});
|
||||
lines.on("line", (line) => {
|
||||
if (!line.trim() || state === "exited" || state === "stopping") return;
|
||||
let decoded: Frame;
|
||||
try {
|
||||
decoded = decodeFrame(line);
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
fail(new AntigravityError(`Invalid Antigravity output: ${message}`, "INVALID_FRAME"));
|
||||
return;
|
||||
}
|
||||
if (state === "starting") {
|
||||
if (decoded.event === "init") {
|
||||
clearTimeout(startupDeadline);
|
||||
state = "ready";
|
||||
resolveReady(decoded);
|
||||
} else if (decoded.event === "result") {
|
||||
fail(new AntigravityError(diagnostic(decoded.result.error), "STARTUP_ERROR"));
|
||||
}
|
||||
return;
|
||||
}
|
||||
options.onFrame(decoded);
|
||||
});
|
||||
|
||||
function fail(failure: AntigravityError): void {
|
||||
clearTimeout(startupDeadline);
|
||||
if (state === "starting") rejectReady(failure);
|
||||
if (state === "ready") options.onExit(failure);
|
||||
if (state === "exited" || state === "stopping") return;
|
||||
state = "stopping";
|
||||
cleanup = Promise.resolve(signalGroup(child, "SIGKILL"));
|
||||
// The stop operation awaits cleanup and owns reporting its failure.
|
||||
void cleanup.catch(() => undefined);
|
||||
}
|
||||
|
||||
return {
|
||||
ready,
|
||||
selection: selection(options.config),
|
||||
prompt(text) {
|
||||
if (state !== "ready")
|
||||
return Promise.reject(new AntigravityError("Antigravity is not ready"));
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
child.stdin.write(encodePrompt(text), (error) => {
|
||||
if (error) reject(error);
|
||||
else resolve();
|
||||
});
|
||||
});
|
||||
},
|
||||
async stop(reason) {
|
||||
if (process.platform === "win32") await cleanup;
|
||||
if (state === "exited") return;
|
||||
if (state === "starting") rejectReady(new AntigravityError("Antigravity startup canceled"));
|
||||
clearTimeout(startupDeadline);
|
||||
state = "stopping";
|
||||
if (process.platform === "win32") {
|
||||
// Node signal emulation kills only the leader; taskkill must see the live tree.
|
||||
cleanup = Promise.resolve(signalGroup(child, "SIGKILL"));
|
||||
await cleanup;
|
||||
await exited;
|
||||
return;
|
||||
}
|
||||
if (reason === "close") child.stdin.end();
|
||||
else signalGroup(child, "SIGINT");
|
||||
const terminate = setTimeout(() => signalGroup(child, "SIGTERM"), 1000);
|
||||
const kill = setTimeout(() => signalGroup(child, "SIGKILL"), 2000);
|
||||
await exited;
|
||||
clearTimeout(terminate);
|
||||
clearTimeout(kill);
|
||||
// A tool can keep running after its CLI leader exits.
|
||||
signalGroup(child, "SIGKILL");
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function signalGroup(
|
||||
child: ChildProcessWithoutNullStreams,
|
||||
signal: NodeJS.Signals,
|
||||
): void | Promise<void> {
|
||||
if (!child.pid) return;
|
||||
return signalProcess({ platform: process.platform, pid: child.pid, signal });
|
||||
}
|
||||
|
||||
interface ProbeOptions {
|
||||
launch: ProviderLaunch;
|
||||
args: string[];
|
||||
cwd?: string;
|
||||
}
|
||||
export function probe(options: ProbeOptions): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const child = spawnProcess(options.launch.command, [...options.launch.args, ...options.args], {
|
||||
env: options.launch.env,
|
||||
cwd: options.cwd,
|
||||
stdio: "pipe",
|
||||
detached: process.platform !== "win32",
|
||||
});
|
||||
let stdout = "";
|
||||
let stderr = "";
|
||||
const deadline = setTimeout(() => {
|
||||
const termination = Promise.resolve(signalGroup(child, "SIGKILL"));
|
||||
void termination.then(() => {
|
||||
reject(new AntigravityError("Antigravity discovery timed out", "PROBE_TIMEOUT"));
|
||||
return undefined;
|
||||
}, reject);
|
||||
}, 10_000);
|
||||
child.stdout.on("data", (chunk: Buffer) => {
|
||||
stdout += chunk.toString();
|
||||
});
|
||||
child.stderr.on("data", (chunk: Buffer) => {
|
||||
stderr = (stderr + chunk.toString()).slice(-8192);
|
||||
});
|
||||
child.on("error", (error: Error) => {
|
||||
clearTimeout(deadline);
|
||||
reject(new AntigravityError(error.message, "SPAWN_ERROR"));
|
||||
});
|
||||
child.on("close", (code) => {
|
||||
clearTimeout(deadline);
|
||||
if (code === 0) resolve(stdout);
|
||||
else
|
||||
reject(
|
||||
new AntigravityError(
|
||||
diagnostic(stderr.trim() || `agy exited with code ${code}`),
|
||||
"PROBE_ERROR",
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { chmod, mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import type { ProviderPrompt } from "@getpaseo/plugin/server/provider";
|
||||
import { AntigravityError } from "./wire.js";
|
||||
|
||||
interface EncodedPrompt {
|
||||
text: string;
|
||||
nativeText: string;
|
||||
}
|
||||
|
||||
export class PromptFiles {
|
||||
private directory: string | null = null;
|
||||
|
||||
async encode(prompt: ProviderPrompt): Promise<EncodedPrompt> {
|
||||
if (
|
||||
prompt.input.type !== "message" ||
|
||||
prompt.delivery === "steer" ||
|
||||
prompt.outputSchema !== undefined
|
||||
)
|
||||
throw new AntigravityError("Antigravity supports messages only");
|
||||
const parts = prompt.input.content.map((part) => {
|
||||
if (part.type === "text") return part;
|
||||
if (part.type === "image") return { ...part, extension: imageExtension(part.mimeType) };
|
||||
throw new AntigravityError("Antigravity supports text and image content only");
|
||||
});
|
||||
const text: string[] = [];
|
||||
const native: string[] = [];
|
||||
for (const part of parts) {
|
||||
if (part.type === "text") {
|
||||
text.push(part.text);
|
||||
native.push(part.text);
|
||||
} else if (part.type === "image") {
|
||||
const extension = part.extension;
|
||||
if (this.directory === null) {
|
||||
this.directory = await mkdtemp(path.join(os.tmpdir(), "paseo-antigravity-images-"));
|
||||
await chmod(this.directory, 0o700);
|
||||
}
|
||||
const file = path.join(this.directory, `${randomUUID()}.${extension}`);
|
||||
await writeFile(file, Buffer.from(part.data, "base64"), { flag: "wx", mode: 0o600 });
|
||||
await chmod(file, 0o600);
|
||||
native.push(`Attached image: ${file}`);
|
||||
}
|
||||
}
|
||||
return { text: text.join("\n"), nativeText: native.join("\n") };
|
||||
}
|
||||
|
||||
async close(): Promise<void> {
|
||||
if (this.directory !== null) {
|
||||
await rm(this.directory, { recursive: true, force: true });
|
||||
this.directory = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function imageExtension(mimeType: string): string {
|
||||
const match = /^image\/([a-z0-9][a-z0-9.+-]*)$/i.exec(mimeType);
|
||||
if (!match) throw new AntigravityError(`Expected an image MIME type, received ${mimeType}`);
|
||||
const subtype = match[1].toLowerCase();
|
||||
if (subtype === "jpeg") return "jpg";
|
||||
if (subtype === "svg+xml") return "svg";
|
||||
return subtype;
|
||||
}
|
||||
@@ -1,397 +0,0 @@
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { z } from "zod";
|
||||
import type {
|
||||
ProviderCatalog,
|
||||
ProviderConfigChanges,
|
||||
ProviderEvent,
|
||||
ProviderPersistence,
|
||||
ProviderPrompt,
|
||||
ProviderSessionConfig,
|
||||
ProviderLaunch,
|
||||
ProviderTimelineItem,
|
||||
ProviderUsage,
|
||||
} from "@getpaseo/plugin/server/provider";
|
||||
import { startDriver, selection, type Driver } from "./process.js";
|
||||
import { validateSelection } from "./catalog.js";
|
||||
import { PromptFiles } from "./prompt.js";
|
||||
import { toolItem } from "./timeline.js";
|
||||
import { AntigravityError, diagnostic, type Frame, type Step } from "./wire.js";
|
||||
|
||||
const persistenceSchema = z
|
||||
.object({ version: z.literal(1), data: z.object({ conversationId: z.string().min(1) }).strict() })
|
||||
.strict();
|
||||
interface Turn {
|
||||
id: string;
|
||||
text: Map<number, string>;
|
||||
usageSteps: Set<number>;
|
||||
tools: Map<string, Extract<ProviderTimelineItem, { type: "tool_call" }>>;
|
||||
usage: Required<Pick<ProviderUsage, "inputTokens" | "outputTokens" | "cachedInputTokens">>;
|
||||
}
|
||||
type State =
|
||||
| { type: "dormant" }
|
||||
| { type: "starting"; driver: Driver }
|
||||
| { type: "idle"; driver: Driver }
|
||||
| { type: "running"; driver: Driver; turn: Turn }
|
||||
| { type: "stopping"; driver: Driver }
|
||||
| { type: "closed" };
|
||||
interface SessionOptions {
|
||||
id: string;
|
||||
config: ProviderSessionConfig;
|
||||
launch: ProviderLaunch;
|
||||
catalog(): ProviderCatalog;
|
||||
persistence?: ProviderPersistence;
|
||||
emit(event: ProviderEvent): void;
|
||||
}
|
||||
|
||||
export class Session {
|
||||
private state: State = { type: "dormant" };
|
||||
private config: ProviderSessionConfig;
|
||||
private conversationId: string | null;
|
||||
private firstMessage: boolean;
|
||||
private readonly promptFiles = new PromptFiles();
|
||||
private readonly reportedDenials = new Map<string, number>();
|
||||
|
||||
constructor(private readonly options: SessionOptions) {
|
||||
this.config = { ...options.config, mode: options.config.mode ?? "full-access" };
|
||||
this.conversationId = options.persistence
|
||||
? persistenceSchema.parse(options.persistence).data.conversationId
|
||||
: null;
|
||||
this.firstMessage = this.conversationId === null;
|
||||
validateSelection(this.config, options.catalog());
|
||||
}
|
||||
|
||||
async open(requestId: string, capabilities: readonly string[]): Promise<void> {
|
||||
await this.ensureDriver();
|
||||
this.emit({
|
||||
type: "session.opened",
|
||||
requestId,
|
||||
sessionId: this.options.id,
|
||||
capabilities,
|
||||
restoration: "core",
|
||||
persistence: this.config.persist ? this.persistence() : undefined,
|
||||
cwd: this.config.cwd,
|
||||
title: this.config.title,
|
||||
});
|
||||
this.publishFullAccessNotice();
|
||||
this.publishConfig();
|
||||
this.emit({ type: "session.commands", sessionId: this.options.id, commands: [] });
|
||||
this.emit({ type: "session.ready", requestId, sessionId: this.options.id });
|
||||
}
|
||||
|
||||
async prompt(prompt: ProviderPrompt): Promise<void> {
|
||||
if (this.state.type === "running")
|
||||
throw new AntigravityError(
|
||||
"Antigravity already has an active turn; wait for it to finish",
|
||||
"TURN_ACTIVE",
|
||||
);
|
||||
const { text, nativeText } = await this.promptFiles.encode(prompt);
|
||||
await this.ensureDriver();
|
||||
if (this.state.type !== "idle") throw new AntigravityError("Antigravity session is not ready");
|
||||
const driver = this.state.driver;
|
||||
const turn: Turn = {
|
||||
id: randomUUID(),
|
||||
text: new Map(),
|
||||
usageSteps: new Set(),
|
||||
tools: new Map(),
|
||||
usage: { inputTokens: 0, outputTokens: 0, cachedInputTokens: 0 },
|
||||
};
|
||||
this.state = { type: "running", driver, turn };
|
||||
this.emit({
|
||||
type: "session.prompt_result",
|
||||
sessionId: this.options.id,
|
||||
clientMessageId: prompt.clientMessageId,
|
||||
result: { type: "turn", turnId: turn.id },
|
||||
});
|
||||
this.emit({
|
||||
type: "session.turn",
|
||||
sessionId: this.options.id,
|
||||
turnId: turn.id,
|
||||
state: "started",
|
||||
});
|
||||
this.item({
|
||||
type: "user_message",
|
||||
id: prompt.clientMessageId,
|
||||
clientMessageId: prompt.clientMessageId,
|
||||
text,
|
||||
});
|
||||
const driverText =
|
||||
this.firstMessage && this.config.systemPrompt
|
||||
? `${this.config.systemPrompt}\n\n${nativeText}`
|
||||
: nativeText;
|
||||
try {
|
||||
await driver.prompt(driverText);
|
||||
this.firstMessage = false;
|
||||
} catch (error) {
|
||||
if (!(error instanceof Error)) throw error;
|
||||
this.failTurn(new AntigravityError(error.message));
|
||||
await driver.stop("interrupt");
|
||||
}
|
||||
}
|
||||
|
||||
configure(changes: ProviderConfigChanges): void {
|
||||
const config = {
|
||||
...this.config,
|
||||
model: changes.model === null ? undefined : (changes.model ?? this.config.model),
|
||||
mode: changes.mode === null ? "full-access" : (changes.mode ?? this.config.mode),
|
||||
thinkingOption:
|
||||
changes.thinkingOption === null
|
||||
? undefined
|
||||
: (changes.thinkingOption ?? this.config.thinkingOption),
|
||||
};
|
||||
if (changes.settings && Object.keys(changes.settings).length > 0)
|
||||
throw new AntigravityError("Antigravity has no configurable settings");
|
||||
validateSelection(config, this.options.catalog());
|
||||
this.config = config;
|
||||
this.publishConfig();
|
||||
}
|
||||
|
||||
async interrupt(): Promise<void> {
|
||||
if (this.state.type !== "running") return;
|
||||
const { driver, turn } = this.state;
|
||||
this.state = { type: "stopping", driver };
|
||||
await driver.stop("interrupt");
|
||||
this.finishTools(turn, "canceled");
|
||||
this.emit({
|
||||
type: "session.turn",
|
||||
sessionId: this.options.id,
|
||||
turnId: turn.id,
|
||||
state: "canceled",
|
||||
});
|
||||
this.state = { type: "dormant" };
|
||||
}
|
||||
|
||||
async close(): Promise<void> {
|
||||
const state = this.state;
|
||||
this.state = { type: "closed" };
|
||||
try {
|
||||
if (state.type !== "dormant" && state.type !== "closed") await state.driver.stop("close");
|
||||
} finally {
|
||||
await this.promptFiles.close();
|
||||
}
|
||||
if (state.type === "running") {
|
||||
this.finishTools(state.turn, "canceled");
|
||||
this.emit({
|
||||
type: "session.turn",
|
||||
sessionId: this.options.id,
|
||||
turnId: state.turn.id,
|
||||
state: "canceled",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private publishFullAccessNotice(): void {
|
||||
this.emit({
|
||||
type: "session.notice",
|
||||
sessionId: this.options.id,
|
||||
notice: {
|
||||
id: `${this.options.id}:full-access`,
|
||||
severity: "warning",
|
||||
title: "Antigravity is running with full access",
|
||||
description:
|
||||
"Antigravity's CLI cannot ask for permission when another app drives it, so Paseo starts it with --dangerously-skip-permissions. Every tool call, including shell commands, runs without asking.",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
private async ensureDriver(): Promise<void> {
|
||||
if (this.state.type === "closed") throw new AntigravityError("Antigravity session is closed");
|
||||
if (this.state.type === "stopping") {
|
||||
await this.state.driver.stop("interrupt");
|
||||
this.state = { type: "dormant" };
|
||||
}
|
||||
if (this.state.type === "idle" && this.state.driver.selection !== selection(this.config)) {
|
||||
const driver = this.state.driver;
|
||||
this.state = { type: "stopping", driver };
|
||||
await driver.stop("close");
|
||||
this.state = { type: "dormant" };
|
||||
}
|
||||
if (this.state.type !== "dormant") return;
|
||||
this.reportedDenials.clear();
|
||||
const driver = startDriver({
|
||||
launch: this.options.launch,
|
||||
config: this.config,
|
||||
conversationId: this.conversationId,
|
||||
onFrame: (frame) => this.accept(frame),
|
||||
onExit: (error) => this.failTurn(error),
|
||||
});
|
||||
this.state = { type: "starting", driver };
|
||||
try {
|
||||
const init = await driver.ready;
|
||||
if (this.conversationId !== null && init.conversation_id !== this.conversationId)
|
||||
throw new AntigravityError(
|
||||
"Antigravity restored a different conversation",
|
||||
"INVALID_RESUME",
|
||||
);
|
||||
this.conversationId = init.conversation_id;
|
||||
this.state = { type: "idle", driver };
|
||||
if (this.config.persist)
|
||||
this.emit({
|
||||
type: "session.persistence",
|
||||
sessionId: this.options.id,
|
||||
persistence: this.persistence(),
|
||||
});
|
||||
} catch (error) {
|
||||
this.state = { type: "dormant" };
|
||||
await driver.stop("interrupt");
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
private accept(frame: Frame): void {
|
||||
if (this.state.type !== "running") return;
|
||||
const { turn, driver } = this.state;
|
||||
if (frame.event === "step_update") {
|
||||
this.acceptStep(frame.step_update, turn);
|
||||
return;
|
||||
}
|
||||
if (frame.event !== "result") return;
|
||||
const result = frame.result;
|
||||
const denied = takeNewDenials(result.denied_actions, this.reportedDenials);
|
||||
if (denied.length > 0) {
|
||||
this.emit({
|
||||
type: "session.notice",
|
||||
sessionId: this.options.id,
|
||||
notice: {
|
||||
id: `${turn.id}:denied`,
|
||||
severity: "warning",
|
||||
title: denialNoticeTitle(denied),
|
||||
description: "Antigravity's own policy denied it.",
|
||||
},
|
||||
});
|
||||
}
|
||||
if (result.status === "ERROR") {
|
||||
const canceled = result.error === "interrupted";
|
||||
this.finishTools(turn, canceled ? "canceled" : "failed");
|
||||
this.retire(driver);
|
||||
this.emit({
|
||||
type: "session.turn",
|
||||
sessionId: this.options.id,
|
||||
turnId: turn.id,
|
||||
state: canceled ? "canceled" : "failed",
|
||||
error: { message: diagnostic(result.error) },
|
||||
});
|
||||
} else {
|
||||
this.finishTools(turn, "completed");
|
||||
this.state = { type: "idle", driver };
|
||||
this.emit({
|
||||
type: "session.turn",
|
||||
sessionId: this.options.id,
|
||||
turnId: turn.id,
|
||||
state: "completed",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private acceptStep(step: Step, turn: Turn): void {
|
||||
const id = `${turn.id}:${step.step_index}`;
|
||||
if (step.step_type === "agent_response") {
|
||||
const previous = turn.text.get(step.step_index) || "";
|
||||
const text = previous + step.text_delta;
|
||||
turn.text.set(step.step_index, text);
|
||||
if (step.text_delta) this.item({ type: "assistant_message", id, messageId: id, text });
|
||||
if (step.state === "DONE" && step.usage && !turn.usageSteps.has(step.step_index)) {
|
||||
turn.usageSteps.add(step.step_index);
|
||||
turn.usage.inputTokens += step.usage.input_tokens;
|
||||
turn.usage.outputTokens += step.usage.output_tokens;
|
||||
turn.usage.cachedInputTokens += step.usage.cache_read_tokens;
|
||||
this.emit({
|
||||
type: "session.usage",
|
||||
sessionId: this.options.id,
|
||||
turnId: turn.id,
|
||||
usage: { ...turn.usage },
|
||||
});
|
||||
}
|
||||
} else if (step.step_type === "tool" || step.step_type === "subagent") {
|
||||
const item = toolItem(step, id);
|
||||
turn.tools.set(id, item);
|
||||
this.item(item);
|
||||
}
|
||||
}
|
||||
|
||||
private failTurn(error: AntigravityError): void {
|
||||
const state = this.state;
|
||||
if (state.type !== "running" && state.type !== "idle") return;
|
||||
this.retire(state.driver);
|
||||
if (state.type === "running") {
|
||||
this.finishTools(state.turn, "failed");
|
||||
this.emit({
|
||||
type: "session.turn",
|
||||
sessionId: this.options.id,
|
||||
turnId: state.turn.id,
|
||||
state: "failed",
|
||||
error: { message: error.message, code: error.code },
|
||||
});
|
||||
} else
|
||||
this.emit({
|
||||
type: "session.runtime_failed",
|
||||
sessionId: this.options.id,
|
||||
error: { message: error.message, code: error.code },
|
||||
});
|
||||
}
|
||||
|
||||
private retire(driver: Driver): void {
|
||||
this.state = { type: "stopping", driver };
|
||||
void driver.stop("interrupt").then(() => {
|
||||
if (this.state.type === "stopping" && this.state.driver === driver)
|
||||
this.state = { type: "dormant" };
|
||||
return undefined;
|
||||
});
|
||||
}
|
||||
|
||||
private finishTools(turn: Turn, status: "completed" | "failed" | "canceled"): void {
|
||||
for (const item of turn.tools.values()) {
|
||||
if (item.status !== "running") continue;
|
||||
if (status === "failed") this.item({ ...item, status, error: "Antigravity turn failed" });
|
||||
else this.item({ ...item, status, error: null });
|
||||
}
|
||||
}
|
||||
|
||||
private persistence(): ProviderPersistence {
|
||||
if (this.conversationId === null) throw new AntigravityError("Antigravity has no conversation");
|
||||
return { version: 1, data: { conversationId: this.conversationId } };
|
||||
}
|
||||
|
||||
private publishConfig(): void {
|
||||
this.emit({
|
||||
type: "session.config",
|
||||
sessionId: this.options.id,
|
||||
config: {
|
||||
model: this.config.model,
|
||||
mode: this.config.mode || "full-access",
|
||||
models: this.options.catalog().models,
|
||||
modes: this.options.catalog().modes,
|
||||
thinkingOptions: [],
|
||||
settings: [],
|
||||
},
|
||||
});
|
||||
}
|
||||
private item(item: ProviderTimelineItem): void {
|
||||
this.emit({ type: "timeline.item", sessionId: this.options.id, item });
|
||||
}
|
||||
private emit(event: ProviderEvent): void {
|
||||
this.options.emit(event);
|
||||
}
|
||||
}
|
||||
|
||||
// Native results contain every denial since this driver started, including repeated actions.
|
||||
function takeNewDenials(
|
||||
actions: Extract<Frame, { event: "result" }>["result"]["denied_actions"],
|
||||
reported: Map<string, number>,
|
||||
) {
|
||||
const counts = new Map<string, number>();
|
||||
const fresh = actions.filter((action) => {
|
||||
const key = JSON.stringify([action.action, action.display_name]);
|
||||
const count = (counts.get(key) ?? 0) + 1;
|
||||
counts.set(key, count);
|
||||
return count > (reported.get(key) ?? 0);
|
||||
});
|
||||
for (const [key, count] of counts) reported.set(key, Math.max(count, reported.get(key) ?? 0));
|
||||
return fresh;
|
||||
}
|
||||
|
||||
function denialNoticeTitle(
|
||||
actions: Extract<Frame, { event: "result" }>["result"]["denied_actions"],
|
||||
): string {
|
||||
if (actions.length > 1) return `${actions.length} actions denied`;
|
||||
return actions[0].action === "command" ? "Shell command denied" : "Action denied";
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
import { execCommand } from "@getpaseo/plugin/server";
|
||||
|
||||
interface SignalOptions {
|
||||
platform: NodeJS.Platform;
|
||||
pid: number;
|
||||
signal: NodeJS.Signals;
|
||||
}
|
||||
|
||||
type SignalPlan =
|
||||
| { type: "group"; pid: number; signal: NodeJS.Signals }
|
||||
| { type: "tree"; command: "taskkill"; args: string[] };
|
||||
|
||||
export function signalPlan(options: SignalOptions): SignalPlan {
|
||||
if (options.platform === "win32") {
|
||||
return { type: "tree", command: "taskkill", args: ["/PID", String(options.pid), "/T", "/F"] };
|
||||
}
|
||||
return { type: "group", pid: -options.pid, signal: options.signal };
|
||||
}
|
||||
|
||||
export function signalProcess(options: SignalOptions): void | Promise<void> {
|
||||
const plan = signalPlan(options);
|
||||
if (plan.type === "tree") return killTree(plan);
|
||||
try {
|
||||
process.kill(plan.pid, plan.signal);
|
||||
} catch (error) {
|
||||
if (!(error instanceof Error && "code" in error && error.code === "ESRCH")) throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async function killTree(plan: Extract<SignalPlan, { type: "tree" }>): Promise<void> {
|
||||
try {
|
||||
await execCommand(plan.command, plan.args, { shell: false });
|
||||
} catch (error) {
|
||||
// taskkill reports an already-exited PID with exit code 128.
|
||||
if (!(error instanceof Error && "code" in error && error.code === 128)) throw error;
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
import type {
|
||||
ProviderTimelineItem,
|
||||
ProviderToolCallDetail,
|
||||
} from "@getpaseo/plugin/server/provider";
|
||||
import type { Step } from "./wire.js";
|
||||
|
||||
export function toolItem(
|
||||
step: Step,
|
||||
id: string,
|
||||
): Extract<ProviderTimelineItem, { type: "tool_call" }> {
|
||||
const detail = toolDetail(step);
|
||||
const name = step.tool_name || "Antigravity tool";
|
||||
const metadata = step.subagent_info ? { subagents: step.subagent_info.subagents } : undefined;
|
||||
const base = { type: "tool_call" as const, id, callId: id, name, detail, metadata };
|
||||
if (step.state === "ERROR") {
|
||||
const error =
|
||||
step.tool_info && step.tool_info.error
|
||||
? step.tool_info.error.message
|
||||
: "Antigravity tool failed";
|
||||
return { ...base, status: "failed", error };
|
||||
}
|
||||
const status = step.state === "ACTIVE" ? "running" : "completed";
|
||||
return { ...base, status, error: null };
|
||||
}
|
||||
|
||||
function toolDetail(step: Step): ProviderToolCallDetail {
|
||||
if (step.subagent_info) {
|
||||
const child = step.subagent_info.subagents[0];
|
||||
if (child)
|
||||
return {
|
||||
type: "sub_agent",
|
||||
subAgentType: child.type_name,
|
||||
description: child.initial_prompt,
|
||||
childSessionId: child.conversation_id === null ? undefined : child.conversation_id,
|
||||
log: child.log_uri,
|
||||
};
|
||||
}
|
||||
const info = step.tool_info;
|
||||
if (!info) return { type: "plain_text", label: step.tool_name, text: "" };
|
||||
const path = info.parameters.AbsolutePath || info.parameters.TargetFile;
|
||||
if (info.name === "run_command" && typeof info.parameters.CommandLine === "string") {
|
||||
return { type: "shell", command: info.parameters.CommandLine, output: info.output };
|
||||
}
|
||||
if (info.name === "view_file" && typeof path === "string")
|
||||
return { type: "read", filePath: path, content: info.output };
|
||||
if (info.name === "write_to_file" && typeof path === "string")
|
||||
return { type: "write", filePath: path };
|
||||
if (
|
||||
(info.name === "replace_file_content" || info.name === "multi_replace_file_content") &&
|
||||
typeof path === "string"
|
||||
)
|
||||
return { type: "edit", filePath: path };
|
||||
// Native frames summarize writes; they do not carry the file contents or diff.
|
||||
return { type: "unknown", input: info.parameters, output: info.error || info.output };
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
import { z } from "zod";
|
||||
|
||||
const usage = z.object({
|
||||
input_tokens: z.number().nonnegative(),
|
||||
output_tokens: z.number().nonnegative(),
|
||||
cache_read_tokens: z.number().nonnegative().default(0),
|
||||
});
|
||||
const tool = z.object({
|
||||
name: z.string(),
|
||||
parameters: z.record(z.string(), z.json()).default({}),
|
||||
output: z.string().default(""),
|
||||
error: z.object({ type: z.string(), message: z.string() }).nullable().default(null),
|
||||
});
|
||||
const child = z.object({
|
||||
type_name: z.string(),
|
||||
role: z.string().default(""),
|
||||
initial_prompt: z.string().default(""),
|
||||
conversation_id: z.string().nullable().default(null),
|
||||
log_uri: z.string().default(""),
|
||||
workspace_uris: z.array(z.string()).default([]),
|
||||
});
|
||||
const frame = z.discriminatedUnion("event", [
|
||||
z.object({
|
||||
event: z.literal("init"),
|
||||
conversation_id: z.string().min(1),
|
||||
init: z.object({ model: z.string().nullable().default(null) }),
|
||||
}),
|
||||
z.object({
|
||||
event: z.literal("step_update"),
|
||||
step_update: z.object({
|
||||
conversation_id: z.string(),
|
||||
step_index: z.number().int().nonnegative(),
|
||||
state: z.enum(["ACTIVE", "DONE", "ERROR"]),
|
||||
step_type: z.string(),
|
||||
text_delta: z.string().default(""),
|
||||
tool_name: z.string().default(""),
|
||||
tool_info: tool.nullable().default(null),
|
||||
subagent_info: z
|
||||
.object({ subagents: z.array(child) })
|
||||
.nullable()
|
||||
.default(null),
|
||||
usage: usage.nullable().default(null),
|
||||
}),
|
||||
}),
|
||||
z.object({
|
||||
event: z.literal("result"),
|
||||
result: z.object({
|
||||
conversation_id: z.string(),
|
||||
status: z.enum(["SUCCESS", "ERROR"]),
|
||||
response: z.string().default(""),
|
||||
error: z.string().default("Antigravity turn failed"),
|
||||
denied_actions: z
|
||||
.array(z.object({ action: z.string(), display_name: z.string() }))
|
||||
.default([]),
|
||||
}),
|
||||
}),
|
||||
]);
|
||||
export type Frame = z.infer<typeof frame>;
|
||||
export type Step = Extract<Frame, { event: "step_update" }>["step_update"];
|
||||
export type Init = Extract<Frame, { event: "init" }>;
|
||||
|
||||
export function decodeFrame(line: string): Frame {
|
||||
return frame.parse(JSON.parse(line));
|
||||
}
|
||||
|
||||
export function encodePrompt(text: string): string {
|
||||
return `${JSON.stringify({ event: "user", message: { content: text } })}\n`;
|
||||
}
|
||||
|
||||
export class AntigravityError extends Error {
|
||||
constructor(
|
||||
message: string,
|
||||
readonly code = "ANTIGRAVITY_ERROR",
|
||||
) {
|
||||
super(message);
|
||||
this.name = "AntigravityError";
|
||||
}
|
||||
}
|
||||
|
||||
export function diagnostic(message: string): string {
|
||||
if (/auth|sign.in|log.in/i.test(message)) {
|
||||
return "Antigravity authentication failed. Run `agy` and sign in, then retry.";
|
||||
}
|
||||
return message;
|
||||
}
|
||||
@@ -1,791 +1,186 @@
|
||||
import { mkdtemp, readFile, rm, stat, writeFile } from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import {
|
||||
PROVIDER_CAPABILITIES,
|
||||
ProviderEventSchema,
|
||||
type ProviderConnection,
|
||||
type ProviderContent,
|
||||
type ProviderEvent,
|
||||
type ProviderInput,
|
||||
type ProviderLaunch,
|
||||
type ProviderPersistence,
|
||||
} from "@getpaseo/plugin/server/provider";
|
||||
import { signalPlan } from "./internal/signals.js";
|
||||
import { tmpdir } from "node:os";
|
||||
import type { ProviderEvent } from "@getpaseo/plugin/server/provider";
|
||||
import { afterEach, expect, it } from "vitest";
|
||||
import { createAntigravityProvider } from "./provider.js";
|
||||
|
||||
const temporary: string[] = [];
|
||||
const connections: ProviderConnection[] = [];
|
||||
const fake = fileURLToPath(new URL("../test/agy.mjs", import.meta.url));
|
||||
const provider = createAntigravityProvider();
|
||||
|
||||
it("publishes a monochrome, theme-aware provider icon", async () => {
|
||||
const icon = await readFile(new URL("../icon.svg", import.meta.url), "utf8");
|
||||
expect(icon).toContain('viewBox="0 0 24 24"');
|
||||
expect(icon).toContain('fill="currentColor"');
|
||||
expect(icon).not.toMatch(/#[\da-f]{3,8}\b|rgba?\(|hsla?\(|url\(/i);
|
||||
expect(icon).not.toMatch(/<(?:style|mask|defs|linearGradient|radialGradient)\b|\bid=/i);
|
||||
expect([...icon.matchAll(/\b(?:fill|stroke)="([^"]+)"/g)].map((match) => match[1])).toEqual([
|
||||
"currentColor",
|
||||
]);
|
||||
});
|
||||
const directories: string[] = [];
|
||||
|
||||
afterEach(async () => {
|
||||
await Promise.all(connections.splice(0).map((connection) => connection.close()));
|
||||
await Promise.all(
|
||||
temporary.splice(0).map((directory) => rm(directory, { recursive: true, force: true })),
|
||||
);
|
||||
await Promise.all(directories.splice(0).map((directory) => rm(directory, { recursive: true })));
|
||||
});
|
||||
|
||||
async function harness(env: Record<string, string> = {}) {
|
||||
const cwd = await mkdtemp(path.join(os.tmpdir(), "antigravity-test-"));
|
||||
temporary.push(cwd);
|
||||
const log = path.join(cwd, "argv.ndjson");
|
||||
const launch: ProviderLaunch = {
|
||||
command: process.execPath,
|
||||
args: [fake, "--launch-prefix"],
|
||||
env: { AGY_TEST_LOG: log, ...env },
|
||||
};
|
||||
const connection = await provider.connect({
|
||||
versions: [1],
|
||||
capabilities: PROVIDER_CAPABILITIES,
|
||||
launch,
|
||||
});
|
||||
connections.push(connection);
|
||||
const events: ProviderEvent[] = [];
|
||||
connection.onEvent((event) => {
|
||||
ProviderEventSchema.parse(event);
|
||||
events.push(event);
|
||||
});
|
||||
async function wait(predicate: (event: ProviderEvent) => boolean) {
|
||||
await expect.poll(() => events.some(predicate), { timeout: 5000, interval: 10 }).toBe(true);
|
||||
const event = events.find(predicate);
|
||||
if (!event) throw new Error("Expected event missing");
|
||||
return event;
|
||||
}
|
||||
async function request(input: ProviderInput) {
|
||||
await connection.send(input);
|
||||
if ("requestId" in input)
|
||||
await wait(
|
||||
(event) =>
|
||||
"requestId" in event &&
|
||||
event.requestId === input.requestId &&
|
||||
(event.type === "request.completed" ||
|
||||
event.type === "request.failed" ||
|
||||
event.type === "session.ready" ||
|
||||
event.type === "catalog"),
|
||||
);
|
||||
}
|
||||
async function open(restored?: ProviderPersistence, sessionId = "s") {
|
||||
await request({
|
||||
type: "session.open",
|
||||
requestId: `open-${events.length}`,
|
||||
sessionId,
|
||||
persistence: restored,
|
||||
history: "replay",
|
||||
config: {
|
||||
cwd,
|
||||
env: { AGY_SESSION_VALUE: "session-overlay" },
|
||||
settings: {},
|
||||
mcpServers: {},
|
||||
persist: true,
|
||||
systemPrompt: "SYSTEM PREFIX",
|
||||
},
|
||||
});
|
||||
}
|
||||
async function message(content: ProviderContent[], sessionId = "s") {
|
||||
const clientMessageId = `prompt-${events.length}`;
|
||||
await connection.send({
|
||||
type: "session.prompt",
|
||||
sessionId,
|
||||
prompt: {
|
||||
clientMessageId,
|
||||
delivery: "auto",
|
||||
input: { type: "message", content },
|
||||
},
|
||||
});
|
||||
await wait(
|
||||
(event) =>
|
||||
event.type === "session.prompt_result" && event.clientMessageId === clientMessageId,
|
||||
);
|
||||
return clientMessageId;
|
||||
}
|
||||
function prompt(text: string) {
|
||||
return message([{ type: "text", text }]);
|
||||
}
|
||||
async function completed(clientMessageId: string) {
|
||||
const result = events.find(
|
||||
(event) =>
|
||||
event.type === "session.prompt_result" && event.clientMessageId === clientMessageId,
|
||||
);
|
||||
if (!result || result.type !== "session.prompt_result" || result.result.type !== "turn")
|
||||
throw new Error("Prompt was not admitted");
|
||||
const turnId = result.result.turnId;
|
||||
return wait(
|
||||
(event) =>
|
||||
event.type === "session.turn" && event.turnId === turnId && event.state !== "started",
|
||||
);
|
||||
}
|
||||
async function records() {
|
||||
return (await readFile(log, "utf8"))
|
||||
.trim()
|
||||
.split("\n")
|
||||
.map((line) => JSON.parse(line));
|
||||
}
|
||||
function persistence() {
|
||||
const opened = events.find((event) => event.type === "session.opened");
|
||||
if (!opened || opened.type !== "session.opened" || !opened.persistence)
|
||||
throw new Error("Missing persistence");
|
||||
return opened.persistence;
|
||||
}
|
||||
async function launchAgent(source: string) {
|
||||
const directory = await mkdtemp(path.join(tmpdir(), "paseo-antigravity-acp-"));
|
||||
directories.push(directory);
|
||||
const executable = path.join(directory, "agy.cjs");
|
||||
await writeFile(executable, source);
|
||||
return {
|
||||
connection,
|
||||
events,
|
||||
launch,
|
||||
cwd,
|
||||
wait,
|
||||
request,
|
||||
open,
|
||||
prompt,
|
||||
message,
|
||||
completed,
|
||||
records,
|
||||
persistence,
|
||||
directory,
|
||||
launch: {
|
||||
command: process.execPath,
|
||||
args: [executable, "acp", "--disable-telemetry"],
|
||||
env: { CAPTURE: path.join(directory, "requests.ndjson") },
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
it("streams complete text snapshots, prefixes the system prompt only once and preserves launch argv/env", async () => {
|
||||
const h = await harness();
|
||||
expect(h.connection.capabilities).toEqual([
|
||||
"prompt.message",
|
||||
"prompt.image",
|
||||
"session.configure",
|
||||
"session.persistence",
|
||||
]);
|
||||
await h.open();
|
||||
await h.completed(await h.prompt("HELLO"));
|
||||
await h.completed(await h.prompt("HELLO AGAIN"));
|
||||
const text = h.events.filter(
|
||||
(event) => event.type === "timeline.item" && event.item.type === "assistant_message",
|
||||
);
|
||||
expect(
|
||||
text.map((event) =>
|
||||
event.type === "timeline.item" && event.item.type === "assistant_message"
|
||||
? event.item.text
|
||||
: "",
|
||||
),
|
||||
).toEqual(["PHASE0_HELLO", "PHASE0_HELLO\n", "PHASE0_HELLO", "PHASE0_HELLO\n"]);
|
||||
const records = await h.records();
|
||||
expect(records.find((entry) => entry.args.includes("--input-format")).args).toEqual([
|
||||
"--launch-prefix",
|
||||
"--input-format",
|
||||
"stream-json",
|
||||
"--output-format",
|
||||
"stream-json",
|
||||
"--add-dir",
|
||||
h.cwd,
|
||||
"--disable-slash-commands",
|
||||
"--dangerously-skip-permissions",
|
||||
]);
|
||||
expect(records.find((entry) => entry.args.includes("--input-format")).env).toBe(
|
||||
"session-overlay",
|
||||
);
|
||||
expect(
|
||||
records.filter((entry) => entry.input).map((entry) => entry.input.message.content),
|
||||
).toEqual(["SYSTEM PREFIX\n\nHELLO", "HELLO AGAIN"]);
|
||||
it("reports a CLI without the acp subcommand as unavailable", async () => {
|
||||
const { launch } = await launchAgent(`
|
||||
process.stderr.write("Unknown command: acp");
|
||||
process.exitCode = 1;
|
||||
`);
|
||||
const provider = createAntigravityProvider();
|
||||
expect(provider.command?.slice(0, 2)).toEqual(["agy", "acp"]);
|
||||
expect(await provider.status!({ launch })).toMatchObject({
|
||||
available: false,
|
||||
diagnostic: expect.stringContaining("1.5.0"),
|
||||
});
|
||||
});
|
||||
|
||||
it("maps tools and emits one denial notice for a SUCCESS result", async () => {
|
||||
const h = await harness();
|
||||
await h.open();
|
||||
// This capture contains three distinct native results, one for each submitted prompt.
|
||||
await h.completed(await h.prompt("TOOLS"));
|
||||
await h.completed(await h.prompt("TOOLS"));
|
||||
const result = await h.completed(await h.prompt("TOOLS"));
|
||||
expect(result).toMatchObject({ type: "session.turn", state: "completed" });
|
||||
const tools = h.events.filter(
|
||||
(event) => event.type === "timeline.item" && event.item.type === "tool_call",
|
||||
);
|
||||
expect(tools).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
item: expect.objectContaining({
|
||||
name: "view_file",
|
||||
status: "completed",
|
||||
detail: expect.objectContaining({ type: "read" }),
|
||||
it.each([true, false])(
|
||||
"loads a saved stream-JSON session with ACP system prompt support %s",
|
||||
async (supportsSystemPrompt) => {
|
||||
const { directory, launch } = await launchAgent(`
|
||||
const { appendFileSync } = require("node:fs");
|
||||
const { createInterface } = require("node:readline");
|
||||
const configOptions = [
|
||||
{ id: "model", name: "Model", category: "model", type: "select", currentValue: "gemini-4-neon",
|
||||
options: [{ value: "gemini-4-neon", name: "Gemini 4 Neon" }, { value: "gemini-3.8-flash", name: "Gemini 3.8 Flash" }, { value: "gemini-4-neon-high", name: "Gemini 4 Neon High" }] },
|
||||
{ id: "thought_level", name: "Thinking", category: "thought_level", type: "select", currentValue: "low",
|
||||
options: [{ value: "low", name: "Low" }, { value: "high", name: "High" }] },
|
||||
{ id: "mode", name: "Mode", category: "mode", type: "select", currentValue: "accept-edits",
|
||||
options: [{ value: "default", name: "Default" }, { value: "accept-edits", name: "Accept edits" }] },
|
||||
];
|
||||
const send = (message) => process.stdout.write(JSON.stringify({ jsonrpc: "2.0", ...message }) + "\\n");
|
||||
createInterface({ input: process.stdin }).on("line", (line) => {
|
||||
appendFileSync(process.env.CAPTURE, line + "\\n");
|
||||
const { id, method, params } = JSON.parse(line);
|
||||
switch (method) {
|
||||
case "initialize":
|
||||
send({ id, result: { protocolVersion: 1, agentCapabilities: {
|
||||
loadSession: true,
|
||||
_meta: { antigravity: { systemPrompt: { append: ${supportsSystemPrompt} } } },
|
||||
} } });
|
||||
break;
|
||||
case "session/load":
|
||||
send({ method: "session/update", params: { sessionId: params.sessionId, update: {
|
||||
sessionUpdate: "agent_message_chunk", content: { type: "text", text: "Saved reply" },
|
||||
} } });
|
||||
send({ method: "session/update", params: { sessionId: params.sessionId, update: {
|
||||
sessionUpdate: "tool_call", toolCallId: "write", name: "write_file", title: "File notes.txt",
|
||||
status: "completed", kind: "edit", rawInput: { Path: "/repo/notes.txt", Content: "hello" },
|
||||
} } });
|
||||
send({ id, result: { configOptions } });
|
||||
break;
|
||||
case "session/set_config_option":
|
||||
configOptions.find(option => option.id === params.configId).currentValue = params.value;
|
||||
send({ id, result: { configOptions } });
|
||||
break;
|
||||
case "session/close":
|
||||
send({ id, result: {} });
|
||||
break;
|
||||
}
|
||||
});
|
||||
`);
|
||||
const provider = createAntigravityProvider();
|
||||
expect(await provider.status!({ launch })).toEqual({ available: true });
|
||||
const connection = await provider.connect({
|
||||
launch,
|
||||
versions: [1],
|
||||
capabilities: ["session.configure", "session.persistence"],
|
||||
});
|
||||
const events: ProviderEvent[] = [];
|
||||
connection.onEvent((event) => events.push(event));
|
||||
try {
|
||||
await connection.send({
|
||||
type: "session.open",
|
||||
requestId: "restore",
|
||||
sessionId: "test",
|
||||
history: "replay",
|
||||
persistence: { version: 1, data: { conversationId: "saved-conversation" } },
|
||||
config: {
|
||||
cwd: directory,
|
||||
model: "gemini-3.8-flash-high",
|
||||
mode: "full-access",
|
||||
systemPrompt: "A test system instruction",
|
||||
env: {},
|
||||
mcpServers: {},
|
||||
settings: {},
|
||||
persist: true,
|
||||
},
|
||||
});
|
||||
await expect
|
||||
.poll(
|
||||
() =>
|
||||
events.find(
|
||||
(event) => event.type === "session.ready" || event.type === "request.failed",
|
||||
),
|
||||
{ timeout: 3_000 },
|
||||
)
|
||||
.toMatchObject({ type: "session.ready" });
|
||||
expect(events).toContainEqual(
|
||||
expect.objectContaining({
|
||||
type: "session.opened",
|
||||
persistence: { version: 1, data: { sessionId: "saved-conversation" } },
|
||||
}),
|
||||
}),
|
||||
expect.objectContaining({
|
||||
item: expect.objectContaining({
|
||||
name: "write_to_file",
|
||||
status: "completed",
|
||||
detail: expect.objectContaining({ type: "write" }),
|
||||
);
|
||||
expect(events).toContainEqual(
|
||||
expect.objectContaining({
|
||||
type: "timeline.item",
|
||||
item: expect.objectContaining({ type: "assistant_message", text: "Saved reply" }),
|
||||
}),
|
||||
}),
|
||||
expect.objectContaining({
|
||||
item: expect.objectContaining({
|
||||
name: "run_command",
|
||||
status: "failed",
|
||||
detail: expect.objectContaining({ type: "shell", command: "printf PHASE0_SHELL" }),
|
||||
}),
|
||||
}),
|
||||
]),
|
||||
);
|
||||
const notices = h.events.filter(
|
||||
(event) => event.type === "session.notice" && event.notice.id !== "s:full-access",
|
||||
);
|
||||
expect(notices).toHaveLength(1);
|
||||
expect(notices[0]).toMatchObject({
|
||||
notice: {
|
||||
title: "Shell command denied",
|
||||
description: "Antigravity's own policy denied it.",
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("reports only new process denials across replayed turns and resets after respawn", async () => {
|
||||
const h = await harness();
|
||||
await h.open();
|
||||
await h.completed(await h.prompt("DENIAL_REPLAY"));
|
||||
expect(
|
||||
h.events.filter(
|
||||
(event) => event.type === "session.notice" && event.notice.id !== "s:full-access",
|
||||
),
|
||||
).toHaveLength(1);
|
||||
const followupStart = h.events.length;
|
||||
await h.completed(await h.prompt("DENIAL_REPLAY"));
|
||||
const followup = h.events.slice(followupStart);
|
||||
expect(
|
||||
followup.some(
|
||||
(event) => event.type === "session.notice" && event.notice.id !== "s:full-access",
|
||||
),
|
||||
).toBe(false);
|
||||
expect(followup).toContainEqual(
|
||||
expect.objectContaining({
|
||||
type: "timeline.item",
|
||||
item: expect.objectContaining({ type: "assistant_message", text: "FOLLOWUP_OK\n" }),
|
||||
}),
|
||||
);
|
||||
await h.request({
|
||||
type: "session.configure",
|
||||
sessionId: "s",
|
||||
requestId: "mode",
|
||||
changes: { model: "gemini-3.8-flash-low" },
|
||||
});
|
||||
await h.completed(await h.prompt("DENIAL_REPLAY"));
|
||||
expect(
|
||||
h.events.filter(
|
||||
(event) => event.type === "session.notice" && event.notice.id !== "s:full-access",
|
||||
),
|
||||
).toHaveLength(2);
|
||||
expect(
|
||||
(await h.records()).filter((entry) => entry.args?.includes("--input-format")),
|
||||
).toHaveLength(2);
|
||||
});
|
||||
|
||||
it("counts repeated native action denials without exposing tool identifiers", async () => {
|
||||
const h = await harness({ AGY_TEST_DENIAL_COUNTS: "2,2,3" });
|
||||
await h.open();
|
||||
await h.completed(await h.prompt("DENIAL_REPLAY"));
|
||||
await h.completed(await h.prompt("DENIAL_REPLAY"));
|
||||
const notices = h.events.filter(
|
||||
(event) => event.type === "session.notice" && event.notice.id !== "s:full-access",
|
||||
);
|
||||
expect(notices).toHaveLength(1);
|
||||
expect(notices[0]).toMatchObject({
|
||||
notice: {
|
||||
title: "2 actions denied",
|
||||
description: "Antigravity's own policy denied it.",
|
||||
},
|
||||
});
|
||||
await h.completed(await h.prompt("DENIAL_REPLAY"));
|
||||
expect(
|
||||
h.events.filter(
|
||||
(event) => event.type === "session.notice" && event.notice.id !== "s:full-access",
|
||||
),
|
||||
).toHaveLength(2);
|
||||
expect(
|
||||
h.events.findLast(
|
||||
(event) => event.type === "session.notice" && event.notice.id !== "s:full-access",
|
||||
),
|
||||
).toMatchObject({
|
||||
notice: { title: "Shell command denied" },
|
||||
});
|
||||
});
|
||||
|
||||
it("accounts DONE generation usage once without adding cumulative results, including resume", async () => {
|
||||
const h = await harness();
|
||||
await h.open();
|
||||
await h.completed(await h.prompt("MULTI"));
|
||||
await h.completed(await h.prompt("MULTI"));
|
||||
const usages = h.events.filter((event) => event.type === "session.usage");
|
||||
expect(
|
||||
usages.map((event) => (event.type === "session.usage" ? event.usage.inputTokens : null)),
|
||||
).toEqual([11263, 11604]);
|
||||
const persistence = h.persistence();
|
||||
await h.request({ type: "session.close", sessionId: "s", requestId: "close" });
|
||||
await h.open(persistence);
|
||||
await h.completed(await h.prompt("RESUME"));
|
||||
expect(h.events.filter((event) => event.type === "session.usage")).toHaveLength(3);
|
||||
expect(h.events.findLast((event) => event.type === "session.usage")).toMatchObject({
|
||||
usage: { inputTokens: 11815 },
|
||||
});
|
||||
});
|
||||
|
||||
it("maps subagent steps to a tool carrying the child conversation ID", async () => {
|
||||
const h = await harness();
|
||||
await h.open();
|
||||
await h.completed(await h.prompt("SUBAGENT"));
|
||||
expect(h.events).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
type: "timeline.item",
|
||||
item: expect.objectContaining({
|
||||
name: "invoke_subagent",
|
||||
status: "completed",
|
||||
detail: expect.objectContaining({
|
||||
type: "sub_agent",
|
||||
childSessionId: "b6f02329-7415-49a7-a9a9-1cd09e898d26",
|
||||
);
|
||||
expect(events).toContainEqual(
|
||||
expect.objectContaining({
|
||||
type: "session.config",
|
||||
config: expect.objectContaining({
|
||||
mode: "full-access",
|
||||
modes: expect.arrayContaining([
|
||||
expect.objectContaining({ id: "full-access", isUnattended: true }),
|
||||
]),
|
||||
model: "gemini-3.8-flash",
|
||||
thinkingOption: "high",
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
it.each(["HANG", "TOOL_HANG"])(
|
||||
"interrupts %s, settles canceled, and respawns the same conversation",
|
||||
async (text) => {
|
||||
const h = await harness();
|
||||
await h.open();
|
||||
const message = await h.prompt(text);
|
||||
await h.wait(
|
||||
(event) =>
|
||||
event.type === "timeline.item" &&
|
||||
(event.item.type === "assistant_message" || event.item.type === "tool_call"),
|
||||
);
|
||||
await h.request({ type: "session.interrupt", requestId: "interrupt", sessionId: "s" });
|
||||
expect(await h.completed(message)).toMatchObject({ state: "canceled" });
|
||||
await h.completed(await h.prompt("HELLO"));
|
||||
const records = await h.records();
|
||||
const launches = records.filter((entry) => entry.args && entry.args.includes("--input-format"));
|
||||
expect(launches).toHaveLength(2);
|
||||
expect(launches[1].args.slice(-2)).toEqual([
|
||||
"--conversation",
|
||||
"e5cf1e2d-c715-4328-8e67-4a85c8dc3cda",
|
||||
]);
|
||||
// Windows taskkill terminates the tree without invoking the CLI's signal handlers.
|
||||
expect(records.filter((entry) => entry.signal)).toEqual(
|
||||
process.platform === "win32" ? [] : [{ signal: "SIGINT" }],
|
||||
);
|
||||
const canceled = h.events.filter(
|
||||
(event) => event.type === "session.turn" && event.state === "canceled",
|
||||
);
|
||||
expect(canceled).toHaveLength(1);
|
||||
},
|
||||
);
|
||||
|
||||
it("stops an unresponsive driver and still respawns the conversation", async () => {
|
||||
const h = await harness({ AGY_TEST_IGNORE_SIGNALS: "yes" });
|
||||
await h.open();
|
||||
const message = await h.prompt("HANG");
|
||||
await h.wait(
|
||||
(event) => event.type === "timeline.item" && event.item.type === "assistant_message",
|
||||
);
|
||||
await h.request({ type: "session.interrupt", requestId: "interrupt-timeout", sessionId: "s" });
|
||||
expect(await h.completed(message)).toMatchObject({ state: "canceled" });
|
||||
expect((await h.records()).filter((entry) => entry.signal)).toEqual(
|
||||
process.platform === "win32" ? [] : [{ signal: "SIGINT" }, { signal: "SIGTERM" }],
|
||||
);
|
||||
await h.completed(await h.prompt("HELLO"));
|
||||
});
|
||||
|
||||
it("rejects plan and keeps the full-access selection without respawning", async () => {
|
||||
const h = await harness();
|
||||
await h.open();
|
||||
await h.request({
|
||||
type: "session.configure",
|
||||
requestId: "plan",
|
||||
sessionId: "s",
|
||||
changes: { mode: "plan" },
|
||||
});
|
||||
expect(h.events).toContainEqual(
|
||||
expect.objectContaining({
|
||||
type: "request.failed",
|
||||
requestId: "plan",
|
||||
error: { code: "INVALID_MODE", message: "Unknown Antigravity mode: plan" },
|
||||
}),
|
||||
);
|
||||
await h.request({
|
||||
type: "session.configure",
|
||||
requestId: "full",
|
||||
sessionId: "s",
|
||||
changes: { mode: "full-access" },
|
||||
});
|
||||
await h.completed(await h.prompt("HELLO"));
|
||||
expect(
|
||||
(await h.records()).filter((entry) => entry.args?.includes("--input-format")),
|
||||
).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("emits one full-access warning per open, none on respawn, and one again on resume", async () => {
|
||||
const h = await harness();
|
||||
await h.open();
|
||||
const warning = {
|
||||
type: "session.notice",
|
||||
sessionId: "s",
|
||||
notice: {
|
||||
id: "s:full-access",
|
||||
severity: "warning",
|
||||
title: "Antigravity is running with full access",
|
||||
description:
|
||||
"Antigravity's CLI cannot ask for permission when another app drives it, so Paseo starts it with --dangerously-skip-permissions. Every tool call, including shell commands, runs without asking.",
|
||||
},
|
||||
};
|
||||
const opened = h.events.findIndex((event) => event.type === "session.opened");
|
||||
expect(h.events[opened + 1]).toEqual(warning);
|
||||
expect(h.events.slice(0, opened).some((event) => event.type === "session.notice")).toBe(false);
|
||||
await h.completed(await h.prompt("HELLO"));
|
||||
await h.request({
|
||||
type: "session.configure",
|
||||
requestId: "model",
|
||||
sessionId: "s",
|
||||
changes: { model: "gemini-3.8-flash-low" },
|
||||
});
|
||||
await h.completed(await h.prompt("HELLO"));
|
||||
expect(h.events.filter((event) => event.type === "session.notice")).toEqual([warning]);
|
||||
const launches = (await h.records()).filter((entry) => entry.args?.includes("--input-format"));
|
||||
expect(launches).toHaveLength(2);
|
||||
for (const launch of launches) {
|
||||
expect(launch.args).toContain("--dangerously-skip-permissions");
|
||||
expect(launch.args).not.toContain("--mode");
|
||||
}
|
||||
const persistence = h.persistence();
|
||||
await h.connection.close();
|
||||
const resumed = await harness();
|
||||
await resumed.open(persistence);
|
||||
await resumed.completed(await resumed.prompt("RESUME"));
|
||||
expect(resumed.events.filter((event) => event.type === "session.notice")).toEqual([warning]);
|
||||
});
|
||||
|
||||
it("defers model and mode changes until the next prompt, then respawns with validated flags", async () => {
|
||||
const h = await harness();
|
||||
await h.open();
|
||||
await h.request({
|
||||
type: "session.configure",
|
||||
requestId: "change",
|
||||
sessionId: "s",
|
||||
changes: { model: "gemini-3.8-flash-low", mode: "full-access" },
|
||||
});
|
||||
expect(
|
||||
(await h.records()).filter((entry) => entry.args && entry.args.includes("--input-format")),
|
||||
).toHaveLength(1);
|
||||
await h.completed(await h.prompt("HELLO"));
|
||||
const launches = (await h.records()).filter(
|
||||
(entry) => entry.args && entry.args.includes("--input-format"),
|
||||
);
|
||||
expect(launches).toHaveLength(2);
|
||||
expect(launches[1].args.slice(-4)).toEqual([
|
||||
"--model",
|
||||
"gemini-3.8-flash-low",
|
||||
"--conversation",
|
||||
"e5cf1e2d-c715-4328-8e67-4a85c8dc3cda",
|
||||
]);
|
||||
await h.request({
|
||||
type: "session.configure",
|
||||
requestId: "invalid",
|
||||
sessionId: "s",
|
||||
changes: { model: "unknown" },
|
||||
});
|
||||
expect(h.events).toContainEqual(
|
||||
expect.objectContaining({
|
||||
type: "request.failed",
|
||||
requestId: "invalid",
|
||||
error: expect.objectContaining({ code: "INVALID_MODEL" }),
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("resumes after connection close without replay or another system prefix", async () => {
|
||||
const first = await harness();
|
||||
await first.open();
|
||||
await first.completed(await first.prompt("HELLO"));
|
||||
const persistence = first.persistence();
|
||||
await first.connection.close();
|
||||
const second = await harness();
|
||||
await second.open(persistence);
|
||||
expect(second.events.filter((event) => event.type === "timeline.item")).toEqual([]);
|
||||
await second.completed(await second.prompt("RESUME"));
|
||||
expect(
|
||||
(await second.records())
|
||||
.filter((entry) => entry.input)
|
||||
.map((entry) => entry.input.message.content),
|
||||
).toEqual(["RESUME"]);
|
||||
});
|
||||
|
||||
it.each(["auth", "exit", "stderr"])(
|
||||
"reports startup %s without waiting for init forever",
|
||||
async (startup) => {
|
||||
const h = await harness({ AGY_TEST_STARTUP: startup });
|
||||
await h.open();
|
||||
expect(h.events.filter((event) => event.type === "session.ready")).toEqual([]);
|
||||
const failure = h.events.find((event) => event.type === "request.failed");
|
||||
expect(failure).toMatchObject({
|
||||
type: "request.failed",
|
||||
error: {
|
||||
message: expect.stringMatching(startup === "exit" ? /exited/ : /Run `agy` and sign in/),
|
||||
},
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it("rejects mid-turn steering and reports a busy message without queueing a second native turn", async () => {
|
||||
const h = await harness();
|
||||
await h.open();
|
||||
await h.prompt("HANG");
|
||||
const second = await h.prompt("SECOND");
|
||||
expect(
|
||||
h.events.find(
|
||||
(event) => event.type === "session.prompt_result" && event.clientMessageId === second,
|
||||
),
|
||||
).toMatchObject({
|
||||
type: "session.prompt_result",
|
||||
result: { type: "failed", error: { code: "TURN_ACTIVE" } },
|
||||
});
|
||||
await expect(
|
||||
h.connection.send({
|
||||
type: "session.prompt",
|
||||
sessionId: "s",
|
||||
prompt: {
|
||||
clientMessageId: "steer",
|
||||
delivery: "steer",
|
||||
input: { type: "message", content: [{ type: "text", text: "x" }] },
|
||||
},
|
||||
}),
|
||||
).rejects.toThrow(/prompt.steer/);
|
||||
});
|
||||
|
||||
describe("discovery", () => {
|
||||
it("reuses one discovered catalog for two opens and configure, and refreshes explicit catalog requests", async () => {
|
||||
const h = await harness();
|
||||
await h.open();
|
||||
await h.open(undefined, "second");
|
||||
await h.request({
|
||||
type: "session.configure",
|
||||
requestId: "configure-cached",
|
||||
sessionId: "second",
|
||||
changes: { model: "gemini-3.8-flash-low" },
|
||||
});
|
||||
expect(
|
||||
(await h.records()).filter((entry) => entry.args && entry.args.includes("models")),
|
||||
).toHaveLength(1);
|
||||
await h.request({ type: "catalog", requestId: "refresh" });
|
||||
expect(
|
||||
(await h.records()).filter((entry) => entry.args && entry.args.includes("models")),
|
||||
).toHaveLength(2);
|
||||
});
|
||||
it.each(["1.1.15", "1.2.12", "1.2.13"])("accepts driver-capable version %s", async (version) => {
|
||||
const h = await harness({ AGY_TEST_VERSION: version });
|
||||
expect(await provider.status?.({ launch: h.launch })).toEqual({ available: true });
|
||||
});
|
||||
|
||||
it("parses tab-separated catalog and exposes only full access without thinking options", async () => {
|
||||
const h = await harness();
|
||||
await h.request({ type: "catalog", requestId: "catalog" });
|
||||
const event = h.events[0];
|
||||
expect(event).toMatchObject({
|
||||
type: "catalog",
|
||||
catalog: {
|
||||
models: expect.arrayContaining([
|
||||
{ id: "gemini-3.8-flash-low", label: "Gemini 3.8 Flash (Low)" },
|
||||
]),
|
||||
thinkingOptions: [],
|
||||
defaultMode: "full-access",
|
||||
},
|
||||
});
|
||||
if (event.type !== "catalog") throw new Error("Missing catalog");
|
||||
expect(event.catalog.models).toHaveLength(11);
|
||||
expect(event.catalog.modes).toEqual([
|
||||
{
|
||||
id: "full-access",
|
||||
label: "Full access",
|
||||
icon: "ShieldOff",
|
||||
colorTier: "dangerous",
|
||||
isUnattended: true,
|
||||
description:
|
||||
"Antigravity cannot ask for permission when another app drives it. Paseo starts it with --dangerously-skip-permissions.",
|
||||
},
|
||||
]);
|
||||
});
|
||||
it("reports missing, old, unauthenticated and available launches", async () => {
|
||||
expect(await provider.status?.({})).toMatchObject({
|
||||
available: false,
|
||||
diagnostic: expect.stringContaining("agy not found"),
|
||||
});
|
||||
const missing = await harness();
|
||||
expect(
|
||||
await provider.status?.({
|
||||
launch: { ...missing.launch, command: path.join(missing.cwd, "missing-agy") },
|
||||
}),
|
||||
).toMatchObject({ available: false, diagnostic: expect.stringContaining("ENOENT") });
|
||||
const old = await harness({ AGY_TEST_VERSION: "1.1.14" });
|
||||
expect(await provider.status?.({ launch: old.launch })).toMatchObject({
|
||||
available: false,
|
||||
diagnostic: expect.stringContaining("1.1.15"),
|
||||
});
|
||||
const unauthenticated = await harness({ AGY_TEST_AUTH: "missing" });
|
||||
expect(await provider.status?.({ launch: unauthenticated.launch })).toEqual({
|
||||
available: false,
|
||||
diagnostic: "Antigravity authentication failed. Run `agy` and sign in, then retry.",
|
||||
});
|
||||
const authenticated = await harness();
|
||||
expect(await provider.status?.({ launch: authenticated.launch })).toEqual({ available: true });
|
||||
});
|
||||
it("keys catalog caching by the complete effective launch without exposing env values", async () => {
|
||||
const h = await harness();
|
||||
const key = await provider.getCatalogCacheKey?.({ scope: "global", launch: h.launch });
|
||||
expect(key).toMatch(/^[a-f0-9]{64}$/);
|
||||
expect(
|
||||
await provider.getCatalogCacheKey?.({
|
||||
scope: "workspace",
|
||||
cwd: h.cwd,
|
||||
force: true,
|
||||
launch: h.launch,
|
||||
}),
|
||||
).toBe(key);
|
||||
expect(
|
||||
await provider.getCatalogCacheKey?.({
|
||||
scope: "global",
|
||||
launch: { ...h.launch, args: [...h.launch.args, "changed"] },
|
||||
}),
|
||||
).not.toBe(key);
|
||||
expect(
|
||||
await provider.getCatalogCacheKey?.({
|
||||
scope: "global",
|
||||
launch: { ...h.launch, env: { ...h.launch.env, HOME: "different" } },
|
||||
}),
|
||||
).not.toBe(key);
|
||||
});
|
||||
});
|
||||
|
||||
describe("process signal plans", () => {
|
||||
it.each(["SIGINT", "SIGTERM", "SIGKILL"] as const)("kills the Windows tree for %s", (signal) => {
|
||||
expect(signalPlan({ platform: "win32", pid: 123, signal })).toEqual({
|
||||
type: "tree",
|
||||
command: "taskkill",
|
||||
args: ["/PID", "123", "/T", "/F"],
|
||||
});
|
||||
});
|
||||
it.each(["SIGINT", "SIGTERM", "SIGKILL"] as const)(
|
||||
"preserves POSIX group signal %s",
|
||||
(signal) => {
|
||||
expect(signalPlan({ platform: "linux", pid: 123, signal })).toEqual({
|
||||
type: "group",
|
||||
pid: -123,
|
||||
signal,
|
||||
);
|
||||
expect(events).toContainEqual(
|
||||
expect.objectContaining({
|
||||
type: "timeline.item",
|
||||
item: expect.objectContaining({
|
||||
type: "tool_call",
|
||||
detail: { type: "write", filePath: "/repo/notes.txt", content: "hello" },
|
||||
}),
|
||||
}),
|
||||
);
|
||||
await connection.send({
|
||||
type: "session.configure",
|
||||
requestId: "native-model",
|
||||
sessionId: "test",
|
||||
changes: { model: "gemini-4-neon-high" },
|
||||
});
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe("image prompts", () => {
|
||||
it.each(["session", "connection"])(
|
||||
"encodes mixed content as private session files and cleans up on %s close",
|
||||
async (close) => {
|
||||
const h = await harness();
|
||||
await h.open();
|
||||
const png = await readFile(
|
||||
new URL("../test/fixtures/image-file-external.png", import.meta.url),
|
||||
await expect
|
||||
.poll(() =>
|
||||
events.find(
|
||||
(event) =>
|
||||
event.type === "session.config" && event.config.model === "gemini-4-neon-high",
|
||||
),
|
||||
)
|
||||
.toBeDefined();
|
||||
const requests = (await readFile(launch.env.CAPTURE, "utf8"))
|
||||
.trim()
|
||||
.split("\n")
|
||||
.map((line) => JSON.parse(line));
|
||||
const load = requests.find((request) => request.method === "session/load");
|
||||
expect(load.params.sessionId).toBe("saved-conversation");
|
||||
expect(load.params._meta.antigravity).toEqual(
|
||||
supportsSystemPrompt
|
||||
? { systemPrompt: { append: "A test system instruction" } }
|
||||
: undefined,
|
||||
);
|
||||
const jpeg = Buffer.from("image file bytes");
|
||||
await h.completed(
|
||||
await h.message([
|
||||
{ type: "text", text: "Describe these images." },
|
||||
{ type: "image", data: png.toString("base64"), mimeType: "image/png" },
|
||||
{ type: "text", text: "Compare them." },
|
||||
{ type: "image", data: jpeg.toString("base64"), mimeType: "image/jpeg" },
|
||||
]),
|
||||
);
|
||||
const sent = (await h.records()).find((entry) => entry.input).input.message.content;
|
||||
const lines = sent.split("\n");
|
||||
const pngPath = lines[3].slice("Attached image: ".length);
|
||||
const jpegPath = lines[5].slice("Attached image: ".length);
|
||||
expect(sent).toBe(
|
||||
`SYSTEM PREFIX\n\nDescribe these images.\nAttached image: ${pngPath}\nCompare them.\nAttached image: ${jpegPath}`,
|
||||
);
|
||||
expect(path.isAbsolute(pngPath)).toBe(true);
|
||||
expect(path.extname(pngPath)).toBe(".png");
|
||||
expect(path.extname(jpegPath)).toBe(".jpg");
|
||||
expect(path.dirname(pngPath)).toBe(path.dirname(jpegPath));
|
||||
expect(path.dirname(pngPath)).not.toBe(h.cwd);
|
||||
expect(await readFile(pngPath)).toEqual(png);
|
||||
expect(await readFile(jpegPath)).toEqual(jpeg);
|
||||
if (process.platform !== "win32") {
|
||||
expect((await stat(path.dirname(pngPath))).mode & 0o777).toBe(0o700);
|
||||
expect((await stat(pngPath)).mode & 0o777).toBe(0o600);
|
||||
expect((await stat(jpegPath)).mode & 0o777).toBe(0o600);
|
||||
}
|
||||
const args = (await h.records()).find((entry) => entry.args?.includes("--input-format")).args;
|
||||
expect(args.filter((arg: string) => arg === "--add-dir")).toHaveLength(1);
|
||||
if (close === "connection") await h.connection.close();
|
||||
else await h.request({ type: "session.close", requestId: "close-images", sessionId: "s" });
|
||||
await expect(stat(path.dirname(pngPath))).rejects.toMatchObject({ code: "ENOENT" });
|
||||
},
|
||||
);
|
||||
|
||||
it("keeps image-only prompts in distinct session directories until each session closes", async () => {
|
||||
const h = await harness();
|
||||
await h.open();
|
||||
await h.open(undefined, "other");
|
||||
const content: ProviderContent[] = [
|
||||
{ type: "image", data: "aW1hZ2U=", mimeType: "image/webp" },
|
||||
];
|
||||
await h.completed(await h.message(content));
|
||||
await h.completed(await h.message(content));
|
||||
await h.completed(await h.message(content, "other"));
|
||||
const paths = (await h.records())
|
||||
.filter((entry) => entry.input)
|
||||
.map((entry) => entry.input.message.content.split("Attached image: ")[1]);
|
||||
expect(new Set(paths).size).toBe(3);
|
||||
expect(path.dirname(paths[0])).toBe(path.dirname(paths[1]));
|
||||
expect(path.dirname(paths[0])).not.toBe(path.dirname(paths[2]));
|
||||
expect(paths.every((file: string) => path.extname(file) === ".webp")).toBe(true);
|
||||
await h.request({ type: "session.close", requestId: "close-first", sessionId: "s" });
|
||||
await expect(stat(path.dirname(paths[0]))).rejects.toMatchObject({ code: "ENOENT" });
|
||||
expect(await readFile(paths[2], "utf8")).toBe("image");
|
||||
await h.connection.close();
|
||||
await expect(stat(path.dirname(paths[2]))).rejects.toMatchObject({ code: "ENOENT" });
|
||||
});
|
||||
|
||||
it("rejects a non-image MIME type before writing to native stdin", async () => {
|
||||
const h = await harness();
|
||||
await h.open();
|
||||
const id = await h.message([{ type: "image", data: "dGV4dA==", mimeType: "text/plain" }]);
|
||||
expect(
|
||||
h.events.find(
|
||||
(event) => event.type === "session.prompt_result" && event.clientMessageId === id,
|
||||
),
|
||||
).toMatchObject({
|
||||
result: { type: "failed", error: { message: expect.stringContaining("image MIME type") } },
|
||||
});
|
||||
expect((await h.records()).filter((entry) => entry.input)).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
|
||||
it.runIf(process.platform === "win32")(
|
||||
"launches an Antigravity command shim for probes and conversation startup",
|
||||
async () => {
|
||||
const h = await harness();
|
||||
const shim = path.join(h.cwd, "agy launcher.cmd");
|
||||
await writeFile(shim, `@echo off\r\n"${process.execPath}" "${fake}" %*\r\n`);
|
||||
h.launch.command = shim;
|
||||
h.launch.args = ["--launch-prefix"];
|
||||
expect(await provider.status!({ launch: h.launch })).toEqual({ available: true });
|
||||
await h.open();
|
||||
expect(await h.wait((event) => event.type === "session.opened")).toMatchObject({
|
||||
sessionId: "s",
|
||||
});
|
||||
} finally {
|
||||
await connection.close();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
@@ -1,171 +1,113 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { runAcpProvider, type AcpTransformer } from "@getpaseo/plugin/server/acp";
|
||||
import {
|
||||
negotiateProviderCapabilities,
|
||||
requireProviderCapabilities,
|
||||
type ProviderCatalog,
|
||||
type ProviderConnection,
|
||||
type ProviderEvent,
|
||||
type ProviderInput,
|
||||
type ProviderLaunch,
|
||||
PROVIDER_PROTOCOL_VERSION,
|
||||
type ProviderRegistration,
|
||||
} from "@getpaseo/plugin/server/provider";
|
||||
import { getCatalog, getStatus } from "./internal/catalog.js";
|
||||
import { Session } from "./internal/session.js";
|
||||
import { AntigravityError } from "./internal/wire.js";
|
||||
import { z } from "zod";
|
||||
|
||||
const capabilities = [
|
||||
"prompt.message",
|
||||
"prompt.image",
|
||||
"session.configure",
|
||||
"session.persistence",
|
||||
] as const;
|
||||
const legacySession = z.object({
|
||||
version: z.literal(1),
|
||||
data: z.object({ conversationId: z.string().min(1) }),
|
||||
});
|
||||
const systemPromptCapability = z.object({
|
||||
antigravity: z.object({ systemPrompt: z.object({ append: z.literal(true) }) }),
|
||||
});
|
||||
|
||||
const fileWrite = z.object({ Path: z.string(), Content: z.string().optional() });
|
||||
|
||||
const antigravity: AcpTransformer = {
|
||||
toolCall(call) {
|
||||
if (call.name === "write_file") {
|
||||
const input = fileWrite.safeParse(call.input);
|
||||
if (input.success) {
|
||||
return {
|
||||
...call,
|
||||
detail: { type: "write", filePath: input.data.Path, content: input.data.Content },
|
||||
};
|
||||
}
|
||||
}
|
||||
if (call.kind === "read" && call.locations[0]) {
|
||||
return { ...call, detail: { type: "read", filePath: call.locations[0] } };
|
||||
}
|
||||
return call;
|
||||
},
|
||||
sessionOpen({ persistence, systemPrompt, agentMetadata }) {
|
||||
// COMPAT(antigravityStreamJson): added in v0.16.2, remove after 2027-11-19.
|
||||
const saved = legacySession.safeParse(persistence);
|
||||
return {
|
||||
sessionId: saved.success ? saved.data.data.conversationId : undefined,
|
||||
metadata:
|
||||
systemPrompt && systemPromptCapability.safeParse(agentMetadata).success
|
||||
? { antigravity: { systemPrompt: { append: systemPrompt } } }
|
||||
: undefined,
|
||||
};
|
||||
},
|
||||
async configure(change, { apply, catalog }) {
|
||||
// COMPAT(antigravityStreamJson): added in v0.16.2, remove after 2027-11-19.
|
||||
if (change.target === "model" && change.value) {
|
||||
const legacyModel = /^(.*)-(xhigh|high|medium|low|minimal)$/.exec(change.value);
|
||||
if (legacyModel) {
|
||||
const { models } = catalog();
|
||||
const [, model, effort] = legacyModel;
|
||||
if (
|
||||
!models.some((option) => option.id === change.value) &&
|
||||
models.some((option) => option.id === model)
|
||||
) {
|
||||
await apply({ target: "model", value: model });
|
||||
if (catalog().thinkingOptions?.some((option) => option.id === effort)) {
|
||||
await apply({ target: "thinking", value: effort });
|
||||
}
|
||||
return "handled";
|
||||
}
|
||||
}
|
||||
}
|
||||
return "pass";
|
||||
},
|
||||
};
|
||||
|
||||
export function createAntigravityProvider(): ProviderRegistration {
|
||||
return {
|
||||
const provider = runAcpProvider({
|
||||
id: "antigravity",
|
||||
label: "Antigravity",
|
||||
icon: "icon.svg",
|
||||
command: ["agy"],
|
||||
description: "Antigravity CLI on your host",
|
||||
icon: "icon.svg",
|
||||
command: ["agy", "acp", "--disable-telemetry"],
|
||||
acpOptions: {
|
||||
waitForInitialCommands: true,
|
||||
loadReplayQuietPeriodMs: 200,
|
||||
autoAcceptMode: {
|
||||
mode: {
|
||||
id: "full-access",
|
||||
label: "Full access",
|
||||
description: "Approve tool requests without asking.",
|
||||
icon: "ShieldOff",
|
||||
colorTier: "dangerous",
|
||||
},
|
||||
nativeMode: "default",
|
||||
default: true,
|
||||
},
|
||||
},
|
||||
transformers: [antigravity],
|
||||
});
|
||||
return {
|
||||
...provider,
|
||||
async status({ launch }) {
|
||||
if (!launch)
|
||||
if (!launch) return { available: false, diagnostic: "Install Antigravity 1.5.0 or later." };
|
||||
try {
|
||||
const connection = await provider.connect({
|
||||
launch,
|
||||
versions: [PROVIDER_PROTOCOL_VERSION],
|
||||
capabilities: [],
|
||||
});
|
||||
await connection.close();
|
||||
return { available: true };
|
||||
} catch {
|
||||
return {
|
||||
available: false,
|
||||
diagnostic: "agy not found on PATH. Install Antigravity, then run `agy` and sign in.",
|
||||
diagnostic:
|
||||
"Antigravity ACP did not start. Install Antigravity 1.5.0 or later. If you override the command, include the acp subcommand.",
|
||||
};
|
||||
return getStatus(launch);
|
||||
},
|
||||
async getCatalogCacheKey({ launch }) {
|
||||
if (!launch) return undefined;
|
||||
const env = Object.entries(launch.env).sort(([left], [right]) => left.localeCompare(right));
|
||||
return createHash("sha256")
|
||||
.update(JSON.stringify([launch.command, launch.args, env]))
|
||||
.digest("hex");
|
||||
},
|
||||
async connect(request) {
|
||||
if (!request.versions.includes(1))
|
||||
throw new AntigravityError("Provider protocol version 1 is required");
|
||||
if (!request.launch)
|
||||
throw new AntigravityError("The daemon must supply the Antigravity launch");
|
||||
const negotiated = negotiateProviderCapabilities(request.capabilities, capabilities);
|
||||
return createConnection(request.launch, negotiated);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function createConnection(
|
||||
launch: ProviderLaunch,
|
||||
negotiated: readonly string[],
|
||||
): ProviderConnection {
|
||||
const sessions = new Map<string, Session>();
|
||||
const listeners = new Set<(event: ProviderEvent) => void>();
|
||||
let discovered: ProviderCatalog | null = null;
|
||||
let closed = false;
|
||||
let pending = Promise.resolve();
|
||||
|
||||
function emit(event: ProviderEvent): void {
|
||||
if (closed) return;
|
||||
for (const listener of listeners) listener(event);
|
||||
}
|
||||
function catalog(): ProviderCatalog {
|
||||
if (discovered === null)
|
||||
throw new AntigravityError("Antigravity catalog has not been discovered");
|
||||
return discovered;
|
||||
}
|
||||
function session(id: string): Session {
|
||||
const found = sessions.get(id);
|
||||
if (!found) throw new AntigravityError(`Unknown Antigravity session: ${id}`);
|
||||
return found;
|
||||
}
|
||||
async function dispatch(input: ProviderInput): Promise<void> {
|
||||
switch (input.type) {
|
||||
case "catalog":
|
||||
discovered = await getCatalog(launch, input.cwd);
|
||||
emit({
|
||||
type: "catalog",
|
||||
requestId: input.requestId,
|
||||
catalog: catalog(),
|
||||
});
|
||||
return;
|
||||
case "session.open": {
|
||||
if (sessions.has(input.sessionId))
|
||||
throw new AntigravityError(`Session already exists: ${input.sessionId}`);
|
||||
if (discovered === null) discovered = await getCatalog(launch, input.config.cwd);
|
||||
const opened = new Session({
|
||||
id: input.sessionId,
|
||||
config: input.config,
|
||||
persistence: input.persistence,
|
||||
catalog,
|
||||
launch,
|
||||
emit,
|
||||
});
|
||||
sessions.set(input.sessionId, opened);
|
||||
try {
|
||||
await opened.open(input.requestId, negotiated);
|
||||
} catch (error) {
|
||||
sessions.delete(input.sessionId);
|
||||
await opened.close();
|
||||
throw error;
|
||||
}
|
||||
return;
|
||||
}
|
||||
case "session.prompt":
|
||||
await session(input.sessionId).prompt(input.prompt);
|
||||
return;
|
||||
case "session.configure":
|
||||
session(input.sessionId).configure(input.changes);
|
||||
break;
|
||||
case "session.interrupt":
|
||||
await session(input.sessionId).interrupt();
|
||||
break;
|
||||
case "session.close": {
|
||||
await session(input.sessionId).close();
|
||||
sessions.delete(input.sessionId);
|
||||
emit({ type: "session.closed", sessionId: input.sessionId });
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new AntigravityError(`Unsupported Antigravity operation: ${input.type}`);
|
||||
}
|
||||
emit({ type: "request.completed", requestId: input.requestId });
|
||||
}
|
||||
function failed(input: ProviderInput, error: unknown): void {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
const code = error instanceof AntigravityError ? error.code : "ANTIGRAVITY_ERROR";
|
||||
if (input.type === "session.prompt")
|
||||
emit({
|
||||
type: "session.prompt_result",
|
||||
sessionId: input.sessionId,
|
||||
clientMessageId: input.prompt.clientMessageId,
|
||||
result: { type: "failed", error: { message, code } },
|
||||
});
|
||||
else if ("requestId" in input)
|
||||
emit({ type: "request.failed", requestId: input.requestId, error: { message, code } });
|
||||
}
|
||||
return {
|
||||
version: 1,
|
||||
capabilities: negotiated,
|
||||
async send(input) {
|
||||
if (closed) throw new AntigravityError("Antigravity connection is closed");
|
||||
requireProviderCapabilities(negotiated, input);
|
||||
pending = pending
|
||||
.then(async () => {
|
||||
if (!closed) await dispatch(input);
|
||||
return undefined;
|
||||
})
|
||||
.catch((error) => failed(input, error));
|
||||
},
|
||||
onEvent(listener) {
|
||||
listeners.add(listener);
|
||||
return () => listeners.delete(listener);
|
||||
},
|
||||
async close() {
|
||||
if (closed) return;
|
||||
closed = true;
|
||||
await pending;
|
||||
await Promise.all([...sessions.values()].map((opened) => opened.close()));
|
||||
sessions.clear();
|
||||
listeners.clear();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,102 +0,0 @@
|
||||
import { readFileSync, appendFileSync } from "node:fs";
|
||||
import { createInterface } from "node:readline";
|
||||
|
||||
const args = process.argv.slice(2);
|
||||
const log = process.env.AGY_TEST_LOG;
|
||||
function record(value) {
|
||||
if (log) appendFileSync(log, `${JSON.stringify(value)}\n`);
|
||||
}
|
||||
record({ args, pid: process.pid, env: process.env.AGY_SESSION_VALUE });
|
||||
function fixture(name, stream = "stdout") {
|
||||
return readFileSync(new URL(`./fixtures/${name}.${stream}.ndjson`, import.meta.url), "utf8")
|
||||
.trim()
|
||||
.split("\n")
|
||||
.filter(Boolean)
|
||||
.map((line) => JSON.parse(line).data);
|
||||
}
|
||||
if (args.includes("--version")) {
|
||||
process.stdout.write(`${process.env.AGY_TEST_VERSION || "1.2.13"}\n`);
|
||||
process.exit(0);
|
||||
}
|
||||
if (args.includes("models")) {
|
||||
if (process.env.AGY_TEST_AUTH === "missing") {
|
||||
process.stderr.write(fixture("models-unauthenticated", "stderr").join("\n"));
|
||||
process.exit(1);
|
||||
}
|
||||
process.stdout.write(fixture("models-api-key").join("\n") + "\n");
|
||||
process.exit(0);
|
||||
}
|
||||
if (process.env.AGY_TEST_STARTUP === "auth") {
|
||||
process.stderr.write(fixture("not-signed-in", "stderr").join("\n"));
|
||||
process.stdout.write(JSON.stringify(fixture("not-signed-in")[0]) + "\n");
|
||||
process.exit(1);
|
||||
}
|
||||
if (process.env.AGY_TEST_STARTUP === "exit") process.exit(3);
|
||||
if (process.env.AGY_TEST_STARTUP === "stderr") {
|
||||
process.stderr.write("Error: authentication required. Run 'agy' to log in, then retry.\n");
|
||||
process.exit(1);
|
||||
}
|
||||
const resumeIndex = args.indexOf("--conversation");
|
||||
const conversationId =
|
||||
resumeIndex >= 0 ? args[resumeIndex + 1] : fixture("text-turn")[0].conversation_id;
|
||||
let denialResults = 0;
|
||||
function emit(frame) {
|
||||
const converted = structuredClone(frame);
|
||||
if (converted.conversation_id !== undefined) converted.conversation_id = conversationId;
|
||||
if (converted.step_update) converted.step_update.conversation_id = conversationId;
|
||||
if (converted.result) {
|
||||
converted.result.conversation_id = conversationId;
|
||||
if (process.env.AGY_TEST_DENIAL_COUNTS && converted.result.denied_actions?.length) {
|
||||
converted.result.denied_actions = Array.from(
|
||||
{ length: Number(process.env.AGY_TEST_DENIAL_COUNTS.split(",")[denialResults++]) },
|
||||
() => converted.result.denied_actions[0],
|
||||
);
|
||||
}
|
||||
}
|
||||
process.stdout.write(JSON.stringify(converted) + "\n");
|
||||
}
|
||||
const init = fixture("text-turn")[0];
|
||||
if (args.includes("--model")) init.init.model = args[args.indexOf("--model") + 1];
|
||||
emit(init);
|
||||
let interrupted = null;
|
||||
const turns = new Map();
|
||||
const lines = createInterface({ input: process.stdin });
|
||||
lines.on("line", (line) => {
|
||||
const input = JSON.parse(line);
|
||||
record({ input });
|
||||
const text = input.message.content;
|
||||
let name = "text-turn";
|
||||
if (text.includes("Attached image: ")) name = "image-file-external";
|
||||
if (text.includes("TOOLS")) name = "tools-default";
|
||||
if (text.includes("DENIAL_REPLAY")) name = "denial-replay";
|
||||
if (text.includes("SUBAGENT")) name = "subagent";
|
||||
if (text.includes("MULTI")) name = "multi-turn-reasoning";
|
||||
if (text.includes("RESUME")) name = "resume";
|
||||
if (text.includes("HANG")) name = "sigint-mid-text";
|
||||
if (text.includes("TOOL_HANG")) name = "sigint-mid-tool";
|
||||
const frames = fixture(name).slice(1);
|
||||
if (name.startsWith("sigint")) {
|
||||
interrupted = frames[frames.length - 1];
|
||||
for (const frame of frames.slice(0, -1)) emit(frame);
|
||||
return;
|
||||
}
|
||||
const count = frames.filter((frame) => frame.event === "result").length;
|
||||
const ordinal = (turns.get(name) || 0) % count;
|
||||
turns.set(name, ordinal + 1);
|
||||
let resultCount = 0;
|
||||
for (const frame of frames) {
|
||||
if (resultCount === ordinal) emit(frame);
|
||||
if (frame.event === "result") resultCount += 1;
|
||||
}
|
||||
});
|
||||
process.on("SIGINT", () => {
|
||||
record({ signal: "SIGINT" });
|
||||
if (process.env.AGY_TEST_IGNORE_SIGNALS === "yes") return;
|
||||
if (interrupted) emit(interrupted);
|
||||
process.exit(1);
|
||||
});
|
||||
process.on("SIGTERM", () => {
|
||||
record({ signal: "SIGTERM" });
|
||||
if (process.env.AGY_TEST_IGNORE_SIGNALS !== "yes") process.exit(1);
|
||||
});
|
||||
lines.on("close", () => process.exit(0));
|
||||
@@ -1,100 +0,0 @@
|
||||
# agy 1.2.13 stream-json captures
|
||||
|
||||
`denial-replay.stdout.ndjson` replays two turns from one real 1.2.13 process: a denied shell
|
||||
command, then a text-only answer whose result retains the first denial. The replay clock is
|
||||
synthetic; frames retain the native cumulative denial payload.
|
||||
|
||||
Captured on Linux x86_64 on 2026-09-29. These are observations from the supplied binary, not guarantees for the Google sign-in route. No product code or capture drivers are included.
|
||||
|
||||
Each row names a capture prefix. Its `.stdin.ndjson`, `.stdout.ndjson`, `.stderr.ndjson`, and `.capture.ndjson` companions keep the streams separate; empty streams are empty files. Every line wraps the exact decoded JSON frame or text line in `{t_ms, stream, data}`. `t_ms` is milliseconds since construction immediately before spawn. Capture annotations record launch arguments, configuration, signals, EOF, timeouts, and exit code; they are not CLI output. Line references refer to the indicated file, starting at 1.
|
||||
|
||||
Commands below run from `<WORKSPACE>`. `<AGY>` expands to `<HOME>/.local/opt/agy/1.2.13/agy` in the real installation home; the child uses a separate isolated `<HOME>` for state. All captures remove inherited credential/provider environment variables, set `HOME`, `XDG_CONFIG_HOME=<HOME>/.config`, `XDG_CACHE_HOME=<HOME>/.cache`, `XDG_DATA_HOME=<HOME>/.local/share`, `BROWSER=/bin/true`, and loopback-only `NO_PROXY`/`no_proxy`. Neither PATH nor shell rc files changed. Resume rows reuse the original isolated HOME.
|
||||
|
||||
For rows marked **API**, the environment also contains `GEMINI_API_KEY=<DUMMY_KEY>` and `GOOGLE_GEMINI_BASE_URL=http://127.0.0.1:<PORT>`, and `<HOME>/.gemini/antigravity-cli/settings.json` contains `{"modelProvider":"gemini"}`. **Env only** sets those two variables without the setting; **None** has neither. The loopback translator reused the prior QA route and forwarded real requests to a paid upstream model. Its credential was read programmatically inside the temporary proxy, with later captures passing it through the proxy environment. It was never passed to agy or recorded. The translator maps all requested Gemini models to one upstream Gemini model: request routing and CLI selection are verified, native model identity/quality is not.
|
||||
|
||||
The translator emits text, function calls, thought parts and usage. Its usage mapping does not populate Gemini thinking/cache counts, so observed zero `thinking_tokens`/`cache_read_tokens` does not prove native zeros. No dedicated reasoning frames appeared, including the matched high-effort probe.
|
||||
|
||||
`<HOME>`, `<WORKSPACE>`, `<CAPTURE>`, `<PORT>`, `<DUMMY_KEY>`, and `<REDACTED_REFERENCE>` are redactions. Unrelated project/model names and help examples are redacted without removing frames. Delta chunk boundaries remain; a path split across deltas can have a different placeholder spelling than the complete result. UUIDs are retained for conversation correlation.
|
||||
|
||||
| Fixture prefix | Exact argv (redacted) | Auth | Demonstrates | agy |
|
||||
| --------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------- |
|
||||
| `agents` | `<AGY> agents` | API | Available agents listing is plain text. | 1.2.13 |
|
||||
| `api-key-env-only` | `<AGY> --input-format stream-json --output-format stream-json` | Env only | Dummy key and custom endpoint alone do not select API-key auth. | 1.2.13 |
|
||||
| `api-key-settings` | `<AGY> --input-format stream-json --output-format stream-json` | API | modelProvider=gemini yields init; missing event input is rejected. | 1.2.13 |
|
||||
| `cwd-without-add-dir` | `<AGY> --input-format stream-json --output-format stream-json --dangerously-skip-permissions` | API | Without add-dir, model-issued pwd returned launch cwd; required tool Cwd is not exposed by this wire frame. | 1.2.13 |
|
||||
| `effort-unsupported-family` | `<AGY> --input-format stream-json --output-format stream-json --model '<REDACTED_REFERENCE>' --effort high` | API | Unsupported non-Gemini family rejects effort; model reference redacted. | 1.2.13 |
|
||||
| `effort-encoded-match` | `<AGY> --input-format stream-json --output-format stream-json --model gemini-3.8-flash-high --effort high` | API | Matching high effort accepted; arithmetic turn; no thought delta observed. | 1.2.13 |
|
||||
| `effort-encoded-mismatch` | `<AGY> --input-format stream-json --output-format stream-json --model gemini-3.8-flash-high --effort low` | API | High-suffixed model conflicts with effort=low; no init. | 1.2.13 |
|
||||
| `effort-mismatch` | `<AGY> --input-format stream-json --output-format stream-json --model gemini-3.1-pro-preview --effort low` | API | Unlisted preview ID does not support effort; startup ERROR. | 1.2.13 |
|
||||
| `help` | `<AGY> --help` | None | Launch flags and subcommands; help is on stderr. | 1.2.13 |
|
||||
| `image-content` | `<AGY> --input-format stream-json --output-format stream-json --disable-slash-commands` | API | Image source block rejected: only text blocks supported. | 1.2.13 |
|
||||
| `mcp-add-http` | `<AGY> mcp add phase0 'http://127.0.0.1:<PORT>/mcp'` | None | Writes .gemini/config/mcp_config.json; file content recorded in capture annotations. | 1.2.13 |
|
||||
| `mcp-add` | `<AGY> mcp add phase0 --url 'http://127.0.0.1:<PORT>/mcp'` | None | Invalid --url syntax rejected; no configuration written. | 1.2.13 |
|
||||
| `mcp-global` | `<AGY> --input-format stream-json --output-format stream-json --add-dir '<WORKSPACE>' --disable-slash-commands --dangerously-skip-permissions` | API | Global HTTP server discovered; strict tool call fails because arguments is a string. | 1.2.13 |
|
||||
| `mcp-help` | `<AGY> mcp add --help` | None | MCP add syntax, HTTP transport, headers/env; flags precede name. | 1.2.13 |
|
||||
| `mcp-list` | `<AGY> mcp list` | None | Model-free empty server list, exit 0. | 1.2.13 |
|
||||
| `mcp-project-config` | `<AGY> --input-format stream-json --output-format stream-json --add-dir '<WORKSPACE>' --disable-slash-commands --dangerously-skip-permissions` | API | Workspace .gemini/config.json mcpServers not discovered in this probe. | 1.2.13 |
|
||||
| `mcp-project-isolated` | `<AGY> --input-format stream-json --output-format stream-json --add-dir '<WORKSPACE>' --dangerously-skip-permissions` | API | Project MCP discovery; no global MCP config before/after; strict arguments error. | 1.2.13 |
|
||||
| `mcp-project` | `<AGY> --input-format stream-json --output-format stream-json --add-dir '<WORKSPACE>' --disable-slash-commands --dangerously-skip-permissions` | API | Project .agents/mcp_config.json discovers HTTP server; strict call rejects string arguments; later translator 502 retained. | 1.2.13 |
|
||||
| `mcp-second-add-dir` | `<AGY> --input-format stream-json --output-format stream-json --disable-slash-commands --dangerously-skip-permissions --add-dir '<WORKSPACE>' --add-dir '<CAPTURE>/owned'` | API | Discovers project MCP from the owned directory; strict arguments fail. Shell uses owned directory and writes occur in both directories. | 1.2.13 |
|
||||
| `mcp-owned-first-add-dir` | `<AGY> --input-format stream-json --output-format stream-json --disable-slash-commands --dangerously-skip-permissions --add-dir '<CAPTURE>/owned' --add-dir '<WORKSPACE>'` | API | Reversing argv does not restore command working directory; owned directory remains the shell default. | 1.2.13 |
|
||||
| `mcp-owned-cwd` | `<AGY> --input-format stream-json --output-format stream-json --disable-slash-commands --dangerously-skip-permissions --add-dir '<WORKSPACE>'`, launched in `<CAPTURE>/owned` through a symlink | API | Discovers owned project MCP, but shell and initial read resolve against owned cwd; writes occur in both directories. | 1.2.13 |
|
||||
| `mcp-agent-file` | `<AGY> --input-format stream-json --output-format stream-json --disable-slash-commands --dangerously-skip-permissions --add-dir '<WORKSPACE>' --agent '<CAPTURE>/owned/agent.md'` | API | Direct external agent filename falls back to default; no MCP discovery. Shell/read/write use workspace. | 1.2.13 |
|
||||
| `mcp-agent-definition` | `<AGY> --input-format stream-json --output-format stream-json --add-dir '<CAPTURE>/owned' --add-dir '<WORKSPACE>' --agent phase2 --dangerously-skip-permissions` | API | Nested Markdown definition with inline mcpServers is not found; default agent, no MCP server. | 1.2.13 |
|
||||
| `mcp-agent-discovered` | `<AGY> --input-format stream-json --output-format stream-json --add-dir '<CAPTURE>/owned' --add-dir '<WORKSPACE>' --agent phase2 --dangerously-skip-permissions` | API | Flat Markdown definition plus agents.json manifest is also not found; default agent, no MCP server. | 1.2.13 |
|
||||
| `image-file-external` | `<AGY> --input-format stream-json --output-format stream-json --add-dir '<WORKSPACE>' --disable-slash-commands` | API | Default mode reads an external image path with view_file and correctly describes its pixels, without an extra add-dir. | 1.2.13 |
|
||||
| `model-switch-invalid` | `<AGY> --input-format stream-json --output-format stream-json --add-dir '<WORKSPACE>' --conversation b966b16a-caf4-448a-bb24-0e34956022b0 --model gemini-3.1-flash-lite-preview` | API | Unlisted model ID rejected before init. | 1.2.13 |
|
||||
| `model-switch-network` | `<AGY> --input-format stream-json --output-format stream-json --conversation b966b16a-caf4-448a-bb24-0e34956022b0 --model gemini-3.8-flash-low` | API | Listed model respawn plus actual Gemini request path in capture annotations; COBALT preserved. | 1.2.13 |
|
||||
| `model-switch-resume` | `<AGY> --input-format stream-json --output-format stream-json --add-dir '<WORKSPACE>' --conversation b966b16a-caf4-448a-bb24-0e34956022b0 --model gemini-3.1-flash-high` | API | Another unlisted model ID rejected before init. | 1.2.13 |
|
||||
| `model-switch-valid` | `<AGY> --input-format stream-json --output-format stream-json --conversation b966b16a-caf4-448a-bb24-0e34956022b0 --model gemini-3.8-flash-low` | API | Listed low-effort model accepted on same conversation; COBALT preserved. | 1.2.13 |
|
||||
| `models-api-key` | `<AGY> models` | API | Authenticated catalog is tab-separated model ID and display label. | 1.2.13 |
|
||||
| `models-unauthenticated` | `<AGY> models` | None | Models requires auth; no catalog on stdout. | 1.2.13 |
|
||||
| `multi-turn-reasoning` | `<AGY> --input-format stream-json --output-format stream-json --add-dir '<WORKSPACE>' --disable-slash-commands` | API | Two text turns with arithmetic; per-generation and cumulative usage. No thought delta observed. | 1.2.13 |
|
||||
| `not-signed-in` | `<AGY> --input-format stream-json --output-format stream-json` | None | No credentials: result ERROR, no init, exit 1. | 1.2.13 |
|
||||
| `project-skill` | `<AGY> --input-format stream-json --output-format stream-json --add-dir '<WORKSPACE>' --disable-slash-commands` | API | Project skill read via view_file; marker reply. No distinct skill event. | 1.2.13 |
|
||||
| `question-auto-denial` | `<AGY> --input-format stream-json --output-format stream-json --add-dir '<WORKSPACE>'` | API | Requested ask_question becomes unknown DONE step, auto-skipped; no question payload on wire. | 1.2.13 |
|
||||
| `resume-after-interrupt` | `<AGY> --input-format stream-json --output-format stream-json --conversation a2c2132f-0f10-400b-a142-74f82230f449` | API | Same interrupted conversation resumes and accepts another turn. | 1.2.13 |
|
||||
| `resume` | `<AGY> --input-format stream-json --output-format stream-json --add-dir '<WORKSPACE>' --disable-slash-commands --conversation b966b16a-caf4-448a-bb24-0e34956022b0` | API | Remembered COBALT after respawn; no old steps replayed. | 1.2.13 |
|
||||
| `schema-prompt` | `<AGY> --input-format stream-json --output-format stream-json` | API | Unknown prompt event ignored with stderr warning; no turn. | 1.2.13 |
|
||||
| `schema-user-message` | `<AGY> --input-format stream-json --output-format stream-json` | API | Decoding a string message fails before event dispatch. | 1.2.13 |
|
||||
| `schema-user` | `<AGY> --input-format stream-json --output-format stream-json` | API | String message rejected; message must be an object. | 1.2.13 |
|
||||
| `sigint-mid-text` | `<AGY> --input-format stream-json --output-format stream-json --add-dir '<WORKSPACE>' --disable-slash-commands --dangerously-skip-permissions` | API | SIGINT after first text delta: interrupted result and exit 1. | 1.2.13 |
|
||||
| `sigint-mid-tool` | `<AGY> --input-format stream-json --output-format stream-json --add-dir '<WORKSPACE>' --dangerously-skip-permissions` | API | SIGINT while run_command ACTIVE: interrupted result and exit 1. | 1.2.13 |
|
||||
| `sigterm` | `<AGY> --input-format stream-json --output-format stream-json --add-dir '<WORKSPACE>' --disable-slash-commands --dangerously-skip-permissions` | API | SIGTERM after user_input: interrupted result and exit 1. | 1.2.13 |
|
||||
| `slash-disabled` | `<AGY> --input-format stream-json --output-format stream-json --disable-slash-commands` | API | /help sent literally to model; normal turn with built-in skill reads. | 1.2.13 |
|
||||
| `slash-enabled` | `<AGY> --input-format stream-json --output-format stream-json` | API | /help rejected in driver mode; result ERROR and exit 2. | 1.2.13 |
|
||||
| `stdin-close-mid-turn` | `<AGY> --input-format stream-json --output-format stream-json --add-dir '<WORKSPACE>' --disable-slash-commands --dangerously-skip-permissions` | API | EOF after user_input: active turn finishes successfully, exit 0. | 1.2.13 |
|
||||
| `stdin-mid-turn` | `<AGY> --input-format stream-json --output-format stream-json --add-dir '<WORKSPACE>' --disable-slash-commands --dangerously-skip-permissions` | API | Second prompt after first user_input queues a separate turn; two results. | 1.2.13 |
|
||||
| `subagent` | `<AGY> --input-format stream-json --output-format stream-json --add-dir '<WORKSPACE>' --dangerously-skip-permissions` | API | Define/invoke child; subagent_info contains child ID/log URI/workspaces; child reply reaches parent. | 1.2.13 |
|
||||
| `text-block` | `<AGY> --input-format stream-json --output-format stream-json --add-dir '<WORKSPACE>'` | API | Array of text content blocks accepted. | 1.2.13 |
|
||||
| `text-turn` | `<AGY> --input-format stream-json --output-format stream-json --add-dir '<WORKSPACE>'` | API | event=user, message.content string; streaming text and final usage. | 1.2.13 |
|
||||
| `tools-accept-edits` | `<AGY> --input-format stream-json --output-format stream-json --add-dir '<WORKSPACE>' --disable-slash-commands --mode accept-edits` | API | Read, create, edit allowed; shell auto-denied. Result SUCCESS includes denied_actions. No permission request. | 1.2.13 |
|
||||
| `tools-default` | `<AGY> --input-format stream-json --output-format stream-json --add-dir '<WORKSPACE>' --disable-slash-commands` | API | Read, create, edit allowed; shell auto-denied. Result SUCCESS includes denied_actions. No permission request. | 1.2.13 |
|
||||
| `tools-plan` | `<AGY> --input-format stream-json --output-format stream-json --add-dir '<WORKSPACE>' --disable-slash-commands --mode plan` | API | Read, create, edit allowed; shell auto-denied. Result SUCCESS includes denied_actions. No permission request. | 1.2.13 |
|
||||
| `tools-sandbox` | `<AGY> --input-format stream-json --output-format stream-json --add-dir '<WORKSPACE>' --disable-slash-commands --sandbox` | API | Read, create, edit allowed; shell auto-denied. Result SUCCESS includes denied_actions. No permission request. | 1.2.13 |
|
||||
| `tools-skip-permissions` | `<AGY> --input-format stream-json --output-format stream-json --add-dir '<WORKSPACE>' --disable-slash-commands --dangerously-skip-permissions` | API | Read, create, edit and shell succeed; permission_mode=always-proceed. | 1.2.13 |
|
||||
| `version` | `<AGY> --version` | None | Installed binary reports 1.2.13. | 1.2.13 |
|
||||
| `mcp-http.requests.ndjson` | `node <CAPTURE>/mcp-server.mjs` alongside the MCP argv above | None | Actual HTTP JSON-RPC requests to a strict SDK server; `params.arguments` is a string. Server implements initialize, tools/list, and echo. | 1.2.13 client |
|
||||
| `state-inspection.ndjson` | `HOME=<HOME> strace -f -e trace=file -o <CAPTURE>/files.trace <AGY> --input-format stream-json --output-format stream-json`; `python3 <CAPTURE>/finalize.py`; `firecrawl scrape <OFFICIAL_MANIFEST_URL> --format markdown` | None | Binary checksum, isolated state accesses, read-only SQLite listings, written file contents, and manifest retrieval caveat. Inspection data, not agy stdout. | 1.2.13 |
|
||||
|
||||
`project-skill` used `<WORKSPACE>/.agents/skills/phase0-marker/SKILL.md` with name `phase0-marker`, description “Return the Phase 0 marker when requested,” and instructions “Respond with PHASE0_SKILL_MARKER. No tools are needed after reading this skill.”
|
||||
|
||||
Each tools capture begins with `input.txt` containing `PHASE0_READ_MARKER`, then requests create→replace from `PHASE0_WRITE` to `PHASE0_EDIT`, then `printf PHASE0_SHELL`. `state-inspection.ndjson` records the resulting files. These successful writes disprove an enforced read-only boundary for default/plan on this credential route. `--sandbox` alone still denies the shell at permission policy, so OS sandbox enforcement is unverified.
|
||||
|
||||
## MCP discovery
|
||||
|
||||
Phase 0 project setup (`mcp-project` and `mcp-project-isolated`) places `{"mcpServers":{"phase0":{"serverUrl":"http://127.0.0.1:<PORT>/mcp"}}}` in `<WORKSPACE>/.agents/mcp_config.json`. `mcp-project-config` instead uses `<WORKSPACE>/.gemini/config.json`; that file did not expose the server. HTTP calls send string arguments and fail strict validation.
|
||||
|
||||
Phase 2 places the same HTTP configuration, named `phase2`, in a plugin-owned `<CAPTURE>/owned/.agents/mcp_config.json`. Both add-dir orders discover it, as does launching in the owned directory and adding the real workspace. All three turns execute shell `pwd` in the owned directory. The file turns read the workspace marker but also write `output.txt` into the owned directory. These routes fail the requirement that tools resolve against the user's workspace. Reordering arguments did not change the observed shell cwd; the precise directory selection rule is unverified.
|
||||
|
||||
The external `--agent` file, nested agent definition, and flat definition with an `agents.json` manifest contain inline `mcpServers`. Native logs record “not found, falling back to default” for each. These experiments do not establish that every agent definition format is unsupported. `parity-inspection.ndjson` records their definitions and log evidence. Searching the tested binary's strings found no `AGY_MCP`, `MCP_CONFIG`, `AGY_CONFIG`, or `ANTIGRAVITY_CONFIG` override; no environment discovery route was verified.
|
||||
|
||||
No tested MCP route satisfies both discovery and workspace ownership. MCP implementation stopped at this gate: no relay or MCP capability change was added. Images and the daemon e2e continued independently. No global MCP configuration exists in the isolated homes, and no configuration was written into the user repository.
|
||||
|
||||
## Image file fallback
|
||||
|
||||
`image-file-external.png` contains a red triangle on the left and a blue circle on the lower right, against white. The prompt supplies only its path and asks for visible shapes and colors. `image-file-external.stdout.ndjson:4–5` records a successful `view_file`; the result describes the pixels correctly. The native function response supplies bytes at `functionResponse.parts[].inlineData`. The temporary translator was corrected to forward these nested parts to the model; forwarding top-level parts alone dropped the image. `parity-inspection.ndjson` records the image hash and response-part location.
|
||||
|
||||
This verifies one default-mode CLI turn reading a file outside the workspace without an extra add-dir. A later isolated-daemon run attached the same image through the provider and returned the same shapes and colors after a successful `view_file`. The provider advertises `prompt.image`; MCP remains outside the parity implementation.
|
||||
|
||||
Unverified: Google login behaviour; native reasoning/cached-token accounting; filesystem/network isolation under sandbox plus approved commands; exhaustive tool policy; other agent definition formats or environment MCP overrides; child transcript streaming beyond parent metadata; a stable public conversation-list command. No fresh login was created. The fetched official manifest returned 1.2.12 while this binary reports 1.2.13; the checksum identifies the tested binary, but that response does not establish its release provenance.
|
||||
@@ -1,2 +0,0 @@
|
||||
{"t_ms": 0, "stream": "capture", "data": {"argv": ["<HOME>/.local/opt/agy/1.2.13/agy", "agents"], "cwd": "<WORKSPACE>", "home": "<HOME>", "settings": {"modelProvider": "gemini"}, "env": {"GEMINI_API_KEY": "<DUMMY_KEY>", "GOOGLE_GEMINI_BASE_URL": "http://127.0.0.1:<PORT>"}}}
|
||||
{"t_ms": 309, "stream": "capture", "data": {"exit_code": 0}}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user