@segmentstream/ontology 0.150.2 → 0.151.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 +12 -0
- package/dist/analyze.d.ts +2 -0
- package/dist/analyze.js +48 -12
- package/dist/chat.d.ts +8 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/manifest.d.ts +29 -3
- package/dist/manifest.js +17 -1
- package/dist/migrate/model.d.ts +8 -0
- package/dist/runtime/agents.js +40 -27
- package/dist/service/agent/protocol.js +2 -1
- package/dist/service/agent/server.js +4 -4
- package/dist/service/runtime-contract.d.ts +6 -4
- package/dist/service/schemas.d.ts +2 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.151.0
|
|
4
|
+
|
|
5
|
+
`inbox` takes `channels`: the WhatsApp and workspace channels `chat` declares whose chats with
|
|
6
|
+
people who are no users join the inbox too, as `agent_chat` records of kind `private` without
|
|
7
|
+
members, such as `inbox: { roles: [client], channels: ["sales_whatsapp"] }`. The agent reports such
|
|
8
|
+
a chat to `POST /api/ontology/agent/chats/seen` without `memberId` when the channel records every
|
|
9
|
+
message (`record: "all"` in `agent/segmentstream.json`). The service registers it only on a listed
|
|
10
|
+
channel, makes nobody a user for it, and leaves the members of a chat it registered before as they
|
|
11
|
+
are. Staff with `agent_chat:read` whose scope holds the record read its messages; nobody reads it as
|
|
12
|
+
its person, and a post to it is refused, since it has no person to answer. `check` reports
|
|
13
|
+
`invalid-inbox` for any other channel. Without `channels`, the manifest is the same as before.
|
|
14
|
+
|
|
3
15
|
## 0.150.2
|
|
4
16
|
|
|
5
17
|
`@segmentstream/ontology/whatsapp` exports `WHATSAPP_REFUSALS`, Meta's error codes the chat names
|
package/dist/analyze.d.ts
CHANGED
|
@@ -233,6 +233,8 @@ export interface Analysis {
|
|
|
233
233
|
/** The wire names of the roles whose private chats join the inbox, when declared. */
|
|
234
234
|
readonly inbox?: {
|
|
235
235
|
readonly roles: ReadonlyArray<string>;
|
|
236
|
+
/** The channels whose chats with people who are no users join the inbox, without members. */
|
|
237
|
+
readonly channels: ReadonlyArray<string>;
|
|
236
238
|
/** The channels whose private chats staff may take over from the agent. */
|
|
237
239
|
readonly takeover: {
|
|
238
240
|
readonly channels: ReadonlyArray<string>;
|
package/dist/analyze.js
CHANGED
|
@@ -46,6 +46,8 @@ const REVIEW_ONLY_CHAT_PROVIDERS = new Set(["email"]);
|
|
|
46
46
|
const RESERVED_CHAT_NAMES = new Set(["web", "task", WORKSPACE_CHANNEL_KIND]);
|
|
47
47
|
/** The keys of `chat` that are settings, not channels. */
|
|
48
48
|
const CHAT_SETTINGS = new Set(["attribution", "retentionDays"]);
|
|
49
|
+
/** The kinds of channel whose agent records every message it receives, when asked to. */
|
|
50
|
+
const INBOX_CHANNEL_KINDS = new Set(["whatsapp", WORKSPACE_CHANNEL_KIND]);
|
|
49
51
|
/** Whether `chat` declares a channel of `kind`: the one named after it, or another of the kind. */
|
|
50
52
|
function declaresChatKind(chat, kind) {
|
|
51
53
|
return (isPlainObject(chat) &&
|
|
@@ -105,11 +107,14 @@ export function analyze(config, options = {}) {
|
|
|
105
107
|
...(linkEmail === undefined ? {} : { linkEmail }),
|
|
106
108
|
...(codeEmail === undefined ? {} : { codeEmail }),
|
|
107
109
|
};
|
|
108
|
-
const
|
|
110
|
+
const chatChannels = isPlainObject(config.chat)
|
|
109
111
|
? Object.entries(config.chat)
|
|
110
112
|
.filter(([name, channel]) => !CHAT_SETTINGS.has(name) && channel !== undefined)
|
|
111
113
|
.map(([name]) => name)
|
|
112
|
-
: []
|
|
114
|
+
: [];
|
|
115
|
+
const inbox = inboxOptions(config.inbox, declaredRoles, guest !== undefined, chatChannels,
|
|
116
|
+
// The channels whose agent records every message, chats of people who are no users among them.
|
|
117
|
+
chatChannels.filter((name) => INBOX_CHANNEL_KINDS.has(chatChannelKind(config.chat, name) ?? "")), report);
|
|
113
118
|
const discovery = config.discovery;
|
|
114
119
|
if (discovery !== undefined &&
|
|
115
120
|
(!isPlainObject(discovery) ||
|
|
@@ -372,26 +377,31 @@ export function analyze(config, options = {}) {
|
|
|
372
377
|
}
|
|
373
378
|
/**
|
|
374
379
|
* `inbox`: the wire names of the roles whose private chats join the inbox, each a declared role or
|
|
375
|
-
* `member`, the channels whose chats
|
|
376
|
-
*
|
|
377
|
-
* unless `attribution` is `none`;
|
|
380
|
+
* `member`, the channels whose chats with people who are no users join it too, the channels whose
|
|
381
|
+
* chats staff may take over: those `takeover.channels` lists, or every channel `chat` declares,
|
|
382
|
+
* and whether a member's own reply carries their name: `name` unless `attribution` is `none`;
|
|
383
|
+
* `undefined` when absent or malformed.
|
|
378
384
|
*/
|
|
379
385
|
function inboxOptions(value, declaredRoles,
|
|
380
386
|
/** Whether the ontology declares `guest`, whose visitors' chats the inbox may take. */
|
|
381
387
|
guests,
|
|
382
388
|
/** The names of the channels `chat` declares. */
|
|
383
|
-
chatChannels,
|
|
389
|
+
chatChannels,
|
|
390
|
+
/** The channels `chat` declares whose agent may record every message they receive. */
|
|
391
|
+
recordingChannels, report) {
|
|
384
392
|
if (value === undefined) {
|
|
385
393
|
return undefined;
|
|
386
394
|
}
|
|
387
395
|
if (!isPlainObject(value) ||
|
|
388
|
-
Object.keys(value).some((key) => key !== "roles" && key !== "takeover" && key !== "attribution") ||
|
|
396
|
+
Object.keys(value).some((key) => key !== "roles" && key !== "channels" && key !== "takeover" && key !== "attribution") ||
|
|
389
397
|
!Array.isArray(value.roles) ||
|
|
390
|
-
value.roles.length === 0
|
|
391
|
-
|
|
392
|
-
|
|
398
|
+
value.roles.length === 0 ||
|
|
399
|
+
(value.channels !== undefined && !Array.isArray(value.channels))) {
|
|
400
|
+
report("invalid-inbox", "inbox", "inbox takes { roles: [...], channels?: [...], takeover?: { channels?: [...] }, " +
|
|
401
|
+
'attribution?: "name" | "none" }, at least one role.');
|
|
393
402
|
return undefined;
|
|
394
403
|
}
|
|
404
|
+
const channels = inboxChannels(value.channels, recordingChannels, report);
|
|
395
405
|
const takeover = takeoverOptions(value.takeover, chatChannels, report);
|
|
396
406
|
const attribution = value.attribution === undefined ? "name" : value.attribution;
|
|
397
407
|
if (attribution !== "name" && attribution !== "none") {
|
|
@@ -418,10 +428,36 @@ chatChannels, report) {
|
|
|
418
428
|
roles.push(name);
|
|
419
429
|
}
|
|
420
430
|
});
|
|
421
|
-
return valid &&
|
|
422
|
-
|
|
431
|
+
return valid &&
|
|
432
|
+
channels !== undefined &&
|
|
433
|
+
takeover !== undefined &&
|
|
434
|
+
(attribution === "name" || attribution === "none")
|
|
435
|
+
? { roles, channels, takeover, attribution }
|
|
423
436
|
: undefined;
|
|
424
437
|
}
|
|
438
|
+
/**
|
|
439
|
+
* `inbox.channels`: the channels whose chats with people who are no users join the inbox, each a
|
|
440
|
+
* WhatsApp or workspace channel `chat` declares, as only their agent records the messages of
|
|
441
|
+
* people it does not answer; none when absent.
|
|
442
|
+
*/
|
|
443
|
+
function inboxChannels(value, recordingChannels, report) {
|
|
444
|
+
if (value === undefined) {
|
|
445
|
+
return [];
|
|
446
|
+
}
|
|
447
|
+
const channels = [];
|
|
448
|
+
let valid = true;
|
|
449
|
+
value.forEach((candidate, index) => {
|
|
450
|
+
if (typeof candidate !== "string" || !recordingChannels.includes(candidate)) {
|
|
451
|
+
report("invalid-inbox", `inbox.channels[${index}]`, "Use a WhatsApp or workspace channel chat declares: only their agent records the " +
|
|
452
|
+
'messages of people it does not answer, with record: "all".');
|
|
453
|
+
valid = false;
|
|
454
|
+
}
|
|
455
|
+
else if (!channels.includes(candidate)) {
|
|
456
|
+
channels.push(candidate);
|
|
457
|
+
}
|
|
458
|
+
});
|
|
459
|
+
return valid ? channels : undefined;
|
|
460
|
+
}
|
|
425
461
|
/**
|
|
426
462
|
* `inbox.takeover`: the channels whose private chats staff may take over from the agent, each a
|
|
427
463
|
* channel `chat` declares, since staff answer through it; every one of them when `channels` is
|
package/dist/chat.d.ts
CHANGED
|
@@ -10,6 +10,14 @@ export interface ChatAttributionSettings {
|
|
|
10
10
|
*/
|
|
11
11
|
export interface InboxOptions<R = unknown> {
|
|
12
12
|
readonly roles: ReadonlyArray<R>;
|
|
13
|
+
/**
|
|
14
|
+
* The channels whose chats with people who are no users join the inbox too, as `agent_chat`
|
|
15
|
+
* records of kind `private` without members: WhatsApp channels and workspace channels `chat`
|
|
16
|
+
* declares, on which the agent records every message (`record: "all"` in
|
|
17
|
+
* `agent/segmentstream.json`). `agent_chat:read` within a scope that holds such a record reads
|
|
18
|
+
* its messages. Absent, only the people `roles` takes join.
|
|
19
|
+
*/
|
|
20
|
+
readonly channels?: ReadonlyArray<string>;
|
|
13
21
|
/**
|
|
14
22
|
* Where staff may take a chat over from the agent, which then records the person's messages and
|
|
15
23
|
* answers none until a member hands it back: `channels` lists channels `chat` declares, `[]` for
|
package/dist/index.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ export type { ActionsBuilder, AnyEntity, ActionHandle, ActionInvoker, MetricQuer
|
|
|
24
24
|
export { ActionRejected, BatchErrorDetails, Conflict, DeploymentInterrupted, DeploymentSwitching, LimitErrorDetails, NotFound, PermissionDenied, ScopeViolated, } from "./errors.js";
|
|
25
25
|
export type { ActionError } from "./errors.js";
|
|
26
26
|
export { browserAuthenticationCompatible } from "./manifest-compatibility.js";
|
|
27
|
-
export { ActionManifest, actionConnectionKeys, canonicalJson, ConnectionManifest, EntityManifest, EntityPermissionsManifest, decodeManifestDocument, encodeManifest, formatManifest, IndexManifest, isValueMatched, MANIFEST_VERSION, manifestHash, ModelMetricManifest, OntologyManifest, OntologyManifestWire, PropertyManifest, RelationshipManifest, RoleManifest, ActionTriggerManifest, ScopeManifest, CronTriggerManifest, isActionTrigger, isCronTrigger, isWebhookTrigger, OtherTriggerManifest, WebhookTriggerManifest, WorkflowManifest, WorkflowTriggerManifest, SelectOptionManifest, SignInManifest, GuestManifest, guestOf, signInPolicyOf, channelPolicyOf, signUpOriginsOf, inboxRolesOf, takeoverChannelsOf, signUpRolesOf, CHAT_RETENTION_DAYS, chatRetentionDaysOf, } from "./manifest.js";
|
|
27
|
+
export { ActionManifest, actionConnectionKeys, canonicalJson, ConnectionManifest, EntityManifest, EntityPermissionsManifest, decodeManifestDocument, encodeManifest, formatManifest, IndexManifest, isValueMatched, MANIFEST_VERSION, manifestHash, ModelMetricManifest, OntologyManifest, OntologyManifestWire, PropertyManifest, RelationshipManifest, RoleManifest, ActionTriggerManifest, ScopeManifest, CronTriggerManifest, isActionTrigger, isCronTrigger, isWebhookTrigger, OtherTriggerManifest, WebhookTriggerManifest, WorkflowManifest, WorkflowTriggerManifest, SelectOptionManifest, SignInManifest, GuestManifest, guestOf, signInPolicyOf, channelPolicyOf, signUpOriginsOf, inboxRolesOf, inboxChannelsOf, takeoverChannelsOf, signUpRolesOf, CHAT_RETENTION_DAYS, chatRetentionDaysOf, } from "./manifest.js";
|
|
28
28
|
export { SYSTEM_PROPERTIES } from "./names.js";
|
|
29
29
|
export type { SystemProperty } from "./names.js";
|
|
30
30
|
export { isMe, isMeMarker, MAX_ME_HOPS, me, ME_KEY, MeMarker, mePathOf, meToWire, MeTypeId, } from "./me.js";
|
package/dist/index.js
CHANGED
|
@@ -13,7 +13,7 @@ export { entity, isEntity } from "./entity.js";
|
|
|
13
13
|
export { isToolset, MCP_TOOL_NAME, TOOLSET_LOCK_VERSION, toolset, ToolsetLock, ToolsetLockTool, } from "./toolset.js";
|
|
14
14
|
export { ActionRejected, BatchErrorDetails, Conflict, DeploymentInterrupted, DeploymentSwitching, LimitErrorDetails, NotFound, PermissionDenied, ScopeViolated, } from "./errors.js";
|
|
15
15
|
export { browserAuthenticationCompatible } from "./manifest-compatibility.js";
|
|
16
|
-
export { ActionManifest, actionConnectionKeys, canonicalJson, ConnectionManifest, EntityManifest, EntityPermissionsManifest, decodeManifestDocument, encodeManifest, formatManifest, IndexManifest, isValueMatched, MANIFEST_VERSION, manifestHash, ModelMetricManifest, OntologyManifest, OntologyManifestWire, PropertyManifest, RelationshipManifest, RoleManifest, ActionTriggerManifest, ScopeManifest, CronTriggerManifest, isActionTrigger, isCronTrigger, isWebhookTrigger, OtherTriggerManifest, WebhookTriggerManifest, WorkflowManifest, WorkflowTriggerManifest, SelectOptionManifest, SignInManifest, GuestManifest, guestOf, signInPolicyOf, channelPolicyOf, signUpOriginsOf, inboxRolesOf, takeoverChannelsOf, signUpRolesOf, CHAT_RETENTION_DAYS, chatRetentionDaysOf, } from "./manifest.js";
|
|
16
|
+
export { ActionManifest, actionConnectionKeys, canonicalJson, ConnectionManifest, EntityManifest, EntityPermissionsManifest, decodeManifestDocument, encodeManifest, formatManifest, IndexManifest, isValueMatched, MANIFEST_VERSION, manifestHash, ModelMetricManifest, OntologyManifest, OntologyManifestWire, PropertyManifest, RelationshipManifest, RoleManifest, ActionTriggerManifest, ScopeManifest, CronTriggerManifest, isActionTrigger, isCronTrigger, isWebhookTrigger, OtherTriggerManifest, WebhookTriggerManifest, WorkflowManifest, WorkflowTriggerManifest, SelectOptionManifest, SignInManifest, GuestManifest, guestOf, signInPolicyOf, channelPolicyOf, signUpOriginsOf, inboxRolesOf, inboxChannelsOf, takeoverChannelsOf, signUpRolesOf, CHAT_RETENTION_DAYS, chatRetentionDaysOf, } from "./manifest.js";
|
|
17
17
|
export { SYSTEM_PROPERTIES } from "./names.js";
|
|
18
18
|
export { isMe, isMeMarker, MAX_ME_HOPS, me, ME_KEY, MeMarker, mePathOf, meToWire, MeTypeId, } from "./me.js";
|
|
19
19
|
export { check, defineOntology } from "./ontology.js";
|
package/dist/manifest.d.ts
CHANGED
|
@@ -105,6 +105,9 @@ import { type ResolvedGuest, type ResolvedSignInOptions, type SignInPolicy } fro
|
|
|
105
105
|
* publication adds a daily cron for that route. Within version 16, `chat` may carry
|
|
106
106
|
* `retention_days`, written only when declared, and then also without a channel: how many days
|
|
107
107
|
* the workspace keeps its chats' messages. Older readers ignore it and keep them 365 days.
|
|
108
|
+
* Within version 16, `inbox` may carry `channels`, written only when declared: the channels whose
|
|
109
|
+
* chats with people who are no users the agent registers as `agent_chat` records of kind
|
|
110
|
+
* `private` without members. Older readers ignore it and register no chat without members.
|
|
108
111
|
*/
|
|
109
112
|
export declare const MANIFEST_VERSION = 16;
|
|
110
113
|
/** The phrase used for a direction the author did not phrase. */
|
|
@@ -1327,10 +1330,13 @@ export declare const OntologyManifestWire: Schema.encodeKeys<Schema.Struct<{
|
|
|
1327
1330
|
* channels whose chats staff may take over from the agent, and `attribution: "none"` when a
|
|
1328
1331
|
* member's own reply there goes without their name. Written only when declared; absent
|
|
1329
1332
|
* registers no private chat, absent `takeover` lets no chat be taken over, absent `attribution`
|
|
1330
|
-
* signs replies, and older readers ignore all three.
|
|
1333
|
+
* signs replies, and older readers ignore all three. Within version 16, `channels`, written only
|
|
1334
|
+
* when it lists some, names the channels whose chats with people who are no users join it too,
|
|
1335
|
+
* without members; absent registers none.
|
|
1331
1336
|
*/
|
|
1332
1337
|
readonly inbox: Schema.optionalKey<Schema.Struct<{
|
|
1333
1338
|
readonly roles: Schema.$Array<Schema.String>;
|
|
1339
|
+
readonly channels: Schema.optionalKey<Schema.$Array<Schema.String>>;
|
|
1334
1340
|
readonly takeover: Schema.optionalKey<Schema.Struct<{
|
|
1335
1341
|
readonly channels: Schema.$Array<Schema.String>;
|
|
1336
1342
|
}>>;
|
|
@@ -1817,6 +1823,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
1817
1823
|
} | undefined;
|
|
1818
1824
|
readonly inbox?: {
|
|
1819
1825
|
readonly roles: readonly string[];
|
|
1826
|
+
readonly channels?: readonly string[] | undefined;
|
|
1820
1827
|
readonly attribution?: "name" | "none" | undefined;
|
|
1821
1828
|
readonly takeover?: {
|
|
1822
1829
|
readonly channels: readonly string[];
|
|
@@ -2173,6 +2180,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
2173
2180
|
} | undefined;
|
|
2174
2181
|
readonly inbox?: {
|
|
2175
2182
|
readonly roles: readonly string[];
|
|
2183
|
+
readonly channels?: readonly string[] | undefined;
|
|
2176
2184
|
readonly attribution?: "name" | "none" | undefined;
|
|
2177
2185
|
readonly takeover?: {
|
|
2178
2186
|
readonly channels: readonly string[];
|
|
@@ -2492,6 +2500,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
2492
2500
|
} | undefined;
|
|
2493
2501
|
readonly inbox?: {
|
|
2494
2502
|
readonly roles: readonly string[];
|
|
2503
|
+
readonly channels?: readonly string[] | undefined;
|
|
2495
2504
|
readonly attribution?: "name" | "none" | undefined;
|
|
2496
2505
|
readonly takeover?: {
|
|
2497
2506
|
readonly channels: readonly string[];
|
|
@@ -2885,6 +2894,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
2885
2894
|
} | undefined;
|
|
2886
2895
|
readonly inbox?: {
|
|
2887
2896
|
readonly roles: readonly string[];
|
|
2897
|
+
readonly channels?: readonly string[] | undefined;
|
|
2888
2898
|
readonly attribution?: "name" | "none" | undefined;
|
|
2889
2899
|
readonly takeover?: {
|
|
2890
2900
|
readonly channels: readonly string[];
|
|
@@ -3248,10 +3258,13 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
3248
3258
|
* channels whose chats staff may take over from the agent, and `attribution: "none"` when a
|
|
3249
3259
|
* member's own reply there goes without their name. Written only when declared; absent
|
|
3250
3260
|
* registers no private chat, absent `takeover` lets no chat be taken over, absent `attribution`
|
|
3251
|
-
* signs replies, and older readers ignore all three.
|
|
3261
|
+
* signs replies, and older readers ignore all three. Within version 16, `channels`, written only
|
|
3262
|
+
* when it lists some, names the channels whose chats with people who are no users join it too,
|
|
3263
|
+
* without members; absent registers none.
|
|
3252
3264
|
*/
|
|
3253
3265
|
readonly inbox: Schema.optionalKey<Schema.Struct<{
|
|
3254
3266
|
readonly roles: Schema.$Array<Schema.String>;
|
|
3267
|
+
readonly channels: Schema.optionalKey<Schema.$Array<Schema.String>>;
|
|
3255
3268
|
readonly takeover: Schema.optionalKey<Schema.Struct<{
|
|
3256
3269
|
readonly channels: Schema.$Array<Schema.String>;
|
|
3257
3270
|
}>>;
|
|
@@ -3731,10 +3744,13 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
3731
3744
|
* channels whose chats staff may take over from the agent, and `attribution: "none"` when a
|
|
3732
3745
|
* member's own reply there goes without their name. Written only when declared; absent
|
|
3733
3746
|
* registers no private chat, absent `takeover` lets no chat be taken over, absent `attribution`
|
|
3734
|
-
* signs replies, and older readers ignore all three.
|
|
3747
|
+
* signs replies, and older readers ignore all three. Within version 16, `channels`, written only
|
|
3748
|
+
* when it lists some, names the channels whose chats with people who are no users join it too,
|
|
3749
|
+
* without members; absent registers none.
|
|
3735
3750
|
*/
|
|
3736
3751
|
readonly inbox: Schema.optionalKey<Schema.Struct<{
|
|
3737
3752
|
readonly roles: Schema.$Array<Schema.String>;
|
|
3753
|
+
readonly channels: Schema.optionalKey<Schema.$Array<Schema.String>>;
|
|
3738
3754
|
readonly takeover: Schema.optionalKey<Schema.Struct<{
|
|
3739
3755
|
readonly channels: Schema.$Array<Schema.String>;
|
|
3740
3756
|
}>>;
|
|
@@ -4213,6 +4229,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
4213
4229
|
} | undefined;
|
|
4214
4230
|
readonly inbox?: {
|
|
4215
4231
|
readonly roles: readonly string[];
|
|
4232
|
+
readonly channels?: readonly string[] | undefined;
|
|
4216
4233
|
readonly attribution?: "name" | "none" | undefined;
|
|
4217
4234
|
readonly takeover?: {
|
|
4218
4235
|
readonly channels: readonly string[];
|
|
@@ -4569,6 +4586,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
4569
4586
|
} | undefined;
|
|
4570
4587
|
readonly inbox?: {
|
|
4571
4588
|
readonly roles: readonly string[];
|
|
4589
|
+
readonly channels?: readonly string[] | undefined;
|
|
4572
4590
|
readonly attribution?: "name" | "none" | undefined;
|
|
4573
4591
|
readonly takeover?: {
|
|
4574
4592
|
readonly channels: readonly string[];
|
|
@@ -4931,6 +4949,7 @@ export declare const decodeManifestDocument: (value: unknown) => Effect.Effect<{
|
|
|
4931
4949
|
} | undefined;
|
|
4932
4950
|
readonly inbox?: {
|
|
4933
4951
|
readonly roles: readonly string[];
|
|
4952
|
+
readonly channels?: readonly string[] | undefined;
|
|
4934
4953
|
readonly attribution?: "name" | "none" | undefined;
|
|
4935
4954
|
readonly takeover?: {
|
|
4936
4955
|
readonly channels: readonly string[];
|
|
@@ -5287,6 +5306,7 @@ export declare const decodeManifestDocument: (value: unknown) => Effect.Effect<{
|
|
|
5287
5306
|
} | undefined;
|
|
5288
5307
|
readonly inbox?: {
|
|
5289
5308
|
readonly roles: readonly string[];
|
|
5309
|
+
readonly channels?: readonly string[] | undefined;
|
|
5290
5310
|
readonly attribution?: "name" | "none" | undefined;
|
|
5291
5311
|
readonly takeover?: {
|
|
5292
5312
|
readonly channels: readonly string[];
|
|
@@ -5361,6 +5381,11 @@ export declare function declaredChatRetentionDaysOf(manifest: Pick<OntologyManif
|
|
|
5361
5381
|
export declare function chatRetentionDaysOf(manifest: Pick<OntologyManifest, "chat">): number;
|
|
5362
5382
|
/** The wire names of the roles whose people's private chats join the inbox; empty without one. */
|
|
5363
5383
|
export declare function inboxRolesOf(manifest: Pick<OntologyManifest, "inbox">): ReadonlySet<string>;
|
|
5384
|
+
/**
|
|
5385
|
+
* The channels whose chats with people who are no users join the inbox, as records without members;
|
|
5386
|
+
* empty without any.
|
|
5387
|
+
*/
|
|
5388
|
+
export declare function inboxChannelsOf(manifest: Pick<OntologyManifest, "inbox">): ReadonlySet<string>;
|
|
5364
5389
|
/** The channels whose private chats staff may take over from the agent; empty without any. */
|
|
5365
5390
|
export declare function takeoverChannelsOf(manifest: Pick<OntologyManifest, "inbox">): ReadonlySet<string>;
|
|
5366
5391
|
/** Whether a member's own reply in the inbox carries their name: `name` unless declared `none`. */
|
|
@@ -5429,6 +5454,7 @@ export declare function buildManifest(input: {
|
|
|
5429
5454
|
readonly chat?: ChatManifestInput;
|
|
5430
5455
|
readonly inbox?: {
|
|
5431
5456
|
readonly roles: ReadonlyArray<string>;
|
|
5457
|
+
readonly channels?: ReadonlyArray<string>;
|
|
5432
5458
|
readonly takeover: {
|
|
5433
5459
|
readonly channels: ReadonlyArray<string>;
|
|
5434
5460
|
};
|
package/dist/manifest.js
CHANGED
|
@@ -106,6 +106,9 @@ import { CHANNEL_PROVIDERS, DEFAULT_SIGN_IN_POLICY, isGuestBotCheckScheme, isGue
|
|
|
106
106
|
* publication adds a daily cron for that route. Within version 16, `chat` may carry
|
|
107
107
|
* `retention_days`, written only when declared, and then also without a channel: how many days
|
|
108
108
|
* the workspace keeps its chats' messages. Older readers ignore it and keep them 365 days.
|
|
109
|
+
* Within version 16, `inbox` may carry `channels`, written only when declared: the channels whose
|
|
110
|
+
* chats with people who are no users the agent registers as `agent_chat` records of kind
|
|
111
|
+
* `private` without members. Older readers ignore it and register no chat without members.
|
|
109
112
|
*/
|
|
110
113
|
export const MANIFEST_VERSION = 16;
|
|
111
114
|
/** The first version whose documents use snake_case names on the wire. */
|
|
@@ -624,10 +627,13 @@ const OntologyManifestModel = Schema.Struct({
|
|
|
624
627
|
* channels whose chats staff may take over from the agent, and `attribution: "none"` when a
|
|
625
628
|
* member's own reply there goes without their name. Written only when declared; absent
|
|
626
629
|
* registers no private chat, absent `takeover` lets no chat be taken over, absent `attribution`
|
|
627
|
-
* signs replies, and older readers ignore all three.
|
|
630
|
+
* signs replies, and older readers ignore all three. Within version 16, `channels`, written only
|
|
631
|
+
* when it lists some, names the channels whose chats with people who are no users join it too,
|
|
632
|
+
* without members; absent registers none.
|
|
628
633
|
*/
|
|
629
634
|
inbox: Schema.optionalKey(Schema.Struct({
|
|
630
635
|
roles: Schema.Array(Schema.String),
|
|
636
|
+
channels: Schema.optionalKey(Schema.Array(Schema.String)),
|
|
631
637
|
takeover: Schema.optionalKey(Schema.Struct({ channels: Schema.Array(Schema.String) })),
|
|
632
638
|
attribution: Schema.optionalKey(Schema.Literals(["name", "none"])),
|
|
633
639
|
})),
|
|
@@ -755,6 +761,13 @@ export function chatRetentionDaysOf(manifest) {
|
|
|
755
761
|
export function inboxRolesOf(manifest) {
|
|
756
762
|
return new Set(manifest.inbox?.roles ?? []);
|
|
757
763
|
}
|
|
764
|
+
/**
|
|
765
|
+
* The channels whose chats with people who are no users join the inbox, as records without members;
|
|
766
|
+
* empty without any.
|
|
767
|
+
*/
|
|
768
|
+
export function inboxChannelsOf(manifest) {
|
|
769
|
+
return new Set(manifest.inbox?.channels ?? []);
|
|
770
|
+
}
|
|
758
771
|
/** The channels whose private chats staff may take over from the agent; empty without any. */
|
|
759
772
|
export function takeoverChannelsOf(manifest) {
|
|
760
773
|
return new Set(manifest.inbox?.takeover?.channels ?? []);
|
|
@@ -1140,6 +1153,9 @@ export function buildManifest(input) {
|
|
|
1140
1153
|
: {
|
|
1141
1154
|
inbox: {
|
|
1142
1155
|
roles: [...input.inbox.roles],
|
|
1156
|
+
...((input.inbox.channels ?? []).length === 0
|
|
1157
|
+
? {}
|
|
1158
|
+
: { channels: [...(input.inbox.channels ?? [])] }),
|
|
1143
1159
|
takeover: { channels: [...input.inbox.takeover.channels] },
|
|
1144
1160
|
...(input.inbox.attribution === "none" ? { attribution: "none" } : {}),
|
|
1145
1161
|
},
|
package/dist/migrate/model.d.ts
CHANGED
|
@@ -605,6 +605,7 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
605
605
|
} | undefined;
|
|
606
606
|
readonly inbox?: {
|
|
607
607
|
readonly roles: readonly string[];
|
|
608
|
+
readonly channels?: readonly string[] | undefined;
|
|
608
609
|
readonly attribution?: "name" | "none" | undefined;
|
|
609
610
|
readonly takeover?: {
|
|
610
611
|
readonly channels: readonly string[];
|
|
@@ -961,6 +962,7 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
961
962
|
} | undefined;
|
|
962
963
|
readonly inbox?: {
|
|
963
964
|
readonly roles: readonly string[];
|
|
965
|
+
readonly channels?: readonly string[] | undefined;
|
|
964
966
|
readonly attribution?: "name" | "none" | undefined;
|
|
965
967
|
readonly takeover?: {
|
|
966
968
|
readonly channels: readonly string[];
|
|
@@ -1280,6 +1282,7 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1280
1282
|
} | undefined;
|
|
1281
1283
|
readonly inbox?: {
|
|
1282
1284
|
readonly roles: readonly string[];
|
|
1285
|
+
readonly channels?: readonly string[] | undefined;
|
|
1283
1286
|
readonly attribution?: "name" | "none" | undefined;
|
|
1284
1287
|
readonly takeover?: {
|
|
1285
1288
|
readonly channels: readonly string[];
|
|
@@ -1673,6 +1676,7 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1673
1676
|
} | undefined;
|
|
1674
1677
|
readonly inbox?: {
|
|
1675
1678
|
readonly roles: readonly string[];
|
|
1679
|
+
readonly channels?: readonly string[] | undefined;
|
|
1676
1680
|
readonly attribution?: "name" | "none" | undefined;
|
|
1677
1681
|
readonly takeover?: {
|
|
1678
1682
|
readonly channels: readonly string[];
|
|
@@ -1966,6 +1970,7 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1966
1970
|
}>>;
|
|
1967
1971
|
readonly inbox: Schema.optionalKey<Schema.Struct<{
|
|
1968
1972
|
readonly roles: Schema.$Array<Schema.String>;
|
|
1973
|
+
readonly channels: Schema.optionalKey<Schema.$Array<Schema.String>>;
|
|
1969
1974
|
readonly takeover: Schema.optionalKey<Schema.Struct<{
|
|
1970
1975
|
readonly channels: Schema.$Array<Schema.String>;
|
|
1971
1976
|
}>>;
|
|
@@ -2320,6 +2325,7 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
2320
2325
|
}>>;
|
|
2321
2326
|
readonly inbox: Schema.optionalKey<Schema.Struct<{
|
|
2322
2327
|
readonly roles: Schema.$Array<Schema.String>;
|
|
2328
|
+
readonly channels: Schema.optionalKey<Schema.$Array<Schema.String>>;
|
|
2323
2329
|
readonly takeover: Schema.optionalKey<Schema.Struct<{
|
|
2324
2330
|
readonly channels: Schema.$Array<Schema.String>;
|
|
2325
2331
|
}>>;
|
|
@@ -2751,6 +2757,7 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
2751
2757
|
} | undefined;
|
|
2752
2758
|
readonly inbox?: {
|
|
2753
2759
|
readonly roles: readonly string[];
|
|
2760
|
+
readonly channels?: readonly string[] | undefined;
|
|
2754
2761
|
readonly attribution?: "name" | "none" | undefined;
|
|
2755
2762
|
readonly takeover?: {
|
|
2756
2763
|
readonly channels: readonly string[];
|
|
@@ -3107,6 +3114,7 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
3107
3114
|
} | undefined;
|
|
3108
3115
|
readonly inbox?: {
|
|
3109
3116
|
readonly roles: readonly string[];
|
|
3117
|
+
readonly channels?: readonly string[] | undefined;
|
|
3110
3118
|
readonly attribution?: "name" | "none" | undefined;
|
|
3111
3119
|
readonly takeover?: {
|
|
3112
3120
|
readonly channels: readonly string[];
|
package/dist/runtime/agents.js
CHANGED
|
@@ -7,7 +7,7 @@ import { AgentChat, agentChatKey } from "../agent-chat.js";
|
|
|
7
7
|
import { chatChannelKind } from "../chat-channel.js";
|
|
8
8
|
import { AgentReview } from "../agent-review.js";
|
|
9
9
|
import { AGENT_IDENTITIES_TABLE, AGENT_PAIRINGS_TABLE, CHANNEL_USERS_TABLE, IDENTITY_NOTICES_TABLE, USER_TABLE, } from "../migrate/storage.js";
|
|
10
|
-
import { inboxRolesOf, takeoverChannelsOf, takeoverProvidersOf } from "../manifest.js";
|
|
10
|
+
import { inboxChannelsOf, inboxRolesOf, takeoverChannelsOf, takeoverProvidersOf, } from "../manifest.js";
|
|
11
11
|
import { GUEST_ROLE } from "../names.js";
|
|
12
12
|
import { MAX_QUERY_LIMIT } from "../query.js";
|
|
13
13
|
import { beginReplicationWrite } from "../replication/transaction.js";
|
|
@@ -648,11 +648,21 @@ export function sqlAgentStore(ontology, sql) {
|
|
|
648
648
|
}))
|
|
649
649
|
.pipe(Effect.orDie),
|
|
650
650
|
seeInboxChat: (input) => Effect.gen(function* () {
|
|
651
|
-
const
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
651
|
+
const { memberId } = input;
|
|
652
|
+
if (memberId === undefined) {
|
|
653
|
+
// A chat with someone who is no user joins only on a channel the inbox lists, without
|
|
654
|
+
// members: nobody is created for them, and staff read it within their scope.
|
|
655
|
+
if (!inboxChannelsOf(ontology.manifest).has(input.provider)) {
|
|
656
|
+
return undefined;
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
else {
|
|
660
|
+
const roles = inboxRolesOf(ontology.manifest);
|
|
661
|
+
const member = isRecordId(memberId) ? yield* store.member(memberId) : undefined;
|
|
662
|
+
// Only the private chats of people whose roles the inbox takes are recorded.
|
|
663
|
+
if (member === undefined || !member.principal.roles.some((role) => roles.has(role))) {
|
|
664
|
+
return undefined;
|
|
665
|
+
}
|
|
656
666
|
}
|
|
657
667
|
return yield* sql.withTransaction(Effect.gen(function* () {
|
|
658
668
|
yield* beginReplicationWrite(sql);
|
|
@@ -707,29 +717,32 @@ export function sqlAgentStore(ontology, sql) {
|
|
|
707
717
|
values: changes,
|
|
708
718
|
});
|
|
709
719
|
// A private chat has one member, its person now: an account paired with someone else
|
|
710
|
-
// since leaves the earlier person out. A link already there changes nothing.
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
720
|
+
// since leaves the earlier person out. A link already there changes nothing. A report
|
|
721
|
+
// without a person leaves the members as they are.
|
|
722
|
+
if (memberId !== undefined) {
|
|
723
|
+
const members = yield* runtime.related({
|
|
724
|
+
entity: AgentChat.name,
|
|
725
|
+
id: String(chat.id),
|
|
726
|
+
relationship: "members",
|
|
727
|
+
query: { limit: MAX_QUERY_LIMIT },
|
|
728
|
+
});
|
|
729
|
+
for (const member of members.items) {
|
|
730
|
+
if (String(member.id) !== memberId) {
|
|
731
|
+
yield* runtime.unlink({
|
|
732
|
+
entity: AgentChat.name,
|
|
733
|
+
relationship: "members",
|
|
734
|
+
id: String(chat.id),
|
|
735
|
+
targetId: String(member.id),
|
|
736
|
+
});
|
|
737
|
+
}
|
|
725
738
|
}
|
|
739
|
+
yield* runtime.link({
|
|
740
|
+
entity: AgentChat.name,
|
|
741
|
+
relationship: "members",
|
|
742
|
+
id: String(chat.id),
|
|
743
|
+
targetId: memberId,
|
|
744
|
+
});
|
|
726
745
|
}
|
|
727
|
-
yield* runtime.link({
|
|
728
|
-
entity: AgentChat.name,
|
|
729
|
-
relationship: "members",
|
|
730
|
-
id: String(chat.id),
|
|
731
|
-
targetId: input.memberId,
|
|
732
|
-
});
|
|
733
746
|
return {
|
|
734
747
|
id: String(chat.id),
|
|
735
748
|
title: String(chat.title),
|
|
@@ -152,7 +152,8 @@ export const ChatSeenRequest = Schema.Struct({
|
|
|
152
152
|
description: "The chat's id before it became a supergroup: its record moves to externalId.",
|
|
153
153
|
})),
|
|
154
154
|
kind: Schema.optionalKey(Schema.Literal("private").annotate({
|
|
155
|
-
description: "A person's private chat, which the inbox registers when memberId holds one of its roles
|
|
155
|
+
description: "A person's private chat, which the inbox registers when memberId holds one of its roles, " +
|
|
156
|
+
"or, without memberId, for someone who is no user on a channel inbox.channels lists; " +
|
|
156
157
|
"absent for a group chat.",
|
|
157
158
|
})),
|
|
158
159
|
recipient: Schema.optionalKey(ChatId.annotate({
|
|
@@ -314,9 +314,9 @@ function seeChat(store) {
|
|
|
314
314
|
}
|
|
315
315
|
const { kind, recipient, threadId, ...seen } = decoded.success;
|
|
316
316
|
if (kind === "private") {
|
|
317
|
-
// A person's private chat joins the inbox, which records nothing for anyone else
|
|
318
|
-
|
|
319
|
-
|
|
317
|
+
// A person's private chat joins the inbox, which records nothing for anyone else; one
|
|
318
|
+
// without a person, someone who is no user, joins on a channel the inbox lists.
|
|
319
|
+
const inboxed = store.seeInboxChat === undefined ||
|
|
320
320
|
seen.leftMemberId !== undefined ||
|
|
321
321
|
seen.agentLeft !== undefined ||
|
|
322
322
|
seen.migratedFrom !== undefined
|
|
@@ -325,7 +325,7 @@ function seeChat(store) {
|
|
|
325
325
|
provider: seen.provider,
|
|
326
326
|
externalId: seen.externalId,
|
|
327
327
|
title: seen.title,
|
|
328
|
-
memberId: seen.memberId,
|
|
328
|
+
...(seen.memberId === undefined ? {} : { memberId: seen.memberId }),
|
|
329
329
|
...(recipient === undefined ? {} : { recipient }),
|
|
330
330
|
...(threadId === undefined ? {} : { threadId }),
|
|
331
331
|
});
|
|
@@ -666,8 +666,10 @@ export interface AgentStore {
|
|
|
666
666
|
* Records a person's private chat with the agent for the inbox: creates the `agent_chat` of kind
|
|
667
667
|
* `private`, with the person as its one member, or keeps its title, recipient and thread current,
|
|
668
668
|
* and records when it last had a message, as `seeChat` does. `undefined`, recording nothing,
|
|
669
|
-
* unless the person is an active member holding a role of the ontology's `inbox`.
|
|
670
|
-
*
|
|
669
|
+
* unless the person is an active member holding a role of the ontology's `inbox`. Without
|
|
670
|
+
* `memberId`, the chat is someone's who is no user: recorded without members, whose members it
|
|
671
|
+
* leaves as they are, and only on a channel `inbox.channels` lists; no user is created. Absent
|
|
672
|
+
* on stores that predate the inbox.
|
|
671
673
|
*/
|
|
672
674
|
readonly seeInboxChat?: (input: InboxChatInput) => Effect.Effect<SeenChat | undefined>;
|
|
673
675
|
/**
|
|
@@ -762,8 +764,8 @@ export interface InboxChatInput {
|
|
|
762
764
|
readonly externalId: string;
|
|
763
765
|
/** The person's name on the channel. */
|
|
764
766
|
readonly title: string;
|
|
765
|
-
/** The person, a user id. */
|
|
766
|
-
readonly memberId
|
|
767
|
+
/** The person, a user id; absent for someone who is no user. */
|
|
768
|
+
readonly memberId?: string;
|
|
767
769
|
/** Whom a reply is sent to, where it differs from `externalId`. */
|
|
768
770
|
readonly recipient?: string;
|
|
769
771
|
/** The thread a reply stays in. */
|
|
@@ -554,6 +554,7 @@ export declare const Catalog: Schema.decodeTo<Schema.Struct<{
|
|
|
554
554
|
}>>;
|
|
555
555
|
readonly inbox: Schema.optionalKey<Schema.Struct<{
|
|
556
556
|
readonly roles: Schema.$Array<Schema.String>;
|
|
557
|
+
readonly channels: Schema.optionalKey<Schema.$Array<Schema.String>>;
|
|
557
558
|
readonly takeover: Schema.optionalKey<Schema.Struct<{
|
|
558
559
|
readonly channels: Schema.$Array<Schema.String>;
|
|
559
560
|
}>>;
|
|
@@ -922,6 +923,7 @@ export declare const Catalog: Schema.decodeTo<Schema.Struct<{
|
|
|
922
923
|
}>>>;
|
|
923
924
|
readonly inbox: Schema.toEncoded<Schema.optionalKey<Schema.Struct<{
|
|
924
925
|
readonly roles: Schema.$Array<Schema.String>;
|
|
926
|
+
readonly channels: Schema.optionalKey<Schema.$Array<Schema.String>>;
|
|
925
927
|
readonly takeover: Schema.optionalKey<Schema.Struct<{
|
|
926
928
|
readonly channels: Schema.$Array<Schema.String>;
|
|
927
929
|
}>>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@segmentstream/ontology",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.151.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",
|