@soft-boy/agentschema 0.4.0 → 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.
Files changed (93) hide show
  1. package/README.md +8 -2
  2. package/dist/bin/agentschema.d.ts +2 -0
  3. package/dist/bin/agentschema.js +333 -0
  4. package/dist/lib/channels.d.ts +65 -0
  5. package/dist/lib/channels.js +339 -0
  6. package/dist/lib/check.d.ts +10 -0
  7. package/dist/lib/check.js +411 -0
  8. package/dist/lib/files.d.ts +7 -0
  9. package/{lib → dist/lib}/files.js +10 -14
  10. package/dist/lib/index.d.ts +24 -0
  11. package/{lib → dist/lib}/index.js +3 -12
  12. package/dist/lib/instance.d.ts +41 -0
  13. package/dist/lib/instance.js +74 -0
  14. package/dist/lib/markdown.d.ts +11 -0
  15. package/dist/lib/markdown.js +38 -0
  16. package/dist/lib/scaffold.d.ts +15 -0
  17. package/dist/lib/scaffold.js +46 -0
  18. package/dist/lib/scheduled.d.ts +56 -0
  19. package/dist/lib/scheduled.js +185 -0
  20. package/dist/lib/skills.d.ts +28 -0
  21. package/dist/lib/skills.js +55 -0
  22. package/dist/lib/stream.d.ts +30 -0
  23. package/dist/lib/stream.js +56 -0
  24. package/dist/lib/system-prompt.d.ts +16 -0
  25. package/{lib → dist/lib}/system-prompt.js +14 -15
  26. package/dist/lib/tools.d.ts +105 -0
  27. package/dist/lib/tools.js +353 -0
  28. package/dist/lib/vaults.d.ts +55 -0
  29. package/dist/lib/vaults.js +143 -0
  30. package/dist/src/chat.d.ts +15 -0
  31. package/dist/src/chat.js +159 -0
  32. package/dist/src/check.d.ts +2 -0
  33. package/dist/src/check.js +14 -0
  34. package/dist/src/cred-menu.d.ts +17 -0
  35. package/dist/src/cred-menu.js +193 -0
  36. package/dist/src/cred.d.ts +54 -0
  37. package/dist/src/cred.js +252 -0
  38. package/dist/src/custom-tools.d.ts +3 -0
  39. package/dist/src/custom-tools.js +18 -0
  40. package/dist/src/delete.d.ts +9 -0
  41. package/dist/src/delete.js +27 -0
  42. package/dist/src/deploy.d.ts +62 -0
  43. package/dist/src/deploy.js +442 -0
  44. package/dist/src/dotenv.d.ts +7 -0
  45. package/dist/src/dotenv.js +54 -0
  46. package/dist/src/folder.d.ts +5 -0
  47. package/{src → dist/src}/folder.js +30 -28
  48. package/dist/src/init.d.ts +11 -0
  49. package/dist/src/init.js +51 -0
  50. package/dist/src/list.d.ts +3 -0
  51. package/dist/src/list.js +46 -0
  52. package/dist/src/lock.d.ts +10 -0
  53. package/dist/src/lock.js +37 -0
  54. package/dist/src/mcp.d.ts +11 -0
  55. package/dist/src/mcp.js +79 -0
  56. package/dist/src/node.d.ts +14 -0
  57. package/dist/src/oauth.d.ts +64 -0
  58. package/dist/src/oauth.js +208 -0
  59. package/dist/src/prompts.d.ts +18 -0
  60. package/dist/src/prompts.js +166 -0
  61. package/dist/src/session.d.ts +58 -0
  62. package/dist/src/session.js +200 -0
  63. package/dist/src/tools-menu.d.ts +8 -0
  64. package/dist/src/tools-menu.js +173 -0
  65. package/package.json +21 -9
  66. package/bin/agentschema.js +0 -326
  67. package/lib/channels.js +0 -338
  68. package/lib/check.js +0 -387
  69. package/lib/instance.js +0 -75
  70. package/lib/markdown.js +0 -42
  71. package/lib/scaffold.js +0 -51
  72. package/lib/scheduled.js +0 -175
  73. package/lib/skills.js +0 -58
  74. package/lib/stream.js +0 -50
  75. package/lib/tools.js +0 -327
  76. package/lib/vaults.js +0 -142
  77. package/src/chat.js +0 -156
  78. package/src/check.js +0 -14
  79. package/src/cred-menu.js +0 -197
  80. package/src/cred.js +0 -263
  81. package/src/custom-tools.js +0 -17
  82. package/src/delete.js +0 -25
  83. package/src/deploy.js +0 -441
  84. package/src/dotenv.js +0 -50
  85. package/src/init.js +0 -54
  86. package/src/list.js +0 -49
  87. package/src/lock.js +0 -40
  88. package/src/mcp.js +0 -76
  89. package/src/oauth.js +0 -215
  90. package/src/prompts.js +0 -159
  91. package/src/session.js +0 -194
  92. package/src/tools-menu.js +0 -163
  93. /package/{src → dist/src}/node.js +0 -0
