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

ipc.ts

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