@segmentstream/ontology 0.163.0 → 0.165.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 +28 -0
- package/dist/agent-chat.d.ts +10 -0
- package/dist/agent-draft.d.ts +18 -6
- package/dist/agent-draft.js +29 -0
- package/dist/chat.d.ts +18 -0
- package/dist/chat.js +10 -0
- package/dist/email.d.ts +1 -1
- package/dist/email.js +1 -1
- package/dist/gmail-send.d.ts +10 -0
- package/dist/gmail-send.js +31 -9
- package/dist/manifest.d.ts +469 -469
- package/dist/migrate/model.d.ts +351 -351
- package/dist/service/chat/delivery.js +79 -3
- package/dist/service/chat/draft-files.d.ts +7 -0
- package/dist/service/chat/draft-files.js +33 -4
- package/dist/service/chat/envelope.d.ts +6 -6
- package/dist/service/chat/local-reads.d.ts +1 -1
- package/dist/service/chat/providers/custom.js +2 -2
- package/dist/service/chat/providers/email.js +13 -11
- package/dist/service/chat/providers/files-send.d.ts +36 -0
- package/dist/service/chat/providers/files-send.js +182 -0
- package/dist/service/chat/providers/provider.d.ts +22 -3
- package/dist/service/chat/providers/provider.js +43 -0
- package/dist/service/chat/providers/slack.js +4 -1
- package/dist/service/chat/providers/telegram.js +23 -3
- package/dist/service/chat/providers/whatsapp.js +4 -1
- package/dist/service/chat/review-delivery.d.ts +4 -2
- package/dist/service/chat/review-delivery.js +22 -2
- package/dist/service/chat/schemas.d.ts +5 -0
- package/dist/service/discovery-search.d.ts +1 -1
- package/dist/slack-files.d.ts +2 -0
- package/dist/slack-files.js +1 -1
- package/dist/telegram-files.d.ts +4 -0
- package/dist/telegram-files.js +6 -2
- package/dist/user-identity.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
import { renderSlack, SLACK_MESSAGE_LIMIT } from "../../../slack.js";
|
|
3
|
+
import { refuseSlackFiles, sendSlackWithFiles, SLACK_FILE_LIMITS } from "./files-send.js";
|
|
3
4
|
import { record, transportFailure, } from "./provider.js";
|
|
4
5
|
/** A message's `ts`, which also names the thread it starts. */
|
|
5
6
|
const SLACK_TS = /^[0-9]+\.[0-9]+$/;
|
|
@@ -120,5 +121,7 @@ export const slackProvider = {
|
|
|
120
121
|
payload: (finalText, buttons) => slackPayload(finalText, finalText, buttons),
|
|
121
122
|
// Each row is an actions block; labels and rows fit within what the schema allows.
|
|
122
123
|
refuseButtons: () => undefined,
|
|
123
|
-
|
|
124
|
+
files: SLACK_FILE_LIMITS,
|
|
125
|
+
refuseFiles: refuseSlackFiles,
|
|
126
|
+
send: (input) => ((input.files ?? []).length > 0 ? sendSlackWithFiles(input) : sendSlack(input)),
|
|
124
127
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isTelegramBotUsername, miniAppLink, telegramMarkdownLinks, telegramMarkdownWithLinks, telegramTextLinks, telegramPreviewOptions, } from "../../../telegram.js";
|
|
2
2
|
import { escapeMarkdownV2, TelegramFormatConverter } from "@chat-adapter/telegram";
|
|
3
3
|
import { Effect } from "effect";
|
|
4
|
+
import { refuseTelegramFiles, sendTelegramWithFiles, TELEGRAM_FILE_LIMITS } from "./files-send.js";
|
|
4
5
|
import { record, transportFailure, } from "./provider.js";
|
|
5
6
|
export const TELEGRAM_MESSAGE_LIMIT = 4096;
|
|
6
7
|
const converter = new TelegramFormatConverter();
|
|
@@ -218,7 +219,26 @@ export const telegramProvider = {
|
|
|
218
219
|
}),
|
|
219
220
|
// An inline keyboard takes every row the schema allows; a token fits its callback data.
|
|
220
221
|
refuseButtons: () => undefined,
|
|
221
|
-
|
|
222
|
+
files: TELEGRAM_FILE_LIMITS,
|
|
223
|
+
refuseFiles: refuseTelegramFiles,
|
|
224
|
+
send: (input) => (input.files ?? []).length > 0 ? sendTelegramFilesReply(input) : sendTelegramText(input),
|
|
225
|
+
};
|
|
226
|
+
/**
|
|
227
|
+
* A reply with files: its text, when it goes as a caption, leads to the app where a text reply
|
|
228
|
+
* would, so its links to the app open in the bot's Mini App too.
|
|
229
|
+
*/
|
|
230
|
+
function sendTelegramFilesReply(input) {
|
|
231
|
+
return Effect.gen(function* () {
|
|
232
|
+
const links = yield* miniAppLinksOf(input, telegramMarkdownLinks(input.text));
|
|
233
|
+
const finalText = links.size === 0
|
|
234
|
+
? input.finalText
|
|
235
|
+
: renderTelegram(input.text, input.attribution, input.separator, links);
|
|
236
|
+
return yield* sendTelegramWithFiles({ ...input, finalText }, sendTelegramText);
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
/** A text reply or post: the member's Markdown, with the chat's links to the app and previews. */
|
|
240
|
+
function sendTelegramText(input) {
|
|
241
|
+
return Effect.gen(function* () {
|
|
222
242
|
const written = [
|
|
223
243
|
...telegramMarkdownLinks(input.text),
|
|
224
244
|
...telegramTextLinks(input.separator),
|
|
@@ -253,5 +273,5 @@ export const telegramProvider = {
|
|
|
253
273
|
? {}
|
|
254
274
|
: { replyMarkup: telegramKeyboard(input.buttons, links) }),
|
|
255
275
|
});
|
|
256
|
-
})
|
|
257
|
-
}
|
|
276
|
+
});
|
|
277
|
+
}
|
|
@@ -2,6 +2,7 @@ import { Effect } from "effect";
|
|
|
2
2
|
import { renderWhatsApp, WHATSAPP_MESSAGE_LIMIT } from "../../../whatsapp.js";
|
|
3
3
|
import { whatsappTemplate } from "./whatsapp-template.js";
|
|
4
4
|
import { REFUSALS, WAMID } from "./whatsapp-refusals.js";
|
|
5
|
+
import { refuseWhatsAppFiles, sendWhatsAppWithFiles, WHATSAPP_FILE_LIMITS } from "./files-send.js";
|
|
5
6
|
import { record, transportFailure, } from "./provider.js";
|
|
6
7
|
/** A WhatsApp id: the member's number, digits only. */
|
|
7
8
|
const WA_ID = /^[1-9][0-9]{5,19}$/;
|
|
@@ -155,6 +156,8 @@ export const whatsappProvider = {
|
|
|
155
156
|
? { type: "text", text: { body: finalText, preview_url: false } }
|
|
156
157
|
: whatsappInteractive(finalText, buttons),
|
|
157
158
|
refuseButtons: refuseWhatsAppButtons,
|
|
158
|
-
|
|
159
|
+
files: WHATSAPP_FILE_LIMITS,
|
|
160
|
+
refuseFiles: refuseWhatsAppFiles,
|
|
161
|
+
send: (input) => (input.files ?? []).length > 0 ? sendWhatsAppWithFiles(input) : sendWhatsApp(input),
|
|
159
162
|
template: whatsappTemplate,
|
|
160
163
|
};
|
|
@@ -39,16 +39,18 @@ export declare function reviewSender(input: {
|
|
|
39
39
|
/** Reads a file's bytes by its download grant; `fetch` by default. */
|
|
40
40
|
readonly fetch?: typeof fetch;
|
|
41
41
|
}): (send: ReviewSendInput) => Effect.Effect<{
|
|
42
|
+
files?: readonly import("../../agent-draft.js").AgentDraftFile[] | undefined;
|
|
42
43
|
recipients?: EmailRecipients | undefined;
|
|
43
44
|
message?: string | undefined;
|
|
44
|
-
status: "sent" | "
|
|
45
|
+
status: "sent" | "failed" | "uncertain";
|
|
45
46
|
text: string;
|
|
46
47
|
messageId: string | null;
|
|
47
48
|
duplicate: true;
|
|
48
49
|
} | {
|
|
50
|
+
files?: readonly import("../../agent-draft.js").AgentDraftFile[] | undefined;
|
|
49
51
|
recipients?: EmailRecipients | undefined;
|
|
50
52
|
message?: string | undefined;
|
|
51
|
-
status: "sent" | "
|
|
53
|
+
status: "sent" | "failed" | "uncertain";
|
|
52
54
|
text: string;
|
|
53
55
|
messageId: string | null;
|
|
54
56
|
duplicate: false;
|
|
@@ -106,10 +106,26 @@ export function reviewSender(input) {
|
|
|
106
106
|
}),
|
|
107
107
|
})
|
|
108
108
|
: undefined;
|
|
109
|
+
const heldFiles = draftFilesOf(review.files);
|
|
110
|
+
// An approval may leave files out, never add one: each it names is one the draft holds.
|
|
111
|
+
const files = send.files === undefined
|
|
112
|
+
? heldFiles
|
|
113
|
+
: heldFiles.filter((file) => send.files.some((named) => named.entity === file.entity &&
|
|
114
|
+
named.id.toLowerCase() === file.id &&
|
|
115
|
+
named.property === file.property &&
|
|
116
|
+
named.revisionId === file.revisionId));
|
|
117
|
+
if (send.files !== undefined && files.length !== send.files.length) {
|
|
118
|
+
return yield* new ActionRejected({
|
|
119
|
+
message: "An approval sends only files the draft holds; nothing was sent.",
|
|
120
|
+
refusal: "file_not_held",
|
|
121
|
+
});
|
|
122
|
+
}
|
|
109
123
|
if (status !== "pending") {
|
|
110
124
|
if ((status === "sent" || status === "uncertain") &&
|
|
111
125
|
text === review.text &&
|
|
112
|
-
(recipients === undefined || sameRecipients(recipients, review))
|
|
126
|
+
(recipients === undefined || sameRecipients(recipients, review)) &&
|
|
127
|
+
// The draft keeps the files it sent: another choice of them is another approval.
|
|
128
|
+
(send.files === undefined || files.length === heldFiles.length)) {
|
|
113
129
|
return {
|
|
114
130
|
status,
|
|
115
131
|
text,
|
|
@@ -117,6 +133,7 @@ export function reviewSender(input) {
|
|
|
117
133
|
duplicate: true,
|
|
118
134
|
...(typeof review.message === "string" ? { message: review.message } : {}),
|
|
119
135
|
...(recipients === undefined ? {} : { recipients }),
|
|
136
|
+
...(files.length === 0 && send.files === undefined ? {} : { files }),
|
|
120
137
|
};
|
|
121
138
|
}
|
|
122
139
|
return yield* new ActionRejected({
|
|
@@ -163,7 +180,6 @@ export function reviewSender(input) {
|
|
|
163
180
|
try: () => provider.render(text, "", ""),
|
|
164
181
|
catch: (cause) => new ActionRejected({ message: "The Markdown could not be rendered.", cause }),
|
|
165
182
|
});
|
|
166
|
-
const files = draftFilesOf(review.files);
|
|
167
183
|
if ((text.trim() === "" && files.length === 0) ||
|
|
168
184
|
text.length > AGENT_DRAFT_TEXT_LIMIT ||
|
|
169
185
|
finalText.length > provider.limit ||
|
|
@@ -320,6 +336,7 @@ export function reviewSender(input) {
|
|
|
320
336
|
messageId: earlier.messageId,
|
|
321
337
|
duplicate: true,
|
|
322
338
|
...(recipients === undefined ? {} : { recipients }),
|
|
339
|
+
...(files.length === 0 && send.files === undefined ? {} : { files }),
|
|
323
340
|
};
|
|
324
341
|
}
|
|
325
342
|
// Each file as its person may read it now, the revision held: everything that can fail is
|
|
@@ -329,6 +346,7 @@ export function reviewSender(input) {
|
|
|
329
346
|
person,
|
|
330
347
|
files,
|
|
331
348
|
fetch: input.fetch ?? fetch,
|
|
349
|
+
...(provider.files?.transfer === undefined ? {} : { transfer: provider.files.transfer }),
|
|
332
350
|
});
|
|
333
351
|
if (sendFiles === undefined) {
|
|
334
352
|
return yield* refused("file_unavailable", providerName);
|
|
@@ -420,6 +438,7 @@ export function reviewSender(input) {
|
|
|
420
438
|
duplicate: true,
|
|
421
439
|
...(message === null ? {} : { message }),
|
|
422
440
|
...(recipients === undefined ? {} : { recipients }),
|
|
441
|
+
...(files.length === 0 && send.files === undefined ? {} : { files }),
|
|
423
442
|
};
|
|
424
443
|
}
|
|
425
444
|
if (reserve.version !== 1 ||
|
|
@@ -482,6 +501,7 @@ export function reviewSender(input) {
|
|
|
482
501
|
duplicate: false,
|
|
483
502
|
...(message === null ? {} : { message }),
|
|
484
503
|
...(recipients === undefined ? {} : { recipients }),
|
|
504
|
+
...(files.length === 0 && send.files === undefined ? {} : { files }),
|
|
485
505
|
};
|
|
486
506
|
});
|
|
487
507
|
}
|
|
@@ -3,6 +3,11 @@ export declare const ChatPostWire: Schema.encodeKeys<Schema.Struct<{
|
|
|
3
3
|
readonly chat: Schema.String;
|
|
4
4
|
readonly text: Schema.String;
|
|
5
5
|
readonly replyTo: Schema.optionalKey<Schema.String>;
|
|
6
|
+
readonly files: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
7
|
+
readonly entity: Schema.String;
|
|
8
|
+
readonly id: Schema.String;
|
|
9
|
+
readonly property: Schema.optionalKey<Schema.String>;
|
|
10
|
+
}>>>;
|
|
6
11
|
readonly idempotencyKey: Schema.String;
|
|
7
12
|
}>, {
|
|
8
13
|
readonly replyTo: "reply_to";
|
|
@@ -22,8 +22,8 @@ export declare function searchDocuments(documents: ReadonlyArray<SearchDocument>
|
|
|
22
22
|
}[];
|
|
23
23
|
readonly summary_truncated: boolean;
|
|
24
24
|
readonly entity?: string | undefined;
|
|
25
|
-
readonly metrics?: readonly string[] | undefined;
|
|
26
25
|
readonly tools?: readonly string[] | undefined;
|
|
26
|
+
readonly metrics?: readonly string[] | undefined;
|
|
27
27
|
readonly relevance?: number | undefined;
|
|
28
28
|
}[];
|
|
29
29
|
/** Bytewise canonical-name ordering is independent of a function instance's locale. */
|
package/dist/slack-files.d.ts
CHANGED
|
@@ -49,5 +49,7 @@ export declare function sendSlackFiles(options: {
|
|
|
49
49
|
readonly index?: number;
|
|
50
50
|
}>;
|
|
51
51
|
readonly text?: string;
|
|
52
|
+
/** Shares nothing unless every file uploaded, as a reply that must arrive whole does. */
|
|
53
|
+
readonly requireAll?: boolean;
|
|
52
54
|
readonly definite?: DefiniteFailure;
|
|
53
55
|
}): Promise<SlackFilesResult>;
|
package/dist/slack-files.js
CHANGED
|
@@ -112,7 +112,7 @@ export async function sendSlackFiles(options) {
|
|
|
112
112
|
});
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
|
-
if (uploaded.length === 0) {
|
|
115
|
+
if (uploaded.length === 0 || (options.requireAll === true && uploaded.length < uploads.length)) {
|
|
116
116
|
return { uploads };
|
|
117
117
|
}
|
|
118
118
|
const part = { files: uploaded.map(({ index }) => index), text: options.text !== undefined };
|
package/dist/telegram-files.d.ts
CHANGED
|
@@ -28,6 +28,8 @@ export interface TelegramEntity {
|
|
|
28
28
|
export interface TelegramFormattedText {
|
|
29
29
|
readonly text: string;
|
|
30
30
|
readonly entities: ReadonlyArray<TelegramEntity>;
|
|
31
|
+
/** Text written in Telegram's MarkdownV2, formatted by Telegram, in place of entities. */
|
|
32
|
+
readonly parseMode?: "MarkdownV2";
|
|
31
33
|
}
|
|
32
34
|
/** How Telegram sends a file of this content type: as a photo or as a document. */
|
|
33
35
|
export declare function telegramFileType(contentType: string): "photo" | "document";
|
|
@@ -77,5 +79,7 @@ export declare function sendTelegramFiles(options: {
|
|
|
77
79
|
readonly index?: number;
|
|
78
80
|
}>;
|
|
79
81
|
readonly caption?: TelegramFormattedText;
|
|
82
|
+
/** The caption without its formatting, sent when Telegram refuses the caption's formatting. */
|
|
83
|
+
readonly plainCaption?: TelegramFormattedText;
|
|
80
84
|
readonly definite?: DefiniteFailure;
|
|
81
85
|
}): Promise<ReadonlyArray<ChannelPart>>;
|
package/dist/telegram-files.js
CHANGED
|
@@ -117,6 +117,9 @@ async function multipart(target, files, caption) {
|
|
|
117
117
|
if (sent.entities.length > 0) {
|
|
118
118
|
form.set("caption_entities", JSON.stringify(sent.entities));
|
|
119
119
|
}
|
|
120
|
+
if (caption.parseMode !== undefined) {
|
|
121
|
+
form.set("parse_mode", caption.parseMode);
|
|
122
|
+
}
|
|
120
123
|
}
|
|
121
124
|
}
|
|
122
125
|
else {
|
|
@@ -127,6 +130,7 @@ async function multipart(target, files, caption) {
|
|
|
127
130
|
? {
|
|
128
131
|
caption: caption.text,
|
|
129
132
|
...(caption.entities.length > 0 ? { caption_entities: caption.entities } : {}),
|
|
133
|
+
...(caption.parseMode === undefined ? {} : { parse_mode: caption.parseMode }),
|
|
130
134
|
}
|
|
131
135
|
: {}),
|
|
132
136
|
}))));
|
|
@@ -208,9 +212,9 @@ export async function sendTelegramFiles(options) {
|
|
|
208
212
|
try {
|
|
209
213
|
reply = await send(built);
|
|
210
214
|
if (caption !== undefined &&
|
|
211
|
-
caption.entities.length > 0 &&
|
|
215
|
+
(caption.entities.length > 0 || caption.parseMode !== undefined) &&
|
|
212
216
|
telegramFormattingRefused(reply.status, replyJson(reply))) {
|
|
213
|
-
caption = { text: caption.text, entities: [] };
|
|
217
|
+
caption = options.plainCaption ?? { text: caption.text, entities: [] };
|
|
214
218
|
reply = await send(await multipart(options.target, batch, caption));
|
|
215
219
|
}
|
|
216
220
|
}
|
package/dist/user-identity.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ export declare const UserIdentity: import("./entity.js").DraftEntity<"user_ident
|
|
|
29
29
|
readonly subject: import("./property.js").Property<string, false, false>;
|
|
30
30
|
readonly username: import("effect/Schema").optionalKey<import("./property.js").Property<string, false, false>>;
|
|
31
31
|
readonly display: import("effect/Schema").optionalKey<import("./property.js").Property<string, false, false>>;
|
|
32
|
-
readonly origin: import("./property.js").Property<"link" | "invite" | "attach" | "
|
|
32
|
+
readonly origin: import("./property.js").Property<"link" | "invite" | "attach" | "sign_in" | "channel" | "pairing", false, false>;
|
|
33
33
|
readonly revokedAt: import("effect/Schema").optionalKey<import("./property.js").Property<string, false, false>>;
|
|
34
34
|
readonly accountKey: import("effect/Schema").optionalKey<import("./property.js").Property<string, false, true>>;
|
|
35
35
|
readonly memberKey: import("effect/Schema").optionalKey<import("./property.js").Property<string, false, true>>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@segmentstream/ontology",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.165.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",
|