@rubics-code/agent-kit 0.0.0-stage → 0.2.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.
Files changed (97) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +88 -2
  3. package/dist/approval.d.ts +20 -0
  4. package/dist/approval.js +32 -0
  5. package/dist/assemble.d.ts +24 -0
  6. package/dist/assemble.js +19 -0
  7. package/dist/briefing.d.ts +12 -0
  8. package/dist/briefing.js +22 -0
  9. package/dist/capabilities.d.ts +2 -0
  10. package/dist/capabilities.js +6 -0
  11. package/dist/cli/bin.d.ts +2 -0
  12. package/dist/cli/bin.js +39 -0
  13. package/dist/cli/init.d.ts +9 -0
  14. package/dist/cli/init.js +73 -0
  15. package/dist/credentials.d.ts +28 -0
  16. package/dist/credentials.js +134 -0
  17. package/dist/errors.d.ts +2 -0
  18. package/dist/errors.js +4 -0
  19. package/dist/group.d.ts +68 -0
  20. package/dist/group.js +89 -0
  21. package/dist/groups/cloudflare/client.d.ts +42 -0
  22. package/dist/groups/cloudflare/client.js +76 -0
  23. package/dist/groups/cloudflare/guidance.md +7 -0
  24. package/dist/groups/cloudflare/memory.d.ts +19 -0
  25. package/dist/groups/cloudflare/memory.js +43 -0
  26. package/dist/groups/cloudflare/tools.d.ts +3 -0
  27. package/dist/groups/cloudflare/tools.js +140 -0
  28. package/dist/groups/infisical/client.d.ts +30 -0
  29. package/dist/groups/infisical/client.js +133 -0
  30. package/dist/groups/infisical/guidance.md +8 -0
  31. package/dist/groups/infisical/memory.d.ts +18 -0
  32. package/dist/groups/infisical/memory.js +43 -0
  33. package/dist/groups/infisical/tools.d.ts +3 -0
  34. package/dist/groups/infisical/tools.js +88 -0
  35. package/dist/groups/mxroute/client.d.ts +90 -0
  36. package/dist/groups/mxroute/client.js +86 -0
  37. package/dist/groups/mxroute/guidance.md +13 -0
  38. package/dist/groups/mxroute/memory.d.ts +34 -0
  39. package/dist/groups/mxroute/memory.js +83 -0
  40. package/dist/groups/mxroute/tools.d.ts +3 -0
  41. package/dist/groups/mxroute/tools.js +158 -0
  42. package/dist/groups/openrouter/client.d.ts +66 -0
  43. package/dist/groups/openrouter/client.js +66 -0
  44. package/dist/groups/openrouter/guidance.md +7 -0
  45. package/dist/groups/openrouter/memory.d.ts +26 -0
  46. package/dist/groups/openrouter/memory.js +59 -0
  47. package/dist/groups/openrouter/tools.d.ts +3 -0
  48. package/dist/groups/openrouter/tools.js +130 -0
  49. package/dist/groups/registrar/client.d.ts +48 -0
  50. package/dist/groups/registrar/client.js +75 -0
  51. package/dist/groups/registrar/guidance.md +9 -0
  52. package/dist/groups/registrar/memory.d.ts +16 -0
  53. package/dist/groups/registrar/memory.js +27 -0
  54. package/dist/groups/registrar/tools.d.ts +4 -0
  55. package/dist/groups/registrar/tools.js +102 -0
  56. package/dist/index.d.ts +35 -0
  57. package/dist/index.js +35 -0
  58. package/dist/policy.d.ts +12 -0
  59. package/dist/policy.js +1 -0
  60. package/dist/result.d.ts +2 -0
  61. package/dist/result.js +17 -0
  62. package/dist/runtime/agent.d.ts +28 -0
  63. package/dist/runtime/agent.js +28 -0
  64. package/dist/runtime/container.d.ts +8 -0
  65. package/dist/runtime/container.js +41 -0
  66. package/dist/runtime/run.d.ts +51 -0
  67. package/dist/runtime/run.js +152 -0
  68. package/dist/runtime/transcribe.d.ts +7 -0
  69. package/dist/runtime/transcribe.js +37 -0
  70. package/dist/runtime/turns.d.ts +13 -0
  71. package/dist/runtime/turns.js +23 -0
  72. package/dist/runtime/web/index.html +452 -0
  73. package/dist/runtime/web/server.d.ts +20 -0
  74. package/dist/runtime/web/server.js +150 -0
  75. package/dist/schemas.d.ts +2 -0
  76. package/dist/schemas.js +6 -0
  77. package/dist/secret-delivery.d.ts +18 -0
  78. package/dist/secret-delivery.js +45 -0
  79. package/dist/secret-store.d.ts +13 -0
  80. package/dist/secret-store.js +1 -0
  81. package/dist/secrets.d.ts +5 -0
  82. package/dist/secrets.js +13 -0
  83. package/package.json +61 -4
  84. package/template/Dockerfile +19 -0
  85. package/template/README.md +55 -0
  86. package/template/_dockerignore +7 -0
  87. package/template/_gitignore +4 -0
  88. package/template/entrypoint.sh +14 -0
  89. package/template/evals/notes.eval.ts +55 -0
  90. package/template/home/memory/README.md +1 -0
  91. package/template/home/prompts/system.md +15 -0
  92. package/template/src/agent.ts +47 -0
  93. package/template/src/groups/notes.ts +85 -0
  94. package/template/src/main.ts +4 -0
  95. package/template/test/agent.test.ts +22 -0
  96. package/template/tsconfig.json +17 -0
  97. package/template/vitest.config.ts +7 -0
