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

ipc.ts

236 lines8.0 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 {
22 ProjectSearchEntriesInput,
23 ProjectSearchEntriesResult,
24 ProjectWriteFileInput,
25 ProjectWriteFileResult,
26} from "./project";
27import type {
28 ServerConfig,
29 ServerProviderUpdatedPayload,
30 ServerUpsertKeybindingResult,
31} from "./server";
32import type {
33 TerminalClearInput,
34 TerminalCloseInput,
35 TerminalEvent,
36 TerminalOpenInput,
37 TerminalResizeInput,
38 TerminalRestartInput,
39 TerminalSessionSnapshot,
40 TerminalWriteInput,
41} from "./terminal";
42import type { ServerUpsertKeybindingInput } from "./server";
43import type {
44 ClientOrchestrationCommand,
45 OrchestrationGetFullThreadDiffInput,
46 OrchestrationGetFullThreadDiffResult,
47 OrchestrationGetTurnDiffInput,
48 OrchestrationGetTurnDiffResult,
49 OrchestrationEvent,
50 OrchestrationReadModel,
51} from "./orchestration";
52import { EditorId } from "./editor";
53import { ServerSettings, ServerSettingsPatch } from "./settings";
54​
55export interface ContextMenuItem<T extends string = string> {
56 id: T;
57 label: string;
58 destructive?: boolean;
59 disabled?: boolean;
61​
62export type DesktopUpdateStatus =
63 | "disabled"
64 | "idle"
65 | "checking"
66 | "up-to-date"
67 | "available"
68 | "downloading"
69 | "downloaded"
70 | "error";
71​
72export type DesktopRuntimeArch = "arm64" | "x64" | "other";
73export type DesktopTheme = "light" | "dark" | "system";
74​
75export interface DesktopRuntimeInfo {
76 hostArch: DesktopRuntimeArch;
77 appArch: DesktopRuntimeArch;
78 runningUnderArm64Translation: boolean;
80​
81export interface DesktopUpdateState {
82 enabled: boolean;
83 status: DesktopUpdateStatus;
84 currentVersion: string;
85 hostArch: DesktopRuntimeArch;
86 appArch: DesktopRuntimeArch;
87 runningUnderArm64Translation: boolean;
88 availableVersion: string | null;
89 downloadedVersion: string | null;
90 downloadPercent: number | null;
91 checkedAt: string | null;
92 message: string | null;
93 errorContext: "check" | "download" | "install" | null;
94 canRetry: boolean;
96​
97export interface DesktopUpdateActionResult {
98 accepted: boolean;
99 completed: boolean;
100 state: DesktopUpdateState;
102​
103export interface DesktopUpdateCheckResult {
104 checked: boolean;
105 state: DesktopUpdateState;
107​
108export interface DesktopEnvironmentBootstrap {
109 label: string;
110 httpBaseUrl: string | null;
111 wsBaseUrl: string | null;
112 bootstrapToken?: string;
114​
115export type DesktopServerExposureMode = "local-only" | "network-accessible";
116​
117export interface DesktopServerExposureState {
118 mode: DesktopServerExposureMode;
119 endpointUrl: string | null;
120 advertisedHost: string | null;
122​
123export interface DesktopBridge {
124 getLocalEnvironmentBootstrap: () => DesktopEnvironmentBootstrap | null;
125 getServerExposureState: () => Promise<DesktopServerExposureState>;
126 setServerExposureMode: (mode: DesktopServerExposureMode) => Promise<DesktopServerExposureState>;
127 pickFolder: () => Promise<string | null>;
128 confirm: (message: string) => Promise<boolean>;
129 setTheme: (theme: DesktopTheme) => Promise<void>;
130 showContextMenu: <T extends string>(
131 items: readonly ContextMenuItem<T>[],
132 position?: { x: number; y: number },
133 ) => Promise<T | null>;
134 openExternal: (url: string) => Promise<boolean>;
135 onMenuAction: (listener: (action: string) => void) => () => void;
136 getUpdateState: () => Promise<DesktopUpdateState>;
137 checkForUpdate: () => Promise<DesktopUpdateCheckResult>;
138 downloadUpdate: () => Promise<DesktopUpdateActionResult>;
139 installUpdate: () => Promise<DesktopUpdateActionResult>;
140 onUpdateState: (listener: (state: DesktopUpdateState) => void) => () => void;
142​
143/**
144 * APIs bound to the local app shell, not to any particular backend environment.
145 *
146 * These capabilities describe the desktop/browser host that the user is
147 * currently running: dialogs, editor/external-link opening, context menus, and
148 * app-level settings/config access. They must not be used as a proxy for
149 * "whatever environment the user is targeting", because in a multi-environment
150 * world the local shell and a selected backend environment are distinct
151 * concepts.
152 */
153export interface LocalApi {
154 dialogs: {
155 pickFolder: () => Promise<string | null>;
156 confirm: (message: string) => Promise<boolean>;
157 };
158 shell: {
159 openInEditor: (cwd: string, editor: EditorId) => Promise<void>;
160 openExternal: (url: string) => Promise<void>;
161 };
162 contextMenu: {
163 show: <T extends string>(
164 items: readonly ContextMenuItem<T>[],
165 position?: { x: number; y: number },
166 ) => Promise<T | null>;
167 };
168 server: {
169 getConfig: () => Promise<ServerConfig>;
170 refreshProviders: () => Promise<ServerProviderUpdatedPayload>;
171 upsertKeybinding: (input: ServerUpsertKeybindingInput) => Promise<ServerUpsertKeybindingResult>;
172 getSettings: () => Promise<ServerSettings>;
173 updateSettings: (patch: ServerSettingsPatch) => Promise<ServerSettings>;
174 };
176​
177/**
178 * APIs bound to a specific backend environment connection.
179 *
180 * These operations must always be routed with explicit environment context.
181 * They represent remote stateful capabilities such as orchestration, terminal,
182 * project, and git operations. In multi-environment mode, each environment gets
183 * its own instance of this surface, and callers should resolve it by
184 * `environmentId` rather than reaching through the local desktop bridge.
185 */
186export interface EnvironmentApi {
187 terminal: {
188 open: (input: typeof TerminalOpenInput.Encoded) => Promise<TerminalSessionSnapshot>;
189 write: (input: typeof TerminalWriteInput.Encoded) => Promise<void>;
190 resize: (input: typeof TerminalResizeInput.Encoded) => Promise<void>;
191 clear: (input: typeof TerminalClearInput.Encoded) => Promise<void>;
192 restart: (input: typeof TerminalRestartInput.Encoded) => Promise<TerminalSessionSnapshot>;
193 close: (input: typeof TerminalCloseInput.Encoded) => Promise<void>;
194 onEvent: (callback: (event: TerminalEvent) => void) => () => void;
195 };
196 projects: {
197 searchEntries: (input: ProjectSearchEntriesInput) => Promise<ProjectSearchEntriesResult>;
198 writeFile: (input: ProjectWriteFileInput) => Promise<ProjectWriteFileResult>;
199 };
200 git: {
201 listBranches: (input: GitListBranchesInput) => Promise<GitListBranchesResult>;
202 createWorktree: (input: GitCreateWorktreeInput) => Promise<GitCreateWorktreeResult>;
203 removeWorktree: (input: GitRemoveWorktreeInput) => Promise<void>;
204 createBranch: (input: GitCreateBranchInput) => Promise<GitCreateBranchResult>;
205 checkout: (input: GitCheckoutInput) => Promise<GitCheckoutResult>;
206 init: (input: GitInitInput) => Promise<void>;
207 resolvePullRequest: (input: GitPullRequestRefInput) => Promise<GitResolvePullRequestResult>;
208 preparePullRequestThread: (
209 input: GitPreparePullRequestThreadInput,
210 ) => Promise<GitPreparePullRequestThreadResult>;
211 pull: (input: GitPullInput) => Promise<GitPullResult>;
212 refreshStatus: (input: GitStatusInput) => Promise<GitStatusResult>;
213 onStatus: (
214 input: GitStatusInput,
215 callback: (status: GitStatusResult) => void,
216 options?: {
217 onResubscribe?: () => void;
218 },
219 ) => () => void;
220 };
221 orchestration: {
222 getSnapshot: () => Promise<OrchestrationReadModel>;
223 dispatchCommand: (command: ClientOrchestrationCommand) => Promise<{ sequence: number }>;
224 getTurnDiff: (input: OrchestrationGetTurnDiffInput) => Promise<OrchestrationGetTurnDiffResult>;
225 getFullThreadDiff: (
226 input: OrchestrationGetFullThreadDiffInput,
227 ) => Promise<OrchestrationGetFullThreadDiffResult>;
228 replayEvents: (fromSequenceExclusive: number) => Promise<OrchestrationEvent[]>;
229 onDomainEvent: (
230 callback: (event: OrchestrationEvent) => void,
231 options?: {
232 onResubscribe?: () => void;
233 },
234 ) => () => void;
235 };