@soft-boy/agentschema 0.3.7 → 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.
Files changed (2) hide show
  1. package/lib/channels.js +20 -3
  2. 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;
@@ -95,6 +95,7 @@ export const CHANNEL_TYPES = {
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
97
  dedicated_channels: { check: listOf(matches(DISCORD_ID, "a numeric channel ID")) },
98
+ send_to: { check: listOf(matches(DISCORD_ID, "a numeric channel ID")) },
98
99
  command: { check: matches(/^[a-z0-9_-]{1,32}$/, "a slash command's name, like ask") },
99
100
  },
100
101
  identity: ({ application_id: id }) => id,
@@ -133,6 +134,8 @@ export function readChannels(files) {
133
134
  export function checkChannels(channels, { agent = { body: "" }, tools = [], toolsets } = {}, errors = [], warnings = []) {
134
135
  const unasked = toolsThatRunUnasked(tools, toolsets);
135
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();
136
139
 
137
140
  for (const channel of channels) {
138
141
  const err = (msg) => errors.push(`${channel.file}: ${msg}`);
@@ -175,6 +178,14 @@ export function checkChannels(channels, { agent = { body: "" }, tools = [], tool
175
178
  else identities.set(identity, channel.file);
176
179
  }
177
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
+
178
189
  if (data.allow === ANYONE && data.enabled !== false && unasked.length > 0) {
179
190
  warn(`anyone can message this channel, and these tools can run without asking, through your sign-ins and connections: ${unasked.join(", ")}`);
180
191
  }
@@ -233,6 +244,9 @@ function checkShared(data, type, err, warn) {
233
244
  if (!LIMITS.includes(key)) err(`unknown field \`limits.${key}\`; use ${LIMITS.map(code).join(" or ")}`);
234
245
  else if (!Number.isInteger(value) || value < 1) err(`\`limits.${key}\` must be a whole number above 0`);
235
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
+ }
236
250
  }
237
251
  }
238
252
 
@@ -258,8 +272,10 @@ function toolsThatRunUnasked(tools, toolsets) {
258
272
  }
259
273
  if (tool.data.type === AGENTBOOK) {
260
274
  const catalog = toolsets?.[tool.data.toolset]?.tools;
261
- const neverRunsLive = (row) => catalog?.find((t) => t.name === row.name)?.liveAllowed === false;
262
- return (tool.rows ?? []).filter((row) => isOn(row) && row.permission === "always_allow" && !neverRunsLive(row)).map((row) => `${tool.name}.${row.name}`);
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}`);
263
279
  }
264
280
  return [];
265
281
  });
@@ -282,6 +298,7 @@ export function channelSettings({ data }) {
282
298
  allow: data.allow,
283
299
  respondTo: data.respond_to ?? DEFAULT_RESPOND_TO,
284
300
  dedicatedChannels: data.dedicated_channels ?? [],
301
+ sendTo: data.send_to ?? [],
285
302
  scope: data.scope ?? type.scopes[0],
286
303
  expiresAfterMs: durationMs(data.expires_after ?? DEFAULT_EXPIRES_AFTER),
287
304
  approvals: data.approvals ?? "deny",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soft-boy/agentschema",
3
- "version": "0.3.7",
3
+ "version": "0.3.8",
4
4
  "description": "Markdown based AI agent schema",
5
5
  "type": "module",
6
6
  "bin": {