@soft-boy/agentschema 0.3.5 → 0.3.7

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 +9 -3
  2. package/package.json +1 -1
package/lib/channels.js CHANGED
@@ -87,13 +87,14 @@ export const CHANNEL_TYPES = {
87
87
  secrets: ["bot_token"],
88
88
  scopes: ["sender", "room"],
89
89
  approvals: ["deny", "sender"],
90
- // Reading ordinary messages takes an always-on connection, so people talk to it with a slash command.
91
- hasGroups: false,
90
+ hasGroups: true,
92
91
  allow: matches(DISCORD_ID, "a numeric user ID"),
93
92
  fields: {
94
93
  application_id: { required: true, check: matches(DISCORD_ID, "a numeric application ID") },
95
94
  public_key: { required: true, check: matches(/^[0-9a-f]{64}$/, "the 64-character public key") },
96
95
  guilds: { check: listOf(matches(DISCORD_ID, "a numeric server ID")) },
96
+ channels: { check: listOf(matches(DISCORD_ID, "a numeric channel ID")) },
97
+ dedicated_channels: { check: listOf(matches(DISCORD_ID, "a numeric channel ID")) },
97
98
  command: { check: matches(/^[a-z0-9_-]{1,32}$/, "a slash command's name, like ask") },
98
99
  },
99
100
  identity: ({ application_id: id }) => id,
@@ -200,7 +201,9 @@ function checkAllow({ allow, approvals }, type, err, warn) {
200
201
  function checkShared(data, type, err, warn) {
201
202
  if (data.enabled !== undefined && typeof data.enabled !== "boolean") err("`enabled` must be true or false");
202
203
 
203
- if (data.respond_to !== undefined) {
204
+ // An agent can answer only in channels it has to itself, and nowhere else.
205
+ const onlyDedicated = Array.isArray(data.respond_to) && data.respond_to.length === 0 && data.dedicated_channels?.length > 0;
206
+ if (data.respond_to !== undefined && !onlyDedicated) {
204
207
  const list = data.respond_to;
205
208
  if (!Array.isArray(list) || list.length === 0 || list.some((v) => !RESPOND_TO.includes(v))) {
206
209
  err(`\`respond_to\` must be a list of ${RESPOND_TO.map(code).join(", ")}`);
@@ -208,6 +211,8 @@ function checkShared(data, type, err, warn) {
208
211
  err("`respond_to`: `all` already covers the others, so list it on its own");
209
212
  } else if (!type.hasGroups) {
210
213
  warn(`\`respond_to\` has no effect on ${data.type}`);
214
+ } else if (list.includes("all") && Object.hasOwn(type.fields, "channels") && data.channels === undefined) {
215
+ 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`");
211
216
  }
212
217
  }
213
218
 
@@ -276,6 +281,7 @@ export function channelSettings({ data }) {
276
281
  enabled: data.enabled ?? true,
277
282
  allow: data.allow,
278
283
  respondTo: data.respond_to ?? DEFAULT_RESPOND_TO,
284
+ dedicatedChannels: data.dedicated_channels ?? [],
279
285
  scope: data.scope ?? type.scopes[0],
280
286
  expiresAfterMs: durationMs(data.expires_after ?? DEFAULT_EXPIRES_AFTER),
281
287
  approvals: data.approvals ?? "deny",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soft-boy/agentschema",
3
- "version": "0.3.5",
3
+ "version": "0.3.7",
4
4
  "description": "Markdown based AI agent schema",
5
5
  "type": "module",
6
6
  "bin": {