mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-31 04:12:10 +03:00
fix: clean up proxy page redundancy and fix 1proxy sync empty body error (#2052)
This commit is contained in:
@@ -1615,9 +1615,10 @@ export async function handleChatCore({
|
||||
// ── Proactive Context Compression (Phase 4) ──
|
||||
// Check if context exceeds 70% of limit and compress proactively before sending to provider.
|
||||
// This prevents "prompt too long" errors for large-but-not-full contexts.
|
||||
const compressionBody = body ? adaptBodyForCompression(body as Record<string, unknown>).body : null;
|
||||
const allMessages =
|
||||
compressionBody?.messages || body?.contents || body?.request?.contents || [];
|
||||
const compressionBody = body
|
||||
? adaptBodyForCompression(body as Record<string, unknown>).body
|
||||
: null;
|
||||
const allMessages = compressionBody?.messages || body?.contents || body?.request?.contents || [];
|
||||
let cavemanOutputModeApplied = false;
|
||||
let cavemanOutputModeIntensity: string | null = null;
|
||||
if (body && Array.isArray(allMessages) && allMessages.length > 0) {
|
||||
|
||||
@@ -78,10 +78,15 @@ export async function handleEmbedding({
|
||||
// Set up request logger for pipeline artifact capture
|
||||
const detailedLoggingEnabled = await isDetailedLoggingEnabled();
|
||||
const captureStreamChunks = await getCallLogPipelineCaptureStreamChunks();
|
||||
const reqLogger = await createRequestLogger(provider || "openai", "openai", body.model as string, {
|
||||
enabled: detailedLoggingEnabled,
|
||||
captureStreamChunks,
|
||||
});
|
||||
const reqLogger = await createRequestLogger(
|
||||
provider || "openai",
|
||||
"openai",
|
||||
body.model as string,
|
||||
{
|
||||
enabled: detailedLoggingEnabled,
|
||||
captureStreamChunks,
|
||||
}
|
||||
);
|
||||
|
||||
// Log client raw request
|
||||
if (clientRawRequest) {
|
||||
|
||||
@@ -190,7 +190,9 @@ function shouldCompressMessage(message: Message, config: RtkConfig): boolean {
|
||||
if (message.role === "tool")
|
||||
return config.applyToToolResults || (config.applyToCodeBlocks && hasCodeFence(message.content));
|
||||
if (message.role === "assistant")
|
||||
return config.applyToAssistantMessages || (config.applyToCodeBlocks && hasCodeFence(message.content));
|
||||
return (
|
||||
config.applyToAssistantMessages || (config.applyToCodeBlocks && hasCodeFence(message.content))
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -198,7 +200,9 @@ function hasCodeFence(content: Message["content"]): boolean {
|
||||
if (!content) return false;
|
||||
if (typeof content === "string") return /```/.test(content);
|
||||
if (!Array.isArray(content)) return false;
|
||||
return content.some((part) => isTextBlock(part) && typeof part.text === "string" && /```/.test(part.text));
|
||||
return content.some(
|
||||
(part) => isTextBlock(part) && typeof part.text === "string" && /```/.test(part.text)
|
||||
);
|
||||
}
|
||||
|
||||
function codeOnlyConfig(config: RtkConfig): boolean {
|
||||
|
||||
@@ -89,7 +89,11 @@ export function applyCompression(
|
||||
return adapter.adapted ? { ...result, body: adapter.restore(result.body) } : result;
|
||||
}
|
||||
if (mode === "stacked") {
|
||||
const result = applyStackedCompression(compressionBody, options?.config?.stackedPipeline, options);
|
||||
const result = applyStackedCompression(
|
||||
compressionBody,
|
||||
options?.config?.stackedPipeline,
|
||||
options
|
||||
);
|
||||
return adapter.adapted ? { ...result, body: adapter.restore(result.body) } : result;
|
||||
}
|
||||
if (mode === "standard") {
|
||||
|
||||
@@ -239,7 +239,8 @@ function getActiveBudgetLimit(budget: NormalizedBudgetConfig): number {
|
||||
function getBudgetWindowTotal(apiKeyId: string, periodStartAt: number): number {
|
||||
try {
|
||||
return (
|
||||
loadCostTotal(apiKeyId, periodStartAt) + spendBatchWriter.getPendingCostTotal(apiKeyId, periodStartAt)
|
||||
loadCostTotal(apiKeyId, periodStartAt) +
|
||||
spendBatchWriter.getPendingCostTotal(apiKeyId, periodStartAt)
|
||||
);
|
||||
} catch {
|
||||
return 0;
|
||||
|
||||
@@ -16,7 +16,12 @@ type PricingByProvider = Record<string, PricingModels>;
|
||||
export type PricingSource = "default" | "litellm" | "modelsDev" | "user";
|
||||
export type PricingSourceMap = Record<string, Record<string, PricingSource>>;
|
||||
type ProxyValue = JsonRecord | string | null;
|
||||
type ProxyResolutionResult = { proxy: ProxyValue; level: string; levelId: string | null; source?: string };
|
||||
type ProxyResolutionResult = {
|
||||
proxy: ProxyValue;
|
||||
level: string;
|
||||
levelId: string | null;
|
||||
source?: string;
|
||||
};
|
||||
type ProxyResolutionCacheEntry = {
|
||||
generation: number;
|
||||
registryGeneration: number;
|
||||
@@ -541,7 +546,12 @@ export async function resolveProxyForConnection(connectionId: string) {
|
||||
const registryResolved = await resolveProxyForConnectionFromRegistry(connectionId);
|
||||
if (registryResolved?.proxy) {
|
||||
if (registryResolved.level === "account") {
|
||||
cacheProxyResolution(connectionId, startGeneration, startRegistryGeneration, registryResolved);
|
||||
cacheProxyResolution(
|
||||
connectionId,
|
||||
startGeneration,
|
||||
startRegistryGeneration,
|
||||
registryResolved
|
||||
);
|
||||
}
|
||||
return registryResolved;
|
||||
}
|
||||
|
||||
@@ -861,9 +861,7 @@ export async function getCallLogById(id: string) {
|
||||
LEFT JOIN provider_nodes pn ON pn.id = cl.provider
|
||||
WHERE cl.id = ?`
|
||||
)
|
||||
.get(id) as
|
||||
| CallLogSummaryRow
|
||||
| undefined;
|
||||
.get(id) as CallLogSummaryRow | undefined;
|
||||
if (!row) return null;
|
||||
|
||||
const entry = mapSummaryRow(row);
|
||||
|
||||
@@ -51,9 +51,18 @@ describe("Caveman language packs", () => {
|
||||
it("keeps the Spanish pack aligned with English rule categories", () => {
|
||||
const esRules = loadAllRulesForLanguage("es", { refresh: true });
|
||||
assert.ok(esRules.length >= 40, `es expected 40+ rules, got ${esRules.length}`);
|
||||
assert.ok(esRules.some((rule) => rule.category === "dedup"), "es missing dedup");
|
||||
assert.ok(esRules.some((rule) => rule.category === "ultra"), "es missing ultra");
|
||||
assert.ok(esRules.some((rule) => rule.category === "terse"), "es missing terse");
|
||||
assert.ok(
|
||||
esRules.some((rule) => rule.category === "dedup"),
|
||||
"es missing dedup"
|
||||
);
|
||||
assert.ok(
|
||||
esRules.some((rule) => rule.category === "ultra"),
|
||||
"es missing ultra"
|
||||
);
|
||||
assert.ok(
|
||||
esRules.some((rule) => rule.category === "terse"),
|
||||
"es missing terse"
|
||||
);
|
||||
});
|
||||
|
||||
it("applies expanded Spanish rules without touching technical terms", () => {
|
||||
|
||||
Reference in New Issue
Block a user