@segmentstream/ontology 0.148.0 → 0.150.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 (40) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/README.md +24 -15
  3. package/dist/analyze.d.ts +11 -3
  4. package/dist/analyze.js +21 -4
  5. package/dist/diagnostics.d.ts +3 -3
  6. package/dist/diagnostics.js +1 -0
  7. package/dist/index.d.ts +1 -1
  8. package/dist/index.js +1 -1
  9. package/dist/manifest.d.ts +53 -5
  10. package/dist/manifest.js +34 -2
  11. package/dist/migrate/model.d.ts +14 -2
  12. package/dist/migrate/plan.js +1 -1
  13. package/dist/migrate/preview.js +4 -1
  14. package/dist/migrate/storage.d.ts +15 -3
  15. package/dist/migrate/storage.js +86 -3
  16. package/dist/runtime/agents.js +2 -0
  17. package/dist/runtime/chat-messages.d.ts +271 -0
  18. package/dist/runtime/chat-messages.js +576 -0
  19. package/dist/service/agent/archive-routes.d.ts +2 -0
  20. package/dist/service/agent/archive-routes.js +2 -1
  21. package/dist/service/agent/chat-archive.d.ts +12 -3
  22. package/dist/service/agent/chat-archive.js +5 -1
  23. package/dist/service/agent/chat-message-routes.d.ts +156 -0
  24. package/dist/service/agent/chat-message-routes.js +264 -0
  25. package/dist/service/agent/server.d.ts +5 -1
  26. package/dist/service/agent/server.js +15 -0
  27. package/dist/service/chat/local-reads.d.ts +71 -0
  28. package/dist/service/chat/local-reads.js +148 -0
  29. package/dist/service/chat/reads.js +7 -0
  30. package/dist/service/chat/routes.js +4 -1
  31. package/dist/service/chat/schemas.d.ts +5 -0
  32. package/dist/service/chat/schemas.js +5 -0
  33. package/dist/service/cron-secret.d.ts +6 -0
  34. package/dist/service/cron-secret.js +14 -0
  35. package/dist/service/mcp/server.js +4 -2
  36. package/dist/service/runtime-contract.d.ts +2 -0
  37. package/dist/service/schemas.d.ts +8 -2
  38. package/dist/service/service.js +4 -1
  39. package/dist/service/workflows.js +2 -9
  40. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,57 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.150.0
4
+
5
+ The chat store's runtime routes take what the agent's dispatch needs: `release`, a change that gives
6
+ up a claim on a message before it was dispatched, so the next delivery of the message takes it at
7
+ once; a skipped message can be claimed, since a later revision of it may address the agent; a
8
+ `meta` change can name the meta it replaces in `expected`, and applies only while the message still
9
+ holds it; a `content` change sets what a channel read of a message after recording it, in one write with
10
+ its routing state and only while the message holds the `meta` the channel read: its text with what
11
+ was transcribed of it, such as a voice message's transcript after its caption, and the files it
12
+ stored, by their attachments' ids, never as an edit, and under a new revision; an `edit` may
13
+ carry its files, which replace the message's, and its revision's `meta` under the `meta` it
14
+ replaces, so an edit that only replaced a file is an edit, and an edit and its routing state are
15
+ one write; `messages/read` with `senderId` reads what a sender wrote in every chat of a
16
+ channel, newest first; and with `pending`, `pendingBefore` lists only the sends requested by a
17
+ time, chosen before the limit, so newer sends never crowd out older ones due (`pendingBefore`
18
+ without `pending` is refused, `pending_required`). The agent SDK uses the chat store only with an
19
+ ontology service that answers `release`.
20
+
21
+ A deleted message keeps none of its content in the channel's private `meta` either: a deletion
22
+ clears `meta` with the text, parts, files and reactions, a send that takes its echo's deletion
23
+ loses its `meta` too, and a `meta` change no longer applies to a deleted message. Its disposition
24
+ stays, so a deleted message never starts another turn.
25
+
26
+ ## 0.149.0
27
+
28
+ The ontology keeps the chats' messages in the workspace's own database: the system table
29
+ `_chat_messages`, beside `agent_chat`, one row per message with its latest state. Deploying creates
30
+ it, also with an unchanged ontology, and a preview starts with it empty. The agent records into it
31
+ from the agent SDK release that uses it; until then nothing changes, and chats stay in the
32
+ platform's chat archive.
33
+
34
+ `chat_history`, `chat_search` and `POST /api/ontology/chat/history` read a chat from the
35
+ workspace's database once it holds the chat's messages, and from the platform's chat archive
36
+ before, with the same readers: a group's for members with `agent_chat:read` or in the group, a
37
+ private message for the people it was written to, and an inbox chat for staff within
38
+ `agent_chat:read`'s scope. The page keeps its shape; each message read from the workspace's
39
+ database also carries `id`, `direction`, `author`, `sender`, `parts`, `files`, `reply_to`,
40
+ `reactions`, `edited`, `deleted`, `delivery`, `disposition` and `reason`, and its `sequence` is its
41
+ revision. `chat_history` takes `after`, a revision, and answers the chat's messages changed since,
42
+ oldest change first, for a page that polls.
43
+
44
+ `defineOntology({ chat: { retentionDays } })` declares how many days the workspace keeps its chats'
45
+ messages: whole days from 1 to 3650, 365 by default, written into the manifest only when declared,
46
+ also without a chat channel. `check` reports `invalid-chat` for any other value. The service
47
+ deletes older messages from the workspace's database once a day; a sent message keeps only its
48
+ idempotency key and outcome, so a replay of the key never sends twice. The manifest is version 16,
49
+ which tells Cloud to schedule that purge as one of the project's cron jobs, with or without
50
+ workflows.
51
+
52
+ The agent's runtime records, changes and reads messages through new routes under
53
+ `/api/ontology/agent/chats/messages`, with the deployment's runtime token, as it reports chats.
54
+
3
55
  ## 0.148.0
4
56
 
5
57
  A connection request in an action or workflow step can send a stored file as its body: pass
