@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.
Files changed (61) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/README.md +8 -7
  3. package/dist/agent-chat.d.ts +1 -1
  4. package/dist/agent-chat.js +8 -8
  5. package/dist/agent-draft.d.ts +287 -0
  6. package/dist/{agent-review.js → agent-draft.js} +103 -82
  7. package/dist/analyze.d.ts +1 -1
  8. package/dist/analyze.js +71 -14
  9. package/dist/channel-files.d.ts +70 -0
  10. package/dist/channel-files.js +58 -0
  11. package/dist/chat.d.ts +2 -2
  12. package/dist/earlier-entity-names.d.ts +35 -0
  13. package/dist/earlier-entity-names.js +88 -0
  14. package/dist/email.d.ts +2 -0
  15. package/dist/email.js +1 -0
  16. package/dist/gmail-send.d.ts +39 -0
  17. package/dist/gmail-send.js +179 -0
  18. package/dist/index.d.ts +1 -1
  19. package/dist/index.js +3 -1
  20. package/dist/migrate/plan.js +31 -2
  21. package/dist/permissions.d.ts +5 -5
  22. package/dist/permissions.js +13 -10
  23. package/dist/replicated-entities.d.ts +1 -1
  24. package/dist/replicated-entities.js +4 -1
  25. package/dist/replication/bigquery.d.ts +24 -2
  26. package/dist/replication/bigquery.js +72 -12
  27. package/dist/runtime/agents.d.ts +1 -1
  28. package/dist/runtime/agents.js +43 -38
  29. package/dist/runtime/chat-messages.d.ts +8 -7
  30. package/dist/runtime/chat-messages.js +11 -10
  31. package/dist/runtime/service-binding.js +1 -1
  32. package/dist/service/agent/protocol.d.ts +4 -4
  33. package/dist/service/agent/protocol.js +7 -7
  34. package/dist/service/agent/server.js +14 -9
  35. package/dist/service/chat/envelope.d.ts +12 -12
  36. package/dist/service/chat/review-delivery.js +23 -22
  37. package/dist/service/chat/review-revision.d.ts +1 -1
  38. package/dist/service/chat/review-revision.js +13 -13
  39. package/dist/service/mcp/runtime-policy.js +1 -1
  40. package/dist/service/mcp/server.js +9 -1
  41. package/dist/service/mcp/tools.js +1 -1
  42. package/dist/service/operations.js +11 -5
  43. package/dist/service/runtime-contract.d.ts +3 -3
  44. package/dist/service/service.d.ts +6 -0
  45. package/dist/service/service.js +21 -3
  46. package/dist/slack-files.d.ts +53 -0
  47. package/dist/slack-files.js +183 -0
  48. package/dist/slack.d.ts +3 -0
  49. package/dist/slack.js +2 -0
  50. package/dist/telegram-files.d.ts +81 -0
  51. package/dist/telegram-files.js +244 -0
  52. package/dist/telegram.d.ts +3 -1
  53. package/dist/telegram.js +2 -0
  54. package/dist/whatsapp-files.d.ts +54 -0
  55. package/dist/whatsapp-files.js +138 -0
  56. package/dist/whatsapp.d.ts +3 -0
  57. package/dist/whatsapp.js +2 -0
  58. package/dist/workspace-channel.d.ts +20 -0
  59. package/dist/workspace-channel.js +10 -0
  60. package/package.json +1 -1
  61. package/dist/agent-review.d.ts +0 -154
@@ -139,8 +139,8 @@ export declare const ChatHandoffRequest: Schema.Struct<{
139
139
  readonly reason: Schema.String;
140
140
  }>;
141
141
  /**
142
- * `POST /api/ontology/agent/reviews`: a reply the agent held for a member to review, for the member
143
- * it answers. `key` names the reply, so a report repeated after a failure finds its review.
142
+ * `POST /api/ontology/agent/drafts`: a reply the agent kept for a member to review, for the member
143
+ * it answers. `key` names the reply, so a report repeated after a failure finds its draft.
144
144
  */
