@segmentstream/ontology 0.150.2 → 0.152.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,52 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.152.0
4
+
5
+ `agent_chat.importHistory` writes a chat's earlier history into the workspace's own database once
6
+ it holds the agent's messages. Each message joins the chat in its place by its time, among the
7
+ messages the agent recorded, so history that overlaps what the chat holds imports as it is: a
8
+ message the chat already holds, by its id, is a duplicate, and importing again adds nothing. The
9
+ rule that only messages at least 15 minutes older than the chat's oldest are added holds only while
10
+ the history still goes to the platform's chat archive, before the workspace's database holds a
11
+ message; there `skipped` counts them, and in the workspace's database it is always 0.
12
+
13
+ An imported message may carry files: `files: [{ upload: <ticket> }]`, each a completed upload begun
14
+ with `files_upload` for `entity: "agent_chat"`, `action: "import_history"` and `property: "files"`
15
+ (or `Files.stage` with `target: { entity: "agent_chat", property: "files" }` in a workflow step), up
16
+ to 20 MB a file, 10 a message and 50 a call. Each file becomes one of the chat's stored attachments
17
+ without its bytes being copied, listed in the message's `files`; a private chat's files are its
18
+ person's, as the files they send are. A message's `text` is now optional when it has files. The
19
+ upload of a message not imported, a duplicate or an expired one, is released. The platform's chat
20
+ archive takes no files, so an import with files is refused until the history goes to the
21
+ workspace's database.
22
+
23
+ A chat channel keeps its chats' files as long as their messages with
24
+ `chat: { whatsapp: { connection: whatsapp, files: { keep: true } } }`: a file the agent receives
25
+ there, and a file imported with a chat's history, then expires `chat.retentionDays` after its
26
+ message instead of 24 hours after it arrives. The manifest carries `files: { keep: true }` on the
27
+ channel only when declared. A member may still receive 50 attachments a day. A message deleted at
28
+ its provider now discards the stored files it held, on every channel.
29
+
30
+ A member whose `agent_chat:read`, within its scope, holds a chat's record downloads and lists that
31
+ chat's files with `attachments_download`, `attachments_get` and `attachments_list` (`chat`), as they
32
+ read its messages: staff working the inbox see the files of the chats they read.
33
+
34
+ The agent never shows a running session history imported after its bookmark in the workspace's
35
+ database, and a session's first turn reads the chat's newest messages in the order of their time,
36
+ imported history among them.
37
+
38
+ ## 0.151.0
39
+
40
+ `inbox` takes `channels`: the WhatsApp and workspace channels `chat` declares whose chats with
41
+ people who are no users join the inbox too, as `agent_chat` records of kind `private` without
42
+ members, such as `inbox: { roles: [client], channels: ["sales_whatsapp"] }`. The agent reports such
43
+ a chat to `POST /api/ontology/agent/chats/seen` without `memberId` when the channel records every
44
+ message (`record: "all"` in `agent/segmentstream.json`). The service registers it only on a listed
45
+ channel, makes nobody a user for it, and leaves the members of a chat it registered before as they
46
+ are. Staff with `agent_chat:read` whose scope holds the record read its messages; nobody reads it as
47
+ its person, and a post to it is refused, since it has no person to answer. `check` reports
48
+ `invalid-inbox` for any other channel. Without `channels`, the manifest is the same as before.
49
+
3
50
  ## 0.150.2
4
51
 
5
52
  `@segmentstream/ontology/whatsapp` exports `WHATSAPP_REFUSALS`, Meta's error codes the chat names
package/README.md CHANGED
@@ -1537,8 +1537,8 @@ deletes the old one. `provider`, `externalId`, `title` and `lastMessageAt` are
1537
1537
  managed. Members set `purpose` and `whenToUse` with the generated
1538
1538
  `agent_chat.update`, the chat's only generated action, which sets no relationship: `handledBy`
1539
1539
  changes only through `agent_chat.takeOver` and `agent_chat.handBack`. `agent_chat.importHistory`
1540
- adds a chat's messages from before the agent recorded it as its earliest history, for a caller with
1541
- `agent_chat:import_history`. Chat read/update permissions remain
1540
+ adds a chat's messages from before the agent recorded it, each in its place by its time and once by
1541
+ its id, with their files as the chat's attachments, for a caller with `agent_chat:import_history`. Chat read/update permissions remain
1542
1542
  `agent_chat:read` and `agent_chat:update`, granted explicitly; wildcard entity grants do not
1543
1543
  cover this built-in registry.
1544
1544
 
