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