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