maritime-cli 0.2.1 → 1.2.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/AGENTS.md +182 -0
- package/dist/api.d.ts +1 -0
- package/dist/api.js +130 -13
- package/dist/commands/blueprint.d.ts +2 -0
- package/dist/commands/blueprint.js +93 -0
- package/dist/commands/chat.d.ts +2 -0
- package/dist/commands/chat.js +93 -0
- package/dist/commands/create.js +138 -54
- package/dist/commands/delete.js +28 -18
- package/dist/commands/deploy.js +51 -9
- package/dist/commands/env.js +206 -43
- package/dist/commands/exec.d.ts +2 -0
- package/dist/commands/exec.js +28 -0
- package/dist/commands/guide.d.ts +2 -0
- package/dist/commands/guide.js +83 -0
- package/dist/commands/history.d.ts +2 -0
- package/dist/commands/history.js +56 -0
- package/dist/commands/info.d.ts +2 -0
- package/dist/commands/info.js +74 -0
- package/dist/commands/keys.d.ts +2 -0
- package/dist/commands/keys.js +90 -0
- package/dist/commands/list.js +13 -10
- package/dist/commands/login.js +70 -10
- package/dist/commands/logs.js +38 -14
- package/dist/commands/open.d.ts +2 -0
- package/dist/commands/open.js +24 -0
- package/dist/commands/restart.js +13 -11
- package/dist/commands/scale.d.ts +2 -0
- package/dist/commands/scale.js +30 -0
- package/dist/commands/sleep.d.ts +2 -0
- package/dist/commands/sleep.js +23 -0
- package/dist/commands/start.js +14 -11
- package/dist/commands/status.d.ts +2 -0
- package/dist/commands/status.js +73 -0
- package/dist/commands/stop.js +13 -11
- package/dist/commands/templates.js +11 -9
- package/dist/commands/triggers.d.ts +2 -0
- package/dist/commands/triggers.js +79 -0
- package/dist/commands/whoami.js +65 -24
- package/dist/config.js +8 -0
- package/dist/index.js +86 -10
- package/dist/interactive.d.ts +1 -0
- package/dist/interactive.js +68 -0
- package/dist/output.d.ts +61 -0
- package/dist/output.js +123 -0
- package/dist/resolve.d.ts +2 -3
- package/dist/resolve.js +23 -10
- package/dist/version-check.d.ts +10 -0
- package/dist/version-check.js +43 -0
- package/dist/websocket.d.ts +13 -0
- package/dist/websocket.js +55 -0
- package/package.json +8 -4
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { select } from '@inquirer/prompts';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { authGet } from './api.js';
|
|
4
|
+
const COMMANDS = [
|
|
5
|
+
{ name: 'list', value: 'list', description: 'List your agents', needsAgent: false },
|
|
6
|
+
{ name: 'create', value: 'create', description: 'Create a new agent', needsAgent: false },
|
|
7
|
+
{ name: 'status', value: 'status', description: 'Show agent status', needsAgent: true },
|
|
8
|
+
{ name: 'info', value: 'info', description: 'Show full agent details', needsAgent: true },
|
|
9
|
+
{ name: 'logs', value: 'logs', description: 'View agent logs', needsAgent: true },
|
|
10
|
+
{ name: 'deploy', value: 'deploy', description: 'Deploy an agent', needsAgent: true },
|
|
11
|
+
{ name: 'start', value: 'start', description: 'Start an agent', needsAgent: true },
|
|
12
|
+
{ name: 'stop', value: 'stop', description: 'Stop an agent', needsAgent: true },
|
|
13
|
+
{ name: 'sleep', value: 'sleep', description: 'Put agent to sleep', needsAgent: true },
|
|
14
|
+
{ name: 'restart', value: 'restart', description: 'Restart an agent', needsAgent: true },
|
|
15
|
+
{ name: 'env', value: 'env', description: 'Manage environment variables', needsAgent: false },
|
|
16
|
+
{ name: 'triggers', value: 'triggers', description: 'Manage triggers', needsAgent: false },
|
|
17
|
+
{ name: 'templates', value: 'templates', description: 'Browse templates', needsAgent: false },
|
|
18
|
+
{ name: 'history', value: 'history', description: 'View deploy history', needsAgent: true },
|
|
19
|
+
{ name: 'blueprint', value: 'blueprint', description: 'Manage blueprints', needsAgent: false },
|
|
20
|
+
{ name: 'scale', value: 'scale', description: 'Change agent tier', needsAgent: true },
|
|
21
|
+
{ name: 'open', value: 'open', description: 'Open agent in browser', needsAgent: true },
|
|
22
|
+
{ name: 'whoami', value: 'whoami', description: 'Show current user', needsAgent: false },
|
|
23
|
+
{ name: 'logout', value: 'logout', description: 'Log out', needsAgent: false },
|
|
24
|
+
];
|
|
25
|
+
export async function runInteractive() {
|
|
26
|
+
console.log(chalk.hex('#8B5CF6')('\n Maritime') + chalk.dim(' — interactive mode\n'));
|
|
27
|
+
const command = await select({
|
|
28
|
+
message: 'What would you like to do?',
|
|
29
|
+
choices: COMMANDS.map((c) => ({
|
|
30
|
+
name: `${c.name.padEnd(12)} ${chalk.dim(c.description)}`,
|
|
31
|
+
value: c.value,
|
|
32
|
+
})),
|
|
33
|
+
});
|
|
34
|
+
const chosen = COMMANDS.find((c) => c.value === command);
|
|
35
|
+
if (!chosen?.needsAgent) {
|
|
36
|
+
return [command];
|
|
37
|
+
}
|
|
38
|
+
// For agent-targeting commands, show agent picker
|
|
39
|
+
try {
|
|
40
|
+
const agents = await authGet('/api/agents');
|
|
41
|
+
if (agents.length === 0) {
|
|
42
|
+
console.log(chalk.yellow('No agents found.') + ' Run `maritime create` first.');
|
|
43
|
+
return [command];
|
|
44
|
+
}
|
|
45
|
+
const agentName = await select({
|
|
46
|
+
message: 'Select an agent:',
|
|
47
|
+
choices: agents.map((a) => ({
|
|
48
|
+
name: `${a.name.padEnd(24)} ${statusBadge(a.status)}`,
|
|
49
|
+
value: a.name,
|
|
50
|
+
})),
|
|
51
|
+
});
|
|
52
|
+
return [command, agentName];
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
// If auth fails, run command without agent (it will show auth error)
|
|
56
|
+
return [command];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function statusBadge(status) {
|
|
60
|
+
switch (status) {
|
|
61
|
+
case 'active': return chalk.green(status);
|
|
62
|
+
case 'sleeping': return chalk.blue(status);
|
|
63
|
+
case 'deploying': return chalk.yellow(status);
|
|
64
|
+
case 'error': return chalk.red(status);
|
|
65
|
+
case 'stopped': return chalk.gray(status);
|
|
66
|
+
default: return status;
|
|
67
|
+
}
|
|
68
|
+
}
|
package/dist/output.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Output + error helpers.
|
|
3
|
+
*
|
|
4
|
+
* Two audiences share this CLI: humans at a terminal, and programs/AI agents
|
|
5
|
+
* that shell out and parse stdout. The `--json` flag switches to a strict
|
|
6
|
+
* machine contract:
|
|
7
|
+
*
|
|
8
|
+
* - success → a single JSON object on STDOUT, nothing else
|
|
9
|
+
* - failure → a single JSON object on STDERR, nothing else
|
|
10
|
+
* - spinners, colors, and the update notice are suppressed
|
|
11
|
+
* - exit code reflects the outcome (see EXIT)
|
|
12
|
+
*
|
|
13
|
+
* In human mode, errors go to STDERR (not stdout) so that even without --json,
|
|
14
|
+
* stdout stays clean enough to pipe.
|
|
15
|
+
*/
|
|
16
|
+
/** Stable exit codes so callers can branch on outcome without parsing text. */
|
|
17
|
+
export declare const EXIT: {
|
|
18
|
+
readonly OK: 0;
|
|
19
|
+
readonly ERROR: 1;
|
|
20
|
+
readonly AUTH: 2;
|
|
21
|
+
readonly NOT_FOUND: 3;
|
|
22
|
+
readonly USAGE: 4;
|
|
23
|
+
};
|
|
24
|
+
export declare function isJsonMode(): boolean;
|
|
25
|
+
/** Emit a success payload on stdout (used by --json). */
|
|
26
|
+
export declare function outputJson(data: unknown): void;
|
|
27
|
+
/**
|
|
28
|
+
* Print a result. In --json mode, emits `jsonData` as JSON on stdout.
|
|
29
|
+
* Otherwise runs `human` (a string or a function that prints).
|
|
30
|
+
*/
|
|
31
|
+
export declare function outputResult(jsonData: unknown, human: string | (() => void)): void;
|
|
32
|
+
interface FailOptions {
|
|
33
|
+
/** Override the exit code (defaults to EXIT.ERROR). */
|
|
34
|
+
exitCode?: number;
|
|
35
|
+
/** Machine-stable error code for --json consumers. */
|
|
36
|
+
code?: string;
|
|
37
|
+
/** Optional HTTP status to surface in --json. */
|
|
38
|
+
status?: number;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Print an error and exit. JSON mode → `{ok:false, error:{...}}` on stderr.
|
|
42
|
+
* Human mode → red "Error:" line on stderr. Always terminates the process.
|
|
43
|
+
*/
|
|
44
|
+
export declare function fail(message: string, opts?: FailOptions): never;
|
|
45
|
+
/**
|
|
46
|
+
* Centralized catch-block handler. Maps CliHttpError → fail() with the right
|
|
47
|
+
* code/exit, and turns any other Error into a structured failure too, so an
|
|
48
|
+
* AI agent never has to scrape an uncaught stack trace.
|
|
49
|
+
*/
|
|
50
|
+
export declare function handleError(error: unknown): never;
|
|
51
|
+
/**
|
|
52
|
+
* A spinner that disappears in --json / non-TTY contexts so it can never
|
|
53
|
+
* corrupt machine output. Lazily loads `ora` only when actually needed.
|
|
54
|
+
*/
|
|
55
|
+
export interface Spinner {
|
|
56
|
+
succeed(text?: string): void;
|
|
57
|
+
fail(text?: string): void;
|
|
58
|
+
stop(): void;
|
|
59
|
+
}
|
|
60
|
+
export declare function makeSpinner(text: string): Promise<Spinner>;
|
|
61
|
+
export {};
|
package/dist/output.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Output + error helpers.
|
|
3
|
+
*
|
|
4
|
+
* Two audiences share this CLI: humans at a terminal, and programs/AI agents
|
|
5
|
+
* that shell out and parse stdout. The `--json` flag switches to a strict
|
|
6
|
+
* machine contract:
|
|
7
|
+
*
|
|
8
|
+
* - success → a single JSON object on STDOUT, nothing else
|
|
9
|
+
* - failure → a single JSON object on STDERR, nothing else
|
|
10
|
+
* - spinners, colors, and the update notice are suppressed
|
|
11
|
+
* - exit code reflects the outcome (see EXIT)
|
|
12
|
+
*
|
|
13
|
+
* In human mode, errors go to STDERR (not stdout) so that even without --json,
|
|
14
|
+
* stdout stays clean enough to pipe.
|
|
15
|
+
*/
|
|
16
|
+
import chalk from 'chalk';
|
|
17
|
+
import { CliHttpError } from './api.js';
|
|
18
|
+
/** Stable exit codes so callers can branch on outcome without parsing text. */
|
|
19
|
+
export const EXIT = {
|
|
20
|
+
OK: 0,
|
|
21
|
+
ERROR: 1,
|
|
22
|
+
AUTH: 2,
|
|
23
|
+
NOT_FOUND: 3,
|
|
24
|
+
USAGE: 4,
|
|
25
|
+
};
|
|
26
|
+
export function isJsonMode() {
|
|
27
|
+
return process.argv.includes('--json');
|
|
28
|
+
}
|
|
29
|
+
/** Emit a success payload on stdout (used by --json). */
|
|
30
|
+
export function outputJson(data) {
|
|
31
|
+
process.stdout.write(JSON.stringify(data, null, 2) + '\n');
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Print a result. In --json mode, emits `jsonData` as JSON on stdout.
|
|
35
|
+
* Otherwise runs `human` (a string or a function that prints).
|
|
36
|
+
*/
|
|
37
|
+
export function outputResult(jsonData, human) {
|
|
38
|
+
if (isJsonMode()) {
|
|
39
|
+
outputJson(jsonData);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (typeof human === 'function')
|
|
43
|
+
human();
|
|
44
|
+
else
|
|
45
|
+
console.log(human);
|
|
46
|
+
}
|
|
47
|
+
/** Map an HTTP status to one of our stable exit codes. */
|
|
48
|
+
function exitCodeForStatus(status) {
|
|
49
|
+
if (status === 401 || status === 403)
|
|
50
|
+
return EXIT.AUTH;
|
|
51
|
+
if (status === 404)
|
|
52
|
+
return EXIT.NOT_FOUND;
|
|
53
|
+
return EXIT.ERROR;
|
|
54
|
+
}
|
|
55
|
+
/** Short machine-stable error code, paired with the human message. */
|
|
56
|
+
function errorCodeForStatus(status) {
|
|
57
|
+
switch (status) {
|
|
58
|
+
case 0:
|
|
59
|
+
return 'network_error';
|
|
60
|
+
case 401:
|
|
61
|
+
case 403:
|
|
62
|
+
return 'unauthorized';
|
|
63
|
+
case 404:
|
|
64
|
+
return 'not_found';
|
|
65
|
+
case 409:
|
|
66
|
+
return 'conflict';
|
|
67
|
+
case 503:
|
|
68
|
+
return 'unavailable';
|
|
69
|
+
default:
|
|
70
|
+
return status >= 500 ? 'server_error' : 'request_failed';
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Print an error and exit. JSON mode → `{ok:false, error:{...}}` on stderr.
|
|
75
|
+
* Human mode → red "Error:" line on stderr. Always terminates the process.
|
|
76
|
+
*/
|
|
77
|
+
export function fail(message, opts = {}) {
|
|
78
|
+
const exitCode = opts.exitCode ?? EXIT.ERROR;
|
|
79
|
+
if (isJsonMode()) {
|
|
80
|
+
process.stderr.write(JSON.stringify({
|
|
81
|
+
ok: false,
|
|
82
|
+
error: {
|
|
83
|
+
code: opts.code ?? 'error',
|
|
84
|
+
message,
|
|
85
|
+
...(opts.status !== undefined ? { status: opts.status } : {}),
|
|
86
|
+
},
|
|
87
|
+
}, null, 2) + '\n');
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
process.stderr.write(chalk.red('Error:') + ` ${message}\n`);
|
|
91
|
+
}
|
|
92
|
+
process.exit(exitCode);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Centralized catch-block handler. Maps CliHttpError → fail() with the right
|
|
96
|
+
* code/exit, and turns any other Error into a structured failure too, so an
|
|
97
|
+
* AI agent never has to scrape an uncaught stack trace.
|
|
98
|
+
*/
|
|
99
|
+
export function handleError(error) {
|
|
100
|
+
if (error instanceof CliHttpError) {
|
|
101
|
+
fail(error.detail, {
|
|
102
|
+
status: error.status,
|
|
103
|
+
code: errorCodeForStatus(error.status),
|
|
104
|
+
exitCode: exitCodeForStatus(error.status),
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
if (error instanceof Error) {
|
|
108
|
+
fail(error.message, { code: 'error' });
|
|
109
|
+
}
|
|
110
|
+
fail(String(error), { code: 'error' });
|
|
111
|
+
}
|
|
112
|
+
export async function makeSpinner(text) {
|
|
113
|
+
if (isJsonMode() || !process.stderr.isTTY) {
|
|
114
|
+
return { succeed() { }, fail() { }, stop() { } };
|
|
115
|
+
}
|
|
116
|
+
const { default: ora } = await import('ora');
|
|
117
|
+
const spinner = ora(text).start();
|
|
118
|
+
return {
|
|
119
|
+
succeed: (t) => spinner.succeed(t),
|
|
120
|
+
fail: (t) => spinner.fail(t),
|
|
121
|
+
stop: () => spinner.stop(),
|
|
122
|
+
};
|
|
123
|
+
}
|
package/dist/resolve.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
interface AgentSummary {
|
|
1
|
+
export interface AgentSummary {
|
|
2
2
|
id: string;
|
|
3
3
|
name: string;
|
|
4
4
|
status: string;
|
|
5
5
|
framework: string;
|
|
6
6
|
tier?: string;
|
|
7
|
-
|
|
7
|
+
createdAt?: string;
|
|
8
8
|
}
|
|
9
9
|
export declare function resolveAgent(nameOrId: string): Promise<AgentSummary>;
|
|
10
|
-
export {};
|
package/dist/resolve.js
CHANGED
|
@@ -1,19 +1,32 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
1
|
import { authGet } from './api.js';
|
|
2
|
+
import { fail, EXIT } from './output.js';
|
|
3
|
+
// Simple in-memory cache for the full agent list (5-second TTL)
|
|
4
|
+
let cachedAgents = null;
|
|
5
|
+
let cacheTime = 0;
|
|
6
|
+
const CACHE_TTL = 5_000;
|
|
7
|
+
async function fetchAllAgents() {
|
|
8
|
+
const now = Date.now();
|
|
9
|
+
if (cachedAgents && now - cacheTime < CACHE_TTL) {
|
|
10
|
+
return cachedAgents;
|
|
11
|
+
}
|
|
12
|
+
cachedAgents = await authGet('/api/agents');
|
|
13
|
+
cacheTime = now;
|
|
14
|
+
return cachedAgents;
|
|
15
|
+
}
|
|
3
16
|
export async function resolveAgent(nameOrId) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const byName = agents.filter((a) => a.name === nameOrId);
|
|
17
|
+
// 1. Try server-side exact name match first (single API call, no full list)
|
|
18
|
+
const byName = await authGet(`/api/agents?name=${encodeURIComponent(nameOrId)}`);
|
|
7
19
|
if (byName.length === 1)
|
|
8
20
|
return byName[0];
|
|
9
|
-
// ID prefix
|
|
21
|
+
// 2. Fall back to full list and match by ID prefix
|
|
22
|
+
const agents = await fetchAllAgents();
|
|
10
23
|
const byId = agents.filter((a) => a.id.startsWith(nameOrId));
|
|
11
24
|
if (byId.length === 1)
|
|
12
25
|
return byId[0];
|
|
13
|
-
if (
|
|
14
|
-
|
|
15
|
-
|
|
26
|
+
if (byId.length > 1) {
|
|
27
|
+
fail(`Ambiguous agent "${nameOrId}". Multiple ID prefix matches.`, {
|
|
28
|
+
code: 'ambiguous_agent',
|
|
29
|
+
});
|
|
16
30
|
}
|
|
17
|
-
|
|
18
|
-
process.exit(1);
|
|
31
|
+
fail(`Agent "${nameOrId}" not found.`, { code: 'not_found', exitCode: EXIT.NOT_FOUND });
|
|
19
32
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Non-blocking daily check against npm registry.
|
|
3
|
+
* Prints a one-line update notice after command output if a newer version exists.
|
|
4
|
+
*/
|
|
5
|
+
export declare function checkForUpdates(currentVersion: string): void;
|
|
6
|
+
/**
|
|
7
|
+
* Print update notice if a newer version was found.
|
|
8
|
+
* Call at the end of command execution.
|
|
9
|
+
*/
|
|
10
|
+
export declare function printUpdateNotice(currentVersion: string): void;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { config } from './config.js';
|
|
3
|
+
const ONE_DAY = 24 * 60 * 60 * 1000;
|
|
4
|
+
/**
|
|
5
|
+
* Non-blocking daily check against npm registry.
|
|
6
|
+
* Prints a one-line update notice after command output if a newer version exists.
|
|
7
|
+
*/
|
|
8
|
+
export function checkForUpdates(currentVersion) {
|
|
9
|
+
const lastCheck = config.get('lastVersionCheck');
|
|
10
|
+
if (lastCheck && Date.now() - lastCheck < ONE_DAY)
|
|
11
|
+
return;
|
|
12
|
+
// Fire-and-forget: don't block CLI execution
|
|
13
|
+
fetch('https://registry.npmjs.org/maritime-cli/latest', {
|
|
14
|
+
signal: AbortSignal.timeout(3000),
|
|
15
|
+
})
|
|
16
|
+
.then((r) => r.json())
|
|
17
|
+
.then((data) => {
|
|
18
|
+
config.set('lastVersionCheck', Date.now());
|
|
19
|
+
const latest = data.version;
|
|
20
|
+
if (latest && latest !== currentVersion) {
|
|
21
|
+
config.set('latestVersion', latest);
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
.catch(() => {
|
|
25
|
+
// Silently ignore — this is a non-blocking check
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Print update notice if a newer version was found.
|
|
30
|
+
* Call at the end of command execution.
|
|
31
|
+
*/
|
|
32
|
+
export function printUpdateNotice(currentVersion) {
|
|
33
|
+
// Never emit chatter on stdout in machine mode — it corrupts JSON output.
|
|
34
|
+
if (process.argv.includes('--json'))
|
|
35
|
+
return;
|
|
36
|
+
const latest = config.get('latestVersion');
|
|
37
|
+
if (latest && latest !== currentVersion) {
|
|
38
|
+
console.log(chalk.dim(`\n Update available: ${currentVersion} → ${chalk.bold(latest)}`) +
|
|
39
|
+
chalk.dim(' Run ') +
|
|
40
|
+
chalk.bold('npm i -g maritime-cli') +
|
|
41
|
+
chalk.dim(' to update'));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface WsOptions {
|
|
2
|
+
/** Called for each text message received */
|
|
3
|
+
onMessage: (data: string) => void;
|
|
4
|
+
/** Called when connection closes cleanly */
|
|
5
|
+
onClose?: () => void;
|
|
6
|
+
/** Max reconnect attempts on transient failures */
|
|
7
|
+
maxReconnects?: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Connect to a Maritime WebSocket endpoint with auth token.
|
|
11
|
+
* Returns a cleanup function that closes the connection.
|
|
12
|
+
*/
|
|
13
|
+
export declare function connectWs(path: string, opts: WsOptions): () => void;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { WebSocket } from 'ws';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { getApiUrl, requireAuth } from './api.js';
|
|
4
|
+
/**
|
|
5
|
+
* Connect to a Maritime WebSocket endpoint with auth token.
|
|
6
|
+
* Returns a cleanup function that closes the connection.
|
|
7
|
+
*/
|
|
8
|
+
export function connectWs(path, opts) {
|
|
9
|
+
const token = requireAuth();
|
|
10
|
+
const baseUrl = getApiUrl().replace(/^http/, 'ws');
|
|
11
|
+
const sep = path.includes('?') ? '&' : '?';
|
|
12
|
+
const url = `${baseUrl}${path}${sep}token=${token}`;
|
|
13
|
+
const maxReconnects = opts.maxReconnects ?? 2;
|
|
14
|
+
let reconnects = 0;
|
|
15
|
+
let closed = false;
|
|
16
|
+
let ws;
|
|
17
|
+
function connect() {
|
|
18
|
+
ws = new WebSocket(url);
|
|
19
|
+
ws.on('message', (raw) => {
|
|
20
|
+
opts.onMessage(raw.toString());
|
|
21
|
+
});
|
|
22
|
+
ws.on('close', () => {
|
|
23
|
+
if (closed) {
|
|
24
|
+
opts.onClose?.();
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (reconnects < maxReconnects) {
|
|
28
|
+
reconnects++;
|
|
29
|
+
setTimeout(connect, 1000 * reconnects);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
opts.onClose?.();
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
ws.on('error', (err) => {
|
|
36
|
+
if (!closed) {
|
|
37
|
+
console.error(chalk.dim(`WebSocket error: ${err.message}`));
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
connect();
|
|
42
|
+
// Clean shutdown on SIGINT
|
|
43
|
+
const sigHandler = () => {
|
|
44
|
+
cleanup();
|
|
45
|
+
};
|
|
46
|
+
process.on('SIGINT', sigHandler);
|
|
47
|
+
function cleanup() {
|
|
48
|
+
closed = true;
|
|
49
|
+
process.removeListener('SIGINT', sigHandler);
|
|
50
|
+
if (ws && ws.readyState === WebSocket.OPEN) {
|
|
51
|
+
ws.close();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return cleanup;
|
|
55
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "maritime-cli",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Maritime CLI - Deploy AI agents from your terminal",
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"description": "Maritime CLI - Deploy and talk to AI agents from your terminal",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "mariagorskikh",
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
"maritime": "./dist/index.js"
|
|
21
21
|
},
|
|
22
22
|
"files": [
|
|
23
|
-
"dist"
|
|
23
|
+
"dist",
|
|
24
|
+
"AGENTS.md"
|
|
24
25
|
],
|
|
25
26
|
"engines": {
|
|
26
27
|
"node": ">=18"
|
|
@@ -31,14 +32,17 @@
|
|
|
31
32
|
"prepublishOnly": "npm run build"
|
|
32
33
|
},
|
|
33
34
|
"dependencies": {
|
|
35
|
+
"@inquirer/prompts": "^7.0.0",
|
|
34
36
|
"chalk": "^5.3.0",
|
|
35
37
|
"commander": "^12.0.0",
|
|
36
38
|
"conf": "^12.0.0",
|
|
37
39
|
"open": "^10.0.0",
|
|
38
|
-
"ora": "^8.0.0"
|
|
40
|
+
"ora": "^8.0.0",
|
|
41
|
+
"ws": "^8.16.0"
|
|
39
42
|
},
|
|
40
43
|
"devDependencies": {
|
|
41
44
|
"@types/node": "^20.0.0",
|
|
45
|
+
"@types/ws": "^8.5.0",
|
|
42
46
|
"tsx": "^4.0.0",
|
|
43
47
|
"typescript": "^5.0.0"
|
|
44
48
|
}
|