145
145
  export declare const ReviewRequest: Schema.Struct<{
146
146
  readonly key: Schema.String;
@@ -161,7 +161,7 @@ export declare const ReviewRequest: Schema.Struct<{
161
161
  }>;
162
162
  export type ReviewRequest = typeof ReviewRequest.Type;
163
163
  /**
164
- * `POST /api/ontology/agent/reviews/revision`: what became of a redraft a member asked for: the new
164
+ * `POST /api/ontology/agent/drafts/revision`: what became of a redraft a member asked for: the new
165
165
  * draft, or, without `text`, that the agent could not write one.
166
166
  */
167
167
  export declare const RevisionRequest: Schema.Struct<{
@@ -170,7 +170,7 @@ export declare const RevisionRequest: Schema.Struct<{
170
170
  readonly text: Schema.optionalKey<Schema.String>;
171
171
  }>;
172
172
  /**
173
- * `POST /api/ontology/agent/reviews/session`: the replies an agent session held for review, so its
173
+ * `POST /api/ontology/agent/drafts/session`: the drafts an agent session kept for review, so its
174
174
  * next turn learns which the person saw.
175
175
  */
176
176
  export declare const SessionReviewsRequest: Schema.Struct<{
@@ -1,6 +1,6 @@
1
1
  import { randomInt } from "node:crypto";
2
2
  import { Schema } from "effect";
3
- import { AGENT_REVIEW_PARTICIPANTS_LIMIT } from "../../agent-review.js";
3
+ import { AGENT_DRAFT_PARTICIPANTS_LIMIT } from "../../agent-draft.js";
4
4
  import { ChatChannelName } from "../../chat-channel.js";
5
5
  import { EMAIL_RECIPIENTS_LIMIT } from "../../email.js";
6
6
  import { EMAIL_PATTERN } from "../../property.js";
@@ -183,8 +183,8 @@ export const ChatHandoffRequest = Schema.Struct({
183
183
  }),
184
184
  });
185
185
  /**
186
- * `POST /api/ontology/agent/reviews`: a reply the agent held for a member to review, for the member
187
- * it answers. `key` names the reply, so a report repeated after a failure finds its review.
186
+ * `POST /api/ontology/agent/drafts`: a reply the agent kept for a member to review, for the member
187
+ * it answers. `key` names the reply, so a report repeated after a failure finds its draft.
188
188
  */
189
189
  export const ReviewRequest = Schema.Struct({
190
190
  key: Schema.String.check(Schema.isMinLength(1), Schema.isMaxLength(512)).annotate({
@@ -208,7 +208,7 @@ export const ReviewRequest = Schema.Struct({
208
208
  description: "A reply to mail: the addresses it copies, in Cc, the thread's other people.",
209
209
  })),
210
210
  participants: Schema.optionalKey(Schema.Array(Schema.String.check(Schema.isUUID()))
211
- .check(Schema.isMaxLength(AGENT_REVIEW_PARTICIPANTS_LIMIT))
211
+ .check(Schema.isMaxLength(AGENT_DRAFT_PARTICIPANTS_LIMIT))
212
212
  .annotate({
213
213
  description: "A reply in a chat several people share, such as an email thread: the members who " +
214
214
  "read it, by user id, as they read the message it answers; its member alone when absent.",
@@ -234,12 +234,12 @@ export const ReviewRequest = Schema.Struct({
234
234
  }),
235
235
  });
236
236
  /**
237
- * `POST /api/ontology/agent/reviews/revision`: what became of a redraft a member asked for: the new
237
+ * `POST /api/ontology/agent/drafts/revision`: what became of a redraft a member asked for: the new
238
238
  * draft, or, without `text`, that the agent could not write one.
239
239
  */
240
240
  export const RevisionRequest = Schema.Struct({
241
241
  review_id: Schema.String.check(Schema.isMinLength(1), Schema.isMaxLength(64)).annotate({
242
- description: "The review the redraft replaces.",
242
+ description: "The draft the redraft replaces.",
243
243
  }),
244
244
  revision: Schema.String.check(Schema.isMinLength(1), Schema.isMaxLength(64)).annotate({
245
245
  description: "The redraft, as the member's request named it.",
@@ -249,7 +249,7 @@ export const RevisionRequest = Schema.Struct({
249
249
  }),
250
250
  });
251
251
  /**
252
- * `POST /api/ontology/agent/reviews/session`: the replies an agent session held for review, so its
252
+ * `POST /api/ontology/agent/drafts/session`: the drafts an agent session kept for review, so its
253
253
  * next turn learns which the person saw.
254
254
  */
255
255
  export const SessionReviewsRequest = Schema.Struct({
@@ -25,6 +25,9 @@ const PAIRINGS_PATH = `${AGENT_PATH}/pairings`;
25
25
  const IDENTITIES_PATH = `${AGENT_PATH}/identities`;
26
26
  const CHATS_SEEN_PATH = `${AGENT_PATH}/chats/seen`;
27
27
  const CHATS_HANDOFF_PATH = `${AGENT_PATH}/chats/handoff`;
28
+ const DRAFTS_PATH = `${AGENT_PATH}/drafts`;
29
+ // @legacy agent.review-runtime-paths
30
+ // The drafts' routes under their earlier name, which agent SDKs released before them call.
28
31
  const REVIEWS_PATH = `${AGENT_PATH}/reviews`;
29
32
  /** Where a signed-in member gets an agent token, and where the agent asks whom one stands for. */
30
33
  export const AGENT_TOKENS_PATH = `${AGENT_PATH}/tokens`;
@@ -346,9 +349,9 @@ function seeChat(store) {
346
349
  });
347
350
  }
348
351
  /**
349
- * `POST /api/ontology/agent/reviews` (runtime): the agent held a reply for review. It becomes a
350
- * pending `agent_review` for the member it answers, once per key; 404 when that member is not an
351
- * active member, so the reply is neither sent nor held.
352
+ * `POST /api/ontology/agent/drafts` (runtime): the agent kept a reply for review. It becomes a
353
+ * pending `agent_draft` for the member it answers, once per key; 404 when that member is not an
354
+ * active member, so the reply is neither sent nor kept.
352
355
  */
353
356
  function holdReply(store) {
354
357
  return (request) => Effect.gen(function* () {
@@ -418,8 +421,8 @@ function holdReply(store) {
418
421
  });
419
422
  }
420
423
  /**
421
- * `POST /api/ontology/agent/reviews/revision` (runtime): the agent redrafted a reply a member sent
422
- * back, or could not. The new draft becomes a pending review for the same person and chat that
424
+ * `POST /api/ontology/agent/drafts/revision` (runtime): the agent redrafted a reply a member sent
425
+ * back, or could not. The new draft becomes a pending draft for the same person and chat that
423
426
  * replaces the earlier one, which becomes `superseded`, once per redraft; a redraft the member no
424
427
  * longer waits for, because the reply was decided or redrafted again since, replaces nothing.
425
428
  */
@@ -465,7 +468,7 @@ function revision(store) {
465
468
  });
466
469
  }
467
470
  /**
468
- * `POST /api/ontology/agent/reviews/session` (runtime): the replies the session held for review,
471
+ * `POST /api/ontology/agent/drafts/session` (runtime): the drafts the session kept for review,
469
472
  * newest first, with what became of each. Nothing a member wrote about them is in it.
470
473
  */
471
474
  function sessionReviews(store) {
@@ -618,9 +621,11 @@ export function agentLayer(options) {
618
621
  yield* router.add("GET", `${AGENT_PATH}${CHAT_MESSAGE_PATHS.purge}`, purge);
619
622
  yield* router.add("POST", `${AGENT_PATH}${CHAT_MESSAGE_PATHS.purge}`, purge);
620
623
  }
621
- yield* router.add("POST", REVIEWS_PATH, asRuntime(holdReply(store)));
622
- yield* router.add("POST", `${REVIEWS_PATH}/session`, asRuntime(sessionReviews(store)));
623
- yield* router.add("POST", `${REVIEWS_PATH}/revision`, asRuntime(revision(store)));
624
+ for (const path of [DRAFTS_PATH, REVIEWS_PATH]) {
625
+ yield* router.add("POST", path, asRuntime(holdReply(store)));
626
+ yield* router.add("POST", `${path}/session`, asRuntime(sessionReviews(store)));
627
+ yield* router.add("POST", `${path}/revision`, asRuntime(revision(store)));
628
+ }
624
629
  yield* router.add("DELETE", `${IDENTITIES_PATH}/:id`, asMember((_, member) => revokeIdentity(store, member)));
625
630
  if (store.web !== undefined && backend.oauth !== undefined) {
626
631
  yield* router.add("POST", AGENT_TOKENS_PATH, asMember(issueAgentToken(store, store.web, fixedWindowLimiter(AGENT_TOKEN_LIMIT))));
@@ -54,6 +54,12 @@ declare const CurrentChatCall_base: Context.ServiceClass<CurrentChatCall, "@segm
54
54
  readonly thread_id: string;
55
55
  readonly message_id?: string | undefined;
56
56
  readonly channel?: string | undefined;
57
+ readonly location?: {
58
+ readonly latitude: number;
59
+ readonly longitude: number;
60
+ readonly horizontal_accuracy?: number | undefined;
61
+ readonly live_period?: number | undefined;
62
+ } | undefined;
57
63
  readonly attachments?: readonly {
58
64
  readonly kind: "photo" | "document" | "voice" | "audio" | "video" | "video_note" | "sticker" | "animation";
59
65
  readonly file_id: string;
@@ -64,12 +70,6 @@ declare const CurrentChatCall_base: Context.ServiceClass<CurrentChatCall, "@segm
64
70
  readonly reply_to_message_id?: string | undefined;
65
71
  readonly callback_query_id?: string | undefined;
66
72
  readonly sender?: string | undefined;
67
- readonly location?: {
68
- readonly latitude: number;
69
- readonly longitude: number;
70
- readonly horizontal_accuracy?: number | undefined;
71
- readonly live_period?: number | undefined;
72
- } | undefined;
73
73
  } | {
74
74
  readonly kind: "private" | "group";
75
75
  readonly provider: "slack" | "whatsapp";
@@ -108,6 +108,12 @@ export declare function consumeChatEnvelope(args: Readonly<Record<string, unknow
108
108
  readonly thread_id: string;
109
109
  readonly message_id?: string | undefined;
110
110
  readonly channel?: string | undefined;
111
+ readonly location?: {
112
+ readonly latitude: number;
113
+ readonly longitude: number;
114
+ readonly horizontal_accuracy?: number | undefined;
115
+ readonly live_period?: number | undefined;
116
+ } | undefined;
111
117
  readonly attachments?: readonly {
112
118
  readonly kind: "photo" | "document" | "voice" | "audio" | "video" | "video_note" | "sticker" | "animation";
113
119
  readonly file_id: string;
@@ -118,12 +124,6 @@ export declare function consumeChatEnvelope(args: Readonly<Record<string, unknow
118
124
  readonly reply_to_message_id?: string | undefined;
119
125
  readonly callback_query_id?: string | undefined;
120
126
  readonly sender?: string | undefined;
121
- readonly location?: {
122
- readonly latitude: number;
123
- readonly longitude: number;
124
- readonly horizontal_accuracy?: number | undefined;
125
- readonly live_period?: number | undefined;
126
- } | undefined;
127
127
  } | {
128
128
  readonly kind: "private" | "group";
129
129
  readonly provider: "slack" | "whatsapp";
@@ -1,5 +1,5 @@
1
1
  import { Effect } from "effect";
2
- import { addressesOfReview, AGENT_REVIEW_TEXT_LIMIT, participantsOfReview, } from "../../agent-review.js";
2
+ import { addressesOfDraft, AGENT_DRAFT_TEXT_LIMIT, participantsOfDraft, } from "../../agent-draft.js";
3
3
  import { EMAIL_RECIPIENTS_LIMIT, emailRecipients } from "../../email.js";
4
4
  import { ActionRejected, PermissionDenied } from "../../errors.js";
5
5
  import { effectiveScope } from "../../permissions.js";
@@ -14,10 +14,10 @@ import { deliveryArchiveOf } from "./store-delivery.js";
14
14
  * recipient, and its `cc`, whatever their order and case.
15
15
  */
16
16
  function sameRecipients(recipients, review) {
17
- const held = addressesOfReview(review.to);
17
+ const held = addressesOfDraft(review.to);
18
18
  const set = (list) => [...new Set(list.map((address) => address.toLowerCase()))].sort().join(",");
19
19
  return (set(recipients.to) ===
20
- set(held.length > 0 ? held : typeof review.recipient === "string" ? [review.recipient] : []) && set(recipients.cc) === set(addressesOfReview(review.cc)));
20
+ set(held.length > 0 ? held : typeof review.recipient === "string" ? [review.recipient] : []) && set(recipients.cc) === set(addressesOfDraft(review.cc)));
21
21
  }
22
22
  /**
23
23
  * Sends a reply the agent held for review, once a member approved it: the draft or the member's
@@ -31,7 +31,7 @@ function sameRecipients(recipients, review) {
31
31
  */
32
32
  export function reviewSender(input) {
33
33
  const { backend, principal } = input;
34
- const report = (phase, cause) => Effect.logWarning("ontology.agent_review.delivery_diagnostic").pipe(Effect.annotateLogs({
34
+ const report = (phase, cause) => Effect.logWarning("ontology.agent_draft.delivery_diagnostic").pipe(Effect.annotateLogs({
35
35
  phase,
36
36
  requestId: input.requestId,
37
37
  error: describeChatError(cause, (text) => input.identityToken ? text.split(input.identityToken).join("[redacted]") : text),
@@ -40,30 +40,30 @@ export function reviewSender(input) {
40
40
  // A role may hold the approval within a scope. The send happens before the action's
41
41
  // transaction, whose write guard comes too late for it: a review outside the scope is
42
42
  // refused here, read through the approval's own scope.
43
- const approvable = effectiveScope("agent_review:approve", principal);
43
+ const approvable = effectiveScope("agent_draft:approve", principal);
44
44
  if (approvable !== undefined) {
45
45
  yield* backend
46
46
  .get({
47
- entity: "agent_review",
47
+ entity: "agent_draft",
48
48
  id: send.review,
49
49
  reader: {
50
50
  ...principal,
51
- permissions: ["agent_review:read"],
52
- scopes: [{ permission: "agent_review:read", where: approvable }],
51
+ permissions: ["agent_draft:read"],
52
+ scopes: [{ permission: "agent_draft:read", where: approvable }],
53
53
  },
54
54
  })
55
55
  .pipe(Effect.mapError(() => new PermissionDenied({
56
- message: "The review is outside the records agent_review:approve covers.",
57
- permission: "agent_review:approve",
56
+ message: "The draft is outside the records agent_draft:approve covers.",
57
+ permission: "agent_draft:approve",
58
58
  })));
59
59
  }
60
60
  const review = yield* backend
61
- .get({ entity: "agent_review", id: send.review })
62
- .pipe(Effect.mapError(() => new ActionRejected({ message: "The review does not exist." })));
61
+ .get({ entity: "agent_draft", id: send.review })
62
+ .pipe(Effect.mapError(() => new ActionRejected({ message: "The draft does not exist." })));
63
63
  const draft = String(review.draft ?? "");
64
64
  const text = send.text ?? draft;
65
65
  const status = String(review.status);
66
- const email = String(review.provider) === "email";
66
+ const email = String(review.channel_kind) === "email";
67
67
  // Only a reply to mail names whom it goes to beside its chat.
68
68
  if (!email && (send.to !== undefined || send.cc !== undefined)) {
69
69
  return yield* new ActionRejected({
@@ -72,7 +72,7 @@ export function reviewSender(input) {
72
72
  }
73
73
  // A reply to mail goes to the review's `to` and `cc`, the thread's people, unless the member
74
74
  // names others; one held before replies named them goes to its recipient alone.
75
- const held = addressesOfReview(review.to);
75
+ const held = addressesOfDraft(review.to);
76
76
  const recipients = email
77
77
  ? yield* Effect.try({
78
78
  try: () => emailRecipients({
@@ -82,7 +82,7 @@ export function reviewSender(input) {
82
82
  : typeof review.recipient === "string"
83
83
  ? [review.recipient]
84
84
  : []),
85
- cc: send.cc ?? addressesOfReview(review.cc),
85
+ cc: send.cc ?? addressesOfDraft(review.cc),
86
86
  }),
87
87
  catch: (cause) => new ActionRejected({
88
88
  message: `A reply to mail goes to 1 to ${EMAIL_RECIPIENTS_LIMIT} plain addresses ` +
@@ -114,17 +114,17 @@ export function reviewSender(input) {
114
114
  // @legacy ontology.reviews-without-channel
115
115
  const providerName = typeof review.channel === "string" && review.channel !== ""
116
116
  ? review.channel
117
- : String(review.provider);
117
+ : String(review.channel_kind);
118
118
  const provider = channelProvider(input.ontology.manifest.chat, providerName);
119
119
  const connection = chatConnection(input.ontology.manifest.chat, providerName) ?? "";
120
120
  const channelKind = chatKind(input.ontology.manifest.chat, providerName);
121
121
  // A workspace channel needs no connection of the ontology's: the agent sends through it.
122
122
  if (provider === undefined ||
123
123
  (!connection && channelKind !== WORKSPACE_CHANNEL_KIND) ||
124
- channelKind !== String(review.provider)) {
124
+ channelKind !== String(review.channel_kind)) {
125
125
  return yield* new ActionRejected({
126
126
  message: `Sending a reviewed reply needs chat.${providerName}.connection in defineOntology, ` +
127
- `of kind ${String(review.provider)}: the connection of the bot, number or mailbox ` +
127
+ `of kind ${String(review.channel_kind)}: the connection of the bot, number or mailbox ` +
128
128
  "the person talks to.",
129
129
  });
130
130
  }
@@ -147,7 +147,7 @@ export function reviewSender(input) {
147
147
  catch: (cause) => new ActionRejected({ message: "The Markdown could not be rendered.", cause }),
148
148
  });
149
149
  if (text.trim() === "" ||
150
- text.length > AGENT_REVIEW_TEXT_LIMIT ||
150
+ text.length > AGENT_DRAFT_TEXT_LIMIT ||
151
151
  finalText.length > provider.limit ||
152
152
  plainText.length > provider.limit ||
153
153
  !provider.isTargetId(externalId, kind) ||
@@ -158,7 +158,7 @@ export function reviewSender(input) {
158
158
  "sent or truncated.",
159
159
  });
160
160
  }
161
- // A guest is no user; `agent_review` is not theirs to approve.
161
+ // A guest is no user; `agent_draft` is not theirs to approve.
162
162
  if (principal.kind === "guest") {
163
163
  return yield* new PermissionDenied({ message: "The approver is unknown." });
164
164
  }
@@ -191,7 +191,7 @@ export function reviewSender(input) {
191
191
  participantIds: [
192
192
  ...new Set([
193
193
  ...(person === null ? [] : [person]),
194
- ...participantsOfReview(review.participants),
194
+ ...participantsOfDraft(review.participants),
195
195
  ]),
196
196
  ],
197
197
  };
@@ -208,6 +208,7 @@ export function reviewSender(input) {
208
208
  const operationId = String(review.id);
209
209
  const scope = deliveryScopeDigest({
210
210
  via: "service",
211
+ // The delivery keys keep the entity's first name: a renamed key would send an approval again.
211
212
  subjectId: `agent_review:${operationId}`,
212
213
  clientId: null,
213
214
  });
@@ -319,7 +320,7 @@ export function reviewSender(input) {
319
320
  transport: input.connections({
320
321
  identityToken: input.identityToken,
321
322
  audit: {
322
- action: "agent_review.approve",
323
+ action: "agent_draft.approve",
323
324
  principalId: principal.id,
324
325
  requestId: input.requestId,
325
326
  },
@@ -9,7 +9,7 @@ export declare const AGENT_REVISION_ROUTE = "/eve/segmentstream/v1/reviews/revis
9
9
  /**
10
10
  * Hands a reply the agent held for review back to it with a member's note: the agent redrafts it in
11
11
  * a session of its own, acting as the person the reply is for and reading only, and reports the new
12
- * draft to `POST /api/ontology/agent/reviews/revision`, where it replaces the review while the review
12
+ * draft to `POST /api/ontology/agent/drafts/revision`, where it replaces the draft while the draft
13
13
  * still waits and this is the last redraft asked for. The request is recorded before the agent is
14
14
  * called, so however soon the agent reports, its report finds it, and it names everything the agent
15
15
  * needs: the agent never looks the review up.
@@ -13,14 +13,14 @@ const text = (value) => typeof value === "string" && value !== "" ? value : null
13
13
  /**
14
14
  * Hands a reply the agent held for review back to it with a member's note: the agent redrafts it in
15
15
  * a session of its own, acting as the person the reply is for and reading only, and reports the new
16
- * draft to `POST /api/ontology/agent/reviews/revision`, where it replaces the review while the review
16
+ * draft to `POST /api/ontology/agent/drafts/revision`, where it replaces the draft while the draft
17
17
  * still waits and this is the last redraft asked for. The request is recorded before the agent is
18
18
  * called, so however soon the agent reports, its report finds it, and it names everything the agent
19
19
  * needs: the agent never looks the review up.
20
20
  */
21
21
  export function reviewReviser(input) {
22
22
  const { backend, principal, agent } = input;
23
- const report = (phase, cause) => Effect.logWarning("ontology.agent_review.revision_diagnostic").pipe(Effect.annotateLogs({
23
+ const report = (phase, cause) => Effect.logWarning("ontology.agent_draft.revision_diagnostic").pipe(Effect.annotateLogs({
24
24
  phase,
25
25
  requestId: input.requestId,
26
26
  error: describeChatError(cause, (value) => agent.identityToken ? value.split(agent.identityToken).join("[redacted]") : value),
@@ -28,29 +28,29 @@ export function reviewReviser(input) {
28
28
  return (revise) => Effect.gen(function* () {
29
29
  // The call happens before the action's transaction, whose write guard comes too late for it:
30
30
  // a review outside the scope is refused here, read through the request's own scope.
31
- const revisable = effectiveScope("agent_review:revise", principal);
31
+ const revisable = effectiveScope("agent_draft:revise", principal);
32
32
  if (revisable !== undefined) {
33
33
  yield* backend
34
34
  .get({
35
- entity: "agent_review",
35
+ entity: "agent_draft",
36
36
  id: revise.review,
37
37
  reader: {
38
38
  ...principal,
39
- permissions: ["agent_review:read"],
40
- scopes: [{ permission: "agent_review:read", where: revisable }],
39
+ permissions: ["agent_draft:read"],
40
+ scopes: [{ permission: "agent_draft:read", where: revisable }],
41
41
  },
42
42
  })
43
43
  .pipe(Effect.mapError(() => new PermissionDenied({
44
- message: "The review is outside the records agent_review:revise covers.",
45
- permission: "agent_review:revise",
44
+ message: "The draft is outside the records agent_draft:revise covers.",
45
+ permission: "agent_draft:revise",
46
46
  })));
47
47
  }
48
48
  if (principal.kind === "guest") {
49
49
  return yield* new PermissionDenied({ message: "The member is unknown." });
50
50
  }
51
51
  const review = yield* backend
52
- .get({ entity: "agent_review", id: revise.review })
53
- .pipe(Effect.mapError(() => new ActionRejected({ message: "The review does not exist." })));
52
+ .get({ entity: "agent_draft", id: revise.review })
53
+ .pipe(Effect.mapError(() => new ActionRejected({ message: "The draft does not exist." })));
54
54
  if (review.status !== "pending") {
55
55
  return yield* new ActionRejected({
56
56
  message: "Only a reply that still waits for a member can be redrafted.",
@@ -83,7 +83,7 @@ export function reviewReviser(input) {
83
83
  break;
84
84
  }
85
85
  const found = yield* backend
86
- .get({ entity: "agent_review", id: earlier })
86
+ .get({ entity: "agent_draft", id: earlier })
87
87
  .pipe(Effect.option);
88
88
  if (Option.isNone(found)) {
89
89
  break;
@@ -115,8 +115,8 @@ export function reviewReviser(input) {
115
115
  roles: person.principal.roles,
116
116
  session_id: String(review.session_id),
117
117
  key: String(first.key),
118
- provider: String(review.provider),
119
- channel: text(review.channel) ?? String(review.provider),
118
+ provider: String(review.channel_kind),
119
+ channel: text(review.channel) ?? String(review.channel_kind),
120
120
  chat_id: String(review.chat_id),
121
121
  thread_id: text(review.thread_id),
122
122
  chat_kind: review.chat_kind === "group" ? "group" : "private",
@@ -39,7 +39,7 @@ export function requireRuntimeOperation(operation) {
39
39
  if (deployment) {
40
40
  yield* Effect.sync(() => requireDeploymentCapability(deployment, invokesAgent(operation) ||
41
41
  operation.entity === "agent_chat" ||
42
- operation.entity === "agent_review"
42
+ operation.entity === "agent_draft"
43
43
  ? "agents"
44
44
  : undefined));
45
45
  }
@@ -2,6 +2,7 @@ import { Cause, Data, Effect, Layer, Option, Redacted, Schema, SchemaTransformat
2
2
  import { HttpRouter, HttpServerRequest, HttpServerResponse } from "effect/unstable/http";
3
3
  import { HttpApiBuilder, HttpApiSecurity } from "effect/unstable/httpapi";
4
4
  import { ActionRejected } from "../../errors.js";
5
+ import { currentToolName } from "../../earlier-entity-names.js";
5
6
  import { DeploymentAdmissionError } from "../../deployment.js";
6
7
  import { effectivePermissions } from "../../permissions.js";
7
8
  import { declaredChatRetentionDaysOf, encodeManifest } from "../../manifest.js";
@@ -527,7 +528,14 @@ function callTool(server, params, request, preview) {
527
528
  const requestId = yield* RequestId;
528
529
  const caller = yield* currentCaller;
529
530
  const principal = yield* CurrentPrincipal;
530
- const call = params;
531
+ // @legacy ontology.agent-review-entity-name
532
+ // A tool named by a built-in entity's earlier name is called under its current name.
533
+ // A tool the server has by the name given is that tool, whatever its name starts with.
534
+ const call = typeof params.name === "string" &&
535
+ !server.tools.some((candidate) => candidate.name === params.name) &&
536
+ currentToolName(params.name) !== params.name
537
+ ? { ...params, name: currentToolName(params.name) }
538
+ : params;
531
539
  const tool = server.tools.find((candidate) => candidate.name === call.name);
532
540
  const allowed = yield* requireRuntimeOperation({
533
541
  ...(typeof call.name === "string" ? { name: call.name } : {}),
@@ -836,7 +836,7 @@ export function mcpTools(built, chatHistory = false, storage = {}, navigation =
836
836
  "agent_chat:read) and DMs in which you participated. Dates are ISO 8601; before is the " +
837
837
  "nextCursor of the previous page. " +
838
838
  "Workspace administrators can read all DMs through the platform API."
839
- : "Search retained chat messages. Requires an available archive and chat archive read access.",
839
+ : "Search retained chat messages. Requires an available chat store and chat read access.",
840
840
  inputSchema: encodedJsonSchema(ChatSearch),
841
841
  annotations: READ,
842
842
  permissions: [],
@@ -20,6 +20,9 @@ import { InvalidActionInput, RequestId } from "./errors.js";
20
20
  import { recordReads } from "./record-reads.js";
21
21
  import { runToolsetToolOf } from "./toolsets.js";
22
22
  import { AGENT_TASK_AUTHENTICATION } from "./agent/task-caller.js";
23
+ import { AgentDraft } from "../agent-draft.js";
24
+ import { currentActionInput } from "../earlier-entity-names.js";
25
+ const AGENT_DRAFT = AgentDraft.name;
23
26
  /**
24
27
  * What the service does for a caller, whatever the transport: the reads and actions of every entity
25
28
  * and the caller's own account. The HTTP routes and the MCP tools both call these, so a permission
@@ -241,20 +244,23 @@ function runActionOf(backend, plan, hooks, connections, replicate, chatDelivery)
241
244
  }
242
245
  input = { ...values, idempotency_key: envelope.operation_id };
243
246
  }
244
- // Approving a held reply sends it to a person: a member, or the agent acting for one with
247
+ // Approving a draft sends it to a person: a member, or the agent acting for one with
245
248
  // their confirmation, decides; an agent task has no one to confirm it.
246
- if (planned.name === "agent_review" &&
249
+ if (planned.name === AGENT_DRAFT &&
247
250
  name === "approve" &&
248
251
  principal.authenticatedVia === AGENT_TASK_AUTHENTICATION) {
249
252
  return yield* new ActionRejected({
250
- message: "Agent tasks cannot approve a held reply: agent_review.approve needs a member to " +
253
+ message: "Agent tasks cannot approve a draft: agent_draft.approve needs a member to " +
251
254
  "confirm the text the person receives.",
252
255
  });
253
256
  }
257
+ // @legacy ontology.agent-review-entity-name
258
+ // Callers written for the entity's earlier name still send its input keys.
259
+ input = currentActionInput(planned.name, input);
254
260
  const requestId = yield* RequestId;
255
- // Every action of the chat registry and of held replies reaches chats through the service:
261
+ // Every action of the chat registry and of drafts reaches chats through the service:
256
262
  // posts, takeovers, imports, approvals and redrafts.
257
- const delivery = planned.name === "agent_chat" || planned.name === "agent_review"
263
+ const delivery = planned.name === "agent_chat" || planned.name === AGENT_DRAFT
258
264
  ? chatDelivery?.({
259
265
  backend,
260
266
  principal,
@@ -689,7 +689,7 @@ export interface AgentStore {
689
689
  */
690
690
  readonly seeGuestChat?: (guestId: string) => Effect.Effect<SeenChat | undefined>;
691
691
  /**
692
- * A reply the agent held for review becomes a pending `agent_review` for the member it answers,
692
+ * A reply the agent kept for review becomes a pending `agent_draft` for the member it answers,
693
693
  * once per `key`: a repeated report answers the review it created. `undefined` when the member is
694
694
  * not an active member of the app. Absent on stores that predate reviews.
695
695
  */
@@ -733,7 +733,7 @@ export interface AgentStore {
733
733
  /** The chats' messages, in `_chat_messages`. Absent on stores that predate the chat store. */
734
734
  readonly chatMessages?: import("../runtime/chat-messages.js").ChatMessageStore;
735
735
  }
736
- /** A reply the agent held for review, as `POST /api/ontology/agent/reviews` reports it. */
736
+ /** A reply the agent held for review, as `POST /api/ontology/agent/drafts` reports it. */
737
737
  export interface HeldReplyInput {
738
738
  readonly key: string;
739
739
  /** The kind of channel the chat is on, such as whatsapp. */
@@ -760,7 +760,7 @@ export interface HeldReplyInput {
760
760
  readonly mode: "always" | "whenUnsure";
761
761
  readonly confidence: number | null;
762
762
  }
763
- /** A reply the agent redrafted, as `POST /api/ontology/agent/reviews/revision` reports it. */
763
+ /** A reply the agent redrafted, as `POST /api/ontology/agent/drafts/revision` reports it. */
764
764
  export interface RevisedReplyInput {
765
765
  /** The review the redraft replaces. */
766
766
  readonly review: string;
@@ -19,3 +19,9 @@ export interface OntologyService {
19
19
  * and `x-request-id`; failures answer with a JSON error and never a stack or SQL.
20
20
  */
21
21
  export declare function createOntologyService(ontology: Ontology, config: OntologyServiceConfig): OntologyService;
22
+ /**
23
+ * The request with a path that names a built-in entity by its earlier name, `/api/ontology/<earlier>/…`,
24
+ * under the current one, so that callers written for the earlier name reach the entity's routes;
25
+ * any other request as it is. Only the current names are listed in the catalog and the docs.
26
+ */
27
+ export declare function withCurrentEntityPath(request: Request): Request;
@@ -30,7 +30,7 @@ import { agentTasksLayer } from "./agent/tasks.js";
30
30
  import { makeMetricQueries } from "./metric-query.js";
31
31
  import { platformMetricQueries } from "./metric-query-platform.js";
32
32
  import { platformWarehouseQueries, WarehouseQueries } from "./warehouse-platform.js";
33
- import { ErrorResponsesLive, buildApi } from "./api.js";
33
+ import { BASE_PATH, ErrorResponsesLive, buildApi } from "./api.js";
34
34
  import { CurrentPrincipal, authenticationLayer, neonAuthSessionExchange, tokenVerifier, withPrincipal, } from "./authentication.js";
35
35
  import { currentCaller } from "./caller-context.js";
36
36
  import { OntologyServiceConfigError, } from "./config.js";
@@ -55,6 +55,7 @@ import { neonEmailCodes } from "./agent/guest-sign-up.js";
55
55
  import { vercelWorkflowEngine, workflowStarter, workflowsLayer } from "./workflows.js";
56
56
  import { deploymentWorkflowEngine } from "./workflow-deployment.js";
57
57
  import { OntologyBackend } from "./runtime-contract.js";
58
+ import { currentEntityPath } from "../earlier-entity-names.js";
58
59
  import { runtimeCredential, runtimeTokenVerifier, } from "./runtime-identity.js";
59
60
  /** The header every response carries: the hash of the manifest the service serves. */
60
61
  export const ONTOLOGY_HASH_HEADER = "x-ontology-hash";
@@ -518,7 +519,9 @@ export function createOntologyService(ontology, config) {
518
519
  const hash = ontology.manifest.hash;
519
520
  // Only names from the deployed plan enter diagnostics; arbitrary path segments may be private.
520
521
  function operationOf(request) {
521
- const path = new URL(request.url).pathname;
522
+ const requested = new URL(request.url).pathname;
523
+ // @legacy ontology.agent-review-entity-name
524
+ const path = currentEntityPath(requested, BASE_PATH) ?? requested;
522
525
  const parts = path.split("/");
523
526
  const entity = plan.entities.find((candidate) => candidate.name === parts[3]);
524
527
  if (parts[1] === "api" && parts[2] === "ontology" && entity !== undefined) {
@@ -555,7 +558,7 @@ export function createOntologyService(ontology, config) {
555
558
  throw new DeploymentAdmissionError("preview_authentication_unavailable");
556
559
  }
557
560
  }
558
- response = await web.handler(request, Context.make(RequestId, requestId));
561
+ response = await web.handler(withCurrentEntityPath(request), Context.make(RequestId, requestId));
559
562
  }
560
563
  catch (error) {
561
564
  if (error instanceof DeploymentAdmissionError) {
@@ -588,3 +591,18 @@ export function createOntologyService(ontology, config) {
588
591
  },
589
592
  };
590
593
  }
594
+ // @legacy ontology.agent-review-entity-name
595
+ /**
596
+ * The request with a path that names a built-in entity by its earlier name, `/api/ontology/<earlier>/…`,
597
+ * under the current one, so that callers written for the earlier name reach the entity's routes;
598
+ * any other request as it is. Only the current names are listed in the catalog and the docs.
599
+ */
600
+ export function withCurrentEntityPath(request) {
601
+ const url = new URL(request.url);
602
+ const current = currentEntityPath(url.pathname, BASE_PATH);
603
+ if (current === undefined) {
604
+ return request;
605
+ }
606
+ url.pathname = current;
607
+ return new Request(url, request);
608
+ }