agenmail 1.0.0 → 1.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/README.md +3 -2
- package/package.json +1 -1
- package/src/cli.js +1 -1
- package/src/commands.js +35 -38
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@ agem code # prints just the newest 6-digit code
|
|
|
23
23
|
| `agem mailme <id>` | Forward to your owner email |
|
|
24
24
|
| `agem block <sender>` / `agem unsubscribe <id>` | Stop a sender |
|
|
25
25
|
| `agem status` | Emails used of the free 100, spend vs cap |
|
|
26
|
-
| `agem claim <address>` |
|
|
26
|
+
| `agem claim <address>` | Owner-only: points to the GitHub login on the web |
|
|
27
27
|
|
|
28
28
|
## For agents
|
|
29
29
|
|
|
@@ -32,6 +32,7 @@ agem code # prints just the newest 6-digit code
|
|
|
32
32
|
- With `--json`, or when not in a terminal, agem never prompts. A missing value fails with a usage error.
|
|
33
33
|
- **Token:** `AGEM_TOKEN` env var, or `~/.agem/config.json` (written by `agem login`, mode 600).
|
|
34
34
|
- **API URL:** `AGEM_API_URL`, or `agem login --api <url>`. The default is `https://agenline.co`.
|
|
35
|
-
- **Non-interactive
|
|
35
|
+
- **Login:** agem logs in as an agent, using the agent token the owner creates in settings (owners sign in on the web with GitHub). Non-interactive: `AGEM_AGENT_TOKEN=agt_... agem login --address you@agenline.co --json`.
|
|
36
|
+
- Agent logins cannot claim addresses or view settings/billing: `agem claim` points to the owner's GitHub login, and `agem status` returns HTTP 403.
|
|
36
37
|
|
|
37
38
|
`agem --help`, `agem <command> --help` and `agem --version` work offline, with no login.
|
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -58,7 +58,7 @@ function rootHelp(c) {
|
|
|
58
58
|
{ title: 'ENVIRONMENT', rows: [
|
|
59
59
|
['AGEM_TOKEN', 'Session token (overrides ~/.agem/config.json)'],
|
|
60
60
|
['AGEM_API_URL', `API base URL (default ${DEFAULT_API})`],
|
|
61
|
-
['
|
|
61
|
+
['AGEM_AGENT_TOKEN', 'Agent token for login without a prompt'],
|
|
62
62
|
] },
|
|
63
63
|
{ title: 'LEARN MORE', lines: ['Use `agem <command> --help` for more information about a command.'] },
|
|
64
64
|
{ title: 'EXAMPLES', lines: ['$ agem login', '$ agem inbox --unread', '$ agem code', '$ agem send --to me@gmail.com --subject Hi --body "Hello"'] },
|
package/src/commands.js
CHANGED
|
@@ -55,30 +55,30 @@ async function getMail(ctx, id) {
|
|
|
55
55
|
|
|
56
56
|
export const COMMANDS = {
|
|
57
57
|
login: {
|
|
58
|
-
summary: 'Log in
|
|
59
|
-
description: 'Log in with your @agenline.co address and
|
|
60
|
-
usage: 'agem login [--address <address>] [--
|
|
58
|
+
summary: 'Log in as an agent',
|
|
59
|
+
description: 'Log in as an agent with your @agenline.co address and the agent token the owner created in settings (owners sign in on the web with GitHub). The session token is saved to ~/.agem/config.json (or use AGEM_TOKEN).',
|
|
60
|
+
usage: 'agem login [--address <address>] [--agent-token <token>] [--api <url>]',
|
|
61
61
|
flags: {
|
|
62
62
|
address: { type: 'string', placeholder: '<address>', desc: 'Your @agenline.co address (or AGEM_ADDRESS)' },
|
|
63
|
-
|
|
63
|
+
'agent-token': { type: 'string', placeholder: '<token>', desc: 'Agent token from the owner (or AGEM_AGENT_TOKEN)' },
|
|
64
64
|
api: { type: 'string', placeholder: '<url>', desc: `API base URL (default ${DEFAULT_API})` },
|
|
65
65
|
},
|
|
66
|
-
examples: ['agem login', '
|
|
66
|
+
examples: ['agem login', 'AGEM_AGENT_TOKEN=agt_... agem login --address muse@agenline.co --json'],
|
|
67
67
|
async run(ctx, { flags }) {
|
|
68
68
|
const cfg = readConfig(ctx.io);
|
|
69
69
|
let address = flags.address ?? ctx.io.env.AGEM_ADDRESS;
|
|
70
|
-
let
|
|
70
|
+
let agentToken = flags['agent-token'] ?? ctx.io.env.AGEM_AGENT_TOKEN;
|
|
71
71
|
if (!address) {
|
|
72
72
|
if (!ctx.interactive) throw new UsageError('Missing --address (or set AGEM_ADDRESS).', 'login');
|
|
73
73
|
address = await ctx.io.prompt('Address: ');
|
|
74
74
|
}
|
|
75
|
-
if (!
|
|
76
|
-
if (!ctx.interactive) throw new UsageError('Missing --
|
|
77
|
-
|
|
75
|
+
if (!agentToken) {
|
|
76
|
+
if (!ctx.interactive) throw new UsageError('Missing --agent-token (or set AGEM_AGENT_TOKEN).', 'login');
|
|
77
|
+
agentToken = await ctx.io.prompt('Agent token: ', { hidden: true });
|
|
78
78
|
}
|
|
79
79
|
const apiUrl = (flags.api || ctx.io.env.AGEM_API_URL || cfg.api_url || DEFAULT_API).replace(/\/+$/, '');
|
|
80
80
|
if (!/^https?:\/\/[^\s/]+/.test(apiUrl)) throw new UsageError(`--api must be an http(s) URL, got "${apiUrl}".`, 'login');
|
|
81
|
-
const { data, token } = await ctx.api('POST', '/api/auth/login', {
|
|
81
|
+
const { data, token } = await ctx.api('POST', '/api/auth/agent-login', { address, agent_token: agentToken }, { auth: false, apiUrl });
|
|
82
82
|
if (!token) throw new CliError('Login succeeded but the server returned no session token.');
|
|
83
83
|
writeConfig(ctx.io, { ...cfg, api_url: apiUrl, token, address: data.email_address });
|
|
84
84
|
return ctx.done({ ok: true, address: data.email_address, api_url: apiUrl }, `Logged in as ${data.email_address}`);
|
|
@@ -107,7 +107,16 @@ export const COMMANDS = {
|
|
|
107
107
|
usage: 'agem whoami',
|
|
108
108
|
examples: ['agem whoami', 'agem whoami --json'],
|
|
109
109
|
async run(ctx) {
|
|
110
|
-
|
|
110
|
+
let s;
|
|
111
|
+
try {
|
|
112
|
+
s = (await ctx.api('GET', '/api/settings')).data;
|
|
113
|
+
} catch (e) {
|
|
114
|
+
// Agent logins cannot read settings: show what the CLI knows locally.
|
|
115
|
+
if (e?.code !== 'agent_forbidden') throw e;
|
|
116
|
+
const address = readConfig(ctx.io).address ?? null;
|
|
117
|
+
const out = { address, role: 'agent', api_url: ctx.apiUrl };
|
|
118
|
+
return ctx.done(out, () => kv([['Address', address ?? 'unknown'], ['Role', 'agent'], ['API', out.api_url]], ctx.c));
|
|
119
|
+
}
|
|
111
120
|
const out = { address: s.email_address, owner_email: s.owner_email, agent_mode: s.agent_mode, api_url: ctx.apiUrl };
|
|
112
121
|
return ctx.done(out, () => kv([
|
|
113
122
|
['Address', out.address], ['Owner email', out.owner_email], ['Agent mode', out.agent_mode ? 'on' : 'off'], ['API', out.api_url],
|
|
@@ -116,30 +125,14 @@ export const COMMANDS = {
|
|
|
116
125
|
},
|
|
117
126
|
|
|
118
127
|
claim: {
|
|
119
|
-
summary: 'Claim
|
|
120
|
-
description: '
|
|
121
|
-
usage: 'agem claim <address>
|
|
128
|
+
summary: 'Claim an address (owner)',
|
|
129
|
+
description: 'Claiming an @agenline.co address is owner-only and needs the owner\'s GitHub login on the web, so the CLI (agent login) cannot do it. This prints where to go.',
|
|
130
|
+
usage: 'agem claim <address>',
|
|
122
131
|
args: [{ name: 'address', required: true, desc: 'Address to claim, e.g. scout or scout@agenline.co' }],
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
examples: ['agem claim scout', 'agem claim scout --password "$PW" --owner-email me@gmail.com --json'],
|
|
128
|
-
async run(ctx, { args, flags }) {
|
|
129
|
-
let owner = flags['owner-email'];
|
|
130
|
-
if (!owner) {
|
|
131
|
-
if (!ctx.token) throw new UsageError('Missing --owner-email (or log in so your owner email can be used).', 'claim');
|
|
132
|
-
owner = (await ctx.api('GET', '/api/settings')).data.owner_email;
|
|
133
|
-
}
|
|
134
|
-
let password = flags.password ?? ctx.io.env.AGEM_PASSWORD;
|
|
135
|
-
if (!password) {
|
|
136
|
-
if (!ctx.interactive) throw new UsageError('Missing --password (or set AGEM_PASSWORD).', 'claim');
|
|
137
|
-
password = await ctx.io.prompt('Password for the new address: ', { hidden: true });
|
|
138
|
-
}
|
|
139
|
-
const { data } = await ctx.api('POST', '/api/auth/signup', { address: args.address, password, owner_email: owner }, { auth: false });
|
|
140
|
-
return ctx.done(data, () => {
|
|
141
|
-
return `${ICON.ok} Claimed ${data.email_address}${data.claim_cost_cents ? ` (${money(data.claim_cost_cents)} recorded)` : ' (free)'}. Run agem login --address ${data.email_address} to use it.\n`;
|
|
142
|
-
});
|
|
132
|
+
examples: ['agem claim scout'],
|
|
133
|
+
async run(ctx, { args }) {
|
|
134
|
+
const url = `${ctx.apiUrl}/api/auth/github`;
|
|
135
|
+
throw new CliError(`Claiming ${args.address} needs the owner's GitHub login. Open ${url} in a browser, sign in, then claim it there.`, { type: 'owner_only' });
|
|
143
136
|
},
|
|
144
137
|
},
|
|
145
138
|
|
|
@@ -333,12 +326,16 @@ export const COMMANDS = {
|
|
|
333
326
|
examples: ['agem status', 'agem status --json'],
|
|
334
327
|
async run(ctx) {
|
|
335
328
|
const { data: b } = await ctx.api('GET', '/api/billing/status');
|
|
336
|
-
|
|
329
|
+
// Agent logins get usage only (no plan/payments); show whatever the server returned.
|
|
330
|
+
const rows = [
|
|
337
331
|
['Emails', `${b.emails_used_this_month} / ${b.emails_free_limit} free this month`],
|
|
338
332
|
['Spend', `${money(b.spend_used_cents)} / ${money(b.spend_cap_cents)} cap`],
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
333
|
+
];
|
|
334
|
+
if (b.plan !== undefined) rows.push(['Plan', b.plan]);
|
|
335
|
+
if (b.payments !== undefined) {
|
|
336
|
+
rows.push(['Payments', b.payments === 'under_maintenance' ? 'Payments under maintenance (no money is taken)' : b.payments]);
|
|
337
|
+
}
|
|
338
|
+
return ctx.done(b, () => kv(rows, ctx.c));
|
|
342
339
|
},
|
|
343
340
|
},
|
|
344
341
|
};
|