Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions open-sse/translator/response/openai-responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
normalizeOutputIndex,
normalizeUpstreamFailure,
extractResponsesReasoningSummaryText,
ensureVisibleResponsesReasoningSummary,
} from "./openai-responses/pureHelpers.ts";
import { createEventEmitter } from "./openai-responses/eventEmitter.ts";

Expand Down Expand Up @@ -1070,6 +1071,7 @@ function openaiResponsesToOpenAIResponseStream(chunk, state) {
!(state.reasoningItemsWithDelta instanceof Set && state.reasoningItemsWithDelta.size > 0);
if (emittedForItem || emittedWithoutItemId) return null;

ensureVisibleResponsesReasoningSummary(item);
const summaryText = extractResponsesReasoningSummaryText(item);
if (!summaryText) return null;
return buildResponsesReasoningDeltaChunk(state, summaryText);
Expand Down
18 changes: 18 additions & 0 deletions open-sse/translator/response/openai-responses/pureHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,21 @@ export function extractResponsesReasoningSummaryText(item) {
)
.join("");
}

const ENCRYPTED_REASONING_SUMMARY =
"Codex is reasoning, but the upstream Responses API exposed this reasoning block only as encrypted private reasoning. OmniRoute cannot recover the plaintext.";

export function ensureVisibleResponsesReasoningSummary(item) {
if (
!item ||
item.type !== "reasoning" ||
extractResponsesReasoningSummaryText(item) ||
typeof item.encrypted_content !== "string" ||
item.encrypted_content.length === 0
) {
return false;
}

item.summary = [{ type: "summary_text", text: ENCRYPTED_REASONING_SUMMARY }];
return true;
}
45 changes: 7 additions & 38 deletions open-sse/utils/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ import {
stripResponsesLifecycleEcho,
} from "./responsesStreamHelpers.ts";
import { processBufferedPassthroughLine } from "./passthroughTailProcessor.ts";
import {
ensureVisibleResponsesReasoningSummary as ensureVisibleResponsesReasoningItemSummary,
extractResponsesReasoningSummaryText,
} from "../translator/response/openai-responses/pureHelpers.ts";
import {
getAnyReasoningValue,
getReadableReasoningValue,
Expand Down Expand Up @@ -1006,47 +1010,12 @@ export function createSSEStream(options: StreamOptions = {}) {
return responseId !== null && outputIndex !== null ? `${responseId}:${outputIndex}` : null;
};

const getResponsesReasoningSummaryText = (item: Record<string, unknown>): string => {
return Array.isArray(item.summary)
? item.summary
.map((part) => {
if (!part || typeof part !== "object" || Array.isArray(part)) {
return "";
}
return typeof (part as Record<string, unknown>).text === "string"
? ((part as Record<string, unknown>).text as string)
: "";
})
.join("")
: "";
};

const ensureVisibleResponsesReasoningSummary = (payload: Record<string, unknown>): boolean => {
const item =
payload.item && typeof payload.item === "object" && !Array.isArray(payload.item)
? (payload.item as Record<string, unknown>)
: null;
if (!item || item.type !== "reasoning") {
return false;
}

if (getResponsesReasoningSummaryText(item)) {
return false;
}

const hasEncryptedReasoning =
typeof item.encrypted_content === "string" && item.encrypted_content.length > 0;
if (!hasEncryptedReasoning) {
return false;
}

item.summary = [
{
type: "summary_text",
text: "Codex is reasoning, but the upstream Responses API exposed this reasoning block only as encrypted state. OmniRoute cannot recover the private reasoning text.",
},
];
return true;
return ensureVisibleResponsesReasoningItemSummary(item);
};

const emitSyntheticResponsesReasoningSummary = (
Expand All @@ -1061,8 +1030,8 @@ export function createSSEStream(options: StreamOptions = {}) {
return;
}

ensureVisibleResponsesReasoningSummary(payload);
const visibleSummary = getResponsesReasoningSummaryText(item);
ensureVisibleResponsesReasoningItemSummary(item);
const visibleSummary = extractResponsesReasoningSummaryText(item);

if (!visibleSummary) {
return;
Expand Down
Loading
Loading