maritime-cli 1.9.0 → 2.0.1
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/README.md +16 -0
- package/archives/checksums.txt +6 -0
- package/archives/maritime_2.0.1_darwin_amd64.tar.gz +0 -0
- package/archives/maritime_2.0.1_darwin_arm64.tar.gz +0 -0
- package/archives/maritime_2.0.1_linux_amd64.tar.gz +0 -0
- package/archives/maritime_2.0.1_linux_arm64.tar.gz +0 -0
- package/archives/maritime_2.0.1_windows_amd64.zip +0 -0
- package/archives/maritime_2.0.1_windows_arm64.zip +0 -0
- package/bin/maritime.js +40 -0
- package/install.js +131 -0
- package/package.json +23 -37
- package/AGENTS.md +0 -361
- package/SKILL.md +0 -181
- package/dist/api.d.ts +0 -30
- package/dist/api.js +0 -246
- package/dist/bundled.d.ts +0 -11
- package/dist/bundled.js +0 -25
- package/dist/commands/chat.d.ts +0 -2
- package/dist/commands/chat.js +0 -120
- package/dist/commands/create.d.ts +0 -2
- package/dist/commands/create.js +0 -310
- package/dist/commands/delete.d.ts +0 -2
- package/dist/commands/delete.js +0 -43
- package/dist/commands/deploy.d.ts +0 -2
- package/dist/commands/deploy.js +0 -180
- package/dist/commands/env.d.ts +0 -2
- package/dist/commands/env.js +0 -368
- package/dist/commands/exec.d.ts +0 -2
- package/dist/commands/exec.js +0 -31
- package/dist/commands/guide.d.ts +0 -2
- package/dist/commands/guide.js +0 -75
- package/dist/commands/history.d.ts +0 -2
- package/dist/commands/history.js +0 -56
- package/dist/commands/info.d.ts +0 -2
- package/dist/commands/info.js +0 -78
- package/dist/commands/init.d.ts +0 -2
- package/dist/commands/init.js +0 -143
- package/dist/commands/keys.d.ts +0 -2
- package/dist/commands/keys.js +0 -90
- package/dist/commands/link.d.ts +0 -4
- package/dist/commands/link.js +0 -65
- package/dist/commands/list.d.ts +0 -2
- package/dist/commands/list.js +0 -55
- package/dist/commands/login.d.ts +0 -2
- package/dist/commands/login.js +0 -368
- package/dist/commands/logout.d.ts +0 -2
- package/dist/commands/logout.js +0 -12
- package/dist/commands/logs.d.ts +0 -2
- package/dist/commands/logs.js +0 -89
- package/dist/commands/message.d.ts +0 -8
- package/dist/commands/message.js +0 -75
- package/dist/commands/open.d.ts +0 -2
- package/dist/commands/open.js +0 -25
- package/dist/commands/restart.d.ts +0 -2
- package/dist/commands/restart.js +0 -26
- package/dist/commands/signup.d.ts +0 -2
- package/dist/commands/signup.js +0 -72
- package/dist/commands/sleep.d.ts +0 -2
- package/dist/commands/sleep.js +0 -22
- package/dist/commands/start.d.ts +0 -2
- package/dist/commands/start.js +0 -27
- package/dist/commands/status.d.ts +0 -2
- package/dist/commands/status.js +0 -69
- package/dist/commands/stop.d.ts +0 -2
- package/dist/commands/stop.js +0 -26
- package/dist/commands/templates.d.ts +0 -2
- package/dist/commands/templates.js +0 -40
- package/dist/commands/triggers.d.ts +0 -2
- package/dist/commands/triggers.js +0 -89
- package/dist/commands/whoami.d.ts +0 -2
- package/dist/commands/whoami.js +0 -76
- package/dist/config.d.ts +0 -2
- package/dist/config.js +0 -14
- package/dist/context.d.ts +0 -39
- package/dist/context.js +0 -110
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -186
- package/dist/interactive.d.ts +0 -1
- package/dist/interactive.js +0 -66
- package/dist/output.d.ts +0 -80
- package/dist/output.js +0 -176
- package/dist/prompt.d.ts +0 -2
- package/dist/prompt.js +0 -62
- package/dist/resolve.d.ts +0 -16
- package/dist/resolve.js +0 -59
- package/dist/version-check.d.ts +0 -20
- package/dist/version-check.js +0 -81
- package/dist/websocket.d.ts +0 -22
- package/dist/websocket.js +0 -89
package/SKILL.md
DELETED
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: maritime
|
|
3
|
-
description: Deploy and operate AI agents on Maritime (maritime.sh), a cloud that gives every agent its own persistent Firecracker micro-VM that sleeps when idle and wakes in about a second. Use when asked to host, deploy, run, or manage an agent on Maritime, to give an agent a persistent computer, to provision one agent per end user from a backend, or to move a bot, worker, or scheduled job onto Maritime. Covers signup, headless login, the JSON output contract, exit codes, deploy recipes, and the email verification wall.
|
|
4
|
-
metadata:
|
|
5
|
-
author: maritime-sh
|
|
6
|
-
version: "1.0"
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
# Maritime
|
|
10
|
-
|
|
11
|
-
Maritime hosts AI agents. Each agent runs in its own micro-VM with a persistent
|
|
12
|
-
disk at `/data`. It sleeps when idle (free while asleep), wakes in about a
|
|
13
|
-
second on the next message or trigger, and hosting is a flat monthly plan with
|
|
14
|
-
no metering. The free plan includes 3 machines, no card.
|
|
15
|
-
|
|
16
|
-
This skill is for driving Maritime as a program or an AI agent, not as a
|
|
17
|
-
human at a keyboard. Every command speaks JSON and every failure is
|
|
18
|
-
structured.
|
|
19
|
-
|
|
20
|
-
## Rules
|
|
21
|
-
|
|
22
|
-
1. Pass `--json` on every command. Success: one JSON value on stdout, stderr
|
|
23
|
-
empty. Failure: `{"ok": false, "error": {"code", "message", "status"}}` on
|
|
24
|
-
stderr, stdout empty. Read stdout, branch on the exit code, never scrape
|
|
25
|
-
human text.
|
|
26
|
-
2. Exit codes: `0` ok, `1` error, `2` auth, `3` not found, `4` usage.
|
|
27
|
-
3. Never guess flags. `maritime guide --json` prints the full command and flag
|
|
28
|
-
manifest, introspected from the installed CLI.
|
|
29
|
-
4. Never paste a secret into chat. Keys go into env vars or `maritime env set`.
|
|
30
|
-
5. Confirm with the user before a paid create. On the free plan a create is
|
|
31
|
-
free (3 machines). A refused create exits `1` with `error.status` 402 and
|
|
32
|
-
`error.code` `seat_limit`; show `error.message` unchanged, it names the fix.
|
|
33
|
-
|
|
34
|
-
## Install
|
|
35
|
-
|
|
36
|
-
```bash
|
|
37
|
-
npm install -g maritime-cli # Node 20.12 or later; the command is `maritime`
|
|
38
|
-
maritime --version # 1.9.0 or later has `login --device` and `signup` in --help
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
If a flag below is unknown, the CLI is old: `npm install -g maritime-cli@latest`.
|
|
42
|
-
|
|
43
|
-
## Authenticate
|
|
44
|
-
|
|
45
|
-
Try these in order and stop at the first that works.
|
|
46
|
-
|
|
47
|
-
1. A token is already present: `MARITIME_TOKEN` in the environment, or a
|
|
48
|
-
saved login. Check with `maritime whoami --json` (exit `2` means no token).
|
|
49
|
-
2. The user has an account and you have no browser: `maritime login --device
|
|
50
|
-
--json`. It prints a code on stderr as one JSON line
|
|
51
|
-
(`{"action":"device_code","user_code":"XXXX-XXXX","verification_uri_complete":"..."}`).
|
|
52
|
-
Show the user the URL and the code, then wait; the command returns when
|
|
53
|
-
they approve.
|
|
54
|
-
3. The user has an account and a browser on this machine: `maritime login`.
|
|
55
|
-
4. No account: `maritime signup -e <email> -p <password> -n <name> --json`.
|
|
56
|
-
Ask the user for the email and password; never invent them. Signup saves a
|
|
57
|
-
token and returns `emailVerified: false`.
|
|
58
|
-
|
|
59
|
-
The email verification wall: until the user clicks the link Maritime emailed
|
|
60
|
-
them, `create`, `deploy`, `start`, `restart`, `keys create` and computer
|
|
61
|
-
creation are refused with status `403` and `error.code`
|
|
62
|
-
`email_not_verified`. When you see it, tell the user to open the email and
|
|
63
|
-
click the link, offer `maritime login --resend` to send it again, then retry
|
|
64
|
-
the same command. Everything else (list, status, logs, templates) works
|
|
65
|
-
before verification.
|
|
66
|
-
|
|
67
|
-
For long-running automation mint a key once the account is verified:
|
|
68
|
-
`maritime keys create --name <purpose> --json` returns `raw_key` (`mk_...`,
|
|
69
|
-
shown once, never expires). Export it as `MARITIME_TOKEN`.
|
|
70
|
-
|
|
71
|
-
`MARITIME_API_URL` overrides the API base (default `https://api.maritime.sh`).
|
|
72
|
-
|
|
73
|
-
## Deploy
|
|
74
|
-
|
|
75
|
-
Pick the recipe that matches what the user has.
|
|
76
|
-
|
|
77
|
-
### A ready-made agent from a template
|
|
78
|
-
|
|
79
|
-
```bash
|
|
80
|
-
maritime templates --json # ids: openclaw, hermes, zeroclaw, claude_code, codex, dsh
|
|
81
|
-
maritime create my-agent --template openclaw --json
|
|
82
|
-
maritime status my-agent --json # poll until .status is "active"
|
|
83
|
-
maritime chat my-agent "introduce yourself" --json | jq -r '.response'
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
Most templates need no model key (Maritime's metered LLM proxy). `claude_code`
|
|
87
|
-
is the exception: it needs `ANTHROPIC_API_KEY` as a secret env var.
|
|
88
|
-
|
|
89
|
-
### The user's own code (any framework, Dockerfile at the repo root)
|
|
90
|
-
|
|
91
|
-
```bash
|
|
92
|
-
maritime create my-bot --repo https://github.com/you/agent --json
|
|
93
|
-
maritime status my-bot --json # builds take 1 to 3 minutes
|
|
94
|
-
maritime logs my-bot --json
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
The container contract: listen on `0.0.0.0:$PORT` (injected, never hardcode
|
|
98
|
-
8080), answer `GET /health` with any 2xx, answer `POST /chat` with JSON
|
|
99
|
-
`{"message": "..."}` within 30 seconds returning text or JSON with one of
|
|
100
|
-
`response`, `reply`, `message`, `text`, `output`. Persist under `/data` only.
|
|
101
|
-
Never use a shell-string `CMD`; launch a real program. Full contract:
|
|
102
|
-
https://maritime.sh/docs/frameworks/custom.md
|
|
103
|
-
|
|
104
|
-
Private GitHub repos need the Maritime GitHub App installed from the
|
|
105
|
-
dashboard. Pre-built public images: `POST /api/agents` with
|
|
106
|
-
`{"framework": "custom", "imageName": "ghcr.io/acme/img:tag"}`.
|
|
107
|
-
|
|
108
|
-
### A public web app on its own HTTPS URL
|
|
109
|
-
|
|
110
|
-
```bash
|
|
111
|
-
maritime create my-app --repo https://github.com/you/app --public --port 3000 --json
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
It sleeps when idle and wakes on the next visit.
|
|
115
|
-
|
|
116
|
-
### Secrets and env vars
|
|
117
|
-
|
|
118
|
-
```bash
|
|
119
|
-
maritime env set my-agent OPENAI_API_KEY=sk-... --reload --json # secret by default
|
|
120
|
-
maritime env import my-agent ./prod.env --reload --json
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
Without `--reload` the change applies on the next boot.
|
|
124
|
-
|
|
125
|
-
### Schedules
|
|
126
|
-
|
|
127
|
-
Timers inside a sleeping VM do not fire. Use platform triggers:
|
|
128
|
-
|
|
129
|
-
```bash
|
|
130
|
-
maritime triggers create my-agent --type cron --cron "0 9 * * *" --json
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
### One agent per end user, from a backend
|
|
134
|
-
|
|
135
|
-
Use the SDK instead of the CLI: `npm install maritime-sdk` or
|
|
136
|
-
`pip install maritime`, key in `MARITIME_API_KEY`. `provision({externalId})`
|
|
137
|
-
is idempotent. Docs: https://maritime.sh/docs/build.md
|
|
138
|
-
|
|
139
|
-
### A persistent desktop for an existing agent (Computers, paid plan)
|
|
140
|
-
|
|
141
|
-
One MCP server, one Linux desktop per end user id:
|
|
142
|
-
|
|
143
|
-
```bash
|
|
144
|
-
claude mcp add --transport http maritime-computers https://mcp.maritime.sh/mcp \
|
|
145
|
-
--header "Authorization: Bearer mk_..."
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
Docs: https://maritime.sh/docs/computers.md
|
|
149
|
-
|
|
150
|
-
## Verify before you finish
|
|
151
|
-
|
|
152
|
-
1. `maritime status <agent> --json` reports `active` (or `sleeping` after
|
|
153
|
-
idle; both are healthy).
|
|
154
|
-
2. `maritime chat <agent> "hello" --json` returns a reply, or for a custom
|
|
155
|
-
container `maritime logs <agent> --json` shows the server listening.
|
|
156
|
-
3. Tell the user the agent name, the dashboard URL
|
|
157
|
-
`https://maritime.sh/agents`, and what you changed in their repo.
|
|
158
|
-
|
|
159
|
-
## Inspect and repair
|
|
160
|
-
|
|
161
|
-
```bash
|
|
162
|
-
maritime list --json
|
|
163
|
-
maritime info my-agent --json # env count, triggers, last deploy
|
|
164
|
-
maritime history my-agent --json # build and deploy attempts with buildLog
|
|
165
|
-
maritime exec my-agent ls /data --json | jq -r '.stdout'
|
|
166
|
-
maritime restart my-agent --json # also picks up new env vars
|
|
167
|
-
maritime delete my-agent --yes --json # --yes is required non-interactively
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
`error.code` `agent_unavailable` on chat means the agent is not running:
|
|
171
|
-
`maritime start <agent>`, wait a few seconds, retry. A 404 on exec or files
|
|
172
|
-
usually means the agent is asleep or errored: start it, do not recreate it.
|
|
173
|
-
|
|
174
|
-
## Reference
|
|
175
|
-
|
|
176
|
-
- Contract file: https://maritime.sh/docs/cli/llms.txt
|
|
177
|
-
- Setup procedure for agents: https://maritime.sh/agents.md
|
|
178
|
-
- Everything: https://maritime.sh/llms.txt (index) and https://maritime.sh/llms-full.txt
|
|
179
|
-
- REST API: https://api.maritime.sh/openapi.json (bearer `mk_` key)
|
|
180
|
-
- Any docs page as markdown: append `.md` to its URL, for example
|
|
181
|
-
https://maritime.sh/docs/quickstart.md
|
package/dist/api.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
type JsonRecord = Record<string, unknown>;
|
|
2
|
-
export declare class CliHttpError extends Error {
|
|
3
|
-
status: number;
|
|
4
|
-
detail: string;
|
|
5
|
-
/** Machine-readable error code from the server when present, e.g.
|
|
6
|
-
* 'seat_limit' when the account hit its plan's agent cap, needs a paid
|
|
7
|
-
* plan for an add-on, or has a lapsed plan. */
|
|
8
|
-
code?: string;
|
|
9
|
-
constructor(status: number, detail: string, code?: string);
|
|
10
|
-
}
|
|
11
|
-
export interface CliUser {
|
|
12
|
-
id: string;
|
|
13
|
-
email: string;
|
|
14
|
-
name?: string | null;
|
|
15
|
-
image?: string | null;
|
|
16
|
-
}
|
|
17
|
-
export interface CliAuthResponse {
|
|
18
|
-
token: string;
|
|
19
|
-
user: CliUser;
|
|
20
|
-
}
|
|
21
|
-
export declare function getApiUrl(): string;
|
|
22
|
-
export declare function requireAuth(): string;
|
|
23
|
-
export declare function isVerbose(): boolean;
|
|
24
|
-
export declare function postJson<T>(path: string, body: JsonRecord): Promise<T>;
|
|
25
|
-
export declare function authGet<T>(path: string): Promise<T>;
|
|
26
|
-
export declare function authPost<T>(path: string, body?: JsonRecord): Promise<T>;
|
|
27
|
-
export declare function authPut<T>(path: string, body?: JsonRecord): Promise<T>;
|
|
28
|
-
export declare function authDelete<T = JsonRecord>(path: string): Promise<T>;
|
|
29
|
-
export declare function publicGet<T>(path: string): Promise<T>;
|
|
30
|
-
export {};
|
package/dist/api.js
DELETED
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
import { config } from './config.js';
|
|
3
|
-
import { fail, EXIT } from './output.js';
|
|
4
|
-
export class CliHttpError extends Error {
|
|
5
|
-
status;
|
|
6
|
-
detail;
|
|
7
|
-
/** Machine-readable error code from the server when present, e.g.
|
|
8
|
-
* 'seat_limit' when the account hit its plan's agent cap, needs a paid
|
|
9
|
-
* plan for an add-on, or has a lapsed plan. */
|
|
10
|
-
code;
|
|
11
|
-
constructor(status, detail, code) {
|
|
12
|
-
super(detail);
|
|
13
|
-
this.status = status;
|
|
14
|
-
this.detail = detail;
|
|
15
|
-
this.code = code;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
function isErrorWithMessage(error) {
|
|
19
|
-
return typeof error === 'object' && error !== null && 'message' in error;
|
|
20
|
-
}
|
|
21
|
-
export function getApiUrl() {
|
|
22
|
-
const stored = config.get('apiUrl');
|
|
23
|
-
return (stored ||
|
|
24
|
-
process.env.MARITIME_API_URL ||
|
|
25
|
-
process.env.NEXT_PUBLIC_API_URL ||
|
|
26
|
-
'https://api.maritime.sh').replace(/\/+$/, '');
|
|
27
|
-
}
|
|
28
|
-
// ---------------------------------------------------------------------------
|
|
29
|
-
// Token helpers
|
|
30
|
-
// ---------------------------------------------------------------------------
|
|
31
|
-
function decodeTokenPayload(token) {
|
|
32
|
-
try {
|
|
33
|
-
const parts = token.split('.');
|
|
34
|
-
if (parts.length !== 3)
|
|
35
|
-
return null;
|
|
36
|
-
return JSON.parse(Buffer.from(parts[1], 'base64url').toString());
|
|
37
|
-
}
|
|
38
|
-
catch {
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
function getTokenExpiry(token) {
|
|
43
|
-
const payload = decodeTokenPayload(token);
|
|
44
|
-
if (!payload || typeof payload.exp !== 'number')
|
|
45
|
-
return null;
|
|
46
|
-
return payload.exp * 1000; // convert to ms
|
|
47
|
-
}
|
|
48
|
-
function isTokenExpired(token) {
|
|
49
|
-
const exp = getTokenExpiry(token);
|
|
50
|
-
if (exp === null)
|
|
51
|
-
return false;
|
|
52
|
-
return Date.now() >= exp;
|
|
53
|
-
}
|
|
54
|
-
function isTokenExpiringSoon(token, thresholdMs = 7 * 24 * 60 * 60 * 1000) {
|
|
55
|
-
const exp = getTokenExpiry(token);
|
|
56
|
-
if (exp === null)
|
|
57
|
-
return false;
|
|
58
|
-
return Date.now() + thresholdMs >= exp;
|
|
59
|
-
}
|
|
60
|
-
async function maybeRefreshToken(token) {
|
|
61
|
-
if (!isTokenExpiringSoon(token))
|
|
62
|
-
return token;
|
|
63
|
-
try {
|
|
64
|
-
const url = `${getApiUrl()}/api/auth/cli-refresh`;
|
|
65
|
-
const response = await fetch(url, {
|
|
66
|
-
method: 'POST',
|
|
67
|
-
headers: {
|
|
68
|
-
Authorization: `Bearer ${token}`,
|
|
69
|
-
'Content-Type': 'application/json',
|
|
70
|
-
},
|
|
71
|
-
});
|
|
72
|
-
if (!response.ok)
|
|
73
|
-
return token;
|
|
74
|
-
const data = (await response.json());
|
|
75
|
-
if (data.token) {
|
|
76
|
-
config.set('token', data.token);
|
|
77
|
-
if (data.user) {
|
|
78
|
-
config.set('user', data.user.email);
|
|
79
|
-
config.set('userId', data.user.id);
|
|
80
|
-
}
|
|
81
|
-
return data.token;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
catch {
|
|
85
|
-
// Refresh failed silently, continue with current token
|
|
86
|
-
}
|
|
87
|
-
return token;
|
|
88
|
-
}
|
|
89
|
-
// ---------------------------------------------------------------------------
|
|
90
|
-
// Auth
|
|
91
|
-
// ---------------------------------------------------------------------------
|
|
92
|
-
export function requireAuth() {
|
|
93
|
-
// 1. Check env var first (for CI/CD usage)
|
|
94
|
-
const envToken = process.env.MARITIME_TOKEN;
|
|
95
|
-
if (envToken)
|
|
96
|
-
return envToken;
|
|
97
|
-
// 2. Fall back to stored token
|
|
98
|
-
const token = config.get('token');
|
|
99
|
-
if (!token) {
|
|
100
|
-
fail('Not logged in. Run `maritime login`, or set the MARITIME_TOKEN env var.', {
|
|
101
|
-
code: 'not_authenticated',
|
|
102
|
-
exitCode: EXIT.AUTH,
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
// 3. Check expiry
|
|
106
|
-
if (isTokenExpired(token)) {
|
|
107
|
-
fail('Token expired. Run `maritime login` to re-authenticate, or set the MARITIME_TOKEN env var.', {
|
|
108
|
-
code: 'token_expired',
|
|
109
|
-
exitCode: EXIT.AUTH,
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
return token;
|
|
113
|
-
}
|
|
114
|
-
// ---------------------------------------------------------------------------
|
|
115
|
-
// Verbose mode
|
|
116
|
-
// ---------------------------------------------------------------------------
|
|
117
|
-
export function isVerbose() {
|
|
118
|
-
return process.argv.includes('--verbose');
|
|
119
|
-
}
|
|
120
|
-
// ---------------------------------------------------------------------------
|
|
121
|
-
// HTTP client
|
|
122
|
-
// ---------------------------------------------------------------------------
|
|
123
|
-
async function parseJson(response) {
|
|
124
|
-
const text = await response.text();
|
|
125
|
-
if (!text) {
|
|
126
|
-
return {};
|
|
127
|
-
}
|
|
128
|
-
try {
|
|
129
|
-
return JSON.parse(text);
|
|
130
|
-
}
|
|
131
|
-
catch {
|
|
132
|
-
// A non-JSON body is almost always an edge/proxy error page (502/503
|
|
133
|
-
// HTML, plain-text 500). Surface the status and a snippet so the
|
|
134
|
-
// operator sees WHAT the server said instead of a bare parse failure.
|
|
135
|
-
const snippet = text.replace(/<[^>]*>/g, ' ').replace(/\s+/g, ' ').trim().slice(0, 160);
|
|
136
|
-
throw new CliHttpError(response.status, `Non-JSON response (HTTP ${response.status}) from ${response.url}` +
|
|
137
|
-
(snippet ? `: ${snippet}` : ''));
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
async function handleResponse(response) {
|
|
141
|
-
const payload = await parseJson(response);
|
|
142
|
-
if (!response.ok) {
|
|
143
|
-
const detail = typeof payload.detail === 'string'
|
|
144
|
-
? payload.detail
|
|
145
|
-
: `Request failed with status ${response.status}`;
|
|
146
|
-
// `code` is Maritime's own field; `error` is the RFC 8628 shape the
|
|
147
|
-
// device-login endpoints answer with ({"error": "authorization_pending"}).
|
|
148
|
-
const code = typeof payload.code === 'string'
|
|
149
|
-
? payload.code
|
|
150
|
-
: typeof payload.error === 'string'
|
|
151
|
-
? payload.error
|
|
152
|
-
: undefined;
|
|
153
|
-
throw new CliHttpError(response.status, detail, code);
|
|
154
|
-
}
|
|
155
|
-
return payload;
|
|
156
|
-
}
|
|
157
|
-
async function requestJson(path, init) {
|
|
158
|
-
const url = `${getApiUrl()}${path}`;
|
|
159
|
-
const verbose = isVerbose();
|
|
160
|
-
const start = verbose ? Date.now() : 0;
|
|
161
|
-
if (verbose) {
|
|
162
|
-
console.log(chalk.dim(` → ${init.method ?? 'GET'} ${url}`));
|
|
163
|
-
}
|
|
164
|
-
let lastError;
|
|
165
|
-
const maxAttempts = 3;
|
|
166
|
-
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
167
|
-
try {
|
|
168
|
-
const response = await fetch(url, init);
|
|
169
|
-
if (verbose) {
|
|
170
|
-
console.log(chalk.dim(` ← ${response.status} (${Date.now() - start}ms)`));
|
|
171
|
-
}
|
|
172
|
-
// Retry on 503 (service unavailable)
|
|
173
|
-
if (response.status === 503 && attempt < maxAttempts) {
|
|
174
|
-
lastError = new CliHttpError(503, 'Service temporarily unavailable');
|
|
175
|
-
await new Promise((r) => setTimeout(r, 1000 * attempt));
|
|
176
|
-
continue;
|
|
177
|
-
}
|
|
178
|
-
return await handleResponse(response);
|
|
179
|
-
}
|
|
180
|
-
catch (error) {
|
|
181
|
-
// Only retry network errors, not HTTP errors
|
|
182
|
-
if (error instanceof CliHttpError)
|
|
183
|
-
throw error;
|
|
184
|
-
lastError = error;
|
|
185
|
-
if (attempt < maxAttempts) {
|
|
186
|
-
await new Promise((r) => setTimeout(r, 1000 * attempt));
|
|
187
|
-
continue;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
const detail = isErrorWithMessage(lastError) ? lastError.message : 'Unknown network error';
|
|
192
|
-
throw new CliHttpError(0, `Unable to reach Maritime API at ${getApiUrl()}: ${detail}`);
|
|
193
|
-
}
|
|
194
|
-
export async function postJson(path, body) {
|
|
195
|
-
return requestJson(path, {
|
|
196
|
-
method: 'POST',
|
|
197
|
-
headers: { 'Content-Type': 'application/json' },
|
|
198
|
-
body: JSON.stringify(body),
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
function authHeaders(token) {
|
|
202
|
-
return {
|
|
203
|
-
Authorization: `Bearer ${token}`,
|
|
204
|
-
'Content-Type': 'application/json',
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
export async function authGet(path) {
|
|
208
|
-
let token = requireAuth();
|
|
209
|
-
token = await maybeRefreshToken(token);
|
|
210
|
-
return requestJson(path, {
|
|
211
|
-
method: 'GET',
|
|
212
|
-
headers: authHeaders(token),
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
export async function authPost(path, body = {}) {
|
|
216
|
-
let token = requireAuth();
|
|
217
|
-
token = await maybeRefreshToken(token);
|
|
218
|
-
return requestJson(path, {
|
|
219
|
-
method: 'POST',
|
|
220
|
-
headers: authHeaders(token),
|
|
221
|
-
body: JSON.stringify(body),
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
export async function authPut(path, body = {}) {
|
|
225
|
-
let token = requireAuth();
|
|
226
|
-
token = await maybeRefreshToken(token);
|
|
227
|
-
return requestJson(path, {
|
|
228
|
-
method: 'PUT',
|
|
229
|
-
headers: authHeaders(token),
|
|
230
|
-
body: JSON.stringify(body),
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
export async function authDelete(path) {
|
|
234
|
-
let token = requireAuth();
|
|
235
|
-
token = await maybeRefreshToken(token);
|
|
236
|
-
return requestJson(path, {
|
|
237
|
-
method: 'DELETE',
|
|
238
|
-
headers: authHeaders(token),
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
export async function publicGet(path) {
|
|
242
|
-
return requestJson(path, {
|
|
243
|
-
method: 'GET',
|
|
244
|
-
headers: { 'Content-Type': 'application/json' },
|
|
245
|
-
});
|
|
246
|
-
}
|
package/dist/bundled.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Reads a file shipped at the package root (the `files` list in package.json),
|
|
3
|
-
* such as AGENTS.md or SKILL.md.
|
|
4
|
-
*
|
|
5
|
-
* Works from both the built layout (dist/bundled.js, one level below the
|
|
6
|
-
* root) and the tsx dev layout (src/bundled.ts). Returns null when the file
|
|
7
|
-
* was not shipped.
|
|
8
|
-
*
|
|
9
|
-
* @param name The file name at the package root.
|
|
10
|
-
*/
|
|
11
|
-
export declare function readBundledFile(name: string): string | null;
|
package/dist/bundled.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from 'node:fs';
|
|
2
|
-
import { fileURLToPath } from 'node:url';
|
|
3
|
-
import { dirname, join } from 'node:path';
|
|
4
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
5
|
-
/**
|
|
6
|
-
* Reads a file shipped at the package root (the `files` list in package.json),
|
|
7
|
-
* such as AGENTS.md or SKILL.md.
|
|
8
|
-
*
|
|
9
|
-
* Works from both the built layout (dist/bundled.js, one level below the
|
|
10
|
-
* root) and the tsx dev layout (src/bundled.ts). Returns null when the file
|
|
11
|
-
* was not shipped.
|
|
12
|
-
*
|
|
13
|
-
* @param name The file name at the package root.
|
|
14
|
-
*/
|
|
15
|
-
export function readBundledFile(name) {
|
|
16
|
-
for (const rel of [['..', name], ['..', '..', name]]) {
|
|
17
|
-
try {
|
|
18
|
-
return readFileSync(join(__dirname, ...rel), 'utf-8');
|
|
19
|
-
}
|
|
20
|
-
catch {
|
|
21
|
-
// try the next candidate
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return null;
|
|
25
|
-
}
|
package/dist/commands/chat.d.ts
DELETED
package/dist/commands/chat.js
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
2
|
-
import { authPost } from '../api.js';
|
|
3
|
-
import { resolveAgent } from '../resolve.js';
|
|
4
|
-
import { getLinkedAgentId } from '../context.js';
|
|
5
|
-
import { outputResult, fail, handleError, makeSpinner } from '../output.js';
|
|
6
|
-
/** Read all of stdin (used when the message isn't passed as an argument). */
|
|
7
|
-
function readStdin() {
|
|
8
|
-
return new Promise((resolve) => {
|
|
9
|
-
let data = '';
|
|
10
|
-
const done = () => {
|
|
11
|
-
// Release the handle so the process can exit the moment the command
|
|
12
|
-
// finishes (a listening stdin would otherwise hold the event loop).
|
|
13
|
-
process.stdin.pause();
|
|
14
|
-
process.stdin.removeAllListeners('data');
|
|
15
|
-
resolve(data);
|
|
16
|
-
};
|
|
17
|
-
process.stdin.setEncoding('utf8');
|
|
18
|
-
process.stdin.on('data', (chunk) => {
|
|
19
|
-
data += chunk;
|
|
20
|
-
});
|
|
21
|
-
process.stdin.once('end', done);
|
|
22
|
-
process.stdin.once('error', done);
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* The agent gateway's reply may be a plain string or a nested object
|
|
27
|
-
* ({response}, {message}, {text}, ...). Normalize to the human-readable text.
|
|
28
|
-
*/
|
|
29
|
-
function extractReply(response) {
|
|
30
|
-
if (response == null)
|
|
31
|
-
return '';
|
|
32
|
-
if (typeof response === 'string')
|
|
33
|
-
return response;
|
|
34
|
-
if (typeof response === 'object') {
|
|
35
|
-
const obj = response;
|
|
36
|
-
for (const key of ['response', 'message', 'text', 'content', 'output']) {
|
|
37
|
-
if (typeof obj[key] === 'string')
|
|
38
|
-
return obj[key];
|
|
39
|
-
}
|
|
40
|
-
return JSON.stringify(response);
|
|
41
|
-
}
|
|
42
|
-
return String(response);
|
|
43
|
-
}
|
|
44
|
-
export const chatCommand = new Command('chat')
|
|
45
|
-
.alias('send')
|
|
46
|
-
.description('Send a message to an agent and print its reply')
|
|
47
|
-
.argument('[agent]', 'Agent name or ID (optional in a linked directory)')
|
|
48
|
-
.argument('[message...]', 'Message to send (reads stdin if omitted)')
|
|
49
|
-
.option('-a, --agent <name>', 'Target a specific agent (overrides the linked one)')
|
|
50
|
-
.option('-c, --conversation-id <id>', 'Conversation ID for multi-turn context')
|
|
51
|
-
.addHelpText('after', `
|
|
52
|
-
Examples:
|
|
53
|
-
maritime chat "what's the status?" # linked agent
|
|
54
|
-
maritime chat my-agent "what's the status?" # explicit agent
|
|
55
|
-
cat prompt.txt | maritime chat --json # linked agent, long prompt
|
|
56
|
-
maritime chat -a other "and then?" --conversation-id abc123`)
|
|
57
|
-
.action(async (agentPos, messageParts, opts) => {
|
|
58
|
-
try {
|
|
59
|
-
// Disambiguate "which agent" vs "the message" using the linked context:
|
|
60
|
-
// in a linked dir all positionals are the message (target = linked agent,
|
|
61
|
-
// overridable with -a); otherwise the first positional is the agent.
|
|
62
|
-
const positionals = [agentPos, ...(messageParts || [])].filter(Boolean);
|
|
63
|
-
let targetArg;
|
|
64
|
-
let message;
|
|
65
|
-
if (opts.agent) {
|
|
66
|
-
targetArg = opts.agent;
|
|
67
|
-
message = positionals.join(' ');
|
|
68
|
-
}
|
|
69
|
-
else if (getLinkedAgentId()) {
|
|
70
|
-
targetArg = undefined;
|
|
71
|
-
message = positionals.join(' ');
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
targetArg = agentPos;
|
|
75
|
-
message = (messageParts || []).join(' ');
|
|
76
|
-
}
|
|
77
|
-
message = message.trim();
|
|
78
|
-
if (!message && !process.stdin.isTTY) {
|
|
79
|
-
message = (await readStdin()).trim();
|
|
80
|
-
}
|
|
81
|
-
if (!message) {
|
|
82
|
-
fail('No message provided. Pass it as an argument or pipe it via stdin.', {
|
|
83
|
-
code: 'usage',
|
|
84
|
-
exitCode: 4,
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
const agent = await resolveAgent(targetArg);
|
|
88
|
-
const spinner = await makeSpinner(`Waiting for ${agent.name}...`);
|
|
89
|
-
let result;
|
|
90
|
-
try {
|
|
91
|
-
result = await authPost(`/api/agents/${agent.id}/chat`, {
|
|
92
|
-
message,
|
|
93
|
-
conversation_id: opts.conversationId,
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
catch (error) {
|
|
97
|
-
spinner.fail('Chat failed');
|
|
98
|
-
throw error;
|
|
99
|
-
}
|
|
100
|
-
spinner.stop();
|
|
101
|
-
// Backend surfaces upstream problems (e.g. agent not running) as `error`.
|
|
102
|
-
if (result.error) {
|
|
103
|
-
fail(result.error, { code: 'agent_unavailable' });
|
|
104
|
-
}
|
|
105
|
-
const reply = extractReply(result.response);
|
|
106
|
-
outputResult({
|
|
107
|
-
ok: true,
|
|
108
|
-
agentId: agent.id,
|
|
109
|
-
agentName: agent.name,
|
|
110
|
-
conversationId: opts.conversationId ?? null,
|
|
111
|
-
response: reply,
|
|
112
|
-
}, () => {
|
|
113
|
-
// Plain text on stdout — clean for piping into another tool.
|
|
114
|
-
process.stdout.write(reply + (reply.endsWith('\n') ? '' : '\n'));
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
catch (error) {
|
|
118
|
-
handleError(error);
|
|
119
|
-
}
|
|
120
|
-
});
|