@segmentstream/agent 0.75.0 → 0.76.1
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 +62 -0
- package/README.md +1 -0
- package/dist/_chunks/{build-metadata-CLenocka.mjs → build-metadata-rKN9hmJm.mjs} +1 -1
- package/dist/_chunks/{chat-archive-CDk-FPLX.mjs → chat-archive-CUMEaSqy.mjs} +1 -0
- package/dist/_chunks/{chat-archive-DHYplDT5.mjs → chat-archive-pVRDSPL2.mjs} +2 -2
- package/dist/extension/config.d.ts +15 -0
- package/dist/extension/config.mjs +25 -5
- package/dist/extension/connections/ontology.mjs +1 -1
- package/dist/extension/extension.d.ts +1 -1
- package/dist/extension/hooks/authorization.mjs +1 -1
- package/dist/extension/hooks/chat-context.mjs +1 -1
- package/dist/extension/hooks/chat-recorder.mjs +1 -1
- package/dist/extension/instructions/persona.mjs +1 -1
- package/dist/extension/lib/actor.mjs +1 -1
- package/dist/extension/lib/admission.d.ts +8 -3
- package/dist/extension/lib/admission.mjs +14 -2
- package/dist/extension/lib/attachment-tools.mjs +1 -1
- package/dist/extension/lib/attachments-send.mjs +1 -1
- package/dist/extension/lib/attachments.mjs +1 -1
- package/dist/extension/lib/build-metadata.mjs +1 -1
- package/dist/extension/lib/chat-address.mjs +1 -1
- package/dist/extension/lib/chat-archive.d.ts +6 -0
- package/dist/extension/lib/chat-archive.mjs +1 -1
- package/dist/extension/lib/chat-context.mjs +4 -3
- package/dist/extension/lib/chat-messages.d.ts +37 -3
- package/dist/extension/lib/chat-messages.mjs +46 -8
- package/dist/extension/lib/chat-recorder.mjs +2 -2
- package/dist/extension/lib/confirmations.mjs +1 -1
- package/dist/extension/lib/email/attachments-send.mjs +1 -1
- package/dist/extension/lib/email/channel.mjs +2 -2
- package/dist/extension/lib/group-routing/routing-context.mjs +1 -1
- package/dist/extension/lib/guest-usage.mjs +1 -1
- package/dist/extension/lib/inbound-media/files.mjs +1 -1
- package/dist/extension/lib/inbound-media/index.d.ts +3 -2
- package/dist/extension/lib/inbound-media/index.mjs +1 -1
- package/dist/extension/lib/model-service-alert.mjs +1 -1
- package/dist/extension/lib/ontology-connection.mjs +1 -1
- package/dist/extension/lib/ontology-file-call.mjs +1 -1
- package/dist/extension/lib/ontology-tools.mjs +1 -1
- package/dist/extension/lib/review/hold.mjs +1 -1
- package/dist/extension/lib/review/judge.mjs +1 -1
- package/dist/extension/lib/review/reply.mjs +2 -2
- package/dist/extension/lib/review/revision-channel.mjs +1 -1
- package/dist/extension/lib/role-skill.mjs +1 -1
- package/dist/extension/lib/runtime-envelope.mjs +1 -1
- package/dist/extension/lib/sent-files.mjs +1 -1
- package/dist/extension/lib/slack/adapter.mjs +2 -2
- package/dist/extension/lib/slack/attachments-send.mjs +1 -1
- package/dist/extension/lib/slack/callbacks.mjs +1 -1
- package/dist/extension/lib/stored-files.mjs +1 -1
- package/dist/extension/lib/telegram/adapter.mjs +4 -4
- package/dist/extension/lib/telegram/attachment-description.mjs +1 -1
- package/dist/extension/lib/telegram/attachments-send.mjs +1 -1
- package/dist/extension/lib/telegram/callbacks.mjs +1 -1
- package/dist/extension/lib/telegram/chat-archive.mjs +1 -1
- package/dist/extension/lib/telegram/confirmations.mjs +2 -2
- package/dist/extension/lib/telegram/customer-text.mjs +1 -1
- package/dist/extension/lib/telegram/delivery-diagnostics.mjs +1 -1
- package/dist/extension/lib/telegram/files.mjs +1 -1
- package/dist/extension/lib/telegram/health.mjs +1 -1
- package/dist/extension/lib/telegram/held-approvals.mjs +1 -1
- package/dist/extension/lib/telegram/inbound-request.mjs +1 -1
- package/dist/extension/lib/telegram/inbound.mjs +2 -2
- package/dist/extension/lib/telegram/lifecycle.mjs +2 -2
- package/dist/extension/lib/telegram/principal.mjs +1 -1
- package/dist/extension/lib/telegram/session-recovery.mjs +1 -1
- package/dist/extension/lib/telegram/silent.mjs +1 -1
- package/dist/extension/lib/telegram/store-capture.mjs +1 -1
- package/dist/extension/lib/telegram/structured.mjs +1 -1
- package/dist/extension/lib/telegram/turn-errors.mjs +2 -2
- package/dist/extension/lib/web/auth.mjs +1 -1
- package/dist/extension/lib/web/channel.mjs +1 -1
- package/dist/extension/lib/whatsapp/adapter.d.ts +6 -2
- package/dist/extension/lib/whatsapp/adapter.mjs +44 -10
- package/dist/extension/lib/whatsapp/attachments-send.mjs +2 -2
- package/dist/extension/lib/whatsapp/callbacks.mjs +1 -1
- package/dist/extension/lib/whatsapp/changes.d.ts +5 -4
- package/dist/extension/lib/whatsapp/changes.mjs +3 -3
- package/dist/extension/lib/whatsapp/echoes.d.ts +4 -3
- package/dist/extension/lib/whatsapp/echoes.mjs +2 -2
- package/dist/extension/lib/whatsapp/files.mjs +1 -1
- package/dist/extension/lib/whatsapp/sent.mjs +1 -1
- package/dist/extension/lib/workspace-action.mjs +1 -1
- package/dist/extension/lib/workspace-channel/attachments-send.mjs +1 -1
- package/dist/extension/lib/workspace-channel/channel.mjs +30 -16
- package/dist/extension/lib/workspace-chat-archive.mjs +1 -1
- package/dist/extension/lib/workspace-source.mjs +1 -1
- package/dist/extension/model.mjs +1 -1
- package/dist/extension/tools/attachments_discard.mjs +1 -1
- package/dist/extension/tools/attachments_list.mjs +1 -1
- package/dist/extension/tools/attachments_promote.mjs +1 -1
- package/dist/extension/tools/attachments_read.mjs +1 -1
- package/dist/extension/tools/attachments_send.mjs +1 -1
- package/dist/extension/tools/attachments_stage.mjs +1 -1
- package/dist/extension/tools/attachments_table.mjs +1 -1
- package/dist/extension/tools/handoff.mjs +1 -1
- package/dist/extension/tools/questions_ask.mjs +1 -1
- package/dist/extension/tools/workspace_source.mjs +1 -1
- package/package.json +2 -2
- package/dist/_chunks/{principal-Zf42Yf4r.mjs → principal-C7aAjyt4.mjs} +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,67 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.76.1
|
|
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
|
+
Pins @segmentstream/ontology 0.152.0.
|
|
39
|
+
|
|
40
|
+
## 0.76.0
|
|
41
|
+
|
|
42
|
+
A WhatsApp or workspace channel takes `"record": "all"` in `agent/segmentstream.json`: it keeps
|
|
43
|
+
every message it receives in its chats, answered or not, on an agent whose ontology keeps the
|
|
44
|
+
workspace chat store. `"agent"`, the default, records as before.
|
|
45
|
+
|
|
46
|
+
- A message from someone the agent does not admit joins their chat without a member and starts no
|
|
47
|
+
turn, `skipped` with `identity_unknown` (the account is no user's), `identity_refused` (a blocked
|
|
48
|
+
or inactive member) or `limited` (over a limit). Admission is unchanged: the person gets the
|
|
49
|
+
workspace's pairing, refusal or limit text as before, and nobody becomes a user by being
|
|
50
|
+
recorded. Their files are recorded by name, not stored.
|
|
51
|
+
- A member's message with nothing the agent reads is `skipped` with `no_text`.
|
|
52
|
+
- What the workspace's side writes outside the agent, and on WhatsApp a contact card, is recorded
|
|
53
|
+
even in a chat the agent has none of yet, without members.
|
|
54
|
+
- The private chat of someone who is no user is reported to the ontology without a person, which
|
|
55
|
+
registers it for the inbox where the ontology's `inbox.channels` lists the channel.
|
|
56
|
+
|
|
57
|
+
Recording every message stores what people the agent never answers wrote. Declare it only on a
|
|
58
|
+
channel whose every conversation the workspace works, scope `agent_chat:read` to the staff who
|
|
59
|
+
work them, and say in the workspace's privacy notice that those messages are kept and read by
|
|
60
|
+
staff. Telegram already records every message it receives; Slack, email and the web chat do not
|
|
61
|
+
take the setting.
|
|
62
|
+
|
|
63
|
+
Pins @segmentstream/ontology 0.151.0.
|
|
64
|
+
|
|
3
65
|
## 0.75.0
|
|
4
66
|
|
|
5
67
|
An email channel can record its whole mailbox in the workspace chat store, beside the mail the agent
|
package/README.md
CHANGED
|
@@ -132,6 +132,7 @@ See [Sandbox](#sandbox).
|
|
|
132
132
|
| `channels.<name>.kind` | the name | A channel not named after its kind, such as `sales_whatsapp`, says its kind and takes that kind's settings: several bots, numbers, apps or mailboxes on one agent; see `docs/agent.md`, "Channels by name" |
|
|
133
133
|
| `channels.<name>.receive` | `"webhook"` | A workspace channel (`kind: "custom"`, defined with `defineChannel`): `webhook`, its provider calls it, or `poll`, the platform wakes it every `checkAfterMinutes`; see `docs/agent.md`, "Workspace channels" |
|
|
134
134
|
| `channels.<name>.secret` | none | A workspace channel's workspace secret, which its `verify` checks deliveries against with `signedWith` or `matches`; only the platform reads it |
|
|
135
|
+
| `channels.<name>.record` | `"agent"` | A WhatsApp or workspace channel: `"all"` keeps every message it receives in its chats, those of people the agent does not admit among them, without a member; see `docs/agent.md`, "Recording every message" |
|
|
135
136
|
| `models.stt` | `"spacexai/grok-stt"` | The AI Gateway transcription model for voice messages; `false` leaves them untranscribed |
|
|
136
137
|
| `models.imageDescription` | `google/gemini-2.5-flash-lite` | Image evidence for group routing even with native vision; `false` disables descriptions |
|
|
137
138
|
| `models.decision` | `"typesafe-ai/jev-1.14.0"` | The AI Gateway decision model of the inbound router |
|
|
@@ -4,7 +4,7 @@ import { createRequire as __eveCreateRequire } from "node:module";
|
|
|
4
4
|
const __filename = __eveFileURLToPath(import.meta.url);
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
|
-
var version = "0.
|
|
7
|
+
var version = "0.76.1";
|
|
8
8
|
function agentBuild(environment = process.env) {
|
|
9
9
|
return {
|
|
10
10
|
agent: version,
|
|
@@ -7,9 +7,9 @@ __eveCreateRequire(import.meta.url);
|
|
|
7
7
|
import { parseArchivedMessage } from "../extension/lib/telegram/archive-message.mjs";
|
|
8
8
|
import { currentChannel, currentKey } from "../extension/lib/channel-scope.mjs";
|
|
9
9
|
import { n as contentText, t as CONTENT_CAPS } from "./content-cDtVnr8Y.mjs";
|
|
10
|
-
import { C as storedFiles, S as sendFingerprint, _ as cutText, a as chatEvent, b as metaOf, d as sessionFailureEventId, f as storeOf, g as boundedMeta, x as reasonCode, y as messageInput } from "./chat-archive-
|
|
10
|
+
import { C as storedFiles, S as sendFingerprint, _ as cutText, a as chatEvent, b as metaOf, d as sessionFailureEventId, f as storeOf, g as boundedMeta, x as reasonCode, y as messageInput } from "./chat-archive-CUMEaSqy.mjs";
|
|
11
11
|
import { ChatStoreError } from "../extension/lib/chat-store.mjs";
|
|
12
|
-
import { c as currentInboundRequest, ht as currentThreadId, xt as reportTelegramError } from "./principal-
|
|
12
|
+
import { c as currentInboundRequest, ht as currentThreadId, xt as reportTelegramError } from "./principal-C7aAjyt4.mjs";
|
|
13
13
|
import { currentConfirmationPrompt } from "../extension/lib/group-routing/messages.mjs";
|
|
14
14
|
import { messageMetadata } from "../extension/lib/telegram/message-metadata.mjs";
|
|
15
15
|
import { reportMembership } from "../extension/lib/telegram/membership.mjs";
|
|
@@ -286,6 +286,8 @@ export interface TelegramChannelInput {
|
|
|
286
286
|
export interface WhatsAppChannelInput {
|
|
287
287
|
/** The key of the workspace's `WhatsAppConnection`, such as `whatsapp`. */
|
|
288
288
|
readonly connection: string;
|
|
289
|
+
/** Which messages the channel records: {@link RecordSetting}. */
|
|
290
|
+
readonly record?: RecordSetting;
|
|
289
291
|
}
|
|
290
292
|
/** `channels.slack`, or a channel of kind `slack`, as authored. */
|
|
291
293
|
export interface SlackChannelInput {
|
|
@@ -344,7 +346,16 @@ export interface WorkspaceChannelInput {
|
|
|
344
346
|
* @deprecated Name a verification value of the channel's connection with `input`.
|
|
345
347
|
*/
|
|
346
348
|
readonly secret?: string;
|
|
349
|
+
/** Which messages the channel records: {@link RecordSetting}. */
|
|
350
|
+
readonly record?: RecordSetting;
|
|
347
351
|
}
|
|
352
|
+
/**
|
|
353
|
+
* Which messages a WhatsApp or workspace channel records in the chat: `agent`, the default, those
|
|
354
|
+
* the agent takes, as every channel does; `all`, every message it receives, the messages of people
|
|
355
|
+
* the agent does not admit among them, recorded without a member and `skipped` with a reason code.
|
|
356
|
+
* Under `all` no turn starts that would not start under `agent`, and nobody becomes a user.
|
|
357
|
+
*/
|
|
358
|
+
export type RecordSetting = "agent" | "all";
|
|
348
359
|
/** A channel named other than its kind, as authored: its settings and its `kind`. */
|
|
349
360
|
export type NamedChannelInput = ({
|
|
350
361
|
readonly kind: "telegram";
|
|
@@ -579,6 +590,8 @@ export declare class SegmentStreamAgentConfigError extends Error {
|
|
|
579
590
|
*/
|
|
580
591
|
export interface WhatsAppSettings {
|
|
581
592
|
readonly connection: string;
|
|
593
|
+
/** `all` when the channel records every message it receives; absent records the agent's. */
|
|
594
|
+
readonly record?: "all";
|
|
582
595
|
}
|
|
583
596
|
/**
|
|
584
597
|
* The Slack channel: the bot of the workspace's `SlackConnection`, through the Slack app
|
|
@@ -633,6 +646,8 @@ export interface WorkspaceChannelSettings {
|
|
|
633
646
|
readonly input?: string;
|
|
634
647
|
/** The workspace secret they are checked against: the older form of `input`. */
|
|
635
648
|
readonly secret?: string;
|
|
649
|
+
/** `all` when the channel records every message it receives; absent records the agent's. */
|
|
650
|
+
readonly record?: "all";
|
|
636
651
|
}
|
|
637
652
|
/**
|
|
638
653
|
* The web the agent may read. `domains` are bare lower-case host names, such as `example.com`;
|
|
@@ -193,14 +193,27 @@ function section(input) {
|
|
|
193
193
|
function isTelegramPolicy(value) {
|
|
194
194
|
return TELEGRAM_POLICIES.some((policy) => policy === value);
|
|
195
195
|
}
|
|
196
|
+
function recordSetting(value, path, issues) {
|
|
197
|
+
if (value === void 0 || value === "agent") return {};
|
|
198
|
+
if (value === "all") return { record: "all" };
|
|
199
|
+
issues.push({
|
|
200
|
+
message: "must be \"agent\" or \"all\"",
|
|
201
|
+
path: [...path, "record"]
|
|
202
|
+
});
|
|
203
|
+
}
|
|
196
204
|
function whatsappSettings(value, issues, path = ["channels", "whatsapp"]) {
|
|
197
205
|
const whatsapp = section({
|
|
198
206
|
value,
|
|
199
207
|
path,
|
|
200
|
-
allowed: [
|
|
208
|
+
allowed: [
|
|
209
|
+
"connection",
|
|
210
|
+
"kind",
|
|
211
|
+
"record"
|
|
212
|
+
],
|
|
201
213
|
issues
|
|
202
214
|
});
|
|
203
215
|
if (whatsapp === void 0) return null;
|
|
216
|
+
const record = recordSetting(whatsapp.record, path, issues);
|
|
204
217
|
if (typeof whatsapp.connection !== "string" || !CONNECTION_KEY.test(whatsapp.connection)) {
|
|
205
218
|
issues.push({
|
|
206
219
|
message: "must be a connection key such as whatsapp",
|
|
@@ -208,7 +221,10 @@ function whatsappSettings(value, issues, path = ["channels", "whatsapp"]) {
|
|
|
208
221
|
});
|
|
209
222
|
return null;
|
|
210
223
|
}
|
|
211
|
-
return
|
|
224
|
+
return record === void 0 ? null : {
|
|
225
|
+
connection: whatsapp.connection,
|
|
226
|
+
...record
|
|
227
|
+
};
|
|
212
228
|
}
|
|
213
229
|
function slackSettings(value, issues, path = ["channels", "slack"]) {
|
|
214
230
|
const slack = section({
|
|
@@ -254,12 +270,14 @@ function workspaceChannelSettings(value, issues, path) {
|
|
|
254
270
|
"receive",
|
|
255
271
|
"checkAfterMinutes",
|
|
256
272
|
"input",
|
|
257
|
-
"secret"
|
|
273
|
+
"secret",
|
|
274
|
+
"record"
|
|
258
275
|
],
|
|
259
276
|
issues
|
|
260
277
|
});
|
|
261
278
|
if (channel === void 0) return null;
|
|
262
279
|
const before = issues.length;
|
|
280
|
+
const record = recordSetting(channel.record, path, issues);
|
|
263
281
|
if (typeof channel.connection !== "string" || !CONNECTION_KEY.test(channel.connection)) issues.push({
|
|
264
282
|
message: "must be the key of the connection the channel's code calls its provider through",
|
|
265
283
|
path: [...path, "connection"]
|
|
@@ -296,11 +314,13 @@ function workspaceChannelSettings(value, issues, path) {
|
|
|
296
314
|
connection: channel.connection,
|
|
297
315
|
receive,
|
|
298
316
|
checkAfterMinutes: minutes,
|
|
299
|
-
...secret
|
|
317
|
+
...secret,
|
|
318
|
+
...record
|
|
300
319
|
} : {
|
|
301
320
|
connection: channel.connection,
|
|
302
321
|
receive: "webhook",
|
|
303
|
-
...secret
|
|
322
|
+
...secret,
|
|
323
|
+
...record
|
|
304
324
|
};
|
|
305
325
|
}
|
|
306
326
|
const MAXIMUM_WEB_DOMAINS = 50;
|
|
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
|
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
7
|
import segmentstream from "../extension.mjs";
|
|
8
|
-
import { T as ontologyConnection } from "../../_chunks/principal-
|
|
8
|
+
import { T as ontologyConnection } from "../../_chunks/principal-C7aAjyt4.mjs";
|
|
9
9
|
import { defineDynamic } from "eve/connections";
|
|
10
10
|
var ontology_default = defineDynamic(async (context) => {
|
|
11
11
|
if (!segmentstream.config.ontology.connection) return null;
|
|
@@ -25,7 +25,7 @@ export default segmentstream;
|
|
|
25
25
|
* runtime's own definition, offered here so that the agent's files import only this package.
|
|
26
26
|
*/
|
|
27
27
|
export { defineAgent } from "eve";
|
|
28
|
-
export { DEFAULT_DECISION_MODEL, DEFAULT_STT_MODEL, DEFAULT_ADMISSION_LIMITS, SegmentStreamAgentConfigError, manifestOf, type ChatModelChoice, type AdmissionLimits, type AdmissionLimitsInput, type AdmissionSettings, type AdmissionReplies, type FirstContactSettings, type LocalizedText, type SegmentStreamAgentConfig, type SegmentStreamAgentConfigInput, type SessionScope, type SessionSettings, type TelegramPolicy, type TelegramSettings, type WebSettings, type BrowserSettings, type BrowserSettingsInput, type BrowserProxySettings, type WorkspaceChannelInput, type WorkspaceChannelSettings, } from "./config.js";
|
|
28
|
+
export { DEFAULT_DECISION_MODEL, DEFAULT_STT_MODEL, DEFAULT_ADMISSION_LIMITS, SegmentStreamAgentConfigError, manifestOf, type ChatModelChoice, type AdmissionLimits, type AdmissionLimitsInput, type AdmissionSettings, type AdmissionReplies, type FirstContactSettings, type LocalizedText, type RecordSetting, type SegmentStreamAgentConfig, type SegmentStreamAgentConfigInput, type SessionScope, type SessionSettings, type TelegramPolicy, type TelegramSettings, type WebSettings, type BrowserSettings, type BrowserSettingsInput, type BrowserProxySettings, type WorkspaceChannelInput, type WorkspaceChannelSettings, } from "./config.js";
|
|
29
29
|
/**
|
|
30
30
|
* Defines a channel in the workspace's own code, `agent/agent/channels/<name>.ts`, for a provider
|
|
31
31
|
* the platform has no channel for: the code receives, reads and sends, the platform does the rest.
|
|
@@ -7,7 +7,7 @@ __eveCreateRequire(import.meta.url);
|
|
|
7
7
|
import segmentstream from "../extension.mjs";
|
|
8
8
|
import { localizedText } from "../lib/admission.mjs";
|
|
9
9
|
import { confirmationLocale } from "../lib/telegram/confirmation-text.mjs";
|
|
10
|
-
import "../../_chunks/principal-
|
|
10
|
+
import "../../_chunks/principal-C7aAjyt4.mjs";
|
|
11
11
|
import { defineHook } from "eve/hooks";
|
|
12
12
|
var authorization_default = defineHook({ events: { "interaction.opened": (event, context) => {
|
|
13
13
|
const principal = context.session.auth.current;
|
|
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
|
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
7
|
import segmentstream from "../extension.mjs";
|
|
8
|
-
import { r as chatArchive } from "../../_chunks/chat-archive-
|
|
8
|
+
import { r as chatArchive } from "../../_chunks/chat-archive-CUMEaSqy.mjs";
|
|
9
9
|
import { chatContextHook } from "../lib/chat-context.mjs";
|
|
10
10
|
import { appOrigin } from "../lib/environment.mjs";
|
|
11
11
|
import { agentSessionReviews } from "../lib/review/client.mjs";
|
|
@@ -6,7 +6,7 @@ __eveDirname(__filename);
|
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
7
|
import segmentstream from "../extension.mjs";
|
|
8
8
|
import { chatRecorder } from "../lib/chat-recorder.mjs";
|
|
9
|
-
import { r as chatArchive } from "../../_chunks/chat-archive-
|
|
9
|
+
import { r as chatArchive } from "../../_chunks/chat-archive-CUMEaSqy.mjs";
|
|
10
10
|
import { repliesReviewed } from "../lib/review/hold.mjs";
|
|
11
11
|
import { defineHook } from "eve/hooks";
|
|
12
12
|
var chat_recorder_default = defineHook({ events: { "*": chatRecorder(chatArchive(), (principal) => repliesReviewed(segmentstream.config.review, principal)) } });
|
|
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
|
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
7
|
import segmentstream from "../extension.mjs";
|
|
8
|
-
import { a as rolesOf } from "../../_chunks/principal-
|
|
8
|
+
import { a as rolesOf } from "../../_chunks/principal-C7aAjyt4.mjs";
|
|
9
9
|
import { personaFor } from "../personas.mjs";
|
|
10
10
|
import { defineDynamic, defineInstructions } from "eve/instructions";
|
|
11
11
|
var persona_default = defineDynamic((context) => {
|
|
@@ -4,4 +4,4 @@ import { createRequire as __eveCreateRequire } from "node:module";
|
|
|
4
4
|
const __filename = __eveFileURLToPath(import.meta.url);
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
|
-
export { R as ACT_AS_HEADER, z as ActorRequiredError, B as actorHeaders, V as actorKey, H as actorOf, U as isGuestSession, W as member, G as memberTool, K as notForGuests } from "../../_chunks/principal-
|
|
7
|
+
export { R as ACT_AS_HEADER, z as ActorRequiredError, B as actorHeaders, V as actorKey, H as actorOf, U as isGuestSession, W as member, G as memberTool, K as notForGuests } from "../../_chunks/principal-C7aAjyt4.mjs";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { AdmissionSettings, LocalizedText } from "../config.js";
|
|
2
|
-
import type
|
|
1
|
+
import type { AdmissionSettings, LocalizedText, RecordSetting } from "../config.js";
|
|
2
|
+
import { type AgentIdentities, type IdentityResolution, type ResolveIdentityInput } from "./identities.js";
|
|
3
3
|
/** Sender language, then English, then the first configured entry. No platform copy. */
|
|
4
4
|
export declare function localizedText(texts: LocalizedText | undefined, languageCode?: string): string | undefined;
|
|
5
5
|
/** The private chat a message arrived in, as the chat archive keys it. */
|
|
@@ -14,7 +14,10 @@ export interface AdmittedChat {
|
|
|
14
14
|
/**
|
|
15
15
|
* Channel-independent admission and at-least-once versioned notice delivery. A private chat a
|
|
16
16
|
* member of staff took over comes back `handled`: the channel records the message with
|
|
17
|
-
* `recordHandledMessage`, or as it records every message, and starts no turn.
|
|
17
|
+
* `recordHandledMessage`, or as it records every message, and starts no turn. On a channel that
|
|
18
|
+
* records every message (`record: "all"`), the private chat of someone who is no user is reported
|
|
19
|
+
* without a member, so that the inbox registers it where the ontology's `inbox.channels` lists the
|
|
20
|
+
* channel; admission itself is the same, and makes nobody a user it would not make one.
|
|
18
21
|
*/
|
|
19
22
|
export declare function admitMessage(input: {
|
|
20
23
|
readonly identity: ResolveIdentityInput;
|
|
@@ -27,4 +30,6 @@ export declare function admitMessage(input: {
|
|
|
27
30
|
readonly chat?: AdmittedChat;
|
|
28
31
|
/** A failed inbox report; by default it is logged. */
|
|
29
32
|
readonly inboxFailed?: (error: unknown) => void;
|
|
33
|
+
/** Which messages the channel records; `agent` by default. */
|
|
34
|
+
readonly record?: RecordSetting;
|
|
30
35
|
}): Promise<IdentityResolution>;
|
|
@@ -4,6 +4,7 @@ import { createRequire as __eveCreateRequire } from "node:module";
|
|
|
4
4
|
const __filename = __eveFileURLToPath(import.meta.url);
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
|
+
import { AgentIdentityError } from "./identities.mjs";
|
|
7
8
|
import { createHash } from "node:crypto";
|
|
8
9
|
function localizedText(texts, languageCode) {
|
|
9
10
|
if (texts === void 0) return;
|
|
@@ -28,7 +29,7 @@ const INBOX_REPORTS_REMEMBERED = 1e3;
|
|
|
28
29
|
const inboxReports = new Map();
|
|
29
30
|
async function reportInboxChat(input) {
|
|
30
31
|
const { chat, identity } = input;
|
|
31
|
-
const key = `${chat.channel}:${chat.chatId}`;
|
|
32
|
+
const key = `${chat.channel}:${chat.chatId}:${input.memberId ?? ""}`;
|
|
32
33
|
const now = Date.now();
|
|
33
34
|
const last = inboxReports.get(key);
|
|
34
35
|
if (!input.every && last !== void 0 && now - last < INBOX_REPORT_INTERVAL_MS) return;
|
|
@@ -43,17 +44,21 @@ async function reportInboxChat(input) {
|
|
|
43
44
|
provider: chat.channel,
|
|
44
45
|
externalId: chat.chatId,
|
|
45
46
|
title: (identity.display?.trim() || identity.externalId).slice(0, 200),
|
|
46
|
-
memberId: input.memberId,
|
|
47
|
+
...input.memberId === void 0 ? {} : { memberId: input.memberId },
|
|
47
48
|
kind: "private",
|
|
48
49
|
...chat.recipient === void 0 || chat.recipient === chat.chatId ? {} : { recipient: chat.recipient },
|
|
49
50
|
...chat.threadId === void 0 || chat.threadId === "" ? {} : { threadId: chat.threadId }
|
|
50
51
|
});
|
|
51
52
|
} catch (error) {
|
|
53
|
+
if (input.memberId === void 0 && error instanceof AgentIdentityError && error.status === 404) return;
|
|
52
54
|
inboxReports.delete(key);
|
|
53
55
|
input.failed?.(error);
|
|
54
56
|
return;
|
|
55
57
|
}
|
|
56
58
|
}
|
|
59
|
+
function noUser(resolution) {
|
|
60
|
+
return resolution.status === "pairing_required" || resolution.status === "limited" && resolution.scope === "newUsersPerHour";
|
|
61
|
+
}
|
|
57
62
|
async function admitMessage(input) {
|
|
58
63
|
const firstContact = input.settings.firstContact;
|
|
59
64
|
const notice = localizedText(firstContact?.notice, input.languageCode);
|
|
@@ -91,6 +96,13 @@ async function admitMessage(input) {
|
|
|
91
96
|
handled: true
|
|
92
97
|
};
|
|
93
98
|
}
|
|
99
|
+
if (input.record === "all" && noUser(resolved) && input.identity.chat === "private" && input.chat !== void 0) await reportInboxChat({
|
|
100
|
+
identity: input.identity,
|
|
101
|
+
identities: input.identities,
|
|
102
|
+
chat: input.chat,
|
|
103
|
+
every: false,
|
|
104
|
+
failed: input.inboxFailed ?? ((error) => console.error("[segmentstream] inbox chat report failed", error))
|
|
105
|
+
});
|
|
94
106
|
return resolved;
|
|
95
107
|
}
|
|
96
108
|
export { admitMessage, localizedText };
|
|
@@ -4,7 +4,7 @@ import { createRequire as __eveCreateRequire } from "node:module";
|
|
|
4
4
|
const __filename = __eveFileURLToPath(import.meta.url);
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
|
-
import { Ft as chatChannel, Pt as chatAddressOf, b as agentAttachments, i as memberIdOf } from "../../_chunks/principal-
|
|
7
|
+
import { Ft as chatChannel, Pt as chatAddressOf, b as agentAttachments, i as memberIdOf } from "../../_chunks/principal-C7aAjyt4.mjs";
|
|
8
8
|
import { detectFile, documentText } from "./attachment-formats.mjs";
|
|
9
9
|
import { readSheets, typedTable } from "./attachment-tables.mjs";
|
|
10
10
|
import { appOrigin } from "./environment.mjs";
|
|
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
|
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
7
|
import { attachmentOwner } from "./attachment-tools.mjs";
|
|
8
|
-
import { Pt as chatAddressOf, _ as AttachmentError, yt as failureText } from "../../_chunks/principal-
|
|
8
|
+
import { Pt as chatAddressOf, _ as AttachmentError, yt as failureText } from "../../_chunks/principal-C7aAjyt4.mjs";
|
|
9
9
|
import { appOrigin, channelsEnabled } from "./environment.mjs";
|
|
10
10
|
import { transientFileStatus } from "./file-grant.mjs";
|
|
11
11
|
import { runtimeToken } from "./runtime-token.mjs";
|
|
@@ -4,4 +4,4 @@ import { createRequire as __eveCreateRequire } from "node:module";
|
|
|
4
4
|
const __filename = __eveFileURLToPath(import.meta.url);
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
|
-
export { h as ATTACHMENT_TTL_HOURS, g as ATTACHMENT_URL_PROTOCOL, _ as AttachmentError, jt as CHAT_HEADER, v as EARLIER_CHAT_HEADER, y as MAXIMUM_ATTACHMENT_BYTES, Nt as SESSION_HEADER, b as agentAttachments, x as attachmentUrl, S as fetchStoredAttachment, C as parseAttachmentUrl } from "../../_chunks/principal-
|
|
7
|
+
export { h as ATTACHMENT_TTL_HOURS, g as ATTACHMENT_URL_PROTOCOL, _ as AttachmentError, jt as CHAT_HEADER, v as EARLIER_CHAT_HEADER, y as MAXIMUM_ATTACHMENT_BYTES, Nt as SESSION_HEADER, b as agentAttachments, x as attachmentUrl, S as fetchStoredAttachment, C as parseAttachmentUrl } from "../../_chunks/principal-C7aAjyt4.mjs";
|
|
@@ -4,4 +4,4 @@ import { createRequire as __eveCreateRequire } from "node:module";
|
|
|
4
4
|
const __filename = __eveFileURLToPath(import.meta.url);
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
|
-
export { t as agentBuild } from "../../_chunks/build-metadata-
|
|
7
|
+
export { t as agentBuild } from "../../_chunks/build-metadata-rKN9hmJm.mjs";
|
|
@@ -4,4 +4,4 @@ import { createRequire as __eveCreateRequire } from "node:module";
|
|
|
4
4
|
const __filename = __eveFileURLToPath(import.meta.url);
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
|
-
export { At as CHAT_ATTRIBUTE, jt as CHAT_HEADER, Mt as RUNTIME_SOURCE_ATTRIBUTE, Nt as SESSION_HEADER, Pt as chatAddressOf, Ft as chatChannel, It as chatHeaders, Lt as chatRuntimeSource, Rt as isSameChat, zt as withChatAddress, Bt as workspaceIdentityProvider } from "../../_chunks/principal-
|
|
7
|
+
export { At as CHAT_ATTRIBUTE, jt as CHAT_HEADER, Mt as RUNTIME_SOURCE_ATTRIBUTE, Nt as SESSION_HEADER, Pt as chatAddressOf, Ft as chatChannel, It as chatHeaders, Lt as chatRuntimeSource, Rt as isSameChat, zt as withChatAddress, Bt as workspaceIdentityProvider } from "../../_chunks/principal-C7aAjyt4.mjs";
|
|
@@ -62,6 +62,12 @@ export interface ChatEvent {
|
|
|
62
62
|
* alone, never sent to the chat archive in Cloud.
|
|
63
63
|
*/
|
|
64
64
|
readonly parts?: ReadonlyArray<ChatPart>;
|
|
65
|
+
/**
|
|
66
|
+
* History the workspace imported from before the chat was recorded, as the workspace chat store
|
|
67
|
+
* marks it: a session reads it when it starts, never as new. The chat archive in Cloud orders it
|
|
68
|
+
* before every row it recorded instead, by a negative sequence.
|
|
69
|
+
*/
|
|
70
|
+
readonly imported?: boolean;
|
|
65
71
|
}
|
|
66
72
|
export interface ChatPage {
|
|
67
73
|
readonly events: ReadonlyArray<ChatEvent & {
|
|
@@ -4,4 +4,4 @@ import { createRequire as __eveCreateRequire } from "node:module";
|
|
|
4
4
|
const __filename = __eveFileURLToPath(import.meta.url);
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
|
-
export { t as AGENT_SENDER, n as archiveSequence, r as chatArchive, i as chatAuthor, a as chatEvent, o as cloudChatArchive, s as collapseChatEvents, c as forgetChatStores, l as replyEvent, u as replyOperation, d as sessionFailureEventId, f as storeOf, p as summarizeArguments, m as topicContext } from "../../_chunks/chat-archive-
|
|
7
|
+
export { t as AGENT_SENDER, n as archiveSequence, r as chatArchive, i as chatAuthor, a as chatEvent, o as cloudChatArchive, s as collapseChatEvents, c as forgetChatStores, l as replyEvent, u as replyOperation, d as sessionFailureEventId, f as storeOf, p as summarizeArguments, m as topicContext } from "../../_chunks/chat-archive-CUMEaSqy.mjs";
|
|
@@ -6,8 +6,8 @@ __eveDirname(__filename);
|
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
7
|
import { agentTaskIdOf } from "./agent-task.mjs";
|
|
8
8
|
import { chatCoordinates, sessionKind } from "./chat-recorder.mjs";
|
|
9
|
-
import { f as storeOf, i as chatAuthor, m as topicContext, n as archiveSequence, r as chatArchive, s as collapseChatEvents } from "../../_chunks/chat-archive-
|
|
10
|
-
import { xt as reportTelegramError } from "../../_chunks/principal-
|
|
9
|
+
import { f as storeOf, i as chatAuthor, m as topicContext, n as archiveSequence, r as chatArchive, s as collapseChatEvents } from "../../_chunks/chat-archive-CUMEaSqy.mjs";
|
|
10
|
+
import { xt as reportTelegramError } from "../../_chunks/principal-C7aAjyt4.mjs";
|
|
11
11
|
import { createHash } from "node:crypto";
|
|
12
12
|
import { deliveries, runs, turns } from "eve/events";
|
|
13
13
|
import { defineState } from "eve/context";
|
|
@@ -172,8 +172,9 @@ async function readChatContext(input) {
|
|
|
172
172
|
const delivering = new Set(input.delivering);
|
|
173
173
|
const messages = collapseChatEvents(unread.filter((event) => since === void 0 || Date.parse(event.storedAt) >= since)).filter((event) => {
|
|
174
174
|
const changed = event.kind === "inbound" && (edited(event) || event.deleted === true);
|
|
175
|
+
if (event.imported === true && !bootstrap && !changed) return false;
|
|
175
176
|
return (event.kind === "inbound" || event.kind === "outbound" && ["completed", "sent"].includes(event.status ?? "")) && !(event.kind === "inbound" && event.messageId !== null && delivering.has(event.messageId)) && (changed || !(event.kind === "inbound" && event.messageId !== null && delivered.has(event.messageId)) && (bootstrap || event.sessionId !== input.sessionId));
|
|
176
|
-
}).sort((first, second) => sequence(first) < sequence(second) ? 1 : -1);
|
|
177
|
+
}).sort(workspace && bootstrap ? (first, second) => Date.parse(second.at) - Date.parse(first.at) || (sequence(first) < sequence(second) ? 1 : -1) : (first, second) => sequence(first) < sequence(second) ? 1 : -1);
|
|
177
178
|
const budget = bootstrap ? BOOTSTRAP_CHARACTERS : TURN_CHARACTERS;
|
|
178
179
|
const selected = [];
|
|
179
180
|
let characters = 2;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { RecordSetting } from "../config.js";
|
|
1
2
|
import type { AdmittedChat } from "./admission.js";
|
|
2
3
|
import { type ChatArchive, type ChatAuthor } from "./chat-archive.js";
|
|
3
4
|
import type { ChatPart, StoredFile } from "./chat-store.js";
|
|
@@ -149,21 +150,54 @@ export type SentOutsideOutcome =
|
|
|
149
150
|
| "no_chat"
|
|
150
151
|
/** The archive holds the message already, such as the agent's own reply a provider echoes. */
|
|
151
152
|
| "known";
|
|
153
|
+
/** How a channel records a message outside a turn: its `record` setting, `agent` by default. */
|
|
154
|
+
export interface RecordOptions {
|
|
155
|
+
readonly record?: RecordSetting;
|
|
156
|
+
}
|
|
152
157
|
/**
|
|
153
158
|
* Records what the workspace's side wrote in a person's chat outside the agent, such as a reply
|
|
154
159
|
* from the provider's own app: an `outbound` message of a human, or of a program when the provider
|
|
155
160
|
* says so, which starts no turn. Only a chat the agent already has with the person is recorded, its
|
|
156
161
|
* members those of its latest message, so a number's or a mailbox's other conversations stay out of
|
|
157
|
-
* the archive.
|
|
162
|
+
* the archive. On a channel that records every message (`record: "all"`), a chat the agent has
|
|
163
|
+
* none of is recorded too, without members, in the workspace chat store. A message the archive
|
|
164
|
+
* holds by its provider id is skipped.
|
|
158
165
|
*/
|
|
159
|
-
export declare function recordSentOutside(archive: ChatArchive, message: Omit<RecordedMessage, "participantIds" | "direction"
|
|
166
|
+
export declare function recordSentOutside(archive: ChatArchive, message: Omit<RecordedMessage, "participantIds" | "direction">, options?: RecordOptions): Promise<SentOutsideOutcome>;
|
|
160
167
|
/**
|
|
161
168
|
* Records a person's message the agent cannot read, such as a contact card on a channel that
|
|
162
169
|
* reads only text and files, in the chat the agent has with them, by the same rule as
|
|
163
170
|
* {@link recordSentOutside}, with `reason` as what the agent did with it: it starts no turn. Only
|
|
164
171
|
* the workspace chat store keeps it; nothing is written to the chat archive in Cloud.
|
|
165
172
|
*/
|
|
166
|
-
export declare function recordUnreadMessage(archive: ChatArchive, message: Omit<RecordedMessage, "participantIds" | "direction" | "by">, reason: string): Promise<SentOutsideOutcome | "dropped">;
|
|
173
|
+
export declare function recordUnreadMessage(archive: ChatArchive, message: Omit<RecordedMessage, "participantIds" | "direction" | "by">, reason: string, options?: RecordOptions): Promise<SentOutsideOutcome | "dropped">;
|
|
174
|
+
/** Why the agent took no turn for a message whose sender it did not admit, as a code. */
|
|
175
|
+
export type UnadmittedReason = "identity_unknown" | "identity_refused" | "limited";
|
|
176
|
+
/**
|
|
177
|
+
* A person's message on a channel that records every message (`record: "all"`), whose sender the
|
|
178
|
+
* agent did not admit: someone who is no user, a refused account, or one over a limit.
|
|
179
|
+
*/
|
|
180
|
+
export interface UnadmittedMessage {
|
|
181
|
+
readonly channel: string;
|
|
182
|
+
readonly chatId: string;
|
|
183
|
+
/** The person's account at the provider. */
|
|
184
|
+
readonly senderId: string;
|
|
185
|
+
readonly senderName?: string | null;
|
|
186
|
+
readonly messageId: string;
|
|
187
|
+
readonly text: string;
|
|
188
|
+
/** Its files, by what the provider says of them: nothing of them is stored. */
|
|
189
|
+
readonly files?: ReadonlyArray<RecordedFile>;
|
|
190
|
+
readonly replyTo?: string;
|
|
191
|
+
readonly parts?: ReadonlyArray<ChatPart>;
|
|
192
|
+
readonly at?: string;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Records the message of a sender the agent did not admit, on a channel that records every
|
|
196
|
+
* message, in the workspace chat store: by its provider id, with no member, so that only staff
|
|
197
|
+
* whose `agent_chat:read` holds the chat read it, and `skipped` with `reason`. It starts no turn
|
|
198
|
+
* and makes nobody a user. True when recorded; nothing is recorded on the chat archive in Cloud.
|
|
199
|
+
*/
|
|
200
|
+
export declare function recordUnadmittedMessage(archive: ChatArchive, message: UnadmittedMessage, reason: UnadmittedReason): Promise<boolean>;
|
|
167
201
|
/**
|
|
168
202
|
* Records a person's message in a private chat a member of the workspace took over, which starts
|
|
169
203
|
* no turn: the inbox shows it, and the agent reads it in its context once the chat is handed back.
|
|
@@ -4,7 +4,7 @@ import { createRequire as __eveCreateRequire } from "node:module";
|
|
|
4
4
|
const __filename = __eveFileURLToPath(import.meta.url);
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
|
-
import { C as storedFiles, a as chatEvent, f as storeOf, h as UNVERIFIED } from "../../_chunks/chat-archive-
|
|
7
|
+
import { C as storedFiles, a as chatEvent, f as storeOf, h as UNVERIFIED } from "../../_chunks/chat-archive-CUMEaSqy.mjs";
|
|
8
8
|
const MAXIMUM_PARTS = 20;
|
|
9
9
|
const PART_BOUNDS = {
|
|
10
10
|
text: 1024,
|
|
@@ -170,20 +170,20 @@ async function recordChatMessage(archive, message) {
|
|
|
170
170
|
}))
|
|
171
171
|
}));
|
|
172
172
|
}
|
|
173
|
-
async function recordSentOutside(archive, message) {
|
|
173
|
+
async function recordSentOutside(archive, message, options = {}) {
|
|
174
174
|
return recordInChat(archive, {
|
|
175
175
|
...message,
|
|
176
176
|
direction: "outbound"
|
|
177
|
-
});
|
|
177
|
+
}, options);
|
|
178
178
|
}
|
|
179
|
-
async function recordUnreadMessage(archive, message, reason) {
|
|
179
|
+
async function recordUnreadMessage(archive, message, reason, options = {}) {
|
|
180
180
|
const store = await storeOf(archive);
|
|
181
181
|
if (store === void 0) return "dropped";
|
|
182
182
|
const outcome = await recordInChat(archive, {
|
|
183
183
|
...message,
|
|
184
184
|
direction: "inbound",
|
|
185
185
|
by: "human"
|
|
186
|
-
});
|
|
186
|
+
}, options);
|
|
187
187
|
if (outcome === "recorded") await store.change({
|
|
188
188
|
channel: message.provider,
|
|
189
189
|
chatId: message.chatId,
|
|
@@ -194,7 +194,7 @@ async function recordUnreadMessage(archive, message, reason) {
|
|
|
194
194
|
});
|
|
195
195
|
return outcome;
|
|
196
196
|
}
|
|
197
|
-
async function recordInChat(archive, message) {
|
|
197
|
+
async function recordInChat(archive, message, options) {
|
|
198
198
|
const chat = {
|
|
199
199
|
provider: message.provider,
|
|
200
200
|
chatId: message.chatId,
|
|
@@ -204,7 +204,14 @@ async function recordInChat(archive, message) {
|
|
|
204
204
|
...chat,
|
|
205
205
|
limit: 1
|
|
206
206
|
})).events;
|
|
207
|
-
if (latest === void 0)
|
|
207
|
+
if (latest === void 0) {
|
|
208
|
+
if (options.record !== "all" || await storeOf(archive) === void 0) return "no_chat";
|
|
209
|
+
await recordChatMessage(archive, {
|
|
210
|
+
...message,
|
|
211
|
+
participantIds: []
|
|
212
|
+
});
|
|
213
|
+
return "recorded";
|
|
214
|
+
}
|
|
208
215
|
const [known] = (await archive.context({
|
|
209
216
|
...chat,
|
|
210
217
|
messageId: message.messageId,
|
|
@@ -217,6 +224,37 @@ async function recordInChat(archive, message) {
|
|
|
217
224
|
});
|
|
218
225
|
return "recorded";
|
|
219
226
|
}
|
|
227
|
+
async function recordUnadmittedMessage(archive, message, reason) {
|
|
228
|
+
const store = await storeOf(archive);
|
|
229
|
+
if (store === void 0) return false;
|
|
230
|
+
const chatId = message.chatId.slice(0, 256);
|
|
231
|
+
const messageId = message.messageId.slice(0, 512);
|
|
232
|
+
await recordChatMessage(archive, {
|
|
233
|
+
provider: message.channel,
|
|
234
|
+
chatId,
|
|
235
|
+
participantIds: [],
|
|
236
|
+
eventId: `unadmitted:${message.channel}:${chatId}:${messageId}`,
|
|
237
|
+
direction: "inbound",
|
|
238
|
+
by: "human",
|
|
239
|
+
senderId: message.senderId,
|
|
240
|
+
senderName: message.senderName ?? null,
|
|
241
|
+
messageId,
|
|
242
|
+
text: message.text,
|
|
243
|
+
...message.files === void 0 ? {} : { files: message.files },
|
|
244
|
+
...message.replyTo === void 0 ? {} : { replyTo: message.replyTo },
|
|
245
|
+
...message.parts === void 0 ? {} : { parts: message.parts },
|
|
246
|
+
...message.at === void 0 ? {} : { at: message.at }
|
|
247
|
+
});
|
|
248
|
+
await store.change({
|
|
249
|
+
channel: message.channel,
|
|
250
|
+
chatId,
|
|
251
|
+
messageId,
|
|
252
|
+
change: "disposition",
|
|
253
|
+
disposition: "skipped",
|
|
254
|
+
reason
|
|
255
|
+
});
|
|
256
|
+
return true;
|
|
257
|
+
}
|
|
220
258
|
async function recordHandledMessage(archive, input) {
|
|
221
259
|
const { chat } = input;
|
|
222
260
|
const eventId = `handled:${chat.channel}:${chat.chatId}:${input.messageId}`;
|
|
@@ -264,4 +302,4 @@ async function recordHandledMessage(archive, input) {
|
|
|
264
302
|
status: "completed"
|
|
265
303
|
}));
|
|
266
304
|
}
|
|
267
|
-
export { MAXIMUM_PARTS, applyChatChange, chatPart, chatParts, recordChatMessage, recordHandledMessage, recordReceivedMessage, recordSentOutside, recordUnreadMessage, stagedFiles };
|
|
305
|
+
export { MAXIMUM_PARTS, applyChatChange, chatPart, chatParts, recordChatMessage, recordHandledMessage, recordReceivedMessage, recordSentOutside, recordUnadmittedMessage, recordUnreadMessage, stagedFiles };
|