@segmentstream/agent 0.66.5 → 0.67.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/_chunks/{build-metadata-CZref5jF.mjs → build-metadata-DabL3CTC.mjs} +1 -1
  3. package/dist/_chunks/{principal-EHH4C9jM.mjs → principal-DYl7vqOp.mjs} +4 -1
  4. package/dist/extension/config.mjs +1 -1
  5. package/dist/extension/connections/ontology.mjs +1 -1
  6. package/dist/extension/hooks/authorization.mjs +1 -1
  7. package/dist/extension/instructions/persona.mjs +1 -1
  8. package/dist/extension/lib/actor.mjs +1 -1
  9. package/dist/extension/lib/attachment-tools.mjs +1 -1
  10. package/dist/extension/lib/attachments-send.mjs +1 -1
  11. package/dist/extension/lib/attachments.mjs +1 -1
  12. package/dist/extension/lib/build-metadata.mjs +1 -1
  13. package/dist/extension/lib/chat-address.mjs +1 -1
  14. package/dist/extension/lib/chat-context.mjs +6 -2
  15. package/dist/extension/lib/chat-messages.d.ts +4 -0
  16. package/dist/extension/lib/chat-messages.mjs +2 -1
  17. package/dist/extension/lib/chat-recorder.d.ts +14 -6
  18. package/dist/extension/lib/chat-recorder.mjs +13 -5
  19. package/dist/extension/lib/confirmations.mjs +1 -1
  20. package/dist/extension/lib/email/attachments-send.mjs +1 -1
  21. package/dist/extension/lib/email/channel.mjs +1 -1
  22. package/dist/extension/lib/guest-usage.mjs +1 -1
  23. package/dist/extension/lib/inbound-media/files.mjs +1 -1
  24. package/dist/extension/lib/inbound-media/index.mjs +1 -1
  25. package/dist/extension/lib/ontology-connection.mjs +1 -1
  26. package/dist/extension/lib/ontology-file-call.mjs +1 -1
  27. package/dist/extension/lib/ontology-tools.mjs +1 -1
  28. package/dist/extension/lib/review/hold.mjs +1 -1
  29. package/dist/extension/lib/review/reply.mjs +3 -3
  30. package/dist/extension/lib/role-skill.mjs +1 -1
  31. package/dist/extension/lib/runtime-envelope.mjs +1 -1
  32. package/dist/extension/lib/sent-files.mjs +1 -1
  33. package/dist/extension/lib/slack/adapter.d.ts +5 -2
  34. package/dist/extension/lib/slack/adapter.mjs +11 -1
  35. package/dist/extension/lib/slack/attachments-send.mjs +1 -1
  36. package/dist/extension/lib/slack/thread-history.d.ts +22 -0
  37. package/dist/extension/lib/slack/thread-history.mjs +46 -0
  38. package/dist/extension/lib/stored-files.mjs +1 -1
  39. package/dist/extension/lib/telegram/adapter.mjs +2 -2
  40. package/dist/extension/lib/telegram/attachment-description.mjs +1 -1
  41. package/dist/extension/lib/telegram/attachments-send.mjs +1 -1
  42. package/dist/extension/lib/telegram/callbacks.mjs +1 -1
  43. package/dist/extension/lib/telegram/chat-archive.mjs +1 -1
  44. package/dist/extension/lib/telegram/confirmations.d.ts +2 -0
  45. package/dist/extension/lib/telegram/confirmations.mjs +97 -2
  46. package/dist/extension/lib/telegram/customer-text.mjs +1 -1
  47. package/dist/extension/lib/telegram/files.mjs +1 -1
  48. package/dist/extension/lib/telegram/health.mjs +1 -1
  49. package/dist/extension/lib/telegram/held-approvals.mjs +1 -1
  50. package/dist/extension/lib/telegram/inbound-request.mjs +1 -1
  51. package/dist/extension/lib/telegram/inbound.mjs +1 -1
  52. package/dist/extension/lib/telegram/lifecycle.mjs +2 -2
  53. package/dist/extension/lib/telegram/principal.mjs +1 -1
  54. package/dist/extension/lib/telegram/session-recovery.mjs +1 -1
  55. package/dist/extension/lib/telegram/silent.mjs +1 -1
  56. package/dist/extension/lib/telegram/structured.mjs +1 -1
  57. package/dist/extension/lib/telegram/texts.d.ts +1 -0
  58. package/dist/extension/lib/telegram/texts.mjs +5 -0
  59. package/dist/extension/lib/telegram/turn-errors.mjs +1 -1
  60. package/dist/extension/lib/telegram/workspace-action.mjs +1 -1
  61. package/dist/extension/lib/web/auth.mjs +1 -1
  62. package/dist/extension/lib/web/channel.mjs +1 -1
  63. package/dist/extension/lib/whatsapp/adapter.mjs +1 -1
  64. package/dist/extension/lib/whatsapp/attachments-send.mjs +1 -1
  65. package/dist/extension/lib/whatsapp/files.mjs +1 -1
  66. package/dist/extension/lib/whatsapp/sent.mjs +2 -2
  67. package/dist/extension/lib/workspace-channel/attachments-send.mjs +1 -1
  68. package/dist/extension/lib/workspace-channel/channel.mjs +1 -1
  69. package/dist/extension/lib/workspace-source.mjs +1 -1
  70. package/dist/extension/model.mjs +1 -1
  71. package/dist/extension/tools/attachments_discard.mjs +1 -1
  72. package/dist/extension/tools/attachments_list.mjs +1 -1
  73. package/dist/extension/tools/attachments_promote.mjs +1 -1
  74. package/dist/extension/tools/attachments_read.mjs +1 -1
  75. package/dist/extension/tools/attachments_send.mjs +1 -1
  76. package/dist/extension/tools/attachments_stage.mjs +1 -1
  77. package/dist/extension/tools/attachments_table.mjs +1 -1
  78. package/dist/extension/tools/handoff.mjs +1 -1
  79. package/dist/extension/tools/questions_ask.mjs +1 -1
  80. package/dist/extension/tools/workspace_source.mjs +1 -1
  81. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.67.0
