@soft-boy/agentschema 0.3.9 → 0.3.11
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/src/oauth.js +24 -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,
|
package/package.json
CHANGED
package/src/oauth.js
CHANGED
|
@@ -18,8 +18,12 @@ export async function discover(serverUrl, { fetch = globalThis.fetch } = {}) {
|
|
|
18
18
|
const url = new URL(serverUrl);
|
|
19
19
|
const path = url.pathname.replace(/\/$/, "");
|
|
20
20
|
|
|
21
|
-
// Protected resource metadata (RFC 9728): which authorization server the MCP server trusts.
|
|
21
|
+
// Protected resource metadata (RFC 9728): which authorization server the MCP server trusts. The
|
|
22
|
+
// server can say where that is when it turns away a request with no token, and some put it where
|
|
23
|
+
// the well-known addresses below wouldn't find it, so its word comes first.
|
|
24
|
+
const hinted = await resourceMetadataHint(serverUrl, fetch);
|
|
22
25
|
const resourceMeta =
|
|
26
|
+
(hinted && (await getJSON(hinted, fetch))) ||
|
|
23
27
|
(path && (await getJSON(`${url.origin}/.well-known/oauth-protected-resource${path}`, fetch))) ||
|
|
24
28
|
(await getJSON(`${url.origin}/.well-known/oauth-protected-resource`, fetch));
|
|
25
29
|
const issuer = resourceMeta?.authorization_servers?.[0] ?? url.origin;
|
|
@@ -53,6 +57,25 @@ export async function discover(serverUrl, { fetch = globalThis.fetch } = {}) {
|
|
|
53
57
|
};
|
|
54
58
|
}
|
|
55
59
|
|
|
60
|
+
// Where the MCP server's 401 says its protected resource metadata is: the resource_metadata
|
|
61
|
+
// parameter of its WWW-Authenticate header. Returns null when it doesn't say.
|
|
62
|
+
async function resourceMetadataHint(serverUrl, fetch) {
|
|
63
|
+
try {
|
|
64
|
+
const res = await fetch(serverUrl, {
|
|
65
|
+
method: "POST",
|
|
66
|
+
headers: { "content-type": "application/json", accept: "application/json, text/event-stream" },
|
|
67
|
+
body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "initialize", params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "agentschema", version: "0" } } }),
|
|
68
|
+
signal: AbortSignal.timeout(10_000),
|
|
69
|
+
});
|
|
70
|
+
if (res.status !== 401) return null;
|
|
71
|
+
const match = /\bresource_metadata\s*=\s*(?:"([^"]*)"|([^\s,]+))/i.exec(res.headers.get("www-authenticate") ?? "");
|
|
72
|
+
const hint = match?.[1] ?? match?.[2];
|
|
73
|
+
return hint && URL.canParse(hint) ? hint : null;
|
|
74
|
+
} catch {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
56
79
|
async function getJSON(url, fetch) {
|
|
57
80
|
try {
|
|
58
81
|
const res = await fetch(url, { headers: { accept: "application/json" } });
|