@atomicmail/agent-skill 0.2.0 → 0.2.2

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.
Files changed (69) hide show
  1. package/README.md +51 -12
  2. package/SKILL.md +56 -38
  3. package/esm/_dnt.polyfills.d.ts +101 -0
  4. package/esm/_dnt.polyfills.d.ts.map +1 -0
  5. package/esm/_dnt.polyfills.js +127 -0
  6. package/esm/lib/agent/auth/agent-auth-http.d.ts.map +1 -0
  7. package/esm/lib/agent/auth/agent-auth-http.js +85 -0
  8. package/esm/lib/{src → agent/auth}/agent-jwt.d.ts +0 -2
  9. package/esm/lib/agent/auth/agent-jwt.d.ts.map +1 -0
  10. package/esm/lib/{src → agent/auth}/agent-jwt.js +0 -2
  11. package/esm/lib/agent/auth/agent-pow.d.ts.map +1 -0
  12. package/esm/lib/{src → agent/jmap}/agent-help-content.d.ts +1 -0
  13. package/esm/lib/agent/jmap/agent-help-content.d.ts.map +1 -0
  14. package/esm/lib/{src → agent/jmap}/agent-help-content.js +46 -19
  15. package/esm/lib/{src → agent/jmap}/agent-jmap.d.ts +7 -0
  16. package/esm/lib/agent/jmap/agent-jmap.d.ts.map +1 -0
  17. package/esm/lib/{src → agent/jmap}/agent-jmap.js +63 -3
  18. package/esm/lib/agent/jmap/agent-vars.d.ts.map +1 -0
  19. package/esm/lib/{src → agent/session}/agent-credentials-store.d.ts +2 -0
  20. package/esm/lib/agent/session/agent-credentials-store.d.ts.map +1 -0
  21. package/esm/lib/{src → agent/session}/agent-credentials-store.js +2 -0
  22. package/esm/lib/agent/session/agent-resolve-config.d.ts +24 -0
  23. package/esm/lib/agent/session/agent-resolve-config.d.ts.map +1 -0
  24. package/esm/lib/agent/session/agent-resolve-config.js +70 -0
  25. package/esm/lib/{src → agent/session}/agent-session.d.ts +5 -0
  26. package/esm/lib/agent/session/agent-session.d.ts.map +1 -0
  27. package/esm/lib/{src → agent/session}/agent-session.js +46 -10
  28. package/esm/lib/core/consts.d.ts.map +1 -0
  29. package/esm/lib/core/read-npm-package-readme.d.ts +6 -0
  30. package/esm/lib/core/read-npm-package-readme.d.ts.map +1 -0
  31. package/esm/lib/core/read-npm-package-readme.js +66 -0
  32. package/esm/lib/core/types.d.ts +2 -0
  33. package/esm/lib/core/types.d.ts.map +1 -0
  34. package/esm/lib/core/types.js +1 -0
  35. package/esm/lib/core/utils.d.ts +10 -0
  36. package/esm/lib/core/utils.d.ts.map +1 -0
  37. package/esm/lib/core/utils.js +28 -0
  38. package/esm/lib/mod.d.ts +15 -0
  39. package/esm/lib/mod.d.ts.map +1 -0
  40. package/esm/lib/mod.js +14 -0
  41. package/esm/lib/network/auth-client.d.ts +57 -0
  42. package/esm/lib/network/auth-client.d.ts.map +1 -0
  43. package/esm/lib/network/auth-client.js +211 -0
  44. package/esm/skill/cli.d.ts +3 -0
  45. package/esm/skill/cli.d.ts.map +1 -0
  46. package/esm/skill/{scripts/cli.js → cli.js} +18 -9
  47. package/package.json +4 -4
  48. package/presets/list_inbox.json +39 -0
  49. package/presets/reply.json +75 -0
  50. package/presets/send_mail.json +42 -0
  51. package/esm/lib/src/agent-auth-http.d.ts.map +0 -1
  52. package/esm/lib/src/agent-auth-http.js +0 -76
  53. package/esm/lib/src/agent-credentials-store.d.ts.map +0 -1
  54. package/esm/lib/src/agent-help-content.d.ts.map +0 -1
  55. package/esm/lib/src/agent-jmap.d.ts.map +0 -1
  56. package/esm/lib/src/agent-jwt.d.ts.map +0 -1
  57. package/esm/lib/src/agent-pow.d.ts.map +0 -1
  58. package/esm/lib/src/agent-session.d.ts.map +0 -1
  59. package/esm/lib/src/agent-vars.d.ts.map +0 -1
  60. package/esm/lib/src/consts.d.ts.map +0 -1
  61. package/esm/skill/scripts/cli.d.ts +0 -3
  62. package/esm/skill/scripts/cli.d.ts.map +0 -1
  63. /package/esm/lib/{src → agent/auth}/agent-auth-http.d.ts +0 -0
  64. /package/esm/lib/{src → agent/auth}/agent-pow.d.ts +0 -0
  65. /package/esm/lib/{src → agent/auth}/agent-pow.js +0 -0
  66. /package/esm/lib/{src → agent/jmap}/agent-vars.d.ts +0 -0
  67. /package/esm/lib/{src → agent/jmap}/agent-vars.js +0 -0
  68. /package/esm/lib/{src → core}/consts.d.ts +0 -0
  69. /package/esm/lib/{src → core}/consts.js +0 -0