package/README.md CHANGED
@@ -1394,18 +1394,22 @@ task header on any other route are a 403.
1394
1394
 
1395
1395
  Without either header the agent may call only the agent routes:
1396
1396
 
1397
- | Route | Caller | Does |
1398
- | ------------------------------------------------------------- | ------ | -------------------------------------------------------------------------------------------------------------------------------------- |
1399
- | `POST /api/ontology/agent/pairings` | agent | `{ provider, external_id, display? }` → `{ code, expires_at }` |
1400
- | `GET /api/ontology/agent/pairings/{code}` | member | `{ provider, display, expires_at }`, for the connect page |
1401
- | `POST /api/ontology/agent/pairings/{code}/approve` | member | Pairs the account with the member → `{ identity }` |
1402
- | `POST /api/ontology/agent/identities/resolve` | agent | Admission and turn limits; see below |
1403
- | `POST /api/ontology/agent/identities/notice` | agent | `{ provider, external_id, sha256, version? }` acknowledges notice delivery: 204 |
1404
- | `GET /api/ontology/agent/identities/{provider}/{external_id}` | agent | `{ user: { id, name }, roles, agent_tools }`; 404 unpaired, 403 revoked, inactive |
1405
- | `GET /api/ontology/agent/identities` | member | `{ identities }`: the member's live identities |
1406
- | `DELETE /api/ontology/agent/identities/{id}` | member | Revokes one of them: 204 |
1407
- | `POST /api/ontology/agent/chats/seen` | agent | `{ provider, externalId, title, memberId?, leftMemberId?, agentLeft?, migratedFrom? }` → `{ id, title, purpose, whenToUse, handled? }` |
1408
- | `POST /api/ontology/agent/chats/handoff` | agent | `{ provider, externalId, memberId, reason }` → `{ id, handoffAt, handled? }`; 404 for a chat staff do not take over |
1397
+ | Route | Caller | Does |
1398
+ | ------------------------------------------------------------- | ------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1399
+ | `POST /api/ontology/agent/pairings` | agent | `{ provider, external_id, display? }` → `{ code, expires_at }` |
1400
+ | `GET /api/ontology/agent/pairings/{code}` | member | `{ provider, display, expires_at }`, for the connect page |
1401
+ | `POST /api/ontology/agent/pairings/{code}/approve` | member | Pairs the account with the member → `{ identity }` |
1402
+ | `POST /api/ontology/agent/identities/resolve` | agent | Admission and turn limits; see below |
1403
+ | `POST /api/ontology/agent/identities/notice` | agent | `{ provider, external_id, sha256, version? }` acknowledges notice delivery: 204 |
1404
+ | `GET /api/ontology/agent/identities/{provider}/{external_id}` | agent | `{ user: { id, name }, roles, agent_tools }`; 404 unpaired, 403 revoked, inactive |
1405
+ | `GET /api/ontology/agent/identities` | member | `{ identities }`: the member's live identities |
1406
+ | `DELETE /api/ontology/agent/identities/{id}` | member | Revokes one of them: 204 |
1407
+ | `POST /api/ontology/agent/chats/seen` | agent | `{ provider, externalId, title, memberId?, leftMemberId?, agentLeft?, migratedFrom? }` → `{ id, title, purpose, whenToUse, handled? }` |
1408
+ | `POST /api/ontology/agent/chats/handoff` | agent | `{ provider, externalId, memberId, reason }` → `{ id, handoffAt, handled? }`; 404 for a chat staff do not take over |
1409
+ | `POST /api/ontology/agent/chats/messages` | agent | Records one message in `_chat_messages`, once by `(channel, chatId, messageId)` and by `operation` → `{ id, first }`; 409 `operation_conflict` for a replay with another `fingerprint` |
1410
+ | `POST /api/ontology/agent/chats/messages/change` | agent | One change to a message: `edit`, `delete`, `reaction`, `status`, `disposition`, `sent` (by `operation`) or `meta` → `{ applied }` |
1411
+ | `POST /api/ontology/agent/chats/messages/read` | agent | A chat's messages before a cursor, after a `revision`, by `messageId`, or the `pending` sends → `{ messages, nextCursor }` |
1412
+ | `GET /api/ontology/agent/chats/purge` | cron | With the project's cron secret, deletes the messages older than `chat.retentionDays` → `{ deleted, scrubbed, more }` |
1409
1413
 
1410
1414
  A pairing code is eight characters without look-alikes (no 0, O, 1, I or L), stored as its
1411
1415
  SHA-256, valid ten minutes and used once. Each instance allows a client address 60 new
