@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,20 +1,20 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import os from 'node:os';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
-
import { ensureBridgeInstructions } from '../
|
|
4
|
+
import { ensureBridgeInstructions } from '../bridge-instructions.js';
|
|
5
5
|
import { evaluateResponsesHostPolicy } from './responses-host-policy.js';
|
|
6
|
-
import { convertBridgeInputToChatMessages } from '../
|
|
6
|
+
import { convertBridgeInputToChatMessages } from '../bridge-message-utils.js';
|
|
7
7
|
import { createToolCallIdTransformer, enforceToolCallIdStyle, resolveToolCallIdStyle, sanitizeResponsesFunctionName } from '../shared/responses-tool-utils.js';
|
|
8
8
|
import { mapChatToolsToBridge } from '../shared/tool-mapping.js';
|
|
9
|
-
import { ProviderProtocolError } from '../
|
|
10
|
-
import { readRuntimeMetadata } from '../
|
|
11
|
-
import { clampResponsesInputItemId } from '../
|
|
12
|
-
import { isImagePath } from '../
|
|
9
|
+
import { ProviderProtocolError } from '../provider-protocol-error.js';
|
|
10
|
+
import { readRuntimeMetadata } from '../runtime-metadata.js';
|
|
11
|
+
import { clampResponsesInputItemId } from '../bridge-id-utils.js';
|
|
12
|
+
import { isImagePath } from '../media.js';
|
|
13
13
|
import { captureReqInboundResponsesContextSnapshotWithNative, mapReqInboundBridgeToolsToChatWithNative } from '../../router/virtual-router/engine-selection/native-hub-pipeline-req-inbound-semantics.js';
|
|
14
14
|
import { buildBridgeHistoryWithNative } from '../../router/virtual-router/engine-selection/native-hub-bridge-action-semantics.js';
|
|
15
15
|
// --- Utilities (ported strictly) ---
|
|
16
|
-
import { createBridgeActionState, runBridgeActionPipeline } from '../
|
|
17
|
-
import { resolveBridgePolicy, resolvePolicyActions } from '../
|
|
16
|
+
import { createBridgeActionState, runBridgeActionPipeline } from '../bridge-actions.js';
|
|
17
|
+
import { resolveBridgePolicy, resolvePolicyActions } from '../bridge-policies.js';
|
|
18
18
|
function isObject(v) {
|
|
19
19
|
return !!v && typeof v === 'object' && !Array.isArray(v);
|
|
20
20
|
}
|
|
@@ -45,7 +45,7 @@ function filterBridgeInputForUpstream(input, options) {
|
|
|
45
45
|
return [clone];
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
|
-
// normalizeTools unified in ../
|
|
48
|
+
// normalizeTools unified in ../args-mapping.ts
|
|
49
49
|
// --- Structured self-repair helpers for tool failures (Responses path) ---
|
|
50
50
|
const IMAGE_MIME_BY_EXT = {
|
|
51
51
|
'.png': 'image/png',
|
|
@@ -247,6 +247,16 @@ export function captureResponsesContext(payload, dto) {
|
|
|
247
247
|
requestId: dto?.route?.requestId,
|
|
248
248
|
toolCallIdStyle: payload?.toolCallIdStyle ?? payload?.metadata?.toolCallIdStyle
|
|
249
249
|
});
|
|
250
|
+
const instructionReasoning = payload?.__rcc_reasoning_instructions;
|
|
251
|
+
if (instructionReasoning !== undefined && instructionReasoning !== null) {
|
|
252
|
+
const segments = Array.isArray(instructionReasoning) ? instructionReasoning : [instructionReasoning];
|
|
253
|
+
const normalized = segments
|
|
254
|
+
.map((entry) => (typeof entry === 'string' ? entry.trim() : String(entry ?? '').trim()))
|
|
255
|
+
.filter((entry) => entry.length > 0);
|
|
256
|
+
if (normalized.length) {
|
|
257
|
+
captured.__rcc_reasoning_instructions_segments = normalized;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
250
260
|
if (preservedInput) {
|
|
251
261
|
captured.input = preservedInput;
|
|
252
262
|
}
|
|
@@ -596,12 +606,35 @@ export function buildResponsesRequestFromChat(payload, ctx, extras) {
|
|
|
596
606
|
typeof envelopeMetadata?.systemInstruction === 'string' && envelopeMetadata.systemInstruction.trim().length ? envelopeMetadata.systemInstruction.trim() : undefined,
|
|
597
607
|
combinedSystemInstruction && combinedSystemInstruction.length > 0 ? combinedSystemInstruction : undefined
|
|
598
608
|
];
|
|
609
|
+
let resolvedInstruction;
|
|
599
610
|
for (const candidate of instructionCandidates) {
|
|
600
611
|
if (candidate && candidate.length) {
|
|
601
|
-
|
|
612
|
+
resolvedInstruction = candidate;
|
|
602
613
|
break;
|
|
603
614
|
}
|
|
604
615
|
}
|
|
616
|
+
if (resolvedInstruction && resolvedInstruction.length) {
|
|
617
|
+
const reasoningSegments = (() => {
|
|
618
|
+
if (!ctx || typeof ctx !== 'object')
|
|
619
|
+
return [];
|
|
620
|
+
const ctxAny = ctx;
|
|
621
|
+
const raw = ctxAny.__rcc_reasoning_instructions_segments;
|
|
622
|
+
if (!raw)
|
|
623
|
+
return [];
|
|
624
|
+
const segments = Array.isArray(raw) ? raw : [raw];
|
|
625
|
+
return segments
|
|
626
|
+
.map((entry) => (typeof entry === 'string' ? entry.trim() : String(entry ?? '').trim()))
|
|
627
|
+
.filter((entry) => entry.length > 0);
|
|
628
|
+
})();
|
|
629
|
+
if (reasoningSegments.length) {
|
|
630
|
+
const combined = `${reasoningSegments.join('\n')}\n${resolvedInstruction}`.trim();
|
|
631
|
+
out.instructions = combined;
|
|
632
|
+
out.instructions_is_raw = true;
|
|
633
|
+
}
|
|
634
|
+
else {
|
|
635
|
+
out.instructions = resolvedInstruction;
|
|
636
|
+
}
|
|
637
|
+
}
|
|
605
638
|
// 不追加 metadata,以便 roundtrip 与原始 payload 对齐;系统提示直接写入 instructions。
|
|
606
639
|
const upstreamInput = filterBridgeInputForUpstream(input, { allowToolCallId: toolCallIdStyle === 'preserve' });
|
|
607
640
|
if (upstreamInput.length) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { isJsonObject, jsonClone } from '
|
|
2
|
-
import { cloneRuntimeMetadataWithNative, ensureRuntimeMetadataCarrierWithNative, readRuntimeMetadataWithNative } from '
|
|
1
|
+
import { isJsonObject, jsonClone } from './hub/types/json.js';
|
|
2
|
+
import { cloneRuntimeMetadataWithNative, ensureRuntimeMetadataCarrierWithNative, readRuntimeMetadataWithNative } from '../router/virtual-router/engine-selection/native-shared-conversion-semantics.js';
|
|
3
3
|
export function readRuntimeMetadata(carrier) {
|
|
4
4
|
if (!carrier || typeof carrier !== 'object') {
|
|
5
5
|
return undefined;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { createBridgeActionState, runBridgeActionPipeline } from '
|
|
2
|
-
import { resolveBridgePolicy, resolvePolicyActions } from '
|
|
1
|
+
import { createBridgeActionState, runBridgeActionPipeline } from '../bridge-actions.js';
|
|
2
|
+
import { resolveBridgePolicy, resolvePolicyActions } from '../bridge-policies.js';
|
|
3
3
|
import { normalizeChatMessageContent } from './chat-output-normalizer.js';
|
|
4
4
|
import { mapBridgeToolsToChat, mapChatToolsToBridge } from './tool-mapping.js';
|
|
5
5
|
import { jsonClone } from '../hub/types/json.js';
|
|
6
|
-
import { ProviderProtocolError } from '
|
|
6
|
+
import { ProviderProtocolError } from '../provider-protocol-error.js';
|
|
7
7
|
import { parseLenientJsonishWithNative } from '../../router/virtual-router/engine-selection/native-shared-conversion-semantics.js';
|
|
8
8
|
function isObject(v) {
|
|
9
9
|
return !!v && typeof v === 'object' && !Array.isArray(v);
|
|
@@ -590,11 +590,22 @@ export function buildAnthropicFromOpenAIChat(oa, options) {
|
|
|
590
590
|
blocks.push({ type: 'text', text });
|
|
591
591
|
}
|
|
592
592
|
}
|
|
593
|
-
const
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
593
|
+
const extensionReasoning = body?.__responses_reasoning;
|
|
594
|
+
const extensionContent = Array.isArray(extensionReasoning?.content)
|
|
595
|
+
? extensionReasoning?.content?.map((entry) => String(entry.text ?? '')).filter((text) => text.trim().length > 0)
|
|
596
|
+
: [];
|
|
597
|
+
const extensionSummary = Array.isArray(extensionReasoning?.summary)
|
|
598
|
+
? extensionReasoning?.summary?.map((entry) => String(entry.text ?? '')).filter((text) => text.trim().length > 0)
|
|
599
|
+
: [];
|
|
600
|
+
const extensionText = extensionContent.length > 0
|
|
601
|
+
? extensionContent.join('\n')
|
|
602
|
+
: (extensionSummary.length > 0 ? extensionSummary.join('\n') : undefined);
|
|
603
|
+
const reasoningField = extensionText ??
|
|
604
|
+
(typeof msg?.reasoning_content === 'string'
|
|
605
|
+
? msg.reasoning_content
|
|
606
|
+
: typeof msg?.reasoning === 'string'
|
|
607
|
+
? msg.reasoning
|
|
608
|
+
: undefined);
|
|
598
609
|
if (reasoningField && reasoningField.trim().length) {
|
|
599
610
|
blocks.push({ type: 'thinking', text: reasoningField.trim() });
|
|
600
611
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import type { ConversionContext, ConversionProfile } from '../types.js';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Native-primary Chat request filters.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
* -
|
|
7
|
-
* 都在这里走同一套工具治理与参数标准化逻辑。
|
|
5
|
+
* Historical TS FilterEngine implementation archived at:
|
|
6
|
+
* - src/conversion/shared/archive/chat-request-filters.ts
|
|
8
7
|
*/
|
|
9
8
|
export declare function runStandardChatRequestFilters(chatRequest: any, profile: ConversionProfile, context: ConversionContext): Promise<any>;
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import { FilterEngine, RequestToolCallsStringifyFilter, RequestToolChoicePolicyFilter } from '../../filters/index.js';
|
|
2
1
|
import { normalizeChatRequest } from '../index.js';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { createSnapshotWriter } from '../snapshot-utils.js';
|
|
3
|
+
import { buildGovernedFilterPayloadWithNativeFallback } from '../../router/virtual-router/engine-selection/native-chat-request-filter-semantics.js';
|
|
5
4
|
/**
|
|
6
|
-
*
|
|
5
|
+
* Native-primary Chat request filters.
|
|
7
6
|
*
|
|
8
|
-
*
|
|
9
|
-
* -
|
|
10
|
-
* 都在这里走同一套工具治理与参数标准化逻辑。
|
|
7
|
+
* Historical TS FilterEngine implementation archived at:
|
|
8
|
+
* - src/conversion/shared/archive/chat-request-filters.ts
|
|
11
9
|
*/
|
|
12
10
|
export async function runStandardChatRequestFilters(chatRequest, profile, context) {
|
|
13
11
|
const existingMetadata = context.metadata ?? {};
|
|
@@ -15,18 +13,13 @@ export async function runStandardChatRequestFilters(chatRequest, profile, contex
|
|
|
15
13
|
context.metadata = existingMetadata;
|
|
16
14
|
}
|
|
17
15
|
const inboundStreamFromContext = typeof existingMetadata.inboundStream === 'boolean' ? existingMetadata.inboundStream : undefined;
|
|
18
|
-
const inboundStreamDetected = chatRequest && typeof chatRequest === 'object' && chatRequest.stream === true;
|
|
19
|
-
const normalizedInboundStream = inboundStreamFromContext ?? inboundStreamDetected
|
|
16
|
+
const inboundStreamDetected = chatRequest && typeof chatRequest === 'object' && chatRequest.stream === true ? true : undefined;
|
|
17
|
+
const normalizedInboundStream = inboundStreamFromContext ?? inboundStreamDetected;
|
|
20
18
|
if (typeof normalizedInboundStream === 'boolean') {
|
|
21
19
|
existingMetadata.inboundStream = normalizedInboundStream;
|
|
22
20
|
}
|
|
23
21
|
const requestId = context.requestId ?? `req_${Date.now()}`;
|
|
24
|
-
const
|
|
25
|
-
? String(chatRequest.model)
|
|
26
|
-
: 'unknown';
|
|
27
|
-
const endpoint = context.entryEndpoint ||
|
|
28
|
-
context.endpoint ||
|
|
29
|
-
'/v1/chat/completions';
|
|
22
|
+
const endpoint = context.entryEndpoint || context.endpoint || '/v1/chat/completions';
|
|
30
23
|
const snapshot = createSnapshotWriter({
|
|
31
24
|
requestId,
|
|
32
25
|
endpoint,
|
|
@@ -38,78 +31,29 @@ export async function runStandardChatRequestFilters(chatRequest, profile, contex
|
|
|
38
31
|
snapshot(stage, payload);
|
|
39
32
|
};
|
|
40
33
|
snapshotStage('req_process_filters_input', chatRequest);
|
|
41
|
-
const reqCtxBase = {
|
|
42
|
-
requestId,
|
|
43
|
-
model: modelId,
|
|
44
|
-
endpoint,
|
|
45
|
-
profile: profile.outgoingProtocol,
|
|
46
|
-
debug: { emit: () => { } }
|
|
47
|
-
};
|
|
48
|
-
const engine = new FilterEngine();
|
|
49
34
|
const incomingProtocol = (profile.incomingProtocol || '').toLowerCase();
|
|
50
|
-
const entryEndpointLower =
|
|
51
|
-
const originalToolCount =
|
|
35
|
+
const entryEndpointLower = endpoint.toLowerCase();
|
|
36
|
+
const originalToolCount = chatRequest && typeof chatRequest === 'object' && Array.isArray(chatRequest.tools)
|
|
52
37
|
? chatRequest.tools.length
|
|
53
38
|
: 0;
|
|
54
39
|
const isAnthropicProfile = incomingProtocol === 'anthropic-messages' ||
|
|
55
40
|
entryEndpointLower.includes('/v1/messages');
|
|
56
41
|
const skipAutoToolInjection = isAnthropicProfile && originalToolCount === 0;
|
|
57
|
-
|
|
58
|
-
if (
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
engine.registerFilter(new RequestToolListFilter());
|
|
62
|
-
}
|
|
63
|
-
catch {
|
|
64
|
-
// 可选过滤器,失败时保持向后兼容
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
engine.registerFilter(new RequestToolCallsStringifyFilter());
|
|
68
|
-
engine.registerFilter(new RequestToolChoicePolicyFilter());
|
|
69
|
-
// FieldMap:保持与 Chat 入口一致,使用 openai-openai.fieldmap.json
|
|
70
|
-
try {
|
|
71
|
-
const cfg = await loadFieldMapConfig('openai-openai.fieldmap.json');
|
|
72
|
-
if (cfg)
|
|
73
|
-
engine.setFieldMap(cfg);
|
|
74
|
-
engine.registerTransform('stringifyJson', (v) => (typeof v === 'string'
|
|
75
|
-
? v
|
|
76
|
-
: (() => {
|
|
77
|
-
try {
|
|
78
|
-
return JSON.stringify(v ?? {});
|
|
79
|
-
}
|
|
80
|
-
catch {
|
|
81
|
-
return '{}';
|
|
82
|
-
}
|
|
83
|
-
})()));
|
|
84
|
-
}
|
|
85
|
-
catch {
|
|
86
|
-
// best-effort:缺少 fieldmap 时保持原样
|
|
87
|
-
}
|
|
88
|
-
let staged = await engine.run('request_pre', chatRequest, reqCtxBase);
|
|
89
|
-
snapshotStage('req_process_filters_request_pre', staged);
|
|
90
|
-
staged = await engine.run('request_map', staged, reqCtxBase);
|
|
91
|
-
snapshotStage('req_process_filters_request_map', staged);
|
|
92
|
-
staged = await engine.run('request_post', staged, reqCtxBase);
|
|
93
|
-
snapshotStage('req_process_filters_request_post', staged);
|
|
94
|
-
if (skipAutoToolInjection && staged && typeof staged === 'object') {
|
|
95
|
-
if (!Array.isArray(staged.tools)) {
|
|
96
|
-
staged.tools = [];
|
|
42
|
+
const nativeGovernedPayload = buildGovernedFilterPayloadWithNativeFallback(chatRequest);
|
|
43
|
+
if (skipAutoToolInjection && nativeGovernedPayload && typeof nativeGovernedPayload === 'object') {
|
|
44
|
+
if (!Array.isArray(nativeGovernedPayload.tools)) {
|
|
45
|
+
nativeGovernedPayload.tools = [];
|
|
97
46
|
}
|
|
98
|
-
|
|
47
|
+
nativeGovernedPayload.__rcc_disable_mcp_tools = true;
|
|
99
48
|
}
|
|
100
|
-
|
|
101
|
-
let normalized = normalizeChatRequest(
|
|
49
|
+
snapshotStage('req_process_filters_native_payload', nativeGovernedPayload);
|
|
50
|
+
let normalized = normalizeChatRequest(nativeGovernedPayload);
|
|
102
51
|
snapshotStage('req_process_filters_normalized', normalized);
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
normalized = await engine.run('request_finalize', normalized, reqCtxBase);
|
|
109
|
-
snapshotStage('req_process_filters_request_finalize', normalized);
|
|
110
|
-
}
|
|
111
|
-
catch {
|
|
112
|
-
// 可选工具归一过滤器,失败时保持已归一化结果
|
|
52
|
+
if (skipAutoToolInjection && normalized && typeof normalized === 'object') {
|
|
53
|
+
if (!Array.isArray(normalized.tools)) {
|
|
54
|
+
normalized.tools = [];
|
|
55
|
+
}
|
|
56
|
+
normalized.__rcc_disable_mcp_tools = true;
|
|
113
57
|
}
|
|
114
58
|
const preserveStreamField = profile.incomingProtocol === 'openai-chat' && profile.outgoingProtocol === 'openai-chat';
|
|
115
59
|
const pruned = pruneChatRequestPayload(normalized, { preserveStreamField });
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BridgeToolDefinition } from '
|
|
1
|
+
import type { BridgeToolDefinition } from '../types/bridge-message-types.js';
|
|
2
2
|
import type { MissingField } from '../hub/types/chat-envelope.js';
|
|
3
3
|
import type { JsonValue, JsonObject } from '../hub/types/json.js';
|
|
4
4
|
export declare function prepareGeminiToolsForBridge(rawTools: JsonValue | undefined, missing?: MissingField[]): BridgeToolDefinition[] | undefined;
|
|
@@ -151,6 +151,7 @@ function normalizeReasoningField(container, mode) {
|
|
|
151
151
|
if (mode === 'append_to_content') {
|
|
152
152
|
appendReasoningToContent(bag, trimmed);
|
|
153
153
|
delete bag.reasoning_content;
|
|
154
|
+
return;
|
|
154
155
|
}
|
|
155
156
|
}
|
|
156
157
|
function appendReasoningToContent(container, reasoning) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { injectMcpToolsForChat } from '
|
|
1
|
+
import { injectMcpToolsForChat } from '../mcp-injection.js';
|
|
2
2
|
import { normalizeOpenaiChatMessagesWithNative, normalizeOpenaiMessageWithNative, normalizeOpenaiToolCallWithNative, normalizeOpenaiToolWithNative } from '../../router/virtual-router/engine-selection/native-shared-conversion-semantics.js';
|
|
3
3
|
// Message normalization utilities for OpenAI chat payloads (renamed to avoid confusion
|
|
4
4
|
// with the deprecated "openai-normalizer" module entry). This file contains the
|
|
@@ -209,4 +209,4 @@ function normalizeToolCall(tc) {
|
|
|
209
209
|
const isDisabled = disableShellCoerce === '1' || disableShellCoerce === 'true';
|
|
210
210
|
return normalizeOpenaiToolCallWithNative(tc, isDisabled);
|
|
211
211
|
}
|
|
212
|
-
import { resolveBudgetForModelSync } from '
|
|
212
|
+
import { resolveBudgetForModelSync } from '../payload-budget.js';
|
|
@@ -42,6 +42,9 @@ function normalizeChatChoice(choice) {
|
|
|
42
42
|
containers.forEach(container => applyNormalizedChatContent(container));
|
|
43
43
|
}
|
|
44
44
|
function applyNormalizedChatContent(container) {
|
|
45
|
+
const existingReasoning = typeof container.reasoning_content === 'string' && container.reasoning_content.trim().length
|
|
46
|
+
? container.reasoning_content.trim()
|
|
47
|
+
: undefined;
|
|
45
48
|
const normalized = normalizeChatMessageContent(container.content);
|
|
46
49
|
const role = typeof container.role === 'string' ? container.role : undefined;
|
|
47
50
|
if (normalized.contentText !== undefined && normalized.contentText.trim().length) {
|
|
@@ -56,6 +59,9 @@ function applyNormalizedChatContent(container) {
|
|
|
56
59
|
if (normalized.reasoningText && normalized.reasoningText.trim().length) {
|
|
57
60
|
container.reasoning_content = normalized.reasoningText.trim();
|
|
58
61
|
}
|
|
62
|
+
else if (existingReasoning) {
|
|
63
|
+
container.reasoning_content = existingReasoning;
|
|
64
|
+
}
|
|
59
65
|
else if ('reasoning_content' in container) {
|
|
60
66
|
delete container.reasoning_content;
|
|
61
67
|
}
|
|
@@ -4,7 +4,8 @@ export function extractReasoningSegments(source, reasoningCollector) {
|
|
|
4
4
|
const hasExplicitOpen = /<think>/i.test(source) ||
|
|
5
5
|
/<reflection>/i.test(source) ||
|
|
6
6
|
/```\s*(?:think|reflection)/i.test(source);
|
|
7
|
-
const hasExplicitClose = /<\/think>/i.test(source) ||
|
|
7
|
+
const hasExplicitClose = /<\/think>/i.test(source) ||
|
|
8
|
+
/<\/reflection>/i.test(source);
|
|
8
9
|
const push = (value) => {
|
|
9
10
|
const trimmed = (value ?? '').trim();
|
|
10
11
|
if (trimmed && reasoningCollector) {
|
|
@@ -22,7 +23,9 @@ export function extractReasoningSegments(source, reasoningCollector) {
|
|
|
22
23
|
return '';
|
|
23
24
|
});
|
|
24
25
|
}
|
|
25
|
-
working = working
|
|
26
|
+
working = working
|
|
27
|
+
.replace(/<\/?think>/gi, '')
|
|
28
|
+
.replace(/<\/?reflection>/gi, '');
|
|
26
29
|
working = working.replace(/\n{3,}/g, '\n\n');
|
|
27
30
|
if (reasoningCollector && !hasExplicitOpen && hasExplicitClose) {
|
|
28
31
|
const trimmed = working.trim();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ProviderProtocolError } from '
|
|
1
|
+
import { ProviderProtocolError } from '../provider-protocol-error.js';
|
|
2
2
|
import { normalizeFunctionCallOutputIdWithNative as normalizeFunctionCallOutputId } from '../../router/virtual-router/engine-selection/native-shared-conversion-semantics.js';
|
|
3
3
|
import { convertResponsesOutputToInputItemsWithNative, pickResponsesPersistedFieldsWithNative } from '../../router/virtual-router/engine-selection/native-shared-conversion-semantics.js';
|
|
4
4
|
const TTL_MS = 1000 * 60 * 30; // 30min
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { normalizeFunctionCallId, normalizeFunctionCallOutputId } from '
|
|
1
|
+
import { normalizeFunctionCallId, normalizeFunctionCallOutputId } from '../bridge-id-utils.js';
|
|
2
2
|
import { normalizeContentPart } from './output-content-normalizer.js';
|
|
3
3
|
import { expandResponsesMessageItem } from '../../sse/shared/responses-output-normalizer.js';
|
|
4
4
|
import { normalizeResponsesUsageWithNative } from '../../router/virtual-router/engine-selection/native-hub-pipeline-resp-semantics.js';
|
|
@@ -86,17 +86,28 @@ export function buildResponsesOutputFromChat(options) {
|
|
|
86
86
|
}
|
|
87
87
|
const hasToolCalls = toolCalls.length > 0;
|
|
88
88
|
const reasoningChunks = [];
|
|
89
|
-
const preservedReasoning =
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
89
|
+
const preservedReasoning = response?.__responses_reasoning;
|
|
90
|
+
const preservedSummary = preservedReasoning?.summary ?? [];
|
|
91
|
+
const preservedContent = preservedReasoning?.content ?? [];
|
|
92
|
+
const preservedEncrypted = preservedReasoning?.encrypted_content;
|
|
93
|
+
if (preservedContent.length) {
|
|
94
|
+
for (const entry of preservedContent) {
|
|
95
|
+
if (!entry || typeof entry !== 'object')
|
|
96
|
+
continue;
|
|
97
|
+
const text = String(entry.text ?? '').trim();
|
|
98
|
+
if (text.length) {
|
|
99
|
+
reasoningChunks.push(text);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
94
102
|
}
|
|
95
103
|
else {
|
|
96
104
|
appendReasoningSegments(reasoningChunks, message?.reasoning_content);
|
|
97
105
|
}
|
|
98
106
|
const convertedContent = convertChatContentToResponses(content);
|
|
99
|
-
const shouldEmitMessage = Boolean(message) && (convertedContent.length > 0 ||
|
|
107
|
+
const shouldEmitMessage = Boolean(message) && (convertedContent.length > 0 ||
|
|
108
|
+
reasoningChunks.length > 0 ||
|
|
109
|
+
preservedSummary.length > 0 ||
|
|
110
|
+
!hasToolCalls);
|
|
100
111
|
if (shouldEmitMessage) {
|
|
101
112
|
const responsesMessage = {
|
|
102
113
|
id: allocateOutputId('message'),
|
|
@@ -110,6 +121,28 @@ export function buildResponsesOutputFromChat(options) {
|
|
|
110
121
|
outputIndex: outputItems.length,
|
|
111
122
|
extraReasoning: reasoningChunks
|
|
112
123
|
});
|
|
124
|
+
const summaryItems = preservedSummary
|
|
125
|
+
.map((entry) => ({ type: 'summary_text', text: String(entry.text ?? '') }))
|
|
126
|
+
.filter((entry) => entry.text.trim().length > 0);
|
|
127
|
+
let reasoningItem = expandedItems.find((item) => item.type === 'reasoning');
|
|
128
|
+
if (!reasoningItem && summaryItems.length > 0) {
|
|
129
|
+
reasoningItem = {
|
|
130
|
+
id: `${responsesMessage.id}_reasoning`,
|
|
131
|
+
type: 'reasoning',
|
|
132
|
+
summary: summaryItems,
|
|
133
|
+
content: undefined,
|
|
134
|
+
...(typeof preservedEncrypted === 'string' ? { encrypted_content: preservedEncrypted } : {})
|
|
135
|
+
};
|
|
136
|
+
expandedItems.unshift(reasoningItem);
|
|
137
|
+
}
|
|
138
|
+
else if (reasoningItem) {
|
|
139
|
+
if (summaryItems.length > 0) {
|
|
140
|
+
reasoningItem.summary = summaryItems;
|
|
141
|
+
}
|
|
142
|
+
if (typeof preservedEncrypted === 'string') {
|
|
143
|
+
reasoningItem.encrypted_content = preservedEncrypted;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
113
146
|
for (const expanded of expandedItems) {
|
|
114
147
|
outputItems.push(expanded);
|
|
115
148
|
}
|
|
@@ -165,7 +198,14 @@ export function buildResponsesOutputFromChat(options) {
|
|
|
165
198
|
};
|
|
166
199
|
}
|
|
167
200
|
function normalizeUsage(usageRaw) {
|
|
168
|
-
|
|
201
|
+
if (usageRaw === null || usageRaw === undefined) {
|
|
202
|
+
return undefined;
|
|
203
|
+
}
|
|
204
|
+
const normalized = normalizeResponsesUsageWithNative(usageRaw);
|
|
205
|
+
if (normalized === null) {
|
|
206
|
+
return undefined;
|
|
207
|
+
}
|
|
208
|
+
return normalized;
|
|
169
209
|
}
|
|
170
210
|
function buildFunctionCallOutput(call, allocateOutputId, sanitizeFunctionName, baseCount, offset) {
|
|
171
211
|
try {
|
|
@@ -265,9 +305,13 @@ function resolveOutputText(parts, meta) {
|
|
|
265
305
|
if (meta && typeof meta === 'object') {
|
|
266
306
|
const hasField = Boolean(meta.hasField);
|
|
267
307
|
if (hasField) {
|
|
268
|
-
const
|
|
269
|
-
if (typeof
|
|
270
|
-
return
|
|
308
|
+
const rawValue = meta.raw;
|
|
309
|
+
if (typeof rawValue === 'string') {
|
|
310
|
+
return rawValue;
|
|
311
|
+
}
|
|
312
|
+
const fallbackValue = meta.value;
|
|
313
|
+
if (typeof fallbackValue === 'string') {
|
|
314
|
+
return fallbackValue;
|
|
271
315
|
}
|
|
272
316
|
return '';
|
|
273
317
|
}
|
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
export interface ResponsesOutputTextMeta {
|
|
2
2
|
hasField: boolean;
|
|
3
3
|
value?: string;
|
|
4
|
+
raw?: string;
|
|
4
5
|
}
|
|
5
|
-
export
|
|
6
|
-
|
|
6
|
+
export interface ResponsesReasoningPayload {
|
|
7
|
+
summary?: Array<{
|
|
8
|
+
type: 'summary_text';
|
|
9
|
+
text: string;
|
|
10
|
+
}>;
|
|
11
|
+
content?: Array<{
|
|
12
|
+
type: 'reasoning_text' | 'text';
|
|
13
|
+
text: string;
|
|
14
|
+
}>;
|
|
15
|
+
encrypted_content?: string | null;
|
|
16
|
+
}
|
|
17
|
+
export declare function registerResponsesReasoning(id: unknown, reasoning: ResponsesReasoningPayload | undefined): void;
|
|
18
|
+
export declare function consumeResponsesReasoning(id: unknown): ResponsesReasoningPayload | undefined;
|
|
7
19
|
export declare function registerResponsesOutputTextMeta(id: unknown, meta: ResponsesOutputTextMeta | undefined): void;
|
|
8
20
|
export declare function consumeResponsesOutputTextMeta(id: unknown): ResponsesOutputTextMeta | undefined;
|
|
9
21
|
export declare function registerResponsesPayloadSnapshot(id: unknown, snapshot: Record<string, unknown> | undefined): void;
|
|
@@ -38,13 +38,35 @@ function cloneSnapshot(snapshot) {
|
|
|
38
38
|
return undefined;
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
-
export function registerResponsesReasoning(id,
|
|
41
|
+
export function registerResponsesReasoning(id, reasoning) {
|
|
42
42
|
if (typeof id !== 'string')
|
|
43
43
|
return;
|
|
44
|
-
if (!
|
|
44
|
+
if (!reasoning)
|
|
45
|
+
return;
|
|
46
|
+
const summary = Array.isArray(reasoning.summary)
|
|
47
|
+
? reasoning.summary
|
|
48
|
+
.map((item) => ({ type: 'summary_text', text: String(item.text ?? '').trim() }))
|
|
49
|
+
.filter((item) => item.text.length > 0)
|
|
50
|
+
: undefined;
|
|
51
|
+
const content = Array.isArray(reasoning.content)
|
|
52
|
+
? reasoning.content
|
|
53
|
+
.map((item) => ({
|
|
54
|
+
type: item.type === 'text' ? 'text' : 'reasoning_text',
|
|
55
|
+
text: String(item.text ?? '').trim()
|
|
56
|
+
}))
|
|
57
|
+
.filter((item) => item.text.length > 0)
|
|
58
|
+
: undefined;
|
|
59
|
+
const hasSummary = Array.isArray(summary) && summary.length > 0;
|
|
60
|
+
const hasContent = Array.isArray(content) && content.length > 0;
|
|
61
|
+
const hasEncrypted = reasoning.encrypted_content !== undefined;
|
|
62
|
+
if (!hasSummary && !hasContent && !hasEncrypted)
|
|
45
63
|
return;
|
|
46
64
|
const entry = ensureEntry(id);
|
|
47
|
-
entry.reasoning =
|
|
65
|
+
entry.reasoning = {
|
|
66
|
+
summary: hasSummary ? summary : undefined,
|
|
67
|
+
content: hasContent ? content : undefined,
|
|
68
|
+
encrypted_content: reasoning.encrypted_content
|
|
69
|
+
};
|
|
48
70
|
}
|
|
49
71
|
export function consumeResponsesReasoning(id) {
|
|
50
72
|
if (typeof id !== 'string')
|
|
@@ -52,7 +74,11 @@ export function consumeResponsesReasoning(id) {
|
|
|
52
74
|
const entry = registry.get(id);
|
|
53
75
|
if (!entry?.reasoning)
|
|
54
76
|
return undefined;
|
|
55
|
-
const value =
|
|
77
|
+
const value = {
|
|
78
|
+
summary: entry.reasoning.summary ? [...entry.reasoning.summary] : undefined,
|
|
79
|
+
content: entry.reasoning.content ? [...entry.reasoning.content] : undefined,
|
|
80
|
+
encrypted_content: entry.reasoning.encrypted_content
|
|
81
|
+
};
|
|
56
82
|
entry.reasoning = undefined;
|
|
57
83
|
pruneEntry(id);
|
|
58
84
|
return value;
|
|
@@ -65,7 +91,8 @@ export function registerResponsesOutputTextMeta(id, meta) {
|
|
|
65
91
|
const entry = ensureEntry(id);
|
|
66
92
|
entry.outputText = {
|
|
67
93
|
hasField: Boolean(meta.hasField),
|
|
68
|
-
value: typeof meta.value === 'string' ? meta.value : undefined
|
|
94
|
+
value: typeof meta.value === 'string' ? meta.value : undefined,
|
|
95
|
+
raw: typeof meta.raw === 'string' ? meta.raw : undefined
|
|
69
96
|
};
|
|
70
97
|
}
|
|
71
98
|
export function consumeResponsesOutputTextMeta(id) {
|
|
@@ -76,7 +103,8 @@ export function consumeResponsesOutputTextMeta(id) {
|
|
|
76
103
|
return undefined;
|
|
77
104
|
const value = {
|
|
78
105
|
hasField: Boolean(entry.outputText.hasField),
|
|
79
|
-
value: entry.outputText.value
|
|
106
|
+
value: entry.outputText.value,
|
|
107
|
+
raw: entry.outputText.raw
|
|
80
108
|
};
|
|
81
109
|
entry.outputText = undefined;
|
|
82
110
|
pruneEntry(id);
|