Open History to see the last commit
1import type {
2 VcsSwitchRefInput,
3 VcsSwitchRefResult,
4 VcsCreateRefInput,
5 GitPreparePullRequestThreadInput,
6 GitPreparePullRequestThreadResult,
7 GitPullRequestRefInput,
8 VcsCreateWorktreeInput,
9 VcsCreateWorktreeResult,
10 VcsInitInput,
11 VcsListRefsInput,
12 VcsListRefsResult,
13 VcsPullInput,
14 VcsPullResult,
15 VcsRemoveWorktreeInput,
16 GitResolvePullRequestResult,
17 VcsStatusInput,
18 VcsStatusResult,
19 VcsCreateRefResult,
20} from "./git.ts";
21import type { FilesystemBrowseInput, FilesystemBrowseResult } from "./filesystem.ts";
22import type {
23 ProjectSearchEntriesInput,
24 ProjectSearchEntriesResult,
25 ProjectWriteFileInput,
26 ProjectWriteFileResult,
27} from "./project.ts";
28import type { ProviderInstanceId } from "./providerInstance.ts";
29import type {
30 ServerConfig,
31 ServerProviderUpdatedPayload,
32 ServerUpsertKeybindingResult,
33} from "./server.ts";
34import type {
35 TerminalClearInput,
36 TerminalCloseInput,
37 TerminalEvent,
38 TerminalOpenInput,
39 TerminalResizeInput,
40 TerminalRestartInput,
41 TerminalSessionSnapshot,
42 TerminalWriteInput,
43} from "./terminal.ts";
44import type { ServerUpsertKeybindingInput } from "./server.ts";
45import type {
46 ClientOrchestrationCommand,
47 OrchestrationGetFullThreadDiffInput,
48 OrchestrationGetFullThreadDiffResult,
49 OrchestrationGetTurnDiffInput,
50 OrchestrationGetTurnDiffResult,
51 OrchestrationShellStreamItem,
52 OrchestrationSubscribeThreadInput,
53 OrchestrationThreadStreamItem,
54} from "./orchestration.ts";
55import type { EnvironmentId } from "./baseSchemas.ts";
56import { EditorId } from "./editor.ts";
57import { ServerSettings, type ClientSettings, type ServerSettingsPatch } from "./settings.ts";
58import type {
59 SourceControlCloneRepositoryInput,
60 SourceControlCloneRepositoryResult,
61 SourceControlDiscoveryResult,
62 SourceControlPublishRepositoryInput,
63 SourceControlPublishRepositoryResult,
64 SourceControlRepositoryInfo,
65 SourceControlRepositoryLookupInput,
66} from "./sourceControl.ts";
67
68export interface ContextMenuItem<T extends string = string> {
69 id: T;
70 label: string;
71 destructive?: boolean;
72 disabled?: boolean;
73 children?: readonly ContextMenuItem<T>[];
74}
75
76export type DesktopUpdateStatus =
77 | "disabled"
78 | "idle"
79 | "checking"
80 | "up-to-date"
81 | "available"
82 | "downloading"
83 | "downloaded"
84 | "error";
85
86export type DesktopRuntimeArch = "arm64" | "x64" | "other";
87export type DesktopTheme = "light" | "dark" | "system";
88export type DesktopUpdateChannel = "latest" | "nightly";
89export type DesktopAppStageLabel = "Alpha" | "Dev" | "Nightly";
90
91export interface DesktopAppBranding {
92 baseName: string;
93 stageLabel: DesktopAppStageLabel;
94 displayName: string;
95}
96
97export interface DesktopRuntimeInfo {
98 hostArch: DesktopRuntimeArch;
99 appArch: DesktopRuntimeArch;
100 runningUnderArm64Translation: boolean;
101}
102
103export interface DesktopUpdateState {
104 enabled: boolean;
105 status: DesktopUpdateStatus;
106 channel: DesktopUpdateChannel;
107 currentVersion: string;
108 hostArch: DesktopRuntimeArch;
109 appArch: DesktopRuntimeArch;
110 runningUnderArm64Translation: boolean;
111 availableVersion: string | null;
112 downloadedVersion: string | null;
113 downloadPercent: number | null;
114 checkedAt: string | null;
115 message: string | null;
116 errorContext: "check" | "download" | "install" | null;
117 canRetry: boolean;
118}
119
120export interface DesktopUpdateActionResult {
121 accepted: boolean;
122 completed: boolean;
123 state: DesktopUpdateState;
124}
125
126export interface DesktopUpdateCheckResult {
127 checked: boolean;
128 state: DesktopUpdateState;
129}
130
131export interface DesktopEnvironmentBootstrap {
132 label: string;
133 httpBaseUrl: string | null;
134 wsBaseUrl: string | null;
135 bootstrapToken?: string;
136}
137
138export interface PersistedSavedEnvironmentRecord {
139 environmentId: EnvironmentId;
140 label: string;
141 wsBaseUrl: string;
142 httpBaseUrl: string;
143 createdAt: string;
144 lastConnectedAt: string | null;
145}
146
147export type DesktopServerExposureMode = "local-only" | "network-accessible";
148
149export interface DesktopServerExposureState {
150 mode: DesktopServerExposureMode;
151 endpointUrl: string | null;
152 advertisedHost: string | null;
153}
154
155export interface PickFolderOptions {
156 initialPath?: string | null;
157}
158
159export interface DesktopBridge {
160 getAppBranding: () => DesktopAppBranding | null;
161 getLocalEnvironmentBootstrap: () => DesktopEnvironmentBootstrap | null;
162 getClientSettings: () => Promise<ClientSettings | null>;
163 setClientSettings: (settings: ClientSettings) => Promise<void>;
164 getSavedEnvironmentRegistry: () => Promise<readonly PersistedSavedEnvironmentRecord[]>;
165 setSavedEnvironmentRegistry: (
166 records: readonly PersistedSavedEnvironmentRecord[],
167 ) => Promise<void>;
168 getSavedEnvironmentSecret: (environmentId: EnvironmentId) => Promise<string | null>;
169 setSavedEnvironmentSecret: (environmentId: EnvironmentId, secret: string) => Promise<boolean>;
170 removeSavedEnvironmentSecret: (environmentId: EnvironmentId) => Promise<void>;
171 getServerExposureState: () => Promise<DesktopServerExposureState>;
172 setServerExposureMode: (mode: DesktopServerExposureMode) => Promise<DesktopServerExposureState>;
173 pickFolder: (options?: PickFolderOptions) => Promise<string | null>;
174 confirm: (message: string) => Promise<boolean>;
175 setTheme: (theme: DesktopTheme) => Promise<void>;
176 showContextMenu: <T extends string>(
177 items: readonly ContextMenuItem<T>[],
178 position?: { x: number; y: number },
179 ) => Promise<T | null>;
180 openExternal: (url: string) => Promise<boolean>;
181 onMenuAction: (listener: (action: string) => void) => () => void;
182 getUpdateState: () => Promise<DesktopUpdateState>;
183 setUpdateChannel: (channel: DesktopUpdateChannel) => Promise<DesktopUpdateState>;
184 checkForUpdate: () => Promise<DesktopUpdateCheckResult>;
185 downloadUpdate: () => Promise<DesktopUpdateActionResult>;
186 installUpdate: () => Promise<DesktopUpdateActionResult>;
187 onUpdateState: (listener: (state: DesktopUpdateState) => void) => () => void;
188}
189
190/**
191 * APIs bound to the local app shell, not to any particular backend environment.
192 *
193 * These capabilities describe the desktop/browser host that the user is
194 * currently running: dialogs, editor/external-link opening, context menus, and
195 * app-level settings/config access. They must not be used as a proxy for
196 * "whatever environment the user is targeting", because in a multi-environment
197 * world the local shell and a selected backend environment are distinct
198 * concepts.
199 */
200export interface LocalApi {
201 dialogs: {
202 pickFolder: (options?: PickFolderOptions) => Promise<string | null>;
203 confirm: (message: string) => Promise<boolean>;
204 };
205 shell: {
206 openInEditor: (cwd: string, editor: EditorId) => Promise<void>;
207 openExternal: (url: string) => Promise<void>;
208 };
209 contextMenu: {
210 show: <T extends string>(
211 items: readonly ContextMenuItem<T>[],
212 position?: { x: number; y: number },
213 ) => Promise<T | null>;
214 };
215 persistence: {
216 getClientSettings: () => Promise<ClientSettings | null>;
217 setClientSettings: (settings: ClientSettings) => Promise<void>;
218 getSavedEnvironmentRegistry: () => Promise<readonly PersistedSavedEnvironmentRecord[]>;
219 setSavedEnvironmentRegistry: (
220 records: readonly PersistedSavedEnvironmentRecord[],
221 ) => Promise<void>;
222 getSavedEnvironmentSecret: (environmentId: EnvironmentId) => Promise<string | null>;
223 setSavedEnvironmentSecret: (environmentId: EnvironmentId, secret: string) => Promise<boolean>;
224 removeSavedEnvironmentSecret: (environmentId: EnvironmentId) => Promise<void>;
225 };
226 server: {
227 getConfig: () => Promise<ServerConfig>;
228 /**
229 * Refresh provider snapshots. When `input.instanceId` is supplied only that
230 * configured instance is probed; otherwise every configured instance is
231 * refreshed (legacy untargeted refresh).
232 */
233 refreshProviders: (input?: {
234 readonly instanceId?: ProviderInstanceId;
235 }) => Promise<ServerProviderUpdatedPayload>;
236 upsertKeybinding: (input: ServerUpsertKeybindingInput) => Promise<ServerUpsertKeybindingResult>;
237 getSettings: () => Promise<ServerSettings>;
238 updateSettings: (patch: ServerSettingsPatch) => Promise<ServerSettings>;
239 discoverSourceControl: () => Promise<SourceControlDiscoveryResult>;
240 };
241}
242
243/**
244 * APIs bound to a specific backend environment connection.
245 *
246 * These operations must always be routed with explicit environment context.
247 * They represent remote stateful capabilities such as orchestration, terminal,
248 * project, VCS, and provider operations. In multi-environment mode, each environment gets
249 * its own instance of this surface, and callers should resolve it by
250 * `environmentId` rather than reaching through the local desktop bridge.
251 */
252export interface EnvironmentApi {
253 terminal: {
254 open: (input: typeof TerminalOpenInput.Encoded) => Promise<TerminalSessionSnapshot>;
255 write: (input: typeof TerminalWriteInput.Encoded) => Promise<void>;
256 resize: (input: typeof TerminalResizeInput.Encoded) => Promise<void>;
257 clear: (input: typeof TerminalClearInput.Encoded) => Promise<void>;
258 restart: (input: typeof TerminalRestartInput.Encoded) => Promise<TerminalSessionSnapshot>;
259 close: (input: typeof TerminalCloseInput.Encoded) => Promise<void>;
260 onEvent: (callback: (event: TerminalEvent) => void) => () => void;
261 };
262 projects: {
263 searchEntries: (input: ProjectSearchEntriesInput) => Promise<ProjectSearchEntriesResult>;
264 writeFile: (input: ProjectWriteFileInput) => Promise<ProjectWriteFileResult>;
265 };
266 filesystem: {
267 browse: (input: FilesystemBrowseInput) => Promise<FilesystemBrowseResult>;
268 };
269 sourceControl: {
270 lookupRepository: (
271 input: SourceControlRepositoryLookupInput,
272 ) => Promise<SourceControlRepositoryInfo>;
273 cloneRepository: (
274 input: SourceControlCloneRepositoryInput,
275 ) => Promise<SourceControlCloneRepositoryResult>;
276 publishRepository: (
277 input: SourceControlPublishRepositoryInput,
278 ) => Promise<SourceControlPublishRepositoryResult>;
279 };
280 vcs: {
281 listRefs: (input: VcsListRefsInput) => Promise<VcsListRefsResult>;
282 createWorktree: (input: VcsCreateWorktreeInput) => Promise<VcsCreateWorktreeResult>;
283 removeWorktree: (input: VcsRemoveWorktreeInput) => Promise<void>;
284 createRef: (input: VcsCreateRefInput) => Promise<VcsCreateRefResult>;
285 switchRef: (input: VcsSwitchRefInput) => Promise<VcsSwitchRefResult>;
286 init: (input: VcsInitInput) => Promise<void>;
287 pull: (input: VcsPullInput) => Promise<VcsPullResult>;
288 refreshStatus: (input: VcsStatusInput) => Promise<VcsStatusResult>;
289 onStatus: (
290 input: VcsStatusInput,
291 callback: (status: VcsStatusResult) => void,
292 options?: {
293 onResubscribe?: () => void;
294 },
295 ) => () => void;
296 };
297 git: {
298 resolvePullRequest: (input: GitPullRequestRefInput) => Promise<GitResolvePullRequestResult>;
299 preparePullRequestThread: (
300 input: GitPreparePullRequestThreadInput,
301 ) => Promise<GitPreparePullRequestThreadResult>;
302 };
303 orchestration: {
304 dispatchCommand: (command: ClientOrchestrationCommand) => Promise<{ sequence: number }>;
305 getTurnDiff: (input: OrchestrationGetTurnDiffInput) => Promise<OrchestrationGetTurnDiffResult>;
306 getFullThreadDiff: (
307 input: OrchestrationGetFullThreadDiffInput,
308 ) => Promise<OrchestrationGetFullThreadDiffResult>;
309 subscribeShell: (
310 callback: (event: OrchestrationShellStreamItem) => void,
311 options?: {
312 onResubscribe?: () => void;
313 },
314 ) => () => void;
315 subscribeThread: (
316 input: OrchestrationSubscribeThreadInput,
317 callback: (event: OrchestrationThreadStreamItem) => void,
318 options?: {
319 onResubscribe?: () => void;
320 },
321 ) => () => void;
322 };
323}