@atomicmail/agent-skill 0.1.0 → 0.2.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 +91 -0
- package/SKILL.md +53 -193
- package/esm/_dnt.polyfills.d.ts +101 -0
- package/esm/_dnt.polyfills.d.ts.map +1 -0
- package/esm/_dnt.polyfills.js +127 -0
- package/esm/{skill/scripts/lib/auth.d.ts → lib/agent/auth/agent-auth-http.d.ts} +1 -17
- package/esm/lib/agent/auth/agent-auth-http.d.ts.map +1 -0
- package/esm/lib/agent/auth/agent-auth-http.js +76 -0
- package/esm/lib/agent/auth/agent-jwt.d.ts +14 -0
- package/esm/lib/agent/auth/agent-jwt.d.ts.map +1 -0
- package/esm/lib/agent/auth/agent-jwt.js +29 -0
- package/esm/lib/agent/auth/agent-pow.d.ts +5 -0
- package/esm/lib/agent/auth/agent-pow.d.ts.map +1 -0
- package/esm/lib/agent/auth/agent-pow.js +49 -0
- package/esm/lib/agent/jmap/agent-help-content.d.ts +4 -0
- package/esm/lib/agent/jmap/agent-help-content.d.ts.map +1 -0
- package/esm/lib/agent/jmap/agent-help-content.js +244 -0
- package/esm/lib/agent/jmap/agent-jmap.d.ts +49 -0
- package/esm/lib/agent/jmap/agent-jmap.d.ts.map +1 -0
- package/esm/lib/agent/jmap/agent-jmap.js +174 -0
- package/esm/lib/agent/jmap/agent-vars.d.ts +23 -0
- package/esm/lib/agent/jmap/agent-vars.d.ts.map +1 -0
- package/esm/lib/agent/jmap/agent-vars.js +65 -0
- package/esm/{skill/scripts/lib/credentials.d.ts → lib/agent/session/agent-credentials-store.d.ts} +4 -1
- package/esm/lib/agent/session/agent-credentials-store.d.ts.map +1 -0
- package/esm/{skill/scripts/lib/credentials.js → lib/agent/session/agent-credentials-store.js} +28 -8
- package/esm/lib/agent/session/agent-resolve-config.d.ts +24 -0
- package/esm/lib/agent/session/agent-resolve-config.d.ts.map +1 -0
- package/esm/lib/agent/session/agent-resolve-config.js +70 -0
- package/esm/lib/agent/session/agent-session.d.ts +62 -0
- package/esm/lib/agent/session/agent-session.d.ts.map +1 -0
- package/esm/lib/agent/session/agent-session.js +206 -0
- package/esm/lib/core/consts.d.ts.map +1 -0
- package/esm/lib/core/types.d.ts +2 -0
- package/esm/lib/core/types.d.ts.map +1 -0
- package/esm/lib/core/types.js +1 -0
- package/esm/lib/core/utils.d.ts +10 -0
- package/esm/lib/core/utils.d.ts.map +1 -0
- package/esm/lib/core/utils.js +28 -0
- package/esm/lib/mod.d.ts +14 -0
- package/esm/lib/mod.d.ts.map +1 -0
- package/esm/lib/mod.js +13 -0
- package/esm/lib/network/auth-client.d.ts +57 -0
- package/esm/lib/network/auth-client.d.ts.map +1 -0
- package/esm/lib/network/auth-client.js +188 -0
- package/esm/skill/cli.d.ts +3 -0
- package/esm/skill/cli.d.ts.map +1 -0
- package/esm/skill/cli.js +306 -0
- package/package.json +5 -6
- package/presets/list_inbox.json +39 -0
- package/presets/reply.json +75 -0
- package/presets/send_mail.json +42 -0
- package/esm/lib/src/consts.d.ts.map +0 -1
- package/esm/skill/scripts/jmap_request.d.ts +0 -3
- package/esm/skill/scripts/jmap_request.d.ts.map +0 -1
- package/esm/skill/scripts/jmap_request.js +0 -265
- package/esm/skill/scripts/lib/auth.d.ts.map +0 -1
- package/esm/skill/scripts/lib/auth.js +0 -163
- package/esm/skill/scripts/lib/credentials.d.ts.map +0 -1
- package/esm/skill/scripts/signup.d.ts +0 -3
- package/esm/skill/scripts/signup.d.ts.map +0 -1
- package/esm/skill/scripts/signup.js +0 -170
- /package/esm/lib/{src → core}/consts.d.ts +0 -0
- /package/esm/lib/{src → core}/consts.js +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# @atomicmail/agent-skill
|
|
2
|
+
|
|
3
|
+
Atomic Mail AgentSkill CLI for shell-capable AI agents. It exposes three
|
|
4
|
+
commands: `register`, `jmap_request`, and `help`.
|
|
5
|
+
|
|
6
|
+
## Install / run
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npx --package=@atomicmail/agent-skill atomicmail --help
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Quick start
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npx --package=@atomicmail/agent-skill atomicmail register \
|
|
16
|
+
--username "myagent"
|
|
17
|
+
|
|
18
|
+
npx --package=@atomicmail/agent-skill atomicmail jmap_request \
|
|
19
|
+
--ops '[["Mailbox/get", {"accountId": "$ACCOUNT_ID"}, "m0"]]'
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## `jmap_request` and placeholders
|
|
23
|
+
|
|
24
|
+
- Built-in placeholders: `$ACCOUNT_ID`, `$INBOX`
|
|
25
|
+
- Custom placeholders: any `$VAR_NAME` via `--vars '{"VAR_NAME":"value"}'`
|
|
26
|
+
- Works for both `--ops` and `--ops-file`
|
|
27
|
+
|
|
28
|
+
Example:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npx --package=@atomicmail/agent-skill atomicmail jmap_request \
|
|
32
|
+
--ops-file send_mail.json \
|
|
33
|
+
--vars '{"TO":"alice@example.com","SUBJECT":"Hello","BODY":"Hi there"}'
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Presets and placeholders
|
|
37
|
+
|
|
38
|
+
Presets are reusable JSON files for `jmap_request`:
|
|
39
|
+
|
|
40
|
+
- Inline JSON: `--ops '[["Mailbox/get", {"accountId":"$ACCOUNT_ID"}, "m0"]]'`
|
|
41
|
+
- Preset file: `--ops-file list_inbox.json --vars '{"COUNT":"10"}'`
|
|
42
|
+
|
|
43
|
+
Resolution order for `--ops-file`:
|
|
44
|
+
|
|
45
|
+
1. Resolve relative to `--credentials-dir` (default `~/.atomicmail`).
|
|
46
|
+
2. If missing, fall back to bundled presets in the package.
|
|
47
|
+
|
|
48
|
+
Placeholder rules:
|
|
49
|
+
|
|
50
|
+
- Pattern: `$VAR_NAME`, where `VAR_NAME` matches `^[A-Z][A-Z0-9_]*$`.
|
|
51
|
+
- Built-ins: `$ACCOUNT_ID`, `$INBOX`.
|
|
52
|
+
- Lowercase `$tokens` such as JMAP back-references (`$draft`) are not matched.
|
|
53
|
+
- Custom placeholders: pass string values via `--vars`.
|
|
54
|
+
- Resolution order per variable: `--vars` first, then built-in auto-resolvers.
|
|
55
|
+
- Built-ins can be overridden via `--vars` using `ACCOUNT_ID` or `INBOX`.
|
|
56
|
+
- If any referenced variable is unresolved, `jmap_request` fails with a missing
|
|
57
|
+
variables error.
|
|
58
|
+
- Substitution is single-pass: inserted values are not scanned again for nested
|
|
59
|
+
`$VAR_NAME` tokens.
|
|
60
|
+
|
|
61
|
+
Bundled presets:
|
|
62
|
+
|
|
63
|
+
- `send_mail.json` (`$TO`, `$SUBJECT`, `$BODY`)
|
|
64
|
+
- `list_inbox.json` (`$COUNT`)
|
|
65
|
+
- `reply.json` (`$MAIL_ID`, `$BODY`)
|
|
66
|
+
|
|
67
|
+
`--ops-file` resolves against `--credentials-dir` first, then bundled presets
|
|
68
|
+
inside the package.
|
|
69
|
+
|
|
70
|
+
## Shared state
|
|
71
|
+
|
|
72
|
+
Credential files in `~/.atomicmail` (mode `0600`):
|
|
73
|
+
|
|
74
|
+
- `credentials.json`
|
|
75
|
+
- `session.jwt`
|
|
76
|
+
- `capability.jwt`
|
|
77
|
+
|
|
78
|
+
This is the on-disk state used by the CLI (and MCP).
|
|
79
|
+
|
|
80
|
+
## Defaults
|
|
81
|
+
|
|
82
|
+
- auth endpoint: `https://auth.atomicmail.ai`
|
|
83
|
+
- api endpoint: `https://api.atomicmail.ai`
|
|
84
|
+
- credentials directory: `~/.atomicmail`
|
|
85
|
+
|
|
86
|
+
## Overriding defaults
|
|
87
|
+
|
|
88
|
+
- Endpoints: `--auth-url`, `--api-url` or `ATOMIC_MAIL_AUTH_URL`,
|
|
89
|
+
`ATOMIC_MAIL_API_URL`
|
|
90
|
+
- Credentials path: `--credentials-dir` or `ATOMIC_MAIL_CREDENTIALS_DIR`
|
|
91
|
+
- PoW salt: `--scrypt-salt` or `ATOMIC_MAIL_SCRYPT_SALT`
|
package/SKILL.md
CHANGED
|
@@ -1,242 +1,102 @@
|
|
|
1
1
|
---
|
|
2
|
-
name:
|
|
3
|
-
description: Read and write email through the Atomic Mail ESP from an AI agent. Handles
|
|
4
|
-
license: MIT
|
|
5
|
-
compatibility: Requires Deno 2.0+ to run scripts directly, or Node 20+ / Bun 1.1+ via `npx @atomic-mail/agent-skill` after publishing. Needs network access to the configured Atomic Mail auth-service and api-service.
|
|
6
|
-
metadata:
|
|
7
|
-
author: atomic-mail
|
|
8
|
-
version: "0.1.0"
|
|
2
|
+
name: atomicmail
|
|
3
|
+
description: Read and write email through the Atomic Mail ESP from an AI agent. Handles proof-of-work authentication and JMAP so the agent thinks in JMAP method calls. Use when the user asks to register an email inbox, list mailboxes, fetch or send email.
|
|
9
4
|
---
|
|
10
5
|
|
|
11
6
|
# Atomic Mail
|
|
12
7
|
|
|
13
|
-
Atomic Mail
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
hides all of that behind two CLI scripts so the agent can focus on JMAP.
|
|
8
|
+
Atomic Mail exposes a programmable inbox over JMAP with PoW signup and JWT
|
|
9
|
+
rotation. This skill ships a single CLI entrypoint with three commands:
|
|
10
|
+
**`register`**, **`jmap_request`**, and **`help`** — matching the MCP server.
|
|
17
11
|
|
|
18
12
|
## When to use this skill
|
|
19
13
|
|
|
20
|
-
|
|
14
|
+
- Register a new inbox or log in with an existing API key.
|
|
15
|
+
- Send JMAP batches (inline JSON or preset files).
|
|
16
|
+
- Read built-in documentation (JMAP cheatsheet, presets, troubleshooting).
|
|
21
17
|
|
|
22
|
-
|
|
23
|
-
- Re-authenticate an existing Atomic Mail account using its API key.
|
|
24
|
-
- Read, search, or modify email via JMAP (`Mailbox/get`, `Email/query`,
|
|
25
|
-
`Email/get`, `Email/set`, etc.).
|
|
26
|
-
- Send email via JMAP (`EmailSubmission/set` with the
|
|
27
|
-
`urn:ietf:params:jmap:submission` capability).
|
|
28
|
-
- Discover the JMAP session object (`/.well-known/jmap`) to find the `accountId`
|
|
29
|
-
before issuing other JMAP method calls.
|
|
30
|
-
|
|
31
|
-
## Available scripts
|
|
32
|
-
|
|
33
|
-
- **`scripts/signup.ts`** — One-time setup: performs PoW signup or login and
|
|
34
|
-
writes credentials to disk. Run once per agent session/inbox.
|
|
35
|
-
- **`scripts/jmap_request.ts`** — Sends JMAP requests using the saved
|
|
36
|
-
credentials. Auto-rotates the session and capability JWTs as they expire.
|
|
37
|
-
|
|
38
|
-
Both scripts are invokable three ways. Pick the one that matches the runtime the
|
|
39
|
-
user has installed:
|
|
18
|
+
## Commands
|
|
40
19
|
|
|
41
20
|
```bash
|
|
42
|
-
|
|
43
|
-
deno run -A scripts/signup.ts ...
|
|
44
|
-
deno run -A scripts/jmap_request.ts ...
|
|
21
|
+
npx --package=@atomicmail/agent-skill atomicmail register --username "myagent"
|
|
45
22
|
|
|
46
|
-
|
|
47
|
-
npx -y @atomic-mail/agent-skill atomic-mail-signup ...
|
|
48
|
-
npx -y @atomic-mail/agent-skill atomic-mail-jmap ...
|
|
49
|
-
|
|
50
|
-
# Bun
|
|
51
|
-
bunx -y @atomic-mail/agent-skill atomic-mail-signup ...
|
|
52
|
-
bunx -y @atomic-mail/agent-skill atomic-mail-jmap ...
|
|
23
|
+
npx --package=@atomicmail/agent-skill atomicmail jmap_request --ops-file list_inbox.json --vars '{"COUNT":"10"}'
|
|
53
24
|
```
|
|
54
25
|
|
|
55
|
-
|
|
56
|
-
> spelling. Both scripts print full usage to stdout and exit `0`.
|
|
57
|
-
|
|
58
|
-
## Required configuration
|
|
26
|
+
Run **`atomicmail --help`** or **`atomicmail <command> --help`** for flags.
|
|
59
27
|
|
|
60
|
-
|
|
61
|
-
flags or set them in the environment:
|
|
28
|
+
## Defaults
|
|
62
29
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
| `--api-url` | `ATOMIC_MAIL_API_URL` | Base URL of `api-service` (JMAP). |
|
|
67
|
-
| `--scrypt-salt` | `ATOMIC_MAIL_SCRYPT_SALT` | Optional PoW salt override (defaults match `auth-service`). |
|
|
68
|
-
|
|
69
|
-
If the user does not know the URLs, ask them — they are deployment-specific.
|
|
30
|
+
- `authUrl`: `https://auth.atomicmail.ai`
|
|
31
|
+
- `apiUrl`: `https://api.atomicmail.ai`
|
|
32
|
+
- credentials directory: `~/.atomicmail`
|
|
70
33
|
|
|
71
34
|
## Workflow
|
|
72
35
|
|
|
73
|
-
### 1.
|
|
36
|
+
### 1. Register (new account)
|
|
74
37
|
|
|
75
38
|
```bash
|
|
76
|
-
|
|
77
|
-
--
|
|
78
|
-
--api-url "$ATOMIC_MAIL_API_URL" \
|
|
79
|
-
--username "alice" \
|
|
80
|
-
--out-dir "./.atomic-mail"
|
|
39
|
+
npx --package=@atomicmail/agent-skill atomicmail register \
|
|
40
|
+
--username "alice"
|
|
81
41
|
```
|
|
82
42
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
- `credentials.json` — `{ apiKey, inboxId, authUrl, apiUrl, scryptSalt }`. The
|
|
86
|
-
agent should store the `apiKey` securely; it is the long-lived secret.
|
|
87
|
-
- `session.jwt` — 4-hour session token.
|
|
88
|
-
- `capability.jwt` — 2-minute capability token used as the JMAP bearer.
|
|
89
|
-
|
|
90
|
-
The script prints a JSON summary to stdout that includes `inboxId` and `apiKey`.
|
|
91
|
-
Save these in the agent's persistent memory (or echo them back to the user) —
|
|
92
|
-
they are the only durable identifiers.
|
|
43
|
+
Writes `credentials.json`, `session.jwt`, `capability.jwt`. Prints JSON
|
|
44
|
+
including `inbox` and `accountId`.
|
|
93
45
|
|
|
94
|
-
### 2.
|
|
95
|
-
|
|
96
|
-
If `credentials.json` already exists, this is normally not needed —
|
|
97
|
-
`jmap_request.ts` will auto-renew session/capability tokens via the stored API
|
|
98
|
-
key. Use `signup.ts --api-key` only if the user wants to start a fresh
|
|
99
|
-
credentials directory from a known API key.
|
|
46
|
+
### 2. Register (existing API key, in case losing the credentials file)
|
|
100
47
|
|
|
101
48
|
```bash
|
|
102
|
-
|
|
103
|
-
--
|
|
104
|
-
--api-url "$ATOMIC_MAIL_API_URL" \
|
|
105
|
-
--api-key "11111111-2222-3333-4444-555555555555" \
|
|
106
|
-
--out-dir "./.atomic-mail"
|
|
49
|
+
npx --package=@atomicmail/agent-skill atomicmail register \
|
|
50
|
+
--api-key "..."
|
|
107
51
|
```
|
|
108
52
|
|
|
109
|
-
### 3.
|
|
110
|
-
|
|
111
|
-
Run this **once** before any other JMAP call to learn the `accountId` and
|
|
112
|
-
mailbox structure.
|
|
53
|
+
### 3. JMAP request
|
|
113
54
|
|
|
114
55
|
```bash
|
|
115
|
-
|
|
116
|
-
--
|
|
117
|
-
--session
|
|
56
|
+
npx --package=@atomicmail/agent-skill atomicmail jmap_request \
|
|
57
|
+
--ops '[["Mailbox/get", {"accountId": "$ACCOUNT_ID"}, "m0"]]'
|
|
118
58
|
```
|
|
119
59
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
`
|
|
60
|
+
`$ACCOUNT_ID` and `$INBOX` resolve from the session/credentials. Other
|
|
61
|
+
placeholders such as `$TO` or `$SUBJECT` require `--vars` with a JSON object of
|
|
62
|
+
strings (same substitution applies to `--ops` and `--ops-file`).
|
|
123
63
|
|
|
124
|
-
|
|
64
|
+
Preset file:
|
|
125
65
|
|
|
126
66
|
```bash
|
|
127
|
-
|
|
128
|
-
--
|
|
129
|
-
--ops '[["Mailbox/get", {"accountId": "ACCOUNT_ID"}, "m0"]]'
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
For multiple method calls or capabilities, pass a full envelope:
|
|
133
|
-
|
|
134
|
-
```bash
|
|
135
|
-
deno run -A scripts/jmap_request.ts \
|
|
136
|
-
--credentials-dir "./.atomic-mail" \
|
|
137
|
-
--ops '{
|
|
138
|
-
"using": ["urn:ietf:params:jmap:core","urn:ietf:params:jmap:mail"],
|
|
139
|
-
"methodCalls": [
|
|
140
|
-
["Mailbox/get", {"accountId": "ACCOUNT_ID"}, "m0"],
|
|
141
|
-
["Email/query", {"accountId": "ACCOUNT_ID", "limit": 10}, "q0"]
|
|
142
|
-
]
|
|
143
|
-
}'
|
|
67
|
+
npx --package=@atomicmail/agent-skill atomicmail jmap_request \
|
|
68
|
+
--ops-file fetch_last_100.json
|
|
144
69
|
```
|
|
145
70
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
For repeated tasks, save the JMAP body to a file and reuse it. The file may
|
|
149
|
-
contain either a `methodCalls` array or a full `{ using, methodCalls }`
|
|
150
|
-
envelope.
|
|
71
|
+
With custom placeholders:
|
|
151
72
|
|
|
152
73
|
```bash
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
"accountId": "ACCOUNT_ID",
|
|
157
|
-
"limit": 100,
|
|
158
|
-
"sort": [{ "property": "receivedAt", "isAscending": false }]
|
|
159
|
-
}, "q0"],
|
|
160
|
-
["Email/get", {
|
|
161
|
-
"accountId": "ACCOUNT_ID",
|
|
162
|
-
"#ids": { "resultOf": "q0", "name": "Email/query", "path": "/ids" },
|
|
163
|
-
"properties": ["id","threadId","subject","from","receivedAt","preview"]
|
|
164
|
-
}, "g0"]
|
|
165
|
-
]
|
|
166
|
-
EOF
|
|
167
|
-
|
|
168
|
-
deno run -A scripts/jmap_request.ts \
|
|
169
|
-
--credentials-dir "./.atomic-mail" \
|
|
170
|
-
--ops-file fetch_last_100.json
|
|
74
|
+
npx --package=@atomicmail/agent-skill atomicmail jmap_request \
|
|
75
|
+
--ops-file send_mail.json \
|
|
76
|
+
--vars '{"TO":"alice@example.com","SUBJECT":"Hello","BODY":"Hi there"}'
|
|
171
77
|
```
|
|
172
78
|
|
|
173
|
-
|
|
174
|
-
`mark_read.json`, etc.) and reuse them across runs.
|
|
79
|
+
Bundled presets (no local file creation required):
|
|
175
80
|
|
|
176
|
-
|
|
81
|
+
- `send_mail.json` (`$TO`, `$SUBJECT`, `$BODY`)
|
|
82
|
+
- `list_inbox.json` (`$COUNT`)
|
|
83
|
+
- `reply.json` (`$MAIL_ID`, `$BODY`)
|
|
177
84
|
|
|
178
|
-
|
|
179
|
-
draft. Remember to add the submission capability to `using`:
|
|
85
|
+
### 4. Help
|
|
180
86
|
|
|
181
87
|
```bash
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
--using "urn:ietf:params:jmap:core,urn:ietf:params:jmap:mail,urn:ietf:params:jmap:submission" \
|
|
185
|
-
--ops-file send_email.json
|
|
88
|
+
npx --package=@atomicmail/agent-skill atomicmail help
|
|
89
|
+
npx --package=@atomicmail/agent-skill atomicmail help --topic jmap_cheatsheet
|
|
186
90
|
```
|
|
187
91
|
|
|
188
|
-
##
|
|
189
|
-
|
|
190
|
-
`jmap_request.ts` checks both JWTs before every request:
|
|
191
|
-
|
|
192
|
-
- If `capability.jwt` is within 20 s of expiry, it calls
|
|
193
|
-
`POST /api/v1/capability` with the existing session JWT and rewrites
|
|
194
|
-
`capability.jwt`.
|
|
195
|
-
- If `session.jwt` is within 60 s of expiry (or missing), it re-runs the full
|
|
196
|
-
PoW handshake using the API key from `credentials.json`, then rewrites both
|
|
197
|
-
`session.jwt` and `capability.jwt`.
|
|
198
|
-
|
|
199
|
-
The agent does not need to call `signup.ts` again to refresh tokens — it only
|
|
200
|
-
needs to call `signup.ts` for the very first registration of an account.
|
|
201
|
-
|
|
202
|
-
## Troubleshooting
|
|
203
|
-
|
|
204
|
-
- **`Could not read credentials file ... Did you run signup first?`** — Run
|
|
205
|
-
`signup.ts` once with `--username` (new account) or `--api-key` (existing
|
|
206
|
-
account) to create the file set.
|
|
207
|
-
- **`auth-service /api/v1/session returned 409`** — The challenge was consumed
|
|
208
|
-
(likely a duplicate request or a clock skew). Just rerun `signup.ts` or the
|
|
209
|
-
failing `jmap_request.ts` once; a fresh challenge will be issued.
|
|
210
|
-
- **`auth-service /api/v1/session returned 401`** — The `apiKey` in
|
|
211
|
-
`credentials.json` is unknown or suspended. Re-register with `--username` or
|
|
212
|
-
get a new API key from the operator.
|
|
213
|
-
- **PoW takes a long time on first run** — Difficulty is fixed at 6 leading zero
|
|
214
|
-
bits, which averages ~64 scrypt iterations. Each scrypt is ~16 MB and ~200-500
|
|
215
|
-
ms, so the whole solve typically completes in under 30 seconds on a modern
|
|
216
|
-
laptop.
|
|
217
|
-
- **`Capability JWT did not contain an inboxId claim`** — Almost certainly a
|
|
218
|
-
server/version mismatch. Verify `--auth-url` points to a current
|
|
219
|
-
`auth-service` deployment.
|
|
220
|
-
|
|
221
|
-
## Security notes
|
|
222
|
-
|
|
223
|
-
- `credentials.json` contains the long-lived API key. The script writes it with
|
|
224
|
-
mode `0600`, but the agent must not echo the file's contents into shared logs
|
|
225
|
-
or commit it to source control.
|
|
226
|
-
- Pick a credentials directory that is private to the agent's runtime user (e.g.
|
|
227
|
-
`~/.config/atomic-mail/` or a per-task working dir).
|
|
228
|
-
- `session.jwt` and `capability.jwt` are short-lived but should be treated as
|
|
229
|
-
bearer credentials too — never log them.
|
|
230
|
-
|
|
231
|
-
## Building an npm package
|
|
232
|
-
|
|
233
|
-
Scripts can be published as an npm package so Node and Bun environments can use
|
|
234
|
-
them through `npx` / `bunx`. From the skill directory:
|
|
92
|
+
## Security
|
|
235
93
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
94
|
+
- `credentials.json` holds the API key (mode `0600`). Do not commit it.
|
|
95
|
+
- JWT files are bearer secrets — do not log them.
|
|
96
|
+
|
|
97
|
+
## Overriding defaults
|
|
240
98
|
|
|
241
|
-
|
|
242
|
-
`
|
|
99
|
+
- Endpoints: `--auth-url`, `--api-url` or `ATOMIC_MAIL_AUTH_URL`,
|
|
100
|
+
`ATOMIC_MAIL_API_URL`
|
|
101
|
+
- Credentials path: `--credentials-dir` or `ATOMIC_MAIL_CREDENTIALS_DIR`
|
|
102
|
+
- PoW salt: `--scrypt-salt` or `ATOMIC_MAIL_SCRYPT_SALT`
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Based on [import-meta-ponyfill](https://github.com/gaubee/import-meta-ponyfill),
|
|
3
|
+
* but instead of using npm to install additional dependencies,
|
|
4
|
+
* this approach manually consolidates cjs/mjs/d.ts into a single file.
|
|
5
|
+
*
|
|
6
|
+
* Note that this code might be imported multiple times
|
|
7
|
+
* (for example, both dnt.test.polyfills.ts and dnt.polyfills.ts contain this code;
|
|
8
|
+
* or Node.js might dynamically clear the cache and then force a require).
|
|
9
|
+
* Therefore, it's important to avoid redundant writes to global objects.
|
|
10
|
+
* Additionally, consider that commonjs is used alongside esm,
|
|
11
|
+
* so the two ponyfill functions are stored independently in two separate global objects.
|
|
12
|
+
*/
|
|
13
|
+
import { createRequire } from "node:module";
|
|
14
|
+
import { type URL } from "node:url";
|
|
15
|
+
declare global {
|
|
16
|
+
interface ImportMeta {
|
|
17
|
+
/** A string representation of the fully qualified module URL. When the
|
|
18
|
+
* module is loaded locally, the value will be a file URL (e.g.
|
|
19
|
+
* `file:///path/module.ts`).
|
|
20
|
+
*
|
|
21
|
+
* You can also parse the string as a URL to determine more information about
|
|
22
|
+
* how the current module was loaded. For example to determine if a module was
|
|
23
|
+
* local or not:
|
|
24
|
+
*
|
|
25
|
+
* ```ts
|
|
26
|
+
* const url = new URL(import.meta.url);
|
|
27
|
+
* if (url.protocol === "file:") {
|
|
28
|
+
* console.log("this module was loaded locally");
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
url: string;
|
|
33
|
+
/**
|
|
34
|
+
* A function that returns resolved specifier as if it would be imported
|
|
35
|
+
* using `import(specifier)`.
|
|
36
|
+
*
|
|
37
|
+
* ```ts
|
|
38
|
+
* console.log(import.meta.resolve("./foo.js"));
|
|
39
|
+
* // file:///dev/foo.js
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @param specifier The module specifier to resolve relative to `parent`.
|
|
43
|
+
* @param parent The absolute parent module URL to resolve from.
|
|
44
|
+
* @returns The absolute (`file:`) URL string for the resolved module.
|
|
45
|
+
*/
|
|
46
|
+
resolve(specifier: string, parent?: string | URL | undefined): string;
|
|
47
|
+
/** A flag that indicates if the current module is the main module that was
|
|
48
|
+
* called when starting the program under Deno.
|
|
49
|
+
*
|
|
50
|
+
* ```ts
|
|
51
|
+
* if (import.meta.main) {
|
|
52
|
+
* // this was loaded as the main module, maybe do some bootstrapping
|
|
53
|
+
* }
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
main: boolean;
|
|
57
|
+
/** The absolute path of the current module.
|
|
58
|
+
*
|
|
59
|
+
* This property is only provided for local modules (ie. using `file://` URLs).
|
|
60
|
+
*
|
|
61
|
+
* Example:
|
|
62
|
+
* ```
|
|
63
|
+
* // Unix
|
|
64
|
+
* console.log(import.meta.filename); // /home/alice/my_module.ts
|
|
65
|
+
*
|
|
66
|
+
* // Windows
|
|
67
|
+
* console.log(import.meta.filename); // C:\alice\my_module.ts
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
filename: string;
|
|
71
|
+
/** The absolute path of the directory containing the current module.
|
|
72
|
+
*
|
|
73
|
+
* This property is only provided for local modules (ie. using `file://` URLs).
|
|
74
|
+
*
|
|
75
|
+
* * Example:
|
|
76
|
+
* ```
|
|
77
|
+
* // Unix
|
|
78
|
+
* console.log(import.meta.dirname); // /home/alice
|
|
79
|
+
*
|
|
80
|
+
* // Windows
|
|
81
|
+
* console.log(import.meta.dirname); // C:\alice
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
dirname: string;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
type NodeRequest = ReturnType<typeof createRequire>;
|
|
88
|
+
type NodeModule = NonNullable<NodeRequest["main"]>;
|
|
89
|
+
interface ImportMetaPonyfillCommonjs {
|
|
90
|
+
(require: NodeRequest, module: NodeModule): ImportMeta;
|
|
91
|
+
}
|
|
92
|
+
interface ImportMetaPonyfillEsmodule {
|
|
93
|
+
(importMeta: ImportMeta): ImportMeta;
|
|
94
|
+
}
|
|
95
|
+
interface ImportMetaPonyfill extends ImportMetaPonyfillCommonjs, ImportMetaPonyfillEsmodule {
|
|
96
|
+
}
|
|
97
|
+
export declare let import_meta_ponyfill_commonjs: ImportMetaPonyfillCommonjs;
|
|
98
|
+
export declare let import_meta_ponyfill_esmodule: ImportMetaPonyfillEsmodule;
|
|
99
|
+
export declare let import_meta_ponyfill: ImportMetaPonyfill;
|
|
100
|
+
export {};
|
|
101
|
+
//# sourceMappingURL=_dnt.polyfills.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_dnt.polyfills.d.ts","sourceRoot":"","sources":["../src/_dnt.polyfills.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAgC,KAAK,GAAG,EAAE,MAAM,UAAU,CAAC;AAGlE,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,UAAU;QAClB;;;;;;;;;;;;;;WAcG;QACH,GAAG,EAAE,MAAM,CAAC;QACZ;;;;;;;;;;;;WAYG;QACH,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,GAAG,GAAG,SAAS,GAAG,MAAM,CAAC;QACtE;;;;;;;;WAQG;QACH,IAAI,EAAE,OAAO,CAAC;QAEd;;;;;;;;;;;;WAYG;QACH,QAAQ,EAAE,MAAM,CAAC;QAEjB;;;;;;;;;;;;WAYG;QACH,OAAO,EAAE,MAAM,CAAC;KACjB;CACF;AAED,KAAK,WAAW,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC;AACpD,KAAK,UAAU,GAAG,WAAW,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;AACnD,UAAU,0BAA0B;IAClC,CAAC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,GAAG,UAAU,CAAC;CACxD;AACD,UAAU,0BAA0B;IAClC,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,CAAC;CACtC;AACD,UAAU,kBACR,SAAQ,0BAA0B,EAAE,0BAA0B;CAC/D;AAiBD,eAAO,IAAI,6BAA6B,EA2BnC,0BAA0B,CAAC;AAMhC,eAAO,IAAI,6BAA6B,EA4DnC,0BAA0B,CAAC;AAMhC,eAAO,IAAI,oBAAoB,EAoB1B,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Based on [import-meta-ponyfill](https://github.com/gaubee/import-meta-ponyfill),
|
|
3
|
+
* but instead of using npm to install additional dependencies,
|
|
4
|
+
* this approach manually consolidates cjs/mjs/d.ts into a single file.
|
|
5
|
+
*
|
|
6
|
+
* Note that this code might be imported multiple times
|
|
7
|
+
* (for example, both dnt.test.polyfills.ts and dnt.polyfills.ts contain this code;
|
|
8
|
+
* or Node.js might dynamically clear the cache and then force a require).
|
|
9
|
+
* Therefore, it's important to avoid redundant writes to global objects.
|
|
10
|
+
* Additionally, consider that commonjs is used alongside esm,
|
|
11
|
+
* so the two ponyfill functions are stored independently in two separate global objects.
|
|
12
|
+
*/
|
|
13
|
+
//@ts-ignore
|
|
14
|
+
import { createRequire } from "node:module";
|
|
15
|
+
//@ts-ignore
|
|
16
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
17
|
+
//@ts-ignore
|
|
18
|
+
import { dirname } from "node:path";
|
|
19
|
+
const defineGlobalPonyfill = (symbolFor, fn) => {
|
|
20
|
+
if (!Reflect.has(globalThis, Symbol.for(symbolFor))) {
|
|
21
|
+
Object.defineProperty(globalThis, Symbol.for(symbolFor), {
|
|
22
|
+
configurable: true,
|
|
23
|
+
get() {
|
|
24
|
+
return fn;
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
export let import_meta_ponyfill_commonjs = (Reflect.get(globalThis, Symbol.for("import-meta-ponyfill-commonjs")) ??
|
|
30
|
+
(() => {
|
|
31
|
+
const moduleImportMetaWM = new WeakMap();
|
|
32
|
+
return (require, module) => {
|
|
33
|
+
let importMetaCache = moduleImportMetaWM.get(module);
|
|
34
|
+
if (importMetaCache == null) {
|
|
35
|
+
const importMeta = Object.assign(Object.create(null), {
|
|
36
|
+
url: pathToFileURL(module.filename).href,
|
|
37
|
+
main: require.main == module,
|
|
38
|
+
resolve: (specifier, parentURL = importMeta.url) => {
|
|
39
|
+
return pathToFileURL((importMeta.url === parentURL
|
|
40
|
+
? require
|
|
41
|
+
: createRequire(parentURL))
|
|
42
|
+
.resolve(specifier)).href;
|
|
43
|
+
},
|
|
44
|
+
filename: module.filename,
|
|
45
|
+
dirname: module.path,
|
|
46
|
+
});
|
|
47
|
+
moduleImportMetaWM.set(module, importMeta);
|
|
48
|
+
importMetaCache = importMeta;
|
|
49
|
+
}
|
|
50
|
+
return importMetaCache;
|
|
51
|
+
};
|
|
52
|
+
})());
|
|
53
|
+
defineGlobalPonyfill("import-meta-ponyfill-commonjs", import_meta_ponyfill_commonjs);
|
|
54
|
+
export let import_meta_ponyfill_esmodule = (Reflect.get(globalThis, Symbol.for("import-meta-ponyfill-esmodule")) ??
|
|
55
|
+
((importMeta) => {
|
|
56
|
+
const resolveFunStr = String(importMeta.resolve);
|
|
57
|
+
const shimWs = new WeakSet();
|
|
58
|
+
//@ts-ignore
|
|
59
|
+
const mainUrl = ("file:///" + process.argv[1].replace(/\\/g, "/"))
|
|
60
|
+
.replace(/\/{3,}/, "///");
|
|
61
|
+
const commonShim = (importMeta) => {
|
|
62
|
+
if (typeof importMeta.main !== "boolean") {
|
|
63
|
+
importMeta.main = importMeta.url === mainUrl;
|
|
64
|
+
}
|
|
65
|
+
if (typeof importMeta.filename !== "string") {
|
|
66
|
+
importMeta.filename = fileURLToPath(importMeta.url);
|
|
67
|
+
importMeta.dirname = dirname(importMeta.filename);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
if (
|
|
71
|
+
// v16.2.0+, v14.18.0+: Add support for WHATWG URL object to parentURL parameter.
|
|
72
|
+
resolveFunStr === "undefined" ||
|
|
73
|
+
// v20.0.0+, v18.19.0+"" This API now returns a string synchronously instead of a Promise.
|
|
74
|
+
resolveFunStr.startsWith("async")
|
|
75
|
+
// enable by --experimental-import-meta-resolve flag
|
|
76
|
+
) {
|
|
77
|
+
import_meta_ponyfill_esmodule = (importMeta) => {
|
|
78
|
+
if (!shimWs.has(importMeta)) {
|
|
79
|
+
shimWs.add(importMeta);
|
|
80
|
+
const importMetaUrlRequire = {
|
|
81
|
+
url: importMeta.url,
|
|
82
|
+
require: createRequire(importMeta.url),
|
|
83
|
+
};
|
|
84
|
+
importMeta.resolve = function resolve(specifier, parentURL = importMeta.url) {
|
|
85
|
+
return pathToFileURL((importMetaUrlRequire.url === parentURL
|
|
86
|
+
? importMetaUrlRequire.require
|
|
87
|
+
: createRequire(parentURL)).resolve(specifier)).href;
|
|
88
|
+
};
|
|
89
|
+
commonShim(importMeta);
|
|
90
|
+
}
|
|
91
|
+
return importMeta;
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
/// native support
|
|
96
|
+
import_meta_ponyfill_esmodule = (importMeta) => {
|
|
97
|
+
if (!shimWs.has(importMeta)) {
|
|
98
|
+
shimWs.add(importMeta);
|
|
99
|
+
commonShim(importMeta);
|
|
100
|
+
}
|
|
101
|
+
return importMeta;
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
return import_meta_ponyfill_esmodule(importMeta);
|
|
105
|
+
}));
|
|
106
|
+
defineGlobalPonyfill("import-meta-ponyfill-esmodule", import_meta_ponyfill_esmodule);
|
|
107
|
+
export let import_meta_ponyfill = ((...args) => {
|
|
108
|
+
const _MODULE = (() => {
|
|
109
|
+
if (typeof require === "function" && typeof module === "object") {
|
|
110
|
+
return "commonjs";
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
// eval("typeof import.meta");
|
|
114
|
+
return "esmodule";
|
|
115
|
+
}
|
|
116
|
+
})();
|
|
117
|
+
if (_MODULE === "commonjs") {
|
|
118
|
+
//@ts-ignore
|
|
119
|
+
import_meta_ponyfill = (r, m) => import_meta_ponyfill_commonjs(r, m);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
//@ts-ignore
|
|
123
|
+
import_meta_ponyfill = (im) => import_meta_ponyfill_esmodule(im);
|
|
124
|
+
}
|
|
125
|
+
//@ts-ignore
|
|
126
|
+
return import_meta_ponyfill(...args);
|
|
127
|
+
});
|
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
export declare const SESSION_TTL_MS: number;
|
|
2
|
-
export declare const CAPABILITY_TTL_MS: number;
|
|
3
|
-
export declare const CAPABILITY_SAFETY_MARGIN_MS = 20000;
|
|
4
|
-
export declare const SESSION_SAFETY_MARGIN_MS = 60000;
|
|
5
|
-
export interface JwtPayload {
|
|
6
|
-
exp?: number;
|
|
7
|
-
iat?: number;
|
|
8
|
-
jti?: string;
|
|
9
|
-
[key: string]: unknown;
|
|
10
|
-
}
|
|
11
|
-
export declare function decodeJwtPayload<T = JwtPayload>(jwt: string): T;
|
|
12
|
-
export declare function isJwtExpired(jwt: string, marginMs: number): boolean;
|
|
13
|
-
export declare function solvePow(challenge: string, difficulty: number, salt: string, onProgress?: (nonce: bigint) => void): Promise<{
|
|
14
|
-
powHex: string;
|
|
15
|
-
nonce: string;
|
|
16
|
-
}>;
|
|
17
1
|
export declare function fetchChallenge(authUrl: string): Promise<{
|
|
18
2
|
challengeJWT: string;
|
|
19
3
|
challenge: string;
|
|
@@ -39,4 +23,4 @@ export interface PerformPoWInput {
|
|
|
39
23
|
onPowProgress?: (nonce: bigint) => void;
|
|
40
24
|
}
|
|
41
25
|
export declare function performPoWAndSession(input: PerformPoWInput): Promise<SessionResponse>;
|
|
42
|
-
//# sourceMappingURL=auth.d.ts.map
|
|
26
|
+
//# sourceMappingURL=agent-auth-http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-auth-http.d.ts","sourceRoot":"","sources":["../../../../src/lib/agent/auth/agent-auth-http.ts"],"names":[],"mappings":"AAoCA,wBAAsB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;IAC7D,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC,CAqBD;AAED,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,wBAAsB,eAAe,CACnC,OAAO,EAAE,MAAM,EACf,IAAI,EAAE;IACJ,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,GACA,OAAO,CAAC,eAAe,CAAC,CAS1B;AAED,wBAAsB,eAAe,CACnC,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,MAAM,CAAC,CAUjB;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACzC;AAED,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,eAAe,GACrB,OAAO,CAAC,eAAe,CAAC,CAgB1B"}
|