@zeph-to/mcp-server 1.2.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/api-client.d.ts +7 -2
- package/dist/api-client.d.ts.map +1 -1
- package/dist/api-client.js +4 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +8 -4
- package/dist/crypto.d.ts +58 -0
- package/dist/crypto.d.ts.map +1 -0
- package/dist/crypto.js +193 -0
- package/dist/error-format.js +1 -1
- package/dist/index.js +9 -0
- package/dist/tools/file.d.ts.map +1 -1
- package/dist/tools/file.js +62 -31
- package/dist/tools/notify.d.ts.map +1 -1
- package/dist/tools/notify.js +50 -9
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -48,11 +48,13 @@ Add to `~/.claude/settings.json`:
|
|
|
48
48
|
|
|
49
49
|
| Variable | Required | Description |
|
|
50
50
|
|----------|----------|-------------|
|
|
51
|
-
| `ZEPH_API_KEY` | Yes | API key from Settings > API Keys |
|
|
51
|
+
| `ZEPH_API_KEY` | Yes* | API key from Settings > API Keys |
|
|
52
52
|
| `ZEPH_HOOK_ID` | No | Hook ID for interactive tools (`zeph_prompt`, `zeph_input`) |
|
|
53
53
|
| `ZEPH_DEVICE_ID` | No | Target device ID. Omit to send to all devices |
|
|
54
54
|
| `ZEPH_BASE_URL` | No | API base URL (default: `https://api.zeph.to/v1`) |
|
|
55
55
|
|
|
56
|
+
\* All env vars fall back to `~/.zeph/config.json` if not set or if the value is an unresolved `${...}` interpolation.
|
|
57
|
+
|
|
56
58
|
## Tools
|
|
57
59
|
|
|
58
60
|
### zeph_notify
|
package/dist/api-client.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export declare class ZephApiClient {
|
|
|
10
10
|
private readonly baseUrl;
|
|
11
11
|
constructor(config: McpServerConfig);
|
|
12
12
|
sendPush(params: {
|
|
13
|
-
title
|
|
13
|
+
title?: string;
|
|
14
14
|
body?: string;
|
|
15
15
|
url?: string;
|
|
16
16
|
type?: string;
|
|
@@ -22,7 +22,12 @@ export declare class ZephApiClient {
|
|
|
22
22
|
fileName: string;
|
|
23
23
|
fileSize: number;
|
|
24
24
|
fileType: string;
|
|
25
|
+
iv?: string;
|
|
26
|
+
encryptedKey?: string;
|
|
25
27
|
}[];
|
|
28
|
+
isEncrypted?: boolean;
|
|
29
|
+
encryptedKey?: string;
|
|
30
|
+
senderPublicKey?: string;
|
|
26
31
|
}): Promise<PushResponse>;
|
|
27
32
|
triggerHook(hookId: string, params: {
|
|
28
33
|
title: string;
|
|
@@ -50,7 +55,7 @@ export declare class ZephApiClient {
|
|
|
50
55
|
fileType: string;
|
|
51
56
|
fileSize: number;
|
|
52
57
|
}): Promise<UploadRequestResponse>;
|
|
53
|
-
uploadToS3(url: string, content: string, contentType: string): Promise<void>;
|
|
58
|
+
uploadToS3(url: string, content: string | Buffer, contentType: string): Promise<void>;
|
|
54
59
|
private request;
|
|
55
60
|
}
|
|
56
61
|
//# sourceMappingURL=api-client.d.ts.map
|
package/dist/api-client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-client.d.ts","sourceRoot":"","sources":["../src/api-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAEV,YAAY,EACZ,mBAAmB,EACnB,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,qBAAqB,EACtB,MAAM,YAAY,CAAC;AAEpB,qBAAa,QAAS,SAAQ,KAAK;aAGf,IAAI,EAAE,MAAM;aACZ,MAAM,EAAE,MAAM;gBAF9B,OAAO,EAAE,MAAM,EACC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM;CAKjC;AAKD,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,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AC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;YAc7E,OAAO;CAsCtB"}
|
package/dist/api-client.js
CHANGED
|
@@ -55,10 +55,12 @@ class ZephApiClient {
|
|
|
55
55
|
return this.request('POST', '/files/upload-request', params);
|
|
56
56
|
}
|
|
57
57
|
async uploadToS3(url, content, contentType) {
|
|
58
|
+
const isText = typeof content === 'string';
|
|
59
|
+
const body = isText ? content : new Uint8Array(content);
|
|
58
60
|
const response = await fetch(url, {
|
|
59
61
|
method: 'PUT',
|
|
60
|
-
headers: { 'Content-Type': `${contentType}; charset=utf-8` },
|
|
61
|
-
body
|
|
62
|
+
headers: { 'Content-Type': isText ? `${contentType}; charset=utf-8` : contentType },
|
|
63
|
+
body,
|
|
62
64
|
signal: AbortSignal.timeout(DEFAULT_TIMEOUT_MS),
|
|
63
65
|
});
|
|
64
66
|
if (!response.ok) {
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAuBD,eAAO,MAAM,UAAU,QAAO,eAgB7B,CAAC"}
|
package/dist/config.js
CHANGED
|
@@ -4,6 +4,10 @@ exports.loadConfig = void 0;
|
|
|
4
4
|
const fs_1 = require("fs");
|
|
5
5
|
const path_1 = require("path");
|
|
6
6
|
const DEFAULT_BASE_URL = 'https://api.zeph.to/v1';
|
|
7
|
+
const resolvedEnv = (key) => {
|
|
8
|
+
const val = process.env[key];
|
|
9
|
+
return val && !val.startsWith('${') ? val : undefined;
|
|
10
|
+
};
|
|
7
11
|
const loadFileConfig = () => {
|
|
8
12
|
try {
|
|
9
13
|
const configPath = (0, path_1.join)(process.env.HOME ?? '~', '.zeph', 'config.json');
|
|
@@ -15,15 +19,15 @@ const loadFileConfig = () => {
|
|
|
15
19
|
};
|
|
16
20
|
const loadConfig = () => {
|
|
17
21
|
const fileConfig = loadFileConfig();
|
|
18
|
-
const apiKey =
|
|
22
|
+
const apiKey = resolvedEnv('ZEPH_API_KEY') ?? fileConfig.apiKey;
|
|
19
23
|
if (!apiKey) {
|
|
20
24
|
throw new Error('ZEPH_API_KEY not found. Run "npx @zeph-to/hook-sdk install" or set ZEPH_API_KEY env var.');
|
|
21
25
|
}
|
|
22
26
|
return {
|
|
23
27
|
apiKey,
|
|
24
|
-
baseUrl: (
|
|
25
|
-
hookId:
|
|
26
|
-
deviceId:
|
|
28
|
+
baseUrl: (resolvedEnv('ZEPH_BASE_URL') ?? fileConfig.baseUrl ?? DEFAULT_BASE_URL).replace(/\/$/, ''),
|
|
29
|
+
hookId: resolvedEnv('ZEPH_HOOK_ID') ?? fileConfig.hookId,
|
|
30
|
+
deviceId: resolvedEnv('ZEPH_DEVICE_ID') ?? fileConfig.deviceId,
|
|
27
31
|
};
|
|
28
32
|
};
|
|
29
33
|
exports.loadConfig = loadConfig;
|
package/dist/crypto.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* E2E encryption for MCP server — self-contained ECDH P-256 + AES-256-GCM
|
|
3
|
+
* Mirrors @zeph/crypto API but bundled inline (no external dependency).
|
|
4
|
+
* Uses Web Crypto API (globalThis.crypto.subtle) — Node.js 18+.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Initialize crypto: load or generate ECDH key pair.
|
|
8
|
+
* Safe to call concurrently — deduplicates to single init.
|
|
9
|
+
* Returns the exported public key (Base64 SPKI).
|
|
10
|
+
*/
|
|
11
|
+
export declare const initCrypto: () => Promise<string>;
|
|
12
|
+
export declare const getKeyPair: () => CryptoKeyPair | null;
|
|
13
|
+
export declare const getPublicKey: () => string | null;
|
|
14
|
+
/**
|
|
15
|
+
* Encrypt push body for a recipient.
|
|
16
|
+
* Returns fields ready to merge into the sendPush payload.
|
|
17
|
+
*/
|
|
18
|
+
export declare const encryptPushBody: (input: {
|
|
19
|
+
title?: string;
|
|
20
|
+
body?: string;
|
|
21
|
+
url?: string;
|
|
22
|
+
}, recipientPublicKeyRaw: string) => Promise<{
|
|
23
|
+
body: string;
|
|
24
|
+
encryptedKey: string;
|
|
25
|
+
senderPublicKey: string;
|
|
26
|
+
isEncrypted: true;
|
|
27
|
+
}>;
|
|
28
|
+
/**
|
|
29
|
+
* Encrypt push body for self (all own devices).
|
|
30
|
+
*/
|
|
31
|
+
export declare const encryptPushBodyForSelf: (input: {
|
|
32
|
+
title?: string;
|
|
33
|
+
body?: string;
|
|
34
|
+
url?: string;
|
|
35
|
+
}) => Promise<{
|
|
36
|
+
body: string;
|
|
37
|
+
encryptedKey: string;
|
|
38
|
+
senderPublicKey: string;
|
|
39
|
+
isEncrypted: true;
|
|
40
|
+
}>;
|
|
41
|
+
/**
|
|
42
|
+
* Encrypt file content for a recipient.
|
|
43
|
+
* Returns encrypted buffer + key material for file attachment metadata.
|
|
44
|
+
*/
|
|
45
|
+
export declare const encryptFileForRecipient: (content: string, recipientPublicKeyRaw: string) => Promise<{
|
|
46
|
+
ciphertext: Buffer;
|
|
47
|
+
iv: string;
|
|
48
|
+
encryptedKey: string;
|
|
49
|
+
}>;
|
|
50
|
+
/**
|
|
51
|
+
* Encrypt file content for self (all own devices).
|
|
52
|
+
*/
|
|
53
|
+
export declare const encryptFileForSelf: (content: string) => Promise<{
|
|
54
|
+
ciphertext: Buffer;
|
|
55
|
+
iv: string;
|
|
56
|
+
encryptedKey: string;
|
|
57
|
+
}>;
|
|
58
|
+
//# sourceMappingURL=crypto.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../src/crypto.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA0JH;;;;GAIG;AACH,eAAO,MAAM,UAAU,QAAO,OAAO,CAAC,MAAM,CAoB3C,CAAC;AAEF,eAAO,MAAM,UAAU,QAAO,aAAa,GAAG,IAAqB,CAAC;AACpE,eAAO,MAAM,YAAY,QAAO,MAAM,GAAG,IAA+B,CAAC;AAEzE;;;GAGG;AACH,eAAO,MAAM,eAAe,GAC1B,OAAO;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,EACtD,uBAAuB,MAAM,KAC5B,OAAO,CAAC;IACT,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,IAAI,CAAC;CACnB,CAeA,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,sBAAsB,GACjC,OAAO;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,KACrD,OAAO,CAAC;IACT,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,IAAI,CAAC;CACnB,CAaA,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,uBAAuB,GAClC,SAAS,MAAM,EACf,uBAAuB,MAAM,KAC5B,OAAO,CAAC;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CASlE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kBAAkB,GAC7B,SAAS,MAAM,KACd,OAAO,CAAC;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CAQlE,CAAC"}
|
package/dist/crypto.js
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* E2E encryption for MCP server — self-contained ECDH P-256 + AES-256-GCM
|
|
4
|
+
* Mirrors @zeph/crypto API but bundled inline (no external dependency).
|
|
5
|
+
* Uses Web Crypto API (globalThis.crypto.subtle) — Node.js 18+.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.encryptFileForSelf = exports.encryptFileForRecipient = exports.encryptPushBodyForSelf = exports.encryptPushBody = exports.getPublicKey = exports.getKeyPair = exports.initCrypto = void 0;
|
|
9
|
+
/// <reference lib="dom" />
|
|
10
|
+
const fs_1 = require("fs");
|
|
11
|
+
const path_1 = require("path");
|
|
12
|
+
// ─── Base64 helpers ───
|
|
13
|
+
const toBase64 = (buffer) => {
|
|
14
|
+
const bytes = new Uint8Array(buffer);
|
|
15
|
+
let binary = '';
|
|
16
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
17
|
+
binary += String.fromCharCode(bytes[i]);
|
|
18
|
+
}
|
|
19
|
+
return btoa(binary);
|
|
20
|
+
};
|
|
21
|
+
const fromBase64 = (base64) => {
|
|
22
|
+
const binary = atob(base64);
|
|
23
|
+
const bytes = new Uint8Array(binary.length);
|
|
24
|
+
for (let i = 0; i < binary.length; i++) {
|
|
25
|
+
bytes[i] = binary.charCodeAt(i);
|
|
26
|
+
}
|
|
27
|
+
return bytes.buffer;
|
|
28
|
+
};
|
|
29
|
+
// ─── ECDH key management ───
|
|
30
|
+
const ECDH_PARAMS = { name: 'ECDH', namedCurve: 'P-256' };
|
|
31
|
+
const generateKeyPair = async () => crypto.subtle.generateKey(ECDH_PARAMS, true, ['deriveKey', 'deriveBits']);
|
|
32
|
+
const exportKeyPair = async (keyPair) => {
|
|
33
|
+
const [publicRaw, privateRaw] = await Promise.all([
|
|
34
|
+
crypto.subtle.exportKey('spki', keyPair.publicKey),
|
|
35
|
+
crypto.subtle.exportKey('pkcs8', keyPair.privateKey),
|
|
36
|
+
]);
|
|
37
|
+
return { publicKey: toBase64(publicRaw), privateKey: toBase64(privateRaw) };
|
|
38
|
+
};
|
|
39
|
+
const importPublicKey = async (base64) => crypto.subtle.importKey('spki', fromBase64(base64), ECDH_PARAMS, true, []);
|
|
40
|
+
const importPrivateKey = async (base64) => crypto.subtle.importKey('pkcs8', fromBase64(base64), ECDH_PARAMS, true, ['deriveKey', 'deriveBits']);
|
|
41
|
+
const importKeyPair = async (exported) => {
|
|
42
|
+
const [publicKey, privateKey] = await Promise.all([
|
|
43
|
+
importPublicKey(exported.publicKey),
|
|
44
|
+
importPrivateKey(exported.privateKey),
|
|
45
|
+
]);
|
|
46
|
+
return { publicKey, privateKey };
|
|
47
|
+
};
|
|
48
|
+
const deriveAesKey = async (privateKey, publicKey) => crypto.subtle.deriveKey({ name: 'ECDH', public: publicKey }, privateKey, { name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt']);
|
|
49
|
+
const encrypt = async (plaintext, senderPrivateKey, recipientPublicKey) => {
|
|
50
|
+
const messageKey = await crypto.subtle.generateKey({ name: 'AES-GCM', length: 256 }, true, ['encrypt', 'decrypt']);
|
|
51
|
+
const iv = crypto.getRandomValues(new Uint8Array(12));
|
|
52
|
+
const ciphertext = await crypto.subtle.encrypt({ name: 'AES-GCM', iv }, messageKey, new TextEncoder().encode(plaintext));
|
|
53
|
+
const sharedKey = await deriveAesKey(senderPrivateKey, recipientPublicKey);
|
|
54
|
+
const rawMessageKey = await crypto.subtle.exportKey('raw', messageKey);
|
|
55
|
+
const keyIv = crypto.getRandomValues(new Uint8Array(12));
|
|
56
|
+
const encryptedKey = await crypto.subtle.encrypt({ name: 'AES-GCM', iv: keyIv }, sharedKey, rawMessageKey);
|
|
57
|
+
return {
|
|
58
|
+
ciphertext: toBase64(ciphertext),
|
|
59
|
+
iv: toBase64(iv.buffer),
|
|
60
|
+
encryptedKey: toBase64(encryptedKey),
|
|
61
|
+
keyIv: toBase64(keyIv.buffer),
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
// ─── File encryption ───
|
|
65
|
+
const encryptFileContent = async (content, senderPrivateKey, recipientPublicKey) => {
|
|
66
|
+
const buffer = new TextEncoder().encode(content).buffer;
|
|
67
|
+
const fileKey = await crypto.subtle.generateKey({ name: 'AES-GCM', length: 256 }, true, ['encrypt', 'decrypt']);
|
|
68
|
+
const iv = crypto.getRandomValues(new Uint8Array(12));
|
|
69
|
+
const ciphertext = await crypto.subtle.encrypt({ name: 'AES-GCM', iv }, fileKey, buffer);
|
|
70
|
+
const sharedKey = await deriveAesKey(senderPrivateKey, recipientPublicKey);
|
|
71
|
+
const rawFileKey = await crypto.subtle.exportKey('raw', fileKey);
|
|
72
|
+
const keyIv = crypto.getRandomValues(new Uint8Array(12));
|
|
73
|
+
const encryptedKey = await crypto.subtle.encrypt({ name: 'AES-GCM', iv: keyIv }, sharedKey, rawFileKey);
|
|
74
|
+
return {
|
|
75
|
+
ciphertext: Buffer.from(ciphertext),
|
|
76
|
+
iv: toBase64(iv.buffer),
|
|
77
|
+
encryptedKey: toBase64(encryptedKey),
|
|
78
|
+
keyIv: toBase64(keyIv.buffer),
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
// ─── Key persistence (~/.config/zeph/keys.json) ───
|
|
82
|
+
const KEYS_DIR = (0, path_1.join)(process.env.HOME ?? '~', '.config', 'zeph');
|
|
83
|
+
const KEYS_PATH = (0, path_1.join)(KEYS_DIR, 'keys.json');
|
|
84
|
+
const loadStoredKeys = () => {
|
|
85
|
+
try {
|
|
86
|
+
return JSON.parse((0, fs_1.readFileSync)(KEYS_PATH, 'utf-8'));
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
const storeKeys = (exported) => {
|
|
93
|
+
(0, fs_1.mkdirSync)(KEYS_DIR, { recursive: true });
|
|
94
|
+
(0, fs_1.writeFileSync)(KEYS_PATH, JSON.stringify(exported, null, 2), { mode: 0o600 });
|
|
95
|
+
};
|
|
96
|
+
// ─── Cached state ───
|
|
97
|
+
let cachedKeyPair = null;
|
|
98
|
+
let cachedExportedPublicKey = null;
|
|
99
|
+
let cachedOwnPublicKey = null;
|
|
100
|
+
let initPromise = null;
|
|
101
|
+
/**
|
|
102
|
+
* Initialize crypto: load or generate ECDH key pair.
|
|
103
|
+
* Safe to call concurrently — deduplicates to single init.
|
|
104
|
+
* Returns the exported public key (Base64 SPKI).
|
|
105
|
+
*/
|
|
106
|
+
const initCrypto = () => {
|
|
107
|
+
if (initPromise)
|
|
108
|
+
return initPromise;
|
|
109
|
+
initPromise = (async () => {
|
|
110
|
+
const stored = loadStoredKeys();
|
|
111
|
+
if (stored) {
|
|
112
|
+
cachedKeyPair = await importKeyPair(stored);
|
|
113
|
+
cachedExportedPublicKey = stored.publicKey;
|
|
114
|
+
cachedOwnPublicKey = cachedKeyPair.publicKey;
|
|
115
|
+
return stored.publicKey;
|
|
116
|
+
}
|
|
117
|
+
const keyPair = await generateKeyPair();
|
|
118
|
+
const exported = await exportKeyPair(keyPair);
|
|
119
|
+
storeKeys(exported);
|
|
120
|
+
cachedKeyPair = keyPair;
|
|
121
|
+
cachedExportedPublicKey = exported.publicKey;
|
|
122
|
+
cachedOwnPublicKey = keyPair.publicKey;
|
|
123
|
+
return exported.publicKey;
|
|
124
|
+
})();
|
|
125
|
+
return initPromise;
|
|
126
|
+
};
|
|
127
|
+
exports.initCrypto = initCrypto;
|
|
128
|
+
const getKeyPair = () => cachedKeyPair;
|
|
129
|
+
exports.getKeyPair = getKeyPair;
|
|
130
|
+
const getPublicKey = () => cachedExportedPublicKey;
|
|
131
|
+
exports.getPublicKey = getPublicKey;
|
|
132
|
+
/**
|
|
133
|
+
* Encrypt push body for a recipient.
|
|
134
|
+
* Returns fields ready to merge into the sendPush payload.
|
|
135
|
+
*/
|
|
136
|
+
const encryptPushBody = async (input, recipientPublicKeyRaw) => {
|
|
137
|
+
if (!cachedKeyPair || !cachedExportedPublicKey)
|
|
138
|
+
throw new Error('Crypto not initialized');
|
|
139
|
+
const recipientKey = await importPublicKey(recipientPublicKeyRaw);
|
|
140
|
+
const payload = await encrypt(JSON.stringify({ title: input.title, body: input.body, url: input.url }), cachedKeyPair.privateKey, recipientKey);
|
|
141
|
+
return {
|
|
142
|
+
body: JSON.stringify({ ciphertext: payload.ciphertext, iv: payload.iv }),
|
|
143
|
+
encryptedKey: JSON.stringify({ encryptedKey: payload.encryptedKey, keyIv: payload.keyIv }),
|
|
144
|
+
senderPublicKey: cachedExportedPublicKey,
|
|
145
|
+
isEncrypted: true,
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
exports.encryptPushBody = encryptPushBody;
|
|
149
|
+
/**
|
|
150
|
+
* Encrypt push body for self (all own devices).
|
|
151
|
+
*/
|
|
152
|
+
const encryptPushBodyForSelf = async (input) => {
|
|
153
|
+
if (!cachedKeyPair || !cachedExportedPublicKey || !cachedOwnPublicKey)
|
|
154
|
+
throw new Error('Crypto not initialized');
|
|
155
|
+
const payload = await encrypt(JSON.stringify({ title: input.title, body: input.body, url: input.url }), cachedKeyPair.privateKey, cachedOwnPublicKey);
|
|
156
|
+
return {
|
|
157
|
+
body: JSON.stringify({ ciphertext: payload.ciphertext, iv: payload.iv }),
|
|
158
|
+
encryptedKey: JSON.stringify({ encryptedKey: payload.encryptedKey, keyIv: payload.keyIv }),
|
|
159
|
+
senderPublicKey: cachedExportedPublicKey,
|
|
160
|
+
isEncrypted: true,
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
exports.encryptPushBodyForSelf = encryptPushBodyForSelf;
|
|
164
|
+
/**
|
|
165
|
+
* Encrypt file content for a recipient.
|
|
166
|
+
* Returns encrypted buffer + key material for file attachment metadata.
|
|
167
|
+
*/
|
|
168
|
+
const encryptFileForRecipient = async (content, recipientPublicKeyRaw) => {
|
|
169
|
+
if (!cachedKeyPair)
|
|
170
|
+
throw new Error('Crypto not initialized');
|
|
171
|
+
const recipientKey = await importPublicKey(recipientPublicKeyRaw);
|
|
172
|
+
const result = await encryptFileContent(content, cachedKeyPair.privateKey, recipientKey);
|
|
173
|
+
return {
|
|
174
|
+
ciphertext: result.ciphertext,
|
|
175
|
+
iv: result.iv,
|
|
176
|
+
encryptedKey: JSON.stringify({ encryptedKey: result.encryptedKey, keyIv: result.keyIv }),
|
|
177
|
+
};
|
|
178
|
+
};
|
|
179
|
+
exports.encryptFileForRecipient = encryptFileForRecipient;
|
|
180
|
+
/**
|
|
181
|
+
* Encrypt file content for self (all own devices).
|
|
182
|
+
*/
|
|
183
|
+
const encryptFileForSelf = async (content) => {
|
|
184
|
+
if (!cachedKeyPair || !cachedOwnPublicKey)
|
|
185
|
+
throw new Error('Crypto not initialized');
|
|
186
|
+
const result = await encryptFileContent(content, cachedKeyPair.privateKey, cachedOwnPublicKey);
|
|
187
|
+
return {
|
|
188
|
+
ciphertext: result.ciphertext,
|
|
189
|
+
iv: result.iv,
|
|
190
|
+
encryptedKey: JSON.stringify({ encryptedKey: result.encryptedKey, keyIv: result.keyIv }),
|
|
191
|
+
};
|
|
192
|
+
};
|
|
193
|
+
exports.encryptFileForSelf = encryptFileForSelf;
|
package/dist/error-format.js
CHANGED
|
@@ -35,7 +35,7 @@ const formatToolError = (err) => {
|
|
|
35
35
|
toolError.suggestion = 'Monthly quota exceeded. Upgrade plan for higher limits';
|
|
36
36
|
}
|
|
37
37
|
else if (err.code === 'UNAUTHORIZED') {
|
|
38
|
-
toolError.suggestion = 'Check ZEPH_API_KEY environment variable';
|
|
38
|
+
toolError.suggestion = 'Check ZEPH_API_KEY environment variable or ~/.zeph/config.json';
|
|
39
39
|
}
|
|
40
40
|
else if (err.code === 'HOOK_DISABLED') {
|
|
41
41
|
toolError.suggestion = 'Enable the Hook in Settings → Hooks';
|
package/dist/index.js
CHANGED
|
@@ -7,6 +7,7 @@ const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
|
7
7
|
const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
8
8
|
const config_js_1 = require("./config.js");
|
|
9
9
|
const api_client_js_1 = require("./api-client.js");
|
|
10
|
+
const crypto_js_1 = require("./crypto.js");
|
|
10
11
|
const notify_js_1 = require("./tools/notify.js");
|
|
11
12
|
const prompt_js_1 = require("./tools/prompt.js");
|
|
12
13
|
const input_js_1 = require("./tools/input.js");
|
|
@@ -66,6 +67,14 @@ const createServer = () => {
|
|
|
66
67
|
return server;
|
|
67
68
|
};
|
|
68
69
|
const main = async () => {
|
|
70
|
+
// Initialize E2E encryption keys (load or generate)
|
|
71
|
+
try {
|
|
72
|
+
const publicKey = await (0, crypto_js_1.initCrypto)();
|
|
73
|
+
console.error(`[Crypto] E2E encryption ready (publicKey: ${publicKey.slice(0, 20)}...)`);
|
|
74
|
+
}
|
|
75
|
+
catch (err) {
|
|
76
|
+
console.error('[Crypto] E2E encryption unavailable:', err);
|
|
77
|
+
}
|
|
69
78
|
const server = createServer();
|
|
70
79
|
const transport = new stdio_js_1.StdioServerTransport();
|
|
71
80
|
await server.connect(transport);
|
package/dist/tools/file.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../src/tools/file.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../src/tools/file.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAwBpD,eAAO,MAAM,gBAAgB,GAAI,QAAQ,SAAS,EAAE,QAAQ,aAAa,EAAE,QAAQ,eAAe,SA0EjG,CAAC"}
|
package/dist/tools/file.js
CHANGED
|
@@ -3,6 +3,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.registerFileTool = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const error_format_js_1 = require("../error-format.js");
|
|
6
|
+
const crypto_js_1 = require("../crypto.js");
|
|
7
|
+
const inferMimeType = (fileName) => {
|
|
8
|
+
const ext = fileName.split('.').pop()?.toLowerCase();
|
|
9
|
+
const map = {
|
|
10
|
+
txt: 'text/plain',
|
|
11
|
+
json: 'application/json',
|
|
12
|
+
csv: 'text/csv',
|
|
13
|
+
md: 'text/markdown',
|
|
14
|
+
html: 'text/html',
|
|
15
|
+
xml: 'text/xml',
|
|
16
|
+
yaml: 'text/yaml',
|
|
17
|
+
yml: 'text/yaml',
|
|
18
|
+
log: 'text/plain',
|
|
19
|
+
ts: 'text/typescript',
|
|
20
|
+
js: 'text/javascript',
|
|
21
|
+
py: 'text/x-python',
|
|
22
|
+
sh: 'text/x-shellscript',
|
|
23
|
+
};
|
|
24
|
+
return map[ext ?? ''] ?? 'text/plain';
|
|
25
|
+
};
|
|
6
26
|
const registerFileTool = (server, client, config) => {
|
|
7
27
|
server.registerTool('zeph_file', {
|
|
8
28
|
description: 'Send a text file to the user\'s device. The content is uploaded and delivered as a file push. Use for logs, reports, code snippets, or any text content.',
|
|
@@ -19,20 +39,50 @@ const registerFileTool = (server, client, config) => {
|
|
|
19
39
|
},
|
|
20
40
|
}, async ({ fileName, content, title, targetDeviceId }) => {
|
|
21
41
|
try {
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
42
|
+
const canEncrypt = !!(0, crypto_js_1.getKeyPair)() && !!(0, crypto_js_1.getPublicKey)();
|
|
43
|
+
let fileType = inferMimeType(fileName);
|
|
44
|
+
const originalSize = new TextEncoder().encode(content).byteLength;
|
|
45
|
+
// Step 1: Optionally encrypt file content
|
|
46
|
+
let uploadContent = content;
|
|
47
|
+
let uploadSize = originalSize;
|
|
48
|
+
let fileIv;
|
|
49
|
+
let fileEncryptedKey;
|
|
50
|
+
if (canEncrypt) {
|
|
51
|
+
try {
|
|
52
|
+
const encrypted = await (0, crypto_js_1.encryptFileForSelf)(content);
|
|
53
|
+
uploadContent = encrypted.ciphertext;
|
|
54
|
+
uploadSize = encrypted.ciphertext.length;
|
|
55
|
+
fileType = 'application/octet-stream';
|
|
56
|
+
fileIv = encrypted.iv;
|
|
57
|
+
fileEncryptedKey = encrypted.encryptedKey;
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
console.error('[Crypto] File encryption failed, sending plaintext:', err);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// Step 2: Request upload URL
|
|
64
|
+
const upload = await client.requestUpload({ fileName, fileType, fileSize: uploadSize });
|
|
65
|
+
// Step 3: Upload content to S3
|
|
66
|
+
await client.uploadToS3(upload.data.uploadUrl, uploadContent, fileType);
|
|
67
|
+
// Step 4: Send file push (encrypt push body if possible)
|
|
68
|
+
const pushTitle = title ?? fileName;
|
|
69
|
+
let pushPayload = {
|
|
70
|
+
title: pushTitle,
|
|
31
71
|
type: 'file',
|
|
32
|
-
files: [{ fileKey: upload.data.fileKey, fileName, fileSize, fileType }],
|
|
72
|
+
files: [{ fileKey: upload.data.fileKey, fileName, fileSize: originalSize, fileType: inferMimeType(fileName), iv: fileIv, encryptedKey: fileEncryptedKey }],
|
|
33
73
|
targetDeviceId: targetDeviceId ?? config.deviceId,
|
|
34
|
-
}
|
|
35
|
-
|
|
74
|
+
};
|
|
75
|
+
if (canEncrypt) {
|
|
76
|
+
try {
|
|
77
|
+
const enc = await (0, crypto_js_1.encryptPushBodyForSelf)({ title: pushTitle });
|
|
78
|
+
pushPayload = { ...pushPayload, title: undefined, body: enc.body, isEncrypted: enc.isEncrypted, encryptedKey: enc.encryptedKey, senderPublicKey: enc.senderPublicKey };
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
console.error('[Crypto] Push encryption failed, sending plaintext:', err);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const result = await client.sendPush(pushPayload);
|
|
85
|
+
return (0, error_format_js_1.textResult)({ pushId: result.data.pushId, fileKey: upload.data.fileKey, fileSize: originalSize, encrypted: canEncrypt });
|
|
36
86
|
}
|
|
37
87
|
catch (err) {
|
|
38
88
|
return (0, error_format_js_1.formatToolError)(err);
|
|
@@ -40,22 +90,3 @@ const registerFileTool = (server, client, config) => {
|
|
|
40
90
|
});
|
|
41
91
|
};
|
|
42
92
|
exports.registerFileTool = registerFileTool;
|
|
43
|
-
const inferMimeType = (fileName) => {
|
|
44
|
-
const ext = fileName.split('.').pop()?.toLowerCase();
|
|
45
|
-
const map = {
|
|
46
|
-
txt: 'text/plain',
|
|
47
|
-
json: 'application/json',
|
|
48
|
-
csv: 'text/csv',
|
|
49
|
-
md: 'text/markdown',
|
|
50
|
-
html: 'text/html',
|
|
51
|
-
xml: 'text/xml',
|
|
52
|
-
yaml: 'text/yaml',
|
|
53
|
-
yml: 'text/yaml',
|
|
54
|
-
log: 'text/plain',
|
|
55
|
-
ts: 'text/typescript',
|
|
56
|
-
js: 'text/javascript',
|
|
57
|
-
py: 'text/x-python',
|
|
58
|
-
sh: 'text/x-shellscript',
|
|
59
|
-
};
|
|
60
|
-
return map[ext ?? ''] ?? 'text/plain';
|
|
61
|
-
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notify.d.ts","sourceRoot":"","sources":["../../src/tools/notify.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEtD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"notify.d.ts","sourceRoot":"","sources":["../../src/tools/notify.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEtD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAYpD,eAAO,MAAM,kBAAkB,GAAI,QAAQ,SAAS,EAAE,QAAQ,aAAa,EAAE,QAAQ,eAAe,SA2GnG,CAAC"}
|
package/dist/tools/notify.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.registerNotifyTool = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const error_format_js_1 = require("../error-format.js");
|
|
6
|
+
const crypto_js_1 = require("../crypto.js");
|
|
6
7
|
const BODY_FILE_THRESHOLD = 0;
|
|
7
8
|
const PREVIEW_LENGTH = 200;
|
|
8
9
|
const inferMimeType = (fileName) => {
|
|
@@ -33,33 +34,73 @@ const registerNotifyTool = (server, client, config) => {
|
|
|
33
34
|
const deviceId = targetDeviceId ?? config.deviceId;
|
|
34
35
|
const bodyBytes = body ? new TextEncoder().encode(body).byteLength : 0;
|
|
35
36
|
const isLongBody = bodyBytes > BODY_FILE_THRESHOLD;
|
|
37
|
+
const canEncrypt = !!(0, crypto_js_1.getKeyPair)() && !!(0, crypto_js_1.getPublicKey)();
|
|
36
38
|
if (isLongBody && body) {
|
|
37
39
|
const fileName = 'response.md';
|
|
38
40
|
const fileType = inferMimeType(fileName);
|
|
39
41
|
const fileSize = bodyBytes;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
+
// Encrypt file content if keys available
|
|
43
|
+
let uploadContent = body;
|
|
44
|
+
let uploadContentType = fileType;
|
|
45
|
+
let fileIv;
|
|
46
|
+
let fileEncryptedKey;
|
|
47
|
+
if (canEncrypt) {
|
|
48
|
+
try {
|
|
49
|
+
const encrypted = await (0, crypto_js_1.encryptFileForSelf)(body);
|
|
50
|
+
uploadContent = encrypted.ciphertext;
|
|
51
|
+
uploadContentType = 'application/octet-stream';
|
|
52
|
+
fileIv = encrypted.iv;
|
|
53
|
+
fileEncryptedKey = encrypted.encryptedKey;
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
console.error('[Crypto] File encryption failed, sending plaintext:', err);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const upload = await client.requestUpload({ fileName, fileType: uploadContentType, fileSize: typeof uploadContent === 'string' ? fileSize : uploadContent.length });
|
|
60
|
+
await client.uploadToS3(upload.data.uploadUrl, uploadContent, uploadContentType);
|
|
42
61
|
const preview = body.length > PREVIEW_LENGTH ? body.slice(0, PREVIEW_LENGTH) + '...' : body;
|
|
43
|
-
|
|
62
|
+
// Encrypt push body (title/preview/url) if keys available
|
|
63
|
+
let pushPayload = {
|
|
44
64
|
title,
|
|
45
65
|
body: preview,
|
|
46
66
|
url,
|
|
47
67
|
type: 'file',
|
|
48
68
|
priority,
|
|
49
|
-
files: [{ fileKey: upload.data.fileKey, fileName, fileSize, fileType }],
|
|
69
|
+
files: [{ fileKey: upload.data.fileKey, fileName, fileSize, fileType, iv: fileIv, encryptedKey: fileEncryptedKey }],
|
|
50
70
|
targetDeviceId: deviceId,
|
|
51
|
-
}
|
|
52
|
-
|
|
71
|
+
};
|
|
72
|
+
if (canEncrypt) {
|
|
73
|
+
try {
|
|
74
|
+
const enc = await (0, crypto_js_1.encryptPushBodyForSelf)({ title, body: preview, url });
|
|
75
|
+
pushPayload = { ...pushPayload, title: undefined, body: enc.body, isEncrypted: enc.isEncrypted, encryptedKey: enc.encryptedKey, senderPublicKey: enc.senderPublicKey };
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
console.error('[Crypto] Push encryption failed, sending plaintext:', err);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const result = await client.sendPush(pushPayload);
|
|
82
|
+
return (0, error_format_js_1.textResult)({ pushId: result.data.pushId, fileKey: upload.data.fileKey, autoFile: true, encrypted: canEncrypt });
|
|
53
83
|
}
|
|
54
|
-
|
|
84
|
+
// Short body — encrypt push only
|
|
85
|
+
let pushPayload = {
|
|
55
86
|
title,
|
|
56
87
|
body,
|
|
57
88
|
url,
|
|
58
89
|
type: 'hook',
|
|
59
90
|
priority,
|
|
60
91
|
targetDeviceId: deviceId,
|
|
61
|
-
}
|
|
62
|
-
|
|
92
|
+
};
|
|
93
|
+
if (canEncrypt) {
|
|
94
|
+
try {
|
|
95
|
+
const enc = await (0, crypto_js_1.encryptPushBodyForSelf)({ title, body, url });
|
|
96
|
+
pushPayload = { ...pushPayload, title: undefined, body: enc.body, isEncrypted: enc.isEncrypted, encryptedKey: enc.encryptedKey, senderPublicKey: enc.senderPublicKey };
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
console.error('[Crypto] Push encryption failed, sending plaintext:', err);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const result = await client.sendPush(pushPayload);
|
|
103
|
+
return (0, error_format_js_1.textResult)({ pushId: result.data.pushId, encrypted: canEncrypt });
|
|
63
104
|
}
|
|
64
105
|
catch (err) {
|
|
65
106
|
return (0, error_format_js_1.formatToolError)(err);
|
package/dist/types.d.ts
CHANGED
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE;QACL,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE;QACJ,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE;QACJ,MAAM,EAAE,MAAM,CAAC;QACf,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;CACH;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE;QACJ,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,SAAS,GAAG,WAAW,GAAG,WAAW,GAAG,WAAW,CAAC;QAC5D,QAAQ,CAAC,EAAE;YACT,QAAQ,CAAC,EAAE,MAAM,CAAC;YAClB,KAAK,CAAC,EAAE,MAAM,CAAC;YACf,iBAAiB,CAAC,EAAE,MAAM,CAAC;SAC5B,CAAC;KACH,CAAC;CACH;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE;QACL,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH;AAED,MAAM,WAAW,YAAY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