@segmentstream/agent 0.52.0 → 0.53.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 (35) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/README.md +6 -2
  3. package/dist/_chunks/{build-metadata-D1C8gnfm.mjs → build-metadata-Bc9qfC4D.mjs} +1 -1
  4. package/dist/extension/instructions.md +8 -5
  5. package/dist/extension/lib/attachments-send.d.ts +84 -0
  6. package/dist/extension/lib/attachments-send.mjs +88 -0
  7. package/dist/extension/lib/build-metadata.mjs +1 -1
  8. package/dist/extension/lib/chat-archive.d.ts +35 -0
  9. package/dist/extension/lib/chat-archive.mjs +37 -1
  10. package/dist/extension/lib/chat-context.d.ts +1 -1
  11. package/dist/extension/lib/chat-context.mjs +3 -2
  12. package/dist/extension/lib/chat-recorder.mjs +2 -1
  13. package/dist/extension/lib/email/attachments-send.d.ts +43 -0
  14. package/dist/extension/lib/email/attachments-send.mjs +130 -0
  15. package/dist/extension/lib/email/channel.d.ts +7 -1
  16. package/dist/extension/lib/email/channel.mjs +221 -52
  17. package/dist/extension/lib/email/gmail.d.ts +22 -6
  18. package/dist/extension/lib/email/gmail.mjs +101 -5
  19. package/dist/extension/lib/email/message.d.ts +19 -0
  20. package/dist/extension/lib/email/message.mjs +22 -1
  21. package/dist/extension/lib/review/judge.mjs +2 -2
  22. package/dist/extension/lib/sent-files.d.ts +29 -9
  23. package/dist/extension/lib/sent-files.mjs +35 -13
  24. package/dist/extension/lib/slack/attachments-send.d.ts +6 -14
  25. package/dist/extension/lib/slack/attachments-send.mjs +128 -170
  26. package/dist/extension/lib/telegram/adapter.mjs +1 -1
  27. package/dist/extension/lib/telegram/attachments-send.mjs +8 -11
  28. package/dist/extension/lib/telegram/health.mjs +1 -1
  29. package/dist/extension/lib/telegram/lifecycle.mjs +1 -1
  30. package/dist/extension/lib/web/channel.d.ts +10 -3
  31. package/dist/extension/lib/web/channel.mjs +9 -2
  32. package/dist/extension/lib/whatsapp/attachments-send.d.ts +35 -0
  33. package/dist/extension/lib/whatsapp/attachments-send.mjs +117 -0
  34. package/dist/extension/tools/attachments_send.mjs +17 -6
  35. package/package.json +2 -2
@@ -0,0 +1,117 @@
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 { _ as AttachmentError } from "../../../_chunks/principal-JoaOmdFL.mjs";
8
+ import { sendStoredAttachments } from "../attachments-send.mjs";
9
+ import { connectionProxy } from "../connection-proxy.mjs";
10
+ import { redactDiagnostic } from "../diagnostics.mjs";
11
+ import { proxyEnvironment } from "../environment.mjs";
12
+ import { StoredFileError, storedFileGrant } from "../sent-files.mjs";
13
+ import { ProxiedWhatsAppAdapter } from "./adapter.mjs";
14
+ import { randomUUID } from "node:crypto";
15
+ import { WhatsAppApiError } from "@chat-adapter/whatsapp";
16
+ function reportWhatsAppError(operation, error, secrets) {
17
+ const reference = randomUUID();
18
+ console.error("[segmentstream] WhatsApp delivery diagnostic", {
19
+ operation,
20
+ reference,
21
+ error: redactDiagnostic(error, secrets)
22
+ });
23
+ return reference;
24
+ }
25
+ function sendFailure(error) {
26
+ if (error instanceof AttachmentError) return error;
27
+ const validation = error instanceof Error && error.name === "ValidationError";
28
+ const code = error instanceof WhatsAppApiError ? error.status === 413 ? "too_large" : error.status === 401 || error.status === 403 ? "forbidden" : "send_failed" : validation && /exceeds/u.test(error.message) ? "too_large" : validation ? "unsupported" : "send_failed";
29
+ return new AttachmentError({
30
+ code,
31
+ message: "WhatsApp did not take the file.",
32
+ cause: error
33
+ });
34
+ }
35
+ async function sendWhatsAppAttachments(options) {
36
+ return sendStoredAttachments({
37
+ ...options,
38
+ provider: "whatsapp",
39
+ channel: "WhatsApp",
40
+ report: (operation, error, _metadata, secrets) => reportWhatsAppError(operation, error, secrets),
41
+ async send(context) {
42
+ const { input, chat, owner, origin, fetch, token, secrets, failed } = context;
43
+ const proxy = connectionProxy({
44
+ environment: proxyEnvironment(context.environment),
45
+ connection: context.connection,
46
+ token,
47
+ fetch
48
+ });
49
+ const adapter = new ProxiedWhatsAppAdapter({
50
+ enabled: () => true,
51
+ secret: () => void 0,
52
+ proxy: () => proxy
53
+ });
54
+ const results = input.documentIds.map(({ id }) => ({
55
+ id,
56
+ filename: ""
57
+ }));
58
+ let caption = input.caption;
59
+ for (const [index, reference] of input.documentIds.entries()) {
60
+ let grant;
61
+ try {
62
+ grant = await storedFileGrant({
63
+ reference,
64
+ owner,
65
+ origin,
66
+ token,
67
+ fetch,
68
+ secrets
69
+ });
70
+ if (grant.size === 0) throw new AttachmentError({
71
+ code: "unsupported",
72
+ message: "WhatsApp cannot send an empty file."
73
+ });
74
+ if (!grant.url.startsWith("https://") || Object.keys(grant.headers).length > 0) throw new AttachmentError({
75
+ code: "unsupported",
76
+ message: "The file's download link is not one WhatsApp can fetch."
77
+ });
78
+ } catch (error) {
79
+ results[index] = {
80
+ id: reference.id,
81
+ filename: error instanceof StoredFileError ? error.filename : grant?.filename ?? "",
82
+ ...failed(error, "stored_attachment_fetch_failed")
83
+ };
84
+ continue;
85
+ }
86
+ results[index] = {
87
+ id: reference.id,
88
+ filename: grant.filename
89
+ };
90
+ try {
91
+ const sent = await adapter.postMessage(chat.chatId, {
92
+ markdown: caption ?? "",
93
+ attachments: [{
94
+ type: grant.contentType.startsWith("image/") ? "image" : "file",
95
+ url: grant.url,
96
+ name: grant.filename,
97
+ mimeType: grant.contentType,
98
+ size: grant.size
99
+ }]
100
+ });
101
+ results[index] = {
102
+ ...results[index],
103
+ whatsappMessageId: sent.id
104
+ };
105
+ caption = void 0;
106
+ } catch (error) {
107
+ results[index] = {
108
+ ...results[index],
109
+ ...failed(sendFailure(error), "attachment_upload_failed")
110
+ };
111
+ }
112
+ }
113
+ return { files: results };
114
+ }
115
+ });
116
+ }
117
+ export { sendWhatsAppAttachments };
@@ -7,12 +7,14 @@ __eveCreateRequire(import.meta.url);
7
7
  import { n as workflowToolResult } from "../../_chunks/workflow-serializable-DU7WeCIW.mjs";
