@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
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
import { pathsUnder, textOf } from "./files.js";
|
|
2
|
+
import { AGENT_FILE } from "./instance.js";
|
|
3
|
+
import { systemPromptOf } from "./system-prompt.js";
|
|
4
|
+
import { FileError, parseMarkdown } from "./markdown.js";
|
|
5
|
+
import { AGENTBOOK, MCP_TOOLSET } from "./tools.js";
|
|
6
|
+
// A channel is a place people can talk to an agent, like Telegram or SMS. Its file says how the channel
|
|
7
|
+
// should behave, and a host that's always on (Agentbook, say) does the connecting, because Anthropic
|
|
8
|
+
// doesn't receive these messages and `run` shouldn't either. So nothing here is sent to the API.
|
|
9
|
+
export const CHANNELS_DIR = "channels";
|
|
10
|
+
export const ANYONE = "*";
|
|
11
|
+
const DEFAULT_RESPOND_TO = ["direct", "mention"];
|
|
12
|
+
const DEFAULT_EXPIRES_AFTER = "24h";
|
|
13
|
+
// An email thread can go quiet for days and still be one conversation.
|
|
14
|
+
const EMAIL_EXPIRES_AFTER = "7d";
|
|
15
|
+
const RESPOND_TO = ["direct", "mention", "reply", "all"];
|
|
16
|
+
const LIMITS = ["messages_per_sender_per_hour", "messages_per_day", "messages_sent_per_hour"];
|
|
17
|
+
const SHARED_FIELDS = ["type", "enabled", "allow", "respond_to", "scope", "expires_after", "approvals", "limits", "greeting"];
|
|
18
|
+
const MAX_GREETING = 1000;
|
|
19
|
+
const MAX_SYSTEM_PROMPT = 100_000;
|
|
20
|
+
const code = (value) => `\`${value}\``;
|
|
21
|
+
const isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
22
|
+
// Phone numbers and long IDs read as numbers in YAML if they aren't quoted, which loses the +.
|
|
23
|
+
const matches = (pattern, what) => (value) => {
|
|
24
|
+
if (typeof value === "string" && pattern.test(value))
|
|
25
|
+
return null;
|
|
26
|
+
return `must be ${what}${typeof value === "number" ? " (put it in quotes, or YAML reads it as a number)" : ""}`;
|
|
27
|
+
};
|
|
28
|
+
const oneOf = (...values) => (value) => (values.includes(value) ? null : `must be ${values.map(code).join(" or ")}`);
|
|
29
|
+
const text = (value) => (typeof value === "string" && value.trim() !== "" ? null : "must be text");
|
|
30
|
+
const listOf = (check) => (value) => {
|
|
31
|
+
if (!Array.isArray(value))
|
|
32
|
+
return "must be a list";
|
|
33
|
+
return value.map(check).find(Boolean) ?? null;
|
|
34
|
+
};
|
|
35
|
+
const PHONE = /^\+[1-9]\d{6,14}$/;
|
|
36
|
+
const DISCORD_ID = /^\d{17,20}$/;
|
|
37
|
+
const EMAIL = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
38
|
+
const EMAIL_ALLOW = matches(/^(\*|[^\s@]+)@[^\s@]+\.[^\s@]+$/, "an email address, or *@ and a domain");
|
|
39
|
+
// What differs between channels. Each `secrets` entry is something the host asks for and keeps: never
|
|
40
|
+
// the file, and never a vault, because a vault's secrets can't be read back to send a reply. The first
|
|
41
|
+
// of `scopes` is the default. `identity` is what two files in one agent can't share, where that's known.
|
|
42
|
+
// `expiresAfter` is the default for `expires_after`, where it isn't the usual one.
|
|
43
|
+
export const CHANNEL_TYPES = {
|
|
44
|
+
telegram: {
|
|
45
|
+
secrets: ["bot_token"],
|
|
46
|
+
scopes: ["sender", "room"],
|
|
47
|
+
approvals: ["deny", "sender"],
|
|
48
|
+
hasGroups: true,
|
|
49
|
+
allow: matches(/^(\d+|@[A-Za-z0-9_]{5,32})$/, "a numeric user ID or an @username"),
|
|
50
|
+
fields: {},
|
|
51
|
+
},
|
|
52
|
+
twilio: {
|
|
53
|
+
secrets: ["account_sid", "auth_token"],
|
|
54
|
+
scopes: ["sender"],
|
|
55
|
+
approvals: ["deny", "sender"],
|
|
56
|
+
hasGroups: false,
|
|
57
|
+
allow: matches(PHONE, "a phone number like +14155550123"),
|
|
58
|
+
fields: {
|
|
59
|
+
transport: { required: true, check: oneOf("sms", "whatsapp") },
|
|
60
|
+
from: { required: true, check: matches(PHONE, "a phone number like +14155550123") },
|
|
61
|
+
},
|
|
62
|
+
identity: ({ transport, from }) => `${transport} ${from}`,
|
|
63
|
+
},
|
|
64
|
+
sendgrid: {
|
|
65
|
+
secrets: ["api_key"],
|
|
66
|
+
scopes: ["thread", "sender"],
|
|
67
|
+
// An email has no buttons, and its sender can be forged.
|
|
68
|
+
approvals: ["deny"],
|
|
69
|
+
hasGroups: false,
|
|
70
|
+
expiresAfter: EMAIL_EXPIRES_AFTER,
|
|
71
|
+
allow: EMAIL_ALLOW,
|
|
72
|
+
fields: {
|
|
73
|
+
address: { required: true, check: matches(EMAIL, "an email address") },
|
|
74
|
+
from_name: { check: text },
|
|
75
|
+
},
|
|
76
|
+
identity: ({ address }) => address,
|
|
77
|
+
},
|
|
78
|
+
// Email at an address the host gives the agent, such as Agentbook's, so the host sends and receives it
|
|
79
|
+
// and there's nothing to connect. `address` can be left out, for the host to fill in.
|
|
80
|
+
email: {
|
|
81
|
+
secrets: [],
|
|
82
|
+
scopes: ["thread", "sender"],
|
|
83
|
+
approvals: ["deny"],
|
|
84
|
+
hasGroups: false,
|
|
85
|
+
expiresAfter: EMAIL_EXPIRES_AFTER,
|
|
86
|
+
allow: EMAIL_ALLOW,
|
|
87
|
+
fields: {
|
|
88
|
+
address: { check: matches(EMAIL, "an email address") },
|
|
89
|
+
from_name: { check: text },
|
|
90
|
+
},
|
|
91
|
+
identity: ({ address }) => address ?? null,
|
|
92
|
+
},
|
|
93
|
+
slack: {
|
|
94
|
+
secrets: ["bot_token", "signing_secret"],
|
|
95
|
+
scopes: ["thread", "sender", "room"],
|
|
96
|
+
approvals: ["deny", "sender"],
|
|
97
|
+
hasGroups: true,
|
|
98
|
+
allow: matches(/^[UW][A-Z0-9]{2,}$/, "a member ID like U012AB3CD"),
|
|
99
|
+
fields: {
|
|
100
|
+
channels: { check: listOf(matches(/^[CG][A-Z0-9]{2,}$/, "a channel ID like C012AB3CD")) },
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
discord: {
|
|
104
|
+
secrets: ["bot_token"],
|
|
105
|
+
scopes: ["sender", "room"],
|
|
106
|
+
approvals: ["deny", "sender"],
|
|
107
|
+
hasGroups: true,
|
|
108
|
+
allow: matches(DISCORD_ID, "a numeric user ID"),
|
|
109
|
+
fields: {
|
|
110
|
+
application_id: { required: true, check: matches(DISCORD_ID, "a numeric application ID") },
|
|
111
|
+
public_key: { required: true, check: matches(/^[0-9a-f]{64}$/, "the 64-character public key") },
|
|
112
|
+
guilds: { check: listOf(matches(DISCORD_ID, "a numeric server ID")) },
|
|
113
|
+
channels: { check: listOf(matches(DISCORD_ID, "a numeric channel ID")) },
|
|
114
|
+
dedicated_channels: { check: listOf(matches(DISCORD_ID, "a numeric channel ID")) },
|
|
115
|
+
send_to: { check: listOf(matches(DISCORD_ID, "a numeric channel ID")) },
|
|
116
|
+
command: { check: matches(/^[a-z0-9_-]{1,32}$/, "a slash command's name, like ask") },
|
|
117
|
+
},
|
|
118
|
+
identity: ({ application_id: id }) => id,
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
// Reads channels/: each .md file directly inside it is a channel named after the file, so an agent can
|
|
122
|
+
// have two Telegram bots. No channels/ folder means no channels.
|
|
123
|
+
// Returns { channels, errors }; a file that can't be parsed has an entry in errors.
|
|
124
|
+
export function readChannels(files) {
|
|
125
|
+
if (CHANNELS_DIR in files)
|
|
126
|
+
return { channels: [], errors: [`${CHANNELS_DIR}: not a directory`] };
|
|
127
|
+
const channels = [];
|
|
128
|
+
const errors = [];
|
|
129
|
+
const reportedFolders = new Set();
|
|
130
|
+
for (const file of pathsUnder(files, CHANNELS_DIR)) {
|
|
131
|
+
const [, item, ...rest] = file.split("/");
|
|
132
|
+
if (rest.length > 0) {
|
|
133
|
+
const folder = `${CHANNELS_DIR}/${item}`;
|
|
134
|
+
if (!reportedFolders.has(folder))
|
|
135
|
+
errors.push(`${folder}: ${CHANNELS_DIR}/ holds channel files, not folders`);
|
|
136
|
+
reportedFolders.add(folder);
|
|
137
|
+
}
|
|
138
|
+
else if (item.endsWith(".md")) {
|
|
139
|
+
try {
|
|
140
|
+
channels.push({ file, name: item.slice(0, -".md".length), ...parseMarkdown(textOf(files[file]), file) });
|
|
141
|
+
}
|
|
142
|
+
catch (err) {
|
|
143
|
+
if (!(err instanceof FileError))
|
|
144
|
+
throw err;
|
|
145
|
+
errors.push(err.message);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return { channels, errors };
|
|
150
|
+
}
|
|
151
|
+
// Errors and warnings for the channel files, in check's format. `agent` and `tools` are what the channel
|
|
152
|
+
// is attached to, and `toolsets` is the catalog behind `type: agentbook` files.
|
|
153
|
+
export function checkChannels(channels, { agent = { body: "" }, systemPrompt = [], tools = [], toolsets } = {}, errors = [], warnings = []) {
|
|
154
|
+
const unasked = toolsThatRunUnasked(tools, toolsets);
|
|
155
|
+
const identities = new Map();
|
|
156
|
+
// Where each place in a `send_to` came from: only one bot can post there, so it's clear which one does.
|
|
157
|
+
const postedTo = new Map();
|
|
158
|
+
for (const channel of channels) {
|
|
159
|
+
const err = (msg) => errors.push(`${channel.file}: ${msg}`);
|
|
160
|
+
const warn = (msg) => warnings.push(`${channel.file}: ${msg}`);
|
|
161
|
+
const { data, name } = channel;
|
|
162
|
+
// Hosts use the name in webhook addresses and to store the channel's secrets.
|
|
163
|
+
if (!/^[a-z0-9][a-z0-9_-]{0,63}$/.test(name))
|
|
164
|
+
err("the name may only use lowercase letters, digits, _ and -, up to 64 characters");
|
|
165
|
+
const type = Object.hasOwn(CHANNEL_TYPES, data.type) ? CHANNEL_TYPES[data.type] : null;
|
|
166
|
+
if (!type) {
|
|
167
|
+
err(`\`type\` must be ${Object.keys(CHANNEL_TYPES).map(code).join(", ")}`);
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
checkAllow(data, type, err, warn);
|
|
171
|
+
checkShared(data, type, err, warn);
|
|
172
|
+
for (const [field, { required, check }] of Object.entries(type.fields)) {
|
|
173
|
+
if (data[field] === undefined) {
|
|
174
|
+
if (required)
|
|
175
|
+
err(`\`${field}\` is required`);
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
const problem = check(data[field]);
|
|
179
|
+
if (problem)
|
|
180
|
+
err(`\`${field}\` ${problem}`);
|
|
181
|
+
}
|
|
182
|
+
for (const key of Object.keys(data)) {
|
|
183
|
+
if (type.secrets.includes(key))
|
|
184
|
+
err(`\`${key}\` doesn't go in the file; whatever hosts the channel asks for it and keeps it`);
|
|
185
|
+
else if (!SHARED_FIELDS.includes(key) && !Object.hasOwn(type.fields, key))
|
|
186
|
+
err(`unknown field \`${key}\``);
|
|
187
|
+
}
|
|
188
|
+
if (channelSystem({ agent, systemPrompt }, channel).length > MAX_SYSTEM_PROMPT) {
|
|
189
|
+
err(`with ${AGENT_FILE}'s system prompt, this comes to more than ${MAX_SYSTEM_PROMPT.toLocaleString("en-US")} characters; the limit is the API's`);
|
|
190
|
+
}
|
|
191
|
+
const hasRequiredFields = Object.entries(type.fields).every(([field, { required }]) => !required || data[field] !== undefined);
|
|
192
|
+
const own = type.identity && hasRequiredFields ? type.identity(data) : null;
|
|
193
|
+
if (own !== null) {
|
|
194
|
+
const identity = `${data.type} ${own}`;
|
|
195
|
+
if (identities.has(identity))
|
|
196
|
+
err(`${identities.get(identity)} already uses this`);
|
|
197
|
+
else
|
|
198
|
+
identities.set(identity, channel.file);
|
|
199
|
+
}
|
|
200
|
+
if (Array.isArray(data.send_to)) {
|
|
201
|
+
for (const place of data.send_to) {
|
|
202
|
+
if (typeof place !== "string")
|
|
203
|
+
continue;
|
|
204
|
+
if (postedTo.has(place))
|
|
205
|
+
err(`\`send_to\`: ${place} is already in ${postedTo.get(place)}, and only one bot can post there`);
|
|
206
|
+
else
|
|
207
|
+
postedTo.set(place, channel.file);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
if (data.allow === ANYONE && data.enabled !== false && unasked.length > 0) {
|
|
211
|
+
warn(`anyone can message this channel, and these tools can run without asking, through your sign-ins and connections: ${unasked.join(", ")}`);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return { errors, warnings };
|
|
215
|
+
}
|
|
216
|
+
function checkAllow({ allow, approvals }, type, err, warn) {
|
|
217
|
+
if (allow === undefined || allow === null)
|
|
218
|
+
return err(`\`allow\` is required: "${ANYONE}" for anyone, or a list of who can use it`);
|
|
219
|
+
if (allow === ANYONE) {
|
|
220
|
+
if (approvals === "sender")
|
|
221
|
+
err(`\`approvals: sender\` would let anyone approve tools, so it needs \`allow\` to be a list`);
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
if (!Array.isArray(allow))
|
|
225
|
+
return err(`\`allow\` must be "${ANYONE}", or a list of who can use it`);
|
|
226
|
+
if (allow.length === 0)
|
|
227
|
+
return err("`allow` has nobody in it; list who can use it, or set `enabled: false`");
|
|
228
|
+
for (const entry of allow) {
|
|
229
|
+
if (entry === ANYONE)
|
|
230
|
+
return err(`write \`allow: "${ANYONE}"\` on its own, not in a list`);
|
|
231
|
+
const problem = type.allow(entry);
|
|
232
|
+
if (problem)
|
|
233
|
+
err(`\`allow\`: ${JSON.stringify(entry)} ${problem}`);
|
|
234
|
+
else if (typeof entry === "string" && entry.startsWith("@"))
|
|
235
|
+
warn(`\`allow\`: ${entry} can change hands, because Telegram usernames can be given up and reclaimed; a numeric user ID is safer`);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
function checkShared(data, type, err, warn) {
|
|
239
|
+
if (data.enabled !== undefined && typeof data.enabled !== "boolean")
|
|
240
|
+
err("`enabled` must be true or false");
|
|
241
|
+
// An agent can answer only in channels it has to itself, and nowhere else.
|
|
242
|
+
const onlyDedicated = Array.isArray(data.respond_to) && data.respond_to.length === 0 && data.dedicated_channels?.length > 0;
|
|
243
|
+
if (data.respond_to !== undefined && !onlyDedicated) {
|
|
244
|
+
const list = data.respond_to;
|
|
245
|
+
if (!Array.isArray(list) || list.length === 0 || list.some((v) => !RESPOND_TO.includes(v))) {
|
|
246
|
+
err(`\`respond_to\` must be a list of ${RESPOND_TO.map(code).join(", ")}`);
|
|
247
|
+
}
|
|
248
|
+
else if (list.includes("all") && list.length > 1) {
|
|
249
|
+
err("`respond_to`: `all` already covers the others, so list it on its own");
|
|
250
|
+
}
|
|
251
|
+
else if (!type.hasGroups) {
|
|
252
|
+
warn(`\`respond_to\` has no effect on ${data.type}`);
|
|
253
|
+
}
|
|
254
|
+
else if (list.includes("all") && Object.hasOwn(type.fields, "channels") && data.channels === undefined) {
|
|
255
|
+
warn("`respond_to: [all]` answers every message in every channel it can see, and each one costs you a turn; list the ones you mean under `channels`");
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
if (data.scope !== undefined && !type.scopes.includes(data.scope))
|
|
259
|
+
err(`\`scope\` must be ${type.scopes.map(code).join(" or ")} on ${data.type}`);
|
|
260
|
+
if (data.expires_after !== undefined && durationMs(data.expires_after) === null) {
|
|
261
|
+
err("`expires_after` must be a length of time like 30m, 24h or 7d");
|
|
262
|
+
}
|
|
263
|
+
if (data.approvals !== undefined && !type.approvals.includes(data.approvals)) {
|
|
264
|
+
err(`\`approvals\` must be ${type.approvals.map(code).join(" or ")} on ${data.type}`);
|
|
265
|
+
}
|
|
266
|
+
if (data.limits !== undefined) {
|
|
267
|
+
if (!isObject(data.limits))
|
|
268
|
+
err("`limits` must be a mapping");
|
|
269
|
+
else {
|
|
270
|
+
for (const [key, value] of Object.entries(data.limits)) {
|
|
271
|
+
if (!LIMITS.includes(key))
|
|
272
|
+
err(`unknown field \`limits.${key}\`; use ${LIMITS.map(code).join(" or ")}`);
|
|
273
|
+
else if (!Number.isInteger(value) || value < 1)
|
|
274
|
+
err(`\`limits.${key}\` must be a whole number above 0`);
|
|
275
|
+
}
|
|
276
|
+
if (data.limits.messages_sent_per_hour !== undefined && data.send_to === undefined) {
|
|
277
|
+
warn("`limits.messages_sent_per_hour` has no effect without `send_to`");
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
if (data.greeting !== undefined) {
|
|
282
|
+
if (text(data.greeting))
|
|
283
|
+
err("`greeting` must be text");
|
|
284
|
+
else if (data.greeting.length > MAX_GREETING)
|
|
285
|
+
err(`\`greeting\` is ${data.greeting.length} characters; the limit is ${MAX_GREETING.toLocaleString("en-US")}`);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
// The tools that act through the owner's sign-ins and connections without anyone approving each call.
|
|
289
|
+
// Pre-built tools aren't here, since they run in the session's own container. In a toolset's table, a
|
|
290
|
+
// blank permission means the file's default, which for an MCP server is the API's default of asking.
|
|
291
|
+
function toolsThatRunUnasked(tools, toolsets) {
|
|
292
|
+
const isOn = (row) => row.enabled.toLowerCase() === "true";
|
|
293
|
+
return tools.flatMap((tool) => {
|
|
294
|
+
if (tool.data.type === MCP_TOOLSET) {
|
|
295
|
+
const defaults = tool.data.default_config;
|
|
296
|
+
const fallback = defaults?.permission_policy?.type ?? "always_ask";
|
|
297
|
+
if (tool.rows?.length) {
|
|
298
|
+
return tool.rows.filter((row) => isOn(row) && (row.permission || fallback) !== "always_ask").map((row) => `${tool.name}.${row.name}`);
|
|
299
|
+
}
|
|
300
|
+
return fallback !== "always_ask" && defaults?.enabled !== false ? [`every tool in ${tool.name}`] : [];
|
|
301
|
+
}
|
|
302
|
+
if (tool.data.type === AGENTBOOK) {
|
|
303
|
+
const catalog = toolsets?.[tool.data.toolset]?.tools;
|
|
304
|
+
const definition = (row) => catalog?.find((t) => t.name === row.name);
|
|
305
|
+
// A tool that never runs on a live agent can't run here, and one that's safe for anyone needn't be mentioned.
|
|
306
|
+
const isOfNoConcern = (row) => definition(row)?.liveAllowed === false || definition(row)?.safeForAnyone === true;
|
|
307
|
+
return (tool.rows ?? []).filter((row) => isOn(row) && row.permission === "always_allow" && !isOfNoConcern(row)).map((row) => `${tool.name}.${row.name}`);
|
|
308
|
+
}
|
|
309
|
+
return [];
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
const UNIT_MS = { m: 60_000, h: 3_600_000, d: 86_400_000 };
|
|
313
|
+
// A length of time like 30m, 24h or 7d, in milliseconds, or null if it isn't one.
|
|
314
|
+
export function durationMs(value) {
|
|
315
|
+
const match = typeof value === "string" ? /^([1-9]\d*)([mhd])$/.exec(value) : null;
|
|
316
|
+
return match ? Number(match[1]) * UNIT_MS[match[2]] : null;
|
|
317
|
+
}
|
|
318
|
+
// How a channel behaves, with the defaults filled in, so that every host agrees on them.
|
|
319
|
+
export function channelSettings({ data }) {
|
|
320
|
+
const type = CHANNEL_TYPES[data.type];
|
|
321
|
+
return {
|
|
322
|
+
type: data.type,
|
|
323
|
+
enabled: data.enabled ?? true,
|
|
324
|
+
allow: data.allow,
|
|
325
|
+
respondTo: data.respond_to ?? DEFAULT_RESPOND_TO,
|
|
326
|
+
dedicatedChannels: data.dedicated_channels ?? [],
|
|
327
|
+
sendTo: data.send_to ?? [],
|
|
328
|
+
scope: data.scope ?? type.scopes[0],
|
|
329
|
+
expiresAfterMs: durationMs(data.expires_after ?? type.expiresAfter ?? DEFAULT_EXPIRES_AFTER),
|
|
330
|
+
approvals: data.approvals ?? "deny",
|
|
331
|
+
limits: data.limits ?? {},
|
|
332
|
+
greeting: data.greeting ?? null,
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
// The system prompt for a conversation on this channel: the agent's, then the channel's own instructions.
|
|
336
|
+
// A session can override `system` for itself, so a channel doesn't need its own copy of the agent.
|
|
337
|
+
// `instance` is what checkFiles returns, so the agent's prompt includes system_prompt/. An agent alone,
|
|
338
|
+
// as before, still works, with only agent.md's body.
|
|
339
|
+
export const channelSystem = (instance, channel) => [instance.agent ? systemPromptOf(instance) : instance.body, channel.body].filter(Boolean).join("\n\n");
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type FileMap } from "./files.ts";
|
|
2
|
+
import { type Instance } from "./instance.ts";
|
|
3
|
+
import { type CheckToolsOptions } from "./tools.ts";
|
|
4
|
+
export type CheckOptions = CheckToolsOptions;
|
|
5
|
+
export interface CheckResult {
|
|
6
|
+
errors: string[];
|
|
7
|
+
warnings: string[];
|
|
8
|
+
instance: Instance | null;
|
|
9
|
+
}
|
|
10
|
+
export declare function checkFiles(files: FileMap, options?: CheckOptions): CheckResult;
|