Open History to see the last commit
1import * as Schema from "effect/Schema";
2import type { DatabaseMigrationProgress } from "./server.ts";
3import type { PreviewCaptureFailureEncoded } from "./previewCapture.ts";
4
5import { SnapShotSource } from "./chatAttachment.ts";
6import { EnvironmentId, PortSchema, TrimmedNonEmptyString } from "./baseSchemas.ts";
7import { BrowserProfileId } from "./browserProfile.ts";
8import type {
9 BrowserImportResult,
10 BrowserImportSource,
11 BrowserImportSourceId,
12} from "./browserImport.ts";
13import { AuthAccessTokenResult, AuthSessionState } from "./auth.ts";
14import { AdvertisedEndpoint } from "./remoteAccess.ts";
15import { ExecutionEnvironmentDescriptor } from "./environment.ts";
16import { type ClientSettings, type QuitConfirmationMode, SnapShotShortcut } from "./settings.ts";
17import type { EditorId } from "./editor.ts";
18import { KeybindingShortcut, type PreviewForwardedShortcut } from "./keybindings.ts";
19
20import type {
21 DesktopAppActivationRequest,
22 DesktopAppActivationResponse,
23} from "./desktopAppActivation.ts";
24
25export interface ContextMenuItem<T extends string = string> {
26 id: T;
27 label: string;
28 detail?: string;
29 destructive?: boolean;
30 disabled?: boolean;
31 header?: boolean;
32 icon?: string;
33 /** PNG data URL; takes precedence over `icon`. */
34 iconImage?: string;
35 separatorBefore?: boolean;
36 checked?: boolean;
37 children?: readonly ContextMenuItem<T>[];
38}
39
40export type QuitShortcutHintEvent =
41 | { readonly state: "down"; readonly mode: Exclude<QuitConfirmationMode, "direct"> }
42 | { readonly state: "up" };
43
44export interface ContextMenuItemSchemaType {
45 readonly id: string;
46 readonly label: string;
47 readonly detail?: string;
48 readonly destructive?: boolean;
49 readonly disabled?: boolean;
50 readonly header?: boolean;
51 readonly icon?: string;
52 readonly iconImage?: string;
53 readonly separatorBefore?: boolean;
54 readonly checked?: boolean;
55 readonly children?: readonly ContextMenuItemSchemaType[];
56}
57
58export const ContextMenuItemSchema: Schema.Codec<ContextMenuItemSchemaType> = Schema.Struct({
59 id: Schema.String,
60 label: Schema.String,
61 detail: Schema.optionalKey(Schema.String),
62 destructive: Schema.optionalKey(Schema.Boolean),
63 disabled: Schema.optionalKey(Schema.Boolean),
64 header: Schema.optionalKey(Schema.Boolean),
65 icon: Schema.optionalKey(Schema.String),
66 iconImage: Schema.optionalKey(Schema.String),
67 separatorBefore: Schema.optionalKey(Schema.Boolean),
68 checked: Schema.optionalKey(Schema.Boolean),
69 children: Schema.optionalKey(
70 Schema.Array(
71 Schema.suspend((): Schema.Codec<ContextMenuItemSchemaType> => ContextMenuItemSchema),
72 ),
73 ),
74});
75
76// Native menus opened from the keyboard select their first item, which is what
77// moves a screen reader into the menu. Electron assumes a mouse unless told.
78export const ContextMenuSource = Schema.Literals(["mouse", "keyboard"]);
79export type ContextMenuSource = typeof ContextMenuSource.Type;
80
81export type DesktopUpdateStatus =
82 | "disabled"
83 | "idle"
84 | "checking"
85 | "up-to-date"
86 | "available"
87 | "downloading"
88 | "downloaded"
89 | "error";
90
91export type DesktopRuntimeArch = "arm64" | "x64" | "other";
92export type DesktopTheme = "light" | "dark" | "system";
93export type DesktopUpdateChannel = "latest" | "nightly";
94export type DesktopAppStageLabel = "Alpha" | "Beta" | "Dev" | "Nightly";
95
96export const DesktopUpdateStatusSchema = Schema.Literals([
97 "disabled",
98 "idle",
99 "checking",
100 "up-to-date",
101 "available",
102 "downloading",
103 "downloaded",
104 "error",
105]);
106export const DesktopRuntimeArchSchema = Schema.Literals(["arm64", "x64", "other"]);
107export const DesktopThemeSchema = Schema.Literals(["light", "dark", "system"]);
108export const DesktopUpdateChannelSchema = Schema.Literals(["latest", "nightly"]);
109export const DesktopAppStageLabelSchema = Schema.Literals(["Alpha", "Beta", "Dev", "Nightly"]);
110
111export interface DesktopAppBranding {
112 baseName: string;
113 stageLabel: DesktopAppStageLabel;
114 displayName: string;
115}
116
117export const DesktopAppBrandingSchema = Schema.Struct({
118 baseName: Schema.String,
119 stageLabel: DesktopAppStageLabelSchema,
120 displayName: Schema.String,
121});
122
123export const DesktopSnapShotMode = Schema.Literals(["direct", "portal", "unavailable"]);
124export type DesktopSnapShotMode = typeof DesktopSnapShotMode.Type;
125
126export const DesktopCaptureExtensionState = Schema.Struct({
127 status: Schema.Literals([
128 "not-installed",
129 "disabled",
130 "enabled",
131 "restart-required",
132 "update-required",
133 "extensions-disabled",
134 "unsupported",
135 "error",
136 ]),
137 message: Schema.String,
138});
139export type DesktopCaptureExtensionState = typeof DesktopCaptureExtensionState.Type;
140
141export const DesktopCaptureHelperState = Schema.Struct({
142 status: Schema.Literals(["not-installed", "update-required", "ready", "error"]),
143 message: Schema.String,
144 feedbackAvailable: Schema.optional(Schema.Boolean),
145});
146export type DesktopCaptureHelperState = typeof DesktopCaptureHelperState.Type;
147
148export const DesktopSnapShotSetupAction = Schema.Literals([
149 "install-extension",
150 "enable-extension",
151 "disable-extension",
152 "install-kde-helper",
153 "remove-kde-helper",
154 "install-hyprland-helper",
155 "remove-hyprland-helper",
156 "test-mac-capture",
157 "allow-screen-recording",
158 "allow-accessibility",
159 "retry-shortcut",
160]);
161export type DesktopSnapShotSetupAction = typeof DesktopSnapShotSetupAction.Type;
162
163export const DesktopCaptureConfigRequest = Schema.Struct({
164 operation: Schema.Literals(["install", "remove"]),
165 chooseFile: Schema.Boolean,
166 shortcut: Schema.optional(Schema.String.check(Schema.isMaxLength(80))),
167});
168export type DesktopCaptureConfigRequest = typeof DesktopCaptureConfigRequest.Type;
169
170export const DesktopCaptureConfigPreview = Schema.Struct({
171 id: Schema.String,
172 path: Schema.String,
173 resolvedPath: Schema.String,
174 before: Schema.String,
175 after: Schema.String,
176 shortcut: Schema.String,
177 operation: Schema.Literals(["install", "remove"]),
178});
179export type DesktopCaptureConfigPreview = typeof DesktopCaptureConfigPreview.Type;
180
181export const DesktopCaptureConfigApplied = Schema.Struct({
182 backupPath: Schema.NullOr(Schema.String),
183 warning: Schema.NullOr(Schema.String),
184});
185export type DesktopCaptureConfigApplied = typeof DesktopCaptureConfigApplied.Type;
186
187export const DesktopSnapShotState = Schema.Struct({
188 mode: DesktopSnapShotMode,
189 windows: Schema.optional(Schema.Boolean),
190 linuxDesktop: Schema.optional(Schema.Literals(["gnome", "kde", "niri", "hyprland"])),
191 linuxBackend: Schema.optional(
192 Schema.Literals(["screenshot-portal", "gnome-extension", "niri", "kde", "hyprland", "picker"]),
193 ),
194 linuxFeedbackAvailable: Schema.optional(Schema.Boolean),
195 shortcut: SnapShotShortcut,
196 shortcutRegistered: Schema.Boolean,
197 shortcutPending: Schema.optional(Schema.Boolean),
198 shortcutCanRetry: Schema.optional(Schema.Boolean),
199 shortcutLabel: Schema.optional(Schema.String),
200 shortcutMessage: Schema.NullOr(Schema.String),
201 shortcutBinding: Schema.optional(Schema.String),
202 shortcutConfigPath: Schema.optional(Schema.String),
203 shortcutActionRegistered: Schema.optional(Schema.Boolean),
204 gnomeExtension: Schema.optional(DesktopCaptureExtensionState),
205 kdeHelper: Schema.optional(DesktopCaptureHelperState),
206 hyprlandHelper: Schema.optional(DesktopCaptureHelperState),
207 macPermissions: Schema.optional(
208 Schema.Struct({ screenRecording: Schema.Boolean, accessibility: Schema.Boolean }),
209 ),
210 shortcutVerified: Schema.optional(Schema.Boolean),
211 message: Schema.NullOr(Schema.String),
212});
213export type DesktopSnapShotState = typeof DesktopSnapShotState.Type;
214
215export const DesktopSnapShotShortcutAvailability = Schema.Struct({
216 available: Schema.Boolean,
217 message: Schema.NullOr(Schema.String),
218});
219export type DesktopSnapShotShortcutAvailability = typeof DesktopSnapShotShortcutAvailability.Type;
220
221export const DesktopSnapShotId = TrimmedNonEmptyString.check(
222 Schema.isMaxLength(64),
223 Schema.isPattern(/^[a-f0-9-]+$/i),
224);
225export type DesktopSnapShotId = typeof DesktopSnapShotId.Type;
226
227/** `id` is absent for failures before a capture exists. */
228export const DesktopSnapShotEvent = Schema.Union([
229 Schema.Struct({ type: Schema.Literal("requested"), id: DesktopSnapShotId }),
230 Schema.Struct({ type: Schema.Literal("started"), id: DesktopSnapShotId }),
231 Schema.Struct({ type: Schema.Literal("ready"), id: DesktopSnapShotId }),
232 Schema.Struct({ type: Schema.Literal("failed"), id: Schema.optional(DesktopSnapShotId) }),
233 Schema.Struct({ type: Schema.Literal("shortcut-changed") }),
234]);
235export type DesktopSnapShotEvent = typeof DesktopSnapShotEvent.Type;
236
237export const DesktopPendingSnapShot = Schema.Struct({
238 id: DesktopSnapShotId,
239 name: Schema.String,
240 mimeType: Schema.Literal("image/png"),
241 sizeBytes: Schema.Int,
242 source: SnapShotSource,
243});
244export type DesktopPendingSnapShot = typeof DesktopPendingSnapShot.Type;
245
246export const DesktopSnapShot = Schema.Struct({
247 ...DesktopPendingSnapShot.fields,
248 dataUrl: Schema.String,
249});
250export type DesktopSnapShot = typeof DesktopSnapShot.Type;
251
252export const DesktopSnapShotAnimationDestination = Schema.Struct({
253 id: DesktopSnapShotId,
254 viewportFrame: Schema.Struct({
255 x: Schema.Number,
256 y: Schema.Number,
257 width: Schema.Number,
258 height: Schema.Number,
259 }),
260 backgroundColor: Schema.String,
261 borderColor: Schema.String,
262 borderWidth: Schema.Number,
263 cornerRadius: Schema.Number,
264 details: Schema.optional(
265 Schema.Struct({
266 appName: SnapShotSource.fields.appName,
267 windowTitle: SnapShotSource.fields.windowTitle,
268 appIconDataUrl: SnapShotSource.fields.appIconDataUrl,
269 }),
270 ),
271});
272export type DesktopSnapShotAnimationDestination = typeof DesktopSnapShotAnimationDestination.Type;
273
274export interface DesktopRuntimeInfo {
275 hostArch: DesktopRuntimeArch;
276 appArch: DesktopRuntimeArch;
277 runningUnderArm64Translation: boolean;
278}
279
280export interface DesktopUpdateState {
281 enabled: boolean;
282 status: DesktopUpdateStatus;
283 channel: DesktopUpdateChannel;
284 currentVersion: string;
285 hostArch: DesktopRuntimeArch;
286 appArch: DesktopRuntimeArch;
287 runningUnderArm64Translation: boolean;
288 availableVersion: string | null;
289 downloadedVersion: string | null;
290 releaseNotes: ReadonlyArray<DesktopUpdateReleaseNote>;
291 omittedReleaseCount: number;
292 downloadPercent: number | null;
293 checkedAt: string | null;
294 message: string | null;
295 errorContext: "check" | "download" | "install" | null;
296 canRetry: boolean;
297 notAppliedVersion?: string;
298 /** Off only because a managed policy rules out this channel; switching channels turns it on. */
299 channelBlockedByPolicy?: true;
300 /** The check failed only because this build's track differs from the saved `channel`. */
301 trackMismatch?: { readonly buildChannel: DesktopUpdateChannel };
302}
303
304export interface DesktopUpdateReleaseNote {
305 version: string;
306 items: ReadonlyArray<string>;
307 totalItems: number;
308 /** ISO time from the update feed for the offered version, else `YYYY-MM-DD` from a prerelease version. */
309 releasedAt?: string;
310 /** Paragraph-style summaries from older releases keep their fixes in `items`. */
311 intro?: string;
312 /** Generated summaries only, for example "275 changes from 22 contributors". */
313 stats?: string;
314 footer?: string;
315}
316
317export const DesktopUpdateReleaseNoteSchema = Schema.Struct({
318 version: Schema.String,
319 items: Schema.Array(Schema.String),
320 totalItems: Schema.Number,
321 releasedAt: Schema.optionalKey(Schema.String),
322 intro: Schema.optionalKey(Schema.String),
323 stats: Schema.optionalKey(Schema.String),
324 footer: Schema.optionalKey(Schema.String),
325});
326
327export const DesktopUpdateStateSchema = Schema.Struct({
328 enabled: Schema.Boolean,
329 status: DesktopUpdateStatusSchema,
330 channel: DesktopUpdateChannelSchema,
331 currentVersion: Schema.String,
332 hostArch: DesktopRuntimeArchSchema,
333 appArch: DesktopRuntimeArchSchema,
334 runningUnderArm64Translation: Schema.Boolean,
335 availableVersion: Schema.NullOr(Schema.String),
336 downloadedVersion: Schema.NullOr(Schema.String),
337 releaseNotes: Schema.Array(DesktopUpdateReleaseNoteSchema),
338 omittedReleaseCount: Schema.Number,
339 downloadPercent: Schema.NullOr(Schema.Number),
340 checkedAt: Schema.NullOr(Schema.String),
341 message: Schema.NullOr(Schema.String),
342 errorContext: Schema.NullOr(Schema.Literals(["check", "download", "install"])),
343 canRetry: Schema.Boolean,
344 notAppliedVersion: Schema.optionalKey(Schema.String),
345 channelBlockedByPolicy: Schema.optionalKey(Schema.Literal(true)),
346 trackMismatch: Schema.optionalKey(Schema.Struct({ buildChannel: DesktopUpdateChannelSchema })),
347});
348
349export const DesktopCliCommandStateSchema = Schema.Struct({
350 supported: Schema.Boolean,
351 installedPath: Schema.NullOr(Schema.String),
352 onPath: Schema.Boolean,
353 shadowedBy: Schema.optionalKey(Schema.String),
354 /** For an installed `t3` that is off PATH: the shell startup file that adds it, and whether it has. */
355 pathSetup: Schema.optionalKey(Schema.Struct({ file: Schema.String, added: Schema.Boolean })),
356 /** The app's bundled `t3` launcher, which runs without Node or a PATH entry. */
357 launcherPath: Schema.NullOr(Schema.String),
358});
359export type DesktopCliCommandState = typeof DesktopCliCommandStateSchema.Type;
360
361export interface DesktopUpdateActionResult {
362 accepted: boolean;
363 completed: boolean;
364 state: DesktopUpdateState;
365}
366
367export const DesktopUpdateActionResultSchema = Schema.Struct({
368 accepted: Schema.Boolean,
369 completed: Schema.Boolean,
370 state: DesktopUpdateStateSchema,
371});
372
373export interface DesktopUpdateCheckResult {
374 checked: boolean;
375 state: DesktopUpdateState;
376}
377
378export const DesktopUpdateCheckResultSchema = Schema.Struct({
379 checked: Schema.Boolean,
380 state: DesktopUpdateStateSchema,
381});
382
383export const PRIMARY_LOCAL_ENVIRONMENT_ID = "primary";
384
385export interface DesktopEnvironmentBootstrap {
386 // Stable backend identity used to reopen routed projects.
387 id: string;
388 label: string;
389 // Actual distro for this run; id stays wsl:default when tracking the default.
390 runningDistro?: string | null;
391 httpBaseUrl: string | null;
392 wsBaseUrl: string | null;
393 bootstrapToken?: string;
394}
395
396export const DesktopEnvironmentBootstrapSchema = Schema.Struct({
397 id: Schema.String,
398 label: Schema.String,
399 runningDistro: Schema.optionalKey(Schema.NullOr(Schema.String)),
400 httpBaseUrl: Schema.NullOr(Schema.String),
401 wsBaseUrl: Schema.NullOr(Schema.String),
402 bootstrapToken: Schema.optionalKey(Schema.String),
403});
404
405export const DesktopSshEnvironmentTargetSchema = Schema.Struct({
406 alias: Schema.String,
407 hostname: Schema.String,
408 username: Schema.NullOr(Schema.String),
409 port: Schema.NullOr(Schema.Number),
410});
411export type DesktopSshEnvironmentTarget = typeof DesktopSshEnvironmentTargetSchema.Type;
412
413export type DesktopSshHostSource = "ssh-config" | "known-hosts";
414export const DesktopSshHostSourceSchema = Schema.Literals(["ssh-config", "known-hosts"]);
415
416export interface DesktopDiscoveredSshHost extends DesktopSshEnvironmentTarget {
417 source: DesktopSshHostSource;
418}
419
420export const DesktopDiscoveredSshHostSchema = Schema.Struct({
421 alias: Schema.String,
422 hostname: Schema.String,
423 username: Schema.NullOr(Schema.String),
424 port: Schema.NullOr(Schema.Number),
425 source: DesktopSshHostSourceSchema,
426});
427
428export interface DesktopSshEnvironmentBootstrap {
429 target: DesktopSshEnvironmentTarget;
430 httpBaseUrl: string;
431 wsBaseUrl: string;
432 pairingToken: string | null;
433 /** Opaque claim on this exact live forward, returned only when requested. */
434 tunnelClaim?: string;
435 remotePort?: number;
436 remoteServerKind?: "external" | "managed";
437}
438
439export const DesktopSshEnvironmentBootstrapSchema = Schema.Struct({
440 target: DesktopSshEnvironmentTargetSchema,
441 httpBaseUrl: Schema.String,
442 wsBaseUrl: Schema.String,
443 pairingToken: Schema.NullOr(Schema.String),
444 tunnelClaim: Schema.optionalKey(Schema.String),
445 remotePort: Schema.optionalKey(Schema.Number),
446 remoteServerKind: Schema.optionalKey(Schema.Literals(["external", "managed"])),
447});
448
449export interface DesktopSshPasswordPromptRequest {
450 requestId: string;
451 destination: string;
452 username: string | null;
453 prompt: string;
454 expiresAt: string;
455}
456
457export const DesktopSshPasswordPromptCancelledType = "ssh-password-prompt-cancelled" as const;
458
459export const DesktopSshPasswordPromptCancelledResultSchema = Schema.Struct({
460 type: Schema.Literal(DesktopSshPasswordPromptCancelledType),
461 message: Schema.String,
462});
463
464export const DesktopSshEnvironmentEnsureOptionsSchema = Schema.Struct({
465 issuePairingToken: Schema.optionalKey(Schema.Boolean),
466 claimTunnel: Schema.optionalKey(Schema.Boolean),
467});
468
469export type DesktopSshEnvironmentEnsureOptions =
470 typeof DesktopSshEnvironmentEnsureOptionsSchema.Type;
471
472export const DesktopSshEnvironmentEnsureInputSchema = Schema.Struct({
473 target: DesktopSshEnvironmentTargetSchema,
474 options: Schema.optionalKey(DesktopSshEnvironmentEnsureOptionsSchema),
475});
476
477export const DesktopSshEnvironmentEnsureResultSchema = Schema.Union([
478 DesktopSshEnvironmentBootstrapSchema,
479 DesktopSshPasswordPromptCancelledResultSchema,
480]);
481
482export const DesktopSshHttpBaseUrlInputSchema = Schema.Struct({
483 httpBaseUrl: Schema.String,
484});
485
486export const DesktopSshBearerRequestInputSchema = Schema.Struct({
487 httpBaseUrl: Schema.String,
488 bearerToken: Schema.String,
489});
490
491export const DesktopSshBearerBootstrapInputSchema = Schema.Struct({
492 httpBaseUrl: Schema.String,
493 credential: Schema.String,
494});
495
496export const DesktopSshPasswordPromptResolutionInputSchema = Schema.Struct({
497 requestId: Schema.String,
498 password: Schema.NullOr(Schema.String),
499});
500
501export const PersistedSavedEnvironmentRecordSchema = Schema.Struct({
502 environmentId: EnvironmentId,
503 label: Schema.String,
504 wsBaseUrl: Schema.String,
505 httpBaseUrl: Schema.String,
506 createdAt: Schema.String,
507 lastConnectedAt: Schema.NullOr(Schema.String),
508 desktopSsh: Schema.optionalKey(DesktopSshEnvironmentTargetSchema),
509 relayManaged: Schema.optionalKey(
510 Schema.Struct({
511 relayUrl: Schema.String,
512 }),
513 ),
514});
515export type PersistedSavedEnvironmentRecord = typeof PersistedSavedEnvironmentRecordSchema.Type;
516
517export type DesktopServerExposureMode = "local-only" | "network-accessible";
518
519export const DesktopServerExposureModeSchema = Schema.Literals([
520 "local-only",
521 "network-accessible",
522]);
523
524export interface DesktopServerExposureState {
525 mode: DesktopServerExposureMode;
526 endpointUrl: string | null;
527 advertisedHost: string | null;
528 tailscaleServeEnabled: boolean;
529 tailscaleServePort: number;
530}
531
532export const DesktopServerExposureStateSchema = Schema.Struct({
533 mode: DesktopServerExposureModeSchema,
534 endpointUrl: Schema.NullOr(Schema.String),
535 advertisedHost: Schema.NullOr(Schema.String),
536 tailscaleServeEnabled: Schema.Boolean,
537 tailscaleServePort: Schema.Number,
538});
539
540export interface PickFolderOptions {
541 initialPath?: string | null;
542 targetEnvironmentId?: string;
543}
544
545export const PickFolderOptionsSchema = Schema.Struct({
546 initialPath: Schema.optionalKey(Schema.NullOr(Schema.String)),
547 targetEnvironmentId: Schema.optionalKey(Schema.String),
548});
549
550/** Oversized files have empty text so the main process never loads their contents. */
551export interface PickedThemeFile {
552 name: string;
553 size: number;
554 text: string;
555}
556
557export const PickedThemeFileSchema = Schema.Struct({
558 name: Schema.String,
559 size: Schema.Number,
560 text: Schema.String,
561});
562
563export interface DesktopWslDistro {
564 name: string;
565 isDefault: boolean;
566 version: 1 | 2;
567}
568
569export const DesktopWslDistroSchema = Schema.Struct({
570 name: Schema.String,
571 isDefault: Schema.Boolean,
572 version: Schema.Literals([1, 2]),
573});
574
575export interface DesktopWslState {
576 enabled: boolean;
577 // null means "track the current WSL default distro".
578 distro: string | null;
579 available: boolean;
580 wslOnly: boolean;
581 distros: readonly DesktopWslDistro[];
582 // Always null in wsl-only mode, which falls back to Windows with a dialog.
583 preflightError: string | null;
584}
585
586export const DesktopWslStateSchema = Schema.Struct({
587 enabled: Schema.Boolean,
588 distro: Schema.NullOr(Schema.String),
589 available: Schema.Boolean,
590 wslOnly: Schema.Boolean,
591 distros: Schema.Array(DesktopWslDistroSchema),
592 preflightError: Schema.NullOr(Schema.String),
593});
594
595export type DesktopPreviewNavStatus =
596 | { kind: "Idle" }
597 | { kind: "Loading"; url: string; title: string }
598 | { kind: "Success"; url: string; title: string }
599 | {
600 kind: "LoadFailed";
601 url: string;
602 title: string;
603 code: number;
604 description: string;
605 };
606
607export type DesktopPreviewColorScheme = "system" | "light" | "dark";
608
609export const DesktopPreviewColorSchemeSchema: Schema.Codec<DesktopPreviewColorScheme> =
610 Schema.Literals(["system", "light", "dark"]);
611
612export const FAVICON_DATA_URL_MAX_LENGTH = 8192;
613export const FAVICON_CAPTURED_AT_MAX = 8_640_000_000_000_000;
614
615export interface DesktopPreviewFavicon {
616 dataUrl: string;
617 pageUrl: string;
618 capturedAt: number;
619}
620
621export interface DesktopPreviewTabState {
622 tabId: string;
623 webContentsId: number | null;
624 navStatus: DesktopPreviewNavStatus;
625 canGoBack: boolean;
626 canGoForward: boolean;
627 zoomFactor: number;
628 pictureInPicture: boolean;
629 colorScheme: DesktopPreviewColorScheme;
630 audioMuted: boolean;
631 /** Chromium reports playback even when audioMuted is true. */
632 audible: boolean;
633 controller: "human" | "agent" | "none";
634 /** A screenshot or stream of the guest is pending, so the client keeps it painting while hidden. */
635 capturing: boolean;
636 /** A streamed viewer's panel size, which a fill tab takes while no desktop window shows it. */
637 viewerSize: { readonly width: number; readonly height: number } | null;
638 favicon?: DesktopPreviewFavicon;
639 updatedAt: string;
640}
641
642export const DesktopPreviewTabIdSchema = Schema.String.check(Schema.isTrimmed()).check(
643 Schema.isNonEmpty(),
644);
645
646export interface DesktopPreviewPointerEvent {
647 tabId: string;
648 phase: "move" | "click";
649 x: number;
650 y: number;
651 sequence: number;
652 createdAt: string;
653}
654
655export interface DesktopPreviewOpenLinkEvent {
656 tabId: string;
657 url: string;
658 background: boolean;
659}
660
661export interface DesktopPreviewFindResultEvent {
662 tabId: string;
663 activeMatchOrdinal: number;
664 matches: number;
665}
666
667export const DesktopPreviewRecordingInputSchema = Schema.Union([
668 Schema.Struct({
669 type: Schema.Literal("pointer"),
670 phase: Schema.Literals(["move", "down", "up", "click"]),
671 x: Schema.Finite,
672 y: Schema.Finite,
673 width: Schema.Finite.check(Schema.isGreaterThan(0)),
674 height: Schema.Finite.check(Schema.isGreaterThan(0)),
675 }),
676 Schema.Struct({
677 type: Schema.Literal("key"),
678 label: Schema.NullOr(Schema.String.check(Schema.isMaxLength(100))),
679 held: Schema.Boolean,
680 width: Schema.Finite.check(Schema.isGreaterThan(0)),
681 }),
682 Schema.Struct({ type: Schema.Literal("clear") }),
683]);
684export type DesktopPreviewRecordingInput = typeof DesktopPreviewRecordingInputSchema.Type;
685export interface DesktopPreviewRecordingInputEvent {
686 readonly tabId: string;
687 readonly input: DesktopPreviewRecordingInput;
688}
689
690export interface DesktopPreviewWebviewConfig {
691 partition: string;
692 /** Sandboxed and context-isolated; the picker preload reaches React through a function it runs in the page. */
693 webPreferences: string;
694 /** Absolute file:// preload URL; null requires disabling element picking. */
695 preloadUrl: string | null;
696}
697
698export const DesktopPreviewWebviewConfigSchema: Schema.Codec<DesktopPreviewWebviewConfig> =
699 Schema.Struct({
700 partition: Schema.String,
701 webPreferences: Schema.String,
702 preloadUrl: Schema.NullOr(Schema.String),
703 });
704
705export interface DesktopPreviewAnnotationTheme {
706 colorScheme: "light" | "dark";
707 radius: string;
708 background: string;
709 foreground: string;
710 popover: string;
711 popoverForeground: string;
712 primary: string;
713 primaryForeground: string;
714 muted: string;
715 mutedForeground: string;
716 accent: string;
717 accentForeground: string;
718 border: string;
719 input: string;
720 ring: string;
721 fontSans: string;
722 fontMono: string;
723}
724
725export const DesktopPreviewAnnotationThemeSchema: Schema.Codec<DesktopPreviewAnnotationTheme> =
726 Schema.Struct({
727 colorScheme: Schema.Literals(["light", "dark"]),
728 radius: Schema.String,
729 background: Schema.String,
730 foreground: Schema.String,
731 popover: Schema.String,
732 popoverForeground: Schema.String,
733 primary: Schema.String,
734 primaryForeground: Schema.String,
735 muted: Schema.String,
736 mutedForeground: Schema.String,
737 accent: Schema.String,
738 accentForeground: Schema.String,
739 border: Schema.String,
740 input: Schema.String,
741 ring: Schema.String,
742 fontSans: Schema.String,
743 fontMono: Schema.String,
744 });
745
746export interface DesktopPreviewRecordingFrame {
747 tabId: string;
748 data: string;
749 width: number;
750 height: number;
751 receivedAt: string;
752}
753
754export interface DesktopPreviewRecordingArtifact {
755 id: string;
756 tabId: string;
757 path: string;
758 mimeType: string;
759 sizeBytes: number;
760 createdAt: string;
761}
762
763export const DesktopPreviewRecordingArtifactSchema: Schema.Codec<DesktopPreviewRecordingArtifact> =
764 Schema.Struct({
765 id: Schema.String,
766 tabId: DesktopPreviewTabIdSchema,
767 path: Schema.String,
768 mimeType: Schema.String,
769 sizeBytes: Schema.Int,
770 createdAt: Schema.String,
771 });
772
773export interface DesktopPreviewScreenshotArtifact {
774 id: string;
775 tabId: string;
776 path: string;
777 mimeType: "image/png";
778 sizeBytes: number;
779 createdAt: string;
780}
781
782export const DesktopPreviewScreenshotArtifactSchema: Schema.Codec<DesktopPreviewScreenshotArtifact> =
783 Schema.Struct({
784 id: Schema.String,
785 tabId: DesktopPreviewTabIdSchema,
786 path: Schema.String,
787 mimeType: Schema.Literal("image/png"),
788 sizeBytes: Schema.Int,
789 createdAt: Schema.String,
790 });
791
792export interface PickedElementStackFrame {
793 functionName: string | null;
794 fileName: string | null;
795 lineNumber: number | null;
796 columnNumber: number | null;
797}
798
799export const PickedElementStackFrameSchema: Schema.Codec<PickedElementStackFrame> = Schema.Struct({
800 functionName: Schema.NullOr(Schema.String),
801 fileName: Schema.NullOr(Schema.String),
802 lineNumber: Schema.NullOr(Schema.Number),
803 columnNumber: Schema.NullOr(Schema.Number),
804});
805
806export interface PickedElementPayload {
807 pageUrl: string;
808 pageTitle: string | null;
809 tagName: string;
810 selector: string | null;
811 htmlPreview: string;
812 componentName: string | null;
813 source: PickedElementStackFrame | null;
814 stack: ReadonlyArray<PickedElementStackFrame>;
815 styles: string;
816 pickedAt: string;
817}
818
819export const PickedElementPayloadSchema: Schema.Codec<PickedElementPayload> = Schema.Struct({
820 pageUrl: Schema.String,
821 pageTitle: Schema.NullOr(Schema.String),
822 tagName: Schema.String,
823 selector: Schema.NullOr(Schema.String),
824 htmlPreview: Schema.String,
825 componentName: Schema.NullOr(Schema.String),
826 source: Schema.NullOr(PickedElementStackFrameSchema),
827 stack: Schema.Array(PickedElementStackFrameSchema),
828 styles: Schema.String,
829 pickedAt: Schema.String,
830});
831
832export interface PreviewAnnotationRect {
833 x: number;
834 y: number;
835 width: number;
836 height: number;
837}
838
839export const PreviewAnnotationRectSchema: Schema.Codec<PreviewAnnotationRect> = Schema.Struct({
840 x: Schema.Number,
841 y: Schema.Number,
842 width: Schema.Number,
843 height: Schema.Number,
844});
845
846export interface PreviewAnnotationPoint {
847 x: number;
848 y: number;
849}
850
851export const PreviewAnnotationPointSchema: Schema.Codec<PreviewAnnotationPoint> = Schema.Struct({
852 x: Schema.Number,
853 y: Schema.Number,
854});
855
856export interface PreviewAnnotationElementTarget {
857 id: string;
858 element: PickedElementPayload;
859 rect: PreviewAnnotationRect;
860}
861
862export const PreviewAnnotationElementTargetSchema: Schema.Codec<PreviewAnnotationElementTarget> =
863 Schema.Struct({
864 id: Schema.String,
865 element: PickedElementPayloadSchema,
866 rect: PreviewAnnotationRectSchema,
867 });
868
869export interface PreviewAnnotationRegionTarget {
870 id: string;
871 rect: PreviewAnnotationRect;
872}
873
874export const PreviewAnnotationRegionTargetSchema: Schema.Codec<PreviewAnnotationRegionTarget> =
875 Schema.Struct({
876 id: Schema.String,
877 rect: PreviewAnnotationRectSchema,
878 });
879
880export interface PreviewAnnotationStrokeTarget {
881 id: string;
882 color: string;
883 width: number;
884 points: ReadonlyArray<PreviewAnnotationPoint>;
885 bounds: PreviewAnnotationRect;
886}
887
888export const PreviewAnnotationStrokeTargetSchema: Schema.Codec<PreviewAnnotationStrokeTarget> =
889 Schema.Struct({
890 id: Schema.String,
891 color: Schema.String,
892 width: Schema.Number,
893 points: Schema.Array(PreviewAnnotationPointSchema),
894 bounds: PreviewAnnotationRectSchema,
895 });
896
897export interface PreviewAnnotationStyleChange {
898 targetId: string;
899 selector: string | null;
900 property: string;
901 previousValue: string;
902 value: string;
903}
904
905export const PreviewAnnotationStyleChangeSchema: Schema.Codec<PreviewAnnotationStyleChange> =
906 Schema.Struct({
907 targetId: Schema.String,
908 selector: Schema.NullOr(Schema.String),
909 property: Schema.String,
910 previousValue: Schema.String,
911 value: Schema.String,
912 });
913
914export interface PreviewAnnotationScreenshot {
915 dataUrl: string;
916 width: number;
917 height: number;
918 cropRect: PreviewAnnotationRect;
919}
920
921export const PreviewAnnotationScreenshotSchema: Schema.Codec<PreviewAnnotationScreenshot> =
922 Schema.Struct({
923 dataUrl: Schema.String,
924 width: Schema.Number,
925 height: Schema.Number,
926 cropRect: PreviewAnnotationRectSchema,
927 });
928
929export interface PreviewAnnotationPayload {
930 id: string;
931 pageUrl: string;
932 pageTitle: string | null;
933 comment: string;
934 elements: ReadonlyArray<PreviewAnnotationElementTarget>;
935 regions: ReadonlyArray<PreviewAnnotationRegionTarget>;
936 strokes: ReadonlyArray<PreviewAnnotationStrokeTarget>;
937 styleChanges: ReadonlyArray<PreviewAnnotationStyleChange>;
938 screenshot: PreviewAnnotationScreenshot | null;
939 createdAt: string;
940}
941
942export const PreviewAnnotationPayloadSchema: Schema.Codec<PreviewAnnotationPayload> = Schema.Struct(
943 {
944 id: Schema.String,
945 pageUrl: Schema.String,
946 pageTitle: Schema.NullOr(Schema.String),
947 comment: Schema.String,
948 elements: Schema.Array(PreviewAnnotationElementTargetSchema),
949 regions: Schema.Array(PreviewAnnotationRegionTargetSchema),
950 strokes: Schema.Array(PreviewAnnotationStrokeTargetSchema),
951 styleChanges: Schema.Array(PreviewAnnotationStyleChangeSchema),
952 screenshot: Schema.NullOr(PreviewAnnotationScreenshotSchema),
953 createdAt: Schema.String,
954 },
955);
956
957export type PreviewAnnotationSubmission = "attach" | "send";
958export const PreviewAnnotationSubmissionSchema: Schema.Codec<PreviewAnnotationSubmission> =
959 Schema.Literals(["attach", "send"]);
960
961export interface PreviewAnnotationSubmissionResult {
962 annotation: PreviewAnnotationPayload;
963 submission: PreviewAnnotationSubmission;
964 screenshotFailed?: boolean;
965}
966export const PreviewAnnotationSubmissionResultSchema: Schema.Codec<PreviewAnnotationSubmissionResult> =
967 Schema.Struct({
968 annotation: PreviewAnnotationPayloadSchema,
969 submission: PreviewAnnotationSubmissionSchema,
970 screenshotFailed: Schema.optionalKey(Schema.Boolean),
971 });
972
973export const DesktopPreviewTabInputSchema = Schema.Struct({
974 tabId: DesktopPreviewTabIdSchema,
975});
976
977/** Apply zoom and color scheme at creation to avoid flashing browser defaults. */
978export const DesktopPreviewCreateTabInputSchema = Schema.Struct({
979 tabId: DesktopPreviewTabIdSchema,
980 zoomFactor: Schema.optional(Schema.Number.check(Schema.isGreaterThan(0))),
981 colorScheme: Schema.optional(DesktopPreviewColorSchemeSchema),
982 serverTab: Schema.optional(
983 Schema.Struct({ threadId: TrimmedNonEmptyString, tabId: TrimmedNonEmptyString }),
984 ),
985});
986
987export interface DesktopPreviewTabDefaults {
988 readonly zoomFactor?: number | undefined;
989 readonly colorScheme?: DesktopPreviewColorScheme | undefined;
990 readonly serverTab?: { readonly threadId: string; readonly tabId: string } | undefined;
991}
992
993export const DesktopPreviewRegisterWebviewInputSchema = Schema.Struct({
994 tabId: DesktopPreviewTabIdSchema,
995 webContentsId: Schema.Int.check(Schema.isGreaterThan(0)),
996});
997
998export const DesktopPreviewNavigateInputSchema = Schema.Struct({
999 tabId: DesktopPreviewTabIdSchema,
1000 url: Schema.String,
1001});
1002
1003export const DesktopPreviewConfigInputSchema = Schema.Struct({
1004 environmentId: EnvironmentId,
1005 /** Main must derive the partition to ensure its session has UA rewrites and permission handlers. */
1006 profileId: Schema.optional(BrowserProfileId),
1007 /** Carry the partition's loopback traffic to the environment instead of this machine. */
1008 tunnelLoopback: Schema.optional(Schema.Boolean),
1009});
1010
1011export interface DesktopPreviewTunnelAccessRequest {
1012 readonly requestId: string;
1013 readonly environmentId: EnvironmentId;
1014}
1015
1016export const DesktopPreviewTunnelAccessResolutionInputSchema = Schema.Struct({
1017 requestId: Schema.String,
1018 /** The environment's tunnel WebSocket URL with its ticket, or null when it cannot be reached. */
1019 url: Schema.NullOr(Schema.String),
1020});
1021
1022/** A loopback port of another environment, reachable on this machine's 127.0.0.1. */
1023export const DesktopPortForwardSchema = Schema.Struct({
1024 environmentId: EnvironmentId,
1025 remotePort: PortSchema,
1026 /** The same as `remotePort` unless that port was taken here. */
1027 localPort: PortSchema,
1028});
1029export type DesktopPortForward = typeof DesktopPortForwardSchema.Type;
1030
1031export const DesktopSharesLoopbackInputSchema = Schema.Struct({ environmentId: EnvironmentId });
1032
1033export const DesktopPortForwardInputSchema = Schema.Struct({
1034 environmentId: EnvironmentId,
1035 remotePort: PortSchema,
1036});
1037
1038export const DesktopPreviewClearDataInputSchema = Schema.Struct({
1039 environmentId: EnvironmentId,
1040 /** Omit to clear every profile; otherwise only this profile's partition. */
1041 profileId: Schema.optional(BrowserProfileId),
1042});
1043
1044export const DesktopPreviewSetColorSchemeInputSchema = Schema.Struct({
1045 tabId: DesktopPreviewTabIdSchema,
1046 colorScheme: DesktopPreviewColorSchemeSchema,
1047});
1048
1049export const DesktopPreviewSetZoomFactorInputSchema = Schema.Struct({
1050 tabId: DesktopPreviewTabIdSchema,
1051 zoomFactor: Schema.Number.check(Schema.isGreaterThan(0)),
1052});
1053
1054export const DesktopPreviewFindInPageInputSchema = Schema.Struct({
1055 tabId: DesktopPreviewTabIdSchema,
1056 text: Schema.NonEmptyString.check(Schema.isMaxLength(1000)),
1057 forward: Schema.Boolean,
1058 newSession: Schema.Boolean,
1059});
1060
1061export const DesktopPreviewSetAudioMutedInputSchema = Schema.Struct({
1062 tabId: DesktopPreviewTabIdSchema,
1063 audioMuted: Schema.Boolean,
1064});
1065
1066export const DesktopPreviewSetShownInputSchema = Schema.Struct({
1067 tabId: DesktopPreviewTabIdSchema,
1068 shown: Schema.Boolean,
1069});
1070
1071export const DesktopPreviewSetCaptureDrawnInputSchema = Schema.Struct({
1072 tabId: DesktopPreviewTabIdSchema,
1073 drawn: Schema.Boolean,
1074});
1075
1076export const DesktopPreviewAnnotationThemeInputSchema = Schema.Struct({
1077 theme: DesktopPreviewAnnotationThemeSchema,
1078});
1079
1080export const DesktopPreviewAnnotationSendEnabledInputSchema = Schema.Struct({
1081 tabId: DesktopPreviewTabIdSchema,
1082 enabled: Schema.Boolean,
1083});
1084
1085export const DesktopPreviewArtifactInputSchema = Schema.Struct({
1086 path: Schema.String.check(Schema.isTrimmed()).check(Schema.isNonEmpty()),
1087});
1088
1089export const DesktopPreviewReadArtifactInputSchema = Schema.Struct({
1090 artifactId: Schema.String.check(Schema.isTrimmed()).check(Schema.isNonEmpty()),
1091 maxBytes: Schema.Int.check(Schema.isGreaterThan(0)),
1092});
1093
1094export const DesktopPreviewRecordingSaveInputSchema = Schema.Struct({
1095 tabId: DesktopPreviewTabIdSchema,
1096 mimeType: Schema.String.check(Schema.isTrimmed()).check(Schema.isNonEmpty()),
1097 data: Schema.Uint8Array,
1098});
1099
1100export const DesktopMediaReadSchema = Schema.Struct({
1101 status: Schema.Number,
1102 mimeType: Schema.String,
1103 data: Schema.Uint8Array,
1104});
1105export type DesktopMediaRead = typeof DesktopMediaReadSchema.Type;
1106
1107/** `value` is the resolved locale from `prepare` and the transcript from `transcribe`. */
1108export const DesktopAppleSpeechResultSchema = Schema.Union([
1109 Schema.Struct({ ok: Schema.Literal(true), value: Schema.String }),
1110 Schema.Struct({
1111 ok: Schema.Literal(false),
1112 code: Schema.Literals(["unavailable", "unsupported-locale", "failed"]),
1113 }),
1114]);
1115export type DesktopAppleSpeechResult = typeof DesktopAppleSpeechResultSchema.Type;
1116
1117export const DesktopAppleSpeechTranscribeInputSchema = Schema.Struct({
1118 locale: Schema.String.check(Schema.isMaxLength(64)),
1119 // 16 kHz mono Float32 PCM, at most five minutes.
1120 pcm: Schema.Uint8Array,
1121});
1122
1123export const SystemSettingsPaneSchema = Schema.Literals(["full-disk-access"]);
1124export type SystemSettingsPane = typeof SystemSettingsPaneSchema.Type;
1125
1126export interface DesktopBridge {
1127 getAppBranding: () => DesktopAppBranding | null;
1128 getDatabaseMigrationProgress?: () => Promise<DatabaseMigrationProgress | null>;
1129 /** `null` until the desktop host has read the login shell's environment; ask again later. */
1130 getRelayTelemetryEnabled: () => boolean | null;
1131 getPathForFile: (file: File) => string;
1132 getClientPlatform: () => string;
1133 restartAudioService?: () => Promise<boolean>;
1134 setNotificationBadge: (badge: { count: number; image: string | null }) => Promise<void>;
1135 onNotificationBadgeClear: (listener: () => void) => () => void;
1136 onTrackpadScrollBegin: (listener: () => void) => () => void;
1137 onTrackpadScrollEnd: (listener: () => void) => () => void;
1138 /**
1139 * Renderer `window.focus()` cannot raise an Electron window, and on Wayland
1140 * only the main process can spend a notification click's activation token.
1141 */
1142 revealWindow: () => Promise<void>;
1143 /**
1144 * The OS locale as a BCP-47 tag, which the renderer cannot read for itself:
1145 * the packaged app ships only the `en-US` Chromium locale pak, so
1146 * `navigator.language` and the default `Intl` locale are pinned to `en-US`
1147 * regardless of OS settings.
1148 */
1149 getSystemLocale: () => string | null;
1150 /** The OS's preferred languages, most preferred first; `navigator.languages` is pinned like the locale. */
1151 getPreferredSystemLanguages: () => readonly string[];
1152 /** False when the OS turned off middle-click PRIMARY paste (`gtk-enable-primary-paste`). */
1153 getPrimaryPasteEnabled?: () => boolean;
1154 getLocalEnvironmentBootstraps: () => readonly DesktopEnvironmentBootstrap[];
1155 getLocalEnvironmentEnabled: () => boolean;
1156 setLocalEnvironmentEnabled: (enabled: boolean) => Promise<void>;
1157 /** The environment ID recorded in this app's T3 home, such as its own machine's background service. */
1158 getHostEnvironmentId?: () => Promise<string | null>;
1159 getLocalEnvironmentBearerToken: () => Promise<string>;
1160 getClientSettings: () => Promise<ClientSettings | null>;
1161 setClientSettings: (settings: ClientSettings) => Promise<void>;
1162 getConnectionCatalog: () => Promise<string | null>;
1163 setConnectionCatalog: (catalog: string, sshTunnelClaim?: string) => Promise<boolean>;
1164 discoverSshHosts: () => Promise<readonly DesktopDiscoveredSshHost[]>;
1165 resolveSshHost: (alias: string) => Promise<DesktopSshEnvironmentTarget>;
1166 requestSnapShotPermissions: (includeAccessibility: boolean) => Promise<void>;
1167 getSnapShotState: () => Promise<DesktopSnapShotState>;
1168 setupSnapShot: (action: DesktopSnapShotSetupAction) => Promise<void>;
1169 previewSnapShotConfig: (
1170 request: DesktopCaptureConfigRequest,
1171 ) => Promise<DesktopCaptureConfigPreview | null>;
1172 applySnapShotConfig: (previewId: string) => Promise<DesktopCaptureConfigApplied>;
1173 checkSnapShotShortcut: (
1174 shortcut: SnapShotShortcut,
1175 ) => Promise<DesktopSnapShotShortcutAvailability>;
1176 setSnapShotShortcutSuppressed: (suppressed: boolean) => Promise<void>;
1177 listPendingSnapShots: () => Promise<readonly DesktopPendingSnapShot[]>;
1178 readSnapShot: (id: string) => Promise<DesktopSnapShot>;
1179 setSnapShotAnimationDestination: (
1180 destination: DesktopSnapShotAnimationDestination,
1181 ) => Promise<void>;
1182 dismissSnapShotAnimation: (id: DesktopSnapShotId) => Promise<void>;
1183 acknowledgeSnapShot: (id: string) => Promise<void>;
1184 ensureSshEnvironment: (
1185 target: DesktopSshEnvironmentTarget,
1186 options?: DesktopSshEnvironmentEnsureOptions,
1187 ) => Promise<DesktopSshEnvironmentBootstrap>;
1188 releaseSshTunnelClaim: (claim: string) => Promise<void>;
1189 disconnectSshEnvironment: (target: DesktopSshEnvironmentTarget) => Promise<void>;
1190 fetchSshEnvironmentDescriptor: (httpBaseUrl: string) => Promise<ExecutionEnvironmentDescriptor>;
1191 bootstrapSshBearerSession: (
1192 httpBaseUrl: string,
1193 credential: string,
1194 ) => Promise<AuthAccessTokenResult>;
1195 fetchSshSessionState: (httpBaseUrl: string, bearerToken: string) => Promise<AuthSessionState>;
1196 onSshPasswordPrompt: (listener: (request: DesktopSshPasswordPromptRequest) => void) => () => void;
1197 /** Fires with a prompt's request id once it is answered, cancelled, expired or abandoned. */
1198 onSshPasswordPromptSettled: (listener: (requestId: string) => void) => () => void;
1199 resolveSshPasswordPrompt: (requestId: string, password: string | null) => Promise<void>;
1200 getServerExposureState: () => Promise<DesktopServerExposureState>;
1201 setServerExposureMode: (mode: DesktopServerExposureMode) => Promise<DesktopServerExposureState>;
1202 setTailscaleServeEnabled: (input: {
1203 readonly enabled: boolean;
1204 readonly port?: number;
1205 }) => Promise<DesktopServerExposureState>;
1206 getAdvertisedEndpoints: () => Promise<readonly AdvertisedEndpoint[]>;
1207 getWslState: () => Promise<DesktopWslState>;
1208 setWslBackendEnabled: (enabled: boolean) => Promise<DesktopWslState>;
1209 setWslDistro: (distro: string | null) => Promise<DesktopWslState>;
1210 setWslOnly: (enabled: boolean) => Promise<DesktopWslState>;
1211 pickFolder: (options?: PickFolderOptions) => Promise<string | null>;
1212 /** Maps a Windows path to the one a local backend (`primary` or `wsl:…`) sees; null when it cannot. */
1213 toLocalBackendPath: (backendId: string, windowsPath: string) => Promise<string | null>;
1214 pickProjectFavicon: (initialPath?: string) => Promise<string | null>;
1215 pickThemeFiles: () => Promise<readonly PickedThemeFile[] | null>;
1216 setTheme: (theme: DesktopTheme) => Promise<void>;
1217 showContextMenu: <T extends string>(
1218 items: readonly ContextMenuItem<T>[],
1219 position?: { x: number; y: number },
1220 source?: ContextMenuSource,
1221 ) => Promise<T | null>;
1222 receiveProviderAuthCallback: (authorizationUrl: string) => Promise<string>;
1223 cancelProviderAuthCallback: (authorizationUrl: string) => Promise<void>;
1224 startFileDrag: (input: { environmentId: EnvironmentId; path: string }) => Promise<boolean>;
1225 openExternal: (url: string) => Promise<boolean>;
1226 /** Reads http(s) media in the main process, outside renderer CORS and CSP; null on network failure. */
1227 readMedia: (url: string) => Promise<DesktopMediaRead | null>;
1228 openSystemSettings: (pane: SystemSettingsPane) => Promise<boolean>;
1229 checkSystemPermission: (pane: SystemSettingsPane) => Promise<boolean>;
1230 probeRemoteEditors: () => Promise<readonly EditorId[]>;
1231 pasteAsText: () => Promise<void>;
1232 onMenuAction: (listener: (action: string) => void) => () => void;
1233 onSnapShotEvent: (listener: (event: DesktopSnapShotEvent) => void) => () => void;
1234 onQuitShortcut: (listener: (event: QuitShortcutHintEvent) => void) => () => void;
1235 getWindowFullscreenState: () => boolean;
1236 onWindowFullscreenStateChange: (listener: (fullscreen: boolean) => void) => () => void;
1237 getWindowZoomFactor: () => number;
1238 getUpdateState: () => Promise<DesktopUpdateState>;
1239 /** `minimumVersion` is a track switch's checked release; nothing older is offered after. */
1240 setUpdateChannel: (
1241 channel: DesktopUpdateChannel,
1242 minimumVersion?: string,
1243 ) => Promise<DesktopUpdateState>;
1244 checkForUpdate: () => Promise<DesktopUpdateCheckResult>;
1245 downloadUpdate: () => Promise<DesktopUpdateActionResult>;
1246 /** With a version, installs only that downloaded build. */
1247 installUpdate: (expectedVersion?: string) => Promise<DesktopUpdateActionResult>;
1248 onUpdateState: (listener: (state: DesktopUpdateState) => void) => () => void;
1249 cliCommand: {
1250 getState: () => Promise<DesktopCliCommandState>;
1251 install: () => Promise<DesktopCliCommandState>;
1252 uninstall: () => Promise<DesktopCliCommandState>;
1253 addToPath: () => Promise<DesktopCliCommandState>;
1254 };
1255 webLinks: {
1256 setReady: (ready: boolean) => Promise<void>;
1257 onOpen: (listener: (url: string) => void) => () => void;
1258 };
1259 appActivation: {
1260 setReady: (ready: boolean) => Promise<void>;
1261 complete: (response: DesktopAppActivationResponse) => Promise<void>;
1262 onRequest: (listener: (request: DesktopAppActivationRequest) => void) => () => void;
1263 };
1264 preview: DesktopPreviewBridge;
1265 /** On-device dictation through macOS 26 SpeechAnalyzer; absent in older desktop builds. */
1266 appleSpeech?: {
1267 supportedLocales: () => Promise<readonly string[]>;
1268 prepare: (locale: string) => Promise<DesktopAppleSpeechResult>;
1269 transcribe: (input: { locale: string; pcm: Uint8Array }) => Promise<DesktopAppleSpeechResult>;
1270 };
1271}
1272
1273/** Renderer callback invoked by Electron with a fresh user gesture before display-media capture. */
1274export const DESKTOP_PREVIEW_RECORDING_CAPTURE_TRIGGER = "__t3DesktopPreviewRecordingCapture";
1275
1276/**
1277 * Dictation for the annotation editor drawn inside a preview guest. The guest only shows
1278 * controls and forwards trusted user gestures; the renderer records, with its consent
1279 * checks, and publishes state back. `shortcuts` are the dictation chords in effect.
1280 */
1281export const DesktopPreviewAnnotationVoiceConfigSchema = Schema.Struct({
1282 sessionId: Schema.String.check(Schema.isMaxLength(64)),
1283 shortcuts: Schema.Array(KeybindingShortcut).check(Schema.isMaxLength(16)),
1284});
1285export type DesktopPreviewAnnotationVoiceConfig =
1286 typeof DesktopPreviewAnnotationVoiceConfigSchema.Type;
1287
1288export const DesktopPreviewAnnotationVoiceEventSchema = Schema.Struct({
1289 sessionId: Schema.String.check(Schema.isMaxLength(64)),
1290 text: Schema.String.check(Schema.isMaxLength(100_000)),
1291 cursor: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
1292 selectionEnd: Schema.optional(Schema.Int.check(Schema.isGreaterThanOrEqualTo(0))),
1293 action: Schema.Literals([
1294 "sync",
1295 "start",
1296 "stop",
1297 "cancel",
1298 "skip",
1299 "settings",
1300 "key",
1301 "focus",
1302 "blur",
1303 ]),
1304 keyboard: Schema.optional(
1305 Schema.Struct({
1306 type: Schema.Literals(["keydown", "keyup"]),
1307 key: Schema.String.check(Schema.isMaxLength(32)),
1308 code: Schema.String.check(Schema.isMaxLength(64)),
1309 metaKey: Schema.Boolean,
1310 ctrlKey: Schema.Boolean,
1311 shiftKey: Schema.Boolean,
1312 altKey: Schema.Boolean,
1313 repeat: Schema.Boolean,
1314 }),
1315 ),
1316});
1317export type DesktopPreviewAnnotationVoiceEvent =
1318 typeof DesktopPreviewAnnotationVoiceEventSchema.Type;
1319
1320export const DesktopPreviewAnnotationVoiceStateSchema = Schema.Struct({
1321 tabId: DesktopPreviewTabIdSchema,
1322 sessionId: Schema.String.check(Schema.isMaxLength(64)),
1323 available: Schema.Boolean,
1324 phase: Schema.Literals([
1325 "idle",
1326 "preparing",
1327 "recording",
1328 "transcribing",
1329 "post-processing",
1330 "error",
1331 ]),
1332 status: Schema.NullOr(Schema.String),
1333 errorAction: Schema.NullOr(Schema.Literals(["retry", "settings"])),
1334 preview: Schema.NullOr(Schema.String),
1335 level: Schema.Number,
1336 shortcutLabel: Schema.NullOr(Schema.String),
1337 freezesEditor: Schema.Boolean,
1338 blocksSubmission: Schema.Boolean,
1339 draft: Schema.NullOr(Schema.Struct({ text: Schema.String, cursor: Schema.Int })),
1340});
1341export type DesktopPreviewAnnotationVoiceState =
1342 typeof DesktopPreviewAnnotationVoiceStateSchema.Type;
1343
1344export const DesktopPreviewPickElementInputSchema = Schema.Struct({
1345 tabId: DesktopPreviewTabIdSchema,
1346 voice: Schema.optional(DesktopPreviewAnnotationVoiceConfigSchema),
1347});
1348
1349export interface DesktopPreviewBridge {
1350 setForwardedShortcuts: (shortcuts: ReadonlyArray<PreviewForwardedShortcut>) => Promise<void>;
1351 createTab: (tabId: string, defaults?: DesktopPreviewTabDefaults) => Promise<void>;
1352 closeTab: (tabId: string) => Promise<void>;
1353 registerWebview: (tabId: string, webContentsId: number) => Promise<void>;
1354 navigate: (tabId: string, url: string) => Promise<void>;
1355 goBack: (tabId: string) => Promise<void>;
1356 goForward: (tabId: string) => Promise<void>;
1357 refresh: (tabId: string) => Promise<void>;
1358 stopLoading: (tabId: string) => Promise<void>;
1359 zoomIn: (tabId: string) => Promise<void>;
1360 zoomOut: (tabId: string) => Promise<void>;
1361 resetZoom: (tabId: string) => Promise<void>;
1362 setZoomFactor: (tabId: string, zoomFactor: number) => Promise<void>;
1363 hardReload: (tabId: string) => Promise<void>;
1364 setColorScheme: (tabId: string, colorScheme: DesktopPreviewColorScheme) => Promise<void>;
1365 setAudioMuted: (tabId: string, audioMuted: boolean) => Promise<void>;
1366 findInPage: (
1367 tabId: string,
1368 text: string,
1369 options: { forward: boolean; newSession: boolean },
1370 ) => Promise<void>;
1371 stopFindInPage: (tabId: string) => Promise<void>;
1372 /** Tells the tab's server whether its webview is on screen. */
1373 setShown: (tabId: string, shown: boolean) => Promise<void>;
1374 /** Tells the tab's server whether its webview is drawn at full detail for a capture. */
1375 setCaptureDrawn: (tabId: string, drawn: boolean) => Promise<void>;
1376 openDevTools: (tabId: string) => Promise<void>;
1377 clearCookies: (environmentId: EnvironmentId, profileId?: string) => Promise<void>;
1378 clearCache: (environmentId: EnvironmentId, profileId?: string) => Promise<void>;
1379 getPreviewConfig: (
1380 environmentId: EnvironmentId,
1381 profileId?: string,
1382 tunnelLoopback?: boolean,
1383 ) => Promise<DesktopPreviewWebviewConfig>;
1384 /** Main asks for an environment's tunnel URL once per connection a tunnelled page opens. */
1385 onTunnelAccessRequest: (
1386 listener: (request: DesktopPreviewTunnelAccessRequest) => void,
1387 ) => () => void;
1388 resolveTunnelAccess: (requestId: string, url: string | null) => Promise<void>;
1389 /** Forwards an environment's loopback port to this machine until stopped or the app quits. */
1390 forwardPort: (environmentId: EnvironmentId, remotePort: number) => Promise<DesktopPortForward>;
1391 stopPortForward: (environmentId: EnvironmentId, remotePort: number) => Promise<void>;
1392 listPortForwards: () => Promise<ReadonlyArray<DesktopPortForward>>;
1393 /** Whether the environment runs on this machine, where its ports need no forward. */
1394 sharesLoopback: (environmentId: EnvironmentId) => Promise<boolean>;
1395 onPortForwards: (listener: (forwards: ReadonlyArray<DesktopPortForward>) => void) => () => void;
1396 listBrowserImportSources: () => Promise<ReadonlyArray<BrowserImportSource>>;
1397 importBrowserCookies: (input: {
1398 readonly environmentId: EnvironmentId;
1399 readonly sourceId: BrowserImportSourceId;
1400 readonly sourceProfileDirectory: string;
1401 readonly targetProfileId: string;
1402 }) => Promise<BrowserImportResult>;
1403 setAnnotationTheme: (theme: DesktopPreviewAnnotationTheme) => Promise<void>;
1404 setAnnotationSendEnabled: (tabId: string, enabled: boolean) => Promise<void>;
1405 annotationVoice: {
1406 onEvent: (
1407 listener: (tabId: string, event: DesktopPreviewAnnotationVoiceEvent) => void,
1408 ) => () => void;
1409 update: (state: DesktopPreviewAnnotationVoiceState) => Promise<void>;
1410 };
1411 /** Resolves with the annotation and attach/send intent, or null on cancellation. Rejects if activation fails. */
1412 pickElement: (
1413 tabId: string,
1414 voice?: DesktopPreviewAnnotationVoiceConfig,
1415 ) => Promise<PreviewAnnotationSubmissionResult | null>;
1416 cancelPickElement: (tabId: string) => Promise<void>;
1417 captureScreenshot: (
1418 tabId: string,
1419 ) => Promise<DesktopPreviewScreenshotArtifact | PreviewCaptureFailureEncoded>;
1420 revealArtifact: (path: string) => Promise<void>;
1421 copyArtifactToClipboard: (path: string) => Promise<void>;
1422 /** Reads a capture this app saved, by its artifact id; rejects files over `maxBytes`. */
1423 readArtifact: (artifactId: string, maxBytes: number) => Promise<Uint8Array>;
1424 pictureInPicture: {
1425 open: (tabId: string) => Promise<void>;
1426 close: (tabId: string) => Promise<void>;
1427 };
1428 recording: {
1429 onInput: (listener: (event: DesktopPreviewRecordingInputEvent) => void) => () => void;
1430 startScreencast: (tabId: string) => Promise<void | PreviewCaptureFailureEncoded>;
1431 stopScreencast: (tabId: string) => Promise<void>;
1432 save: (
1433 tabId: string,
1434 mimeType: string,
1435 data: Uint8Array,
1436 ) => Promise<DesktopPreviewRecordingArtifact>;
1437 };
1438 onStateChange: (listener: (tabId: string, state: DesktopPreviewTabState) => void) => () => void;
1439 onPointerEvent: (listener: (event: DesktopPreviewPointerEvent) => void) => () => void;
1440 onOpenLink: (listener: (event: DesktopPreviewOpenLinkEvent) => void) => () => void;
1441 onFindResult: (listener: (event: DesktopPreviewFindResultEvent) => void) => () => void;
1442}
1443
1444export type ConfirmDialogVariant = "default" | "destructive";
1445
1446export interface ConfirmDialogOptions {
1447 readonly variant?: ConfirmDialogVariant;
1448 /** Which button takes focus on open. Defaults to Cancel; destructive confirms always keep Cancel. */
1449 readonly initialFocus?: "confirm" | "cancel";
1450}
1451
1452export interface LocalApi {
1453 dialogs: {
1454 pickFolder: (options?: PickFolderOptions) => Promise<string | null>;
1455 confirm: (message: string, options?: ConfirmDialogOptions) => Promise<boolean>;
1456 };
1457 shell: {
1458 openExternal: (url: string) => Promise<void>;
1459 openSystemSettings: (pane: SystemSettingsPane) => Promise<void>;
1460 };
1461 contextMenu: {
1462 show: <T extends string>(
1463 items: readonly ContextMenuItem<T>[],
1464 position?: { x: number; y: number },
1465 source?: ContextMenuSource,
1466 ) => Promise<T | null>;
1467 close: () => Promise<void>;
1468 };
1469 persistence: {
1470 getClientSettings: () => Promise<ClientSettings | null>;
1471 setClientSettings: (settings: ClientSettings) => Promise<void>;
1472 };
1473}