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

ipc.ts

1,421 lines48.5 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 DesktopPreviewRecordingSource {
738 sourceId: string;
739 width: number;
740 height: number;
742​
743export const DesktopPreviewRecordingSourceSchema: Schema.Codec<DesktopPreviewRecordingSource> =
744 Schema.Struct({
745 sourceId: Schema.String,
746 width: Schema.Int.check(Schema.isGreaterThan(0)),
747 height: Schema.Int.check(Schema.isGreaterThan(0)),
748 });
749​
750export interface DesktopPreviewRecordingArtifact {
751 id: string;
752 tabId: string;
753 path: string;
754 mimeType: string;
755 sizeBytes: number;
756 createdAt: string;
758​
759export const DesktopPreviewRecordingArtifactSchema: Schema.Codec<DesktopPreviewRecordingArtifact> =
760 Schema.Struct({
761 id: Schema.String,
762 tabId: DesktopPreviewTabIdSchema,
763 path: Schema.String,
764 mimeType: Schema.String,
765 sizeBytes: Schema.Int,
766 createdAt: Schema.String,
767 });
768​
769export interface DesktopPreviewScreenshotArtifact {
770 id: string;
771 tabId: string;
772 path: string;
773 mimeType: "image/png";
774 sizeBytes: number;
775 createdAt: string;
777​
778export const DesktopPreviewScreenshotArtifactSchema: Schema.Codec<DesktopPreviewScreenshotArtifact> =
779 Schema.Struct({
780 id: Schema.String,
781 tabId: DesktopPreviewTabIdSchema,
782 path: Schema.String,
783 mimeType: Schema.Literal("image/png"),
784 sizeBytes: Schema.Int,
785 createdAt: Schema.String,
786 });
787​
788/**
789 * Single stack frame captured by react-grab's `getElementContext`. We surface
790 * the source file/line so coding agents can jump straight to the JSX that
791 * produced the picked DOM node.
792 */
793export interface PickedElementStackFrame {
794 functionName: string | null;
795 fileName: string | null;
796 lineNumber: number | null;
797 columnNumber: number | null;
799​
800export const PickedElementStackFrameSchema: Schema.Codec<PickedElementStackFrame> = Schema.Struct({
801 functionName: Schema.NullOr(Schema.String),
802 fileName: Schema.NullOr(Schema.String),
803 lineNumber: Schema.NullOr(Schema.Number),
804 columnNumber: Schema.NullOr(Schema.Number),
805});
806​
807/**
808 * A successful element pick from the preview webview. All fields are
809 * best-effort — pages that don't ship a React fiber tree (or aren't running
810 * in dev) will still produce a usable payload (selector + html preview),
811 * just without component / source attribution.
812 */
813export interface PickedElementPayload {
814 /** URL of the page the element was picked on. */
815 pageUrl: string;
816 /** Optional `<title>` of that page (best-effort). */
817 pageTitle: string | null;
818 /** Lowercase tag name, e.g. `"button"`. */
819 tagName: string;
820 /** CSS selector resolving back to the element on a re-render. */
821 selector: string | null;
822 /** Truncated outer-HTML preview (matches react-grab's `htmlPreview`). */
823 htmlPreview: string;
824 /** Nearest React component display name, or null when unavailable. */
825 componentName: string | null;
826 /** First source-mapped stack frame (file + line of the JSX source). */
827 source: PickedElementStackFrame | null;
828 /** Full owner-stack frames; can be empty. Useful for richer context. */
829 stack: ReadonlyArray<PickedElementStackFrame>;
830 /** Author CSS only (UA defaults stripped) — react-grab's `styles`. */
831 styles: string;
832 /** Wall-clock pick time as ISO-8601 string. */
833 pickedAt: string;
835​
836export const PickedElementPayloadSchema: Schema.Codec<PickedElementPayload> = Schema.Struct({
837 pageUrl: Schema.String,
838 pageTitle: Schema.NullOr(Schema.String),
839 tagName: Schema.String,
840 selector: Schema.NullOr(Schema.String),
841 htmlPreview: Schema.String,
842 componentName: Schema.NullOr(Schema.String),
843 source: Schema.NullOr(PickedElementStackFrameSchema),
844 stack: Schema.Array(PickedElementStackFrameSchema),
845 styles: Schema.String,
846 pickedAt: Schema.String,
847});
848​
849export interface PreviewAnnotationRect {
850 x: number;
851 y: number;
852 width: number;
853 height: number;
855​
856export const PreviewAnnotationRectSchema: Schema.Codec<PreviewAnnotationRect> = Schema.Struct({
857 x: Schema.Number,
858 y: Schema.Number,
859 width: Schema.Number,
860 height: Schema.Number,
861});
862​
863export interface PreviewAnnotationPoint {
864 x: number;
865 y: number;
867​
868export const PreviewAnnotationPointSchema: Schema.Codec<PreviewAnnotationPoint> = Schema.Struct({
869 x: Schema.Number,
870 y: Schema.Number,
871});
872​
873export interface PreviewAnnotationElementTarget {
874 id: string;
875 element: PickedElementPayload;
876 rect: PreviewAnnotationRect;
878​
879export const PreviewAnnotationElementTargetSchema: Schema.Codec<PreviewAnnotationElementTarget> =
880 Schema.Struct({
881 id: Schema.String,
882 element: PickedElementPayloadSchema,
883 rect: PreviewAnnotationRectSchema,
884 });
885​
886export interface PreviewAnnotationRegionTarget {
887 id: string;
888 rect: PreviewAnnotationRect;
890​
891export const PreviewAnnotationRegionTargetSchema: Schema.Codec<PreviewAnnotationRegionTarget> =
892 Schema.Struct({
893 id: Schema.String,
894 rect: PreviewAnnotationRectSchema,
895 });
896​
897export interface PreviewAnnotationStrokeTarget {
898 id: string;
899 color: string;
900 width: number;
901 points: ReadonlyArray<PreviewAnnotationPoint>;
902 bounds: PreviewAnnotationRect;
904​
905export const PreviewAnnotationStrokeTargetSchema: Schema.Codec<PreviewAnnotationStrokeTarget> =
906 Schema.Struct({
907 id: Schema.String,
908 color: Schema.String,
909 width: Schema.Number,
910 points: Schema.Array(PreviewAnnotationPointSchema),
911 bounds: PreviewAnnotationRectSchema,
912 });
913​
914export interface PreviewAnnotationStyleChange {
915 targetId: string;
916 selector: string | null;
917 property: string;
918 previousValue: string;
919 value: string;
921​
922export const PreviewAnnotationStyleChangeSchema: Schema.Codec<PreviewAnnotationStyleChange> =
923 Schema.Struct({
924 targetId: Schema.String,
925 selector: Schema.NullOr(Schema.String),
926 property: Schema.String,
927 previousValue: Schema.String,
928 value: Schema.String,
929 });
930​
931export interface PreviewAnnotationScreenshot {
932 dataUrl: string;
933 width: number;
934 height: number;
935 cropRect: PreviewAnnotationRect;
937​
938export const PreviewAnnotationScreenshotSchema: Schema.Codec<PreviewAnnotationScreenshot> =
939 Schema.Struct({
940 dataUrl: Schema.String,
941 width: Schema.Number,
942 height: Schema.Number,
943 cropRect: PreviewAnnotationRectSchema,
944 });
945​
946/**
947 * A submitted preview annotation. One annotation may reference multiple DOM
948 * elements, freeform regions, and ink strokes. The desktop main process adds
949 * the screenshot after the guest preload submits the structured draft.
950 */
951export interface PreviewAnnotationPayload {
952 id: string;
953 pageUrl: string;
954 pageTitle: string | null;
955 comment: string;
956 elements: ReadonlyArray<PreviewAnnotationElementTarget>;
957 regions: ReadonlyArray<PreviewAnnotationRegionTarget>;
958 strokes: ReadonlyArray<PreviewAnnotationStrokeTarget>;
959 styleChanges: ReadonlyArray<PreviewAnnotationStyleChange>;
960 screenshot: PreviewAnnotationScreenshot | null;
961 createdAt: string;
963​
964export const PreviewAnnotationPayloadSchema: Schema.Codec<PreviewAnnotationPayload> = Schema.Struct(
965 {
966 id: Schema.String,
967 pageUrl: Schema.String,
968 pageTitle: Schema.NullOr(Schema.String),
969 comment: Schema.String,
970 elements: Schema.Array(PreviewAnnotationElementTargetSchema),
971 regions: Schema.Array(PreviewAnnotationRegionTargetSchema),
972 strokes: Schema.Array(PreviewAnnotationStrokeTargetSchema),
973 styleChanges: Schema.Array(PreviewAnnotationStyleChangeSchema),
974 screenshot: Schema.NullOr(PreviewAnnotationScreenshotSchema),
975 createdAt: Schema.String,
976 },
977);
978​
979export type PreviewAnnotationSubmission = "attach" | "send";
980export const PreviewAnnotationSubmissionSchema: Schema.Codec<PreviewAnnotationSubmission> =
981 Schema.Literals(["attach", "send"]);
982​
983export interface PreviewAnnotationSubmissionResult {
984 annotation: PreviewAnnotationPayload;
985 submission: PreviewAnnotationSubmission;
987export const PreviewAnnotationSubmissionResultSchema: Schema.Codec<PreviewAnnotationSubmissionResult> =
988 Schema.Struct({
989 annotation: PreviewAnnotationPayloadSchema,
990 submission: PreviewAnnotationSubmissionSchema,
991 });
992​
993export const DesktopPreviewTabInputSchema = Schema.Struct({
994 tabId: DesktopPreviewTabIdSchema,
995});
996​
997/**
998 * Tab creation carries the client's configured browser defaults so the guest
999 * is born already zoomed and color-scheme-emulated. Applying them after
1000 * creation instead would paint one frame at 100%/system first, which reads as
1001 * a flash on every tab open. Both fields are optional so an older renderer
1002 * still gets the historical defaults.
1003 */
1004export const DesktopPreviewCreateTabInputSchema = Schema.Struct({
1005 tabId: DesktopPreviewTabIdSchema,
1006 zoomFactor: Schema.optional(Schema.Number.check(Schema.isGreaterThan(0))),
1007 colorScheme: Schema.optional(DesktopPreviewColorSchemeSchema),
1008});
1009​
1010export interface DesktopPreviewTabDefaults {
1011 readonly zoomFactor?: number | undefined;
1012 readonly colorScheme?: DesktopPreviewColorScheme | undefined;
1014​
1015export const DesktopPreviewRegisterWebviewInputSchema = Schema.Struct({
1016 tabId: DesktopPreviewTabIdSchema,
1017 webContentsId: Schema.Int.check(Schema.isGreaterThan(0)),
1018});
1019​
1020export const DesktopPreviewNavigateInputSchema = Schema.Struct({
1021 tabId: DesktopPreviewTabIdSchema,
1022 url: Schema.String,
1023});
1024​
1025export const DesktopPreviewConfigInputSchema = Schema.Struct({
1026 environmentId: EnvironmentId,
1027});
1028​
1029export const DesktopPreviewSetColorSchemeInputSchema = Schema.Struct({
1030 tabId: DesktopPreviewTabIdSchema,
1031 colorScheme: DesktopPreviewColorSchemeSchema,
1032});
1033​
1034export const DesktopPreviewSetAudioMutedInputSchema = Schema.Struct({
1035 tabId: DesktopPreviewTabIdSchema,
1036 audioMuted: Schema.Boolean,
1037});
1038​
1039export const DesktopPreviewAnnotationThemeInputSchema = Schema.Struct({
1040 theme: DesktopPreviewAnnotationThemeSchema,
1041});
1042​
1043export const DesktopPreviewArtifactInputSchema = Schema.Struct({
1044 path: Schema.String.check(Schema.isTrimmed()).check(Schema.isNonEmpty()),
1045});
1046​
1047export const DesktopPreviewRecordingSaveInputSchema = Schema.Struct({
1048 tabId: DesktopPreviewTabIdSchema,
1049 mimeType: Schema.String.check(Schema.isTrimmed()).check(Schema.isNonEmpty()),
1050 data: Schema.Uint8Array,
1051});
1052​
1053export const DesktopPreviewAutomationClickInputSchema = Schema.Struct({
1054 tabId: DesktopPreviewTabIdSchema,
1055 input: PreviewAutomationClickInput,
1056});
1057​
1058export const DesktopPreviewAutomationTypeInputSchema = Schema.Struct({
1059 tabId: DesktopPreviewTabIdSchema,
1060 input: PreviewAutomationTypeInput,
1061});
1062​
1063export const DesktopPreviewAutomationPressInputSchema = Schema.Struct({
1064 tabId: DesktopPreviewTabIdSchema,
1065 input: PreviewAutomationPressInput,
1066});
1067​
1068export const DesktopPreviewAutomationScrollInputSchema = Schema.Struct({
1069 tabId: DesktopPreviewTabIdSchema,
1070 input: PreviewAutomationScrollInput,
1071});
1072​
1073export const DesktopPreviewAutomationEvaluateInputSchema = Schema.Struct({
1074 tabId: DesktopPreviewTabIdSchema,
1075 input: PreviewAutomationEvaluateInput,
1076});
1077​
1078export const DesktopPreviewAutomationWaitForInputSchema = Schema.Struct({
1079 tabId: DesktopPreviewTabIdSchema,
1080 input: PreviewAutomationWaitForInput,
1081});
1082​
1083export interface DesktopBridge {
1084 getAppBranding: () => DesktopAppBranding | null;
1085 /** The desktop client's OS platform, read from Electron's preload process. */
1086 getClientPlatform?: () => string;
1087 /**
1088 * The OS locale as a BCP-47 tag, which the renderer cannot read for itself:
1089 * the packaged app ships only the `en-US` Chromium locale pak, so
1090 * `navigator.language` and the default `Intl` locale are pinned to `en-US`
1091 * regardless of OS settings.
1092 */
1093 getSystemLocale?: () => string | null;
1094 // One bootstrap per pool instance currently registered with bootstrap
1095 // info (omits instances whose backend hasn't produced a config yet).
1096 // The primary backend is identified by id === PRIMARY_LOCAL_ENVIRONMENT_ID.
1097 getLocalEnvironmentBootstraps: () => readonly DesktopEnvironmentBootstrap[];
1098 getLocalEnvironmentBearerToken: () => Promise<string>;
1099 getClientSettings: () => Promise<ClientSettings | null>;
1100 setClientSettings: (settings: ClientSettings) => Promise<void>;
1101 getConnectionCatalog?: () => Promise<string | null>;
1102 setConnectionCatalog?: (catalog: string) => Promise<boolean>;
1103 clearConnectionCatalog?: () => Promise<void>;
1104 discoverSshHosts: () => Promise<readonly DesktopDiscoveredSshHost[]>;
1105 ensureSshEnvironment: (
1106 target: DesktopSshEnvironmentTarget,
1107 options?: { issuePairingToken?: boolean },
1108 ) => Promise<DesktopSshEnvironmentBootstrap>;
1109 disconnectSshEnvironment: (target: DesktopSshEnvironmentTarget) => Promise<void>;
1110 fetchSshEnvironmentDescriptor: (httpBaseUrl: string) => Promise<ExecutionEnvironmentDescriptor>;
1111 bootstrapSshBearerSession: (
1112 httpBaseUrl: string,
1113 credential: string,
1114 ) => Promise<AuthAccessTokenResult>;
1115 fetchSshSessionState: (httpBaseUrl: string, bearerToken: string) => Promise<AuthSessionState>;
1116 issueSshWebSocketTicket: (
1117 httpBaseUrl: string,
1118 bearerToken: string,
1119 ) => Promise<AuthWebSocketTicketResult>;
1120 onSshPasswordPrompt: (listener: (request: DesktopSshPasswordPromptRequest) => void) => () => void;
1121 resolveSshPasswordPrompt: (requestId: string, password: string | null) => Promise<void>;
1122 getServerExposureState: () => Promise<DesktopServerExposureState>;
1123 setServerExposureMode: (mode: DesktopServerExposureMode) => Promise<DesktopServerExposureState>;
1124 setTailscaleServeEnabled: (input: {
1125 readonly enabled: boolean;
1126 readonly port?: number;
1127 }) => Promise<DesktopServerExposureState>;
1128 getAdvertisedEndpoints: () => Promise<readonly AdvertisedEndpoint[]>;
1129 getWslState: () => Promise<DesktopWslState>;
1130 setWslBackendEnabled: (enabled: boolean) => Promise<DesktopWslState>;
1131 setWslDistro: (distro: string | null) => Promise<DesktopWslState>;
1132 setWslOnly: (enabled: boolean) => Promise<DesktopWslState>;
1133 pickFolder: (options?: PickFolderOptions) => Promise<string | null>;
1134 /** Optional while older desktop shells can host a newer web client. */
1135 pickProjectFavicon?: (initialPath?: string) => Promise<string | null>;
1136 /**
1137 * Multi-select JSON file picker that opens in the VS Code extensions
1138 * directory when one exists. Optional: older desktop builds lack it, and
1139 * web callers fall back to a plain file input.
1140 */
1141 pickThemeFiles?: () => Promise<readonly PickedThemeFile[] | null>;
1142 setTheme: (theme: DesktopTheme) => Promise<void>;
1143 showContextMenu: <T extends string>(
1144 items: readonly ContextMenuItem<T>[],
1145 position?: { x: number; y: number },
1146 ) => Promise<T | null>;
1147 openExternal: (url: string) => Promise<boolean>;
1148 /**
1149 * Probe this desktop machine for installed remote-capable editor CLIs
1150 * (used for remote open-in-editor deep links). Optional: older desktop
1151 * builds lack it; callers fall back to VS Code only.
1152 */
1153 probeRemoteEditors?: () => Promise<readonly EditorId[]>;
1154 onMenuAction: (listener: (action: string) => void) => () => void;
1155 /**
1156 * Hold-to-quit hint pushes: "down" when the quit shortcut is first pressed,
1157 * "up" when it is released before the hold completes. Optional: older
1158 * desktop builds never emit it.
1159 */
1160 onQuitShortcut?: (listener: (state: "down" | "up") => void) => () => void;
1161 getWindowFullscreenState: () => boolean;
1162 onWindowFullscreenStateChange: (listener: (fullscreen: boolean) => void) => () => void;
1163 getUpdateState: () => Promise<DesktopUpdateState>;
1164 setUpdateChannel: (channel: DesktopUpdateChannel) => Promise<DesktopUpdateState>;
1165 checkForUpdate: () => Promise<DesktopUpdateCheckResult>;
1166 downloadUpdate: () => Promise<DesktopUpdateActionResult>;
1167 installUpdate: () => Promise<DesktopUpdateActionResult>;
1168 onUpdateState: (listener: (state: DesktopUpdateState) => void) => () => void;
1169 /**
1170 * Desktop-only preview surface. Present iff the renderer is hosted by the
1171 * Electron desktop build; web builds have `preview === undefined`.
1172 */
1173 preview?: DesktopPreviewBridge;
1175​
1176export interface DesktopPreviewBridge {
1177 createTab: (tabId: string, defaults?: DesktopPreviewTabDefaults) => Promise<void>;
1178 closeTab: (tabId: string) => Promise<void>;
1179 registerWebview: (tabId: string, webContentsId: number) => Promise<void>;
1180 navigate: (tabId: string, url: string) => Promise<void>;
1181 goBack: (tabId: string) => Promise<void>;
1182 goForward: (tabId: string) => Promise<void>;
1183 refresh: (tabId: string) => Promise<void>;
1184 zoomIn: (tabId: string) => Promise<void>;
1185 zoomOut: (tabId: string) => Promise<void>;
1186 resetZoom: (tabId: string) => Promise<void>;
1187 /** Reload bypassing the HTTP cache. */
1188 hardReload: (tabId: string) => Promise<void>;
1189 /**
1190 * Emulate `prefers-color-scheme` on the guest page ("system" clears the
1191 * override). Persists per tab and is re-applied across webview swaps.
1192 */
1193 setColorScheme: (tabId: string, colorScheme: DesktopPreviewColorScheme) => Promise<void>;
1194 /**
1195 * Silence the tab's audio output. Persists per tab and is re-applied across
1196 * webview swaps, but is dropped when the tab closes. Muting a silent tab is
1197 * allowed; it simply takes effect once the page plays something.
1198 */
1199 setAudioMuted: (tabId: string, audioMuted: boolean) => Promise<void>;
1200 /** Open the guest webview's DevTools (detached). */
1201 openDevTools: (tabId: string) => Promise<void>;
1202 /** Drop cookies + storage data for the preview partition (all tabs). */
1203 clearCookies: () => Promise<void>;
1204 /** Drop the HTTP cache for the preview partition (all tabs). */
1205 clearCache: () => Promise<void>;
1206 /**
1207 * One-shot config for mounting a preview `<webview>`. Replaces three
1208 * earlier round-trip calls (`getBrowserPartition`, `getWebviewPreferences`,
1209 * `getPickPreloadPath`) so adding a new field here only requires touching
1210 * the contract + main, not the renderer's mount logic.
1211 */
1212 getPreviewConfig: (environmentId: EnvironmentId) => Promise<DesktopPreviewWebviewConfig>;
1213 setAnnotationTheme: (theme: DesktopPreviewAnnotationTheme) => Promise<void>;
1214 /**
1215 * Activate the in-page element picker for the given tab. Resolves with
1216 * the picked annotation and its attach/send intent, or `null` when the
1217 * user cancels (Escape / nav). The promise rejects if the picker can't be
1218 * activated (no webview, etc.).
1219 */
1220 pickElement: (tabId: string) => Promise<PreviewAnnotationSubmissionResult | null>;
1221 /** Cancel an in-flight preview annotation session. */
1222 cancelPickElement: (tabId: string) => Promise<void>;
1223 captureScreenshot: (tabId: string) => Promise<DesktopPreviewScreenshotArtifact>;
1224 revealArtifact: (path: string) => Promise<void>;
1225 copyArtifactToClipboard: (path: string) => Promise<void>;
1226 pictureInPicture: {
1227 open: (tabId: string) => Promise<void>;
1228 close: (tabId: string) => Promise<void>;
1229 };
1230 recording: {
1231 startScreencast: (tabId: string) => Promise<DesktopPreviewRecordingSource>;
1232 stopScreencast: (tabId: string) => Promise<void>;
1233 save: (
1234 tabId: string,
1235 mimeType: string,
1236 data: Uint8Array,
1237 ) => Promise<DesktopPreviewRecordingArtifact>;
1238 onFrame: (listener: (frame: DesktopPreviewRecordingFrame) => void) => () => void;
1239 };
1240 automation: {
1241 status: (tabId: string) => Promise<DesktopPreviewAutomationStatus>;
1242 snapshot: (tabId: string) => Promise<PreviewAutomationSnapshot>;
1243 click: (tabId: string, input: PreviewAutomationClickInput) => Promise<void>;
1244 type: (tabId: string, input: PreviewAutomationTypeInput) => Promise<void>;
1245 press: (tabId: string, input: PreviewAutomationPressInput) => Promise<void>;
1246 scroll: (tabId: string, input: PreviewAutomationScrollInput) => Promise<void>;
1247 evaluate: (tabId: string, input: PreviewAutomationEvaluateInput) => Promise<unknown>;
1248 waitFor: (tabId: string, input: PreviewAutomationWaitForInput) => Promise<void>;
1249 };
1250 onStateChange: (listener: (tabId: string, state: DesktopPreviewTabState) => void) => () => void;
1251 onPointerEvent: (listener: (event: DesktopPreviewPointerEvent) => void) => () => void;
1253​
1254export type ConfirmDialogVariant = "default" | "destructive";
1255​
1256export interface ConfirmDialogOptions {
1257 readonly variant?: ConfirmDialogVariant;
1259​
1260/**
1261 * APIs bound to the local app shell, not to any particular backend environment.
1263 * These capabilities describe the desktop/browser host that the user is
1264 * currently running: dialogs, external-link opening, context menus, and
1265 * app-level settings/config access. They must not be used as a proxy for
1266 * "whatever environment the user is targeting", because in a multi-environment
1267 * world the local shell and a selected backend environment are distinct
1268 * concepts.
1269 */
1270export interface LocalApi {
1271 dialogs: {
1272 pickFolder: (options?: PickFolderOptions) => Promise<string | null>;
1273 confirm: (message: string, options?: ConfirmDialogOptions) => Promise<boolean>;
1274 };
1275 shell: {
1276 openExternal: (url: string) => Promise<void>;
1277 };
1278 contextMenu: {
1279 show: <T extends string>(
1280 items: readonly ContextMenuItem<T>[],
1281 position?: { x: number; y: number },
1282 ) => Promise<T | null>;
1283 close: () => Promise<void>;
1284 };
1285 persistence: {
1286 getClientSettings: () => Promise<ClientSettings | null>;
1287 setClientSettings: (settings: ClientSettings) => Promise<void>;
1288 };
1290​
1291/**
1292 * APIs bound to a specific backend environment connection.
1294 * These operations must always be routed with explicit environment context.
1295 * They represent remote stateful capabilities such as orchestration, terminal,
1296 * project, VCS, and provider operations. In multi-environment mode, each environment gets
1297 * its own instance of this surface, and callers should resolve it by
1298 * `environmentId` rather than reaching through the local desktop bridge.
1299 */
1300export interface EnvironmentApi {
1301 terminal: {
1302 open: (input: typeof TerminalOpenInput.Encoded) => Promise<TerminalSessionSnapshot>;
1303 attach: (
1304 input: typeof TerminalAttachInput.Encoded,
1305 callback: (event: TerminalAttachStreamEvent) => void,
1306 options?: {
1307 onResubscribe?: () => void;
1308 },
1309 ) => () => void;
1310 write: (input: typeof TerminalWriteInput.Encoded) => Promise<void>;
1311 resize: (input: typeof TerminalResizeInput.Encoded) => Promise<void>;
1312 clear: (input: typeof TerminalClearInput.Encoded) => Promise<void>;
1313 restart: (input: typeof TerminalRestartInput.Encoded) => Promise<TerminalSessionSnapshot>;
1314 close: (input: typeof TerminalCloseInput.Encoded) => Promise<void>;
1315 onMetadata: (
1316 callback: (event: TerminalMetadataStreamEvent) => void,
1317 options?: {
1318 onResubscribe?: () => void;
1319 },
1320 ) => () => void;
1321 };
1322 projects: {
1323 listEntries: (input: ProjectListEntriesInput) => Promise<ProjectListEntriesResult>;
1324 readFile: (input: ProjectReadFileInput) => Promise<ProjectReadFileResult>;
1325 searchEntries: (input: ProjectSearchEntriesInput) => Promise<ProjectSearchEntriesResult>;
1326 writeFile: (input: ProjectWriteFileInput) => Promise<ProjectWriteFileResult>;
1327 };
1328 filesystem: {
1329 browse: (input: FilesystemBrowseInput) => Promise<FilesystemBrowseResult>;
1330 };
1331 assets: {
1332 createUrl: (input: AssetCreateUrlInput) => Promise<AssetCreateUrlResult>;
1333 };
1334 sourceControl: {
1335 lookupRepository: (
1336 input: SourceControlRepositoryLookupInput,
1337 ) => Promise<SourceControlRepositoryInfo>;
1338 cloneRepository: (
1339 input: SourceControlCloneRepositoryInput,
1340 ) => Promise<SourceControlCloneRepositoryResult>;
1341 publishRepository: (
1342 input: SourceControlPublishRepositoryInput,
1343 ) => Promise<SourceControlPublishRepositoryResult>;
1344 };
1345 vcs: {
1346 listRefs: (input: VcsListRefsInput) => Promise<VcsListRefsResult>;
1347 createWorktree: (input: VcsCreateWorktreeInput) => Promise<VcsCreateWorktreeResult>;
1348 removeWorktree: (input: VcsRemoveWorktreeInput) => Promise<void>;
1349 createRef: (input: VcsCreateRefInput) => Promise<VcsCreateRefResult>;
1350 switchRef: (input: VcsSwitchRefInput) => Promise<VcsSwitchRefResult>;
1351 init: (input: VcsInitInput) => Promise<void>;
1352 pull: (input: VcsPullInput) => Promise<VcsPullResult>;
1353 refreshStatus: (input: VcsStatusInput) => Promise<VcsStatusResult>;
1354 onStatus: (
1355 input: VcsStatusInput,
1356 callback: (status: VcsStatusResult) => void,
1357 options?: {
1358 onResubscribe?: () => void;
1359 },
1360 ) => () => void;
1361 };
1362 git: {
1363 resolvePullRequest: (input: GitPullRequestRefInput) => Promise<GitResolvePullRequestResult>;
1364 preparePullRequestThread: (
1365 input: GitPreparePullRequestThreadInput,
1366 ) => Promise<GitPreparePullRequestThreadResult>;
1367 };
1368 review: {
1369 getDiffPreview: (input: ReviewDiffPreviewInput) => Promise<ReviewDiffPreviewResult>;
1370 getDiffFileContents: (
1371 input: ReviewDiffFileContentsInput,
1372 ) => Promise<ReviewDiffFileContentsResult>;
1373 };
1374 orchestration: {
1375 dispatchCommand: (command: ClientOrchestrationCommand) => Promise<{ sequence: number }>;
1376 getTurnDiff: (input: OrchestrationGetTurnDiffInput) => Promise<OrchestrationGetTurnDiffResult>;
1377 getFullThreadDiff: (
1378 input: OrchestrationGetFullThreadDiffInput,
1379 ) => Promise<OrchestrationGetFullThreadDiffResult>;
1380 getArchivedShellSnapshot: () => Promise<OrchestrationShellSnapshot>;
1381 subscribeShell: (
1382 callback: (event: OrchestrationShellStreamItem) => void,
1383 options?: {
1384 onResubscribe?: () => void;
1385 },
1386 ) => () => void;
1387 subscribeThread: (
1388 input: OrchestrationSubscribeThreadInput,
1389 callback: (event: OrchestrationThreadStreamItem) => void,
1390 options?: {
1391 onResubscribe?: () => 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 };