promptmic 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +287 -0
- package/apps/server/dist/config-store.js +15 -0
- package/apps/server/dist/http/local-only-middleware.js +10 -0
- package/apps/server/dist/http/routes/config-routes.js +21 -0
- package/apps/server/dist/http/routes/filesystem-routes.js +28 -0
- package/apps/server/dist/http/routes/system-routes.js +16 -0
- package/apps/server/dist/http/static-assets.js +12 -0
- package/apps/server/dist/http/types.js +1 -0
- package/apps/server/dist/http-routes.js +15 -0
- package/apps/server/dist/index.js +54 -0
- package/apps/server/dist/main.js +8 -0
- package/apps/server/dist/pty-spawner.js +72 -0
- package/apps/server/dist/runtime-config.js +108 -0
- package/apps/server/dist/server-lifecycle.js +37 -0
- package/apps/server/dist/server-types.js +1 -0
- package/apps/server/dist/session-runtime.js +120 -0
- package/apps/web/dist/assets/DirectoryPickerDialog-D7IDk0pz.js +1 -0
- package/apps/web/dist/assets/SettingsDialog-uQLxj7UI.js +1 -0
- package/apps/web/dist/assets/index-BBNxXHaX.js +5 -0
- package/apps/web/dist/assets/index-G1_MX_Dd.css +1 -0
- package/apps/web/dist/assets/react-vendor-DQ3p2tNP.js +40 -0
- package/apps/web/dist/assets/scroll-area-C8DJNmaJ.js +1 -0
- package/apps/web/dist/assets/terminal-Beg8tuEN.css +32 -0
- package/apps/web/dist/assets/terminal-CnuCQtKf.js +9 -0
- package/apps/web/dist/assets/ui-vendor-Btc0UVaC.js +155 -0
- package/apps/web/dist/index.html +20 -0
- package/bin/termspeak-lib.mjs +189 -0
- package/bin/termspeak.mjs +9 -0
- package/config.example.json +21 -0
- package/package.json +70 -0
- package/packages/shared/dist/index.d.ts +2 -0
- package/packages/shared/dist/index.js +2 -0
- package/packages/shared/dist/provider.d.ts +85 -0
- package/packages/shared/dist/provider.js +13 -0
- package/packages/shared/dist/ws-messages.d.ts +219 -0
- package/packages/shared/dist/ws-messages.js +56 -0
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { spawn } from 'node:child_process';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
|
|
7
|
+
const ROOT_DIR = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
8
|
+
const SERVER_ENTRY = path.join(ROOT_DIR, 'apps/server/dist/index.js');
|
|
9
|
+
const DEFAULT_CONFIG_PATH = path.join(homedir(), '.term-speak', 'config.json');
|
|
10
|
+
|
|
11
|
+
export function readVersion() {
|
|
12
|
+
try {
|
|
13
|
+
const packageJson = JSON.parse(readFileSync(path.join(ROOT_DIR, 'package.json'), 'utf-8'));
|
|
14
|
+
return typeof packageJson.version === 'string' ? packageJson.version : '0.0.0';
|
|
15
|
+
} catch {
|
|
16
|
+
return '0.0.0';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function getHelpText() {
|
|
21
|
+
return `TermSpeak
|
|
22
|
+
|
|
23
|
+
Usage:
|
|
24
|
+
termspeak [options]
|
|
25
|
+
|
|
26
|
+
Options:
|
|
27
|
+
--port <number> Port to bind the local server (default: 3001)
|
|
28
|
+
--host <host> Host to bind the local server (default: 127.0.0.1)
|
|
29
|
+
--allow-remote Allow binding to non-local hosts and disable local-only protections
|
|
30
|
+
--open Open the browser after the server starts
|
|
31
|
+
--no-open Do not open the browser after the server starts (default)
|
|
32
|
+
--config <path> Path to the config file (default: ${DEFAULT_CONFIG_PATH})
|
|
33
|
+
--cwd <path> Default working directory for new sessions
|
|
34
|
+
--help, -h Show this help message
|
|
35
|
+
--version, -v Show the current version
|
|
36
|
+
`;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function printHelp() {
|
|
40
|
+
console.log(getHelpText());
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function parseArgs(argv) {
|
|
44
|
+
const options = {
|
|
45
|
+
open: false,
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const takeValue = (flag, index) => {
|
|
49
|
+
const value = argv[index + 1];
|
|
50
|
+
if (!value || value.startsWith('-')) {
|
|
51
|
+
throw new Error(`Missing value for ${flag}.`);
|
|
52
|
+
}
|
|
53
|
+
return value;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
57
|
+
const arg = argv[i];
|
|
58
|
+
|
|
59
|
+
if (arg === '--help' || arg === '-h') {
|
|
60
|
+
options.help = true;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (arg === '--version' || arg === '-v') {
|
|
65
|
+
options.version = true;
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (arg === '--open') {
|
|
70
|
+
options.open = true;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (arg === '--allow-remote') {
|
|
75
|
+
options.allowRemote = true;
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (arg === '--no-open') {
|
|
80
|
+
options.open = false;
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (arg === '--port' || arg.startsWith('--port=')) {
|
|
85
|
+
const raw = arg.includes('=') ? arg.slice('--port='.length) : takeValue(arg, i++);
|
|
86
|
+
const port = Number(raw);
|
|
87
|
+
if (!Number.isInteger(port) || port <= 0 || port > 65535) {
|
|
88
|
+
throw new Error(`Invalid port: ${raw}`);
|
|
89
|
+
}
|
|
90
|
+
options.port = port;
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (arg === '--host' || arg.startsWith('--host=')) {
|
|
95
|
+
const host = arg.includes('=') ? arg.slice('--host='.length) : takeValue(arg, i++);
|
|
96
|
+
options.host = host;
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (arg === '--config' || arg.startsWith('--config=')) {
|
|
101
|
+
const configPath = arg.includes('=') ? arg.slice('--config='.length) : takeValue(arg, i++);
|
|
102
|
+
options.configPath = path.resolve(configPath);
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (arg === '--cwd' || arg.startsWith('--cwd=')) {
|
|
107
|
+
const cwd = arg.includes('=') ? arg.slice('--cwd='.length) : takeValue(arg, i++);
|
|
108
|
+
options.cwd = path.resolve(cwd);
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
throw new Error(`Unknown argument: ${arg}`);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return options;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function openBrowser(url) {
|
|
119
|
+
const platform = process.platform;
|
|
120
|
+
|
|
121
|
+
if (platform === 'darwin') {
|
|
122
|
+
const child = spawn('open', [url], { detached: true, stdio: 'ignore' });
|
|
123
|
+
child.unref();
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (platform === 'win32') {
|
|
128
|
+
const child = spawn('cmd', ['/c', 'start', '', url], { detached: true, stdio: 'ignore' });
|
|
129
|
+
child.unref();
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const child = spawn('xdg-open', [url], { detached: true, stdio: 'ignore' });
|
|
134
|
+
child.unref();
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export async function main(argv = process.argv.slice(2)) {
|
|
138
|
+
const options = parseArgs(argv);
|
|
139
|
+
|
|
140
|
+
if (options.help) {
|
|
141
|
+
printHelp();
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (options.version) {
|
|
146
|
+
console.log(readVersion());
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (!existsSync(SERVER_ENTRY)) {
|
|
151
|
+
throw new Error('TermSpeak is not built yet. Run `npm run build` first.');
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const { startServer } = await import(SERVER_ENTRY);
|
|
155
|
+
const started = await startServer({
|
|
156
|
+
port: options.port,
|
|
157
|
+
host: options.host,
|
|
158
|
+
workdir: options.cwd,
|
|
159
|
+
configPath: options.configPath,
|
|
160
|
+
preferUserConfig: !options.configPath,
|
|
161
|
+
allowRemote: options.allowRemote,
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
console.log(`TermSpeak running at ${started.url}`);
|
|
165
|
+
console.log(`Config file: ${started.configPath}`);
|
|
166
|
+
console.log('Press Ctrl+C to stop.');
|
|
167
|
+
|
|
168
|
+
if (options.open) {
|
|
169
|
+
openBrowser(started.url);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const stop = async () => {
|
|
173
|
+
process.off('SIGINT', handleSigint);
|
|
174
|
+
process.off('SIGTERM', handleSigterm);
|
|
175
|
+
await started.close();
|
|
176
|
+
process.exit(0);
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
const handleSigint = () => {
|
|
180
|
+
void stop();
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
const handleSigterm = () => {
|
|
184
|
+
void stop();
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
process.on('SIGINT', handleSigint);
|
|
188
|
+
process.on('SIGTERM', handleSigterm);
|
|
189
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"providers": {
|
|
3
|
+
"claude": {
|
|
4
|
+
"label": "Claude Code CLI",
|
|
5
|
+
"executionMode": "direct",
|
|
6
|
+
"command": "claude",
|
|
7
|
+
"args": [],
|
|
8
|
+
"env": {
|
|
9
|
+
"CLAUDE_CONFIG_DIR": "~/.claude"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"codex": {
|
|
13
|
+
"label": "Codex CLI",
|
|
14
|
+
"executionMode": "direct",
|
|
15
|
+
"command": "codex",
|
|
16
|
+
"args": [],
|
|
17
|
+
"env": {}
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"defaultProvider": "claude"
|
|
21
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "promptmic",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Voice-first local UI for terminal-based AI coding assistants.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"ai",
|
|
8
|
+
"assistant",
|
|
9
|
+
"cli",
|
|
10
|
+
"voice",
|
|
11
|
+
"terminal",
|
|
12
|
+
"pty",
|
|
13
|
+
"codex",
|
|
14
|
+
"claude",
|
|
15
|
+
"aider"
|
|
16
|
+
],
|
|
17
|
+
"homepage": "https://github.com/lucasaclima03/term-speak#readme",
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/lucasaclima03/term-speak/issues"
|
|
20
|
+
},
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/lucasaclima03/term-speak.git"
|
|
24
|
+
},
|
|
25
|
+
"bin": {
|
|
26
|
+
"promptmic": "bin/termspeak.mjs"
|
|
27
|
+
},
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=20"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"bin/termspeak.mjs",
|
|
33
|
+
"bin/termspeak-lib.mjs",
|
|
34
|
+
"apps/server/dist",
|
|
35
|
+
"apps/web/dist",
|
|
36
|
+
"packages/shared/dist",
|
|
37
|
+
"LICENSE",
|
|
38
|
+
"README.md",
|
|
39
|
+
"config.example.json"
|
|
40
|
+
],
|
|
41
|
+
"workspaces": [
|
|
42
|
+
"apps/server",
|
|
43
|
+
"apps/web",
|
|
44
|
+
"packages/*"
|
|
45
|
+
],
|
|
46
|
+
"scripts": {
|
|
47
|
+
"dev": "npm run build -w packages/shared && concurrently -n shared,server,web -c magenta,cyan,green \"npm run dev -w packages/shared\" \"npm run dev -w apps/server\" \"npm run dev -w apps/web\"",
|
|
48
|
+
"dev:shared": "npm run dev -w packages/shared",
|
|
49
|
+
"dev:server": "npm run dev -w apps/server",
|
|
50
|
+
"dev:web": "npm run dev -w apps/web",
|
|
51
|
+
"clean": "rm -rf apps/server/dist apps/web/dist packages/shared/dist",
|
|
52
|
+
"build": "npm run build -w packages/shared && npm run build -w apps/server && npm run build -w apps/web",
|
|
53
|
+
"test": "npm run build -w packages/shared && vitest run",
|
|
54
|
+
"test:watch": "npm run build -w packages/shared && vitest",
|
|
55
|
+
"prepack": "npm run clean && npm run build",
|
|
56
|
+
"start": "node ./bin/termspeak.mjs",
|
|
57
|
+
"start:repo": "node ./bin/termspeak.mjs --config ./config.json",
|
|
58
|
+
"start:open": "node ./bin/termspeak.mjs --open"
|
|
59
|
+
},
|
|
60
|
+
"dependencies": {
|
|
61
|
+
"express": "^4.21.2",
|
|
62
|
+
"node-pty": "^1.1.0-beta34",
|
|
63
|
+
"ws": "^8.18.0",
|
|
64
|
+
"zod": "^3.24.2"
|
|
65
|
+
},
|
|
66
|
+
"devDependencies": {
|
|
67
|
+
"concurrently": "^9.1.2",
|
|
68
|
+
"vitest": "^4.1.0"
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { providerExecutionModeSchema, providerEntrySchema, configSchema, type ProviderExecutionMode, type ProviderEntry, type Config, type ProviderInfo, type ProviderConfig, type FullConfig, type ApiInfo, } from './provider.js';
|
|
2
|
+
export { startSessionSchema, inputSchema, resizeSchema, stopSessionSchema, wsCommandSchema, sessionStartedSchema, outputSchema, sessionExitSchema, errorSchema, wsEventSchema, type StartSession, type Input, type Resize, type StopSession, type WsCommand, type SessionStarted, type Output, type SessionExit, type WsError, type WsEvent, } from './ws-messages.js';
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { providerExecutionModeSchema, providerEntrySchema, configSchema, } from './provider.js';
|
|
2
|
+
export { startSessionSchema, inputSchema, resizeSchema, stopSessionSchema, wsCommandSchema, sessionStartedSchema, outputSchema, sessionExitSchema, errorSchema, wsEventSchema, } from './ws-messages.js';
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const providerExecutionModeSchema: z.ZodEnum<["direct", "shell"]>;
|
|
3
|
+
export declare const providerEntrySchema: z.ZodObject<{
|
|
4
|
+
label: z.ZodString;
|
|
5
|
+
executionMode: z.ZodDefault<z.ZodEnum<["direct", "shell"]>>;
|
|
6
|
+
command: z.ZodString;
|
|
7
|
+
args: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
8
|
+
env: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
9
|
+
}, "strip", z.ZodTypeAny, {
|
|
10
|
+
label: string;
|
|
11
|
+
executionMode: "direct" | "shell";
|
|
12
|
+
command: string;
|
|
13
|
+
args: string[];
|
|
14
|
+
env: Record<string, string>;
|
|
15
|
+
}, {
|
|
16
|
+
label: string;
|
|
17
|
+
command: string;
|
|
18
|
+
executionMode?: "direct" | "shell" | undefined;
|
|
19
|
+
args?: string[] | undefined;
|
|
20
|
+
env?: Record<string, string> | undefined;
|
|
21
|
+
}>;
|
|
22
|
+
export declare const configSchema: z.ZodObject<{
|
|
23
|
+
providers: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
24
|
+
label: z.ZodString;
|
|
25
|
+
executionMode: z.ZodDefault<z.ZodEnum<["direct", "shell"]>>;
|
|
26
|
+
command: z.ZodString;
|
|
27
|
+
args: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
28
|
+
env: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
29
|
+
}, "strip", z.ZodTypeAny, {
|
|
30
|
+
label: string;
|
|
31
|
+
executionMode: "direct" | "shell";
|
|
32
|
+
command: string;
|
|
33
|
+
args: string[];
|
|
34
|
+
env: Record<string, string>;
|
|
35
|
+
}, {
|
|
36
|
+
label: string;
|
|
37
|
+
command: string;
|
|
38
|
+
executionMode?: "direct" | "shell" | undefined;
|
|
39
|
+
args?: string[] | undefined;
|
|
40
|
+
env?: Record<string, string> | undefined;
|
|
41
|
+
}>>;
|
|
42
|
+
defaultProvider: z.ZodOptional<z.ZodString>;
|
|
43
|
+
}, "strip", z.ZodTypeAny, {
|
|
44
|
+
providers: Record<string, {
|
|
45
|
+
label: string;
|
|
46
|
+
executionMode: "direct" | "shell";
|
|
47
|
+
command: string;
|
|
48
|
+
args: string[];
|
|
49
|
+
env: Record<string, string>;
|
|
50
|
+
}>;
|
|
51
|
+
defaultProvider?: string | undefined;
|
|
52
|
+
}, {
|
|
53
|
+
providers: Record<string, {
|
|
54
|
+
label: string;
|
|
55
|
+
command: string;
|
|
56
|
+
executionMode?: "direct" | "shell" | undefined;
|
|
57
|
+
args?: string[] | undefined;
|
|
58
|
+
env?: Record<string, string> | undefined;
|
|
59
|
+
}>;
|
|
60
|
+
defaultProvider?: string | undefined;
|
|
61
|
+
}>;
|
|
62
|
+
export type ProviderEntry = z.infer<typeof providerEntrySchema>;
|
|
63
|
+
export type Config = z.infer<typeof configSchema>;
|
|
64
|
+
export type ProviderExecutionMode = z.infer<typeof providerExecutionModeSchema>;
|
|
65
|
+
export type ProviderInfo = {
|
|
66
|
+
id: string;
|
|
67
|
+
label: string;
|
|
68
|
+
};
|
|
69
|
+
export type ProviderConfig = {
|
|
70
|
+
label: string;
|
|
71
|
+
executionMode: ProviderExecutionMode;
|
|
72
|
+
command: string;
|
|
73
|
+
args: string[];
|
|
74
|
+
env: Record<string, string>;
|
|
75
|
+
};
|
|
76
|
+
export type FullConfig = {
|
|
77
|
+
providers: Record<string, ProviderConfig>;
|
|
78
|
+
defaultProvider?: string;
|
|
79
|
+
};
|
|
80
|
+
export type ApiInfo = {
|
|
81
|
+
cwd: string;
|
|
82
|
+
home: string;
|
|
83
|
+
providers: ProviderInfo[];
|
|
84
|
+
defaultProvider: string;
|
|
85
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export const providerExecutionModeSchema = z.enum(['direct', 'shell']);
|
|
3
|
+
export const providerEntrySchema = z.object({
|
|
4
|
+
label: z.string().min(1),
|
|
5
|
+
executionMode: providerExecutionModeSchema.default('shell'),
|
|
6
|
+
command: z.string().min(1),
|
|
7
|
+
args: z.array(z.string()).default([]),
|
|
8
|
+
env: z.record(z.string(), z.string()).default({}),
|
|
9
|
+
});
|
|
10
|
+
export const configSchema = z.object({
|
|
11
|
+
providers: z.record(z.string().regex(/^[a-z0-9-]+$/), providerEntrySchema),
|
|
12
|
+
defaultProvider: z.string().optional(),
|
|
13
|
+
});
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const startSessionSchema: z.ZodObject<{
|
|
3
|
+
type: z.ZodLiteral<"start_session">;
|
|
4
|
+
provider: z.ZodString;
|
|
5
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
6
|
+
}, "strip", z.ZodTypeAny, {
|
|
7
|
+
type: "start_session";
|
|
8
|
+
provider: string;
|
|
9
|
+
cwd?: string | undefined;
|
|
10
|
+
}, {
|
|
11
|
+
type: "start_session";
|
|
12
|
+
provider: string;
|
|
13
|
+
cwd?: string | undefined;
|
|
14
|
+
}>;
|
|
15
|
+
export declare const inputSchema: z.ZodObject<{
|
|
16
|
+
type: z.ZodLiteral<"input">;
|
|
17
|
+
sessionId: z.ZodString;
|
|
18
|
+
data: z.ZodString;
|
|
19
|
+
}, "strip", z.ZodTypeAny, {
|
|
20
|
+
type: "input";
|
|
21
|
+
sessionId: string;
|
|
22
|
+
data: string;
|
|
23
|
+
}, {
|
|
24
|
+
type: "input";
|
|
25
|
+
sessionId: string;
|
|
26
|
+
data: string;
|
|
27
|
+
}>;
|
|
28
|
+
export declare const resizeSchema: z.ZodObject<{
|
|
29
|
+
type: z.ZodLiteral<"resize">;
|
|
30
|
+
sessionId: z.ZodString;
|
|
31
|
+
cols: z.ZodNumber;
|
|
32
|
+
rows: z.ZodNumber;
|
|
33
|
+
}, "strip", z.ZodTypeAny, {
|
|
34
|
+
type: "resize";
|
|
35
|
+
sessionId: string;
|
|
36
|
+
cols: number;
|
|
37
|
+
rows: number;
|
|
38
|
+
}, {
|
|
39
|
+
type: "resize";
|
|
40
|
+
sessionId: string;
|
|
41
|
+
cols: number;
|
|
42
|
+
rows: number;
|
|
43
|
+
}>;
|
|
44
|
+
export declare const stopSessionSchema: z.ZodObject<{
|
|
45
|
+
type: z.ZodLiteral<"stop_session">;
|
|
46
|
+
sessionId: z.ZodString;
|
|
47
|
+
}, "strip", z.ZodTypeAny, {
|
|
48
|
+
type: "stop_session";
|
|
49
|
+
sessionId: string;
|
|
50
|
+
}, {
|
|
51
|
+
type: "stop_session";
|
|
52
|
+
sessionId: string;
|
|
53
|
+
}>;
|
|
54
|
+
export declare const wsCommandSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
|
55
|
+
type: z.ZodLiteral<"start_session">;
|
|
56
|
+
provider: z.ZodString;
|
|
57
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
58
|
+
}, "strip", z.ZodTypeAny, {
|
|
59
|
+
type: "start_session";
|
|
60
|
+
provider: string;
|
|
61
|
+
cwd?: string | undefined;
|
|
62
|
+
}, {
|
|
63
|
+
type: "start_session";
|
|
64
|
+
provider: string;
|
|
65
|
+
cwd?: string | undefined;
|
|
66
|
+
}>, z.ZodObject<{
|
|
67
|
+
type: z.ZodLiteral<"input">;
|
|
68
|
+
sessionId: z.ZodString;
|
|
69
|
+
data: z.ZodString;
|
|
70
|
+
}, "strip", z.ZodTypeAny, {
|
|
71
|
+
type: "input";
|
|
72
|
+
sessionId: string;
|
|
73
|
+
data: string;
|
|
74
|
+
}, {
|
|
75
|
+
type: "input";
|
|
76
|
+
sessionId: string;
|
|
77
|
+
data: string;
|
|
78
|
+
}>, z.ZodObject<{
|
|
79
|
+
type: z.ZodLiteral<"resize">;
|
|
80
|
+
sessionId: z.ZodString;
|
|
81
|
+
cols: z.ZodNumber;
|
|
82
|
+
rows: z.ZodNumber;
|
|
83
|
+
}, "strip", z.ZodTypeAny, {
|
|
84
|
+
type: "resize";
|
|
85
|
+
sessionId: string;
|
|
86
|
+
cols: number;
|
|
87
|
+
rows: number;
|
|
88
|
+
}, {
|
|
89
|
+
type: "resize";
|
|
90
|
+
sessionId: string;
|
|
91
|
+
cols: number;
|
|
92
|
+
rows: number;
|
|
93
|
+
}>, z.ZodObject<{
|
|
94
|
+
type: z.ZodLiteral<"stop_session">;
|
|
95
|
+
sessionId: z.ZodString;
|
|
96
|
+
}, "strip", z.ZodTypeAny, {
|
|
97
|
+
type: "stop_session";
|
|
98
|
+
sessionId: string;
|
|
99
|
+
}, {
|
|
100
|
+
type: "stop_session";
|
|
101
|
+
sessionId: string;
|
|
102
|
+
}>]>;
|
|
103
|
+
export type StartSession = z.infer<typeof startSessionSchema>;
|
|
104
|
+
export type Input = z.infer<typeof inputSchema>;
|
|
105
|
+
export type Resize = z.infer<typeof resizeSchema>;
|
|
106
|
+
export type StopSession = z.infer<typeof stopSessionSchema>;
|
|
107
|
+
export type WsCommand = z.infer<typeof wsCommandSchema>;
|
|
108
|
+
export declare const sessionStartedSchema: z.ZodObject<{
|
|
109
|
+
type: z.ZodLiteral<"session_started">;
|
|
110
|
+
sessionId: z.ZodString;
|
|
111
|
+
provider: z.ZodString;
|
|
112
|
+
cwd: z.ZodString;
|
|
113
|
+
}, "strip", z.ZodTypeAny, {
|
|
114
|
+
type: "session_started";
|
|
115
|
+
provider: string;
|
|
116
|
+
cwd: string;
|
|
117
|
+
sessionId: string;
|
|
118
|
+
}, {
|
|
119
|
+
type: "session_started";
|
|
120
|
+
provider: string;
|
|
121
|
+
cwd: string;
|
|
122
|
+
sessionId: string;
|
|
123
|
+
}>;
|
|
124
|
+
export declare const outputSchema: z.ZodObject<{
|
|
125
|
+
type: z.ZodLiteral<"output">;
|
|
126
|
+
sessionId: z.ZodString;
|
|
127
|
+
data: z.ZodString;
|
|
128
|
+
}, "strip", z.ZodTypeAny, {
|
|
129
|
+
type: "output";
|
|
130
|
+
sessionId: string;
|
|
131
|
+
data: string;
|
|
132
|
+
}, {
|
|
133
|
+
type: "output";
|
|
134
|
+
sessionId: string;
|
|
135
|
+
data: string;
|
|
136
|
+
}>;
|
|
137
|
+
export declare const sessionExitSchema: z.ZodObject<{
|
|
138
|
+
type: z.ZodLiteral<"session_exit">;
|
|
139
|
+
sessionId: z.ZodString;
|
|
140
|
+
exitCode: z.ZodNumber;
|
|
141
|
+
signal: z.ZodNumber;
|
|
142
|
+
}, "strip", z.ZodTypeAny, {
|
|
143
|
+
type: "session_exit";
|
|
144
|
+
sessionId: string;
|
|
145
|
+
exitCode: number;
|
|
146
|
+
signal: number;
|
|
147
|
+
}, {
|
|
148
|
+
type: "session_exit";
|
|
149
|
+
sessionId: string;
|
|
150
|
+
exitCode: number;
|
|
151
|
+
signal: number;
|
|
152
|
+
}>;
|
|
153
|
+
export declare const errorSchema: z.ZodObject<{
|
|
154
|
+
type: z.ZodLiteral<"error">;
|
|
155
|
+
message: z.ZodString;
|
|
156
|
+
}, "strip", z.ZodTypeAny, {
|
|
157
|
+
message: string;
|
|
158
|
+
type: "error";
|
|
159
|
+
}, {
|
|
160
|
+
message: string;
|
|
161
|
+
type: "error";
|
|
162
|
+
}>;
|
|
163
|
+
export declare const wsEventSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
|
164
|
+
type: z.ZodLiteral<"session_started">;
|
|
165
|
+
sessionId: z.ZodString;
|
|
166
|
+
provider: z.ZodString;
|
|
167
|
+
cwd: z.ZodString;
|
|
168
|
+
}, "strip", z.ZodTypeAny, {
|
|
169
|
+
type: "session_started";
|
|
170
|
+
provider: string;
|
|
171
|
+
cwd: string;
|
|
172
|
+
sessionId: string;
|
|
173
|
+
}, {
|
|
174
|
+
type: "session_started";
|
|
175
|
+
provider: string;
|
|
176
|
+
cwd: string;
|
|
177
|
+
sessionId: string;
|
|
178
|
+
}>, z.ZodObject<{
|
|
179
|
+
type: z.ZodLiteral<"output">;
|
|
180
|
+
sessionId: z.ZodString;
|
|
181
|
+
data: z.ZodString;
|
|
182
|
+
}, "strip", z.ZodTypeAny, {
|
|
183
|
+
type: "output";
|
|
184
|
+
sessionId: string;
|
|
185
|
+
data: string;
|
|
186
|
+
}, {
|
|
187
|
+
type: "output";
|
|
188
|
+
sessionId: string;
|
|
189
|
+
data: string;
|
|
190
|
+
}>, z.ZodObject<{
|
|
191
|
+
type: z.ZodLiteral<"session_exit">;
|
|
192
|
+
sessionId: z.ZodString;
|
|
193
|
+
exitCode: z.ZodNumber;
|
|
194
|
+
signal: z.ZodNumber;
|
|
195
|
+
}, "strip", z.ZodTypeAny, {
|
|
196
|
+
type: "session_exit";
|
|
197
|
+
sessionId: string;
|
|
198
|
+
exitCode: number;
|
|
199
|
+
signal: number;
|
|
200
|
+
}, {
|
|
201
|
+
type: "session_exit";
|
|
202
|
+
sessionId: string;
|
|
203
|
+
exitCode: number;
|
|
204
|
+
signal: number;
|
|
205
|
+
}>, z.ZodObject<{
|
|
206
|
+
type: z.ZodLiteral<"error">;
|
|
207
|
+
message: z.ZodString;
|
|
208
|
+
}, "strip", z.ZodTypeAny, {
|
|
209
|
+
message: string;
|
|
210
|
+
type: "error";
|
|
211
|
+
}, {
|
|
212
|
+
message: string;
|
|
213
|
+
type: "error";
|
|
214
|
+
}>]>;
|
|
215
|
+
export type SessionStarted = z.infer<typeof sessionStartedSchema>;
|
|
216
|
+
export type Output = z.infer<typeof outputSchema>;
|
|
217
|
+
export type SessionExit = z.infer<typeof sessionExitSchema>;
|
|
218
|
+
export type WsError = z.infer<typeof errorSchema>;
|
|
219
|
+
export type WsEvent = z.infer<typeof wsEventSchema>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
// ── Client → Server (commands) ──────────────────────────────────────
|
|
3
|
+
export const startSessionSchema = z.object({
|
|
4
|
+
type: z.literal('start_session'),
|
|
5
|
+
provider: z.string(),
|
|
6
|
+
cwd: z.string().optional(),
|
|
7
|
+
});
|
|
8
|
+
export const inputSchema = z.object({
|
|
9
|
+
type: z.literal('input'),
|
|
10
|
+
sessionId: z.string(),
|
|
11
|
+
data: z.string(),
|
|
12
|
+
});
|
|
13
|
+
export const resizeSchema = z.object({
|
|
14
|
+
type: z.literal('resize'),
|
|
15
|
+
sessionId: z.string(),
|
|
16
|
+
cols: z.number().int().positive(),
|
|
17
|
+
rows: z.number().int().positive(),
|
|
18
|
+
});
|
|
19
|
+
export const stopSessionSchema = z.object({
|
|
20
|
+
type: z.literal('stop_session'),
|
|
21
|
+
sessionId: z.string(),
|
|
22
|
+
});
|
|
23
|
+
export const wsCommandSchema = z.discriminatedUnion('type', [
|
|
24
|
+
startSessionSchema,
|
|
25
|
+
inputSchema,
|
|
26
|
+
resizeSchema,
|
|
27
|
+
stopSessionSchema,
|
|
28
|
+
]);
|
|
29
|
+
// ── Server → Client (events) ───────────────────────────────────────
|
|
30
|
+
export const sessionStartedSchema = z.object({
|
|
31
|
+
type: z.literal('session_started'),
|
|
32
|
+
sessionId: z.string(),
|
|
33
|
+
provider: z.string(),
|
|
34
|
+
cwd: z.string(),
|
|
35
|
+
});
|
|
36
|
+
export const outputSchema = z.object({
|
|
37
|
+
type: z.literal('output'),
|
|
38
|
+
sessionId: z.string(),
|
|
39
|
+
data: z.string(),
|
|
40
|
+
});
|
|
41
|
+
export const sessionExitSchema = z.object({
|
|
42
|
+
type: z.literal('session_exit'),
|
|
43
|
+
sessionId: z.string(),
|
|
44
|
+
exitCode: z.number(),
|
|
45
|
+
signal: z.number(),
|
|
46
|
+
});
|
|
47
|
+
export const errorSchema = z.object({
|
|
48
|
+
type: z.literal('error'),
|
|
49
|
+
message: z.string(),
|
|
50
|
+
});
|
|
51
|
+
export const wsEventSchema = z.discriminatedUnion('type', [
|
|
52
|
+
sessionStartedSchema,
|
|
53
|
+
outputSchema,
|
|
54
|
+
sessionExitSchema,
|
|
55
|
+
errorSchema,
|
|
56
|
+
]);
|