@jsonstudio/llms 0.6.2979 → 0.6.3238
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/dist/conversion/args-mapping.js +8 -0
- package/dist/conversion/{shared/bridge-actions.js → bridge-actions.js} +2 -1
- package/dist/conversion/{shared/bridge-id-utils.js → bridge-id-utils.js} +1 -1
- package/dist/conversion/{shared/bridge-instructions.js → bridge-instructions.js} +1 -1
- package/dist/conversion/{shared/bridge-message-utils.d.ts → bridge-message-utils.d.ts} +1 -1
- package/dist/conversion/{shared/bridge-message-utils.js → bridge-message-utils.js} +5 -149
- package/dist/conversion/{shared/bridge-metadata.js → bridge-metadata.js} +1 -1
- package/dist/conversion/{shared/bridge-policies.js → bridge-policies.js} +1 -1
- package/dist/conversion/codecs/gemini-openai-codec.js +27 -8
- package/dist/conversion/codecs/responses-openai-codec.js +1 -1
- package/dist/conversion/{shared/compaction-detect.d.ts → compaction-detect.d.ts} +1 -1
- package/dist/conversion/compaction-detect.js +4 -0
- package/dist/conversion/compat/actions/apply-patch-fixer.js +2 -2
- package/dist/conversion/compat/actions/deepseek-web-response.d.ts +0 -1
- package/dist/conversion/compat/actions/deepseek-web-response.js +15 -405
- package/dist/conversion/compat/actions/harvest-tool-calls-from-text.js +1 -1
- package/dist/conversion/compat/actions/lmstudio-responses-fc-ids.js +1 -1
- package/dist/conversion/compat/actions/qwen-transform.js +74 -2
- package/dist/conversion/compat/actions/snapshot.js +1 -1
- package/dist/conversion/compat/antigravity-session-signature.js +36 -0
- package/dist/conversion/compat/profiles/chat-deepseek-web.json +0 -22
- package/dist/conversion/compat/profiles/chat-glm.json +251 -72
- package/dist/conversion/compat/profiles/chat-iflow.json +174 -39
- package/dist/conversion/compat/profiles/chat-lmstudio.json +43 -14
- package/dist/conversion/hub/operation-table/operation-table-runner.js +2 -2
- package/dist/conversion/hub/operation-table/semantic-mappers/anthropic-mapper.js +1 -1
- package/dist/conversion/hub/operation-table/semantic-mappers/archive/chat-mapper.archive.d.ts +8 -0
- package/dist/conversion/hub/operation-table/semantic-mappers/archive/chat-mapper.archive.js +404 -0
- package/dist/conversion/hub/operation-table/semantic-mappers/chat-mapper.js +5 -381
- package/dist/conversion/hub/operation-table/semantic-mappers/gemini-mapper.js +2 -2
- package/dist/conversion/hub/operation-table/semantic-mappers/responses-mapper.js +2 -8
- package/dist/conversion/hub/pipeline/hub-pipeline.d.ts +1 -0
- package/dist/conversion/hub/pipeline/hub-pipeline.js +50 -3
- package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage2_semantic_map/index.d.ts +1 -1
- package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage2_semantic_map/index.js +62 -0
- package/dist/conversion/hub/pipeline/stages/req_process/req_process_stage2_route_select/index.js +3 -1
- package/dist/conversion/hub/pipeline/stages/resp_inbound/resp_inbound_stage1_sse_decode/index.js +1 -1
- package/dist/conversion/hub/pipeline/stages/resp_outbound/resp_outbound_stage1_client_remap/chat-process-semantics-bridge.d.ts +1 -1
- package/dist/conversion/hub/pipeline/stages/resp_process/resp_process_stage1_tool_governance/index.js +42 -29
- package/dist/conversion/hub/pipeline/stages/resp_process/resp_process_stage2_finalize/index.js +12 -0
- package/dist/conversion/hub/policy/protocol-spec.js +1 -1
- package/dist/conversion/hub/process/chat-process-clock-reminders.js +1 -1
- package/dist/conversion/hub/process/chat-process-clock-tools.js +1 -1
- package/dist/conversion/hub/process/chat-process-continue-execution.js +1 -1
- package/dist/conversion/hub/process/chat-process-servertool-orchestration.js +1 -1
- package/dist/conversion/hub/process/chat-process-web-search.js +1 -1
- package/dist/conversion/hub/response/provider-response.js +14 -5
- package/dist/conversion/hub/response/response-mappers.js +23 -1
- package/dist/conversion/hub/response/response-runtime.js +28 -5
- package/dist/conversion/hub/snapshot-recorder.js +3 -92
- package/dist/conversion/hub/tool-governance/engine.d.ts +8 -0
- package/dist/conversion/hub/tool-governance/engine.js +40 -193
- package/dist/conversion/hub/tool-governance/rules.js +73 -69
- package/dist/conversion/hub/tool-surface/tool-surface-engine.js +1 -1
- package/dist/conversion/index.d.ts +1 -2
- package/dist/conversion/index.js +1 -2
- package/dist/conversion/{shared/jsonish.js → jsonish.js} +1 -1
- package/dist/conversion/{shared/mcp-injection.js → mcp-injection.js} +1 -1
- package/dist/conversion/media.js +4 -0
- package/dist/conversion/{shared/metadata-passthrough.d.ts → metadata-passthrough.d.ts} +1 -1
- package/dist/conversion/{shared/metadata-passthrough.js → metadata-passthrough.js} +2 -2
- package/dist/conversion/payload-budget.js +47 -0
- package/dist/conversion/protocol-field-allowlists.d.ts +7 -0
- package/dist/conversion/protocol-field-allowlists.js +9 -0
- package/dist/conversion/{shared/protocol-state.d.ts → protocol-state.d.ts} +2 -2
- package/dist/conversion/{shared/protocol-state.js → protocol-state.js} +2 -2
- package/dist/conversion/{shared/errors.d.ts → provider-protocol-error.d.ts} +0 -3
- package/dist/conversion/provider-protocol-error.js +25 -0
- package/dist/conversion/responses/responses-openai-bridge/response-payload.js +8 -5
- package/dist/conversion/responses/responses-openai-bridge/types.d.ts +1 -1
- package/dist/conversion/responses/responses-openai-bridge.d.ts +1 -1
- package/dist/conversion/responses/responses-openai-bridge.js +43 -10
- package/dist/conversion/{shared/runtime-metadata.d.ts → runtime-metadata.d.ts} +1 -1
- package/dist/conversion/{shared/runtime-metadata.js → runtime-metadata.js} +2 -2
- package/dist/conversion/shared/anthropic-message-utils.js +19 -8
- package/dist/conversion/shared/chat-request-filters.d.ts +3 -4
- package/dist/conversion/shared/chat-request-filters.js +22 -78
- package/dist/conversion/shared/gemini-tool-utils.d.ts +1 -1
- package/dist/conversion/shared/openai-finalizer.js +1 -0
- package/dist/conversion/shared/openai-message-normalize.js +2 -2
- package/dist/conversion/shared/reasoning-normalizer.js +6 -0
- package/dist/conversion/shared/reasoning-utils.js +5 -2
- package/dist/conversion/shared/responses-conversation-store.js +1 -1
- package/dist/conversion/shared/responses-output-builder.js +55 -11
- package/dist/conversion/shared/responses-reasoning-registry.d.ts +14 -2
- package/dist/conversion/shared/responses-reasoning-registry.js +34 -6
- package/dist/conversion/shared/responses-response-utils.js +99 -9
- package/dist/conversion/shared/responses-tool-utils.js +1 -1
- package/dist/conversion/shared/text-markup-normalizer/normalize.d.ts +1 -1
- package/dist/conversion/shared/text-markup-normalizer.d.ts +2 -2
- package/dist/conversion/shared/text-markup-normalizer.js +1 -1
- package/dist/conversion/shared/tool-filter-pipeline.js +1 -1
- package/dist/conversion/shared/tool-governor.js +3 -3
- package/dist/conversion/shared/tool-mapping.d.ts +1 -1
- package/dist/conversion/{shared/snapshot-utils.d.ts → snapshot-utils.d.ts} +11 -0
- package/dist/conversion/{shared/snapshot-utils.js → snapshot-utils.js} +14 -23
- package/dist/conversion/types/text-markup-normalizer.d.ts +13 -0
- package/dist/conversion/types/text-markup-normalizer.js +1 -0
- package/dist/filters/special/request-tools-normalize.js +1 -1
- package/dist/filters/special/response-tool-text-canonicalize.js +2 -2
- package/dist/native/router_hotpath_napi.node +0 -0
- package/dist/quota/quota-manager.js +31 -59
- package/dist/quota/quota-state.js +14 -7
- package/dist/router/virtual-router/bootstrap/profile-builder.d.ts +1 -0
- package/dist/router/virtual-router/bootstrap/profile-builder.js +13 -0
- package/dist/router/virtual-router/bootstrap/provider-normalization.d.ts +2 -0
- package/dist/router/virtual-router/bootstrap/provider-normalization.js +4 -1
- package/dist/router/virtual-router/bootstrap/streaming-helpers.d.ts +7 -0
- package/dist/router/virtual-router/bootstrap/streaming-helpers.js +44 -0
- package/dist/router/virtual-router/bootstrap.js +2 -0
- package/dist/router/virtual-router/engine/routing-state/store.d.ts +1 -2
- package/dist/router/virtual-router/engine/routing-state/store.js +2 -2
- package/dist/router/virtual-router/engine-legacy/config.d.ts +11 -0
- package/dist/router/virtual-router/engine-legacy/config.js +108 -0
- package/dist/router/virtual-router/engine-legacy/direct-model.d.ts +10 -0
- package/dist/router/virtual-router/engine-legacy/direct-model.js +38 -0
- package/dist/router/virtual-router/engine-legacy/health.d.ts +13 -0
- package/dist/router/virtual-router/engine-legacy/health.js +104 -0
- package/dist/router/virtual-router/engine-legacy/helpers.d.ts +16 -0
- package/dist/router/virtual-router/engine-legacy/helpers.js +226 -0
- package/dist/router/virtual-router/engine-legacy/route-finalize.d.ts +9 -0
- package/dist/router/virtual-router/engine-legacy/route-finalize.js +84 -0
- package/dist/router/virtual-router/engine-legacy/route-selection.d.ts +17 -0
- package/dist/router/virtual-router/engine-legacy/route-selection.js +205 -0
- package/dist/router/virtual-router/engine-legacy/route-state-allowlist.d.ts +3 -0
- package/dist/router/virtual-router/engine-legacy/route-state-allowlist.js +36 -0
- package/dist/router/virtual-router/engine-legacy/route-state.d.ts +12 -0
- package/dist/router/virtual-router/engine-legacy/route-state.js +386 -0
- package/dist/router/virtual-router/engine-legacy/route-utils.d.ts +19 -0
- package/dist/router/virtual-router/engine-legacy/route-utils.js +212 -0
- package/dist/router/virtual-router/engine-legacy/routing.d.ts +8 -0
- package/dist/router/virtual-router/engine-legacy/routing.js +8 -0
- package/dist/router/virtual-router/engine-legacy/selection-core.d.ts +28 -0
- package/dist/router/virtual-router/engine-legacy/selection-core.js +112 -0
- package/dist/router/virtual-router/engine-legacy/selection-state.d.ts +16 -0
- package/dist/router/virtual-router/engine-legacy/selection-state.js +187 -0
- package/dist/router/virtual-router/engine-legacy/state-accessors.d.ts +21 -0
- package/dist/router/virtual-router/engine-legacy/state-accessors.js +118 -0
- package/dist/router/virtual-router/engine-legacy.d.ts +123 -0
- package/dist/router/virtual-router/engine-legacy.js +194 -0
- package/dist/router/virtual-router/engine-logging.d.ts +2 -0
- package/dist/router/virtual-router/engine-logging.js +7 -2
- package/dist/router/virtual-router/engine-selection/key-parsing.js +0 -3
- package/dist/router/virtual-router/engine-selection/native-chat-request-filter-semantics.d.ts +1 -0
- package/dist/router/virtual-router/engine-selection/native-chat-request-filter-semantics.js +54 -0
- package/dist/router/virtual-router/engine-selection/native-hub-bridge-policy-semantics.d.ts +10 -0
- package/dist/router/virtual-router/engine-selection/native-hub-bridge-policy-semantics.js +67 -0
- package/dist/router/virtual-router/engine-selection/native-hub-pipeline-governance-semantics.d.ts +30 -0
- package/dist/router/virtual-router/engine-selection/native-hub-pipeline-governance-semantics.js +202 -0
- package/dist/router/virtual-router/engine-selection/native-hub-pipeline-semantic-mappers.d.ts +2 -0
- package/dist/router/virtual-router/engine-selection/native-hub-pipeline-semantic-mappers.js +83 -0
- package/dist/router/virtual-router/engine-selection/native-router-hotpath-loader.js +43 -2
- package/dist/router/virtual-router/engine-selection/native-shared-conversion-semantics.d.ts +75 -0
- package/dist/router/virtual-router/engine-selection/native-shared-conversion-semantics.js +205 -0
- package/dist/router/virtual-router/engine-selection/native-snapshot-hooks.d.ts +3 -0
- package/dist/router/virtual-router/engine-selection/native-snapshot-hooks.js +109 -0
- package/dist/router/virtual-router/engine-selection/native-virtual-router-engine-proxy.d.ts +16 -0
- package/dist/router/virtual-router/engine-selection/native-virtual-router-engine-proxy.js +14 -0
- package/dist/router/virtual-router/engine-selection/native-virtual-router-routing-instructions-semantics.d.ts +2 -0
- package/dist/router/virtual-router/engine-selection/native-virtual-router-routing-instructions-semantics.js +86 -0
- package/dist/router/virtual-router/engine-selection/tier-selection-quota-integration.js +100 -0
- package/dist/router/virtual-router/engine-selection/tier-selection-select.js +99 -0
- package/dist/router/virtual-router/engine.d.ts +22 -105
- package/dist/router/virtual-router/engine.js +274 -1641
- package/dist/router/virtual-router/load-balancer.d.ts +8 -0
- package/dist/router/virtual-router/load-balancer.js +65 -2
- package/dist/router/virtual-router/provider-registry.js +2 -0
- package/dist/router/virtual-router/routing-instructions/clean.d.ts +3 -0
- package/dist/router/virtual-router/routing-instructions/clean.js +34 -0
- package/dist/router/virtual-router/routing-instructions/parse.d.ts +18 -0
- package/dist/router/virtual-router/routing-instructions/parse.js +377 -0
- package/dist/router/virtual-router/routing-instructions/state.d.ts +4 -0
- package/dist/router/virtual-router/routing-instructions/state.js +245 -0
- package/dist/router/virtual-router/routing-instructions/types.d.ts +70 -0
- package/dist/router/virtual-router/routing-instructions/types.js +2 -0
- package/dist/router/virtual-router/routing-instructions.d.ts +5 -89
- package/dist/router/virtual-router/routing-instructions.js +4 -655
- package/dist/router/virtual-router/sticky-session-store.d.ts +4 -0
- package/dist/router/virtual-router/sticky-session-store.js +19 -81
- package/dist/router/virtual-router/tool-signals.js +21 -3
- package/dist/router/virtual-router/types.d.ts +4 -0
- package/dist/servertool/clock/session-scope.js +32 -1
- package/dist/servertool/engine.js +79 -8
- package/dist/servertool/handlers/antigravity-thought-signature-bootstrap.js +1 -1
- package/dist/servertool/handlers/clock-auto.js +1 -1
- package/dist/servertool/handlers/clock.js +1 -1
- package/dist/servertool/handlers/compaction-detect.d.ts +1 -1
- package/dist/servertool/handlers/compaction-detect.js +1 -1
- package/dist/servertool/handlers/gemini-empty-reply-continue.js +1 -1
- package/dist/servertool/handlers/iflow-model-error-retry.js +1 -1
- package/dist/servertool/handlers/recursive-detection-guard.js +1 -1
- package/dist/servertool/handlers/review.js +1 -1
- package/dist/servertool/handlers/stop-message-auto/iflow-followup.js +1 -1
- package/dist/servertool/handlers/stop-message-auto/runtime-utils.js +1 -1
- package/dist/servertool/handlers/stop-message-auto.js +1 -1
- package/dist/servertool/handlers/vision.js +1 -1
- package/dist/servertool/handlers/web-search.js +1 -1
- package/dist/servertool/reenter-backend.js +1 -1
- package/dist/servertool/server-side-tools.js +2 -2
- package/dist/servertool/stop-gateway-context.js +1 -1
- package/dist/servertool/stop-message-compare-context.js +1 -1
- package/dist/sse/json-to-sse/event-generators/responses.d.ts +4 -0
- package/dist/sse/json-to-sse/event-generators/responses.js +95 -1
- package/dist/sse/json-to-sse/sequencers/responses-sequencer.js +6 -4
- package/dist/sse/sse-to-json/builders/response-builder.d.ts +8 -0
- package/dist/sse/sse-to-json/builders/response-builder.js +162 -4
- package/dist/sse/sse-to-json/responses-sse-to-json-converter.js +2 -0
- package/dist/sse/types/responses-types.d.ts +6 -2
- package/dist/tools/apply-patch/structured/coercion.js +5 -0
- package/dist/tools/args-json.js +29 -0
- package/package.json +8 -5
- package/dist/conversion/shared/args-mapping.js +0 -77
- package/dist/conversion/shared/compaction-detect.js +0 -4
- package/dist/conversion/shared/errors.js +0 -31
- package/dist/conversion/shared/media.js +0 -4
- package/dist/conversion/shared/payload-budget.js +0 -165
- package/dist/conversion/shared/protocol-field-allowlists.d.ts +0 -7
- package/dist/conversion/shared/protocol-field-allowlists.js +0 -149
- package/dist/conversion/shared/snapshot-hooks.d.ts +0 -11
- package/dist/conversion/shared/snapshot-hooks.js +0 -503
- package/dist/conversion/shared/text-markup-normalizer/extractors-apply-patch.d.ts +0 -2
- package/dist/conversion/shared/text-markup-normalizer/extractors-apply-patch.js +0 -129
- package/dist/conversion/shared/text-markup-normalizer/extractors-json.d.ts +0 -4
- package/dist/conversion/shared/text-markup-normalizer/extractors-json.js +0 -637
- package/dist/conversion/shared/text-markup-normalizer/extractors-shared.d.ts +0 -21
- package/dist/conversion/shared/text-markup-normalizer/extractors-shared.js +0 -177
- package/dist/conversion/shared/text-markup-normalizer/extractors-transcript.d.ts +0 -5
- package/dist/conversion/shared/text-markup-normalizer/extractors-transcript.js +0 -385
- package/dist/conversion/shared/text-markup-normalizer/extractors-xml.d.ts +0 -10
- package/dist/conversion/shared/text-markup-normalizer/extractors-xml.js +0 -602
- package/dist/conversion/shared/text-markup-normalizer/extractors.d.ts +0 -5
- package/dist/conversion/shared/text-markup-normalizer/extractors.js +0 -4
- package/dist/conversion/shared/tool-canonicalizer.d.ts +0 -2
- package/dist/conversion/shared/tool-canonicalizer.js +0 -38
- /package/dist/conversion/{shared/args-mapping.d.ts → args-mapping.d.ts} +0 -0
- /package/dist/conversion/{shared/bridge-actions.d.ts → bridge-actions.d.ts} +0 -0
- /package/dist/conversion/{shared/bridge-id-utils.d.ts → bridge-id-utils.d.ts} +0 -0
- /package/dist/conversion/{shared/bridge-instructions.d.ts → bridge-instructions.d.ts} +0 -0
- /package/dist/conversion/{shared/bridge-metadata.d.ts → bridge-metadata.d.ts} +0 -0
- /package/dist/conversion/{shared/bridge-policies.d.ts → bridge-policies.d.ts} +0 -0
- /package/dist/conversion/{shared/jsonish.d.ts → jsonish.d.ts} +0 -0
- /package/dist/conversion/{shared/mcp-injection.d.ts → mcp-injection.d.ts} +0 -0
- /package/dist/conversion/{shared/media.d.ts → media.d.ts} +0 -0
- /package/dist/conversion/{shared/payload-budget.d.ts → payload-budget.d.ts} +0 -0
- /package/dist/conversion/{shared → types}/bridge-message-types.d.ts +0 -0
- /package/dist/conversion/{shared → types}/bridge-message-types.js +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { extractOutputSegments } from './output-content-normalizer.js';
|
|
2
|
-
import { createBridgeActionState, runBridgeActionPipeline } from '
|
|
3
|
-
import { resolveBridgePolicy, resolvePolicyActions } from '
|
|
2
|
+
import { createBridgeActionState, runBridgeActionPipeline } from '../bridge-actions.js';
|
|
3
|
+
import { resolveBridgePolicy, resolvePolicyActions } from '../bridge-policies.js';
|
|
4
4
|
import { registerResponsesPayloadSnapshot, registerResponsesPassthrough } from './responses-reasoning-registry.js';
|
|
5
5
|
import { normalizeFunctionCallIdWithNative, sanitizeReasoningTaggedTextWithNative } from '../../router/virtual-router/engine-selection/native-shared-conversion-semantics.js';
|
|
6
6
|
import { sanitizeResponsesFunctionNameWithNative } from '../../router/virtual-router/engine-selection/native-hub-pipeline-resp-semantics.js';
|
|
@@ -153,6 +153,60 @@ function collectRawReasoningSegments(response) {
|
|
|
153
153
|
}
|
|
154
154
|
return segments;
|
|
155
155
|
}
|
|
156
|
+
function collectReasoningSummarySegments(response) {
|
|
157
|
+
const segments = [];
|
|
158
|
+
const outputItems = Array.isArray(response.output) ? response.output : [];
|
|
159
|
+
for (const item of outputItems) {
|
|
160
|
+
if (!item || typeof item !== 'object')
|
|
161
|
+
continue;
|
|
162
|
+
const type = typeof item.type === 'string' ? String(item.type).toLowerCase() : '';
|
|
163
|
+
if (type !== 'reasoning')
|
|
164
|
+
continue;
|
|
165
|
+
const summary = Array.isArray(item.summary) ? item.summary : [];
|
|
166
|
+
for (const entry of summary) {
|
|
167
|
+
if (typeof entry === 'string') {
|
|
168
|
+
segments.push(entry);
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
if (entry && typeof entry === 'object' && typeof entry.text === 'string') {
|
|
172
|
+
segments.push(entry.text);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return segments;
|
|
177
|
+
}
|
|
178
|
+
function collectReasoningEncryptedContent(response) {
|
|
179
|
+
const outputItems = Array.isArray(response.output) ? response.output : [];
|
|
180
|
+
for (const item of outputItems) {
|
|
181
|
+
if (!item || typeof item !== 'object')
|
|
182
|
+
continue;
|
|
183
|
+
const type = typeof item.type === 'string' ? String(item.type).toLowerCase() : '';
|
|
184
|
+
if (type !== 'reasoning')
|
|
185
|
+
continue;
|
|
186
|
+
const encrypted = item.encrypted_content;
|
|
187
|
+
if (typeof encrypted === 'string' && encrypted.trim().length) {
|
|
188
|
+
return encrypted;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return undefined;
|
|
192
|
+
}
|
|
193
|
+
function buildReasoningPayload(options) {
|
|
194
|
+
const { summarySegments, contentSegments, encryptedContent } = options;
|
|
195
|
+
const summary = summarySegments.length
|
|
196
|
+
? summarySegments.map((text) => ({ type: 'summary_text', text }))
|
|
197
|
+
: undefined;
|
|
198
|
+
const content = contentSegments.length
|
|
199
|
+
? contentSegments.map((text) => ({ type: 'reasoning_text', text }))
|
|
200
|
+
: undefined;
|
|
201
|
+
if (!summary && !content && encryptedContent === undefined) {
|
|
202
|
+
return undefined;
|
|
203
|
+
}
|
|
204
|
+
return {
|
|
205
|
+
summary,
|
|
206
|
+
content,
|
|
207
|
+
encrypted_content: encryptedContent
|
|
208
|
+
};
|
|
209
|
+
}
|
|
156
210
|
function registerPassthroughSnapshot(payload) {
|
|
157
211
|
const ids = new Set();
|
|
158
212
|
const requestId = typeof payload?.request_id === 'string' ? payload.request_id.trim() : '';
|
|
@@ -165,6 +219,23 @@ function registerPassthroughSnapshot(payload) {
|
|
|
165
219
|
registerResponsesPassthrough(candidate, payload);
|
|
166
220
|
}
|
|
167
221
|
}
|
|
222
|
+
function cloneSnapshot(value) {
|
|
223
|
+
try {
|
|
224
|
+
const structuredCloneImpl = globalThis.structuredClone;
|
|
225
|
+
if (typeof structuredCloneImpl === 'function') {
|
|
226
|
+
return structuredCloneImpl(value);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
catch {
|
|
230
|
+
/* ignore structuredClone failures */
|
|
231
|
+
}
|
|
232
|
+
try {
|
|
233
|
+
return JSON.parse(JSON.stringify(value));
|
|
234
|
+
}
|
|
235
|
+
catch {
|
|
236
|
+
return { ...value };
|
|
237
|
+
}
|
|
238
|
+
}
|
|
168
239
|
export function buildChatResponseFromResponses(payload) {
|
|
169
240
|
if (!payload || typeof payload !== 'object')
|
|
170
241
|
return payload;
|
|
@@ -185,8 +256,13 @@ export function buildChatResponseFromResponses(payload) {
|
|
|
185
256
|
const toolCalls = collectToolCallsFromResponses(response);
|
|
186
257
|
const { textParts, reasoningParts } = extractOutputSegments(response);
|
|
187
258
|
const rawReasoningSegments = collectRawReasoningSegments(response);
|
|
188
|
-
const
|
|
189
|
-
|
|
259
|
+
const summaryReasoningSegments = collectReasoningSummarySegments(response);
|
|
260
|
+
const encryptedReasoning = collectReasoningEncryptedContent(response);
|
|
261
|
+
const outputTextRaw = typeof response.output_text === 'string' && response.output_text.trim().length
|
|
262
|
+
? response.output_text
|
|
263
|
+
: undefined;
|
|
264
|
+
const explicitOutput = typeof outputTextRaw === 'string'
|
|
265
|
+
? sanitizeReasoningTaggedTextWithNative(outputTextRaw)
|
|
190
266
|
: undefined;
|
|
191
267
|
const messageContentText = explicitOutput || textParts.join('\n').trim();
|
|
192
268
|
const messageContent = messageContentText || '';
|
|
@@ -218,7 +294,9 @@ export function buildChatResponseFromResponses(payload) {
|
|
|
218
294
|
if (toolCalls.length) {
|
|
219
295
|
message.tool_calls = toolCalls;
|
|
220
296
|
}
|
|
221
|
-
const reasoningSegments = rawReasoningSegments.length
|
|
297
|
+
const reasoningSegments = rawReasoningSegments.length
|
|
298
|
+
? rawReasoningSegments
|
|
299
|
+
: (reasoningParts.length ? reasoningParts : summaryReasoningSegments);
|
|
222
300
|
if (reasoningSegments.length) {
|
|
223
301
|
message.reasoning_content = reasoningSegments.join('\n');
|
|
224
302
|
}
|
|
@@ -237,13 +315,18 @@ export function buildChatResponseFromResponses(payload) {
|
|
|
237
315
|
]
|
|
238
316
|
};
|
|
239
317
|
const hasOutputTextField = Object.prototype.hasOwnProperty.call(response, 'output_text');
|
|
240
|
-
|
|
241
|
-
|
|
318
|
+
const reasoningPayload = buildReasoningPayload({
|
|
319
|
+
summarySegments: summaryReasoningSegments,
|
|
320
|
+
contentSegments: rawReasoningSegments.length ? rawReasoningSegments : reasoningParts,
|
|
321
|
+
encryptedContent: encryptedReasoning
|
|
322
|
+
});
|
|
323
|
+
if (reasoningPayload) {
|
|
324
|
+
chat.__responses_reasoning = reasoningPayload;
|
|
242
325
|
}
|
|
243
326
|
chat.__responses_output_text_meta = {
|
|
244
327
|
hasField: hasOutputTextField,
|
|
245
|
-
value:
|
|
246
|
-
? sanitizeReasoningTaggedTextWithNative(
|
|
328
|
+
value: typeof outputTextRaw === 'string'
|
|
329
|
+
? sanitizeReasoningTaggedTextWithNative(outputTextRaw)
|
|
247
330
|
: undefined
|
|
248
331
|
};
|
|
249
332
|
if (usage !== undefined) {
|
|
@@ -256,5 +339,12 @@ export function buildChatResponseFromResponses(payload) {
|
|
|
256
339
|
chat.request_id = requestId;
|
|
257
340
|
}
|
|
258
341
|
registerResponsesPayloadSnapshot(id, response);
|
|
342
|
+
if (requestId && requestId !== id) {
|
|
343
|
+
registerResponsesPayloadSnapshot(requestId, response);
|
|
344
|
+
}
|
|
345
|
+
const snapshot = cloneSnapshot(response);
|
|
346
|
+
if (snapshot) {
|
|
347
|
+
chat.__responses_payload_snapshot = snapshot;
|
|
348
|
+
}
|
|
259
349
|
return chat;
|
|
260
350
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { normalizeFunctionCallId, normalizeFunctionCallOutputId, normalizeResponsesCallId } from '
|
|
1
|
+
import { normalizeFunctionCallId, normalizeFunctionCallOutputId, normalizeResponsesCallId } from '../bridge-id-utils.js';
|
|
2
2
|
import { sanitizeResponsesFunctionNameWithNative } from '../../router/virtual-router/engine-selection/native-hub-pipeline-resp-semantics.js';
|
|
3
3
|
export function createToolCallIdTransformer(style) {
|
|
4
4
|
if (style !== 'fc') {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { TextMarkupNormalizeOptions } from '
|
|
1
|
+
import type { TextMarkupNormalizeOptions } from '../../types/text-markup-normalizer.js';
|
|
2
2
|
export declare function normalizeAssistantTextToToolCalls(message: Record<string, any>, _options?: TextMarkupNormalizeOptions): Record<string, any>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { JsonToolRepairConfig, TextMarkupNormalizeOptions, ToolCallLite } from '
|
|
2
|
-
export { extractApplyPatchCallsFromText, extractBareExecCommandFromText, extractExecuteBlocksFromText, extractExploredListDirectoryCallsFromText, extractInvokeToolsFromText, extractJsonToolCallsFromText, extractParameterXmlToolsFromText, extractQwenToolCallTokensFromText, extractSimpleXmlToolsFromText, extractToolNamespaceXmlBlocksFromText, extractXMLToolCallsFromText } from '
|
|
1
|
+
export type { JsonToolRepairConfig, TextMarkupNormalizeOptions, ToolCallLite } from '../types/text-markup-normalizer.js';
|
|
2
|
+
export { extractApplyPatchCallsFromTextWithNative as extractApplyPatchCallsFromText, extractBareExecCommandFromTextWithNative as extractBareExecCommandFromText, extractExecuteBlocksFromTextWithNative as extractExecuteBlocksFromText, extractExploredListDirectoryCallsFromTextWithNative as extractExploredListDirectoryCallsFromText, extractInvokeToolsFromTextWithNative as extractInvokeToolsFromText, extractJsonToolCallsFromTextWithNative as extractJsonToolCallsFromText, extractParameterXmlToolsFromTextWithNative as extractParameterXmlToolsFromText, extractQwenToolCallTokensFromTextWithNative as extractQwenToolCallTokensFromText, extractSimpleXmlToolsFromTextWithNative as extractSimpleXmlToolsFromText, extractToolNamespaceXmlBlocksFromTextWithNative as extractToolNamespaceXmlBlocksFromText, extractXMLToolCallsFromTextWithNative as extractXMLToolCallsFromText } from '../../router/virtual-router/engine-selection/native-shared-conversion-semantics.js';
|
|
3
3
|
export { normalizeAssistantTextToToolCalls } from './text-markup-normalizer/normalize.js';
|
|
4
4
|
export { extractToolCallsFromReasoningTextWithNative, parseLenientJsonishWithNative, repairArgumentsToStringWithNative } from '../../router/virtual-router/engine-selection/native-shared-conversion-semantics.js';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { extractApplyPatchCallsFromText, extractBareExecCommandFromText, extractExecuteBlocksFromText, extractExploredListDirectoryCallsFromText, extractInvokeToolsFromText, extractJsonToolCallsFromText, extractParameterXmlToolsFromText, extractQwenToolCallTokensFromText, extractSimpleXmlToolsFromText, extractToolNamespaceXmlBlocksFromText, extractXMLToolCallsFromText } from '
|
|
1
|
+
export { extractApplyPatchCallsFromTextWithNative as extractApplyPatchCallsFromText, extractBareExecCommandFromTextWithNative as extractBareExecCommandFromText, extractExecuteBlocksFromTextWithNative as extractExecuteBlocksFromText, extractExploredListDirectoryCallsFromTextWithNative as extractExploredListDirectoryCallsFromText, extractInvokeToolsFromTextWithNative as extractInvokeToolsFromText, extractJsonToolCallsFromTextWithNative as extractJsonToolCallsFromText, extractParameterXmlToolsFromTextWithNative as extractParameterXmlToolsFromText, extractQwenToolCallTokensFromTextWithNative as extractQwenToolCallTokensFromText, extractSimpleXmlToolsFromTextWithNative as extractSimpleXmlToolsFromText, extractToolNamespaceXmlBlocksFromTextWithNative as extractToolNamespaceXmlBlocksFromText, extractXMLToolCallsFromTextWithNative as extractXMLToolCallsFromText } from '../../router/virtual-router/engine-selection/native-shared-conversion-semantics.js';
|
|
2
2
|
export { normalizeAssistantTextToToolCalls } from './text-markup-normalizer/normalize.js';
|
|
3
3
|
export { extractToolCallsFromReasoningTextWithNative, parseLenientJsonishWithNative, repairArgumentsToStringWithNative } from '../../router/virtual-router/engine-selection/native-shared-conversion-semantics.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FilterEngine } from '../../filters/index.js';
|
|
2
2
|
import { loadFieldMapConfig } from '../../filters/utils/fieldmap-loader.js';
|
|
3
|
-
import { createSnapshotWriter } from '
|
|
3
|
+
import { createSnapshotWriter } from '../snapshot-utils.js';
|
|
4
4
|
import { normalizeChatResponseReasoningToolsWithNative as normalizeChatResponseReasoningTools } from '../../router/virtual-router/engine-selection/native-hub-bridge-action-semantics.js';
|
|
5
5
|
const REQUEST_FILTER_STAGES = [
|
|
6
6
|
'request_pre',
|
|
@@ -6,7 +6,8 @@ import { augmentOpenAITools } from '../../guidance/index.js';
|
|
|
6
6
|
import { validateToolCall } from '../../tools/tool-registry.js';
|
|
7
7
|
import { captureApplyPatchRegression } from '../../tools/patch-regression-capturer.js';
|
|
8
8
|
import { normalizeExecCommandArgs } from '../../tools/exec-command/normalize.js';
|
|
9
|
-
import { readRuntimeMetadata } from '
|
|
9
|
+
import { readRuntimeMetadata } from '../runtime-metadata.js';
|
|
10
|
+
import { normalizeChatResponseReasoningToolsWithNative } from '../../router/virtual-router/engine-selection/native-hub-bridge-action-semantics.js';
|
|
10
11
|
function isObject(v) { return !!v && typeof v === 'object' && !Array.isArray(v); }
|
|
11
12
|
// Note: tool schema strict augmentation removed per alignment
|
|
12
13
|
function enforceChatBudget(chat, _modelId) { return chat; }
|
|
@@ -639,8 +640,7 @@ export function processChatResponseTools(resp) {
|
|
|
639
640
|
if (!isObject(resp))
|
|
640
641
|
return resp;
|
|
641
642
|
try {
|
|
642
|
-
const
|
|
643
|
-
const canon = canonicalizeChatResponseTools(resp);
|
|
643
|
+
const canon = normalizeChatResponseReasoningToolsWithNative(resp);
|
|
644
644
|
const withPatch = normalizeApplyPatchToolCallsOnResponse(canon);
|
|
645
645
|
return enhanceResponseToolArguments(withPatch);
|
|
646
646
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ChatToolDefinition } from '../hub/types/chat-envelope.js';
|
|
2
|
-
import type { BridgeToolDefinition } from '
|
|
2
|
+
import type { BridgeToolDefinition } from '../types/bridge-message-types.js';
|
|
3
3
|
export interface ToolCallFunction {
|
|
4
4
|
name: string;
|
|
5
5
|
arguments: string;
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
export interface SnapshotHookOptions {
|
|
2
|
+
endpoint: string;
|
|
3
|
+
stage: string;
|
|
4
|
+
requestId: string;
|
|
5
|
+
data: unknown;
|
|
6
|
+
verbosity?: 'minimal' | 'verbose';
|
|
7
|
+
channel?: string;
|
|
8
|
+
providerKey?: string;
|
|
9
|
+
groupRequestId?: string;
|
|
10
|
+
}
|
|
1
11
|
interface SnapshotPayload {
|
|
2
12
|
stage: string;
|
|
3
13
|
requestId: string;
|
|
@@ -8,6 +18,7 @@ interface SnapshotPayload {
|
|
|
8
18
|
groupRequestId?: string;
|
|
9
19
|
}
|
|
10
20
|
export declare function shouldRecordSnapshots(): boolean;
|
|
21
|
+
export declare function writeSnapshotViaHooks(options: SnapshotHookOptions): Promise<void>;
|
|
11
22
|
export declare function recordSnapshot(options: SnapshotPayload): Promise<void>;
|
|
12
23
|
export type SnapshotWriter = (stage: string, payload: unknown) => void;
|
|
13
24
|
export declare function createSnapshotWriter(opts: {
|
|
@@ -1,27 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
function resolveBoolFromEnv(value, fallback) {
|
|
3
|
-
if (!value) {
|
|
4
|
-
return fallback;
|
|
5
|
-
}
|
|
6
|
-
const normalized = value.trim().toLowerCase();
|
|
7
|
-
if (['1', 'true', 'yes', 'on'].includes(normalized)) {
|
|
8
|
-
return true;
|
|
9
|
-
}
|
|
10
|
-
if (['0', 'false', 'no', 'off'].includes(normalized)) {
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
return fallback;
|
|
14
|
-
}
|
|
1
|
+
import { shouldRecordSnapshotsWithNative, writeSnapshotViaHooksWithNative } from '../router/virtual-router/engine-selection/native-snapshot-hooks.js';
|
|
15
2
|
export function shouldRecordSnapshots() {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
3
|
+
return shouldRecordSnapshotsWithNative();
|
|
4
|
+
}
|
|
5
|
+
export async function writeSnapshotViaHooks(options) {
|
|
6
|
+
writeSnapshotViaHooksWithNative({
|
|
7
|
+
endpoint: options.endpoint,
|
|
8
|
+
stage: options.stage,
|
|
9
|
+
requestId: options.requestId,
|
|
10
|
+
data: options.data,
|
|
11
|
+
verbosity: options.verbosity,
|
|
12
|
+
channel: options.channel,
|
|
13
|
+
providerKey: options.providerKey,
|
|
14
|
+
groupRequestId: options.groupRequestId
|
|
15
|
+
});
|
|
25
16
|
}
|
|
26
17
|
export async function recordSnapshot(options) {
|
|
27
18
|
if (!shouldRecordSnapshots())
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type JsonToolArgumentAliasMap = Record<string, string[]>;
|
|
2
|
+
export type JsonToolRepairConfig = {
|
|
3
|
+
toolNameAliases?: Record<string, string>;
|
|
4
|
+
argumentAliases?: Record<string, JsonToolArgumentAliasMap>;
|
|
5
|
+
};
|
|
6
|
+
export type TextMarkupNormalizeOptions = {
|
|
7
|
+
jsonToolRepair?: JsonToolRepairConfig;
|
|
8
|
+
};
|
|
9
|
+
export type ToolCallLite = {
|
|
10
|
+
id?: string;
|
|
11
|
+
name: string;
|
|
12
|
+
args: string;
|
|
13
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -26,7 +26,7 @@ export class RequestOpenAIToolsNormalizeFilter {
|
|
|
26
26
|
}
|
|
27
27
|
let normalizedList = [];
|
|
28
28
|
try {
|
|
29
|
-
const mod = await import('../../conversion/
|
|
29
|
+
const mod = await import('../../conversion/args-mapping.js');
|
|
30
30
|
const normalizeTools = mod?.normalizeTools;
|
|
31
31
|
if (typeof normalizeTools === 'function')
|
|
32
32
|
normalizedList = normalizeTools(tools);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { normalizeChatResponseReasoningToolsWithNative } from '../../router/virtual-router/engine-selection/native-hub-bridge-action-semantics.js';
|
|
2
2
|
/**
|
|
3
3
|
* Canonicalize structured tool_calls (Chat path).
|
|
4
4
|
*
|
|
@@ -10,7 +10,7 @@ export class ResponseToolTextCanonicalizeFilter {
|
|
|
10
10
|
name = 'response_tool_text_canonicalize';
|
|
11
11
|
stage = 'response_pre';
|
|
12
12
|
apply(input) {
|
|
13
|
-
const out =
|
|
13
|
+
const out = normalizeChatResponseReasoningToolsWithNative(input);
|
|
14
14
|
return { ok: true, data: out };
|
|
15
15
|
}
|
|
16
16
|
}
|
|
Binary file
|
|
@@ -115,16 +115,6 @@ function collectUpstreamErrorSources(ev) {
|
|
|
115
115
|
function isAntigravityProviderKey(providerKey) {
|
|
116
116
|
return providerKey.toLowerCase().startsWith('antigravity.');
|
|
117
117
|
}
|
|
118
|
-
function resolveAntigravityRuntimeKey(providerKey, ev) {
|
|
119
|
-
const rtKey = safeTrim(ev?.runtime?.target?.runtimeKey);
|
|
120
|
-
if (rtKey)
|
|
121
|
-
return rtKey;
|
|
122
|
-
const parts = providerKey.split('.').filter(Boolean);
|
|
123
|
-
if (parts.length >= 2) {
|
|
124
|
-
return `${parts[0]}.${parts[1]}`;
|
|
125
|
-
}
|
|
126
|
-
return null;
|
|
127
|
-
}
|
|
128
118
|
function isGoogleAccountVerificationRequired(ev, sources) {
|
|
129
119
|
if (!sources.length) {
|
|
130
120
|
sources = collectUpstreamErrorSources(ev);
|
|
@@ -277,64 +267,46 @@ export class QuotaManager {
|
|
|
277
267
|
const code = safeTrim(ev.code) || safeTrim(ev?.runtime?.errorCode);
|
|
278
268
|
const details = ev.details && typeof ev.details === 'object' ? ev.details : undefined;
|
|
279
269
|
const state = this.ensureProvider(providerKey);
|
|
280
|
-
// Antigravity account-scope auth verification required:
|
|
270
|
+
// Antigravity account-scope auth verification required: isolate to current providerKey only.
|
|
281
271
|
if (isAntigravityProviderKey(providerKey)) {
|
|
282
272
|
const sources = collectUpstreamErrorSources(ev);
|
|
283
|
-
|
|
284
|
-
if (runtimeKey && isGoogleAccountVerificationRequired(ev, sources)) {
|
|
273
|
+
if (isGoogleAccountVerificationRequired(ev, sources)) {
|
|
285
274
|
const url = extractFirstUrl(sources);
|
|
286
275
|
const banUntil = nowMs + ANTIGRAVITY_AUTH_VERIFY_BAN_MS;
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
lastErrorSeries: 'EFATAL',
|
|
305
|
-
consecutiveErrorCount: 0
|
|
306
|
-
};
|
|
307
|
-
this.states.set(key, tickQuotaStateTime(next, nowMs));
|
|
308
|
-
}
|
|
276
|
+
const next = {
|
|
277
|
+
...state,
|
|
278
|
+
inPool: false,
|
|
279
|
+
reason: 'authVerify',
|
|
280
|
+
authIssue: {
|
|
281
|
+
kind: 'google_account_verification',
|
|
282
|
+
...(url ? { url } : {}),
|
|
283
|
+
message: 'account verification required'
|
|
284
|
+
},
|
|
285
|
+
blacklistUntil: Math.max(state.blacklistUntil ?? 0, banUntil) || banUntil,
|
|
286
|
+
cooldownUntil: null,
|
|
287
|
+
lastErrorAtMs: nowMs,
|
|
288
|
+
lastErrorCode: code || 'AUTH_VERIFY',
|
|
289
|
+
lastErrorSeries: 'EFATAL',
|
|
290
|
+
consecutiveErrorCount: 0
|
|
291
|
+
};
|
|
292
|
+
this.states.set(providerKey, tickQuotaStateTime(next, nowMs));
|
|
309
293
|
this.markDirty();
|
|
310
294
|
return;
|
|
311
295
|
}
|
|
312
|
-
// Thought signature missing:
|
|
296
|
+
// Thought signature missing: cooldown current providerKey only.
|
|
313
297
|
if (isThoughtSignatureMissing(ev, sources)) {
|
|
314
298
|
const freezeUntil = nowMs + ANTIGRAVITY_THOUGHT_SIGNATURE_MISSING_COOLDOWN_MS;
|
|
315
|
-
const
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
const next = {
|
|
327
|
-
...s,
|
|
328
|
-
inPool: false,
|
|
329
|
-
reason: 'cooldown',
|
|
330
|
-
cooldownUntil: Math.max(s.cooldownUntil ?? 0, freezeUntil) || freezeUntil,
|
|
331
|
-
lastErrorAtMs: nowMs,
|
|
332
|
-
lastErrorCode: code || 'SIGNATURE_MISSING',
|
|
333
|
-
lastErrorSeries: 'EOTHER',
|
|
334
|
-
consecutiveErrorCount: 0
|
|
335
|
-
};
|
|
336
|
-
this.states.set(key, tickQuotaStateTime(next, nowMs));
|
|
337
|
-
}
|
|
299
|
+
const next = {
|
|
300
|
+
...state,
|
|
301
|
+
inPool: false,
|
|
302
|
+
reason: 'cooldown',
|
|
303
|
+
cooldownUntil: Math.max(state.cooldownUntil ?? 0, freezeUntil) || freezeUntil,
|
|
304
|
+
lastErrorAtMs: nowMs,
|
|
305
|
+
lastErrorCode: code || 'SIGNATURE_MISSING',
|
|
306
|
+
lastErrorSeries: 'EOTHER',
|
|
307
|
+
consecutiveErrorCount: 0
|
|
308
|
+
};
|
|
309
|
+
this.states.set(providerKey, tickQuotaStateTime(next, nowMs));
|
|
338
310
|
this.markDirty();
|
|
339
311
|
return;
|
|
340
312
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const COOLDOWN_SCHEDULE_429_MS = [
|
|
2
|
-
const COOLDOWN_SCHEDULE_FATAL_MS = [
|
|
3
|
-
const COOLDOWN_SCHEDULE_DEFAULT_MS = [
|
|
1
|
+
const COOLDOWN_SCHEDULE_429_MS = [3_000, 10_000, 31_000, 61_000];
|
|
2
|
+
const COOLDOWN_SCHEDULE_FATAL_MS = [3_000, 10_000, 31_000, 61_000];
|
|
3
|
+
const COOLDOWN_SCHEDULE_DEFAULT_MS = [3_000, 10_000, 31_000, 61_000];
|
|
4
4
|
const ERROR_CHAIN_WINDOW_MS = 10 * 60_000;
|
|
5
5
|
const NETWORK_ERROR_CODES = [
|
|
6
6
|
'ECONNRESET',
|
|
@@ -56,14 +56,21 @@ export function normalizeErrorSeries(event) {
|
|
|
56
56
|
}
|
|
57
57
|
function normalizeErrorKey(event) {
|
|
58
58
|
const rawCode = String(event.code || '').trim().toUpperCase();
|
|
59
|
-
|
|
59
|
+
const status = typeof event.httpStatus === 'number' ? event.httpStatus : null;
|
|
60
|
+
const isGenericCode = rawCode === '' ||
|
|
61
|
+
rawCode === 'ERR_PROVIDER_FAILURE' ||
|
|
62
|
+
rawCode === 'ERR_PIPELINE_FAILURE' ||
|
|
63
|
+
rawCode === 'ERR_COMPATIBILITY' ||
|
|
64
|
+
rawCode === 'EXTERNAL_ERROR' ||
|
|
65
|
+
rawCode === 'INTERNAL_ERROR' ||
|
|
66
|
+
rawCode === 'TOOL_ERROR';
|
|
67
|
+
if (!isGenericCode) {
|
|
60
68
|
return rawCode;
|
|
61
69
|
}
|
|
62
|
-
const status = typeof event.httpStatus === 'number' ? event.httpStatus : null;
|
|
63
70
|
if (status && Number.isFinite(status)) {
|
|
64
71
|
return `HTTP_${Math.floor(status)}`;
|
|
65
72
|
}
|
|
66
|
-
return 'ERR_UNKNOWN';
|
|
73
|
+
return rawCode || 'ERR_UNKNOWN';
|
|
67
74
|
}
|
|
68
75
|
function computeCooldownMsBySeries(series, consecutive) {
|
|
69
76
|
if (consecutive <= 0) {
|
|
@@ -125,12 +132,12 @@ export function applyErrorEvent(state, event, nowMs = event.timestampMs ?? Date.
|
|
|
125
132
|
nowMs - lastAt >= 0 &&
|
|
126
133
|
nowMs - lastAt <= ERROR_CHAIN_WINDOW_MS;
|
|
127
134
|
const sameErrorKey = withinChainWindow && state.lastErrorCode === errorKey;
|
|
128
|
-
const rawNextCount = sameErrorKey ? state.consecutiveErrorCount + 1 : 1;
|
|
129
135
|
const schedule = series === 'E429'
|
|
130
136
|
? COOLDOWN_SCHEDULE_429_MS
|
|
131
137
|
: series === 'EFATAL'
|
|
132
138
|
? COOLDOWN_SCHEDULE_FATAL_MS
|
|
133
139
|
: COOLDOWN_SCHEDULE_DEFAULT_MS;
|
|
140
|
+
const rawNextCount = sameErrorKey ? state.consecutiveErrorCount + 1 : 1;
|
|
134
141
|
const nextCount = rawNextCount > schedule.length ? 1 : rawNextCount;
|
|
135
142
|
const cooldownMs = computeCooldownMsBySeries(series, nextCount);
|
|
136
143
|
const nextUntil = cooldownMs ? nowMs + cooldownMs : null;
|
|
@@ -4,4 +4,5 @@ export declare function buildProviderProfiles(targetKeys: Set<string>, runtimeEn
|
|
|
4
4
|
targetRuntime: Record<string, ProviderRuntimeProfile>;
|
|
5
5
|
};
|
|
6
6
|
export declare function resolveContextTokens(runtime: ProviderRuntimeProfile, modelId: string): number;
|
|
7
|
+
export declare function resolveOutputTokens(runtime: ProviderRuntimeProfile, modelId: string): number | undefined;
|
|
7
8
|
export declare function normalizeHealth(input: unknown): ProviderHealthConfig | undefined;
|
|
@@ -16,6 +16,7 @@ export function buildProviderProfiles(targetKeys, runtimeEntries) {
|
|
|
16
16
|
? runtime.modelStreaming?.[parsed.modelId]
|
|
17
17
|
: runtime.streaming;
|
|
18
18
|
const contextTokens = resolveContextTokens(runtime, parsed.modelId);
|
|
19
|
+
const outputTokens = resolveOutputTokens(runtime, parsed.modelId);
|
|
19
20
|
profiles[targetKey] = {
|
|
20
21
|
providerKey: targetKey,
|
|
21
22
|
providerType: runtime.providerType,
|
|
@@ -28,6 +29,7 @@ export function buildProviderProfiles(targetKeys, runtimeEntries) {
|
|
|
28
29
|
processMode: runtime.processMode || 'chat',
|
|
29
30
|
responsesConfig: runtime.responsesConfig,
|
|
30
31
|
streaming: streamingPref,
|
|
32
|
+
maxOutputTokens: outputTokens,
|
|
31
33
|
maxContextTokens: contextTokens,
|
|
32
34
|
...(runtime.deepseek ? { deepseek: runtime.deepseek } : {}),
|
|
33
35
|
...(runtime.serverToolsDisabled ? { serverToolsDisabled: true } : {})
|
|
@@ -52,6 +54,17 @@ export function resolveContextTokens(runtime, modelId) {
|
|
|
52
54
|
}
|
|
53
55
|
return DEFAULT_MODEL_CONTEXT_TOKENS;
|
|
54
56
|
}
|
|
57
|
+
export function resolveOutputTokens(runtime, modelId) {
|
|
58
|
+
const specific = runtime.modelOutputTokens?.[modelId];
|
|
59
|
+
if (typeof specific === 'number' && Number.isFinite(specific) && specific > 0) {
|
|
60
|
+
return Math.floor(specific);
|
|
61
|
+
}
|
|
62
|
+
const fallback = runtime.defaultOutputTokens;
|
|
63
|
+
if (typeof fallback === 'number' && Number.isFinite(fallback) && fallback > 0) {
|
|
64
|
+
return Math.floor(fallback);
|
|
65
|
+
}
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
55
68
|
export function normalizeHealth(input) {
|
|
56
69
|
if (!input || typeof input !== 'object')
|
|
57
70
|
return undefined;
|
|
@@ -18,6 +18,8 @@ export interface NormalizedProvider {
|
|
|
18
18
|
responsesConfig?: ResponsesProviderConfig;
|
|
19
19
|
streaming?: 'always' | 'auto' | 'never';
|
|
20
20
|
modelStreaming?: Record<string, 'always' | 'auto' | 'never'>;
|
|
21
|
+
modelOutputTokens?: Record<string, number>;
|
|
22
|
+
defaultOutputTokens?: number;
|
|
21
23
|
modelContextTokens?: Record<string, number>;
|
|
22
24
|
defaultContextTokens?: number;
|
|
23
25
|
deepseek?: DeepSeekCompatRuntimeOptions;
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { VirtualRouterError, VirtualRouterErrorCode } from '../types.js';
|
|
6
6
|
import { CLAUDE_CODE_DEFAULT_USER_AGENT, CLAUDE_CODE_DEFAULT_X_APP, CLAUDE_CODE_DEFAULT_ANTHROPIC_BETA, parseClaudeCodeAppVersionFromUserAgent } from './claude-code-helpers.js';
|
|
7
7
|
import { normalizeResponsesConfig, resolveProviderStreamingPreference } from './responses-helpers.js';
|
|
8
|
-
import { normalizeModelStreaming, normalizeModelContextTokens } from './streaming-helpers.js';
|
|
8
|
+
import { normalizeModelStreaming, normalizeModelContextTokens, normalizeModelOutputTokens } from './streaming-helpers.js';
|
|
9
9
|
/**
|
|
10
10
|
* Normalize a raw provider configuration into a NormalizedProvider.
|
|
11
11
|
*/
|
|
@@ -33,6 +33,7 @@ export function normalizeProvider(providerId, raw) {
|
|
|
33
33
|
const streaming = resolveProviderStreamingPreference(provider, responsesNode);
|
|
34
34
|
const modelStreaming = normalizeModelStreaming(provider);
|
|
35
35
|
const { modelContextTokens, defaultContextTokens } = normalizeModelContextTokens(provider);
|
|
36
|
+
const { modelOutputTokens, defaultOutputTokens } = normalizeModelOutputTokens(provider);
|
|
36
37
|
const deepseek = normalizeDeepSeekOptions(provider);
|
|
37
38
|
const serverToolsDisabled = provider.serverToolsDisabled === true ||
|
|
38
39
|
(typeof provider.serverToolsDisabled === 'string' &&
|
|
@@ -51,6 +52,8 @@ export function normalizeProvider(providerId, raw) {
|
|
|
51
52
|
responsesConfig,
|
|
52
53
|
streaming,
|
|
53
54
|
modelStreaming,
|
|
55
|
+
modelOutputTokens,
|
|
56
|
+
defaultOutputTokens,
|
|
54
57
|
modelContextTokens,
|
|
55
58
|
defaultContextTokens,
|
|
56
59
|
...(deepseek ? { deepseek } : {}),
|
|
@@ -10,3 +10,10 @@ export declare function normalizeModelContextTokens(provider: Record<string, unk
|
|
|
10
10
|
modelContextTokens?: Record<string, number>;
|
|
11
11
|
defaultContextTokens?: number;
|
|
12
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* Normalize model-level output token limits (maxTokens / max_output_tokens).
|
|
15
|
+
*/
|
|
16
|
+
export declare function normalizeModelOutputTokens(provider: Record<string, unknown>): {
|
|
17
|
+
modelOutputTokens?: Record<string, number>;
|
|
18
|
+
defaultOutputTokens?: number;
|
|
19
|
+
};
|