@eddyskywalker/dsh-chatgpt-subscription 0.91.1 → 0.92.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/client.js.map +1 -1
- package/lib/index.js +284 -75
- package/lib/{tool-result-pruner-Baz9Lrov.js → tool-result-pruner-DvBErf9I.js} +1 -1
- package/lib/tool-result-pruner.js +1 -1
- package/lib/types/compat.d.ts +1 -1
- package/lib/types/host/providers/codex-chatgpt/responses-client.d.ts.map +1 -1
- package/lib/types/host/providers/relayone/adapter.d.ts +5 -0
- package/lib/types/host/providers/relayone/adapter.d.ts.map +1 -1
- package/lib/types/host/providers/relayone/mapper-openai.d.ts +1 -1
- package/lib/types/host/providers/relayone/mapper-openai.d.ts.map +1 -1
- package/lib/types/host/providers/relayone/remote-compaction.d.ts +30 -0
- package/lib/types/host/providers/relayone/remote-compaction.d.ts.map +1 -0
- package/lib/types/host/runtime/guards/compaction-policy-guard.d.ts +1 -0
- package/lib/types/host/runtime/guards/compaction-policy-guard.d.ts.map +1 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { a as resolveProgressUpdatesSettings, n as attachProgressSettings } from "./progress-updates-jiHnSAmz.js";
|
|
2
2
|
import { h as resolvePlanModePipelineEnabled, l as attachPlanModePipelineSettings } from "./plan-mode-pipeline-DQ8TM6mP.js";
|
|
3
3
|
import { a as PLUGIN_MESSAGE_SOURCE_KIND, c as formatToolUpdateNotice, d as midConversationUpdateToUserMessage, f as normalizeGenerateOptions, i as LlmError$1, l as leadingSystemEndIndex, n as installBundledPresets, o as extractSystemText, r as resolvesFromHere, s as formatMidConversationSystemReminder, u as midConversationSystemToUserMessage } from "./preset-sync-gvhSzmlr.js";
|
|
4
|
-
import { A as isDeepSeekV41Flash, B as
|
|
4
|
+
import { A as isDeepSeekV41Flash, B as estimateCodexPayloadTokens, C as isOpenModelSessionPrefixCacheProtected, D as matchOpenModelScope, E as matchOpenModelProfile, F as checkpointFromMetadata, G as shouldCompactCodexPayload, H as latestCodexCompaction, I as checkpointFromOutputItems, K as withCodexCompactionTrigger, L as codexCompactionReplayMetadata, M as isDeepSeekV41FlashSession, N as readScopeRoute, O as matchOpenModelSession, P as readSessionRoute, R as codexRemoteCompactionEnabled, S as isOpenModelPrefixCacheProtected, T as isStepOpenModel, U as noteCodexRemoteCompactionFailure, V as isCompactionItem, W as projectFreshCodexCompaction, _ as isKimiOpenModel, b as isMinimaxOpenModel, d as OPEN_MODEL_PROFILES, f as bareOpenModelId, g as isKimiK31OpenModel, h as isGlm5OpenModel, j as isDeepSeekV41FlashScope, k as DEEPSEEK_OFFICIAL_PROVIDERS, l as resolveSkipProviders, m as isGlm54OpenModel, n as DEFAULT_SKIP_PROVIDERS, p as isDeepSeekV4NonV41Model, r as PRUNER_SERVICE_NAME, u as shouldSkipPruningForSession, v as isLongSparseOpenModel, w as isQwenOpenModel, x as isOpenModelCacheWarmupProtected, y as isMimoOpenModel, z as codexRemoteCompactionThreshold } from "./tool-result-pruner-DvBErf9I.js";
|
|
5
5
|
import { C as isDelegatedCaller, S as installDispatchExecutionGuard, T as resolveDispatchExecutionGuardEnabled, _ as installPlanModeExitReminder, b as registeredPlanControllerActive, h as createPlanNotice, l as PLAN_PROJECTION_KEY, n as EXIT_PLAN_MODE, w as isDelegatedSession } from "./plan-mode-cY8pp0PZ.js";
|
|
6
6
|
import { createRequire } from "node:module";
|
|
7
7
|
import * as LlmModule from "@deepseek-ai/dsh-llm";
|
|
@@ -840,7 +840,7 @@ const ROUTE_PREFIX$5 = "/api/dsh-chatgpt-subscription";
|
|
|
840
840
|
* `test/responses-client.test.ts` asserts the two agree, so a release that
|
|
841
841
|
* forgets this constant fails the suite instead of shipping quietly.
|
|
842
842
|
*/
|
|
843
|
-
const PLUGIN_VERSION = "0.
|
|
843
|
+
const PLUGIN_VERSION = "0.92.0";
|
|
844
844
|
const CODEX_CHATGPT_PROVIDER_ID = "codex-chatgpt";
|
|
845
845
|
const CODEX_API_BASE = "https://chatgpt.com/backend-api/codex";
|
|
846
846
|
const CODEX_RESPONSES_URL = `${CODEX_API_BASE}/responses`;
|
|
@@ -6510,9 +6510,9 @@ function upstreamExcerpt(text) {
|
|
|
6510
6510
|
return collapsed.length > MAX_UPSTREAM_EXCERPT_CHARS ? `${collapsed.slice(0, MAX_UPSTREAM_EXCERPT_CHARS)}…` : collapsed;
|
|
6511
6511
|
}
|
|
6512
6512
|
function readBase64Image(value) {
|
|
6513
|
-
const root = record$
|
|
6513
|
+
const root = record$10(value);
|
|
6514
6514
|
const data = Array.isArray(root?.data) ? root.data[0] : null;
|
|
6515
|
-
const image = string$2(record$
|
|
6515
|
+
const image = string$2(record$10(data)?.b64_json) ?? string$2(record$10(data)?.image_base64) ?? string$2(root?.b64_json) ?? string$2(root?.image);
|
|
6516
6516
|
if (image === null) throw new HarnessError("Codex image response did not include image data.", "CODEX_IMAGE_RESPONSE_INVALID");
|
|
6517
6517
|
return image;
|
|
6518
6518
|
}
|
|
@@ -6541,7 +6541,7 @@ function decodeImageBytes(base64, maxBytes) {
|
|
|
6541
6541
|
function maxGeneratedImageBytes(attachments) {
|
|
6542
6542
|
return Math.min(attachments.imageLimits.maxImageBytes, attachments.imageLimits.maxMessageImageBytes);
|
|
6543
6543
|
}
|
|
6544
|
-
function record$
|
|
6544
|
+
function record$10(value) {
|
|
6545
6545
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : null;
|
|
6546
6546
|
}
|
|
6547
6547
|
function string$2(value) {
|
|
@@ -6636,13 +6636,13 @@ function normalizeSearchResult(data, maxResults) {
|
|
|
6636
6636
|
};
|
|
6637
6637
|
}
|
|
6638
6638
|
function readSources(data) {
|
|
6639
|
-
const root = record$
|
|
6639
|
+
const root = record$9(data);
|
|
6640
6640
|
if (root === null) return [];
|
|
6641
6641
|
const candidates = [
|
|
6642
6642
|
root.sources,
|
|
6643
6643
|
root.results,
|
|
6644
|
-
record$
|
|
6645
|
-
record$
|
|
6644
|
+
record$9(root.search_result)?.sources,
|
|
6645
|
+
record$9(root.web_search)?.sources
|
|
6646
6646
|
];
|
|
6647
6647
|
for (const candidate of candidates) {
|
|
6648
6648
|
if (!Array.isArray(candidate)) continue;
|
|
@@ -6652,7 +6652,7 @@ function readSources(data) {
|
|
|
6652
6652
|
return [];
|
|
6653
6653
|
}
|
|
6654
6654
|
function readSource(value) {
|
|
6655
|
-
const data = record$
|
|
6655
|
+
const data = record$9(value);
|
|
6656
6656
|
if (data === null) return null;
|
|
6657
6657
|
const url = string$1(data.url) ?? string$1(data.link) ?? string$1(data.uri);
|
|
6658
6658
|
if (url === null || !isHttpUrl(url)) return null;
|
|
@@ -6681,7 +6681,7 @@ function readSource(value) {
|
|
|
6681
6681
|
* counterpart of `output`, not a fallback for it.
|
|
6682
6682
|
*/
|
|
6683
6683
|
function readContent(data) {
|
|
6684
|
-
const root = record$
|
|
6684
|
+
const root = record$9(data);
|
|
6685
6685
|
if (root === null) return void 0;
|
|
6686
6686
|
return string$1(root.content) ?? string$1(root.output_text) ?? string$1(root.summary) ?? string$1(root.output) ?? void 0;
|
|
6687
6687
|
}
|
|
@@ -6696,7 +6696,7 @@ function dedupeSources(sources) {
|
|
|
6696
6696
|
}
|
|
6697
6697
|
return result;
|
|
6698
6698
|
}
|
|
6699
|
-
function record$
|
|
6699
|
+
function record$9(value) {
|
|
6700
6700
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : null;
|
|
6701
6701
|
}
|
|
6702
6702
|
function string$1(value) {
|
|
@@ -9814,7 +9814,7 @@ function offloadOldestInputImages(input, maxBytes = maxRequestImageBytes$2()) {
|
|
|
9814
9814
|
for (const item of input) {
|
|
9815
9815
|
if (!Array.isArray(item.content)) continue;
|
|
9816
9816
|
for (const [index, block] of item.content.entries()) {
|
|
9817
|
-
if (record$
|
|
9817
|
+
if (record$8(block) === null || block.type !== "input_image") continue;
|
|
9818
9818
|
const url = block.image_url;
|
|
9819
9819
|
if (typeof url !== "string") continue;
|
|
9820
9820
|
retained.push({
|
|
@@ -10432,12 +10432,12 @@ function replayOutputItems(message, model, compHash) {
|
|
|
10432
10432
|
const replay = message.source?.replayState;
|
|
10433
10433
|
if (typeof replay !== "object" || replay === null || Array.isArray(replay)) return null;
|
|
10434
10434
|
const envelope = replay;
|
|
10435
|
-
const items = Array.isArray(envelope.outputItems) ? envelope.outputItems : Array.isArray(record$
|
|
10435
|
+
const items = Array.isArray(envelope.outputItems) ? envelope.outputItems : Array.isArray(record$8(envelope.response)?.outputItems) ? record$8(envelope.response).outputItems : null;
|
|
10436
10436
|
if (!Array.isArray(items)) return null;
|
|
10437
|
-
const nativeCheckpoint = checkpointFromMetadata(record$
|
|
10437
|
+
const nativeCheckpoint = checkpointFromMetadata(record$8(record$8(envelope.response)?.nativeCompaction), model, compHash);
|
|
10438
10438
|
return structuredClone(items.filter((item) => typeof item === "object" && item !== null && !Array.isArray(item)).filter((item) => !isCompactionItem(item) || codexRemoteCompactionEnabled() && nativeCheckpoint !== null));
|
|
10439
10439
|
}
|
|
10440
|
-
function record$
|
|
10440
|
+
function record$8(value) {
|
|
10441
10441
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : null;
|
|
10442
10442
|
}
|
|
10443
10443
|
//#endregion
|
|
@@ -10834,10 +10834,10 @@ const MAX_TRACKED_TURN_STATES = 200;
|
|
|
10834
10834
|
const codexPrefixRequests = new PrefixRequestCoordinator();
|
|
10835
10835
|
function codexColdGroupKey(payload, credentials) {
|
|
10836
10836
|
const input = Array.isArray(payload.input) ? payload.input : [];
|
|
10837
|
-
const head = record$
|
|
10837
|
+
const head = record$7(input[0]);
|
|
10838
10838
|
const liteTools = head?.type === "additional_tools" ? head.tools : void 0;
|
|
10839
|
-
const instructions = liteTools === void 0 ? head : record$
|
|
10840
|
-
const kinds = record$
|
|
10839
|
+
const instructions = liteTools === void 0 ? head : record$7(input[1]);
|
|
10840
|
+
const kinds = record$7(instructions?.internal_chat_message_metadata_passthrough)?.content_item_kinds;
|
|
10841
10841
|
if (instructions?.role !== "developer" || !Array.isArray(kinds) || !kinds.includes("model.base_instructions")) return void 0;
|
|
10842
10842
|
const digest = createHash("sha256").update(JSON.stringify([
|
|
10843
10843
|
instructions.content,
|
|
@@ -10974,7 +10974,7 @@ var ResponsesClient = class {
|
|
|
10974
10974
|
const stream = wrapStreamWithWatchdog((watchdogSignal, activity) => parseResponsesStream(opened.response, watchdogSignal, void 0, activity), signal, this.codexStreamIdleTimeoutMs, "LLM_STREAM_IDLE_TIMEOUT", "Codex remote compaction");
|
|
10975
10975
|
for await (const chunk of stream) {
|
|
10976
10976
|
if (chunk.type !== "finish") continue;
|
|
10977
|
-
const response = record$
|
|
10977
|
+
const response = record$7(record$7(chunk.replayState)?.response);
|
|
10978
10978
|
checkpoint = checkpointFromOutputItems(Array.isArray(response?.outputItems) ? response.outputItems : [], String(payload.model), capabilities.compHash);
|
|
10979
10979
|
}
|
|
10980
10980
|
if (checkpoint === null) throw new LlmError$1("Codex remote compaction did not return exactly one encrypted compaction item.", "PROTOCOL_ERROR");
|
|
@@ -11305,7 +11305,7 @@ async function* parseResponsesStream(response, signal, _legacyHiddenSandboxContr
|
|
|
11305
11305
|
return;
|
|
11306
11306
|
}
|
|
11307
11307
|
if (type === "response.content_part.done") {
|
|
11308
|
-
const part = record$
|
|
11308
|
+
const part = record$7(event.part);
|
|
11309
11309
|
const partType = string(part?.type);
|
|
11310
11310
|
if (partType === "output_text" || partType === "refusal") yield* adoptText(string(part?.text) ?? "");
|
|
11311
11311
|
return;
|
|
@@ -11337,7 +11337,7 @@ async function* parseResponsesStream(response, signal, _legacyHiddenSandboxContr
|
|
|
11337
11337
|
return;
|
|
11338
11338
|
}
|
|
11339
11339
|
if (type === "response.output_item.added" || type === "response.output_item.done") {
|
|
11340
|
-
const item = record$
|
|
11340
|
+
const item = record$7(event.item);
|
|
11341
11341
|
if (item !== null && type === "response.output_item.done") replayOutput.push(structuredClone(item));
|
|
11342
11342
|
if (string(item?.type) !== "function_call") {
|
|
11343
11343
|
if (type === "response.output_item.done") yield* adoptText(messageItemText(item));
|
|
@@ -11397,13 +11397,18 @@ async function* parseResponsesStream(response, signal, _legacyHiddenSandboxContr
|
|
|
11397
11397
|
return;
|
|
11398
11398
|
}
|
|
11399
11399
|
if (type === "response.completed" || type === "response.incomplete") {
|
|
11400
|
-
const completed = record$
|
|
11401
|
-
usage = mapUsage$2(record$
|
|
11400
|
+
const completed = record$7(event.response);
|
|
11401
|
+
usage = mapUsage$2(record$7(completed?.usage));
|
|
11402
11402
|
const output = completed?.output;
|
|
11403
11403
|
if (Array.isArray(output)) {
|
|
11404
|
-
const terminalOutput = output.filter((item) => record$
|
|
11405
|
-
|
|
11406
|
-
|
|
11404
|
+
const terminalOutput = output.filter((item) => record$7(item) !== null).map((item) => structuredClone(item));
|
|
11405
|
+
const carriedCompaction = replayOutput.filter((item) => item.type === "compaction" && (nativeCompaction === void 0 || JSON.stringify(item) !== JSON.stringify(nativeCompaction.item)) && !terminalOutput.some((candidate) => typeof candidate.id === "string" && candidate.id === item.id || JSON.stringify(candidate) === JSON.stringify(item)));
|
|
11406
|
+
replayOutput = nativeCompaction === void 0 ? [...terminalOutput, ...carriedCompaction] : [
|
|
11407
|
+
structuredClone(nativeCompaction.item),
|
|
11408
|
+
...terminalOutput,
|
|
11409
|
+
...carriedCompaction
|
|
11410
|
+
];
|
|
11411
|
+
for (const item of output) yield* adoptText(messageItemText(record$7(item)));
|
|
11407
11412
|
}
|
|
11408
11413
|
if (type === "response.incomplete") {
|
|
11409
11414
|
terminalIncomplete = true;
|
|
@@ -11412,7 +11417,7 @@ async function* parseResponsesStream(response, signal, _legacyHiddenSandboxContr
|
|
|
11412
11417
|
return;
|
|
11413
11418
|
}
|
|
11414
11419
|
if (type === "response.failed" || type === "error") {
|
|
11415
|
-
const error = record$
|
|
11420
|
+
const error = record$7(event.error) ?? record$7(record$7(event.response)?.error);
|
|
11416
11421
|
const message = string(error?.message) ?? "Codex generation failed.";
|
|
11417
11422
|
const rawCode = string(error?.code)?.toLowerCase();
|
|
11418
11423
|
const isOverload = message.toLowerCase().includes("overload") || message.toLowerCase().includes("server error") || rawCode === "server_error" || rawCode === "service_unavailable" || rawCode === "internal_error";
|
|
@@ -11438,7 +11443,7 @@ async function* parseResponsesStream(response, signal, _legacyHiddenSandboxContr
|
|
|
11438
11443
|
} catch {
|
|
11439
11444
|
throw new LlmError$1("Codex returned malformed streaming JSON.", "PROTOCOL_ERROR");
|
|
11440
11445
|
}
|
|
11441
|
-
const valueRecord = record$
|
|
11446
|
+
const valueRecord = record$7(event);
|
|
11442
11447
|
if (valueRecord !== null) yield* consume(valueRecord);
|
|
11443
11448
|
}
|
|
11444
11449
|
}
|
|
@@ -11537,12 +11542,12 @@ async function* parseResponsesStream(response, signal, _legacyHiddenSandboxContr
|
|
|
11537
11542
|
* the report says what actually happened instead of naming a guess.
|
|
11538
11543
|
*/
|
|
11539
11544
|
function incompleteFinishReason(response) {
|
|
11540
|
-
const details = record$
|
|
11545
|
+
const details = record$7(response?.incomplete_details);
|
|
11541
11546
|
const reason = details === null ? void 0 : details.reason;
|
|
11542
11547
|
if (reason === void 0 || reason === null || reason === "max_output_tokens" || reason === "max_messages") return { kind: "max-tokens" };
|
|
11543
11548
|
if (reason === "steered") return { kind: "stop" };
|
|
11544
11549
|
const detail = JSON.stringify(reason);
|
|
11545
|
-
const message = string(record$
|
|
11550
|
+
const message = string(record$7(response?.error)?.message);
|
|
11546
11551
|
throw new LlmError$1(`Codex returned an incomplete response (${detail})${message ? `: ${message}` : "."}`, reason === "content_filter" ? "CONTENT_FILTER" : "PROVIDER_INCOMPLETE");
|
|
11547
11552
|
}
|
|
11548
11553
|
function visibleReasoningDelta(delta, currentVisibleChars, alreadyTruncated) {
|
|
@@ -11577,10 +11582,10 @@ function mapUsage$2(value) {
|
|
|
11577
11582
|
if (value === null) return null;
|
|
11578
11583
|
const totalInput = number$1(value.input_tokens) ?? 0;
|
|
11579
11584
|
const outputTokens = number$1(value.output_tokens) ?? 0;
|
|
11580
|
-
const details = record$
|
|
11585
|
+
const details = record$7(value.input_tokens_details);
|
|
11581
11586
|
const cached = number$1(details?.cached_tokens);
|
|
11582
11587
|
const written = number$1(details?.cache_write_tokens);
|
|
11583
|
-
const reasoning = number$1(record$
|
|
11588
|
+
const reasoning = number$1(record$7(value.output_tokens_details)?.reasoning_tokens);
|
|
11584
11589
|
return {
|
|
11585
11590
|
inputTokens: Math.max(0, totalInput - (cached ?? 0) - (written ?? 0)),
|
|
11586
11591
|
outputTokens,
|
|
@@ -11622,14 +11627,14 @@ function messageItemText(item) {
|
|
|
11622
11627
|
if (item === null || string(item.type) !== "message" || !Array.isArray(item.content)) return "";
|
|
11623
11628
|
let text = "";
|
|
11624
11629
|
for (const part of item.content) {
|
|
11625
|
-
const value = record$
|
|
11630
|
+
const value = record$7(part);
|
|
11626
11631
|
const kind = string(value?.type);
|
|
11627
11632
|
if (kind !== "output_text" && kind !== "refusal") continue;
|
|
11628
11633
|
text += string(value?.text) ?? "";
|
|
11629
11634
|
}
|
|
11630
11635
|
return text;
|
|
11631
11636
|
}
|
|
11632
|
-
function record$
|
|
11637
|
+
function record$7(value) {
|
|
11633
11638
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : null;
|
|
11634
11639
|
}
|
|
11635
11640
|
function string(value) {
|
|
@@ -12702,7 +12707,7 @@ function mapCodexUsage(value) {
|
|
|
12702
12707
|
return parseCodexUsage(value).buckets;
|
|
12703
12708
|
}
|
|
12704
12709
|
function parseCodexUsage(value) {
|
|
12705
|
-
const data = record$
|
|
12710
|
+
const data = record$6(value);
|
|
12706
12711
|
if (data === null) return structuredClone(EMPTY_USAGE);
|
|
12707
12712
|
const planType = typeof data.plan_type === "string" ? data.plan_type : null;
|
|
12708
12713
|
const buckets = [];
|
|
@@ -12711,7 +12716,7 @@ function parseCodexUsage(value) {
|
|
|
12711
12716
|
addBucket(buckets, usedIds, "code-review", "Code review", planType, data.code_review_rate_limit);
|
|
12712
12717
|
const additional = Array.isArray(data.additional_rate_limits) ? data.additional_rate_limits : [];
|
|
12713
12718
|
for (const [index, value] of additional.entries()) {
|
|
12714
|
-
const limit = record$
|
|
12719
|
+
const limit = record$6(value);
|
|
12715
12720
|
if (limit === null) continue;
|
|
12716
12721
|
const idSource = text$8(limit.limit_name) ?? text$8(limit.metered_feature) ?? `additional-${index + 1}`;
|
|
12717
12722
|
addBucket(buckets, usedIds, uniqueId(slug(idSource), usedIds), readableLimitName(text$8(limit.limit_name) ?? text$8(limit.metered_feature) ?? idSource), planType, limit.rate_limit);
|
|
@@ -12719,13 +12724,13 @@ function parseCodexUsage(value) {
|
|
|
12719
12724
|
return {
|
|
12720
12725
|
buckets,
|
|
12721
12726
|
credits: mapCredits(data.credits),
|
|
12722
|
-
individualLimit: mapIndividualLimit(record$
|
|
12723
|
-
spendControlReached: boolean(record$
|
|
12727
|
+
individualLimit: mapIndividualLimit(record$6(data.spend_control)?.individual_limit),
|
|
12728
|
+
spendControlReached: boolean(record$6(data.spend_control)?.reached),
|
|
12724
12729
|
resetCredits: mapResetCredits(data.rate_limit_reset_credits)
|
|
12725
12730
|
};
|
|
12726
12731
|
}
|
|
12727
12732
|
function addBucket(result, usedIds, id, name, planType, value) {
|
|
12728
|
-
const source = record$
|
|
12733
|
+
const source = record$6(value);
|
|
12729
12734
|
if (source === null) return;
|
|
12730
12735
|
const primary = mapWindow(source.primary_window);
|
|
12731
12736
|
const secondary = mapWindow(source.secondary_window);
|
|
@@ -12741,7 +12746,7 @@ function addBucket(result, usedIds, id, name, planType, value) {
|
|
|
12741
12746
|
usedIds.add(id);
|
|
12742
12747
|
}
|
|
12743
12748
|
function mapWindow(value) {
|
|
12744
|
-
const data = record$
|
|
12749
|
+
const data = record$6(value);
|
|
12745
12750
|
if (data === null) return null;
|
|
12746
12751
|
const used = numeric(data.used_percent);
|
|
12747
12752
|
if (used === void 0) return null;
|
|
@@ -12754,7 +12759,7 @@ function mapWindow(value) {
|
|
|
12754
12759
|
};
|
|
12755
12760
|
}
|
|
12756
12761
|
function mapCredits(value) {
|
|
12757
|
-
const data = record$
|
|
12762
|
+
const data = record$6(value);
|
|
12758
12763
|
if (data === null) return null;
|
|
12759
12764
|
const hasCredits = boolean(data.has_credits);
|
|
12760
12765
|
const unlimited = boolean(data.unlimited);
|
|
@@ -12767,7 +12772,7 @@ function mapCredits(value) {
|
|
|
12767
12772
|
};
|
|
12768
12773
|
}
|
|
12769
12774
|
function mapIndividualLimit(value) {
|
|
12770
|
-
const data = record$
|
|
12775
|
+
const data = record$6(value);
|
|
12771
12776
|
if (data === null) return null;
|
|
12772
12777
|
const remaining = numeric(data.remaining_percent);
|
|
12773
12778
|
const reset = numeric(data.reset_at);
|
|
@@ -12782,7 +12787,7 @@ function mapIndividualLimit(value) {
|
|
|
12782
12787
|
};
|
|
12783
12788
|
}
|
|
12784
12789
|
function mapResetCredits(value) {
|
|
12785
|
-
const data = record$
|
|
12790
|
+
const data = record$6(value);
|
|
12786
12791
|
if (data === null) return null;
|
|
12787
12792
|
const available = numeric(data.available_count);
|
|
12788
12793
|
if (available === void 0) return null;
|
|
@@ -12792,13 +12797,13 @@ function mapResetCredits(value) {
|
|
|
12792
12797
|
};
|
|
12793
12798
|
}
|
|
12794
12799
|
function parseResetCredits(value) {
|
|
12795
|
-
const data = record$
|
|
12800
|
+
const data = record$6(value);
|
|
12796
12801
|
if (data === null) return {
|
|
12797
12802
|
availableCount: 0,
|
|
12798
12803
|
expiresAt: null,
|
|
12799
12804
|
availableCreditIds: []
|
|
12800
12805
|
};
|
|
12801
|
-
const available = (Array.isArray(data.credits) ? data.credits : []).map(record$
|
|
12806
|
+
const available = (Array.isArray(data.credits) ? data.credits : []).map(record$6).filter((credit) => credit !== null && credit.status === "available").map((credit) => ({
|
|
12802
12807
|
id: text$8(credit.id),
|
|
12803
12808
|
expiresAt: timestamp(credit.expires_at)
|
|
12804
12809
|
})).filter((credit) => credit.id !== null).sort((left, right) => (left.expiresAt ?? Number.MAX_SAFE_INTEGER) - (right.expiresAt ?? Number.MAX_SAFE_INTEGER));
|
|
@@ -12816,7 +12821,7 @@ function timestamp(value) {
|
|
|
12816
12821
|
const parsed = Date.parse(value);
|
|
12817
12822
|
return Number.isFinite(parsed) ? Math.floor(parsed / 1e3) : null;
|
|
12818
12823
|
}
|
|
12819
|
-
function record$
|
|
12824
|
+
function record$6(value) {
|
|
12820
12825
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : null;
|
|
12821
12826
|
}
|
|
12822
12827
|
function boolean(value) {
|
|
@@ -30682,11 +30687,11 @@ function asRecord$16(value) {
|
|
|
30682
30687
|
}
|
|
30683
30688
|
//#endregion
|
|
30684
30689
|
//#region src/host/providers/aws-quick/images.ts
|
|
30685
|
-
function record$
|
|
30690
|
+
function record$5(block) {
|
|
30686
30691
|
return block;
|
|
30687
30692
|
}
|
|
30688
30693
|
function quickImageName(block) {
|
|
30689
|
-
const value = record$
|
|
30694
|
+
const value = record$5(block);
|
|
30690
30695
|
const attachment = value.attachment && typeof value.attachment === "object" ? value.attachment : void 0;
|
|
30691
30696
|
return typeof attachment?.name === "string" && attachment.name || typeof value.name === "string" && value.name || "attached image";
|
|
30692
30697
|
}
|
|
@@ -30694,7 +30699,7 @@ function quickImageLabel(block) {
|
|
|
30694
30699
|
return "[Image: " + quickImageName(block) + "]";
|
|
30695
30700
|
}
|
|
30696
30701
|
function inline(block, images) {
|
|
30697
|
-
const loaded = imageBlockToInline$2(record$
|
|
30702
|
+
const loaded = imageBlockToInline$2(record$5(block), images);
|
|
30698
30703
|
if (!loaded) throw new LlmError$1("AWS Quick could not read " + quickImageLabel(block) + "; attach the image again.", "INVALID_REQUEST");
|
|
30699
30704
|
return loaded;
|
|
30700
30705
|
}
|
|
@@ -30732,7 +30737,7 @@ function quickToolResultContent(blocks, images) {
|
|
|
30732
30737
|
});
|
|
30733
30738
|
continue;
|
|
30734
30739
|
}
|
|
30735
|
-
throw new LlmError$1("AWS Quick cannot project tool result block " + String(record$
|
|
30740
|
+
throw new LlmError$1("AWS Quick cannot project tool result block " + String(record$5(block).type ?? "unknown") + ".", "INVALID_REQUEST");
|
|
30736
30741
|
}
|
|
30737
30742
|
return out;
|
|
30738
30743
|
}
|
|
@@ -57774,14 +57779,14 @@ const MEDIA_OUTPUT = {
|
|
|
57774
57779
|
text: JSON.stringify(value, null, 2)
|
|
57775
57780
|
}]
|
|
57776
57781
|
};
|
|
57777
|
-
function record$
|
|
57782
|
+
function record$4(value) {
|
|
57778
57783
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
57779
57784
|
}
|
|
57780
57785
|
function text$5(value) {
|
|
57781
57786
|
return typeof value === "string" && value.trim() !== "" ? value.trim() : void 0;
|
|
57782
57787
|
}
|
|
57783
57788
|
function records(value) {
|
|
57784
|
-
return Array.isArray(value) ? value.map(record$
|
|
57789
|
+
return Array.isArray(value) ? value.map(record$4).filter((item) => item !== void 0) : [];
|
|
57785
57790
|
}
|
|
57786
57791
|
function requiredText(value, field) {
|
|
57787
57792
|
const result = text$5(value);
|
|
@@ -57791,7 +57796,7 @@ function requiredText(value, field) {
|
|
|
57791
57796
|
function requestArray(value, maximum) {
|
|
57792
57797
|
if (!Array.isArray(value) || value.length < 1 || value.length > maximum) throw new HarnessError("requests must contain 1 through " + maximum + " items", "MINIMAX_MEDIA_BATCH_INVALID");
|
|
57793
57798
|
return value.map((item, index) => {
|
|
57794
|
-
const row = record$
|
|
57799
|
+
const row = record$4(item);
|
|
57795
57800
|
if (row === void 0) throw new HarnessError("requests[" + index + "] must be an object", "MINIMAX_MEDIA_ARGUMENT_INVALID");
|
|
57796
57801
|
return row;
|
|
57797
57802
|
});
|
|
@@ -98452,6 +98457,112 @@ function installTeamPolicyCacheGuard(ctx, options = {}) {
|
|
|
98452
98457
|
} };
|
|
98453
98458
|
}
|
|
98454
98459
|
//#endregion
|
|
98460
|
+
//#region src/host/providers/relayone/remote-compaction.ts
|
|
98461
|
+
/** Sessions whose current upstream cannot take remote compaction fall back to DSH. */
|
|
98462
|
+
const disabledSessions = /* @__PURE__ */ new Set();
|
|
98463
|
+
function relayOneRemoteCompactionEnabled(env = process.env) {
|
|
98464
|
+
const raw = (env.DSH_RELAYONE_REMOTE_COMPACTION ?? "").trim().toLowerCase();
|
|
98465
|
+
return ![
|
|
98466
|
+
"0",
|
|
98467
|
+
"false",
|
|
98468
|
+
"no",
|
|
98469
|
+
"off",
|
|
98470
|
+
"none"
|
|
98471
|
+
].includes(raw);
|
|
98472
|
+
}
|
|
98473
|
+
/** Keep the guard and adapter on the same model vocabulary. */
|
|
98474
|
+
function relayOneRemoteCompactionModel(model) {
|
|
98475
|
+
return /^(?:gpt-|o[134](?:-|$)|codex)/i.test(model);
|
|
98476
|
+
}
|
|
98477
|
+
function sessionKey$1(sessionId, model) {
|
|
98478
|
+
return sessionId.trim() + "\0" + model;
|
|
98479
|
+
}
|
|
98480
|
+
/** Whether ordinary pressure compaction should be left to the RelayOne native path. */
|
|
98481
|
+
function relayOneRemoteCompactionOwns(sessionId, model, env = process.env) {
|
|
98482
|
+
return sessionId !== void 0 && sessionId.trim() !== "" && relayOneRemoteCompactionEnabled(env) && relayOneRemoteCompactionModel(model) && !disabledSessions.has(sessionKey$1(sessionId, model));
|
|
98483
|
+
}
|
|
98484
|
+
/** A definite protocol failure re-enables DSH pressure compaction for this session. */
|
|
98485
|
+
function noteRelayOneRemoteCompactionResult(sessionId, model, supported) {
|
|
98486
|
+
if (sessionId === void 0 || sessionId.trim() === "") return;
|
|
98487
|
+
const key = sessionKey$1(sessionId, model);
|
|
98488
|
+
if (supported) disabledSessions.delete(key);
|
|
98489
|
+
else disabledSessions.add(key);
|
|
98490
|
+
}
|
|
98491
|
+
function shouldCompactRelayOnePayload(payload, contextWindow, sessionId, model, env = process.env) {
|
|
98492
|
+
if (!relayOneRemoteCompactionOwns(sessionId, model, env)) return false;
|
|
98493
|
+
const threshold = codexRemoteCompactionThreshold({ contextWindow });
|
|
98494
|
+
return threshold !== null && estimateCodexPayloadTokens(payload) >= threshold;
|
|
98495
|
+
}
|
|
98496
|
+
function withRelayOneCompactionTrigger(payload) {
|
|
98497
|
+
return withCodexCompactionTrigger(payload);
|
|
98498
|
+
}
|
|
98499
|
+
function projectFreshRelayOneCompaction(payload, checkpoint) {
|
|
98500
|
+
return projectFreshCodexCompaction(payload, checkpoint);
|
|
98501
|
+
}
|
|
98502
|
+
function relayOneCheckpointFromOutputItems(items, model, scope) {
|
|
98503
|
+
const checkpoint = checkpointFromOutputItems(items, model, null);
|
|
98504
|
+
return checkpoint === null ? null : {
|
|
98505
|
+
...checkpoint,
|
|
98506
|
+
scope
|
|
98507
|
+
};
|
|
98508
|
+
}
|
|
98509
|
+
/** Latest compatible checkpoint in the durable DSH transcript. */
|
|
98510
|
+
function latestRelayOneCompaction(messages, model, scope) {
|
|
98511
|
+
if (!relayOneRemoteCompactionEnabled()) return null;
|
|
98512
|
+
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
|
98513
|
+
const message = messages[index];
|
|
98514
|
+
if (message.role !== "assistant" || message.source?.kind !== "model") continue;
|
|
98515
|
+
const metadata = record$3(record$3(record$3(message.source.replayState)?.response)?.nativeCompaction);
|
|
98516
|
+
if (metadata?.scope !== scope) continue;
|
|
98517
|
+
const checkpoint = checkpointFromMetadata(metadata, model, null);
|
|
98518
|
+
if (checkpoint !== null) return {
|
|
98519
|
+
index,
|
|
98520
|
+
checkpoint: {
|
|
98521
|
+
...checkpoint,
|
|
98522
|
+
scope
|
|
98523
|
+
}
|
|
98524
|
+
};
|
|
98525
|
+
}
|
|
98526
|
+
return null;
|
|
98527
|
+
}
|
|
98528
|
+
function relayOneCompactionReplayMetadata(checkpoint) {
|
|
98529
|
+
return {
|
|
98530
|
+
model: checkpoint.model,
|
|
98531
|
+
scope: checkpoint.scope,
|
|
98532
|
+
item: structuredClone(checkpoint.item)
|
|
98533
|
+
};
|
|
98534
|
+
}
|
|
98535
|
+
/** Preserve the key scope that the Codex parser's own metadata does not know about. */
|
|
98536
|
+
function withRelayOneCompactionMetadata(chunk, checkpoint) {
|
|
98537
|
+
if (chunk.type !== "finish") return chunk;
|
|
98538
|
+
const replay = record$3(chunk.replayState);
|
|
98539
|
+
const response = record$3(replay?.response);
|
|
98540
|
+
return {
|
|
98541
|
+
...chunk,
|
|
98542
|
+
replayState: {
|
|
98543
|
+
...replay,
|
|
98544
|
+
response: {
|
|
98545
|
+
...response,
|
|
98546
|
+
nativeCompaction: relayOneCompactionReplayMetadata(checkpoint)
|
|
98547
|
+
}
|
|
98548
|
+
}
|
|
98549
|
+
};
|
|
98550
|
+
}
|
|
98551
|
+
/** Only a definite protocol refusal disables remote attempts; transport failures stay retryable. */
|
|
98552
|
+
function isDefiniteRelayOneCompactionFailure(error) {
|
|
98553
|
+
const value = record$3(error);
|
|
98554
|
+
const status = typeof value?.status === "number" ? value.status : typeof value?.relayOneStatus === "number" ? value.relayOneStatus : void 0;
|
|
98555
|
+
return value?.code === "PROTOCOL_ERROR" || status !== void 0 && [
|
|
98556
|
+
400,
|
|
98557
|
+
404,
|
|
98558
|
+
405,
|
|
98559
|
+
422
|
|
98560
|
+
].includes(status);
|
|
98561
|
+
}
|
|
98562
|
+
function record$3(value) {
|
|
98563
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
98564
|
+
}
|
|
98565
|
+
//#endregion
|
|
98455
98566
|
//#region src/host/runtime/guards/compaction-policy-guard.ts
|
|
98456
98567
|
/**
|
|
98457
98568
|
* 「压缩策略守卫」——把 `compaction-basic` 的预算换成 Kimi Code 的口径,
|
|
@@ -98758,7 +98869,12 @@ function installCompactionPolicyGuard(ctx, options = {}) {
|
|
|
98758
98869
|
const replacement = function(...args) {
|
|
98759
98870
|
observeFrom(args[0]);
|
|
98760
98871
|
observeFrom(args[1]);
|
|
98761
|
-
if (
|
|
98872
|
+
if (name === "compactPressure" || name === "compactIfNeeded" && args[1] !== "context-overflow") {
|
|
98873
|
+
const targetProvider = providerFrom(args[0]);
|
|
98874
|
+
if (codexRemoteCompactionEnabled() && targetProvider === "codex-chatgpt") return null;
|
|
98875
|
+
const relayTarget = targetProvider === "relayone" ? relayOneTargetFrom(args[0]) : void 0;
|
|
98876
|
+
if (relayTarget !== void 0 && relayOneRemoteCompactionOwns(relayTarget.sessionId, relayTarget.model)) return null;
|
|
98877
|
+
}
|
|
98762
98878
|
let nextArgs = args;
|
|
98763
98879
|
if (name === "summarize") {
|
|
98764
98880
|
const input = args[0];
|
|
@@ -98936,6 +99052,42 @@ function providerFrom(source) {
|
|
|
98936
99052
|
return;
|
|
98937
99053
|
}
|
|
98938
99054
|
}
|
|
99055
|
+
/** Read the session/model pair needed to release a failed RelayOne native route back to DSH. */
|
|
99056
|
+
function relayOneTargetFrom(source) {
|
|
99057
|
+
if (!isRecord$29(source)) return void 0;
|
|
99058
|
+
const session = isRecord$29(source["session"]) ? source["session"] : void 0;
|
|
99059
|
+
const sessionId = typeof session?.["id"] === "string" ? session["id"] : void 0;
|
|
99060
|
+
const direct = isRecord$29(source["config"]) ? source["config"] : void 0;
|
|
99061
|
+
if (typeof direct?.["model"] === "string") return {
|
|
99062
|
+
sessionId,
|
|
99063
|
+
model: direct["model"]
|
|
99064
|
+
};
|
|
99065
|
+
const options = isRecord$29(source["options"]) ? source["options"] : void 0;
|
|
99066
|
+
if (typeof options?.["model"] === "string") return {
|
|
99067
|
+
sessionId,
|
|
99068
|
+
model: options["model"]
|
|
99069
|
+
};
|
|
99070
|
+
const requestHeader = session?.["requestHeader"];
|
|
99071
|
+
if (typeof requestHeader === "function") try {
|
|
99072
|
+
const header = requestHeader.call(session);
|
|
99073
|
+
if (isRecord$29(header) && isRecord$29(header["config"]) && typeof header["config"]["model"] === "string") return {
|
|
99074
|
+
sessionId,
|
|
99075
|
+
model: header["config"]["model"]
|
|
99076
|
+
};
|
|
99077
|
+
} catch {
|
|
99078
|
+
return;
|
|
99079
|
+
}
|
|
99080
|
+
const model = isRecord$29(source["model"]) ? source["model"] : void 0;
|
|
99081
|
+
if (typeof model?.["current"] === "function") try {
|
|
99082
|
+
const current = model["current"].call(model);
|
|
99083
|
+
if (isRecord$29(current) && typeof current["model"] === "string") return {
|
|
99084
|
+
sessionId,
|
|
99085
|
+
model: current["model"]
|
|
99086
|
+
};
|
|
99087
|
+
} catch {
|
|
99088
|
+
return;
|
|
99089
|
+
}
|
|
99090
|
+
}
|
|
98939
99091
|
/** Read a service name from one reflect-store record. */
|
|
98940
99092
|
function readServiceName(record) {
|
|
98941
99093
|
if (typeof record.name === "string") return record.name;
|
|
@@ -118017,9 +118169,10 @@ function responseMessageContent(message, images, accepted) {
|
|
|
118017
118169
|
return parts;
|
|
118018
118170
|
}
|
|
118019
118171
|
/** Standard OpenAI Responses request; no Codex subscription-only headers or Lite items. */
|
|
118020
|
-
function buildRelayOneResponsesRequest(options, images, entry, settings) {
|
|
118172
|
+
function buildRelayOneResponsesRequest(options, images, entry, settings, compactionScope) {
|
|
118021
118173
|
const input = [];
|
|
118022
118174
|
const knownCalls = /* @__PURE__ */ new Set();
|
|
118175
|
+
const nativeCompaction = compactionScope === void 0 ? null : latestRelayOneCompaction(options.messages, options.model, compactionScope);
|
|
118023
118176
|
const { base, current, leadingEnd, developerInInstructions } = relayOneResponsesInstructions(options, entry);
|
|
118024
118177
|
if (base !== "") input.push({
|
|
118025
118178
|
type: "message",
|
|
@@ -118031,6 +118184,7 @@ function buildRelayOneResponsesRequest(options, images, entry, settings) {
|
|
|
118031
118184
|
});
|
|
118032
118185
|
for (let index = leadingEnd; index < options.messages.length; index += 1) {
|
|
118033
118186
|
const message = options.messages[index];
|
|
118187
|
+
if (nativeCompaction !== null && index < nativeCompaction.index && message.role !== "developer") continue;
|
|
118034
118188
|
if (message.role === "developer" && developerInInstructions) continue;
|
|
118035
118189
|
if (message.role === "system" || message.role === "developer") {
|
|
118036
118190
|
const text = relayOneInstructionText(message);
|
|
@@ -118062,7 +118216,7 @@ function buildRelayOneResponsesRequest(options, images, entry, settings) {
|
|
|
118062
118216
|
});
|
|
118063
118217
|
continue;
|
|
118064
118218
|
}
|
|
118065
|
-
const replay = message.role === "assistant" ? relayOneReplayOutputItems(message) : null;
|
|
118219
|
+
const replay = message.role === "assistant" ? relayOneReplayOutputItems(message)?.filter((item) => item.type !== "compaction" || nativeCompaction !== null && index === nativeCompaction.index) ?? null : null;
|
|
118066
118220
|
const content = responseMessageContent(message, images, entry.supportsImages);
|
|
118067
118221
|
const hasReplayText = replay?.some((item) => item.type === "message" && Array.isArray(item.content) && item.content.some((part) => {
|
|
118068
118222
|
if (!isRelayOneRecord(part)) return false;
|
|
@@ -118484,6 +118638,8 @@ var RelayOneAdapter = class extends LlmAdapter {
|
|
|
118484
118638
|
options;
|
|
118485
118639
|
fetchFn;
|
|
118486
118640
|
fallbacks = /* @__PURE__ */ new Map();
|
|
118641
|
+
/** Endpoint/model pairs that definitively refused remote compaction. */
|
|
118642
|
+
unsupportedRemoteCompaction = /* @__PURE__ */ new Set();
|
|
118487
118643
|
/** The pool, when this line runs several keys; null means the single-key path. */
|
|
118488
118644
|
pool;
|
|
118489
118645
|
/**
|
|
@@ -118584,18 +118740,18 @@ var RelayOneAdapter = class extends LlmAdapter {
|
|
|
118584
118740
|
async *streamWithEntry(rawOptions, entry) {
|
|
118585
118741
|
yield* wrapStreamWithWatchdog((signal, activity) => this.requestStream(rawOptions, entry, signal, activity), rawOptions.signal, STREAM_IDLE_TIMEOUT_MS$7, STREAM_IDLE_TIMEOUT_CODE$6, PROVIDER_NAME$4);
|
|
118586
118742
|
}
|
|
118587
|
-
buildRequest(protocol, options, images, entry, settings, sessionKey) {
|
|
118743
|
+
buildRequest(protocol, options, images, entry, settings, compactionScope, sessionKey) {
|
|
118588
118744
|
if (protocol === "anthropic") {
|
|
118589
118745
|
const body = buildRelayOneAnthropicRequest(options, images, entry, settings);
|
|
118590
118746
|
if (sessionKey !== void 0) body.metadata = { user_id: sessionKey };
|
|
118591
118747
|
return body;
|
|
118592
118748
|
}
|
|
118593
118749
|
const responses = protocol === "openai-responses";
|
|
118594
|
-
const body = responses ? buildRelayOneResponsesRequest(options, images, entry, settings) : buildRelayOneChatRequest(options, images, entry, settings);
|
|
118750
|
+
const body = responses ? buildRelayOneResponsesRequest(options, images, entry, settings, compactionScope) : buildRelayOneChatRequest(options, images, entry, settings);
|
|
118595
118751
|
if (sessionKey !== void 0 && (responses || isRelayOneOpenAIModel(entry.id, entry.vendor))) body.prompt_cache_key = sessionKey;
|
|
118596
118752
|
return body;
|
|
118597
118753
|
}
|
|
118598
|
-
async openRequest(protocol, body, apiKey, signal) {
|
|
118754
|
+
async openRequest(protocol, body, apiKey, signal, remoteCompaction = false) {
|
|
118599
118755
|
let response;
|
|
118600
118756
|
try {
|
|
118601
118757
|
response = await this.fetchFn(protocolUrl(protocol), {
|
|
@@ -118603,7 +118759,8 @@ var RelayOneAdapter = class extends LlmAdapter {
|
|
|
118603
118759
|
headers: {
|
|
118604
118760
|
...relayOneHeaders(apiKey),
|
|
118605
118761
|
accept: "text/event-stream",
|
|
118606
|
-
...protocol === "anthropic" ? { "anthropic-version": "2023-06-01" } : {}
|
|
118762
|
+
...protocol === "anthropic" ? { "anthropic-version": "2023-06-01" } : {},
|
|
118763
|
+
...remoteCompaction ? { "x-codex-beta-features": "remote_compaction_v2" } : {}
|
|
118607
118764
|
},
|
|
118608
118765
|
body: JSON.stringify(body),
|
|
118609
118766
|
signal
|
|
@@ -118655,6 +118812,26 @@ var RelayOneAdapter = class extends LlmAdapter {
|
|
|
118655
118812
|
}
|
|
118656
118813
|
if (status === 429) await this.pool.markCooldown(accountId, RELAYONE_COOLDOWN_MS, "RelayOne 429").catch(() => void 0);
|
|
118657
118814
|
}
|
|
118815
|
+
/** Run the side request without emitting its chunks into the user-visible turn. */
|
|
118816
|
+
async remoteCompact(body, model, scope, key, signal, activity) {
|
|
118817
|
+
const response = await this.openRequest("openai-responses", withRelayOneCompactionTrigger(body), key, signal, true);
|
|
118818
|
+
let checkpoint = null;
|
|
118819
|
+
try {
|
|
118820
|
+
for await (const chunk of parseResponsesStream(response, signal, void 0, activity)) {
|
|
118821
|
+
if (chunk.type !== "finish") continue;
|
|
118822
|
+
if (chunk.reason.kind === "error" || chunk.reason.kind === "aborted") {
|
|
118823
|
+
checkpoint = null;
|
|
118824
|
+
continue;
|
|
118825
|
+
}
|
|
118826
|
+
const items = chunk.replayState?.response?.outputItems;
|
|
118827
|
+
if (Array.isArray(items)) checkpoint = relayOneCheckpointFromOutputItems(items, model, scope);
|
|
118828
|
+
}
|
|
118829
|
+
if (checkpoint === null) throw new LlmError$1("RelayOne remote compaction did not return exactly one encrypted compaction item.", "PROTOCOL_ERROR");
|
|
118830
|
+
return checkpoint;
|
|
118831
|
+
} finally {
|
|
118832
|
+
await response.body?.cancel().catch(() => void 0);
|
|
118833
|
+
}
|
|
118834
|
+
}
|
|
118658
118835
|
async *requestStream(rawOptions, entry, signal, activity) {
|
|
118659
118836
|
const settings = await this.settingsStore.read();
|
|
118660
118837
|
const { apiKey: key, accountId } = await this.resolveKey();
|
|
@@ -118677,31 +118854,53 @@ var RelayOneAdapter = class extends LlmAdapter {
|
|
|
118677
118854
|
if (primary === null) throw new LlmError$1("RelayOne selected a media-only model for a chat request.", "NOT_FOUND");
|
|
118678
118855
|
const fallbackKey = scope + ":" + entry.id + ":" + primary;
|
|
118679
118856
|
let protocol = this.fallbacks.get(fallbackKey) ?? primary;
|
|
118680
|
-
|
|
118857
|
+
const remotePair = scope + ":" + entry.id;
|
|
118858
|
+
let nativeCompaction = protocol === "openai-responses" ? latestRelayOneCompaction(requestOptions.messages, entry.id, scope)?.checkpoint ?? null : null;
|
|
118859
|
+
if (protocol !== "openai-responses") {
|
|
118860
|
+
this.unsupportedRemoteCompaction.add(remotePair);
|
|
118861
|
+
noteRelayOneRemoteCompactionResult(sessionId, entry.id, false);
|
|
118862
|
+
}
|
|
118863
|
+
let body = this.buildRequest(protocol, requestOptions, images, entry, settings, scope, sessionKey);
|
|
118864
|
+
if (nativeCompaction === null && protocol === "openai-responses" && requestOptions.purpose === void 0 && !this.unsupportedRemoteCompaction.has(remotePair) && shouldCompactRelayOnePayload(body, settings.contextWindowOverrides[entry.id] ?? entry.contextWindow, sessionId, entry.id)) try {
|
|
118865
|
+
nativeCompaction = await this.remoteCompact(body, entry.id, scope, key, signal, activity);
|
|
118866
|
+
this.unsupportedRemoteCompaction.delete(remotePair);
|
|
118867
|
+
noteRelayOneRemoteCompactionResult(sessionId, entry.id, true);
|
|
118868
|
+
body = projectFreshRelayOneCompaction(body, nativeCompaction);
|
|
118869
|
+
} catch (error) {
|
|
118870
|
+
if (signal.aborted) throw error;
|
|
118871
|
+
if (isDefiniteRelayOneCompactionFailure(error)) {
|
|
118872
|
+
this.unsupportedRemoteCompaction.add(remotePair);
|
|
118873
|
+
noteRelayOneRemoteCompactionResult(sessionId, entry.id, false);
|
|
118874
|
+
}
|
|
118875
|
+
}
|
|
118681
118876
|
let response;
|
|
118682
118877
|
try {
|
|
118683
118878
|
response = await this.openRequest(protocol, body, key, signal);
|
|
118684
118879
|
} catch (error) {
|
|
118685
118880
|
const classified = error;
|
|
118686
118881
|
await this.noteAccountVerdict(accountId, classified);
|
|
118687
|
-
|
|
118688
|
-
|
|
118689
|
-
|
|
118690
|
-
|
|
118691
|
-
|
|
118692
|
-
|
|
118882
|
+
if (nativeCompaction !== null && isDefiniteRelayOneCompactionFailure(classified)) {
|
|
118883
|
+
this.unsupportedRemoteCompaction.add(remotePair);
|
|
118884
|
+
noteRelayOneRemoteCompactionResult(sessionId, entry.id, false);
|
|
118885
|
+
nativeCompaction = null;
|
|
118886
|
+
body = this.buildRequest(protocol, requestOptions, images, entry, settings, void 0, sessionKey);
|
|
118887
|
+
response = await this.openRequest(protocol, body, key, signal);
|
|
118888
|
+
} else {
|
|
118889
|
+
const fallback = fallbackRelayOneProtocol(entry, protocol);
|
|
118890
|
+
if (fallback === null || protocol !== primary || !isRelayOneProtocolUnsupported(classified.relayOneStatus ?? classified.status ?? 0, classified.relayOneDetail ?? "")) throw error;
|
|
118891
|
+
this.fallbacks.set(fallbackKey, fallback);
|
|
118892
|
+
protocol = fallback;
|
|
118893
|
+
nativeCompaction = null;
|
|
118894
|
+
this.unsupportedRemoteCompaction.add(remotePair);
|
|
118895
|
+
noteRelayOneRemoteCompactionResult(sessionId, entry.id, false);
|
|
118896
|
+
body = this.buildRequest(protocol, requestOptions, images, entry, settings, void 0, sessionKey);
|
|
118897
|
+
response = await this.openRequest(protocol, body, key, signal);
|
|
118898
|
+
}
|
|
118693
118899
|
}
|
|
118694
118900
|
if (accountId !== null && this.pool !== null) await this.pool.recordModel(accountId, entry.id).catch(() => void 0);
|
|
118695
118901
|
activity?.pulse();
|
|
118696
118902
|
if (protocol === "openai-responses") {
|
|
118697
|
-
|
|
118698
|
-
yield* parseResponsesStream(response, signal, void 0, activity);
|
|
118699
|
-
} catch (error) {
|
|
118700
|
-
if (error instanceof LlmError$1 && /Codex|ChatGPT/.test(error.message)) throw new LlmError$1(error.message.replace(/Codex|ChatGPT/g, "RelayOne"), error.code, { cause: error });
|
|
118701
|
-
throw error;
|
|
118702
|
-
} finally {
|
|
118703
|
-
await response.body?.cancel().catch(() => void 0);
|
|
118704
|
-
}
|
|
118903
|
+
yield* this.pumpResponses(response, nativeCompaction, signal, activity);
|
|
118705
118904
|
return;
|
|
118706
118905
|
}
|
|
118707
118906
|
if (response.body === null) throw new LlmError$1("RelayOne returned no response stream.", "PROVIDER_ERROR");
|
|
@@ -118739,6 +118938,16 @@ var RelayOneAdapter = class extends LlmAdapter {
|
|
|
118739
118938
|
await reader.cancel().catch(() => void 0);
|
|
118740
118939
|
}
|
|
118741
118940
|
}
|
|
118941
|
+
async *pumpResponses(response, checkpoint, signal, activity) {
|
|
118942
|
+
try {
|
|
118943
|
+
for await (const chunk of parseResponsesStream(response, signal, void 0, activity, checkpoint ?? void 0)) yield checkpoint === null ? chunk : withRelayOneCompactionMetadata(chunk, checkpoint);
|
|
118944
|
+
} catch (error) {
|
|
118945
|
+
if (error instanceof LlmError$1 && /Codex|ChatGPT/.test(error.message)) throw new LlmError$1(error.message.replace(/Codex|ChatGPT/g, "RelayOne"), error.code, { cause: error });
|
|
118946
|
+
throw error;
|
|
118947
|
+
} finally {
|
|
118948
|
+
await response.body?.cancel().catch(() => void 0);
|
|
118949
|
+
}
|
|
118950
|
+
}
|
|
118742
118951
|
};
|
|
118743
118952
|
//#endregion
|
|
118744
118953
|
//#region src/host/providers/relayone/client.ts
|