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