@@ -1625,10 +1629,15 @@ history_recorded }`; private chats may have no URL. A receipt-write failure leav
1625
1629
  `history_recorded: false` without sending again. An older archive lacking the claim protocol
1626
1630
  cannot authorize delivery. Local provider proxies alone cannot replace the production archive.
1627
1631
 
1628
- `chat_history({ chat, before?, limit? })` and `chat_search` read the archive with independent
1632
+ `chat_history({ chat, before?, after?, limit? })` and `chat_search` read a chat with independent
1629
1633
  chat authorization: a member reads the group chats they are in (the chat's `members`,
1630
- like its attachments), `agent_chat:read` reads every group, and a private chat is read by its
1631
- participant. A posting service cannot read member chats. The canonical
1634
+ like its attachments), `agent_chat:read` reads every group, and a private message is read by the
1635
+ participants it names. A posting service cannot read member chats. They read the workspace's
1636
+ `_chat_messages` once it holds the chat, with each message's `direction`, `author`, `sender`,
1637
+ `parts`, `files`, `reply_to`, `reactions`, `edited`, `deleted`, `delivery`, `disposition` and
1638
+ `reason` beside the archive's fields, and the platform's chat archive before; `after`, a revision,
1639
+ reads the chat's changes since. `chat.retentionDays` (1–3650, 365 by default) sets how long the
1640
+ workspace keeps them. The canonical
1632
1641
  REST facade is `/api/ontology/chat/{list,history,search,actions/post_message}`; the post action
1633
1642
  uses the standard `{ input, options?: { validate_only? } }` envelope and action response.
1634
1643
  Validation checks eligibility and exact text without reserving or sending.
package/dist/analyze.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { ChatAttributionSettings, InboxOptions } from "./chat.js";
2
2
  import { type ChatKind } from "./chat-channel.js";
3
- import type { ChatManifestInput } from "./manifest.js";
3
+ import { type ChatManifestInput } from "./manifest.js";
4
4
  import { Schema } from "effect";
5
5
  import { type Action, type ActionHints } from "./action.js";
6
6
  import { type AnyConnectionHandle } from "./connection.js";
@@ -266,7 +266,10 @@ export interface ChatChannelConfig {
266
266
  readonly kind?: ChatKind;
267
267
  readonly connection?: AnyConnectionHandle;
268
268
  }
269
- /** `chat` of {@link OntologyConfig}: the agent's channels by name, and the post attribution. */
269
+ /**
270
+ * `chat` of {@link OntologyConfig}: the agent's channels by name, the post attribution, and how
271
+ * long the workspace keeps its chats' messages.
272
+ */
270
273
  export interface ChatConfig {
271
274
  readonly telegram?: {
272
275
  readonly connection: AnyConnectionHandle;
@@ -281,8 +284,13 @@ export interface ChatConfig {
281
284
  readonly connection: AnyConnectionHandle;
282
285
  };
283
286
  readonly attribution?: ChatAttributionSettings;
287
+ /**
288
+ * How many days the workspace keeps its chats' messages, from 1 to 3650; 365 when absent. Older
289
+ * messages are deleted from the workspace's database, and a send's row keeps only its key.
290
+ */
291
+ readonly retentionDays?: number;
284
292
  /** A channel of another name, such as `sales_whatsapp`, with its `kind`. */
285
- readonly [name: string]: ChatChannelConfig | ChatAttributionSettings | undefined;
293
+ readonly [name: string]: ChatChannelConfig | ChatAttributionSettings | number | undefined;
286
294
  }
287
295
  /**
288
296
  * Resolves an ontology definition and checks it. It never throws: every problem, including a thunk
package/dist/analyze.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { validateBrowserSignIn } from "./sign-in.js";
2
2
  import { CHAT_CHANNEL_KINDS, CHAT_CHANNEL_NAME, CHAT_KINDS, chatChannelKind, isChatKind, WORKSPACE_CHANNEL_KIND, workspaceChannelOf, } from "./chat-channel.js";
3
+ import { CHAT_RETENTION_DAYS } from "./manifest.js";
3
4
  import { checkWarehouseSource } from "./warehouse-backed.js";
4
5
  import { Result, Schema } from "effect";
5
6
  import { BLOB_UPLOAD_ANNOTATION } from "./blob.js";
@@ -43,10 +44,12 @@ const REVIEW_ONLY_CHAT_PROVIDERS = new Set(["email"]);
43
44
  * workspace channel, which always has a name of its own.
44
45
  */
45
46
  const RESERVED_CHAT_NAMES = new Set(["web", "task", WORKSPACE_CHANNEL_KIND]);
47
+ /** The keys of `chat` that are settings, not channels. */
48
+ const CHAT_SETTINGS = new Set(["attribution", "retentionDays"]);
46
49
  /** Whether `chat` declares a channel of `kind`: the one named after it, or another of the kind. */
47
50
  function declaresChatKind(chat, kind) {
48
51
  return (isPlainObject(chat) &&
49
- Object.entries(chat).some(([name, value]) => name !== "attribution" &&
52
+ Object.entries(chat).some(([name, value]) => !CHAT_SETTINGS.has(name) &&
50
53
  value !== undefined &&
51
54
  chatChannelKind(chat, name) === kind));
52
55
  }
@@ -104,7 +107,7 @@ export function analyze(config, options = {}) {
104
107
  };
105
108
  const inbox = inboxOptions(config.inbox, declaredRoles, guest !== undefined, isPlainObject(config.chat)
106
109
  ? Object.entries(config.chat)
107
- .filter(([name, channel]) => name !== "attribution" && channel !== undefined)
110
+ .filter(([name, channel]) => !CHAT_SETTINGS.has(name) && channel !== undefined)
108
111
  .map(([name]) => name)
109
112
  : [], report);
110
113
  const discovery = config.discovery;
@@ -171,7 +174,7 @@ export function analyze(config, options = {}) {
171
174
  let chat;
172
175
  if (config.chat !== undefined) {
173
176
  const entries = isPlainObject(config.chat)
174
- ? Object.entries(config.chat).filter(([name, value]) => name !== "attribution" && value !== undefined)
177
+ ? Object.entries(config.chat).filter(([name, value]) => !CHAT_SETTINGS.has(name) && value !== undefined)
175
178
  : [];
176
179
  const unknown = isPlainObject(config.chat)
177
180
  ? entries.find(([name]) => !CHAT_CHANNEL_NAME.test(name) || RESERVED_CHAT_NAMES.has(name))?.[0]
@@ -198,7 +201,7 @@ export function analyze(config, options = {}) {
198
201
  const unlisted = handles.find(([, handle]) => !(config.connections ?? []).includes(handle));
199
202
  const shared = handles.find(([, handle], index) => handles.findIndex(([, other]) => other === handle) !== index);
200
203
  if (unknown !== undefined) {
201
- report("invalid-connection", "chat", `chat accepts attribution and channels by the agent's names for them: ` +
204
+ report("invalid-connection", "chat", `chat accepts attribution, retentionDays and channels by the agent's names for them: ` +
202
205
  `${CHAT_PROVIDER_KEYS.join(", ")}, or another lower-case name with its kind; ` +
203
206
  `web and task are the agent's own, and ${WORKSPACE_CHANNEL_KIND} is a kind.`);
204
207
  }
@@ -271,6 +274,20 @@ export function analyze(config, options = {}) {
271
274
  report("invalid-connection", "chat.attribution", "Attribution requires a template containing {name} (at most 512 characters) " +
272
275
  "and a separator of at most 100 characters.");
273
276
  }
