@atomicmail/mcp 0.2.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.
Files changed (77) hide show
  1. package/README.md +73 -83
  2. package/esm/_dnt.polyfills.d.ts +101 -0
  3. package/esm/_dnt.polyfills.d.ts.map +1 -0
  4. package/esm/_dnt.polyfills.js +127 -0
  5. package/esm/lib/agent/auth/agent-auth-http.d.ts.map +1 -0
  6. package/esm/lib/agent/auth/agent-jwt.d.ts.map +1 -0
  7. package/esm/lib/agent/auth/agent-pow.d.ts.map +1 -0
  8. package/esm/lib/agent/jmap/agent-help-content.d.ts.map +1 -0
  9. package/esm/lib/{src → agent/jmap}/agent-help-content.js +11 -3
  10. package/esm/lib/agent/jmap/agent-jmap.d.ts.map +1 -0
  11. package/esm/lib/{src → agent/jmap}/agent-jmap.js +47 -3
  12. package/esm/lib/agent/jmap/agent-vars.d.ts.map +1 -0
  13. package/esm/lib/agent/session/agent-credentials-store.d.ts.map +1 -0
  14. package/esm/lib/agent/session/agent-resolve-config.d.ts.map +1 -0
  15. package/esm/lib/{src → agent/session}/agent-resolve-config.js +1 -1
  16. package/esm/lib/agent/session/agent-session.d.ts.map +1 -0
  17. package/esm/lib/{src → agent/session}/agent-session.js +3 -3
  18. package/esm/lib/core/consts.d.ts.map +1 -0
  19. package/esm/lib/core/types.d.ts +2 -0
  20. package/esm/lib/core/types.d.ts.map +1 -0
  21. package/esm/lib/core/types.js +1 -0
  22. package/esm/lib/core/utils.d.ts +10 -0
  23. package/esm/lib/core/utils.d.ts.map +1 -0
  24. package/esm/lib/core/utils.js +28 -0
  25. package/esm/lib/mod.d.ts +14 -0
  26. package/esm/lib/mod.d.ts.map +1 -0
  27. package/esm/lib/mod.js +13 -0
  28. package/esm/lib/network/auth-client.d.ts +57 -0
  29. package/esm/lib/network/auth-client.d.ts.map +1 -0
  30. package/esm/lib/network/auth-client.js +188 -0
  31. package/esm/mcp/main.d.ts +3 -0
  32. package/esm/mcp/main.d.ts.map +1 -0
  33. package/esm/mcp/{src/main.js → main.js} +2 -2
  34. package/esm/mcp/tools/help.d.ts.map +1 -0
  35. package/esm/mcp/{src/tools → tools}/help.js +1 -1
  36. package/esm/mcp/{src/tools → tools}/jmap.d.ts +1 -1
  37. package/esm/mcp/tools/jmap.d.ts.map +1 -0
  38. package/esm/mcp/{src/tools → tools}/jmap.js +1 -1
  39. package/esm/mcp/{src/tools → tools}/register.d.ts +1 -1
  40. package/esm/mcp/tools/register.d.ts.map +1 -0
  41. package/package.json +5 -5
  42. package/presets/list_inbox.json +39 -0
  43. package/presets/reply.json +75 -0
  44. package/presets/send_mail.json +42 -0
  45. package/esm/lib/src/agent-auth-http.d.ts.map +0 -1
  46. package/esm/lib/src/agent-credentials-store.d.ts.map +0 -1
  47. package/esm/lib/src/agent-help-content.d.ts.map +0 -1
  48. package/esm/lib/src/agent-jmap.d.ts.map +0 -1
  49. package/esm/lib/src/agent-jwt.d.ts.map +0 -1
  50. package/esm/lib/src/agent-pow.d.ts.map +0 -1
  51. package/esm/lib/src/agent-resolve-config.d.ts.map +0 -1
  52. package/esm/lib/src/agent-session.d.ts.map +0 -1
  53. package/esm/lib/src/agent-vars.d.ts.map +0 -1
  54. package/esm/lib/src/consts.d.ts.map +0 -1
  55. package/esm/mcp/src/main.d.ts +0 -3
  56. package/esm/mcp/src/main.d.ts.map +0 -1
  57. package/esm/mcp/src/tools/help.d.ts.map +0 -1
  58. package/esm/mcp/src/tools/jmap.d.ts.map +0 -1
  59. package/esm/mcp/src/tools/register.d.ts.map +0 -1
  60. /package/esm/lib/{src → agent/auth}/agent-auth-http.d.ts +0 -0
  61. /package/esm/lib/{src → agent/auth}/agent-auth-http.js +0 -0
  62. /package/esm/lib/{src → agent/auth}/agent-jwt.d.ts +0 -0
  63. /package/esm/lib/{src → agent/auth}/agent-jwt.js +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-help-content.d.ts +0 -0
  67. /package/esm/lib/{src → agent/jmap}/agent-jmap.d.ts +0 -0
  68. /package/esm/lib/{src → agent/jmap}/agent-vars.d.ts +0 -0
  69. /package/esm/lib/{src → agent/jmap}/agent-vars.js +0 -0
  70. /package/esm/lib/{src → agent/session}/agent-credentials-store.d.ts +0 -0
  71. /package/esm/lib/{src → agent/session}/agent-credentials-store.js +0 -0
  72. /package/esm/lib/{src → agent/session}/agent-resolve-config.d.ts +0 -0
  73. /package/esm/lib/{src → agent/session}/agent-session.d.ts +0 -0
  74. /package/esm/lib/{src → core}/consts.d.ts +0 -0
  75. /package/esm/lib/{src → core}/consts.js +0 -0
  76. /package/esm/mcp/{src/tools → tools}/help.d.ts +0 -0
  77. /package/esm/mcp/{src/tools → tools}/register.js +0 -0