package/src/tools-menu.js DELETED
@@ -1,163 +0,0 @@
1
- import { existsSync, mkdirSync, writeFileSync } from "node:fs";
2
- import { dirname, join } from "node:path";
3
- import { stringify } from "yaml";
4
- import { check } from "./check.js";
5
- import { serviceName } from "./cred-menu.js";
6
- import { DeployError } from "./deploy.js";
7
- import { AGENT_FILE, COMPUTER_FILE, OLD_COMPUTER_FILE } from "../lib/instance.js";
8
- import { builtInFile } from "../lib/scaffold.js";
9
- import { updateFrontmatter } from "./folder.js";
10
- import { listMcpTools } from "./mcp.js";
11
- import { MCP_TOOLSET, POLICIES, PREBUILT_TOOLS, TOOLSET, TOOLSET_FILE, TOOLS_DIR, mcpToolsetFile } from "../lib/tools.js";
12
-
13
- const PREBUILT = "Pre-built tools (bash, files, web search)";
14
- const CUSTOM = "Custom tool (JavaScript that runs on your machine)";
15
- const MCP = "MCP server";
16
- const INPUT_TYPES = ["string", "number", "integer", "boolean", "object", "string[]", "number[]", "integer[]", "boolean[]", "object[]"];
17
-
18
- // `tools create`: asks what kind of tool to add, then writes its file in tools/.
19
- // Returns the path of the file written.
20
- export async function toolsCreate(dir = ".", { io, fetch = globalThis.fetch, log = () => {} }) {
21
- const { errors, instance } = check(dir);
22
- if (!instance) throw new DeployError(`${dir} isn't an agent folder:\n ${errors.join("\n ")}`);
23
-
24
- const kind = await io.select("What kind of tool?", [PREBUILT, CUSTOM, MCP], PREBUILT);
25
- const write = kind === PREBUILT ? prebuilt : kind === CUSTOM ? custom : mcp;
26
- const { path, text, addServer } = await write(dir, instance, io, { fetch, log });
27
-
28
- const file = join(dir, path);
29
- mkdirSync(dirname(file), { recursive: true });
30
- writeFileSync(file, text);
31
- log(`Wrote ${file}`);
32
- if (addServer) {
33
- updateFrontmatter(join(dir, AGENT_FILE), (doc) => {
34
- if (doc.hasIn(["mcp_servers"])) doc.addIn(["mcp_servers"], doc.createNode(addServer));
35
- else doc.setIn(["mcp_servers"], doc.createNode([addServer]));
36
- });
37
- log(`Added ${addServer.name} to mcp_servers in ${join(dir, AGENT_FILE)}`);
38
- }
39
-
40
- const after = check(dir);
41
- const related = (m) => m.startsWith(path) || (kind === MCP && [AGENT_FILE, COMPUTER_FILE, OLD_COMPUTER_FILE].some((file) => m.startsWith(file)));
42
- for (const w of after.warnings.filter(related)) log(`warning: ${w}`);
43
- for (const e of after.errors.filter(related)) log(`error: ${e}`);
44
- if (kind === CUSTOM) log(`\nWrite the tool's code in its ## Code block, then deploy with:\n agentschema deploy ${dir}`);
45
- else if (kind === MCP) log(`\nIf the server needs you to sign in, add a credential for it:\n agentschema cred create ${dir}\nThen deploy with:\n agentschema deploy ${dir}`);
46
- else log(`\nDeploy with:\n agentschema deploy ${dir}`);
47
- return file;
48
- }
49
-
50
- // The pre-built toolset: one file, with a row for each tool.
51
- async function prebuilt(dir, { tools }, io) {
52
- const existing = tools.find((t) => t.data.type === TOOLSET);
53
- if (existing) throw new DeployError(`the agent already has its pre-built tools in ${existing.file}; edit that file's table to turn tools on or off`);
54
-
55
- let enabled = PREBUILT_TOOLS;
56
- if (!(await io.confirm(`Turn on all eight (${PREBUILT_TOOLS.join(", ")})?`, true))) {
57
- enabled = [];
58
- for (const name of PREBUILT_TOOLS) if (await io.confirm(` ${name}?`, true)) enabled.push(name);
59
- }
60
- return { path: `${TOOLS_DIR}/${TOOLSET_FILE}`, text: builtInFile(PREBUILT_TOOLS, enabled, await choosePermission(io, "auto")) };
61
- }
62
-
63
- // A custom tool: its name, description and inputs, with a code block to fill in.
64
- async function custom(dir, { tools }, io) {
65
- const taken = new Set(tools.filter((t) => t.data.type === "custom").map((t) => t.name));
66
- const name = await io.text("Tool name? (letters, digits, _ and -)", "", {
67
- validate: (n) => {
68
- if (!/^[a-zA-Z0-9_-]{1,64}$/.test(n)) return "Use letters, digits, _ and -, up to 64 characters";
69
- if (PREBUILT_TOOLS.includes(n)) return `${n} is a pre-built tool's name`;
70
- if (/^(mcp__|ant__)/.test(n)) return "A custom tool's name can't start with mcp__ or ant__";
71
- if (taken.has(n) || existsSync(join(dir, TOOLS_DIR, `${n}.md`))) return `There's already a tool called ${n}`;
72
- return null;
73
- },
74
- });
75
- const description = await io.text("What does it do? (Claude reads this to decide when to call it)", "", {
76
- validate: (d) => (d ? null : "The description is required"),
77
- });
78
-
79
- const inputs = [];
80
- while (true) {
81
- const input = await io.text(inputs.length === 0 ? "First input's name? (Enter for none)" : "Next input's name? (Enter when done)", "", {
82
- validate: (n) => {
83
- if (n && !/^[a-zA-Z_$][\w$]*$/.test(n)) return "Use a name like city or max_results";
84
- if (inputs.some((i) => i.name === n)) return `${n} is already an input`;
85
- return null;
86
- },
87
- });
88
- if (!input) break;
89
- const type = await io.select(` ${input}'s type?`, INPUT_TYPES, "string");
90
- const about = await io.text(` ${input}'s description?`, "");
91
- const required = await io.confirm(` Is ${input} required?`, true);
92
- inputs.push({ name: input, type, about, required });
93
- }
94
-
95
- const cell = (s) => s.replace(/\|/g, "\\|");
96
- const table = inputs.length === 0 ? "" : [
97
- "## Input Schema", "",
98
- "| Name | Type | Description | Required |",
99
- "|---|---|---|---|",
100
- ...inputs.map((i) => `| \`${i.name}\` | \`${i.type}\` | ${cell(i.about)} | \`${i.required}\` |`),
101
- "", "",
102
- ].join("\n");
103
- const args = inputs.length === 0 ? "()" : `({ ${inputs.map((i) => i.name).join(", ")} })`;
104
- const code = [
105
- "## Code", "",
106
- "```javascript",
107
- `module.exports = async ${args} => {`,
108
- ` throw new Error("${name} isn't implemented yet");`,
109
- "};",
110
- "```", "",
111
- ].join("\n");
112
-
113
- const front = stringify({ type: "custom", name, description });
114
- return { path: `${TOOLS_DIR}/${name}.md`, text: `---\n${front}---\n\n${table}${code}` };
115
- }
116
-
117
- // An MCP server: its URL and name, how its tools are approved, and a table of those tools.
118
- // The server itself is declared in agent.md; a server already declared there only needs its file.
119
- async function mcp(dir, instance, io, { fetch, log }) {
120
- const { tools, agent } = instance;
121
- const declared = Array.isArray(agent.data.mcp_servers) ? agent.data.mcp_servers : [];
122
- const toolsets = new Set(tools.filter((t) => t.data.type === MCP_TOOLSET).map((t) => t.data.mcp_server_name));
123
- const url = await io.text("MCP server URL?", "", {
124
- validate: (u) => {
125
- if (!/^https?:\/\/\S+$/.test(u)) return "Enter an http(s) URL";
126
- const same = declared.find((s) => s?.url === u);
127
- return same && toolsets.has(same.name) ? `${AGENT_FILE} already declares that server, as ${same.name}` : null;
128
- },
129
- });
130
- const existing = declared.find((s) => s?.url === url);
131
- const name = existing?.name ?? await io.text("Name for it?", serviceName(url).toLowerCase(), {
132
- validate: (n) => {
133
- if (!n || /[/\\]/.test(n) || n.startsWith(".")) return "Use a name without / that doesn't start with .";
134
- if (declared.some((s) => s?.name === n)) return `${AGENT_FILE} already declares a server called ${n}`;
135
- if (existsSync(join(dir, TOOLS_DIR, `${n}.md`))) return `There's already a tool file called ${n}.md`;
136
- return null;
137
- },
138
- });
139
- const addServer = existing ? null : { type: "url", name, url };
140
-
141
- const permission = await choosePermission(io, "always_ask");
142
-
143
- log(`Asking ${url} for its tools…`);
144
- const names = await listMcpTools(url, { fetch });
145
- if (names) log(`It has ${names.length} tool${names.length === 1 ? "" : "s"}.`);
146
- else log("It won't list its tools without signing in, so they'll be listed once you have; until then, every tool is on.");
147
- return { path: `${TOOLS_DIR}/${name}.md`, text: mcpToolsetFile({ name, tools: names ?? [], permission }), addServer };
148
- }
149
-
150
- // Asks how a set of tools should be approved, offering `recommended` first.
151
- export async function choosePermission(io, recommended) {
152
- const policies = [recommended, ...POLICIES.filter((p) => p !== recommended)];
153
- const answer = await io.select("Ask you before each call? (permission for its tools)", policies.map(describePolicy), describePolicy(recommended));
154
- return policies.find((p) => describePolicy(p) === answer);
155
- }
156
-
157
- function describePolicy(policy) {
158
- return {
159
- always_ask: "always_ask: ask before every call (the API's default for MCP tools)",
160
- always_allow: "always_allow: never ask",
161
- auto: "auto: Anthropic decides per call, and asks when it can't",
162
- }[policy];
163
- }
File without changes