@soft-boy/agentschema 0.3.6 → 0.3.8
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/lib/channels.js +25 -4
- package/package.json +1 -1
package/lib/channels.js
CHANGED
|
@@ -12,7 +12,7 @@ export const ANYONE = "*";
|
|
|
12
12
|
const DEFAULT_RESPOND_TO = ["direct", "mention"];
|
|
13
13
|
const DEFAULT_EXPIRES_AFTER = "24h";
|
|
14
14
|
const RESPOND_TO = ["direct", "mention", "reply", "all"];
|
|
15
|
-
const LIMITS = ["messages_per_sender_per_hour", "messages_per_day"];
|
|
15
|
+
const LIMITS = ["messages_per_sender_per_hour", "messages_per_day", "messages_sent_per_hour"];
|
|
16
16
|
const SHARED_FIELDS = ["type", "enabled", "allow", "respond_to", "scope", "expires_after", "approvals", "limits", "greeting"];
|
|
17
17
|
const MAX_GREETING = 1000;
|
|
18
18
|
const MAX_SYSTEM_PROMPT = 100_000;
|
|
@@ -94,6 +94,8 @@ export const CHANNEL_TYPES = {
|
|
|
94
94
|
public_key: { required: true, check: matches(/^[0-9a-f]{64}$/, "the 64-character public key") },
|
|
95
95
|
guilds: { check: listOf(matches(DISCORD_ID, "a numeric server ID")) },
|
|
96
96
|
channels: { check: listOf(matches(DISCORD_ID, "a numeric channel ID")) },
|
|
97
|
+
dedicated_channels: { check: listOf(matches(DISCORD_ID, "a numeric channel ID")) },
|
|
98
|
+
send_to: { check: listOf(matches(DISCORD_ID, "a numeric channel ID")) },
|
|
97
99
|
command: { check: matches(/^[a-z0-9_-]{1,32}$/, "a slash command's name, like ask") },
|
|
98
100
|
},
|
|
99
101
|
identity: ({ application_id: id }) => id,
|
|
@@ -132,6 +134,8 @@ export function readChannels(files) {
|
|
|
132
134
|
export function checkChannels(channels, { agent = { body: "" }, tools = [], toolsets } = {}, errors = [], warnings = []) {
|
|
133
135
|
const unasked = toolsThatRunUnasked(tools, toolsets);
|
|
134
136
|
const identities = new Map();
|
|
137
|
+
// Where each place in a `send_to` came from: only one bot can post there, so it's clear which one does.
|
|
138
|
+
const postedTo = new Map();
|
|
135
139
|
|
|
136
140
|
for (const channel of channels) {
|
|
137
141
|
const err = (msg) => errors.push(`${channel.file}: ${msg}`);
|
|
@@ -174,6 +178,14 @@ export function checkChannels(channels, { agent = { body: "" }, tools = [], tool
|
|
|
174
178
|
else identities.set(identity, channel.file);
|
|
175
179
|
}
|
|
176
180
|
|
|
181
|
+
if (Array.isArray(data.send_to)) {
|
|
182
|
+
for (const place of data.send_to) {
|
|
183
|
+
if (typeof place !== "string") continue;
|
|
184
|
+
if (postedTo.has(place)) err(`\`send_to\`: ${place} is already in ${postedTo.get(place)}, and only one bot can post there`);
|
|
185
|
+
else postedTo.set(place, channel.file);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
177
189
|
if (data.allow === ANYONE && data.enabled !== false && unasked.length > 0) {
|
|
178
190
|
warn(`anyone can message this channel, and these tools can run without asking, through your sign-ins and connections: ${unasked.join(", ")}`);
|
|
179
191
|
}
|
|
@@ -200,7 +212,9 @@ function checkAllow({ allow, approvals }, type, err, warn) {
|
|
|
200
212
|
function checkShared(data, type, err, warn) {
|
|
201
213
|
if (data.enabled !== undefined && typeof data.enabled !== "boolean") err("`enabled` must be true or false");
|
|
202
214
|
|
|
203
|
-
|
|
215
|
+
// An agent can answer only in channels it has to itself, and nowhere else.
|
|
216
|
+
const onlyDedicated = Array.isArray(data.respond_to) && data.respond_to.length === 0 && data.dedicated_channels?.length > 0;
|
|
217
|
+
if (data.respond_to !== undefined && !onlyDedicated) {
|
|
204
218
|
const list = data.respond_to;
|
|
205
219
|
if (!Array.isArray(list) || list.length === 0 || list.some((v) => !RESPOND_TO.includes(v))) {
|
|
206
220
|
err(`\`respond_to\` must be a list of ${RESPOND_TO.map(code).join(", ")}`);
|
|
@@ -230,6 +244,9 @@ function checkShared(data, type, err, warn) {
|
|
|
230
244
|
if (!LIMITS.includes(key)) err(`unknown field \`limits.${key}\`; use ${LIMITS.map(code).join(" or ")}`);
|
|
231
245
|
else if (!Number.isInteger(value) || value < 1) err(`\`limits.${key}\` must be a whole number above 0`);
|
|
232
246
|
}
|
|
247
|
+
if (data.limits.messages_sent_per_hour !== undefined && data.send_to === undefined) {
|
|
248
|
+
warn("`limits.messages_sent_per_hour` has no effect without `send_to`");
|
|
249
|
+
}
|
|
233
250
|
}
|
|
234
251
|
}
|
|
235
252
|
|
|
@@ -255,8 +272,10 @@ function toolsThatRunUnasked(tools, toolsets) {
|
|
|
255
272
|
}
|
|
256
273
|
if (tool.data.type === AGENTBOOK) {
|
|
257
274
|
const catalog = toolsets?.[tool.data.toolset]?.tools;
|
|
258
|
-
const
|
|
259
|
-
|
|
275
|
+
const definition = (row) => catalog?.find((t) => t.name === row.name);
|
|
276
|
+
// A tool that never runs on a live agent can't run here, and one that's safe for anyone needn't be mentioned.
|
|
277
|
+
const isOfNoConcern = (row) => definition(row)?.liveAllowed === false || definition(row)?.safeForAnyone === true;
|
|
278
|
+
return (tool.rows ?? []).filter((row) => isOn(row) && row.permission === "always_allow" && !isOfNoConcern(row)).map((row) => `${tool.name}.${row.name}`);
|
|
260
279
|
}
|
|
261
280
|
return [];
|
|
262
281
|
});
|
|
@@ -278,6 +297,8 @@ export function channelSettings({ data }) {
|
|
|
278
297
|
enabled: data.enabled ?? true,
|
|
279
298
|
allow: data.allow,
|
|
280
299
|
respondTo: data.respond_to ?? DEFAULT_RESPOND_TO,
|
|
300
|
+
dedicatedChannels: data.dedicated_channels ?? [],
|
|
301
|
+
sendTo: data.send_to ?? [],
|
|
281
302
|
scope: data.scope ?? type.scopes[0],
|
|
282
303
|
expiresAfterMs: durationMs(data.expires_after ?? DEFAULT_EXPIRES_AFTER),
|
|
283
304
|
approvals: data.approvals ?? "deny",
|