4
+
5
+ A chat session that reaches its usage limit (`limits.sessionUsage`) can be continued from Telegram.
6
+
7
+ - **Buttons.** The question now comes with two buttons, continue and stop, instead of a text that had to be answered with a typed reply. It holds the chat's session until it is answered, so in a group any member paired with the workspace may press either button, not only the person whose request reached the limit. The workspace supplies the words in the new optional `texts.usageLimit.{prompt,continue,stop}`; without them the buttons keep eve's own question and labels.
8
+ - **Typed answers.** A typed answer to a question eve asks, such as `1` or `Approve`, now reaches eve as what the person typed. A reply to the bot's message used to carry the source-message marker into the comparison, so it never matched and the session stayed blocked.
9
+
10
+ ## 0.66.6
11
+
12
+ A thread in a Slack channel is archived as the channel's thread, a `group` chat keyed by the
13
+ channel's id and the thread's first message, where it was kept under the runtime's own names as a
14
+ private chat. The `whenUnsure` review now reads the thread's earlier messages before judging a
15
+ reply there, where it read none. The agent's session there now reads replies staff approved or
16
+ posted in the thread, and what became of the replies it held, from the same chat. A mention in a
17
+ thread the agent was not in yet records what the thread said before it, Slack's first 50 messages
18
+ of the thread, for the agent's first turn and its review to read. Messages earlier releases
19
+ archived from a Slack channel's threads stay under the old names.
20
+
21
+ Pins @segmentstream/ontology 0.141.0.
22
+
3
23
  ## 0.66.5
4
24
 
5
25
  A Telegram group message that addresses the agent is no longer dropped in silence. When the chat
