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