Open History to see the last commit
1import { z } from "zod";
2
3// ── WebSocket RPC Method Names ───────────────────────────────────────
4
5export const WS_METHODS = {
6 // Provider methods (mirrors NativeApi.providers)
7 providersStartSession: "providers.startSession",
8 providersSendTurn: "providers.sendTurn",
9 providersInterruptTurn: "providers.interruptTurn",
10 providersRespondToRequest: "providers.respondToRequest",
11 providersStopSession: "providers.stopSession",
12 providersListSessions: "providers.listSessions",
13
14 // Project registry methods
15 projectsList: "projects.list",
16 projectsAdd: "projects.add",
17 projectsRemove: "projects.remove",
18 projectsSearchEntries: "projects.searchEntries",
19 projectsUpdateScripts: "projects.updateScripts",
20
21 // Shell methods
22 shellOpenInEditor: "shell.openInEditor",
23
24 // Git methods
25 gitPull: "git.pull",
26 gitStatus: "git.status",
27 gitRunStackedAction: "git.runStackedAction",
28 gitListBranches: "git.listBranches",
29 gitCreateWorktree: "git.createWorktree",
30 gitRemoveWorktree: "git.removeWorktree",
31 gitCreateBranch: "git.createBranch",
32 gitCheckout: "git.checkout",
33 gitInit: "git.init",
34
35 // Terminal methods
36 terminalOpen: "terminal.open",
37 terminalWrite: "terminal.write",
38 terminalResize: "terminal.resize",
39 terminalClear: "terminal.clear",
40 terminalRestart: "terminal.restart",
41 terminalClose: "terminal.close",
42
43 // Server meta
44 serverGetConfig: "server.getConfig",
45 serverUpsertKeybinding: "server.upsertKeybinding",
46} as const;
47
48// ── Push Event Channels ──────────────────────────────────────────────
49
50export const WS_CHANNELS = {
51 providerEvent: "providers.event",
52 terminalEvent: "terminal.event",
53 serverWelcome: "server.welcome",
54} as const;
55
56// ── Client → Server (request) ────────────────────────────────────────
57
58export const wsRequestSchema = z.object({
59 id: z.string().min(1),
60 method: z.string().min(1),
61 params: z.unknown().optional(),
62});
63
64export type WsRequest = z.infer<typeof wsRequestSchema>;
65
66// ── Server → Client (response to request) ────────────────────────────
67
68export const wsResponseSchema = z.object({
69 id: z.string().min(1),
70 result: z.unknown().optional(),
71 error: z
72 .object({
73 message: z.string(),
74 })
75 .optional(),
76});
77
78export type WsResponse = z.infer<typeof wsResponseSchema>;
79
80// ── Server → Client (push event) ─────────────────────────────────────
81
82export const wsPushSchema = z.object({
83 type: z.literal("push"),
84 channel: z.string().min(1),
85 data: z.unknown(),
86});
87
88export type WsPush = z.infer<typeof wsPushSchema>;
89
90// ── Union of all server → client messages ─────────────────────────────
91
92export type WsServerMessage = WsResponse | WsPush;
93
94// ── Server welcome payload ───────────────────────────────────────────
95
96export const wsWelcomePayloadSchema = z.object({
97 cwd: z.string().min(1),
98 projectName: z.string().min(1),
99});
100
101export type WsWelcomePayload = z.infer<typeof wsWelcomePayloadSchema>;