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

ipc.ts

1,391 lines49.6 KB

1import * as Schema from "effect/Schema";
2​
3import {
4 PreviewAutomationClickInput,
5 PreviewAutomationEvaluateInput,
6 PreviewAutomationPressInput,
7 PreviewAutomationScrollInput,
8 PreviewAutomationSnapshot,
9 PreviewAutomationStatus,
10 PreviewAutomationTypeInput,
11 PreviewAutomationWaitForInput,
12} from "./previewAutomation.ts";
13import { SnapShotSource } from "./orchestration.ts";
14import { EnvironmentId, TrimmedNonEmptyString } from "./baseSchemas.ts";
15import { BrowserProfileId } from "./browserProfile.ts";
16import type {
17 BrowserImportResult,
18 BrowserImportSource,
19 BrowserImportSourceId,
20} from "./browserImport.ts";
21import { AuthAccessTokenResult, AuthSessionState, AuthWebSocketTicketResult } from "./auth.ts";
22import { AdvertisedEndpoint } from "./remoteAccess.ts";
23import { ExecutionEnvironmentDescriptor } from "./environment.ts";
24import { type ClientSettings, type QuitConfirmationMode, SnapShotShortcut } from "./settings.ts";
25import type { EditorId } from "./editor.ts";
26​
27import type {
28 DesktopAppActivationRequest,
29 DesktopAppActivationResponse,
30} from "./desktopAppActivation.ts";
31​
32export interface ContextMenuItem<T extends string = string> {
33 id: T;
34 label: string;
35 destructive?: boolean;
36 disabled?: boolean;
37 /** Renders as a non-interactive section header label. Web fallback only — stripped on desktop native menus. */
38 header?: boolean;
39 /** Icon keyword resolved by the web fallback. Stripped on desktop native menus. */
40 icon?: string;
41 /** Inserts a visual section divider immediately before this item. */
42 separatorBefore?: boolean;
43 /** Shows a check mark. Used to mark the current option inside a submenu. */
44 checked?: boolean;
45 children?: readonly ContextMenuItem<T>[];
47​
48export type QuitShortcutHintEvent =
49 | { readonly state: "down"; readonly mode: Exclude<QuitConfirmationMode, "direct"> }
50 | { readonly state: "up" };
51​
52export interface ContextMenuItemSchemaType {
53 readonly id: string;
54 readonly label: string;
55 readonly destructive?: boolean;
56 readonly disabled?: boolean;
57 readonly header?: boolean;
58 readonly icon?: string;
59 readonly separatorBefore?: boolean;
60 readonly checked?: boolean;
61 readonly children?: readonly ContextMenuItemSchemaType[];
63​
64export const ContextMenuItemSchema: Schema.Codec<ContextMenuItemSchemaType> = Schema.Struct({
65 id: Schema.String,
66 label: Schema.String,
67 destructive: Schema.optionalKey(Schema.Boolean),
68 disabled: Schema.optionalKey(Schema.Boolean),
69 header: Schema.optionalKey(Schema.Boolean),
70 icon: Schema.optionalKey(Schema.String),
71 separatorBefore: Schema.optionalKey(Schema.Boolean),
72 checked: Schema.optionalKey(Schema.Boolean),
73 children: Schema.optionalKey(
74 Schema.Array(
75 Schema.suspend((): Schema.Codec<ContextMenuItemSchemaType> => ContextMenuItemSchema),
76 ),
77 ),
78});
79​
80export type DesktopUpdateStatus =
81 | "disabled"
82 | "idle"
83 | "checking"
84 | "up-to-date"
85 | "available"
86 | "downloading"
87 | "downloaded"
88 | "error";
89​
90export type DesktopRuntimeArch = "arm64" | "x64" | "other";
91export type DesktopTheme = "light" | "dark" | "system";
92export type DesktopUpdateChannel = "latest" | "nightly";
93export type DesktopAppStageLabel = "Alpha" | "Dev" | "Nightly";
94​
95export const DesktopUpdateStatusSchema = Schema.Literals([
96 "disabled",
97 "idle",
98 "checking",
99 "up-to-date",
100 "available",
101 "downloading",
102 "downloaded",
103 "error",
104]);
105export const DesktopRuntimeArchSchema = Schema.Literals(["arm64", "x64", "other"]);
106export const DesktopThemeSchema = Schema.Literals(["light", "dark", "system"]);
107export const DesktopUpdateChannelSchema = Schema.Literals(["latest", "nightly"]);
108export const DesktopAppStageLabelSchema = Schema.Literals(["Alpha", "Dev", "Nightly"]);
109​
110export interface DesktopAppBranding {
111 baseName: string;
112 stageLabel: DesktopAppStageLabel;
113 displayName: string;
115​
116export const DesktopAppBrandingSchema = Schema.Struct({
117 baseName: Schema.String,
118 stageLabel: DesktopAppStageLabelSchema,
119 displayName: Schema.String,
120});
121​
122export const DesktopSnapShotMode = Schema.Literals(["direct", "portal", "unavailable"]);
123export type DesktopSnapShotMode = typeof DesktopSnapShotMode.Type;
124​
125export const DesktopCaptureExtensionState = Schema.Struct({
126 status: Schema.Literals([
127 "not-installed",
128 "disabled",
129 "enabled",
130 "restart-required",
131 "update-required",
132 "extensions-disabled",
133 "unsupported",
134 "error",
135 ]),
136 message: Schema.String,
137});
138export type DesktopCaptureExtensionState = typeof DesktopCaptureExtensionState.Type;
139​
140export const DesktopCaptureHelperState = Schema.Struct({
141 status: Schema.Literals(["not-installed", "update-required", "ready", "error"]),
142 message: Schema.String,
143 feedbackAvailable: Schema.optional(Schema.Boolean),
144});
145export type DesktopCaptureHelperState = typeof DesktopCaptureHelperState.Type;
146​
147export const DesktopSnapShotSetupAction = Schema.Literals([
148 "install-extension",
149 "enable-extension",
150 "disable-extension",
151 "install-kde-helper",
152 "remove-kde-helper",
153 "install-hyprland-helper",
154 "remove-hyprland-helper",
155 "test-mac-capture",
156 "allow-screen-recording",
157 "allow-accessibility",
158 "retry-shortcut",
159]);
160export type DesktopSnapShotSetupAction = typeof DesktopSnapShotSetupAction.Type;
161​
162export const DesktopCaptureConfigRequest = Schema.Struct({
163 operation: Schema.Literals(["install", "remove"]),
164 chooseFile: Schema.Boolean,
165 shortcut: Schema.optional(Schema.String.check(Schema.isMaxLength(80))),
166});
167export type DesktopCaptureConfigRequest = typeof DesktopCaptureConfigRequest.Type;
168​
169export const DesktopCaptureConfigPreview = Schema.Struct({
170 id: Schema.String,
171 path: Schema.String,
172 resolvedPath: Schema.String,
173 before: Schema.String,
174 after: Schema.String,
175 shortcut: Schema.String,
176 operation: Schema.Literals(["install", "remove"]),
177});
178export type DesktopCaptureConfigPreview = typeof DesktopCaptureConfigPreview.Type;
179​
180export const DesktopCaptureConfigApplied = Schema.Struct({
181 backupPath: Schema.NullOr(Schema.String),
182 warning: Schema.NullOr(Schema.String),
183});
184export type DesktopCaptureConfigApplied = typeof DesktopCaptureConfigApplied.Type;
185​
186export const DesktopSnapShotState = Schema.Struct({
187 mode: DesktopSnapShotMode,
188 windows: Schema.optional(Schema.Boolean),
189 linuxDesktop: Schema.optional(Schema.Literals(["gnome", "kde", "niri", "hyprland"])),
190 linuxBackend: Schema.optional(
191 Schema.Literals(["screenshot-portal", "gnome-extension", "niri", "kde", "hyprland", "picker"]),
192 ),
193 linuxFeedbackAvailable: Schema.optional(Schema.Boolean),
194 shortcut: SnapShotShortcut,
195 shortcutRegistered: Schema.Boolean,
196 shortcutPending: Schema.optional(Schema.Boolean),
197 shortcutCanRetry: Schema.optional(Schema.Boolean),
198 shortcutLabel: Schema.optional(Schema.String),
199 shortcutMessage: Schema.NullOr(Schema.String),
200 shortcutBinding: Schema.optional(Schema.String),
201 shortcutConfigPath: Schema.optional(Schema.String),
202 shortcutActionRegistered: Schema.optional(Schema.Boolean),
203 gnomeExtension: Schema.optional(DesktopCaptureExtensionState),
204 kdeHelper: Schema.optional(DesktopCaptureHelperState),
205 hyprlandHelper: Schema.optional(DesktopCaptureHelperState),
206 macPermissions: Schema.optional(
207 Schema.Struct({ screenRecording: Schema.Boolean, accessibility: Schema.Boolean }),
208 ),
209 shortcutVerified: Schema.optional(Schema.Boolean),
210 message: Schema.NullOr(Schema.String),
211});
212export type DesktopSnapShotState = typeof DesktopSnapShotState.Type;
213​
214export const DesktopSnapShotShortcutAvailability = Schema.Struct({
215 available: Schema.Boolean,
216 message: Schema.NullOr(Schema.String),
217});
218export type DesktopSnapShotShortcutAvailability = typeof DesktopSnapShotShortcutAvailability.Type;
219​
220export const DesktopSnapShotId = TrimmedNonEmptyString.check(
221 Schema.isMaxLength(64),
222 Schema.isPattern(/^[a-f0-9-]+$/i),
223);
224export type DesktopSnapShotId = typeof DesktopSnapShotId.Type;
225​
226/** Main-process capture lifecycle pushes. `id` is absent for failures before a capture exists. */
227export const DesktopSnapShotEvent = Schema.Union([
228 Schema.Struct({ type: Schema.Literal("requested"), id: DesktopSnapShotId }),
229 Schema.Struct({ type: Schema.Literal("started"), id: DesktopSnapShotId }),
230 Schema.Struct({ type: Schema.Literal("ready"), id: DesktopSnapShotId }),
231 Schema.Struct({ type: Schema.Literal("failed"), id: Schema.optional(DesktopSnapShotId) }),
232 Schema.Struct({ type: Schema.Literal("shortcut-changed") }),
233]);
234export type DesktopSnapShotEvent = typeof DesktopSnapShotEvent.Type;
235​
236export const DesktopPendingSnapShot = Schema.Struct({
237 id: DesktopSnapShotId,
238 name: Schema.String,
239 mimeType: Schema.Literal("image/png"),
240 sizeBytes: Schema.Int,
241 source: SnapShotSource,
242});
243export type DesktopPendingSnapShot = typeof DesktopPendingSnapShot.Type;
244​
245export const DesktopSnapShot = Schema.Struct({
246 ...DesktopPendingSnapShot.fields,
247 dataUrl: Schema.String,
248});
249export type DesktopSnapShot = typeof DesktopSnapShot.Type;
250​
251export const DesktopSnapShotAnimationDestination = Schema.Struct({
252 id: DesktopSnapShotId,
253 viewportFrame: Schema.Struct({
254 x: Schema.Number,
255 y: Schema.Number,
256 width: Schema.Number,
257 height: Schema.Number,
258 }),
259 backgroundColor: Schema.String,
260 borderColor: Schema.String,
261 borderWidth: Schema.Number,
262 cornerRadius: Schema.Number,
263 details: Schema.optional(
264 Schema.Struct({
265 appName: SnapShotSource.fields.appName,
266 windowTitle: SnapShotSource.fields.windowTitle,
267 appIconDataUrl: SnapShotSource.fields.appIconDataUrl,
268 }),
269 ),
270});
271export type DesktopSnapShotAnimationDestination = typeof DesktopSnapShotAnimationDestination.Type;
272​
273export interface DesktopRuntimeInfo {
274 hostArch: DesktopRuntimeArch;
275 appArch: DesktopRuntimeArch;
276 runningUnderArm64Translation: boolean;
278​
279export interface DesktopUpdateState {
280 enabled: boolean;
281 status: DesktopUpdateStatus;
282 channel: DesktopUpdateChannel;
283 currentVersion: string;
284 hostArch: DesktopRuntimeArch;
285 appArch: DesktopRuntimeArch;
286 runningUnderArm64Translation: boolean;
287 availableVersion: string | null;
288 downloadedVersion: string | null;
289 releaseNotes: ReadonlyArray<DesktopUpdateReleaseNote>;
290 omittedReleaseCount: number;
291 downloadPercent: number | null;
292 checkedAt: string | null;
293 message: string | null;
294 errorContext: "check" | "download" | "install" | null;
295 canRetry: boolean;
297​
298export interface DesktopUpdateReleaseNote {
299 version: string;
300 items: ReadonlyArray<string>;
301 totalItems: number;
303​
304export const DesktopUpdateReleaseNoteSchema = Schema.Struct({
305 version: Schema.String,
306 items: Schema.Array(Schema.String),
307 totalItems: Schema.Number,
308});
309​
310export const DesktopUpdateStateSchema = Schema.Struct({
311 enabled: Schema.Boolean,
312 status: DesktopUpdateStatusSchema,
313 channel: DesktopUpdateChannelSchema,
314 currentVersion: Schema.String,
315 hostArch: DesktopRuntimeArchSchema,
316 appArch: DesktopRuntimeArchSchema,
317 runningUnderArm64Translation: Schema.Boolean,
318 availableVersion: Schema.NullOr(Schema.String),
319 downloadedVersion: Schema.NullOr(Schema.String),
320 releaseNotes: Schema.Array(DesktopUpdateReleaseNoteSchema),
321 omittedReleaseCount: Schema.Number,
322 downloadPercent: Schema.NullOr(Schema.Number),
323 checkedAt: Schema.NullOr(Schema.String),
324 message: Schema.NullOr(Schema.String),
325 errorContext: Schema.NullOr(Schema.Literals(["check", "download", "install"])),
326 canRetry: Schema.Boolean,
327});
328​
329export interface DesktopUpdateActionResult {
330 accepted: boolean;
331 completed: boolean;
332 state: DesktopUpdateState;
334​
335export const DesktopUpdateActionResultSchema = Schema.Struct({
336 accepted: Schema.Boolean,
337 completed: Schema.Boolean,
338 state: DesktopUpdateStateSchema,
339});
340​
341export interface DesktopUpdateCheckResult {
342 checked: boolean;
343 state: DesktopUpdateState;
345​
346export const DesktopUpdateCheckResultSchema = Schema.Struct({
347 checked: Schema.Boolean,
348 state: DesktopUpdateStateSchema,
349});
350​
351// Stable id for the Windows-native primary backend. Desktop side wraps
352// this with a brand inside DesktopBackendManager; web side keeps it as
353// a plain string so the env-runtime can compare against it without
354// importing brand machinery from the desktop package.
355export const PRIMARY_LOCAL_ENVIRONMENT_ID = "primary";
356​
357export interface DesktopEnvironmentBootstrap {
358 // Stable backend instance id (e.g. "primary" or "wsl:ubuntu"). The
359 // web env runtime keys local environments off this so projects
360 // routed to a specific backend reopen against the same one.
361 id: string;
362 label: string;
363 // Concrete WSL distro used by the current backend run. This stays separate
364 // from id because a default-tracking instance keeps the stable
365 // "wsl:default" IPC target while each run launches a specific distro.
366 runningDistro?: string | null;
367 httpBaseUrl: string | null;
368 wsBaseUrl: string | null;
369 bootstrapToken?: string;
371​
372export const DesktopEnvironmentBootstrapSchema = Schema.Struct({
373 id: Schema.String,
374 label: Schema.String,
375 runningDistro: Schema.optionalKey(Schema.NullOr(Schema.String)),
376 httpBaseUrl: Schema.NullOr(Schema.String),
377 wsBaseUrl: Schema.NullOr(Schema.String),
378 bootstrapToken: Schema.optionalKey(Schema.String),
379});
380​
381export const DesktopSshEnvironmentTargetSchema = Schema.Struct({
382 alias: Schema.String,
383 hostname: Schema.String,
384 username: Schema.NullOr(Schema.String),
385 port: Schema.NullOr(Schema.Number),
386});
387export type DesktopSshEnvironmentTarget = typeof DesktopSshEnvironmentTargetSchema.Type;
388​
389export type DesktopSshHostSource = "ssh-config" | "known-hosts";
390export const DesktopSshHostSourceSchema = Schema.Literals(["ssh-config", "known-hosts"]);
391​
392export interface DesktopDiscoveredSshHost extends DesktopSshEnvironmentTarget {
393 source: DesktopSshHostSource;
395​
396export const DesktopDiscoveredSshHostSchema = Schema.Struct({
397 alias: Schema.String,
398 hostname: Schema.String,
399 username: Schema.NullOr(Schema.String),
400 port: Schema.NullOr(Schema.Number),
401 source: DesktopSshHostSourceSchema,
402});
403​
404export interface DesktopSshEnvironmentBootstrap {
405 target: DesktopSshEnvironmentTarget;
406 httpBaseUrl: string;
407 wsBaseUrl: string;
408 pairingToken: string | null;
409 remotePort?: number;
410 remoteServerKind?: "external" | "managed";
412​
413export const DesktopSshEnvironmentBootstrapSchema = Schema.Struct({
414 target: DesktopSshEnvironmentTargetSchema,
415 httpBaseUrl: Schema.String,
416 wsBaseUrl: Schema.String,
417 pairingToken: Schema.NullOr(Schema.String),
418 remotePort: Schema.optionalKey(Schema.Number),
419 remoteServerKind: Schema.optionalKey(Schema.Literals(["external", "managed"])),
420});
421​
422export interface DesktopSshPasswordPromptRequest {
423 requestId: string;
424 destination: string;
425 username: string | null;
426 prompt: string;
427 expiresAt: string;
429​
430export const DesktopSshPasswordPromptCancelledType = "ssh-password-prompt-cancelled" as const;
431​
432export const DesktopSshPasswordPromptCancelledResultSchema = Schema.Struct({
433 type: Schema.Literal(DesktopSshPasswordPromptCancelledType),
434 message: Schema.String,
435});
436​
437export const DesktopSshEnvironmentEnsureOptionsSchema = Schema.Struct({
438 issuePairingToken: Schema.optionalKey(Schema.Boolean),
439});
440​
441export const DesktopSshEnvironmentEnsureInputSchema = Schema.Struct({
442 target: DesktopSshEnvironmentTargetSchema,
443 options: Schema.optionalKey(DesktopSshEnvironmentEnsureOptionsSchema),
444});
445​
446export const DesktopSshEnvironmentEnsureResultSchema = Schema.Union([
447 DesktopSshEnvironmentBootstrapSchema,
448 DesktopSshPasswordPromptCancelledResultSchema,
449]);
450​
451export const DesktopSshHttpBaseUrlInputSchema = Schema.Struct({
452 httpBaseUrl: Schema.String,
453});
454​
455export const DesktopSshBearerRequestInputSchema = Schema.Struct({
456 httpBaseUrl: Schema.String,
457 bearerToken: Schema.String,
458});
459​
460export const DesktopSshBearerBootstrapInputSchema = Schema.Struct({
461 httpBaseUrl: Schema.String,
462 credential: Schema.String,
463});
464​
465export const DesktopSshPasswordPromptResolutionInputSchema = Schema.Struct({
466 requestId: Schema.String,
467 password: Schema.NullOr(Schema.String),
468});
469​
470export const PersistedSavedEnvironmentRecordSchema = Schema.Struct({
471 environmentId: EnvironmentId,
472 label: Schema.String,
473 wsBaseUrl: Schema.String,
474 httpBaseUrl: Schema.String,
475 createdAt: Schema.String,
476 lastConnectedAt: Schema.NullOr(Schema.String),
477 desktopSsh: Schema.optionalKey(DesktopSshEnvironmentTargetSchema),
478 relayManaged: Schema.optionalKey(
479 Schema.Struct({
480 relayUrl: Schema.String,
481 }),
482 ),
483});
484export type PersistedSavedEnvironmentRecord = typeof PersistedSavedEnvironmentRecordSchema.Type;
485​
486export type DesktopServerExposureMode = "local-only" | "network-accessible";
487​
488export const DesktopServerExposureModeSchema = Schema.Literals([
489 "local-only",
490 "network-accessible",
491]);
492​
493export interface DesktopServerExposureState {
494 mode: DesktopServerExposureMode;
495 endpointUrl: string | null;
496 advertisedHost: string | null;
497 tailscaleServeEnabled: boolean;
498 tailscaleServePort: number;
500​
501export const DesktopServerExposureStateSchema = Schema.Struct({
502 mode: DesktopServerExposureModeSchema,
503 endpointUrl: Schema.NullOr(Schema.String),
504 advertisedHost: Schema.NullOr(Schema.String),
505 tailscaleServeEnabled: Schema.Boolean,
506 tailscaleServePort: Schema.Number,
507});
508​
509export interface PickFolderOptions {
510 initialPath?: string | null;
511 // When set, the desktop dialog opens against the named backend's
512 // filesystem instead of the primary's. Used by callers that already
513 // know which local environment they're targeting (e.g. opening a
514 // project that lives inside WSL). Omitting it keeps the historical
515 // behavior so non-WSL users never see a different picker.
516 targetEnvironmentId?: string;
518​
519export const PickFolderOptionsSchema = Schema.Struct({
520 initialPath: Schema.optionalKey(Schema.NullOr(Schema.String)),
521 targetEnvironmentId: Schema.optionalKey(Schema.String),
522});
523​
524/**
525 * A file returned by the desktop theme-file picker. Oversized files carry an
526 * empty text so the renderer can reject them by size without the main
527 * process ever holding their contents.
528 */
529export interface PickedThemeFile {
530 name: string;
531 size: number;
532 text: string;
534​
535export const PickedThemeFileSchema = Schema.Struct({
536 name: Schema.String,
537 size: Schema.Number,
538 text: Schema.String,
539});
540​
541export interface DesktopWslDistro {
542 name: string;
543 isDefault: boolean;
544 version: 1 | 2;
546​
547export const DesktopWslDistroSchema = Schema.Struct({
548 name: Schema.String,
549 isDefault: Schema.Boolean,
550 version: Schema.Literals([1, 2]),
551});
552​
553export interface DesktopWslState {
554 // True when the user has opted the WSL backend in; the actual backend
555 // process is registered with the desktop pool independently of this
556 // flag and may take a moment to come up after the user enables it.
557 enabled: boolean;
558 // null means "track the current WSL default distro".
559 distro: string | null;
560 available: boolean;
561 // When true (and `enabled` is also true) the desktop runs only the
562 // WSL backend as the primary; the Windows-side Node backend is not
563 // started. Toggling this requires an app restart because the
564 // primary backend's spec is captured once at layer init.
565 wslOnly: boolean;
566 distros: readonly DesktopWslDistro[];
567 // Reason the dual-mode WSL backend last failed preflight (no node, wrong
568 // version, missing build tools), or null. Surfaced inline in Connections
569 // settings. Always null in wsl-only mode — that path shows a dialog and
570 // falls back to Windows instead.
571 preflightError: string | null;
573​
574export const DesktopWslStateSchema = Schema.Struct({
575 enabled: Schema.Boolean,
576 distro: Schema.NullOr(Schema.String),
577 available: Schema.Boolean,
578 wslOnly: Schema.Boolean,
579 distros: Schema.Array(DesktopWslDistroSchema),
580 preflightError: Schema.NullOr(Schema.String),
581});
582​
583/**
584 * Renderer-facing snapshot of a desktop preview tab. Mirrors the main-process
585 * PreviewTabState shape but uses serialisable primitives only.
586 */
587export type DesktopPreviewNavStatus =
588 | { kind: "Idle" }
589 | { kind: "Loading"; url: string; title: string }
590 | { kind: "Success"; url: string; title: string }
591 | {
592 kind: "LoadFailed";
593 url: string;
594 title: string;
595 code: number;
596 description: string;
597 };
598​
599/**
600 * Emulated `prefers-color-scheme` for the guest page. "system" clears the
601 * override so the page follows the OS appearance.
602 */
603export type DesktopPreviewColorScheme = "system" | "light" | "dark";
604​
605export const DesktopPreviewColorSchemeSchema: Schema.Codec<DesktopPreviewColorScheme> =
606 Schema.Literals(["system", "light", "dark"]);
607​
608export const FAVICON_DATA_URL_MAX_LENGTH = 8192;
609export const FAVICON_CAPTURED_AT_MAX = 8_640_000_000_000_000;
610​
611export interface DesktopPreviewFavicon {
612 dataUrl: string;
613 pageUrl: string;
614 capturedAt: number;
616​
617export interface DesktopPreviewTabState {
618 tabId: string;
619 webContentsId: number | null;
620 navStatus: DesktopPreviewNavStatus;
621 canGoBack: boolean;
622 canGoForward: boolean;
623 /** Current zoom factor (1.0 = 100%). */
624 zoomFactor: number;
625 /** Whether this tab is currently mirrored into a desktop picture-in-picture window. */
626 pictureInPicture: boolean;
627 colorScheme: DesktopPreviewColorScheme;
628 /**
629 * Whether the user has silenced this tab. Per tab rather than per origin, so
630 * two tabs on the same site mute independently. Survives navigation and
631 * webview swaps, but is dropped when the tab closes.
632 */
633 audioMuted: boolean;
634 /**
635 * Whether the guest is currently emitting audio. Observed from Chromium, and
636 * independent of {@link audioMuted}: a muted tab that is playing still reports
637 * `true`, which is what lets the tab strip distinguish "muted and making
638 * sound" from "muted and silent".
639 */
640 audible: boolean;
641 controller: "human" | "agent" | "none";
642 favicon?: DesktopPreviewFavicon;
643 updatedAt: string;
645​
646export const DesktopPreviewTabIdSchema = Schema.String.check(Schema.isTrimmed()).check(
647 Schema.isNonEmpty(),
648);
649​
650export const DesktopPreviewAutomationStatusSchema = Schema.Struct({
651 ...PreviewAutomationStatus.fields,
652 tabId: Schema.NullOr(DesktopPreviewTabIdSchema),
653});
654export type DesktopPreviewAutomationStatus = typeof DesktopPreviewAutomationStatusSchema.Type;
655​
656export interface DesktopPreviewPointerEvent {
657 tabId: string;
658 phase: "move" | "click";
659 x: number;
660 y: number;
661 sequence: number;
662 createdAt: string;
664​
665/** Recording decorations are forwarded separately from the captured page pixels. */
666export const DesktopPreviewRecordingInputSchema = Schema.Union([
667 Schema.Struct({
668 type: Schema.Literal("pointer"),
669 phase: Schema.Literals(["move", "down", "up", "click"]),
670 x: Schema.Finite,
671 y: Schema.Finite,
672 width: Schema.Finite.check(Schema.isGreaterThan(0)),
673 height: Schema.Finite.check(Schema.isGreaterThan(0)),
674 }),
675 Schema.Struct({
676 type: Schema.Literal("key"),
677 label: Schema.NullOr(Schema.String.check(Schema.isMaxLength(100))),
678 held: Schema.Boolean,
679 width: Schema.Finite.check(Schema.isGreaterThan(0)),
680 }),
681 Schema.Struct({ type: Schema.Literal("clear") }),
682]);
683export type DesktopPreviewRecordingInput = typeof DesktopPreviewRecordingInputSchema.Type;
684export interface DesktopPreviewRecordingInputEvent {
685 readonly tabId: string;
686 readonly input: DesktopPreviewRecordingInput;
688​
689/**
690 * Static config a renderer needs to mount a preview `<webview>`. Returned
691 * atomically by `DesktopPreviewBridge.getPreviewConfig()` so the renderer
692 * doesn't have to wait on three separate IPC round-trips before the webview
693 * can attach.
694 */
695export interface DesktopPreviewWebviewConfig {
696 /** `persist:t3code-preview` (or whatever the desktop chose). */
697 partition: string;
698 /**
699 * Canonical `<webview webpreferences="...">` string. Encodes the security
700 * posture (sandboxed but contextIsolation off so the picker preload can
701 * read the page's React DevTools hook). Always present.
702 */
703 webPreferences: string;
704 /**
705 * Absolute `file://`-style URL to the picker preload bundle. Set to null
706 * when the bundle isn't present (older builds, broken install) — the
707 * renderer must then disable element-pick affordances.
708 */
709 preloadUrl: string | null;
711​
712export const DesktopPreviewWebviewConfigSchema: Schema.Codec<DesktopPreviewWebviewConfig> =
713 Schema.Struct({
714 partition: Schema.String,
715 webPreferences: Schema.String,
716 preloadUrl: Schema.NullOr(Schema.String),
717 });
718​
719export interface DesktopPreviewAnnotationTheme {
720 colorScheme: "light" | "dark";
721 radius: string;
722 background: string;
723 foreground: string;
724 popover: string;
725 popoverForeground: string;
726 primary: string;
727 primaryForeground: string;
728 muted: string;
729 mutedForeground: string;
730 accent: string;
731 accentForeground: string;
732 border: string;
733 input: string;
734 ring: string;
735 fontSans: string;
736 fontMono: string;
738​
739export const DesktopPreviewAnnotationThemeSchema: Schema.Codec<DesktopPreviewAnnotationTheme> =
740 Schema.Struct({
741 colorScheme: Schema.Literals(["light", "dark"]),
742 radius: Schema.String,
743 background: Schema.String,
744 foreground: Schema.String,
745 popover: Schema.String,
746 popoverForeground: Schema.String,
747 primary: Schema.String,
748 primaryForeground: Schema.String,
749 muted: Schema.String,
750 mutedForeground: Schema.String,
751 accent: Schema.String,
752 accentForeground: Schema.String,
753 border: Schema.String,
754 input: Schema.String,
755 ring: Schema.String,
756 fontSans: Schema.String,
757 fontMono: Schema.String,
758 });
759​
760export interface DesktopPreviewRecordingFrame {
761 tabId: string;
762 data: string;
763 width: number;
764 height: number;
765 receivedAt: string;
767​
768export interface DesktopPreviewRecordingArtifact {
769 id: string;
770 tabId: string;
771 path: string;
772 mimeType: string;
773 sizeBytes: number;
774 createdAt: string;
776​
777export const DesktopPreviewRecordingArtifactSchema: Schema.Codec<DesktopPreviewRecordingArtifact> =
778 Schema.Struct({
779 id: Schema.String,
780 tabId: DesktopPreviewTabIdSchema,
781 path: Schema.String,
782 mimeType: Schema.String,
783 sizeBytes: Schema.Int,
784 createdAt: Schema.String,
785 });
786​
787export interface DesktopPreviewScreenshotArtifact {
788 id: string;
789 tabId: string;
790 path: string;
791 mimeType: "image/png";
792 sizeBytes: number;
793 createdAt: string;
795​
796export const DesktopPreviewScreenshotArtifactSchema: Schema.Codec<DesktopPreviewScreenshotArtifact> =
797 Schema.Struct({
798 id: Schema.String,
799 tabId: DesktopPreviewTabIdSchema,
800 path: Schema.String,
801 mimeType: Schema.Literal("image/png"),
802 sizeBytes: Schema.Int,
803 createdAt: Schema.String,
804 });
805​
806/**
807 * Single stack frame captured by react-grab's `getElementContext`. We surface
808 * the source file/line so coding agents can jump straight to the JSX that
809 * produced the picked DOM node.
810 */
811export interface PickedElementStackFrame {
812 functionName: string | null;
813 fileName: string | null;
814 lineNumber: number | null;
815 columnNumber: number | null;
817​
818export const PickedElementStackFrameSchema: Schema.Codec<PickedElementStackFrame> = Schema.Struct({
819 functionName: Schema.NullOr(Schema.String),
820 fileName: Schema.NullOr(Schema.String),
821 lineNumber: Schema.NullOr(Schema.Number),
822 columnNumber: Schema.NullOr(Schema.Number),
823});
824​
825/**
826 * A successful element pick from the preview webview. All fields are
827 * best-effort — pages that don't ship a React fiber tree (or aren't running
828 * in dev) will still produce a usable payload (selector + html preview),
829 * just without component / source attribution.
830 */
831export interface PickedElementPayload {
832 /** URL of the page the element was picked on. */
833 pageUrl: string;
834 /** Optional `<title>` of that page (best-effort). */
835 pageTitle: string | null;
836 /** Lowercase tag name, e.g. `"button"`. */
837 tagName: string;
838 /** CSS selector resolving back to the element on a re-render. */
839 selector: string | null;
840 /** Truncated outer-HTML preview (matches react-grab's `htmlPreview`). */
841 htmlPreview: string;
842 /** Nearest React component display name, or null when unavailable. */
843 componentName: string | null;
844 /** First source-mapped stack frame (file + line of the JSX source). */
845 source: PickedElementStackFrame | null;
846 /** Full owner-stack frames; can be empty. Useful for richer context. */
847 stack: ReadonlyArray<PickedElementStackFrame>;
848 /** Author CSS only (UA defaults stripped) — react-grab's `styles`. */
849 styles: string;
850 /** Wall-clock pick time as ISO-8601 string. */
851 pickedAt: string;
853​
854export const PickedElementPayloadSchema: Schema.Codec<PickedElementPayload> = Schema.Struct({
855 pageUrl: Schema.String,
856 pageTitle: Schema.NullOr(Schema.String),
857 tagName: Schema.String,
858 selector: Schema.NullOr(Schema.String),
859 htmlPreview: Schema.String,
860 componentName: Schema.NullOr(Schema.String),
861 source: Schema.NullOr(PickedElementStackFrameSchema),
862 stack: Schema.Array(PickedElementStackFrameSchema),
863 styles: Schema.String,
864 pickedAt: Schema.String,
865});
866​
867export interface PreviewAnnotationRect {
868 x: number;
869 y: number;
870 width: number;
871 height: number;
873​
874export const PreviewAnnotationRectSchema: Schema.Codec<PreviewAnnotationRect> = Schema.Struct({
875 x: Schema.Number,
876 y: Schema.Number,
877 width: Schema.Number,
878 height: Schema.Number,
879});
880​
881export interface PreviewAnnotationPoint {
882 x: number;
883 y: number;
885​
886export const PreviewAnnotationPointSchema: Schema.Codec<PreviewAnnotationPoint> = Schema.Struct({
887 x: Schema.Number,
888 y: Schema.Number,
889});
890​
891export interface PreviewAnnotationElementTarget {
892 id: string;
893 element: PickedElementPayload;
894 rect: PreviewAnnotationRect;
896​
897export const PreviewAnnotationElementTargetSchema: Schema.Codec<PreviewAnnotationElementTarget> =
898 Schema.Struct({
899 id: Schema.String,
900 element: PickedElementPayloadSchema,
901 rect: PreviewAnnotationRectSchema,
902 });
903​
904export interface PreviewAnnotationRegionTarget {
905 id: string;
906 rect: PreviewAnnotationRect;
908​
909export const PreviewAnnotationRegionTargetSchema: Schema.Codec<PreviewAnnotationRegionTarget> =
910 Schema.Struct({
911 id: Schema.String,
912 rect: PreviewAnnotationRectSchema,
913 });
914​
915export interface PreviewAnnotationStrokeTarget {
916 id: string;
917 color: string;
918 width: number;
919 points: ReadonlyArray<PreviewAnnotationPoint>;
920 bounds: PreviewAnnotationRect;
922​
923export const PreviewAnnotationStrokeTargetSchema: Schema.Codec<PreviewAnnotationStrokeTarget> =
924 Schema.Struct({
925 id: Schema.String,
926 color: Schema.String,
927 width: Schema.Number,
928 points: Schema.Array(PreviewAnnotationPointSchema),
929 bounds: PreviewAnnotationRectSchema,
930 });
931​
932export interface PreviewAnnotationStyleChange {
933 targetId: string;
934 selector: string | null;
935 property: string;
936 previousValue: string;
937 value: string;
939​
940export const PreviewAnnotationStyleChangeSchema: Schema.Codec<PreviewAnnotationStyleChange> =
941 Schema.Struct({
942 targetId: Schema.String,
943 selector: Schema.NullOr(Schema.String),
944 property: Schema.String,
945 previousValue: Schema.String,
946 value: Schema.String,
947 });
948​
949export interface PreviewAnnotationScreenshot {
950 dataUrl: string;
951 width: number;
952 height: number;
953 cropRect: PreviewAnnotationRect;
955​
956export const PreviewAnnotationScreenshotSchema: Schema.Codec<PreviewAnnotationScreenshot> =
957 Schema.Struct({
958 dataUrl: Schema.String,
959 width: Schema.Number,
960 height: Schema.Number,
961 cropRect: PreviewAnnotationRectSchema,
962 });
963​
964/**
965 * A submitted preview annotation. One annotation may reference multiple DOM
966 * elements, freeform regions, and ink strokes. The desktop main process adds
967 * the screenshot after the guest preload submits the structured draft.
968 */
969export interface PreviewAnnotationPayload {
970 id: string;
971 pageUrl: string;
972 pageTitle: string | null;
973 comment: string;
974 elements: ReadonlyArray<PreviewAnnotationElementTarget>;
975 regions: ReadonlyArray<PreviewAnnotationRegionTarget>;
976 strokes: ReadonlyArray<PreviewAnnotationStrokeTarget>;
977 styleChanges: ReadonlyArray<PreviewAnnotationStyleChange>;
978 screenshot: PreviewAnnotationScreenshot | null;
979 createdAt: string;
981​
982export const PreviewAnnotationPayloadSchema: Schema.Codec<PreviewAnnotationPayload> = Schema.Struct(
983 {
984 id: Schema.String,
985 pageUrl: Schema.String,
986 pageTitle: Schema.NullOr(Schema.String),
987 comment: Schema.String,
988 elements: Schema.Array(PreviewAnnotationElementTargetSchema),
989 regions: Schema.Array(PreviewAnnotationRegionTargetSchema),
990 strokes: Schema.Array(PreviewAnnotationStrokeTargetSchema),
991 styleChanges: Schema.Array(PreviewAnnotationStyleChangeSchema),
992 screenshot: Schema.NullOr(PreviewAnnotationScreenshotSchema),
993 createdAt: Schema.String,
994 },
995);
996​
997export type PreviewAnnotationSubmission = "attach" | "send";
998export const PreviewAnnotationSubmissionSchema: Schema.Codec<PreviewAnnotationSubmission> =
999 Schema.Literals(["attach", "send"]);
1000​
1001export interface PreviewAnnotationSubmissionResult {
1002 annotation: PreviewAnnotationPayload;
1003 submission: PreviewAnnotationSubmission;
1004 /** The crop was requested but failed or timed out, so `annotation.screenshot` is null. */
1005 screenshotFailed?: boolean;
1007export const PreviewAnnotationSubmissionResultSchema: Schema.Codec<PreviewAnnotationSubmissionResult> =
1008 Schema.Struct({
1009 annotation: PreviewAnnotationPayloadSchema,
1010 submission: PreviewAnnotationSubmissionSchema,
1011 screenshotFailed: Schema.optionalKey(Schema.Boolean),
1012 });
1013​
1014export const DesktopPreviewTabInputSchema = Schema.Struct({
1015 tabId: DesktopPreviewTabIdSchema,
1016});
1017​
1018/**
1019 * Tab creation carries the client's configured browser defaults so the guest
1020 * is born already zoomed and color-scheme-emulated. Applying them after
1021 * creation instead would paint one frame at 100%/system first, which reads as
1022 * a flash on every tab open. Both fields are optional so an older renderer
1023 * still gets the historical defaults.
1024 */
1025export const DesktopPreviewCreateTabInputSchema = Schema.Struct({
1026 tabId: DesktopPreviewTabIdSchema,
1027 zoomFactor: Schema.optional(Schema.Number.check(Schema.isGreaterThan(0))),
1028 colorScheme: Schema.optional(DesktopPreviewColorSchemeSchema),
1029});
1030​
1031export interface DesktopPreviewTabDefaults {
1032 readonly zoomFactor?: number | undefined;
1033 readonly colorScheme?: DesktopPreviewColorScheme | undefined;
1035​
1036export const DesktopPreviewRegisterWebviewInputSchema = Schema.Struct({
1037 tabId: DesktopPreviewTabIdSchema,
1038 webContentsId: Schema.Int.check(Schema.isGreaterThan(0)),
1039});
1040​
1041export const DesktopPreviewNavigateInputSchema = Schema.Struct({
1042 tabId: DesktopPreviewTabIdSchema,
1043 url: Schema.String,
1044});
1045​
1046export const DesktopPreviewConfigInputSchema = Schema.Struct({
1047 environmentId: EnvironmentId,
1048 /**
1049 * Browser profile the partition is derived from. Derivation stays in main:
1050 * `will-attach-webview` only prefix-checks the partition string, so a
1051 * renderer-supplied partition could attach to a session that never had the
1052 * UA rewrite or permission handlers installed.
1053 */
1054 profileId: Schema.optional(BrowserProfileId),
1055});
1056​
1057export const DesktopPreviewClearDataInputSchema = Schema.Struct({
1058 environmentId: EnvironmentId,
1059 /** Omit to clear every profile; otherwise only this profile's partition. */
1060 profileId: Schema.optional(BrowserProfileId),
1061});
1062​
1063export const DesktopPreviewSetColorSchemeInputSchema = Schema.Struct({
1064 tabId: DesktopPreviewTabIdSchema,
1065 colorScheme: DesktopPreviewColorSchemeSchema,
1066});
1067​
1068export const DesktopPreviewSetAudioMutedInputSchema = Schema.Struct({
1069 tabId: DesktopPreviewTabIdSchema,
1070 audioMuted: Schema.Boolean,
1071});
1072​
1073export const DesktopPreviewAnnotationThemeInputSchema = Schema.Struct({
1074 theme: DesktopPreviewAnnotationThemeSchema,
1075});
1076​
1077export const DesktopPreviewArtifactInputSchema = Schema.Struct({
1078 path: Schema.String.check(Schema.isTrimmed()).check(Schema.isNonEmpty()),
1079});
1080​
1081export const DesktopPreviewRecordingSaveInputSchema = Schema.Struct({
1082 tabId: DesktopPreviewTabIdSchema,
1083 mimeType: Schema.String.check(Schema.isTrimmed()).check(Schema.isNonEmpty()),
1084 data: Schema.Uint8Array,
1085});
1086​
1087export const DesktopPreviewAutomationClickInputSchema = Schema.Struct({
1088 tabId: DesktopPreviewTabIdSchema,
1089 input: PreviewAutomationClickInput,
1090});
1091​
1092export const DesktopPreviewAutomationTypeInputSchema = Schema.Struct({
1093 tabId: DesktopPreviewTabIdSchema,
1094 input: PreviewAutomationTypeInput,
1095});
1096​
1097export const DesktopPreviewAutomationPressInputSchema = Schema.Struct({
1098 tabId: DesktopPreviewTabIdSchema,
1099 input: PreviewAutomationPressInput,
1100});
1101​
1102export const DesktopPreviewAutomationScrollInputSchema = Schema.Struct({
1103 tabId: DesktopPreviewTabIdSchema,
1104 input: PreviewAutomationScrollInput,
1105});
1106​
1107export const DesktopPreviewAutomationEvaluateInputSchema = Schema.Struct({
1108 tabId: DesktopPreviewTabIdSchema,
1109 input: PreviewAutomationEvaluateInput,
1110});
1111​
1112export const DesktopPreviewAutomationWaitForInputSchema = Schema.Struct({
1113 tabId: DesktopPreviewTabIdSchema,
1114 input: PreviewAutomationWaitForInput,
1115});
1116​
1117/**
1118 * A System Settings pane the app can deep-link to. The identifier crosses IPC
1119 * rather than a URL, so the renderer can only reach these known destinations.
1120 */
1121export const SystemSettingsPaneSchema = Schema.Literals(["full-disk-access"]);
1122export type SystemSettingsPane = typeof SystemSettingsPaneSchema.Type;
1123​
1124export interface DesktopBridge {
1125 getAppBranding: () => DesktopAppBranding | null;
1126 /** Absolute path of a dropped or picked file; absent on desktop builds predating it. */
1127 getPathForFile?: (file: File) => string;
1128 /** The desktop client's OS platform, read from Electron's preload process. */
1129 getClientPlatform?: () => string;
1130 setNotificationBadge?: (badge: { count: number; image: string | null }) => Promise<void>;
1131 onNotificationBadgeClear?: (listener: () => void) => () => void;
1132 onTrackpadScrollEnd?: (listener: () => void) => () => void;
1133 /**
1134 * The OS locale as a BCP-47 tag, which the renderer cannot read for itself:
1135 * the packaged app ships only the `en-US` Chromium locale pak, so
1136 * `navigator.language` and the default `Intl` locale are pinned to `en-US`
1137 * regardless of OS settings.
1138 */
1139 getSystemLocale?: () => string | null;
1140 // One bootstrap per pool instance currently registered with bootstrap
1141 // info (omits instances whose backend hasn't produced a config yet).
1142 // The primary backend is identified by id === PRIMARY_LOCAL_ENVIRONMENT_ID.
1143 getLocalEnvironmentBootstraps: () => readonly DesktopEnvironmentBootstrap[];
1144 getLocalEnvironmentEnabled?: () => boolean;
1145 setLocalEnvironmentEnabled?: (enabled: boolean) => Promise<void>;
1146 getLocalEnvironmentBearerToken: () => Promise<string>;
1147 getClientSettings: () => Promise<ClientSettings | null>;
1148 setClientSettings: (settings: ClientSettings) => Promise<void>;
1149 getConnectionCatalog?: () => Promise<string | null>;
1150 setConnectionCatalog?: (catalog: string) => Promise<boolean>;
1151 clearConnectionCatalog?: () => Promise<void>;
1152 discoverSshHosts: () => Promise<readonly DesktopDiscoveredSshHost[]>;
1153 /** Resolves a suggested SSH alias before populating the connection form. */
1154 resolveSshHost: (alias: string) => Promise<DesktopSshEnvironmentTarget>;
1155 requestSnapShotPermissions?: (includeAccessibility: boolean) => Promise<void>;
1156 getSnapShotState?: () => Promise<DesktopSnapShotState>;
1157 setupSnapShot?: (action: DesktopSnapShotSetupAction) => Promise<void>;
1158 previewSnapShotConfig?: (
1159 request: DesktopCaptureConfigRequest,
1160 ) => Promise<DesktopCaptureConfigPreview | null>;
1161 applySnapShotConfig?: (previewId: string) => Promise<DesktopCaptureConfigApplied>;
1162 checkSnapShotShortcut?: (
1163 shortcut: SnapShotShortcut,
1164 ) => Promise<DesktopSnapShotShortcutAvailability>;
1165 setSnapShotShortcutSuppressed?: (suppressed: boolean) => Promise<void>;
1166 listPendingSnapShots?: () => Promise<readonly DesktopPendingSnapShot[]>;
1167 readSnapShot?: (id: string) => Promise<DesktopSnapShot>;
1168 setSnapShotAnimationDestination?: (
1169 destination: DesktopSnapShotAnimationDestination,
1170 ) => Promise<void>;
1171 dismissSnapShotAnimation?: (id: DesktopSnapShotId) => Promise<void>;
1172 acknowledgeSnapShot?: (id: string) => Promise<void>;
1173 ensureSshEnvironment: (
1174 target: DesktopSshEnvironmentTarget,
1175 options?: { issuePairingToken?: boolean },
1176 ) => Promise<DesktopSshEnvironmentBootstrap>;
1177 disconnectSshEnvironment: (target: DesktopSshEnvironmentTarget) => Promise<void>;
1178 fetchSshEnvironmentDescriptor: (httpBaseUrl: string) => Promise<ExecutionEnvironmentDescriptor>;
1179 bootstrapSshBearerSession: (
1180 httpBaseUrl: string,
1181 credential: string,
1182 ) => Promise<AuthAccessTokenResult>;
1183 fetchSshSessionState: (httpBaseUrl: string, bearerToken: string) => Promise<AuthSessionState>;
1184 issueSshWebSocketTicket: (
1185 httpBaseUrl: string,
1186 bearerToken: string,
1187 ) => Promise<AuthWebSocketTicketResult>;
1188 onSshPasswordPrompt: (listener: (request: DesktopSshPasswordPromptRequest) => void) => () => void;
1189 resolveSshPasswordPrompt: (requestId: string, password: string | null) => Promise<void>;
1190 getServerExposureState: () => Promise<DesktopServerExposureState>;
1191 setServerExposureMode: (mode: DesktopServerExposureMode) => Promise<DesktopServerExposureState>;
1192 setTailscaleServeEnabled: (input: {
1193 readonly enabled: boolean;
1194 readonly port?: number;
1195 }) => Promise<DesktopServerExposureState>;
1196 getAdvertisedEndpoints: () => Promise<readonly AdvertisedEndpoint[]>;
1197 getWslState: () => Promise<DesktopWslState>;
1198 setWslBackendEnabled: (enabled: boolean) => Promise<DesktopWslState>;
1199 setWslDistro: (distro: string | null) => Promise<DesktopWslState>;
1200 setWslOnly: (enabled: boolean) => Promise<DesktopWslState>;
1201 pickFolder: (options?: PickFolderOptions) => Promise<string | null>;
1202 /** Optional while older desktop shells can host a newer web client. */
1203 pickProjectFavicon?: (initialPath?: string) => Promise<string | null>;
1204 /**
1205 * Multi-select JSON file picker that opens in the VS Code extensions
1206 * directory when one exists. Optional: older desktop builds lack it, and
1207 * web callers fall back to a plain file input.
1208 */
1209 pickThemeFiles?: () => Promise<readonly PickedThemeFile[] | null>;
1210 setTheme: (theme: DesktopTheme) => Promise<void>;
1211 showContextMenu: <T extends string>(
1212 items: readonly ContextMenuItem<T>[],
1213 position?: { x: number; y: number },
1214 ) => Promise<T | null>;
1215 /** Receives a local OAuth code for a sign-in owned by a remote environment. */
1216 receiveProviderAuthCallback?: (authorizationUrl: string) => Promise<string>;
1217 cancelProviderAuthCallback?: (authorizationUrl: string) => Promise<void>;
1218 openExternal: (url: string) => Promise<boolean>;
1219 /**
1220 * Open a System Settings pane by identifier. Optional: older desktop builds
1221 * lack it, and callers no-op when it is missing.
1222 */
1223 openSystemSettings?: (pane: SystemSettingsPane) => Promise<boolean>;
1224 checkSystemPermission?: (pane: SystemSettingsPane) => Promise<boolean>;
1225 /**
1226 * Probe this desktop machine for installed remote-capable editor CLIs
1227 * (used for remote open-in-editor deep links). Optional: older desktop
1228 * builds lack it; callers fall back to VS Code only.
1229 */
1230 probeRemoteEditors?: () => Promise<readonly EditorId[]>;
1231 /** Present when the desktop shell can perform an ordered plain-text paste. */
1232 pasteAsText?: () => Promise<void>;
1233 onMenuAction: (listener: (action: string) => void) => () => void;
1234 onSnapShotEvent?: (listener: (event: DesktopSnapShotEvent) => void) => () => void;
1235 /**
1236 * Quit-confirmation hint pushes. Optional: older desktop builds never emit
1237 * them.
1238 */
1239 onQuitShortcut?: (listener: (event: QuitShortcutHintEvent) => void) => () => void;
1240 getWindowFullscreenState: () => boolean;
1241 onWindowFullscreenStateChange: (listener: (fullscreen: boolean) => void) => () => void;
1242 getUpdateState: () => Promise<DesktopUpdateState>;
1243 setUpdateChannel: (channel: DesktopUpdateChannel) => Promise<DesktopUpdateState>;
1244 checkForUpdate: () => Promise<DesktopUpdateCheckResult>;
1245 downloadUpdate: () => Promise<DesktopUpdateActionResult>;
1246 installUpdate: () => Promise<DesktopUpdateActionResult>;
1247 onUpdateState: (listener: (state: DesktopUpdateState) => void) => () => void;
1248 /** Present when the desktop shell accepts `t3 app` activation requests. */
1249 appActivation?: {
1250 setReady: (ready: boolean) => Promise<void>;
1251 complete: (response: DesktopAppActivationResponse) => Promise<void>;
1252 onRequest: (listener: (request: DesktopAppActivationRequest) => void) => () => void;
1253 };
1254 /**
1255 * Desktop-only preview surface. Present iff the renderer is hosted by the
1256 * Electron desktop build; web builds have `preview === undefined`.
1257 */
1258 preview?: DesktopPreviewBridge;
1260​
1261/** Renderer callback invoked by Electron with a fresh user gesture before display-media capture. */
1262export const DESKTOP_PREVIEW_RECORDING_CAPTURE_TRIGGER = "__t3DesktopPreviewRecordingCapture";
1263​
1264export interface DesktopPreviewBridge {
1265 createTab: (tabId: string, defaults?: DesktopPreviewTabDefaults) => Promise<void>;
1266 closeTab: (tabId: string) => Promise<void>;
1267 registerWebview: (tabId: string, webContentsId: number) => Promise<void>;
1268 navigate: (tabId: string, url: string) => Promise<void>;
1269 goBack: (tabId: string) => Promise<void>;
1270 goForward: (tabId: string) => Promise<void>;
1271 refresh: (tabId: string) => Promise<void>;
1272 zoomIn: (tabId: string) => Promise<void>;
1273 zoomOut: (tabId: string) => Promise<void>;
1274 resetZoom: (tabId: string) => Promise<void>;
1275 /** Reload bypassing the HTTP cache. */
1276 hardReload: (tabId: string) => Promise<void>;
1277 /**
1278 * Emulate `prefers-color-scheme` on the guest page ("system" clears the
1279 * override). Persists per tab and is re-applied across webview swaps.
1280 */
1281 setColorScheme: (tabId: string, colorScheme: DesktopPreviewColorScheme) => Promise<void>;
1282 /**
1283 * Silence the tab's audio output. Persists per tab and is re-applied across
1284 * webview swaps, but is dropped when the tab closes. Muting a silent tab is
1285 * allowed; it simply takes effect once the page plays something.
1286 */
1287 setAudioMuted: (tabId: string, audioMuted: boolean) => Promise<void>;
1288 /** Open the guest webview's DevTools (detached). */
1289 openDevTools: (tabId: string) => Promise<void>;
1290 /** Drop cookies + storage data for the preview partition (all tabs). */
1291 clearCookies: (environmentId: EnvironmentId, profileId?: string) => Promise<void>;
1292 /** Drop the HTTP cache for the preview partition (all tabs). */
1293 clearCache: (environmentId: EnvironmentId, profileId?: string) => Promise<void>;
1294 /**
1295 * One-shot config for mounting a preview `<webview>`. Replaces three
1296 * earlier round-trip calls (`getBrowserPartition`, `getWebviewPreferences`,
1297 * `getPickPreloadPath`) so adding a new field here only requires touching
1298 * the contract + main, not the renderer's mount logic.
1299 */
1300 getPreviewConfig: (
1301 environmentId: EnvironmentId,
1302 profileId?: string,
1303 ) => Promise<DesktopPreviewWebviewConfig>;
1304 /** Browsers on this machine whose cookies can be imported. */
1305 listBrowserImportSources: () => Promise<ReadonlyArray<BrowserImportSource>>;
1306 importBrowserCookies: (input: {
1307 readonly environmentId: EnvironmentId;
1308 readonly sourceId: BrowserImportSourceId;
1309 readonly sourceProfileDirectory: string;
1310 readonly targetProfileId: string;
1311 }) => Promise<BrowserImportResult>;
1312 setAnnotationTheme: (theme: DesktopPreviewAnnotationTheme) => Promise<void>;
1313 /**
1314 * Activate the in-page element picker for the given tab. Resolves with
1315 * the picked annotation and its attach/send intent, or `null` when the
1316 * user cancels (Escape / nav). The promise rejects if the picker can't be
1317 * activated (no webview, etc.).
1318 */
1319 pickElement: (tabId: string) => Promise<PreviewAnnotationSubmissionResult | null>;
1320 /** Cancel an in-flight preview annotation session. */
1321 cancelPickElement: (tabId: string) => Promise<void>;
1322 captureScreenshot: (tabId: string) => Promise<DesktopPreviewScreenshotArtifact>;
1323 revealArtifact: (path: string) => Promise<void>;
1324 copyArtifactToClipboard: (path: string) => Promise<void>;
1325 pictureInPicture: {
1326 open: (tabId: string) => Promise<void>;
1327 close: (tabId: string) => Promise<void>;
1328 };
1329 recording: {
1330 onInput: (listener: (event: DesktopPreviewRecordingInputEvent) => void) => () => void;
1331 startScreencast: (tabId: string) => Promise<void>;
1332 stopScreencast: (tabId: string) => Promise<void>;
1333 save: (
1334 tabId: string,
1335 mimeType: string,
1336 data: Uint8Array,
1337 ) => Promise<DesktopPreviewRecordingArtifact>;
1338 onFrame: (listener: (frame: DesktopPreviewRecordingFrame) => void) => () => void;
1339 };
1340 automation: {
1341 status: (tabId: string) => Promise<DesktopPreviewAutomationStatus>;
1342 snapshot: (tabId: string) => Promise<PreviewAutomationSnapshot>;
1343 click: (tabId: string, input: PreviewAutomationClickInput) => Promise<void>;
1344 type: (tabId: string, input: PreviewAutomationTypeInput) => Promise<void>;
1345 press: (tabId: string, input: PreviewAutomationPressInput) => Promise<void>;
1346 scroll: (tabId: string, input: PreviewAutomationScrollInput) => Promise<void>;
1347 evaluate: (tabId: string, input: PreviewAutomationEvaluateInput) => Promise<unknown>;
1348 waitFor: (tabId: string, input: PreviewAutomationWaitForInput) => Promise<void>;
1349 };
1350 onStateChange: (listener: (tabId: string, state: DesktopPreviewTabState) => void) => () => void;
1351 onPointerEvent: (listener: (event: DesktopPreviewPointerEvent) => void) => () => void;
1353​
1354export type ConfirmDialogVariant = "default" | "destructive";
1355​
1356export interface ConfirmDialogOptions {
1357 readonly variant?: ConfirmDialogVariant;
1359​
1360/**
1361 * APIs bound to the local app shell, not to any particular backend environment.
1363 * These capabilities describe the desktop/browser host that the user is
1364 * currently running: dialogs, external-link opening, context menus, and
1365 * app-level settings/config access. They must not be used as a proxy for
1366 * "whatever environment the user is targeting", because in a multi-environment
1367 * world the local shell and a selected backend environment are distinct
1368 * concepts.
1369 */
1370export interface LocalApi {
1371 dialogs: {
1372 pickFolder: (options?: PickFolderOptions) => Promise<string | null>;
1373 confirm: (message: string, options?: ConfirmDialogOptions) => Promise<boolean>;
1374 };
1375 shell: {
1376 openExternal: (url: string) => Promise<void>;
1377 /** Opens a known System Settings pane; no-ops outside the desktop app. */
1378 openSystemSettings: (pane: SystemSettingsPane) => Promise<void>;
1379 };
1380 contextMenu: {
1381 show: <T extends string>(
1382 items: readonly ContextMenuItem<T>[],
1383 position?: { x: number; y: number },
1384 ) => Promise<T | null>;
1385 close: () => Promise<void>;
1386 };
1387 persistence: {
1388 getClientSettings: () => Promise<ClientSettings | null>;
1389 setClientSettings: (settings: ClientSettings) => Promise<void>;
1390 };