277
+ const retentionDays = isPlainObject(config.chat) ? config.chat.retentionDays : undefined;
278
+ if (retentionDays !== undefined) {
279
+ if (typeof retentionDays !== "number" ||
280
+ !Number.isInteger(retentionDays) ||
281
+ retentionDays < CHAT_RETENTION_DAYS.minimum ||
282
+ retentionDays > CHAT_RETENTION_DAYS.maximum) {
283
+ report("invalid-chat", "chat.retentionDays", `chat.retentionDays takes whole days from ${CHAT_RETENTION_DAYS.minimum} to ` +
284
+ `${CHAT_RETENTION_DAYS.maximum}.`);
285
+ }
286
+ else {
287
+ // Written only when declared, also without channels: the messages are kept whatever they are.
288
+ chat = { ...chat, retentionDays };
289
+ }
290
+ }
274
291
  checkEntityIdentities(resolved, report);
275
292
  checkMemberNames(resolved, report);
276
293
  const toolsets = resolveToolsets(original.toolsets, resolved, connections, report);
@@ -1,10 +1,10 @@
1
1
  import { Schema } from "effect";
2
- export declare const DIAGNOSTIC_CODES: readonly ["invalid-source", "missing-column", "invalid-column", "invalid-scope", "invalid-scope-path", "scope-reads-all", "scope-unused", "scope-member-overlap", "source-with-actions", "source-with-index", "invalid-metric", "unknown-metric", "circular-metric", "invalid-join", "missing-join", "invalid-entity", "invalid-property", "invalid-relationship", "invalid-actions", "invalid-action", "invalid-action-input", "invalid-role", "invalid-name", "reserved-name", "duplicate-name", "invalid-entity-id", "duplicate-entity-id", "missing-label", "missing-description", "invalid-title", "invalid-options", "invalid-default", "invalid-constraint", "unknown-relationship-target", "inverse-collision", "invalid-on-delete", "invalid-phrase", "invalid-index", "unknown-reference", "invalid-renamed-from", "earlier-name", "invalid-guide", "invalid-writes", "generated-update-empty", "managed-without-effect", "missing-permissions", "invalid-permission", "unknown-permission", "removed-allow", "unreachable-action", "wildcard-permission", "invalid-sign-in", "invalid-inbox", "invalid-connection", "invalid-feedback", "invalid-discovery", "invalid-email", "feedback-unanswerable", "feedback-unreportable", "agent-tools-implicit", "named-secret-deprecated", "unknown-connection", "unused-connection", "invalid-prepare", "invalid-tool-name", "invalid-toolset", "toolset-lock-mismatch", "invalid-alignment", "single-entity-model-metric", "invalid-workflow", "workflow_role_unknown", "workflow_role_is_member", "workflow_role_grants_nothing", "workflow_role_wildcard", "workflow_role_scoped", "workflow_cron_never_fires", "workflow_input_invalid", "workflow_cron_invalid", "workflow_run_missing", "invalid-trigger", "trigger_action_unknown", "trigger_function_async", "trigger_runs_invalid", "workflow_trigger_limit_exceeded", "workflow_webhook_duplicate", "workflow_webhook_input_invalid", "workflow_webhook_mixed_triggers", "workflow_webhook_signature_invalid", "workflow_webhook_verification_invalid", "workflow_webhook_headers_invalid", "workflow_webhook_limit_exceeded"];
2
+ export declare const DIAGNOSTIC_CODES: readonly ["invalid-source", "missing-column", "invalid-column", "invalid-scope", "invalid-scope-path", "scope-reads-all", "scope-unused", "scope-member-overlap", "source-with-actions", "source-with-index", "invalid-metric", "unknown-metric", "circular-metric", "invalid-join", "missing-join", "invalid-entity", "invalid-property", "invalid-relationship", "invalid-actions", "invalid-action", "invalid-action-input", "invalid-role", "invalid-name", "reserved-name", "duplicate-name", "invalid-entity-id", "duplicate-entity-id", "missing-label", "missing-description", "invalid-title", "invalid-options", "invalid-default", "invalid-constraint", "unknown-relationship-target", "inverse-collision", "invalid-on-delete", "invalid-phrase", "invalid-index", "unknown-reference", "invalid-renamed-from", "earlier-name", "invalid-guide", "invalid-writes", "generated-update-empty", "managed-without-effect", "missing-permissions", "invalid-permission", "unknown-permission", "removed-allow", "unreachable-action", "wildcard-permission", "invalid-sign-in", "invalid-inbox", "invalid-chat", "invalid-connection", "invalid-feedback", "invalid-discovery", "invalid-email", "feedback-unanswerable", "feedback-unreportable", "agent-tools-implicit", "named-secret-deprecated", "unknown-connection", "unused-connection", "invalid-prepare", "invalid-tool-name", "invalid-toolset", "toolset-lock-mismatch", "invalid-alignment", "single-entity-model-metric", "invalid-workflow", "workflow_role_unknown", "workflow_role_is_member", "workflow_role_grants_nothing", "workflow_role_wildcard", "workflow_role_scoped", "workflow_cron_never_fires", "workflow_input_invalid", "workflow_cron_invalid", "workflow_run_missing", "invalid-trigger", "trigger_action_unknown", "trigger_function_async", "trigger_runs_invalid", "workflow_trigger_limit_exceeded", "workflow_webhook_duplicate", "workflow_webhook_input_invalid", "workflow_webhook_mixed_triggers", "workflow_webhook_signature_invalid", "workflow_webhook_verification_invalid", "workflow_webhook_headers_invalid", "workflow_webhook_limit_exceeded"];
3
3
  export type DiagnosticCode = (typeof DIAGNOSTIC_CODES)[number];
4
4
  /** A problem `check` found in an ontology definition. */