package/README.md CHANGED
@@ -1,7 +1,11 @@
1
+ ---
2
+ description: Install and run the @atomicmail/agent-skill CLI (register, jmap_request, help) for shell-capable agents and automation.
3
+ ---
4
+
1
5
  # @atomicmail/agent-skill
2
6
 
3
- Atomic Mail AgentSkill CLI for AI agents. It exposes three commands: `register`,
4
- `jmap_request`, and `help` (same surface as `@atomicmail/mcp`).
7
+ Atomic Mail AgentSkill CLI for shell-capable AI agents. It exposes three
8
+ commands: `register`, `jmap_request`, and `help`.
5
9
 
6
10
  ## Install / run
7
11
 
@@ -9,12 +13,6 @@ Atomic Mail AgentSkill CLI for AI agents. It exposes three commands: `register`,
9
13
  npx --package=@atomicmail/agent-skill atomicmail --help
10
14
  ```
11
15
 
12
- From source:
13
-
14
- ```bash
15
- deno run -A scripts/cli.ts --help
16
- ```
17
-
18
16
  ## Quick start
19
17
 
20
18
  ```bash
@@ -25,7 +23,7 @@ npx --package=@atomicmail/agent-skill atomicmail jmap_request \
25
23
  --ops '[["Mailbox/get", {"accountId": "$ACCOUNT_ID"}, "m0"]]'
26
24
  ```
27
25
 
28
- ## Placeholder substitution
26
+ ## `jmap_request` and placeholders
29
27
 
30
28
  - Built-in placeholders: `$ACCOUNT_ID`, `$INBOX`
31
29
  - Custom placeholders: any `$VAR_NAME` via `--vars '{"VAR_NAME":"value"}'`
@@ -35,10 +33,44 @@ Example:
35
33
 
36
34
  ```bash
37
35
  npx --package=@atomicmail/agent-skill atomicmail jmap_request \
38
- --ops-file send_email.json \
36
+ --ops-file send_mail.json \
39
37
  --vars '{"TO":"alice@example.com","SUBJECT":"Hello","BODY":"Hi there"}'
