@jsonstudio/llms 0.6.2979 → 0.6.3214
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/chat-mapper.js +7 -4
- 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 +1 -1
- package/dist/conversion/hub/tool-governance/engine.d.ts +8 -0
- package/dist/conversion/hub/tool-governance/engine.js +25 -68
- 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 +22 -0
- package/dist/router/virtual-router/engine-selection/native-hub-pipeline-governance-semantics.js +154 -0
- package/dist/router/virtual-router/engine-selection/native-router-hotpath-loader.js +38 -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 +2 -0
- package/dist/router/virtual-router/engine-selection/native-snapshot-hooks.js +69 -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,76 +1,80 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { resolveDefaultToolGovernanceRulesWithNative } from '../../../router/virtual-router/engine-selection/native-hub-pipeline-governance-semantics.js';
|
|
2
2
|
const ALPHA_NUMERIC = /[A-Za-z0-9_-]/;
|
|
3
3
|
const LOWER_SNAKE = /[a-z0-9_-]/;
|
|
4
4
|
function clonePattern(pattern) {
|
|
5
5
|
const flags = pattern.flags.replace(/g/g, '');
|
|
6
6
|
return new RegExp(pattern.source, flags);
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
'
|
|
11
|
-
|
|
12
|
-
maxNameLength: 64,
|
|
13
|
-
allowedCharacters: clonePattern(ALPHA_NUMERIC),
|
|
14
|
-
defaultName: DEFAULT_TOOL_NAME,
|
|
15
|
-
trimWhitespace: true,
|
|
16
|
-
onViolation: 'truncate'
|
|
17
|
-
},
|
|
18
|
-
response: {
|
|
19
|
-
maxNameLength: 64,
|
|
20
|
-
allowedCharacters: clonePattern(ALPHA_NUMERIC),
|
|
21
|
-
defaultName: DEFAULT_TOOL_NAME,
|
|
22
|
-
trimWhitespace: true,
|
|
23
|
-
onViolation: 'truncate'
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
'openai-responses': {
|
|
27
|
-
request: {
|
|
28
|
-
maxNameLength: 64,
|
|
29
|
-
allowedCharacters: clonePattern(ALPHA_NUMERIC),
|
|
30
|
-
defaultName: DEFAULT_TOOL_NAME,
|
|
31
|
-
trimWhitespace: true,
|
|
32
|
-
onViolation: 'truncate'
|
|
33
|
-
},
|
|
34
|
-
response: {
|
|
35
|
-
maxNameLength: 64,
|
|
36
|
-
allowedCharacters: clonePattern(ALPHA_NUMERIC),
|
|
37
|
-
defaultName: DEFAULT_TOOL_NAME,
|
|
38
|
-
trimWhitespace: true,
|
|
39
|
-
onViolation: 'truncate'
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
anthropic: {
|
|
43
|
-
request: {
|
|
44
|
-
maxNameLength: 64,
|
|
45
|
-
allowedCharacters: clonePattern(LOWER_SNAKE),
|
|
46
|
-
forceCase: 'lower',
|
|
47
|
-
defaultName: DEFAULT_TOOL_NAME,
|
|
48
|
-
trimWhitespace: true,
|
|
49
|
-
onViolation: 'truncate'
|
|
50
|
-
},
|
|
51
|
-
response: {
|
|
52
|
-
maxNameLength: 64,
|
|
53
|
-
allowedCharacters: clonePattern(LOWER_SNAKE),
|
|
54
|
-
forceCase: 'lower',
|
|
55
|
-
defaultName: DEFAULT_TOOL_NAME,
|
|
56
|
-
trimWhitespace: true,
|
|
57
|
-
onViolation: 'truncate'
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
|
-
gemini: {
|
|
61
|
-
request: {
|
|
62
|
-
maxNameLength: 64,
|
|
63
|
-
allowedCharacters: clonePattern(ALPHA_NUMERIC),
|
|
64
|
-
defaultName: DEFAULT_TOOL_NAME,
|
|
65
|
-
trimWhitespace: true,
|
|
66
|
-
onViolation: 'truncate'
|
|
67
|
-
},
|
|
68
|
-
response: {
|
|
69
|
-
maxNameLength: 64,
|
|
70
|
-
allowedCharacters: clonePattern(ALPHA_NUMERIC),
|
|
71
|
-
defaultName: DEFAULT_TOOL_NAME,
|
|
72
|
-
trimWhitespace: true,
|
|
73
|
-
onViolation: 'truncate'
|
|
74
|
-
}
|
|
8
|
+
function mapAllowedCharacters(token, fallback) {
|
|
9
|
+
const normalized = String(token || '').trim().toLowerCase();
|
|
10
|
+
if (normalized === 'lower_snake') {
|
|
11
|
+
return clonePattern(LOWER_SNAKE);
|
|
75
12
|
}
|
|
76
|
-
|
|
13
|
+
return clonePattern(fallback);
|
|
14
|
+
}
|
|
15
|
+
function mapNativeRules(nativeRules, fallback) {
|
|
16
|
+
if (!nativeRules || typeof nativeRules !== 'object') {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
maxNameLength: typeof nativeRules.maxNameLength === 'number' && Number.isFinite(nativeRules.maxNameLength)
|
|
21
|
+
? Math.max(1, Math.floor(nativeRules.maxNameLength))
|
|
22
|
+
: fallback.maxNameLength,
|
|
23
|
+
allowedCharacters: mapAllowedCharacters(nativeRules.allowedCharacters, fallback.allowedCharacters),
|
|
24
|
+
defaultName: typeof nativeRules.defaultName === 'string' && nativeRules.defaultName.trim().length
|
|
25
|
+
? nativeRules.defaultName.trim()
|
|
26
|
+
: fallback.defaultName,
|
|
27
|
+
trimWhitespace: nativeRules.trimWhitespace !== false,
|
|
28
|
+
...(nativeRules.forceCase === 'lower' || nativeRules.forceCase === 'upper'
|
|
29
|
+
? { forceCase: nativeRules.forceCase }
|
|
30
|
+
: {}),
|
|
31
|
+
onViolation: nativeRules.onViolation === 'reject' ? 'reject' : 'truncate'
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function mapProtocolNode(nativeNode, options) {
|
|
35
|
+
const defaultName = 'tool';
|
|
36
|
+
const maxNameLength = 64;
|
|
37
|
+
const fallbackBase = {
|
|
38
|
+
allowedCharacters: options.allowedCharacters,
|
|
39
|
+
defaultName,
|
|
40
|
+
maxNameLength
|
|
41
|
+
};
|
|
42
|
+
const request = mapNativeRules(nativeNode?.request, fallbackBase) ?? {
|
|
43
|
+
...fallbackBase,
|
|
44
|
+
trimWhitespace: true,
|
|
45
|
+
onViolation: 'truncate',
|
|
46
|
+
...(options.forceCase ? { forceCase: options.forceCase } : {})
|
|
47
|
+
};
|
|
48
|
+
const response = mapNativeRules(nativeNode?.response, fallbackBase) ?? {
|
|
49
|
+
...fallbackBase,
|
|
50
|
+
trimWhitespace: true,
|
|
51
|
+
onViolation: 'truncate',
|
|
52
|
+
...(options.forceCase ? { forceCase: options.forceCase } : {})
|
|
53
|
+
};
|
|
54
|
+
if (options.forceCase) {
|
|
55
|
+
request.forceCase = options.forceCase;
|
|
56
|
+
response.forceCase = options.forceCase;
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
request,
|
|
60
|
+
response
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function mapNativeRegistry(nativeRegistry) {
|
|
64
|
+
return {
|
|
65
|
+
'openai-chat': mapProtocolNode(nativeRegistry['openai-chat'], {
|
|
66
|
+
allowedCharacters: ALPHA_NUMERIC
|
|
67
|
+
}),
|
|
68
|
+
'openai-responses': mapProtocolNode(nativeRegistry['openai-responses'], {
|
|
69
|
+
allowedCharacters: ALPHA_NUMERIC
|
|
70
|
+
}),
|
|
71
|
+
anthropic: mapProtocolNode(nativeRegistry.anthropic, {
|
|
72
|
+
allowedCharacters: LOWER_SNAKE,
|
|
73
|
+
forceCase: 'lower'
|
|
74
|
+
}),
|
|
75
|
+
gemini: mapProtocolNode(nativeRegistry.gemini, {
|
|
76
|
+
allowedCharacters: ALPHA_NUMERIC
|
|
77
|
+
})
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
export const DEFAULT_TOOL_GOVERNANCE_RULES = mapNativeRegistry(resolveDefaultToolGovernanceRulesWithNative());
|
|
@@ -2,7 +2,7 @@ import { isJsonObject, jsonClone } from '../types/json.js';
|
|
|
2
2
|
import { mapBridgeToolsToChat, mapChatToolsToBridge } from '../../shared/tool-mapping.js';
|
|
3
3
|
import { buildGeminiToolsFromBridge, prepareGeminiToolsForBridge } from '../../shared/gemini-tool-utils.js';
|
|
4
4
|
import { mapAnthropicToolsToChat, mapChatToolsToAnthropicTools } from '../../shared/anthropic-message-utils.js';
|
|
5
|
-
import { convertBridgeInputToChatMessages, convertMessagesToBridgeInput } from '../../
|
|
5
|
+
import { convertBridgeInputToChatMessages, convertMessagesToBridgeInput } from '../../bridge-message-utils.js';
|
|
6
6
|
import { resolveHubProtocolSpec } from '../policy/protocol-spec.js';
|
|
7
7
|
import { normalizeProviderProtocolTokenWithNative } from '../../../router/virtual-router/engine-selection/native-hub-pipeline-req-inbound-semantics.js';
|
|
8
8
|
function clampSampleRate(value) {
|
|
@@ -19,9 +19,8 @@ export * from './shared/tooling.js';
|
|
|
19
19
|
export * from '../guidance/index.js';
|
|
20
20
|
export * from './shared/tool-mapping.js';
|
|
21
21
|
export * from './shared/reasoning-mapping.js';
|
|
22
|
-
export * from './
|
|
22
|
+
export * from './args-mapping.js';
|
|
23
23
|
export * from './shared/text-markup-normalizer.js';
|
|
24
|
-
export * from './shared/tool-canonicalizer.js';
|
|
25
24
|
export * from './shared/tool-governor.js';
|
|
26
25
|
export { governTools } from './shared/tool-governor.js';
|
|
27
26
|
export * from './shared/streaming-text-extractor.js';
|
package/dist/conversion/index.js
CHANGED
|
@@ -19,9 +19,8 @@ export * from './shared/tooling.js';
|
|
|
19
19
|
export * from '../guidance/index.js';
|
|
20
20
|
export * from './shared/tool-mapping.js';
|
|
21
21
|
export * from './shared/reasoning-mapping.js';
|
|
22
|
-
export * from './
|
|
22
|
+
export * from './args-mapping.js';
|
|
23
23
|
export * from './shared/text-markup-normalizer.js';
|
|
24
|
-
export * from './shared/tool-canonicalizer.js';
|
|
25
24
|
export * from './shared/tool-governor.js';
|
|
26
25
|
export { governTools } from './shared/tool-governor.js';
|
|
27
26
|
export * from './shared/streaming-text-extractor.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Shared JSON-ish parsing helpers
|
|
2
|
-
import { parseLenientJsonishWithNative, repairArgumentsToStringWithNative } from '
|
|
2
|
+
import { parseLenientJsonishWithNative, repairArgumentsToStringWithNative } from '../router/virtual-router/engine-selection/native-shared-conversion-semantics.js';
|
|
3
3
|
export function tryParseJson(s) {
|
|
4
4
|
if (typeof s !== 'string')
|
|
5
5
|
return s;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { injectMcpToolsForChatWithNative, injectMcpToolsForResponsesWithNative } from '
|
|
1
|
+
import { injectMcpToolsForChatWithNative, injectMcpToolsForResponsesWithNative } from '../router/virtual-router/engine-selection/native-shared-conversion-semantics.js';
|
|
2
2
|
export function injectMcpToolsForChat(tools, discoveredServers) {
|
|
3
3
|
return injectMcpToolsForChatWithNative(tools, discoveredServers);
|
|
4
4
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { isJsonObject, jsonClone } from '
|
|
2
|
-
import { encodeMetadataPassthroughWithNative, extractMetadataPassthroughWithNative } from '
|
|
1
|
+
import { isJsonObject, jsonClone } from './hub/types/json.js';
|
|
2
|
+
import { encodeMetadataPassthroughWithNative, extractMetadataPassthroughWithNative } from '../router/virtual-router/engine-selection/native-shared-conversion-semantics.js';
|
|
3
3
|
export function encodeMetadataPassthrough(parameters, options) {
|
|
4
4
|
return encodeMetadataPassthroughWithNative(parameters, options.prefix, options.keys);
|
|
5
5
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Resolve payload budget (bytes) for a given model from host app config, with safety headroom.
|
|
2
|
+
import { UnifiedConfig } from '../config-unified/unified-config.js';
|
|
3
|
+
import { enforceChatBudgetWithNative, resolveBudgetForModelWithNative } from '../router/virtual-router/engine-selection/native-shared-conversion-semantics.js';
|
|
4
|
+
export function resolveBudgetForModelSync(modelId) {
|
|
5
|
+
let viaFacade = null;
|
|
6
|
+
try {
|
|
7
|
+
const resolved = UnifiedConfig.getContextBudgetForModel(modelId);
|
|
8
|
+
if (resolved && typeof resolved.allowedBytes === 'number') {
|
|
9
|
+
viaFacade = resolved;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
// ignore facade errors and fallback
|
|
14
|
+
}
|
|
15
|
+
if (viaFacade) {
|
|
16
|
+
return viaFacade;
|
|
17
|
+
}
|
|
18
|
+
return resolveBudgetForModelWithNative(modelId, null);
|
|
19
|
+
}
|
|
20
|
+
export const resolveBudgetForModel = async (modelId) => resolveBudgetForModelSync(modelId);
|
|
21
|
+
// Apply payload budget enforcement to an OpenAI Chat-shaped request object in-place.
|
|
22
|
+
// Strategy (deterministic, minimal):
|
|
23
|
+
// 1) Truncate the first system message to RCC_SYSTEM_TEXT_LIMIT (default 8192 chars).
|
|
24
|
+
// 2) Remove assistant messages that have no tool_calls and empty/whitespace content.
|
|
25
|
+
// 3) Iteratively clamp tool role message content down to fit allowedBytes.
|
|
26
|
+
// 4) If仍超限,轻度收紧 assistant 文本(不移除,仅截断)。
|
|
27
|
+
export function enforceChatBudget(chat, modelId) {
|
|
28
|
+
try {
|
|
29
|
+
if (!chat || typeof chat !== 'object')
|
|
30
|
+
return chat;
|
|
31
|
+
const messages = Array.isArray(chat.messages) ? chat.messages : [];
|
|
32
|
+
if (!messages.length)
|
|
33
|
+
return chat;
|
|
34
|
+
const budget = resolveBudgetForModelSync(modelId || 'unknown');
|
|
35
|
+
const allowed = Math.max(1024, Number(budget.allowedBytes || 200000));
|
|
36
|
+
const sysLimit = (() => {
|
|
37
|
+
const raw = process?.env?.RCC_SYSTEM_TEXT_LIMIT;
|
|
38
|
+
const n = Number(raw);
|
|
39
|
+
return Number.isFinite(n) && n >= 0 ? n : 8192;
|
|
40
|
+
})();
|
|
41
|
+
return enforceChatBudgetWithNative(chat, allowed, sysLimit);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
// ignore budget errors
|
|
45
|
+
}
|
|
46
|
+
return chat;
|
|
47
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const OPENAI_CHAT_ALLOWED_FIELDS: readonly string[];
|
|
2
|
+
export declare const ANTHROPIC_ALLOWED_FIELDS: readonly string[];
|
|
3
|
+
export declare const OPENAI_RESPONSES_ALLOWED_FIELDS: readonly string[];
|
|
4
|
+
export declare const GEMINI_ALLOWED_FIELDS: readonly string[];
|
|
5
|
+
export declare const OPENAI_RESPONSES_PARAMETERS_WRAPPER_ALLOW_KEYS: readonly string[];
|
|
6
|
+
export declare const OPENAI_CHAT_PARAMETERS_WRAPPER_ALLOW_KEYS: readonly string[];
|
|
7
|
+
export declare const ANTHROPIC_PARAMETERS_WRAPPER_ALLOW_KEYS: readonly string[];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { resolveHubProtocolAllowlistsWithNative } from '../router/virtual-router/engine-selection/native-hub-bridge-policy-semantics.js';
|
|
2
|
+
const allowlists = resolveHubProtocolAllowlistsWithNative();
|
|
3
|
+
export const OPENAI_CHAT_ALLOWED_FIELDS = Object.freeze([...allowlists.openaiChatAllowedFields]);
|
|
4
|
+
export const ANTHROPIC_ALLOWED_FIELDS = Object.freeze([...allowlists.anthropicAllowedFields]);
|
|
5
|
+
export const OPENAI_RESPONSES_ALLOWED_FIELDS = Object.freeze([...allowlists.openaiResponsesAllowedFields]);
|
|
6
|
+
export const GEMINI_ALLOWED_FIELDS = Object.freeze([...allowlists.geminiAllowedFields]);
|
|
7
|
+
export const OPENAI_RESPONSES_PARAMETERS_WRAPPER_ALLOW_KEYS = Object.freeze([...allowlists.openaiResponsesParametersWrapperAllowKeys]);
|
|
8
|
+
export const OPENAI_CHAT_PARAMETERS_WRAPPER_ALLOW_KEYS = Object.freeze([...allowlists.openaiChatParametersWrapperAllowKeys]);
|
|
9
|
+
export const ANTHROPIC_PARAMETERS_WRAPPER_ALLOW_KEYS = Object.freeze([...allowlists.anthropicParametersWrapperAllowKeys]);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ChatEnvelope } from '
|
|
2
|
-
import { type JsonObject } from '
|
|
1
|
+
import type { ChatEnvelope } from './hub/types/chat-envelope.js';
|
|
2
|
+
import { type JsonObject } from './hub/types/json.js';
|
|
3
3
|
export declare function ensureProtocolState(metadata: ChatEnvelope['metadata'], protocol: string): JsonObject;
|
|
4
4
|
export declare function getProtocolState(metadata: ChatEnvelope['metadata'] | undefined, protocol: string): JsonObject | undefined;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { isJsonObject } from '
|
|
2
|
-
import { ensureProtocolStateWithNative, getProtocolStateWithNative } from '
|
|
1
|
+
import { isJsonObject } from './hub/types/json.js';
|
|
2
|
+
import { ensureProtocolStateWithNative, getProtocolStateWithNative } from '../router/virtual-router/engine-selection/native-shared-conversion-semantics.js';
|
|
3
3
|
const PROTOCOL_STATE_KEY = 'protocolState';
|
|
4
4
|
export function ensureProtocolState(metadata, protocol) {
|
|
5
5
|
const native = ensureProtocolStateWithNative(metadata, protocol);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { buildProviderProtocolErrorWithNative } from '../router/virtual-router/engine-selection/native-shared-conversion-semantics.js';
|
|
2
|
+
export class ProviderProtocolError extends Error {
|
|
3
|
+
code;
|
|
4
|
+
protocol;
|
|
5
|
+
providerType;
|
|
6
|
+
category;
|
|
7
|
+
details;
|
|
8
|
+
constructor(message, options) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = 'ProviderProtocolError';
|
|
11
|
+
const native = buildProviderProtocolErrorWithNative({
|
|
12
|
+
message,
|
|
13
|
+
code: options.code,
|
|
14
|
+
protocol: options.protocol,
|
|
15
|
+
providerType: options.providerType,
|
|
16
|
+
category: options.category,
|
|
17
|
+
details: options.details
|
|
18
|
+
});
|
|
19
|
+
this.code = options.code;
|
|
20
|
+
this.protocol = typeof native.protocol === 'string' ? native.protocol : options.protocol;
|
|
21
|
+
this.providerType = typeof native.providerType === 'string' ? native.providerType : options.providerType;
|
|
22
|
+
this.category = native.category || options.category || 'EXTERNAL_ERROR';
|
|
23
|
+
this.details = native.details ?? options.details;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { evaluateResponsesHostPolicy } from '../responses-host-policy.js';
|
|
2
|
-
import { canonicalizeChatResponseTools } from '../../shared/tool-canonicalizer.js';
|
|
3
2
|
import { normalizeMessageReasoningTools } from '../../shared/reasoning-tool-normalizer.js';
|
|
4
|
-
import { createBridgeActionState, runBridgeActionPipeline } from '../../
|
|
5
|
-
import { resolveBridgePolicy, resolvePolicyActions } from '../../
|
|
3
|
+
import { createBridgeActionState, runBridgeActionPipeline } from '../../bridge-actions.js';
|
|
4
|
+
import { resolveBridgePolicy, resolvePolicyActions } from '../../bridge-policies.js';
|
|
6
5
|
import { buildResponsesOutputFromChat } from '../../shared/responses-output-builder.js';
|
|
7
6
|
import { consumeResponsesPayloadSnapshot, consumeResponsesPassthrough } from '../../shared/responses-reasoning-registry.js';
|
|
8
7
|
import { sanitizeResponsesFunctionName, stripInternalToolingMetadata } from '../../shared/responses-tool-utils.js';
|
|
9
|
-
import { ProviderProtocolError } from '../../
|
|
8
|
+
import { ProviderProtocolError } from '../../provider-protocol-error.js';
|
|
10
9
|
import { normalizeResponsesToolCallArgumentsForClientWithNative } from '../../../router/virtual-router/engine-selection/native-hub-pipeline-resp-semantics.js';
|
|
10
|
+
import { normalizeChatResponseReasoningToolsWithNative } from '../../../router/virtual-router/engine-selection/native-hub-bridge-action-semantics.js';
|
|
11
11
|
function isPlainObject(value) {
|
|
12
12
|
return Boolean(value && typeof value === 'object' && !Array.isArray(value));
|
|
13
13
|
}
|
|
@@ -77,6 +77,9 @@ function mergeResponseOutputItems(baseOutput, sourceOutput) {
|
|
|
77
77
|
if (isMissingResponseField(baseItem.summary) && sourceItem.summary !== undefined) {
|
|
78
78
|
baseItem.summary = deepCloneRecord({ value: sourceItem.summary }).value;
|
|
79
79
|
}
|
|
80
|
+
if (isMissingResponseField(baseItem.encrypted_content) && sourceItem.encrypted_content !== undefined) {
|
|
81
|
+
baseItem.encrypted_content = deepCloneRecord({ value: sourceItem.encrypted_content }).value;
|
|
82
|
+
}
|
|
80
83
|
return baseItem;
|
|
81
84
|
});
|
|
82
85
|
}
|
|
@@ -381,7 +384,7 @@ export function buildResponsesPayloadFromChat(payload, context) {
|
|
|
381
384
|
}
|
|
382
385
|
return mergedFallback;
|
|
383
386
|
}
|
|
384
|
-
const canonical =
|
|
387
|
+
const canonical = normalizeChatResponseReasoningToolsWithNative(response);
|
|
385
388
|
const choices = Array.isArray(canonical?.choices) ? canonical.choices : [];
|
|
386
389
|
const primaryChoice = choices[0] && typeof choices[0] === 'object' ? choices[0] : undefined;
|
|
387
390
|
const message = primaryChoice && typeof primaryChoice.message === 'object' ? primaryChoice.message : undefined;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BridgeInputItem, BridgeToolDefinition } from '../../
|
|
1
|
+
import type { BridgeInputItem, BridgeToolDefinition } from '../../types/bridge-message-types.js';
|
|
2
2
|
import type { ChatToolDefinition } from '../../hub/types/chat-envelope.js';
|
|
3
3
|
import type { JsonObject, JsonValue } from '../../hub/types/json.js';
|
|
4
4
|
import type { ToolCallIdStyle } from '../../shared/responses-tool-utils.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BridgeInputBuildResult } from '../
|
|
1
|
+
import type { BridgeInputBuildResult } from '../bridge-message-utils.js';
|
|
2
2
|
import type { BuildChatRequestResult, BuildResponsesRequestResult, ResponsesRequestContext } from './responses-openai-bridge/types.js';
|
|
3
3
|
export type { BuildChatRequestResult, BuildResponsesRequestResult, ResponsesRequestContext } from './responses-openai-bridge/types.js';
|
|
4
4
|
export declare function captureResponsesContext(payload: Record<string, unknown>, dto?: {
|
|
@@ -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>;
|