






















@@ -1,3 +1,7 @@
1+/**
2+ * Runs CPU-heavy compaction planning in a worker thread when histories are
3+ * large enough to risk starving the main event loop.
4+ */
15import path from "node:path";
26import { fileURLToPath, pathToFileURL } from "node:url";
37import { Worker } from "node:worker_threads";
@@ -191,6 +195,7 @@ async function runWithUnavailableFallback<T extends CompactionPlanningWorkerValu
191195}
192196}
193197198+/** Builds summary chunks, offloading large histories to the planning worker. */
194199export async function buildSummaryChunksWithWorker(params: {
195200messages: AgentMessage[];
196201maxChunkTokens: number;
@@ -219,6 +224,7 @@ export async function buildSummaryChunksWithWorker(params: {
219224return value.chunks;
220225}
221226227+/** Builds an oversized-message fallback plan, using the worker when worthwhile. */
222228export async function buildOversizedFallbackPlanWithWorker(params: {
223229messages: AgentMessage[];
224230contextWindow: number;
@@ -250,6 +256,7 @@ export async function buildOversizedFallbackPlanWithWorker(params: {
250256};
251257}
252258259+/** Builds a staged summarization split plan with worker fallback. */
253260export async function buildStageSplitPlanWithWorker(params: {
254261messages: AgentMessage[];
255262maxChunkTokens: number;
@@ -282,6 +289,7 @@ export async function buildStageSplitPlanWithWorker(params: {
282289return value.mode === "split" ? { mode: "split", chunks: value.chunks } : { mode: "single" };
283290}
284291292+/** Builds a history-pruning plan with worker fallback for large transcripts. */
285293export async function buildHistoryPrunePlanWithWorker(params: {
286294messagesToSummarize: AgentMessage[];
287295turnPrefixMessages: AgentMessage[];
@@ -324,6 +332,7 @@ export async function buildHistoryPrunePlanWithWorker(params: {
324332};
325333}
326334335+/** Computes the adaptive compaction chunk ratio with worker fallback. */
327336export async function computeAdaptiveChunkRatioWithWorker(params: {
328337messages: AgentMessage[];
329338contextWindow: number;
@@ -352,6 +361,7 @@ export async function computeAdaptiveChunkRatioWithWorker(params: {
352361return value.ratio;
353362}
354363364+/** Test-only worker internals for URL resolution and error-path coverage. */
355365export const compactionPlanningWorkerTesting = {
356366 resolveCompactionPlanningWorkerUrl,
357367 runCompactionPlanningWorker,
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。