40
38
  ```
41
39
 
40
+ ## Presets and placeholders
41
+
42
+ Presets are reusable JSON files for `jmap_request`:
43
+
44
+ - Inline JSON: `--ops '[["Mailbox/get", {"accountId":"$ACCOUNT_ID"}, "m0"]]'`
45
+ - Preset file: `--ops-file list_inbox.json --vars '{"COUNT":"10"}'`
46
+
47
+ Resolution order for `--ops-file`:
48
+
49
+ 1. Resolve relative to `--credentials-dir` (default `~/.atomicmail`).
50
+ 2. If missing, fall back to bundled presets in the package.
51
+
52
+ Placeholder rules:
53
+
54
+ - Pattern: `$VAR_NAME`, where `VAR_NAME` matches `^[A-Z][A-Z0-9_]*$`.
55
+ - Built-ins: `$ACCOUNT_ID`, `$INBOX`.
56
+ - Lowercase `$tokens` such as JMAP back-references (`$draft`) are not matched.
57
+ - Custom placeholders: pass string values via `--vars`.
58
+ - Resolution order per variable: `--vars` first, then built-in auto-resolvers.
59
+ - Built-ins can be overridden via `--vars` using `ACCOUNT_ID` or `INBOX`.
60
+ - If any referenced variable is unresolved, `jmap_request` fails with a missing
61
+ variables error.
62
+ - Substitution is single-pass: inserted values are not scanned again for nested
63
+ `$VAR_NAME` tokens.
64
+
65
+ Bundled presets:
66
+
67
+ - `send_mail.json` (`$TO`, `$SUBJECT`, `$BODY`)
68
+ - `list_inbox.json` (`$COUNT`)
69
+ - `reply.json` (`$MAIL_ID`, `$BODY`)
70
+
71
+ `--ops-file` resolves against `--credentials-dir` first, then bundled presets
72
+ inside the package.
73
+
42
74
  ## Shared state
43
75
 
44
76
  Credential files in `~/.atomicmail` (mode `0600`):
@@ -47,10 +79,17 @@ Credential files in `~/.atomicmail` (mode `0600`):
47
79
  - `session.jwt`
48
80
  - `capability.jwt`
49
81
 
50
- The skill and MCP server share this layout.
82
+ This is the on-disk state used by the CLI (and MCP).
83
+
84
+ ## Defaults
85
+
86
+ - auth endpoint: `https://auth.atomicmail.ai`
87
+ - api endpoint: `https://api.atomicmail.ai`
88
+ - credentials directory: `~/.atomicmail`
51
89
 
52
90
  ## Overriding defaults
53
91
 
54
- - Endpoints: `--auth-url`, `--api-url` or `ATOMIC_MAIL_AUTH_URL`, `ATOMIC_MAIL_API_URL`
92
+ - Endpoints: `--auth-url`, `--api-url` or `ATOMIC_MAIL_AUTH_URL`,
93
+ `ATOMIC_MAIL_API_URL`
55
94
  - Credentials path: `--credentials-dir` or `ATOMIC_MAIL_CREDENTIALS_DIR`
56
95
  - PoW salt: `--scrypt-salt` or `ATOMIC_MAIL_SCRYPT_SALT`
package/SKILL.md CHANGED
@@ -1,8 +1,6 @@
1
1
  ---
2
2
  name: atomicmail
3
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.
4
- license: MIT
5
- compatibility: Requires Deno 2.0+ to run scripts directly, or Node 20+ / Bun 1.1+ via `npx @atomicmail/agent-skill` after publishing. Needs network access to the configured auth-service and api-service.
6
4
  ---
7
5
 
8
6
  # Atomic Mail
@@ -15,21 +13,15 @@ rotation. This skill ships a single CLI entrypoint with three commands:
15
13
 
16
14
  - Register a new inbox or log in with an existing API key.
17
15
  - Send JMAP batches (inline JSON or preset files).
18
- - Read built-in documentation (JMAP cheatsheet, presets, troubleshooting).
16
+ - Read built-in documentation (JMAP cheatsheet, presets, troubleshooting) or
17
+ the package README (`atomicmail help --topic readme`).
19
18
 
20
19
  ## Commands
21
20
 
22
- All invocations use `scripts/cli.ts` or the published binary **`atomicmail`**:
23
-
24
21
  ```bash
25
- # Deno (repo)
26
- deno run -A scripts/cli.ts register --username alice
27
- deno run -A scripts/cli.ts jmap_request --ops-file x.json
28
- deno run -A scripts/cli.ts help --topic presets
29
-
30
- # Node / Bun (after publish)
31
- npx --package=@atomicmail/agent-skill atomicmail register --username "myagent" ...
32
- npx --package=@atomicmail/agent-skill atomicmail jmap_request --ops-file send_hello.json
22
+ npx --package=@atomicmail/agent-skill atomicmail register --username "myagent"
23
+
24
+ npx --package=@atomicmail/agent-skill atomicmail jmap_request --ops-file list_inbox.json --vars '{"COUNT":"10"}'
33
25
  ```
34
26
 
