Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions open-sse/mcp-server/schemas/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1095,11 +1095,31 @@ export const compressionStatusTool: McpToolDefinition<
export const compressionConfigureInput = z.object({
enabled: z.boolean().optional(),
strategy: z
.enum(["off", "lite", "standard", "aggressive", "ultra", "rtk", "stacked", "omniglyph"])
.enum([
"off",
"lite",
"standard",
"aggressive",
"ultra",
"rtk",
"codex-responses",
"stacked",
"omniglyph",
])
.optional()
.describe("Compression mode"),
autoTriggerMode: z
.enum(["off", "lite", "standard", "aggressive", "ultra", "rtk", "stacked", "omniglyph"])
.enum([
"off",
"lite",
"standard",
"aggressive",
"ultra",
"rtk",
"codex-responses",
"stacked",
"omniglyph",
])
.optional(),
maxTokens: z
.number()
Expand Down Expand Up @@ -1132,7 +1152,7 @@ export const compressionConfigureTool: McpToolDefinition<
> = {
name: "omniroute_compression_configure",
description:
"Configure compression settings at runtime. Supports enabling/disabling compression, changing strategy (off/lite/standard/aggressive/ultra/rtk/stacked), adjusting maxTokens threshold, targetRatio, auto-trigger mode, system prompt preservation, and MCP description compression.",
"Configure compression settings at runtime. Supports enabling/disabling compression, changing strategy (off/lite/standard/aggressive/ultra/rtk/codex-responses/stacked), adjusting maxTokens threshold, targetRatio, auto-trigger mode, system prompt preservation, and MCP description compression.",
inputSchema: compressionConfigureInput,
outputSchema: compressionConfigureOutput,
scopes: ["write:compression"],
Expand All @@ -1142,7 +1162,7 @@ export const compressionConfigureTool: McpToolDefinition<
};

export const setCompressionEngineInput = z.object({
engine: z.enum(["off", "caveman", "rtk", "stacked"]).optional(),
engine: z.enum(["off", "caveman", "rtk", "codex-responses", "stacked"]).optional(),
Comment thread
JxnLexn marked this conversation as resolved.
Resolved
cavemanIntensity: z.enum(["lite", "full", "ultra"]).optional(),
rtkIntensity: z.enum(["minimal", "standard", "aggressive"]).optional(),
outputMode: z.boolean().optional(),
Expand Down
21 changes: 17 additions & 4 deletions open-sse/mcp-server/tools/compressionTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,26 +428,39 @@ export async function handleSetCompressionEngine(
args: z.infer<typeof setCompressionEngineInput>
): Promise<{ success: boolean; settings: Record<string, unknown> }> {
const updates: Record<string, unknown> = { enabled: true };
const current = await getCompressionSettings();
if (args.engine) {
updates.defaultMode = args.engine === "caveman" ? "standard" : args.engine;
if (args.engine === "off") updates.enabled = false;
if (args.engine === "off") {
updates.enabled = false;
} else if (args.engine !== "stacked") {
const selectedEngine = args.engine === "caveman" ? "caveman" : args.engine;
updates.engines = Object.fromEntries(
Object.entries(current.engines).map(([id, toggle]) => [
id,
{
...toggle,
enabled: id === selectedEngine,
...(id === "caveman" && args.cavemanIntensity ? { level: args.cavemanIntensity } : {}),
...(id === "rtk" && args.rtkIntensity ? { level: args.rtkIntensity } : {}),
},
])
);
}
}
if (args.cavemanIntensity) {
const current = await getCompressionSettings();
updates.cavemanConfig = {
...(current.cavemanConfig ?? {}),
intensity: args.cavemanIntensity,
};
}
if (args.rtkIntensity) {
const current = await getCompressionSettings();
updates.rtkConfig = {
...(current.rtkConfig ?? {}),
intensity: args.rtkIntensity,
};
}
if (args.outputMode !== undefined) {
const current = await getCompressionSettings();
updates.cavemanOutputMode = {
...(current.cavemanOutputMode ?? {}),
enabled: args.outputMode,
Expand Down
88 changes: 84 additions & 4 deletions open-sse/services/compression/bodyAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ type MessageLike = {
[key: string]: unknown;
};

export const CODEX_RESPONSE_ITEM_META = Symbol("codexResponseItemMeta");

export type CodexResponseItemMeta = {
type: string;
eligible: boolean;
};

type CodexMessageLike = MessageLike & {
[CODEX_RESPONSE_ITEM_META]?: CodexResponseItemMeta;
};

type ResponsesItem = {
type?: unknown;
role?: unknown;
Expand All @@ -18,6 +29,8 @@ const RESPONSES_MESSAGE_TYPES = new Set([
"message",
"function_call_output",
"custom_tool_call_output",
"local_shell_call_output",
"apply_patch_call_output",
]);
const COMPRESSION_INPUT_INDEX = Symbol("compressionInputIndex");

Expand Down Expand Up @@ -100,11 +113,16 @@ function responsesToolOutputField(item: ResponsesItem): "output" | "content" {
return item.output !== null && item.output !== undefined ? "output" : "content";
}

function responsesItemToMessage(item: ResponsesItem): MessageLike | null {
function responsesItemToMessage(item: ResponsesItem): CodexMessageLike | null {
const type = typeof item.type === "string" ? item.type : "message";
if (!RESPONSES_MESSAGE_TYPES.has(type)) return null;

if (type === "function_call_output" || type === "custom_tool_call_output") {
if (
type === "function_call_output" ||
type === "custom_tool_call_output" ||
type === "local_shell_call_output" ||
type === "apply_patch_call_output"
) {
const rawOutput = item.output ?? item.content;
// OpenAI Responses shape (Codex): body.input holds Responses items. When
// output is a JSON object (not a string or content array), serialise it so
Expand All @@ -123,6 +141,7 @@ function responsesItemToMessage(item: ResponsesItem): MessageLike | null {
: isObjectOutput
? JSON.stringify(rawOutput)
: toChatContent(rawOutput),
[CODEX_RESPONSE_ITEM_META]: { type, eligible: false },
};
}

Expand All @@ -132,9 +151,65 @@ function responsesItemToMessage(item: ResponsesItem): MessageLike | null {
};
}

const DEFAULT_CODEX_PROTECTED_TOOL_NAMES = new Set([
"read",
"glob",
"grep",
"write",
"edit",
"websearch",
"webfetch",
"web_search",
"web_fetch",
]);
function markCodexResponseEligibility(
messages: CodexMessageLike[],
inputItems: unknown[],
preserveToolNames: string[] = []
): void {
const protectedNames = new Set([
...DEFAULT_CODEX_PROTECTED_TOOL_NAMES,
...preserveToolNames.map((name) => name.trim().toLowerCase()),
]);
const functionCalls = new Map<string, string>();
const skippedCallIds = new Set<string>();
for (const raw of inputItems) {
if (!isRecord(raw) || raw.type !== "function_call") continue;
if (typeof raw.call_id !== "string" || raw.call_id.length === 0) continue;
const name = typeof raw.name === "string" ? raw.name : "";
functionCalls.set(raw.call_id, name);
if (
protectedNames.has(name.trim().toLowerCase()) ||
name === "headless_retrieval" ||
name.endsWith("__headless_retrieval")
) {
skippedCallIds.add(raw.call_id);
}
}

for (const message of messages) {
const meta = message[CODEX_RESPONSE_ITEM_META];
if (!meta) continue;
if (meta.type === "local_shell_call_output" || meta.type === "apply_patch_call_output") {
meta.eligible = true;
continue;
}
if (meta.type !== "function_call_output") continue;
const rawIndex = message[COMPRESSION_INPUT_INDEX];
const rawItem = typeof rawIndex === "number" ? inputItems[rawIndex] : null;
const callId = isRecord(rawItem) && typeof rawItem.call_id === "string" ? rawItem.call_id : "";
meta.eligible = callId.length > 0 && functionCalls.has(callId) && !skippedCallIds.has(callId);
}
}

function messageToResponsesItem(message: MessageLike, originalItem: ResponsesItem): ResponsesItem {
const type = typeof originalItem.type === "string" ? originalItem.type : "message";
if (type === "function_call_output" || type === "custom_tool_call_output") {
if (
type === "function_call_output" ||
type === "custom_tool_call_output" ||
type === "local_shell_call_output" ||
type === "apply_patch_call_output"
) {
const outputField = responsesToolOutputField(originalItem);
const originalOutput = originalItem[outputField];
return {
Expand Down Expand Up @@ -166,7 +241,10 @@ export type CompressionBodyAdapter = {
restore(compressedBody: Record<string, unknown>): Record<string, unknown>;
};

export function adaptBodyForCompression(body: Record<string, unknown>): CompressionBodyAdapter {
export function adaptBodyForCompression(
body: Record<string, unknown>,
preserveToolNames: string[] = []
): CompressionBodyAdapter {
if (Array.isArray(body.messages)) {
return {
body,
Expand Down Expand Up @@ -205,6 +283,8 @@ export function adaptBodyForCompression(body: Record<string, unknown>): Compress
messages.push({ ...message, [COMPRESSION_INPUT_INDEX]: index });
});

markCodexResponseEligibility(messages, inputItems, preserveToolNames);

if (messages.length === 0) {
return {
body,
Expand Down
10 changes: 3 additions & 7 deletions open-sse/services/compression/deriveDefaultPlan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,12 @@ const SINGLE_MODE_OF: Record<string, string> = {
aggressive: "aggressive",
ultra: "ultra",
rtk: "rtk",
"codex-responses": "codex-responses",
omniglyph: "omniglyph",
};

export type CompressionSource =
| "request-header"
| "routing-override"
| "active-profile"
| "auto-trigger"
| "default"
| "off";
"request-header" | "routing-override" | "active-profile" | "auto-trigger" | "default" | "off";

export interface DerivedPlan {
mode: string;
Expand All @@ -37,7 +33,7 @@ export interface DerivedPlan {
*/
export function deriveDefaultPlan(
engines: Record<string, EngineToggle>,
masterEnabled: boolean,
masterEnabled: boolean
): DerivedPlan {
if (!masterEnabled) return { mode: "off", stackedPipeline: [] };

Expand Down
17 changes: 15 additions & 2 deletions open-sse/services/compression/engineCatalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export interface EngineMeta {
id: string;
label: string;
stackPriority: number;
levels?: string[]; // intensity options; undefined = no level selector
isSingleMode: boolean; // can be the effective mode when it is the only engine on
levels?: string[]; // intensity options; undefined = no level selector
isSingleMode: boolean; // can be the effective mode when it is the only engine on
description: string;
guidance: EngineGuidance;
}
Expand Down Expand Up @@ -82,6 +82,19 @@ export const ENGINE_CATALOG: Record<string, EngineMeta> = {
cacheImpact: "moderate",
},
},
"codex-responses": {
Comment thread
JxnLexn marked this conversation as resolved.
Resolved
id: "codex-responses",
label: "Responses Tool Output",
stackPriority: 12,
isSingleMode: true,
description: "Conservative compression for supported Responses tool outputs.",
guidance: {
tradeoffs:
"Lossless-first JSON and bounded diagnostic compression for shell, patch, search, and build outputs. Protected tools and uncertain shapes pass through unchanged.",
lossy: true,
cacheImpact: "low",
},
},
headroom: {
id: "headroom",
label: "Headroom",
Expand Down
Loading
Loading