8
8
  import segmentstream from "../extension.mjs";
9
9
  import { mt as chatAddressOf, q as memberTool } from "../../_chunks/principal-JoaOmdFL.mjs";
10
+ import { sendEmailAttachments } from "../lib/email/attachments-send.mjs";
10
11
  import { sendSlackAttachments } from "../lib/slack/attachments-send.mjs";
11
12
  import { sendAttachments, sendAttachmentsInput } from "../lib/telegram/attachments-send.mjs";
13
+ import { sendWhatsAppAttachments } from "../lib/whatsapp/attachments-send.mjs";
12
14
  import { defineTool } from "eve/tools";
13
15
  const tool = defineTool({
14
16
  availableInSubagents: false,
15
- description: "Send 1 to 10 stored ontology files to this turn's Telegram chat or Slack chat, as the paired member. Bare ids are document record ids; use entity/id/property references for other file records. In Telegram, images use sendPhoto, other files sendDocument, with compatible albums when possible; in Slack the files are shared together in the thread, with the caption. Uploads are limited to 2 MiB by the connection proxy. Use the question as caption when sending documents with a question; one question per message. In groups follow the chat's purpose and never send restricted documents.",
17
+ description: "Send 1 to 10 stored ontology files to this turn's Telegram, Slack, WhatsApp or email chat, as the paired member. Bare ids are document record ids; use entity/id/property references for other file records. In Telegram, images use sendPhoto, other files sendDocument, with compatible albums when possible; in Slack the files are shared together in the thread, with the caption; Telegram and Slack uploads are limited to 2 MiB by the connection proxy. In WhatsApp each file is its own message, the caption on the first. In email the files go in one reply in the person's thread, at most 20 MiB together, the caption as its text. Use the question as caption when sending documents with a question; one question per message. In groups follow the chat's purpose and never send restricted documents.",
16
18
  inputSchema: {
17
19
  type: "object",
18
20
  properties: {
@@ -52,19 +54,28 @@ const tool = defineTool({
52
54
  label: { start: () => "Send stored attachments" },
53
55
  async execute(input, ctx) {
54
56
  const principal = ctx.session.auth.current;
55
- if (chatAddressOf(principal)?.provider === "web") throw new Error("Stored attachments cannot be sent in a web chat; link to them instead.");
57
+ const provider = chatAddressOf(principal)?.provider;
58
+ if (provider === "web") throw new Error("Stored attachments cannot be sent in a web chat; link to them instead.");
56
59
  const options = {
57
60
  input: sendAttachmentsInput(input),
58
61
  principal,
59
62
  sessionId: ctx.session.id
60
63
  };
61
- return workflowToolResult(chatAddressOf(principal)?.provider === "slack" ? await sendSlackAttachments({
64
+ const channels = segmentstream.config.channels;
65
+ return workflowToolResult(provider === "slack" ? await sendSlackAttachments({
62
66
  ...options,
63
- connection: segmentstream.config.channels.slack?.connection
67
+ connection: channels.slack?.connection
68
+ }) : provider === "email" ? await sendEmailAttachments({
69
+ ...options,
70
+ callId: ctx.callId,
71
+ connection: channels.email?.connection
72
+ }) : provider === "whatsapp" ? await sendWhatsAppAttachments({
73
+ ...options,
74
+ connection: channels.whatsapp?.connection
64
75
  }) : await sendAttachments({
65
76
  ...options,
66
- connection: segmentstream.config.channels.telegram?.connection,
67
- appLinks: segmentstream.config.channels.telegram
77
+ connection: channels.telegram?.connection,
78
+ appLinks: channels.telegram
68
79
  }), ctx);
69
80
  }
70
81
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@segmentstream/agent",
3
- "version": "0.52.0",
3
+ "version": "0.53.0",
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.107.0",
83
+ "@segmentstream/ontology": "0.109.0",
84
84
  "@vercel/oidc": "^3.8.4",
85
85
  "ai": "^7.0.172",
86
86
  "chat": "4.42.0",