@segmentstream/ontology 0.156.0 → 0.158.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 +53 -0
- package/README.md +8 -7
- package/dist/agent-chat.d.ts +1 -1
- package/dist/agent-chat.js +8 -8
- package/dist/agent-draft.d.ts +287 -0
- package/dist/{agent-review.js → agent-draft.js} +103 -82
- package/dist/analyze.d.ts +1 -1
- package/dist/analyze.js +71 -14
- package/dist/channel-files.d.ts +70 -0
- package/dist/channel-files.js +58 -0
- package/dist/chat.d.ts +2 -2
- package/dist/earlier-entity-names.d.ts +35 -0
- package/dist/earlier-entity-names.js +88 -0
- package/dist/email.d.ts +2 -0
- package/dist/email.js +1 -0
- package/dist/gmail-send.d.ts +39 -0
- package/dist/gmail-send.js +179 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -1
- package/dist/migrate/plan.js +31 -2
- package/dist/permissions.d.ts +5 -5
- package/dist/permissions.js +13 -10
- package/dist/replicated-entities.d.ts +1 -1
- package/dist/replicated-entities.js +4 -1
- package/dist/replication/bigquery.d.ts +24 -2
- package/dist/replication/bigquery.js +72 -12
- package/dist/runtime/agents.d.ts +1 -1
- package/dist/runtime/agents.js +43 -38
- package/dist/runtime/chat-messages.d.ts +8 -7
- package/dist/runtime/chat-messages.js +11 -10
- package/dist/runtime/service-binding.js +1 -1
- package/dist/service/agent/protocol.d.ts +4 -4
- package/dist/service/agent/protocol.js +7 -7
- package/dist/service/agent/server.js +14 -9
- package/dist/service/chat/envelope.d.ts +12 -12
- package/dist/service/chat/review-delivery.js +23 -22
- package/dist/service/chat/review-revision.d.ts +1 -1
- package/dist/service/chat/review-revision.js +13 -13
- package/dist/service/mcp/runtime-policy.js +1 -1
- package/dist/service/mcp/server.js +9 -1
- package/dist/service/mcp/tools.js +1 -1
- package/dist/service/operations.js +11 -5
- package/dist/service/runtime-contract.d.ts +3 -3
- package/dist/service/service.d.ts +6 -0
- package/dist/service/service.js +21 -3
- package/dist/slack-files.d.ts +53 -0
- package/dist/slack-files.js +183 -0
- package/dist/slack.d.ts +3 -0
- package/dist/slack.js +2 -0
- package/dist/telegram-files.d.ts +81 -0
- package/dist/telegram-files.js +244 -0
- package/dist/telegram.d.ts +3 -1
- package/dist/telegram.js +2 -0
- package/dist/whatsapp-files.d.ts +54 -0
- package/dist/whatsapp-files.js +138 -0
- package/dist/whatsapp.d.ts +3 -0
- package/dist/whatsapp.js +2 -0
- package/dist/workspace-channel.d.ts +20 -0
- package/dist/workspace-channel.js +10 -0
- package/package.json +1 -1
- package/dist/agent-review.d.ts +0 -154
|
@@ -8,15 +8,15 @@ import { EMAIL_PATTERN, p } from "./property.js";
|
|
|
8
8
|
import { isUuid } from "./query.js";
|
|
9
9
|
import { rel } from "./relationship.js";
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
12
|
-
* person the agent replies to, whether a member reviews its replies (`chats.*.review`);
|
|
13
|
-
*
|
|
14
|
-
* the
|
|
15
|
-
* sender attribution a chat post carries, at most once; rejecting discards it. Reading,
|
|
16
|
-
* and rejecting each need a permission that names `
|
|
17
|
-
* it, since its records hold the workspace's chats with the people it serves.
|
|
11
|
+
* The agent's draft reply awaiting a staff decision. `agent/segmentstream.json` says, per role of
|
|
12
|
+
* the person the agent replies to, whether a member reviews its replies (`chats.*.review`); the
|
|
13
|
+
* agent records each reply it keeps for review here as a draft, and only the actions below change
|
|
14
|
+
* it. Approving sends the draft, or the member's edit of it, to the person's chat as the agent,
|
|
15
|
+
* without the sender attribution a chat post carries, at most once; rejecting discards it. Reading,
|
|
16
|
+
* approving and rejecting each need a permission that names `agent_draft`: an entity wildcard does
|
|
17
|
+
* not cover it, since its records hold the workspace's chats with the people it serves.
|
|
18
18
|
*/
|
|
19
|
-
export const
|
|
19
|
+
export const AGENT_DRAFT_STATUSES = [
|
|
20
20
|
{ value: "pending", description: "Waiting for a member to approve, edit or reject it." },
|
|
21
21
|
{ value: "sent", description: "Approved and delivered to the person." },
|
|
22
22
|
{
|
|
@@ -27,40 +27,40 @@ export const AGENT_REVIEW_STATUSES = [
|
|
|
27
27
|
{ value: "rejected", description: "Rejected: the person never sees it." },
|
|
28
28
|
{
|
|
29
29
|
value: "superseded",
|
|
30
|
-
description: "Redrafted at a member's request: the
|
|
30
|
+
description: "Redrafted at a member's request: the draft that revises it replaces it.",
|
|
31
31
|
},
|
|
32
32
|
];
|
|
33
|
-
export const
|
|
33
|
+
export const AGENT_DRAFT_REVISION_STATES = [
|
|
34
34
|
{ value: "requested", description: "A member asked the agent to redraft it; it is redrafting." },
|
|
35
35
|
{ value: "failed", description: "The agent could not redraft it; it still waits as it is." },
|
|
36
36
|
];
|
|
37
|
-
export const
|
|
37
|
+
export const AGENT_DRAFT_MODES = [
|
|
38
38
|
{ value: "always", description: "Every reply in the chat waits for a member." },
|
|
39
39
|
{
|
|
40
40
|
value: "whenUnsure",
|
|
41
41
|
description: "The decision model was not sure enough that staff would send it as written.",
|
|
42
42
|
},
|
|
43
43
|
];
|
|
44
|
-
/** The longest reply a
|
|
45
|
-
export const
|
|
44
|
+
/** The longest reply a draft holds; a provider may accept less in one message. */
|
|
45
|
+
export const AGENT_DRAFT_TEXT_LIMIT = 20_000;
|
|
46
46
|
/** The longest reason a member gives for rejecting a reply. */
|
|
47
|
-
export const
|
|
47
|
+
export const AGENT_DRAFT_REASON_LIMIT = 2_000;
|
|
48
48
|
/** The longest note a member gives the agent for redrafting a reply. */
|
|
49
|
-
export const
|
|
50
|
-
/** The longest list of addresses a
|
|
51
|
-
const
|
|
52
|
-
/** The most members a
|
|
53
|
-
export const
|
|
54
|
-
/** The longest list of user ids a
|
|
55
|
-
const
|
|
49
|
+
export const AGENT_DRAFT_NOTE_LIMIT = 2_000;
|
|
50
|
+
/** The longest list of addresses a draft keeps in `to` or `cc`: as many as a reply goes to. */
|
|
51
|
+
const AGENT_DRAFT_RECIPIENTS_LENGTH = EMAIL_RECIPIENTS_LIMIT * 256;
|
|
52
|
+
/** The most members a draft names as the readers of its reply, as many as a reply to mail goes to. */
|
|
53
|
+
export const AGENT_DRAFT_PARTICIPANTS_LIMIT = EMAIL_RECIPIENTS_LIMIT;
|
|
54
|
+
/** The longest list of user ids a draft keeps in `participants`. */
|
|
55
|
+
const AGENT_DRAFT_PARTICIPANTS_LENGTH = AGENT_DRAFT_PARTICIPANTS_LIMIT * 38;
|
|
56
56
|
/** An address a member names for a reply to mail. */
|
|
57
57
|
const EmailAddress = Schema.String.check(Schema.isMaxLength(254), Schema.isPattern(EMAIL_PATTERN));
|
|
58
|
-
/** Addresses as a
|
|
59
|
-
export function
|
|
58
|
+
/** Addresses as a draft keeps them in `to` and `cc`: separated by commas. */
|
|
59
|
+
export function draftAddresses(addresses) {
|
|
60
60
|
return addresses.join(", ");
|
|
61
61
|
}
|
|
62
|
-
/** The addresses a
|
|
63
|
-
export function
|
|
62
|
+
/** The addresses a draft keeps in `to` or `cc`; none for an empty value. */
|
|
63
|
+
export function addressesOfDraft(value) {
|
|
64
64
|
return typeof value !== "string"
|
|
65
65
|
? []
|
|
66
66
|
: value
|
|
@@ -68,26 +68,29 @@ export function addressesOfReview(value) {
|
|
|
68
68
|
.map((address) => address.trim())
|
|
69
69
|
.filter((address) => address !== "");
|
|
70
70
|
}
|
|
71
|
-
/** Members as a
|
|
72
|
-
export function
|
|
71
|
+
/** Members as a draft keeps them in `participants`: their user ids, once each, by commas. */
|
|
72
|
+
export function draftParticipants(ids) {
|
|
73
73
|
return [...new Set(ids.map((id) => id.toLowerCase()))].join(", ");
|
|
74
74
|
}
|
|
75
|
-
/** The members a
|
|
76
|
-
export function
|
|
75
|
+
/** The members a draft keeps in `participants`, once each; anything that is no user id is left out. */
|
|
76
|
+
export function participantsOfDraft(value) {
|
|
77
77
|
return [
|
|
78
|
-
...new Set(
|
|
78
|
+
...new Set(addressesOfDraft(value)
|
|
79
79
|
.filter(isUuid)
|
|
80
80
|
.map((id) => id.toLowerCase())),
|
|
81
81
|
];
|
|
82
82
|
}
|
|
83
|
-
export const
|
|
83
|
+
export const AgentDraft = entity("agent_draft", {
|
|
84
|
+
// The id of the entity's first name: a changed id would be a new entity, without its records.
|
|
84
85
|
id: "ent_agent_review",
|
|
85
|
-
|
|
86
|
-
|
|
86
|
+
// @legacy ontology.agent-review-entity-name
|
|
87
|
+
renamedFrom: "agent_review",
|
|
88
|
+
label: "Agent draft",
|
|
89
|
+
plural: "Agent drafts",
|
|
87
90
|
title: "draft",
|
|
88
|
-
description: "
|
|
89
|
-
"
|
|
90
|
-
"the agent; reject it to discard it.",
|
|
91
|
+
description: "The agent's draft reply awaiting a staff decision: a reply it wrote to a person in a chat " +
|
|
92
|
+
"whose replies a member reviews, as the workspace's chats settings ask. Approve it, with an " +
|
|
93
|
+
"edit if needed, to send it to the person as the agent; reject it to discard it.",
|
|
91
94
|
writes: "actions",
|
|
92
95
|
properties: {
|
|
93
96
|
key: p.text({
|
|
@@ -96,8 +99,11 @@ export const AgentReview = entity("agent_review", {
|
|
|
96
99
|
unique: true,
|
|
97
100
|
description: "The agent's key for the reply, so a repeated report holds it once.",
|
|
98
101
|
}),
|
|
99
|
-
|
|
102
|
+
channelKind: p.text({
|
|
100
103
|
managed: true,
|
|
104
|
+
// @legacy ontology.agent-review-entity-name
|
|
105
|
+
renamedFrom: "provider",
|
|
106
|
+
label: "Channel kind",
|
|
101
107
|
description: "The kind of channel the chat is on, for example telegram.",
|
|
102
108
|
}),
|
|
103
109
|
channel: p.text({
|
|
@@ -115,7 +121,7 @@ export const AgentReview = entity("agent_review", {
|
|
|
115
121
|
to: p.text({
|
|
116
122
|
optional: true,
|
|
117
123
|
managed: true,
|
|
118
|
-
maxLength:
|
|
124
|
+
maxLength: AGENT_DRAFT_RECIPIENTS_LENGTH,
|
|
119
125
|
description: "A reply to mail: the addresses it goes to, in To, separated by commas; once approved, " +
|
|
120
126
|
"those it was sent to. Empty on another channel, and on a reply held before replies " +
|
|
121
127
|
"named them, which goes to recipient.",
|
|
@@ -123,14 +129,14 @@ export const AgentReview = entity("agent_review", {
|
|
|
123
129
|
cc: p.text({
|
|
124
130
|
optional: true,
|
|
125
131
|
managed: true,
|
|
126
|
-
maxLength:
|
|
132
|
+
maxLength: AGENT_DRAFT_RECIPIENTS_LENGTH,
|
|
127
133
|
description: "A reply to mail: the addresses it copies, in Cc, separated by commas, as the thread's " +
|
|
128
134
|
"other people; once approved, those it was sent to. Empty when it copies no one.",
|
|
129
135
|
}),
|
|
130
136
|
participants: p.text({
|
|
131
137
|
optional: true,
|
|
132
138
|
managed: true,
|
|
133
|
-
maxLength:
|
|
139
|
+
maxLength: AGENT_DRAFT_PARTICIPANTS_LENGTH,
|
|
134
140
|
description: "A reply in a chat several people share, such as an email thread: the members who " +
|
|
135
141
|
"read it in the chat's history, its person among them, by user id, separated by " +
|
|
136
142
|
"commas, as they read the message it answers. Empty when only its person reads it.",
|
|
@@ -152,22 +158,22 @@ export const AgentReview = entity("agent_review", {
|
|
|
152
158
|
sessionId: p.text({ managed: true, description: "The agent's session that wrote the reply." }),
|
|
153
159
|
draft: p.text({
|
|
154
160
|
managed: true,
|
|
155
|
-
maxLength:
|
|
161
|
+
maxLength: AGENT_DRAFT_TEXT_LIMIT,
|
|
156
162
|
display: "multiline",
|
|
157
163
|
description: "The reply as the agent wrote it, in Markdown.",
|
|
158
164
|
}),
|
|
159
165
|
text: p.text({
|
|
160
166
|
optional: true,
|
|
161
167
|
managed: true,
|
|
162
|
-
maxLength:
|
|
168
|
+
maxLength: AGENT_DRAFT_TEXT_LIMIT,
|
|
163
169
|
display: "multiline",
|
|
164
170
|
description: "The reply as approved: the draft, or the member's edit of it.",
|
|
165
171
|
}),
|
|
166
|
-
status: p.select(
|
|
172
|
+
status: p.select(AGENT_DRAFT_STATUSES, {
|
|
167
173
|
managed: true,
|
|
168
174
|
description: "Whether the reply waits, was delivered, or was rejected.",
|
|
169
175
|
}),
|
|
170
|
-
mode: p.select(
|
|
176
|
+
mode: p.select(AGENT_DRAFT_MODES, { managed: true, description: "Why the reply was held." }),
|
|
171
177
|
confidence: p.number({
|
|
172
178
|
optional: true,
|
|
173
179
|
managed: true,
|
|
@@ -191,7 +197,7 @@ export const AgentReview = entity("agent_review", {
|
|
|
191
197
|
reason: p.text({
|
|
192
198
|
optional: true,
|
|
193
199
|
managed: true,
|
|
194
|
-
maxLength:
|
|
200
|
+
maxLength: AGENT_DRAFT_REASON_LIMIT,
|
|
195
201
|
display: "multiline",
|
|
196
202
|
description: "Why the member rejected the reply, when they said: for the workspace's own review of " +
|
|
197
203
|
"the agent's replies. The person and the agent's chat with them never see it.",
|
|
@@ -199,7 +205,7 @@ export const AgentReview = entity("agent_review", {
|
|
|
199
205
|
note: p.text({
|
|
200
206
|
optional: true,
|
|
201
207
|
managed: true,
|
|
202
|
-
maxLength:
|
|
208
|
+
maxLength: AGENT_DRAFT_NOTE_LIMIT,
|
|
203
209
|
display: "multiline",
|
|
204
210
|
description: "What the member asked the agent to change when they asked it to redraft the reply. " +
|
|
205
211
|
"Only the redraft reads it; the person and the agent's chat with them never see it.",
|
|
@@ -210,7 +216,7 @@ export const AgentReview = entity("agent_review", {
|
|
|
210
216
|
maxLength: 64,
|
|
211
217
|
description: "The redraft last asked for, by its id: only its result replaces the reply.",
|
|
212
218
|
}),
|
|
213
|
-
revisionState: p.select(
|
|
219
|
+
revisionState: p.select(AGENT_DRAFT_REVISION_STATES, {
|
|
214
220
|
optional: true,
|
|
215
221
|
managed: true,
|
|
216
222
|
label: "Revision",
|
|
@@ -220,26 +226,26 @@ export const AgentReview = entity("agent_review", {
|
|
|
220
226
|
relationships: {
|
|
221
227
|
// By name, so that an ontology rebuilt with the deployed `user` still resolves it.
|
|
222
228
|
person: rel.one("user", {
|
|
223
|
-
inverse: "
|
|
229
|
+
inverse: "agentDrafts",
|
|
224
230
|
onDelete: "cascade",
|
|
225
231
|
phrase: ["answers", "is answered by"],
|
|
226
232
|
description: "The person the reply is for.",
|
|
227
233
|
}),
|
|
228
234
|
decidedBy: rel.one("user", {
|
|
229
235
|
optional: true,
|
|
230
|
-
inverse: "
|
|
236
|
+
inverse: "decidedAgentDrafts",
|
|
231
237
|
onDelete: "setNull",
|
|
232
238
|
phrase: ["was decided by", "decided"],
|
|
233
239
|
description: "The member who approved, rejected or had the reply redrafted.",
|
|
234
240
|
}),
|
|
235
241
|
notedBy: rel.one("user", {
|
|
236
242
|
optional: true,
|
|
237
|
-
inverse: "
|
|
243
|
+
inverse: "notedAgentDrafts",
|
|
238
244
|
onDelete: "setNull",
|
|
239
245
|
phrase: ["was sent back by", "sent back"],
|
|
240
246
|
description: "The member who last asked the agent to redraft the reply.",
|
|
241
247
|
}),
|
|
242
|
-
revises: rel.one("
|
|
248
|
+
revises: rel.one("agent_draft", {
|
|
243
249
|
optional: true,
|
|
244
250
|
inverse: "revisions",
|
|
245
251
|
onDelete: "setNull",
|
|
@@ -248,7 +254,7 @@ export const AgentReview = entity("agent_review", {
|
|
|
248
254
|
}),
|
|
249
255
|
agentChat: rel.one("agent_chat", {
|
|
250
256
|
optional: true,
|
|
251
|
-
inverse: "
|
|
257
|
+
inverse: "drafts",
|
|
252
258
|
onDelete: "setNull",
|
|
253
259
|
phrase: ["was held in", "holds"],
|
|
254
260
|
description: "The chat the reply was held in, as the agent_chat registry has it: a group the agent " +
|
|
@@ -258,30 +264,30 @@ export const AgentReview = entity("agent_review", {
|
|
|
258
264
|
indexes: [{ properties: ["status"] }, { properties: ["sessionId"] }],
|
|
259
265
|
}).actions((self) => ({
|
|
260
266
|
approve: action({
|
|
261
|
-
description: "Send
|
|
262
|
-
"
|
|
263
|
-
"
|
|
264
|
-
"
|
|
265
|
-
"
|
|
266
|
-
"
|
|
267
|
+
description: "Send the agent's draft reply to the person, as written or with your edit in text " +
|
|
268
|
+
"(Markdown), as the agent and without sender attribution. A reply to mail goes to the " +
|
|
269
|
+
"draft's to and cc, the thread's people; to and cc, each a list of addresses, replace " +
|
|
270
|
+
"them. Confirm the final text and, for mail, its recipients with the member first. It is " +
|
|
271
|
+
"sent at most once: approving again with the same text and recipients returns the " +
|
|
272
|
+
"delivery, and an approved or rejected draft is refused otherwise. status " +
|
|
267
273
|
"failed means the provider refused it and nothing was sent.",
|
|
268
274
|
hints: { destructive: false, irreversible: true, idempotent: true },
|
|
269
275
|
input: Schema.Struct({
|
|
270
|
-
|
|
276
|
+
draft: self.ref,
|
|
271
277
|
text: Schema.optionalKey(p.text({
|
|
272
|
-
maxLength:
|
|
278
|
+
maxLength: AGENT_DRAFT_TEXT_LIMIT,
|
|
273
279
|
description: "The member's edit of the reply; omit it to send the draft.",
|
|
274
280
|
})),
|
|
275
281
|
to: Schema.optionalKey(Schema.Array(EmailAddress)
|
|
276
282
|
.check(Schema.isMinLength(1), Schema.isMaxLength(EMAIL_RECIPIENTS_LIMIT))
|
|
277
283
|
.annotate({
|
|
278
|
-
description: "A reply to mail: the addresses it goes to, in place of the
|
|
284
|
+
description: "A reply to mail: the addresses it goes to, in place of the draft's to; omit it " +
|
|
279
285
|
"to keep them.",
|
|
280
286
|
})),
|
|
281
287
|
cc: Schema.optionalKey(Schema.Array(EmailAddress)
|
|
282
288
|
.check(Schema.isMaxLength(EMAIL_RECIPIENTS_LIMIT))
|
|
283
289
|
.annotate({
|
|
284
|
-
description: "A reply to mail: the addresses it copies, in place of the
|
|
290
|
+
description: "A reply to mail: the addresses it copies, in place of the draft's cc; [] copies " +
|
|
285
291
|
"no one, and omitting it keeps them.",
|
|
286
292
|
})),
|
|
287
293
|
}),
|
|
@@ -291,21 +297,21 @@ export const AgentReview = entity("agent_review", {
|
|
|
291
297
|
const send = Option.isSome(delivery) ? delivery.value.sendReview : undefined;
|
|
292
298
|
if (send === undefined) {
|
|
293
299
|
return yield* new ActionRejected({
|
|
294
|
-
message: "Sending a
|
|
300
|
+
message: "Sending a draft reply requires the authenticated ontology service.",
|
|
295
301
|
});
|
|
296
302
|
}
|
|
297
303
|
return yield* send({
|
|
298
|
-
review: String(input.
|
|
304
|
+
review: String(input.draft),
|
|
299
305
|
...(input.text === undefined ? {} : { text: input.text }),
|
|
300
306
|
...(input.to === undefined ? {} : { to: input.to }),
|
|
301
307
|
...(input.cc === undefined ? {} : { cc: input.cc }),
|
|
302
308
|
});
|
|
303
309
|
}),
|
|
304
310
|
handler: ({ input, prepared, principal }) => Effect.gen(function* () {
|
|
305
|
-
const review = yield* self.get(input.
|
|
311
|
+
const review = yield* self.get(input.draft, { forUpdate: true });
|
|
306
312
|
const recipients = prepared.recipients;
|
|
307
313
|
// The delivery happened, or definitely did not: the record says what the provider did,
|
|
308
|
-
// and whom a reply to mail went to, even when another member rejected the
|
|
314
|
+
// and whom a reply to mail went to, even when another member rejected the draft meanwhile.
|
|
309
315
|
yield* self.update(review, {
|
|
310
316
|
status: prepared.status,
|
|
311
317
|
text: prepared.text,
|
|
@@ -315,11 +321,13 @@ export const AgentReview = entity("agent_review", {
|
|
|
315
321
|
...(recipients === undefined
|
|
316
322
|
? {}
|
|
317
323
|
: {
|
|
318
|
-
to:
|
|
319
|
-
cc: recipients.cc.length === 0 ? null :
|
|
324
|
+
to: draftAddresses(recipients.to),
|
|
325
|
+
cc: recipients.cc.length === 0 ? null : draftAddresses(recipients.cc),
|
|
320
326
|
}),
|
|
321
327
|
});
|
|
322
328
|
return {
|
|
329
|
+
draft: review.id,
|
|
330
|
+
// @legacy ontology.agent-review-entity-name
|
|
323
331
|
review: review.id,
|
|
324
332
|
status: prepared.status,
|
|
325
333
|
message_id: prepared.messageId,
|
|
@@ -329,21 +337,23 @@ export const AgentReview = entity("agent_review", {
|
|
|
329
337
|
}),
|
|
330
338
|
}),
|
|
331
339
|
reject: action({
|
|
332
|
-
description: "Discard
|
|
333
|
-
"
|
|
334
|
-
"
|
|
340
|
+
description: "Discard the agent's draft reply: the person never sees it. Say why in reason when the " +
|
|
341
|
+
"member gives one; it stays with the draft and never reaches the person or the agent's " +
|
|
342
|
+
"chat with them. A draft already approved is refused.",
|
|
335
343
|
hints: { destructive: true, irreversible: false, idempotent: true },
|
|
336
344
|
input: Schema.Struct({
|
|
337
|
-
|
|
345
|
+
draft: self.ref,
|
|
338
346
|
reason: Schema.optionalKey(p.text({
|
|
339
|
-
maxLength:
|
|
347
|
+
maxLength: AGENT_DRAFT_REASON_LIMIT,
|
|
340
348
|
description: "Why the reply should not be sent, in the member's words.",
|
|
341
349
|
})),
|
|
342
350
|
}),
|
|
343
351
|
handler: ({ input, principal }) => Effect.gen(function* () {
|
|
344
|
-
const review = yield* self.get(input.
|
|
352
|
+
const review = yield* self.get(input.draft, { forUpdate: true });
|
|
353
|
+
// @legacy ontology.agent-review-entity-name
|
|
354
|
+
const result = { draft: review.id, review: review.id, status: "rejected" };
|
|
345
355
|
if (review.status === "rejected") {
|
|
346
|
-
return
|
|
356
|
+
return result;
|
|
347
357
|
}
|
|
348
358
|
if (review.status !== "pending") {
|
|
349
359
|
return yield* new ActionRejected({
|
|
@@ -357,20 +367,20 @@ export const AgentReview = entity("agent_review", {
|
|
|
357
367
|
decidedBy: principal.id,
|
|
358
368
|
...(reason === undefined || reason === "" ? {} : { reason }),
|
|
359
369
|
});
|
|
360
|
-
return
|
|
370
|
+
return result;
|
|
361
371
|
}),
|
|
362
372
|
}),
|
|
363
373
|
revise: action({
|
|
364
|
-
description: "Ask the agent to redraft
|
|
374
|
+
description: "Ask the agent to redraft its draft reply, with what to change in note, in the " +
|
|
365
375
|
"member's words. The agent writes it again in a session of its own, which reads the chat " +
|
|
366
376
|
"and what it looked up for the reply but changes nothing; the new draft replaces this one " +
|
|
367
|
-
"as a
|
|
377
|
+
"as a draft that waits for a member. The person and the agent's chat with them never see " +
|
|
368
378
|
"the note. Only a reply that still waits can be redrafted.",
|
|
369
379
|
hints: { destructive: false, irreversible: false, idempotent: false },
|
|
370
380
|
input: Schema.Struct({
|
|
371
|
-
|
|
381
|
+
draft: self.ref,
|
|
372
382
|
note: p.text({
|
|
373
|
-
maxLength:
|
|
383
|
+
maxLength: AGENT_DRAFT_NOTE_LIMIT,
|
|
374
384
|
description: "What the agent should change, in the member's words.",
|
|
375
385
|
}),
|
|
376
386
|
}),
|
|
@@ -383,13 +393,24 @@ export const AgentReview = entity("agent_review", {
|
|
|
383
393
|
message: "Redrafting a reply requires the authenticated ontology service.",
|
|
384
394
|
});
|
|
385
395
|
}
|
|
386
|
-
return yield* revise({ review: String(input.
|
|
396
|
+
return yield* revise({ review: String(input.draft), note: input.note.trim() });
|
|
387
397
|
}),
|
|
388
398
|
// The request is recorded before the agent is asked, so that its result always finds it.
|
|
389
399
|
handler: ({ input, prepared }) => Effect.succeed({
|
|
390
|
-
|
|
400
|
+
draft: String(input.draft),
|
|
401
|
+
// @legacy ontology.agent-review-entity-name
|
|
402
|
+
review: String(input.draft),
|
|
391
403
|
revision: prepared.revision,
|
|
392
404
|
status: "requested",
|
|
393
405
|
}),
|
|
394
406
|
}),
|
|
395
407
|
}));
|
|
408
|
+
// @legacy ontology.agent-review-entity-name
|
|
409
|
+
/** @deprecated Use {@link AgentDraft}: `agent_review` is the entity's earlier name. */
|
|
410
|
+
export const AgentReview = AgentDraft;
|
|
411
|
+
/** @deprecated Use {@link AGENT_DRAFT_STATUSES}. */
|
|
412
|
+
export const AGENT_REVIEW_STATUSES = AGENT_DRAFT_STATUSES;
|
|
413
|
+
/** @deprecated Use {@link AGENT_DRAFT_MODES}. */
|
|
414
|
+
export const AGENT_REVIEW_MODES = AGENT_DRAFT_MODES;
|
|
415
|
+
/** @deprecated Use {@link AGENT_DRAFT_TEXT_LIMIT}. */
|
|
416
|
+
export const AGENT_REVIEW_TEXT_LIMIT = AGENT_DRAFT_TEXT_LIMIT;
|
package/dist/analyze.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ import { type ResolvedToolset, type Toolset } from "./toolset.js";
|
|
|
20
20
|
/** The input of `defineOntology` and `check`. */
|
|
21
21
|
export interface OntologyConfig<Entities extends ReadonlyArray<AnyEntity> = ReadonlyArray<AnyEntity>, Metrics extends ModelMetrics = ModelMetrics> extends EarlierMetricsField<Metrics> {
|
|
22
22
|
/**
|
|
23
|
-
* The app's entities. The built-in `User`, `AgentChat`, `UserIdentity` and `
|
|
23
|
+
* The app's entities. The built-in `User`, `AgentChat`, `UserIdentity` and `AgentDraft` are
|
|
24
24
|
* always included; listing them is optional.
|
|
25
25
|
*/
|
|
26
26
|
readonly entities: Entities;
|
package/dist/analyze.js
CHANGED
|
@@ -13,11 +13,12 @@ import { QUERY_METRICS_ROUTE, LEGACY_MEMBER_NAME, ENTITY_ID, GENERATED_ACTIONS,
|
|
|
13
13
|
import { REFERENCE_ANNOTATION, propertyDefinition, propertyOptionNames, unknownPropertyOptions, referenceTarget, } from "./property.js";
|
|
14
14
|
import { AGENT_TOOL, AGENT_TOOL_VERBS, EXPLICIT_GRANT_ENTITIES, generatedActionPermissions, grants, isAllowed, MEMBER_AGENT_TOOLS, namesAgentTools, normalizePermission, parsePermission, parseWorkflowPermission, permissionOf, READ_VERB, rolesGranting, USER_IDENTITY_VERBS, USER_MEMBER_VERBS, WILDCARD, wildcardEntityCovers, WORKSPACE_SOURCE, WORKSPACE_SOURCE_PERMISSION, } from "./permissions.js";
|
|
15
15
|
import { ON_DELETE, isRelationship } from "./relationship.js";
|
|
16
|
-
import { implicitMemberOf, implicitRole, isImplicitRole, isRole, member, role, } from "./role.js";
|
|
16
|
+
import { implicitMemberOf, implicitRole, isImplicitRole, isRole, member, role, roleEntries, rolePermissions, } from "./role.js";
|
|
17
17
|
import { CHANNEL_PROVIDERS, DEFAULT_SIGN_IN_POLICY, GUEST_BOT_CHECK_SCHEMES, GUEST_CHANNELS, SIGN_UP_CHANNELS, SIGN_UP_CHAT_CHANNELS, isGuestBotCheckScheme, isGuestChannel, isSignInPolicy, isSignUpChannel, websiteOrigin, } from "./sign-in.js";
|
|
18
18
|
import { BUILT_IN_EMAIL_VALUES, emailOptions, emailValueNames, SIGN_IN_CODE_VALUE, } from "./emails.js";
|
|
19
19
|
import { AgentChat } from "./agent-chat.js";
|
|
20
|
-
import {
|
|
20
|
+
import { AgentDraft } from "./agent-draft.js";
|
|
21
|
+
import { currentEntityName, currentPermissionName, isEarlierEntityName, } from "./earlier-entity-names.js";
|
|
21
22
|
import { APP_FEEDBACK_ENTITIES } from "./app-feedback.js";
|
|
22
23
|
import { feedbackOptions, feedbackRoles, checkFeedbackReporters, checkFeedbackResponders, } from "./feedback-config.js";
|
|
23
24
|
import { User } from "./user.js";
|
|
@@ -83,7 +84,7 @@ export function analyze(config, options = {}) {
|
|
|
83
84
|
options.user ?? User,
|
|
84
85
|
AgentChat,
|
|
85
86
|
UserIdentity,
|
|
86
|
-
|
|
87
|
+
AgentDraft,
|
|
87
88
|
...(feedbackSetting !== false ? APP_FEEDBACK_ENTITIES : []),
|
|
88
89
|
], report);
|
|
89
90
|
config = normalized.config;
|
|
@@ -167,17 +168,17 @@ export function analyze(config, options = {}) {
|
|
|
167
168
|
const { feedback, roles: feedbackAndDeclared } = feedbackRoles(feedbackSetting, files, declaredRoles, report);
|
|
168
169
|
// The guests' role comes last: no declared role, builder, workflow or sign-up may name it.
|
|
169
170
|
const roles = guest === undefined ? feedbackAndDeclared : [...feedbackAndDeclared, guest.role];
|
|
170
|
-
// Resolve authored entities before the optional feedback entities and the agent's
|
|
171
|
+
// Resolve authored entities before the optional feedback entities and the agent's drafts,
|
|
171
172
|
// preserving their ordering: built-ins added later never move an authored entity.
|
|
172
173
|
const isFeedback = (candidate) => APP_FEEDBACK_ENTITIES.some((feedback) => feedback.name === candidate.name);
|
|
173
|
-
const
|
|
174
|
+
const isDraft = (candidate) => candidate.name === AgentDraft.name;
|
|
174
175
|
let resolved = [
|
|
175
176
|
...entities
|
|
176
|
-
.filter((candidate) => !isFeedback(candidate) && !
|
|
177
|
+
.filter((candidate) => !isFeedback(candidate) && !isDraft(candidate))
|
|
177
178
|
.map((candidate) => resolveEntity(candidate, scope, properties.get(candidate))),
|
|
178
179
|
...entities.filter(isFeedback).map((candidate) => resolveEntity(candidate, scope)),
|
|
179
180
|
...entities
|
|
180
|
-
.filter(
|
|
181
|
+
.filter(isDraft)
|
|
181
182
|
.map((candidate) => resolveEntity(candidate, scope, properties.get(candidate))),
|
|
182
183
|
];
|
|
183
184
|
let chat;
|
|
@@ -260,13 +261,13 @@ export function analyze(config, options = {}) {
|
|
|
260
261
|
// Posting to a chat and sending a reviewed reply both send through the chat connections.
|
|
261
262
|
const sends = {
|
|
262
263
|
agent_chat: "post_message",
|
|
263
|
-
|
|
264
|
+
[AgentDraft.name]: "approve",
|
|
264
265
|
};
|
|
265
266
|
// A chat post never reaches a channel whose kind only sends reviewed replies, except a
|
|
266
267
|
// reply in a private chat the inbox registered, and the ontology sends nothing through a
|
|
267
268
|
// workspace channel's connection: the agent does.
|
|
268
269
|
const reaches = (entity) => handles.filter(([, , kind]) => kind !== WORKSPACE_CHANNEL_KIND &&
|
|
269
|
-
(entity ===
|
|
270
|
+
(entity === AgentDraft.name ||
|
|
270
271
|
inbox !== undefined ||
|
|
271
272
|
!REVIEW_ONLY_CHAT_PROVIDERS.has(kind)));
|
|
272
273
|
resolved = resolved.map((entity) => sends[entity.name] === undefined
|
|
@@ -1037,7 +1038,14 @@ function resolveActionTrigger(trigger, at, entities, schema, wire, report) {
|
|
|
1037
1038
|
"such as Lead.");
|
|
1038
1039
|
return undefined;
|
|
1039
1040
|
}
|
|
1040
|
-
|
|
1041
|
+
// @legacy ontology.agent-review-entity-name
|
|
1042
|
+
// A handle of an earlier SDK's built-in entity names it by its earlier name.
|
|
1043
|
+
const entity = currentEntityName(trigger.entity);
|
|
1044
|
+
if (entity !== trigger.entity) {
|
|
1045
|
+
report("earlier-name", `${at}.target`, `${trigger.entity} is the deprecated earlier name of ${entity}; trigger on ${entity}. ` +
|
|
1046
|
+
"The earlier name stops working on 2027-05-22.", "warning");
|
|
1047
|
+
}
|
|
1048
|
+
const owner = entities.find((candidate) => candidate.name === entity);
|
|
1041
1049
|
if (owner === undefined || owner.entity.definition.source !== undefined) {
|
|
1042
1050
|
report("invalid-trigger", `${at}.target`, owner === undefined
|
|
1043
1051
|
? `${JSON.stringify(trigger.entity)} is not an entity of this ontology; list it in ` +
|
|
@@ -1918,12 +1926,12 @@ function guestOptions(config, report) {
|
|
|
1918
1926
|
if (options.confirmations !== undefined && typeof options.confirmations !== "boolean") {
|
|
1919
1927
|
report("invalid-sign-in", "guest.confirmations", "confirmations is true to let guests confirm actions in the website's chat, or false.");
|
|
1920
1928
|
}
|
|
1921
|
-
const guest = role(GUEST_ROLE, {
|
|
1929
|
+
const guest = withCurrentEntityNames(role(GUEST_ROLE, {
|
|
1922
1930
|
description: "Every guest: a visitor of a declared website, who is no user.",
|
|
1923
1931
|
permissions: Array.isArray(options.permissions)
|
|
1924
1932
|
? options.permissions
|
|
1925
1933
|
: [],
|
|
1926
|
-
});
|
|
1934
|
+
}), "guest.permissions", report);
|
|
1927
1935
|
BUILT_IN_GUESTS.add(guest);
|
|
1928
1936
|
return {
|
|
1929
1937
|
resolved: {
|
|
@@ -2153,7 +2161,10 @@ function checkSignUpAction(input) {
|
|
|
2153
2161
|
}
|
|
2154
2162
|
}
|
|
2155
2163
|
function collectRoles(config, report) {
|
|
2156
|
-
const
|
|
2164
|
+
const declared = memberRole(config, report);
|
|
2165
|
+
const implicit = declared === undefined
|
|
2166
|
+
? undefined
|
|
2167
|
+
: withCurrentEntityNames(declared, "member.permissions", report);
|
|
2157
2168
|
const roles = implicit === undefined ? [] : [implicit];
|
|
2158
2169
|
(config.roles ?? []).forEach((candidate, index) => {
|
|
2159
2170
|
if (!isRole(candidate)) {
|
|
@@ -2195,10 +2206,50 @@ function collectRoles(config, report) {
|
|
|
2195
2206
|
if ("allow" in candidate) {
|
|
2196
2207
|
report("removed-allow", `${path}.allow`, REMOVED_ALLOW);
|
|
2197
2208
|
}
|
|
2198
|
-
roles.push(candidate);
|
|
2209
|
+
roles.push(withCurrentEntityNames(candidate, `${path}.permissions`, report));
|
|
2199
2210
|
});
|
|
2200
2211
|
return roles;
|
|
2201
2212
|
}
|
|
2213
|
+
// @legacy ontology.agent-review-entity-name
|
|
2214
|
+
/**
|
|
2215
|
+
* The role with each permission that names a built-in entity by its earlier name, scoped or not,
|
|
2216
|
+
* under the current one, warning where: the manifest and every runtime check see only current
|
|
2217
|
+
* names. The same role when it names none, so that identity checks on built-in roles still hold.
|
|
2218
|
+
*/
|
|
2219
|
+
function withCurrentEntityNames(candidate, path, report) {
|
|
2220
|
+
const permissions = candidate.permissions;
|
|
2221
|
+
const scopes = candidate.scopes;
|
|
2222
|
+
if (!Array.isArray(permissions) || !Array.isArray(scopes)) {
|
|
2223
|
+
return candidate;
|
|
2224
|
+
}
|
|
2225
|
+
const earlier = (value) => typeof value === "string" && currentPermissionName(value) !== value;
|
|
2226
|
+
if (!permissions.some(earlier) &&
|
|
2227
|
+
!scopes.some((scope) => isPlainObject(scope) && earlier(scope.permission))) {
|
|
2228
|
+
return candidate;
|
|
2229
|
+
}
|
|
2230
|
+
for (const value of new Set(permissions.filter(earlier))) {
|
|
2231
|
+
report("earlier-name", path, `${value} names the entity by its deprecated earlier name; write ` +
|
|
2232
|
+
`${currentPermissionName(value)}. The earlier name stops working on 2027-05-22.`, "warning");
|
|
2233
|
+
}
|
|
2234
|
+
// The role's entries again, each under the current name, classified anew: an unscoped grant under
|
|
2235
|
+
// one name and a scoped one under the other are one permission, which the unscoped grant covers.
|
|
2236
|
+
const entries = [
|
|
2237
|
+
...roleEntries(permissions, scopes),
|
|
2238
|
+
...(candidate.unusedScopes ?? []),
|
|
2239
|
+
].map((entry) => typeof entry === "string"
|
|
2240
|
+
? currentPermissionName(entry)
|
|
2241
|
+
: isPlainObject(entry) && earlier(entry.permission)
|
|
2242
|
+
? { ...entry, permission: currentPermissionName(entry.permission) }
|
|
2243
|
+
: entry);
|
|
2244
|
+
const classified = rolePermissions(entries);
|
|
2245
|
+
// A copy keeps the role's own marks, which are symbol properties.
|
|
2246
|
+
return {
|
|
2247
|
+
...candidate,
|
|
2248
|
+
permissions: classified.permissions,
|
|
2249
|
+
scopes: classified.scopes,
|
|
2250
|
+
...(classified.unusedScopes === undefined ? {} : { unusedScopes: classified.unusedScopes }),
|
|
2251
|
+
};
|
|
2252
|
+
}
|
|
2202
2253
|
function resolveEntity(candidate, scope, resolvedProperties) {
|
|
2203
2254
|
const { report } = scope;
|
|
2204
2255
|
const { definition, name } = candidate;
|
|
@@ -2884,6 +2935,12 @@ function checkEntityIdentities(entities, report) {
|
|
|
2884
2935
|
else {
|
|
2885
2936
|
names.set(candidate.name, candidate);
|
|
2886
2937
|
}
|
|
2938
|
+
// @legacy ontology.agent-review-entity-name
|
|
2939
|
+
// A built-in entity's earlier name still names it in routes, tools and permissions.
|
|
2940
|
+
if (!candidate.builtIn && isEarlierEntityName(candidate.name)) {
|
|
2941
|
+
report("reserved-name", candidate.name, `${candidate.name} is the earlier name of the built-in ${currentEntityName(candidate.name)}, ` +
|
|
2942
|
+
"which still answers to it; choose another name.");
|
|
2943
|
+
}
|
|
2887
2944
|
if (!ENTITY_ID.test(definition.id ?? "")) {
|
|
2888
2945
|
report("invalid-entity-id", candidate.name, "entity ids look like ent_01J9Q4M8ZK and never change.");
|
|
2889
2946
|
}
|