@segmentstream/agent 0.97.0 → 0.98.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.98.0
4
+
5
+ `agent_chat.draft` asks the agent for a draft in an email thread's chat (`chats: "thread"` on the
6
+ email channel), which it refused before.
7
+
8
+ - The draft is for the sender of the mail it answers: the `message` named, or else the thread's
9
+ latest mail a person wrote. That sender, by the member the mail was recorded as, is the person
10
+ the drafting session acts as, with the roles they hold now. When the mail names no member, or
11
+ that member is no longer active, the request is refused and nothing is recorded; it never falls
12
+ back to the requester's roles.
13
+ - The draft goes to everyone in the thread, as the agent's own reply to that mail does: to its
14
+ sender, copying the thread's other people without the mailbox, as the thread reads when the
15
+ draft is asked for, and is read by the members among them. The ontology names them to the agent
16
+ in `to`, `cc` and `participants`, in place of one `recipient`, and the agent holds the draft with
17
+ them, so its approval replies to all in the thread. Asking reads the thread through the mailbox's
18
+ connection and sends nothing; a thread that cannot be read is refused.
19
+ - An agent SDK released before such drafts refuses a request without a `recipient`, and the
20
+ ontology says that the workspace's agent predates drafts in a chat several people share, rather
21
+ than have it hold a draft for its person alone. Upgrade both SDKs to draft in thread chats; a
22
+ person's own chat drafts as before.
23
+
24
+ Pins @segmentstream/ontology 0.178.0.
25
+
3
26
  ## 0.97.0
4
27
 
5
28
  `triage: { entity, action, contextVersion: 2 }` in `agent/segmentstream.json` names a routine
