@soft-boy/agentschema 0.3.12 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -9
- package/dist/bin/agentschema.d.ts +2 -0
- package/dist/bin/agentschema.js +333 -0
- package/dist/lib/channels.d.ts +65 -0
- package/dist/lib/channels.js +339 -0
- package/dist/lib/check.d.ts +10 -0
- package/dist/lib/check.js +411 -0
- package/dist/lib/files.d.ts +7 -0
- package/{lib → dist/lib}/files.js +10 -14
- package/dist/lib/index.d.ts +24 -0
- package/{lib → dist/lib}/index.js +3 -10
- package/dist/lib/instance.d.ts +41 -0
- package/dist/lib/instance.js +74 -0
- package/dist/lib/markdown.d.ts +11 -0
- package/dist/lib/markdown.js +38 -0
- package/dist/lib/scaffold.d.ts +15 -0
- package/dist/lib/scaffold.js +46 -0
- package/dist/lib/scheduled.d.ts +56 -0
- package/dist/lib/scheduled.js +185 -0
- package/dist/lib/skills.d.ts +28 -0
- package/dist/lib/skills.js +55 -0
- package/dist/lib/stream.d.ts +30 -0
- package/dist/lib/stream.js +56 -0
- package/dist/lib/system-prompt.d.ts +16 -0
- package/{lib → dist/lib}/system-prompt.js +14 -15
- package/dist/lib/tools.d.ts +105 -0
- package/dist/lib/tools.js +353 -0
- package/dist/lib/vaults.d.ts +55 -0
- package/dist/lib/vaults.js +143 -0
- package/dist/src/chat.d.ts +15 -0
- package/dist/src/chat.js +159 -0
- package/dist/src/check.d.ts +2 -0
- package/dist/src/check.js +14 -0
- package/dist/src/cred-menu.d.ts +17 -0
- package/dist/src/cred-menu.js +193 -0
- package/dist/src/cred.d.ts +54 -0
- package/dist/src/cred.js +252 -0
- package/dist/src/custom-tools.d.ts +3 -0
- package/dist/src/custom-tools.js +18 -0
- package/dist/src/delete.d.ts +9 -0
- package/dist/src/delete.js +27 -0
- package/dist/src/deploy.d.ts +62 -0
- package/dist/src/deploy.js +442 -0
- package/dist/src/dotenv.d.ts +7 -0
- package/dist/src/dotenv.js +54 -0
- package/dist/src/folder.d.ts +5 -0
- package/dist/src/folder.js +57 -0
- package/dist/src/init.d.ts +11 -0
- package/dist/src/init.js +51 -0
- package/dist/src/list.d.ts +3 -0
- package/dist/src/list.js +46 -0
- package/dist/src/lock.d.ts +10 -0
- package/dist/src/lock.js +37 -0
- package/dist/src/mcp.d.ts +11 -0
- package/dist/src/mcp.js +79 -0
- package/dist/src/node.d.ts +14 -0
- package/dist/src/oauth.d.ts +64 -0
- package/dist/src/oauth.js +208 -0
- package/dist/src/prompts.d.ts +18 -0
- package/dist/src/prompts.js +166 -0
- package/dist/src/session.d.ts +58 -0
- package/dist/src/session.js +200 -0
- package/dist/src/tools-menu.d.ts +8 -0
- package/dist/src/tools-menu.js +173 -0
- package/package.json +21 -9
- package/bin/agentschema.js +0 -326
- package/lib/channels.js +0 -338
- package/lib/check.js +0 -388
- package/lib/instance.js +0 -48
- package/lib/markdown.js +0 -42
- package/lib/scaffold.js +0 -51
- package/lib/scheduled.js +0 -175
- package/lib/skills.js +0 -58
- package/lib/stream.js +0 -50
- package/lib/tools.js +0 -327
- package/lib/vaults.js +0 -142
- package/src/chat.js +0 -156
- package/src/check.js +0 -14
- package/src/cred-menu.js +0 -197
- package/src/cred.js +0 -263
- package/src/custom-tools.js +0 -17
- package/src/delete.js +0 -25
- package/src/deploy.js +0 -441
- package/src/dotenv.js +0 -50
- package/src/folder.js +0 -55
- package/src/init.js +0 -54
- package/src/list.js +0 -49
- package/src/lock.js +0 -40
- package/src/mcp.js +0 -76
- package/src/oauth.js +0 -215
- package/src/prompts.js +0 -159
- package/src/session.js +0 -194
- package/src/tools-menu.js +0 -163
- /package/{src → dist/src}/node.js +0 -0
package/lib/check.js
DELETED
|
@@ -1,388 +0,0 @@
|
|
|
1
|
-
import { checkChannels, readChannels } from "./channels.js";
|
|
2
|
-
import { textOf } from "./files.js";
|
|
3
|
-
import { AGENT_FILE, ENV_FILE, readInstance } from "./instance.js";
|
|
4
|
-
import { checkScheduled, readScheduled } from "./scheduled.js";
|
|
5
|
-
import { SYSTEM_PROMPT_DIR, readSystemPrompt, systemPromptOf } from "./system-prompt.js";
|
|
6
|
-
import { MAX_UPLOAD_BYTES, SKILLS_DIR, readSkills } from "./skills.js";
|
|
7
|
-
import { MCP_TOOLSET, TOOLS_DIR, checkTools, readTools } from "./tools.js";
|
|
8
|
-
import { CREDENTIAL_TYPES, ENV_VAR, SECRET_FIELDS, TOKEN_ENDPOINT_AUTH, VAULT_FILE, get, readVaults } from "./vaults.js";
|
|
9
|
-
|
|
10
|
-
const AGENT_FIELDS = new Set([
|
|
11
|
-
"name", "model", "description", "mcp_servers", "skills",
|
|
12
|
-
"multiagent", "metadata", "execution_identity",
|
|
13
|
-
]);
|
|
14
|
-
const ENV_FIELDS = new Set(["name", "config", "description", "metadata", "scope"]);
|
|
15
|
-
|
|
16
|
-
const SECRET_PATTERNS = [
|
|
17
|
-
[/sk-ant-[A-Za-z0-9_-]{8,}/, "an Anthropic API key"],
|
|
18
|
-
[/\bghp_[A-Za-z0-9]{20,}/, "a GitHub token"],
|
|
19
|
-
[/\bgithub_pat_[A-Za-z0-9_]{20,}/, "a GitHub token"],
|
|
20
|
-
[/\bxox[bpas]-[A-Za-z0-9-]{10,}/, "a Slack token"],
|
|
21
|
-
[/\bAKIA[0-9A-Z]{16}\b/, "an AWS access key"],
|
|
22
|
-
[/\b\d{6,12}:[A-Za-z0-9_-]{35}\b/, "a Telegram bot token"],
|
|
23
|
-
[/\bSG\.[A-Za-z0-9_-]{16,}\.[A-Za-z0-9_-]{16,}/, "a SendGrid API key"],
|
|
24
|
-
[/\b(AC|SK)[0-9a-f]{32}\b/, "a Twilio SID"],
|
|
25
|
-
[/\b[MNO][A-Za-z0-9_-]{23,}\.[A-Za-z0-9_-]{6,7}\.[A-Za-z0-9_-]{27,}\b/, "a Discord bot token"],
|
|
26
|
-
];
|
|
27
|
-
|
|
28
|
-
const isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
29
|
-
|
|
30
|
-
// Validates an agent's files without calling the API. `files` is a file map (see files.js), and
|
|
31
|
-
// `options` is what checkTools takes: { customTools, toolsets }.
|
|
32
|
-
// Returns { errors, warnings, instance }; instance is null when the files can't be read.
|
|
33
|
-
export function checkFiles(files, options = {}) {
|
|
34
|
-
const { agent, env, errors } = readInstance(files);
|
|
35
|
-
const { tools, errors: toolErrors } = readTools(files);
|
|
36
|
-
const { vaults, errors: vaultErrors } = readVaults(files);
|
|
37
|
-
const { skills, errors: skillErrors } = readSkills(files);
|
|
38
|
-
const { channels, errors: channelErrors } = readChannels(files);
|
|
39
|
-
const { tasks: scheduled, errors: scheduledErrors } = readScheduled(files);
|
|
40
|
-
const { parts: systemPrompt, errors: systemPromptErrors } = readSystemPrompt(files);
|
|
41
|
-
errors.push(...toolErrors, ...vaultErrors, ...skillErrors, ...channelErrors, ...scheduledErrors, ...systemPromptErrors);
|
|
42
|
-
const warnings = [];
|
|
43
|
-
|
|
44
|
-
if (agent) checkAgent(agent, errors, warnings);
|
|
45
|
-
if (agent) checkSystemPromptLength({ agent, systemPrompt }, errors);
|
|
46
|
-
if (env) checkEnv(env, errors, warnings);
|
|
47
|
-
checkTools(tools, errors, warnings, options);
|
|
48
|
-
if (agent) checkMcpServers(agent, tools, errors);
|
|
49
|
-
if (agent && env) checkMcpNetworking(agent, env, warnings);
|
|
50
|
-
for (const skill of skills) checkSkill(skill, errors);
|
|
51
|
-
const declaredSkills = Array.isArray(agent?.data.skills) ? agent.data.skills.length : 0;
|
|
52
|
-
if (declaredSkills + skills.length > 500) errors.push(`${declaredSkills + skills.length} skills; the limit is 500`);
|
|
53
|
-
for (const vault of vaults) checkVault(vault, errors, warnings);
|
|
54
|
-
checkEnvVarCredentials(vaults, env, warnings);
|
|
55
|
-
checkChannels(channels, { agent: agent ?? undefined, systemPrompt, tools, toolsets: options.toolsets }, errors, warnings);
|
|
56
|
-
checkScheduled(scheduled, { tools }, errors, warnings);
|
|
57
|
-
|
|
58
|
-
const vaultFiles = vaults.flatMap((v) => [...(v.file ? [[`${v.path}/${VAULT_FILE}`, v.file]] : []), ...v.credentials.map((c) => [c.file, c])]);
|
|
59
|
-
const skillTexts = skills.flatMap((s) => s.files.map((f) => [`${s.path}/${f.rel}`, { raw: textOf(f.bytes) }]));
|
|
60
|
-
for (const [file, parsed] of [[AGENT_FILE, agent], [ENV_FILE, env], ...tools.map((t) => [t.file, t]), ...vaultFiles, ...skillTexts, ...channels.map((c) => [c.file, c]), ...scheduled.map((t) => [t.file, t]), ...systemPrompt.map((p) => [p.file, { raw: p.text }])]) {
|
|
61
|
-
if (!parsed) continue;
|
|
62
|
-
for (const [pattern, what] of SECRET_PATTERNS) {
|
|
63
|
-
if (pattern.test(parsed.raw)) errors.push(`${file}: looks like it contains ${what}; keep secrets out of these files`);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return { errors, warnings, instance: agent && env ? { agent, env, tools, vaults, skills, channels, scheduled, systemPrompt } : null };
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const MAX_SYSTEM_PROMPT = 100_000;
|
|
71
|
-
|
|
72
|
-
// The system prompt is agent.md's body and system_prompt/'s files together, and the API's limit is on
|
|
73
|
-
// all of it.
|
|
74
|
-
function checkSystemPromptLength(instance, errors) {
|
|
75
|
-
const { length } = systemPromptOf(instance);
|
|
76
|
-
if (length <= MAX_SYSTEM_PROMPT) return;
|
|
77
|
-
const where = instance.systemPrompt.length > 0 ? `${AGENT_FILE} and ${SYSTEM_PROMPT_DIR}/` : AGENT_FILE;
|
|
78
|
-
errors.push(`${where}: the system prompt is ${length.toLocaleString("en-US")} characters; the limit is ${MAX_SYSTEM_PROMPT.toLocaleString("en-US")}`);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function checkAgent({ data, body }, errors, warnings) {
|
|
82
|
-
const err = (msg) => errors.push(`${AGENT_FILE}: ${msg}`);
|
|
83
|
-
|
|
84
|
-
if (typeof data.name !== "string" || data.name.trim() === "") err("`name` is required");
|
|
85
|
-
else if (data.name.length > 256) err("`name` must be at most 256 characters");
|
|
86
|
-
|
|
87
|
-
if (data.model === undefined) err("`model` is required");
|
|
88
|
-
else if (isObject(data.model) ? typeof data.model.id !== "string" : typeof data.model !== "string") {
|
|
89
|
-
err("`model` must be a model ID, or a mapping with an `id`");
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if ("system" in data) err("`system` is not allowed in frontmatter; the Markdown body is the system prompt");
|
|
93
|
-
|
|
94
|
-
if (data.description !== undefined && data.description !== null) {
|
|
95
|
-
if (typeof data.description !== "string") err("`description` must be a string");
|
|
96
|
-
else if (data.description.length > 2048) err("`description` must be at most 2048 characters");
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if ("tools" in data) err(`\`tools\` is not allowed in frontmatter; define each tool as a file in ${TOOLS_DIR}/`);
|
|
100
|
-
|
|
101
|
-
for (const [field, max] of [["mcp_servers", 20], ["skills", 500]]) {
|
|
102
|
-
if (data[field] === undefined) continue;
|
|
103
|
-
if (!Array.isArray(data[field])) err(`\`${field}\` must be a list`);
|
|
104
|
-
else if (data[field].length > max) err(`\`${field}\` has ${data[field].length} entries; the limit is ${max}`);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (Array.isArray(data.skills)) {
|
|
108
|
-
for (const [index, skill] of data.skills.entries()) checkSkillRef(skill, (msg) => err(`\`skills[${index}]\`: ${msg}`));
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
checkMetadata(data.metadata, 16, err);
|
|
112
|
-
|
|
113
|
-
for (const key of Object.keys(data)) {
|
|
114
|
-
if (!AGENT_FIELDS.has(key) && key !== "system" && key !== "tools") {
|
|
115
|
-
warnings.push(`${AGENT_FILE}: unknown field \`${key}\` will be sent to the API as written`);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function checkEnv({ data }, errors, warnings) {
|
|
121
|
-
const err = (msg) => errors.push(`${ENV_FILE}: ${msg}`);
|
|
122
|
-
|
|
123
|
-
if (typeof data.name !== "string" || data.name.trim() === "") err("`name` is required");
|
|
124
|
-
|
|
125
|
-
if (data.config !== undefined) {
|
|
126
|
-
const { config } = data;
|
|
127
|
-
if (!isObject(config)) err("`config` must be a mapping");
|
|
128
|
-
else {
|
|
129
|
-
if (!["cloud", "self_hosted"].includes(config.type)) err("`config.type` must be `cloud` or `self_hosted`");
|
|
130
|
-
const net = config.networking;
|
|
131
|
-
if (net !== undefined && !(isObject(net) && ["limited", "unrestricted"].includes(net.type))) {
|
|
132
|
-
err("`config.networking.type` must be `limited` or `unrestricted`");
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (data.description !== undefined && data.description !== null && typeof data.description !== "string") {
|
|
138
|
-
err("`description` must be a string");
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
checkMetadata(data.metadata, Infinity, err);
|
|
142
|
-
|
|
143
|
-
for (const key of Object.keys(data)) {
|
|
144
|
-
if (!ENV_FIELDS.has(key)) warnings.push(`${ENV_FILE}: unknown field \`${key}\` will be sent to the API as written`);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// An entry in agent.md's `skills` list, in the API's shape.
|
|
149
|
-
function checkSkillRef(skill, err) {
|
|
150
|
-
if (typeof skill === "string") {
|
|
151
|
-
return err(`write this as a mapping with \`type\` and \`skill_id\`; a skill in ${SKILLS_DIR}/ is attached without being listed`);
|
|
152
|
-
}
|
|
153
|
-
if (!isObject(skill)) return err("must be a mapping with `type` and `skill_id`");
|
|
154
|
-
if (!["anthropic", "custom"].includes(skill.type)) err("`type` must be `anthropic` or `custom`");
|
|
155
|
-
if (typeof skill.skill_id !== "string" || skill.skill_id === "") err("`skill_id` is required");
|
|
156
|
-
else if (skill.type === "custom" && !skill.skill_id.startsWith("skill_")) err("a custom skill's `skill_id` starts with skill_");
|
|
157
|
-
if (skill.version !== undefined && skill.version !== null && typeof skill.version !== "string") {
|
|
158
|
-
err("`version` must be a string (quote numbers)");
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
function checkSkill(skill, errors) {
|
|
163
|
-
const err = (msg) => errors.push(`${skill.file}: ${msg}`);
|
|
164
|
-
const { name, description } = skill.data;
|
|
165
|
-
if (typeof name !== "string" || name === "") err("`name` is required");
|
|
166
|
-
else {
|
|
167
|
-
if (name !== skill.name) err(`\`name\` must match the folder's name (${skill.name})`);
|
|
168
|
-
if (!/^[a-z0-9-]{1,64}$/.test(name)) err("`name` may only use lowercase letters, digits and hyphens, up to 64 characters");
|
|
169
|
-
if (/anthropic|claude/.test(name)) err("`name` can't contain the reserved words `anthropic` or `claude`");
|
|
170
|
-
}
|
|
171
|
-
if (typeof description !== "string" || description.trim() === "") err("`description` is required");
|
|
172
|
-
else {
|
|
173
|
-
if (description.length > 1024) err(`\`description\` is ${description.length} characters; the limit is 1,024`);
|
|
174
|
-
if (/<[^>]+>/.test(description)) err("`description` can't contain XML tags");
|
|
175
|
-
}
|
|
176
|
-
const size = skill.files.reduce((total, f) => total + f.bytes.length, 0);
|
|
177
|
-
if (size > MAX_UPLOAD_BYTES) errors.push(`${skill.path}: its files add up to ${Math.ceil(size / 1024 / 1024)} MB; the limit is 30 MB`);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
const mcpServers = (agent) => (Array.isArray(agent.data.mcp_servers) ? agent.data.mcp_servers.filter(isObject) : []);
|
|
181
|
-
|
|
182
|
-
// Each server agent.md declares needs a toolset file, and each toolset file a declared server;
|
|
183
|
-
// the API rejects an agent otherwise.
|
|
184
|
-
function checkMcpServers(agent, tools, errors) {
|
|
185
|
-
const err = (msg) => errors.push(`${AGENT_FILE}: ${msg}`);
|
|
186
|
-
const names = new Set();
|
|
187
|
-
for (const server of mcpServers(agent)) {
|
|
188
|
-
const label = typeof server.name === "string" && server.name ? `\`${server.name}\`` : "an entry";
|
|
189
|
-
if (server.type !== "url") err(`\`mcp_servers\`: ${label} must have \`type: url\``);
|
|
190
|
-
if (typeof server.name !== "string" || server.name === "" || server.name.length > 255) {
|
|
191
|
-
err("`mcp_servers`: each server needs a `name` of 1 to 255 characters");
|
|
192
|
-
} else if (names.has(server.name)) {
|
|
193
|
-
err(`\`mcp_servers\`: \`${server.name}\` is declared twice`);
|
|
194
|
-
}
|
|
195
|
-
if (typeof server.url !== "string" || !/^https?:\/\/\S+$/.test(server.url) || server.url.length > 2048) {
|
|
196
|
-
err(`\`mcp_servers\`: ${label} needs a \`url\`, an http(s) URL of at most 2048 characters`);
|
|
197
|
-
}
|
|
198
|
-
names.add(server.name);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
const toolsets = tools.filter((t) => t.data.type === MCP_TOOLSET);
|
|
202
|
-
const covered = new Set(toolsets.map((t) => t.data.mcp_server_name));
|
|
203
|
-
for (const name of names) {
|
|
204
|
-
if (typeof name === "string" && name && !covered.has(name)) {
|
|
205
|
-
err(`\`mcp_servers\`: \`${name}\` has no toolset; add ${TOOLS_DIR}/${name}.md with \`type: mcp_toolset\`, or the API rejects the agent`);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
for (const toolset of toolsets) {
|
|
209
|
-
const name = toolset.data.mcp_server_name;
|
|
210
|
-
if (typeof name === "string" && name && !names.has(name)) {
|
|
211
|
-
errors.push(`${toolset.file}: \`${name}\` isn't in ${AGENT_FILE}'s \`mcp_servers\``);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
// A limited network blocks MCP servers that aren't allowed, and the API then refuses to start sessions.
|
|
217
|
-
function checkMcpNetworking(agent, env, warnings) {
|
|
218
|
-
const net = env.data.config?.networking;
|
|
219
|
-
if (net?.type !== "limited" || net.allow_mcp_servers === true) return;
|
|
220
|
-
const allowed = net.allowed_hosts ?? [];
|
|
221
|
-
for (const server of mcpServers(agent)) {
|
|
222
|
-
let host;
|
|
223
|
-
try {
|
|
224
|
-
host = new URL(server.url).host;
|
|
225
|
-
} catch {
|
|
226
|
-
continue;
|
|
227
|
-
}
|
|
228
|
-
if (!allowed.includes(host)) {
|
|
229
|
-
warnings.push(
|
|
230
|
-
`${ENV_FILE}: its limited networking doesn't allow MCP server \`${server.name}\` (${host}), so sessions won't start; ` +
|
|
231
|
-
`set config.networking.allow_mcp_servers to true, or add ${host} to allowed_hosts`,
|
|
232
|
-
);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
function checkVault(vault, errors, warnings) {
|
|
238
|
-
if (vault.name.length > 255) errors.push(`${vault.path}: a vault's name (its folder name) must be at most 255 characters`);
|
|
239
|
-
|
|
240
|
-
if (vault.file) {
|
|
241
|
-
const file = `${vault.path}/${VAULT_FILE}`;
|
|
242
|
-
const err = (msg) => errors.push(`${file}: ${msg}`);
|
|
243
|
-
const { data } = vault.file;
|
|
244
|
-
if ("display_name" in data) err("`display_name` is not allowed; the folder name is the vault's name");
|
|
245
|
-
checkMetadata(data.metadata, 16, err);
|
|
246
|
-
for (const key of Object.keys(data)) {
|
|
247
|
-
if (key !== "metadata" && key !== "display_name") warnings.push(`${file}: unknown field \`${key}\` will be sent to the API as written`);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
if (vault.credentials.length > 20) errors.push(`${vault.path}: ${vault.credentials.length} credentials; a vault holds at most 20`);
|
|
252
|
-
const urls = new Map();
|
|
253
|
-
const secretNames = new Map();
|
|
254
|
-
for (const cred of vault.credentials) {
|
|
255
|
-
checkCredential(cred, errors, warnings);
|
|
256
|
-
const url = cred.data.auth?.mcp_server_url;
|
|
257
|
-
if (typeof url === "string") {
|
|
258
|
-
if (urls.has(url)) errors.push(`${cred.file}: ${urls.get(url)} is already a credential for ${url}; a vault holds one per server`);
|
|
259
|
-
else urls.set(url, cred.file);
|
|
260
|
-
}
|
|
261
|
-
const secretName = cred.data.auth?.secret_name;
|
|
262
|
-
if (typeof secretName === "string") {
|
|
263
|
-
if (secretNames.has(secretName)) errors.push(`${cred.file}: ${secretNames.get(secretName)} already sets ${secretName}; a vault holds one per variable`);
|
|
264
|
-
else secretNames.set(secretName, cred.file);
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
// What an environment variable credential depends on outside its own file.
|
|
270
|
-
function checkEnvVarCredentials(vaults, env, warnings) {
|
|
271
|
-
const creds = vaults.flatMap((v) => v.credentials).filter((c) => c.data.auth?.type === ENV_VAR);
|
|
272
|
-
const net = env?.data.config?.networking;
|
|
273
|
-
const seen = new Map();
|
|
274
|
-
for (const cred of creds) {
|
|
275
|
-
const warn = (msg) => warnings.push(`${cred.file}: ${msg}`);
|
|
276
|
-
const { secret_name: name, networking } = cred.data.auth;
|
|
277
|
-
|
|
278
|
-
// Two vaults can both set a variable, but the docs don't say which one wins.
|
|
279
|
-
if (typeof name === "string") {
|
|
280
|
-
if (seen.has(name) && seen.get(name).vault !== cred.vault) warn(`${seen.get(name).file} also sets ${name}, and the API doesn't document which vault wins`);
|
|
281
|
-
else seen.set(name, cred);
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
if (env?.data.config?.type === "self_hosted") warn("environment variable credentials aren't supported on self-hosted environments yet");
|
|
285
|
-
|
|
286
|
-
// allowed_hosts only decides where the secret is substituted; the environment decides what's reachable.
|
|
287
|
-
if (net?.type === "limited" && networking?.type === "limited" && Array.isArray(networking.allowed_hosts)) {
|
|
288
|
-
for (const host of networking.allowed_hosts) {
|
|
289
|
-
if (!(net.allowed_hosts ?? []).includes(host)) {
|
|
290
|
-
warn(`${ENV_FILE}'s limited networking doesn't allow ${host}, so requests to it will be blocked; add it to allowed_hosts in ${ENV_FILE}`);
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
function checkCredential(cred, errors, warnings) {
|
|
298
|
-
const err = (msg) => errors.push(`${cred.file}: ${msg}`);
|
|
299
|
-
const warn = (msg) => warnings.push(`${cred.file}: ${msg}`);
|
|
300
|
-
const { data } = cred;
|
|
301
|
-
if (cred.name.length > 255) err("a credential's name (its file name) must be at most 255 characters");
|
|
302
|
-
if ("display_name" in data) err("`display_name` is not allowed; the file name is the credential's name");
|
|
303
|
-
checkMetadata(data.metadata, 16, err);
|
|
304
|
-
for (const key of Object.keys(data)) {
|
|
305
|
-
if (!["auth", "metadata", "display_name"].includes(key)) warn(`unknown field \`${key}\` will be sent to the API as written`);
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
const { auth } = data;
|
|
309
|
-
if (!isObject(auth)) return err("`auth` is required");
|
|
310
|
-
if (!CREDENTIAL_TYPES.includes(auth.type)) return err(`\`auth.type\` must be ${CREDENTIAL_TYPES.map((t) => `\`${t}\``).join(" or ")}; other credential types aren't supported yet`);
|
|
311
|
-
|
|
312
|
-
for (const path of SECRET_FIELDS[auth.type]) {
|
|
313
|
-
if (get(auth, path) !== undefined) {
|
|
314
|
-
err(`\`auth.${path.join(".")}\` doesn't go in the file; \`agentschema cred deploy\` asks for it and sends it straight to the vault`);
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
if (auth.type === ENV_VAR) return checkEnvVarAuth(auth, err, warn);
|
|
319
|
-
|
|
320
|
-
const url = (value, field) => {
|
|
321
|
-
if (typeof value !== "string" || value === "") return err(`\`${field}\` is required`);
|
|
322
|
-
if (!/^https?:\/\/\S+$/.test(value)) err(`\`${field}\` must be an http(s) URL`);
|
|
323
|
-
};
|
|
324
|
-
url(auth.mcp_server_url, "auth.mcp_server_url");
|
|
325
|
-
for (const key of Object.keys(auth)) {
|
|
326
|
-
if (!["type", "mcp_server_url", "refresh", "access_token", "expires_at"].includes(key)) {
|
|
327
|
-
warn(`unknown field \`auth.${key}\` will be sent to the API as written`);
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
if (auth.refresh === undefined || auth.refresh === null) return;
|
|
332
|
-
const { refresh } = auth;
|
|
333
|
-
if (!isObject(refresh)) return err("`auth.refresh` must be a mapping");
|
|
334
|
-
url(refresh.token_endpoint, "auth.refresh.token_endpoint");
|
|
335
|
-
if (typeof refresh.client_id !== "string" || refresh.client_id === "") err("`auth.refresh.client_id` is required, as a string (quote it if it looks like a number)");
|
|
336
|
-
for (const field of ["scope", "resource"]) {
|
|
337
|
-
if (refresh[field] !== undefined && typeof refresh[field] !== "string") err(`\`auth.refresh.${field}\` must be a string`);
|
|
338
|
-
}
|
|
339
|
-
if (!isObject(refresh.token_endpoint_auth) || !TOKEN_ENDPOINT_AUTH.includes(refresh.token_endpoint_auth.type)) {
|
|
340
|
-
err(`\`auth.refresh.token_endpoint_auth.type\` must be ${TOKEN_ENDPOINT_AUTH.map((t) => `\`${t}\``).join(", ")}`);
|
|
341
|
-
}
|
|
342
|
-
for (const key of Object.keys(refresh)) {
|
|
343
|
-
if (!["token_endpoint", "client_id", "scope", "resource", "token_endpoint_auth", "refresh_token"].includes(key)) {
|
|
344
|
-
warn(`unknown field \`auth.refresh.${key}\` will be sent to the API as written`);
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
function checkEnvVarAuth(auth, err, warn) {
|
|
350
|
-
if (typeof auth.secret_name !== "string" || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(auth.secret_name)) {
|
|
351
|
-
err("`auth.secret_name` is required, and must be a variable name like STRIPE_API_KEY");
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
const { networking: net, injection_location: where } = auth;
|
|
355
|
-
if (!isObject(net) || !["limited", "unrestricted"].includes(net.type)) {
|
|
356
|
-
err("`auth.networking.type` is required, and must be `limited` or `unrestricted`");
|
|
357
|
-
} else if (net.type === "unrestricted") {
|
|
358
|
-
warn("`auth.networking` is `unrestricted`, so the secret is substituted on requests to any host; a prompt-injected agent could send it anywhere");
|
|
359
|
-
} else if (!Array.isArray(net.allowed_hosts) || net.allowed_hosts.length === 0 || net.allowed_hosts.some((h) => typeof h !== "string" || h === "")) {
|
|
360
|
-
err("`auth.networking.allowed_hosts` must list the hosts the secret may be sent to");
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
if (where !== undefined && where !== null) {
|
|
364
|
-
if (!isObject(where)) err("`auth.injection_location` must be a mapping");
|
|
365
|
-
else {
|
|
366
|
-
for (const field of ["header", "body"]) {
|
|
367
|
-
if (where[field] !== undefined && typeof where[field] !== "boolean") err(`\`auth.injection_location.${field}\` must be true or false`);
|
|
368
|
-
}
|
|
369
|
-
if (where.header !== true && where.body !== true) err("`auth.injection_location` must enable `header` or `body`; a field you leave out is false");
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
for (const key of Object.keys(auth)) {
|
|
374
|
-
if (!["type", "secret_name", "secret_value", "networking", "injection_location"].includes(key)) {
|
|
375
|
-
warn(`unknown field \`auth.${key}\` will be sent to the API as written`);
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
function checkMetadata(metadata, maxKeys, err) {
|
|
381
|
-
if (metadata === undefined) return;
|
|
382
|
-
if (!isObject(metadata)) return err("`metadata` must be a mapping");
|
|
383
|
-
const keys = Object.keys(metadata);
|
|
384
|
-
if (keys.length > maxKeys) err(`\`metadata\` has ${keys.length} keys; the limit is ${maxKeys}`);
|
|
385
|
-
for (const key of keys) {
|
|
386
|
-
if (typeof metadata[key] !== "string") err(`\`metadata.${key}\` must be a string (quote numbers and booleans)`);
|
|
387
|
-
}
|
|
388
|
-
}
|
package/lib/instance.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { textOf } from "./files.js";
|
|
2
|
-
import { FileError, parseMarkdown } from "./markdown.js";
|
|
3
|
-
import { systemPromptOf } from "./system-prompt.js";
|
|
4
|
-
import { compileTools } from "./tools.js";
|
|
5
|
-
|
|
6
|
-
export const AGENT_FILE = "agent.md";
|
|
7
|
-
export const ENV_FILE = "env.md";
|
|
8
|
-
|
|
9
|
-
// Reads agent.md and env.md. Returns { agent, env, errors }; a file that can't be read is null
|
|
10
|
-
// and has an entry in errors.
|
|
11
|
-
export function readInstance(files) {
|
|
12
|
-
const names = Object.keys(files).filter((path) => !path.includes("/"));
|
|
13
|
-
const errors = [];
|
|
14
|
-
const read = (name) => {
|
|
15
|
-
try {
|
|
16
|
-
// Exact names only, so an agent behaves the same on a case-sensitive file system.
|
|
17
|
-
if (!names.includes(name)) {
|
|
18
|
-
const wrongCase = names.find((n) => n.toLowerCase() === name);
|
|
19
|
-
const hint = wrongCase ? ` (found ${wrongCase}; the name must be lowercase)` : "";
|
|
20
|
-
throw new FileError(`${name}: missing${hint}`);
|
|
21
|
-
}
|
|
22
|
-
return parseMarkdown(textOf(files[name]), name);
|
|
23
|
-
} catch (err) {
|
|
24
|
-
if (!(err instanceof FileError)) throw err;
|
|
25
|
-
errors.push(err.message);
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
return { agent: read(AGENT_FILE), env: read(ENV_FILE), errors };
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// The bodies sent to POST /v1/agents and POST /v1/environments.
|
|
33
|
-
// The agent's tools come from tools/, compiled into the API's `tools` list. `skills` are the
|
|
34
|
-
// references to the skills deployed from skills/, added to any in agent.md's frontmatter. The system
|
|
35
|
-
// prompt is agent.md's body, then system_prompt/'s files.
|
|
36
|
-
// `options.toolsets` is the catalog behind `type: agentbook` tool files.
|
|
37
|
-
export function agentBody(instance, skills = [], options = {}) {
|
|
38
|
-
const { agent, tools } = instance;
|
|
39
|
-
const body = { ...agent.data, tools: compileTools(tools, options) };
|
|
40
|
-
if (skills.length > 0) body.skills = [...(agent.data.skills ?? []), ...skills];
|
|
41
|
-
const system = systemPromptOf(instance);
|
|
42
|
-
if (system) body.system = system;
|
|
43
|
-
return body;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function envBody({ env }) {
|
|
47
|
-
return { ...env.data };
|
|
48
|
-
}
|
package/lib/markdown.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { parseDocument } from "yaml";
|
|
2
|
-
|
|
3
|
-
export class FileError extends Error {}
|
|
4
|
-
|
|
5
|
-
// Splits a Markdown file into YAML frontmatter (between `---` fences) and body.
|
|
6
|
-
export function parseMarkdown(text, file) {
|
|
7
|
-
const normalized = normalize(text);
|
|
8
|
-
if (!normalized.startsWith("---\n")) {
|
|
9
|
-
throw new FileError(`${file}: must start with YAML frontmatter between --- lines`);
|
|
10
|
-
}
|
|
11
|
-
const closing = /^---[ \t]*$/m.exec(normalized.slice(4));
|
|
12
|
-
if (!closing) throw new FileError(`${file}: frontmatter is not closed with a --- line`);
|
|
13
|
-
const end = 4 + closing.index;
|
|
14
|
-
const afterFence = normalized.slice(end + closing[0].length);
|
|
15
|
-
|
|
16
|
-
const doc = parseDocument(normalized.slice(4, end));
|
|
17
|
-
if (doc.errors.length > 0) {
|
|
18
|
-
// The YAML library counts lines from the start of the frontmatter; +1 for the opening fence.
|
|
19
|
-
const err = doc.errors[0];
|
|
20
|
-
const line = err.linePos?.[0]?.line;
|
|
21
|
-
const where = line ? `:${line + 1}` : "";
|
|
22
|
-
throw new FileError(`${file}${where}: invalid YAML: ${err.message.split("\n")[0]}`);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const data = doc.toJS() ?? {};
|
|
26
|
-
if (typeof data !== "object" || Array.isArray(data)) {
|
|
27
|
-
throw new FileError(`${file}: frontmatter must be a YAML mapping (key: value pairs)`);
|
|
28
|
-
}
|
|
29
|
-
return { data, body: afterFence.trim(), raw: text };
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// Edits a file's frontmatter through `edit(doc)`, keeping its comments and the rest of the file.
|
|
33
|
-
// Returns the new text.
|
|
34
|
-
export function editFrontmatter(text, edit) {
|
|
35
|
-
const normalized = normalize(text);
|
|
36
|
-
const end = 4 + /^---[ \t]*$/m.exec(normalized.slice(4)).index;
|
|
37
|
-
const doc = parseDocument(normalized.slice(4, end));
|
|
38
|
-
edit(doc);
|
|
39
|
-
return `---\n${doc.toString({ lineWidth: 0 })}${normalized.slice(end)}`;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const normalize = (text) => text.replace(/^/, "").replace(/\r\n/g, "\n");
|
package/lib/scaffold.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { stringify } from "yaml";
|
|
2
|
-
import { AGENT_FILE, ENV_FILE } from "./instance.js";
|
|
3
|
-
import { PREBUILT_TOOLS, TOOLSET, TOOLSET_FILE, TOOLS_DIR } from "./tools.js";
|
|
4
|
-
|
|
5
|
-
export const MODELS = ["claude-opus-5-5", "claude-sonnet-5-5", "claude-haiku-5-5"];
|
|
6
|
-
export const NETWORKING = ["limited", "unrestricted"];
|
|
7
|
-
|
|
8
|
-
// The answers used for a new agent called `name`, when a question is skipped.
|
|
9
|
-
export function defaultAnswers(name) {
|
|
10
|
-
const slug = name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "") || "agent";
|
|
11
|
-
return {
|
|
12
|
-
name: slug.split("-").map((w) => w[0].toUpperCase() + w.slice(1)).join(" "),
|
|
13
|
-
model: MODELS[0],
|
|
14
|
-
system: "You are a helpful assistant.",
|
|
15
|
-
tools: true,
|
|
16
|
-
permission: "auto",
|
|
17
|
-
environment: slug,
|
|
18
|
-
networking: "limited",
|
|
19
|
-
packageManagers: true,
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// Returns { path: text } for a set of answers: agent.md, env.md, and tools/agent_toolset_20260401.md
|
|
24
|
-
// listing every pre-built tool when the agent gets them.
|
|
25
|
-
export function scaffold(answers) {
|
|
26
|
-
const agent = { name: answers.name, model: answers.model };
|
|
27
|
-
|
|
28
|
-
const networking = { type: answers.networking };
|
|
29
|
-
if (answers.networking === "limited") networking.allow_package_managers = answers.packageManagers;
|
|
30
|
-
const env = { name: answers.environment, config: { type: "cloud", networking } };
|
|
31
|
-
|
|
32
|
-
const access = answers.networking === "unrestricted"
|
|
33
|
-
? "unrestricted network access"
|
|
34
|
-
: answers.packageManagers ? "limited networking and package manager access" : "limited networking";
|
|
35
|
-
const files = {
|
|
36
|
-
[AGENT_FILE]: `---\n${stringify(agent)}---\n\n${answers.system.trim()}\n`,
|
|
37
|
-
[ENV_FILE]: `---\n${stringify(env)}---\nCloud container with ${access}.\n`,
|
|
38
|
-
};
|
|
39
|
-
if (answers.tools) {
|
|
40
|
-
files[`${TOOLS_DIR}/${TOOLSET_FILE}`] = builtInFile(PREBUILT_TOOLS, PREBUILT_TOOLS, answers.permission);
|
|
41
|
-
}
|
|
42
|
-
return files;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// The pre-built toolset file, with a row for each of `names`: on if it's in `enabled`, each with
|
|
46
|
-
// `permission`, so what's chosen is there to read and change. `auto` is what the API recommends for
|
|
47
|
-
// these tools: Anthropic judges each call, and asks when it can't tell.
|
|
48
|
-
export function builtInFile(names, enabled = names, permission = "auto") {
|
|
49
|
-
const rows = names.map((name) => `| \`${name}\` | \`${enabled.includes(name)}\` | \`${permission}\` |`).join("\n");
|
|
50
|
-
return `---\ntype: ${TOOLSET}\n---\n\nThe tools Claude runs in the agent's container. Set Enabled to false to turn a tool off.\n\n## Tools\n\n| Name | Enabled | Permission |\n|---|---|---|\n${rows}\n`;
|
|
51
|
-
}
|