35
27
  Run **`atomicmail --help`** or **`atomicmail <command> --help`** for flags.
@@ -45,7 +37,7 @@ Run **`atomicmail --help`** or **`atomicmail <command> --help`** for flags.
45
37
  ### 1. Register (new account)
46
38
 
47
39
  ```bash
48
- deno run -A scripts/cli.ts register \
40
+ npx --package=@atomicmail/agent-skill atomicmail register \
49
41
  --username "alice"
50
42
  ```
51
43
 
@@ -55,59 +47,90 @@ including `inbox` and `accountId`.
55
47
  ### 2. Register (existing API key, in case losing the credentials file)
56
48
 
57
49
  ```bash
58
- deno run -A scripts/cli.ts register \
50
+ npx --package=@atomicmail/agent-skill atomicmail register \
59
51
  --api-key "..."
60
52
  ```
61
53
 
62
54
  ### 3. JMAP request
63
55
 
64
56
  ```bash
65
- deno run -A scripts/cli.ts jmap_request \
57
+ npx --package=@atomicmail/agent-skill atomicmail jmap_request \
66
58
  --ops '[["Mailbox/get", {"accountId": "$ACCOUNT_ID"}, "m0"]]'
67
59
  ```
68
60
 
69
- `$ACCOUNT_ID` and `$INBOX` resolve from the session/credentials. Other
70
- placeholders such as `$TO` or `$SUBJECT` require `--vars` with a JSON object of
71
- strings (same substitution applies to `--ops` and `--ops-file`).
61
+ `$ACCOUNT_ID`, `$INBOX`, `$UPLOAD_URL`, and `$DOWNLOAD_URL` resolve from the
62
+ session/credentials. Other placeholders such as `$TO` or `$SUBJECT` require
63
+ `--vars` with a JSON object of strings (same substitution applies to `--ops` and
64
+ `--ops-file`).
72
65
 
73
66
  Preset file:
74
67
 
75
68
  ```bash
76
- deno run -A scripts/cli.ts jmap_request \
69
+ npx --package=@atomicmail/agent-skill atomicmail jmap_request \
77
70
  --ops-file fetch_last_100.json
78
71
  ```
79
72
 
80
73
  With custom placeholders:
81
74
 
82
75
  ```bash
83
- deno run -A scripts/cli.ts jmap_request \
84
- --ops-file send_email.json \
76
+ npx --package=@atomicmail/agent-skill atomicmail jmap_request \
77
+ --ops-file send_mail.json \
85
78
  --vars '{"TO":"alice@example.com","SUBJECT":"Hello","BODY":"Hi there"}'
86
79
  ```
87
80
 
81
+ Bundled presets (no local file creation required):
82
+
83
+ - `send_mail.json` (`$TO`, `$SUBJECT`, `$BODY`)
84
+ - `list_inbox.json` (`$COUNT`)
85
+ - `reply.json` (`$MAIL_ID`, `$BODY`)
86
+
88
87
  ### 4. Help
89
88
 
90
89
  ```bash
91
- deno run -A scripts/cli.ts help
92
- deno run -A scripts/cli.ts help --topic jmap_cheatsheet
90
+ npx --package=@atomicmail/agent-skill atomicmail help
91
+ npx --package=@atomicmail/agent-skill atomicmail help --topic jmap_cheatsheet
93
92
  ```
94
93
 
95
- ## npm package
94
+ ## Security
95
+
96
+ - `credentials.json` holds the API key (mode `0600`). Do not commit it.
97
+ - JWT files are bearer secrets — do not log them.
98
+
99
+ ## Attachments and blobs
100
+
101
+ ### Inline blobs in JMAP (RFC 9404)
96
102
 
97
- From the `skill/` directory:
103
+ Use `Blob/upload` and `Blob/get` through `jmap_request` by adding
104
+ `urn:ietf:params:jmap:blob` to `using`.
98
105
 
