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

ipc.ts

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