@@ -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.97.0";
7
+ var version = "0.98.0";
8
8
  function agentBuild(environment = process.env) {
9
9
  return {
10
10
  agent: version,
@@ -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-fijGydlU.mjs";
7
+ export { t as agentBuild } from "../../_chunks/build-metadata-BMaei-TJ.mjs";
@@ -30,8 +30,8 @@ import { GMAIL_ID, GmailError, ReplyNotSent, gmail, replyKeyOf } from "./gmail.m
30
30
  import { inboundMail, parseMail, sentMail } from "./message.mjs";
31
31
  import { createHmac, randomUUID, timingSafeEqual } from "node:crypto";
32
32
  import { reply } from "eve/events";
33
- import { POST, defineChannel } from "eve/channels";
34
33
  import { EMAIL_FILES_BYTES, EMAIL_MESSAGE_LIMIT, EMAIL_RECIPIENTS_LIMIT, GmailMaybeSent, REPLY_KEY as REPLY_KEY$1, REPLY_KEY_HEADER, isEmailAddress } from "@segmentstream/ontology/email";
34
+ import { POST, defineChannel } from "eve/channels";
35
35
  const EMAIL_ROUTE = "/eve/segmentstream/v1/email";
36
36
  const EMAIL_DELIVER_ROUTE = `${EMAIL_ROUTE}/:channel/deliver`;
37
37
  const DELIVER_FILE_TIMEOUT_MS = 3e4;
@@ -47,6 +47,8 @@ export interface RevisionRequest {
47
47
  /**
48
48
  * A draft a member or workflow asked for in a person's private chat (`agent_chat.draft`), as the
49
49
  * ontology's request names it: the chat, the message to answer, and what holding the draft needs.
50
+ * In an email thread's chat several people share, the person is the writer of the mail it answers,
51
+ * and the request names everyone the draft goes to in place of one recipient.
50
52
  */
51
53
  export interface DraftRequest {
52
54
  /** The request, which keys the draft the session holds. */
@@ -71,12 +73,24 @@ export interface DraftRequest {
71
73
  readonly text: string | null;
72
74
  readonly files: ReadonlyArray<DraftMessageFile>;
73
75
  };
74
- /** Whom the provider sends the reply to, and the thread it goes in, `""` without one. */
76
+ /**
77
+ * Whom the provider sends the reply to, and the thread it goes in, `""` without one. In a thread's
78
+ * chat, the person, the first of `to`.
79
+ */
75
80
  readonly recipient: string;
76
81
  readonly replyThreadId: string;
77
82
  readonly replyTo: string | null;
78
83
  /** Where the chat stood when the draft was asked for, `<time>~<id>`. */
79
84
  readonly basis: string;
85
+ /**
86
+ * In an email thread's chat several people share: whom the draft goes to, in `To`, the person,
87
+ * and the thread's other people it copies, in `Cc`, as a reply to all; and the members who read
88
+ * it, by user id. The draft is held with them, as the email channel holds its own reply there.
89
+ * Absent in a person's own chat.
90
+ */
91
+ readonly to?: ReadonlyArray<string>;
92
+ readonly cc?: ReadonlyArray<string>;
93
+ readonly participants?: ReadonlyArray<string>;
80
94
  }
81
95
  /** A file of the message a draft answers, as the chat store describes it. */
82
96
  export interface DraftMessageFile {
@@ -9,6 +9,7 @@ import { AgentIdentityError, refusal } from "../identities.mjs";
9
9
  import { readChat } from "./judge.mjs";
10
10
  import { postDraftRoute } from "./routes.mjs";
11
11
  import { ontologyDeploymentHeaders } from "../environment.mjs";
12
+ import { EMAIL_RECIPIENTS_LIMIT, isEmailAddress } from "@segmentstream/ontology/email";
12
13
  const REVISION_AUTHENTICATOR = "segmentstream-review-revision";
13
14
  const REVISION_ROUTE = "/eve/segmentstream/v1/reviews/revise";
14
15
  const REVISION_SCOPE = "ontology:read";
@@ -55,6 +56,17 @@ const MESSAGE_TEXT_LIMIT = 1e5;
55
56
  function text(value, limit = 512) {
56
57
  return typeof value === "string" && value !== "" && value.length <= limit ? value : void 0;
57
58
  }
59
+ function threadPeople(record) {
60
+ const addresses = (value) => Array.isArray(value) && value.every((address) => typeof address === "string" && isEmailAddress(address)) ? value : void 0;
61
+ const to = addresses(record.to);
62
+ const cc = addresses(record.cc);
63
+ const participants = record.participants;
64
+ return to === void 0 || cc === void 0 || to.length === 0 || to.length + cc.length > EMAIL_RECIPIENTS_LIMIT || !Array.isArray(participants) || participants.length > EMAIL_RECIPIENTS_LIMIT || !participants.every((id) => typeof id === "string" && ID.test(id)) ? void 0 : {
65
+ to,
66
+ cc,
67
+ participants
68
+ };
69
+ }
58
70
  function revisionRequest(body) {
59
71
  if (typeof body !== "object" || body === null || Array.isArray(body)) return;
60
72
  const record = body;
@@ -98,7 +110,8 @@ function draftRequest(body) {
98
110
  const channel = text(record.channel, 64);
99
111
  const chatId = text(record.chat_id);
100
112
  const threadId = record.thread_id === null ? null : text(record.thread_id);
101
- const recipient = text(record.recipient);
113
+ const thread = record.to === void 0 ? void 0 : threadPeople(record);
114
+ const recipient = record.to === void 0 ? text(record.recipient) : record.recipient === void 0 && provider === "email" ? thread?.to[0] : void 0;
102
115
  const replyThreadId = record.reply_thread_id === "" ? "" : text(record.reply_thread_id);
103
116
  const replyTo = record.reply_to === null ? null : text(record.reply_to);
104
117
  const basis = text(record.basis, 128);
@@ -128,7 +141,8 @@ function draftRequest(body) {
128
141
  recipient,
129
142
  replyThreadId,
130
143
  replyTo,
131
- basis
144
+ basis,
145
+ ...thread === void 0 ? {} : thread
132
146
  };
133
147
  }
134
148
  const REQUESTED = "requested";
@@ -142,7 +156,12 @@ function draftPrincipal(request) {
142
156
  replyTo: request.replyTo,
143
157
  ...request.note === void 0 ? {} : { note: request.note },
144
158
  notedBy: request.notedBy,
145
- basis: request.basis
159
+ basis: request.basis,
160
+ ...request.to === void 0 ? {} : {
161
+ to: request.to,
162
+ cc: request.cc ?? []
163
+ },
164
+ ...request.participants === void 0 ? {} : { participants: request.participants }
146
165
  };
147
166
  return {
148
167
  authenticator: REVISION_AUTHENTICATOR,
@@ -181,6 +200,11 @@ function requestedDraft(input) {
181
200
  recipient: hold.recipient,
182
201
  threadId: hold.threadId,
183
202
  replyTo: hold.replyTo,
203
+ ...hold.to === void 0 ? {} : {
204
+ to: hold.to,
205
+ cc: hold.cc ?? []
206
+ },
207
+ ...hold.participants === void 0 ? {} : { participants: hold.participants },
184
208
  memberId: drafting.memberId,
185
209
  sessionId: input.sessionId,
186
210
  text: input.text.slice(0, TEXT_LIMIT),
@@ -13,7 +13,7 @@ import { dispatchStructuredMessage, structuredMessage } from "./structured.mjs";
13
13
  import { handleWorkspaceCallback } from "./callbacks.mjs";
14
14
  import { workspaceTriage } from "../triage.mjs";
15
15
  import { telegramText, withTelegramTexts } from "./texts.mjs";
16
- import { t as agentBuild } from "../../../_chunks/build-metadata-fijGydlU.mjs";
16
+ import { t as agentBuild } from "../../../_chunks/build-metadata-BMaei-TJ.mjs";
17
17
  import { attachmentLifecycle } from "./lifecycle.mjs";
18
18
  import { manifestOf } from "../../config.mjs";
19
19
  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-fijGydlU.mjs";
7
+ import { t as agentBuild } from "../../../_chunks/build-metadata-BMaei-TJ.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";
@@ -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, Et as principalRuntimeSource, L as needsConfirmation, Ot as runtimeEnvelope, W as member, c as currentInboundRequest, j as ontologyTools, k as actionToolName, kt as telegramRuntimeSource } from "../../../_chunks/principal-DL9NdRRP.mjs";
8
- import { t as agentBuild } from "../../../_chunks/build-metadata-fijGydlU.mjs";
8
+ import { t as agentBuild } from "../../../_chunks/build-metadata-BMaei-TJ.mjs";
9
9
  import { object } from "../confirmation-description.mjs";
10
10
  var AttachmentLifecycleNotPermitted = class extends Error {
11
11
  code = "attachment_lifecycle_not_permitted";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@segmentstream/agent",
3
- "version": "0.97.0",
3
+ "version": "0.98.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",
@@ -88,7 +88,7 @@
88
88
  "@chat-adapter/state-memory": "4.42.0",
89
89
  "@chat-adapter/telegram": "4.41.0",
90
90
  "@chat-adapter/whatsapp": "4.42.0",
91
- "@segmentstream/ontology": "0.177.0",
91
+ "@segmentstream/ontology": "0.178.0",
92
92
  "@vercel/oidc": "^3.8.4",
93
93
  "ai": "^7.0.172",
94
94
  "chat": "4.42.0",