@segmentstream/ontology 0.110.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 +54 -0
- package/README.md +15 -3
- package/dist/agent-review.d.ts +2 -0
- package/dist/agent-review.js +11 -1
- package/dist/analyze.d.ts +38 -34
- package/dist/analyze.js +109 -41
- package/dist/chat-channel.d.ts +47 -0
- package/dist/chat-channel.js +69 -0
- 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 +6 -2
- package/dist/index.js +3 -0
- package/dist/manifest.d.ts +282 -50
- package/dist/manifest.js +41 -6
- package/dist/migrate/model.d.ts +126 -18
- package/dist/runtime/agents.js +3 -0
- package/dist/runtime/resolve-agent-identity.js +4 -1
- package/dist/runtime-source.d.ts +4 -0
- package/dist/runtime-source.js +5 -0
- package/dist/runtime.d.ts +4 -1
- package/dist/service/agent/protocol.d.ts +5 -1
- package/dist/service/agent/protocol.js +12 -3
- package/dist/service/agent/server.js +17 -0
- package/dist/service/authentication.d.ts +5 -3
- package/dist/service/authentication.js +20 -5
- package/dist/service/chat/delivery.d.ts +10 -1
- package/dist/service/chat/delivery.js +30 -8
- package/dist/service/chat/envelope.d.ts +8 -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 +20 -9
- package/dist/service/chat/providers/index.js +41 -12
- package/dist/service/chat/providers/provider.d.ts +19 -0
- package/dist/service/chat/reads.d.ts +6 -3
- package/dist/service/chat/reads.js +26 -14
- package/dist/service/chat/resolve.d.ts +7 -2
- package/dist/service/chat/resolve.js +11 -3
- package/dist/service/chat/review-delivery.d.ts +5 -2
- package/dist/service/chat/review-delivery.js +23 -9
- package/dist/service/chat/routes.js +2 -1
- package/dist/service/chat/schemas.d.ts +2 -0
- package/dist/service/chat/schemas.js +8 -1
- package/dist/service/config.d.ts +6 -2
- package/dist/service/mcp/server.js +2 -1
- package/dist/service/runtime-contract.d.ts +9 -0
- package/dist/service/schemas.d.ts +34 -4
- 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
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
|
+
import { channelIdentityProvider } from "../../chat-channel.js";
|
|
2
3
|
import { ActionRejected, PermissionDenied } from "../../errors.js";
|
|
3
4
|
import { isAllowed } from "../../permissions.js";
|
|
4
5
|
import { ChatArchiveUnavailable } from "../agent/chat-archive.js";
|
|
@@ -66,10 +67,14 @@ export function withChatMembership(transport, backend) {
|
|
|
66
67
|
})), Effect.flatMap((memberGroups) => transport({ ...input, memberGroups })));
|
|
67
68
|
}
|
|
68
69
|
/**
|
|
69
|
-
* Resolves the chats of `providers
|
|
70
|
-
* chat on each
|
|
70
|
+
* Resolves the chats of `providers`, the agent's channels by name: their group chats in the
|
|
71
|
+
* registry, and each member's private chat on each channel whose kind they have a live identity
|
|
72
|
+
* on, `<channel>:private:<member id>`. People are not per channel: one identity of a kind reaches
|
|
73
|
+
* the member on every channel of that kind. A workspace channel's accounts are its own
|
|
74
|
+
* (`channel:<name>`).
|
|
71
75
|
*/
|
|
72
76
|
export function chatResolver(backend, principal, providers, options = {}) {
|
|
77
|
+
const kindOf = options.kindOf ?? ((channel) => channel);
|
|
73
78
|
const canGroup = isAllowed("agent_chat:read", principal) || isAllowed("agent_chat:post_message", principal);
|
|
74
79
|
const memberGroups = options.memberGroups === true && principal.kind === "member";
|
|
75
80
|
const canDirectory = isAllowed("user:read", principal) || isAllowed("agent_chat:post_message", principal);
|
|
@@ -125,7 +130,10 @@ export function chatResolver(backend, principal, providers, options = {}) {
|
|
|
125
130
|
}
|
|
126
131
|
const identities = yield* backend.agents.listIdentities(member.principal.id);
|
|
127
132
|
for (const provider of named === undefined ? providers : [named]) {
|
|
128
|
-
const
|
|
133
|
+
const kind = kindOf(provider);
|
|
134
|
+
// The accounts of the channel's kind, or of a workspace channel its own.
|
|
135
|
+
const account = kind === undefined ? undefined : channelIdentityProvider(kind, provider);
|
|
136
|
+
const identity = identities.find((item) => account !== undefined && item.provider === account && item.revokedAt === null);
|
|
129
137
|
if (identity !== undefined) {
|
|
130
138
|
result.push({
|
|
131
139
|
id: `${provider}:private:${member.principal.id}`,
|
|
@@ -7,10 +7,11 @@ import type { Principal } from "../../runtime.js";
|
|
|
7
7
|
import type { ConnectionTransportFactory } from "../connections.js";
|
|
8
8
|
import type { OntologyBackend } from "../runtime-contract.js";
|
|
9
9
|
import type { DeliveryArchive } from "./archive.js";
|
|
10
|
+
import type { AgentChannelTransport } from "./providers/provider.js";
|
|
10
11
|
/**
|
|
11
12
|
* Sends a reply the agent held for review, once a member approved it: the draft or the member's
|
|
12
|
-
* edit, to the person's chat through the ontology's chat connection
|
|
13
|
-
* the agent and without attribution. The archive's delivery claim, keyed by the review and not by
|
|
13
|
+
* edit, to the person's chat through the ontology's chat connection of the channel the chat is on,
|
|
14
|
+
* as the agent and without attribution. The archive's delivery claim, keyed by the review and not by
|
|
14
15
|
* the member, makes it at most once: a replay of the same approval returns the delivery, and a
|
|
15
16
|
* different approval, by another member or with another text, is refused. A provider that refused
|
|
16
17
|
* it consumes the claim: the reply is never sent again.
|
|
@@ -18,6 +19,8 @@ import type { DeliveryArchive } from "./archive.js";
|
|
|
18
19
|
export declare function reviewSender(input: {
|
|
19
20
|
readonly ontology: Ontology;
|
|
20
21
|
readonly connections: ConnectionTransportFactory;
|
|
22
|
+
/** The app's agent, which sends through a workspace channel. */
|
|
23
|
+
readonly agent?: AgentChannelTransport;
|
|
21
24
|
readonly archive: DeliveryArchive;
|
|
22
25
|
/** Link previews for the destination connection, as a chat post gets them. */
|
|
23
26
|
readonly previews?: TelegramPreviewContext;
|
|
@@ -4,11 +4,12 @@ import { ActionRejected, PermissionDenied } from "../../errors.js";
|
|
|
4
4
|
import { effectiveScope } from "../../permissions.js";
|
|
5
5
|
import { describeChatError } from "./diagnostics.js";
|
|
6
6
|
import { deliveryFingerprint, deliveryKeyDigest, deliveryScopeDigest } from "./idempotency.js";
|
|
7
|
-
import {
|
|
7
|
+
import { WORKSPACE_CHANNEL_KIND } from "../../chat-channel.js";
|
|
8
|
+
import { channelProvider, chatConnection, chatKind } from "./providers/index.js";
|
|
8
9
|
/**
|
|
9
10
|
* Sends a reply the agent held for review, once a member approved it: the draft or the member's
|
|
10
|
-
* edit, to the person's chat through the ontology's chat connection
|
|
11
|
-
* the agent and without attribution. The archive's delivery claim, keyed by the review and not by
|
|
11
|
+
* edit, to the person's chat through the ontology's chat connection of the channel the chat is on,
|
|
12
|
+
* as the agent and without attribution. The archive's delivery claim, keyed by the review and not by
|
|
12
13
|
* the member, makes it at most once: a replay of the same approval returns the delivery, and a
|
|
13
14
|
* different approval, by another member or with another text, is refused. A provider that refused
|
|
14
15
|
* it consumes the claim: the reply is never sent again.
|
|
@@ -62,13 +63,23 @@ export function reviewSender(input) {
|
|
|
62
63
|
: "The reply was already approved; it is never sent again.",
|
|
63
64
|
});
|
|
64
65
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
// The channel the chat is on, by name. A review held before channels had names has none:
|
|
67
|
+
// it is on the channel named after its kind.
|
|
68
|
+
// @legacy ontology.reviews-without-channel
|
|
69
|
+
const providerName = typeof review.channel === "string" && review.channel !== ""
|
|
70
|
+
? review.channel
|
|
71
|
+
: String(review.provider);
|
|
72
|
+
const provider = channelProvider(input.ontology.manifest.chat, providerName);
|
|
73
|
+
const connection = chatConnection(input.ontology.manifest.chat, providerName) ?? "";
|
|
74
|
+
const channelKind = chatKind(input.ontology.manifest.chat, providerName);
|
|
75
|
+
// A workspace channel needs no connection of the ontology's: the agent sends through it.
|
|
76
|
+
if (provider === undefined ||
|
|
77
|
+
(!connection && channelKind !== WORKSPACE_CHANNEL_KIND) ||
|
|
78
|
+
channelKind !== String(review.provider)) {
|
|
69
79
|
return yield* new ActionRejected({
|
|
70
|
-
message: `Sending a reviewed reply needs chat.${providerName}.connection in defineOntology
|
|
71
|
-
|
|
80
|
+
message: `Sending a reviewed reply needs chat.${providerName}.connection in defineOntology, ` +
|
|
81
|
+
`of kind ${String(review.provider)}: the connection of the bot, number or mailbox ` +
|
|
82
|
+
"the person talks to.",
|
|
72
83
|
});
|
|
73
84
|
}
|
|
74
85
|
const kind = review.chat_kind === "group" ? "group" : "private";
|
|
@@ -222,6 +233,9 @@ export function reviewSender(input) {
|
|
|
222
233
|
plainText,
|
|
223
234
|
replyTo,
|
|
224
235
|
threadId,
|
|
236
|
+
operationId,
|
|
237
|
+
chatId,
|
|
238
|
+
...(input.agent === undefined ? {} : { agent: input.agent }),
|
|
225
239
|
...(input.previews === undefined ? {} : { previews: input.previews }),
|
|
226
240
|
transport: input.connections({
|
|
227
241
|
identityToken: input.identityToken,
|
|
@@ -8,7 +8,7 @@ import { RequestId, failureResponse } from "../errors.js";
|
|
|
8
8
|
import { OntologyBackend } from "../runtime-contract.js";
|
|
9
9
|
import { identityToken, makeOperations } from "../operations.js";
|
|
10
10
|
import { ChatSearch } from "../agent/chat-archive.js";
|
|
11
|
-
import { listedChatProviders } from "./providers/index.js";
|
|
11
|
+
import { chatKind, listedChatProviders } from "./providers/index.js";
|
|
12
12
|
import { chatReads } from "./reads.js";
|
|
13
13
|
import { withChatMembership } from "./resolve.js";
|
|
14
14
|
import { ChatList, ChatHistory } from "./schemas.js";
|
|
@@ -19,6 +19,7 @@ export function chatRoutes(options) {
|
|
|
19
19
|
const chatHistory = options.chatHistory && withChatMembership(options.chatHistory, backend);
|
|
20
20
|
const reads = chatReads(backend, {
|
|
21
21
|
providers: listedChatProviders(options.built.plan.ontology.manifest.chat),
|
|
22
|
+
kindOf: (channel) => chatKind(options.built.plan.ontology.manifest.chat, channel),
|
|
22
23
|
chatHistory,
|
|
23
24
|
attribution: options.built.plan.ontology.config.chat?.attribution,
|
|
24
25
|
});
|
|
@@ -28,6 +28,7 @@ export declare const ChatDestination: Schema.Struct<{
|
|
|
28
28
|
readonly id: Schema.String;
|
|
29
29
|
readonly title: Schema.String;
|
|
30
30
|
readonly provider: Schema.String;
|
|
31
|
+
readonly kind: Schema.optionalKey<Schema.Literals<readonly ["telegram", "slack", "whatsapp", "email", "custom"]>>;
|
|
31
32
|
readonly external_id: Schema.String;
|
|
32
33
|
readonly attribution: Schema.NullOr<Schema.String>;
|
|
33
34
|
}>;
|
|
@@ -36,6 +37,7 @@ export declare const ChatListResult: Schema.Struct<{
|
|
|
36
37
|
readonly id: Schema.String;
|
|
37
38
|
readonly title: Schema.String;
|
|
38
39
|
readonly provider: Schema.String;
|
|
40
|
+
readonly kind: Schema.optionalKey<Schema.Literals<readonly ["telegram", "slack", "whatsapp", "email", "custom"]>>;
|
|
39
41
|
readonly external_id: Schema.String;
|
|
40
42
|
readonly attribution: Schema.NullOr<Schema.String>;
|
|
41
43
|
}>>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
2
|
import { ChatPostInput } from "../../chat.js";
|
|
3
|
+
import { CHAT_KINDS } from "../../chat-channel.js";
|
|
3
4
|
const Id = Schema.String.check(Schema.isMinLength(1), Schema.isMaxLength(512));
|
|
4
5
|
export const ChatPostWire = ChatPostInput.pipe(Schema.encodeKeys({ replyTo: "reply_to", idempotencyKey: "idempotency_key" }));
|
|
5
6
|
export const RuntimeChatPostWire = Schema.Struct({
|
|
@@ -21,7 +22,13 @@ export const ChatHistory = Schema.Struct({
|
|
|
21
22
|
export const ChatDestination = Schema.Struct({
|
|
22
23
|
id: Id,
|
|
23
24
|
title: Schema.String,
|
|
24
|
-
provider: Schema.String
|
|
25
|
+
provider: Schema.String.annotate({
|
|
26
|
+
description: "The agent's channel the chat is on, by its name: its kind for the channel named after " +
|
|
27
|
+
"its kind, such as telegram.",
|
|
28
|
+
}),
|
|
29
|
+
kind: Schema.optionalKey(Schema.Literals(CHAT_KINDS).annotate({
|
|
30
|
+
description: "The kind of that channel, which decides how a message to the chat renders.",
|
|
31
|
+
})),
|
|
25
32
|
external_id: Id,
|
|
26
33
|
attribution: Schema.NullOr(Schema.String),
|
|
27
34
|
});
|
package/dist/service/config.d.ts
CHANGED
|
@@ -122,7 +122,8 @@ export interface OntologyEnvironment {
|
|
|
122
122
|
readonly localConnections?: LocalConnectionContext;
|
|
123
123
|
/**
|
|
124
124
|
* The deployment's production origin, `https://` and `VERCEL_PROJECT_PRODUCTION_URL`, where
|
|
125
|
-
* `agentTask` hands the app's agent its tasks
|
|
125
|
+
* `agentTask` hands the app's agent its tasks, a workspace channel's approved replies and chat
|
|
126
|
+
* posts reach the agent, and sign-in links sent from actions open.
|
|
126
127
|
* Production only: without it, and without `runtimeIdentity`, `agentTask` answers
|
|
127
128
|
* `agent_unavailable`, and `User.sendSignInLink` marks its emails failed.
|
|
128
129
|
*/
|
|
@@ -204,7 +205,10 @@ export interface OntologyServiceConfig extends OntologyEnvironment {
|
|
|
204
205
|
* replace it.
|
|
205
206
|
*/
|
|
206
207
|
readonly emailCodes?: import("./agent/guest-sign-up.js").EmailCodes;
|
|
207
|
-
/**
|
|
208
|
+
/**
|
|
209
|
+
* How `agentTask`, and a workspace channel's approved reply or chat post, call the app's agent at
|
|
210
|
+
* `agentOrigin`: `fetch` by default. Tests replace it.
|
|
211
|
+
*/
|
|
208
212
|
readonly agentTaskTransport?: import("./agent/task-start.js").AgentTransport;
|
|
209
213
|
/**
|
|
210
214
|
* How `discover` asks the decision model of `defineOntology({ discovery })`: AI Gateway, with
|
|
@@ -14,7 +14,7 @@ import { CONFIRMATION_PREVIEW_METHOD, previewLocale, withoutConfirmation } from
|
|
|
14
14
|
import { consumeChatEnvelope, CurrentChatCall } from "../chat/envelope.js";
|
|
15
15
|
import { ChatList, ChatHistory, ChatPostWire, RuntimeChatPostWire } from "../chat/schemas.js";
|
|
16
16
|
import { ChatPostResult } from "../../chat.js";
|
|
17
|
-
import { listedChatProviders } from "../chat/providers/index.js";
|
|
17
|
+
import { chatKind, listedChatProviders } from "../chat/providers/index.js";
|
|
18
18
|
import { chatReads } from "../chat/reads.js";
|
|
19
19
|
import { withChatMembership } from "../chat/resolve.js";
|
|
20
20
|
import { catalogFor } from "../catalog.js";
|
|
@@ -850,6 +850,7 @@ export function mcpLayer(options) {
|
|
|
850
850
|
const server = {
|
|
851
851
|
chats: chatReads(backend, {
|
|
852
852
|
providers: listedChatProviders(options.built.plan.ontology.manifest.chat),
|
|
853
|
+
kindOf: (channel) => chatKind(options.built.plan.ontology.manifest.chat, channel),
|
|
853
854
|
chatHistory,
|
|
854
855
|
attribution: options.built.plan.ontology.config.chat?.attribution,
|
|
855
856
|
}),
|
|
@@ -599,6 +599,12 @@ export interface AgentStore {
|
|
|
599
599
|
readonly member: (userId: string) => Effect.Effect<AgentMember | undefined>;
|
|
600
600
|
/** The member a runtime caller acts for: active, and with a live identity. */
|
|
601
601
|
readonly actingMember: (userId: string, provider?: string) => Effect.Effect<Principal | undefined>;
|
|
602
|
+
/**
|
|
603
|
+
* The kind of the agent's channel `name`, as the ontology's `chat` declares it: the name itself
|
|
604
|
+
* for the channel named after its kind, such as `telegram`; `undefined` for another name it does
|
|
605
|
+
* not declare. Without it, every channel is taken for the one named after its kind.
|
|
606
|
+
*/
|
|
607
|
+
readonly channelKind?: (name: string) => string | undefined;
|
|
602
608
|
/**
|
|
603
609
|
* Records a message the agent saw in a group chat: creates the `agent_chat` or keeps its title
|
|
604
610
|
* current, records when the chat last had a message (at most every 15 minutes, so that history
|
|
@@ -630,7 +636,10 @@ export interface AgentStore {
|
|
|
630
636
|
/** A reply the agent held for review, as `POST /api/ontology/agent/reviews` reports it. */
|
|
631
637
|
export interface HeldReplyInput {
|
|
632
638
|
readonly key: string;
|
|
639
|
+
/** The kind of channel the chat is on, such as whatsapp. */
|
|
633
640
|
readonly provider: string;
|
|
641
|
+
/** The channel the chat is on, by name: its kind for the channel named after its kind. */
|
|
642
|
+
readonly channel: string;
|
|
634
643
|
readonly chatId: string;
|
|
635
644
|
/** Whom the provider sends the reply to: the chat's id, or the person's id where it differs. */
|
|
636
645
|
readonly recipient: string;
|
|
@@ -470,14 +470,25 @@ export declare const Catalog: Schema.decodeTo<Schema.Struct<{
|
|
|
470
470
|
readonly botCheck: "bot_check";
|
|
471
471
|
}>>;
|
|
472
472
|
readonly invitationEmail: Schema.optionalKey<Schema.String>;
|
|
473
|
+
readonly linkEmail: Schema.optionalKey<Schema.String>;
|
|
474
|
+
readonly codeEmail: Schema.optionalKey<Schema.String>;
|
|
473
475
|
}>, {
|
|
474
476
|
readonly onNewUser: "on_new_user";
|
|
475
477
|
readonly codeLink: "code_link";
|
|
476
478
|
readonly signUp: "sign_up";
|
|
477
479
|
readonly onSignUp: "on_sign_up";
|
|
478
480
|
readonly invitationEmail: "invitation_email";
|
|
481
|
+
readonly linkEmail: "link_email";
|
|
482
|
+
readonly codeEmail: "code_email";
|
|
479
483
|
}>>;
|
|
480
|
-
readonly emails: Schema.optionalKey<Schema.$Record<Schema.String, Schema.encodeKeys<Schema.Struct<{
|
|
484
|
+
readonly emails: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Union<readonly [Schema.encodeKeys<Schema.Struct<{
|
|
485
|
+
readonly subject: Schema.String;
|
|
486
|
+
readonly html: Schema.String;
|
|
487
|
+
readonly text: Schema.String;
|
|
488
|
+
readonly replyTo: Schema.optionalKey<Schema.String>;
|
|
489
|
+
}>, {
|
|
490
|
+
readonly replyTo: "reply_to";
|
|
491
|
+
}>, Schema.encodeKeys<Schema.Struct<{
|
|
481
492
|
readonly subject: Schema.String;
|
|
482
493
|
readonly eyebrow: Schema.optionalKey<Schema.String>;
|
|
483
494
|
readonly heading: Schema.String;
|
|
@@ -506,7 +517,7 @@ export declare const Catalog: Schema.decodeTo<Schema.Struct<{
|
|
|
506
517
|
readonly replyTo: Schema.optionalKey<Schema.String>;
|
|
507
518
|
}>, {
|
|
508
519
|
readonly replyTo: "reply_to";
|
|
509
|
-
}>>>;
|
|
520
|
+
}>]>>>;
|
|
510
521
|
readonly connections: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
511
522
|
readonly key: Schema.String;
|
|
512
523
|
readonly description: Schema.String;
|
|
@@ -525,6 +536,10 @@ export declare const Catalog: Schema.decodeTo<Schema.Struct<{
|
|
|
525
536
|
readonly email: Schema.optionalKey<Schema.Struct<{
|
|
526
537
|
readonly connection: Schema.String;
|
|
527
538
|
}>>;
|
|
539
|
+
readonly channels: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Struct<{
|
|
540
|
+
readonly kind: Schema.Literals<readonly ["telegram", "slack", "whatsapp", "email", "custom"]>;
|
|
541
|
+
readonly connection: Schema.optionalKey<Schema.String>;
|
|
542
|
+
}>>>;
|
|
528
543
|
readonly attribution: Schema.optionalKey<Schema.Struct<{
|
|
529
544
|
readonly template: Schema.optionalKey<Schema.String>;
|
|
530
545
|
readonly separator: Schema.optionalKey<Schema.String>;
|
|
@@ -773,14 +788,25 @@ export declare const Catalog: Schema.decodeTo<Schema.Struct<{
|
|
|
773
788
|
readonly botCheck: "bot_check";
|
|
774
789
|
}>>;
|
|
775
790
|
readonly invitationEmail: Schema.optionalKey<Schema.String>;
|
|
791
|
+
readonly linkEmail: Schema.optionalKey<Schema.String>;
|
|
792
|
+
readonly codeEmail: Schema.optionalKey<Schema.String>;
|
|
776
793
|
}>, {
|
|
777
794
|
readonly onNewUser: "on_new_user";
|
|
778
795
|
readonly codeLink: "code_link";
|
|
779
796
|
readonly signUp: "sign_up";
|
|
780
797
|
readonly onSignUp: "on_sign_up";
|
|
781
798
|
readonly invitationEmail: "invitation_email";
|
|
799
|
+
readonly linkEmail: "link_email";
|
|
800
|
+
readonly codeEmail: "code_email";
|
|
782
801
|
}>>>;
|
|
783
|
-
readonly emails: Schema.toEncoded<Schema.optionalKey<Schema.$Record<Schema.String, Schema.encodeKeys<Schema.Struct<{
|
|
802
|
+
readonly emails: Schema.toEncoded<Schema.optionalKey<Schema.$Record<Schema.String, Schema.Union<readonly [Schema.encodeKeys<Schema.Struct<{
|
|
803
|
+
readonly subject: Schema.String;
|
|
804
|
+
readonly html: Schema.String;
|
|
805
|
+
readonly text: Schema.String;
|
|
806
|
+
readonly replyTo: Schema.optionalKey<Schema.String>;
|
|
807
|
+
}>, {
|
|
808
|
+
readonly replyTo: "reply_to";
|
|
809
|
+
}>, Schema.encodeKeys<Schema.Struct<{
|
|
784
810
|
readonly subject: Schema.String;
|
|
785
811
|
readonly eyebrow: Schema.optionalKey<Schema.String>;
|
|
786
812
|
readonly heading: Schema.String;
|
|
@@ -809,7 +835,7 @@ export declare const Catalog: Schema.decodeTo<Schema.Struct<{
|
|
|
809
835
|
readonly replyTo: Schema.optionalKey<Schema.String>;
|
|
810
836
|
}>, {
|
|
811
837
|
readonly replyTo: "reply_to";
|
|
812
|
-
}>>>>;
|
|
838
|
+
}>]>>>>;
|
|
813
839
|
readonly connections: Schema.toEncoded<Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
814
840
|
readonly key: Schema.String;
|
|
815
841
|
readonly description: Schema.String;
|
|
@@ -828,6 +854,10 @@ export declare const Catalog: Schema.decodeTo<Schema.Struct<{
|
|
|
828
854
|
readonly email: Schema.optionalKey<Schema.Struct<{
|
|
829
855
|
readonly connection: Schema.String;
|
|
830
856
|
}>>;
|
|
857
|
+
readonly channels: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Struct<{
|
|
858
|
+
readonly kind: Schema.Literals<readonly ["telegram", "slack", "whatsapp", "email", "custom"]>;
|
|
859
|
+
readonly connection: Schema.optionalKey<Schema.String>;
|
|
860
|
+
}>>>;
|
|
831
861
|
readonly attribution: Schema.optionalKey<Schema.Struct<{
|
|
832
862
|
readonly template: Schema.optionalKey<Schema.String>;
|
|
833
863
|
readonly separator: Schema.optionalKey<Schema.String>;
|
package/dist/service/service.js
CHANGED
|
@@ -342,7 +342,12 @@ export function createOntologyService(ontology, config) {
|
|
|
342
342
|
? deployedConnections(config)
|
|
343
343
|
: localConnections(config.localConnections)));
|
|
344
344
|
const replicate = deployedReplication(config);
|
|
345
|
-
const chatDelivery = makeChatDelivery(ontology, connections, config.chatArchive ?? platformDeliveryArchive(config), { settings: config.channels?.telegram, ownOrigins: config.appOrigins }
|
|
345
|
+
const chatDelivery = makeChatDelivery(ontology, connections, config.chatArchive ?? platformDeliveryArchive(config), { settings: config.channels?.telegram, ownOrigins: config.appOrigins },
|
|
346
|
+
// The app's agent sends through a workspace channel, at the origin it takes its tasks at.
|
|
347
|
+
{
|
|
348
|
+
origin: config.agentOrigin,
|
|
349
|
+
...(config.agentTaskTransport === undefined ? {} : { fetch: config.agentTaskTransport }),
|
|
350
|
+
});
|
|
346
351
|
const chatHistory = config.runtimeIdentity === undefined ? undefined : platformChatArchive(config);
|
|
347
352
|
const metricQueries = makeMetricQueries({
|
|
348
353
|
ontology,
|
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.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"
|