@@ -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.66.5";
7
+ var version = "0.67.0";
8
8
  function agentBuild(environment = process.env) {
9
9
  return {
10
10
  agent: version,
@@ -1918,6 +1918,8 @@ function withReplacedText(source, request) {
1918
1918
  return {
1919
1919
  ...source,
1920
1920
  async send(message, options) {
1921
+ const typed = typeof message === "string" ? message : message.filter((part) => part.type === "text").map((part) => part.text).join("\n");
1922
+ const answerText = options?.answerText ?? (typed.trim() === "" ? request.text : typed);
1921
1923
  const marker = request.replyTo === void 0 ? void 0 : `[source-message:${request.replyTo};trigger:${request.triggeringMessageId ?? request.replyTo}]`;
1922
1924
  const replacement = marker === void 0 ? request.text : `${marker}\n${request.text ?? (typeof message === "string" ? message : message.filter((part) => part.type === "text").map((part) => part.text).join("\n"))}`;
1923
1925
  const text = replacement === void 0 ? message : replaceText(message, replacement);
@@ -1930,7 +1932,8 @@ function withReplacedText(source, request) {
1930
1932
  try {
1931
1933
  result = await source.send(content, {
1932
1934
  ...options,
1933
- turnPolicy: request.turnPolicy
1935
+ turnPolicy: request.turnPolicy,
1936
+ ...answerText === void 0 ? {} : { answerText }
1934
1937
  });
1935
1938
  } catch (error) {
1936
1939
  try {
@@ -955,7 +955,7 @@ function telegramTexts(value, issues) {
955
955
  if (sectionValue === void 0) continue;
956
956
  output[group] = {};
957
957
  for (const key of keys) if (sectionValue[key] !== void 0) {
958
- const maximum = group === "confirmation" ? key === "question" ? 300 : 24 : group === "callback" ? 200 : group === "authorization" && key === "button" ? 24 : 4e3;
958
+ const maximum = group === "confirmation" ? key === "question" ? 300 : 24 : group === "callback" ? 200 : group === "authorization" && key === "button" || group === "usageLimit" && key !== "prompt" ? 24 : 4e3;
959
959
  output[group][key] = localizedText(sectionValue[key], [
960
960
  "texts",
961
961
  group,
@@ -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-EHH4C9jM.mjs";
8
+ import { T as ontologyConnection } from "../../_chunks/principal-DYl7vqOp.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;
@@ -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-EHH4C9jM.mjs";
10
+ import "../../_chunks/principal-DYl7vqOp.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 { a as rolesOf } from "../../_chunks/principal-EHH4C9jM.mjs";
8
+ import { a as rolesOf } from "../../_chunks/principal-DYl7vqOp.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-EHH4C9jM.mjs";
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-DYl7vqOp.mjs";
@@ -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 { _t as chatChannel, b as agentAttachments, gt as chatAddressOf, i as memberIdOf } from "../../_chunks/principal-EHH4C9jM.mjs";
7
+ import { _t as chatChannel, b as agentAttachments, gt as chatAddressOf, i as memberIdOf } from "../../_chunks/principal-DYl7vqOp.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 { Ot as failureText, _ as AttachmentError, gt as chatAddressOf } from "../../_chunks/principal-EHH4C9jM.mjs";
8
+ import { Ot as failureText, _ as AttachmentError, gt as chatAddressOf } from "../../_chunks/principal-DYl7vqOp.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, mt as CHAT_HEADER, v as EARLIER_CHAT_HEADER, y as MAXIMUM_ATTACHMENT_BYTES, ht as SESSION_HEADER, b as agentAttachments, x as attachmentUrl, S as fetchStoredAttachment, C as parseAttachmentUrl } from "../../_chunks/principal-EHH4C9jM.mjs";
7
+ export { h as ATTACHMENT_TTL_HOURS, g as ATTACHMENT_URL_PROTOCOL, _ as AttachmentError, mt as CHAT_HEADER, v as EARLIER_CHAT_HEADER, y as MAXIMUM_ATTACHMENT_BYTES, ht as SESSION_HEADER, b as agentAttachments, x as attachmentUrl, S as fetchStoredAttachment, C as parseAttachmentUrl } from "../../_chunks/principal-DYl7vqOp.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-CZref5jF.mjs";
7
+ export { t as agentBuild } from "../../_chunks/build-metadata-DabL3CTC.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 { pt as CHAT_ATTRIBUTE, mt as CHAT_HEADER, ht as SESSION_HEADER, gt as chatAddressOf, _t as chatChannel, vt as chatHeaders, yt as isSameChat, bt as withChatAddress, xt as workspaceIdentityProvider } from "../../_chunks/principal-EHH4C9jM.mjs";
7
+ export { pt as CHAT_ATTRIBUTE, mt as CHAT_HEADER, ht as SESSION_HEADER, gt as chatAddressOf, _t as chatChannel, vt as chatHeaders, yt as isSameChat, bt as withChatAddress, xt as workspaceIdentityProvider } from "../../_chunks/principal-DYl7vqOp.mjs";
@@ -7,7 +7,7 @@ __eveCreateRequire(import.meta.url);
7
7
  import { agentTaskIdOf } from "./agent-task.mjs";
8
8
  import { chatCoordinates, sessionKind } from "./chat-recorder.mjs";
9
9
  import { archiveSequence, chatArchive, chatAuthor, collapseChatEvents, topicContext } from "./chat-archive.mjs";
10
- import { At as reportTelegramError } from "../../_chunks/principal-EHH4C9jM.mjs";
10
+ import { At as reportTelegramError } from "../../_chunks/principal-DYl7vqOp.mjs";
11
11
  import { createHash } from "node:crypto";
12
12
  import { deliveries, runs, turns } from "eve/events";
13
13
  import { defineState } from "eve/context";
@@ -174,7 +174,11 @@ function legacySince(context, turnId) {
174
174
  const at = started.length === 0 ? context.now.getTime() : Math.max(...started);
175
175
  return new Date(at - LEGACY_OVERLAP_MS).toISOString();
176
176
  }
177
- const CONTEXT_CHANNELS = new Set(["telegram", "email"]);
177
+ const CONTEXT_CHANNELS = new Set([
178
+ "telegram",
179
+ "email",
180
+ "slack"
181
+ ]);
178
182
  function chatOf(context) {
179
183
  const coordinates = chatCoordinates(context);
180
184
  const kind = sessionKind(context);
@@ -36,6 +36,10 @@ export interface RecordedMessage {
36
36
  readonly messageId: string;
37
37
  readonly text: string;
38
38
  readonly files?: ReadonlyArray<RecordedFile>;
39
+ /** A group's chat, such as a thread in a Slack channel; by default a person's private chat. */
40
+ readonly chatType?: "private" | "group";
41
+ /** When the message was written, if not now. */
42
+ readonly at?: string;
39
43
  }
40
44
  /** Records one message that starts no turn; true for its first record. */
41
45
  export declare function recordChatMessage(archive: ChatArchive, message: RecordedMessage): Promise<boolean | void>;
@@ -11,7 +11,7 @@ async function recordChatMessage(archive, message) {
11
11
  eventId,
12
12
  provider: message.provider,
13
13
  chatId: message.chatId,
14
- chatType: "private",
14
+ chatType: message.chatType ?? "private",
15
15
  threadId: message.threadId === void 0 || message.threadId === "" ? null : message.threadId,
16
16
  participantIds: message.participantIds,
17
17
  senderId: message.senderId === "agent" ? null : message.senderId,
@@ -21,6 +21,7 @@ async function recordChatMessage(archive, message) {
21
21
  messageId: message.messageId,
22
22
  text: message.text,
23
23
  ...message.direction === "outbound" ? { status: "completed" } : {},
24
+ ...message.at === void 0 ? {} : { at: message.at },
24
25
  attachments: (message.files ?? []).map((file, index) => ({
25
26
  id: `${eventId}:file:${index}`,
26
27
  kind: "file",
@@ -20,13 +20,21 @@ export declare function sessionKind(context: {
20
20
  readonly channel: RuntimeContext["channel"];
21
21
  }): string | undefined;
22
22
  /**
23
- * A member's private chat, kept under the chat its channel stamped, by the channel's name, the
24
- * same coordinates its replies, attachments and reviews use: an email chat is one Gmail thread
25
- * with one person, a WhatsApp chat one person's thread, a Slack chat a direct message, and a
26
- * workspace channel's chat one person's. Undefined for Telegram, which keys its chats from its
27
- * updates, a web chat, a group, and a session without a member.
23
+ * A member's chat, kept under the chat its channel stamped, by the channel's name: the same
24
+ * coordinates its replies, attachments, reviews and inbox use. An email chat is one Gmail thread
25
+ * with one person, a WhatsApp chat one person's thread, a Slack direct message one chat whatever
26
+ * thread a message is in, a thread in a Slack channel the chat of everyone in it, and a workspace
27
+ * channel's chat one person's. Undefined for Telegram, which keys its chats from its updates, a
28
+ * web chat, and a session without a member.
28
29
  */
29
- export declare function stampedPrivateChat(principal: SessionAuthContext | null | undefined): {
30
+ export declare function stampedChat(principal: SessionAuthContext | null | undefined): {
31
+ provider: string;
32
+ chatId: string;
33
+ chatType: "group";
34
+ threadId: string | null;
35
+ participantIds: string[];
36
+ senderId: string | null;
37
+ } | {
30
38
  provider: string;
31
39
  chatId: string;
32
40
  chatType: "private";
@@ -8,7 +8,7 @@ import { n as contentText, t as CONTENT_CAPS } from "../../_chunks/content-cDtVn
8
8
  import { chatArchive, chatEvent, sessionFailureEventId, summarizeArguments } from "./chat-archive.mjs";
9
9
  import { agentTaskIdOf } from "./agent-task.mjs";
10
10
  import { revisionOf } from "./review/revision.mjs";
11
- import { _t as chatChannel, gt as chatAddressOf, i as memberIdOf, ot as guestIdOf } from "../../_chunks/principal-EHH4C9jM.mjs";
11
+ import { _t as chatChannel, gt as chatAddressOf, i as memberIdOf, ot as guestIdOf } from "../../_chunks/principal-DYl7vqOp.mjs";
12
12
  import { keyChannel, principalChannel } from "./channel-scope.mjs";
13
13
  import { parseAddress } from "./telegram/sessions.mjs";
14
14
  import { completionKind } from "./telegram/silent.mjs";
@@ -20,10 +20,18 @@ function isTelegram(context) {
20
20
  function sessionKind(context) {
21
21
  return isTelegram(context) ? "telegram" : chatAddressOf(context.session.auth.current)?.provider;
22
22
  }
23
- function stampedPrivateChat(principal) {
23
+ function stampedChat(principal) {
24
24
  const chat = chatAddressOf(principal);
25
25
  const memberId = memberIdOf(principal);
26
- if (chat === void 0 || chat.kind !== "private" || chat.provider === "telegram" || chat.provider === "web" || memberId === void 0) return;
26
+ if (chat === void 0 || chat.provider === "telegram" || chat.provider === "web" || memberId === void 0) return;
27
+ if (chat.kind === "group") return {
28
+ provider: chatChannel(chat),
29
+ chatId: chat.chatId,
30
+ chatType: "group",
31
+ threadId: chat.threadId === "" ? null : chat.threadId,
32
+ participantIds: [memberId],
33
+ senderId: principal?.subject ?? null
34
+ };
27
35
  return {
28
36
  provider: chatChannel(chat),
29
37
  chatId: chat.chatId,
@@ -72,7 +80,7 @@ function chatCoordinates(context) {
72
80
  participantIds: [],
73
81
  senderId: `guest:${guestId}`
74
82
  };
75
- const stamped = stampedPrivateChat(principal);
83
+ const stamped = stampedChat(principal);
76
84
  if (stamped !== void 0) return stamped;
77
85
  const telegram = isTelegram(context);
78
86
  const address = context.channel.continuationToken;
@@ -232,4 +240,4 @@ function resultErrorMessage(output) {
232
240
  if (output !== null && typeof output === "object" && "message" in output && typeof output.message === "string") return output.message;
233
241
  return null;
234
242
  }
235
- export { chatCoordinates, chatRecorder, isTelegram, sessionKind, stampedPrivateChat };
243
+ export { chatCoordinates, chatRecorder, isTelegram, sessionKind, stampedChat };
@@ -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 { N as CONFIRMATION_TTL_MS, P as actionApproval, F as confirmations, I as inputHash, L as needsConfirmation } from "../../_chunks/principal-EHH4C9jM.mjs";
7
+ export { N as CONFIRMATION_TTL_MS, P as actionApproval, F as confirmations, I as inputHash, L as needsConfirmation } from "../../_chunks/principal-DYl7vqOp.mjs";
@@ -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 { _ as AttachmentError } from "../../../_chunks/principal-EHH4C9jM.mjs";
7
+ import { _ as AttachmentError } from "../../../_chunks/principal-DYl7vqOp.mjs";
8
8
  import { sendStoredAttachments } from "../attachments-send.mjs";
9
9
  import { ConnectionProxyError, connectionProxy } from "../connection-proxy.mjs";
10
10
  import { redactDiagnostic } from "../diagnostics.mjs";
@@ -8,7 +8,7 @@ import { PUBSUB_TOPIC } from "../../config.mjs";
8
8
  import { admitMessage, localizedText } from "../admission.mjs";
9
9
  import { agentToolsAttribute } from "../agent-tools.mjs";
10
10
  import { providerChat } from "../attachment-tools.mjs";
11
- import { S as fetchStoredAttachment, b as agentAttachments, bt as withChatAddress, d as prepareInboundMedia, gt as chatAddressOf, i as memberIdOf, m as turnContent } from "../../../_chunks/principal-EHH4C9jM.mjs";
11
+ import { S as fetchStoredAttachment, b as agentAttachments, bt as withChatAddress, d as prepareInboundMedia, gt as chatAddressOf, i as memberIdOf, m as turnContent } from "../../../_chunks/principal-DYl7vqOp.mjs";
12
12
  import { channelAttributes, currentChannel, currentKey, inHandlerChannels, withNamedRoutes } from "../channel-scope.mjs";
13
13
  import { chatArchive, replyEvent } from "../chat-archive.mjs";
14
14
  import { recordHandledMessage, recordSentOutside } from "../chat-messages.mjs";
@@ -6,7 +6,7 @@ __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { appOrigin } from "./environment.mjs";
8
8
  import { runtimeToken } from "./runtime-token.mjs";
9
- import { ot as guestIdOf } from "../../_chunks/principal-EHH4C9jM.mjs";
9
+ import { ot as guestIdOf } from "../../_chunks/principal-DYl7vqOp.mjs";
10
10
  const GUEST_USAGE_PATH = "/api/ontology/agent/guests/usage";
11
11
  const REPORT_TIMEOUT_MS = 5e3;
12
12
  function ontologyGuestUsage(options = {}) {
@@ -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 { f as attachmentsContext, p as storeFiles, m as turnContent } from "../../../_chunks/principal-EHH4C9jM.mjs";
7
+ export { f as attachmentsContext, p as storeFiles, m as turnContent } from "../../../_chunks/principal-DYl7vqOp.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 { f as attachmentsContext, d as prepareInboundMedia, p as storeFiles, m as turnContent } from "../../../_chunks/principal-EHH4C9jM.mjs";
7
+ export { f as attachmentsContext, d as prepareInboundMedia, p as storeFiles, m as turnContent } from "../../../_chunks/principal-DYl7vqOp.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 { R as ACT_AS_HEADER, w as actAsHeaders, T as ontologyConnection } from "../../_chunks/principal-EHH4C9jM.mjs";
7
+ export { R as ACT_AS_HEADER, w as actAsHeaders, T as ontologyConnection } from "../../_chunks/principal-DYl7vqOp.mjs";
@@ -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 { F as confirmations, H as actorOf, I as inputHash, It as runtimeEnvelope, P as actionApproval, V as actorKey, j as ontologyTools } from "../../_chunks/principal-EHH4C9jM.mjs";
7
+ import { F as confirmations, H as actorOf, I as inputHash, It as runtimeEnvelope, P as actionApproval, V as actorKey, j as ontologyTools } from "../../_chunks/principal-DYl7vqOp.mjs";
8
8
  import { isChatPost } from "./chat-post-confirmation.mjs";
9
9
  import { sandboxFile } from "./sandbox-session.mjs";
10
10
  import { saveOntologyResult } from "./ontology-result-file.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 { E as OntologyActionNotPermitted, D as OntologyFileUnavailable, O as OntologyToolRejected, k as actionToolName, A as ontologyToolLabels, j as ontologyTools, M as promotionTarget } from "../../_chunks/principal-EHH4C9jM.mjs";
7
+ export { E as OntologyActionNotPermitted, D as OntologyFileUnavailable, O as OntologyToolRejected, k as actionToolName, A as ontologyToolLabels, j as ontologyTools, M as promotionTarget } from "../../_chunks/principal-DYl7vqOp.mjs";
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { reviewFor } from "../../review.mjs";
8
- import { a as rolesOf, gt as chatAddressOf, i as memberIdOf } from "../../../_chunks/principal-EHH4C9jM.mjs";
8
+ import { a as rolesOf, gt as chatAddressOf, i as memberIdOf } from "../../../_chunks/principal-DYl7vqOp.mjs";
9
9
  function reviewOf(settings, principal) {
10
10
  return reviewFor(settings, rolesOf(principal));
11
11
  }
@@ -4,9 +4,9 @@ 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 { _t as chatChannel, gt as chatAddressOf, i as memberIdOf } from "../../../_chunks/principal-EHH4C9jM.mjs";
7
+ import { _t as chatChannel, gt as chatAddressOf, i as memberIdOf } from "../../../_chunks/principal-DYl7vqOp.mjs";
8
8
  import { chatArchive, chatEvent } from "../chat-archive.mjs";
9
- import { stampedPrivateChat } from "../chat-recorder.mjs";
9
+ import { stampedChat } from "../chat-recorder.mjs";
10
10
  import { appOrigin } from "../environment.mjs";
11
11
  import { agentReviews } from "./client.mjs";
12
12
  import { heldReply, repliesReviewed, reviewOf, reviewOutcome } from "./hold.mjs";
@@ -14,7 +14,7 @@ import { judgeReply, readChat } from "./judge.mjs";
14
14
  const VERDICTS_REMEMBERED = 512;
15
15
  function reviewedChat(principal) {
16
16
  const chat = chatAddressOf(principal);
17
- const stamped = stampedPrivateChat(principal);
17
+ const stamped = stampedChat(principal);
18
18
  return chat === void 0 ? void 0 : stamped !== void 0 ? {
19
19
  provider: stamped.provider,
20
20
  chatId: stamped.chatId,
@@ -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 { a as rolesOf } from "../../_chunks/principal-EHH4C9jM.mjs";
7
+ import { a as rolesOf } from "../../_chunks/principal-DYl7vqOp.mjs";
8
8
  import { defineDynamic, defineSkill } from "eve/skills";
9
9
  function forRoles(roles, skill) {
10
10
  if (!Array.isArray(roles) || roles.length === 0 || !roles.every((role) => typeof role === "string" && role.trim() !== "")) throw new TypeError("forRoles() needs at least one role name; a skill for everyone is an ordinary skill file.");
@@ -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 { Nt as RUNTIME_SOURCE_PROTOCOL, Pt as compatibleRuntimeEnvelope, Ft as principalRuntimeSource, It as runtimeEnvelope, Lt as telegramRuntimeSource } from "../../_chunks/principal-EHH4C9jM.mjs";
7
+ export { Nt as RUNTIME_SOURCE_PROTOCOL, Pt as compatibleRuntimeEnvelope, Ft as principalRuntimeSource, It as runtimeEnvelope, Lt as telegramRuntimeSource } from "../../_chunks/principal-DYl7vqOp.mjs";
@@ -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 { R as ACT_AS_HEADER, _ as AttachmentError, ht as SESSION_HEADER, mt as CHAT_HEADER, v as EARLIER_CHAT_HEADER } from "../../_chunks/principal-EHH4C9jM.mjs";
7
+ import { R as ACT_AS_HEADER, _ as AttachmentError, ht as SESSION_HEADER, mt as CHAT_HEADER, v as EARLIER_CHAT_HEADER } from "../../_chunks/principal-DYl7vqOp.mjs";
8
8
  import { fetchFileGrant, transientFileStatus } from "./file-grant.mjs";
9
9
  var StoredFileError = class extends AttachmentError {
10
10
  filename;
@@ -149,7 +149,7 @@ export declare function withTurnMedia<State>(source: ChannelSource<State>, turn:
149
149
  * privately answering anyone else with the workspace's reply, if it has one.
150
150
  */
151
151
  export declare function receive(input: {
152
- readonly ctx: Pick<SlackInboundMessageContext, "thread" | "edit" | "slack"> & Partial<Pick<SlackInboundMessageContext, "resolveSession">>;
152
+ readonly ctx: Pick<SlackInboundMessageContext, "thread" | "edit" | "slack"> & Partial<Pick<SlackInboundMessageContext, "resolveSession" | "isSubscribed">>;
153
153
  readonly message: Pick<SlackMessage, "author" | "text" | "attachments" | "ts"> & Partial<Pick<SlackMessage, "raw">>;
154
154
  readonly direct: boolean;
155
155
  readonly admission: AdmissionSettings;
@@ -157,7 +157,10 @@ export declare function receive(input: {
157
157
  readonly environment: Environment;
158
158
  /** The chat registry a channel a paired member writes in is reported to. */
159
159
  readonly chats?: AgentChats;
160
- /** Where a direct message staff took over is recorded; by default, the platform's archive. */
160
+ /**
161
+ * Where a direct message staff took over, and a thread's messages from before the agent was
162
+ * called into it, are recorded; by default, the platform's archive.
163
+ */
161
164
  readonly archive?: () => ChatArchive;
162
165
  /** Keeps the report alive after the turn starts; without it the report is awaited. */
163
166
  readonly waitUntil?: (task: Promise<unknown>) => void;
@@ -8,7 +8,7 @@ import { admitMessage, localizedText } from "../admission.mjs";
8
8
  import { agentToolsAttribute } from "../agent-tools.mjs";
9
9
  import { agentChats, channelChats } from "../chats.mjs";
10
10
  import { withButtonDecision } from "../confirmation-buttons.mjs";
11
- import { b as agentAttachments, bt as withChatAddress, d as prepareInboundMedia, m as turnContent } from "../../../_chunks/principal-EHH4C9jM.mjs";
11
+ import { b as agentAttachments, bt as withChatAddress, d as prepareInboundMedia, m as turnContent } from "../../../_chunks/principal-DYl7vqOp.mjs";
12
12
  import { channelAttributes, currentChannel, withNamedRoutes, withSessionChannels } from "../channel-scope.mjs";
13
13
  import { redactDiagnostic } from "../diagnostics.mjs";
14
14
  import { MAXIMUM_DOWNLOAD_BYTES, connectionProxy } from "../connection-proxy.mjs";
@@ -19,6 +19,7 @@ import { gatewayImageDescriber } from "../inbound-media/images.mjs";
19
19
  import { gatewayMediaCapabilities, turnMediaPlan } from "../inbound-media/plan.mjs";
20
20
  import { gatewayTranscriber } from "../inbound-media/speech.mjs";
21
21
  import { slackFileDownload, slackFiles } from "./files.mjs";
22
+ import { recordThreadHistory } from "./thread-history.mjs";
22
23
  import { channelReview, withReviewedReplies } from "../review/reply.mjs";
23
24
  import { runtimeToken } from "../runtime-token.mjs";
24
25
  import { chatArchive } from "../chat-archive.mjs";
@@ -441,6 +442,15 @@ async function receive(input) {
441
442
  else input.waitUntil(reported);
442
443
  }
443
444
  if (!turn) return null;
445
+ if (!input.direct && ctx.edit === void 0 && ctx.isSubscribed !== void 0 && !await ctx.isSubscribed()) await recordThreadHistory({
446
+ archive: input.archive?.() ?? chatArchive({ environment: input.environment }),
447
+ thread: ctx.thread,
448
+ channel: currentChannel("slack"),
449
+ chatId: ctx.slack.channelId,
450
+ threadTs: ctx.slack.threadTs,
451
+ messageTs: message.ts,
452
+ memberId: resolution.member.id
453
+ }).catch((error) => report("thread_history_failed", error));
444
454
  const auth = withChatAddress(slackPrincipal(resolution.member, user), {
445
455
  provider: "slack",
446
456
  ...currentChannel("slack") === "slack" ? {} : { channel: currentChannel("slack") },
@@ -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 { _ as AttachmentError } from "../../../_chunks/principal-EHH4C9jM.mjs";
7
+ import { _ as AttachmentError } from "../../../_chunks/principal-DYl7vqOp.mjs";
8
8
  import { sendStoredAttachments } from "../attachments-send.mjs";
9
9
  import { MAXIMUM_PROXY_BODY_BYTES, connectionProxy } from "../connection-proxy.mjs";
10
10
  import { redactDiagnostic } from "../diagnostics.mjs";
@@ -0,0 +1,22 @@
1
+ import { type SlackThread } from "eve/channels/slack";
2
+ import type { ChatArchive } from "../chat-archive.js";
3
+ /**
4
+ * Records the messages of a thread in a Slack channel written before a member first called the
5
+ * agent into it, as messages that started no turn (docs/agent-chat-storage.md): its new session reads
6
+ * them in its first turn's context, and the review of its replies reads them as the thread's. Slack
7
+ * gives the thread's first 50 messages. The agent's own messages are left out, as are messages no
8
+ * later than the newest the archive holds of the thread: those reached a session of the agent's.
9
+ */
10
+ export declare function recordThreadHistory(input: {
11
+ readonly archive: ChatArchive;
12
+ readonly thread: Pick<SlackThread, "recentMessages" | "refresh">;
13
+ /** The channel's name, as the archive keys its chats. */
14
+ readonly channel: string;
15
+ readonly chatId: string;
16
+ /** The thread's first message. */
17
+ readonly threadTs: string;
18
+ /** The message that called the agent. */
19
+ readonly messageTs: string;
20
+ /** The member who called it, who may read what is recorded. */
21
+ readonly memberId: string;
22
+ }): Promise<void>;
@@ -0,0 +1,46 @@
1
+ import { fileURLToPath as __eveFileURLToPath } from "node:url";
2
+ import { dirname as __eveDirname } from "node:path";
3
+ import { createRequire as __eveCreateRequire } from "node:module";
4
+ const __filename = __eveFileURLToPath(import.meta.url);
5
+ __eveDirname(__filename);
6
+ __eveCreateRequire(import.meta.url);
7
+ import { recordChatMessage } from "../chat-messages.mjs";
8
+ import { loadThreadContextMessages } from "eve/channels/slack";
9
+ function slackTime(ts) {
10
+ const seconds = Number(ts);
11
+ return Number.isFinite(seconds) && seconds > 0 ? new Date(seconds * 1e3).toISOString() : void 0;
12
+ }
13
+ async function recordThreadHistory(input) {
14
+ if (input.threadTs === input.messageTs) return;
15
+ const chat = {
16
+ provider: input.channel,
17
+ chatId: input.chatId,
18
+ threadId: input.threadTs
19
+ };
20
+ const [newest] = (await input.archive.context({
21
+ ...chat,
22
+ limit: 1
23
+ })).events;
24
+ const recordedUntil = newest === void 0 ? void 0 : Date.parse(newest.at);
25
+ const earlier = await loadThreadContextMessages(input.thread, {
26
+ threadTs: input.threadTs,
27
+ ts: input.messageTs
28
+ });
29
+ for (const message of earlier) {
30
+ const at = slackTime(message.ts);
31
+ if (message.isMe || message.markdown.trim() === "" || at === void 0 || recordedUntil !== void 0 && Date.parse(at) <= recordedUntil) continue;
32
+ await recordChatMessage(input.archive, {
33
+ ...chat,
34
+ chatType: "group",
35
+ participantIds: [input.memberId],
36
+ eventId: `slack-thread:${input.channel}:${input.chatId}:${message.ts}`,
37
+ direction: "inbound",
38
+ by: message.botId === void 0 ? "human" : "bot",
39
+ senderId: message.user ?? message.botId ?? null,
40
+ messageId: message.ts,
41
+ text: message.markdown,
42
+ at
43
+ });
44
+ }
45
+ }
46
+ export { recordThreadHistory };
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { object } from "./confirmation-description.mjs";
8
- import { D as OntologyFileUnavailable, W as member, i as memberIdOf, j as ontologyTools } from "../../_chunks/principal-EHH4C9jM.mjs";
8
+ import { D as OntologyFileUnavailable, W as member, i as memberIdOf, j as ontologyTools } from "../../_chunks/principal-DYl7vqOp.mjs";
9
9
  import { redactDiagnostic } from "./diagnostics.mjs";
10
10
  import { createHash } from "node:crypto";
11
11
  async function readStoredFile(input, principal, options = {}) {
@@ -10,12 +10,12 @@ import { groupRoutingHealth } from "../group-routing/health.mjs";
10
10
  import { dispatchStructuredMessage, structuredMessage } from "./structured.mjs";
11
11
  import { handleWorkspaceCallback, isWorkspaceCallback } from "./callbacks.mjs";
12
12
  import { telegramText, withTelegramTexts } from "./texts.mjs";
13
- import { t as agentBuild } from "../../../_chunks/build-metadata-CZref5jF.mjs";
13
+ import { t as agentBuild } from "../../../_chunks/build-metadata-DabL3CTC.mjs";
14
14
  import { attachmentLifecycle } from "./lifecycle.mjs";
15
15
  import { manifestOf } from "../../config.mjs";
16
16
  import { gatewayAttachmentDescriber } from "./attachment-description.mjs";
17
17
  import { chooseModel } from "../../model.mjs";
18
- import { At as reportTelegramError, Ct as currentLocale, Mt as withDeliveryLocale, Ot as failureText, S as fetchStoredAttachment, b as agentAttachments, c as currentInboundRequest, jt as safeTelegramFetch, l as runInboundRequest, n as chatLanguage, o as telegramPrincipal, s as InboundRequest, u as withReplacedText } from "../../../_chunks/principal-EHH4C9jM.mjs";
18
+ import { At as reportTelegramError, Ct as currentLocale, Mt as withDeliveryLocale, Ot as failureText, S as fetchStoredAttachment, b as agentAttachments, c as currentInboundRequest, jt as safeTelegramFetch, l as runInboundRequest, n as chatLanguage, o as telegramPrincipal, s as InboundRequest, u as withReplacedText } from "../../../_chunks/principal-DYl7vqOp.mjs";
19
19
  import { MAXIMUM_DOWNLOAD_BYTES, connectionProxy } from "../connection-proxy.mjs";
20
20
  import { appOrigin, channelsEnabled, proxyEnvironment, runtimeIdentityEnvironment, webhookSecret } from "../environment.mjs";
21
21
  import { agentIdentities } from "../identities.mjs";
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { describableImage } from "../inbound-media/images.mjs";
8
- import { At as reportTelegramError } from "../../../_chunks/principal-EHH4C9jM.mjs";
8
+ import { At as reportTelegramError } from "../../../_chunks/principal-DYl7vqOp.mjs";
9
9
  import { gateway, generateText } from "ai";
10
10
  const MAXIMUM_ROUTING_ATTACHMENT_BYTES = 5242880;
11
11
  const ROUTING_ATTACHMENT_TIMEOUT_MS = 15e3;
@@ -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 { At as reportTelegramError, Et as customerMessage, Ot as failureText, _ as AttachmentError, kt as formattingRefused } from "../../../_chunks/principal-EHH4C9jM.mjs";
8
+ import { At as reportTelegramError, Et as customerMessage, Ot as failureText, _ as AttachmentError, kt as formattingRefused } from "../../../_chunks/principal-DYl7vqOp.mjs";
9
9
  import { attachmentFailure } from "../attachments-send.mjs";
10
10
  import { MAXIMUM_PROXY_BODY_BYTES, connectionProxy } from "../connection-proxy.mjs";
11
11
  import { redactDiagnostic } from "../diagnostics.mjs";
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { object } from "../confirmation-description.mjs";
8
- import { At as reportTelegramError, It as runtimeEnvelope, Lt as telegramRuntimeSource, c as currentInboundRequest, i as memberIdOf, o as telegramPrincipal } from "../../../_chunks/principal-EHH4C9jM.mjs";
8
+ import { At as reportTelegramError, It as runtimeEnvelope, Lt as telegramRuntimeSource, c as currentInboundRequest, i as memberIdOf, o as telegramPrincipal } from "../../../_chunks/principal-DYl7vqOp.mjs";
9
9
  import { formatAddress, parseAddress, scopedAddress } from "./sessions.mjs";
10
10
  import { telegramText } from "./texts.mjs";
11
11
  import { workspaceAction } from "./workspace-action.mjs";