@segmentstream/ontology 0.111.0 → 0.114.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 +41 -0
- package/README.md +9 -3
- package/dist/analyze.d.ts +8 -4
- package/dist/analyze.js +83 -35
- 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/permissions.d.ts +10 -3
- package/dist/permissions.js +10 -3
- package/dist/runtime/guests.d.ts +2 -1
- package/dist/runtime/guests.js +4 -3
- 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/dist/sign-in.d.ts
CHANGED
|
@@ -17,7 +17,12 @@ export type ChannelProvider = (typeof CHANNEL_PROVIDERS)[number];
|
|
|
17
17
|
* Telegram Mini App.
|
|
18
18
|
*/
|
|
19
19
|
export declare const SIGN_UP_CHANNELS: readonly ["email", "telegram", "whatsapp", "web"];
|
|
20
|
-
|
|
20
|
+
/**
|
|
21
|
+
* The people of a channel the workspace defines in its own code, `channel:<name>`, such as
|
|
22
|
+
* `channel:zernio`: the accounts they write from there, which are that channel's alone.
|
|
23
|
+
*/
|
|
24
|
+
export type WorkspaceSignUpChannel = `channel:${string}`;
|
|
25
|
+
export type SignUpChannel = (typeof SIGN_UP_CHANNELS)[number] | WorkspaceSignUpChannel;
|
|
21
26
|
/** The sign-up channels a person reaches through a chat, which need a matching `chat` adapter. */
|
|
22
27
|
export declare const SIGN_UP_CHAT_CHANNELS: ReadonlyArray<SignUpChannel>;
|
|
23
28
|
export declare function isSignUpChannel(value: unknown): value is SignUpChannel;
|
|
@@ -148,6 +153,22 @@ export interface SignInOptions {
|
|
|
148
153
|
* invitation when omitted. A checked ontology holds the email's wire name.
|
|
149
154
|
*/
|
|
150
155
|
readonly invitationEmail?: string;
|
|
156
|
+
/**
|
|
157
|
+
* One of the ontology's `emails`, by its camelCase name, that the platform sends instead of its
|
|
158
|
+
* own sign-in link: to anyone who asks the app for one, and when `User.sendSignInLink` names no
|
|
159
|
+
* template for a member who has signed in before. Like the invitation, it may use only the
|
|
160
|
+
* built-in values. The platform's own sign-in email when omitted.
|
|
161
|
+
*/
|
|
162
|
+
readonly linkEmail?: string;
|
|
163
|
+
/**
|
|
164
|
+
* One of the ontology's `emails`, by its camelCase name, that the platform sends instead of its
|
|
165
|
+
* own sign-in code, to a member who asks for one; a verification or reset code keeps the
|
|
166
|
+
* platform's. Besides the built-in values it shows `{{code}}`,
|
|
167
|
+
* the code, for instance as a section's value to copy. Its button opens the app's sign-in page
|
|
168
|
+
* with the code filled in when `codeLink` is on and is left out otherwise. The platform's own
|
|
169
|
+
* code email when omitted.
|
|
170
|
+
*/
|
|
171
|
+
readonly codeEmail?: string;
|
|
151
172
|
}
|
|
152
173
|
/** The sign-in options of a checked ontology, with the sign-up its definition declares. */
|
|
153
174
|
export interface ResolvedSignInOptions extends SignInOptions {
|
package/dist/sign-in.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { WORKSPACE_IDENTITY_PROVIDER } from "./chat-channel.js";
|
|
1
2
|
/**
|
|
2
3
|
* Who may become a member by signing in. `invited`: only a person whose email a member row already
|
|
3
4
|
* holds, created by an invitation or a role grant; anyone else is refused. `open`: anyone who signs
|
|
@@ -19,7 +20,8 @@ export const SIGN_UP_CHANNELS = ["email", "telegram", "whatsapp", "web"];
|
|
|
19
20
|
/** The sign-up channels a person reaches through a chat, which need a matching `chat` adapter. */
|
|
20
21
|
export const SIGN_UP_CHAT_CHANNELS = ["telegram", "whatsapp"];
|
|
21
22
|
export function isSignUpChannel(value) {
|
|
22
|
-
return SIGN_UP_CHANNELS.includes(value)
|
|
23
|
+
return (SIGN_UP_CHANNELS.includes(value) ||
|
|
24
|
+
(typeof value === "string" && WORKSPACE_IDENTITY_PROVIDER.test(value)));
|
|
23
25
|
}
|
|
24
26
|
/** The channels a guest talks to the agent through: only `web`, a website's chat, so far. */
|
|
25
27
|
export const GUEST_CHANNELS = ["web"];
|
package/dist/storage/tables.d.ts
CHANGED
|
@@ -3,10 +3,11 @@ export declare const BLOB_TABLES_DDL: ReadonlyArray<string>;
|
|
|
3
3
|
/** The agent's temporary attachments, beside the blob tables whose storage they share. */
|
|
4
4
|
export declare const ATTACHMENTS_TABLE = "_agent_attachments";
|
|
5
5
|
/**
|
|
6
|
-
* Where an attachment comes from: a chat message on a channel,
|
|
7
|
-
*
|
|
6
|
+
* Where an attachment comes from: a chat message on a channel, `channel` for a channel the
|
|
7
|
+
* workspace defines in its own code, or a file the agent produced in its sandbox and stores so
|
|
8
|
+
* that an action can keep it.
|
|
8
9
|
*/
|
|
9
|
-
export declare const ATTACHMENT_SOURCES: readonly ["telegram", "slack", "whatsapp", "email", "sandbox"];
|
|
10
|
+
export declare const ATTACHMENT_SOURCES: readonly ["telegram", "slack", "whatsapp", "email", "sandbox", "channel"];
|
|
10
11
|
/** The check that limits `source` to {@link ATTACHMENT_SOURCES}; its name is PostgreSQL's default. */
|
|
11
12
|
export declare const ATTACHMENT_SOURCE_CHECK = "_agent_attachments_source_check";
|
|
12
13
|
/**
|
package/dist/storage/tables.js
CHANGED
|
@@ -56,10 +56,18 @@ export const BLOB_TABLES_DDL = [
|
|
|
56
56
|
/** The agent's temporary attachments, beside the blob tables whose storage they share. */
|
|
57
57
|
export const ATTACHMENTS_TABLE = "_agent_attachments";
|
|
58
58
|
/**
|
|
59
|
-
* Where an attachment comes from: a chat message on a channel,
|
|
60
|
-
*
|
|
59
|
+
* Where an attachment comes from: a chat message on a channel, `channel` for a channel the
|
|
60
|
+
* workspace defines in its own code, or a file the agent produced in its sandbox and stores so
|
|
61
|
+
* that an action can keep it.
|
|
61
62
|
*/
|
|
62
|
-
export const ATTACHMENT_SOURCES = [
|
|
63
|
+
export const ATTACHMENT_SOURCES = [
|
|
64
|
+
"telegram",
|
|
65
|
+
"slack",
|
|
66
|
+
"whatsapp",
|
|
67
|
+
"email",
|
|
68
|
+
"sandbox",
|
|
69
|
+
"channel",
|
|
70
|
+
];
|
|
63
71
|
/** The check that limits `source` to {@link ATTACHMENT_SOURCES}; its name is PostgreSQL's default. */
|
|
64
72
|
export const ATTACHMENT_SOURCE_CHECK = `${ATTACHMENTS_TABLE}_source_check`;
|
|
65
73
|
const SOURCE_CHECK = `CHECK ("source" IN (${ATTACHMENT_SOURCES.map((source) => `'${source}'`).join(", ")}))`;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The contract between the ontology service and a channel the workspace defines in its own code
|
|
3
|
+
* (`docs/agent.md`, "Workspace channels"). The ontology cannot send through such a channel: the
|
|
4
|
+
* agent's code knows the provider. A reply a member approves, and a chat post, reach the person
|
|
5
|
+
* through the agent instead, at {@link workspaceChannelSendRoute}, which only the deployment's own
|
|
6
|
+
* functions may call, with their Vercel OIDC token, as the ontology hands the agent its tasks.
|
|
7
|
+
*
|
|
8
|
+
* The text is sent as written: the platform knows no formatting of the provider, so the agent's
|
|
9
|
+
* confirmation of a chat post and the ontology compute the same text with
|
|
10
|
+
* {@link renderWorkspaceChannelText}.
|
|
11
|
+
*/
|
|
12
|
+
/** Where the agent serves its workspace channels, each under its name. */
|
|
13
|
+
export declare const WORKSPACE_CHANNEL_ROUTE = "/eve/segmentstream/v1/custom";
|
|
14
|
+
/**
|
|
15
|
+
* The route of the workspace channel `name`: where its webhook receives, or where the platform
|
|
16
|
+
* wakes it when it reads its source on a schedule.
|
|
17
|
+
*/
|
|
18
|
+
export declare function workspaceChannelRoute(name: string): string;
|
|
19
|
+
/** The route the ontology sends an approved reply or a chat post through, as the deployment. */
|
|
20
|
+
export declare function workspaceChannelSendRoute(name: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* A chat, person or message id on a workspace channel: letters, digits and `:_.@+-`, at most 256
|
|
23
|
+
* characters, as the platform keys chats and their provenance. A provider's id of other characters
|
|
24
|
+
* is encoded by the channel's code, such as in base64url.
|
|
25
|
+
*/
|
|
26
|
+
export declare const WORKSPACE_CHANNEL_ID: RegExp;
|
|
27
|
+
/** The most characters one message through a workspace channel may have, whatever its provider. */
|
|
28
|
+
export declare const WORKSPACE_CHANNEL_TEXT_LIMIT = 20000;
|
|
29
|
+
/** The text a workspace channel sends: the text as written, then the separator and attribution. */
|
|
30
|
+
export declare function renderWorkspaceChannelText(text: string, attribution: string, separator: string): string;
|
|
31
|
+
/** `POST` {@link workspaceChannelSendRoute}: one message to one person's chat. */
|
|
32
|
+
export interface WorkspaceChannelSend {
|
|
33
|
+
/** Names the message, so a send the ontology tries again is the same message. */
|
|
34
|
+
readonly operation_id: string;
|
|
35
|
+
/**
|
|
36
|
+
* The chat's id on the channel, as the agent keyed it; null for a chat post, which names only the
|
|
37
|
+
* person: the agent sends it to the chat the person last wrote from, and refuses it with
|
|
38
|
+
* `chat_unknown` when they never wrote.
|
|
39
|
+
*/
|
|
40
|
+
readonly chat_id: string | null;
|
|
41
|
+
/** Whom the channel sends to: the chat's person. */
|
|
42
|
+
readonly recipient: string;
|
|
43
|
+
readonly thread_id: string | null;
|
|
44
|
+
/** The message the post answers, when the channel replies to one. */
|
|
45
|
+
readonly reply_to: string | null;
|
|
46
|
+
readonly text: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The agent's answer: `200 { message_id }` once the channel's `send` returned, with the provider's
|
|
50
|
+
* id when it gave one. A `4xx` with `{ error }` sent nothing; anything else may have sent it.
|
|
51
|
+
*/
|
|
52
|
+
export interface WorkspaceChannelSent {
|
|
53
|
+
readonly message_id: string | null;
|
|
54
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The contract between the ontology service and a channel the workspace defines in its own code
|
|
3
|
+
* (`docs/agent.md`, "Workspace channels"). The ontology cannot send through such a channel: the
|
|
4
|
+
* agent's code knows the provider. A reply a member approves, and a chat post, reach the person
|
|
5
|
+
* through the agent instead, at {@link workspaceChannelSendRoute}, which only the deployment's own
|
|
6
|
+
* functions may call, with their Vercel OIDC token, as the ontology hands the agent its tasks.
|
|
7
|
+
*
|
|
8
|
+
* The text is sent as written: the platform knows no formatting of the provider, so the agent's
|
|
9
|
+
* confirmation of a chat post and the ontology compute the same text with
|
|
10
|
+
* {@link renderWorkspaceChannelText}.
|
|
11
|
+
*/
|
|
12
|
+
/** Where the agent serves its workspace channels, each under its name. */
|
|
13
|
+
export const WORKSPACE_CHANNEL_ROUTE = "/eve/segmentstream/v1/custom";
|
|
14
|
+
/**
|
|
15
|
+
* The route of the workspace channel `name`: where its webhook receives, or where the platform
|
|
16
|
+
* wakes it when it reads its source on a schedule.
|
|
17
|
+
*/
|
|
18
|
+
export function workspaceChannelRoute(name) {
|
|
19
|
+
return `${WORKSPACE_CHANNEL_ROUTE}/${name}`;
|
|
20
|
+
}
|
|
21
|
+
/** The route the ontology sends an approved reply or a chat post through, as the deployment. */
|
|
22
|
+
export function workspaceChannelSendRoute(name) {
|
|
23
|
+
return `${workspaceChannelRoute(name)}/send`;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A chat, person or message id on a workspace channel: letters, digits and `:_.@+-`, at most 256
|
|
27
|
+
* characters, as the platform keys chats and their provenance. A provider's id of other characters
|
|
28
|
+
* is encoded by the channel's code, such as in base64url.
|
|
29
|
+
*/
|
|
30
|
+
export const WORKSPACE_CHANNEL_ID = /^[A-Za-z0-9:_.@+-]{1,256}$/;
|
|
31
|
+
/** The most characters one message through a workspace channel may have, whatever its provider. */
|
|
32
|
+
export const WORKSPACE_CHANNEL_TEXT_LIMIT = 20_000;
|
|
33
|
+
/** The text a workspace channel sends: the text as written, then the separator and attribution. */
|
|
34
|
+
export function renderWorkspaceChannelText(text, attribution, separator) {
|
|
35
|
+
return attribution === "" ? text : `${text}${separator}${attribution}`;
|
|
36
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@segmentstream/ontology",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.114.0",
|
|
4
4
|
"description": "Define a SegmentStream workspace app's ontology: entities, relationships, roles and actions, written with Effect.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "SegmentStream",
|
|
@@ -41,6 +41,10 @@
|
|
|
41
41
|
"types": "./dist/email.d.ts",
|
|
42
42
|
"import": "./dist/email.js"
|
|
43
43
|
},
|
|
44
|
+
"./workspace-channel": {
|
|
45
|
+
"types": "./dist/workspace-channel.d.ts",
|
|
46
|
+
"import": "./dist/workspace-channel.js"
|
|
47
|
+
},
|
|
44
48
|
"./channel-session": {
|
|
45
49
|
"types": "./dist/channel-session.d.ts",
|
|
46
50
|
"import": "./dist/channel-session.js"
|