openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
99 lines (98 loc) • 3.76 kB
JavaScript
import "./session-key-CqAyZeVk.mjs";
import { n as normalizeAccountId } from "./account-id-BqKT3GuY.mjs";
import { t as normalizeAnyChannelId } from "./registry-normalize-guW5_4yo.mjs";
import { n as normalizeMessageChannel } from "./message-channel-core-BbYZT1a-.mjs";
import { t as getChannelPlugin } from "./registry-ByqVE5S3.mjs";
import "./message-channel-DTYVLJT1.mjs";
import "./plugins-BoMiRtiY.mjs";
import { r as resolveChannelAccountEntry } from "./account-lookup-FhQZVFfo.mjs";
import { b as resolveChannelStreamingBlockCoalesce } from "./streaming-DsQF8isK.mjs";
import { c as resolveTextChunkLimit, s as resolveChunkMode } from "./chunk-D9JRZpRm.mjs";
//#region src/auto-reply/reply/block-streaming.ts
const DEFAULT_BLOCK_STREAM_MIN = 800;
const DEFAULT_BLOCK_STREAM_MAX = 1200;
const DEFAULT_BLOCK_STREAM_COALESCE_IDLE_MS = 1e3;
function resolveProviderChunkContext(e, t, n) {
const r = t ? normalizeMessageChannel(t) : void 0;
const i = r ? normalizeAnyChannelId(r) : null;
const a = i ? getChannelPlugin(i)?.outbound?.textChunkLimit : void 0;
return {
providerKey: r,
providerId: i,
textLimit: resolveTextChunkLimit(e, r, n, { fallbackLimit: a })
};
}
function clampPositiveInteger(e, t, n) {
if (typeof e !== "number" || !Number.isFinite(e)) return t;
const r = Math.round(e);
return r < n.min ? n.min : Math.min(r, n.max);
}
function resolveEffectiveBlockStreamingConfig(e) {
const t = resolveProviderChunkContext(e.cfg, e.provider, e.accountId);
const n = e.chunking ?? resolveBlockStreamingChunking(e.cfg, e.provider, e.accountId);
const r = clampPositiveInteger(e.maxChunkChars, n.maxChars, {
min: 1,
max: Math.max(1, t.textLimit)
});
const i = {
...n,
minChars: Math.min(n.minChars, r),
maxChars: r
};
const a = e.cfg;
const o = e.accountId;
const { providerKey: s, providerId: c, textLimit: l } = t;
const u = c ? getChannelPlugin(c)?.streaming?.blockStreamingCoalesceDefaults : void 0;
let d;
if (a && s) {
const e = a.channels?.[s];
if (e && typeof e === "object") {
const t = normalizeAccountId(o);
const n = e;
const r = resolveChannelAccountEntry(n.accounts, t, s);
const i = resolveChannelStreamingBlockCoalesce(n);
const a = r ? resolveChannelStreamingBlockCoalesce(r) : void 0;
if (i || a) d = {
...i,
...a
};
}
}
const f = d ?? a?.agents?.defaults?.blockStreamingCoalesce;
const p = Math.max(1, Math.floor(f?.minChars ?? u?.minChars ?? i.minChars));
const m = Math.max(1, Math.floor(f?.maxChars ?? l));
const h = Math.max(1, Math.min(m, l));
const g = Math.min(p, h);
const _ = Math.max(0, Math.floor(f?.idleMs ?? u?.idleMs ?? DEFAULT_BLOCK_STREAM_COALESCE_IDLE_MS));
const v = i.breakPreference;
const y = v === "sentence" ? " " : v === "newline" ? "\n" : "\n\n";
const b = Math.max(1, Math.min(h, i.maxChars));
return {
chunking: i,
coalescing: {
minChars: Math.min(g, b),
maxChars: b,
idleMs: clampPositiveInteger(e.coalesceIdleMs, _, {
min: 0,
max: 5e3
}),
joiner: y
}
};
}
function resolveBlockStreamingChunking(e, t, n) {
const { providerKey: r, textLimit: i } = resolveProviderChunkContext(e, t, n);
const a = e?.agents?.defaults?.blockStreamingChunk;
const o = resolveChunkMode(e, r, n);
const s = Math.max(1, Math.floor(a?.maxChars ?? DEFAULT_BLOCK_STREAM_MAX));
const c = Math.max(1, Math.min(s, i));
const l = Math.max(1, Math.floor(a?.minChars ?? DEFAULT_BLOCK_STREAM_MIN));
return {
minChars: Math.min(l, c),
maxChars: c,
breakPreference: a?.breakPreference === "newline" || a?.breakPreference === "sentence" ? a.breakPreference : "paragraph",
flushOnParagraph: o === "newline"
};
}
//#endregion
export { resolveEffectiveBlockStreamingConfig as n, resolveBlockStreamingChunking as t };