dsh-aimail 0.1.7 → 0.1.8

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.
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=register-cli.d.ts.map
@@ -0,0 +1,118 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * register-cli — CLI-spawnable dsh↔AIMail binding entry (TS home of the
4
+ * retired cli/dsh/bind_agent.py; platform boundary: CLI never implements
5
+ * platform registration, it spawns this entry via the platform registry).
6
+ *
7
+ * Flow (parity with bind_agent.py, Python shared chain replaced by the
8
+ * mail-core chain):
9
+ * 1. systemId: --system-id | AIMAIL_SYSTEM_ID | unique local system
10
+ * 2. email: --email | emailForAgent('agent', domain, system_name)
11
+ * 3. gateway chain: autoBind (registerAddress+activate+saveBinding+route)
12
+ * 4. --force: re-bind with a fresh session_id (cloud webhook refresh +
13
+ * local extra update) — mirrors bind_agent's every-run semantics.
14
+ *
15
+ * ABI: stdout = one JSON line {ok,email,system_id,exists?,registered?,
16
+ * config_path?,api_key?,error?,hint?}; logs → stderr; exit 0 = ok.
17
+ *
18
+ * Usage (from the CLI platform registry):
19
+ * node <dsh-aimail>/dist/register-cli.js [--system-id S] [--email E]
20
+ * [--manager M] [--session-id U] [--preset mail] [--local-webhook URL]
21
+ * [--force]
22
+ */
23
+ import { randomUUID } from 'node:crypto';
24
+ import { autoBind, emailForAgent, listSystemDirs, loadAgentConfig, readSystemConfig, registerAddress, registerBridgeRoute, saveBinding, } from '@aimail/mail-core';
25
+ function arg(argv, name) {
26
+ const i = argv.indexOf(name);
27
+ return i >= 0 && i + 1 < argv.length ? argv[i + 1] : '';
28
+ }
29
+ function flag(argv, name) {
30
+ return argv.includes(name);
31
+ }
32
+ async function main() {
33
+ const argv = process.argv.slice(2);
34
+ const systemIdArg = arg(argv, '--system-id');
35
+ const emailArg = arg(argv, '--email');
36
+ const manager = arg(argv, '--manager');
37
+ const sessionId = arg(argv, '--session-id');
38
+ const preset = arg(argv, '--preset') || 'mail';
39
+ const localWebhook = arg(argv, '--local-webhook') || 'http://127.0.0.1:9099/aimail/inbound';
40
+ const force = flag(argv, '--force');
41
+ const systemId = systemIdArg ||
42
+ process.env.AIMAIL_SYSTEM_ID ||
43
+ (await listSystemDirs())[0] ||
44
+ '';
45
+ if (!systemId) {
46
+ console.log(JSON.stringify({ ok: false, error: 'no aimail system found', hint: 'run aimail install first' }));
47
+ return 1;
48
+ }
49
+ const gw = await readSystemConfig(systemId);
50
+ const email = emailArg || emailForAgent('agent', gw.domain || '', gw.system_name || '');
51
+ try {
52
+ if (!force) {
53
+ const res = await autoBind({
54
+ systemId,
55
+ email,
56
+ webhookUrl: localWebhook,
57
+ ...(manager ? { managerAddress: manager } : {}),
58
+ extraFields: {
59
+ session_id: sessionId || randomUUID().replace(/-/g, ''),
60
+ preset,
61
+ },
62
+ });
63
+ console.log(JSON.stringify({
64
+ ok: true,
65
+ email,
66
+ system_id: systemId,
67
+ ...(res.exists ? { exists: true } : { registered: true }),
68
+ ...(res.config_path ? { config_path: res.config_path } : {}),
69
+ }));
70
+ return 0;
71
+ }
72
+ // force re-bind: refresh cloud webhook config, keep/refresh local key,
73
+ // update session extra. Remote address exists → registerAddress refreshes
74
+ // webhook and returns {exists}; local key is carried over.
75
+ const existing = await loadAgentConfig(systemId, email);
76
+ if (!existing || !existing.api_key) {
77
+ // No local binding — plain autoBind path.
78
+ const res = await autoBind({
79
+ systemId,
80
+ email,
81
+ webhookUrl: localWebhook,
82
+ ...(manager ? { managerAddress: manager } : {}),
83
+ extraFields: { session_id: sessionId || randomUUID().replace(/-/g, ''), preset },
84
+ });
85
+ console.log(JSON.stringify({ ok: true, email, system_id: systemId, registered: true, ...(res.config_path ? { config_path: res.config_path } : {}) }));
86
+ return 0;
87
+ }
88
+ const webhookSecret = existing.webhook_secret || '';
89
+ const reg = await registerAddress({
90
+ systemId,
91
+ email,
92
+ webhookUrl: localWebhook,
93
+ webhookSecret: webhookSecret || randomUUID().replace(/-/g, '') + randomUUID().replace(/-/g, ''),
94
+ ...(manager ? { managerAddress: manager } : {}),
95
+ });
96
+ void reg; // exists:true expected (refresh); new-key path handled above
97
+ const configPath = await saveBinding({
98
+ systemId,
99
+ email,
100
+ apiKey: existing.api_key,
101
+ webhookUrl: localWebhook,
102
+ webhookSecret,
103
+ ...(manager ? { managerAddress: manager } : {}),
104
+ extra: { session_id: sessionId || randomUUID().replace(/-/g, ''), preset },
105
+ gateway: gw,
106
+ });
107
+ await registerBridgeRoute({ systemId, email, webhookUrl: localWebhook });
108
+ console.log(JSON.stringify({ ok: true, email, system_id: systemId, registered: true, config_path: configPath }));
109
+ return 0;
110
+ }
111
+ catch (e) {
112
+ const msg = e instanceof Error ? e.message : String(e);
113
+ console.log(JSON.stringify({ ok: false, error: msg, hint: 'see host plugin state / aimail check' }));
114
+ return 1;
115
+ }
116
+ }
117
+ void main().then((code) => process.exit(code));
118
+ //# sourceMappingURL=register-cli.js.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-aimail",
3
3
  "description": "AIMail plugin for dsh — install via: dsh plugin --profile web add dsh-aimail",
4
- "version": "0.1.7",
4
+ "version": "0.1.8",
5
5
  "publishConfig": {
6
6
  "access": "public",
7
7
  "provenance": true
@@ -51,8 +51,8 @@
51
51
  "@deepseek-ai/dsh-tools": "^0.0.1-rc.1"
52
52
  },
53
53
  "dependencies": {
54
- "@aimail/mail-core": "^0.1.7",
55
- "@aimail/mail": "^0.1.7"
54
+ "@aimail/mail-core": "^0.1.8",
55
+ "@aimail/mail": "^0.1.8"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@deepseek-ai/cordis": "^4.0.1",