Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
de238add41 | ||
|
|
f8bf1b3c7a |
No files matched your search
@@ -74,7 +74,9 @@ it.layer(NodeServices.layer)("readBootstrapEnvelope", (it) => {
|
||||
(fd) => Effect.sync(() => NodeFS.closeSync(fd)),
|
||||
);
|
||||
|
||||
const payload = yield* readBootstrapEnvelope(TestEnvelopeSchema, fd, { timeoutMs: 100 });
|
||||
const payload = yield* readBootstrapEnvelope(TestEnvelopeSchema, fd, {
|
||||
timeout: Duration.millis(100),
|
||||
});
|
||||
assertSome(payload, {
|
||||
mode: "desktop",
|
||||
});
|
||||
@@ -100,7 +102,7 @@ it.layer(NodeServices.layer)("readBootstrapEnvelope", (it) => {
|
||||
openSyncInterceptor.failPath = `/proc/self/fd/${fd}`;
|
||||
try {
|
||||
const payload = yield* readBootstrapEnvelope(TestEnvelopeSchema, fd, {
|
||||
timeoutMs: 100,
|
||||
timeout: Duration.millis(100),
|
||||
}).pipe(Effect.provideService(HostProcessPlatform, "linux"));
|
||||
assertSome(payload, {
|
||||
mode: "desktop",
|
||||
@@ -125,7 +127,7 @@ it.layer(NodeServices.layer)("readBootstrapEnvelope", (it) => {
|
||||
openSyncInterceptor.errorCode = "EIO";
|
||||
try {
|
||||
const error = yield* readBootstrapEnvelope(TestEnvelopeSchema, fd, {
|
||||
timeoutMs: 100,
|
||||
timeout: Duration.millis(100),
|
||||
}).pipe(Effect.provideService(HostProcessPlatform, "linux"), Effect.flip);
|
||||
|
||||
assert.instanceOf(error, BootstrapInputStreamOpenError);
|
||||
@@ -149,7 +151,9 @@ it.layer(NodeServices.layer)("readBootstrapEnvelope", (it) => {
|
||||
const fd = NodeFS.openSync("/dev/null", "r");
|
||||
NodeFS.closeSync(fd);
|
||||
|
||||
const payload = yield* readBootstrapEnvelope(TestEnvelopeSchema, fd, { timeoutMs: 100 });
|
||||
const payload = yield* readBootstrapEnvelope(TestEnvelopeSchema, fd, {
|
||||
timeout: Duration.millis(100),
|
||||
});
|
||||
assertNone(payload);
|
||||
}),
|
||||
);
|
||||
@@ -164,7 +168,7 @@ it.layer(NodeServices.layer)("readBootstrapEnvelope", (it) => {
|
||||
fstatSyncInterceptor.failFd = fd;
|
||||
try {
|
||||
const error = yield* readBootstrapEnvelope(TestEnvelopeSchema, fd, {
|
||||
timeoutMs: 100,
|
||||
timeout: Duration.millis(100),
|
||||
}).pipe(Effect.flip);
|
||||
|
||||
assert.instanceOf(error, BootstrapFdStatError);
|
||||
@@ -188,7 +192,7 @@ it.layer(NodeServices.layer)("readBootstrapEnvelope", (it) => {
|
||||
(fd) => Effect.sync(() => NodeFS.closeSync(fd)),
|
||||
);
|
||||
const error = yield* readBootstrapEnvelope(TestEnvelopeSchema, fd, {
|
||||
timeoutMs: 100,
|
||||
timeout: Duration.millis(100),
|
||||
}).pipe(Effect.flip);
|
||||
|
||||
assert.instanceOf(error, BootstrapEnvelopeDecodeError);
|
||||
@@ -227,7 +231,7 @@ it.layer(NodeServices.layer)("readBootstrapEnvelope", (it) => {
|
||||
);
|
||||
|
||||
const fiber = yield* readBootstrapEnvelope(TestEnvelopeSchema, fd, {
|
||||
timeoutMs: 100,
|
||||
timeout: Duration.millis(100),
|
||||
}).pipe(Effect.forkScoped);
|
||||
|
||||
yield* Effect.yieldNow;
|
||||
|
||||
@@ -4,6 +4,7 @@ import * as NodeNet from "node:net";
|
||||
import * as NodeReadline from "node:readline";
|
||||
import type * as NodeStream from "node:stream";
|
||||
|
||||
import * as Duration from "effect/Duration";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Option from "effect/Option";
|
||||
import * as Predicate from "effect/Predicate";
|
||||
@@ -75,7 +76,7 @@ export const readBootstrapEnvelope = Effect.fn("readBootstrapEnvelope")(function
|
||||
schema: Schema.Codec<A, I>,
|
||||
fd: number,
|
||||
options?: {
|
||||
timeoutMs?: number;
|
||||
readonly timeout?: Duration.Duration;
|
||||
},
|
||||
): Effect.fn.Return<Option.Option<A>, BootstrapError> {
|
||||
const fdReady = yield* isFdReady(fd);
|
||||
@@ -83,7 +84,7 @@ export const readBootstrapEnvelope = Effect.fn("readBootstrapEnvelope")(function
|
||||
|
||||
const stream = yield* makeBootstrapInputStream(fd);
|
||||
|
||||
const timeoutMs = options?.timeoutMs ?? 1000;
|
||||
const timeout = options?.timeout ?? Duration.seconds(1);
|
||||
|
||||
return yield* Effect.callback<
|
||||
Option.Option<A>,
|
||||
@@ -142,7 +143,7 @@ export const readBootstrapEnvelope = Effect.fn("readBootstrapEnvelope")(function
|
||||
input.once("close", handleClose);
|
||||
|
||||
return Effect.sync(cleanup);
|
||||
}).pipe(Effect.timeoutOption(timeoutMs), Effect.map(Option.flatten));
|
||||
}).pipe(Effect.timeoutOption(timeout), Effect.map(Option.flatten));
|
||||
});
|
||||
|
||||
const isUnavailableBootstrapFdError = Predicate.compose(
|
||||
|
||||
@@ -24,6 +24,7 @@ interface Props {
|
||||
url: string;
|
||||
displayUrl?: string | undefined;
|
||||
loading: boolean;
|
||||
loadProgress: number;
|
||||
canGoBack: boolean;
|
||||
canGoForward: boolean;
|
||||
refreshDisabled: boolean;
|
||||
@@ -58,33 +59,11 @@ interface Props {
|
||||
|
||||
const NOOP = () => {};
|
||||
|
||||
function useFocusPreviewUrlInput(
|
||||
inputRef: React.RefObject<HTMLInputElement | null>,
|
||||
focusUrlNonce: number | undefined,
|
||||
): void {
|
||||
useEffect(() => {
|
||||
if (focusUrlNonce == null) return;
|
||||
inputRef.current?.focus();
|
||||
}, [focusUrlNonce, inputRef]);
|
||||
}
|
||||
|
||||
function PreviewLoadingProgress({ loading }: { loading: boolean }) {
|
||||
return (
|
||||
<div
|
||||
aria-hidden
|
||||
className={cn(
|
||||
"pointer-events-none absolute bottom-0 left-0 z-10 h-0.5 w-full origin-left rounded-r-full bg-primary",
|
||||
loading ? "preview-loading-progress-active" : "preview-loading-progress-idle",
|
||||
)}
|
||||
style={{ boxShadow: "0 0 6px 1px var(--color-ring)" }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export function PreviewChromeRow({
|
||||
url,
|
||||
displayUrl,
|
||||
loading,
|
||||
loadProgress,
|
||||
canGoBack,
|
||||
canGoForward,
|
||||
refreshDisabled,
|
||||
@@ -107,7 +86,13 @@ export function PreviewChromeRow({
|
||||
const inputRef = useRef<HTMLInputElement | null>(null);
|
||||
const [draft, setDraft] = useState(url);
|
||||
const [inputFocused, setInputFocused] = useState(false);
|
||||
useFocusPreviewUrlInput(inputRef, focusUrlNonce);
|
||||
|
||||
useEffect(() => {
|
||||
if (focusUrlNonce == null) return;
|
||||
const node = inputRef.current;
|
||||
if (!node) return;
|
||||
node.focus();
|
||||
}, [focusUrlNonce]);
|
||||
|
||||
const submit = (event?: FormEvent | KeyboardEvent) => {
|
||||
event?.preventDefault();
|
||||
@@ -291,7 +276,16 @@ export function PreviewChromeRow({
|
||||
) : null}
|
||||
{trailingActions}
|
||||
</form>
|
||||
<PreviewLoadingProgress loading={loading} />
|
||||
{loadProgress > 0 ? (
|
||||
<div
|
||||
aria-hidden
|
||||
className="pointer-events-none absolute bottom-0 left-0 z-10 h-0.5 rounded-r-full bg-primary transition-all duration-150 ease-out"
|
||||
style={{
|
||||
width: `${loadProgress}%`,
|
||||
boxShadow: "0 0 6px 1px var(--color-ring)",
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -39,6 +39,7 @@ import { revealInFileExplorerLabel } from "./fileExplorerLabel";
|
||||
import { shouldShowPreviewEmptyState } from "./previewEmptyStateLogic";
|
||||
import { BrowserSurfaceSlot } from "~/browser/BrowserSurfaceSlot";
|
||||
import { useBrowserSurfaceStore } from "~/browser/browserSurfaceStore";
|
||||
import { useLoadingProgress } from "./useLoadingProgress";
|
||||
import { usePreviewSession } from "./usePreviewSession";
|
||||
import { ZoomIndicator } from "./ZoomIndicator";
|
||||
import { AgentBrowserCursor } from "./AgentBrowserCursor";
|
||||
@@ -97,6 +98,7 @@ export function PreviewView({ threadRef, tabId: requestedTabId, configuredUrls,
|
||||
const isUnreachable = navStatus._tag === "LoadFailed";
|
||||
const showEmptyState = shouldShowPreviewEmptyState(snapshot);
|
||||
const controller = desktopOverlay?.controller ?? "none";
|
||||
const loadProgress = useLoadingProgress(loading);
|
||||
const displayUrl =
|
||||
url && environment && environmentHttpBaseUrl
|
||||
? (formatPreviewUrl({
|
||||
@@ -562,6 +564,7 @@ export function PreviewView({ threadRef, tabId: requestedTabId, configuredUrls,
|
||||
url={url}
|
||||
displayUrl={displayUrl}
|
||||
loading={loading}
|
||||
loadProgress={loadProgress}
|
||||
canGoBack={canGoBack}
|
||||
canGoForward={canGoForward}
|
||||
refreshDisabled={refreshDisabled}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
|
||||
const TICK_INTERVAL_MS = 120;
|
||||
const FADE_OUT_DELAY_MS = 220;
|
||||
const SEED_PERCENT = 4;
|
||||
const ASYMPTOTE_PERCENT = 90;
|
||||
const APPROACH_FACTOR = 0.08;
|
||||
const MIN_INCREMENT = 0.5;
|
||||
|
||||
/**
|
||||
* Indeterminate progress simulator for the preview chrome's loading bar.
|
||||
* Animates 0 → 90% asymptotically while `loading` is true, snaps to 100%
|
||||
* on release, then resets after a short pause.
|
||||
*
|
||||
* Uses a ref to thread the latest progress through interval ticks without
|
||||
* needing `loading` to retrigger the effect, which sidesteps the stale-
|
||||
* closure pitfalls of reading `progress` directly.
|
||||
*/
|
||||
export function useLoadingProgress(loading: boolean): number {
|
||||
const [progress, setProgress] = useState(0);
|
||||
const progressRef = useRef(0);
|
||||
progressRef.current = progress;
|
||||
|
||||
useEffect(() => {
|
||||
if (!loading) {
|
||||
if (progressRef.current === 0) return;
|
||||
setProgress(100);
|
||||
const timer = window.setTimeout(() => setProgress(0), FADE_OUT_DELAY_MS);
|
||||
return () => window.clearTimeout(timer);
|
||||
}
|
||||
|
||||
setProgress((value) => (value > 0 && value < 95 ? value : SEED_PERCENT));
|
||||
const interval = window.setInterval(() => {
|
||||
const current = progressRef.current;
|
||||
if (current >= ASYMPTOTE_PERCENT) return;
|
||||
const remaining = ASYMPTOTE_PERCENT - current;
|
||||
const increment = Math.max(MIN_INCREMENT, remaining * APPROACH_FACTOR);
|
||||
setProgress(Math.min(ASYMPTOTE_PERCENT, current + increment));
|
||||
}, TICK_INTERVAL_MS);
|
||||
|
||||
return () => window.clearInterval(interval);
|
||||
}, [loading]);
|
||||
|
||||
return progress;
|
||||
}
|
||||
@@ -891,33 +891,3 @@ label:has(> select#reasoning-effort) select {
|
||||
.dark .model-picker-list::-webkit-scrollbar-thumb:hover {
|
||||
background: rgba(255, 255, 255, 0.15);
|
||||
}
|
||||
|
||||
@keyframes preview-loading-progress {
|
||||
from {
|
||||
transform: scaleX(0.04);
|
||||
}
|
||||
|
||||
to {
|
||||
transform: scaleX(0.9);
|
||||
}
|
||||
}
|
||||
|
||||
.preview-loading-progress-active {
|
||||
opacity: 1;
|
||||
animation: preview-loading-progress 10s cubic-bezier(0.1, 0.5, 0.2, 1) forwards;
|
||||
}
|
||||
|
||||
.preview-loading-progress-idle {
|
||||
opacity: 0;
|
||||
transform: scaleX(1);
|
||||
transition:
|
||||
transform 150ms ease-out,
|
||||
opacity 150ms ease-out 220ms;
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.preview-loading-progress-active {
|
||||
transform: scaleX(0.9);
|
||||
animation: none;
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,18 @@
|
||||
import * as NodeNet from "node:net";
|
||||
|
||||
import * as Data from "effect/Data";
|
||||
import * as Duration from "effect/Duration";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Context from "effect/Context";
|
||||
import * as Predicate from "effect/Predicate";
|
||||
import * as Schema from "effect/Schema";
|
||||
|
||||
export class NetError extends Data.TaggedError("NetError")<{
|
||||
readonly message: string;
|
||||
readonly cause?: unknown;
|
||||
}> {}
|
||||
export class NetError extends Schema.TaggedErrorClass<NetError>()("NetError", {
|
||||
message: Schema.String,
|
||||
cause: Schema.optional(Schema.Defect()),
|
||||
}) {}
|
||||
|
||||
const LISTENER_PROBE_TIMEOUT = Duration.millis(250);
|
||||
|
||||
const isErrnoExceptionWithCode = (
|
||||
cause: unknown,
|
||||
@@ -110,7 +113,7 @@ export const make = () => {
|
||||
};
|
||||
|
||||
socket.unref();
|
||||
socket.setTimeout(250);
|
||||
socket.setTimeout(Duration.toMillis(LISTENER_PROBE_TIMEOUT));
|
||||
socket.once("connect", () => {
|
||||
settle(true);
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user