@segmentstream/agent 0.57.0 → 0.58.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 CHANGED
@@ -1,5 +1,24 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.58.1
4
+
5
+ Pins @segmentstream/ontology 0.116.0.
6
+
7
+ ## 0.58.0
8
+
9
+ The agent reports a person's private chat to the ontology's inbox when the answer to the
10
+ message's admission says the inbox takes them, on Telegram, WhatsApp, Slack direct messages,
11
+ email and workspace channels, at most every few minutes per chat. A failed report is logged and
12
+ never stands in the way of the message. Agents on an ontology without an inbox send nothing new.
13
+
14
+ A member's private chat on WhatsApp, Slack, email or a workspace channel is now archived under the
15
+ chat its channel stamped, by the channel's name, as its replies, attachments and reviews already
16
+ key it. Rows of the WhatsApp and Slack channels named after their kind were keyed under the
17
+ runtime's own channel names before; those rows keep them, and Slack direct messages are now one
18
+ chat per channel with each thread's `threadId`.
19
+
20
+ Pins @segmentstream/ontology 0.115.0.
21
+
3
22
  ## 0.57.0
4
23
 
5
24
  The agent can drive its own web browser. `"browser": {}` in `agent/segmentstream.json`, with
@@ -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.57.0";
7
+ var version = "0.58.1";
8
8
  function agentBuild(environment = process.env) {
9
9
  return {
10
10
  agent: version,
@@ -2,6 +2,15 @@ import type { AdmissionSettings, LocalizedText } from "../config.js";
2
2
  import type { AgentIdentities, IdentityResolution, 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
+ /** The private chat a message arrived in, as the chat archive keys it. */
6
+ export interface AdmittedChat {
7
+ /** The channel's name: its kind for the channel named after its kind. */
8
+ readonly channel: string;
9
+ readonly chatId: string;
10
+ readonly threadId?: string;
11
+ /** Whom a reply is sent to, where it differs from the chat's id. */
12
+ readonly recipient?: string;
13
+ }
5
14
  /** Channel-independent admission and at-least-once versioned notice delivery. */
6
15
  export declare function admitMessage(input: {
7
16
  readonly identity: ResolveIdentityInput;
@@ -10,4 +19,8 @@ export declare function admitMessage(input: {
10
19
  readonly languageCode?: string;
11
20
  readonly sendNotice: (text: string) => Promise<unknown>;
12
21
  readonly noticeFailed: (error: unknown) => void;
22
+ /** The private chat the message arrived in, which the inbox registers when it takes the person. */
23
+ readonly chat?: AdmittedChat;
24
+ /** A failed inbox report; by default it is logged. */
25
+ readonly inboxFailed?: (error: unknown) => void;
13
26
  }): Promise<IdentityResolution>;
@@ -23,6 +23,36 @@ function messengerLimits(limits) {
23
23
  workspaceTurnsPerDay
24
24
  };
25
25
  }
26
+ const INBOX_REPORT_INTERVAL_MS = 3e5;
27
+ const INBOX_REPORTS_REMEMBERED = 1e3;
28
+ const inboxReports = new Map();
29
+ async function reportInboxChat(input) {
30
+ const { chat, identity } = input;
31
+ const key = `${chat.channel}:${chat.chatId}`;
32
+ const now = Date.now();
33
+ const last = inboxReports.get(key);
34
+ if (last !== void 0 && now - last < INBOX_REPORT_INTERVAL_MS) return;
35
+ inboxReports.delete(key);
36
+ inboxReports.set(key, now);
37
+ if (inboxReports.size > INBOX_REPORTS_REMEMBERED) {
38
+ const oldest = inboxReports.keys().next();
39
+ if (oldest.done !== true) inboxReports.delete(oldest.value);
40
+ }
41
+ try {
42
+ await input.identities.seenChat({
43
+ provider: chat.channel,
44
+ externalId: chat.chatId,
45
+ title: (identity.display?.trim() || identity.externalId).slice(0, 200),
46
+ memberId: input.memberId,
47
+ kind: "private",
48
+ ...chat.recipient === void 0 || chat.recipient === chat.chatId ? {} : { recipient: chat.recipient },
49
+ ...chat.threadId === void 0 || chat.threadId === "" ? {} : { threadId: chat.threadId }
50
+ });
51
+ } catch (error) {
52
+ inboxReports.delete(key);
53
+ input.failed?.(error);
54
+ }
55
+ }
26
56
  async function admitMessage(input) {
27
57
  const firstContact = input.settings.firstContact;
28
58
  const notice = localizedText(firstContact?.notice, input.languageCode);
@@ -46,6 +76,13 @@ async function admitMessage(input) {
46
76
  } catch (error) {
47
77
  input.noticeFailed(error);
48
78
  }
79
+ if ((resolved.status === "existing" || resolved.status === "created") && resolved.inbox === true && input.identity.chat === "private" && input.chat !== void 0) await reportInboxChat({
80
+ identity: input.identity,
81
+ identities: input.identities,
82
+ chat: input.chat,
83
+ memberId: resolved.member.id,
84
+ failed: input.inboxFailed ?? ((error) => console.error("[segmentstream] inbox chat report failed", error))
85
+ });
49
86
  return resolved;
50
87
  }
51
88
  export { admitMessage, localizedText };
@@ -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-Bh07gNAt.mjs";
7
+ export { t as agentBuild } from "../../_chunks/build-metadata-5A5F_9VQ.mjs";
@@ -49,7 +49,7 @@ function chatCoordinates(context) {
49
49
  participantIds: [],
50
50
  senderId: `guest:${guestId}`
51
51
  };
52
- if ((chat?.provider === "email" || chat?.provider === "custom") && webMemberId !== void 0) return {
52
+ if (chat !== void 0 && chat.kind === "private" && chat.provider !== "telegram" && chat.provider !== "web" && webMemberId !== void 0) return {
53
53
  provider: chatChannel(chat),
54
54
  chatId: chat.chatId,
55
55
  chatType: "private",
@@ -339,7 +339,14 @@ function emailChannelDefinition(options) {
339
339
  identities: people(),
340
340
  settings: admission,
341
341
  sendNotice: (text) => answer(added.threadId, mail.from, text),
342
- noticeFailed: (error) => log("[segmentstream] email notice failed", { error: redactDiagnostic(error, new Set()) })
342
+ noticeFailed: (error) => log("[segmentstream] email notice failed", { error: redactDiagnostic(error, new Set()) }),
343
+ chat: {
344
+ channel: currentChannel("email"),
345
+ chatId: emailChatId(added.threadId, mail.from),
346
+ threadId: added.threadId,
347
+ recipient: mail.from
348
+ },
349
+ inboxFailed: (error) => log("[segmentstream] email inbox report failed", { error: redactDiagnostic(error, new Set()) })
343
350
  });
344
351
  if (resolution.status === "limited") {
345
352
  const replies = admission.replies;
@@ -40,6 +40,11 @@ export type IdentityResolution = (({
40
40
  readonly provisioned: boolean;
41
41
  readonly noticeDue: boolean;
42
42
  readonly onNewUserPending: boolean;
43
+ /**
44
+ * The ontology's inbox takes the person's private chats: the channel reports the chat it
45
+ * admitted the message in, which registers it for the workspace's staff.
46
+ */
47
+ readonly inbox?: true;
43
48
  }) | {
44
49
  readonly status: "pairing_required";
45
50
  } | {
@@ -111,6 +116,13 @@ export interface AgentIdentities {
111
116
  readonly leftMemberId?: string;
112
117
  readonly agentLeft?: true;
113
118
  readonly migratedFrom?: string;
119
+ /**
120
+ * A person's private chat, reported only when the ontology's resolution said `inbox`: an
121
+ * older ontology refuses the field. `memberId` is the person.
122
+ */
123
+ readonly kind?: "private";
124
+ readonly recipient?: string;
125
+ readonly threadId?: string;
114
126
  }): Promise<AgentChat>;
115
127
  }
116
128
  /** The ontology service refused or failed a pairing call. Carries its error code, not its body. */
@@ -68,7 +68,8 @@ function resolution(value) {
68
68
  member: pairedMember(value),
69
69
  provisioned: value.provisioned,
70
70
  noticeDue: value.notice_due,
71
- onNewUserPending: value.on_new_user_pending
71
+ onNewUserPending: value.on_new_user_pending,
72
+ ...value.inbox === true ? { inbox: true } : {}
72
73
  };
73
74
  if (value.status === "pairing_required") return { status: "pairing_required" };
74
75
  if (value.status === "refused" && (value.reason === "blocked" || value.reason === "inactive")) return {
@@ -388,7 +388,13 @@ async function receive(input) {
388
388
  identities,
389
389
  settings: admission,
390
390
  sendNotice: (text) => notify(text),
391
- noticeFailed: (error) => report("notice_failed", error)
391
+ noticeFailed: (error) => report("notice_failed", error),
392
+ ...input.direct ? { chat: {
393
+ channel: currentChannel("slack"),
394
+ chatId: ctx.slack.channelId,
395
+ recipient: user
396
+ } } : {},
397
+ inboxFailed: (error) => report("inbox_report_failed", error)
392
398
  });
393
399
  switch (resolution.status) {
394
400
  case "existing":
@@ -10,7 +10,7 @@ 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-Bh07gNAt.mjs";
13
+ import { t as agentBuild } from "../../../_chunks/build-metadata-5A5F_9VQ.mjs";
14
14
  import { attachmentLifecycle } from "./lifecycle.mjs";
15
15
  import { manifestOf } from "../../config.mjs";
16
16
  import { gatewayAttachmentDescriber } from "./attachment-description.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 agentBuild } from "../../../_chunks/build-metadata-Bh07gNAt.mjs";
7
+ import { t as agentBuild } from "../../../_chunks/build-metadata-5A5F_9VQ.mjs";
8
8
  import { runtimeRequestFailure } from "./runtime-request.mjs";
9
9
  import { GET } from "eve/channels";
10
10
  const HEALTH_ROUTE = "/eve/v1/telegram/health";
@@ -6,6 +6,7 @@ __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { WorkspaceActionAlreadyDispatched } from "./workspace-action.mjs";
8
8
  import { structuredMessage } from "./structured.mjs";
9
+ import { currentChannel } from "../channel-scope.mjs";
9
10
  import { At as reportTelegramError, It as runtimeEnvelope, Lt as telegramRuntimeSource, f as attachmentsContext, n as chatLanguage, o as telegramPrincipal, x as attachmentUrl } from "../../../_chunks/principal-TJ6zB2rF.mjs";
10
11
  import { routingBurst } from "../group-routing/burst.mjs";
11
12
  import { telegramSignals } from "./signals.mjs";
@@ -292,7 +293,11 @@ async function handleInboundMessage(input) {
292
293
  sendNotice: (text) => context.telegram.post(text),
293
294
  noticeFailed: (error) => {
294
295
  reportTelegramError("identity_notice_failed", error, { provider: "telegram" });
295
- }
296
+ },
297
+ ...sent.chat.type === "private" ? { chat: {
298
+ channel: currentChannel("telegram"),
299
+ chatId: String(sent.chat.id)
300
+ } } : {}
296
301
  });
297
302
  const turn = structured === void 0 && input.request?.structuredContext === void 0 && addressed !== void 0 && hasContent && (addressed !== "reply-to-bot" || elsewhere === void 0);
298
303
  const lookup = await resolve(turn);
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { E as OntologyActionNotPermitted, Ft as principalRuntimeSource, It as runtimeEnvelope, L as needsConfirmation, Lt as telegramRuntimeSource, W as member, c as currentInboundRequest, j as ontologyTools, k as actionToolName } from "../../../_chunks/principal-TJ6zB2rF.mjs";
8
- import { t as agentBuild } from "../../../_chunks/build-metadata-Bh07gNAt.mjs";
8
+ import { t as agentBuild } from "../../../_chunks/build-metadata-5A5F_9VQ.mjs";
9
9
  import { object } from "../confirmation-description.mjs";
10
10
  var AttachmentLifecycleNotPermitted = class extends Error {
11
11
  code = "attachment_lifecycle_not_permitted";
@@ -312,7 +312,13 @@ async function receive(input) {
312
312
  identities,
313
313
  settings: admission,
314
314
  sendNotice: (text) => thread.post(text),
315
- noticeFailed: (error) => report("notice_failed", error)
315
+ noticeFailed: (error) => report("notice_failed", error),
316
+ chat: {
317
+ channel: currentChannel("whatsapp"),
318
+ chatId: thread.id,
319
+ recipient: sender
320
+ },
321
+ inboxFailed: (error) => report("inbox_report_failed", error)
316
322
  });
317
323
  switch (resolution.status) {
318
324
  case "existing":
@@ -225,7 +225,13 @@ function workspaceChannelDefinition(options) {
225
225
  identities: people(),
226
226
  settings: config,
227
227
  sendNotice: notice,
228
- noticeFailed: (cause) => report("notice_failed", cause)
228
+ noticeFailed: (cause) => report("notice_failed", cause),
229
+ chat: {
230
+ channel: name,
231
+ chatId: message.chatId,
232
+ recipient: message.sender.id
233
+ },
234
+ inboxFailed: (cause) => report("inbox_report_failed", cause)
229
235
  });
230
236
  if (resolution.status === "limited") {
231
237
  const replies = config.replies;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@segmentstream/agent",
3
- "version": "0.57.0",
3
+ "version": "0.58.1",
4
4
  "description": "The SegmentStream workspace agent: the ontology as tools, acting as the member who writes, and the browser, Telegram, WhatsApp and Slack through the workspace's connections.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "SegmentStream",
@@ -80,7 +80,7 @@
80
80
  "@chat-adapter/state-memory": "4.42.0",
81
81
  "@chat-adapter/telegram": "4.41.0",
82
82
  "@chat-adapter/whatsapp": "4.42.0",
83
- "@segmentstream/ontology": "0.114.0",
83
+ "@segmentstream/ontology": "0.116.0",
84
84
  "@vercel/oidc": "^3.8.4",
85
85
  "ai": "^7.0.172",
86
86
  "chat": "4.42.0",