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