package/README.md CHANGED
@@ -4,14 +4,22 @@ Atomic Mail MCP server — a local stdio Model Context Protocol server that give
4
4
  an AI agent a programmable email inbox over JMAP, with automatic Proof-of-Work
5
5
  auth and capability-token rotation.
6
6
 
7
- The server is authored in TypeScript on Deno and built with
8
- [`dnt`](https://jsr.io/@deno/dnt) into a Node-compatible npm package, so the
9
- **same source** runs unchanged on Deno, Node, and Bun.
7
+ ## Install
8
+
9
+ ```json
10
+ // mcp.json
11
+
12
+ {
13
+ "mcpServers": {
14
+ "atomicmail": {
15
+ "command": "npx",
16
+ "args": ["-y", "@atomicmail/mcp"]
17
+ }
18
+ }
19
+ }
20
+ ```
10
21
 
11
- It is the MCP companion to
12
- [`@atomicmail/agent-skill`](https://www.npmjs.com/package/@atomicmail/agent-skill)
13
- — a CLI with identical credential semantics. The MCP and the skill share the
14
- same on-disk layout (`credentials.json` + `session.jwt` + `capability.jwt`).
22
+ Your MCP host spawns this process; see configuration below.
15
23
 
16
24
  ## Tools exposed
17
25
 
@@ -21,23 +29,63 @@ same on-disk layout (`credentials.json` + `session.jwt` + `capability.jwt`).
21
29
  | `jmap_request` | JMAP batch via `ops` or `ops_file`. Uppercase `$VAR_NAME` tokens are substituted (`$ACCOUNT_ID` / `$INBOX` from session; others via optional `vars` map). |
22
30
  | `help` | Built-in docs (`topic` optional). |
23
31
 
24
- ## Install
32
+ ## Typical MCP workflow
25
33
 
26
- ```bash
27
- npx -y @atomicmail/mcp
28
- bunx @atomicmail/mcp
29
- deno run -A npm:@atomicmail/mcp/atomicmail-mcp
30
- ```
34
+ 1. Call `register` with a username (or rely on existing `credentials.json`).
35
+ 2. `jmap_request` with `ops` or `ops_file` (optional `vars` for `$TO`,
36
+ `$SUBJECT`, etc.).
37
+ 3. `help` when stuck.
31
38
 
32
- Your MCP host spawns this process; see configuration below.
39
+ ## `jmap_request` input patterns
33
40
 
34
- ## Defaults
41
+ `jmap_request` accepts either:
35
42
 
36
- - auth endpoint: `https://auth.atomicmail.ai`
37
- - api endpoint: `https://api.atomicmail.ai`
38
- - credentials directory: `~/.atomicmail`
43
+ - inline `ops` (JMAP methodCalls array), or
44
+ - `ops_file` (JSON file path)
45
+
46
+ When using `ops_file`, relative paths first resolve against the credential
47
+ directory. If a file is not present there, the runtime falls back to bundled
48
+ presets shipped in the npm package.
49
+
50
+ ## Presets and placeholders
51
+
52
+ Presets are reusable JSON files for `jmap_request` batches:
53
+
54
+ - Inline JSON: `{"ops":[...],"vars":{"COUNT":"10"}}`
55
+ - Preset file: `{"ops_file":"list_inbox.json","vars":{"COUNT":"10"}}`
56
+
57
+ Resolution order for `ops_file`:
58
+
59
+ 1. Resolve relative to credentials directory (`~/.atomicmail` by default).
60
+ 2. If missing, fall back to bundled presets in the npm package.
61
+
62
+ Placeholder rules:
63
+
64
+ - Pattern: `$VAR_NAME`, where `VAR_NAME` matches `^[A-Z][A-Z0-9_]*$`.
65
+ - Built-ins: `$ACCOUNT_ID`, `$INBOX`.
66
+ - Lowercase `$tokens` such as JMAP back-references (`$draft`) are not matched.
67
+ - Custom placeholders: passed in `vars` as string values.
68
+ - Resolution order per variable: `vars` first, then built-in auto-resolvers.
69
+ - Built-ins can be overridden by providing `ACCOUNT_ID` or `INBOX` in `vars`.
70
+ - If any referenced variable is unresolved, `jmap_request` fails with a missing
71
+ variables error.
72
+ - Substitution is single-pass: inserted values are not scanned again for nested
73
+ `$VAR_NAME` tokens.
74
+
75
+ Bundled presets:
76
+
77
+ - `send_mail.json` (`$TO`, `$SUBJECT`, `$BODY`)
78
+ - `list_inbox.json` (`$COUNT`)
79
+ - `reply.json` (`$MAIL_ID`, `$BODY`)
80
+
81
+ `ops-file` resolves against credentials directory first, then bundled presets
82
+ inside the package.
83
+
84
+ Example:
39
85
 
40
- ## Credential files
86
+ `{ "ops_file": "list_inbox.json", "vars": { "COUNT": "10" } }`
87
+
88
+ ## Credential files and token lifecycle
41
89
 
42
90
  Mode `0600`:
43
91
 
@@ -45,25 +93,14 @@ Mode `0600`:
45
93
  - `session.jwt` — 4h TTL, rotated via PoW
46
94
  - `capability.jwt` — 2m TTL, rotated before JMAP calls
47
95
 
48
- Use **`npx atomicmail register`** (from `@atomicmail/agent-skill`) against the
49
- same directory, or the MCP `register` tool.
50
-
51
- ## MCP host configuration examples
52
-
53
- ### Cursor
96
+ These files are created and rotated automatically by MCP tool calls. AgentSkill
97
+ CLI uses the same files.
54
98
 
55
- `~/.cursor/mcp.json`:
99
+ ## Defaults
56
100
 
57
- ```json
58
- {
59
- "mcpServers": {
60
- "atomicmail": {
61
- "command": "npx",
62
- "args": ["-y", "@atomicmail/mcp"]
63
- }
64
- }
65
- }
66
- ```
101
+ - auth endpoint: `https://auth.atomicmail.ai`
102
+ - api endpoint: `https://api.atomicmail.ai`
103
+ - credentials directory: `~/.atomicmail`
67
104
 
68
105
  ## Overriding defaults
69
106
 
@@ -84,50 +121,3 @@ same directory, or the MCP `register` tool.
84
121
  }
85
122
  }
