Files
MailUI4Agents/plugins/dsh-mail-bridge/lib/relay-key.d.ts
JianFeeeee 13fcb00acc feat: relay-key 共用模块(三桥 + homeagent)
Sha256 clamp relay_key 过 160 字节上限,避免服务端 400
被 worker 当暂时失败让位,导致邮件驱动会话无本地 UI 静默挂死。

新增 relay_key.go / relay-key.js + 15 个纯函数测试。
2026-09-06 15:16:34 +08:00

21 lines
850 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/** 服务端 relay_key 列宽(字节)。 */
export const RELAY_KEY_MAX_BYTES: number;
/** UTF-8 字节数。 */
export function byteLength(s: string | null | undefined): number;
/** 按字节截断,回退到最近的字符边界(不产生半个字符)。 */
export function truncateToBytes(s: string | null | undefined, maxBytes: number): string;
/**
* 把 relay_key 收敛到服务端能接受的长度。
* 未超限时原样返回;超限时保留可读前缀 + `:sha256:<原始键的完整哈希>`。
*/
export function clampRelayKey(key: string | null | undefined, limit?: number): string;
/**
* 这次失败是不是「永远不会成功」。
* 4xx除 408 / 429= 永久408 / 429 / 5xx / 无 status = 暂时。
*/
export function isPermanentFailure(err: { status?: number | string } | null | undefined): boolean;