@segmentstream/ontology 0.188.0 → 0.189.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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.189.0
4
+
5
+ A staff read of a chat may ask for what the agent kept in it for staff.
6
+ `POST /api/ontology/chat/history` and the MCP tool `chat_history` take `internal: true`, which also
7
+ returns the chat's internal messages from the workspace's chat store, never sent: the agent's
8
+ `note` for staff on a turn's `reply` and the questions it could not answer
9
+ (`segmentstream__unanswered`), as events of kind `internal` with their `sessionId` and `turnId`.
10
+ Only a member or workflow whose `agent_chat:read`, within its scope, holds the private chat it
11
+ reads by its `agent_chat` id receives them. Every other read, the chat's own person's, a group's
12
+ and a search's among them, leaves them out whether it asks or not, and a read that does not ask
13
+ answers as before.
14
+
3
15
  ## 0.188.0
4
16
 
5
17
  List, search and read deployed workspace code with the current member’s explicit
package/README.md CHANGED
@@ -1642,14 +1642,17 @@ history_recorded }`; private chats may have no URL. A receipt-write failure leav
1642
1642
  `history_recorded: false` without sending again. An older archive lacking the claim protocol
1643
1643
  cannot authorize delivery. Local provider proxies alone cannot replace the production archive.
1644
1644
 
1645
- `chat_history({ chat, before?, after?, limit? })` and `chat_search` read a chat with independent
1645
+ `chat_history({ chat, before?, after?, limit?, internal? })` and `chat_search` read a chat with independent
1646
1646
  chat authorization: a member reads the group chats they are in (the chat's `members`,
1647
1647
  like its attachments), `agent_chat:read` reads every group, and a private message is read by the
1648
1648
  participants it names. A posting service cannot read member chats. They read the workspace's
1649
1649
  `_chat_messages` once it holds the chat, with each message's `direction`, `author`, `sender`,
1650
1650
  `parts`, `files`, `reply_to`, `reactions`, `edited`, `deleted`, `delivery`, `disposition` and
1651
1651
  `reason` beside the archive's fields, and the platform's chat archive before; `after`, a revision,
1652
- reads the chat's changes since. `chat.retentionDays` (1–3650, 365 by default) sets how long the
1652
+ reads the chat's changes since. `internal: true` also returns the agent's internal messages, never
1653
+ sent (its notes for staff and the questions it could not answer), to a member or workflow whose
1654
+ `agent_chat:read` holds the private chat it reads by its `agent_chat` id, and to no other reader.
1655
+ `chat.retentionDays` (1–3650, 365 by default) sets how long the
1653
1656
  workspace keeps them. The canonical
1654
1657
  REST facade is `/api/ontology/chat/{list,history,search}`, and `send` is
1655
1658
  `POST /api/ontology/agent_chat/actions/send`, with the standard
@@ -261,8 +261,9 @@ export interface ChatMessageSearch {
261
261
  * `participantId`, row by row. A search of several chats names, by `<channel>:<chat id>`, the
262
262
  * groups the reader is in (`groupChats`), read as `groups` reads every group, and the chats the
263
263
  * ontology checked (`chats`), each read as `chat` reads the one searched. Every rule reads only
264
- * what reached the provider: never an internal row, a send still unsent, or one that failed
265
- * before the provider took it.
264
+ * what reached the provider: never a send still unsent, or one that failed before the provider
265
+ * took it, and never an internal row, unless a staff read of the one chat `chat` admits asks for
266
+ * them (`internal`).
266
267
  */
267
268
  export interface ChatMessageReader {
268
269
  readonly participantId: string | null;
@@ -270,6 +271,11 @@ export interface ChatMessageReader {
270
271
  readonly chat: boolean;
271
272
  readonly groupChats?: ReadonlyArray<string>;
272
273
  readonly chats?: ReadonlyArray<string>;
274
+ /**
275
+ * With `chat`, the chat's internal rows too, never sent: the agent's notes for staff and the
276
+ * questions it could not answer. Without `chat`, nothing.
277
+ */
278
+ readonly internal?: boolean;
273
279
  }
274
280
  export interface ChatMessagePage {
275
281
  readonly messages: ReadonlyArray<ChatMessage>;
@@ -669,14 +669,16 @@ export function sqlChatMessageStore(sql) {
669
669
  return Effect.succeed({ messages: [], nextCursor: null });
670
670
  }
671
671
  conditions.push(`(${rules.join(" OR ")})`);
672
- // Every rule reads what reached the provider: never an internal row, a send still unsent, nor
673
- // one that failed before the provider took it; a send becomes readable under the revision its
674
- // receipt takes. One the provider took and later failed stays, `failed`, and an echo a send
675
- // took over stays a change, so a reader polling after a revision sees the same chat as one
676
- // reading it whole.
672
+ // Every rule reads what reached the provider: never a send still unsent, nor one that failed
673
+ // before the provider took it; a send becomes readable under the revision its receipt takes.
674
+ // One the provider took and later failed stays, `failed`, and an echo a send took over stays a
675
+ // change, so a reader polling after a revision sees the same chat as one reading it whole. An
676
+ // internal row is no rule's, unless a staff read of the one chat it checked asks for it.
677
677
  conditions.push(`("direction" = 'inbound' OR "replaced_by" IS NOT NULL OR ("direction" = 'outbound' AND ` +
678
678
  `("status" IS NULL OR "status" IN ('sent', 'delivered', 'read') OR ` +
679
- `("status" = 'failed' AND "message_id" IS NOT NULL))))`);
679
+ `("status" = 'failed' AND "message_id" IS NOT NULL)))` +
680
+ (reader.chat && reader.internal === true ? ` OR "direction" = 'internal'` : "") +
681
+ `)`);
680
682
  return page(conditions, params, input);
681
683
  };
682
684
  const holds = (chat) => rows(chat === undefined
@@ -45,6 +45,12 @@ export type ChatArchiveTransport = (input: {
45
45
  * first: a read of the store alone (`withChatStore`).
46
46
  */
47
47
  readonly after?: string;
48
+ /**
49
+ * A staff read of one of `chats` asks for its internal messages too, never sent (the agent's
50
+ * notes for staff and the questions it could not answer), which only the workspace's chat store
51
+ * keeps. Any other read leaves them out.
52
+ */
53
+ readonly internal?: boolean;
48
54
  }) => Effect.Effect<ChatPage, ChatArchiveUnavailable | PermissionDenied | ActionRejected>;
49
55
  /**
50
56
  * The authenticated ontology service forwards its resolved member, never a caller-supplied ID.
@@ -65,8 +65,9 @@ export declare function chatMessageEvent(message: ChatMessage): {
65
65
  /**
66
66
  * Reads a chat from the workspace's chat store, `_chat_messages`, when the store holds its
67
67
  * messages, and a search of several chats once the store holds any message, the evidence that the
68
- * agent records there; each as the reader the chat archive's rule admits, row by row. Reads after
69
- * a `revision`, or before a cursor of the store, are the store's alone. Any other read goes to
70
- * `transport`, within the retention the ontology declares, `retentionDays`.
68
+ * agent records there; each as the reader the chat archive's rule admits, row by row, with the
69
+ * chat's internal messages only for a read of a chat the ontology checked that asks for them
70
+ * (`internal`). Reads after a `revision`, or before a cursor of the store, are the store's alone.
71
+ * Any other read goes to `transport`, within the retention the ontology declares, `retentionDays`.
71
72
  */
72
73
  export declare function withChatStore(transport: ChatArchiveTransport, backend: OntologyBackend["Service"], retentionDays: number | undefined): ChatArchiveTransport;
@@ -91,9 +91,10 @@ function withinRetention(input, retentionDays, now) {
91
91
  /**
92
92
  * Reads a chat from the workspace's chat store, `_chat_messages`, when the store holds its
93
93
  * messages, and a search of several chats once the store holds any message, the evidence that the
94
- * agent records there; each as the reader the chat archive's rule admits, row by row. Reads after
95
- * a `revision`, or before a cursor of the store, are the store's alone. Any other read goes to
96
- * `transport`, within the retention the ontology declares, `retentionDays`.
94
+ * agent records there; each as the reader the chat archive's rule admits, row by row, with the
95
+ * chat's internal messages only for a read of a chat the ontology checked that asks for them
96
+ * (`internal`). Reads after a `revision`, or before a cursor of the store, are the store's alone.
97
+ * Any other read goes to `transport`, within the retention the ontology declares, `retentionDays`.
97
98
  */
98
99
  export function withChatStore(transport, backend, retentionDays) {
99
100
  return (input) => Effect.gen(function* () {
@@ -129,13 +130,17 @@ export function withChatStore(transport, backend, retentionDays) {
129
130
  return yield* new ActionRejected({ message: "invalid_chat_search" });
130
131
  }
131
132
  // One chat's reader is decided for the chat; several chats' row by row, by each row's chat.
133
+ // Only a read of one chat the ontology checked may ask for its internal messages too.
134
+ const checked = key !== undefined && (chats ?? []).includes(key);
135
+ const internal = checked && input.internal === true ? { internal: true } : {};
132
136
  const reader = key !== undefined
133
137
  ? service
134
- ? { participantId: null, groups: false, chat: (chats ?? []).includes(key) }
138
+ ? { participantId: null, groups: false, chat: checked, ...internal }
135
139
  : {
136
140
  participantId: principal.id,
137
141
  groups: isAllowed("agent_chat:read", principal) || (memberGroups ?? []).includes(key),
138
- chat: (chats ?? []).includes(key),
142
+ chat: checked,
143
+ ...internal,
139
144
  }
140
145
  : service
141
146
  ? { participantId: null, groups: false, chat: false, chats: chats ?? [] }
@@ -95,9 +95,9 @@ export function chatReads(backend, options) {
95
95
  return yield* new ActionRejected({ message: "The chat archive is not configured." });
96
96
  }
97
97
  const key = `${registered.provider}:${registered.externalId}`;
98
- // Staff read the chat's messages whoever wrote them; its person reads the messages they
99
- // took part in, as in any private chat, so an account paired with someone else since
100
- // shows the earlier person nothing newer.
98
+ // Staff read the chat's messages whoever wrote them, and on request its internal ones;
99
+ // its person reads the messages they took part in, as in any private chat, so an account
100
+ // paired with someone else since shows the earlier person nothing newer.
101
101
  return yield* chatHistory({
102
102
  principal,
103
103
  identityToken,
@@ -108,7 +108,9 @@ export function chatReads(backend, options) {
108
108
  ...(input.limit === undefined ? {} : { limit: input.limit }),
109
109
  },
110
110
  memberGroups: [],
111
- ...(registered.staff ? { chats: [key] } : {}),
111
+ ...(registered.staff
112
+ ? { chats: [key], ...(input.internal === true ? { internal: true } : {}) }
113
+ : {}),
112
114
  ...after,
113
115
  });
114
116
  }
@@ -73,6 +73,11 @@ export declare const ChatHistory: Schema.Struct<{
73
73
  */
74
74
  readonly after: Schema.optionalKey<Schema.String>;
75
75
  readonly limit: Schema.optionalKey<Schema.Int>;
76
+ /**
77
+ * A staff read's request for more than reached the provider: the chat's internal messages too,
78
+ * each never sent. A read that may not have them reads the chat as without it.
79
+ */
80
+ readonly internal: Schema.optionalKey<Schema.Boolean>;
76
81
  }>;
77
82
  export declare const ChatDestination: Schema.Struct<{
78
83
  readonly id: Schema.String;
@@ -25,6 +25,16 @@ export const ChatHistory = Schema.Struct({
25
25
  */
26
26
  after: Schema.optionalKey(Schema.String.check(Schema.isPattern(/^\d{1,18}$/))),
27
27
  limit: Schema.optionalKey(Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 200 }))),
28
+ /**
29
+ * A staff read's request for more than reached the provider: the chat's internal messages too,
30
+ * each never sent. A read that may not have them reads the chat as without it.
31
+ */
32
+ internal: Schema.optionalKey(Schema.Boolean.annotate({
33
+ description: "Also return the chat's internal messages (kind internal), which were never sent: the " +
34
+ "agent's notes for staff on its replies and the questions it could not answer. Only for " +
35
+ "a private chat read by its agent_chat id with agent_chat:read within your scope; any " +
36
+ "other read leaves them out.",
37
+ })),
28
38
  });
29
39
  export const ChatDestination = Schema.Struct({
30
40
  id: Id,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@segmentstream/ontology",
3
- "version": "0.188.0",
3
+ "version": "0.189.0",
4
4
  "description": "Define a SegmentStream workspace app's ontology: entities, relationships, roles and actions, written with Effect.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "SegmentStream",