UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

51 lines (50 loc) • 1.91 kB
import { n as sha256Hex } from "./node-crypto-B6yuTjmm.mjs"; import { n as estimateUtf8Bytes, r as splitTextToUtf8ByteLimit } from "./embedding-input-limits-C6s74CMk.mjs"; import "./markdown-chunks-DoKq_kBI.mjs"; import { r as hasNonTextEmbeddingParts } from "./embedding-inputs-BGMBVJOW.mjs"; //#region packages/memory-host-sdk/src/host/embedding-model-limits.ts const DEFAULT_EMBEDDING_MAX_INPUT_TOKENS = 8192; const DEFAULT_LOCAL_EMBEDDING_MAX_INPUT_TOKENS = 2048; /** Resolve the effective embedding input limit for a provider. */ function resolveEmbeddingMaxInputTokens(e) { if (typeof e.maxInputTokens === "number") return e.maxInputTokens; if (e.id === "local") return DEFAULT_LOCAL_EMBEDDING_MAX_INPUT_TOKENS; return DEFAULT_EMBEDDING_MAX_INPUT_TOKENS; } //#endregion //#region packages/memory-host-sdk/src/host/embedding-chunk-limits.ts /** * Split text-only chunks to the provider's effective input limit. * * Structured multimodal chunks are preserved because only the provider can decide how to count * non-text parts. */ function enforceEmbeddingMaxInputTokens(e, t, n) { const r = resolveEmbeddingMaxInputTokens(e); const i = typeof n === "number" && n > 0 ? Math.min(r, n) : r; const a = []; for (const e of t) { if (hasNonTextEmbeddingParts(e.embeddingInput) || estimateUtf8Bytes(e.text) <= i) { a.push(e); continue; } for (const t of splitTextToUtf8ByteLimit(e.text, i)) a.push({ startLine: e.startLine, endLine: e.endLine, ...e.entryStartLine !== void 0 ? { entryStartLine: e.entryStartLine, entryEndLine: e.entryEndLine } : {}, text: t, hash: sha256Hex(t), embeddingInput: { text: t }, ...e.provenance ? { provenance: e.provenance } : {} }); } return a; } //#endregion //#region src/plugin-sdk/memory-core-host-engine-indexing.ts const hashText = sha256Hex; //#endregion export { enforceEmbeddingMaxInputTokens as n, hashText as t };