@segmentstream/ontology 0.185.0 → 0.187.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,41 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.187.0
4
+
5
+ An ontology may declare 100 action triggers (`after(…)`), up from 50. `MAX_ACTION_TRIGGERS` is 100,
6
+ and `check` and publication report `workflow_trigger_limit_exceeded` above it. A workflow may carry
7
+ several action triggers, so the count can exceed the 50 workflows an ontology may declare. Each
8
+ trigger still adds its work to every action on its entity, inside that action's transaction.
9
+
10
+ ## 0.186.0
11
+
12
+ The ontology's Slack messages, a post in either voice (`agent_chat.send`), a draft a member approves
13
+ and a reply its review lets go, are rendered and checked as before and handed to the agent's Slack
14
+ channel of the chat's name at `POST /eve/segmentstream/v1/slack/<name>/deliver`, which sends them
15
+ through its app: the exact Markdown with its attribution, with its buttons as blocks, in the thread
16
+ of the message it answers or the chat's thread, and the files with the text, each by a short-lived
17
+ link granted just before. What the channel answers is recorded as the ontology's own send was:
18
+ `sent` with the message's `ts`, `failed` when Slack refused it, or `uncertain`, with each file's
19
+ result and the same payload in the delivery's history.
20
+
21
+ `@segmentstream/ontology/slack` exports the route and its wire types: `slackDeliverRoute`,
22
+ `SlackDeliver`, `SlackDeliverMessage`, `SlackDelivered` and `SlackDeliverRefused`, with
23
+ `ChannelDeliverFile` and `ChannelDeliveredFile`. It also exports `SLACK_POSSIBLY_POSTED`, Slack's
24
+ `ok: false` codes that do not prove nothing was posted, by which both SDKs classify Slack's answers.
25
+
26
+ An agent from before the route answers 404, and one without a Slack channel of the chat's name on
27
+ the connection `chat` names answers `channel_unknown`: the ontology then sends the message through
28
+ that connection itself, as before. This release works with the agent SDK's previous release, and
29
+ the agent SDK's next release works with this ontology SDK's previous one, which never calls the
30
+ route.
31
+
32
+ Action required: upgrade `@segmentstream/agent` together with `@segmentstream/ontology`, and give
33
+ the agent a Slack channel of the name of each Slack channel in the ontology's `chat`, on the same
34
+ connection (`channels.slack.connection` in `agent/segmentstream.json` naming the connection of
35
+ `chat.slack`, and so for a channel of another name). The ontology's own Slack sender, which sends
36
+ for an agent without such a channel, is deprecated and stops on 2027-05-28
37
+ (`ontology.slack-own-sender`).
38
+
3
39
  ## 0.185.0
4
40
 
5
41
  The ontology's WhatsApp messages, a post in either voice (`agent_chat.send`), a draft a member
