





















@@ -1,7 +1,11 @@
11import { Type, type TSchema } from "typebox";
22import type { SourceReplyDeliveryMode } from "../../auto-reply/get-reply-options.types.js";
33import type { InboundEventKind } from "../../channels/inbound-event/kind.js";
4-import { listChannelPlugins } from "../../channels/plugins/index.js";
4+import {
5+getChannelPlugin,
6+getLoadedChannelPlugin,
7+listChannelPlugins,
8+} from "../../channels/plugins/index.js";
59import {
610channelSupportsMessageCapability,
711channelSupportsMessageCapabilityForChannel,
@@ -158,7 +162,11 @@ const presentationMessageSchema = Type.Object(
158162},
159163);
160164161-function buildSendSchema(options: { includePresentation: boolean; includeDeliveryPin: boolean }) {
165+function buildSendSchema(options: {
166+includePresentation: boolean;
167+includeDeliveryPin: boolean;
168+includeBestEffort: boolean;
169+}) {
162170const props: Record<string, TSchema> = {
163171message: Type.Optional(Type.String()),
164172effectId: Type.Optional(
@@ -207,7 +215,6 @@ function buildSendSchema(options: { includePresentation: boolean; includeDeliver
207215asVoice: Type.Optional(Type.Boolean()),
208216silent: Type.Optional(Type.Boolean()),
209217quoteText: Type.Optional(Type.String({ description: "Telegram reply quote text." })),
210-bestEffort: Type.Optional(Type.Boolean()),
211218gifPlayback: Type.Optional(Type.Boolean()),
212219forceDocument: Type.Optional(
213220Type.Boolean({
@@ -223,6 +230,14 @@ function buildSendSchema(options: { includePresentation: boolean; includeDeliver
223230if (options.includePresentation) {
224231props.presentation = Type.Optional(presentationMessageSchema);
225232}
233+if (options.includeBestEffort) {
234+props.bestEffort = Type.Optional(
235+Type.Boolean({
236+description:
237+"Optional delivery mode. Omit or set true for ordinary replies. Set false only when required durable delivery is necessary.",
238+}),
239+);
240+}
226241if (options.includeDeliveryPin) {
227242props.delivery = Type.Optional(
228243Type.Object(
@@ -466,6 +481,7 @@ function buildChannelManagementSchema() {
466481function buildMessageToolSchemaProps(options: {
467482includePresentation: boolean;
468483includeDeliveryPin: boolean;
484+includeBestEffort: boolean;
469485extraProperties?: Record<string, TSchema>;
470486}) {
471487return {
@@ -494,6 +510,7 @@ function isSendOnlyActions(actions: readonly string[]): boolean {
494510function buildSendOnlyMessageToolSchemaProps(options: {
495511includePresentation: boolean;
496512includeDeliveryPin: boolean;
513+includeBestEffort: boolean;
497514extraProperties?: Record<string, TSchema>;
498515}) {
499516return {
@@ -509,6 +526,7 @@ function buildMessageToolSchemaFromActions(
509526options: {
510527includePresentation: boolean;
511528includeDeliveryPin: boolean;
529+includeBestEffort: boolean;
512530extraProperties?: Record<string, TSchema>;
513531},
514532) {
@@ -524,6 +542,7 @@ function buildMessageToolSchemaFromActions(
524542const MessageToolSchema = buildMessageToolSchemaFromActions(AllMessageActions, {
525543includePresentation: true,
526544includeDeliveryPin: true,
545+includeBestEffort: false,
527546});
528547529548type MessageToolOptions = {
@@ -743,10 +762,27 @@ function resolveIncludeDeliveryPin(params: MessageToolDiscoveryParams): boolean
743762return resolveIncludeCapability(params, "delivery-pin");
744763}
745764765+function resolveIncludeBestEffort(params: MessageToolDiscoveryParams): boolean {
766+const currentChannel = normalizeMessageChannel(params.currentChannelProvider);
767+if (!currentChannel) {
768+return false;
769+}
770+const adapter =
771+listChannelPlugins().find((plugin) => plugin.id === currentChannel)?.message ??
772+getLoadedChannelPlugin(currentChannel as Parameters<typeof getLoadedChannelPlugin>[0])
773+?.message ??
774+getChannelPlugin(currentChannel as Parameters<typeof getChannelPlugin>[0])?.message;
775+return (
776+adapter?.durableFinal?.capabilities?.reconcileUnknownSend === true &&
777+typeof adapter.durableFinal.reconcileUnknownSend === "function"
778+);
779+}
780+746781function buildMessageToolSchema(params: MessageToolDiscoveryParams) {
747782const actions = resolveMessageToolActionSchemaActions(params);
748783const includePresentation = resolveIncludePresentation(params);
749784const includeDeliveryPin = resolveIncludeDeliveryPin(params);
785+const includeBestEffort = resolveIncludeBestEffort(params);
750786const extraProperties = resolveChannelMessageToolSchemaProperties(
751787buildMessageActionDiscoveryInput(
752788params,
@@ -756,6 +792,7 @@ function buildMessageToolSchema(params: MessageToolDiscoveryParams) {
756792return buildMessageToolSchemaFromActions(actions.length > 0 ? actions : ["send"], {
757793 includePresentation,
758794 includeDeliveryPin,
795+ includeBestEffort,
759796 extraProperties,
760797});
761798}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。