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

ipc.ts

1,180 lines39.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 { ReviewDiffPreviewInput, ReviewDiffPreviewResult } from "./review.ts";
22import type { FilesystemBrowseInput, FilesystemBrowseResult } from "./filesystem.ts";
23import type { AssetCreateUrlInput, AssetCreateUrlResult } from "./assets.ts";
24import type {
25 ProjectListEntriesInput,
26 ProjectListEntriesResult,
27 ProjectReadFileInput,
28 ProjectReadFileResult,
29 ProjectSearchEntriesInput,
30 ProjectSearchEntriesResult,
31 ProjectWriteFileInput,
32 ProjectWriteFileResult,
33} from "./project.ts";
34import type { ProviderInstanceId } from "./providerInstance.ts";
35import type {
36 ServerConfig,
37 ServerProcessDiagnosticsResult,
38 ServerProcessResourceHistoryInput,
39 ServerProcessResourceHistoryResult,
40 ServerProviderUpdateInput,
41 ServerProviderUpdatedPayload,
42 ServerRemoveKeybindingResult,
43 ServerSignalProcessInput,
44 ServerSignalProcessResult,
45 ServerTraceDiagnosticsResult,
46 ServerUpsertKeybindingResult,
47} from "./server.ts";
48import type {
49 TerminalAttachInput,
50 TerminalAttachStreamEvent,
51 TerminalClearInput,
52 TerminalCloseInput,
53 TerminalMetadataStreamEvent,
54 TerminalOpenInput,
55 TerminalResizeInput,
56 TerminalRestartInput,
57 TerminalSessionSnapshot,
58 TerminalWriteInput,
59} from "./terminal.ts";
60import type { ServerRemoveKeybindingInput, ServerUpsertKeybindingInput } from "./server.ts";
61import * as Schema from "effect/Schema";
62import type {
63 DiscoveredLocalServerList,
64 PreviewCloseInput,
65 PreviewEvent,
66 PreviewListInput,
67 PreviewListResult,
68 PreviewNavigateInput,
69 PreviewOpenInput,
70 PreviewRefreshInput,
71 PreviewReportStatusInput,
72 PreviewSessionSnapshot,
73} from "./preview.ts";
74import {
75 PreviewAutomationClickInput,
76 PreviewAutomationEvaluateInput,
77 PreviewAutomationOwner,
78 PreviewAutomationOwnerIdentity,
79 PreviewAutomationPressInput,
80 PreviewAutomationRequest,
81 PreviewAutomationResponse,
82 PreviewAutomationScrollInput,
83 PreviewAutomationSnapshot,
84 PreviewAutomationStatus,
85 PreviewAutomationTypeInput,
86 PreviewAutomationWaitForInput,
87} from "./previewAutomation.ts";
88import type {
89 ClientOrchestrationCommand,
90 OrchestrationGetFullThreadDiffInput,
91 OrchestrationGetFullThreadDiffResult,
92 OrchestrationGetTurnDiffInput,
93 OrchestrationGetTurnDiffResult,
94 OrchestrationShellSnapshot,
95 OrchestrationShellStreamItem,
96 OrchestrationSubscribeThreadInput,
97 OrchestrationThreadStreamItem,
98} from "./orchestration.ts";
99import { EnvironmentId } from "./baseSchemas.ts";
100import { AuthAccessTokenResult, AuthSessionState, AuthWebSocketTicketResult } from "./auth.ts";
101import { AdvertisedEndpoint } from "./remoteAccess.ts";
102import { EditorId } from "./editor.ts";
103import { ExecutionEnvironmentDescriptor } from "./environment.ts";
104import type { ClientSettings, ServerSettings, ServerSettingsPatch } from "./settings.ts";
105import type {
106 SourceControlCloneRepositoryInput,
107 SourceControlCloneRepositoryResult,
108 SourceControlDiscoveryResult,
109 SourceControlPublishRepositoryInput,
110 SourceControlPublishRepositoryResult,
111 SourceControlRepositoryInfo,
112 SourceControlRepositoryLookupInput,
113} from "./sourceControl.ts";
114​
115export interface ContextMenuItem<T extends string = string> {
116 id: T;
117 label: string;
118 destructive?: boolean;
119 disabled?: boolean;
120 /** Renders as a non-interactive section header label. Web fallback only — stripped on desktop native menus. */
121 header?: boolean;
122 /** Icon keyword resolved by the web fallback. Stripped on desktop native menus. */
123 icon?: string;
124 children?: readonly ContextMenuItem<T>[];
126​
127export interface ContextMenuItemSchemaType {
128 readonly id: string;
129 readonly label: string;
130 readonly destructive?: boolean;
131 readonly disabled?: boolean;
132 readonly header?: boolean;
133 readonly icon?: string;
134 readonly children?: readonly ContextMenuItemSchemaType[];
136​
137export const ContextMenuItemSchema: Schema.Codec<ContextMenuItemSchemaType> = Schema.Struct({
138 id: Schema.String,
139 label: Schema.String,
140 destructive: Schema.optionalKey(Schema.Boolean),
141 disabled: Schema.optionalKey(Schema.Boolean),
142 header: Schema.optionalKey(Schema.Boolean),
143 icon: Schema.optionalKey(Schema.String),
144 children: Schema.optionalKey(
145 Schema.Array(
146 Schema.suspend((): Schema.Codec<ContextMenuItemSchemaType> => ContextMenuItemSchema),
147 ),
148 ),
149});
150​
151export type DesktopUpdateStatus =
152 | "disabled"
153 | "idle"
154 | "checking"
155 | "up-to-date"
156 | "available"
157 | "downloading"
158 | "downloaded"
159 | "error";
160​
161export type DesktopRuntimeArch = "arm64" | "x64" | "other";
162export type DesktopTheme = "light" | "dark" | "system";
163export type DesktopUpdateChannel = "latest" | "nightly";
164export type DesktopAppStageLabel = "Alpha" | "Dev" | "Nightly";
165​
166export const DesktopUpdateStatusSchema = Schema.Literals([
167 "disabled",
168 "idle",
169 "checking",
170 "up-to-date",
171 "available",
172 "downloading",
173 "downloaded",
174 "error",
175]);
176export const DesktopRuntimeArchSchema = Schema.Literals(["arm64", "x64", "other"]);
177export const DesktopThemeSchema = Schema.Literals(["light", "dark", "system"]);
178export const DesktopUpdateChannelSchema = Schema.Literals(["latest", "nightly"]);
179export const DesktopAppStageLabelSchema = Schema.Literals(["Alpha", "Dev", "Nightly"]);
180​
181export interface DesktopAppBranding {
182 baseName: string;
183 stageLabel: DesktopAppStageLabel;
184 displayName: string;
186​
187export const DesktopAppBrandingSchema = Schema.Struct({
188 baseName: Schema.String,
189 stageLabel: DesktopAppStageLabelSchema,
190 displayName: Schema.String,
191});
192​
193export interface DesktopRuntimeInfo {
194 hostArch: DesktopRuntimeArch;
195 appArch: DesktopRuntimeArch;
196 runningUnderArm64Translation: boolean;
198​
199export const DesktopRuntimeInfoSchema = Schema.Struct({
200 hostArch: DesktopRuntimeArchSchema,
201 appArch: DesktopRuntimeArchSchema,
202 runningUnderArm64Translation: Schema.Boolean,
203});
204​
205export interface DesktopUpdateState {
206 enabled: boolean;
207 status: DesktopUpdateStatus;
208 channel: DesktopUpdateChannel;
209 currentVersion: string;
210 hostArch: DesktopRuntimeArch;
211 appArch: DesktopRuntimeArch;
212 runningUnderArm64Translation: boolean;
213 availableVersion: string | null;
214 downloadedVersion: string | null;
215 downloadPercent: number | null;
216 checkedAt: string | null;
217 message: string | null;
218 errorContext: "check" | "download" | "install" | null;
219 canRetry: boolean;
221​
222export const DesktopUpdateStateSchema = Schema.Struct({
223 enabled: Schema.Boolean,
224 status: DesktopUpdateStatusSchema,
225 channel: DesktopUpdateChannelSchema,
226 currentVersion: Schema.String,
227 hostArch: DesktopRuntimeArchSchema,
228 appArch: DesktopRuntimeArchSchema,
229 runningUnderArm64Translation: Schema.Boolean,
230 availableVersion: Schema.NullOr(Schema.String),
231 downloadedVersion: Schema.NullOr(Schema.String),
232 downloadPercent: Schema.NullOr(Schema.Number),
233 checkedAt: Schema.NullOr(Schema.String),
234 message: Schema.NullOr(Schema.String),
235 errorContext: Schema.NullOr(Schema.Literals(["check", "download", "install"])),
236 canRetry: Schema.Boolean,
237});
238​
239export interface DesktopUpdateActionResult {
240 accepted: boolean;
241 completed: boolean;
242 state: DesktopUpdateState;
244​
245export const DesktopUpdateActionResultSchema = Schema.Struct({
246 accepted: Schema.Boolean,
247 completed: Schema.Boolean,
248 state: DesktopUpdateStateSchema,
249});
250​
251export interface DesktopUpdateCheckResult {
252 checked: boolean;
253 state: DesktopUpdateState;
255​
256export const DesktopUpdateCheckResultSchema = Schema.Struct({
257 checked: Schema.Boolean,
258 state: DesktopUpdateStateSchema,
259});
260​
261export interface DesktopEnvironmentBootstrap {
262 label: string;
263 httpBaseUrl: string | null;
264 wsBaseUrl: string | null;
265 bootstrapToken?: string;
267​
268export const DesktopEnvironmentBootstrapSchema = Schema.Struct({
269 label: Schema.String,
270 httpBaseUrl: Schema.NullOr(Schema.String),
271 wsBaseUrl: Schema.NullOr(Schema.String),
272 bootstrapToken: Schema.optionalKey(Schema.String),
273});
274​
275export const DesktopSshEnvironmentTargetSchema = Schema.Struct({
276 alias: Schema.String,
277 hostname: Schema.String,
278 username: Schema.NullOr(Schema.String),
279 port: Schema.NullOr(Schema.Number),
280});
281export type DesktopSshEnvironmentTarget = typeof DesktopSshEnvironmentTargetSchema.Type;
282​
283export type DesktopSshHostSource = "ssh-config" | "known-hosts";
284export const DesktopSshHostSourceSchema = Schema.Literals(["ssh-config", "known-hosts"]);
285​
286export interface DesktopDiscoveredSshHost extends DesktopSshEnvironmentTarget {
287 source: DesktopSshHostSource;
289​
290export const DesktopDiscoveredSshHostSchema = Schema.Struct({
291 alias: Schema.String,
292 hostname: Schema.String,
293 username: Schema.NullOr(Schema.String),
294 port: Schema.NullOr(Schema.Number),
295 source: DesktopSshHostSourceSchema,
296});
297​
298export interface DesktopSshEnvironmentBootstrap {
299 target: DesktopSshEnvironmentTarget;
300 httpBaseUrl: string;
301 wsBaseUrl: string;
302 pairingToken: string | null;
303 remotePort?: number;
304 remoteServerKind?: "external" | "managed";
306​
307export const DesktopSshEnvironmentBootstrapSchema = Schema.Struct({
308 target: DesktopSshEnvironmentTargetSchema,
309 httpBaseUrl: Schema.String,
310 wsBaseUrl: Schema.String,
311 pairingToken: Schema.NullOr(Schema.String),
312 remotePort: Schema.optionalKey(Schema.Number),
313 remoteServerKind: Schema.optionalKey(Schema.Literals(["external", "managed"])),
314});
315​
316export interface DesktopSshPasswordPromptRequest {
317 requestId: string;
318 destination: string;
319 username: string | null;
320 prompt: string;
321 expiresAt: string;
323​
324export const DesktopSshPasswordPromptRequestSchema = Schema.Struct({
325 requestId: Schema.String,
326 destination: Schema.String,
327 username: Schema.NullOr(Schema.String),
328 prompt: Schema.String,
329 expiresAt: Schema.String,
330});
331​
332export const DesktopSshPasswordPromptCancelledType = "ssh-password-prompt-cancelled" as const;
333​
334export const DesktopSshPasswordPromptCancelledResultSchema = Schema.Struct({
335 type: Schema.Literal(DesktopSshPasswordPromptCancelledType),
336 message: Schema.String,
337});
338​
339export const DesktopSshEnvironmentEnsureOptionsSchema = Schema.Struct({
340 issuePairingToken: Schema.optionalKey(Schema.Boolean),
341});
342​
343export const DesktopSshEnvironmentEnsureInputSchema = Schema.Struct({
344 target: DesktopSshEnvironmentTargetSchema,
345 options: Schema.optionalKey(DesktopSshEnvironmentEnsureOptionsSchema),
346});
347​
348export const DesktopSshEnvironmentEnsureResultSchema = Schema.Union([
349 DesktopSshEnvironmentBootstrapSchema,
350 DesktopSshPasswordPromptCancelledResultSchema,
351]);
352​
353export const DesktopSshHttpBaseUrlInputSchema = Schema.Struct({
354 httpBaseUrl: Schema.String,
355});
356​
357export const DesktopSshBearerRequestInputSchema = Schema.Struct({
358 httpBaseUrl: Schema.String,
359 bearerToken: Schema.String,
360});
361​
362export const DesktopSshBearerBootstrapInputSchema = Schema.Struct({
363 httpBaseUrl: Schema.String,
364 credential: Schema.String,
365});
366​
367export const DesktopSshPasswordPromptResolutionInputSchema = Schema.Struct({
368 requestId: Schema.String,
369 password: Schema.NullOr(Schema.String),
370});
371​
372export const PersistedSavedEnvironmentRecordSchema = Schema.Struct({
373 environmentId: EnvironmentId,
374 label: Schema.String,
375 wsBaseUrl: Schema.String,
376 httpBaseUrl: Schema.String,
377 createdAt: Schema.String,
378 lastConnectedAt: Schema.NullOr(Schema.String),
379 desktopSsh: Schema.optionalKey(DesktopSshEnvironmentTargetSchema),
380 relayManaged: Schema.optionalKey(
381 Schema.Struct({
382 relayUrl: Schema.String,
383 }),
384 ),
385});
386export type PersistedSavedEnvironmentRecord = typeof PersistedSavedEnvironmentRecordSchema.Type;
387​
388export type DesktopServerExposureMode = "local-only" | "network-accessible";
389​
390export const DesktopServerExposureModeSchema = Schema.Literals([
391 "local-only",
392 "network-accessible",
393]);
394​
395export interface DesktopServerExposureState {
396 mode: DesktopServerExposureMode;
397 endpointUrl: string | null;
398 advertisedHost: string | null;
399 tailscaleServeEnabled: boolean;
400 tailscaleServePort: number;
402​
403export const DesktopServerExposureStateSchema = Schema.Struct({
404 mode: DesktopServerExposureModeSchema,
405 endpointUrl: Schema.NullOr(Schema.String),
406 advertisedHost: Schema.NullOr(Schema.String),
407 tailscaleServeEnabled: Schema.Boolean,
408 tailscaleServePort: Schema.Number,
409});
410​
411export interface PickFolderOptions {
412 initialPath?: string | null;
414​
415export const PickFolderOptionsSchema = Schema.Struct({
416 initialPath: Schema.optionalKey(Schema.NullOr(Schema.String)),
417});
418​
419/**
420 * Renderer-facing snapshot of a desktop preview tab. Mirrors the main-process
421 * PreviewTabState shape but uses serialisable primitives only.
422 */
423export type DesktopPreviewNavStatus =
424 | { kind: "Idle" }
425 | { kind: "Loading"; url: string; title: string }
426 | { kind: "Success"; url: string; title: string }
427 | {
428 kind: "LoadFailed";
429 url: string;
430 title: string;
431 code: number;
432 description: string;
433 };
434​
435export interface DesktopPreviewTabState {
436 tabId: string;
437 webContentsId: number | null;
438 navStatus: DesktopPreviewNavStatus;
439 canGoBack: boolean;
440 canGoForward: boolean;
441 /** Current zoom factor (1.0 = 100%). */
442 zoomFactor: number;
443 controller: "human" | "agent" | "none";
444 updatedAt: string;
446​
447export const DesktopPreviewTabIdSchema = Schema.String.check(Schema.isTrimmed()).check(
448 Schema.isNonEmpty(),
449);
450​
451export const DesktopPreviewNavStatusSchema = Schema.Union([
452 Schema.Struct({ kind: Schema.Literal("Idle") }),
453 Schema.Struct({
454 kind: Schema.Literal("Loading"),
455 url: Schema.String,
456 title: Schema.String,
457 }),
458 Schema.Struct({
459 kind: Schema.Literal("Success"),
460 url: Schema.String,
461 title: Schema.String,
462 }),
463 Schema.Struct({
464 kind: Schema.Literal("LoadFailed"),
465 url: Schema.String,
466 title: Schema.String,
467 code: Schema.Number,
468 description: Schema.String,
469 }),
470]);
471​
472export const DesktopPreviewTabStateSchema: Schema.Codec<DesktopPreviewTabState> = Schema.Struct({
473 tabId: DesktopPreviewTabIdSchema,
474 webContentsId: Schema.NullOr(Schema.Int),
475 navStatus: DesktopPreviewNavStatusSchema,
476 canGoBack: Schema.Boolean,
477 canGoForward: Schema.Boolean,
478 zoomFactor: Schema.Number,
479 controller: Schema.Literals(["human", "agent", "none"]),
480 updatedAt: Schema.String,
481});
482​
483export interface DesktopPreviewPointerEvent {
484 tabId: string;
485 phase: "move" | "click";
486 x: number;
487 y: number;
488 sequence: number;
489 createdAt: string;
491​
492export const DesktopPreviewPointerEventSchema: Schema.Codec<DesktopPreviewPointerEvent> =
493 Schema.Struct({
494 tabId: DesktopPreviewTabIdSchema,
495 phase: Schema.Literals(["move", "click"]),
496 x: Schema.Number,
497 y: Schema.Number,
498 sequence: Schema.Int,
499 createdAt: Schema.String,
500 });
501​
502/**
503 * Static config a renderer needs to mount a preview `<webview>`. Returned
504 * atomically by `DesktopPreviewBridge.getPreviewConfig()` so the renderer
505 * doesn't have to wait on three separate IPC round-trips before the webview
506 * can attach.
507 */
508export interface DesktopPreviewWebviewConfig {
509 /** `persist:t3code-preview` (or whatever the desktop chose). */
510 partition: string;
511 /**
512 * Canonical `<webview webpreferences="...">` string. Encodes the security
513 * posture (sandboxed but contextIsolation off so the picker preload can
514 * read the page's React DevTools hook). Always present.
515 */
516 webPreferences: string;
517 /**
518 * Absolute `file://`-style URL to the picker preload bundle. Set to null
519 * when the bundle isn't present (older builds, broken install) — the
520 * renderer must then disable element-pick affordances.
521 */
522 preloadUrl: string | null;
524​
525export const DesktopPreviewWebviewConfigSchema: Schema.Codec<DesktopPreviewWebviewConfig> =
526 Schema.Struct({
527 partition: Schema.String,
528 webPreferences: Schema.String,
529 preloadUrl: Schema.NullOr(Schema.String),
530 });
531​
532export interface DesktopPreviewAnnotationTheme {
533 colorScheme: "light" | "dark";
534 radius: string;
535 background: string;
536 foreground: string;
537 popover: string;
538 popoverForeground: string;
539 primary: string;
540 primaryForeground: string;
541 muted: string;
542 mutedForeground: string;
543 accent: string;
544 accentForeground: string;
545 border: string;
546 input: string;
547 ring: string;
548 fontSans: string;
549 fontMono: string;
551​
552export const DesktopPreviewAnnotationThemeSchema: Schema.Codec<DesktopPreviewAnnotationTheme> =
553 Schema.Struct({
554 colorScheme: Schema.Literals(["light", "dark"]),
555 radius: Schema.String,
556 background: Schema.String,
557 foreground: Schema.String,
558 popover: Schema.String,
559 popoverForeground: Schema.String,
560 primary: Schema.String,
561 primaryForeground: Schema.String,
562 muted: Schema.String,
563 mutedForeground: Schema.String,
564 accent: Schema.String,
565 accentForeground: Schema.String,
566 border: Schema.String,
567 input: Schema.String,
568 ring: Schema.String,
569 fontSans: Schema.String,
570 fontMono: Schema.String,
571 });
572​
573export interface DesktopPreviewRecordingFrame {
574 tabId: string;
575 data: string;
576 width: number;
577 height: number;
578 receivedAt: string;
580​
581export const DesktopPreviewRecordingFrameSchema: Schema.Codec<DesktopPreviewRecordingFrame> =
582 Schema.Struct({
583 tabId: DesktopPreviewTabIdSchema,
584 data: Schema.String,
585 width: Schema.Number,
586 height: Schema.Number,
587 receivedAt: Schema.String,
588 });
589​
590export interface DesktopPreviewRecordingArtifact {
591 id: string;
592 tabId: string;
593 path: string;
594 mimeType: string;
595 sizeBytes: number;
596 createdAt: string;
598​
599export const DesktopPreviewRecordingArtifactSchema: Schema.Codec<DesktopPreviewRecordingArtifact> =
600 Schema.Struct({
601 id: Schema.String,
602 tabId: DesktopPreviewTabIdSchema,
603 path: Schema.String,
604 mimeType: Schema.String,
605 sizeBytes: Schema.Int,
606 createdAt: Schema.String,
607 });
608​
609export interface DesktopPreviewScreenshotArtifact {
610 id: string;
611 tabId: string;
612 path: string;
613 mimeType: "image/png";
614 sizeBytes: number;
615 createdAt: string;
617​
618export const DesktopPreviewScreenshotArtifactSchema: Schema.Codec<DesktopPreviewScreenshotArtifact> =
619 Schema.Struct({
620 id: Schema.String,
621 tabId: DesktopPreviewTabIdSchema,
622 path: Schema.String,
623 mimeType: Schema.Literal("image/png"),
624 sizeBytes: Schema.Int,
625 createdAt: Schema.String,
626 });
627​
628/**
629 * Single stack frame captured by react-grab's `getElementContext`. We surface
630 * the source file/line so coding agents can jump straight to the JSX that
631 * produced the picked DOM node.
632 */
633export interface PickedElementStackFrame {
634 functionName: string | null;
635 fileName: string | null;
636 lineNumber: number | null;
637 columnNumber: number | null;
639​
640export const PickedElementStackFrameSchema: Schema.Codec<PickedElementStackFrame> = Schema.Struct({
641 functionName: Schema.NullOr(Schema.String),
642 fileName: Schema.NullOr(Schema.String),
643 lineNumber: Schema.NullOr(Schema.Number),
644 columnNumber: Schema.NullOr(Schema.Number),
645});
646​
647/**
648 * A successful element pick from the preview webview. All fields are
649 * best-effort — pages that don't ship a React fiber tree (or aren't running
650 * in dev) will still produce a usable payload (selector + html preview),
651 * just without component / source attribution.
652 */
653export interface PickedElementPayload {
654 /** URL of the page the element was picked on. */
655 pageUrl: string;
656 /** Optional `<title>` of that page (best-effort). */
657 pageTitle: string | null;
658 /** Lowercase tag name, e.g. `"button"`. */
659 tagName: string;
660 /** CSS selector resolving back to the element on a re-render. */
661 selector: string | null;
662 /** Truncated outer-HTML preview (matches react-grab's `htmlPreview`). */
663 htmlPreview: string;
664 /** Nearest React component display name, or null when unavailable. */
665 componentName: string | null;
666 /** First source-mapped stack frame (file + line of the JSX source). */
667 source: PickedElementStackFrame | null;
668 /** Full owner-stack frames; can be empty. Useful for richer context. */
669 stack: ReadonlyArray<PickedElementStackFrame>;
670 /** Author CSS only (UA defaults stripped) — react-grab's `styles`. */
671 styles: string;
672 /** Wall-clock pick time as ISO-8601 string. */
673 pickedAt: string;
675​
676export const PickedElementPayloadSchema: Schema.Codec<PickedElementPayload> = Schema.Struct({
677 pageUrl: Schema.String,
678 pageTitle: Schema.NullOr(Schema.String),
679 tagName: Schema.String,
680 selector: Schema.NullOr(Schema.String),
681 htmlPreview: Schema.String,
682 componentName: Schema.NullOr(Schema.String),
683 source: Schema.NullOr(PickedElementStackFrameSchema),
684 stack: Schema.Array(PickedElementStackFrameSchema),
685 styles: Schema.String,
686 pickedAt: Schema.String,
687});
688​
689export interface PreviewAnnotationRect {
690 x: number;
691 y: number;
692 width: number;
693 height: number;
695​
696export const PreviewAnnotationRectSchema: Schema.Codec<PreviewAnnotationRect> = Schema.Struct({
697 x: Schema.Number,
698 y: Schema.Number,
699 width: Schema.Number,
700 height: Schema.Number,
701});
702​
703export interface PreviewAnnotationPoint {
704 x: number;
705 y: number;
707​
708export const PreviewAnnotationPointSchema: Schema.Codec<PreviewAnnotationPoint> = Schema.Struct({
709 x: Schema.Number,
710 y: Schema.Number,
711});
712​
713export interface PreviewAnnotationElementTarget {
714 id: string;
715 element: PickedElementPayload;
716 rect: PreviewAnnotationRect;
718​
719export const PreviewAnnotationElementTargetSchema: Schema.Codec<PreviewAnnotationElementTarget> =
720 Schema.Struct({
721 id: Schema.String,
722 element: PickedElementPayloadSchema,
723 rect: PreviewAnnotationRectSchema,
724 });
725​
726export interface PreviewAnnotationRegionTarget {
727 id: string;
728 rect: PreviewAnnotationRect;
730​
731export const PreviewAnnotationRegionTargetSchema: Schema.Codec<PreviewAnnotationRegionTarget> =
732 Schema.Struct({
733 id: Schema.String,
734 rect: PreviewAnnotationRectSchema,
735 });
736​
737export interface PreviewAnnotationStrokeTarget {
738 id: string;
739 color: string;
740 width: number;
741 points: ReadonlyArray<PreviewAnnotationPoint>;
742 bounds: PreviewAnnotationRect;
744​
745export const PreviewAnnotationStrokeTargetSchema: Schema.Codec<PreviewAnnotationStrokeTarget> =
746 Schema.Struct({
747 id: Schema.String,
748 color: Schema.String,
749 width: Schema.Number,
750 points: Schema.Array(PreviewAnnotationPointSchema),
751 bounds: PreviewAnnotationRectSchema,
752 });
753​
754export interface PreviewAnnotationStyleChange {
755 targetId: string;
756 selector: string | null;
757 property: string;
758 previousValue: string;
759 value: string;
761​
762export const PreviewAnnotationStyleChangeSchema: Schema.Codec<PreviewAnnotationStyleChange> =
763 Schema.Struct({
764 targetId: Schema.String,
765 selector: Schema.NullOr(Schema.String),
766 property: Schema.String,
767 previousValue: Schema.String,
768 value: Schema.String,
769 });
770​
771export interface PreviewAnnotationScreenshot {
772 dataUrl: string;
773 width: number;
774 height: number;
775 cropRect: PreviewAnnotationRect;
777​
778export const PreviewAnnotationScreenshotSchema: Schema.Codec<PreviewAnnotationScreenshot> =
779 Schema.Struct({
780 dataUrl: Schema.String,
781 width: Schema.Number,
782 height: Schema.Number,
783 cropRect: PreviewAnnotationRectSchema,
784 });
785​
786/**
787 * A submitted preview annotation. One annotation may reference multiple DOM
788 * elements, freeform regions, and ink strokes. The desktop main process adds
789 * the screenshot after the guest preload submits the structured draft.
790 */
791export interface PreviewAnnotationPayload {
792 id: string;
793 pageUrl: string;
794 pageTitle: string | null;
795 comment: string;
796 elements: ReadonlyArray<PreviewAnnotationElementTarget>;
797 regions: ReadonlyArray<PreviewAnnotationRegionTarget>;
798 strokes: ReadonlyArray<PreviewAnnotationStrokeTarget>;
799 styleChanges: ReadonlyArray<PreviewAnnotationStyleChange>;
800 screenshot: PreviewAnnotationScreenshot | null;
801 createdAt: string;
803​
804export const PreviewAnnotationPayloadSchema: Schema.Codec<PreviewAnnotationPayload> = Schema.Struct(
805 {
806 id: Schema.String,
807 pageUrl: Schema.String,
808 pageTitle: Schema.NullOr(Schema.String),
809 comment: Schema.String,
810 elements: Schema.Array(PreviewAnnotationElementTargetSchema),
811 regions: Schema.Array(PreviewAnnotationRegionTargetSchema),
812 strokes: Schema.Array(PreviewAnnotationStrokeTargetSchema),
813 styleChanges: Schema.Array(PreviewAnnotationStyleChangeSchema),
814 screenshot: Schema.NullOr(PreviewAnnotationScreenshotSchema),
815 createdAt: Schema.String,
816 },
817);
818​
819export const DesktopPreviewTabInputSchema = Schema.Struct({
820 tabId: DesktopPreviewTabIdSchema,
821});
822​
823export const DesktopPreviewRegisterWebviewInputSchema = Schema.Struct({
824 tabId: DesktopPreviewTabIdSchema,
825 webContentsId: Schema.Int.check(Schema.isGreaterThan(0)),
826});
827​
828export const DesktopPreviewNavigateInputSchema = Schema.Struct({
829 tabId: DesktopPreviewTabIdSchema,
830 url: Schema.String,
831});
832​
833export const DesktopPreviewConfigInputSchema = Schema.Struct({
834 environmentId: EnvironmentId,
835});
836​
837export const DesktopPreviewAnnotationThemeInputSchema = Schema.Struct({
838 theme: DesktopPreviewAnnotationThemeSchema,
839});
840​
841export const DesktopPreviewArtifactInputSchema = Schema.Struct({
842 path: Schema.String.check(Schema.isTrimmed()).check(Schema.isNonEmpty()),
843});
844​
845export const DesktopPreviewRecordingSaveInputSchema = Schema.Struct({
846 tabId: DesktopPreviewTabIdSchema,
847 mimeType: Schema.String.check(Schema.isTrimmed()).check(Schema.isNonEmpty()),
848 data: Schema.Uint8Array,
849});
850​
851export const DesktopPreviewAutomationClickInputSchema = Schema.Struct({
852 tabId: DesktopPreviewTabIdSchema,
853 input: PreviewAutomationClickInput,
854});
855​
856export const DesktopPreviewAutomationTypeInputSchema = Schema.Struct({
857 tabId: DesktopPreviewTabIdSchema,
858 input: PreviewAutomationTypeInput,
859});
860​
861export const DesktopPreviewAutomationPressInputSchema = Schema.Struct({
862 tabId: DesktopPreviewTabIdSchema,
863 input: PreviewAutomationPressInput,
864});
865​
866export const DesktopPreviewAutomationScrollInputSchema = Schema.Struct({
867 tabId: DesktopPreviewTabIdSchema,
868 input: PreviewAutomationScrollInput,
869});
870​
871export const DesktopPreviewAutomationEvaluateInputSchema = Schema.Struct({
872 tabId: DesktopPreviewTabIdSchema,
873 input: PreviewAutomationEvaluateInput,
874});
875​
876export const DesktopPreviewAutomationWaitForInputSchema = Schema.Struct({
877 tabId: DesktopPreviewTabIdSchema,
878 input: PreviewAutomationWaitForInput,
879});
880​
881export interface DesktopBridge {
882 getAppBranding: () => DesktopAppBranding | null;
883 getLocalEnvironmentBootstrap: () => DesktopEnvironmentBootstrap | null;
884 getLocalEnvironmentBearerToken: () => Promise<string>;
885 getClientSettings: () => Promise<ClientSettings | null>;
886 setClientSettings: (settings: ClientSettings) => Promise<void>;
887 getConnectionCatalog?: () => Promise<string | null>;
888 setConnectionCatalog?: (catalog: string) => Promise<boolean>;
889 clearConnectionCatalog?: () => Promise<void>;
890 discoverSshHosts: () => Promise<readonly DesktopDiscoveredSshHost[]>;
891 ensureSshEnvironment: (
892 target: DesktopSshEnvironmentTarget,
893 options?: { issuePairingToken?: boolean },
894 ) => Promise<DesktopSshEnvironmentBootstrap>;
895 disconnectSshEnvironment: (target: DesktopSshEnvironmentTarget) => Promise<void>;
896 fetchSshEnvironmentDescriptor: (httpBaseUrl: string) => Promise<ExecutionEnvironmentDescriptor>;
897 bootstrapSshBearerSession: (
898 httpBaseUrl: string,
899 credential: string,
900 ) => Promise<AuthAccessTokenResult>;
901 fetchSshSessionState: (httpBaseUrl: string, bearerToken: string) => Promise<AuthSessionState>;
902 issueSshWebSocketTicket: (
903 httpBaseUrl: string,
904 bearerToken: string,
905 ) => Promise<AuthWebSocketTicketResult>;
906 onSshPasswordPrompt: (listener: (request: DesktopSshPasswordPromptRequest) => void) => () => void;
907 resolveSshPasswordPrompt: (requestId: string, password: string | null) => Promise<void>;
908 getServerExposureState: () => Promise<DesktopServerExposureState>;
909 setServerExposureMode: (mode: DesktopServerExposureMode) => Promise<DesktopServerExposureState>;
910 setTailscaleServeEnabled: (input: {
911 readonly enabled: boolean;
912 readonly port?: number;
913 }) => Promise<DesktopServerExposureState>;
914 getAdvertisedEndpoints: () => Promise<readonly AdvertisedEndpoint[]>;
915 pickFolder: (options?: PickFolderOptions) => Promise<string | null>;
916 confirm: (message: string) => Promise<boolean>;
917 setTheme: (theme: DesktopTheme) => Promise<void>;
918 showContextMenu: <T extends string>(
919 items: readonly ContextMenuItem<T>[],
920 position?: { x: number; y: number },
921 ) => Promise<T | null>;
922 openExternal: (url: string) => Promise<boolean>;
923 onMenuAction: (listener: (action: string) => void) => () => void;
924 getUpdateState: () => Promise<DesktopUpdateState>;
925 setUpdateChannel: (channel: DesktopUpdateChannel) => Promise<DesktopUpdateState>;
926 checkForUpdate: () => Promise<DesktopUpdateCheckResult>;
927 downloadUpdate: () => Promise<DesktopUpdateActionResult>;
928 installUpdate: () => Promise<DesktopUpdateActionResult>;
929 onUpdateState: (listener: (state: DesktopUpdateState) => void) => () => void;
930 /**
931 * Desktop-only preview surface. Present iff the renderer is hosted by the
932 * Electron desktop build; web builds have `preview === undefined`.
933 */
934 preview?: DesktopPreviewBridge;
936​
937export interface DesktopPreviewBridge {
938 createTab: (tabId: string) => Promise<void>;
939 closeTab: (tabId: string) => Promise<void>;
940 registerWebview: (tabId: string, webContentsId: number) => Promise<void>;
941 navigate: (tabId: string, url: string) => Promise<void>;
942 goBack: (tabId: string) => Promise<void>;
943 goForward: (tabId: string) => Promise<void>;
944 refresh: (tabId: string) => Promise<void>;
945 zoomIn: (tabId: string) => Promise<void>;
946 zoomOut: (tabId: string) => Promise<void>;
947 resetZoom: (tabId: string) => Promise<void>;
948 /** Reload bypassing the HTTP cache. */
949 hardReload: (tabId: string) => Promise<void>;
950 /** Open the guest webview's DevTools (detached). */
951 openDevTools: (tabId: string) => Promise<void>;
952 /** Drop cookies + storage data for the preview partition (all tabs). */
953 clearCookies: () => Promise<void>;
954 /** Drop the HTTP cache for the preview partition (all tabs). */
955 clearCache: () => Promise<void>;
956 /**
957 * One-shot config for mounting a preview `<webview>`. Replaces three
958 * earlier round-trip calls (`getBrowserPartition`, `getWebviewPreferences`,
959 * `getPickPreloadPath`) so adding a new field here only requires touching
960 * the contract + main, not the renderer's mount logic.
961 */
962 getPreviewConfig: (environmentId: EnvironmentId) => Promise<DesktopPreviewWebviewConfig>;
963 setAnnotationTheme: (theme: DesktopPreviewAnnotationTheme) => Promise<void>;
964 /**
965 * Activate the in-page element picker for the given tab. Resolves with
966 * the picked payload, or `null` when the user cancels (Escape / nav). The
967 * promise rejects if the picker can't be activated (no webview, etc.).
968 */
969 pickElement: (tabId: string) => Promise<PreviewAnnotationPayload | null>;
970 /** Cancel an in-flight preview annotation session. */
971 cancelPickElement: (tabId: string) => Promise<void>;
972 captureScreenshot: (tabId: string) => Promise<DesktopPreviewScreenshotArtifact>;
973 revealArtifact: (path: string) => Promise<void>;
974 copyArtifactToClipboard: (path: string) => Promise<void>;
975 recording: {
976 startScreencast: (tabId: string) => Promise<void>;
977 stopScreencast: (tabId: string) => Promise<void>;
978 save: (
979 tabId: string,
980 mimeType: string,
981 data: Uint8Array,
982 ) => Promise<DesktopPreviewRecordingArtifact>;
983 onFrame: (listener: (frame: DesktopPreviewRecordingFrame) => void) => () => void;
984 };
985 automation: {
986 status: (tabId: string) => Promise<PreviewAutomationStatus>;
987 snapshot: (tabId: string) => Promise<PreviewAutomationSnapshot>;
988 click: (tabId: string, input: PreviewAutomationClickInput) => Promise<void>;
989 type: (tabId: string, input: PreviewAutomationTypeInput) => Promise<void>;
990 press: (tabId: string, input: PreviewAutomationPressInput) => Promise<void>;
991 scroll: (tabId: string, input: PreviewAutomationScrollInput) => Promise<void>;
992 evaluate: (tabId: string, input: PreviewAutomationEvaluateInput) => Promise<unknown>;
993 waitFor: (tabId: string, input: PreviewAutomationWaitForInput) => Promise<void>;
994 };
995 onStateChange: (listener: (tabId: string, state: DesktopPreviewTabState) => void) => () => void;
996 onPointerEvent: (listener: (event: DesktopPreviewPointerEvent) => void) => () => void;
998​
999/**
1000 * APIs bound to the local app shell, not to any particular backend environment.
1002 * These capabilities describe the desktop/browser host that the user is
1003 * currently running: dialogs, editor/external-link opening, context menus, and
1004 * app-level settings/config access. They must not be used as a proxy for
1005 * "whatever environment the user is targeting", because in a multi-environment
1006 * world the local shell and a selected backend environment are distinct
1007 * concepts.
1008 */
1009export interface LocalApi {
1010 dialogs: {
1011 pickFolder: (options?: PickFolderOptions) => Promise<string | null>;
1012 confirm: (message: string) => Promise<boolean>;
1013 };
1014 shell: {
1015 openInEditor: (cwd: string, editor: EditorId) => Promise<void>;
1016 openExternal: (url: string) => Promise<void>;
1017 };
1018 contextMenu: {
1019 show: <T extends string>(
1020 items: readonly ContextMenuItem<T>[],
1021 position?: { x: number; y: number },
1022 ) => Promise<T | null>;
1023 };
1024 persistence: {
1025 getClientSettings: () => Promise<ClientSettings | null>;
1026 setClientSettings: (settings: ClientSettings) => Promise<void>;
1027 };
1028 server: {
1029 getConfig: () => Promise<ServerConfig>;
1030 /**
1031 * Refresh provider snapshots. When `input.instanceId` is supplied only that
1032 * configured instance is probed; otherwise every configured instance is
1033 * refreshed (legacy untargeted refresh).
1034 */
1035 refreshProviders: (input?: {
1036 readonly instanceId?: ProviderInstanceId;
1037 }) => Promise<ServerProviderUpdatedPayload>;
1038 updateProvider: (input: ServerProviderUpdateInput) => Promise<ServerProviderUpdatedPayload>;
1039 upsertKeybinding: (input: ServerUpsertKeybindingInput) => Promise<ServerUpsertKeybindingResult>;
1040 removeKeybinding: (input: ServerRemoveKeybindingInput) => Promise<ServerRemoveKeybindingResult>;
1041 getSettings: () => Promise<ServerSettings>;
1042 updateSettings: (patch: ServerSettingsPatch) => Promise<ServerSettings>;
1043 discoverSourceControl: () => Promise<SourceControlDiscoveryResult>;
1044 getTraceDiagnostics: () => Promise<ServerTraceDiagnosticsResult>;
1045 getProcessDiagnostics: () => Promise<ServerProcessDiagnosticsResult>;
1046 getProcessResourceHistory: (
1047 input: ServerProcessResourceHistoryInput,
1048 ) => Promise<ServerProcessResourceHistoryResult>;
1049 signalProcess: (input: ServerSignalProcessInput) => Promise<ServerSignalProcessResult>;
1050 };
1052​
1053/**
1054 * APIs bound to a specific backend environment connection.
1056 * These operations must always be routed with explicit environment context.
1057 * They represent remote stateful capabilities such as orchestration, terminal,
1058 * project, VCS, and provider operations. In multi-environment mode, each environment gets
1059 * its own instance of this surface, and callers should resolve it by
1060 * `environmentId` rather than reaching through the local desktop bridge.
1061 */
1062export interface EnvironmentApi {
1063 terminal: {
1064 open: (input: typeof TerminalOpenInput.Encoded) => Promise<TerminalSessionSnapshot>;
1065 attach: (
1066 input: typeof TerminalAttachInput.Encoded,
1067 callback: (event: TerminalAttachStreamEvent) => void,
1068 options?: {
1069 onResubscribe?: () => void;
1070 },
1071 ) => () => void;
1072 write: (input: typeof TerminalWriteInput.Encoded) => Promise<void>;
1073 resize: (input: typeof TerminalResizeInput.Encoded) => Promise<void>;
1074 clear: (input: typeof TerminalClearInput.Encoded) => Promise<void>;
1075 restart: (input: typeof TerminalRestartInput.Encoded) => Promise<TerminalSessionSnapshot>;
1076 close: (input: typeof TerminalCloseInput.Encoded) => Promise<void>;
1077 onMetadata: (
1078 callback: (event: TerminalMetadataStreamEvent) => void,
1079 options?: {
1080 onResubscribe?: () => void;
1081 },
1082 ) => () => void;
1083 };
1084 projects: {
1085 listEntries: (input: ProjectListEntriesInput) => Promise<ProjectListEntriesResult>;
1086 readFile: (input: ProjectReadFileInput) => Promise<ProjectReadFileResult>;
1087 searchEntries: (input: ProjectSearchEntriesInput) => Promise<ProjectSearchEntriesResult>;
1088 writeFile: (input: ProjectWriteFileInput) => Promise<ProjectWriteFileResult>;
1089 };
1090 filesystem: {
1091 browse: (input: FilesystemBrowseInput) => Promise<FilesystemBrowseResult>;
1092 };
1093 assets: {
1094 createUrl: (input: AssetCreateUrlInput) => Promise<AssetCreateUrlResult>;
1095 };
1096 sourceControl: {
1097 lookupRepository: (
1098 input: SourceControlRepositoryLookupInput,
1099 ) => Promise<SourceControlRepositoryInfo>;
1100 cloneRepository: (
1101 input: SourceControlCloneRepositoryInput,
1102 ) => Promise<SourceControlCloneRepositoryResult>;
1103 publishRepository: (
1104 input: SourceControlPublishRepositoryInput,
1105 ) => Promise<SourceControlPublishRepositoryResult>;
1106 };
1107 vcs: {
1108 listRefs: (input: VcsListRefsInput) => Promise<VcsListRefsResult>;
1109 createWorktree: (input: VcsCreateWorktreeInput) => Promise<VcsCreateWorktreeResult>;
1110 removeWorktree: (input: VcsRemoveWorktreeInput) => Promise<void>;
1111 createRef: (input: VcsCreateRefInput) => Promise<VcsCreateRefResult>;
1112 switchRef: (input: VcsSwitchRefInput) => Promise<VcsSwitchRefResult>;
1113 init: (input: VcsInitInput) => Promise<void>;
1114 pull: (input: VcsPullInput) => Promise<VcsPullResult>;
1115 refreshStatus: (input: VcsStatusInput) => Promise<VcsStatusResult>;
1116 onStatus: (
1117 input: VcsStatusInput,
1118 callback: (status: VcsStatusResult) => void,
1119 options?: {
1120 onResubscribe?: () => void;
1121 },
1122 ) => () => void;
1123 };
1124 git: {
1125 resolvePullRequest: (input: GitPullRequestRefInput) => Promise<GitResolvePullRequestResult>;
1126 preparePullRequestThread: (
1127 input: GitPreparePullRequestThreadInput,
1128 ) => Promise<GitPreparePullRequestThreadResult>;
1129 };
1130 review: {
1131 getDiffPreview: (input: ReviewDiffPreviewInput) => Promise<ReviewDiffPreviewResult>;
1132 };
1133 orchestration: {
1134 dispatchCommand: (command: ClientOrchestrationCommand) => Promise<{ sequence: number }>;
1135 getTurnDiff: (input: OrchestrationGetTurnDiffInput) => Promise<OrchestrationGetTurnDiffResult>;
1136 getFullThreadDiff: (
1137 input: OrchestrationGetFullThreadDiffInput,
1138 ) => Promise<OrchestrationGetFullThreadDiffResult>;
1139 getArchivedShellSnapshot: () => Promise<OrchestrationShellSnapshot>;
1140 subscribeShell: (
1141 callback: (event: OrchestrationShellStreamItem) => void,
1142 options?: {
1143 onResubscribe?: () => void;
1144 },
1145 ) => () => void;
1146 subscribeThread: (
1147 input: OrchestrationSubscribeThreadInput,
1148 callback: (event: OrchestrationThreadStreamItem) => void,
1149 options?: {
1150 onResubscribe?: () => void;
1151 },
1152 ) => () => void;
1153 };
1154 preview: {
1155 open: (input: typeof PreviewOpenInput.Encoded) => Promise<PreviewSessionSnapshot>;
1156 navigate: (input: typeof PreviewNavigateInput.Encoded) => Promise<PreviewSessionSnapshot>;
1157 refresh: (input: typeof PreviewRefreshInput.Encoded) => Promise<void>;
1158 close: (input: typeof PreviewCloseInput.Encoded) => Promise<void>;
1159 list: (input: typeof PreviewListInput.Encoded) => Promise<PreviewListResult>;
1160 reportStatus: (input: typeof PreviewReportStatusInput.Encoded) => Promise<void>;
1161 automation: {
1162 connect: (
1163 input: { clientId: string },
1164 callback: (request: PreviewAutomationRequest) => void,
1165 options?: { onResubscribe?: () => void },
1166 ) => () => void;
1167 respond: (response: PreviewAutomationResponse) => Promise<void>;
1168 reportOwner: (owner: PreviewAutomationOwner) => Promise<void>;
1169 clearOwner: (input: PreviewAutomationOwnerIdentity) => Promise<void>;
1170 };
1171 onEvent: (
1172 callback: (event: PreviewEvent) => void,
1173 options?: { onResubscribe?: () => void },
1174 ) => () => void;
1175 subscribePorts: (
1176 callback: (servers: DiscoveredLocalServerList) => void,
1177 options?: { onResubscribe?: () => void },
1178 ) => () => void;
1179 };