@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.
Files changed (47) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/README.md +9 -3
  3. package/dist/analyze.d.ts +8 -4
  4. package/dist/analyze.js +72 -27
  5. package/dist/chat-channel.d.ts +27 -2
  6. package/dist/chat-channel.js +36 -2
  7. package/dist/email-html.d.ts +23 -0
  8. package/dist/email-html.js +249 -0
  9. package/dist/emails.d.ts +38 -6
  10. package/dist/emails.js +71 -2
  11. package/dist/index.d.ts +5 -3
  12. package/dist/index.js +3 -1
  13. package/dist/manifest.d.ts +208 -52
  14. package/dist/manifest.js +32 -6
  15. package/dist/migrate/model.d.ts +98 -34
  16. package/dist/runtime/resolve-agent-identity.js +4 -1
  17. package/dist/service/agent/protocol.d.ts +4 -1
  18. package/dist/service/agent/protocol.js +7 -3
  19. package/dist/service/agent/server.js +8 -2
  20. package/dist/service/authentication.d.ts +2 -1
  21. package/dist/service/authentication.js +13 -3
  22. package/dist/service/chat/delivery.d.ts +10 -1
  23. package/dist/service/chat/delivery.js +21 -3
  24. package/dist/service/chat/envelope.d.ts +2 -2
  25. package/dist/service/chat/providers/custom.d.ts +13 -0
  26. package/dist/service/chat/providers/custom.js +103 -0
  27. package/dist/service/chat/providers/index.d.ts +1 -0
  28. package/dist/service/chat/providers/index.js +12 -3
  29. package/dist/service/chat/providers/provider.d.ts +19 -0
  30. package/dist/service/chat/reads.d.ts +1 -1
  31. package/dist/service/chat/reads.js +2 -2
  32. package/dist/service/chat/resolve.d.ts +2 -1
  33. package/dist/service/chat/resolve.js +6 -2
  34. package/dist/service/chat/review-delivery.d.ts +3 -0
  35. package/dist/service/chat/review-delivery.js +9 -3
  36. package/dist/service/chat/schemas.d.ts +2 -2
  37. package/dist/service/chat/schemas.js +2 -2
  38. package/dist/service/config.d.ts +6 -2
  39. package/dist/service/schemas.d.ts +30 -8
  40. package/dist/service/service.js +6 -1
  41. package/dist/sign-in.d.ts +22 -1
  42. package/dist/sign-in.js +3 -1
  43. package/dist/storage/tables.d.ts +4 -3
  44. package/dist/storage/tables.js +11 -3
  45. package/dist/workspace-channel.d.ts +54 -0
  46. package/dist/workspace-channel.js +36 -0
  47. package/package.json +5 -1
@@ -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, or a file the agent produced in its
60
- * sandbox and stores so that an action can keep it.
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 = ["telegram", "slack", "whatsapp", "email", "sandbox"];
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.111.0",
3
+ "version": "0.113.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"