Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ipc.ts

1,383 lines49.1 KB

1import * as Schema from "effect/Schema";
2​
3import {
4 PreviewAutomationClickInput,
5 PreviewAutomationEvaluateInput,
6 PreviewAutomationPressInput,
7 PreviewAutomationScrollInput,
8 PreviewAutomationSnapshot,
9 PreviewAutomationStatus,
10 PreviewAutomationTypeInput,
11 PreviewAutomationWaitForInput,
12} from "./previewAutomation.ts";
13import { SnapShotSource } from "./orchestration.ts";
14import { EnvironmentId, TrimmedNonEmptyString } from "./baseSchemas.ts";
15import { BrowserProfileId } from "./browserProfile.ts";
16import type {
17 BrowserImportResult,
18 BrowserImportSource,
19 BrowserImportSourceId,
20} from "./browserImport.ts";
21import { AuthAccessTokenResult, AuthSessionState, AuthWebSocketTicketResult } from "./auth.ts";
22import { AdvertisedEndpoint } from "./remoteAccess.ts";
23import { ExecutionEnvironmentDescriptor } from "./environment.ts";
24import { type ClientSettings, type QuitConfirmationMode, SnapShotShortcut } from "./settings.ts";
25import type { EditorId } from "./editor.ts";
26​
27import type {
28 DesktopAppActivationRequest,
29 DesktopAppActivationResponse,
30} from "./desktopAppActivation.ts";
31​
32export interface ContextMenuItem<T extends string = string> {
33 id: T;
34 label: string;
35 destructive?: boolean;
36 disabled?: boolean;
37 /** Renders as a non-interactive section header label. Web fallback only — stripped on desktop native menus. */
38 header?: boolean;
39 /** Icon keyword resolved by the web fallback. Stripped on desktop native menus. */
40 icon?: string;
41 /** Inserts a visual section divider immediately before this item. */
42 separatorBefore?: boolean;
43 children?: readonly ContextMenuItem<T>[];
45​
46export type QuitShortcutHintEvent =
47 | { readonly state: "down"; readonly mode: Exclude<QuitConfirmationMode, "direct"> }
48 | { readonly state: "up" };
49​
50export interface ContextMenuItemSchemaType {
51 readonly id: string;
52 readonly label: string;
53 readonly destructive?: boolean;
54 readonly disabled?: boolean;
55 readonly header?: boolean;
56 readonly icon?: string;
57 readonly separatorBefore?: boolean;
58 readonly children?: readonly ContextMenuItemSchemaType[];
60​
61export const ContextMenuItemSchema: Schema.Codec<ContextMenuItemSchemaType> = Schema.Struct({
62 id: Schema.String,
63 label: Schema.String,
64 destructive: Schema.optionalKey(Schema.Boolean),
65 disabled: Schema.optionalKey(Schema.Boolean),
66 header: Schema.optionalKey(Schema.Boolean),
67 icon: Schema.optionalKey(Schema.String),
68 separatorBefore: Schema.optionalKey(Schema.Boolean),
69 children: Schema.optionalKey(
70 Schema.Array(
71 Schema.suspend((): Schema.Codec<ContextMenuItemSchemaType> => ContextMenuItemSchema),
72 ),
73 ),
74});
75​
76export type DesktopUpdateStatus =
77 | "disabled"
78 | "idle"
79 | "checking"
80 | "up-to-date"
81 | "available"
82 | "downloading"
83 | "downloaded"
84 | "error";
85​
86export type DesktopRuntimeArch = "arm64" | "x64" | "other";
87export type DesktopTheme = "light" | "dark" | "system";
88export type DesktopUpdateChannel = "latest" | "nightly";
89export type DesktopAppStageLabel = "Alpha" | "Dev" | "Nightly";
90​
91export const DesktopUpdateStatusSchema = Schema.Literals([
92 "disabled",
93 "idle",
94 "checking",
95 "up-to-date",
96 "available",
97 "downloading",
98 "downloaded",
99 "error",
100]);
101export const DesktopRuntimeArchSchema = Schema.Literals(["arm64", "x64", "other"]);
102export const DesktopThemeSchema = Schema.Literals(["light", "dark", "system"]);
103export const DesktopUpdateChannelSchema = Schema.Literals(["latest", "nightly"]);
104export const DesktopAppStageLabelSchema = Schema.Literals(["Alpha", "Dev", "Nightly"]);
105​
106export interface DesktopAppBranding {
107 baseName: string;
108 stageLabel: DesktopAppStageLabel;
109 displayName: string;
111​
112export const DesktopAppBrandingSchema = Schema.Struct({
113 baseName: Schema.String,
114 stageLabel: DesktopAppStageLabelSchema,
115 displayName: Schema.String,
116});
117​
118export const DesktopSnapShotMode = Schema.Literals(["direct", "portal", "unavailable"]);
119export type DesktopSnapShotMode = typeof DesktopSnapShotMode.Type;
120​
121export const DesktopCaptureExtensionState = Schema.Struct({
122 status: Schema.Literals([
123 "not-installed",
124 "disabled",
125 "enabled",
126 "restart-required",
127 "update-required",
128 "extensions-disabled",
129 "unsupported",
130 "error",
131 ]),
132 message: Schema.String,
133});
134export type DesktopCaptureExtensionState = typeof DesktopCaptureExtensionState.Type;
135​
136export const DesktopCaptureHelperState = Schema.Struct({
137 status: Schema.Literals(["not-installed", "update-required", "ready", "error"]),
138 message: Schema.String,
139 feedbackAvailable: Schema.optional(Schema.Boolean),
140});
141export type DesktopCaptureHelperState = typeof DesktopCaptureHelperState.Type;
142​
143export const DesktopSnapShotSetupAction = Schema.Literals([
144 "install-extension",
145 "enable-extension",
146 "disable-extension",
147 "install-kde-helper",
148 "remove-kde-helper",
149 "install-hyprland-helper",
150 "remove-hyprland-helper",
151 "test-mac-capture",
152 "allow-screen-recording",
153 "allow-accessibility",
154 "retry-shortcut",
155]);
156export type DesktopSnapShotSetupAction = typeof DesktopSnapShotSetupAction.Type;
157​
158export const DesktopCaptureConfigRequest = Schema.Struct({
159 operation: Schema.Literals(["install", "remove"]),
160 chooseFile: Schema.Boolean,
161 shortcut: Schema.optional(Schema.String.check(Schema.isMaxLength(80))),
162});
163export type DesktopCaptureConfigRequest = typeof DesktopCaptureConfigRequest.Type;
164​
165export const DesktopCaptureConfigPreview = Schema.Struct({
166 id: Schema.String,
167 path: Schema.String,
168 resolvedPath: Schema.String,
169 before: Schema.String,
170 after: Schema.String,
171 shortcut: Schema.String,
172 operation: Schema.Literals(["install", "remove"]),
173});
174export type DesktopCaptureConfigPreview = typeof DesktopCaptureConfigPreview.Type;
175​
176export const DesktopCaptureConfigApplied = Schema.Struct({
177 backupPath: Schema.NullOr(Schema.String),
178 warning: Schema.NullOr(Schema.String),
179});
180export type DesktopCaptureConfigApplied = typeof DesktopCaptureConfigApplied.Type;
181​
182export const DesktopSnapShotState = Schema.Struct({
183 mode: DesktopSnapShotMode,
184 windows: Schema.optional(Schema.Boolean),
185 linuxDesktop: Schema.optional(Schema.Literals(["gnome", "kde", "niri", "hyprland"])),
186 linuxBackend: Schema.optional(
187 Schema.Literals(["screenshot-portal", "gnome-extension", "niri", "kde", "hyprland", "picker"]),
188 ),
189 linuxFeedbackAvailable: Schema.optional(Schema.Boolean),
190 shortcut: SnapShotShortcut,
191 shortcutRegistered: Schema.Boolean,
192 shortcutPending: Schema.optional(Schema.Boolean),
193 shortcutCanRetry: Schema.optional(Schema.Boolean),
194 shortcutLabel: Schema.optional(Schema.String),
195 shortcutMessage: Schema.NullOr(Schema.String),
196 shortcutBinding: Schema.optional(Schema.String),
197 shortcutConfigPath: Schema.optional(Schema.String),
198 shortcutActionRegistered: Schema.optional(Schema.Boolean),
199 gnomeExtension: Schema.optional(DesktopCaptureExtensionState),
200 kdeHelper: Schema.optional(DesktopCaptureHelperState),
201 hyprlandHelper: Schema.optional(DesktopCaptureHelperState),
202 macPermissions: Schema.optional(
203 Schema.Struct({ screenRecording: Schema.Boolean, accessibility: Schema.Boolean }),
204 ),
205 shortcutVerified: Schema.optional(Schema.Boolean),
206 message: Schema.NullOr(Schema.String),
207});
208export type DesktopSnapShotState = typeof DesktopSnapShotState.Type;
209​
210export const DesktopSnapShotShortcutAvailability = Schema.Struct({
211 available: Schema.Boolean,
212 message: Schema.NullOr(Schema.String),
213});
214export type DesktopSnapShotShortcutAvailability = typeof DesktopSnapShotShortcutAvailability.Type;
215​
216export const DesktopSnapShotId = TrimmedNonEmptyString.check(
217 Schema.isMaxLength(64),
218 Schema.isPattern(/^[a-f0-9-]+$/i),
219);
220export type DesktopSnapShotId = typeof DesktopSnapShotId.Type;
221​
222/** Main-process capture lifecycle pushes. `id` is absent for failures before a capture exists. */
223export const DesktopSnapShotEvent = Schema.Union([
224 Schema.Struct({ type: Schema.Literal("requested"), id: DesktopSnapShotId }),
225 Schema.Struct({ type: Schema.Literal("started"), id: DesktopSnapShotId }),
226 Schema.Struct({ type: Schema.Literal("ready"), id: DesktopSnapShotId }),
227 Schema.Struct({ type: Schema.Literal("failed"), id: Schema.optional(DesktopSnapShotId) }),
228 Schema.Struct({ type: Schema.Literal("shortcut-changed") }),
229]);
230export type DesktopSnapShotEvent = typeof DesktopSnapShotEvent.Type;
231​
232export const DesktopPendingSnapShot = Schema.Struct({
233 id: DesktopSnapShotId,
234 name: Schema.String,
235 mimeType: Schema.Literal("image/png"),
236 sizeBytes: Schema.Int,
237 source: SnapShotSource,
238});
239export type DesktopPendingSnapShot = typeof DesktopPendingSnapShot.Type;
240​
241export const DesktopSnapShot = Schema.Struct({
242 ...DesktopPendingSnapShot.fields,
243 dataUrl: Schema.String,
244});
245export type DesktopSnapShot = typeof DesktopSnapShot.Type;
246​
247export const DesktopSnapShotAnimationDestination = Schema.Struct({
248 id: DesktopSnapShotId,
249 viewportFrame: Schema.Struct({
250 x: Schema.Number,
251 y: Schema.Number,
252 width: Schema.Number,
253 height: Schema.Number,
254 }),
255 backgroundColor: Schema.String,
256 borderColor: Schema.String,
257 borderWidth: Schema.Number,
258 cornerRadius: Schema.Number,
259 details: Schema.optional(
260 Schema.Struct({
261 appName: SnapShotSource.fields.appName,
262 windowTitle: SnapShotSource.fields.windowTitle,
263 appIconDataUrl: SnapShotSource.fields.appIconDataUrl,
264 }),
265 ),
266});
267export type DesktopSnapShotAnimationDestination = typeof DesktopSnapShotAnimationDestination.Type;
268​
269export interface DesktopRuntimeInfo {
270 hostArch: DesktopRuntimeArch;
271 appArch: DesktopRuntimeArch;
272 runningUnderArm64Translation: boolean;
274​
275export interface DesktopUpdateState {
276 enabled: boolean;
277 status: DesktopUpdateStatus;
278 channel: DesktopUpdateChannel;
279 currentVersion: string;
280 hostArch: DesktopRuntimeArch;
281 appArch: DesktopRuntimeArch;
282 runningUnderArm64Translation: boolean;
283 availableVersion: string | null;
284 downloadedVersion: string | null;
285 releaseNotes: ReadonlyArray<DesktopUpdateReleaseNote>;
286 omittedReleaseCount: number;
287 downloadPercent: number | null;
288 checkedAt: string | null;
289 message: string | null;
290 errorContext: "check" | "download" | "install" | null;
291 canRetry: boolean;
293​
294export interface DesktopUpdateReleaseNote {
295 version: string;
296 items: ReadonlyArray<string>;
297 totalItems: number;
299​
300export const DesktopUpdateReleaseNoteSchema = Schema.Struct({
301 version: Schema.String,
302 items: Schema.Array(Schema.String),
303 totalItems: Schema.Number,
304});
305​
306export const DesktopUpdateStateSchema = Schema.Struct({
307 enabled: Schema.Boolean,
308 status: DesktopUpdateStatusSchema,
309 channel: DesktopUpdateChannelSchema,
310 currentVersion: Schema.String,
311 hostArch: DesktopRuntimeArchSchema,
312 appArch: DesktopRuntimeArchSchema,
313 runningUnderArm64Translation: Schema.Boolean,
314 availableVersion: Schema.NullOr(Schema.String),
315 downloadedVersion: Schema.NullOr(Schema.String),
316 releaseNotes: Schema.Array(DesktopUpdateReleaseNoteSchema),
317 omittedReleaseCount: Schema.Number,
318 downloadPercent: Schema.NullOr(Schema.Number),
319 checkedAt: Schema.NullOr(Schema.String),
320 message: Schema.NullOr(Schema.String),
321 errorContext: Schema.NullOr(Schema.Literals(["check", "download", "install"])),
322 canRetry: Schema.Boolean,
323});
324​
325export interface DesktopUpdateActionResult {
326 accepted: boolean;
327 completed: boolean;
328 state: DesktopUpdateState;
330​
331export const DesktopUpdateActionResultSchema = Schema.Struct({
332 accepted: Schema.Boolean,
333 completed: Schema.Boolean,
334 state: DesktopUpdateStateSchema,
335});
336​
337export interface DesktopUpdateCheckResult {
338 checked: boolean;
339 state: DesktopUpdateState;
341​
342export const DesktopUpdateCheckResultSchema = Schema.Struct({
343 checked: Schema.Boolean,
344 state: DesktopUpdateStateSchema,
345});
346​
347// Stable id for the Windows-native primary backend. Desktop side wraps
348// this with a brand inside DesktopBackendManager; web side keeps it as
349// a plain string so the env-runtime can compare against it without
350// importing brand machinery from the desktop package.
351export const PRIMARY_LOCAL_ENVIRONMENT_ID = "primary";
352​
353export interface DesktopEnvironmentBootstrap {
354 // Stable backend instance id (e.g. "primary" or "wsl:ubuntu"). The
355 // web env runtime keys local environments off this so projects
356 // routed to a specific backend reopen against the same one.
357 id: string;
358 label: string;
359 // Concrete WSL distro used by the current backend run. This stays separate
360 // from id because a default-tracking instance keeps the stable
361 // "wsl:default" IPC target while each run launches a specific distro.
362 runningDistro?: string | null;
363 httpBaseUrl: string | null;
364 wsBaseUrl: string | null;
365 bootstrapToken?: string;
367​
368export const DesktopEnvironmentBootstrapSchema = Schema.Struct({
369 id: Schema.String,
370 label: Schema.String,
371 runningDistro: Schema.optionalKey(Schema.NullOr(Schema.String)),
372 httpBaseUrl: Schema.NullOr(Schema.String),
373 wsBaseUrl: Schema.NullOr(Schema.String),
374 bootstrapToken: Schema.optionalKey(Schema.String),
375});
376​
377export const DesktopSshEnvironmentTargetSchema = Schema.Struct({
378 alias: Schema.String,
379 hostname: Schema.String,
380 username: Schema.NullOr(Schema.String),
381 port: Schema.NullOr(Schema.Number),
382});
383export type DesktopSshEnvironmentTarget = typeof DesktopSshEnvironmentTargetSchema.Type;
384​
385export type DesktopSshHostSource = "ssh-config" | "known-hosts";
386export const DesktopSshHostSourceSchema = Schema.Literals(["ssh-config", "known-hosts"]);
387​
388export interface DesktopDiscoveredSshHost extends DesktopSshEnvironmentTarget {
389 source: DesktopSshHostSource;
391​
392export const DesktopDiscoveredSshHostSchema = Schema.Struct({
393 alias: Schema.String,
394 hostname: Schema.String,
395 username: Schema.NullOr(Schema.String),
396 port: Schema.NullOr(Schema.Number),
397 source: DesktopSshHostSourceSchema,
398});
399​
400export interface DesktopSshEnvironmentBootstrap {
401 target: DesktopSshEnvironmentTarget;
402 httpBaseUrl: string;
403 wsBaseUrl: string;
404 pairingToken: string | null;
405 remotePort?: number;
406 remoteServerKind?: "external" | "managed";
408​
409export const DesktopSshEnvironmentBootstrapSchema = Schema.Struct({
410 target: DesktopSshEnvironmentTargetSchema,
411 httpBaseUrl: Schema.String,
412 wsBaseUrl: Schema.String,
413 pairingToken: Schema.NullOr(Schema.String),
414 remotePort: Schema.optionalKey(Schema.Number),
415 remoteServerKind: Schema.optionalKey(Schema.Literals(["external", "managed"])),
416});
417​
418export interface DesktopSshPasswordPromptRequest {
419 requestId: string;
420 destination: string;
421 username: string | null;
422 prompt: string;
423 expiresAt: string;
425​
426export const DesktopSshPasswordPromptCancelledType = "ssh-password-prompt-cancelled" as const;
427​
428export const DesktopSshPasswordPromptCancelledResultSchema = Schema.Struct({
429 type: Schema.Literal(DesktopSshPasswordPromptCancelledType),
430 message: Schema.String,
431});
432​
433export const DesktopSshEnvironmentEnsureOptionsSchema = Schema.Struct({
434 issuePairingToken: Schema.optionalKey(Schema.Boolean),
435});
436​
437export const DesktopSshEnvironmentEnsureInputSchema = Schema.Struct({
438 target: DesktopSshEnvironmentTargetSchema,
439 options: Schema.optionalKey(DesktopSshEnvironmentEnsureOptionsSchema),
440});
441​
442export const DesktopSshEnvironmentEnsureResultSchema = Schema.Union([
443 DesktopSshEnvironmentBootstrapSchema,
444 DesktopSshPasswordPromptCancelledResultSchema,
445]);
446​
447export const DesktopSshHttpBaseUrlInputSchema = Schema.Struct({
448 httpBaseUrl: Schema.String,
449});
450​
451export const DesktopSshBearerRequestInputSchema = Schema.Struct({
452 httpBaseUrl: Schema.String,
453 bearerToken: Schema.String,
454});
455​
456export const DesktopSshBearerBootstrapInputSchema = Schema.Struct({
457 httpBaseUrl: Schema.String,
458 credential: Schema.String,
459});
460​
461export const DesktopSshPasswordPromptResolutionInputSchema = Schema.Struct({
462 requestId: Schema.String,
463 password: Schema.NullOr(Schema.String),
464});
465​
466export const PersistedSavedEnvironmentRecordSchema = Schema.Struct({
467 environmentId: EnvironmentId,
468 label: Schema.String,
469 wsBaseUrl: Schema.String,
470 httpBaseUrl: Schema.String,
471 createdAt: Schema.String,
472 lastConnectedAt: Schema.NullOr(Schema.String),
473 desktopSsh: Schema.optionalKey(DesktopSshEnvironmentTargetSchema),
474 relayManaged: Schema.optionalKey(
475 Schema.Struct({
476 relayUrl: Schema.String,
477 }),
478 ),
479});
480export type PersistedSavedEnvironmentRecord = typeof PersistedSavedEnvironmentRecordSchema.Type;
481​
482export type DesktopServerExposureMode = "local-only" | "network-accessible";
483​
484export const DesktopServerExposureModeSchema = Schema.Literals([
485 "local-only",
486 "network-accessible",
487]);
488​
489export interface DesktopServerExposureState {
490 mode: DesktopServerExposureMode;
491 endpointUrl: string | null;
492 advertisedHost: string | null;
493 tailscaleServeEnabled: boolean;
494 tailscaleServePort: number;
496​
497export const DesktopServerExposureStateSchema = Schema.Struct({
498 mode: DesktopServerExposureModeSchema,
499 endpointUrl: Schema.NullOr(Schema.String),
500 advertisedHost: Schema.NullOr(Schema.String),
501 tailscaleServeEnabled: Schema.Boolean,
502 tailscaleServePort: Schema.Number,
503});
504​
505export interface PickFolderOptions {
506 initialPath?: string | null;
507 // When set, the desktop dialog opens against the named backend's
508 // filesystem instead of the primary's. Used by callers that already
509 // know which local environment they're targeting (e.g. opening a
510 // project that lives inside WSL). Omitting it keeps the historical
511 // behavior so non-WSL users never see a different picker.
512 targetEnvironmentId?: string;
514​
515export const PickFolderOptionsSchema = Schema.Struct({
516 initialPath: Schema.optionalKey(Schema.NullOr(Schema.String)),
517 targetEnvironmentId: Schema.optionalKey(Schema.String),
518});
519​
520/**
521 * A file returned by the desktop theme-file picker. Oversized files carry an
522 * empty text so the renderer can reject them by size without the main
523 * process ever holding their contents.
524 */
525export interface PickedThemeFile {
526 name: string;
527 size: number;
528 text: string;
530​
531export const PickedThemeFileSchema = Schema.Struct({
532 name: Schema.String,
533 size: Schema.Number,
534 text: Schema.String,
535});
536​
537export interface DesktopWslDistro {
538 name: string;
539 isDefault: boolean;
540 version: 1 | 2;
542​
543export const DesktopWslDistroSchema = Schema.Struct({
544 name: Schema.String,
545 isDefault: Schema.Boolean,
546 version: Schema.Literals([1, 2]),
547});
548​
549export interface DesktopWslState {
550 // True when the user has opted the WSL backend in; the actual backend
551 // process is registered with the desktop pool independently of this
552 // flag and may take a moment to come up after the user enables it.
553 enabled: boolean;
554 // null means "track the current WSL default distro".
555 distro: string | null;
556 available: boolean;
557 // When true (and `enabled` is also true) the desktop runs only the
558 // WSL backend as the primary; the Windows-side Node backend is not
559 // started. Toggling this requires an app restart because the
560 // primary backend's spec is captured once at layer init.
561 wslOnly: boolean;
562 distros: readonly DesktopWslDistro[];
563 // Reason the dual-mode WSL backend last failed preflight (no node, wrong
564 // version, missing build tools), or null. Surfaced inline in Connections
565 // settings. Always null in wsl-only mode — that path shows a dialog and
566 // falls back to Windows instead.
567 preflightError: string | null;
569​
570export const DesktopWslStateSchema = Schema.Struct({
571 enabled: Schema.Boolean,
572 distro: Schema.NullOr(Schema.String),
573 available: Schema.Boolean,
574 wslOnly: Schema.Boolean,
575 distros: Schema.Array(DesktopWslDistroSchema),
576 preflightError: Schema.NullOr(Schema.String),
577});
578​
579/**
580 * Renderer-facing snapshot of a desktop preview tab. Mirrors the main-process
581 * PreviewTabState shape but uses serialisable primitives only.
582 */
583export type DesktopPreviewNavStatus =
584 | { kind: "Idle" }
585 | { kind: "Loading"; url: string; title: string }
586 | { kind: "Success"; url: string; title: string }
587 | {
588 kind: "LoadFailed";
589 url: string;
590 title: string;
591 code: number;
592 description: string;
593 };
594​
595/**
596 * Emulated `prefers-color-scheme` for the guest page. "system" clears the
597 * override so the page follows the OS appearance.
598 */
599export type DesktopPreviewColorScheme = "system" | "light" | "dark";
600​
601export const DesktopPreviewColorSchemeSchema: Schema.Codec<DesktopPreviewColorScheme> =
602 Schema.Literals(["system", "light", "dark"]);
603​
604export const FAVICON_DATA_URL_MAX_LENGTH = 8192;
605export const FAVICON_CAPTURED_AT_MAX = 8_640_000_000_000_000;
606​
607export interface DesktopPreviewFavicon {
608 dataUrl: string;
609 pageUrl: string;
610 capturedAt: number;
612​
613export interface DesktopPreviewTabState {
614 tabId: string;
615 webContentsId: number | null;
616 navStatus: DesktopPreviewNavStatus;
617 canGoBack: boolean;
618 canGoForward: boolean;
619 /** Current zoom factor (1.0 = 100%). */
620 zoomFactor: number;
621 /** Whether this tab is currently mirrored into a desktop picture-in-picture window. */
622 pictureInPicture: boolean;
623 colorScheme: DesktopPreviewColorScheme;
624 /**
625 * Whether the user has silenced this tab. Per tab rather than per origin, so
626 * two tabs on the same site mute independently. Survives navigation and
627 * webview swaps, but is dropped when the tab closes.
628 */
629 audioMuted: boolean;
630 /**
631 * Whether the guest is currently emitting audio. Observed from Chromium, and
632 * independent of {@link audioMuted}: a muted tab that is playing still reports
633 * `true`, which is what lets the tab strip distinguish "muted and making
634 * sound" from "muted and silent".
635 */
636 audible: boolean;
637 controller: "human" | "agent" | "none";
638 favicon?: DesktopPreviewFavicon;
639 updatedAt: string;
641​
642export const DesktopPreviewTabIdSchema = Schema.String.check(Schema.isTrimmed()).check(
643 Schema.isNonEmpty(),
644);
645​
646export const DesktopPreviewAutomationStatusSchema = Schema.Struct({
647 ...PreviewAutomationStatus.fields,
648 tabId: Schema.NullOr(DesktopPreviewTabIdSchema),
649});
650export type DesktopPreviewAutomationStatus = typeof DesktopPreviewAutomationStatusSchema.Type;
651​
652export interface DesktopPreviewPointerEvent {
653 tabId: string;
654 phase: "move" | "click";
655 x: number;
656 y: number;
657 sequence: number;
658 createdAt: string;
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;
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;
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;
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;
763​
764export interface DesktopPreviewRecordingArtifact {
765 id: string;
766 tabId: string;
767 path: string;
768 mimeType: string;
769 sizeBytes: number;
770 createdAt: string;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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});
1026​
1027export interface DesktopPreviewTabDefaults {
1028 readonly zoomFactor?: number | undefined;
1029 readonly colorScheme?: DesktopPreviewColorScheme | undefined;
1031​
1032export const DesktopPreviewRegisterWebviewInputSchema = Schema.Struct({
1033 tabId: DesktopPreviewTabIdSchema,
1034 webContentsId: Schema.Int.check(Schema.isGreaterThan(0)),
1035});
1036​
1037export const DesktopPreviewNavigateInputSchema = Schema.Struct({
1038 tabId: DesktopPreviewTabIdSchema,
1039 url: Schema.String,
1040});
1041​
1042export const DesktopPreviewConfigInputSchema = Schema.Struct({
1043 environmentId: EnvironmentId,
1044 /**
1045 * Browser profile the partition is derived from. Derivation stays in main:
1046 * `will-attach-webview` only prefix-checks the partition string, so a
1047 * renderer-supplied partition could attach to a session that never had the
1048 * UA rewrite or permission handlers installed.
1049 */
1050 profileId: Schema.optional(BrowserProfileId),
1051});
1052​
1053export const DesktopPreviewClearDataInputSchema = Schema.Struct({
1054 environmentId: EnvironmentId,
1055 /** Omit to clear every profile; otherwise only this profile's partition. */
1056 profileId: Schema.optional(BrowserProfileId),
1057});
1058​
1059export const DesktopPreviewSetColorSchemeInputSchema = Schema.Struct({
1060 tabId: DesktopPreviewTabIdSchema,
1061 colorScheme: DesktopPreviewColorSchemeSchema,
1062});
1063​
1064export const DesktopPreviewSetAudioMutedInputSchema = Schema.Struct({
1065 tabId: DesktopPreviewTabIdSchema,
1066 audioMuted: Schema.Boolean,
1067});
1068​
1069export const DesktopPreviewAnnotationThemeInputSchema = Schema.Struct({
1070 theme: DesktopPreviewAnnotationThemeSchema,
1071});
1072​
1073export const DesktopPreviewArtifactInputSchema = Schema.Struct({
1074 path: Schema.String.check(Schema.isTrimmed()).check(Schema.isNonEmpty()),
1075});
1076​
1077export const DesktopPreviewRecordingSaveInputSchema = Schema.Struct({
1078 tabId: DesktopPreviewTabIdSchema,
1079 mimeType: Schema.String.check(Schema.isTrimmed()).check(Schema.isNonEmpty()),
1080 data: Schema.Uint8Array,
1081});
1082​
1083export const DesktopPreviewAutomationClickInputSchema = Schema.Struct({
1084 tabId: DesktopPreviewTabIdSchema,
1085 input: PreviewAutomationClickInput,
1086});
1087​
1088export const DesktopPreviewAutomationTypeInputSchema = Schema.Struct({
1089 tabId: DesktopPreviewTabIdSchema,
1090 input: PreviewAutomationTypeInput,
1091});
1092​
1093export const DesktopPreviewAutomationPressInputSchema = Schema.Struct({
1094 tabId: DesktopPreviewTabIdSchema,
1095 input: PreviewAutomationPressInput,
1096});
1097​
1098export const DesktopPreviewAutomationScrollInputSchema = Schema.Struct({
1099 tabId: DesktopPreviewTabIdSchema,
1100 input: PreviewAutomationScrollInput,
1101});
1102​
1103export const DesktopPreviewAutomationEvaluateInputSchema = Schema.Struct({
1104 tabId: DesktopPreviewTabIdSchema,
1105 input: PreviewAutomationEvaluateInput,
1106});
1107​
1108export const DesktopPreviewAutomationWaitForInputSchema = Schema.Struct({
1109 tabId: DesktopPreviewTabIdSchema,
1110 input: PreviewAutomationWaitForInput,
1111});
1112​
1113/**
1114 * A System Settings pane the app can deep-link to. The identifier crosses IPC
1115 * rather than a URL, so the renderer can only reach these known destinations.
1116 */
1117export const SystemSettingsPaneSchema = Schema.Literals(["full-disk-access"]);
1118export type SystemSettingsPane = typeof SystemSettingsPaneSchema.Type;
1119​
1120export interface DesktopBridge {
1121 getAppBranding: () => DesktopAppBranding | null;
1122 /** Absolute path of a dropped or picked file; absent on desktop builds predating it. */
1123 getPathForFile?: (file: File) => string;
1124 /** The desktop client's OS platform, read from Electron's preload process. */
1125 getClientPlatform?: () => string;
1126 setNotificationBadge?: (badge: { count: number; image: string | null }) => Promise<void>;
1127 onNotificationBadgeClear?: (listener: () => void) => () => void;
1128 /**
1129 * The OS locale as a BCP-47 tag, which the renderer cannot read for itself:
1130 * the packaged app ships only the `en-US` Chromium locale pak, so
1131 * `navigator.language` and the default `Intl` locale are pinned to `en-US`
1132 * regardless of OS settings.
1133 */
1134 getSystemLocale?: () => string | null;
1135 // One bootstrap per pool instance currently registered with bootstrap
1136 // info (omits instances whose backend hasn't produced a config yet).
1137 // The primary backend is identified by id === PRIMARY_LOCAL_ENVIRONMENT_ID.
1138 getLocalEnvironmentBootstraps: () => readonly DesktopEnvironmentBootstrap[];
1139 getLocalEnvironmentEnabled?: () => boolean;
1140 setLocalEnvironmentEnabled?: (enabled: boolean) => Promise<void>;
1141 getLocalEnvironmentBearerToken: () => Promise<string>;
1142 getClientSettings: () => Promise<ClientSettings | null>;
1143 setClientSettings: (settings: ClientSettings) => Promise<void>;
1144 getConnectionCatalog?: () => Promise<string | null>;
1145 setConnectionCatalog?: (catalog: string) => Promise<boolean>;
1146 clearConnectionCatalog?: () => Promise<void>;
1147 discoverSshHosts: () => Promise<readonly DesktopDiscoveredSshHost[]>;
1148 /** Resolves a suggested SSH alias before populating the connection form. */
1149 resolveSshHost: (alias: string) => Promise<DesktopSshEnvironmentTarget>;
1150 requestSnapShotPermissions?: (includeAccessibility: boolean) => Promise<void>;
1151 getSnapShotState?: () => Promise<DesktopSnapShotState>;
1152 setupSnapShot?: (action: DesktopSnapShotSetupAction) => Promise<void>;
1153 previewSnapShotConfig?: (
1154 request: DesktopCaptureConfigRequest,
1155 ) => Promise<DesktopCaptureConfigPreview | null>;
1156 applySnapShotConfig?: (previewId: string) => Promise<DesktopCaptureConfigApplied>;
1157 checkSnapShotShortcut?: (
1158 shortcut: SnapShotShortcut,
1159 ) => Promise<DesktopSnapShotShortcutAvailability>;
1160 setSnapShotShortcutSuppressed?: (suppressed: boolean) => Promise<void>;
1161 listPendingSnapShots?: () => Promise<readonly DesktopPendingSnapShot[]>;
1162 readSnapShot?: (id: string) => Promise<DesktopSnapShot>;
1163 setSnapShotAnimationDestination?: (
1164 destination: DesktopSnapShotAnimationDestination,
1165 ) => Promise<void>;
1166 dismissSnapShotAnimation?: (id: DesktopSnapShotId) => Promise<void>;
1167 acknowledgeSnapShot?: (id: string) => Promise<void>;
1168 ensureSshEnvironment: (
1169 target: DesktopSshEnvironmentTarget,
1170 options?: { issuePairingToken?: boolean },
1171 ) => Promise<DesktopSshEnvironmentBootstrap>;
1172 disconnectSshEnvironment: (target: DesktopSshEnvironmentTarget) => Promise<void>;
1173 fetchSshEnvironmentDescriptor: (httpBaseUrl: string) => Promise<ExecutionEnvironmentDescriptor>;
1174 bootstrapSshBearerSession: (
1175 httpBaseUrl: string,
1176 credential: string,
1177 ) => Promise<AuthAccessTokenResult>;
1178 fetchSshSessionState: (httpBaseUrl: string, bearerToken: string) => Promise<AuthSessionState>;
1179 issueSshWebSocketTicket: (
1180 httpBaseUrl: string,
1181 bearerToken: string,
1182 ) => Promise<AuthWebSocketTicketResult>;
1183 onSshPasswordPrompt: (listener: (request: DesktopSshPasswordPromptRequest) => void) => () => void;
1184 resolveSshPasswordPrompt: (requestId: string, password: string | null) => Promise<void>;
1185 getServerExposureState: () => Promise<DesktopServerExposureState>;
1186 setServerExposureMode: (mode: DesktopServerExposureMode) => Promise<DesktopServerExposureState>;
1187 setTailscaleServeEnabled: (input: {
1188 readonly enabled: boolean;
1189 readonly port?: number;
1190 }) => Promise<DesktopServerExposureState>;
1191 getAdvertisedEndpoints: () => Promise<readonly AdvertisedEndpoint[]>;
1192 getWslState: () => Promise<DesktopWslState>;
1193 setWslBackendEnabled: (enabled: boolean) => Promise<DesktopWslState>;
1194 setWslDistro: (distro: string | null) => Promise<DesktopWslState>;
1195 setWslOnly: (enabled: boolean) => Promise<DesktopWslState>;
1196 pickFolder: (options?: PickFolderOptions) => Promise<string | null>;
1197 /** Optional while older desktop shells can host a newer web client. */
1198 pickProjectFavicon?: (initialPath?: string) => Promise<string | null>;
1199 /**
1200 * Multi-select JSON file picker that opens in the VS Code extensions
1201 * directory when one exists. Optional: older desktop builds lack it, and
1202 * web callers fall back to a plain file input.
1203 */
1204 pickThemeFiles?: () => Promise<readonly PickedThemeFile[] | null>;
1205 setTheme: (theme: DesktopTheme) => Promise<void>;
1206 showContextMenu: <T extends string>(
1207 items: readonly ContextMenuItem<T>[],
1208 position?: { x: number; y: number },
1209 ) => Promise<T | null>;
1210 openExternal: (url: string) => Promise<boolean>;
1211 /**
1212 * Open a System Settings pane by identifier. Optional: older desktop builds
1213 * lack it, and callers no-op when it is missing.
1214 */
1215 openSystemSettings?: (pane: SystemSettingsPane) => Promise<boolean>;
1216 checkSystemPermission?: (pane: SystemSettingsPane) => Promise<boolean>;
1217 /**
1218 * Probe this desktop machine for installed remote-capable editor CLIs
1219 * (used for remote open-in-editor deep links). Optional: older desktop
1220 * builds lack it; callers fall back to VS Code only.
1221 */
1222 probeRemoteEditors?: () => Promise<readonly EditorId[]>;
1223 /** Present when the desktop shell can perform an ordered plain-text paste. */
1224 pasteAsText?: () => Promise<void>;
1225 onMenuAction: (listener: (action: string) => void) => () => void;
1226 onSnapShotEvent?: (listener: (event: DesktopSnapShotEvent) => void) => () => void;
1227 /**
1228 * Quit-confirmation hint pushes. Optional: older desktop builds never emit
1229 * them.
1230 */
1231 onQuitShortcut?: (listener: (event: QuitShortcutHintEvent) => void) => () => void;
1232 getWindowFullscreenState: () => boolean;
1233 onWindowFullscreenStateChange: (listener: (fullscreen: boolean) => void) => () => void;
1234 getUpdateState: () => Promise<DesktopUpdateState>;
1235 setUpdateChannel: (channel: DesktopUpdateChannel) => Promise<DesktopUpdateState>;
1236 checkForUpdate: () => Promise<DesktopUpdateCheckResult>;
1237 downloadUpdate: () => Promise<DesktopUpdateActionResult>;
1238 installUpdate: () => Promise<DesktopUpdateActionResult>;
1239 onUpdateState: (listener: (state: DesktopUpdateState) => void) => () => void;
1240 /** Present when the desktop shell accepts `t3 app` activation requests. */
1241 appActivation?: {
1242 setReady: (ready: boolean) => Promise<void>;
1243 complete: (response: DesktopAppActivationResponse) => Promise<void>;
1244 onRequest: (listener: (request: DesktopAppActivationRequest) => void) => () => void;
1245 };
1246 /**
1247 * Desktop-only preview surface. Present iff the renderer is hosted by the
1248 * Electron desktop build; web builds have `preview === undefined`.
1249 */
1250 preview?: DesktopPreviewBridge;
1252​
1253/** Renderer callback invoked by Electron with a fresh user gesture before display-media capture. */
1254export const DESKTOP_PREVIEW_RECORDING_CAPTURE_TRIGGER = "__t3DesktopPreviewRecordingCapture";
1255​
1256export interface DesktopPreviewBridge {
1257 createTab: (tabId: string, defaults?: DesktopPreviewTabDefaults) => Promise<void>;
1258 closeTab: (tabId: string) => Promise<void>;
1259 registerWebview: (tabId: string, webContentsId: number) => Promise<void>;
1260 navigate: (tabId: string, url: string) => Promise<void>;
1261 goBack: (tabId: string) => Promise<void>;
1262 goForward: (tabId: string) => Promise<void>;
1263 refresh: (tabId: string) => Promise<void>;
1264 zoomIn: (tabId: string) => Promise<void>;
1265 zoomOut: (tabId: string) => Promise<void>;
1266 resetZoom: (tabId: string) => Promise<void>;
1267 /** Reload bypassing the HTTP cache. */
1268 hardReload: (tabId: string) => Promise<void>;
1269 /**
1270 * Emulate `prefers-color-scheme` on the guest page ("system" clears the
1271 * override). Persists per tab and is re-applied across webview swaps.
1272 */
1273 setColorScheme: (tabId: string, colorScheme: DesktopPreviewColorScheme) => Promise<void>;
1274 /**
1275 * Silence the tab's audio output. Persists per tab and is re-applied across
1276 * webview swaps, but is dropped when the tab closes. Muting a silent tab is
1277 * allowed; it simply takes effect once the page plays something.
1278 */
1279 setAudioMuted: (tabId: string, audioMuted: boolean) => Promise<void>;
1280 /** Open the guest webview's DevTools (detached). */
1281 openDevTools: (tabId: string) => Promise<void>;
1282 /** Drop cookies + storage data for the preview partition (all tabs). */
1283 clearCookies: (environmentId: EnvironmentId, profileId?: string) => Promise<void>;
1284 /** Drop the HTTP cache for the preview partition (all tabs). */
1285 clearCache: (environmentId: EnvironmentId, profileId?: string) => Promise<void>;
1286 /**
1287 * One-shot config for mounting a preview `<webview>`. Replaces three
1288 * earlier round-trip calls (`getBrowserPartition`, `getWebviewPreferences`,
1289 * `getPickPreloadPath`) so adding a new field here only requires touching
1290 * the contract + main, not the renderer's mount logic.
1291 */
1292 getPreviewConfig: (
1293 environmentId: EnvironmentId,
1294 profileId?: string,
1295 ) => Promise<DesktopPreviewWebviewConfig>;
1296 /** Browsers on this machine whose cookies can be imported. */
1297 listBrowserImportSources: () => Promise<ReadonlyArray<BrowserImportSource>>;
1298 importBrowserCookies: (input: {
1299 readonly environmentId: EnvironmentId;
1300 readonly sourceId: BrowserImportSourceId;
1301 readonly sourceProfileDirectory: string;
1302 readonly targetProfileId: string;
1303 }) => Promise<BrowserImportResult>;
1304 setAnnotationTheme: (theme: DesktopPreviewAnnotationTheme) => 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 automation: {
1333 status: (tabId: string) => Promise<DesktopPreviewAutomationStatus>;
1334 snapshot: (tabId: string) => Promise<PreviewAutomationSnapshot>;
1335 click: (tabId: string, input: PreviewAutomationClickInput) => Promise<void>;
1336 type: (tabId: string, input: PreviewAutomationTypeInput) => Promise<void>;
1337 press: (tabId: string, input: PreviewAutomationPressInput) => Promise<void>;
1338 scroll: (tabId: string, input: PreviewAutomationScrollInput) => Promise<void>;
1339 evaluate: (tabId: string, input: PreviewAutomationEvaluateInput) => Promise<unknown>;
1340 waitFor: (tabId: string, input: PreviewAutomationWaitForInput) => Promise<void>;
1341 };
1342 onStateChange: (listener: (tabId: string, state: DesktopPreviewTabState) => void) => () => void;
1343 onPointerEvent: (listener: (event: DesktopPreviewPointerEvent) => void) => () => void;
1345​
1346export type ConfirmDialogVariant = "default" | "destructive";
1347​
1348export interface ConfirmDialogOptions {
1349 readonly variant?: ConfirmDialogVariant;
1351​
1352/**
1353 * APIs bound to the local app shell, not to any particular backend environment.
1355 * These capabilities describe the desktop/browser host that the user is
1356 * currently running: dialogs, external-link opening, context menus, and
1357 * app-level settings/config access. They must not be used as a proxy for
1358 * "whatever environment the user is targeting", because in a multi-environment
1359 * world the local shell and a selected backend environment are distinct
1360 * concepts.
1361 */
1362export interface LocalApi {
1363 dialogs: {
1364 pickFolder: (options?: PickFolderOptions) => Promise<string | null>;
1365 confirm: (message: string, options?: ConfirmDialogOptions) => Promise<boolean>;
1366 };
1367 shell: {
1368 openExternal: (url: string) => Promise<void>;
1369 /** Opens a known System Settings pane; no-ops outside the desktop app. */
1370 openSystemSettings: (pane: SystemSettingsPane) => Promise<void>;
1371 };
1372 contextMenu: {
1373 show: <T extends string>(
1374 items: readonly ContextMenuItem<T>[],
1375 position?: { x: number; y: number },
1376 ) => Promise<T | null>;
1377 close: () => Promise<void>;
1378 };
1379 persistence: {
1380 getClientSettings: () => Promise<ClientSettings | null>;
1381 setClientSettings: (settings: ClientSettings) => Promise<void>;
1382 };