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