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