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

ipc.ts

291 lines10.3 KB

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