@atomicmail/agent-skill-openclaw 0.3.24
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/LICENSE +21 -0
- package/README.md +182 -0
- package/SKILL.md +206 -0
- package/esm/_dnt.polyfills.d.ts +101 -0
- package/esm/_dnt.polyfills.d.ts.map +1 -0
- package/esm/_dnt.polyfills.js +127 -0
- package/esm/lib/agent/auth/agent-auth-http.d.ts +26 -0
- package/esm/lib/agent/auth/agent-auth-http.d.ts.map +1 -0
- package/esm/lib/agent/auth/agent-auth-http.js +85 -0
- package/esm/lib/agent/auth/agent-jwt.d.ts +12 -0
- package/esm/lib/agent/auth/agent-jwt.d.ts.map +1 -0
- package/esm/lib/agent/auth/agent-jwt.js +27 -0
- package/esm/lib/agent/auth/agent-pow.d.ts +5 -0
- package/esm/lib/agent/auth/agent-pow.d.ts.map +1 -0
- package/esm/lib/agent/auth/agent-pow.js +49 -0
- package/esm/lib/agent/jmap/agent-help-content.d.ts +2 -0
- package/esm/lib/agent/jmap/agent-help-content.d.ts.map +1 -0
- package/esm/lib/agent/jmap/agent-help-content.js +2 -0
- package/esm/lib/agent/jmap/agent-jmap-blob-limits.d.ts +27 -0
- package/esm/lib/agent/jmap/agent-jmap-blob-limits.d.ts.map +1 -0
- package/esm/lib/agent/jmap/agent-jmap-blob-limits.js +166 -0
- package/esm/lib/agent/jmap/agent-jmap-blob-upload.d.ts +24 -0
- package/esm/lib/agent/jmap/agent-jmap-blob-upload.d.ts.map +1 -0
- package/esm/lib/agent/jmap/agent-jmap-blob-upload.js +104 -0
- package/esm/lib/agent/jmap/agent-jmap-email-charset.d.ts +8 -0
- package/esm/lib/agent/jmap/agent-jmap-email-charset.d.ts.map +1 -0
- package/esm/lib/agent/jmap/agent-jmap-email-charset.js +61 -0
- package/esm/lib/agent/jmap/agent-jmap-run.d.ts +52 -0
- package/esm/lib/agent/jmap/agent-jmap-run.d.ts.map +1 -0
- package/esm/lib/agent/jmap/agent-jmap-run.js +260 -0
- package/esm/lib/agent/jmap/agent-jmap-verify.d.ts +9 -0
- package/esm/lib/agent/jmap/agent-jmap-verify.d.ts.map +1 -0
- package/esm/lib/agent/jmap/agent-jmap-verify.js +50 -0
- package/esm/lib/agent/jmap/agent-jmap.d.ts +89 -0
- package/esm/lib/agent/jmap/agent-jmap.d.ts.map +1 -0
- package/esm/lib/agent/jmap/agent-jmap.js +373 -0
- package/esm/lib/agent/jmap/agent-vars.d.ts +30 -0
- package/esm/lib/agent/jmap/agent-vars.d.ts.map +1 -0
- package/esm/lib/agent/jmap/agent-vars.js +96 -0
- package/esm/lib/agent/jmap/help-content/auth.d.ts +2 -0
- package/esm/lib/agent/jmap/help-content/auth.d.ts.map +1 -0
- package/esm/lib/agent/jmap/help-content/auth.js +33 -0
- package/esm/lib/agent/jmap/help-content/cron.d.ts +6 -0
- package/esm/lib/agent/jmap/help-content/cron.d.ts.map +1 -0
- package/esm/lib/agent/jmap/help-content/cron.js +159 -0
- package/esm/lib/agent/jmap/help-content/index.d.ts +6 -0
- package/esm/lib/agent/jmap/help-content/index.d.ts.map +1 -0
- package/esm/lib/agent/jmap/help-content/index.js +61 -0
- package/esm/lib/agent/jmap/help-content/installation.d.ts +2 -0
- package/esm/lib/agent/jmap/help-content/installation.d.ts.map +1 -0
- package/esm/lib/agent/jmap/help-content/installation.js +47 -0
- package/esm/lib/agent/jmap/help-content/jmap-cheatsheet.d.ts +2 -0
- package/esm/lib/agent/jmap/help-content/jmap-cheatsheet.d.ts.map +1 -0
- package/esm/lib/agent/jmap/help-content/jmap-cheatsheet.js +230 -0
- package/esm/lib/agent/jmap/help-content/multi-account.d.ts +2 -0
- package/esm/lib/agent/jmap/help-content/multi-account.d.ts.map +1 -0
- package/esm/lib/agent/jmap/help-content/multi-account.js +49 -0
- package/esm/lib/agent/jmap/help-content/overview.d.ts +2 -0
- package/esm/lib/agent/jmap/help-content/overview.d.ts.map +1 -0
- package/esm/lib/agent/jmap/help-content/overview.js +49 -0
- package/esm/lib/agent/jmap/help-content/presets.d.ts +2 -0
- package/esm/lib/agent/jmap/help-content/presets.d.ts.map +1 -0
- package/esm/lib/agent/jmap/help-content/presets.js +51 -0
- package/esm/lib/agent/jmap/help-content/tools.d.ts +2 -0
- package/esm/lib/agent/jmap/help-content/tools.d.ts.map +1 -0
- package/esm/lib/agent/jmap/help-content/tools.js +49 -0
- package/esm/lib/agent/jmap/help-content/troubleshooting.d.ts +2 -0
- package/esm/lib/agent/jmap/help-content/troubleshooting.d.ts.map +1 -0
- package/esm/lib/agent/jmap/help-content/troubleshooting.js +65 -0
- package/esm/lib/agent/session/agent-credentials-store.d.ts +45 -0
- package/esm/lib/agent/session/agent-credentials-store.d.ts.map +1 -0
- package/esm/lib/agent/session/agent-credentials-store.js +121 -0
- package/esm/lib/agent/session/agent-resolve-config.d.ts +29 -0
- package/esm/lib/agent/session/agent-resolve-config.d.ts.map +1 -0
- package/esm/lib/agent/session/agent-resolve-config.js +71 -0
- package/esm/lib/agent/session/agent-session-for-dir.d.ts +8 -0
- package/esm/lib/agent/session/agent-session-for-dir.d.ts.map +1 -0
- package/esm/lib/agent/session/agent-session-for-dir.js +33 -0
- package/esm/lib/agent/session/agent-session.d.ts +89 -0
- package/esm/lib/agent/session/agent-session.d.ts.map +1 -0
- package/esm/lib/agent/session/agent-session.js +320 -0
- package/esm/lib/agent/session/inbox-id-to-mailbox-email.d.ts +6 -0
- package/esm/lib/agent/session/inbox-id-to-mailbox-email.d.ts.map +1 -0
- package/esm/lib/agent/session/inbox-id-to-mailbox-email.js +21 -0
- package/esm/lib/core/consts.d.ts +17 -0
- package/esm/lib/core/consts.d.ts.map +1 -0
- package/esm/lib/core/consts.js +28 -0
- package/esm/lib/core/jmap-hints.d.ts +3 -0
- package/esm/lib/core/jmap-hints.d.ts.map +1 -0
- package/esm/lib/core/jmap-hints.js +6 -0
- package/esm/lib/core/messages.d.ts +6 -0
- package/esm/lib/core/messages.d.ts.map +1 -0
- package/esm/lib/core/messages.js +19 -0
- package/esm/lib/core/read-npm-package-readme.d.ts +6 -0
- package/esm/lib/core/read-npm-package-readme.d.ts.map +1 -0
- package/esm/lib/core/read-npm-package-readme.js +81 -0
- package/esm/lib/core/shared-assets.d.ts +6 -0
- package/esm/lib/core/shared-assets.d.ts.map +1 -0
- package/esm/lib/core/shared-assets.js +46 -0
- package/esm/lib/core/types.d.ts +2 -0
- package/esm/lib/core/types.d.ts.map +1 -0
- package/esm/lib/core/types.js +2 -0
- package/esm/lib/core/utils.d.ts +12 -0
- package/esm/lib/core/utils.d.ts.map +1 -0
- package/esm/lib/core/utils.js +29 -0
- package/esm/lib/integrations/create-agent-session.d.ts +25 -0
- package/esm/lib/integrations/create-agent-session.d.ts.map +1 -0
- package/esm/lib/integrations/create-agent-session.js +36 -0
- package/esm/lib/integrations/key-value-credential-store.d.ts +21 -0
- package/esm/lib/integrations/key-value-credential-store.d.ts.map +1 -0
- package/esm/lib/integrations/key-value-credential-store.js +71 -0
- package/esm/lib/integrations/n8n-credential-store.d.ts +18 -0
- package/esm/lib/integrations/n8n-credential-store.d.ts.map +1 -0
- package/esm/lib/integrations/n8n-credential-store.js +62 -0
- package/esm/lib/mod.d.ts +23 -0
- package/esm/lib/mod.d.ts.map +1 -0
- package/esm/lib/mod.js +22 -0
- package/esm/lib/network/auth-client.d.ts +57 -0
- package/esm/lib/network/auth-client.d.ts.map +1 -0
- package/esm/lib/network/auth-client.js +210 -0
- package/esm/package.json +3 -0
- package/esm/skill/cli.d.ts +3 -0
- package/esm/skill/cli.d.ts.map +1 -0
- package/esm/skill/cli.js +321 -0
- package/package.json +45 -0
- package/presets/list_inbox.json +46 -0
- package/presets/reply.json +97 -0
- package/presets/send_mail.json +70 -0
- package/presets/send_mail_attachment.json +92 -0
- package/presets/send_mail_blob_attachment.json +74 -0
- package/shared/consts.json +11 -0
- package/shared/fixtures/pow_vectors.json +32 -0
- package/shared/help/fragments/inbox_cron_agent_prompt.md +1 -0
- package/shared/help/fragments/post_register_cron_reminder.md +5 -0
- package/shared/help/readme_stub.md +3 -0
- package/shared/help/topics/auth.md +8 -0
- package/shared/help/topics/cron.md +217 -0
- package/shared/help/topics/installation.md +35 -0
- package/shared/help/topics/jmap_cheatsheet.md +19 -0
- package/shared/help/topics/multi_account.md +9 -0
- package/shared/help/topics/overview.md +27 -0
- package/shared/help/topics/presets.md +12 -0
- package/shared/help/topics/tools.md +16 -0
- package/shared/help/topics/troubleshooting.md +6 -0
- package/shared/manifest.json +31 -0
- package/shared/messages/errors.json +68 -0
- package/shared/messages/hints.json +8 -0
- package/shared/presets/list_inbox.json +46 -0
- package/shared/presets/reply.json +97 -0
- package/shared/presets/send_mail.json +70 -0
- package/shared/presets/send_mail_attachment.json +92 -0
- package/shared/presets/send_mail_blob_attachment.json +74 -0
- package/shared/skill/SKILL.template.md +202 -0
- package/shared/skill/manifest.json +89 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { dirname, resolve as resolvePath } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
const moduleDir = dirname(fileURLToPath(globalThis[Symbol.for("import-meta-ponyfill-esmodule")](import.meta).url));
|
|
5
|
+
function resolveSharedRoot() {
|
|
6
|
+
let current = moduleDir;
|
|
7
|
+
for (let depth = 0; depth < 12; depth++) {
|
|
8
|
+
const candidate = resolvePath(current, "shared");
|
|
9
|
+
if (existsSync(candidate))
|
|
10
|
+
return candidate;
|
|
11
|
+
const parent = resolvePath(current, "..");
|
|
12
|
+
if (parent === current)
|
|
13
|
+
break;
|
|
14
|
+
current = parent;
|
|
15
|
+
}
|
|
16
|
+
throw new Error(`Shared asset directory was not found from module path: ${moduleDir}`);
|
|
17
|
+
}
|
|
18
|
+
let cachedSharedRoot;
|
|
19
|
+
export function getSharedRootPath() {
|
|
20
|
+
if (!cachedSharedRoot)
|
|
21
|
+
cachedSharedRoot = resolveSharedRoot();
|
|
22
|
+
return cachedSharedRoot;
|
|
23
|
+
}
|
|
24
|
+
export function readSharedText(relativePath) {
|
|
25
|
+
const fullPath = resolvePath(getSharedRootPath(), relativePath);
|
|
26
|
+
return readFileSync(fullPath, "utf-8");
|
|
27
|
+
}
|
|
28
|
+
export function readSharedJson(relativePath) {
|
|
29
|
+
return JSON.parse(readSharedText(relativePath));
|
|
30
|
+
}
|
|
31
|
+
export function tryReadSharedText(relativePath) {
|
|
32
|
+
try {
|
|
33
|
+
return readSharedText(relativePath);
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export function tryReadSharedJson(relativePath) {
|
|
40
|
+
try {
|
|
41
|
+
return readSharedJson(relativePath);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/lib/core/types.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
/** Optional hook before the next retry; must not throw. */
|
|
8
|
+
onBeforeRetry?: (e: unknown) => MaybePromise<void>;
|
|
9
|
+
};
|
|
10
|
+
/** Retries `fn` on throw with exponential backoff until `maxTimeoutMs` is exceeded. */
|
|
11
|
+
export declare function retry<R>(fn: () => MaybePromise<R>, config: RetryCfg): Promise<R>;
|
|
12
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/lib/core/utils.ts"],"names":[],"mappings":"AAGA,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;IACpB,2DAA2D;IAC3D,aAAa,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,YAAY,CAAC,IAAI,CAAC,CAAC;CACpD,CAAC;AAQF,uFAAuF;AACvF,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,29 @@
|
|
|
1
|
+
// Small async helpers (delay, exponential backoff retry).
|
|
2
|
+
import { ONE_SEC_MS } from "./consts.js";
|
|
3
|
+
export function delay(ms) {
|
|
4
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
5
|
+
}
|
|
6
|
+
const defaultCfg = {
|
|
7
|
+
maxTimeoutMs: ONE_SEC_MS * 32,
|
|
8
|
+
startTimeoutMs: ONE_SEC_MS,
|
|
9
|
+
backoffMul: 2,
|
|
10
|
+
};
|
|
11
|
+
/** Retries `fn` on throw with exponential backoff until `maxTimeoutMs` is exceeded. */
|
|
12
|
+
export async function retry(fn, config) {
|
|
13
|
+
const cfg = { ...defaultCfg, ...config };
|
|
14
|
+
let curTimeoutMs = cfg.startTimeoutMs;
|
|
15
|
+
while (true) {
|
|
16
|
+
try {
|
|
17
|
+
const res = await fn();
|
|
18
|
+
return res;
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
if (cfg.onBeforeRetry)
|
|
22
|
+
await cfg.onBeforeRetry(e);
|
|
23
|
+
if (curTimeoutMs > cfg.maxTimeoutMs)
|
|
24
|
+
throw e;
|
|
25
|
+
await delay(curTimeoutMs);
|
|
26
|
+
curTimeoutMs = Math.floor(curTimeoutMs * cfg.backoffMul);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { AgentSession } from "../agent/session/agent-session.js";
|
|
2
|
+
import type { CredentialStore } from "../agent/session/agent-credentials-store.js";
|
|
3
|
+
import { type KeyValueStore } from "./key-value-credential-store.js";
|
|
4
|
+
export interface IntegrationEnv {
|
|
5
|
+
authUrl?: string;
|
|
6
|
+
apiUrl?: string;
|
|
7
|
+
scryptSalt?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface CreateAgentSessionInput {
|
|
10
|
+
store: CredentialStore;
|
|
11
|
+
env?: IntegrationEnv;
|
|
12
|
+
apiKey?: string;
|
|
13
|
+
/** Virtual credential namespace label (for logging / parity). */
|
|
14
|
+
credentialDir?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface CreateAgentSessionFromKeyValueInput {
|
|
17
|
+
storage: KeyValueStore;
|
|
18
|
+
accountId?: string;
|
|
19
|
+
env?: IntegrationEnv;
|
|
20
|
+
apiKey?: string;
|
|
21
|
+
credentialDir?: string;
|
|
22
|
+
}
|
|
23
|
+
export declare function createAgentSession(input: CreateAgentSessionInput): Promise<AgentSession>;
|
|
24
|
+
export declare function createAgentSessionFromKeyValue(input: CreateAgentSessionFromKeyValueInput): Promise<AgentSession>;
|
|
25
|
+
//# sourceMappingURL=create-agent-session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-agent-session.d.ts","sourceRoot":"","sources":["../../../src/lib/integrations/create-agent-session.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AACjE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6CAA6C,CAAC;AACnF,OAAO,EAEL,KAAK,aAAa,EACnB,MAAM,iCAAiC,CAAC;AAEzC,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,uBAAuB;IACtC,KAAK,EAAE,eAAe,CAAC;IACvB,GAAG,CAAC,EAAE,cAAc,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iEAAiE;IACjE,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,mCAAmC;IAClD,OAAO,EAAE,aAAa,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,cAAc,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAcD,wBAAsB,kBAAkB,CACtC,KAAK,EAAE,uBAAuB,GAC7B,OAAO,CAAC,YAAY,CAAC,CAcvB;AAED,wBAAsB,8BAA8B,CAClD,KAAK,EAAE,mCAAmC,GACzC,OAAO,CAAC,YAAY,CAAC,CAUvB"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Create AgentSession for integration hosts (Activepieces, Dify-style runtimes).
|
|
2
|
+
import { DEFAULT_API_URL, DEFAULT_AUTH_URL, DEFAULT_POW_SCRYPT_SALT_HEX, } from "../core/consts.js";
|
|
3
|
+
import { AgentSession } from "../agent/session/agent-session.js";
|
|
4
|
+
import { KeyValueCredentialStore, } from "./key-value-credential-store.js";
|
|
5
|
+
function resolveIntegrationEnv(env) {
|
|
6
|
+
return {
|
|
7
|
+
authUrl: (env?.authUrl ?? DEFAULT_AUTH_URL).replace(/\/+$/, ""),
|
|
8
|
+
apiUrl: (env?.apiUrl ?? DEFAULT_API_URL).replace(/\/+$/, ""),
|
|
9
|
+
scryptSalt: env?.scryptSalt ?? DEFAULT_POW_SCRYPT_SALT_HEX,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export async function createAgentSession(input) {
|
|
13
|
+
const resolved = resolveIntegrationEnv(input.env);
|
|
14
|
+
const loaded = await input.store.load();
|
|
15
|
+
const creds = loaded.credentials;
|
|
16
|
+
return AgentSession.create({
|
|
17
|
+
authUrl: creds?.authUrl ?? resolved.authUrl,
|
|
18
|
+
apiUrl: creds?.apiUrl ?? resolved.apiUrl,
|
|
19
|
+
scryptSalt: creds?.scryptSalt ?? resolved.scryptSalt,
|
|
20
|
+
apiKey: input.apiKey ?? creds?.apiKey,
|
|
21
|
+
inboxId: creds?.inboxId,
|
|
22
|
+
credentialDir: input.credentialDir ?? "integration://default",
|
|
23
|
+
store: input.store,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
export async function createAgentSessionFromKeyValue(input) {
|
|
27
|
+
const accountId = input.accountId ?? "default";
|
|
28
|
+
const store = new KeyValueCredentialStore(input.storage, accountId);
|
|
29
|
+
return createAgentSession({
|
|
30
|
+
store,
|
|
31
|
+
env: input.env,
|
|
32
|
+
apiKey: input.apiKey,
|
|
33
|
+
credentialDir: input.credentialDir ??
|
|
34
|
+
`integration://account/${accountId}`,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type CredentialArtifacts, type CredentialStore } from "../agent/session/agent-credentials-store.js";
|
|
2
|
+
export interface KeyValueStore {
|
|
3
|
+
get(key: string): Promise<string | undefined>;
|
|
4
|
+
set(key: string, value: string): Promise<void>;
|
|
5
|
+
delete(key: string): Promise<void>;
|
|
6
|
+
has?(key: string): Promise<boolean>;
|
|
7
|
+
}
|
|
8
|
+
export declare class KeyValueCredentialStore implements CredentialStore {
|
|
9
|
+
private readonly storage;
|
|
10
|
+
private readonly accountId;
|
|
11
|
+
constructor(storage: KeyValueStore, accountId?: string);
|
|
12
|
+
private key;
|
|
13
|
+
private get credentialsKey();
|
|
14
|
+
private get sessionKey();
|
|
15
|
+
private get capabilityKey();
|
|
16
|
+
private exists;
|
|
17
|
+
load(): Promise<CredentialArtifacts>;
|
|
18
|
+
save(artifacts: CredentialArtifacts): Promise<void>;
|
|
19
|
+
clear(): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=key-value-credential-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"key-value-credential-store.d.ts","sourceRoot":"","sources":["../../../src/lib/integrations/key-value-credential-store.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,eAAe,EAIrB,MAAM,6CAA6C,CAAC;AAErD,MAAM,WAAW,aAAa;IAC5B,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IAC9C,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/C,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC,GAAG,CAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACrC;AAED,qBAAa,uBAAwB,YAAW,eAAe;IAE3D,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,SAAS;gBADT,OAAO,EAAE,aAAa,EACtB,SAAS,SAAY;IAGxC,OAAO,CAAC,GAAG;IAIX,OAAO,KAAK,cAAc,GAEzB;IAED,OAAO,KAAK,UAAU,GAErB;IAED,OAAO,KAAK,aAAa,GAExB;YAEa,MAAM;IAQd,IAAI,IAAI,OAAO,CAAC,mBAAmB,CAAC;IAwBpC,IAAI,CAAC,SAAS,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAenD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAW7B"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// Credential persistence backed by a host-provided key-value store (Dify, Activepieces, …).
|
|
2
|
+
import { parseCredentialsJson, serializeCredentials, } from "../agent/session/agent-credentials-store.js";
|
|
3
|
+
export class KeyValueCredentialStore {
|
|
4
|
+
storage;
|
|
5
|
+
accountId;
|
|
6
|
+
constructor(storage, accountId = "default") {
|
|
7
|
+
this.storage = storage;
|
|
8
|
+
this.accountId = accountId;
|
|
9
|
+
}
|
|
10
|
+
key(suffix) {
|
|
11
|
+
return `account:${this.accountId}:${suffix}`;
|
|
12
|
+
}
|
|
13
|
+
get credentialsKey() {
|
|
14
|
+
return this.key("credentials.json");
|
|
15
|
+
}
|
|
16
|
+
get sessionKey() {
|
|
17
|
+
return this.key("session.jwt");
|
|
18
|
+
}
|
|
19
|
+
get capabilityKey() {
|
|
20
|
+
return this.key("capability.jwt");
|
|
21
|
+
}
|
|
22
|
+
async exists(key) {
|
|
23
|
+
if (this.storage.has) {
|
|
24
|
+
return this.storage.has(key);
|
|
25
|
+
}
|
|
26
|
+
const value = await this.storage.get(key);
|
|
27
|
+
return value !== undefined;
|
|
28
|
+
}
|
|
29
|
+
async load() {
|
|
30
|
+
let credentials;
|
|
31
|
+
const rawCredentials = await this.storage.get(this.credentialsKey);
|
|
32
|
+
if (rawCredentials) {
|
|
33
|
+
try {
|
|
34
|
+
credentials = parseCredentialsJson(rawCredentials, this.credentialsKey);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
credentials = undefined;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const sessionJwt = await this.storage.get(this.sessionKey);
|
|
41
|
+
const capabilityJwt = await this.storage.get(this.capabilityKey);
|
|
42
|
+
return {
|
|
43
|
+
credentials,
|
|
44
|
+
sessionJwt,
|
|
45
|
+
capabilityJwt,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
async save(artifacts) {
|
|
49
|
+
if (artifacts.credentials !== undefined) {
|
|
50
|
+
await this.storage.set(this.credentialsKey, serializeCredentials(artifacts.credentials));
|
|
51
|
+
}
|
|
52
|
+
if (artifacts.sessionJwt !== undefined) {
|
|
53
|
+
await this.storage.set(this.sessionKey, artifacts.sessionJwt);
|
|
54
|
+
}
|
|
55
|
+
if (artifacts.capabilityJwt !== undefined) {
|
|
56
|
+
await this.storage.set(this.capabilityKey, artifacts.capabilityJwt);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async clear() {
|
|
60
|
+
for (const key of [this.credentialsKey, this.sessionKey, this.capabilityKey]) {
|
|
61
|
+
try {
|
|
62
|
+
if (await this.exists(key)) {
|
|
63
|
+
await this.storage.delete(key);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
// non-fatal
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { CredentialStore } from "../agent/session/agent-credentials-store.js";
|
|
2
|
+
/** Host-provided backend (n8n static data object, custom adapter, …). */
|
|
3
|
+
export interface N8nKeyValueBackend {
|
|
4
|
+
get(key: string): Promise<string | undefined> | string | undefined;
|
|
5
|
+
set(key: string, value: string): Promise<void> | void;
|
|
6
|
+
delete(key: string): Promise<void> | void;
|
|
7
|
+
has?(key: string): Promise<boolean> | boolean;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Wrap n8n host storage as a CredentialStore.
|
|
11
|
+
* Keys: `atomicmail:{accountId}:account:{accountId}:credentials.json`, etc.
|
|
12
|
+
*/
|
|
13
|
+
export declare function createN8nCredentialStore(backend: N8nKeyValueBackend, accountId?: string): CredentialStore;
|
|
14
|
+
/** Alias for integration hosts that expect a generic factory name. */
|
|
15
|
+
export declare const createKeyValueStore: typeof createN8nCredentialStore;
|
|
16
|
+
/** Adapter for n8n `getWorkflowStaticData()`-style object storage. */
|
|
17
|
+
export declare function n8nStaticDataBackend(data: Record<string, unknown>): N8nKeyValueBackend;
|
|
18
|
+
//# sourceMappingURL=n8n-credential-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"n8n-credential-store.d.ts","sourceRoot":"","sources":["../../../src/lib/integrations/n8n-credential-store.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6CAA6C,CAAC;AAMnF,yEAAyE;AACzE,MAAM,WAAW,kBAAkB;IACjC,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,GAAG,MAAM,GAAG,SAAS,CAAC;IACnE,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IACtD,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAC1C,GAAG,CAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;CAC/C;AA0CD;;;GAGG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,kBAAkB,EAC3B,SAAS,SAAY,GACpB,eAAe,CAKjB;AAED,sEAAsE;AACtE,eAAO,MAAM,mBAAmB,iCAA2B,CAAC;AAE5D,sEAAsE;AACtE,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,kBAAkB,CAgBpB"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// n8n credential persistence via host key-value / static-data storage.
|
|
2
|
+
import { KeyValueCredentialStore, } from "./key-value-credential-store.js";
|
|
3
|
+
const KEY_PREFIX = "atomicmail";
|
|
4
|
+
function scopedKey(accountId, suffix) {
|
|
5
|
+
return `${KEY_PREFIX}:${accountId}:${suffix}`;
|
|
6
|
+
}
|
|
7
|
+
function normalizeBackend(backend) {
|
|
8
|
+
return {
|
|
9
|
+
async get(key) {
|
|
10
|
+
const value = await backend.get(key);
|
|
11
|
+
return value === undefined || value === null ? undefined : String(value);
|
|
12
|
+
},
|
|
13
|
+
async set(key, value) {
|
|
14
|
+
await backend.set(key, value);
|
|
15
|
+
},
|
|
16
|
+
async delete(key) {
|
|
17
|
+
await backend.delete(key);
|
|
18
|
+
},
|
|
19
|
+
...(backend.has && {
|
|
20
|
+
async has(key) {
|
|
21
|
+
return Boolean(await backend.has(key));
|
|
22
|
+
},
|
|
23
|
+
}),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function prefixingStore(backend, accountId) {
|
|
27
|
+
return {
|
|
28
|
+
get: (key) => backend.get(scopedKey(accountId, key)),
|
|
29
|
+
set: (key, value) => backend.set(scopedKey(accountId, key), value),
|
|
30
|
+
delete: (key) => backend.delete(scopedKey(accountId, key)),
|
|
31
|
+
...(backend.has && {
|
|
32
|
+
has: (key) => backend.has(scopedKey(accountId, key)),
|
|
33
|
+
}),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Wrap n8n host storage as a CredentialStore.
|
|
38
|
+
* Keys: `atomicmail:{accountId}:account:{accountId}:credentials.json`, etc.
|
|
39
|
+
*/
|
|
40
|
+
export function createN8nCredentialStore(backend, accountId = "default") {
|
|
41
|
+
return new KeyValueCredentialStore(prefixingStore(normalizeBackend(backend), accountId), accountId);
|
|
42
|
+
}
|
|
43
|
+
/** Alias for integration hosts that expect a generic factory name. */
|
|
44
|
+
export const createKeyValueStore = createN8nCredentialStore;
|
|
45
|
+
/** Adapter for n8n `getWorkflowStaticData()`-style object storage. */
|
|
46
|
+
export function n8nStaticDataBackend(data) {
|
|
47
|
+
return {
|
|
48
|
+
get(key) {
|
|
49
|
+
const value = data[key];
|
|
50
|
+
return typeof value === "string" ? value : undefined;
|
|
51
|
+
},
|
|
52
|
+
set(key, value) {
|
|
53
|
+
data[key] = value;
|
|
54
|
+
},
|
|
55
|
+
delete(key) {
|
|
56
|
+
delete data[key];
|
|
57
|
+
},
|
|
58
|
+
has(key) {
|
|
59
|
+
return Object.prototype.hasOwnProperty.call(data, key);
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
package/esm/lib/mod.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export * from "./network/auth-client.js";
|
|
2
|
+
export * from "./core/utils.js";
|
|
3
|
+
export * from "./core/read-npm-package-readme.js";
|
|
4
|
+
export * from "./core/consts.js";
|
|
5
|
+
export * from "./core/messages.js";
|
|
6
|
+
export * from "./core/shared-assets.js";
|
|
7
|
+
export * from "./core/types.js";
|
|
8
|
+
export * from "./agent/session/agent-credentials-store.js";
|
|
9
|
+
export * from "./agent/session/inbox-id-to-mailbox-email.js";
|
|
10
|
+
export * from "./agent/auth/agent-jwt.js";
|
|
11
|
+
export * from "./agent/auth/agent-pow.js";
|
|
12
|
+
export * from "./agent/auth/agent-auth-http.js";
|
|
13
|
+
export * from "./agent/jmap/agent-jmap.js";
|
|
14
|
+
export * from "./agent/jmap/agent-jmap-verify.js";
|
|
15
|
+
export * from "./agent/session/agent-session.js";
|
|
16
|
+
export * from "./agent/session/agent-resolve-config.js";
|
|
17
|
+
export * from "./agent/session/agent-session-for-dir.js";
|
|
18
|
+
export * from "./agent/jmap/agent-help-content.js";
|
|
19
|
+
export * from "./agent/jmap/agent-vars.js";
|
|
20
|
+
export * from "./integrations/key-value-credential-store.js";
|
|
21
|
+
export * from "./integrations/create-agent-session.js";
|
|
22
|
+
export * from "./integrations/n8n-credential-store.js";
|
|
23
|
+
//# 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,mCAAmC,CAAC;AAClD,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,iBAAiB,CAAC;AAEhC,cAAc,4CAA4C,CAAC;AAC3D,cAAc,8CAA8C,CAAC;AAC7D,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iCAAiC,CAAC;AAChD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mCAAmC,CAAC;AAClD,cAAc,kCAAkC,CAAC;AACjD,cAAc,yCAAyC,CAAC;AACxD,cAAc,0CAA0C,CAAC;AACzD,cAAc,oCAAoC,CAAC;AACnD,cAAc,4BAA4B,CAAC;AAE3C,cAAc,8CAA8C,CAAC;AAC7D,cAAc,wCAAwC,CAAC;AACvD,cAAc,wCAAwC,CAAC"}
|
package/esm/lib/mod.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export * from "./network/auth-client.js";
|
|
2
|
+
export * from "./core/utils.js";
|
|
3
|
+
export * from "./core/read-npm-package-readme.js";
|
|
4
|
+
export * from "./core/consts.js";
|
|
5
|
+
export * from "./core/messages.js";
|
|
6
|
+
export * from "./core/shared-assets.js";
|
|
7
|
+
export * from "./core/types.js";
|
|
8
|
+
export * from "./agent/session/agent-credentials-store.js";
|
|
9
|
+
export * from "./agent/session/inbox-id-to-mailbox-email.js";
|
|
10
|
+
export * from "./agent/auth/agent-jwt.js";
|
|
11
|
+
export * from "./agent/auth/agent-pow.js";
|
|
12
|
+
export * from "./agent/auth/agent-auth-http.js";
|
|
13
|
+
export * from "./agent/jmap/agent-jmap.js";
|
|
14
|
+
export * from "./agent/jmap/agent-jmap-verify.js";
|
|
15
|
+
export * from "./agent/session/agent-session.js";
|
|
16
|
+
export * from "./agent/session/agent-resolve-config.js";
|
|
17
|
+
export * from "./agent/session/agent-session-for-dir.js";
|
|
18
|
+
export * from "./agent/jmap/agent-help-content.js";
|
|
19
|
+
export * from "./agent/jmap/agent-vars.js";
|
|
20
|
+
export * from "./integrations/key-value-credential-store.js";
|
|
21
|
+
export * from "./integrations/create-agent-session.js";
|
|
22
|
+
export * from "./integrations/n8n-credential-store.js";
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export interface AuthClientOptions {
|
|
2
|
+
/** Base URL of auth-service, e.g. "http://localhost:8000". Trailing slashes are stripped. */
|
|
3
|
+
baseUrl: string;
|
|
4
|
+
/**
|
|
5
|
+
* PoW scrypt salt (hex string). When omitted, {@link DEFAULT_POW_SCRYPT_SALT_HEX}
|
|
6
|
+
* is used so clients match the bundled auth-service.
|
|
7
|
+
*/
|
|
8
|
+
scryptSaltHex?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface SignupResult {
|
|
11
|
+
/** Freshly minted API key. The server only returns it once — persist it. */
|
|
12
|
+
apiKey: string;
|
|
13
|
+
sessionJWT: string;
|
|
14
|
+
}
|
|
15
|
+
export interface LoginResult {
|
|
16
|
+
sessionJWT: string;
|
|
17
|
+
}
|
|
18
|
+
export interface RenewResult {
|
|
19
|
+
capabilityJWT: string;
|
|
20
|
+
}
|
|
21
|
+
/** Thrown for any non-2xx HTTP response or malformed payload. */
|
|
22
|
+
export declare class AuthClientError extends Error {
|
|
23
|
+
status: number;
|
|
24
|
+
bodyText: string;
|
|
25
|
+
constructor(status: number, bodyText: string, message: string);
|
|
26
|
+
}
|
|
27
|
+
export declare class AuthClient {
|
|
28
|
+
private readonly baseUrl;
|
|
29
|
+
private readonly scryptSaltHex;
|
|
30
|
+
constructor(options: AuthClientOptions);
|
|
31
|
+
/**
|
|
32
|
+
* Register a new inbox under `username`. Returns the freshly minted API key
|
|
33
|
+
* (the server only ever returns it once — the caller MUST persist it) and
|
|
34
|
+
* a session JWT.
|
|
35
|
+
*/
|
|
36
|
+
signup(username: string): Promise<SignupResult>;
|
|
37
|
+
/** Exchange an existing API key for a fresh session JWT. */
|
|
38
|
+
login(apiKey: string): Promise<LoginResult>;
|
|
39
|
+
/**
|
|
40
|
+
* Exchange a session JWT for a short-lived capability JWT (audience:
|
|
41
|
+
* api-service).
|
|
42
|
+
*/
|
|
43
|
+
renew(sessionJWT: string): Promise<RenewResult>;
|
|
44
|
+
private fetchChallenge;
|
|
45
|
+
private postSession;
|
|
46
|
+
private parseJsonOrThrow;
|
|
47
|
+
/**
|
|
48
|
+
* Brute-force a PoW nonce. Mirrors `generatePow` in
|
|
49
|
+
* services/auth-service/src/crypto.ts: scrypt(`${challenge}:${nonce}`, salt,
|
|
50
|
+
* 64) until `difficulty` leading bits of the digest are zero.
|
|
51
|
+
*
|
|
52
|
+
* Expected work at the server's POW_DIFFICULTY=6 is ~2^6 = 64 attempts; well
|
|
53
|
+
* within the challenge JWT's 3-minute TTL.
|
|
54
|
+
*/
|
|
55
|
+
private solvePoW;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=auth-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-client.d.ts","sourceRoot":"","sources":["../../../src/lib/network/auth-client.ts"],"names":[],"mappings":"AAmBA,MAAM,WAAW,iBAAiB;IAChC,6FAA6F;IAC7F,OAAO,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,YAAY;IAC3B,4EAA4E;IAC5E,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,WAAW;IAC1B,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,WAAW;IAC1B,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,iEAAiE;AACjE,qBAAa,eAAgB,SAAQ,KAAK;IACxC,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;gBAEL,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAM9D;AAOD,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;gBAE3B,OAAO,EAAE,iBAAiB;IAKtC;;;;OAIG;IACG,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAyBrD,4DAA4D;IACtD,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAgBjD;;;OAGG;IACG,KAAK,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;YAoBvC,cAAc;YAsCd,WAAW;YAyCX,gBAAgB;IAuB9B;;;;;;;OAOG;YACW,QAAQ;CAgBvB"}
|