@segmentstream/ontology 0.111.0 → 0.113.0
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/CHANGELOG.md +34 -0
- package/README.md +9 -3
- package/dist/analyze.d.ts +8 -4
- package/dist/analyze.js +72 -27
- package/dist/chat-channel.d.ts +27 -2
- package/dist/chat-channel.js +36 -2
- package/dist/email-html.d.ts +23 -0
- package/dist/email-html.js +249 -0
- package/dist/emails.d.ts +38 -6
- package/dist/emails.js +71 -2
- package/dist/index.d.ts +5 -3
- package/dist/index.js +3 -1
- package/dist/manifest.d.ts +208 -52
- package/dist/manifest.js +32 -6
- package/dist/migrate/model.d.ts +98 -34
- package/dist/runtime/resolve-agent-identity.js +4 -1
- package/dist/service/agent/protocol.d.ts +4 -1
- package/dist/service/agent/protocol.js +7 -3
- package/dist/service/agent/server.js +8 -2
- package/dist/service/authentication.d.ts +2 -1
- package/dist/service/authentication.js +13 -3
- package/dist/service/chat/delivery.d.ts +10 -1
- package/dist/service/chat/delivery.js +21 -3
- package/dist/service/chat/envelope.d.ts +2 -2
- package/dist/service/chat/providers/custom.d.ts +13 -0
- package/dist/service/chat/providers/custom.js +103 -0
- package/dist/service/chat/providers/index.d.ts +1 -0
- package/dist/service/chat/providers/index.js +12 -3
- package/dist/service/chat/providers/provider.d.ts +19 -0
- package/dist/service/chat/reads.d.ts +1 -1
- package/dist/service/chat/reads.js +2 -2
- package/dist/service/chat/resolve.d.ts +2 -1
- package/dist/service/chat/resolve.js +6 -2
- package/dist/service/chat/review-delivery.d.ts +3 -0
- package/dist/service/chat/review-delivery.js +9 -3
- package/dist/service/chat/schemas.d.ts +2 -2
- package/dist/service/chat/schemas.js +2 -2
- package/dist/service/config.d.ts +6 -2
- package/dist/service/schemas.d.ts +30 -8
- package/dist/service/service.js +6 -1
- package/dist/sign-in.d.ts +22 -1
- package/dist/sign-in.js +3 -1
- package/dist/storage/tables.d.ts +4 -3
- package/dist/storage/tables.js +11 -3
- package/dist/workspace-channel.d.ts +54 -0
- package/dist/workspace-channel.js +36 -0
- package/package.json +5 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.113.0
|
|
4
|
+
|
|
5
|
+
A workspace can write every email its people receive, whole. An email in `emails` may be a
|
|
6
|
+
document of its own, `{ subject, html, text, replyTo? }`, instead of fields the platform lays out:
|
|
7
|
+
the platform then only fills its placeholders, escaped in the HTML, and sends it. Its HTML links
|
|
8
|
+
to `{{link}}`, the sign-in link, now a built-in value of every email; it may not run code or post
|
|
9
|
+
forms, and it links only to `https:`, `mailto:` and `tel:` addresses, anchors, or the app's own
|
|
10
|
+
`{{link}}`, `{{app.url}}` and `{{app.mcpUrl}}`. Inside its tags only those three and
|
|
11
|
+
`{{workspace.name}}` may stand; every other value goes in text, so no value an action passes
|
|
12
|
+
becomes an address or an attribute. `check` reports `invalid-email` otherwise.
|
|
13
|
+
|
|
14
|
+
`signIn.linkEmail` and `signIn.codeEmail` name the emails the platform sends instead of its own
|
|
15
|
+
sign-in link and sign-in code, as `signIn.invitationEmail` does for the invitation. The code email
|
|
16
|
+
shows `{{code}}`; its button opens the app's sign-in page, with the code filled in when `codeLink`
|
|
17
|
+
is on. The starter's `ontology/emails.ts` writes all three. Older platform deployments ignore both
|
|
18
|
+
names and documents and send their own emails.
|
|
19
|
+
|
|
20
|
+
## 0.112.0
|
|
21
|
+
|
|
22
|
+
`chat` declares a channel the workspace defines in its own code by its name with
|
|
23
|
+
`kind: "custom"` and no connection, such as `chat: { zernio: { kind: "custom" } }`. The ontology
|
|
24
|
+
sends nothing through it: an approved reply on it, and a chat post to one of its chats, go to the
|
|
25
|
+
app's agent, at `/eve/segmentstream/v1/custom/<name>/send` on the production origin, with the
|
|
26
|
+
service's Vercel OIDC token, as `agentTask` hands the agent its tasks; the agent's refusal sent
|
|
27
|
+
nothing, and anything else may have. A chat post names only the person, whose chat the agent
|
|
28
|
+
finds. `chat_list` lists its members' private chats with kind
|
|
29
|
+
`custom`, and `@segmentstream/ontology/workspace-channel` holds the route and the text both sides
|
|
30
|
+
compute.
|
|
31
|
+
|
|
32
|
+
Its people's accounts are its own, `channel:<name>`, so it can claim no other channel's account:
|
|
33
|
+
`signUp.channels` may list `channel:<name>` for a channel `chat` declares, a user it creates is
|
|
34
|
+
named after the channel, and history keeps a chat on it only for its own people. Attachments from
|
|
35
|
+
it have the source `channel`; the database's check widens on the next migration.
|
|
36
|
+
|
|
3
37
|
## 0.111.0
|
|
4
38
|
|
|
5
39
|
`chat` names the agent's channels as its `channels` does: the channel named after its kind
|
package/README.md
CHANGED
|
@@ -509,8 +509,11 @@ export default defineOntology({
|
|
|
509
509
|
built-in `{{member.name}}`, `{{member.firstName}}`, `{{workspace.name}}`, `{{app.url}}` and
|
|
510
510
|
`{{app.mcpUrl}}`. `sections` are boxes below the button, each
|
|
511
511
|
`{ title, text?, copy?: { label?, value }, items?: [{ label, text?, code? }], note? }`.
|
|
512
|
-
|
|
513
|
-
|
|
512
|
+
An email may instead be a whole document, `{ subject, html, text, replyTo? }`, whose HTML
|
|
513
|
+
links to `{{link}}`; the platform then only fills its values, escaped in the HTML.
|
|
514
|
+
`signIn.invitationEmail`, `linkEmail` and `codeEmail` name the ones the platform sends instead
|
|
515
|
+
of its own invitation, sign-in link and sign-in code; they may use only built-in values, and
|
|
516
|
+
the code email shows `{{code}}`. A handler sends
|
|
514
517
|
one with `User.sendSignInLink(user, { template: "agreementReview", returnTo: "/shared/1", values })`:
|
|
515
518
|
after the commit, in production, the platform emails the member a link that signs them in and
|
|
516
519
|
opens `returnTo`, laid out in its design, from the workspace's name, with replies to `replyTo`
|
|
@@ -1556,7 +1559,10 @@ not change it.
|
|
|
1556
1559
|
such as a second number, says its kind: `chat: { sales_whatsapp: { kind: "whatsapp", connection:
|
|
1557
1560
|
waSales } }`. Its chats are keyed by its name (`sales_whatsapp:private:<member UUID>`, and the
|
|
1558
1561
|
`provider` of its `agent_chat` records), and posts and reviewed replies there leave through its
|
|
1559
|
-
connection. A member's account reaches them on every channel of its kind.
|
|
1562
|
+
connection. A member's account reaches them on every channel of its kind. A channel the workspace
|
|
1563
|
+
defines in its own code is `chat: { zernio: { kind: "custom" } }`, with no connection: its posts
|
|
1564
|
+
and reviewed replies go to the app's agent, which sends them with the channel's code, and its
|
|
1565
|
+
people's accounts are its own, `channel:zernio`, which `signUp.channels` may list.
|
|
1560
1566
|
|
|
1561
1567
|
`chat_list({ query?, chat?, after?, limit? })` returns eligible routing metadata and server-derived
|
|
1562
1568
|
attribution: each item's `provider` is the channel the chat is on, by name, and `kind` its kind. `query` filters titles by a case-insensitive literal substring before pagination.
|
package/dist/analyze.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ChatAttributionSettings } from "./chat.js";
|
|
2
|
-
import { type
|
|
2
|
+
import { type ChatKind } from "./chat-channel.js";
|
|
3
3
|
import type { ChatManifestInput } from "./manifest.js";
|
|
4
4
|
import { Schema } from "effect";
|
|
5
5
|
import { type Action, type ActionHints } from "./action.js";
|
|
@@ -227,10 +227,14 @@ export interface Analysis {
|
|
|
227
227
|
readonly toolsets: ReadonlyArray<ResolvedToolset>;
|
|
228
228
|
readonly diagnostics: ReadonlyArray<Diagnostic>;
|
|
229
229
|
}
|
|
230
|
-
/**
|
|
230
|
+
/**
|
|
231
|
+
* One channel of `chat`, by name: the channel named after its kind, or one that says its kind. A
|
|
232
|
+
* channel the workspace defines in its own code says `kind: "custom"` and takes no connection: the
|
|
233
|
+
* agent sends through it, with the connection `agent/segmentstream.json` gives it.
|
|
234
|
+
*/
|
|
231
235
|
export interface ChatChannelConfig {
|
|
232
|
-
readonly kind?:
|
|
233
|
-
readonly connection
|
|
236
|
+
readonly kind?: ChatKind;
|
|
237
|
+
readonly connection?: AnyConnectionHandle;
|
|
234
238
|
}
|
|
235
239
|
/** `chat` of {@link OntologyConfig}: the agent's channels by name, and the post attribution. */
|
|
236
240
|
export interface ChatConfig {
|
package/dist/analyze.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { validateBrowserSignIn } from "./sign-in.js";
|
|
2
|
-
import { CHAT_CHANNEL_KINDS, CHAT_CHANNEL_NAME, chatChannelKind,
|
|
2
|
+
import { CHAT_CHANNEL_KINDS, CHAT_CHANNEL_NAME, CHAT_KINDS, chatChannelKind, isChatKind, WORKSPACE_CHANNEL_KIND, workspaceChannelOf, } from "./chat-channel.js";
|
|
3
3
|
import { checkWarehouseSource } from "./warehouse-backed.js";
|
|
4
4
|
import { Result, Schema } from "effect";
|
|
5
5
|
import { BLOB_UPLOAD_ANNOTATION } from "./blob.js";
|
|
@@ -13,7 +13,7 @@ import { AGENT_TOOL, AGENT_TOOL_VERBS, EXPLICIT_GRANT_ENTITIES, generatedActionP
|
|
|
13
13
|
import { ON_DELETE, isRelationship } from "./relationship.js";
|
|
14
14
|
import { isRole, member, role } from "./role.js";
|
|
15
15
|
import { CHANNEL_PROVIDERS, DEFAULT_SIGN_IN_POLICY, GUEST_BOT_CHECK_SCHEMES, GUEST_CHANNELS, SIGN_UP_CHANNELS, SIGN_UP_CHAT_CHANNELS, isGuestBotCheckScheme, isGuestChannel, isSignInPolicy, isSignUpChannel, websiteOrigin, } from "./sign-in.js";
|
|
16
|
-
import { BUILT_IN_EMAIL_VALUES, emailOptions, emailValueNames, } from "./emails.js";
|
|
16
|
+
import { BUILT_IN_EMAIL_VALUES, emailOptions, emailValueNames, SIGN_IN_CODE_VALUE, } from "./emails.js";
|
|
17
17
|
import { AgentChat } from "./agent-chat.js";
|
|
18
18
|
import { AgentReview } from "./agent-review.js";
|
|
19
19
|
import { APP_FEEDBACK_ENTITIES } from "./app-feedback.js";
|
|
@@ -37,8 +37,11 @@ const GENERATED_UPSERT = new RegExp(`^${GENERATED_UPSERT_PREFIX}`);
|
|
|
37
37
|
const CHAT_PROVIDER_KEYS = CHAT_CHANNEL_KINDS;
|
|
38
38
|
/** The kinds of channel reviewed replies leave through, but chat posts never reach. */
|
|
39
39
|
const REVIEW_ONLY_CHAT_PROVIDERS = new Set(["email"]);
|
|
40
|
-
/**
|
|
41
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Names the agent keeps its own chats under, which no channel of `chat` takes, and the kind of a
|
|
42
|
+
* workspace channel, which always has a name of its own.
|
|
43
|
+
*/
|
|
44
|
+
const RESERVED_CHAT_NAMES = new Set(["web", "task", WORKSPACE_CHANNEL_KIND]);
|
|
42
45
|
/** Whether `chat` declares a channel of `kind`: the one named after it, or another of the kind. */
|
|
43
46
|
function declaresChatKind(chat, kind) {
|
|
44
47
|
return (isPlainObject(chat) &&
|
|
@@ -88,12 +91,16 @@ export function analyze(config, options = {}) {
|
|
|
88
91
|
const emails = emailOptions(config.emails, report, (name, path) => camelCaseName(name, path, "agreementReview", "Email", report));
|
|
89
92
|
const signInDeclared = signInOptions(config, report);
|
|
90
93
|
const guest = guestOptions(config, report);
|
|
91
|
-
const invitationEmail =
|
|
94
|
+
const invitationEmail = signInEmailOption(config, emails, report, "invitationEmail");
|
|
95
|
+
const linkEmail = signInEmailOption(config, emails, report, "linkEmail");
|
|
96
|
+
const codeEmail = signInEmailOption(config, emails, report, "codeEmail");
|
|
92
97
|
const signIn = {
|
|
93
98
|
...signInDeclared,
|
|
94
99
|
...signUpOptions(config, signInDeclared, declaredRoles, report),
|
|
95
100
|
...(guest === undefined ? {} : { guest: guest.resolved }),
|
|
96
101
|
...(invitationEmail === undefined ? {} : { invitationEmail }),
|
|
102
|
+
...(linkEmail === undefined ? {} : { linkEmail }),
|
|
103
|
+
...(codeEmail === undefined ? {} : { codeEmail }),
|
|
97
104
|
};
|
|
98
105
|
const discovery = config.discovery;
|
|
99
106
|
if (discovery !== undefined &&
|
|
@@ -168,26 +175,32 @@ export function analyze(config, options = {}) {
|
|
|
168
175
|
const named = !CHAT_PROVIDER_KEYS.includes(name);
|
|
169
176
|
return (!isPlainObject(value) ||
|
|
170
177
|
Object.keys(value).some((key) => key !== "connection" && key !== "kind") ||
|
|
171
|
-
|
|
172
|
-
|
|
178
|
+
// A workspace channel has no connection here: the agent sends through it, with the
|
|
179
|
+
// connection agent/segmentstream.json gives it. Every other channel sends through its own.
|
|
180
|
+
(value.kind === WORKSPACE_CHANNEL_KIND
|
|
181
|
+
? value.connection !== undefined
|
|
182
|
+
: !isConnection(value.connection)) ||
|
|
183
|
+
(named ? !isChatKind(value.kind) : value.kind !== undefined && value.kind !== name));
|
|
173
184
|
})?.[0];
|
|
174
185
|
// Read only once every declared channel is well formed.
|
|
175
|
-
const
|
|
186
|
+
const channels = malformed === undefined && unknown === undefined
|
|
176
187
|
? entries.map(([name, value]) => {
|
|
177
188
|
const entry = value;
|
|
178
189
|
return [name, entry.connection, entry.kind ?? name];
|
|
179
190
|
})
|
|
180
191
|
: [];
|
|
192
|
+
const handles = channels.flatMap(([name, handle, kind]) => handle === undefined ? [] : [[name, handle, kind]]);
|
|
181
193
|
const unlisted = handles.find(([, handle]) => !(config.connections ?? []).includes(handle));
|
|
182
194
|
const shared = handles.find(([, handle], index) => handles.findIndex(([, other]) => other === handle) !== index);
|
|
183
195
|
if (unknown !== undefined) {
|
|
184
196
|
report("invalid-connection", "chat", `chat accepts attribution and channels by the agent's names for them: ` +
|
|
185
197
|
`${CHAT_PROVIDER_KEYS.join(", ")}, or another lower-case name with its kind; ` +
|
|
186
|
-
|
|
198
|
+
`web and task are the agent's own, and ${WORKSPACE_CHANNEL_KIND} is a kind.`);
|
|
187
199
|
}
|
|
188
200
|
else if (malformed !== undefined) {
|
|
189
201
|
report("invalid-connection", "chat", `chat.${malformed}.connection must reference a declared connection handle, and a ` +
|
|
190
|
-
`channel not named after its kind needs kind: ${
|
|
202
|
+
`channel not named after its kind needs kind: ${CHAT_KINDS.join(", ")}; a ` +
|
|
203
|
+
`${WORKSPACE_CHANNEL_KIND} channel takes none, as the agent sends through it.`);
|
|
191
204
|
}
|
|
192
205
|
else if (unlisted !== undefined) {
|
|
193
206
|
report("invalid-connection", `chat.${unlisted[0]}.connection`, "The chat channel connection must be listed in connections.");
|
|
@@ -195,8 +208,8 @@ export function analyze(config, options = {}) {
|
|
|
195
208
|
else if (shared !== undefined) {
|
|
196
209
|
report("invalid-connection", `chat.${shared[0]}.connection`, "Each chat channel needs its own connection.");
|
|
197
210
|
}
|
|
198
|
-
else if (
|
|
199
|
-
const named =
|
|
211
|
+
else if (channels.length > 0) {
|
|
212
|
+
const named = channels.filter(([name]) => !CHAT_PROVIDER_KEYS.includes(name));
|
|
200
213
|
chat = {
|
|
201
214
|
...Object.fromEntries(handles
|
|
202
215
|
.filter(([name]) => CHAT_PROVIDER_KEYS.includes(name))
|
|
@@ -204,7 +217,10 @@ export function analyze(config, options = {}) {
|
|
|
204
217
|
...(named.length === 0
|
|
205
218
|
? {}
|
|
206
219
|
: {
|
|
207
|
-
channels: Object.fromEntries(named.map(([name, handle, kind]) => [
|
|
220
|
+
channels: Object.fromEntries(named.map(([name, handle, kind]) => [
|
|
221
|
+
name,
|
|
222
|
+
{ kind, ...(handle === undefined ? {} : { connection: handle.key }) },
|
|
223
|
+
])),
|
|
208
224
|
}),
|
|
209
225
|
...(config.chat.attribution === undefined ? {} : { attribution: config.chat.attribution }),
|
|
210
226
|
};
|
|
@@ -213,8 +229,10 @@ export function analyze(config, options = {}) {
|
|
|
213
229
|
agent_chat: "post_message",
|
|
214
230
|
agent_review: "approve",
|
|
215
231
|
};
|
|
216
|
-
// A chat post never reaches a channel whose kind only sends reviewed replies
|
|
217
|
-
|
|
232
|
+
// A chat post never reaches a channel whose kind only sends reviewed replies, and the
|
|
233
|
+
// ontology sends nothing through a workspace channel's connection: the agent does.
|
|
234
|
+
const reaches = (entity) => handles.filter(([, , kind]) => kind !== WORKSPACE_CHANNEL_KIND &&
|
|
235
|
+
(entity === "agent_review" || !REVIEW_ONLY_CHAT_PROVIDERS.has(kind)));
|
|
218
236
|
resolved = resolved.map((entity) => sends[entity.name] === undefined
|
|
219
237
|
? entity
|
|
220
238
|
: {
|
|
@@ -1259,7 +1277,16 @@ function signInOptions(config, report) {
|
|
|
1259
1277
|
return fallback;
|
|
1260
1278
|
}
|
|
1261
1279
|
for (const key of Object.keys(options)) {
|
|
1262
|
-
if (![
|
|
1280
|
+
if (![
|
|
1281
|
+
"policy",
|
|
1282
|
+
"channels",
|
|
1283
|
+
"onNewUser",
|
|
1284
|
+
"browser",
|
|
1285
|
+
"codeLink",
|
|
1286
|
+
"invitationEmail",
|
|
1287
|
+
"linkEmail",
|
|
1288
|
+
"codeEmail",
|
|
1289
|
+
].includes(key)) {
|
|
1263
1290
|
report("invalid-sign-in", `signIn.${key}`, `Unknown signIn key: ${key}.`);
|
|
1264
1291
|
}
|
|
1265
1292
|
}
|
|
@@ -1317,19 +1344,26 @@ function signInOptions(config, report) {
|
|
|
1317
1344
|
...(typeof codeLink === "boolean" ? { codeLink } : {}),
|
|
1318
1345
|
};
|
|
1319
1346
|
}
|
|
1347
|
+
const SIGN_IN_EMAILS = {
|
|
1348
|
+
invitationEmail: { role: "the invitation", values: [] },
|
|
1349
|
+
linkEmail: { role: "the sign-in link email", values: [] },
|
|
1350
|
+
codeEmail: { role: "the sign-in code email", values: [SIGN_IN_CODE_VALUE] },
|
|
1351
|
+
};
|
|
1320
1352
|
/**
|
|
1321
|
-
* `signIn.invitationEmail`: the wire name of the declared email the
|
|
1322
|
-
*
|
|
1353
|
+
* `signIn.invitationEmail`, `linkEmail` or `codeEmail`: the wire name of the declared email the
|
|
1354
|
+
* platform sends instead of its own. It may use only the built-in values and its own (the code's
|
|
1355
|
+
* `{{code}}`), and the code email must show the code.
|
|
1323
1356
|
*/
|
|
1324
|
-
function
|
|
1357
|
+
function signInEmailOption(config, emails, report, key) {
|
|
1325
1358
|
const options = config.signIn;
|
|
1326
|
-
const name = isPlainObject(options) ? options
|
|
1327
|
-
const path =
|
|
1359
|
+
const name = isPlainObject(options) ? options[key] : undefined;
|
|
1360
|
+
const path = `signIn.${key}`;
|
|
1361
|
+
const { role, values: own } = SIGN_IN_EMAILS[key];
|
|
1328
1362
|
if (name === undefined) {
|
|
1329
1363
|
return undefined;
|
|
1330
1364
|
}
|
|
1331
1365
|
if (typeof name !== "string" || !/^[a-z][a-zA-Z0-9]*$/.test(name)) {
|
|
1332
|
-
report("invalid-sign-in", path,
|
|
1366
|
+
report("invalid-sign-in", path, `${key} names one of the ontology's emails, such as memberInvitation.`);
|
|
1333
1367
|
return undefined;
|
|
1334
1368
|
}
|
|
1335
1369
|
const wire = nameToWire(name);
|
|
@@ -1338,10 +1372,15 @@ function invitationEmailOption(config, emails, report) {
|
|
|
1338
1372
|
report("invalid-sign-in", path, `${name} is not one of the ontology's emails.`);
|
|
1339
1373
|
return undefined;
|
|
1340
1374
|
}
|
|
1341
|
-
const
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1375
|
+
const used = emailValueNames(template);
|
|
1376
|
+
const unfilled = used.filter((value) => !own.includes(value));
|
|
1377
|
+
if (unfilled.length > 0) {
|
|
1378
|
+
report("invalid-email", `emails.${name}`, `${name} is ${role}, and nothing fills ${unfilled.map((value) => `{{${value}}}`).join(", ")}: ` +
|
|
1379
|
+
`use only ${[...BUILT_IN_EMAIL_VALUES, ...own].map((value) => `{{${value}}}`).join(", ")}.`);
|
|
1380
|
+
return undefined;
|
|
1381
|
+
}
|
|
1382
|
+
if (key === "codeEmail" && !used.includes(SIGN_IN_CODE_VALUE)) {
|
|
1383
|
+
report("invalid-email", `emails.${name}`, `${name} is ${role}: show the code with {{${SIGN_IN_CODE_VALUE}}}, for instance as a section's value to copy.`);
|
|
1345
1384
|
return undefined;
|
|
1346
1385
|
}
|
|
1347
1386
|
return wire;
|
|
@@ -1455,6 +1494,12 @@ function signUpOptions(config, signIn, declaredRoles, report) {
|
|
|
1455
1494
|
report("invalid-sign-in", `signUp.channels`, `Signing up on ${channel} needs a matching chat.${channel} adapter.`);
|
|
1456
1495
|
}
|
|
1457
1496
|
}
|
|
1497
|
+
// A workspace channel's people sign up through that channel, which chat declares.
|
|
1498
|
+
const workspace = workspaceChannelOf(channel);
|
|
1499
|
+
if (workspace !== undefined &&
|
|
1500
|
+
chatChannelKind(isPlainObject(config.chat) ? config.chat : undefined, workspace) !== WORKSPACE_CHANNEL_KIND) {
|
|
1501
|
+
report("invalid-sign-in", `signUp.channels`, `Signing up on ${channel} needs chat.${workspace} with kind ${WORKSPACE_CHANNEL_KIND}.`);
|
|
1502
|
+
}
|
|
1458
1503
|
}
|
|
1459
1504
|
const origins = [];
|
|
1460
1505
|
if (options.origins !== undefined) {
|
|
@@ -1769,7 +1814,7 @@ function checkSignUpAction(input) {
|
|
|
1769
1814
|
}
|
|
1770
1815
|
for (const [channel, granted] of Object.entries(signIn.signUp?.channels ?? {})) {
|
|
1771
1816
|
const permissions = roles
|
|
1772
|
-
.filter((candidate) => granted.includes(candidate.name))
|
|
1817
|
+
.filter((candidate) => (granted ?? []).includes(candidate.name))
|
|
1773
1818
|
.flatMap((candidate) => (Array.isArray(candidate.permissions) ? candidate.permissions : []));
|
|
1774
1819
|
if (!isAllowed(found.permission, { permissions })) {
|
|
1775
1820
|
fail(`onSignUp must be runnable by the roles ${channel} sign-up grants.`);
|
package/dist/chat-channel.d.ts
CHANGED
|
@@ -7,16 +7,41 @@ import { Schema } from "effect";
|
|
|
7
7
|
* takes the same names, so a reply a member approves, or a chat post, leaves through the connection
|
|
8
8
|
* of the channel the chat is on. Where the platform keys a chat by its `provider`, such as
|
|
9
9
|
* `agent_chat` and the archive, the value is the channel's name.
|
|
10
|
+
*
|
|
11
|
+
* A workspace may define a channel in its own code (`docs/agent.md`, "Workspace channels"): its
|
|
12
|
+
* kind is {@link WORKSPACE_CHANNEL_KIND}, it always has a name of its own, and the agent sends
|
|
13
|
+
* through it, so a reply a member approves, or a chat post, goes to the agent's channel instead of
|
|
14
|
+
* a connection. Its people's accounts are its own: {@link channelIdentityProvider}.
|
|
10
15
|
*/
|
|
11
|
-
/** The kinds of channel the platform
|
|
16
|
+
/** The kinds of channel the platform provides, each with a channel named after it. */
|
|
12
17
|
export declare const CHAT_CHANNEL_KINDS: readonly ["telegram", "slack", "whatsapp", "email"];
|
|
13
18
|
export type ChatChannelKind = (typeof CHAT_CHANNEL_KINDS)[number];
|
|
14
19
|
export declare function isChatChannelKind(value: unknown): value is ChatChannelKind;
|
|
20
|
+
/**
|
|
21
|
+
* The kind of a channel the workspace defines in its own code. No channel is named after it: each
|
|
22
|
+
* has a name of its own.
|
|
23
|
+
*/
|
|
24
|
+
export declare const WORKSPACE_CHANNEL_KIND = "custom";
|
|
25
|
+
/** Every kind a channel of another name may say: the platform's, and the workspace's own. */
|
|
26
|
+
export declare const CHAT_KINDS: readonly ["telegram", "slack", "whatsapp", "email", "custom"];
|
|
27
|
+
export type ChatKind = (typeof CHAT_KINDS)[number];
|
|
28
|
+
export declare function isChatKind(value: unknown): value is ChatKind;
|
|
15
29
|
/** A channel's name: a lower-case letter, then up to 31 lower-case letters, digits or `_`. */
|
|
16
30
|
export declare const CHAT_CHANNEL_NAME: RegExp;
|
|
17
31
|
export declare const ChatChannelName: Schema.String;
|
|
32
|
+
/** A workspace channel's identity provider: `channel:<name>`. */
|
|
33
|
+
export declare const WORKSPACE_IDENTITY_PROVIDER: RegExp;
|
|
34
|
+
/**
|
|
35
|
+
* The provider of the accounts people write from on the channel `name` of `kind`: the kind for
|
|
36
|
+
* the platform's channels, whose accounts are the same on every channel of the kind, and
|
|
37
|
+
* `channel:<name>` for a workspace channel, whose accounts are its own, so it can claim no
|
|
38
|
+
* Telegram, WhatsApp or email account, nor another workspace channel's.
|
|
39
|
+
*/
|
|
40
|
+
export declare function channelIdentityProvider(kind: string, name: string): string;
|
|
41
|
+
/** The workspace channel whose accounts `provider` names, or undefined for any other provider. */
|
|
42
|
+
export declare function workspaceChannelOf(provider: string): string | undefined;
|
|
18
43
|
/**
|
|
19
44
|
* The kind of the channel `name`, by `chat`'s entries: the kind an entry names, or the name itself
|
|
20
45
|
* for the channel named after its kind. Undefined for a name that is neither.
|
|
21
46
|
*/
|
|
22
|
-
export declare function chatChannelKind(chat: Readonly<Record<string, unknown>> | undefined, name: string):
|
|
47
|
+
export declare function chatChannelKind(chat: Readonly<Record<string, unknown>> | undefined, name: string): ChatKind | undefined;
|
package/dist/chat-channel.js
CHANGED
|
@@ -7,18 +7,52 @@ import { Schema } from "effect";
|
|
|
7
7
|
* takes the same names, so a reply a member approves, or a chat post, leaves through the connection
|
|
8
8
|
* of the channel the chat is on. Where the platform keys a chat by its `provider`, such as
|
|
9
9
|
* `agent_chat` and the archive, the value is the channel's name.
|
|
10
|
+
*
|
|
11
|
+
* A workspace may define a channel in its own code (`docs/agent.md`, "Workspace channels"): its
|
|
12
|
+
* kind is {@link WORKSPACE_CHANNEL_KIND}, it always has a name of its own, and the agent sends
|
|
13
|
+
* through it, so a reply a member approves, or a chat post, goes to the agent's channel instead of
|
|
14
|
+
* a connection. Its people's accounts are its own: {@link channelIdentityProvider}.
|
|
10
15
|
*/
|
|
11
|
-
/** The kinds of channel the platform
|
|
16
|
+
/** The kinds of channel the platform provides, each with a channel named after it. */
|
|
12
17
|
export const CHAT_CHANNEL_KINDS = ["telegram", "slack", "whatsapp", "email"];
|
|
13
18
|
export function isChatChannelKind(value) {
|
|
14
19
|
return CHAT_CHANNEL_KINDS.some((kind) => kind === value);
|
|
15
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* The kind of a channel the workspace defines in its own code. No channel is named after it: each
|
|
23
|
+
* has a name of its own.
|
|
24
|
+
*/
|
|
25
|
+
export const WORKSPACE_CHANNEL_KIND = "custom";
|
|
26
|
+
/** Every kind a channel of another name may say: the platform's, and the workspace's own. */
|
|
27
|
+
export const CHAT_KINDS = [...CHAT_CHANNEL_KINDS, WORKSPACE_CHANNEL_KIND];
|
|
28
|
+
export function isChatKind(value) {
|
|
29
|
+
return CHAT_KINDS.some((kind) => kind === value);
|
|
30
|
+
}
|
|
16
31
|
/** A channel's name: a lower-case letter, then up to 31 lower-case letters, digits or `_`. */
|
|
17
32
|
export const CHAT_CHANNEL_NAME = /^[a-z][a-z0-9_]{0,31}$/;
|
|
18
33
|
export const ChatChannelName = Schema.String.check(Schema.isPattern(CHAT_CHANNEL_NAME)).annotate({
|
|
19
34
|
description: "The channel's name, as the agent's channels and the ontology's chat name it: its kind, such " +
|
|
20
35
|
"as telegram, for the channel named after its kind.",
|
|
21
36
|
});
|
|
37
|
+
/** What a workspace channel's people's accounts are named under, before the channel's name. */
|
|
38
|
+
const WORKSPACE_IDENTITY_PREFIX = "channel:";
|
|
39
|
+
/** A workspace channel's identity provider: `channel:<name>`. */
|
|
40
|
+
export const WORKSPACE_IDENTITY_PROVIDER = /^channel:[a-z][a-z0-9_]{0,31}$/;
|
|
41
|
+
/**
|
|
42
|
+
* The provider of the accounts people write from on the channel `name` of `kind`: the kind for
|
|
43
|
+
* the platform's channels, whose accounts are the same on every channel of the kind, and
|
|
44
|
+
* `channel:<name>` for a workspace channel, whose accounts are its own, so it can claim no
|
|
45
|
+
* Telegram, WhatsApp or email account, nor another workspace channel's.
|
|
46
|
+
*/
|
|
47
|
+
export function channelIdentityProvider(kind, name) {
|
|
48
|
+
return kind === WORKSPACE_CHANNEL_KIND ? `${WORKSPACE_IDENTITY_PREFIX}${name}` : kind;
|
|
49
|
+
}
|
|
50
|
+
/** The workspace channel whose accounts `provider` names, or undefined for any other provider. */
|
|
51
|
+
export function workspaceChannelOf(provider) {
|
|
52
|
+
return WORKSPACE_IDENTITY_PROVIDER.test(provider)
|
|
53
|
+
? provider.slice(WORKSPACE_IDENTITY_PREFIX.length)
|
|
54
|
+
: undefined;
|
|
55
|
+
}
|
|
22
56
|
/**
|
|
23
57
|
* The kind of the channel `name`, by `chat`'s entries: the kind an entry names, or the name itself
|
|
24
58
|
* for the channel named after its kind. Undefined for a name that is neither.
|
|
@@ -31,5 +65,5 @@ export function chatChannelKind(chat, name) {
|
|
|
31
65
|
if (isChatChannelKind(name)) {
|
|
32
66
|
return kind === undefined || kind === name ? name : undefined;
|
|
33
67
|
}
|
|
34
|
-
return
|
|
68
|
+
return isChatKind(kind) && name !== WORKSPACE_CHANNEL_KIND ? kind : undefined;
|
|
35
69
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The safety rules of an email the workspace lays out itself, applied to its HTML as a browser
|
|
3
|
+
* reads it. A small tokenizer follows the HTML standard's tag, attribute, comment and raw-text
|
|
4
|
+
* states, so markup cannot hide a tag or an attribute from the check (an apostrophe in an unquoted
|
|
5
|
+
* value, a `/` between attributes, a missing space after a quote).
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* The values that may stand inside a tag, such as in an `href`: the platform's own addresses and
|
|
9
|
+
* the workspace's name. Every other value (the recipient's name, the code, what an action passes)
|
|
10
|
+
* stands only in text, where escaping keeps it text, so it can never become an address or add an
|
|
11
|
+
* attribute.
|
|
12
|
+
*/
|
|
13
|
+
export declare const EMAIL_MARKUP_VALUES: readonly ["link", "app.url", "app.mcpUrl", "workspace.name"];
|
|
14
|
+
/**
|
|
15
|
+
* Why an email's HTML is unsafe to send, or undefined: an element that runs code, embeds a page or
|
|
16
|
+
* posts a form; `<svg>`, `<math>` or `<plaintext>`; an event handler; a `<meta http-equiv>`; a
|
|
17
|
+
* value other than {@link EMAIL_MARKUP_VALUES} inside a tag, a comment or a `<style>`, or any value
|
|
18
|
+
* outside a quoted attribute value of a tag or right after `<`; a tag the HTML leaves unclosed; or
|
|
19
|
+
* an address that is not `https:`, `mailto:`, `tel:`, an anchor or the app's own `{{link}}`,
|
|
20
|
+
* `{{app.url}}` or `{{app.mcpUrl}}`. The platform applies the same rules to every deployed email
|
|
21
|
+
* before it sends one.
|
|
22
|
+
*/
|
|
23
|
+
export declare function unsafeEmailHtml(html: string): string | undefined;
|