package/README.md CHANGED
@@ -627,7 +627,7 @@ export default workflow("remindStaleLeads", {
627
627
  (`{ record, before, after }`, typed as the entity's records); `input` omitted means `{}`.
628
628
  `changed(field, { from?, to? })` is a `when` for the common case. A workflow reacts to an action,
629
629
  not to a field. The manifest records the kind, name, description, entity and action, never the
630
- functions. At most 50 action triggers per ontology; `check` reports `invalid-trigger`,
630
+ functions. At most 100 action triggers per ontology; `check` reports `invalid-trigger`,
631
631
  `trigger_action_unknown`, `trigger_function_async` and `workflow_trigger_limit_exceeded`.
632
632
  - `webhook(name, { description, signature?, headers? })` starts the workflow for each delivery a
633
633
  provider pushes to `/api/webhooks/<name>`, whose wire name is unique across the ontology. The
@@ -1582,9 +1582,11 @@ defineOntology({
1582
1582
 
1583
1583
  Its destinations are the `agent_chat` registry's Slack channels, which the agent's Slack channel
1584
1584
  reports, and `slack:private:<member UUID>` for each member paired on Slack, posted to their user
1585
- id. A Slack post is one `chat.postMessage` with `markdown_text`: the member's exact Markdown, then
1586
- the separator and attribution with Markdown escaped and the attribution in italics, as
1587
- `renderSlack` from `@segmentstream/ontology/slack` renders it. `reply_to` is a thread message's
1585
+ id. A Slack post is one `chat.postMessage` with `markdown_text`, which the agent's Slack channel of
1586
+ the chat's name sends through its app (`POST /eve/segmentstream/v1/slack/<name>/deliver`,
1587
+ `slackDeliverRoute`), or the ontology itself for an agent without one: the member's exact
1588
+ Markdown, then the separator and attribution with Markdown escaped and the attribution in italics,
1589
+ as `renderSlack` from `@segmentstream/ontology/slack` renders it. `reply_to` is a thread message's
1588
1590
  `ts`. Slack's `ok: false` refusal consumes the key; a timeout, a 5xx or an unverifiable answer is
1589
1591
  `uncertain`. The receipt's `message_id` is the message's `ts`; it has no URL.
1590
1592
 
@@ -23,6 +23,8 @@ export declare function refuseSlackFiles(files: ReadonlyArray<{
23
23
  /**
24
24
  * Slack: every file uploaded, which nobody sees, then one share of them all with the text: one
25
25
  * visible message. A file that does not upload shares nothing, so the reply is definitely unsent.
26
+ * @legacy ontology.slack-own-sender The ontology's own send of a message with files, which the
27
+ * agent's Slack channel's deliver route does in its place.
26
28
  */
27
29
  export declare function sendSlackWithFiles(input: ChatSend): Effect.Effect<ProviderOutcome>;
28
30
  /** WhatsApp: up to ten files, one message each, by WhatsApp's bound of each type. */
@@ -110,6 +110,8 @@ export function refuseSlackFiles(files) {
110
110
  /**
111
111
  * Slack: every file uploaded, which nobody sees, then one share of them all with the text: one
112
112
  * visible message. A file that does not upload shares nothing, so the reply is definitely unsent.
113
+ * @legacy ontology.slack-own-sender The ontology's own send of a message with files, which the
114
+ * agent's Slack channel's deliver route does in its place.
113
115
  */
114
116
  export function sendSlackWithFiles(input) {
115
117
  return Effect.gen(function* () {
@@ -12,7 +12,13 @@ export declare function slackPayload(finalText: string, plainText: string, butto
12
12
  * message it replies to, else in the chat's thread, such as the one a reviewed reply answers.
13
13
  * Slack's own refusal (`ok: false` with an error code) is definite; a timeout, a 5xx, an
14
14
  * unparseable answer or a success that does not name the message, or its thread, is uncertain.
15
+ * @legacy ontology.slack-own-sender The ontology's own send of a message without files, which the
16
+ * agent's Slack channel's deliver route does in its place.
15
17
  */
16
18
  export declare function sendSlack(input: ChatSend): Effect.Effect<ProviderOutcome>;
17
- /** Slack: the member's Markdown as `markdown_text`, in a channel or a member's direct message. */
19
+ /**
20
+ * Slack: the member's Markdown as `markdown_text`, in a channel or a member's direct message. The
21
+ * ontology renders the message, its text and its buttons, and the agent's Slack channel of the
22
+ * chat's name sends it through its app.
23
+ */
18
24
  export declare const slackProvider: ChatProvider;
@@ -1,18 +1,9 @@
1
- import { Effect } from "effect";
2
- import { renderSlack, SLACK_MESSAGE_LIMIT } from "../../../slack.js";
1
+ import { Cause, Effect } from "effect";
2
+ import { renderSlack, slackDeliverRoute, SLACK_MESSAGE_LIMIT, SLACK_POSSIBLY_POSTED, } from "../../../slack.js";
3
3
  import { refuseSlackFiles, sendSlackWithFiles, SLACK_FILE_LIMITS } from "./files-send.js";
4
- import { record, transportFailure, } from "./provider.js";
4
+ import { agentFileLinks, deliveredFiles, postToAgent, record, transportFailure, } from "./provider.js";
5
5
  /** A message's `ts`, which also names the thread it starts. */
6
6
  const SLACK_TS = /^[0-9]+\.[0-9]+$/;
7
- /**
8
- * Slack's `ok: false` codes that do not prove the message was not posted: Slack says some of the
9
- * operation may have succeeded before the error.
10
- */
11
- const POSSIBLY_POSTED = new Set([
12
- "internal_error",
13
- "fatal_error",
14
- "service_unavailable",
15
- ]);
16
7
  /**
17
8
  * A message with buttons as Slack shows it: the Markdown in a `markdown` block, then a row of
18
9
  * buttons in an `actions` block each, a workspace button's value `ws:<token>`, with the plain text
@@ -38,17 +29,34 @@ export function slackPayload(finalText, plainText, buttons) {
38
29
  ],
39
30
  };
40
31
  }
32
+ /**
33
+ * The thread a message without files goes in: the one of the message it replies to, else the
34
+ * chat's thread, such as the one a reviewed reply answers, when it is a Slack `ts`.
35
+ */
36
+ function messageThread(input) {
37
+ return (input.replyTo ??
38
+ (typeof input.threadId === "string" && SLACK_TS.test(input.threadId) ? input.threadId : null));
39
+ }
40
+ /**
41
+ * The thread a message with files is shared in: the one of the message it replies to, else the
42
+ * chat's thread, whatever it is.
43
+ */
44
+ function filesThread(input) {
45
+ const thread = input.replyTo ?? input.threadId ?? null;
46
+ return thread === "" ? null : thread;
47
+ }
41
48
  /**
42
49
  * One `chat.postMessage` through the connection's `web` API, never retried, in the thread of the
43
50
  * message it replies to, else in the chat's thread, such as the one a reviewed reply answers.
44
51
  * Slack's own refusal (`ok: false` with an error code) is definite; a timeout, a 5xx, an
45
52
  * unparseable answer or a success that does not name the message, or its thread, is uncertain.
53
+ * @legacy ontology.slack-own-sender The ontology's own send of a message without files, which the
54
+ * agent's Slack channel's deliver route does in its place.
46
55
  */
47
56
  export function sendSlack(input) {
48
57
  return Effect.gen(function* () {
49
58
  const payload = slackPayload(input.finalText, input.plainText, input.buttons);
50
- const thread = input.replyTo ??
51
- (typeof input.threadId === "string" && SLACK_TS.test(input.threadId) ? input.threadId : null);
59
+ const thread = messageThread(input);
52
60
  const result = yield* input.transport
53
61
  .request({
54
62
  connection: input.connection,
@@ -85,7 +93,7 @@ export function sendSlack(input) {
85
93
  }
86
94
  if (body.ok === false && typeof body.error === "string" && body.error !== "") {
87
95
  const cause = new Error(`Slack refused the message: ${body.error}.`);
88
- return POSSIBLY_POSTED.has(body.error)
96
+ return SLACK_POSSIBLY_POSTED.has(body.error)
89
97
  ? uncertain(cause)
90
98
  : { payload, status: "failed", messageId: null, url: null, cause };
91
99
  }
@@ -105,7 +113,11 @@ export function sendSlack(input) {
105
113
  return { payload, status: "sent", messageId: body.ts, url: null };
106
114
  });
107
115
  }
108
- /** Slack: the member's Markdown as `markdown_text`, in a channel or a member's direct message. */
116
+ /**
117
+ * Slack: the member's Markdown as `markdown_text`, in a channel or a member's direct message. The
118
+ * ontology renders the message, its text and its buttons, and the agent's Slack channel of the
119
+ * chat's name sends it through its app.
120
+ */
109
121
  export const slackProvider = {
110
122
  provider: "slack",
111
123
  limit: SLACK_MESSAGE_LIMIT,
@@ -123,5 +135,134 @@ export const slackProvider = {
123
135
  refuseButtons: () => undefined,
124
136
  files: SLACK_FILE_LIMITS,
125
137
  refuseFiles: refuseSlackFiles,
126
- send: (input) => ((input.files ?? []).length > 0 ? sendSlackWithFiles(input) : sendSlack(input)),
138
+ send: deliverSlack,
127
139
  };
140
+ /**
141
+ * One message, rendered here and sent by the agent's Slack channel; by the ontology itself for an
142
+ * agent without its deliver route.
143
+ */
144
+ function deliverSlack(input) {
145
+ return Effect.gen(function* () {
146
+ if (input.agent?.origin !== undefined && input.agent.identityToken !== undefined) {
147
+ const delivered = yield* deliverThroughAgent(input);
148
+ if (delivered !== undefined) {
149
+ return delivered;
150
+ }
151
+ }
152
+ // @legacy ontology.slack-own-sender The ontology's own Slack sender, for an agent without the
153
+ // Slack channel's deliver route or without a Slack channel of the chat's name on its
154
+ // connection: the message, or each file's bytes and then their share, through the ontology's
155
+ // connection.
156
+ return yield* (input.files ?? []).length > 0 ? sendSlackWithFiles(input) : sendSlack(input);
157
+ });
158
+ }
159
+ /**
160
+ * How long the agent's Slack channel has to send one message: its `chat.postMessage`, or each
161
+ * file's upload and then their share, through the connection.
162
+ */
163
+ const AGENT_DELIVER_TIMEOUT_MS = 90_000;
164
+ /**
165
+ * One message through the agent's Slack channel (`POST` {@link slackDeliverRoute}), never retried:
166
+ * the channel sends what is rendered here through its app, the message, or the files and then
167
+ * their share with the text. Undefined when the agent has no such route (`404`) or no Slack channel
168
+ * of the chat's name on this connection (`channel_unknown`), so the ontology sends it itself. The
169
+ * agent's other `4xx` sent nothing; a `2xx` says what reached the person; a timeout, a `5xx` or an
170
+ * answer without its shape may have sent it, and is uncertain.
171
+ */
172
+ function deliverThroughAgent(input) {
173
+ return Effect.gen(function* () {
174
+ const files = input.files ?? [];
175
+ const message = slackPayload(input.finalText, input.plainText, input.buttons);
176
+ // What the delivery's history keeps, as the ontology's own sender kept it.
177
+ const payload = files.length === 0 ? message : { initial_comment: input.finalText };
178
+ const outcome = (status, results, rest) => ({
179
+ payload: results === undefined
180
+ ? payload
181
+ : {
182
+ ...payload,
183
+ files: results.map((result) => ({
184
+ index: result.index,
185
+ filename: files[result.index]?.filename ?? "",
186
+ status: result.status,
187
+ messageId: result.messageId,
188
+ })),
189
+ },
190
+ status,
191
+ ...rest,
192
+ ...(results === undefined ? {} : { files: results }),
193
+ });
194
+ const unsent = files.length === 0
195
+ ? undefined
196
+ : files.map((_file, index) => ({ index, status: "failed", messageId: null }));
197
+ const links = yield* agentFileLinks(files).pipe(Effect.exit);
198
+ if (links._tag === "Failure") {
199
+ return outcome("failed", unsent, {
200
+ messageId: null,
201
+ url: null,
202
+ cause: Cause.squash(links.cause),
203
+ });
204
+ }
205
+ const body = {
206
+ operation_id: input.operationId ?? input.destination.id,
207
+ connection: input.connection,
208
+ ...(files.length === 0
209
+ ? {
210
+ channel: input.destination.external_id,
211
+ thread_ts: messageThread(input),
212
+ message: message,
213
+ }
214
+ : {
215
+ // Files are shared in the chat itself: a direct message's channel, not its member's id.
216
+ channel: input.chatId ?? input.destination.external_id,
217
+ thread_ts: filesThread(input),
218
+ // A message of files alone has no text to share them with.
219
+ ...(input.plainText.trim() === "" ? {} : { initial_comment: input.finalText }),
220
+ files: links.value,
221
+ }),
222
+ };
223
+ const answered = yield* postToAgent(input.agent, slackDeliverRoute(input.destination.provider), body, AGENT_DELIVER_TIMEOUT_MS).pipe(Effect.exit);
224
+ if (answered._tag === "Failure") {
225
+ return outcome("uncertain", undefined, {
226
+ messageId: null,
227
+ url: null,
228
+ cause: Cause.squash(answered.cause),
229
+ });
230
+ }
231
+ const { status, answer } = answered.value;
232
+ if (status === 404 || (status === 422 && answer.error === "channel_unknown")) {
233
+ return undefined;
234
+ }
235
+ if (status >= 400 && status < 500) {
236
+ return outcome("failed", unsent, {
237
+ messageId: null,
238
+ url: null,
239
+ cause: new Error(`The agent's Slack channel refused the message (${typeof answer.error === "string" ? answer.error : `status ${status}`}${typeof answer.reference === "string" ? `, reference ${answer.reference}` : ""}).`),
240
+ });
241
+ }
242
+ const results = deliveredFiles(answer.files, files.length, SLACK_TS);
243
+ const id = answer.message_id;
244
+ if (status < 200 ||
245
+ status >= 300 ||
246
+ (answer.status !== "sent" && answer.status !== "uncertain") ||
247
+ (id !== null && (typeof id !== "string" || !SLACK_TS.test(id))) ||
248
+ // A message is sent with its `ts`; a share of files may be one Slack's answer names none of.
249
+ (answer.status === "sent" &&
250
+ ((files.length === 0 && id === null) ||
251
+ results?.some((result) => result.status !== "sent") === true)) ||
252
+ (files.length > 0 && results === undefined)) {
253
+ return outcome("uncertain", undefined, {
254
+ messageId: null,
255
+ url: null,
256
+ cause: new Error(`The agent's Slack channel answered with status ${status}.`),
257
+ });
258
+ }
259
+ return answer.status === "sent"
260
+ ? outcome("sent", results, { messageId: id, url: null })
261
+ : outcome("uncertain", results, {
262
+ messageId: id,
263
+ url: null,
264
+ cause: new Error("The agent's Slack channel could not prove the message sent" +
265
+ `${typeof answer.reference === "string" ? ` (reference ${answer.reference})` : ""}.`),
266
+ });
267
+ });
268
+ }
@@ -1,14 +1,15 @@
1
1
  import { type ChannelFile, type ChannelPart, type ChannelRequest, type ChannelStoredFile, type DefiniteFailure } from "./channel-files.js";
2
2
  /**
3
- * Slack's message with files, which the agent's `attachments_send` and the ontology's delivery of
4
- * an approved draft both send, with Slack's external upload: each file's bytes go to the address
5
- * `files.getUploadURLExternal` answers, then one `files.completeUploadExternal` shares all of them
6
- * in the chat with the text, as one visible message. Nothing is visible until that share, so a
7
- * file that fails to upload is left out without anything reaching the person. The Web API calls
8
- * go on the connection's `web` API. The bytes go on its `files` API, within one request's body,
9
- * or, given a `fetch`, straight to the upload address, which carries its own authorization and
10
- * needs no credential of the connection's: a stored file then streams from the workspace's file
11
- * storage to Slack without being held whole, up to Slack's own bound.
3
+ * Slack's message with files, which the agent's `attachments_send`, the agent's Slack channel's
4
+ * deliver route and the ontology's own sender all send, with Slack's external upload: each file's
5
+ * bytes go to the address `files.getUploadURLExternal` answers, then one
6
+ * `files.completeUploadExternal` shares all of them in the chat with the text, as one visible
7
+ * message. Nothing is visible until that share, so a file that fails to upload is left out without
8
+ * anything reaching the person. The Web API calls go on the connection's `web` API. The bytes go on
9
+ * its `files` API, within one request's body, or, given a `fetch`, straight to the upload address,
10
+ * which carries its own authorization and needs no credential of the connection's: a stored file
11
+ * then streams from the workspace's file storage to Slack without being held whole, up to Slack's
12
+ * own bound.
12
13
  */
13
14
  /** The most bytes of one file a single connection request carries to Slack. */
14
15
  export declare const SLACK_FILE_BYTES: number;
@@ -16,6 +17,11 @@ export declare const SLACK_FILE_BYTES: number;
16
17
  export declare const SLACK_UPLOAD_BYTES: number;
17
18
  /** The most files one `files.completeUploadExternal` shares. */
18
19
  export declare const SLACK_FILES_PER_MESSAGE = 10;
20
+ /**
21
+ * Slack's `ok: false` codes that do not prove a message or a share was not posted: Slack says some
22
+ * of the operation may have succeeded before the error. Every other code proves nothing was.
23
+ */
24
+ export declare const SLACK_POSSIBLY_POSTED: ReadonlySet<string>;
19
25
  /**
20
26
  * Why Slack cannot take this file through one connection request, or, uploaded straight to its
21
27
  * address (`direct`), at all; undefined when it can.
@@ -1,15 +1,16 @@
1
1
  import { ChannelAnswerError, fileSize, isRecord, isStoredFile, replyJson, unrelayed, } from "./channel-files.js";
2
2
  import { MAXIMUM_CONNECTION_BODY_BYTES } from "./connection.js";
3
3
  /**
4
- * Slack's message with files, which the agent's `attachments_send` and the ontology's delivery of
5
- * an approved draft both send, with Slack's external upload: each file's bytes go to the address
6
- * `files.getUploadURLExternal` answers, then one `files.completeUploadExternal` shares all of them
7
- * in the chat with the text, as one visible message. Nothing is visible until that share, so a
8
- * file that fails to upload is left out without anything reaching the person. The Web API calls
9
- * go on the connection's `web` API. The bytes go on its `files` API, within one request's body,
10
- * or, given a `fetch`, straight to the upload address, which carries its own authorization and
11
- * needs no credential of the connection's: a stored file then streams from the workspace's file
12
- * storage to Slack without being held whole, up to Slack's own bound.
4
+ * Slack's message with files, which the agent's `attachments_send`, the agent's Slack channel's
5
+ * deliver route and the ontology's own sender all send, with Slack's external upload: each file's
6
+ * bytes go to the address `files.getUploadURLExternal` answers, then one
7
+ * `files.completeUploadExternal` shares all of them in the chat with the text, as one visible
8
+ * message. Nothing is visible until that share, so a file that fails to upload is left out without
9
+ * anything reaching the person. The Web API calls go on the connection's `web` API. The bytes go on
10
+ * its `files` API, within one request's body, or, given a `fetch`, straight to the upload address,
11
+ * which carries its own authorization and needs no credential of the connection's: a stored file
12
+ * then streams from the workspace's file storage to Slack without being held whole, up to Slack's
13
+ * own bound.
13
14
  */
14
15
  /** The most bytes of one file a single connection request carries to Slack. */
15
16
  export const SLACK_FILE_BYTES = MAXIMUM_CONNECTION_BODY_BYTES;
@@ -22,10 +23,10 @@ export const SLACK_FILES_PER_MESSAGE = 10;
22
23
  /** Where Slack's upload addresses are, which the connection's `files` API reaches. */
23
24
  const SLACK_FILES = "https://files.slack.com/";
24
25
  /**
25
- * Slack's `ok: false` codes that do not prove the share was not posted: Slack says some of the
26
- * operation may have succeeded before the error.
26
+ * Slack's `ok: false` codes that do not prove a message or a share was not posted: Slack says some
27
+ * of the operation may have succeeded before the error. Every other code proves nothing was.
27
28
  */
28
- const POSSIBLY_POSTED = new Set([
29
+ export const SLACK_POSSIBLY_POSTED = new Set([
29
30
  "internal_error",
30
31
  "fatal_error",
31
32
  "service_unavailable",
@@ -244,7 +245,7 @@ export async function sendSlackFiles(options) {
244
245
  isRecord(answer) &&
245
246
  answer.ok === false &&
246
247
  error !== "" &&
247
- !POSSIBLY_POSTED.has(error);
248
+ !SLACK_POSSIBLY_POSTED.has(error);
248
249
  return {
249
250
  uploads,
250
251
  share: {
package/dist/slack.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { ChannelDeliverFile, ChannelDeliveredFile } from "./channel-files.js";
1
2
  /**
2
3
  * Slack's text for an exact chat post. The ontology service sends it and the agent's
3
4
  * confirmation computes it from the same function, so the digest the member approves and the
@@ -13,6 +14,75 @@ export declare function escapeSlackMarkdown(text: string): string;
13
14
  * Markdown.
14
15
  */
15
16
  export declare function renderSlack(markdown: string, attribution: string, separator?: string): string;
16
- export type { ChannelCall, ChannelCallFile, ChannelFile, ChannelFileRead, ChannelPart, ChannelReply, ChannelRequest, ChannelStoredFile, DefiniteFailure, } from "./channel-files.js";
17
+ /**
18
+ * Where the agent's Slack channel `name` delivers a message the ontology sends: a draft a member
19
+ * approved, a reply its review let go, a member's or a service's post. The ontology decides and
20
+ * renders it, its exact Markdown with its attribution and its buttons; the channel sends it through
21
+ * its app as given, in one operation. Only the deployment's own functions may call it.
22
+ */
23
+ export declare function slackDeliverRoute(name: string): string;
24
+ /**
25
+ * One message as `chat.postMessage` takes it, without where it goes: the Markdown as
26
+ * `markdown_text`, or, with buttons, the text for notifications and the `blocks` that show the
27
+ * Markdown and each row of buttons.
28
+ */
29
+ export type SlackDeliverMessage = {
30
+ readonly markdown_text: string;
31
+ } | {
32
+ readonly text: string;
33
+ readonly blocks: ReadonlyArray<Readonly<Record<string, unknown>>>;
34
+ };
35
+ /** One message for the agent's Slack channel to send (`POST` {@link slackDeliverRoute}). */
36
+ export interface SlackDeliver {
37
+ /** The ontology's delivery, which the agent's diagnostics name. */
38
+ readonly operation_id: string;
39
+ /**
40
+ * The connection the ontology's `chat` names for the channel: the channel sends only through
41
+ * the same app, and answers `channel_unknown` otherwise.
42
+ */
43
+ readonly connection: string;
44
+ /**
45
+ * Where it goes, by Slack's id: a channel, or a member, whose direct message Slack posts a message
46
+ * to; files are shared in the direct message itself, by its own id.
47
+ */
48
+ readonly channel: string;
49
+ /** The `ts` of the thread it goes in, which Slack must confirm; `null` for none. */
50
+ readonly thread_ts: string | null;
51
+ /** The message, for one without files. */
52
+ readonly message?: SlackDeliverMessage;
53
+ /** The text of a message with files, shared with them as one message. */
54
+ readonly initial_comment?: string;
55
+ /**
56
+ * The files, in order, each uploaded and then all shared at once with the text: nothing is
57
+ * shared unless every one uploaded. At most `SLACK_FILES_PER_MESSAGE`.
58
+ */
59
+ readonly files?: ReadonlyArray<ChannelDeliverFile>;
60
+ }
61
+ /**
62
+ * The agent's answer once it sent something: `sent` when Slack's answer proves the message, or the
63
+ * share of the files, posted; `uncertain` when it may have, with what became of each file. A `4xx`
64
+ * with {@link SlackDeliverRefused} sent nothing (`404` alone: an agent without the route); anything
65
+ * else may have sent it.
66
+ */
67
+ export interface SlackDelivered {
68
+ readonly status: "sent" | "uncertain";
69
+ /** The message's `ts`; a share of files Slack's answer names none of has `null`. */
70
+ readonly message_id: string | null;
71
+ readonly files?: ReadonlyArray<ChannelDeliveredFile>;
72
+ /** The agent's diagnostic of what did not go, when something did not. */
73
+ readonly reference?: string;
74
+ }
75
+ /**
76
+ * Why the agent sent nothing (`4xx`): `channel_unknown` when it has no Slack channel of the name on
77
+ * the connection, so the ontology sends the message itself; `provider_refused` when Slack refused
78
+ * it, or refused a file, so that nothing was shared; `connection_refused` when SegmentStream's
79
+ * connection refused the call; or the request's own fault, such as `invalid_request` or
80
+ * `file_too_large`.
81
+ */
82
+ export interface SlackDeliverRefused {
83
+ readonly error: string;
84
+ readonly reference?: string;
85
+ }
86
+ export type { ChannelCall, ChannelCallFile, ChannelDeliverFile, ChannelDeliveredFile, ChannelFile, ChannelFileRead, ChannelPart, ChannelReply, ChannelRequest, ChannelStoredFile, DefiniteFailure, } from "./channel-files.js";
17
87
  export { CHANNEL_FILE_FRAME_BYTES, ChannelAnswerError } from "./channel-files.js";
18
- export { sendSlackFiles, slackFileRefusal, SLACK_FILE_BYTES, SLACK_FILES_PER_MESSAGE, SLACK_UPLOAD_BYTES, type SlackFilesResult, } from "./slack-files.js";
88
+ export { sendSlackFiles, slackFileRefusal, SLACK_FILE_BYTES, SLACK_FILES_PER_MESSAGE, SLACK_POSSIBLY_POSTED, SLACK_UPLOAD_BYTES, type SlackFilesResult, } from "./slack-files.js";
package/dist/slack.js CHANGED
@@ -21,5 +21,14 @@ export function renderSlack(markdown, attribution, separator = "\n\n") {
21
21
  ? markdown
22
22
  : `${markdown}${escapeSlackMarkdown(separator)}_${escapeSlackMarkdown(attribution)}_`;
23
23
  }
24
+ /**
25
+ * Where the agent's Slack channel `name` delivers a message the ontology sends: a draft a member
26
+ * approved, a reply its review let go, a member's or a service's post. The ontology decides and
27
+ * renders it, its exact Markdown with its attribution and its buttons; the channel sends it through
28
+ * its app as given, in one operation. Only the deployment's own functions may call it.
29
+ */
30
+ export function slackDeliverRoute(name) {
31
+ return `/eve/segmentstream/v1/slack/${name}/deliver`;
32
+ }
24
33
  export { CHANNEL_FILE_FRAME_BYTES, ChannelAnswerError } from "./channel-files.js";
25
- export { sendSlackFiles, slackFileRefusal, SLACK_FILE_BYTES, SLACK_FILES_PER_MESSAGE, SLACK_UPLOAD_BYTES, } from "./slack-files.js";
34
+ export { sendSlackFiles, slackFileRefusal, SLACK_FILE_BYTES, SLACK_FILES_PER_MESSAGE, SLACK_POSSIBLY_POSTED, SLACK_UPLOAD_BYTES, } from "./slack-files.js";
@@ -16,9 +16,9 @@ export declare const MAX_WORKFLOWS = 50;
16
16
  * action evaluates the triggers on its entity inside its own transaction, so this bounds the work
17
17
  * one action can add: about 4 to 6 ms per trigger for a batch create of 100 records, nothing
18
18
  * measurable for a single update. It does not bound the runs a bulk action starts, one per edited
19
- * record. As many as the workflows an ontology may declare.
19
+ * record. A workflow may carry several, so it exceeds the workflows an ontology may declare.
20
20
  */
21
- export declare const MAX_ACTION_TRIGGERS = 50;
21
+ export declare const MAX_ACTION_TRIGGERS = 100;
22
22
  /**
23
23
  * What a trigger listed in `defineOntology({ triggers })` runs instead of a workflow: one action,
24
24
  * in a durable run retried like a step, as the trigger's own workflow user holding `role`. The
package/dist/workflow.js CHANGED
@@ -10,9 +10,9 @@ export const MAX_WORKFLOWS = 50;
10
10
  * action evaluates the triggers on its entity inside its own transaction, so this bounds the work
11
11
  * one action can add: about 4 to 6 ms per trigger for a batch create of 100 records, nothing
12
12
  * measurable for a single update. It does not bound the runs a bulk action starts, one per edited
13
- * record. As many as the workflows an ontology may declare.
13
+ * record. A workflow may carry several, so it exceeds the workflows an ontology may declare.
14
14
  */
15
- export const MAX_ACTION_TRIGGERS = 50;
15
+ export const MAX_ACTION_TRIGGERS = 100;
16
16
  /** Declares a cron trigger; list it in `workflow(name, { triggers })`. UTC, five fields. */
17
17
  export function cron(name, expression, options) {
18
18
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@segmentstream/ontology",
3
- "version": "0.185.0",
3
+ "version": "0.187.0",
4
4
  "description": "Define a SegmentStream workspace app's ontology: entities, relationships, roles and actions, written with Effect.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "SegmentStream",