5
5
  export declare const Diagnostic: Schema.Struct<{
6
6
  readonly severity: Schema.Literals<readonly ["error", "warning", "info"]>;
7
- readonly code: Schema.Literals<readonly ["invalid-source", "missing-column", "invalid-column", "invalid-scope", "invalid-scope-path", "scope-reads-all", "scope-unused", "scope-member-overlap", "source-with-actions", "source-with-index", "invalid-metric", "unknown-metric", "circular-metric", "invalid-join", "missing-join", "invalid-entity", "invalid-property", "invalid-relationship", "invalid-actions", "invalid-action", "invalid-action-input", "invalid-role", "invalid-name", "reserved-name", "duplicate-name", "invalid-entity-id", "duplicate-entity-id", "missing-label", "missing-description", "invalid-title", "invalid-options", "invalid-default", "invalid-constraint", "unknown-relationship-target", "inverse-collision", "invalid-on-delete", "invalid-phrase", "invalid-index", "unknown-reference", "invalid-renamed-from", "earlier-name", "invalid-guide", "invalid-writes", "generated-update-empty", "managed-without-effect", "missing-permissions", "invalid-permission", "unknown-permission", "removed-allow", "unreachable-action", "wildcard-permission", "invalid-sign-in", "invalid-inbox", "invalid-connection", "invalid-feedback", "invalid-discovery", "invalid-email", "feedback-unanswerable", "feedback-unreportable", "agent-tools-implicit", "named-secret-deprecated", "unknown-connection", "unused-connection", "invalid-prepare", "invalid-tool-name", "invalid-toolset", "toolset-lock-mismatch", "invalid-alignment", "single-entity-model-metric", "invalid-workflow", "workflow_role_unknown", "workflow_role_is_member", "workflow_role_grants_nothing", "workflow_role_wildcard", "workflow_role_scoped", "workflow_cron_never_fires", "workflow_input_invalid", "workflow_cron_invalid", "workflow_run_missing", "invalid-trigger", "trigger_action_unknown", "trigger_function_async", "trigger_runs_invalid", "workflow_trigger_limit_exceeded", "workflow_webhook_duplicate", "workflow_webhook_input_invalid", "workflow_webhook_mixed_triggers", "workflow_webhook_signature_invalid", "workflow_webhook_verification_invalid", "workflow_webhook_headers_invalid", "workflow_webhook_limit_exceeded"]>;
7
+ readonly code: Schema.Literals<readonly ["invalid-source", "missing-column", "invalid-column", "invalid-scope", "invalid-scope-path", "scope-reads-all", "scope-unused", "scope-member-overlap", "source-with-actions", "source-with-index", "invalid-metric", "unknown-metric", "circular-metric", "invalid-join", "missing-join", "invalid-entity", "invalid-property", "invalid-relationship", "invalid-actions", "invalid-action", "invalid-action-input", "invalid-role", "invalid-name", "reserved-name", "duplicate-name", "invalid-entity-id", "duplicate-entity-id", "missing-label", "missing-description", "invalid-title", "invalid-options", "invalid-default", "invalid-constraint", "unknown-relationship-target", "inverse-collision", "invalid-on-delete", "invalid-phrase", "invalid-index", "unknown-reference", "invalid-renamed-from", "earlier-name", "invalid-guide", "invalid-writes", "generated-update-empty", "managed-without-effect", "missing-permissions", "invalid-permission", "unknown-permission", "removed-allow", "unreachable-action", "wildcard-permission", "invalid-sign-in", "invalid-inbox", "invalid-chat", "invalid-connection", "invalid-feedback", "invalid-discovery", "invalid-email", "feedback-unanswerable", "feedback-unreportable", "agent-tools-implicit", "named-secret-deprecated", "unknown-connection", "unused-connection", "invalid-prepare", "invalid-tool-name", "invalid-toolset", "toolset-lock-mismatch", "invalid-alignment", "single-entity-model-metric", "invalid-workflow", "workflow_role_unknown", "workflow_role_is_member", "workflow_role_grants_nothing", "workflow_role_wildcard", "workflow_role_scoped", "workflow_cron_never_fires", "workflow_input_invalid", "workflow_cron_invalid", "workflow_run_missing", "invalid-trigger", "trigger_action_unknown", "trigger_function_async", "trigger_runs_invalid", "workflow_trigger_limit_exceeded", "workflow_webhook_duplicate", "workflow_webhook_input_invalid", "workflow_webhook_mixed_triggers", "workflow_webhook_signature_invalid", "workflow_webhook_verification_invalid", "workflow_webhook_headers_invalid", "workflow_webhook_limit_exceeded"]>;
8
8
  /** Where the problem is, for example `lead.properties.status.options[1]`. */
9
9
  readonly path: Schema.String;
10
10
  readonly message: Schema.String;
@@ -14,7 +14,7 @@ declare const InvalidOntology_base: Schema.Class<InvalidOntology, Schema.TaggedS
14
14
  readonly message: Schema.String;
15
15
  readonly diagnostics: Schema.$Array<Schema.Struct<{
16
16
  readonly severity: Schema.Literals<readonly ["error", "warning", "info"]>;
17
- readonly code: Schema.Literals<readonly ["invalid-source", "missing-column", "invalid-column", "invalid-scope", "invalid-scope-path", "scope-reads-all", "scope-unused", "scope-member-overlap", "source-with-actions", "source-with-index", "invalid-metric", "unknown-metric", "circular-metric", "invalid-join", "missing-join", "invalid-entity", "invalid-property", "invalid-relationship", "invalid-actions", "invalid-action", "invalid-action-input", "invalid-role", "invalid-name", "reserved-name", "duplicate-name", "invalid-entity-id", "duplicate-entity-id", "missing-label", "missing-description", "invalid-title", "invalid-options", "invalid-default", "invalid-constraint", "unknown-relationship-target", "inverse-collision", "invalid-on-delete", "invalid-phrase", "invalid-index", "unknown-reference", "invalid-renamed-from", "earlier-name", "invalid-guide", "invalid-writes", "generated-update-empty", "managed-without-effect", "missing-permissions", "invalid-permission", "unknown-permission", "removed-allow", "unreachable-action", "wildcard-permission", "invalid-sign-in", "invalid-inbox", "invalid-connection", "invalid-feedback", "invalid-discovery", "invalid-email", "feedback-unanswerable", "feedback-unreportable", "agent-tools-implicit", "named-secret-deprecated", "unknown-connection", "unused-connection", "invalid-prepare", "invalid-tool-name", "invalid-toolset", "toolset-lock-mismatch", "invalid-alignment", "single-entity-model-metric", "invalid-workflow", "workflow_role_unknown", "workflow_role_is_member", "workflow_role_grants_nothing", "workflow_role_wildcard", "workflow_role_scoped", "workflow_cron_never_fires", "workflow_input_invalid", "workflow_cron_invalid", "workflow_run_missing", "invalid-trigger", "trigger_action_unknown", "trigger_function_async", "trigger_runs_invalid", "workflow_trigger_limit_exceeded", "workflow_webhook_duplicate", "workflow_webhook_input_invalid", "workflow_webhook_mixed_triggers", "workflow_webhook_signature_invalid", "workflow_webhook_verification_invalid", "workflow_webhook_headers_invalid", "workflow_webhook_limit_exceeded"]>;
17
+ readonly code: Schema.Literals<readonly ["invalid-source", "missing-column", "invalid-column", "invalid-scope", "invalid-scope-path", "scope-reads-all", "scope-unused", "scope-member-overlap", "source-with-actions", "source-with-index", "invalid-metric", "unknown-metric", "circular-metric", "invalid-join", "missing-join", "invalid-entity", "invalid-property", "invalid-relationship", "invalid-actions", "invalid-action", "invalid-action-input", "invalid-role", "invalid-name", "reserved-name", "duplicate-name", "invalid-entity-id", "duplicate-entity-id", "missing-label", "missing-description", "invalid-title", "invalid-options", "invalid-default", "invalid-constraint", "unknown-relationship-target", "inverse-collision", "invalid-on-delete", "invalid-phrase", "invalid-index", "unknown-reference", "invalid-renamed-from", "earlier-name", "invalid-guide", "invalid-writes", "generated-update-empty", "managed-without-effect", "missing-permissions", "invalid-permission", "unknown-permission", "removed-allow", "unreachable-action", "wildcard-permission", "invalid-sign-in", "invalid-inbox", "invalid-chat", "invalid-connection", "invalid-feedback", "invalid-discovery", "invalid-email", "feedback-unanswerable", "feedback-unreportable", "agent-tools-implicit", "named-secret-deprecated", "unknown-connection", "unused-connection", "invalid-prepare", "invalid-tool-name", "invalid-toolset", "toolset-lock-mismatch", "invalid-alignment", "single-entity-model-metric", "invalid-workflow", "workflow_role_unknown", "workflow_role_is_member", "workflow_role_grants_nothing", "workflow_role_wildcard", "workflow_role_scoped", "workflow_cron_never_fires", "workflow_input_invalid", "workflow_cron_invalid", "workflow_run_missing", "invalid-trigger", "trigger_action_unknown", "trigger_function_async", "trigger_runs_invalid", "workflow_trigger_limit_exceeded", "workflow_webhook_duplicate", "workflow_webhook_input_invalid", "workflow_webhook_mixed_triggers", "workflow_webhook_signature_invalid", "workflow_webhook_verification_invalid", "workflow_webhook_headers_invalid", "workflow_webhook_limit_exceeded"]>;
18
18
  /** Where the problem is, for example `lead.properties.status.options[1]`. */
19
19
  readonly path: Schema.String;
20
20
  readonly message: Schema.String;
@@ -53,6 +53,7 @@ export const DIAGNOSTIC_CODES = [
53
53
  "wildcard-permission",
54
54
  "invalid-sign-in",
55
55
  "invalid-inbox",
56
+ "invalid-chat",
56
57
  "invalid-connection",
57
58
  "invalid-feedback",
58
59
  "invalid-discovery",
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, } 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, 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, } 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, 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";
@@ -100,8 +100,13 @@ import { type ResolvedGuest, type ResolvedSignInOptions, type SignInPolicy } fro
100
100
  * older publication check refuses the scheme. A signature may carry `generated: true` instead of
101
101
  * `secret`: the platform derives the webhook's secret. Older readers find no secret name; an older
102
102
  * publication check refuses it.
103
+ * Version 16 changes no other field: it marks an SDK whose service keeps the chats' messages in
104
+ * the workspace's own database and purges them at `/api/ontology/agent/chats/purge`, so
105
+ * publication adds a daily cron for that route. Within version 16, `chat` may carry
106
+ * `retention_days`, written only when declared, and then also without a channel: how many days
107
+ * the workspace keeps its chats' messages. Older readers ignore it and keep them 365 days.
103
108
  */
104
- export declare const MANIFEST_VERSION = 15;
109
+ export declare const MANIFEST_VERSION = 16;
105
110
  /** The phrase used for a direction the author did not phrase. */
106
111
  export declare const DEFAULT_PHRASE = "has";
107
112
  export declare const SelectOptionManifest: Schema.Struct<{
@@ -1291,7 +1296,7 @@ export declare const OntologyManifestWire: Schema.encodeKeys<Schema.Struct<{
1291
1296
  * with their kinds. `email`, within version 15, is the mailbox reviewed replies to mail leave
1292
1297
  * from; no chat post goes to it, nor to another channel of its kind.
1293
1298
  */
1294
- readonly chat: Schema.optionalKey<Schema.Struct<{
1299
+ readonly chat: Schema.optionalKey<Schema.encodeKeys<Schema.Struct<{
1295
1300
  readonly telegram: Schema.optionalKey<Schema.Struct<{
1296
1301
  readonly connection: Schema.String;
1297
1302
  }>>;
@@ -1312,6 +1317,10 @@ export declare const OntologyManifestWire: Schema.encodeKeys<Schema.Struct<{
1312
1317
  readonly template: Schema.optionalKey<Schema.String>;
1313
1318
  readonly separator: Schema.optionalKey<Schema.String>;
1314
1319
  }>>;
1320
+ /** How many days the workspace keeps its chats' messages; absent keeps them 365. */
1321
+ readonly retentionDays: Schema.optionalKey<Schema.Int>;
1322
+ }>, {
1323
+ readonly retentionDays: "retention_days";
1315
1324
  }>>;
1316
1325
  /**
1317
1326
  * Whose private chats join the inbox, within version 15: the wire names of their roles, the
@@ -1631,6 +1640,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
1631
1640
  readonly template?: string | undefined;
1632
1641
  readonly separator?: string | undefined;
1633
1642
  } | undefined;
1643
+ readonly retentionDays?: number | undefined;
1634
1644
  } | undefined;
1635
1645
  readonly workflows?: readonly {
1636
1646
  readonly description: string;
@@ -1986,6 +1996,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
1986
1996
  readonly template?: string | undefined;
1987
1997
  readonly separator?: string | undefined;
1988
1998
  } | undefined;
1999
+ readonly retentionDays?: number | undefined;
1989
2000
  } | undefined;
1990
2001
  readonly workflows?: readonly {
1991
2002
  readonly description: string;
@@ -2341,6 +2352,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
2341
2352
  readonly template?: string | undefined;
2342
2353
  readonly separator?: string | undefined;
2343
2354
  } | undefined;
2355
+ readonly retention_days?: number | undefined;
2344
2356
  } | undefined;
2345
2357
  readonly workflows?: readonly {
2346
2358
  readonly description: string;
@@ -2696,6 +2708,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
2696
2708
  readonly template?: string | undefined;
2697
2709
  readonly separator?: string | undefined;
2698
2710
  } | undefined;
2711
+ readonly retention_days?: number | undefined;
2699
2712
  } | undefined;
2700
2713
  readonly workflows?: readonly {
2701
2714
  readonly description: string;
@@ -3204,7 +3217,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
3204
3217
  * with their kinds. `email`, within version 15, is the mailbox reviewed replies to mail leave
3205
3218
  * from; no chat post goes to it, nor to another channel of its kind.
3206
3219
  */
3207
- readonly chat: Schema.optionalKey<Schema.Struct<{
3220
+ readonly chat: Schema.optionalKey<Schema.encodeKeys<Schema.Struct<{
3208
3221
  readonly telegram: Schema.optionalKey<Schema.Struct<{
3209
3222
  readonly connection: Schema.String;
3210
3223
  }>>;
@@ -3225,6 +3238,10 @@ export declare const OntologyManifest: Schema.declareConstructor<{
3225
3238
  readonly template: Schema.optionalKey<Schema.String>;
3226
3239
  readonly separator: Schema.optionalKey<Schema.String>;
3227
3240
  }>>;
3241
+ /** How many days the workspace keeps its chats' messages; absent keeps them 365. */
3242
+ readonly retentionDays: Schema.optionalKey<Schema.Int>;
3243
+ }>, {
3244
+ readonly retentionDays: "retention_days";
3228
3245
  }>>;
3229
3246
  /**
3230
3247
  * Whose private chats join the inbox, within version 15: the wire names of their roles, the
@@ -3683,7 +3700,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
3683
3700
  * with their kinds. `email`, within version 15, is the mailbox reviewed replies to mail leave
3684
3701
  * from; no chat post goes to it, nor to another channel of its kind.
3685
3702
  */
3686
- readonly chat: Schema.optionalKey<Schema.Struct<{
3703
+ readonly chat: Schema.optionalKey<Schema.encodeKeys<Schema.Struct<{
3687
3704
  readonly telegram: Schema.optionalKey<Schema.Struct<{
3688
3705
  readonly connection: Schema.String;
3689
3706
  }>>;
@@ -3704,6 +3721,10 @@ export declare const OntologyManifest: Schema.declareConstructor<{
3704
3721
  readonly template: Schema.optionalKey<Schema.String>;
3705
3722
  readonly separator: Schema.optionalKey<Schema.String>;
3706
3723
  }>>;
3724
+ /** How many days the workspace keeps its chats' messages; absent keeps them 365. */
3725
+ readonly retentionDays: Schema.optionalKey<Schema.Int>;
3726
+ }>, {
3727
+ readonly retentionDays: "retention_days";
3707
3728
  }>>;
3708
3729
  /**
3709
3730
  * Whose private chats join the inbox, within version 15: the wire names of their roles, the
@@ -4015,6 +4036,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
4015
4036
  readonly template?: string | undefined;
4016
4037
  readonly separator?: string | undefined;
4017
4038
  } | undefined;
4039
+ readonly retentionDays?: number | undefined;
4018
4040
  } | undefined;
4019
4041
  readonly workflows?: readonly {
4020
4042
  readonly description: string;
@@ -4370,6 +4392,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
4370
4392
  readonly template?: string | undefined;
4371
4393
  readonly separator?: string | undefined;
4372
4394
  } | undefined;
4395
+ readonly retentionDays?: number | undefined;
4373
4396
  } | undefined;
4374
4397
  readonly workflows?: readonly {
4375
4398
  readonly description: string;
@@ -4731,6 +4754,7 @@ export declare const decodeManifestDocument: (value: unknown) => Effect.Effect<{
4731
4754
  readonly template?: string | undefined;
4732
4755
  readonly separator?: string | undefined;
4733
4756
  } | undefined;
4757
+ readonly retentionDays?: number | undefined;
4734
4758
  } | undefined;
4735
4759
  readonly workflows?: readonly {
4736
4760
  readonly description: string;
@@ -5086,6 +5110,7 @@ export declare const decodeManifestDocument: (value: unknown) => Effect.Effect<{
5086
5110
  readonly template?: string | undefined;
5087
5111
  readonly separator?: string | undefined;
5088
5112
  } | undefined;
5113
+ readonly retentionDays?: number | undefined;
5089
5114
  } | undefined;
5090
5115
  readonly workflows?: readonly {
5091
5116
  readonly description: string;
@@ -5315,6 +5340,25 @@ export declare function signInPolicyOf(manifest: Pick<OntologyManifest, "signIn"
5315
5340
  * the channel is closed to sign-up: not a channel this reader knows, or no well-formed entry.
5316
5341
  */
5317
5342
  export declare function signUpRolesOf(manifest: Pick<OntologyManifest, "signIn">, channel: string): ReadonlyArray<string> | undefined;
5343
+ /**
5344
+ * `chat.retentionDays` of `defineOntology`: how many days the workspace keeps its chats' messages,
5345
+ * a whole number in this range; 365 when the ontology declares none.
5346
+ */
5347
+ export declare const CHAT_RETENTION_DAYS: {
5348
+ readonly default: 365;
5349
+ readonly minimum: 1;
5350
+ readonly maximum: 3650;
5351
+ };
5352
+ /**
5353
+ * The days the ontology declares it keeps its chats' messages, as {@link chatRetentionDaysOf}
5354
+ * reads them; `undefined` when it declares none.
5355
+ */
5356
+ export declare function declaredChatRetentionDaysOf(manifest: Pick<OntologyManifest, "chat">): number | undefined;
5357
+ /**
5358
+ * How many days the workspace keeps its chats' messages: `chat.retentionDays` where it is a whole
5359
+ * number in range, else the default.
5360
+ */
5361
+ export declare function chatRetentionDaysOf(manifest: Pick<OntologyManifest, "chat">): number;
5318
5362
  /** The wire names of the roles whose people's private chats join the inbox; empty without one. */
5319
5363
  export declare function inboxRolesOf(manifest: Pick<OntologyManifest, "inbox">): ReadonlySet<string>;
5320
5364
  /** The channels whose private chats staff may take over from the agent; empty without any. */
@@ -5355,7 +5399,10 @@ export declare function manifestHash(manifest: Readonly<Record<string, unknown>>
5355
5399
  * aggregates, top-level or inside arithmetic: `check` lets them name one property at most.
5356
5400
  */
5357
5401
  export declare function metricsManifest(resolved: ResolvedEntity): ReadonlyArray<MetricManifest>;
5358
- /** `chat` as the manifest writes it: the channel of each kind, the other channels, attribution. */
5402
+ /**
5403
+ * `chat` as the manifest writes it: the channel of each kind, the other channels, attribution, and
5404
+ * how long the chats' messages are kept.
5405
+ */
5359
5406
  export interface ChatManifestInput {
5360
5407
  readonly telegram?: {
5361
5408
  readonly connection: string;
@@ -5374,6 +5421,7 @@ export interface ChatManifestInput {
5374
5421
  readonly connection?: string;
5375
5422
  }>>;
5376
5423
  readonly attribution?: ChatAttributionSettings;
5424
+ readonly retentionDays?: number;
5377
5425
  }
5378
5426
  /** Builds the manifest of a resolved ontology that passed `check`. */
5379
5427
  export declare function buildManifest(input: {
package/dist/manifest.js CHANGED
@@ -101,8 +101,13 @@ import { CHANNEL_PROVIDERS, DEFAULT_SIGN_IN_POLICY, isGuestBotCheckScheme, isGue
101
101
  * older publication check refuses the scheme. A signature may carry `generated: true` instead of
102
102
  * `secret`: the platform derives the webhook's secret. Older readers find no secret name; an older
103
103
  * publication check refuses it.
104
+ * Version 16 changes no other field: it marks an SDK whose service keeps the chats' messages in
105
+ * the workspace's own database and purges them at `/api/ontology/agent/chats/purge`, so
106
+ * publication adds a daily cron for that route. Within version 16, `chat` may carry
107
+ * `retention_days`, written only when declared, and then also without a channel: how many days
108
+ * the workspace keeps its chats' messages. Older readers ignore it and keep them 365 days.
104
109
  */
105
- export const MANIFEST_VERSION = 15;
110
+ export const MANIFEST_VERSION = 16;
106
111
  /** The first version whose documents use snake_case names on the wire. */
107
112
  const WIRE_MANIFEST_VERSION = 4;
108
113
  /** The first version whose documents name metrics as this SDK does; earlier ones keep theirs. */
@@ -611,7 +616,9 @@ const OntologyManifestModel = Schema.Struct({
611
616
  template: Schema.optionalKey(Schema.String),
612
617
  separator: Schema.optionalKey(Schema.String),
613
618
  })),
614
- })),
619
+ /** How many days the workspace keeps its chats' messages; absent keeps them 365. */
620
+ retentionDays: Schema.optionalKey(Schema.Int),
621
+ }).pipe(Schema.encodeKeys({ retentionDays: "retention_days" }))),
615
622
  /**
616
623
  * Whose private chats join the inbox, within version 15: the wire names of their roles, the
617
624
  * channels whose chats staff may take over from the agent, and `attribution: "none"` when a
@@ -719,6 +726,31 @@ export function signUpRolesOf(manifest, channel) {
719
726
  ? roles
720
727
  : undefined;
721
728
  }
729
+ /**
730
+ * `chat.retentionDays` of `defineOntology`: how many days the workspace keeps its chats' messages,
731
+ * a whole number in this range; 365 when the ontology declares none.
732
+ */
733
+ export const CHAT_RETENTION_DAYS = { default: 365, minimum: 1, maximum: 3650 };
734
+ /**
735
+ * The days the ontology declares it keeps its chats' messages, as {@link chatRetentionDaysOf}
736
+ * reads them; `undefined` when it declares none.
737
+ */
738
+ export function declaredChatRetentionDaysOf(manifest) {
739
+ return manifest.chat?.retentionDays === undefined ? undefined : chatRetentionDaysOf(manifest);
740
+ }
741
+ /**
742
+ * How many days the workspace keeps its chats' messages: `chat.retentionDays` where it is a whole
743
+ * number in range, else the default.
744
+ */
745
+ export function chatRetentionDaysOf(manifest) {
746
+ const days = manifest.chat?.retentionDays;
747
+ return typeof days === "number" &&
748
+ Number.isInteger(days) &&
749
+ days >= CHAT_RETENTION_DAYS.minimum &&
750
+ days <= CHAT_RETENTION_DAYS.maximum
751
+ ? days
752
+ : CHAT_RETENTION_DAYS.default;
753
+ }
722
754
  /** The wire names of the roles whose people's private chats join the inbox; empty without one. */
723
755
  export function inboxRolesOf(manifest) {
724
756
  return new Set(manifest.inbox?.roles ?? []);