@soft-boy/agentschema 0.3.9 → 0.3.10
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 +1 -1
- package/lib/channels.js +26 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -145,7 +145,7 @@ auth:
|
|
|
145
145
|
|
|
146
146
|
### `channels/`
|
|
147
147
|
|
|
148
|
-
Each `.md` file is a place people can talk to the agent: `telegram`, `twilio`, `sendgrid`, `slack` or `discord`. The frontmatter says who can use it and how it behaves, and the body is added to the system prompt there. `check` validates these files, but `deploy` and `run` don't connect them, because that takes a host that's always on. See [Channels](docs/channels.md):
|
|
148
|
+
Each `.md` file is a place people can talk to the agent: `telegram`, `twilio`, `sendgrid`, `email`, `slack` or `discord`. The frontmatter says who can use it and how it behaves, and the body is added to the system prompt there. `check` validates these files, but `deploy` and `run` don't connect them, because that takes a host that's always on. See [Channels](docs/channels.md):
|
|
149
149
|
|
|
150
150
|
```markdown
|
|
151
151
|
---
|
package/lib/channels.js
CHANGED
|
@@ -11,6 +11,8 @@ export const ANYONE = "*";
|
|
|
11
11
|
|
|
12
12
|
const DEFAULT_RESPOND_TO = ["direct", "mention"];
|
|
13
13
|
const DEFAULT_EXPIRES_AFTER = "24h";
|
|
14
|
+
// An email thread can go quiet for days and still be one conversation.
|
|
15
|
+
const EMAIL_EXPIRES_AFTER = "7d";
|
|
14
16
|
const RESPOND_TO = ["direct", "mention", "reply", "all"];
|
|
15
17
|
const LIMITS = ["messages_per_sender_per_hour", "messages_per_day", "messages_sent_per_hour"];
|
|
16
18
|
const SHARED_FIELDS = ["type", "enabled", "allow", "respond_to", "scope", "expires_after", "approvals", "limits", "greeting"];
|
|
@@ -36,9 +38,12 @@ const PHONE = /^\+[1-9]\d{6,14}$/;
|
|
|
36
38
|
const DISCORD_ID = /^\d{17,20}$/;
|
|
37
39
|
const EMAIL = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
38
40
|
|
|
41
|
+
const EMAIL_ALLOW = matches(/^(\*|[^\s@]+)@[^\s@]+\.[^\s@]+$/, "an email address, or *@ and a domain");
|
|
42
|
+
|
|
39
43
|
// What differs between channels. Each `secrets` entry is something the host asks for and keeps: never
|
|
40
44
|
// the file, and never a vault, because a vault's secrets can't be read back to send a reply. The first
|
|
41
45
|
// of `scopes` is the default. `identity` is what two files in one agent can't share, where that's known.
|
|
46
|
+
// `expiresAfter` is the default for `expires_after`, where it isn't the usual one.
|
|
42
47
|
export const CHANNEL_TYPES = {
|
|
43
48
|
telegram: {
|
|
44
49
|
secrets: ["bot_token"],
|
|
@@ -66,13 +71,29 @@ export const CHANNEL_TYPES = {
|
|
|
66
71
|
// An email has no buttons, and its sender can be forged.
|
|
67
72
|
approvals: ["deny"],
|
|
68
73
|
hasGroups: false,
|
|
69
|
-
|
|
74
|
+
expiresAfter: EMAIL_EXPIRES_AFTER,
|
|
75
|
+
allow: EMAIL_ALLOW,
|
|
70
76
|
fields: {
|
|
71
77
|
address: { required: true, check: matches(EMAIL, "an email address") },
|
|
72
78
|
from_name: { check: text },
|
|
73
79
|
},
|
|
74
80
|
identity: ({ address }) => address,
|
|
75
81
|
},
|
|
82
|
+
// Email at an address the host gives the agent, such as Agentbook's, so the host sends and receives it
|
|
83
|
+
// and there's nothing to connect. `address` can be left out, for the host to fill in.
|
|
84
|
+
email: {
|
|
85
|
+
secrets: [],
|
|
86
|
+
scopes: ["thread", "sender"],
|
|
87
|
+
approvals: ["deny"],
|
|
88
|
+
hasGroups: false,
|
|
89
|
+
expiresAfter: EMAIL_EXPIRES_AFTER,
|
|
90
|
+
allow: EMAIL_ALLOW,
|
|
91
|
+
fields: {
|
|
92
|
+
address: { check: matches(EMAIL, "an email address") },
|
|
93
|
+
from_name: { check: text },
|
|
94
|
+
},
|
|
95
|
+
identity: ({ address }) => address ?? null,
|
|
96
|
+
},
|
|
76
97
|
slack: {
|
|
77
98
|
secrets: ["bot_token", "signing_secret"],
|
|
78
99
|
scopes: ["thread", "sender", "room"],
|
|
@@ -172,8 +193,9 @@ export function checkChannels(channels, { agent = { body: "" }, tools = [], tool
|
|
|
172
193
|
}
|
|
173
194
|
|
|
174
195
|
const hasRequiredFields = Object.entries(type.fields).every(([field, { required }]) => !required || data[field] !== undefined);
|
|
175
|
-
|
|
176
|
-
|
|
196
|
+
const own = type.identity && hasRequiredFields ? type.identity(data) : null;
|
|
197
|
+
if (own !== null) {
|
|
198
|
+
const identity = `${data.type} ${own}`;
|
|
177
199
|
if (identities.has(identity)) err(`${identities.get(identity)} already uses this`);
|
|
178
200
|
else identities.set(identity, channel.file);
|
|
179
201
|
}
|
|
@@ -300,7 +322,7 @@ export function channelSettings({ data }) {
|
|
|
300
322
|
dedicatedChannels: data.dedicated_channels ?? [],
|
|
301
323
|
sendTo: data.send_to ?? [],
|
|
302
324
|
scope: data.scope ?? type.scopes[0],
|
|
303
|
-
expiresAfterMs: durationMs(data.expires_after ?? DEFAULT_EXPIRES_AFTER),
|
|
325
|
+
expiresAfterMs: durationMs(data.expires_after ?? type.expiresAfter ?? DEFAULT_EXPIRES_AFTER),
|
|
304
326
|
approvals: data.approvals ?? "deny",
|
|
305
327
|
limits: data.limits ?? {},
|
|
306
328
|
greeting: data.greeting ?? null,
|