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