Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

previewAutomationOpenReadiness.ts

69 lines2.3 KB

1import {
2 FILL_PREVIEW_VIEWPORT,
3 type PreviewAutomationOperation,
4 type PreviewAutomationOpenInput,
5 type PreviewSessionSnapshot,
6 type PreviewViewportSetting,
7} from "@t3tools/contracts";
8​
9/**
10 * Viewport an agent-opened tab falls back to when the user has no configured
11 * browser default. Agents screenshot and assert against what they open, so a
12 * brand-new tab left in fill mode would be sized by whatever the panel happens
13 * to be — deterministic beats incidental here.
14 */
15export const DEFAULT_PREVIEW_AUTOMATION_VIEWPORT = {
16 _tag: "freeform",
17 width: 1280,
18 height: 800,
19} as const satisfies PreviewViewportSetting;
20​
21/**
22 * An explicit `open`/`show` is the agent deliberately surfacing or suppressing
23 * its work, so it outranks the preference; the setting only decides what
24 * happens when the agent said nothing either way.
25 */
26export function shouldOpenPreviewMiniPlayer(
27 input: PreviewAutomationOpenInput,
28 autoShowFloatingPreview = true,
29): boolean {
30 return input.open ?? input.show ?? autoShowFloatingPreview;
32​
33export function shouldAutoShowPreviewForAutomationUse(input: {
34 readonly operation: PreviewAutomationOperation;
35 readonly autoShowFloatingPreview: boolean;
36 readonly presentationSuppressed: boolean;
37}): boolean {
38 return (
39 input.operation !== "open" && input.autoShowFloatingPreview && !input.presentationSuppressed
40 );
42​
43export function explicitlySuppressesPreviewMiniPlayer(input: PreviewAutomationOpenInput): boolean {
44 return (input.open ?? input.show) === false;
46​
47export function previewAutomationOpenNeedsOverlay(
48 input: PreviewAutomationOpenInput,
49 snapshot: PreviewSessionSnapshot,
50): boolean {
51 return input.url !== undefined || snapshot.navStatus._tag !== "Idle";
53​
54/**
55 * Whether a freshly opened automation tab still needs a viewport applied.
56 *
57 * A configured browser default is sent with `preview.open`, so the snapshot
58 * already carries it and nothing is needed here. Fill means the user has no
59 * stated preference, which is where the agent fallback applies.
60 */
61export function previewAutomationDefaultViewport(
62 reusedExistingTab: boolean,
63 snapshot: PreviewSessionSnapshot,
64): PreviewViewportSetting | null {
65 const viewport = snapshot.viewport ?? FILL_PREVIEW_VIEWPORT;
66 return !reusedExistingTab && viewport._tag === "fill"
67 ? DEFAULT_PREVIEW_AUTOMATION_VIEWPORT
68 : null;