@rubics-code/agent-kit 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +80 -2
- package/dist/approval.d.ts +20 -0
- package/dist/approval.js +32 -0
- package/dist/assemble.d.ts +24 -0
- package/dist/assemble.js +19 -0
- package/dist/briefing.d.ts +12 -0
- package/dist/briefing.js +22 -0
- package/dist/capabilities.d.ts +2 -0
- package/dist/capabilities.js +6 -0
- package/dist/credentials.d.ts +28 -0
- package/dist/credentials.js +134 -0
- package/dist/errors.d.ts +2 -0
- package/dist/errors.js +4 -0
- package/dist/group.d.ts +68 -0
- package/dist/group.js +89 -0
- package/dist/groups/cloudflare/client.d.ts +42 -0
- package/dist/groups/cloudflare/client.js +76 -0
- package/dist/groups/cloudflare/guidance.md +7 -0
- package/dist/groups/cloudflare/memory.d.ts +19 -0
- package/dist/groups/cloudflare/memory.js +43 -0
- package/dist/groups/cloudflare/tools.d.ts +3 -0
- package/dist/groups/cloudflare/tools.js +140 -0
- package/dist/groups/infisical/client.d.ts +30 -0
- package/dist/groups/infisical/client.js +133 -0
- package/dist/groups/infisical/guidance.md +8 -0
- package/dist/groups/infisical/memory.d.ts +18 -0
- package/dist/groups/infisical/memory.js +43 -0
- package/dist/groups/infisical/tools.d.ts +3 -0
- package/dist/groups/infisical/tools.js +88 -0
- package/dist/groups/mxroute/client.d.ts +90 -0
- package/dist/groups/mxroute/client.js +86 -0
- package/dist/groups/mxroute/guidance.md +13 -0
- package/dist/groups/mxroute/memory.d.ts +34 -0
- package/dist/groups/mxroute/memory.js +83 -0
- package/dist/groups/mxroute/tools.d.ts +3 -0
- package/dist/groups/mxroute/tools.js +158 -0
- package/dist/groups/openrouter/client.d.ts +66 -0
- package/dist/groups/openrouter/client.js +66 -0
- package/dist/groups/openrouter/guidance.md +7 -0
- package/dist/groups/openrouter/memory.d.ts +26 -0
- package/dist/groups/openrouter/memory.js +59 -0
- package/dist/groups/openrouter/tools.d.ts +3 -0
- package/dist/groups/openrouter/tools.js +130 -0
- package/dist/groups/registrar/client.d.ts +48 -0
- package/dist/groups/registrar/client.js +75 -0
- package/dist/groups/registrar/guidance.md +9 -0
- package/dist/groups/registrar/memory.d.ts +16 -0
- package/dist/groups/registrar/memory.js +27 -0
- package/dist/groups/registrar/tools.d.ts +4 -0
- package/dist/groups/registrar/tools.js +102 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +35 -0
- package/dist/policy.d.ts +12 -0
- package/dist/policy.js +1 -0
- package/dist/result.d.ts +2 -0
- package/dist/result.js +17 -0
- package/dist/runtime/agent.d.ts +28 -0
- package/dist/runtime/agent.js +28 -0
- package/dist/runtime/container.d.ts +8 -0
- package/dist/runtime/container.js +41 -0
- package/dist/runtime/run.d.ts +51 -0
- package/dist/runtime/run.js +152 -0
- package/dist/runtime/transcribe.d.ts +7 -0
- package/dist/runtime/transcribe.js +37 -0
- package/dist/runtime/turns.d.ts +13 -0
- package/dist/runtime/turns.js +23 -0
- package/dist/runtime/web/index.html +452 -0
- package/dist/runtime/web/server.d.ts +20 -0
- package/dist/runtime/web/server.js +150 -0
- package/dist/schemas.d.ts +2 -0
- package/dist/schemas.js +6 -0
- package/dist/secret-delivery.d.ts +18 -0
- package/dist/secret-delivery.js +45 -0
- package/dist/secret-store.d.ts +13 -0
- package/dist/secret-store.js +1 -0
- package/dist/secrets.d.ts +5 -0
- package/dist/secrets.js +13 -0
- package/package.json +57 -4
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { OpenRouterError } from "./client.js";
|
|
2
|
+
// In-memory OpenRouter key API for tests and evals. It records every write.
|
|
3
|
+
export class MemoryOpenRouterKeys {
|
|
4
|
+
keys = new Map();
|
|
5
|
+
writes = [];
|
|
6
|
+
values = new Map();
|
|
7
|
+
#next = 1;
|
|
8
|
+
constructor(seed = []) {
|
|
9
|
+
for (const s of seed)
|
|
10
|
+
this.#add(s.name, s.limit ?? null, "monthly", s.usageMonthly ?? 0, s.disabled ?? false);
|
|
11
|
+
}
|
|
12
|
+
#add(name, limit, reset, usage, disabled, expires) {
|
|
13
|
+
const n = this.#next++;
|
|
14
|
+
const hash = n.toString(16).padStart(64, "0");
|
|
15
|
+
const key = {
|
|
16
|
+
hash,
|
|
17
|
+
name,
|
|
18
|
+
label: `sk-or-v1-${hash.slice(-3)}...${hash.slice(-4)}`,
|
|
19
|
+
disabled,
|
|
20
|
+
limit,
|
|
21
|
+
limit_remaining: limit === null ? null : Math.max(0, limit - usage),
|
|
22
|
+
limit_reset: reset,
|
|
23
|
+
usage,
|
|
24
|
+
usage_daily: 0,
|
|
25
|
+
usage_weekly: 0,
|
|
26
|
+
usage_monthly: usage,
|
|
27
|
+
created_at: "2026-11-01T00:00:00Z",
|
|
28
|
+
last_used_at: null,
|
|
29
|
+
expires_at: expires ?? null,
|
|
30
|
+
};
|
|
31
|
+
this.keys.set(hash, key);
|
|
32
|
+
return key;
|
|
33
|
+
}
|
|
34
|
+
async getCredits() {
|
|
35
|
+
return { total_credits: 100, total_usage: 12.5 };
|
|
36
|
+
}
|
|
37
|
+
async listKeys(opts = {}) {
|
|
38
|
+
return [...this.keys.values()].filter((k) => opts.includeDisabled || !k.disabled);
|
|
39
|
+
}
|
|
40
|
+
async getKey(hash) {
|
|
41
|
+
const key = this.keys.get(hash);
|
|
42
|
+
if (!key)
|
|
43
|
+
throw new OpenRouterError(404, "Resource not found");
|
|
44
|
+
return key;
|
|
45
|
+
}
|
|
46
|
+
async createKey(input) {
|
|
47
|
+
this.writes.push({ op: "createKey", args: input });
|
|
48
|
+
const data = this.#add(input.name, input.limit, input.limit_reset, 0, false, input.expires_at);
|
|
49
|
+
const key = `sk-or-v1-${data.hash}`;
|
|
50
|
+
this.values.set(data.hash, key);
|
|
51
|
+
return { data, key };
|
|
52
|
+
}
|
|
53
|
+
async updateKey(hash, input) {
|
|
54
|
+
this.writes.push({ op: "updateKey", args: { hash, ...input } });
|
|
55
|
+
const key = await this.getKey(hash);
|
|
56
|
+
Object.assign(key, input);
|
|
57
|
+
return key;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// The OpenRouter keys tool group. The spend limit is the agent policy's
|
|
2
|
+
// maximum; the schema rejects a higher one before the approval step.
|
|
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 { HttpOpenRouterKeys } from "./client.js";
|
|
8
|
+
import { NO_INFISICAL, deliverSecret, describePlace, storeAtFor } from "../../secret-delivery.js";
|
|
9
|
+
import { result } from "../../result.js";
|
|
10
|
+
const guidance = readFileSync(new URL("./guidance.md", import.meta.url), "utf8");
|
|
11
|
+
const hash = z
|
|
12
|
+
.string()
|
|
13
|
+
.regex(/^[A-Za-z0-9_-]{8,128}$/, "the hash of a key, from openrouter_list_keys")
|
|
14
|
+
.describe("The key hash from openrouter_list_keys");
|
|
15
|
+
const limitReset = z.enum(["daily", "weekly", "monthly"]).describe("When the spend limit resets");
|
|
16
|
+
const usd = (n) => (n === null ? "no limit" : `$${n.toFixed(2)}`);
|
|
17
|
+
function view(k) {
|
|
18
|
+
return {
|
|
19
|
+
hash: k.hash,
|
|
20
|
+
name: k.name,
|
|
21
|
+
label: k.label,
|
|
22
|
+
disabled: k.disabled,
|
|
23
|
+
limit_usd: k.limit,
|
|
24
|
+
limit_remaining_usd: k.limit_remaining,
|
|
25
|
+
limit_reset: k.limit_reset,
|
|
26
|
+
usage_month_usd: k.usage_monthly,
|
|
27
|
+
usage_total_usd: k.usage,
|
|
28
|
+
last_used_at: k.last_used_at,
|
|
29
|
+
expires_at: k.expires_at,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export const openrouterGroup = {
|
|
33
|
+
id: "openrouter",
|
|
34
|
+
name: "OpenRouter keys",
|
|
35
|
+
host: "openrouter.ai",
|
|
36
|
+
keys: ["OPENROUTER_MANAGEMENT_KEY"],
|
|
37
|
+
setup: "Add the OpenRouter management key to the agent's secrets in Infisical, then restart the agent.",
|
|
38
|
+
guidance,
|
|
39
|
+
connect(ctx) {
|
|
40
|
+
return holdsAll(ctx, this.keys) ? new HttpOpenRouterKeys(ctx.get("OPENROUTER_MANAGEMENT_KEY")) : undefined;
|
|
41
|
+
},
|
|
42
|
+
tools(keys, shared) {
|
|
43
|
+
const { secrets, store, policy } = shared;
|
|
44
|
+
const { operator, maxKeyLimitUsd } = policy;
|
|
45
|
+
const storeAt = storeAtFor(policy);
|
|
46
|
+
const limitUsd = z
|
|
47
|
+
.number()
|
|
48
|
+
.positive()
|
|
49
|
+
.max(maxKeyLimitUsd)
|
|
50
|
+
.describe(`Spend limit in USD, at most ${maxKeyLimitUsd}`);
|
|
51
|
+
const getCredits = tool(() => result(() => keys.getCredits()), {
|
|
52
|
+
name: "openrouter_get_credits",
|
|
53
|
+
description: "Get the OpenRouter credits bought and used, in USD.",
|
|
54
|
+
schema: z.object({}),
|
|
55
|
+
});
|
|
56
|
+
const listKeys = tool(({ includeDisabled }) => result(async () => (await keys.listKeys({ includeDisabled })).map(view)), {
|
|
57
|
+
name: "openrouter_list_keys",
|
|
58
|
+
description: "List the OpenRouter API keys with their spend limits and usage in USD.",
|
|
59
|
+
schema: z.object({
|
|
60
|
+
includeDisabled: z.boolean().optional().describe("Also list disabled keys. Default false."),
|
|
61
|
+
}),
|
|
62
|
+
});
|
|
63
|
+
const createKey = approvedTool({
|
|
64
|
+
name: "openrouter_create_key",
|
|
65
|
+
operator,
|
|
66
|
+
description: `Create an OpenRouter API key with a spend limit. The tool gives the key to ${operator} directly, or stores it in Infisical with storeAt; you never see it. ${operator} must approve this action.`,
|
|
67
|
+
schema: z.object({
|
|
68
|
+
name: z.string().min(1).max(100).describe("What the key is for, for example 'Acme website chatbot'"),
|
|
69
|
+
limitUsd,
|
|
70
|
+
limitReset: limitReset.optional().describe("When the spend limit resets. Default monthly."),
|
|
71
|
+
expiresOn: z.iso.date().optional().describe("Last day the key works, YYYY-MM-DD (UTC). Default no expiry."),
|
|
72
|
+
storeAt,
|
|
73
|
+
}),
|
|
74
|
+
prepare: async (args) => {
|
|
75
|
+
if (args.storeAt && !store)
|
|
76
|
+
return { summary: "", early: NO_INFISICAL };
|
|
77
|
+
const reset = args.limitReset ?? "monthly";
|
|
78
|
+
const expires = args.expiresOn ? ` until ${args.expiresOn}` : " with no expiry";
|
|
79
|
+
const where = args.storeAt && store ? ` and store it in ${await describePlace(policy, store, args.storeAt)}` : "";
|
|
80
|
+
return {
|
|
81
|
+
summary: `Create the OpenRouter API key "${args.name}" (limit ${usd(args.limitUsd)} ${reset}${expires})${where}`,
|
|
82
|
+
args: { ...args, limitReset: reset },
|
|
83
|
+
data: { reset },
|
|
84
|
+
};
|
|
85
|
+
},
|
|
86
|
+
run: async (args, data) => {
|
|
87
|
+
const created = await keys.createKey({
|
|
88
|
+
name: args.name,
|
|
89
|
+
limit: args.limitUsd,
|
|
90
|
+
limit_reset: data.reset,
|
|
91
|
+
...(args.expiresOn ? { expires_at: `${args.expiresOn}T23:59:59Z` } : {}),
|
|
92
|
+
});
|
|
93
|
+
const done = await deliverSecret({ policy, secrets, store, place: args.storeAt }, `OpenRouter key ${args.name}`, created.key);
|
|
94
|
+
return `Created the key "${args.name}" (${created.data.label}, hash ${created.data.hash}). ${done}`;
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
const updateKey = approvedTool({
|
|
98
|
+
name: "openrouter_update_key",
|
|
99
|
+
operator,
|
|
100
|
+
description: `Change the spend limit of an OpenRouter API key, or disable or enable it. A disabled key stops at once. ${operator} must approve this action.`,
|
|
101
|
+
schema: z
|
|
102
|
+
.object({
|
|
103
|
+
hash,
|
|
104
|
+
limitUsd: limitUsd.optional(),
|
|
105
|
+
limitReset: limitReset.optional(),
|
|
106
|
+
disabled: z.boolean().optional().describe("true stops the key; false starts it again"),
|
|
107
|
+
})
|
|
108
|
+
.refine((a) => a.limitUsd !== undefined || a.limitReset !== undefined || a.disabled !== undefined, {
|
|
109
|
+
message: "give at least one change: limitUsd, limitReset or disabled",
|
|
110
|
+
}),
|
|
111
|
+
prepare: async (args) => {
|
|
112
|
+
const current = await keys.getKey(args.hash);
|
|
113
|
+
const changes = [];
|
|
114
|
+
if (args.limitUsd !== undefined)
|
|
115
|
+
changes.push(`limit ${usd(current.limit)} to ${usd(args.limitUsd)}`);
|
|
116
|
+
if (args.limitReset !== undefined)
|
|
117
|
+
changes.push(`reset ${current.limit_reset ?? "never"} to ${args.limitReset}`);
|
|
118
|
+
if (args.disabled !== undefined)
|
|
119
|
+
changes.push(args.disabled ? "disable it" : "enable it");
|
|
120
|
+
return { summary: `Change the OpenRouter API key "${current.name}" (${current.label}): ${changes.join(", ")}` };
|
|
121
|
+
},
|
|
122
|
+
run: async (args) => view(await keys.updateKey(args.hash, {
|
|
123
|
+
...(args.limitUsd !== undefined ? { limit: args.limitUsd } : {}),
|
|
124
|
+
...(args.limitReset !== undefined ? { limit_reset: args.limitReset } : {}),
|
|
125
|
+
...(args.disabled !== undefined ? { disabled: args.disabled } : {}),
|
|
126
|
+
})),
|
|
127
|
+
});
|
|
128
|
+
return [getCredits, listKeys, createKey, updateKey];
|
|
129
|
+
},
|
|
130
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export interface DomainPricing {
|
|
2
|
+
currency: string;
|
|
3
|
+
registration_cost: string;
|
|
4
|
+
renewal_cost: string;
|
|
5
|
+
}
|
|
6
|
+
export interface DomainOffer {
|
|
7
|
+
name: string;
|
|
8
|
+
registrable: boolean;
|
|
9
|
+
tier?: "standard" | "premium";
|
|
10
|
+
pricing?: DomainPricing;
|
|
11
|
+
reason?: string;
|
|
12
|
+
}
|
|
13
|
+
export type RegistrationState = "pending" | "in_progress" | "action_required" | "blocked" | "succeeded" | "failed";
|
|
14
|
+
export interface RegistrationStatus {
|
|
15
|
+
state: RegistrationState;
|
|
16
|
+
completed: boolean;
|
|
17
|
+
context?: {
|
|
18
|
+
domain_name?: string;
|
|
19
|
+
action?: string;
|
|
20
|
+
confirmation_sent_to?: string;
|
|
21
|
+
registration?: {
|
|
22
|
+
expires_at?: string;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
error?: {
|
|
26
|
+
code?: string;
|
|
27
|
+
message?: string;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export interface CloudflareRegistrar {
|
|
31
|
+
pollDelayMs?: number;
|
|
32
|
+
search(query: string, limit?: number): Promise<DomainOffer[]>;
|
|
33
|
+
check(domains: string[]): Promise<DomainOffer[]>;
|
|
34
|
+
register(domain: string): Promise<RegistrationStatus>;
|
|
35
|
+
status(domain: string): Promise<RegistrationStatus>;
|
|
36
|
+
}
|
|
37
|
+
export declare class HttpCloudflareRegistrar implements CloudflareRegistrar {
|
|
38
|
+
#private;
|
|
39
|
+
constructor(token: string, opts?: {
|
|
40
|
+
baseUrl?: string;
|
|
41
|
+
fetch?: typeof fetch;
|
|
42
|
+
accountId?: string;
|
|
43
|
+
});
|
|
44
|
+
search(query: string, limit?: number): Promise<DomainOffer[]>;
|
|
45
|
+
check(domains: string[]): Promise<DomainOffer[]>;
|
|
46
|
+
register(domain: string): Promise<RegistrationStatus>;
|
|
47
|
+
status(domain: string): Promise<RegistrationStatus>;
|
|
48
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Client for the Cloudflare Registrar API, v4. Only the calls the tools need.
|
|
2
|
+
import { CloudflareError } from "../cloudflare/client.js";
|
|
3
|
+
export class HttpCloudflareRegistrar {
|
|
4
|
+
#token;
|
|
5
|
+
#baseUrl;
|
|
6
|
+
#fetch;
|
|
7
|
+
#accountId;
|
|
8
|
+
constructor(token, opts = {}) {
|
|
9
|
+
this.#token = token;
|
|
10
|
+
this.#baseUrl = opts.baseUrl ?? "https://api.cloudflare.com/client/v4";
|
|
11
|
+
this.#fetch = opts.fetch ?? fetch;
|
|
12
|
+
this.#accountId = opts.accountId;
|
|
13
|
+
}
|
|
14
|
+
async #request(method, path, body) {
|
|
15
|
+
const res = await this.#fetch(`${this.#baseUrl}${path}`, {
|
|
16
|
+
method,
|
|
17
|
+
headers: {
|
|
18
|
+
Authorization: `Bearer ${this.#token}`,
|
|
19
|
+
Accept: "application/json",
|
|
20
|
+
...(body === undefined ? {} : { "Content-Type": "application/json" }),
|
|
21
|
+
},
|
|
22
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
23
|
+
});
|
|
24
|
+
const text = await res.text();
|
|
25
|
+
let json;
|
|
26
|
+
try {
|
|
27
|
+
json = text ? JSON.parse(text) : {};
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
throw new CloudflareError(res.status, [], `not JSON: ${text.slice(0, 200)}`);
|
|
31
|
+
}
|
|
32
|
+
if (!res.ok || json.success === false) {
|
|
33
|
+
const errors = json.errors ?? [];
|
|
34
|
+
const message = errors.map((e) => e.message).filter(Boolean).join("; ") || res.statusText;
|
|
35
|
+
throw new CloudflareError(res.status, errors.map((e) => e.code).filter((c) => typeof c === "number"), message);
|
|
36
|
+
}
|
|
37
|
+
if (json.result === undefined)
|
|
38
|
+
throw new CloudflareError(res.status, [], "no result in the response");
|
|
39
|
+
return json.result;
|
|
40
|
+
}
|
|
41
|
+
// The token must see exactly one account, so a purchase cannot go to the wrong one.
|
|
42
|
+
async #account() {
|
|
43
|
+
if (this.#accountId)
|
|
44
|
+
return this.#accountId;
|
|
45
|
+
const accounts = await this.#request("GET", "/accounts");
|
|
46
|
+
if (accounts.length !== 1) {
|
|
47
|
+
throw new CloudflareError(400, [], `the token sees ${accounts.length} accounts; it must see exactly one`);
|
|
48
|
+
}
|
|
49
|
+
this.#accountId = accounts[0].id;
|
|
50
|
+
return this.#accountId;
|
|
51
|
+
}
|
|
52
|
+
async search(query, limit = 20) {
|
|
53
|
+
const a = await this.#account();
|
|
54
|
+
const q = new URLSearchParams({ q: query, limit: String(limit) });
|
|
55
|
+
return (await this.#request("GET", `/accounts/${a}/registrar/domain-search?${q}`)).domains;
|
|
56
|
+
}
|
|
57
|
+
async check(domains) {
|
|
58
|
+
const a = await this.#account();
|
|
59
|
+
return (await this.#request("POST", `/accounts/${a}/registrar/domain-check`, { domains }))
|
|
60
|
+
.domains;
|
|
61
|
+
}
|
|
62
|
+
async register(domain) {
|
|
63
|
+
const a = await this.#account();
|
|
64
|
+
return this.#request("POST", `/accounts/${a}/registrar/registrations`, {
|
|
65
|
+
domain_name: domain,
|
|
66
|
+
years: 1,
|
|
67
|
+
auto_renew: false,
|
|
68
|
+
privacy_mode: "redaction",
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
async status(domain) {
|
|
72
|
+
const a = await this.#account();
|
|
73
|
+
return this.#request("GET", `/accounts/${a}/registrar/registrations/${encodeURIComponent(domain)}/registration-status`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Cloudflare Registrar
|
|
2
|
+
|
|
3
|
+
You can search for domains, check if a domain is available, and register a domain in Cloudflare. A registration costs money and has no refund.
|
|
4
|
+
|
|
5
|
+
- Search first, then call the register tool with the exact domain. The tool checks the live price and shows it in the approval. Do not tell {{operator}} a price that you did not get from a tool.
|
|
6
|
+
- The tool registers one year, with auto-renew off and WHOIS redaction on. It uses the default contact in the Cloudflare account.
|
|
7
|
+
- The API cannot register premium domains, or the extensions giving, mom, inc, lol, sh, link, cc and new. For these, tell {{operator}} to use the Cloudflare dashboard.
|
|
8
|
+
- If the state is action_required, give {{operator}} the action. Do not register again.
|
|
9
|
+
- A new domain has no DNS zone at first. Tell {{operator}} that Terraform must add the zone before you can add mail records.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { CloudflareRegistrar, DomainOffer, RegistrationStatus } from "./client.js";
|
|
2
|
+
export declare class MemoryCloudflareRegistrar implements CloudflareRegistrar {
|
|
3
|
+
#private;
|
|
4
|
+
readonly offers: Map<string, DomainOffer>;
|
|
5
|
+
pollDelayMs: number;
|
|
6
|
+
readonly writes: {
|
|
7
|
+
op: string;
|
|
8
|
+
args: unknown;
|
|
9
|
+
}[];
|
|
10
|
+
states: RegistrationStatus[];
|
|
11
|
+
constructor(offers?: DomainOffer[]);
|
|
12
|
+
search(query: string, limit?: number): Promise<DomainOffer[]>;
|
|
13
|
+
check(domains: string[]): Promise<DomainOffer[]>;
|
|
14
|
+
register(domain: string): Promise<RegistrationStatus>;
|
|
15
|
+
status(_domain: string): Promise<RegistrationStatus>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// In-memory Cloudflare Registrar for tests and evals. It records every write.
|
|
2
|
+
export class MemoryCloudflareRegistrar {
|
|
3
|
+
offers;
|
|
4
|
+
pollDelayMs = 0;
|
|
5
|
+
writes = [];
|
|
6
|
+
// The states that register() and then each status() call return, in order.
|
|
7
|
+
states = [{ state: "succeeded", completed: true }];
|
|
8
|
+
constructor(offers = []) {
|
|
9
|
+
this.offers = new Map(offers.map((o) => [o.name, o]));
|
|
10
|
+
}
|
|
11
|
+
async search(query, limit = 20) {
|
|
12
|
+
return [...this.offers.values()].filter((o) => o.name.includes(query.toLowerCase())).slice(0, limit);
|
|
13
|
+
}
|
|
14
|
+
async check(domains) {
|
|
15
|
+
return domains.map((name) => this.offers.get(name) ?? { name, registrable: false, reason: "domain_unavailable" });
|
|
16
|
+
}
|
|
17
|
+
async register(domain) {
|
|
18
|
+
this.writes.push({ op: "register", args: { domain } });
|
|
19
|
+
return this.#next();
|
|
20
|
+
}
|
|
21
|
+
async status(_domain) {
|
|
22
|
+
return this.#next();
|
|
23
|
+
}
|
|
24
|
+
#next() {
|
|
25
|
+
return this.states.length > 1 ? this.states.shift() : this.states[0];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type ToolGroupDef } from "../../group.js";
|
|
2
|
+
import { type CloudflareRegistrar } from "./client.js";
|
|
3
|
+
export declare const DASHBOARD_ONLY: readonly ["giving", "mom", "inc", "lol", "sh", "link", "cc", "new"];
|
|
4
|
+
export declare const registrarGroup: ToolGroupDef<CloudflareRegistrar>;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// The Cloudflare Registrar tool group: search, live check, and a gated
|
|
2
|
+
// registration. The price in the approval comes from a live check in the
|
|
3
|
+
// same call, never from the model.
|
|
4
|
+
import { readFileSync } from "node:fs";
|
|
5
|
+
import { tool } from "langchain";
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import { approvedTool, holdsAll } from "../../group.js";
|
|
8
|
+
import { domain } from "../../schemas.js";
|
|
9
|
+
import { result } from "../../result.js";
|
|
10
|
+
import { HttpCloudflareRegistrar } from "./client.js";
|
|
11
|
+
const guidance = readFileSync(new URL("./guidance.md", import.meta.url), "utf8");
|
|
12
|
+
// Extensions that the API cannot register. The dashboard can.
|
|
13
|
+
export const DASHBOARD_ONLY = ["giving", "mom", "inc", "lol", "sh", "link", "cc", "new"];
|
|
14
|
+
const POLLS = 10;
|
|
15
|
+
function view(o) {
|
|
16
|
+
return {
|
|
17
|
+
name: o.name,
|
|
18
|
+
registrable: o.registrable,
|
|
19
|
+
...(o.tier ? { tier: o.tier } : {}),
|
|
20
|
+
...(o.pricing ? { pricing: o.pricing } : {}),
|
|
21
|
+
...(o.reason ? { reason: o.reason } : {}),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export const registrarGroup = {
|
|
25
|
+
id: "registrar",
|
|
26
|
+
name: "Cloudflare Registrar",
|
|
27
|
+
host: "api.cloudflare.com",
|
|
28
|
+
keys: ["CLOUDFLARE_API_TOKEN"],
|
|
29
|
+
setup: "Give the Cloudflare API token Registrar permission, and add a default payment method and a default contact in the Cloudflare dashboard. Then restart the agent.",
|
|
30
|
+
guidance,
|
|
31
|
+
connect(ctx) {
|
|
32
|
+
return holdsAll(ctx, this.keys) ? new HttpCloudflareRegistrar(ctx.get("CLOUDFLARE_API_TOKEN")) : undefined;
|
|
33
|
+
},
|
|
34
|
+
tools(reg, shared) {
|
|
35
|
+
const { operator } = shared.policy;
|
|
36
|
+
const wait = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
37
|
+
const dashboard = (d, why) => `Not done: the API cannot register ${d} (${why}). Tell ${operator} to register it in the Cloudflare dashboard.`;
|
|
38
|
+
const search = tool(({ query, limit }) => result(async () => (await reg.search(query, limit)).map(view)), {
|
|
39
|
+
name: "cloudflare_search_domains",
|
|
40
|
+
description: "Search Cloudflare Registrar for domains that match a word or a name. The availability is advisory: the register tool checks it again.",
|
|
41
|
+
schema: z.object({
|
|
42
|
+
query: z.string().min(1).max(100).describe("A word, a phrase or a domain name"),
|
|
43
|
+
limit: z.number().int().min(1).max(50).optional().describe("The maximum number of results, default 20"),
|
|
44
|
+
}),
|
|
45
|
+
});
|
|
46
|
+
const check = tool(({ domains }) => result(async () => (await reg.check(domains)).map(view)), {
|
|
47
|
+
name: "cloudflare_check_domains",
|
|
48
|
+
description: "Check with the registry, now, if domains are available, and get their prices.",
|
|
49
|
+
schema: z.object({ domains: z.array(domain).min(1).max(20) }),
|
|
50
|
+
});
|
|
51
|
+
function report(d, s) {
|
|
52
|
+
switch (s.state) {
|
|
53
|
+
case "succeeded":
|
|
54
|
+
return `Registered ${d}${s.context?.registration?.expires_at ? `, expires ${s.context.registration.expires_at}` : ""}. Auto-renew is off. Terraform must add the DNS zone before mail records.`;
|
|
55
|
+
case "action_required":
|
|
56
|
+
return `Not finished: Cloudflare needs an action for ${d}: ${s.context?.action ?? "unknown"}${s.context?.confirmation_sent_to ? ` (sent to ${s.context.confirmation_sent_to})` : ""}. Tell ${operator}. Do not register again.`;
|
|
57
|
+
case "failed":
|
|
58
|
+
return `Failed: Cloudflare did not register ${d}: ${s.error?.code ?? ""} ${s.error?.message ?? ""}`.trim();
|
|
59
|
+
case "blocked":
|
|
60
|
+
return `Blocked: Cloudflare blocked the registration of ${d}. Tell ${operator} to look in the dashboard. Do not register again.`;
|
|
61
|
+
default:
|
|
62
|
+
return `Still ${s.state}: Cloudflare has not finished ${d}. Tell ${operator} to look in the dashboard later. Do not register again.`;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const register = approvedTool({
|
|
66
|
+
name: "cloudflare_register_domain",
|
|
67
|
+
operator,
|
|
68
|
+
description: `Register one domain in Cloudflare for one year. This costs money and has no refund. ${operator} must approve this action.`,
|
|
69
|
+
schema: z.object({ domain }),
|
|
70
|
+
prepare: async ({ domain: d }) => {
|
|
71
|
+
const ext = d.split(".").pop();
|
|
72
|
+
if (DASHBOARD_ONLY.includes(ext))
|
|
73
|
+
return { summary: "", early: dashboard(d, `.${ext}`) };
|
|
74
|
+
const [offer] = await reg.check([d]);
|
|
75
|
+
if (!offer?.registrable || !offer.pricing) {
|
|
76
|
+
if (offer?.reason === "domain_premium" || offer?.tier === "premium")
|
|
77
|
+
return { summary: "", early: dashboard(d, "premium") };
|
|
78
|
+
if (offer?.reason?.startsWith("extension_not_supported"))
|
|
79
|
+
return { summary: "", early: dashboard(d, offer.reason) };
|
|
80
|
+
return { summary: "", early: `Not done: ${d} is not available (${offer?.reason ?? "unknown"}).` };
|
|
81
|
+
}
|
|
82
|
+
if (offer.tier === "premium")
|
|
83
|
+
return { summary: "", early: dashboard(d, "premium") };
|
|
84
|
+
const p = offer.pricing;
|
|
85
|
+
return {
|
|
86
|
+
summary: `Register ${d} in Cloudflare for 1 year: ${p.registration_cost} ${p.currency} now, renewal ${p.renewal_cost} ${p.currency} a year. Auto-renew off, WHOIS redaction on, default contact. No refund.`,
|
|
87
|
+
// The gate hashes the price too, so an approval cannot cover a changed price.
|
|
88
|
+
args: { domain: d, currency: p.currency, registration_cost: p.registration_cost },
|
|
89
|
+
};
|
|
90
|
+
},
|
|
91
|
+
run: async ({ domain: d }) => {
|
|
92
|
+
let s = await reg.register(d);
|
|
93
|
+
for (let i = 0; i < POLLS && (s.state === "pending" || s.state === "in_progress"); i++) {
|
|
94
|
+
await wait(reg.pollDelayMs ?? 3000);
|
|
95
|
+
s = await reg.status(d);
|
|
96
|
+
}
|
|
97
|
+
return report(d, s);
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
return [search, check, register];
|
|
101
|
+
},
|
|
102
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export * from "./approval.js";
|
|
2
|
+
export * from "./errors.js";
|
|
3
|
+
export * from "./policy.js";
|
|
4
|
+
export * from "./result.js";
|
|
5
|
+
export * from "./secret-store.js";
|
|
6
|
+
export * from "./secrets.js";
|
|
7
|
+
export * from "./group.js";
|
|
8
|
+
export * from "./capabilities.js";
|
|
9
|
+
export * from "./briefing.js";
|
|
10
|
+
export * from "./assemble.js";
|
|
11
|
+
export * from "./credentials.js";
|
|
12
|
+
export * from "./schemas.js";
|
|
13
|
+
export * from "./secret-delivery.js";
|
|
14
|
+
export type { StructuredTool } from "@langchain/core/tools";
|
|
15
|
+
export * from "./groups/mxroute/client.js";
|
|
16
|
+
export * from "./groups/mxroute/memory.js";
|
|
17
|
+
export * from "./groups/mxroute/tools.js";
|
|
18
|
+
export * from "./groups/cloudflare/client.js";
|
|
19
|
+
export * from "./groups/cloudflare/memory.js";
|
|
20
|
+
export * from "./groups/cloudflare/tools.js";
|
|
21
|
+
export * from "./groups/registrar/client.js";
|
|
22
|
+
export * from "./groups/registrar/memory.js";
|
|
23
|
+
export * from "./groups/registrar/tools.js";
|
|
24
|
+
export * from "./groups/openrouter/client.js";
|
|
25
|
+
export * from "./groups/openrouter/memory.js";
|
|
26
|
+
export * from "./groups/openrouter/tools.js";
|
|
27
|
+
export * from "./groups/infisical/client.js";
|
|
28
|
+
export * from "./groups/infisical/memory.js";
|
|
29
|
+
export * from "./groups/infisical/tools.js";
|
|
30
|
+
export * from "./runtime/agent.js";
|
|
31
|
+
export * from "./runtime/turns.js";
|
|
32
|
+
export * from "./runtime/transcribe.js";
|
|
33
|
+
export * from "./runtime/web/server.js";
|
|
34
|
+
export * from "./runtime/run.js";
|
|
35
|
+
export * from "./runtime/container.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// The Kit's interface. Agents import the machinery from here.
|
|
2
|
+
export * from "./approval.js";
|
|
3
|
+
export * from "./errors.js";
|
|
4
|
+
export * from "./policy.js";
|
|
5
|
+
export * from "./result.js";
|
|
6
|
+
export * from "./secret-store.js";
|
|
7
|
+
export * from "./secrets.js";
|
|
8
|
+
export * from "./group.js";
|
|
9
|
+
export * from "./capabilities.js";
|
|
10
|
+
export * from "./briefing.js";
|
|
11
|
+
export * from "./assemble.js";
|
|
12
|
+
export * from "./credentials.js";
|
|
13
|
+
export * from "./schemas.js";
|
|
14
|
+
export * from "./secret-delivery.js";
|
|
15
|
+
export * from "./groups/mxroute/client.js";
|
|
16
|
+
export * from "./groups/mxroute/memory.js";
|
|
17
|
+
export * from "./groups/mxroute/tools.js";
|
|
18
|
+
export * from "./groups/cloudflare/client.js";
|
|
19
|
+
export * from "./groups/cloudflare/memory.js";
|
|
20
|
+
export * from "./groups/cloudflare/tools.js";
|
|
21
|
+
export * from "./groups/registrar/client.js";
|
|
22
|
+
export * from "./groups/registrar/memory.js";
|
|
23
|
+
export * from "./groups/registrar/tools.js";
|
|
24
|
+
export * from "./groups/openrouter/client.js";
|
|
25
|
+
export * from "./groups/openrouter/memory.js";
|
|
26
|
+
export * from "./groups/openrouter/tools.js";
|
|
27
|
+
export * from "./groups/infisical/client.js";
|
|
28
|
+
export * from "./groups/infisical/memory.js";
|
|
29
|
+
export * from "./groups/infisical/tools.js";
|
|
30
|
+
export * from "./runtime/agent.js";
|
|
31
|
+
export * from "./runtime/turns.js";
|
|
32
|
+
export * from "./runtime/transcribe.js";
|
|
33
|
+
export * from "./runtime/web/server.js";
|
|
34
|
+
export * from "./runtime/run.js";
|
|
35
|
+
export * from "./runtime/container.js";
|
package/dist/policy.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
export interface InfisicalPolicy {
|
|
3
|
+
readablePath: z.ZodType<string>;
|
|
4
|
+
writablePath: z.ZodType<string>;
|
|
5
|
+
envLabel(path: string): string;
|
|
6
|
+
}
|
|
7
|
+
export interface AgentPolicy {
|
|
8
|
+
agent: string;
|
|
9
|
+
operator: string;
|
|
10
|
+
maxKeyLimitUsd: number;
|
|
11
|
+
infisical: InfisicalPolicy;
|
|
12
|
+
}
|
package/dist/policy.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/result.d.ts
ADDED
package/dist/result.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ServiceError } from "./errors.js";
|
|
2
|
+
export async function result(run) {
|
|
3
|
+
try {
|
|
4
|
+
const value = await run();
|
|
5
|
+
return typeof value === "string" ? value : JSON.stringify(value);
|
|
6
|
+
}
|
|
7
|
+
catch (err) {
|
|
8
|
+
if (err instanceof ServiceError)
|
|
9
|
+
return `Error: ${err.message}`;
|
|
10
|
+
throw err;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
// The operator's name comes from the agent's policy (ADR-0003). The model
|
|
14
|
+
// never writes this copy; the gate decided the rejection.
|
|
15
|
+
export function rejected(reason, operator = "the operator") {
|
|
16
|
+
return `Not done: ${operator} did not approve (${reason}). Do not try again unless ${operator} asks.`;
|
|
17
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { BaseChatModel } from "@langchain/core/language_models/chat_models";
|
|
2
|
+
import type { StructuredTool } from "@langchain/core/tools";
|
|
3
|
+
import { type BaseCheckpointSaver } from "@langchain/langgraph";
|
|
4
|
+
export declare const OPENROUTER_BASE_URL = "https://openrouter.ai/api/v1";
|
|
5
|
+
export declare const DEFAULT_TOOL_CALL_LIMIT = 25;
|
|
6
|
+
export declare function createAgentGraph(opts: {
|
|
7
|
+
model: BaseChatModel;
|
|
8
|
+
tools: StructuredTool[];
|
|
9
|
+
briefing: string;
|
|
10
|
+
checkpointer?: BaseCheckpointSaver;
|
|
11
|
+
toolCallLimit?: number;
|
|
12
|
+
}): import("langchain").ReactAgent<import("langchain").AgentTypeConfig<import("langchain").ResponseFormatUndefined, undefined, import("langchain").AnyAnnotationRoot, readonly [import("langchain").AgentMiddleware<import("zod/v3").ZodObject<{
|
|
13
|
+
threadToolCallCount: import("zod/v3").ZodDefault<import("zod/v3").ZodRecord<import("zod/v3").ZodString, import("zod/v3").ZodNumber>>;
|
|
14
|
+
runToolCallCount: import("zod/v3").ZodDefault<import("zod/v3").ZodRecord<import("zod/v3").ZodString, import("zod/v3").ZodNumber>>;
|
|
15
|
+
}, "strip", import("zod/v3").ZodTypeAny, {
|
|
16
|
+
threadToolCallCount: Record<string, number>;
|
|
17
|
+
runToolCallCount: Record<string, number>;
|
|
18
|
+
}, {
|
|
19
|
+
threadToolCallCount?: Record<string, number> | undefined;
|
|
20
|
+
runToolCallCount?: Record<string, number> | undefined;
|
|
21
|
+
}>, undefined, unknown, readonly (import("@langchain/core/tools").ServerTool | import("@langchain/core/tools").ClientTool)[], readonly []>], readonly (import("@langchain/core/tools").ServerTool | StructuredTool<import("@langchain/core/tools").ToolSchemaBase, any, any, any, unknown> | import("@langchain/core/tools").ClientTool)[], readonly []>>;
|
|
22
|
+
export type AgentGraph = ReturnType<typeof createAgentGraph>;
|
|
23
|
+
export declare function openRouterModel(opts: {
|
|
24
|
+
apiKey: string;
|
|
25
|
+
model: string;
|
|
26
|
+
title: string;
|
|
27
|
+
baseUrl?: string;
|
|
28
|
+
}): BaseChatModel;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { MemorySaver } from "@langchain/langgraph";
|
|
2
|
+
import { ChatOpenAI } from "@langchain/openai";
|
|
3
|
+
import { createAgent, toolCallLimitMiddleware } from "langchain";
|
|
4
|
+
export const OPENROUTER_BASE_URL = "https://openrouter.ai/api/v1";
|
|
5
|
+
// Upper limit of tool calls in one user turn. It stops a loop.
|
|
6
|
+
export const DEFAULT_TOOL_CALL_LIMIT = 25;
|
|
7
|
+
export function createAgentGraph(opts) {
|
|
8
|
+
return createAgent({
|
|
9
|
+
model: opts.model,
|
|
10
|
+
tools: opts.tools,
|
|
11
|
+
systemPrompt: opts.briefing,
|
|
12
|
+
checkpointer: opts.checkpointer ?? new MemorySaver(),
|
|
13
|
+
middleware: [toolCallLimitMiddleware({ runLimit: opts.toolCallLimit ?? DEFAULT_TOOL_CALL_LIMIT })],
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
// A chat model on OpenRouter (or any OpenAI-compatible endpoint). `title` is
|
|
17
|
+
// the X-Title header, which names the app in OpenRouter's activity list.
|
|
18
|
+
export function openRouterModel(opts) {
|
|
19
|
+
return new ChatOpenAI({
|
|
20
|
+
model: opts.model,
|
|
21
|
+
apiKey: opts.apiKey,
|
|
22
|
+
temperature: 0,
|
|
23
|
+
configuration: {
|
|
24
|
+
baseURL: opts.baseUrl ?? OPENROUTER_BASE_URL,
|
|
25
|
+
defaultHeaders: { "X-Title": opts.title },
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
}
|