@@ -0,0 +1,88 @@
1
+ // The Infisical secret tool group. Its paths come from the agent's policy:
2
+ // the readable and writable roots are policy data, and the identity's Infisical
3
+ // role is the second limit behind them.
4
+ import { readFileSync } from "node:fs";
5
+ import { randomBytes } from "node:crypto";
6
+ import { tool } from "langchain";
7
+ import { z } from "zod";
8
+ import { approvedTool } from "../../group.js";
9
+ import { describePlace, placeText } from "../../secret-delivery.js";
10
+ import { result } from "../../result.js";
11
+ const guidance = readFileSync(new URL("./guidance.md", import.meta.url), "utf8");
12
+ export const infisicalGroup = {
13
+ id: "infisical",
14
+ name: "Infisical",
15
+ // The real host is the agent's Infisical deployment; the agent overrides it
16
+ // at assembly time (review below reads env.host).
17
+ host: "infisical",
18
+ keys: [],
19
+ setup: "Put the agent's Infisical identity in its .env file and start it with the identity script.",
20
+ guidance,
21
+ review(env) {
22
+ if (env.vaultHosts) {
23
+ const on = !!env.host && env.vaultHosts.has(env.host);
24
+ return { enabled: on, missing: on || !env.host ? [] : [env.host] };
25
+ }
26
+ // Identity mode: the store exists, so the tools are on. Without it, the
27
+ // identity's own keys are what is missing.
28
+ return {
29
+ enabled: env.hasStore,
30
+ missing: env.hasStore ? [] : ["INFISICAL_CLIENT_ID", "INFISICAL_CLIENT_SECRET"],
31
+ };
32
+ },
33
+ // The store is the service. The agent makes it from its own Infisical config.
34
+ connect(ctx) {
35
+ return ctx.store;
36
+ },
37
+ tools(store, shared) {
38
+ const { policy } = shared;
39
+ const { operator } = policy;
40
+ const { readablePath, writablePath } = policy.infisical;
41
+ const listFolders = tool(({ path }) => result(() => store.listFolders(path)), {
42
+ name: "infisical_list_folders",
43
+ description: "List the folders in an Infisical folder, for example /agents to see the agents.",
44
+ schema: z.object({ path: readablePath }),
45
+ });
46
+ const listNames = tool(({ path }) => result(() => store.listSecretNames(path)), {
47
+ name: "infisical_list_secret_names",
48
+ description: "List the secret names in an Infisical folder. You never see a value.",
49
+ schema: z.object({ path: readablePath }),
50
+ });
51
+ const createRandom = approvedTool({
52
+ name: "infisical_create_random_secret",
53
+ operator,
54
+ description: `Make a new random secret, for example an API_SERVER_KEY, and store it in Infisical. It does not replace a secret that exists. ${operator} must approve this action.`,
55
+ schema: z.object({
56
+ path: writablePath,
57
+ name: z
58
+ .string()
59
+ .regex(/^[A-Z][A-Z0-9_]{0,127}$/, "upper case with underscores, for example API_SERVER_KEY")
60
+ .describe("Secret name, upper case with underscores, for example API_SERVER_KEY"),
61
+ bytes: z.number().int().min(16).max(64).optional().describe("Random bytes. Default 32."),
62
+ format: z.enum(["hex", "base64url"]).optional().describe("Default hex."),
63
+ }),
64
+ prepare: async (args) => {
65
+ const place = { path: args.path, name: args.name };
66
+ const { exists } = await store.check(place);
67
+ if (exists) {
68
+ return {
69
+ summary: "",
70
+ early: `Not done: ${placeText(policy, place)} already exists. You cannot replace a value with a random one. Tell ${operator}.`,
71
+ };
72
+ }
73
+ const bytes = args.bytes ?? 32;
74
+ const format = args.format ?? "hex";
75
+ return {
76
+ summary: `Make a random secret (${bytes} bytes, ${format}) and store it in ${await describePlace(policy, store, place)}`,
77
+ args: { ...args, bytes, format },
78
+ data: { bytes, format },
79
+ };
80
+ },
81
+ run: async (args, data) => {
82
+ await store.put({ path: args.path, name: args.name }, randomBytes(data.bytes).toString(data.format));
83
+ return `Stored a new random secret in ${placeText(policy, { path: args.path, name: args.name })}. You do not have it.`;
84
+ },
85
+ });
86
+ return [listFolders, listNames, createRandom];
87
+ },
88
+ };
@@ -0,0 +1,90 @@
1
+ import { ServiceError } from "../../errors.js";
2
+ export interface EmailAccount {
3
+ username: string;
4
+ email: string;
5
+ quota: number;
6
+ usage: number;
7
+ limit: number;
8
+ sent: number;
9
+ suspended: boolean;
10
+ }
11
+ export interface Forwarder {
12
+ alias: string;
13
+ email: string;
14
+ destinations: string[];
15
+ }
16
+ export interface MxrouteDnsRecord {
17
+ type: string;
18
+ name: string;
19
+ value: string;
20
+ }
21
+ export interface DnsInfo {
22
+ mx_records: {
23
+ priority: number;
24
+ hostname: string;
25
+ description?: string;
26
+ }[];
27
+ spf: MxrouteDnsRecord;
28
+ dkim: MxrouteDnsRecord | null;
29
+ verification: (MxrouteDnsRecord & {
30
+ description?: string;
31
+ }) | null;
32
+ }
33
+ export interface VerificationKey {
34
+ key: string;
35
+ record: MxrouteDnsRecord;
36
+ }
37
+ export interface Mxroute {
38
+ listDomains(): Promise<string[]>;
39
+ getDnsInfo(domain: string): Promise<DnsInfo>;
40
+ getVerificationKey(): Promise<VerificationKey>;
41
+ listEmailAccounts(domain: string): Promise<EmailAccount[]>;
42
+ listForwarders(domain: string): Promise<Forwarder[]>;
43
+ addDomain(domain: string): Promise<void>;
44
+ createEmailAccount(domain: string, input: {
45
+ username: string;
46
+ password: string;
47
+ quota: number;
48
+ limit: number;
49
+ }): Promise<void>;
50
+ setEmailPassword(domain: string, username: string, password: string): Promise<void>;
51
+ createForwarder(domain: string, input: {
52
+ alias: string;
53
+ destinations: string[];
54
+ }): Promise<void>;
55
+ }
56
+ export declare class MxrouteError extends ServiceError {
57
+ readonly code: string;
58
+ readonly status: number;
59
+ readonly field: string | undefined;
60
+ constructor(status: number, code: string, message: string, field?: string);
61
+ }
62
+ export interface MxrouteCredentials {
63
+ server: string;
64
+ username: string;
65
+ apiKey: string;
66
+ }
67
+ export declare class HttpMxroute implements Mxroute {
68
+ #private;
69
+ constructor(creds: MxrouteCredentials, opts?: {
70
+ baseUrl?: string;
71
+ fetch?: typeof fetch;
72
+ });
73
+ listDomains(): Promise<string[]>;
74
+ getDnsInfo(domain: string): Promise<DnsInfo>;
75
+ getVerificationKey(): Promise<VerificationKey>;
76
+ listEmailAccounts(domain: string): Promise<EmailAccount[]>;
77
+ listForwarders(domain: string): Promise<Forwarder[]>;
78
+ addDomain(domain: string): Promise<void>;
79
+ createEmailAccount(domain: string, input: {
80
+ username: string;
81
+ password: string;
82
+ quota: number;
83
+ limit: number;
84
+ }): Promise<void>;
85
+ setEmailPassword(domain: string, username: string, password: string): Promise<void>;
86
+ createForwarder(domain: string, input: {
87
+ alias: string;
88
+ destinations: string[];
89
+ }): Promise<void>;
90
+ }
@@ -0,0 +1,86 @@
1
+ // Client for the MXroute REST API. Spec: https://api.mxroute.com/openapi.yaml
2
+ import { ServiceError } from "../../errors.js";
3
+ export class MxrouteError extends ServiceError {
4
+ code;
5
+ status;
6
+ field;
7
+ constructor(status, code, message, field) {
8
+ super(`MXroute ${code} (${status}): ${message}${field ? ` [field: ${field}]` : ""}`);
9
+ this.name = "MxrouteError";
10
+ this.status = status;
11
+ this.code = code;
12
+ this.field = field;
13
+ }
14
+ }
15
+ export class HttpMxroute {
16
+ #creds;
17
+ #baseUrl;
18
+ #fetch;
19
+ constructor(creds, opts = {}) {
20
+ this.#creds = creds;
21
+ this.#baseUrl = opts.baseUrl ?? "https://api.mxroute.com";
22
+ this.#fetch = opts.fetch ?? fetch;
23
+ }
24
+ async #request(method, path, body) {
25
+ const res = await this.#fetch(`${this.#baseUrl}${path}`, {
26
+ method,
27
+ headers: {
28
+ "X-Server": this.#creds.server,
29
+ "X-Username": this.#creds.username,
30
+ "X-API-Key": this.#creds.apiKey,
31
+ Accept: "application/json",
32
+ ...(body === undefined ? {} : { "Content-Type": "application/json" }),
33
+ },
34
+ body: body === undefined ? undefined : JSON.stringify(body),
35
+ });
36
+ if (res.status === 204)
37
+ return undefined;
38
+ const text = await res.text();
39
+ let json;
40
+ try {
41
+ json = text ? JSON.parse(text) : {};
42
+ }
43
+ catch {
44
+ throw new MxrouteError(res.status, "BAD_RESPONSE", `not JSON: ${text.slice(0, 200)}`);
45
+ }
46
+ if (!res.ok || json.success === false) {
47
+ const err = json.error ?? {};
48
+ const retry = res.headers.get("Retry-After");
49
+ const message = (err.message ?? res.statusText) + (retry ? ` (retry after ${retry}s)` : "");
50
+ throw new MxrouteError(res.status, err.code ?? "HTTP_ERROR", message, err.field);
51
+ }
52
+ return json.data;
53
+ }
54
+ #d(domain) {
55
+ return `/domains/${encodeURIComponent(domain)}`;
56
+ }
57
+ listDomains() {
58
+ return this.#request("GET", "/domains");
59
+ }
60
+ getDnsInfo(domain) {
61
+ return this.#request("GET", `${this.#d(domain)}/dns`);
62
+ }
63
+ getVerificationKey() {
64
+ return this.#request("GET", "/verification-key");
65
+ }
66
+ listEmailAccounts(domain) {
67
+ return this.#request("GET", `${this.#d(domain)}/email-accounts`);
68
+ }
69
+ listForwarders(domain) {
70
+ return this.#request("GET", `${this.#d(domain)}/forwarders`);
71
+ }
72
+ async addDomain(domain) {
73
+ await this.#request("POST", "/domains", { domain });
74
+ }
75
+ async createEmailAccount(domain, input) {
76
+ await this.#request("POST", `${this.#d(domain)}/email-accounts`, input);
77
+ }
78
+ async setEmailPassword(domain, username, password) {
79
+ await this.#request("PATCH", `${this.#d(domain)}/email-accounts/${encodeURIComponent(username)}`, {
80
+ password,
81
+ });
82
+ }
83
+ async createForwarder(domain, input) {
84
+ await this.#request("POST", `${this.#d(domain)}/forwarders`, input);
85
+ }
86
+ }
@@ -0,0 +1,13 @@
1
+ # MXroute
2
+
3
+ You can list domains, mailboxes and forwarders, get the DNS records a domain needs, add a domain, create a mailbox, reset a mailbox password and create a forwarder. The tools make the passwords; you never see one. A mailbox password goes to {{operator}} directly, or into Infisical with `storeAt`.
4
+
5
+ To add a new domain:
6
+
7
+ 1. Get the verification record. Create it at the domain's DNS host. If you cannot, give {{operator}} the record to add by hand and stop: add the domain only when {{operator}} says the record is live.
8
+ 2. Add the domain to MXroute. If MXroute cannot find the verification record yet, tell {{operator}} to wait a few minutes. Do not try again in the same turn.
9
+ 3. Get the DNS records (MX, SPF, DKIM) from MXroute. Create each one at the domain's DNS host, one call for each record.
10
+ 4. If a tool says that a record already exists, or that the name already has an SPF record, do not work around it. Tell {{operator}} what is there.
11
+ 5. List the records at the DNS host and give {{operator}} the result.
12
+
13
+ A forwarder to Gmail, Yahoo or AOL turns on Expert Spam Filtering for the domain.
@@ -0,0 +1,34 @@
1
+ import { type DnsInfo, type EmailAccount, type Forwarder, type Mxroute, type VerificationKey } from "./client.js";
2
+ export declare class MemoryMxroute implements Mxroute {
3
+ #private;
4
+ readonly domains: Map<string, {
5
+ accounts: EmailAccount[];
6
+ forwarders: Forwarder[];
7
+ }>;
8
+ readonly writes: {
9
+ op: string;
10
+ args: unknown;
11
+ }[];
12
+ readonly passwords: Map<string, string>;
13
+ constructor(seed?: Record<string, {
14
+ accounts?: string[];
15
+ forwarders?: Record<string, string[]>;
16
+ }>);
17
+ listDomains(): Promise<string[]>;
18
+ getDnsInfo(domain: string): Promise<DnsInfo>;
19
+ getVerificationKey(): Promise<VerificationKey>;
20
+ listEmailAccounts(domain: string): Promise<EmailAccount[]>;
21
+ listForwarders(domain: string): Promise<Forwarder[]>;
22
+ addDomain(domain: string): Promise<void>;
23
+ createEmailAccount(domain: string, input: {
24
+ username: string;
25
+ password: string;
26
+ quota: number;
27
+ limit: number;
28
+ }): Promise<void>;
29
+ setEmailPassword(domain: string, username: string, password: string): Promise<void>;
30
+ createForwarder(domain: string, input: {
31
+ alias: string;
32
+ destinations: string[];
33
+ }): Promise<void>;
34
+ }
@@ -0,0 +1,83 @@
1
+ import { MxrouteError, } from "./client.js";
2
+ // In-memory MXroute for tests and evals. It records every write.
3
+ export class MemoryMxroute {
4
+ domains = new Map();
5
+ writes = [];
6
+ passwords = new Map();
7
+ constructor(seed = {}) {
8
+ for (const [domain, s] of Object.entries(seed)) {
9
+ this.domains.set(domain, {
10
+ accounts: (s.accounts ?? []).map((u) => account(domain, u, 1024, 9600)),
11
+ forwarders: Object.entries(s.forwarders ?? {}).map(([alias, destinations]) => ({
12
+ alias,
13
+ email: `${alias}@${domain}`,
14
+ destinations,
15
+ })),
16
+ });
17
+ }
18
+ }
19
+ #get(domain) {
20
+ const d = this.domains.get(domain);
21
+ if (!d)
22
+ throw new MxrouteError(404, "NOT_FOUND", `domain ${domain} not found`);
23
+ return d;
24
+ }
25
+ async listDomains() {
26
+ return [...this.domains.keys()];
27
+ }
28
+ async getDnsInfo(domain) {
29
+ this.#get(domain);
30
+ return {
31
+ mx_records: [
32
+ { priority: 10, hostname: "sunfire.mxrouting.net" },
33
+ { priority: 20, hostname: "sunfire-relay.mxrouting.net" },
34
+ ],
35
+ spf: { type: "TXT", name: "@", value: "v=spf1 include:mxroute.com -all" },
36
+ dkim: { type: "TXT", name: "x._domainkey", value: "v=DKIM1; k=rsa; p=MIIBFAKEKEY" },
37
+ verification: null,
38
+ };
39
+ }
40
+ async getVerificationKey() {
41
+ const key = "_da-verify-00000000000000000000000000000000";
42
+ return { key, record: { type: "TXT", name: key, value: "domain-verified" } };
43
+ }
44
+ async listEmailAccounts(domain) {
45
+ return this.#get(domain).accounts;
46
+ }
47
+ async listForwarders(domain) {
48
+ return this.#get(domain).forwarders;
49
+ }
50
+ async addDomain(domain) {
51
+ this.writes.push({ op: "addDomain", args: { domain } });
52
+ if (this.domains.has(domain))
53
+ throw new MxrouteError(409, "CONFLICT", `${domain} already exists`);
54
+ this.domains.set(domain, { accounts: [], forwarders: [] });
55
+ }
56
+ async createEmailAccount(domain, input) {
57
+ this.writes.push({
58
+ op: "createEmailAccount",
59
+ args: { domain, username: input.username, quota: input.quota, limit: input.limit },
60
+ });
61
+ const d = this.#get(domain);
62
+ if (d.accounts.some((a) => a.username === input.username)) {
63
+ throw new MxrouteError(409, "CONFLICT", `${input.username}@${domain} already exists`);
64
+ }
65
+ d.accounts.push(account(domain, input.username, input.quota, input.limit));
66
+ this.passwords.set(`${input.username}@${domain}`, input.password);
67
+ }
68
+ async setEmailPassword(domain, username, password) {
69
+ this.writes.push({ op: "setEmailPassword", args: { domain, username } });
70
+ if (!this.#get(domain).accounts.some((a) => a.username === username)) {
71
+ throw new MxrouteError(404, "NOT_FOUND", `${username}@${domain} not found`);
72
+ }
73
+ this.passwords.set(`${username}@${domain}`, password);
74
+ }
75
+ async createForwarder(domain, input) {
76
+ this.writes.push({ op: "createForwarder", args: { domain, ...input } });
77
+ const d = this.#get(domain);
78
+ d.forwarders.push({ alias: input.alias, email: `${input.alias}@${domain}`, destinations: input.destinations });
79
+ }
80
+ }
81
+ function account(domain, username, quota, limit) {
82
+ return { username, email: `${username}@${domain}`, quota, usage: 0, limit, sent: 0, suspended: false };
83
+ }
@@ -0,0 +1,3 @@
1
+ import { type ToolGroupDef } from "../../group.js";
2
+ import { type Mxroute } from "./client.js";
3
+ export declare const mxrouteGroup: ToolGroupDef<Mxroute>;
@@ -0,0 +1,158 @@
1
+ // The MXroute tool group. One definition carries everything the rest of the
2
+ // system needs to know: its tools, keys, host, setup hint and guidance.
3
+ import { readFileSync } from "node:fs";
4
+ import { tool } from "langchain";
5
+ import { z } from "zod";
6
+ import { approvedTool, holdsAll } from "../../group.js";
7
+ import { HttpMxroute } from "./client.js";
8
+ import { generatePassword } from "../../secrets.js";
9
+ import { domain } from "../../schemas.js";
10
+ import { NO_INFISICAL, deliverSecret, describePlace, storeAtFor } from "../../secret-delivery.js";
11
+ import { result } from "../../result.js";
12
+ const guidance = readFileSync(new URL("./guidance.md", import.meta.url), "utf8");
13
+ // MXroute: starts with a letter or digit; letters, digits, '.', '_', '-'; at most 64.
14
+ const localPart = z
15
+ .string()
16
+ .regex(/^[a-z0-9][a-z0-9._-]{0,63}$/, "a lowercase local part, for example hello")
17
+ .describe("The part before the @, lowercase, for example hello");
18
+ export const mxrouteGroup = {
19
+ id: "mxroute",
20
+ name: "MXroute",
21
+ host: "api.mxroute.com",
22
+ keys: ["MXROUTE_SERVER", "MXROUTE_USERNAME", "MXROUTE_API_KEY"],
23
+ setup: "Add the MXroute keys to the agent's secrets in Infisical, then restart the agent.",
24
+ guidance,
25
+ connect(ctx) {
26
+ if (!holdsAll(ctx, this.keys))
27
+ return undefined;
28
+ return new HttpMxroute({
29
+ server: ctx.get("MXROUTE_SERVER"),
30
+ username: ctx.get("MXROUTE_USERNAME"),
31
+ apiKey: ctx.get("MXROUTE_API_KEY"),
32
+ });
33
+ },
34
+ tools(mx, shared) {
35
+ const { secrets, store, policy } = shared;
36
+ const { operator } = policy;
37
+ const storeAt = storeAtFor(policy);
38
+ // Where a stored password would go, for the approval text.
39
+ const where = async (place) => place && store ? ` and store the password in ${await describePlace(policy, store, place)}` : "";
40
+ const listDomains = tool(() => result(() => mx.listDomains()), {
41
+ name: "mxroute_list_domains",
42
+ description: "List the domains on the MXroute account.",
43
+ schema: z.object({}),
44
+ });
45
+ const listMailboxes = tool(({ domain: d }) => result(() => mx.listEmailAccounts(d)), {
46
+ name: "mxroute_list_mailboxes",
47
+ description: "List the mailboxes of a domain, with quota (MB), usage (MB) and daily send limit.",
48
+ schema: z.object({ domain }),
49
+ });
50
+ const listForwarders = tool(({ domain: d }) => result(() => mx.listForwarders(d)), {
51
+ name: "mxroute_list_forwarders",
52
+ description: "List the forwarders of a domain.",
53
+ schema: z.object({ domain }),
54
+ });
55
+ const getDnsRecords = tool(({ domain: d }) => result(() => mx.getDnsInfo(d)), {
56
+ name: "mxroute_get_dns_records",
57
+ description: "Get the DNS records (MX, SPF, DKIM) that a domain on MXroute needs at its DNS host.",
58
+ schema: z.object({ domain }),
59
+ });
60
+ const getVerificationRecord = tool(({ domain: d }) => result(async () => {
61
+ const v = await mx.getVerificationKey();
62
+ return { type: v.record.type, name: `${v.record.name}.${d}`, value: v.record.value };
63
+ }), {
64
+ name: "mxroute_get_verification_record",
65
+ description: "Get the TXT record that must exist in a domain's DNS before MXroute accepts the domain. Use it before mxroute_add_domain.",
66
+ schema: z.object({ domain }),
67
+ });
68
+ const addDomain = approvedTool({
69
+ name: "mxroute_add_domain",
70
+ operator,
71
+ description: `Add a domain to MXroute. The verification TXT record must be live first. ${operator} must approve this action.`,
72
+ schema: z.object({ domain }),
73
+ prepare: async (args) => ({ summary: `Add the domain ${args.domain} to MXroute` }),
74
+ run: async (args) => {
75
+ await mx.addDomain(args.domain);
76
+ return `Added ${args.domain}. Next, get its DNS records with mxroute_get_dns_records.`;
77
+ },
78
+ });
79
+ const createMailbox = approvedTool({
80
+ name: "mxroute_create_mailbox",
81
+ operator,
82
+ description: `Create a mailbox. The tool makes the password and gives it to ${operator} directly, or stores it in Infisical with storeAt; never ask for one. ${operator} must approve this action.`,
83
+ schema: z.object({
84
+ domain,
85
+ username: localPart,
86
+ quotaMb: z.number().int().min(0).max(102400).optional().describe("Storage quota in MB. 0 = unlimited. Default 1024."),
87
+ dailySendLimit: z.number().int().min(1).max(9600).optional().describe("Emails per day. Default 9600."),
88
+ storeAt,
89
+ }),
90
+ prepare: async (args) => {
91
+ if (args.storeAt && !store)
92
+ return { summary: "", early: NO_INFISICAL };
93
+ const quota = args.quotaMb ?? 1024;
94
+ const limit = args.dailySendLimit ?? 9600;
95
+ return {
96
+ summary: `Create the mailbox ${args.username}@${args.domain} (quota ${quota === 0 ? "unlimited" : `${quota} MB`}, send limit ${limit} per day)${await where(args.storeAt)}`,
97
+ args: { ...args, quotaMb: quota, dailySendLimit: limit },
98
+ data: { quota, limit },
99
+ };
100
+ },
101
+ run: async (args, data) => {
102
+ const password = generatePassword();
103
+ await mx.createEmailAccount(args.domain, {
104
+ username: args.username,
105
+ password,
106
+ quota: data.quota,
107
+ limit: data.limit,
108
+ });
109
+ const label = `${args.username}@${args.domain}`;
110
+ return `Created ${label}. ${await deliverSecret({ policy, secrets, store, place: args.storeAt }, label, password)}`;
111
+ },
112
+ });
113
+ const resetPassword = approvedTool({
114
+ name: "mxroute_reset_mailbox_password",
115
+ operator,
116
+ description: `Give a mailbox a new password. The tool makes it and gives it to ${operator} directly, or stores it in Infisical with storeAt. ${operator} must approve this action.`,
117
+ schema: z.object({ domain, username: localPart, storeAt }),
118
+ prepare: async (args) => ({
119
+ summary: `Set a new password for ${args.username}@${args.domain}. The old password stops working${await where(args.storeAt)}.`,
120
+ early: args.storeAt && !store ? NO_INFISICAL : undefined,
121
+ }),
122
+ run: async (args) => {
123
+ const password = generatePassword();
124
+ await mx.setEmailPassword(args.domain, args.username, password);
125
+ const label = `${args.username}@${args.domain}`;
126
+ return `New password set for ${label}. ${await deliverSecret({ policy, secrets, store, place: args.storeAt }, label, password)}`;
127
+ },
128
+ });
129
+ const createForwarder = approvedTool({
130
+ name: "mxroute_create_forwarder",
131
+ operator,
132
+ description: `Create a forwarder. A forwarder to Gmail, Yahoo or AOL turns on Expert Spam Filtering for the domain. ${operator} must approve this action.`,
133
+ schema: z.object({
134
+ domain,
135
+ alias: localPart,
136
+ destinations: z.array(z.email()).min(1).max(10).describe("Addresses that get the mail"),
137
+ }),
138
+ prepare: async (args) => ({
139
+ summary: `Forward ${args.alias}@${args.domain} to ${args.destinations.join(", ")}`,
140
+ }),
141
+ run: async (args) => {
142
+ await mx.createForwarder(args.domain, { alias: args.alias, destinations: args.destinations });
143
+ return `Created the forwarder ${args.alias}@${args.domain}.`;
144
+ },
145
+ });
146
+ return [
147
+ listDomains,
148
+ listMailboxes,
149
+ listForwarders,
150
+ getDnsRecords,
151
+ getVerificationRecord,
152
+ addDomain,
153
+ createMailbox,
154
+ resetPassword,
155
+ createForwarder,
156
+ ];
157
+ },
158
+ };
@@ -0,0 +1,66 @@
1
+ import { ServiceError } from "../../errors.js";
2
+ export type LimitReset = "daily" | "weekly" | "monthly";
3
+ export interface ApiKey {
4
+ hash: string;
5
+ name: string;
6
+ label: string;
7
+ disabled: boolean;
8
+ limit: number | null;
9
+ limit_remaining: number | null;
10
+ limit_reset: LimitReset | null;
11
+ usage: number;
12
+ usage_daily: number;
13
+ usage_weekly: number;
14
+ usage_monthly: number;
15
+ created_at: string;
16
+ last_used_at: string | null;
17
+ expires_at: string | null;
18
+ }
19
+ export interface Credits {
20
+ total_credits: number;
21
+ total_usage: number;
22
+ }
23
+ export interface CreateKeyInput {
24
+ name: string;
25
+ limit: number;
26
+ limit_reset: LimitReset;
27
+ expires_at?: string;
28
+ }
29
+ export interface UpdateKeyInput {
30
+ limit?: number;
31
+ limit_reset?: LimitReset;
32
+ disabled?: boolean;
33
+ }
34
+ export interface OpenRouterKeys {
35
+ getCredits(): Promise<Credits>;
36
+ listKeys(opts?: {
37
+ includeDisabled?: boolean;
38
+ }): Promise<ApiKey[]>;
39
+ getKey(hash: string): Promise<ApiKey>;
40
+ createKey(input: CreateKeyInput): Promise<{
41
+ data: ApiKey;
42
+ key: string;
43
+ }>;
44
+ updateKey(hash: string, input: UpdateKeyInput): Promise<ApiKey>;
45
+ }
46
+ export declare class OpenRouterError extends ServiceError {
47
+ readonly status: number;
48
+ constructor(status: number, message: string);
49
+ }
50
+ export declare class HttpOpenRouterKeys implements OpenRouterKeys {
51
+ #private;
52
+ constructor(managementKey: string, opts?: {
53
+ baseUrl?: string;
54
+ fetch?: typeof fetch;
55
+ });
56
+ getCredits(): Promise<Credits>;
57
+ listKeys(opts?: {
58
+ includeDisabled?: boolean;
59
+ }): Promise<ApiKey[]>;
60
+ getKey(hash: string): Promise<ApiKey>;
61
+ createKey(input: CreateKeyInput): Promise<{
62
+ data: ApiKey;
63
+ key: string;
64
+ }>;
65
+ updateKey(hash: string, input: UpdateKeyInput): Promise<ApiKey>;
66
+ }