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

ipc.ts

1,408 lines48.1 KB

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