@@ -54,8 +54,13 @@ export declare const AgentChat: import("./entity.js").Entity<"agent_chat", {
54
54
  readonly direction: Schema.Literals<readonly ["inbound", "outbound"]>;
55
55
  readonly by: Schema.optionalKey<Schema.Literals<readonly ["human", "agent", "bot"]>>;
56
56
  readonly name: Schema.optionalKey<Schema.String>;
57
- readonly text: Schema.String;
57
+ readonly text: Schema.optionalKey<Schema.String>;
58
58
  readonly replyTo: Schema.optionalKey<Schema.String>;
59
+ readonly files: Schema.optionalKey<Schema.$Array<Schema.Struct<{
60
+ readonly upload: Schema.Struct<{
61
+ readonly uploadId: Schema.String;
62
+ }>;
63
+ }>>>;
59
64
  }>>;
60
65
  }>, {
61
66
  readonly imported: number;
@@ -199,12 +199,15 @@ export const AgentChat = entity("agent_chat", {
199
199
  }),
200
200
  importHistory: action({
201
201
  description: "Import a chat's messages from before the agent recorded it, such as a client's earlier " +
202
- "conversation kept elsewhere: they become the chat's earliest messages, which the agent's " +
203
- "next session of the chat, the inbox and chat search read as history. Name the chat by its " +
204
- "agent_chat record, or by channel and chatId as the channel keys it. Only messages older " +
205
- "than the chat's oldest message are added; one the chat already holds, by id, is a " +
206
- "duplicate, so importing again adds nothing. Up to 500 messages a call: import a long chat " +
207
- "newest first. Nothing is sent and no turn starts.",
202
+ "conversation kept elsewhere: each joins the chat in its place by its time, which the " +
203
+ "agent's next session of the chat, the inbox and chat search read as history. Name the chat " +
204
+ "by its agent_chat record, or by channel and chatId as the channel keys it. A message the " +
205
+ "chat already holds, by id, is a duplicate, so importing again adds nothing, and history " +
206
+ "that overlaps what the chat recorded adds only what it lacks. A message's files are " +
207
+ "completed uploads, from files_upload with entity agent_chat, action import_history and " +
208
+ "property files, given as files: [{ upload: <ticket> }]. Up to 500 messages and 50 files " +
209
+ "a call. Nothing is sent and no turn starts. Until the chat store holds the agent's " +
210
+ "messages, only text older than the chat's oldest message is added.",
208
211
  input: ChatHistoryImportInput,
209
212
  hints: { destructive: false, irreversible: true, idempotent: true },
210
213
  connections: [],
package/dist/analyze.d.ts CHANGED
@@ -233,6 +233,8 @@ export interface Analysis {
233
233
  /** The wire names of the roles whose private chats join the inbox, when declared. */
234
234
  readonly inbox?: {
235
235
  readonly roles: ReadonlyArray<string>;
236
+ /** The channels whose chats with people who are no users join the inbox, without members. */
237
+ readonly channels: ReadonlyArray<string>;
236
238
  /** The channels whose private chats staff may take over from the agent. */
237
239
  readonly takeover: {
238
240
  readonly channels: ReadonlyArray<string>;
@@ -265,6 +267,16 @@ export interface Analysis {
265
267
  export interface ChatChannelConfig {
266
268
  readonly kind?: ChatKind;
267
269
  readonly connection?: AnyConnectionHandle;
270
+ /**
271
+ * What the channel's chats keep of their files. With `keep: true`, a file a message of the
272
+ * channel holds, received by the agent or imported with `agent_chat.importHistory`, is kept as
273
+ * long as the chat's messages (`retentionDays`); otherwise it expires 24 hours after it arrives.
274
+ */
275
+ readonly files?: ChatFilesConfig;
276
+ }
277
+ /** `files` of a chat channel: whether its chats keep their files with their messages. */
278
+ export interface ChatFilesConfig {
279
+ readonly keep?: boolean;
268
280
  }
269
281
  /**
270
282
  * `chat` of {@link OntologyConfig}: the agent's channels by name, the post attribution, and how
@@ -273,15 +285,19 @@ export interface ChatChannelConfig {
273
285
  export interface ChatConfig {
274
286
  readonly telegram?: {
275
287
  readonly connection: AnyConnectionHandle;
288
+ readonly files?: ChatFilesConfig;
276
289
  };
277
290
  readonly slack?: {
278
291
  readonly connection: AnyConnectionHandle;
292
+ readonly files?: ChatFilesConfig;
279
293
  };
280
294
  readonly whatsapp?: {
281
295
  readonly connection: AnyConnectionHandle;
296
+ readonly files?: ChatFilesConfig;
282
297
  };
283
298
  readonly email?: {
284
299
  readonly connection: AnyConnectionHandle;
300
+ readonly files?: ChatFilesConfig;
285
301
  };
286
302
  readonly attribution?: ChatAttributionSettings;
287
303
  /**
package/dist/analyze.js CHANGED
@@ -46,6 +46,8 @@ const REVIEW_ONLY_CHAT_PROVIDERS = new Set(["email"]);
46
46
  const RESERVED_CHAT_NAMES = new Set(["web", "task", WORKSPACE_CHANNEL_KIND]);
47
47
  /** The keys of `chat` that are settings, not channels. */
48
48
  const CHAT_SETTINGS = new Set(["attribution", "retentionDays"]);
49
+ /** The kinds of channel whose agent records every message it receives, when asked to. */
50
+ const INBOX_CHANNEL_KINDS = new Set(["whatsapp", WORKSPACE_CHANNEL_KIND]);
49
51
  /** Whether `chat` declares a channel of `kind`: the one named after it, or another of the kind. */
50
52
  function declaresChatKind(chat, kind) {
51
53
  return (isPlainObject(chat) &&
@@ -105,11 +107,14 @@ export function analyze(config, options = {}) {
105
107
  ...(linkEmail === undefined ? {} : { linkEmail }),
106
108
  ...(codeEmail === undefined ? {} : { codeEmail }),
107
109
  };
108
- const inbox = inboxOptions(config.inbox, declaredRoles, guest !== undefined, isPlainObject(config.chat)
110
+ const chatChannels = isPlainObject(config.chat)
109
111
  ? Object.entries(config.chat)
110
112
  .filter(([name, channel]) => !CHAT_SETTINGS.has(name) && channel !== undefined)
111
113
  .map(([name]) => name)
112
- : [], report);
114
+ : [];
115
+ const inbox = inboxOptions(config.inbox, declaredRoles, guest !== undefined, chatChannels,
116
+ // The channels whose agent records every message, chats of people who are no users among them.
117
+ chatChannels.filter((name) => INBOX_CHANNEL_KINDS.has(chatChannelKind(config.chat, name) ?? "")), report);
113
118
  const discovery = config.discovery;
114
119
  if (discovery !== undefined &&
115
120
  (!isPlainObject(discovery) ||
@@ -182,7 +187,11 @@ export function analyze(config, options = {}) {
182
187
  const malformed = entries.find(([name, value]) => {
183
188
  const named = !CHAT_PROVIDER_KEYS.includes(name);
184
189
  return (!isPlainObject(value) ||
185
- Object.keys(value).some((key) => key !== "connection" && key !== "kind") ||
190
+ Object.keys(value).some((key) => key !== "connection" && key !== "kind" && key !== "files") ||
191
+ (value.files !== undefined &&
192
+ (!isPlainObject(value.files) ||
193
+ Object.keys(value.files).some((key) => key !== "keep") ||
194
+ (value.files.keep !== undefined && typeof value.files.keep !== "boolean"))) ||
186
195
  // A workspace channel has no connection here: the agent sends through it, with the
187
196
  // connection agent/segmentstream.json gives it. Every other channel sends through its own.
188
197
  (value.kind === WORKSPACE_CHANNEL_KIND
@@ -194,9 +203,16 @@ export function analyze(config, options = {}) {
194
203
  const channels = malformed === undefined && unknown === undefined
195
204
  ? entries.map(([name, value]) => {
196
205
  const entry = value;
197
- return [name, entry.connection, entry.kind ?? name];
206
+ return [
207
+ name,
208
+ entry.connection,
209
+ entry.kind ?? name,
210
+ entry.files?.keep === true,
211
+ ];
198
212
  })
199
213
  : [];
214
+ // Written only for a channel that keeps its files: older readers keep none.
215
+ const keptFiles = (keep) => (keep ? { files: { keep: true } } : {});
200
216
  const handles = channels.flatMap(([name, handle, kind]) => handle === undefined ? [] : [[name, handle, kind]]);
201
217
  const unlisted = handles.find(([, handle]) => !(config.connections ?? []).includes(handle));
202
218
  const shared = handles.find(([, handle], index) => handles.findIndex(([, other]) => other === handle) !== index);
@@ -208,7 +224,8 @@ export function analyze(config, options = {}) {
208
224
  else if (malformed !== undefined) {
209
225
  report("invalid-connection", "chat", `chat.${malformed}.connection must reference a declared connection handle, and a ` +
210
226
  `channel not named after its kind needs kind: ${CHAT_KINDS.join(", ")}; a ` +
211
- `${WORKSPACE_CHANNEL_KIND} channel takes none, as the agent sends through it.`);
227
+ `${WORKSPACE_CHANNEL_KIND} channel takes none, as the agent sends through it. ` +
228
+ `files takes keep, true or false.`);
212
229
  }
213
230
  else if (unlisted !== undefined) {
214
231
  report("invalid-connection", `chat.${unlisted[0]}.connection`, "The chat channel connection must be listed in connections.");
@@ -219,15 +236,19 @@ export function analyze(config, options = {}) {
219
236
  else if (channels.length > 0) {
220
237
  const named = channels.filter(([name]) => !CHAT_PROVIDER_KEYS.includes(name));
221
238
  chat = {
222
- ...Object.fromEntries(handles
239
+ ...Object.fromEntries(channels
223
240
  .filter(([name]) => CHAT_PROVIDER_KEYS.includes(name))
224
- .map(([name, handle]) => [name, { connection: handle.key }])),
241
+ .flatMap(([name, handle, , keep]) => handle === undefined ? [] : [[name, { connection: handle.key, ...keptFiles(keep) }]])),
225
242
  ...(named.length === 0
226
243
  ? {}
227
244
  : {
228
- channels: Object.fromEntries(named.map(([name, handle, kind]) => [
245
+ channels: Object.fromEntries(named.map(([name, handle, kind, keep]) => [
229
246
  name,
230
- { kind, ...(handle === undefined ? {} : { connection: handle.key }) },
247
+ {
248
+ kind,
249
+ ...(handle === undefined ? {} : { connection: handle.key }),
250
+ ...keptFiles(keep),
251
+ },
231
252
  ])),
232
253
  }),
233
254
  ...(config.chat.attribution === undefined ? {} : { attribution: config.chat.attribution }),
@@ -372,26 +393,31 @@ export function analyze(config, options = {}) {
372
393
  }
373
394
  /**
374
395
  * `inbox`: the wire names of the roles whose private chats join the inbox, each a declared role or
375
- * `member`, the channels whose chats staff may take over: those `takeover.channels` lists, or
376
- * every channel `chat` declares, and whether a member's own reply carries their name: `name`
377
- * unless `attribution` is `none`; `undefined` when absent or malformed.
396
+ * `member`, the channels whose chats with people who are no users join it too, the channels whose
397
+ * chats staff may take over: those `takeover.channels` lists, or every channel `chat` declares,
398
+ * and whether a member's own reply carries their name: `name` unless `attribution` is `none`;
399
+ * `undefined` when absent or malformed.
378
400
  */
379
401
  function inboxOptions(value, declaredRoles,
380
402
  /** Whether the ontology declares `guest`, whose visitors' chats the inbox may take. */
381
403
  guests,
382
404
  /** The names of the channels `chat` declares. */
383
- chatChannels, report) {
405
+ chatChannels,
406
+ /** The channels `chat` declares whose agent may record every message they receive. */
407
+ recordingChannels, report) {
384
408
  if (value === undefined) {
385
409
  return undefined;
386
410
  }
387
411
  if (!isPlainObject(value) ||
388
- Object.keys(value).some((key) => key !== "roles" && key !== "takeover" && key !== "attribution") ||
412
+ Object.keys(value).some((key) => key !== "roles" && key !== "channels" && key !== "takeover" && key !== "attribution") ||
389
413
  !Array.isArray(value.roles) ||
390
- value.roles.length === 0) {
391
- report("invalid-inbox", "inbox", 'inbox takes { roles: [...], takeover?: { channels?: [...] }, attribution?: "name" | ' +
392
- '"none" }, at least one role.');
414
+ value.roles.length === 0 ||
415
+ (value.channels !== undefined && !Array.isArray(value.channels))) {
416
+ report("invalid-inbox", "inbox", "inbox takes { roles: [...], channels?: [...], takeover?: { channels?: [...] }, " +
417
+ 'attribution?: "name" | "none" }, at least one role.');
393
418
  return undefined;
394
419
  }
420
+ const channels = inboxChannels(value.channels, recordingChannels, report);
395
421
  const takeover = takeoverOptions(value.takeover, chatChannels, report);
396
422
  const attribution = value.attribution === undefined ? "name" : value.attribution;
397
423
  if (attribution !== "name" && attribution !== "none") {
@@ -418,10 +444,36 @@ chatChannels, report) {
418
444
  roles.push(name);
419
445
  }
420
446
  });
421
- return valid && takeover !== undefined && (attribution === "name" || attribution === "none")
422
- ? { roles, takeover, attribution }
447
+ return valid &&
448
+ channels !== undefined &&
449
+ takeover !== undefined &&
450
+ (attribution === "name" || attribution === "none")
451
+ ? { roles, channels, takeover, attribution }
423
452
  : undefined;
424
453
  }
454
+ /**
455
+ * `inbox.channels`: the channels whose chats with people who are no users join the inbox, each a
456
+ * WhatsApp or workspace channel `chat` declares, as only their agent records the messages of
457
+ * people it does not answer; none when absent.
458
+ */
459
+ function inboxChannels(value, recordingChannels, report) {
460
+ if (value === undefined) {
461
+ return [];
462
+ }
463
+ const channels = [];
464
+ let valid = true;
465
+ value.forEach((candidate, index) => {
466
+ if (typeof candidate !== "string" || !recordingChannels.includes(candidate)) {
467
+ report("invalid-inbox", `inbox.channels[${index}]`, "Use a WhatsApp or workspace channel chat declares: only their agent records the " +
468
+ 'messages of people it does not answer, with record: "all".');
469
+ valid = false;
470
+ }
471
+ else if (!channels.includes(candidate)) {
472
+ channels.push(candidate);
473
+ }
474
+ });
475
+ return valid ? channels : undefined;
476
+ }
425
477
  /**
426
478
  * `inbox.takeover`: the channels whose private chats staff may take over from the agent, each a
427
479
  * channel `chat` declares, since staff answer through it; every one of them when `channels` is
package/dist/chat.d.ts CHANGED
@@ -10,6 +10,14 @@ export interface ChatAttributionSettings {
10
10
  */
11
11
  export interface InboxOptions<R = unknown> {
12
12
  readonly roles: ReadonlyArray<R>;
13
+ /**
14
+ * The channels whose chats with people who are no users join the inbox too, as `agent_chat`
15
+ * records of kind `private` without members: WhatsApp channels and workspace channels `chat`
16
+ * declares, on which the agent records every message (`record: "all"` in
17
+ * `agent/segmentstream.json`). `agent_chat:read` within a scope that holds such a record reads
18
+ * its messages. Absent, only the people `roles` takes join.
19
+ */
20
+ readonly channels?: ReadonlyArray<string>;
13
21
  /**
14
22
  * Where staff may take a chat over from the agent, which then records the person's messages and
15
23
  * answers none until a member hands it back: `channels` lists channels `chat` declares, `[]` for
@@ -141,6 +149,8 @@ export interface ChatPreview {
141
149
  }
142
150
  export declare const chatOperationId: (sessionId: string, callId: string) => string;
143
151
  export declare const chatPreviewDigest: (preview: ChatPreview) => string;
152
+ /** The most files one imported message carries. */
153
+ export declare const CHAT_HISTORY_MESSAGE_FILES = 10;
144
154
  /** One message of a chat from before the agent's archive recorded it, as the workspace kept it. */
145
155
  export declare const ChatHistoryMessage: Schema.Struct<{
146
156
  readonly id: Schema.String;
@@ -148,12 +158,19 @@ export declare const ChatHistoryMessage: Schema.Struct<{
148
158
  readonly direction: Schema.Literals<readonly ["inbound", "outbound"]>;
149
159
  readonly by: Schema.optionalKey<Schema.Literals<readonly ["human", "agent", "bot"]>>;
150
160
  readonly name: Schema.optionalKey<Schema.String>;
151
- readonly text: Schema.String;
161
+ readonly text: Schema.optionalKey<Schema.String>;
152
162
  readonly replyTo: Schema.optionalKey<Schema.String>;
163
+ readonly files: Schema.optionalKey<Schema.$Array<Schema.Struct<{
164
+ readonly upload: Schema.Struct<{
165
+ readonly uploadId: Schema.String;
166
+ }>;
167
+ }>>>;
153
168
  }>;
154
169
  export type ChatHistoryMessage = typeof ChatHistoryMessage.Type;
155
170
  /** The most messages one import takes. */
156
171
  export declare const CHAT_HISTORY_MESSAGES = 500;
172
+ /** The most files one import takes, of all its messages together. */
173
+ export declare const CHAT_HISTORY_FILES = 50;
157
174
  export declare const ChatHistoryImportInput: Schema.Struct<{
158
175
  readonly chat: Schema.optionalKey<Schema.String>;
159
176
  readonly channel: Schema.optionalKey<Schema.String>;
@@ -167,8 +184,13 @@ export declare const ChatHistoryImportInput: Schema.Struct<{
167
184
  readonly direction: Schema.Literals<readonly ["inbound", "outbound"]>;
168
185
  readonly by: Schema.optionalKey<Schema.Literals<readonly ["human", "agent", "bot"]>>;
169
186
  readonly name: Schema.optionalKey<Schema.String>;
170
- readonly text: Schema.String;
187
+ readonly text: Schema.optionalKey<Schema.String>;
171
188
  readonly replyTo: Schema.optionalKey<Schema.String>;
189
+ readonly files: Schema.optionalKey<Schema.$Array<Schema.Struct<{
190
+ readonly upload: Schema.Struct<{
191
+ readonly uploadId: Schema.String;
192
+ }>;
193
+ }>>>;
172
194
  }>>;
173
195
  }>;
174
196
  export type ChatHistoryImportInput = typeof ChatHistoryImportInput.Type;
@@ -214,7 +236,7 @@ declare const ChatDelivery_base: Context.ServiceClass<ChatDelivery, "@segmentstr
214
236
  readonly sendReview?: (input: ReviewSendInput) => Effect.Effect<ReviewSendResult, ActionError>;
215
237
  /** Asks the agent to redraft a reply it held for review, in a session of its own. */
216
238
  readonly reviseReview?: (input: ReviewReviseInput) => Effect.Effect<ReviewReviseResult, ActionError>;
217
- /** Adds a chat's messages from before the archive recorded it, as its earliest messages. */
239
+ /** Adds a chat's messages from before the agent recorded it, each in its place by its time. */
218
240
  readonly importHistory?: (input: ChatHistoryImportInput) => Effect.Effect<ChatHistoryImportResult, ActionError>;
219
241
  /** The channels whose private chats staff may take over, as the ontology's inbox lists them. */
220
242
  readonly takeoverChannels?: ReadonlySet<string>;
package/dist/chat.js CHANGED
@@ -1,5 +1,7 @@
1
1
  import { createHash } from "node:crypto";
2
2
  import { Context, Schema } from "effect";
3
+ import { BLOB_UPLOAD_ANNOTATION, BlobUpload } from "./blob.js";
4
+ import { CHAT_FILES } from "./files.js";
3
5
  const Identifier = Schema.String.check(Schema.isMinLength(1), Schema.isMaxLength(512));
4
6
  export const ChatPostInput = Schema.Struct({
5
7
  chat: Identifier,
@@ -123,6 +125,8 @@ export const chatPreviewDigest = (preview) => chatProtocolDigest([
123
125
  preview.finalText,
124
126
  preview.replyTo,
125
127
  ]);
128
+ /** The most files one imported message carries. */
129
+ export const CHAT_HISTORY_MESSAGE_FILES = 10;
126
130
  /** One message of a chat from before the agent's archive recorded it, as the workspace kept it. */
127
131
  export const ChatHistoryMessage = Schema.Struct({
128
132
  id: Identifier.annotate({
@@ -140,11 +144,23 @@ export const ChatHistoryMessage = Schema.Struct({
140
144
  "agent for outbound.",
141
145
  })),
142
146
  name: Schema.optionalKey(Schema.String.check(Schema.isMaxLength(200))),
143
- text: Schema.String.check(Schema.isMinLength(1), Schema.isMaxLength(100_000)),
147
+ text: Schema.optionalKey(Schema.String.check(Schema.isMinLength(1), Schema.isMaxLength(100_000))),
144
148
  replyTo: Schema.optionalKey(Identifier),
149
+ files: Schema.optionalKey(Schema.Array(Schema.Struct({
150
+ upload: BlobUpload.annotate({
151
+ description: "A completed upload, from files_upload with entity agent_chat, action " +
152
+ "import_history and property files: the file the message carried, which the chat " +
153
+ "keeps as its attachment.",
154
+ [BLOB_UPLOAD_ANNOTATION]: { entity: CHAT_FILES.entity, property: CHAT_FILES.property },
155
+ }),
156
+ }))
157
+ .check(Schema.isMinLength(1), Schema.isMaxLength(CHAT_HISTORY_MESSAGE_FILES))
158
+ .annotate({ description: "The message's files. A message has text, files or both." })),
145
159
  });
146
160
  /** The most messages one import takes. */
147
161
  export const CHAT_HISTORY_MESSAGES = 500;
162
+ /** The most files one import takes, of all its messages together. */
163
+ export const CHAT_HISTORY_FILES = 50;
148
164
  export const ChatHistoryImportInput = Schema.Struct({
149
165
  chat: Schema.optionalKey(Identifier.annotate({ description: "The agent_chat record of the chat, if it has one." })),
150
166
  channel: Schema.optionalKey(Identifier.annotate({ description: "Without chat: the channel's name, such as whatsapp." })),
package/dist/files.d.ts CHANGED
@@ -6,6 +6,13 @@ export interface FileTarget {
6
6
  readonly entity: string;
7
7
  readonly property: string;
8
8
  }
9
+ /**
10
+ * A file of a chat's message, which `agent_chat.importHistory` keeps as one of the chat's
11
+ * attachments: the one upload target that is no record's property.
12
+ */
13
+ export declare const CHAT_FILES: FileTarget;
14
+ /** The action that takes {@link CHAT_FILES} uploads. */
15
+ export declare const CHAT_FILES_ACTION = "agent_chat.import_history";
9
16
  export interface StageFile<E, R> {
10
17
  readonly target: FileTarget;
11
18
  /** Stable source identity within this action or workflow step's idempotency key. */
package/dist/files.js CHANGED
@@ -1,4 +1,11 @@
1
1
  import { Context } from "effect";
2
+ /**
3
+ * A file of a chat's message, which `agent_chat.importHistory` keeps as one of the chat's
4
+ * attachments: the one upload target that is no record's property.
5
+ */
6
+ export const CHAT_FILES = { entity: "agent_chat", property: "files" };
7
+ /** The action that takes {@link CHAT_FILES} uploads. */
8
+ export const CHAT_FILES_ACTION = "agent_chat.import_history";
2
9
  /** File I/O outside transactions, bound to the current action or workflow principal. */
3
10
  export class Files extends Context.Service()("@segmentstream/ontology/Files") {
4
11
  }
package/dist/index.d.ts CHANGED
@@ -14,7 +14,7 @@ export type { ConfirmContext } from "./confirmation.js";
14
14
  export type { Action, ActionConfig, ActionConfigWithConnections, ActionContext, ActionIdentity, ActionEncodedInput, ActionHints, ActionInput, ActionResult, ActionWriteTarget, Actions, AnyAction, PrepareContext, PrepareError, } from "./action.js";
15
15
  export { CONNECTION_ERROR_REASONS, CONNECTION_KEY, CONNECTION_METHODS, connection, ConnectionError, Connections, ConnectionTransport, isConnection, MAXIMUM_CONNECTION_BODY_BYTES, MAXIMUM_CONNECTION_FILE_BYTES, MAXIMUM_CONNECTION_RESPONSE_BYTES, } from "./connection.js";
16
16
  export type { AnyConnectionHandle, Connection, ConnectionCall, ConnectionClient, ConnectionErrorReason, ConnectionHandle, ConnectionHeaders, ConnectionMethod, ConnectionOptions, ConnectionReply, ConnectionRequest, ConnectionRequestOptions, ConnectionResponse, ConnectionStreamReply, ConnectionStreamResponse, ConnectionsOf, ConnectionStub, StubRequest, StubResponse, } from "./connection.js";
17
- export type { ChatChannelConfig, ChatConfig, DiscoveryOptions, EntityPermissions, JsonSchemaObject, MemberOptions, OntologyConfig, ResolvedAction, ResolvedConnection, ResolvedEntity, ResolvedIndex, ResolvedProperty, ResolvedRelationship, } from "./analyze.js";
17
+ export type { ChatChannelConfig, ChatConfig, ChatFilesConfig, DiscoveryOptions, EntityPermissions, JsonSchemaObject, MemberOptions, OntologyConfig, ResolvedAction, ResolvedConnection, ResolvedEntity, ResolvedIndex, ResolvedProperty, ResolvedRelationship, } from "./analyze.js";
18
18
  export { Diagnostic, DIAGNOSTIC_CODES, formatDiagnostics, InvalidOntology } from "./diagnostics.js";
19
19
  export type { DiagnosticCode } from "./diagnostics.js";
20
20
  export { entity, isEntity } from "./entity.js";
@@ -24,7 +24,7 @@ export type { ActionsBuilder, AnyEntity, ActionHandle, ActionInvoker, MetricQuer
24
24
  export { ActionRejected, BatchErrorDetails, Conflict, DeploymentInterrupted, DeploymentSwitching, LimitErrorDetails, NotFound, PermissionDenied, ScopeViolated, } from "./errors.js";
25
25
  export type { ActionError } from "./errors.js";
26
26
  export { browserAuthenticationCompatible } from "./manifest-compatibility.js";
27
- export { ActionManifest, actionConnectionKeys, canonicalJson, ConnectionManifest, EntityManifest, EntityPermissionsManifest, decodeManifestDocument, encodeManifest, formatManifest, IndexManifest, isValueMatched, MANIFEST_VERSION, manifestHash, ModelMetricManifest, OntologyManifest, OntologyManifestWire, PropertyManifest, RelationshipManifest, RoleManifest, ActionTriggerManifest, ScopeManifest, CronTriggerManifest, isActionTrigger, isCronTrigger, isWebhookTrigger, OtherTriggerManifest, WebhookTriggerManifest, WorkflowManifest, WorkflowTriggerManifest, SelectOptionManifest, SignInManifest, GuestManifest, guestOf, signInPolicyOf, channelPolicyOf, signUpOriginsOf, inboxRolesOf, takeoverChannelsOf, signUpRolesOf, CHAT_RETENTION_DAYS, chatRetentionDaysOf, } from "./manifest.js";
27
+ export { ActionManifest, actionConnectionKeys, canonicalJson, ConnectionManifest, EntityManifest, EntityPermissionsManifest, decodeManifestDocument, encodeManifest, formatManifest, IndexManifest, isValueMatched, MANIFEST_VERSION, manifestHash, ModelMetricManifest, OntologyManifest, OntologyManifestWire, PropertyManifest, RelationshipManifest, RoleManifest, ActionTriggerManifest, ScopeManifest, CronTriggerManifest, isActionTrigger, isCronTrigger, isWebhookTrigger, OtherTriggerManifest, WebhookTriggerManifest, WorkflowManifest, WorkflowTriggerManifest, SelectOptionManifest, SignInManifest, GuestManifest, guestOf, signInPolicyOf, channelPolicyOf, signUpOriginsOf, inboxRolesOf, inboxChannelsOf, takeoverChannelsOf, signUpRolesOf, CHAT_RETENTION_DAYS, chatRetentionDaysOf, keepsChatFiles, } from "./manifest.js";
28
28
  export { SYSTEM_PROPERTIES } from "./names.js";
29
29
  export type { SystemProperty } from "./names.js";
30
30
  export { isMe, isMeMarker, MAX_ME_HOPS, me, ME_KEY, MeMarker, mePathOf, meToWire, MeTypeId, } from "./me.js";
package/dist/index.js CHANGED
@@ -13,7 +13,7 @@ export { entity, isEntity } from "./entity.js";
13
13
  export { isToolset, MCP_TOOL_NAME, TOOLSET_LOCK_VERSION, toolset, ToolsetLock, ToolsetLockTool, } from "./toolset.js";
14
14
  export { ActionRejected, BatchErrorDetails, Conflict, DeploymentInterrupted, DeploymentSwitching, LimitErrorDetails, NotFound, PermissionDenied, ScopeViolated, } from "./errors.js";
15
15
  export { browserAuthenticationCompatible } from "./manifest-compatibility.js";
16
- export { ActionManifest, actionConnectionKeys, canonicalJson, ConnectionManifest, EntityManifest, EntityPermissionsManifest, decodeManifestDocument, encodeManifest, formatManifest, IndexManifest, isValueMatched, MANIFEST_VERSION, manifestHash, ModelMetricManifest, OntologyManifest, OntologyManifestWire, PropertyManifest, RelationshipManifest, RoleManifest, ActionTriggerManifest, ScopeManifest, CronTriggerManifest, isActionTrigger, isCronTrigger, isWebhookTrigger, OtherTriggerManifest, WebhookTriggerManifest, WorkflowManifest, WorkflowTriggerManifest, SelectOptionManifest, SignInManifest, GuestManifest, guestOf, signInPolicyOf, channelPolicyOf, signUpOriginsOf, inboxRolesOf, takeoverChannelsOf, signUpRolesOf, CHAT_RETENTION_DAYS, chatRetentionDaysOf, } from "./manifest.js";
16
+ export { ActionManifest, actionConnectionKeys, canonicalJson, ConnectionManifest, EntityManifest, EntityPermissionsManifest, decodeManifestDocument, encodeManifest, formatManifest, IndexManifest, isValueMatched, MANIFEST_VERSION, manifestHash, ModelMetricManifest, OntologyManifest, OntologyManifestWire, PropertyManifest, RelationshipManifest, RoleManifest, ActionTriggerManifest, ScopeManifest, CronTriggerManifest, isActionTrigger, isCronTrigger, isWebhookTrigger, OtherTriggerManifest, WebhookTriggerManifest, WorkflowManifest, WorkflowTriggerManifest, SelectOptionManifest, SignInManifest, GuestManifest, guestOf, signInPolicyOf, channelPolicyOf, signUpOriginsOf, inboxRolesOf, inboxChannelsOf, takeoverChannelsOf, signUpRolesOf, CHAT_RETENTION_DAYS, chatRetentionDaysOf, keepsChatFiles, } 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";