mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-04 14:22:09 +03:00
fix(api): accept all catalog engines on compression PUT schema (#6792)
Reconstructed onto release/v3.8.47 to drop unrelated main-drift (deps/electron/proxy files belong to #6620, not this PR). Resolved the release's OmniGlyph engine addition additively (types.ts/compression.ts kept both 'relevance' and 'omniglyph') and extended stackedPipelineStepSchema + STACKED_PIPELINE_ENGINE_INTENSITIES with the omniglyph branch so the ENGINE_CATALOG-parity test passes. Co-authored-by: Pitchfork-and-Torch <Pitchfork-and-Torch@users.noreply.github.com> Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
This commit is contained in:
@@ -260,8 +260,9 @@ function normalizeContextEditingConfig(value: unknown): ContextEditingConfig {
|
||||
}
|
||||
|
||||
// Engines allowed in the global stackedPipeline setting. MUST stay in sync with the
|
||||
// compression-combo KNOWN_ENGINE_IDS (src/lib/db/compressionCombos.ts) — otherwise the
|
||||
// global setting silently strips engines the combo path accepts (B-PIPELINE-DIVERGENCE).
|
||||
// compression-combo KNOWN_ENGINE_IDS (src/lib/db/compressionCombos.ts) and with
|
||||
// stackedPipelineStepSchema / ENGINE_CATALOG — otherwise the global setting silently
|
||||
// strips engines the combo path accepts (B-PIPELINE-DIVERGENCE / #6747).
|
||||
const STACKED_PIPELINE_ENGINE_IDS = new Set([
|
||||
"lite",
|
||||
"caveman",
|
||||
@@ -272,6 +273,7 @@ const STACKED_PIPELINE_ENGINE_IDS = new Set([
|
||||
"session-dedup",
|
||||
"ccr",
|
||||
"llmlingua",
|
||||
"relevance",
|
||||
"omniglyph",
|
||||
]);
|
||||
|
||||
@@ -657,8 +659,7 @@ export async function getCompressionSettings(): Promise<CompressionConfig> {
|
||||
storedEngines = parseStoredEnginesMap(parsed);
|
||||
break;
|
||||
case "activeComboId":
|
||||
config.activeComboId =
|
||||
typeof parsed === "string" && parsed.trim() ? parsed.trim() : null;
|
||||
config.activeComboId = typeof parsed === "string" && parsed.trim() ? parsed.trim() : null;
|
||||
break;
|
||||
case "ultraEngine":
|
||||
// Phase 4 (B): SLM tier selector. Only the two known values; anything else
|
||||
|
||||
@@ -56,6 +56,7 @@ function parseJsonArray<T>(value: unknown, fallback: T[]): T[] {
|
||||
}
|
||||
}
|
||||
|
||||
// Keep in sync with stackedPipelineStepSchema + ENGINE_CATALOG (#6747).
|
||||
const KNOWN_ENGINE_IDS = [
|
||||
"lite",
|
||||
"caveman",
|
||||
@@ -66,6 +67,7 @@ const KNOWN_ENGINE_IDS = [
|
||||
"session-dedup",
|
||||
"ccr",
|
||||
"llmlingua",
|
||||
"relevance",
|
||||
];
|
||||
|
||||
function normalizePipeline(value: unknown): CompressionPipelineStep[] {
|
||||
@@ -92,8 +94,7 @@ function upgradeLegacySeededDefaultCompressionCombo(): void {
|
||||
const row = db
|
||||
.prepare("SELECT name, description, pipeline FROM compression_combos WHERE id = ?")
|
||||
.get(DEFAULT_COMPRESSION_COMBO_ID) as
|
||||
| { name?: string; description?: string; pipeline?: string }
|
||||
| undefined;
|
||||
{ name?: string; description?: string; pipeline?: string } | undefined;
|
||||
|
||||
if (!row) return;
|
||||
|
||||
|
||||
@@ -141,6 +141,19 @@ export const ultraConfigSchema = z
|
||||
|
||||
const noConfigSchema = z.object({}).strict();
|
||||
|
||||
// Structural engines (session-dedup / ccr / headroom / relevance / llmlingua) do not
|
||||
// expose a fixed intensity enum in ENGINE_CATALOG — accept optional free-form intensity
|
||||
// and a loose config bag so GET→PUT round-trips of stackedPipeline succeed (#6747).
|
||||
const structuralStepConfigSchema = z.record(z.string(), z.unknown()).optional();
|
||||
|
||||
/**
|
||||
* Writable stacked-pipeline step shape for PUT /api/settings/compression and
|
||||
* PUT /api/context/combos/[id]. MUST accept every engine id in ENGINE_CATALOG /
|
||||
* GET /api/compression/engines and every engine the DB normalizer keeps
|
||||
* (src/lib/db/compression.ts STACKED_PIPELINE_ENGINE_IDS). Issue #6747: a 5-engine
|
||||
* discriminator rejected session-dedup/ccr/headroom/relevance/llmlingua on write even
|
||||
* though GET returned them.
|
||||
*/
|
||||
export const stackedPipelineStepSchema = z.discriminatedUnion("engine", [
|
||||
z
|
||||
.object({
|
||||
@@ -159,7 +172,8 @@ export const stackedPipelineStepSchema = z.discriminatedUnion("engine", [
|
||||
z
|
||||
.object({
|
||||
engine: z.literal("aggressive"),
|
||||
intensity: z.literal("standard").optional(),
|
||||
// #6747: previously only "standard"; GET / engines.level may echo "ultra"
|
||||
intensity: z.enum(["standard", "ultra"]).optional(),
|
||||
config: aggressiveConfigSchema.optional(),
|
||||
})
|
||||
.strict(),
|
||||
@@ -177,6 +191,48 @@ export const stackedPipelineStepSchema = z.discriminatedUnion("engine", [
|
||||
config: rtkConfigSchema.optional(),
|
||||
})
|
||||
.strict(),
|
||||
z
|
||||
.object({
|
||||
engine: z.literal("session-dedup"),
|
||||
intensity: z.string().optional(),
|
||||
config: structuralStepConfigSchema,
|
||||
})
|
||||
.strict(),
|
||||
z
|
||||
.object({
|
||||
engine: z.literal("ccr"),
|
||||
intensity: z.string().optional(),
|
||||
config: structuralStepConfigSchema,
|
||||
})
|
||||
.strict(),
|
||||
z
|
||||
.object({
|
||||
engine: z.literal("headroom"),
|
||||
intensity: z.string().optional(),
|
||||
config: structuralStepConfigSchema,
|
||||
})
|
||||
.strict(),
|
||||
z
|
||||
.object({
|
||||
engine: z.literal("relevance"),
|
||||
intensity: z.string().optional(),
|
||||
config: structuralStepConfigSchema,
|
||||
})
|
||||
.strict(),
|
||||
z
|
||||
.object({
|
||||
engine: z.literal("llmlingua"),
|
||||
intensity: z.string().optional(),
|
||||
config: structuralStepConfigSchema,
|
||||
})
|
||||
.strict(),
|
||||
z
|
||||
.object({
|
||||
engine: z.literal("omniglyph"),
|
||||
intensity: z.string().optional(),
|
||||
config: structuralStepConfigSchema,
|
||||
})
|
||||
.strict(),
|
||||
]);
|
||||
|
||||
/**
|
||||
@@ -185,17 +241,23 @@ export const stackedPipelineStepSchema = z.discriminatedUnion("engine", [
|
||||
* dropdowns and `stackedPipelineStepSchema`: every engine/intensity offered here is,
|
||||
* by construction, accepted by the API update schema.
|
||||
*
|
||||
* Do NOT add an engine here that is not a branch of `stackedPipelineStepSchema` — the
|
||||
* `PUT /api/context/combos/[id]` route validates against that discriminated union and
|
||||
* would reject the payload with HTTP 400 (#4955: the UI previously offered `headroom`,
|
||||
* `session-dedup`, `ccr`, `llmlingua`, none of which the union accepts, so selecting
|
||||
* one silently failed the save). The parity is guarded by a unit test.
|
||||
* Every ENGINE_CATALOG id must appear here (empty intensity list = no level selector).
|
||||
* Parity with `stackedPipelineStepSchema` is guarded by unit tests (#4955 / #6747).
|
||||
* #4955 fixed a UI/schema drift by shrinking the UI; #6747 expands the schema so the
|
||||
* full catalog (and GET stackedPipeline) can round-trip on PUT.
|
||||
*/
|
||||
export const STACKED_PIPELINE_ENGINE_INTENSITIES: Record<string, readonly string[]> = {
|
||||
rtk: ["minimal", "standard", "aggressive"],
|
||||
caveman: ["lite", "full", "ultra"],
|
||||
// Order matches ENGINE_CATALOG stackPriority for readability
|
||||
"session-dedup": [],
|
||||
ccr: [],
|
||||
lite: ["lite"],
|
||||
aggressive: ["standard"],
|
||||
rtk: ["minimal", "standard", "aggressive"],
|
||||
headroom: [],
|
||||
relevance: [],
|
||||
caveman: ["lite", "full", "ultra"],
|
||||
aggressive: ["standard", "ultra"],
|
||||
llmlingua: [],
|
||||
omniglyph: [],
|
||||
ultra: ["ultra"],
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user