The preview browser always opened in fill mode, at 100% zoom, following the system appearance. That is rarely what you want if you work in responsive mode against a handful of known viewports, and there was no way to say otherwise. Adds a Settings → Integrations page whose first section is Browser, holding the defaults a preview tab opens at: viewport (fill, responsive, or a device preset), zoom, and appearance. They apply to every entry point that opens a tab without stating its own size — a hand-opened browser panel and an agent calling `preview_open` alike. The viewport travels with `preview.open` and zoom/appearance with `createTab`, so a tab is born configured rather than reflowing a frame later. Agents keep their 1280x800 fallback, but only when no default is configured: a fill-mode tab would otherwise be sized by whatever the panel happens to be, and agents assert against what they open. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
48 lines
1.5 KiB
TypeScript
48 lines
1.5 KiB
TypeScript
import type {
|
|
EnvironmentId,
|
|
PreviewOpenInput,
|
|
PreviewSessionSnapshot,
|
|
PreviewViewportSetting,
|
|
ScopedThreadRef,
|
|
} from "@t3tools/contracts";
|
|
import type { AtomCommandResult } from "@t3tools/client-runtime/state/runtime";
|
|
|
|
import { browserDefaultOpenViewport } from "~/browser/browserDefaults";
|
|
import { applyPreviewServerSnapshot, rememberPreviewUrl } from "~/previewStateStore";
|
|
|
|
interface OpenPreviewSessionInput<E> {
|
|
openPreview: (input: {
|
|
readonly environmentId: EnvironmentId;
|
|
readonly input: PreviewOpenInput;
|
|
}) => Promise<AtomCommandResult<PreviewSessionSnapshot, E>>;
|
|
threadRef: ScopedThreadRef;
|
|
url?: string;
|
|
/** Overrides the configured default; automation passes an explicit size. */
|
|
viewport?: PreviewViewportSetting;
|
|
}
|
|
|
|
export async function openPreviewSession<E>(
|
|
input: OpenPreviewSessionInput<E>,
|
|
): Promise<AtomCommandResult<PreviewSessionSnapshot, E>> {
|
|
const result = await input.openPreview({
|
|
environmentId: input.threadRef.environmentId,
|
|
input: {
|
|
threadId: input.threadRef.threadId,
|
|
...(input.url === undefined ? {} : { url: input.url }),
|
|
viewport: input.viewport ?? browserDefaultOpenViewport(),
|
|
},
|
|
});
|
|
if (result._tag === "Failure") {
|
|
return result;
|
|
}
|
|
const snapshot = result.value;
|
|
applyPreviewServerSnapshot(input.threadRef, snapshot);
|
|
if (input.url !== undefined) {
|
|
rememberPreviewUrl(
|
|
input.threadRef,
|
|
snapshot.navStatus._tag === "Idle" ? input.url : snapshot.navStatus.url,
|
|
);
|
|
}
|
|
return result;
|
|
}
|