@theokit/gateway 0.25.0 → 0.26.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 +9 -0
- package/README.md +56 -0
- package/dist/index.cjs +188 -31
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +127 -10
- package/dist/index.d.ts +127 -10
- package/dist/index.js +186 -32
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -821,14 +821,37 @@ interface OutboundMessage {
|
|
|
821
821
|
*/
|
|
822
822
|
readonly attachments?: ReadonlyArray<OutboundAttachment>;
|
|
823
823
|
}
|
|
824
|
-
/**
|
|
824
|
+
/**
|
|
825
|
+
* Shared failure codes for {@link SendResult}.
|
|
826
|
+
*
|
|
827
|
+
* - `empty_text`, `not_connected`, `invalid_channel`, `attachments_unsupported`: core refused the send.
|
|
828
|
+
* - `rate_limit`: the platform throttled the send; see `retryAfterMs`.
|
|
829
|
+
* - `permission_denied`: the credential is valid but may not post here (HTTP 403).
|
|
830
|
+
* - `auth_failed`: the credential was rejected (HTTP 401).
|
|
831
|
+
* - `timeout`: the platform or the request timed out (HTTP 408).
|
|
832
|
+
* - `server_error`: the platform failed (HTTP 5xx).
|
|
833
|
+
* - `network_error`: the request never got an answer.
|
|
834
|
+
* - `platform_error`: any other platform refusal.
|
|
835
|
+
*/
|
|
836
|
+
type SendErrorCode = "empty_text" | "not_connected" | "invalid_channel" | "attachments_unsupported" | "rate_limit" | "permission_denied" | "auth_failed" | "timeout" | "server_error" | "network_error" | "platform_error";
|
|
837
|
+
/** The error of a failed {@link SendResult}. */
|
|
838
|
+
interface SendError {
|
|
839
|
+
/** A known code, or a platform-specific one an adapter has not mapped yet. */
|
|
840
|
+
readonly code: SendErrorCode | (string & {});
|
|
841
|
+
readonly message: string;
|
|
842
|
+
/** Set when the platform said how long to wait. */
|
|
843
|
+
readonly retryAfterMs?: number;
|
|
844
|
+
/** The platform's own code, kept for logs. */
|
|
845
|
+
readonly platformCode?: string;
|
|
846
|
+
}
|
|
847
|
+
/**
|
|
848
|
+
* Send result — adapters return this instead of throwing on platform errors.
|
|
849
|
+
* `error.code` is a {@link SendErrorCode} or a platform-specific string.
|
|
850
|
+
*/
|
|
825
851
|
interface SendResult {
|
|
826
852
|
readonly ok: boolean;
|
|
827
853
|
readonly messageId?: string;
|
|
828
|
-
readonly error?:
|
|
829
|
-
readonly code: string;
|
|
830
|
-
readonly message: string;
|
|
831
|
-
};
|
|
854
|
+
readonly error?: SendError;
|
|
832
855
|
}
|
|
833
856
|
/** The facts about an adapter that an app picks its rendering from. */
|
|
834
857
|
interface AdapterCapabilities {
|
|
@@ -1010,6 +1033,17 @@ declare abstract class BasePlatformAdapter {
|
|
|
1010
1033
|
stopTyping(_channelId: string): Promise<void>;
|
|
1011
1034
|
}
|
|
1012
1035
|
|
|
1036
|
+
/**
|
|
1037
|
+
* Map an HTTP status to a failed SendResult: 429 -> rate_limit (retryAfterMs from a Retry-After
|
|
1038
|
+
* value in seconds or an HTTP date), 401 -> auth_failed, 403 -> permission_denied,
|
|
1039
|
+
* 408 -> timeout, 5xx -> server_error, other -> platform_error.
|
|
1040
|
+
*/
|
|
1041
|
+
declare function sendErrorFromHttp(status: number, message: string, options?: {
|
|
1042
|
+
retryAfter?: string | null;
|
|
1043
|
+
platformCode?: string;
|
|
1044
|
+
now?: () => number;
|
|
1045
|
+
}): SendResult;
|
|
1046
|
+
|
|
1013
1047
|
/**
|
|
1014
1048
|
* `WeixinAdapterBase` — the connect / token / send / dispatch flow that the WeChat and WeCom
|
|
1015
1049
|
* adapters share. A subclass supplies the platform's endpoints, its signature check and its event
|
|
@@ -1067,7 +1101,7 @@ declare abstract class WeixinAdapterBase extends BasePlatformAdapter {
|
|
|
1067
1101
|
private readonly cfg;
|
|
1068
1102
|
private readonly doFetch;
|
|
1069
1103
|
private connected;
|
|
1070
|
-
private
|
|
1104
|
+
private readonly tokens;
|
|
1071
1105
|
private readonly seen;
|
|
1072
1106
|
constructor(cfg: WeixinAdapterConfig);
|
|
1073
1107
|
/** Path and query of the access-token request. */
|
|
@@ -1089,6 +1123,7 @@ declare abstract class WeixinAdapterBase extends BasePlatformAdapter {
|
|
|
1089
1123
|
/** Turn a plain (decrypted) XML body into one event, dispatch it and answer the webhook. */
|
|
1090
1124
|
protected handleMessage(xml: string): Promise<WeixinWebhookAnswer>;
|
|
1091
1125
|
private token;
|
|
1126
|
+
private requestToken;
|
|
1092
1127
|
private call;
|
|
1093
1128
|
}
|
|
1094
1129
|
|
|
@@ -1101,6 +1136,45 @@ declare abstract class WeixinAdapterBase extends BasePlatformAdapter {
|
|
|
1101
1136
|
*/
|
|
1102
1137
|
declare function parseFlatXml(xml: string): Record<string, string>;
|
|
1103
1138
|
|
|
1139
|
+
/**
|
|
1140
|
+
* `createTokenCache` — holds one expiring access token and shares a single refresh between every
|
|
1141
|
+
* concurrent caller.
|
|
1142
|
+
*
|
|
1143
|
+
* @public
|
|
1144
|
+
*/
|
|
1145
|
+
/** A token as the platform reported it. @public */
|
|
1146
|
+
interface FetchedToken {
|
|
1147
|
+
readonly value: string;
|
|
1148
|
+
/** Lifetime in seconds as the platform reported it; `defaultTtlS` when absent or not positive. */
|
|
1149
|
+
readonly expiresInS?: number;
|
|
1150
|
+
}
|
|
1151
|
+
/** Options of {@link createTokenCache}. @public */
|
|
1152
|
+
interface TokenCacheOptions {
|
|
1153
|
+
/** Fetch a fresh token. Receives the signal of the caller that started the fetch. */
|
|
1154
|
+
readonly fetchToken: (signal?: AbortSignal) => Promise<FetchedToken>;
|
|
1155
|
+
/** Refresh this long before expiry. Default 60_000. */
|
|
1156
|
+
readonly marginMs?: number;
|
|
1157
|
+
/** Default 7200. */
|
|
1158
|
+
readonly defaultTtlS?: number;
|
|
1159
|
+
readonly now?: () => number;
|
|
1160
|
+
}
|
|
1161
|
+
/** A cached expiring token. @public */
|
|
1162
|
+
interface TokenCache {
|
|
1163
|
+
/**
|
|
1164
|
+
* The cached token, or one fetch shared by every concurrent caller. `force` skips the cache
|
|
1165
|
+
* (but still joins a fetch already in flight). The signal of the caller that starts a fetch
|
|
1166
|
+
* governs it; later callers' signals do not cancel their wait.
|
|
1167
|
+
*/
|
|
1168
|
+
get(options?: {
|
|
1169
|
+
force?: boolean;
|
|
1170
|
+
signal?: AbortSignal;
|
|
1171
|
+
}): Promise<string>;
|
|
1172
|
+
/** Forget the cached token (after a 401, for example). */
|
|
1173
|
+
clear(): void;
|
|
1174
|
+
}
|
|
1175
|
+
/** Build a {@link TokenCache}. A failed fetch rejects every waiting caller and is not cached. @public */
|
|
1176
|
+
declare function createTokenCache(options: TokenCacheOptions): TokenCache;
|
|
1177
|
+
|
|
1104
1178
|
/**
|
|
1105
1179
|
* `GatewayConfigurationError` — shared base for per-adapter configuration
|
|
1106
1180
|
* errors (roadmap M0/M2).
|
|
@@ -1933,6 +2007,42 @@ interface MediaUnderstandingOptions {
|
|
|
1933
2007
|
/** Wraps a handler: the event it receives has the transcript or description appended to text. */
|
|
1934
2008
|
declare function withMediaUnderstanding(handler: GatewayHandler, options: MediaUnderstandingOptions): GatewayHandler;
|
|
1935
2009
|
|
|
2010
|
+
/**
|
|
2011
|
+
* Options for {@link ReconnectBackoff}. Delay fields default as documented on `ReconnectPolicy`.
|
|
2012
|
+
*
|
|
2013
|
+
* @public
|
|
2014
|
+
*/
|
|
2015
|
+
interface ReconnectBackoffOptions extends ReconnectPolicy {
|
|
2016
|
+
/** A connection open at least this long resets the delay. Default 60_000. */
|
|
2017
|
+
readonly stableAfterMs?: number;
|
|
2018
|
+
/** Clock in ms; defaults to `Date.now`. */
|
|
2019
|
+
readonly now?: () => number;
|
|
2020
|
+
}
|
|
2021
|
+
/**
|
|
2022
|
+
* Reconnect delay for an adapter that holds a long-lived connection: `min(initialDelayMs *
|
|
2023
|
+
* factor^(n-1), maxDelayMs)` for attempt n, reset after a connection that stayed open for
|
|
2024
|
+
* `stableAfterMs`.
|
|
2025
|
+
*
|
|
2026
|
+
* @public
|
|
2027
|
+
*/
|
|
2028
|
+
declare class ReconnectBackoff {
|
|
2029
|
+
private readonly initialDelayMs;
|
|
2030
|
+
private readonly maxDelayMs;
|
|
2031
|
+
private readonly factor;
|
|
2032
|
+
private readonly maxAttempts;
|
|
2033
|
+
private readonly stableAfterMs;
|
|
2034
|
+
private readonly now;
|
|
2035
|
+
private attempts;
|
|
2036
|
+
private openedAt;
|
|
2037
|
+
constructor(options?: ReconnectBackoffOptions);
|
|
2038
|
+
/** Call when the connection opens. */
|
|
2039
|
+
opened(): void;
|
|
2040
|
+
/** Delay before the next attempt; `undefined` once `maxAttempts` is spent. Resets first if the last connection was stable. */
|
|
2041
|
+
nextDelayMs(): number | undefined;
|
|
2042
|
+
/** Back to the initial delay. */
|
|
2043
|
+
reset(): void;
|
|
2044
|
+
}
|
|
2045
|
+
|
|
1936
2046
|
/** A credential shape this module masks, and the cost of matching it. */
|
|
1937
2047
|
interface CoveredShape {
|
|
1938
2048
|
/** The platform and field, for the reader of the table. */
|
|
@@ -2305,11 +2415,18 @@ declare function scanFences(text: string): readonly FenceRegion[];
|
|
|
2305
2415
|
*
|
|
2306
2416
|
* @internal
|
|
2307
2417
|
*/
|
|
2418
|
+
/** The unit `partLimit` is measured in. */
|
|
2419
|
+
interface SplitKeepingRowsOptions {
|
|
2420
|
+
/** How `partLimit` is measured. Default "utf16" (UTF-16 units). */
|
|
2421
|
+
readonly unit?: "utf16" | "codepoint";
|
|
2422
|
+
}
|
|
2308
2423
|
/**
|
|
2309
|
-
* Parts of at most `partLimit` units,
|
|
2310
|
-
* Shared by the SMS and LINE splitters (text no
|
|
2424
|
+
* Parts of at most `partLimit` units (UTF-16 units, or code points with `unit: "codepoint"`), cut
|
|
2425
|
+
* at grapheme boundaries and before straddled rows. Shared by the SMS and LINE splitters (text no
|
|
2426
|
+
* longer than a part is theirs to handle). In code-point mode `partLimit` must be a positive
|
|
2427
|
+
* integer and a single grapheme longer than it throws `RangeError`.
|
|
2311
2428
|
*/
|
|
2312
|
-
declare function splitKeepingRows(text: string, partLimit: number): string[];
|
|
2429
|
+
declare function splitKeepingRows(text: string, partLimit: number, options?: SplitKeepingRowsOptions): string[];
|
|
2313
2430
|
|
|
2314
2431
|
/** The outcome of delivering one event to the runner's handlers. */
|
|
2315
2432
|
type DeliverOutcome = "ok" | "no_handler" | "handler_threw";
|
|
@@ -2457,4 +2574,4 @@ interface WebhookHandlerOptions {
|
|
|
2457
2574
|
*/
|
|
2458
2575
|
declare function createWebhookHandler(options: WebhookHandlerOptions): (request: Request) => Promise<Response>;
|
|
2459
2576
|
|
|
2460
|
-
export { type AccessPolicyOptions, type AdapterCapabilities, type AdapterState, type AgentBindingRule, type AgentBindings, type AgentBindingsOptions, type AgentIdStrategy, type BaseMessageEvent, BasePlatformAdapter, type BuiltChannel, type BuzzMessageEvent, CREDENTIAL_SHAPES, type ChannelConfigField, type ChannelConfigInput, type ChannelConfigReaders, type ChannelDescriptor, type ChannelEntry, type ChannelRejection, type ChannelRendering, type ChannelWebhook, type ChatCommand, type ChunkByGraphemeOptions, type ChunkTextOptions, type ClickClackMessageEvent, type ConnectFailure, type CoveredShape, type CreateChannelsResult, type CredentialStore, DEFAULT_WEBHOOK_MAX_BYTES, type DeliveryRequest, DeliveryRouter, type DeliveryTarget, type DiscordMessageEvent, type DmPolicy, type DmScope, type EmailMessageEvent, type EnvConfig, type FeishuLarkMessageEvent, type FenceRegion, GatewayConfigurationError, type GatewayConfigurationErrorOptions, type GatewayContext, type GatewayHandler, type GatewayHook, GatewayLifecycleError, type GatewayLifecycleErrorOptions, GatewayRunner, type GatewayRunnerOptions, type GoogleChatMessageEvent, type HookDecision, HookExecutor, type HookName, type IMessageMessageEvent, type InboundAudio, type IngestResult, type IrcMessageEvent, type LineMessageEvent, type ListenableApp, type ListenerLike, type MatrixMessageEvent, type MattermostMessageEvent, type MediaUnderstandingOptions, type MessageEvent, type NextcloudTalkMessageEvent, type NostrMessageEvent, type OnErrorContext, type OutboundAttachment, type OutboundMessage, type PairingStore, type ParsedChatCommand, type PlatformEventRegistry, type PlatformName, type PostOutboundContext, type PreInboundContext, type QQMessageEvent, type RaftMessageEvent, type RawBodyCaptureOptions, type RawBodyRequest, type ReconnectPolicy, type SMSMessageEvent, type ScopedStrategyOptions, SeenIds, type SendResult, type SenderIdentity, SessionRouter, type SignalMessageEvent, type SlackMessageEvent, type StartResult, type SynologyChatMessageEvent, type TeamsMessageEvent, type TelegramMessageEvent, type TlonUrbitMessageEvent, type TwitchMessageEvent, type UncoveredShape, type WeChatMessageEvent, type WeComMessageEvent, type WebhookAnswer, type WebhookHandlerOptions, type WebhookRequest, WeixinAdapterBase, type WeixinAdapterConfig, type WeixinFetch, type WeixinSendRequest, type WeixinWebhookAnswer, type WhatsAppMessageEvent, type XMessageEvent, type XThreadTweet, type YuanbaoMessageEvent, type ZaloMessageEvent, type ZaloPersonalMessageEvent, bindingStrategy, channelConfigReaders, channelRendering, chunkByGrapheme, chunkText, commandHook, configFromEnv, createAccessPolicyHook, createAgentBindings, createChannels, createFileCredentialStore, createFilePairingStore, createWebhookHandler, defaultStrategy, helpText, isAuthenticatedSender, listenerLifecycle, loadPeer, maskSecrets, maskShapes, parseChatCommand, parseFlatXml, rawBodyCapture, redactSecrets, scanFences, scopedStrategy, selectVariant, senderKey, splitKeepingRows, statusForDeliver, toDialect, withMediaUnderstanding };
|
|
2577
|
+
export { type AccessPolicyOptions, type AdapterCapabilities, type AdapterState, type AgentBindingRule, type AgentBindings, type AgentBindingsOptions, type AgentIdStrategy, type BaseMessageEvent, BasePlatformAdapter, type BuiltChannel, type BuzzMessageEvent, CREDENTIAL_SHAPES, type ChannelConfigField, type ChannelConfigInput, type ChannelConfigReaders, type ChannelDescriptor, type ChannelEntry, type ChannelRejection, type ChannelRendering, type ChannelWebhook, type ChatCommand, type ChunkByGraphemeOptions, type ChunkTextOptions, type ClickClackMessageEvent, type ConnectFailure, type CoveredShape, type CreateChannelsResult, type CredentialStore, DEFAULT_WEBHOOK_MAX_BYTES, type DeliveryRequest, DeliveryRouter, type DeliveryTarget, type DiscordMessageEvent, type DmPolicy, type DmScope, type EmailMessageEvent, type EnvConfig, type FeishuLarkMessageEvent, type FenceRegion, type FetchedToken, GatewayConfigurationError, type GatewayConfigurationErrorOptions, type GatewayContext, type GatewayHandler, type GatewayHook, GatewayLifecycleError, type GatewayLifecycleErrorOptions, GatewayRunner, type GatewayRunnerOptions, type GoogleChatMessageEvent, type HookDecision, HookExecutor, type HookName, type IMessageMessageEvent, type InboundAudio, type IngestResult, type IrcMessageEvent, type LineMessageEvent, type ListenableApp, type ListenerLike, type MatrixMessageEvent, type MattermostMessageEvent, type MediaUnderstandingOptions, type MessageEvent, type NextcloudTalkMessageEvent, type NostrMessageEvent, type OnErrorContext, type OutboundAttachment, type OutboundMessage, type PairingStore, type ParsedChatCommand, type PlatformEventRegistry, type PlatformName, type PostOutboundContext, type PreInboundContext, type QQMessageEvent, type RaftMessageEvent, type RawBodyCaptureOptions, type RawBodyRequest, ReconnectBackoff, type ReconnectBackoffOptions, type ReconnectPolicy, type SMSMessageEvent, type ScopedStrategyOptions, SeenIds, type SendError, type SendErrorCode, type SendResult, type SenderIdentity, SessionRouter, type SignalMessageEvent, type SlackMessageEvent, type SplitKeepingRowsOptions, type StartResult, type SynologyChatMessageEvent, type TeamsMessageEvent, type TelegramMessageEvent, type TlonUrbitMessageEvent, type TokenCache, type TokenCacheOptions, type TwitchMessageEvent, type UncoveredShape, type WeChatMessageEvent, type WeComMessageEvent, type WebhookAnswer, type WebhookHandlerOptions, type WebhookRequest, WeixinAdapterBase, type WeixinAdapterConfig, type WeixinFetch, type WeixinSendRequest, type WeixinWebhookAnswer, type WhatsAppMessageEvent, type XMessageEvent, type XThreadTweet, type YuanbaoMessageEvent, type ZaloMessageEvent, type ZaloPersonalMessageEvent, bindingStrategy, channelConfigReaders, channelRendering, chunkByGrapheme, chunkText, commandHook, configFromEnv, createAccessPolicyHook, createAgentBindings, createChannels, createFileCredentialStore, createFilePairingStore, createTokenCache, createWebhookHandler, defaultStrategy, helpText, isAuthenticatedSender, listenerLifecycle, loadPeer, maskSecrets, maskShapes, parseChatCommand, parseFlatXml, rawBodyCapture, redactSecrets, scanFences, scopedStrategy, selectVariant, sendErrorFromHttp, senderKey, splitKeepingRows, statusForDeliver, toDialect, withMediaUnderstanding };
|
package/dist/index.d.ts
CHANGED
|
@@ -821,14 +821,37 @@ interface OutboundMessage {
|
|
|
821
821
|
*/
|
|
822
822
|
readonly attachments?: ReadonlyArray<OutboundAttachment>;
|
|
823
823
|
}
|
|
824
|
-
/**
|
|
824
|
+
/**
|
|
825
|
+
* Shared failure codes for {@link SendResult}.
|
|
826
|
+
*
|
|
827
|
+
* - `empty_text`, `not_connected`, `invalid_channel`, `attachments_unsupported`: core refused the send.
|
|
828
|
+
* - `rate_limit`: the platform throttled the send; see `retryAfterMs`.
|
|
829
|
+
* - `permission_denied`: the credential is valid but may not post here (HTTP 403).
|
|
830
|
+
* - `auth_failed`: the credential was rejected (HTTP 401).
|
|
831
|
+
* - `timeout`: the platform or the request timed out (HTTP 408).
|
|
832
|
+
* - `server_error`: the platform failed (HTTP 5xx).
|
|
833
|
+
* - `network_error`: the request never got an answer.
|
|
834
|
+
* - `platform_error`: any other platform refusal.
|
|
835
|
+
*/
|
|
836
|
+
type SendErrorCode = "empty_text" | "not_connected" | "invalid_channel" | "attachments_unsupported" | "rate_limit" | "permission_denied" | "auth_failed" | "timeout" | "server_error" | "network_error" | "platform_error";
|
|
837
|
+
/** The error of a failed {@link SendResult}. */
|
|
838
|
+
interface SendError {
|
|
839
|
+
/** A known code, or a platform-specific one an adapter has not mapped yet. */
|
|
840
|
+
readonly code: SendErrorCode | (string & {});
|
|
841
|
+
readonly message: string;
|
|
842
|
+
/** Set when the platform said how long to wait. */
|
|
843
|
+
readonly retryAfterMs?: number;
|
|
844
|
+
/** The platform's own code, kept for logs. */
|
|
845
|
+
readonly platformCode?: string;
|
|
846
|
+
}
|
|
847
|
+
/**
|
|
848
|
+
* Send result — adapters return this instead of throwing on platform errors.
|
|
849
|
+
* `error.code` is a {@link SendErrorCode} or a platform-specific string.
|
|
850
|
+
*/
|
|
825
851
|
interface SendResult {
|
|
826
852
|
readonly ok: boolean;
|
|
827
853
|
readonly messageId?: string;
|
|
828
|
-
readonly error?:
|
|
829
|
-
readonly code: string;
|
|
830
|
-
readonly message: string;
|
|
831
|
-
};
|
|
854
|
+
readonly error?: SendError;
|
|
832
855
|
}
|
|
833
856
|
/** The facts about an adapter that an app picks its rendering from. */
|
|
834
857
|
interface AdapterCapabilities {
|
|
@@ -1010,6 +1033,17 @@ declare abstract class BasePlatformAdapter {
|
|
|
1010
1033
|
stopTyping(_channelId: string): Promise<void>;
|
|
1011
1034
|
}
|
|
1012
1035
|
|
|
1036
|
+
/**
|
|
1037
|
+
* Map an HTTP status to a failed SendResult: 429 -> rate_limit (retryAfterMs from a Retry-After
|
|
1038
|
+
* value in seconds or an HTTP date), 401 -> auth_failed, 403 -> permission_denied,
|
|
1039
|
+
* 408 -> timeout, 5xx -> server_error, other -> platform_error.
|
|
1040
|
+
*/
|
|
1041
|
+
declare function sendErrorFromHttp(status: number, message: string, options?: {
|
|
1042
|
+
retryAfter?: string | null;
|
|
1043
|
+
platformCode?: string;
|
|
1044
|
+
now?: () => number;
|
|
1045
|
+
}): SendResult;
|
|
1046
|
+
|
|
1013
1047
|
/**
|
|
1014
1048
|
* `WeixinAdapterBase` — the connect / token / send / dispatch flow that the WeChat and WeCom
|
|
1015
1049
|
* adapters share. A subclass supplies the platform's endpoints, its signature check and its event
|
|
@@ -1067,7 +1101,7 @@ declare abstract class WeixinAdapterBase extends BasePlatformAdapter {
|
|
|
1067
1101
|
private readonly cfg;
|
|
1068
1102
|
private readonly doFetch;
|
|
1069
1103
|
private connected;
|
|
1070
|
-
private
|
|
1104
|
+
private readonly tokens;
|
|
1071
1105
|
private readonly seen;
|
|
1072
1106
|
constructor(cfg: WeixinAdapterConfig);
|
|
1073
1107
|
/** Path and query of the access-token request. */
|
|
@@ -1089,6 +1123,7 @@ declare abstract class WeixinAdapterBase extends BasePlatformAdapter {
|
|
|
1089
1123
|
/** Turn a plain (decrypted) XML body into one event, dispatch it and answer the webhook. */
|
|
1090
1124
|
protected handleMessage(xml: string): Promise<WeixinWebhookAnswer>;
|
|
1091
1125
|
private token;
|
|
1126
|
+
private requestToken;
|
|
1092
1127
|
private call;
|
|
1093
1128
|
}
|
|
1094
1129
|
|
|
@@ -1101,6 +1136,45 @@ declare abstract class WeixinAdapterBase extends BasePlatformAdapter {
|
|
|
1101
1136
|
*/
|
|
1102
1137
|
declare function parseFlatXml(xml: string): Record<string, string>;
|
|
1103
1138
|
|
|
1139
|
+
/**
|
|
1140
|
+
* `createTokenCache` — holds one expiring access token and shares a single refresh between every
|
|
1141
|
+
* concurrent caller.
|
|
1142
|
+
*
|
|
1143
|
+
* @public
|
|
1144
|
+
*/
|
|
1145
|
+
/** A token as the platform reported it. @public */
|
|
1146
|
+
interface FetchedToken {
|
|
1147
|
+
readonly value: string;
|
|
1148
|
+
/** Lifetime in seconds as the platform reported it; `defaultTtlS` when absent or not positive. */
|
|
1149
|
+
readonly expiresInS?: number;
|
|
1150
|
+
}
|
|
1151
|
+
/** Options of {@link createTokenCache}. @public */
|
|
1152
|
+
interface TokenCacheOptions {
|
|
1153
|
+
/** Fetch a fresh token. Receives the signal of the caller that started the fetch. */
|
|
1154
|
+
readonly fetchToken: (signal?: AbortSignal) => Promise<FetchedToken>;
|
|
1155
|
+
/** Refresh this long before expiry. Default 60_000. */
|
|
1156
|
+
readonly marginMs?: number;
|
|
1157
|
+
/** Default 7200. */
|
|
1158
|
+
readonly defaultTtlS?: number;
|
|
1159
|
+
readonly now?: () => number;
|
|
1160
|
+
}
|
|
1161
|
+
/** A cached expiring token. @public */
|
|
1162
|
+
interface TokenCache {
|
|
1163
|
+
/**
|
|
1164
|
+
* The cached token, or one fetch shared by every concurrent caller. `force` skips the cache
|
|
1165
|
+
* (but still joins a fetch already in flight). The signal of the caller that starts a fetch
|
|
1166
|
+
* governs it; later callers' signals do not cancel their wait.
|
|
1167
|
+
*/
|
|
1168
|
+
get(options?: {
|
|
1169
|
+
force?: boolean;
|
|
1170
|
+
signal?: AbortSignal;
|
|
1171
|
+
}): Promise<string>;
|
|
1172
|
+
/** Forget the cached token (after a 401, for example). */
|
|
1173
|
+
clear(): void;
|
|
1174
|
+
}
|
|
1175
|
+
/** Build a {@link TokenCache}. A failed fetch rejects every waiting caller and is not cached. @public */
|
|
1176
|
+
declare function createTokenCache(options: TokenCacheOptions): TokenCache;
|
|
1177
|
+
|
|
1104
1178
|
/**
|
|
1105
1179
|
* `GatewayConfigurationError` — shared base for per-adapter configuration
|
|
1106
1180
|
* errors (roadmap M0/M2).
|
|
@@ -1933,6 +2007,42 @@ interface MediaUnderstandingOptions {
|
|
|
1933
2007
|
/** Wraps a handler: the event it receives has the transcript or description appended to text. */
|
|
1934
2008
|
declare function withMediaUnderstanding(handler: GatewayHandler, options: MediaUnderstandingOptions): GatewayHandler;
|
|
1935
2009
|
|
|
2010
|
+
/**
|
|
2011
|
+
* Options for {@link ReconnectBackoff}. Delay fields default as documented on `ReconnectPolicy`.
|
|
2012
|
+
*
|
|
2013
|
+
* @public
|
|
2014
|
+
*/
|
|
2015
|
+
interface ReconnectBackoffOptions extends ReconnectPolicy {
|
|
2016
|
+
/** A connection open at least this long resets the delay. Default 60_000. */
|
|
2017
|
+
readonly stableAfterMs?: number;
|
|
2018
|
+
/** Clock in ms; defaults to `Date.now`. */
|
|
2019
|
+
readonly now?: () => number;
|
|
2020
|
+
}
|
|
2021
|
+
/**
|
|
2022
|
+
* Reconnect delay for an adapter that holds a long-lived connection: `min(initialDelayMs *
|
|
2023
|
+
* factor^(n-1), maxDelayMs)` for attempt n, reset after a connection that stayed open for
|
|
2024
|
+
* `stableAfterMs`.
|
|
2025
|
+
*
|
|
2026
|
+
* @public
|
|
2027
|
+
*/
|
|
2028
|
+
declare class ReconnectBackoff {
|
|
2029
|
+
private readonly initialDelayMs;
|
|
2030
|
+
private readonly maxDelayMs;
|
|
2031
|
+
private readonly factor;
|
|
2032
|
+
private readonly maxAttempts;
|
|
2033
|
+
private readonly stableAfterMs;
|
|
2034
|
+
private readonly now;
|
|
2035
|
+
private attempts;
|
|
2036
|
+
private openedAt;
|
|
2037
|
+
constructor(options?: ReconnectBackoffOptions);
|
|
2038
|
+
/** Call when the connection opens. */
|
|
2039
|
+
opened(): void;
|
|
2040
|
+
/** Delay before the next attempt; `undefined` once `maxAttempts` is spent. Resets first if the last connection was stable. */
|
|
2041
|
+
nextDelayMs(): number | undefined;
|
|
2042
|
+
/** Back to the initial delay. */
|
|
2043
|
+
reset(): void;
|
|
2044
|
+
}
|
|
2045
|
+
|
|
1936
2046
|
/** A credential shape this module masks, and the cost of matching it. */
|
|
1937
2047
|
interface CoveredShape {
|
|
1938
2048
|
/** The platform and field, for the reader of the table. */
|
|
@@ -2305,11 +2415,18 @@ declare function scanFences(text: string): readonly FenceRegion[];
|
|
|
2305
2415
|
*
|
|
2306
2416
|
* @internal
|
|
2307
2417
|
*/
|
|
2418
|
+
/** The unit `partLimit` is measured in. */
|
|
2419
|
+
interface SplitKeepingRowsOptions {
|
|
2420
|
+
/** How `partLimit` is measured. Default "utf16" (UTF-16 units). */
|
|
2421
|
+
readonly unit?: "utf16" | "codepoint";
|
|
2422
|
+
}
|
|
2308
2423
|
/**
|
|
2309
|
-
* Parts of at most `partLimit` units,
|
|
2310
|
-
* Shared by the SMS and LINE splitters (text no
|
|
2424
|
+
* Parts of at most `partLimit` units (UTF-16 units, or code points with `unit: "codepoint"`), cut
|
|
2425
|
+
* at grapheme boundaries and before straddled rows. Shared by the SMS and LINE splitters (text no
|
|
2426
|
+
* longer than a part is theirs to handle). In code-point mode `partLimit` must be a positive
|
|
2427
|
+
* integer and a single grapheme longer than it throws `RangeError`.
|
|
2311
2428
|
*/
|
|
2312
|
-
declare function splitKeepingRows(text: string, partLimit: number): string[];
|
|
2429
|
+
declare function splitKeepingRows(text: string, partLimit: number, options?: SplitKeepingRowsOptions): string[];
|
|
2313
2430
|
|
|
2314
2431
|
/** The outcome of delivering one event to the runner's handlers. */
|
|
2315
2432
|
type DeliverOutcome = "ok" | "no_handler" | "handler_threw";
|
|
@@ -2457,4 +2574,4 @@ interface WebhookHandlerOptions {
|
|
|
2457
2574
|
*/
|
|
2458
2575
|
declare function createWebhookHandler(options: WebhookHandlerOptions): (request: Request) => Promise<Response>;
|
|
2459
2576
|
|
|
2460
|
-
export { type AccessPolicyOptions, type AdapterCapabilities, type AdapterState, type AgentBindingRule, type AgentBindings, type AgentBindingsOptions, type AgentIdStrategy, type BaseMessageEvent, BasePlatformAdapter, type BuiltChannel, type BuzzMessageEvent, CREDENTIAL_SHAPES, type ChannelConfigField, type ChannelConfigInput, type ChannelConfigReaders, type ChannelDescriptor, type ChannelEntry, type ChannelRejection, type ChannelRendering, type ChannelWebhook, type ChatCommand, type ChunkByGraphemeOptions, type ChunkTextOptions, type ClickClackMessageEvent, type ConnectFailure, type CoveredShape, type CreateChannelsResult, type CredentialStore, DEFAULT_WEBHOOK_MAX_BYTES, type DeliveryRequest, DeliveryRouter, type DeliveryTarget, type DiscordMessageEvent, type DmPolicy, type DmScope, type EmailMessageEvent, type EnvConfig, type FeishuLarkMessageEvent, type FenceRegion, GatewayConfigurationError, type GatewayConfigurationErrorOptions, type GatewayContext, type GatewayHandler, type GatewayHook, GatewayLifecycleError, type GatewayLifecycleErrorOptions, GatewayRunner, type GatewayRunnerOptions, type GoogleChatMessageEvent, type HookDecision, HookExecutor, type HookName, type IMessageMessageEvent, type InboundAudio, type IngestResult, type IrcMessageEvent, type LineMessageEvent, type ListenableApp, type ListenerLike, type MatrixMessageEvent, type MattermostMessageEvent, type MediaUnderstandingOptions, type MessageEvent, type NextcloudTalkMessageEvent, type NostrMessageEvent, type OnErrorContext, type OutboundAttachment, type OutboundMessage, type PairingStore, type ParsedChatCommand, type PlatformEventRegistry, type PlatformName, type PostOutboundContext, type PreInboundContext, type QQMessageEvent, type RaftMessageEvent, type RawBodyCaptureOptions, type RawBodyRequest, type ReconnectPolicy, type SMSMessageEvent, type ScopedStrategyOptions, SeenIds, type SendResult, type SenderIdentity, SessionRouter, type SignalMessageEvent, type SlackMessageEvent, type StartResult, type SynologyChatMessageEvent, type TeamsMessageEvent, type TelegramMessageEvent, type TlonUrbitMessageEvent, type TwitchMessageEvent, type UncoveredShape, type WeChatMessageEvent, type WeComMessageEvent, type WebhookAnswer, type WebhookHandlerOptions, type WebhookRequest, WeixinAdapterBase, type WeixinAdapterConfig, type WeixinFetch, type WeixinSendRequest, type WeixinWebhookAnswer, type WhatsAppMessageEvent, type XMessageEvent, type XThreadTweet, type YuanbaoMessageEvent, type ZaloMessageEvent, type ZaloPersonalMessageEvent, bindingStrategy, channelConfigReaders, channelRendering, chunkByGrapheme, chunkText, commandHook, configFromEnv, createAccessPolicyHook, createAgentBindings, createChannels, createFileCredentialStore, createFilePairingStore, createWebhookHandler, defaultStrategy, helpText, isAuthenticatedSender, listenerLifecycle, loadPeer, maskSecrets, maskShapes, parseChatCommand, parseFlatXml, rawBodyCapture, redactSecrets, scanFences, scopedStrategy, selectVariant, senderKey, splitKeepingRows, statusForDeliver, toDialect, withMediaUnderstanding };
|
|
2577
|
+
export { type AccessPolicyOptions, type AdapterCapabilities, type AdapterState, type AgentBindingRule, type AgentBindings, type AgentBindingsOptions, type AgentIdStrategy, type BaseMessageEvent, BasePlatformAdapter, type BuiltChannel, type BuzzMessageEvent, CREDENTIAL_SHAPES, type ChannelConfigField, type ChannelConfigInput, type ChannelConfigReaders, type ChannelDescriptor, type ChannelEntry, type ChannelRejection, type ChannelRendering, type ChannelWebhook, type ChatCommand, type ChunkByGraphemeOptions, type ChunkTextOptions, type ClickClackMessageEvent, type ConnectFailure, type CoveredShape, type CreateChannelsResult, type CredentialStore, DEFAULT_WEBHOOK_MAX_BYTES, type DeliveryRequest, DeliveryRouter, type DeliveryTarget, type DiscordMessageEvent, type DmPolicy, type DmScope, type EmailMessageEvent, type EnvConfig, type FeishuLarkMessageEvent, type FenceRegion, type FetchedToken, GatewayConfigurationError, type GatewayConfigurationErrorOptions, type GatewayContext, type GatewayHandler, type GatewayHook, GatewayLifecycleError, type GatewayLifecycleErrorOptions, GatewayRunner, type GatewayRunnerOptions, type GoogleChatMessageEvent, type HookDecision, HookExecutor, type HookName, type IMessageMessageEvent, type InboundAudio, type IngestResult, type IrcMessageEvent, type LineMessageEvent, type ListenableApp, type ListenerLike, type MatrixMessageEvent, type MattermostMessageEvent, type MediaUnderstandingOptions, type MessageEvent, type NextcloudTalkMessageEvent, type NostrMessageEvent, type OnErrorContext, type OutboundAttachment, type OutboundMessage, type PairingStore, type ParsedChatCommand, type PlatformEventRegistry, type PlatformName, type PostOutboundContext, type PreInboundContext, type QQMessageEvent, type RaftMessageEvent, type RawBodyCaptureOptions, type RawBodyRequest, ReconnectBackoff, type ReconnectBackoffOptions, type ReconnectPolicy, type SMSMessageEvent, type ScopedStrategyOptions, SeenIds, type SendError, type SendErrorCode, type SendResult, type SenderIdentity, SessionRouter, type SignalMessageEvent, type SlackMessageEvent, type SplitKeepingRowsOptions, type StartResult, type SynologyChatMessageEvent, type TeamsMessageEvent, type TelegramMessageEvent, type TlonUrbitMessageEvent, type TokenCache, type TokenCacheOptions, type TwitchMessageEvent, type UncoveredShape, type WeChatMessageEvent, type WeComMessageEvent, type WebhookAnswer, type WebhookHandlerOptions, type WebhookRequest, WeixinAdapterBase, type WeixinAdapterConfig, type WeixinFetch, type WeixinSendRequest, type WeixinWebhookAnswer, type WhatsAppMessageEvent, type XMessageEvent, type XThreadTweet, type YuanbaoMessageEvent, type ZaloMessageEvent, type ZaloPersonalMessageEvent, bindingStrategy, channelConfigReaders, channelRendering, chunkByGrapheme, chunkText, commandHook, configFromEnv, createAccessPolicyHook, createAgentBindings, createChannels, createFileCredentialStore, createFilePairingStore, createTokenCache, createWebhookHandler, defaultStrategy, helpText, isAuthenticatedSender, listenerLifecycle, loadPeer, maskSecrets, maskShapes, parseChatCommand, parseFlatXml, rawBodyCapture, redactSecrets, scanFences, scopedStrategy, selectVariant, sendErrorFromHttp, senderKey, splitKeepingRows, statusForDeliver, toDialect, withMediaUnderstanding };
|