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