@jsonstudio/llms 0.6.1164 → 0.6.1354
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/codecs/gemini-openai-codec.d.ts +3 -1
- package/dist/conversion/codecs/gemini-openai-codec.js +10 -4
- package/dist/conversion/compat/actions/gemini-web-search.d.ts +1 -1
- package/dist/conversion/compat/actions/gemini-web-search.js +5 -2
- package/dist/conversion/compat/actions/iflow-tool-text-fallback.d.ts +12 -0
- package/dist/conversion/compat/actions/iflow-tool-text-fallback.js +199 -0
- package/dist/conversion/compat/actions/iflow-web-search.d.ts +1 -1
- package/dist/conversion/compat/actions/iflow-web-search.js +5 -2
- package/dist/conversion/hub/operation-table/semantic-mappers/anthropic-mapper.js +47 -56
- package/dist/conversion/hub/operation-table/semantic-mappers/chat-mapper.js +1 -13
- package/dist/conversion/hub/operation-table/semantic-mappers/gemini-mapper.js +523 -50
- package/dist/conversion/hub/operation-table/semantic-mappers/responses-mapper.js +18 -38
- package/dist/conversion/hub/pipeline/compat/compat-pipeline-executor.js +6 -0
- package/dist/conversion/hub/pipeline/compat/compat-types.d.ts +3 -0
- package/dist/conversion/hub/pipeline/hub-pipeline/adapter-context.d.ts +10 -0
- package/dist/conversion/hub/pipeline/hub-pipeline/adapter-context.js +134 -0
- package/dist/conversion/hub/pipeline/hub-pipeline/anthropic-alias-map.d.ts +6 -0
- package/dist/conversion/hub/pipeline/hub-pipeline/anthropic-alias-map.js +79 -0
- package/dist/conversion/hub/pipeline/hub-pipeline/apply-patch-tool-mode.d.ts +3 -0
- package/dist/conversion/hub/pipeline/hub-pipeline/apply-patch-tool-mode.js +46 -0
- package/dist/conversion/hub/pipeline/hub-pipeline/execute-chat-process-entry.d.ts +8 -0
- package/dist/conversion/hub/pipeline/hub-pipeline/execute-chat-process-entry.js +366 -0
- package/dist/conversion/hub/pipeline/hub-pipeline/execute-request-stage.d.ts +9 -0
- package/dist/conversion/hub/pipeline/hub-pipeline/execute-request-stage.js +384 -0
- package/dist/conversion/hub/pipeline/hub-pipeline/node-results.d.ts +3 -0
- package/dist/conversion/hub/pipeline/hub-pipeline/node-results.js +14 -0
- package/dist/conversion/hub/pipeline/hub-pipeline/payload-normalize.d.ts +2 -0
- package/dist/conversion/hub/pipeline/hub-pipeline/payload-normalize.js +144 -0
- package/dist/conversion/hub/pipeline/hub-pipeline/policy.d.ts +4 -0
- package/dist/conversion/hub/pipeline/hub-pipeline/policy.js +32 -0
- package/dist/conversion/hub/pipeline/hub-pipeline/protocol.d.ts +8 -0
- package/dist/conversion/hub/pipeline/hub-pipeline/protocol.js +63 -0
- package/dist/conversion/hub/pipeline/hub-pipeline/resolve-protocol-hooks.d.ts +2 -0
- package/dist/conversion/hub/pipeline/hub-pipeline/resolve-protocol-hooks.js +43 -0
- package/dist/conversion/hub/pipeline/hub-pipeline/semantic-gate.d.ts +1 -0
- package/dist/conversion/hub/pipeline/hub-pipeline/semantic-gate.js +29 -0
- package/dist/conversion/hub/pipeline/hub-pipeline/servertool-runtime-config.d.ts +2 -0
- package/dist/conversion/hub/pipeline/hub-pipeline/servertool-runtime-config.js +16 -0
- package/dist/conversion/hub/pipeline/hub-pipeline/types.d.ts +116 -0
- package/dist/conversion/hub/pipeline/hub-pipeline/types.js +1 -0
- package/dist/conversion/hub/pipeline/hub-pipeline.d.ts +3 -95
- package/dist/conversion/hub/pipeline/hub-pipeline.js +19 -1281
- package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage1_format_parse/index.js +1 -1
- package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage2_semantic_map/index.d.ts +7 -0
- package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage2_semantic_map/index.js +65 -1
- package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/index.js +25 -22
- package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage1_semantic_map/index.js +1 -1
- package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage2_format_build/index.d.ts +1 -1
- package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage2_format_build/index.js +2 -2
- package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage3_compat/index.js +2 -2
- package/dist/conversion/hub/pipeline/stages/req_process/req_process_stage1_tool_governance/index.js +1 -1
- package/dist/conversion/hub/pipeline/stages/req_process/req_process_stage2_route_select/index.js +1 -1
- package/dist/conversion/hub/pipeline/stages/resp_inbound/resp_inbound_stage1_sse_decode/index.js +11 -11
- package/dist/conversion/hub/pipeline/stages/resp_inbound/resp_inbound_stage2_format_parse/index.js +1 -1
- package/dist/conversion/hub/pipeline/stages/resp_inbound/resp_inbound_stage3_semantic_map/index.d.ts +1 -0
- package/dist/conversion/hub/pipeline/stages/resp_inbound/resp_inbound_stage3_semantic_map/index.js +4 -2
- package/dist/conversion/hub/pipeline/stages/resp_outbound/resp_outbound_stage1_client_remap/index.d.ts +1 -0
- package/dist/conversion/hub/pipeline/stages/resp_outbound/resp_outbound_stage1_client_remap/index.js +17 -9
- package/dist/conversion/hub/pipeline/stages/resp_outbound/resp_outbound_stage2_sse_stream/index.js +2 -2
- package/dist/conversion/hub/pipeline/stages/resp_process/resp_process_stage1_tool_governance/index.js +40 -2
- package/dist/conversion/hub/pipeline/stages/resp_process/resp_process_stage2_finalize/index.js +1 -1
- package/dist/conversion/hub/pipeline/target-utils.js +9 -5
- package/dist/conversion/hub/process/chat-process.js +256 -16
- package/dist/conversion/hub/response/provider-response.d.ts +8 -0
- package/dist/conversion/hub/response/provider-response.js +85 -27
- package/dist/conversion/hub/response/response-mappers.d.ts +10 -3
- package/dist/conversion/hub/response/response-mappers.js +30 -6
- package/dist/conversion/hub/response/response-runtime.js +4 -38
- package/dist/conversion/hub/snapshot-recorder.js +5 -1
- package/dist/conversion/hub/standardized-bridge.js +23 -15
- package/dist/conversion/pipeline/codecs/v2/anthropic-openai-pipeline.js +36 -5
- package/dist/conversion/responses/responses-openai-bridge.js +20 -4
- package/dist/conversion/shared/gemini-tool-utils.d.ts +8 -1
- package/dist/conversion/shared/gemini-tool-utils.js +580 -108
- package/dist/conversion/shared/jsonish.js +1 -1
- package/dist/conversion/shared/mcp-injection.js +67 -33
- package/dist/conversion/shared/openai-finalizer.js +2 -1
- package/dist/conversion/shared/openai-message-normalize.js +76 -21
- package/dist/conversion/shared/responses-output-builder.js +6 -0
- package/dist/conversion/shared/runtime-metadata.d.ts +7 -0
- package/dist/conversion/shared/runtime-metadata.js +23 -0
- package/dist/conversion/shared/text-markup-normalizer.d.ts +2 -0
- package/dist/conversion/shared/text-markup-normalizer.js +284 -4
- package/dist/conversion/shared/tool-canonicalizer.js +2 -1
- package/dist/conversion/shared/tool-governor.js +3 -3
- package/dist/filters/engine.js +5 -5
- package/dist/filters/special/request-tool-list-filter.js +194 -60
- package/dist/filters/special/request-tools-normalize.js +1 -1
- package/dist/filters/special/response-tool-text-canonicalize.d.ts +4 -7
- package/dist/filters/special/response-tool-text-canonicalize.js +7 -35
- package/dist/filters/special/tool-filter-hooks.js +58 -62
- package/dist/guidance/index.js +5 -1
- package/dist/http/sse-response.js +6 -6
- package/dist/router/virtual-router/bootstrap.js +65 -5
- package/dist/router/virtual-router/context-advisor.d.ts +4 -0
- package/dist/router/virtual-router/context-advisor.js +3 -0
- package/dist/router/virtual-router/context-weighted.d.ts +31 -0
- package/dist/router/virtual-router/context-weighted.js +54 -0
- package/dist/router/virtual-router/engine-health.d.ts +1 -1
- package/dist/router/virtual-router/engine-health.js +11 -110
- package/dist/router/virtual-router/engine-selection/alias-selection.d.ts +15 -0
- package/dist/router/virtual-router/engine-selection/alias-selection.js +156 -0
- package/dist/router/virtual-router/engine-selection/context-weight-multipliers.d.ts +11 -0
- package/dist/router/virtual-router/engine-selection/context-weight-multipliers.js +23 -0
- package/dist/router/virtual-router/engine-selection/direct-provider-model.d.ts +9 -0
- package/dist/router/virtual-router/engine-selection/direct-provider-model.js +49 -0
- package/dist/router/virtual-router/engine-selection/instruction-target.d.ts +6 -0
- package/dist/router/virtual-router/engine-selection/instruction-target.js +54 -0
- package/dist/router/virtual-router/engine-selection/key-parsing.d.ts +8 -0
- package/dist/router/virtual-router/engine-selection/key-parsing.js +64 -0
- package/dist/router/virtual-router/engine-selection/route-utils.d.ts +12 -0
- package/dist/router/virtual-router/engine-selection/route-utils.js +150 -0
- package/dist/router/virtual-router/engine-selection/routing-state-filter.d.ts +4 -0
- package/dist/router/virtual-router/engine-selection/routing-state-filter.js +50 -0
- package/dist/router/virtual-router/engine-selection/selection-deps.d.ts +39 -0
- package/dist/router/virtual-router/engine-selection/selection-deps.js +1 -0
- package/dist/router/virtual-router/engine-selection/sticky-pool.d.ts +11 -0
- package/dist/router/virtual-router/engine-selection/sticky-pool.js +109 -0
- package/dist/router/virtual-router/engine-selection/tier-priority.d.ts +12 -0
- package/dist/router/virtual-router/engine-selection/tier-priority.js +55 -0
- package/dist/router/virtual-router/engine-selection/tier-selection-select.d.ts +22 -0
- package/dist/router/virtual-router/engine-selection/tier-selection-select.js +400 -0
- package/dist/router/virtual-router/engine-selection/tier-selection.d.ts +3 -0
- package/dist/router/virtual-router/engine-selection/tier-selection.js +225 -0
- package/dist/router/virtual-router/engine-selection.d.ts +4 -30
- package/dist/router/virtual-router/engine-selection.js +10 -815
- package/dist/router/virtual-router/engine.d.ts +1 -0
- package/dist/router/virtual-router/engine.js +55 -10
- package/dist/router/virtual-router/routing-instructions.js +6 -1
- package/dist/router/virtual-router/stop-message-state-sync.d.ts +5 -0
- package/dist/router/virtual-router/stop-message-state-sync.js +6 -14
- package/dist/router/virtual-router/types.d.ts +53 -1
- package/dist/servertool/clock/config.d.ts +8 -0
- package/dist/servertool/clock/config.js +22 -0
- package/dist/servertool/clock/log.d.ts +3 -0
- package/dist/servertool/clock/log.js +13 -0
- package/dist/servertool/clock/task-store.d.ts +1 -1
- package/dist/servertool/clock/task-store.js +1 -1
- package/dist/servertool/clock/tasks.js +1 -1
- package/dist/servertool/engine.js +146 -21
- package/dist/servertool/handlers/clock-auto.js +11 -6
- package/dist/servertool/handlers/clock.js +36 -10
- package/dist/servertool/handlers/followup-request-builder.js +8 -2
- package/dist/servertool/handlers/gemini-empty-reply-continue.js +15 -9
- package/dist/servertool/handlers/iflow-model-error-retry.js +6 -4
- package/dist/servertool/handlers/recursive-detection-guard.js +4 -2
- package/dist/servertool/handlers/stop-message-auto.js +100 -10
- package/dist/servertool/handlers/vision.js +4 -1
- package/dist/servertool/handlers/web-search.js +3 -1
- package/dist/servertool/pending-session.d.ts +19 -0
- package/dist/servertool/pending-session.js +97 -0
- package/dist/servertool/reenter-backend.js +5 -3
- package/dist/servertool/server-side-tools.js +235 -6
- package/dist/servertool/types.d.ts +13 -0
- package/dist/sse/json-to-sse/event-generators/responses.js +1 -1
- package/dist/sse/shared/chat-serializer.js +2 -2
- package/dist/sse/shared/constants.js +1 -1
- package/dist/sse/sse-to-json/anthropic-sse-to-json-converter.d.ts +7 -1
- package/dist/sse/sse-to-json/builders/response-builder.js +16 -0
- package/dist/sse/sse-to-json/responses-sse-to-json-converter.d.ts +1 -1
- package/dist/tools/apply-patch/execution-capturer.js +1 -1
- package/dist/tools/exec-command/normalize.js +4 -0
- package/dist/tools/exec-command/regression-capturer.js +1 -1
- package/package.json +10 -5
|
@@ -59,40 +59,9 @@ function createToolNameResolver(options) {
|
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
61
|
function extractAliasMapFromChatPayload(payload) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (candidate && typeof candidate === 'object') {
|
|
66
|
-
const serialized = {};
|
|
67
|
-
for (const [key, value] of Object.entries(candidate)) {
|
|
68
|
-
if (typeof key === 'string' && typeof value === 'string') {
|
|
69
|
-
const trimmedKey = key.trim();
|
|
70
|
-
const trimmedValue = value.trim();
|
|
71
|
-
if (trimmedKey.length && trimmedValue.length) {
|
|
72
|
-
serialized[trimmedKey] = trimmedValue;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
if (Object.keys(serialized).length) {
|
|
77
|
-
return serialized;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
if (payload?.anthropicToolNameMap && typeof payload.anthropicToolNameMap === 'object') {
|
|
82
|
-
const map = {};
|
|
83
|
-
for (const [key, value] of Object.entries(payload.anthropicToolNameMap)) {
|
|
84
|
-
if (typeof key === 'string' && typeof value === 'string') {
|
|
85
|
-
const trimmedKey = key.trim();
|
|
86
|
-
const trimmedValue = value.trim();
|
|
87
|
-
if (trimmedKey.length && trimmedValue.length) {
|
|
88
|
-
map[trimmedKey] = trimmedValue;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
if (Object.keys(map).length) {
|
|
93
|
-
return map;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
62
|
+
// Deprecated: tool-name alias maps are mappable semantics and must be carried via requestSemantics
|
|
63
|
+
// (ChatSemantics.tools.toolNameAliasMap). Do not embed them inside response payload fields/metadata.
|
|
64
|
+
void payload;
|
|
96
65
|
return undefined;
|
|
97
66
|
}
|
|
98
67
|
function createToolAliasSerializer(aliasMap) {
|
|
@@ -285,9 +254,6 @@ export function buildOpenAIChatFromAnthropicMessage(payload, options) {
|
|
|
285
254
|
chatResponse.request_id = chatResponse.id;
|
|
286
255
|
}
|
|
287
256
|
}
|
|
288
|
-
if (Object.keys(aliasCollector).length && !chatResponse.anthropicToolNameMap) {
|
|
289
|
-
chatResponse.anthropicToolNameMap = aliasCollector;
|
|
290
|
-
}
|
|
291
257
|
return chatResponse;
|
|
292
258
|
}
|
|
293
259
|
function mapShellCommandArgsForAnthropic(raw) {
|
|
@@ -326,7 +292,7 @@ function mapShellCommandArgsForAnthropic(raw) {
|
|
|
326
292
|
export function buildAnthropicResponseFromChat(chatResponse, options) {
|
|
327
293
|
const choice = Array.isArray(chatResponse?.choices) ? chatResponse.choices[0] : undefined;
|
|
328
294
|
const message = choice && typeof choice === 'object' ? choice.message : undefined;
|
|
329
|
-
const aliasMap = options?.aliasMap
|
|
295
|
+
const aliasMap = options?.aliasMap;
|
|
330
296
|
const outboundAliasSerializer = createToolAliasSerializer(aliasMap);
|
|
331
297
|
if (message) {
|
|
332
298
|
try {
|
|
@@ -38,9 +38,13 @@ export function createSnapshotRecorder(context, endpoint) {
|
|
|
38
38
|
}
|
|
39
39
|
const STAGE_KIND_MAP = {
|
|
40
40
|
req_inbound_stage2_semantic_map: 'request_inbound',
|
|
41
|
+
'chat_process.req.stage2.semantic_map': 'request_inbound',
|
|
41
42
|
req_outbound_stage1_semantic_map: 'request_outbound',
|
|
43
|
+
'chat_process.req.stage6.outbound.semantic_map': 'request_outbound',
|
|
42
44
|
resp_inbound_stage3_semantic_map: 'response_inbound',
|
|
43
|
-
|
|
45
|
+
'chat_process.resp.stage4.semantic_map_to_chat': 'response_inbound',
|
|
46
|
+
resp_outbound_stage1_client_remap: 'response_outbound',
|
|
47
|
+
'chat_process.resp.stage9.client_remap': 'response_outbound'
|
|
44
48
|
};
|
|
45
49
|
function normalizeStagePayload(stage, payload) {
|
|
46
50
|
const kind = STAGE_KIND_MAP[stage];
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isJsonObject, jsonClone } from './types/json.js';
|
|
2
|
+
import { cloneRuntimeMetadata } from '../shared/runtime-metadata.js';
|
|
2
3
|
const HUB_CAPTURE_KEY = '__hub_capture';
|
|
3
4
|
export function chatEnvelopeToStandardized(chat, options) {
|
|
4
5
|
const parameters = { ...(chat.parameters ?? {}) };
|
|
@@ -14,9 +15,6 @@ export function chatEnvelopeToStandardized(chat, options) {
|
|
|
14
15
|
if (isJsonObject(chat.metadata?.providerMetadata)) {
|
|
15
16
|
hubState.providerMetadata = chat.metadata?.providerMetadata;
|
|
16
17
|
}
|
|
17
|
-
if (isJsonObject(chat.metadata?.extraFields)) {
|
|
18
|
-
hubState.extraFields = chat.metadata?.extraFields;
|
|
19
|
-
}
|
|
20
18
|
if (isJsonObject(chat.metadata?.protocolState)) {
|
|
21
19
|
hubState.protocolState = chat.metadata?.protocolState;
|
|
22
20
|
}
|
|
@@ -65,17 +63,31 @@ export function standardizedToChatEnvelope(request, options) {
|
|
|
65
63
|
const sourceMeta = (request.metadata && typeof request.metadata === 'object'
|
|
66
64
|
? request.metadata
|
|
67
65
|
: undefined);
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
66
|
+
// E1: internal runtime metadata must live under the __rt carrier (never as top-level metadata keys).
|
|
67
|
+
// Merge runtime hints from AdapterContext + StandardizedRequest.metadata (legacy/compat).
|
|
68
|
+
try {
|
|
69
|
+
const merged = {
|
|
70
|
+
...(cloneRuntimeMetadata(adapterContext) ?? {}),
|
|
71
|
+
...(cloneRuntimeMetadata(sourceMeta ?? null) ?? {})
|
|
72
|
+
};
|
|
73
|
+
if (sourceMeta && typeof sourceMeta === 'object') {
|
|
74
|
+
if (sourceMeta.webSearch && typeof sourceMeta.webSearch === 'object' && merged.webSearch === undefined) {
|
|
75
|
+
merged.webSearch = sourceMeta.webSearch;
|
|
76
|
+
}
|
|
77
|
+
if (sourceMeta.forceWebSearch === true && merged.forceWebSearch === undefined) {
|
|
78
|
+
merged.forceWebSearch = true;
|
|
79
|
+
}
|
|
80
|
+
if (sourceMeta.forceVision === true && merged.forceVision === undefined) {
|
|
81
|
+
merged.forceVision = true;
|
|
82
|
+
}
|
|
74
83
|
}
|
|
75
|
-
if (
|
|
76
|
-
metadata.
|
|
84
|
+
if (Object.keys(merged).length) {
|
|
85
|
+
metadata.__rt = merged;
|
|
77
86
|
}
|
|
78
87
|
}
|
|
88
|
+
catch {
|
|
89
|
+
// best-effort
|
|
90
|
+
}
|
|
79
91
|
if (typeof adapterContext.toolCallIdStyle === 'string' && adapterContext.toolCallIdStyle.length) {
|
|
80
92
|
metadata.toolCallIdStyle = adapterContext.toolCallIdStyle;
|
|
81
93
|
}
|
|
@@ -85,9 +97,6 @@ export function standardizedToChatEnvelope(request, options) {
|
|
|
85
97
|
if (hubState?.providerMetadata) {
|
|
86
98
|
metadata.providerMetadata = hubState.providerMetadata;
|
|
87
99
|
}
|
|
88
|
-
if (hubState?.extraFields) {
|
|
89
|
-
metadata.extraFields = hubState.extraFields;
|
|
90
|
-
}
|
|
91
100
|
if (hubState?.protocolState) {
|
|
92
101
|
metadata.protocolState = hubState.protocolState;
|
|
93
102
|
}
|
|
@@ -280,6 +289,5 @@ function hubStateContextPopulated(state) {
|
|
|
280
289
|
return Boolean(state.context ||
|
|
281
290
|
(state.missingFields && state.missingFields.length) ||
|
|
282
291
|
state.providerMetadata ||
|
|
283
|
-
state.extraFields ||
|
|
284
292
|
(state.protocolState && Object.keys(state.protocolState).length));
|
|
285
293
|
}
|
|
@@ -31,6 +31,38 @@ function coerceAliasMap(candidate) {
|
|
|
31
31
|
}
|
|
32
32
|
return populated ? result : undefined;
|
|
33
33
|
}
|
|
34
|
+
function readAliasMapFromSemantics(semantics) {
|
|
35
|
+
if (!semantics || typeof semantics !== 'object' || Array.isArray(semantics)) {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
const toolsNode = semantics.tools;
|
|
39
|
+
if (!toolsNode || typeof toolsNode !== 'object' || Array.isArray(toolsNode)) {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
const candidate = toolsNode.toolNameAliasMap ??
|
|
43
|
+
toolsNode.toolAliasMap;
|
|
44
|
+
return coerceAliasMap(candidate);
|
|
45
|
+
}
|
|
46
|
+
function ensureAliasMapInSemantics(chatEnvelope, aliasMap) {
|
|
47
|
+
if (!chatEnvelope || typeof chatEnvelope !== 'object') {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const semantics = chatEnvelope.semantics && typeof chatEnvelope.semantics === 'object' && !Array.isArray(chatEnvelope.semantics)
|
|
51
|
+
? chatEnvelope.semantics
|
|
52
|
+
: (() => {
|
|
53
|
+
chatEnvelope.semantics = {};
|
|
54
|
+
return chatEnvelope.semantics;
|
|
55
|
+
})();
|
|
56
|
+
const toolsNode = semantics.tools && typeof semantics.tools === 'object' && !Array.isArray(semantics.tools)
|
|
57
|
+
? semantics.tools
|
|
58
|
+
: (() => {
|
|
59
|
+
semantics.tools = {};
|
|
60
|
+
return semantics.tools;
|
|
61
|
+
})();
|
|
62
|
+
if (!toolsNode.toolNameAliasMap && !toolsNode.toolAliasMap) {
|
|
63
|
+
toolsNode.toolNameAliasMap = { ...aliasMap };
|
|
64
|
+
}
|
|
65
|
+
}
|
|
34
66
|
function createAnthropicHooks() {
|
|
35
67
|
const formatAdapter = new AnthropicFormatAdapter();
|
|
36
68
|
const semanticMapper = new AnthropicSemanticMapper();
|
|
@@ -45,11 +77,10 @@ function createAnthropicHooks() {
|
|
|
45
77
|
});
|
|
46
78
|
const formatEnvelope = await formatAdapter.parseRequest(wire, adapterContext);
|
|
47
79
|
const chatEnvelope = await semanticMapper.toChat(formatEnvelope, adapterContext);
|
|
48
|
-
const aliasMap =
|
|
49
|
-
coerceAliasMap(chatEnvelope.metadata?.anthropicToolNameMap);
|
|
80
|
+
const aliasMap = readAliasMapFromSemantics(chatEnvelope.semantics);
|
|
50
81
|
if (aliasMap) {
|
|
51
|
-
|
|
52
|
-
|
|
82
|
+
// A1: tool alias map is mappable semantics; keep it in chat.semantics (never metadata).
|
|
83
|
+
ensureAliasMapInSemantics(chatEnvelope, aliasMap);
|
|
53
84
|
}
|
|
54
85
|
const canonical = chatEnvelopeToStandardized(chatEnvelope, {
|
|
55
86
|
adapterContext,
|
|
@@ -61,7 +92,7 @@ function createAnthropicHooks() {
|
|
|
61
92
|
},
|
|
62
93
|
outbound: {
|
|
63
94
|
serialize: async ({ canonical, context }) => {
|
|
64
|
-
const aliasMap =
|
|
95
|
+
const aliasMap = readAliasMapFromSemantics(canonical.semantics);
|
|
65
96
|
const anthropicPayload = buildAnthropicFromOpenAIChat(canonical, {
|
|
66
97
|
toolNameMap: aliasMap,
|
|
67
98
|
requestId: context.requestId
|
|
@@ -4,6 +4,7 @@ import { convertMessagesToBridgeInput, convertBridgeInputToChatMessages } from '
|
|
|
4
4
|
import { createToolCallIdTransformer, enforceToolCallIdStyle, resolveToolCallIdStyle, stripInternalToolingMetadata, sanitizeResponsesFunctionName } from '../shared/responses-tool-utils.js';
|
|
5
5
|
import { mapBridgeToolsToChat, mapChatToolsToBridge } from '../shared/tool-mapping.js';
|
|
6
6
|
import { ProviderProtocolError } from '../shared/errors.js';
|
|
7
|
+
import { readRuntimeMetadata } from '../shared/runtime-metadata.js';
|
|
7
8
|
// --- Utilities (ported strictly) ---
|
|
8
9
|
import { canonicalizeChatResponseTools } from '../shared/tool-canonicalizer.js';
|
|
9
10
|
import { normalizeMessageReasoningTools } from '../shared/reasoning-tool-normalizer.js';
|
|
@@ -249,10 +250,25 @@ function mergeResponsesTools(originalTools, fromChat) {
|
|
|
249
250
|
export function buildResponsesRequestFromChat(payload, ctx, extras) {
|
|
250
251
|
const chat = unwrapData(payload);
|
|
251
252
|
const out = {};
|
|
252
|
-
const forceWebSearch =
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
253
|
+
const forceWebSearch = (() => {
|
|
254
|
+
if (!ctx || typeof ctx !== 'object') {
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
const metaCarrier = ctx.metadata && typeof ctx.metadata === 'object'
|
|
258
|
+
? ctx.metadata
|
|
259
|
+
: undefined;
|
|
260
|
+
const rt = readRuntimeMetadata(metaCarrier ?? null);
|
|
261
|
+
if (rt && typeof rt === 'object') {
|
|
262
|
+
if (rt.forceWebSearch === true) {
|
|
263
|
+
return true;
|
|
264
|
+
}
|
|
265
|
+
const webSearch = rt.webSearch;
|
|
266
|
+
if (webSearch && typeof webSearch === 'object' && webSearch.force === true) {
|
|
267
|
+
return true;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
return false;
|
|
271
|
+
})();
|
|
256
272
|
// 基本字段
|
|
257
273
|
out.model = chat.model;
|
|
258
274
|
// tools: 反向映射为 ResponsesToolDefinition 形状
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import type { BridgeToolDefinition } from './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
|
+
export declare function isGeminiFunctionNameSafe(name: string): boolean;
|
|
5
|
+
export declare function sanitizeGeminiFunctionName(name: string, options?: {
|
|
6
|
+
maxLen?: number;
|
|
7
|
+
}): string;
|
|
8
|
+
export type GeminiToolSchemaMode = 'default' | 'antigravity';
|
|
4
9
|
export declare function prepareGeminiToolsForBridge(rawTools: JsonValue | undefined, missing?: MissingField[]): BridgeToolDefinition[] | undefined;
|
|
5
|
-
export declare function buildGeminiToolsFromBridge(defs: BridgeToolDefinition[] | undefined
|
|
10
|
+
export declare function buildGeminiToolsFromBridge(defs: BridgeToolDefinition[] | undefined, options?: {
|
|
11
|
+
mode?: GeminiToolSchemaMode;
|
|
12
|
+
}): JsonObject[] | undefined;
|