99
106
  ```bash
100
- deno task build:npm
101
- cd npm && npm publish --access public
107
+ npx --package=@atomicmail/agent-skill atomicmail jmap_request \
108
+ --ops '{
109
+ "using":[
110
+ "urn:ietf:params:jmap:core",
111
+ "urn:ietf:params:jmap:mail",
112
+ "urn:ietf:params:jmap:submission",
113
+ "urn:ietf:params:jmap:blob"
114
+ ],
115
+ "methodCalls":[
116
+ ["Blob/upload",{
117
+ "accountId":"$ACCOUNT_ID",
118
+ "create":{"b1":{"data:asText":"Hello attachment","type":"text/plain"}}
119
+ },"b0"]
120
+ ]
121
+ }'
102
122
  ```
103
123
 
104
- The published **`atomicmail`** binary exposes `register`, `jmap_request`, and
105
- `help`.
124
+ ### Separate upload/download templates (RFC 8620)
106
125
 
107
- ## Security
126
+ `credentials.json` stores `uploadUrl` and `downloadUrl` from
127
+ `GET /.well-known/jmap`.
108
128
 
109
- - `credentials.json` holds the API key (mode `0600`). Do not commit it.
110
- - JWT files are bearer secrets do not log them.
129
+ - `$UPLOAD_URL` is the RFC 8620 upload template.
130
+ - `$DOWNLOAD_URL` is the RFC 8620 download template.
131
+
132
+ Use these placeholders when building out-of-band blob transfer steps and attach
133
+ the resulting `blobId` in follow-up JMAP calls.
111
134
 
112
135
  ## Overriding defaults
113
136
 
@@ -115,8 +138,3 @@ The published **`atomicmail`** binary exposes `register`, `jmap_request`, and
115
138
  `ATOMIC_MAIL_API_URL`
116
139
  - Credentials path: `--credentials-dir` or `ATOMIC_MAIL_CREDENTIALS_DIR`
117
140
  - PoW salt: `--scrypt-salt` or `ATOMIC_MAIL_SCRYPT_SALT`
118
-
119
- ## Building
120
-
121
- See repository [`AGENTS.md`](../AGENTS.md) for formatting (`deno fmt`) and
122
- conventions.
@@ -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
+ });
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-auth-http.d.ts","sourceRoot":"","sources":["../../../../src/lib/agent/auth/agent-auth-http.ts"],"names":[],"mappings":"AAKA,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,CA8BD;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,CA8B1B;AAED,wBAAsB,eAAe,CACnC,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,MAAM,CAAC,CAejB;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"}
@@ -0,0 +1,85 @@
1
+ // auth-service HTTP: challenge → session → capability.
2
+ import { decodeJwtPayload } from "./agent-jwt.js";
3
+ import { solvePow } from "./agent-pow.js";
4
+ export async function fetchChallenge(authUrl) {
5
+ const res = await fetch(`${authUrl}/api/v1/challenge`, {
6
+ method: "POST",
7
+ });
8
+ const text = await res.text();
9
+ if (!res.ok) {
10
+ throw new Error(`auth-service /api/v1/challenge returned ${res.status}: ${text}`);
11
+ }
12
+ const challengeJWT = readBearerToken(res.headers.get("Authorization"), "Challenge response missing Authorization bearer token.");
13
+ const payload = decodeJwtPayload(challengeJWT);
14
+ if (typeof payload.jti !== "string" ||
15
+ typeof payload.difficulty !== "number") {
16
+ throw new Error("Challenge JWT payload malformed (missing jti or difficulty).");
17
+ }
18
+ return {
19
+ challengeJWT,
20
+ challenge: payload.jti,
21
+ difficulty: payload.difficulty,
22
+ };
23
+ }
24
+ export async function exchangeSession(authUrl, body) {
25
+ const { challengeJWT, ...payload } = body;
26
+ const res = await fetch(`${authUrl}/api/v1/session`, {
27
+ method: "POST",
28
+ headers: {
29
+ "Content-Type": "application/json",
30
+ Authorization: `Bearer ${challengeJWT}`,
31
+ },
32
+ body: JSON.stringify(payload),
33
+ });
34
+ const text = await res.text();
35
+ if (!res.ok) {
36
+ throw new Error(`auth-service /api/v1/session returned ${res.status}: ${text}`);
37
+ }
38
+ const sessionJWT = readBearerToken(res.headers.get("Authorization"), "Session response missing Authorization bearer token.");
39
+ let data = {};
40
+ if (text.trim().length > 0) {
41
+ try {
42
+ data = JSON.parse(text);
43
+ }
44
+ catch {
45
+ throw new Error("auth-service /api/v1/session returned non-JSON body.");
46
+ }
47
+ }
48
+ return {
49
+ sessionJWT,
50
+ apiKey: typeof data.apiKey === "string" ? data.apiKey : undefined,
51
+ };
52
+ }
53
+ export async function fetchCapability(authUrl, sessionJWT) {
54
+ const res = await fetch(`${authUrl}/api/v1/capability`, {
55
+ method: "POST",
56
+ headers: { Authorization: `Bearer ${sessionJWT}` },
57
+ });
58
+ const text = await res.text();
59
+ if (!res.ok) {
60
+ throw new Error(`auth-service /api/v1/capability returned ${res.status}: ${text}`);
61
+ }
62
+ return readBearerToken(res.headers.get("Authorization"), "Capability response missing Authorization bearer token.");
63
+ }
64
+ export async function performPoWAndSession(input) {
65
+ const { authUrl, scryptSalt } = input;
66
+ const { challengeJWT, challenge, difficulty } = await fetchChallenge(authUrl);
67
+ const { powHex, nonce } = await solvePow(challenge, difficulty, scryptSalt, input.onPowProgress);
68
+ return exchangeSession(authUrl, {
69
+ challengeJWT,
70
+ powHex,
71
+ nonce,
72
+ apiKey: input.apiKey,
73
+ username: input.username,
74
+ });
75
+ }
76
+ function readBearerToken(headerValue, missingError) {
77
+ if (!headerValue) {
78
+ throw new Error(missingError);
79
+ }
80
+ const match = /^\s*Bearer\s+(.+?)\s*$/i.exec(headerValue);
81
+ if (!match || !match[1]) {
82
+ throw new Error("Authorization header must use Bearer scheme.");
83
+ }
84
+ return match[1];
85
+ }
@@ -1,5 +1,3 @@
1
- export declare const SESSION_TTL_MS: number;
2
- export declare const CAPABILITY_TTL_MS: number;
3
1
  export declare const SESSION_SAFETY_MARGIN_MS = 60000;
