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

ipc.ts

561 lines19.8 KB

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 ServerProcessDiagnosticsResult,
32 ServerProviderUpdateInput,
33 ServerProviderUpdatedPayload,
34 ServerRemoveKeybindingResult,
35 ServerSignalProcessInput,
36 ServerSignalProcessResult,
37 ServerTraceDiagnosticsResult,
38 ServerUpsertKeybindingResult,
39} from "./server.ts";
40import type {
41 TerminalClearInput,
42 TerminalCloseInput,
43 TerminalEvent,
44 TerminalOpenInput,
45 TerminalResizeInput,
46 TerminalRestartInput,
47 TerminalSessionSnapshot,
48 TerminalWriteInput,
49} from "./terminal.ts";
50import type { ServerRemoveKeybindingInput, ServerUpsertKeybindingInput } from "./server.ts";
51import * as Schema from "effect/Schema";
52import type {
53 ClientOrchestrationCommand,
54 OrchestrationGetFullThreadDiffInput,
55 OrchestrationGetFullThreadDiffResult,
56 OrchestrationGetTurnDiffInput,
57 OrchestrationGetTurnDiffResult,
58 OrchestrationShellStreamItem,
59 OrchestrationSubscribeThreadInput,
60 OrchestrationThreadStreamItem,
61} from "./orchestration.ts";
62import { EnvironmentId } from "./baseSchemas.ts";
63import { AuthBearerBootstrapResult, AuthSessionState, AuthWebSocketTokenResult } from "./auth.ts";
64import { AdvertisedEndpoint } from "./remoteAccess.ts";
65import { EditorId } from "./editor.ts";
66import { ExecutionEnvironmentDescriptor } from "./environment.ts";
67import type { ClientSettings, ServerSettings, ServerSettingsPatch } from "./settings.ts";
68import type {
69 SourceControlCloneRepositoryInput,
70 SourceControlCloneRepositoryResult,
71 SourceControlDiscoveryResult,
72 SourceControlPublishRepositoryInput,
73 SourceControlPublishRepositoryResult,
74 SourceControlRepositoryInfo,
75 SourceControlRepositoryLookupInput,
76} from "./sourceControl.ts";
77​
78export interface ContextMenuItem<T extends string = string> {
79 id: T;
80 label: string;
81 destructive?: boolean;
82 disabled?: boolean;
83 children?: readonly ContextMenuItem<T>[];
85​
86export interface ContextMenuItemSchemaType {
87 readonly id: string;
88 readonly label: string;
89 readonly destructive?: boolean;
90 readonly disabled?: boolean;
91 readonly children?: readonly ContextMenuItemSchemaType[];
93​
94export const ContextMenuItemSchema: Schema.Codec<ContextMenuItemSchemaType> = Schema.Struct({
95 id: Schema.String,
96 label: Schema.String,
97 destructive: Schema.optionalKey(Schema.Boolean),
98 disabled: Schema.optionalKey(Schema.Boolean),
99 children: Schema.optionalKey(
100 Schema.Array(
101 Schema.suspend((): Schema.Codec<ContextMenuItemSchemaType> => ContextMenuItemSchema),
102 ),
103 ),
104});
105​
106export type DesktopUpdateStatus =
107 | "disabled"
108 | "idle"
109 | "checking"
110 | "up-to-date"
111 | "available"
112 | "downloading"
113 | "downloaded"
114 | "error";
115​
116export type DesktopRuntimeArch = "arm64" | "x64" | "other";
117export type DesktopTheme = "light" | "dark" | "system";
118export type DesktopUpdateChannel = "latest" | "nightly";
119export type DesktopAppStageLabel = "Alpha" | "Dev" | "Nightly";
120​
121export const DesktopUpdateStatusSchema = Schema.Literals([
122 "disabled",
123 "idle",
124 "checking",
125 "up-to-date",
126 "available",
127 "downloading",
128 "downloaded",
129 "error",
130]);
131export const DesktopRuntimeArchSchema = Schema.Literals(["arm64", "x64", "other"]);
132export const DesktopThemeSchema = Schema.Literals(["light", "dark", "system"]);
133export const DesktopUpdateChannelSchema = Schema.Literals(["latest", "nightly"]);
134export const DesktopAppStageLabelSchema = Schema.Literals(["Alpha", "Dev", "Nightly"]);
135​
136export interface DesktopAppBranding {
137 baseName: string;
138 stageLabel: DesktopAppStageLabel;
139 displayName: string;
141​
142export const DesktopAppBrandingSchema = Schema.Struct({
143 baseName: Schema.String,
144 stageLabel: DesktopAppStageLabelSchema,
145 displayName: Schema.String,
146});
147​
148export interface DesktopRuntimeInfo {
149 hostArch: DesktopRuntimeArch;
150 appArch: DesktopRuntimeArch;
151 runningUnderArm64Translation: boolean;
153​
154export const DesktopRuntimeInfoSchema = Schema.Struct({
155 hostArch: DesktopRuntimeArchSchema,
156 appArch: DesktopRuntimeArchSchema,
157 runningUnderArm64Translation: Schema.Boolean,
158});
159​
160export interface DesktopUpdateState {
161 enabled: boolean;
162 status: DesktopUpdateStatus;
163 channel: DesktopUpdateChannel;
164 currentVersion: string;
165 hostArch: DesktopRuntimeArch;
166 appArch: DesktopRuntimeArch;
167 runningUnderArm64Translation: boolean;
168 availableVersion: string | null;
169 downloadedVersion: string | null;
170 downloadPercent: number | null;
171 checkedAt: string | null;
172 message: string | null;
173 errorContext: "check" | "download" | "install" | null;
174 canRetry: boolean;
176​
177export const DesktopUpdateStateSchema = Schema.Struct({
178 enabled: Schema.Boolean,
179 status: DesktopUpdateStatusSchema,
180 channel: DesktopUpdateChannelSchema,
181 currentVersion: Schema.String,
182 hostArch: DesktopRuntimeArchSchema,
183 appArch: DesktopRuntimeArchSchema,
184 runningUnderArm64Translation: Schema.Boolean,
185 availableVersion: Schema.NullOr(Schema.String),
186 downloadedVersion: Schema.NullOr(Schema.String),
187 downloadPercent: Schema.NullOr(Schema.Number),
188 checkedAt: Schema.NullOr(Schema.String),
189 message: Schema.NullOr(Schema.String),
190 errorContext: Schema.NullOr(Schema.Literals(["check", "download", "install"])),
191 canRetry: Schema.Boolean,
192});
193​
194export interface DesktopUpdateActionResult {
195 accepted: boolean;
196 completed: boolean;
197 state: DesktopUpdateState;
199​
200export const DesktopUpdateActionResultSchema = Schema.Struct({
201 accepted: Schema.Boolean,
202 completed: Schema.Boolean,
203 state: DesktopUpdateStateSchema,
204});
205​
206export interface DesktopUpdateCheckResult {
207 checked: boolean;
208 state: DesktopUpdateState;
210​
211export const DesktopUpdateCheckResultSchema = Schema.Struct({
212 checked: Schema.Boolean,
213 state: DesktopUpdateStateSchema,
214});
215​
216export interface DesktopEnvironmentBootstrap {
217 label: string;
218 httpBaseUrl: string | null;
219 wsBaseUrl: string | null;
220 bootstrapToken?: string;
222​
223export const DesktopEnvironmentBootstrapSchema = Schema.Struct({
224 label: Schema.String,
225 httpBaseUrl: Schema.NullOr(Schema.String),
226 wsBaseUrl: Schema.NullOr(Schema.String),
227 bootstrapToken: Schema.optionalKey(Schema.String),
228});
229​
230export const DesktopSshEnvironmentTargetSchema = Schema.Struct({
231 alias: Schema.String,
232 hostname: Schema.String,
233 username: Schema.NullOr(Schema.String),
234 port: Schema.NullOr(Schema.Number),
235});
236export type DesktopSshEnvironmentTarget = typeof DesktopSshEnvironmentTargetSchema.Type;
237​
238export type DesktopSshHostSource = "ssh-config" | "known-hosts";
239export const DesktopSshHostSourceSchema = Schema.Literals(["ssh-config", "known-hosts"]);
240​
241export interface DesktopDiscoveredSshHost extends DesktopSshEnvironmentTarget {
242 source: DesktopSshHostSource;
244​
245export const DesktopDiscoveredSshHostSchema = Schema.Struct({
246 alias: Schema.String,
247 hostname: Schema.String,
248 username: Schema.NullOr(Schema.String),
249 port: Schema.NullOr(Schema.Number),
250 source: DesktopSshHostSourceSchema,
251});
252​
253export interface DesktopSshEnvironmentBootstrap {
254 target: DesktopSshEnvironmentTarget;
255 httpBaseUrl: string;
256 wsBaseUrl: string;
257 pairingToken: string | null;
258 remotePort?: number;
259 remoteServerKind?: "external" | "managed";
261​
262export const DesktopSshEnvironmentBootstrapSchema = Schema.Struct({
263 target: DesktopSshEnvironmentTargetSchema,
264 httpBaseUrl: Schema.String,
265 wsBaseUrl: Schema.String,
266 pairingToken: Schema.NullOr(Schema.String),
267 remotePort: Schema.optionalKey(Schema.Number),
268 remoteServerKind: Schema.optionalKey(Schema.Literals(["external", "managed"])),
269});
270​
271export interface DesktopSshPasswordPromptRequest {
272 requestId: string;
273 destination: string;
274 username: string | null;
275 prompt: string;
276 expiresAt: string;
278​
279export const DesktopSshPasswordPromptRequestSchema = Schema.Struct({
280 requestId: Schema.String,
281 destination: Schema.String,
282 username: Schema.NullOr(Schema.String),
283 prompt: Schema.String,
284 expiresAt: Schema.String,
285});
286​
287export const DesktopSshPasswordPromptCancelledType = "ssh-password-prompt-cancelled" as const;
288​
289export const DesktopSshPasswordPromptCancelledResultSchema = Schema.Struct({
290 type: Schema.Literal(DesktopSshPasswordPromptCancelledType),
291 message: Schema.String,
292});
293​
294export const DesktopSshEnvironmentEnsureOptionsSchema = Schema.Struct({
295 issuePairingToken: Schema.optionalKey(Schema.Boolean),
296});
297​
298export const DesktopSshEnvironmentEnsureInputSchema = Schema.Struct({
299 target: DesktopSshEnvironmentTargetSchema,
300 options: Schema.optionalKey(DesktopSshEnvironmentEnsureOptionsSchema),
301});
302​
303export const DesktopSshEnvironmentEnsureResultSchema = Schema.Union([
304 DesktopSshEnvironmentBootstrapSchema,
305 DesktopSshPasswordPromptCancelledResultSchema,
306]);
307​
308export const DesktopSshHttpBaseUrlInputSchema = Schema.Struct({
309 httpBaseUrl: Schema.String,
310});
311​
312export const DesktopSshBearerRequestInputSchema = Schema.Struct({
313 httpBaseUrl: Schema.String,
314 bearerToken: Schema.String,
315});
316​
317export const DesktopSshBearerBootstrapInputSchema = Schema.Struct({
318 httpBaseUrl: Schema.String,
319 credential: Schema.String,
320});
321​
322export const DesktopSshPasswordPromptResolutionInputSchema = Schema.Struct({
323 requestId: Schema.String,
324 password: Schema.NullOr(Schema.String),
325});
326​
327export const PersistedSavedEnvironmentRecordSchema = Schema.Struct({
328 environmentId: EnvironmentId,
329 label: Schema.String,
330 wsBaseUrl: Schema.String,
331 httpBaseUrl: Schema.String,
332 createdAt: Schema.String,
333 lastConnectedAt: Schema.NullOr(Schema.String),
334 desktopSsh: Schema.optionalKey(DesktopSshEnvironmentTargetSchema),
335});
336export type PersistedSavedEnvironmentRecord = typeof PersistedSavedEnvironmentRecordSchema.Type;
337​
338export type DesktopServerExposureMode = "local-only" | "network-accessible";
339​
340export const DesktopServerExposureModeSchema = Schema.Literals([
341 "local-only",
342 "network-accessible",
343]);
344​
345export interface DesktopServerExposureState {
346 mode: DesktopServerExposureMode;
347 endpointUrl: string | null;
348 advertisedHost: string | null;
349 tailscaleServeEnabled: boolean;
350 tailscaleServePort: number;
352​
353export const DesktopServerExposureStateSchema = Schema.Struct({
354 mode: DesktopServerExposureModeSchema,
355 endpointUrl: Schema.NullOr(Schema.String),
356 advertisedHost: Schema.NullOr(Schema.String),
357 tailscaleServeEnabled: Schema.Boolean,
358 tailscaleServePort: Schema.Number,
359});
360​
361export interface PickFolderOptions {
362 initialPath?: string | null;
364​
365export const PickFolderOptionsSchema = Schema.Struct({
366 initialPath: Schema.optionalKey(Schema.NullOr(Schema.String)),
367});
368​
369export interface DesktopBridge {
370 getAppBranding: () => DesktopAppBranding | null;
371 getLocalEnvironmentBootstrap: () => DesktopEnvironmentBootstrap | null;
372 getClientSettings: () => Promise<ClientSettings | null>;
373 setClientSettings: (settings: ClientSettings) => Promise<void>;
374 getSavedEnvironmentRegistry: () => Promise<readonly PersistedSavedEnvironmentRecord[]>;
375 setSavedEnvironmentRegistry: (
376 records: readonly PersistedSavedEnvironmentRecord[],
377 ) => Promise<void>;
378 getSavedEnvironmentSecret: (environmentId: EnvironmentId) => Promise<string | null>;
379 setSavedEnvironmentSecret: (environmentId: EnvironmentId, secret: string) => Promise<boolean>;
380 removeSavedEnvironmentSecret: (environmentId: EnvironmentId) => Promise<void>;
381 discoverSshHosts: () => Promise<readonly DesktopDiscoveredSshHost[]>;
382 ensureSshEnvironment: (
383 target: DesktopSshEnvironmentTarget,
384 options?: { issuePairingToken?: boolean },
385 ) => Promise<DesktopSshEnvironmentBootstrap>;
386 disconnectSshEnvironment: (target: DesktopSshEnvironmentTarget) => Promise<void>;
387 fetchSshEnvironmentDescriptor: (httpBaseUrl: string) => Promise<ExecutionEnvironmentDescriptor>;
388 bootstrapSshBearerSession: (
389 httpBaseUrl: string,
390 credential: string,
391 ) => Promise<AuthBearerBootstrapResult>;
392 fetchSshSessionState: (httpBaseUrl: string, bearerToken: string) => Promise<AuthSessionState>;
393 issueSshWebSocketToken: (
394 httpBaseUrl: string,
395 bearerToken: string,
396 ) => Promise<AuthWebSocketTokenResult>;
397 onSshPasswordPrompt: (listener: (request: DesktopSshPasswordPromptRequest) => void) => () => void;
398 resolveSshPasswordPrompt: (requestId: string, password: string | null) => Promise<void>;
399 getServerExposureState: () => Promise<DesktopServerExposureState>;
400 setServerExposureMode: (mode: DesktopServerExposureMode) => Promise<DesktopServerExposureState>;
401 setTailscaleServeEnabled: (input: {
402 readonly enabled: boolean;
403 readonly port?: number;
404 }) => Promise<DesktopServerExposureState>;
405 getAdvertisedEndpoints: () => Promise<readonly AdvertisedEndpoint[]>;
406 pickFolder: (options?: PickFolderOptions) => Promise<string | null>;
407 confirm: (message: string) => Promise<boolean>;
408 setTheme: (theme: DesktopTheme) => Promise<void>;
409 showContextMenu: <T extends string>(
410 items: readonly ContextMenuItem<T>[],
411 position?: { x: number; y: number },
412 ) => Promise<T | null>;
413 openExternal: (url: string) => Promise<boolean>;
414 onMenuAction: (listener: (action: string) => void) => () => void;
415 getUpdateState: () => Promise<DesktopUpdateState>;
416 setUpdateChannel: (channel: DesktopUpdateChannel) => Promise<DesktopUpdateState>;
417 checkForUpdate: () => Promise<DesktopUpdateCheckResult>;
418 downloadUpdate: () => Promise<DesktopUpdateActionResult>;
419 installUpdate: () => Promise<DesktopUpdateActionResult>;
420 onUpdateState: (listener: (state: DesktopUpdateState) => void) => () => void;
422​
423/**
424 * APIs bound to the local app shell, not to any particular backend environment.
425 *
426 * These capabilities describe the desktop/browser host that the user is
427 * currently running: dialogs, editor/external-link opening, context menus, and
428 * app-level settings/config access. They must not be used as a proxy for
429 * "whatever environment the user is targeting", because in a multi-environment
430 * world the local shell and a selected backend environment are distinct
431 * concepts.
432 */
433export interface LocalApi {
434 dialogs: {
435 pickFolder: (options?: PickFolderOptions) => Promise<string | null>;
436 confirm: (message: string) => Promise<boolean>;
437 };
438 shell: {
439 openInEditor: (cwd: string, editor: EditorId) => Promise<void>;
440 openExternal: (url: string) => Promise<void>;
441 };
442 contextMenu: {
443 show: <T extends string>(
444 items: readonly ContextMenuItem<T>[],
445 position?: { x: number; y: number },
446 ) => Promise<T | null>;
447 };
448 persistence: {
449 getClientSettings: () => Promise<ClientSettings | null>;
450 setClientSettings: (settings: ClientSettings) => Promise<void>;
451 getSavedEnvironmentRegistry: () => Promise<readonly PersistedSavedEnvironmentRecord[]>;
452 setSavedEnvironmentRegistry: (
453 records: readonly PersistedSavedEnvironmentRecord[],
454 ) => Promise<void>;
455 getSavedEnvironmentSecret: (environmentId: EnvironmentId) => Promise<string | null>;
456 setSavedEnvironmentSecret: (environmentId: EnvironmentId, secret: string) => Promise<boolean>;
457 removeSavedEnvironmentSecret: (environmentId: EnvironmentId) => Promise<void>;
458 };
459 server: {
460 getConfig: () => Promise<ServerConfig>;
461 /**
462 * Refresh provider snapshots. When `input.instanceId` is supplied only that
463 * configured instance is probed; otherwise every configured instance is
464 * refreshed (legacy untargeted refresh).
465 */
466 refreshProviders: (input?: {
467 readonly instanceId?: ProviderInstanceId;
468 }) => Promise<ServerProviderUpdatedPayload>;
469 updateProvider: (input: ServerProviderUpdateInput) => Promise<ServerProviderUpdatedPayload>;
470 upsertKeybinding: (input: ServerUpsertKeybindingInput) => Promise<ServerUpsertKeybindingResult>;
471 removeKeybinding: (input: ServerRemoveKeybindingInput) => Promise<ServerRemoveKeybindingResult>;
472 getSettings: () => Promise<ServerSettings>;
473 updateSettings: (patch: ServerSettingsPatch) => Promise<ServerSettings>;
474 discoverSourceControl: () => Promise<SourceControlDiscoveryResult>;
475 getTraceDiagnostics: () => Promise<ServerTraceDiagnosticsResult>;
476 getProcessDiagnostics: () => Promise<ServerProcessDiagnosticsResult>;
477 signalProcess: (input: ServerSignalProcessInput) => Promise<ServerSignalProcessResult>;
478 };
480​
481/**
482 * APIs bound to a specific backend environment connection.
483 *
484 * These operations must always be routed with explicit environment context.
485 * They represent remote stateful capabilities such as orchestration, terminal,
486 * project, VCS, and provider operations. In multi-environment mode, each environment gets
487 * its own instance of this surface, and callers should resolve it by
488 * `environmentId` rather than reaching through the local desktop bridge.
489 */
490export interface EnvironmentApi {
491 terminal: {
492 open: (input: typeof TerminalOpenInput.Encoded) => Promise<TerminalSessionSnapshot>;
493 write: (input: typeof TerminalWriteInput.Encoded) => Promise<void>;
494 resize: (input: typeof TerminalResizeInput.Encoded) => Promise<void>;
495 clear: (input: typeof TerminalClearInput.Encoded) => Promise<void>;
496 restart: (input: typeof TerminalRestartInput.Encoded) => Promise<TerminalSessionSnapshot>;
497 close: (input: typeof TerminalCloseInput.Encoded) => Promise<void>;
498 onEvent: (callback: (event: TerminalEvent) => void) => () => void;
499 };
500 projects: {
501 searchEntries: (input: ProjectSearchEntriesInput) => Promise<ProjectSearchEntriesResult>;
502 writeFile: (input: ProjectWriteFileInput) => Promise<ProjectWriteFileResult>;
503 };
504 filesystem: {
505 browse: (input: FilesystemBrowseInput) => Promise<FilesystemBrowseResult>;
506 };
507 sourceControl: {
508 lookupRepository: (
509 input: SourceControlRepositoryLookupInput,
510 ) => Promise<SourceControlRepositoryInfo>;
511 cloneRepository: (
512 input: SourceControlCloneRepositoryInput,
513 ) => Promise<SourceControlCloneRepositoryResult>;
514 publishRepository: (
515 input: SourceControlPublishRepositoryInput,
516 ) => Promise<SourceControlPublishRepositoryResult>;
517 };
518 vcs: {
519 listRefs: (input: VcsListRefsInput) => Promise<VcsListRefsResult>;
520 createWorktree: (input: VcsCreateWorktreeInput) => Promise<VcsCreateWorktreeResult>;
521 removeWorktree: (input: VcsRemoveWorktreeInput) => Promise<void>;
522 createRef: (input: VcsCreateRefInput) => Promise<VcsCreateRefResult>;
523 switchRef: (input: VcsSwitchRefInput) => Promise<VcsSwitchRefResult>;
524 init: (input: VcsInitInput) => Promise<void>;
525 pull: (input: VcsPullInput) => Promise<VcsPullResult>;
526 refreshStatus: (input: VcsStatusInput) => Promise<VcsStatusResult>;
527 onStatus: (
528 input: VcsStatusInput,
529 callback: (status: VcsStatusResult) => void,
530 options?: {
531 onResubscribe?: () => void;
532 },
533 ) => () => void;
534 };
535 git: {
536 resolvePullRequest: (input: GitPullRequestRefInput) => Promise<GitResolvePullRequestResult>;
537 preparePullRequestThread: (
538 input: GitPreparePullRequestThreadInput,
539 ) => Promise<GitPreparePullRequestThreadResult>;
540 };
541 orchestration: {
542 dispatchCommand: (command: ClientOrchestrationCommand) => Promise<{ sequence: number }>;
543 getTurnDiff: (input: OrchestrationGetTurnDiffInput) => Promise<OrchestrationGetTurnDiffResult>;
544 getFullThreadDiff: (
545 input: OrchestrationGetFullThreadDiffInput,
546 ) => Promise<OrchestrationGetFullThreadDiffResult>;
547 subscribeShell: (
548 callback: (event: OrchestrationShellStreamItem) => void,
549 options?: {
550 onResubscribe?: () => void;
551 },
552 ) => () => void;
553 subscribeThread: (
554 input: OrchestrationSubscribeThreadInput,
555 callback: (event: OrchestrationThreadStreamItem) => void,
556 options?: {
557 onResubscribe?: () => void;
558 },
559 ) => () => void;
560 };