mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-05 23:02:10 +03:00
Integrated into release/v3.8.36 (#3501 chatCore extraction stack 2/13)
This commit is contained in:
committed by
GitHub
parent
e494afebcf
commit
e420c34fce
@@ -166,6 +166,11 @@ import {
|
||||
mergeResponseToolNameMap,
|
||||
} from "./chatCore/passthroughToolNames.ts";
|
||||
import { resolveCompressionSettings } from "./chatCore/compressionSettings.ts";
|
||||
import {
|
||||
isBuiltinStackedPipeline,
|
||||
isStackedCompressionCombo,
|
||||
type RuntimeCompressionCombo,
|
||||
} from "./chatCore/compressionComboPredicates.ts";
|
||||
import { recordContextEditingTelemetryHook } from "./chatCore/contextEditingTelemetry.ts";
|
||||
import { recordCompressionCacheStats } from "./chatCore/compressionCacheStats.ts";
|
||||
import { writeCavemanOutputAnalytics } from "./chatCore/cavemanOutputAnalytics.ts";
|
||||
@@ -908,27 +913,6 @@ export async function handleChatCore({
|
||||
}
|
||||
let compressionComboKey = comboName ?? null;
|
||||
let compressionComboApplied = false;
|
||||
type RuntimeCompressionCombo = {
|
||||
id: string;
|
||||
pipeline: NonNullable<CompressionConfig["stackedPipeline"]>;
|
||||
languagePacks: string[];
|
||||
outputMode: boolean;
|
||||
outputModeIntensity: string;
|
||||
};
|
||||
const isBuiltinStackedPipeline = (
|
||||
pipeline: CompressionConfig["stackedPipeline"] | undefined
|
||||
): boolean => {
|
||||
if (!Array.isArray(pipeline) || pipeline.length !== 2) return false;
|
||||
const [first, second] = pipeline;
|
||||
return (
|
||||
first?.engine === "rtk" &&
|
||||
(first.intensity === undefined || first.intensity === "standard") &&
|
||||
!first.config &&
|
||||
second?.engine === "caveman" &&
|
||||
(second.intensity === undefined || second.intensity === "full") &&
|
||||
!second.config
|
||||
);
|
||||
};
|
||||
const applyCompressionComboConfig = (
|
||||
compressionCombo: RuntimeCompressionCombo | null,
|
||||
routingOverrideIds: string[] = []
|
||||
@@ -987,14 +971,6 @@ export async function handleChatCore({
|
||||
compressionComboApplied = true;
|
||||
return true;
|
||||
};
|
||||
const isStackedCompressionCombo = (
|
||||
compressionCombo: RuntimeCompressionCombo | null
|
||||
): compressionCombo is RuntimeCompressionCombo => {
|
||||
// >= 1: a single-engine default combo (user enabled exactly one layer via the
|
||||
// per-engine config page) must still apply. applyCompressionComboConfig already
|
||||
// guards length === 0.
|
||||
return Boolean(compressionCombo && compressionCombo.pipeline.length >= 1);
|
||||
};
|
||||
if (isCombo && comboName) {
|
||||
try {
|
||||
const { getComboByName } = await import("../../src/lib/localDb");
|
||||
|
||||
41
open-sse/handlers/chatCore/compressionComboPredicates.ts
Normal file
41
open-sse/handlers/chatCore/compressionComboPredicates.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* chatCore compression-combo predicates (Quality Gate v2 / Fase 9 — chatCore god-file
|
||||
* decomposition, #3501).
|
||||
*
|
||||
* Pure predicates extracted from handleChatCore's compression setup: detect the built-in
|
||||
* RTK→caveman stacked pipeline and whether a runtime combo has at least one pipeline layer.
|
||||
* No handler state is captured; behaviour is byte-identical to the previous inline closures.
|
||||
*/
|
||||
|
||||
import type { CompressionConfig } from "../../services/compression/types.ts";
|
||||
|
||||
export type RuntimeCompressionCombo = {
|
||||
id: string;
|
||||
pipeline: NonNullable<CompressionConfig["stackedPipeline"]>;
|
||||
languagePacks: string[];
|
||||
outputMode: boolean;
|
||||
outputModeIntensity: string;
|
||||
};
|
||||
|
||||
export function isBuiltinStackedPipeline(
|
||||
pipeline: CompressionConfig["stackedPipeline"] | undefined
|
||||
): boolean {
|
||||
if (!Array.isArray(pipeline) || pipeline.length !== 2) return false;
|
||||
const [first, second] = pipeline;
|
||||
return (
|
||||
first?.engine === "rtk" &&
|
||||
(first.intensity === undefined || first.intensity === "standard") &&
|
||||
!first.config &&
|
||||
second?.engine === "caveman" &&
|
||||
(second.intensity === undefined || second.intensity === "full") &&
|
||||
!second.config
|
||||
);
|
||||
}
|
||||
|
||||
export function isStackedCompressionCombo(
|
||||
compressionCombo: RuntimeCompressionCombo | null
|
||||
): compressionCombo is RuntimeCompressionCombo {
|
||||
// >= 1: a single-engine default combo (user enabled exactly one layer via the per-engine config
|
||||
// page) must still apply. applyCompressionComboConfig already guards length === 0.
|
||||
return Boolean(compressionCombo && compressionCombo.pipeline.length >= 1);
|
||||
}
|
||||
64
tests/unit/chatcore-compression-combo-predicates.test.ts
Normal file
64
tests/unit/chatcore-compression-combo-predicates.test.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
// Characterization of the pure compression-combo predicates extracted from handleChatCore's
|
||||
// compression setup (chatCore god-file decomposition, #3501). No DB, no handler state.
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
const { isBuiltinStackedPipeline, isStackedCompressionCombo } = await import(
|
||||
"../../open-sse/handlers/chatCore/compressionComboPredicates.ts"
|
||||
);
|
||||
|
||||
test("isBuiltinStackedPipeline true only for the rtk(standard)→caveman(full) shape", () => {
|
||||
assert.equal(
|
||||
isBuiltinStackedPipeline([{ engine: "rtk" }, { engine: "caveman" }] as never),
|
||||
true
|
||||
);
|
||||
assert.equal(
|
||||
isBuiltinStackedPipeline([
|
||||
{ engine: "rtk", intensity: "standard" },
|
||||
{ engine: "caveman", intensity: "full" },
|
||||
] as never),
|
||||
true
|
||||
);
|
||||
});
|
||||
|
||||
test("isBuiltinStackedPipeline false for wrong length / engines / intensities / config", () => {
|
||||
assert.equal(isBuiltinStackedPipeline(undefined), false);
|
||||
assert.equal(isBuiltinStackedPipeline([] as never), false);
|
||||
assert.equal(isBuiltinStackedPipeline([{ engine: "rtk" }] as never), false);
|
||||
assert.equal(
|
||||
isBuiltinStackedPipeline([{ engine: "caveman" }, { engine: "rtk" }] as never),
|
||||
false
|
||||
);
|
||||
assert.equal(
|
||||
isBuiltinStackedPipeline([
|
||||
{ engine: "rtk", intensity: "aggressive" },
|
||||
{ engine: "caveman", intensity: "full" },
|
||||
] as never),
|
||||
false
|
||||
);
|
||||
assert.equal(
|
||||
isBuiltinStackedPipeline([
|
||||
{ engine: "rtk", config: { x: 1 } },
|
||||
{ engine: "caveman" },
|
||||
] as never),
|
||||
false
|
||||
);
|
||||
});
|
||||
|
||||
test("isStackedCompressionCombo true when the combo has >= 1 pipeline layer", () => {
|
||||
assert.equal(isStackedCompressionCombo(null), false);
|
||||
assert.equal(
|
||||
isStackedCompressionCombo({ id: "c", pipeline: [], languagePacks: [], outputMode: false, outputModeIntensity: "full" } as never),
|
||||
false
|
||||
);
|
||||
assert.equal(
|
||||
isStackedCompressionCombo({
|
||||
id: "c",
|
||||
pipeline: [{ engine: "rtk" }],
|
||||
languagePacks: [],
|
||||
outputMode: false,
|
||||
outputModeIntensity: "full",
|
||||
} as never),
|
||||
true
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user