4
2
  export declare const CAPABILITY_SAFETY_MARGIN_MS = 20000;
5
3
  export interface JwtPayload {
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-jwt.d.ts","sourceRoot":"","sources":["../../../../src/lib/agent/auth/agent-jwt.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,wBAAwB,QAAS,CAAC;AAC/C,eAAO,MAAM,2BAA2B,QAAS,CAAC;AAElD,MAAM,WAAW,UAAU;IACzB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,wBAAgB,gBAAgB,CAAC,CAAC,GAAG,UAAU,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,CAc/D;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAQnE"}
@@ -1,6 +1,4 @@
1
1
  // JWT helpers for capability/session expiry checks.
2
- export const SESSION_TTL_MS = 4 * 60 * 60 * 1000;
3
- export const CAPABILITY_TTL_MS = 2 * 60 * 1000;
4
2
  export const SESSION_SAFETY_MARGIN_MS = 60_000;
5
3
  export const CAPABILITY_SAFETY_MARGIN_MS = 20_000;
6
4
  export function decodeJwtPayload(jwt) {
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-pow.d.ts","sourceRoot":"","sources":["../../../../src/lib/agent/auth/agent-pow.ts"],"names":[],"mappings":"AAuCA,wBAAsB,QAAQ,CAC5B,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,EACZ,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,GACnC,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAU5C"}
@@ -1,4 +1,5 @@
1
1
  export declare const HELP_TOPICS: Record<string, string>;
2
2
  export declare const HELP_TOPIC_LIST: string[];
3
+ export declare function normalizeHelpTopic(topic: string): string;
3
4
  export declare function getHelp(topic?: string): string;
4
5
  //# sourceMappingURL=agent-help-content.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-help-content.d.ts","sourceRoot":"","sources":["../../../../src/lib/agent/jmap/agent-help-content.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CA0P9C,CAAC;AAEF,eAAO,MAAM,eAAe,UAA2B,CAAC;AAExD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAExD;AAED,wBAAgB,OAAO,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAkB9C"}