86
123
  ```
87
-
88
- ## Typical agent workflow
89
-
90
- 1. `register` with a username (or rely on existing `credentials.json`).
91
- 2. `jmap_request` with `ops` or `ops_file` (optional `vars` for `$TO`,
92
- `$SUBJECT`, etc.).
93
- 3. `help` when stuck.
94
-
95
- ## JMAP presets (`ops_file`)
96
-
97
- Relative paths resolve against the credential directory. Example file
98
- `fetch_last_100.json` — then call `jmap_request` with
99
- `{ "ops_file": "fetch_last_100.json" }`.
100
-
101
- See `help` with topic `presets`.
102
-
103
- ## Develop
104
-
105
- ```bash
106
- deno task start
107
- deno task check
108
- deno task fmt
109
- deno task build:npm
110
- node npm/esm/mcp/src/main.js
111
- ```
112
-
113
- ### Project layout
114
-
115
- ```
116
- mcp/
117
- ├── deno.json
118
- ├── build_npm.ts
119
- ├── README.md
120
- ├── src/
121
- │ ├── main.ts
122
- │ └── tools/
123
- │ ├── register.ts
124
- │ ├── jmap.ts
125
- │ └── help.ts
126
- └── npm/ # dnt output (gitignored)
127
- ```
128
-
129
- Shared auth/JMAP logic lives in [`../lib/`](../lib/) (`AgentSession`, etc.).
130
-
131
- ## License
132
-
133
- MIT
@@ -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":"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"}
@@ -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,cAAc,QAAqB,CAAC;AACjD,eAAO,MAAM,iBAAiB,QAAgB,CAAC;AAE/C,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"}
@@ -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"}
@@ -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,CA+O9C,CAAC;AAEF,eAAO,MAAM,eAAe,UAA2B,CAAC;AAExD,wBAAgB,OAAO,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAW9C"}
@@ -51,7 +51,8 @@ presets, troubleshooting.`,
51
51
  \`\`\`bash
52
52
  npx --package=@atomicmail/agent-skill atomicmail register --username "myagent"
53
53
  npx --package=@atomicmail/agent-skill atomicmail jmap_request \\
54
- --ops-file send_hello.json
54
+ --ops-file list_inbox.json \\
55
+ --vars '{"COUNT":"10"}'
55
56
  npx --package=@atomicmail/agent-skill atomicmail help
56
57
  \`\`\`
57
58
 
@@ -180,8 +181,15 @@ troubleshooting.`,
180
181
  Save a method-call array or a full \`{ "using", "methodCalls" }\` envelope
181
182
  as JSON, then pass \`ops_file\` (MCP) or \`--ops-file\` (skill).
182
183
 
183
- Relative paths resolve against the credential directory (MCP) or current
184
- \`--credentials-dir\` (skill).
184
+ Relative paths first resolve against the credential directory (MCP) or current
185
+ \`--credentials-dir\` (skill). If not found, the runtime falls back to bundled
186
+ presets that ship in both npm packages.
187
+
188
+ ## Bundled presets
189
+
190
+ - \`send_mail.json\` — sends one email using \`$TO\`, \`$SUBJECT\`, \`$BODY\`.
191
+ - \`list_inbox.json\` — returns the latest \`$COUNT\` inbox messages.
192
+ - \`reply.json\` — replies in-thread using \`$MAIL_ID\` and \`$BODY\`.
185
193
 
186
194
  ## Placeholders
187
195
 
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-jmap.d.ts","sourceRoot":"","sources":["../../../../src/lib/agent/jmap/agent-jmap.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,kBAAkB,qEAGrB,CAAC;AAEX,eAAO,MAAM,aAAa,EAAG,2BAAoC,CAAC;AAElE,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,WAAW,EAAE,OAAO,EAAE,CAAC;CACxB;AAED,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,MAAM,EACX,YAAY,EAAE,MAAM,EAAE,EACtB,MAAM,EAAE,MAAM,GACb,YAAY,CAyBd;AAED,wBAAgB,kBAAkB,CAChC,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,MAAM,GACd,MAAM,CAER;AAED,wBAAsB,WAAW,CAC/B,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,CAAC,CAiBjB;AA8CD,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/B,MAAM,CAcR;AAED,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAclC;AAED,wEAAwE;AACxE,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE;QAAE,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC;IAC5C,uBAAuB,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAC3C,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IACtC,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;CAClC;AAED,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,eAAe,CAAC;IACzB,mDAAmD;IACnD,OAAO,EAAE,MAAM,CAAC;IAChB,iDAAiD;IACjD,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,6BAA6B;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,wFAAwF;IACxF,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC/B;AAED;;GAEG;AACH,wBAAsB,cAAc,CAClC,KAAK,EAAE,mBAAmB,GACzB,OAAO,CAAC;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CA4C5D;AAED,wBAAsB,QAAQ,CAC5B,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,YAAY,GACrB,OAAO,CAAC;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CAY5D;AAQD,0EAA0E;AAC1E,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAU5D"}
@@ -1,7 +1,8 @@
1
1
  // JMAP envelope parsing, preset paths, $VAR substitution, and HTTP helpers.
2
2
  import { readFile } from "node:fs/promises";
3
- import { isAbsolute, resolve as resolvePath } from "node:path";
4
- import { readCredentials } from "./agent-credentials-store.js";
3
+ import { dirname, isAbsolute, resolve as resolvePath } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ import { readCredentials } from "../session/agent-credentials-store.js";
5
6
  import { substituteVars } from "./agent-vars.js";
6
7
  export const DEFAULT_JMAP_USING = [
7
8
  "urn:ietf:params:jmap:core",
@@ -36,7 +37,50 @@ export function resolveOpsFilePath(credentialDir, opsFile) {
36
37
  }
37
38
  export async function readOpsFile(credentialDir, opsFile) {
38
39
  const filePath = resolveOpsFilePath(credentialDir, opsFile);
39
- return await readFile(filePath, "utf-8");
40
+ try {
41
+ return await readFile(filePath, "utf-8");
42
+ }
43
+ catch (err) {
44
+ if (!(err instanceof Error) || !isFileNotFound(err) || isAbsolute(opsFile)) {
45
+ throw err;
46
+ }
47
+ }
48
+ const bundledPath = await resolveBundledPresetPath(opsFile);
49
+ if (!bundledPath) {
50
+ return await readFile(filePath, "utf-8");
51
+ }
52
+ return await readFile(bundledPath, "utf-8");
53
+ }
54
+ function isFileNotFound(err) {
55
+ const code = err.code;
56
+ return code === "ENOENT" || code === "ENOTDIR";
57
+ }
58
+ async function resolveBundledPresetPath(opsFile) {
59
+ const moduleDir = dirname(fileURLToPath(globalThis[Symbol.for("import-meta-ponyfill-esmodule")](import.meta).url));
60
+ let currentDir = moduleDir;
61
+ for (let depth = 0; depth < 8; depth++) {
62
+ const candidates = [
63
+ resolvePath(currentDir, "presets", opsFile),
64
+ resolvePath(currentDir, "agent", "jmap", "presets", opsFile),
65
+ resolvePath(currentDir, "lib", "src", "agent", "jmap", "presets", opsFile),
66
+ ];
67
+ for (const candidate of candidates) {
68
+ try {
69
+ await readFile(candidate, "utf-8");
70
+ return candidate;
71
+ }
72
+ catch (err) {
73
+ if (!(err instanceof Error) || !isFileNotFound(err)) {
74
+ throw err;
75
+ }
76
+ }
77
+ }
78
+ const parent = resolvePath(currentDir, "..");
79
+ if (parent === currentDir)
80
+ break;
81
+ currentDir = parent;
82
+ }
83
+ return undefined;
40
84
  }
41
85
  export function extractPrimaryMailAccountId(session) {
42
86
  const primary = session["primaryAccounts"];
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-vars.d.ts","sourceRoot":"","sources":["../../../../src/lib/agent/jmap/agent-vars.ts"],"names":[],"mappings":"AAEA,4EAA4E;AAC5E,eAAO,MAAM,WAAW,QAAyB,CAAC;AAMlD,uFAAuF;AACvF,eAAO,MAAM,iBAAiB,aAA2C,CAAC;AAE1E,MAAM,WAAW,mBAAmB;IAClC,GAAG,EAAE,MAAM,CAAC;IACZ,iFAAiF;IACjF,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,iGAAiG;IACjG,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC;CAChE;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;CACd;AAED,gFAAgF;AAChF,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAWvD;AAeD;;;;GAIG;AACH,wBAAsB,cAAc,CAClC,KAAK,EAAE,mBAAmB,GACzB,OAAO,CAAC,oBAAoB,CAAC,CA+B/B"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-credentials-store.d.ts","sourceRoot":"","sources":["../../../../src/lib/agent/session/agent-credentials-store.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,UAAU;IACzB,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAOjE;AAMD,wBAAsB,gBAAgB,CACpC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,WAAW,GACjB,OAAO,CAAC,IAAI,CAAC,CAGf;AAED,wBAAsB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAiCxE;AAED,wBAAsB,kBAAkB,CACtC,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,CAOlC;AAED,wBAAsB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAG3E;AAED,wBAAsB,cAAc,CAClC,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAO7B;AAED,0EAA0E;AAC1E,wBAAsB,yBAAyB,CAC7C,KAAK,EAAE,UAAU,GAChB,OAAO,CAAC,IAAI,CAAC,CAcf"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-resolve-config.d.ts","sourceRoot":"","sources":["../../../../src/lib/agent/session/agent-resolve-config.ts"],"names":[],"mappings":"AAKA,OAAO,EAEL,KAAK,UAAU,EAEhB,MAAM,8BAA8B,CAAC;AAEtC,MAAM,MAAM,YAAY,GACpB,kBAAkB,GAClB,KAAK,GACL,OAAO,GACP,YAAY,CAAC;AAEjB,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,UAAU,CAAC;IAClB,MAAM,EAAE,YAAY,CAAC;CACtB;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,CAW7C;AAED;;;GAGG;AACH,wBAAsB,yBAAyB,IAAI,OAAO,CACxD,mBAAmB,CACpB,CAoDA"}
@@ -1,6 +1,6 @@
1
1
  // Resolve MCP / process credential dir + URLs from env + credentials.json.
2
2
  import process from "node:process";
3
- import { DEFAULT_POW_SCRYPT_SALT_HEX } from "./consts.js";
3
+ import { DEFAULT_POW_SCRYPT_SALT_HEX } from "../../core/consts.js";
4
4
  import { defaultFilesFromOutDir, tryReadCredentials, } from "./agent-credentials-store.js";
5
5
  /**
6
6
  * Default credential directory:
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-session.d.ts","sourceRoot":"","sources":["../../../../src/lib/agent/session/agent-session.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,UAAU,EAMhB,MAAM,8BAA8B,CAAC;AAatC,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,UAAU,CAAC;CACnB;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,iEAAiE;IACjE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAMD,iEAAiE;AACjE,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAKtD;AAED,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,MAAM,CAAqB;IACnC,OAAO,CAAC,OAAO,CAAqB;IACpC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAE3B,OAAO,CAAC,UAAU,CAAqB;IACvC,OAAO,CAAC,aAAa,CAAqB;IAC1C,OAAO,CAAC,mBAAmB,CAAqB;gBAEpC,GAAG,EAAE,kBAAkB;WAUtB,MAAM,CAAC,GAAG,EAAE,kBAAkB,GAAG,OAAO,CAAC,YAAY,CAAC;IAMnE,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,IAAI,cAAc,IAAI,MAAM,GAAG,SAAS,CAEvC;YAEa,YAAY;IAU1B;;OAEG;IACG,uBAAuB,IAAI,OAAO,CAAC,MAAM,CAAC;IAShD,0BAA0B,IAAI,IAAI;IAIlC;;;OAGG;IACG,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAuEnD,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;YA4B7B,aAAa;IAyB3B,OAAO,IAAI,IAAI;CAGhB;AAED,MAAM,WAAW,2BAA2B;IAC1C,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,UAAU,CAAC;IAClB,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACzC;AAED,0EAA0E;AAC1E,wBAAsB,sBAAsB,CAC1C,KAAK,EAAE,2BAA2B,GACjC,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,CAyB9B"}
@@ -1,8 +1,8 @@
1
1
  // Stateful PoW + capability JWT + optional cached JMAP session (accountId).
2
2
  import { tryReadCredentials, tryReadJwtFile, unlinkCredentialArtifacts, writeCredentials, writeJwtFile, } from "./agent-credentials-store.js";
3
- import { CAPABILITY_SAFETY_MARGIN_MS, decodeJwtPayload, isJwtExpired, SESSION_SAFETY_MARGIN_MS, } from "./agent-jwt.js";
4
- import { extractPrimaryMailAccountId, fetchJmapWellKnown, } from "./agent-jmap.js";
5
- import { fetchCapability, performPoWAndSession } from "./agent-auth-http.js";
3
+ import { CAPABILITY_SAFETY_MARGIN_MS, decodeJwtPayload, isJwtExpired, SESSION_SAFETY_MARGIN_MS, } from "../auth/agent-jwt.js";
4
+ import { extractPrimaryMailAccountId, fetchJmapWellKnown, } from "../jmap/agent-jmap.js";
5
+ import { fetchCapability, performPoWAndSession } from "../auth/agent-auth-http.js";
6
6
  function normalizeUsername(u) {
7
7
  return u.trim().toLowerCase();
8
8
  }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../../../src/lib/core/consts.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,2BAA2B,qEAC4B,CAAC;AAErE,eAAO,MAAM,UAAU,OAAO,CAAC;AAC/B,eAAO,MAAM,UAAU,QAAkB,CAAC;AAC1C,eAAO,MAAM,WAAW,QAAkB,CAAC;AAC3C,eAAO,MAAM,UAAU,QAAmB,CAAC;AAC3C,eAAO,MAAM,YAAY,QAAkB,CAAC;AAC5C,eAAO,MAAM,WAAW,QAAmB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export type MaybePromise<R> = R | Promise<R>;
2
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/lib/core/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ import type { MaybePromise } from "./types.js";
2
+ export declare function delay(ms: number): Promise<void>;
3
+ export type RetryCfg = {
4
+ maxTimeoutMs?: number;
5
+ startTimeoutMs?: number;
6
+ backoffMul?: number;
7
+ onBeforeRetry?: (e: unknown) => MaybePromise<void>;
8
+ };
9
+ export declare function retry<R>(fn: () => MaybePromise<R>, config: RetryCfg): Promise<R>;
10
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/lib/core/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE/C;AAED,MAAM,MAAM,QAAQ,GAAG;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,aAAa,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,YAAY,CAAC,IAAI,CAAC,CAAC;CACpD,CAAC;AASF,wBAAsB,KAAK,CAAC,CAAC,EAC3B,EAAE,EAAE,MAAM,YAAY,CAAC,CAAC,CAAC,EACzB,MAAM,EAAE,QAAQ,GACf,OAAO,CAAC,CAAC,CAAC,CAgBZ"}
@@ -0,0 +1,28 @@
1
+ import { ONE_SEC_MS } from "./consts.js";
2
+ export function delay(ms) {
3
+ return new Promise((resolve) => setTimeout(resolve, ms));
4
+ }
5
+ const defaultCfg = {
6
+ maxTimeoutMs: ONE_SEC_MS * 32,
7
+ startTimeoutMs: ONE_SEC_MS,
8
+ backoffMul: 2,
9
+ };
10
+ // retry with exponential backoff, retries the fn on throw, re-throws on max backoff
11
+ export async function retry(fn, config) {
12
+ const cfg = { ...defaultCfg, ...config };
13
+ let curTimeoutMs = cfg.startTimeoutMs;
14
+ while (true) {
15
+ try {
16
+ const res = await fn();
17
+ return res;
18
+ }
19
+ catch (e) {
20
+ if (cfg.onBeforeRetry)
21
+ await cfg.onBeforeRetry(e);
22
+ if (curTimeoutMs > cfg.maxTimeoutMs)
23
+ throw e;
24
+ await delay(curTimeoutMs);
25
+ curTimeoutMs = Math.floor(curTimeoutMs * cfg.backoffMul);
26
+ }
27
+ }
28
+ }
@@ -0,0 +1,14 @@
1
+ export * from "./network/auth-client.js";
2
+ export * from "./core/utils.js";
3
+ export * from "./core/consts.js";
4
+ export * from "./core/types.js";
5
+ export * from "./agent/session/agent-credentials-store.js";
6
+ export * from "./agent/auth/agent-jwt.js";
7
+ export * from "./agent/auth/agent-pow.js";
8
+ export * from "./agent/auth/agent-auth-http.js";
9
+ export * from "./agent/jmap/agent-jmap.js";
10
+ export * from "./agent/session/agent-session.js";
11
+ export * from "./agent/session/agent-resolve-config.js";
12
+ export * from "./agent/jmap/agent-help-content.js";
13
+ export * from "./agent/jmap/agent-vars.js";
14
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/lib/mod.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAEhC,cAAc,4CAA4C,CAAC;AAC3D,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iCAAiC,CAAC;AAChD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,kCAAkC,CAAC;AACjD,cAAc,yCAAyC,CAAC;AACxD,cAAc,oCAAoC,CAAC;AACnD,cAAc,4BAA4B,CAAC"}