@jsonstudio/llms 0.6.3409 → 0.6.3541
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/anthropic-openai-codec.d.ts +12 -3
- package/dist/conversion/codecs/anthropic-openai-codec.js +32 -92
- package/dist/conversion/codecs/gemini-openai-codec.d.ts +6 -5
- package/dist/conversion/codecs/gemini-openai-codec.js +48 -685
- package/dist/conversion/codecs/openai-openai-codec.d.ts +1 -1
- package/dist/conversion/codecs/openai-openai-codec.js +34 -100
- package/dist/conversion/codecs/responses-openai-codec.d.ts +1 -1
- package/dist/conversion/codecs/responses-openai-codec.js +47 -159
- package/dist/conversion/compat/actions/anthropic-claude-code-system-prompt.d.ts +2 -6
- package/dist/conversion/compat/actions/anthropic-claude-code-system-prompt.js +29 -245
- package/dist/conversion/compat/actions/anthropic-claude-code-user-id.d.ts +3 -0
- package/dist/conversion/compat/actions/anthropic-claude-code-user-id.js +30 -0
- package/dist/conversion/compat/actions/antigravity-thought-signature-prepare.js +21 -232
- package/dist/conversion/compat/actions/deepseek-web-request.js +41 -276
- package/dist/conversion/compat/actions/deepseek-web-response.js +117 -855
- package/dist/conversion/compat/actions/gemini-cli-request.d.ts +1 -1
- package/dist/conversion/compat/actions/gemini-cli-request.js +20 -613
- package/dist/conversion/compat/actions/gemini-web-search.d.ts +1 -15
- package/dist/conversion/compat/actions/gemini-web-search.js +22 -69
- package/dist/conversion/compat/actions/glm-tool-extraction.d.ts +3 -2
- package/dist/conversion/compat/actions/glm-tool-extraction.js +28 -257
- package/dist/conversion/compat/actions/iflow-tool-text-fallback.d.ts +0 -8
- package/dist/conversion/compat/actions/iflow-tool-text-fallback.js +24 -206
- package/dist/conversion/compat/actions/qwen-transform.d.ts +3 -2
- package/dist/conversion/compat/actions/qwen-transform.js +30 -271
- package/dist/conversion/compat/actions/tool-text-request-guidance.js +3 -173
- package/dist/conversion/compat/actions/universal-shape-filter.d.ts +6 -23
- package/dist/conversion/compat/actions/universal-shape-filter.js +4 -383
- package/dist/conversion/hub/pipeline/compat/native-adapter-context.js +1 -0
- package/dist/conversion/pipeline/codecs/v2/anthropic-openai-pipeline.d.ts +1 -2
- package/dist/conversion/pipeline/codecs/v2/anthropic-openai-pipeline.js +50 -104
- package/dist/conversion/pipeline/codecs/v2/openai-openai-pipeline.js +12 -10
- package/dist/conversion/pipeline/codecs/v2/responses-openai-pipeline.d.ts +0 -2
- package/dist/conversion/pipeline/codecs/v2/responses-openai-pipeline.js +46 -67
- package/dist/conversion/pipeline/codecs/v2/shared/openai-chat-helpers.js +15 -40
- package/dist/conversion/responses/responses-openai-bridge/response-payload.js +47 -348
- package/dist/conversion/responses/responses-openai-bridge.js +129 -611
- package/dist/conversion/shared/chat-output-normalizer.js +6 -0
- package/dist/conversion/shared/chat-request-filters.js +1 -1
- package/dist/conversion/shared/output-content-normalizer.js +10 -0
- package/dist/conversion/shared/responses-conversation-store.js +22 -135
- package/dist/conversion/shared/responses-output-builder.d.ts +0 -2
- package/dist/conversion/shared/responses-output-builder.js +28 -318
- package/dist/conversion/shared/responses-response-utils.js +35 -86
- package/dist/conversion/shared/streaming-text-extractor.d.ts +1 -2
- package/dist/conversion/shared/streaming-text-extractor.js +13 -14
- package/dist/native/router_hotpath_napi.node +0 -0
- package/dist/quota/quota-state.js +29 -7
- package/dist/quota/types.d.ts +1 -0
- package/dist/router/virtual-router/bootstrap/routing-config.js +11 -3
- package/dist/router/virtual-router/engine-legacy.d.ts +3 -3
- package/dist/router/virtual-router/engine-legacy.js +15 -7
- package/dist/router/virtual-router/engine-selection/native-compat-action-semantics.d.ts +16 -0
- package/dist/router/virtual-router/engine-selection/native-compat-action-semantics.js +434 -46
- package/dist/router/virtual-router/engine-selection/native-hub-bridge-action-semantics.d.ts +83 -0
- package/dist/router/virtual-router/engine-selection/native-hub-bridge-action-semantics.js +295 -0
- package/dist/router/virtual-router/engine-selection/native-hub-pipeline-req-outbound-semantics.d.ts +1 -0
- package/dist/router/virtual-router/engine-selection/native-hub-pipeline-resp-semantics.d.ts +7 -0
- package/dist/router/virtual-router/engine-selection/native-hub-pipeline-resp-semantics.js +8 -1
- package/dist/router/virtual-router/engine-selection/native-router-hotpath-loader.js +383 -298
- package/dist/router/virtual-router/engine-selection/native-shared-conversion-semantics.d.ts +20 -0
- package/dist/router/virtual-router/engine-selection/native-shared-conversion-semantics.js +201 -0
- package/dist/router/virtual-router/engine-selection/native-virtual-router-routing-instructions-semantics.d.ts +1 -0
- package/dist/router/virtual-router/engine-selection/native-virtual-router-routing-instructions-semantics.js +37 -0
- package/dist/router/virtual-router/engine.js +0 -38
- package/dist/router/virtual-router/features.js +44 -3
- package/dist/router/virtual-router/routing-instructions/parse.d.ts +0 -12
- package/dist/router/virtual-router/routing-instructions/parse.js +9 -389
- package/dist/router/virtual-router/stop-message-state-sync.d.ts +3 -6
- package/dist/router/virtual-router/stop-message-state-sync.js +50 -21
- package/dist/servertool/handlers/followup-request-builder.js +12 -2
- package/dist/sse/sse-to-json/anthropic-sse-to-json-converter.d.ts +1 -0
- package/dist/sse/sse-to-json/anthropic-sse-to-json-converter.js +26 -0
- package/dist/sse/sse-to-json/builders/anthropic-response-builder.js +12 -2
- package/package.json +1 -1
- package/dist/router/virtual-router/engine-legacy/route-finalize.d.ts +0 -9
- package/dist/router/virtual-router/engine-legacy/route-finalize.js +0 -84
- package/dist/router/virtual-router/engine-legacy/route-selection.d.ts +0 -17
- package/dist/router/virtual-router/engine-legacy/route-selection.js +0 -205
- package/dist/router/virtual-router/engine-legacy/route-state-allowlist.d.ts +0 -3
- package/dist/router/virtual-router/engine-legacy/route-state-allowlist.js +0 -36
- package/dist/router/virtual-router/engine-legacy/route-state.d.ts +0 -12
- package/dist/router/virtual-router/engine-legacy/route-state.js +0 -386
- package/dist/router/virtual-router/engine-legacy/routing.d.ts +0 -8
- package/dist/router/virtual-router/engine-legacy/routing.js +0 -8
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { JsonObject } from '../../hub/types/json.js';
|
|
2
1
|
import type { AdapterContext } from '../../hub/types/chat-envelope.js';
|
|
2
|
+
import type { JsonObject } from '../../hub/types/json.js';
|
|
3
3
|
export declare function wrapGeminiCliRequest(payload: JsonObject, adapterContext?: AdapterContext): JsonObject;
|
|
@@ -1,620 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
'safetySettings'
|
|
9
|
-
];
|
|
10
|
-
const ROOT_ONLY_FIELDS = [
|
|
11
|
-
'model',
|
|
12
|
-
'project',
|
|
13
|
-
'requestId',
|
|
14
|
-
'requestType',
|
|
15
|
-
'userAgent',
|
|
16
|
-
'action'
|
|
17
|
-
];
|
|
18
|
-
const TOOL_NAME_ALIASES = {
|
|
19
|
-
'mcp__context7__query-docs': 'mcp__context7__query_docs',
|
|
20
|
-
'mcp__context7__resolve-library-id': 'mcp__context7__resolve_library_id',
|
|
21
|
-
'mcp__mcp-server-time__convert_time': 'mcp__mcp_server_time__convert_time',
|
|
22
|
-
'mcp__mcp-server-time__get_current_time': 'mcp__mcp_server_time__get_current_time'
|
|
23
|
-
};
|
|
24
|
-
const TOOL_PARAM_WHITELIST = {
|
|
25
|
-
exec_command: ['command', 'workdir'],
|
|
26
|
-
write_stdin: ['session_id', 'chars', 'max_output_tokens', 'yield_time_ms', 'text'],
|
|
27
|
-
apply_patch: ['patch', 'input', 'instructions', 'text']
|
|
28
|
-
};
|
|
29
|
-
function isRecord(value) {
|
|
30
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
31
|
-
}
|
|
32
|
-
function extractAntigravityAliasKeyFromRequestId(value) {
|
|
33
|
-
if (typeof value !== 'string') {
|
|
34
|
-
return undefined;
|
|
35
|
-
}
|
|
36
|
-
const raw = value.trim();
|
|
37
|
-
if (!raw) {
|
|
38
|
-
return undefined;
|
|
39
|
-
}
|
|
40
|
-
const match = raw.match(/antigravity\.([^.\\s]+)/i);
|
|
41
|
-
const alias = match && match[1] ? match[1].trim() : '';
|
|
42
|
-
if (!alias) {
|
|
43
|
-
return undefined;
|
|
44
|
-
}
|
|
45
|
-
return `antigravity.${alias}`.toLowerCase();
|
|
46
|
-
}
|
|
47
|
-
function resolveAntigravityAliasKey(adapterContext, requestIdHint) {
|
|
48
|
-
const ctxAny = adapterContext;
|
|
49
|
-
const candidates = [
|
|
50
|
-
ctxAny && typeof ctxAny.runtimeKey === 'string' ? String(ctxAny.runtimeKey) : '',
|
|
51
|
-
ctxAny && typeof ctxAny.providerKey === 'string' ? String(ctxAny.providerKey) : '',
|
|
52
|
-
ctxAny && typeof ctxAny.providerId === 'string' ? String(ctxAny.providerId) : '',
|
|
53
|
-
ctxAny && typeof ctxAny.requestId === 'string' ? String(ctxAny.requestId) : '',
|
|
54
|
-
typeof requestIdHint === 'string' ? String(requestIdHint) : ''
|
|
55
|
-
].filter((v) => typeof v === 'string' && v.trim().length);
|
|
56
|
-
for (const value of candidates) {
|
|
57
|
-
const trimmed = value.trim();
|
|
58
|
-
const lower = trimmed.toLowerCase();
|
|
59
|
-
if (lower === 'antigravity') {
|
|
60
|
-
continue;
|
|
61
|
-
}
|
|
62
|
-
if (lower.startsWith('antigravity.')) {
|
|
63
|
-
const parts = trimmed.split('.');
|
|
64
|
-
if (parts.length >= 2 && parts[0] && parts[1]) {
|
|
65
|
-
return `${parts[0].trim()}.${parts[1].trim()}`.toLowerCase();
|
|
66
|
-
}
|
|
67
|
-
const extracted = extractAntigravityAliasKeyFromRequestId(trimmed);
|
|
68
|
-
if (extracted)
|
|
69
|
-
return extracted;
|
|
70
|
-
}
|
|
71
|
-
const extracted = extractAntigravityAliasKeyFromRequestId(trimmed);
|
|
72
|
-
if (extracted)
|
|
73
|
-
return extracted;
|
|
74
|
-
}
|
|
75
|
-
return 'antigravity.unknown';
|
|
76
|
-
}
|
|
77
|
-
function normalizeSchemaTypes(value) {
|
|
78
|
-
if (!value || typeof value !== 'object')
|
|
79
|
-
return value;
|
|
80
|
-
if (Array.isArray(value))
|
|
81
|
-
return value.map((entry) => normalizeSchemaTypes(entry));
|
|
82
|
-
const record = value;
|
|
83
|
-
const out = {};
|
|
84
|
-
for (const [key, val] of Object.entries(record)) {
|
|
85
|
-
if (key === 'type' && typeof val === 'string') {
|
|
86
|
-
out[key] = val.toUpperCase();
|
|
87
|
-
continue;
|
|
88
|
-
}
|
|
89
|
-
out[key] = normalizeSchemaTypes(val);
|
|
90
|
-
}
|
|
91
|
-
return out;
|
|
92
|
-
}
|
|
93
|
-
function pickDescription(value, fallback) {
|
|
94
|
-
return typeof value === 'string' && value.trim().length ? value : fallback;
|
|
95
|
-
}
|
|
96
|
-
function normalizeToolDeclaration(decl) {
|
|
97
|
-
const rawName = typeof decl.name === 'string' ? decl.name.trim() : '';
|
|
98
|
-
const name = (TOOL_NAME_ALIASES[rawName] ?? rawName).trim().toLowerCase();
|
|
99
|
-
const params = isRecord(decl.parameters) ? { ...decl.parameters } : {};
|
|
100
|
-
const props = isRecord(params.properties) ? { ...params.properties } : {};
|
|
101
|
-
if (name === 'view_image') {
|
|
102
|
-
return {};
|
|
103
|
-
}
|
|
104
|
-
if (name === 'exec_command') {
|
|
105
|
-
const command = isRecord(props.command) ? props.command : undefined;
|
|
106
|
-
const cmd = isRecord(props.cmd) ? props.cmd : undefined;
|
|
107
|
-
const nextProps = {
|
|
108
|
-
command: {
|
|
109
|
-
type: 'STRING',
|
|
110
|
-
description: pickDescription(command?.description ?? cmd?.description, 'Shell command to execute.')
|
|
111
|
-
},
|
|
112
|
-
workdir: {
|
|
113
|
-
type: 'STRING',
|
|
114
|
-
description: 'Working directory.'
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
return {
|
|
118
|
-
...decl,
|
|
119
|
-
name,
|
|
120
|
-
description: 'Run a shell command. Provide `cmd` (string) (alias: `command`) and optional `workdir` (string).',
|
|
121
|
-
parameters: {
|
|
122
|
-
type: 'OBJECT',
|
|
123
|
-
properties: nextProps
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
if (name === 'write_stdin') {
|
|
128
|
-
const nextProps = {};
|
|
129
|
-
for (const key of TOOL_PARAM_WHITELIST.write_stdin) {
|
|
130
|
-
const entry = props[key];
|
|
131
|
-
const fallbackType = key === 'session_id' || key.endsWith('_tokens') || key.endsWith('_ms') ? 'NUMBER' : 'STRING';
|
|
132
|
-
nextProps[key] = {
|
|
133
|
-
type: (typeof entry?.type === 'string' ? entry.type : fallbackType).toUpperCase(),
|
|
134
|
-
...(entry?.description ? { description: entry.description } : {})
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
return {
|
|
138
|
-
...decl,
|
|
139
|
-
name,
|
|
140
|
-
description: 'Write to an existing exec session. Provide `session_id` (number) and optional `chars` (string).',
|
|
141
|
-
parameters: {
|
|
142
|
-
type: 'OBJECT',
|
|
143
|
-
properties: nextProps
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
if (name === 'apply_patch') {
|
|
148
|
-
const nextProps = {};
|
|
149
|
-
for (const key of TOOL_PARAM_WHITELIST.apply_patch) {
|
|
150
|
-
const entry = props[key];
|
|
151
|
-
nextProps[key] = {
|
|
152
|
-
type: 'STRING',
|
|
153
|
-
...(entry?.description ? { description: entry.description } : {})
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
return {
|
|
157
|
-
...decl,
|
|
158
|
-
name,
|
|
159
|
-
description: 'Edit files by providing patch text in `patch` (string). Supports "*** Begin Patch" / "*** End Patch" or GNU unified diff. `input`/`instructions`/`text` are accepted as aliases.',
|
|
160
|
-
parameters: {
|
|
161
|
-
type: 'OBJECT',
|
|
162
|
-
properties: nextProps
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
if (name === 'list_mcp_resources') {
|
|
167
|
-
return {
|
|
168
|
-
...decl,
|
|
169
|
-
name,
|
|
170
|
-
description: 'Lists resources provided by MCP servers. Resources allow servers to share data that provides context to language models, such as files, database schemas, or application-specific information. Prefer resources over web search when possible.',
|
|
171
|
-
parameters: {
|
|
172
|
-
type: 'OBJECT',
|
|
173
|
-
properties: {
|
|
174
|
-
server: { type: 'STRING', minLength: 1 },
|
|
175
|
-
filter: { type: 'STRING' },
|
|
176
|
-
root: { type: 'STRING' }
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
if (name === 'list_mcp_resource_templates') {
|
|
182
|
-
return {
|
|
183
|
-
...decl,
|
|
184
|
-
name,
|
|
185
|
-
description: 'Lists resource templates provided by MCP servers. Parameterized resource templates allow servers to share data that takes parameters and provides context to language models, such as files, database schemas, or application-specific information. Prefer resource templates over web search when possible.',
|
|
186
|
-
parameters: {
|
|
187
|
-
type: 'OBJECT',
|
|
188
|
-
properties: {
|
|
189
|
-
cursor: { type: 'STRING' },
|
|
190
|
-
server: { type: 'STRING', minLength: 1 }
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
if (name === 'read_mcp_resource') {
|
|
196
|
-
return {
|
|
197
|
-
...decl,
|
|
198
|
-
name,
|
|
199
|
-
description: 'Read a specific resource from an MCP server given the server name and resource URI.',
|
|
200
|
-
parameters: {
|
|
201
|
-
type: 'OBJECT',
|
|
202
|
-
properties: {
|
|
203
|
-
server: {
|
|
204
|
-
type: 'STRING',
|
|
205
|
-
description: "MCP server name exactly as configured. Must match the 'server' field returned by list_mcp_resources."
|
|
206
|
-
},
|
|
207
|
-
uri: {
|
|
208
|
-
type: 'STRING',
|
|
209
|
-
description: 'Resource URI to read. Must be one of the URIs returned by list_mcp_resources.'
|
|
210
|
-
}
|
|
211
|
-
},
|
|
212
|
-
required: ['server', 'uri']
|
|
213
|
-
}
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
if (name === 'update_plan') {
|
|
217
|
-
return {
|
|
218
|
-
...decl,
|
|
219
|
-
name,
|
|
220
|
-
description: 'Updates the task plan.\nProvide an optional explanation and a list of plan items, each with a step and status.\nAt most one step can be in_progress at a time.\n',
|
|
221
|
-
parameters: {
|
|
222
|
-
type: 'OBJECT',
|
|
223
|
-
properties: {
|
|
224
|
-
explanation: { type: 'STRING' },
|
|
225
|
-
plan: {
|
|
226
|
-
type: 'ARRAY',
|
|
227
|
-
items: {
|
|
228
|
-
type: 'OBJECT',
|
|
229
|
-
properties: {
|
|
230
|
-
status: { type: 'STRING', description: 'One of: pending, in_progress, completed' },
|
|
231
|
-
step: { type: 'STRING' }
|
|
232
|
-
},
|
|
233
|
-
required: ['step', 'status']
|
|
234
|
-
},
|
|
235
|
-
description: 'The list of steps'
|
|
236
|
-
}
|
|
237
|
-
},
|
|
238
|
-
required: ['plan']
|
|
239
|
-
}
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
if (name === 'request_user_input') {
|
|
243
|
-
return {
|
|
244
|
-
...decl,
|
|
245
|
-
name,
|
|
246
|
-
description: 'Request user input for one to three short questions and wait for the response.',
|
|
247
|
-
parameters: {
|
|
248
|
-
type: 'OBJECT',
|
|
249
|
-
properties: {
|
|
250
|
-
questions: {
|
|
251
|
-
type: 'ARRAY',
|
|
252
|
-
items: {
|
|
253
|
-
type: 'OBJECT',
|
|
254
|
-
properties: {
|
|
255
|
-
header: { type: 'STRING', description: 'Short header label shown in the UI (12 or fewer chars).' },
|
|
256
|
-
id: { type: 'STRING', description: 'Stable identifier for mapping answers (snake_case).' },
|
|
257
|
-
options: {
|
|
258
|
-
type: 'ARRAY',
|
|
259
|
-
items: {
|
|
260
|
-
type: 'OBJECT',
|
|
261
|
-
properties: {
|
|
262
|
-
description: {
|
|
263
|
-
type: 'STRING',
|
|
264
|
-
description: 'One short sentence explaining impact/tradeoff if selected.'
|
|
265
|
-
},
|
|
266
|
-
label: { type: 'STRING', description: 'User-facing label (1-5 words).' }
|
|
267
|
-
},
|
|
268
|
-
required: ['label', 'description']
|
|
269
|
-
},
|
|
270
|
-
description: 'Optional 2-3 mutually exclusive choices. Put the recommended option first and suffix its label with "(Recommended)". Only include "Other" option if we want to include a free form option. If the question is free form in nature, please do not have any option.'
|
|
271
|
-
},
|
|
272
|
-
question: { type: 'STRING', description: 'Single-sentence prompt shown to the user.' }
|
|
273
|
-
},
|
|
274
|
-
required: ['id', 'header', 'question']
|
|
275
|
-
},
|
|
276
|
-
description: 'Questions to show the user. Prefer 1 and do not exceed 3'
|
|
277
|
-
}
|
|
278
|
-
},
|
|
279
|
-
required: ['questions']
|
|
280
|
-
}
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
if (name === 'mcp__context7__query_docs') {
|
|
284
|
-
return {
|
|
285
|
-
...decl,
|
|
286
|
-
name,
|
|
287
|
-
description: "Retrieves and queries up-to-date documentation and code examples from Context7 for any programming library or framework.\n\nYou must call 'resolve-library-id' first to obtain the exact Context7-compatible library ID required to use this tool, UNLESS the user explicitly provides a library ID in the format '/org/project' or '/org/project/version' in their query.\n\nIMPORTANT: Do not call this tool more than 3 times per question. If you cannot find what you need after 3 calls, use the best information you have.",
|
|
288
|
-
parameters: {
|
|
289
|
-
type: 'OBJECT',
|
|
290
|
-
properties: {
|
|
291
|
-
libraryId: {
|
|
292
|
-
type: 'STRING',
|
|
293
|
-
description: "Exact Context7-compatible library ID (e.g., '/mongodb/docs', '/vercel/next.js', '/supabase/supabase', '/vercel/next.js/v14.3.0-canary.87') retrieved from 'resolve-library-id' or directly from user query in the format '/org/project' or '/org/project/version'."
|
|
294
|
-
},
|
|
295
|
-
query: {
|
|
296
|
-
type: 'STRING',
|
|
297
|
-
description: "The question or task you need help with. Be specific and include relevant details. Good: 'How to set up authentication with JWT in Express.js' or 'React useEffect cleanup function examples'. Bad: 'auth' or 'hooks'. IMPORTANT: Do not include any sensitive or confidential information such as API keys, passwords, credentials, or personal data in your query."
|
|
298
|
-
}
|
|
299
|
-
},
|
|
300
|
-
required: ['libraryId', 'query']
|
|
301
|
-
}
|
|
302
|
-
};
|
|
303
|
-
}
|
|
304
|
-
if (name === 'mcp__context7__resolve_library_id') {
|
|
305
|
-
return {
|
|
306
|
-
...decl,
|
|
307
|
-
name,
|
|
308
|
-
description: "Resolves a package/product name to a Context7-compatible library ID and returns matching libraries.\n\nYou MUST call this function before 'query-docs' to obtain a valid Context7-compatible library ID UNLESS the user explicitly provides a library ID in the format '/org/project' or '/org/project/version' in their query.\n\nSelection Process:\n1. Analyze the query to understand what library/package the user is looking for\n2. Return the most relevant match based on:\n- Name similarity to the query (exact matches prioritized)\n- Description relevance to the query's intent\n- Documentation coverage (prioritize libraries with higher Code Snippet counts)\n- Source reputation (consider libraries with High or Medium reputation more authoritative)\n- Benchmark Score: Quality indicator (100 is the highest score)\n\nResponse Format:\n- Return the selected library ID in a clearly marked section\n- Provide a brief explanation for why this library was chosen\n- If multiple good matches exist, acknowledge this but proceed with the most relevant one\n- If no good matches exist, clearly state this and suggest query refinements\n\nFor ambiguous queries, request clarification before proceeding with a best-guess match.\n\nIMPORTANT: Do not call this tool more than 3 times per question. If you cannot find what you need after 3 calls, use the best result you have.",
|
|
309
|
-
parameters: {
|
|
310
|
-
type: 'OBJECT',
|
|
311
|
-
properties: {
|
|
312
|
-
libraryName: {
|
|
313
|
-
type: 'STRING',
|
|
314
|
-
description: 'Library name to search for and retrieve a Context7-compatible library ID.'
|
|
315
|
-
},
|
|
316
|
-
query: {
|
|
317
|
-
type: 'STRING',
|
|
318
|
-
description: "The user's original question or task. This is used to rank library results by relevance to what the user is trying to accomplish. IMPORTANT: Do not include any sensitive or confidential information such as API keys, passwords, credentials, or personal data in your query."
|
|
319
|
-
}
|
|
320
|
-
},
|
|
321
|
-
required: ['query', 'libraryName']
|
|
322
|
-
}
|
|
323
|
-
};
|
|
324
|
-
}
|
|
325
|
-
if (name === 'mcp__mcp_server_time__convert_time') {
|
|
326
|
-
return {
|
|
327
|
-
...decl,
|
|
328
|
-
name,
|
|
329
|
-
description: 'Convert time between timezones',
|
|
330
|
-
parameters: {
|
|
331
|
-
type: 'OBJECT',
|
|
332
|
-
properties: {
|
|
333
|
-
source_timezone: {
|
|
334
|
-
type: 'STRING',
|
|
335
|
-
description: "Source IANA timezone name (e.g., 'America/New_York', 'Europe/London'). Use 'Asia/Shanghai' as local timezone if no source timezone provided by the user."
|
|
336
|
-
},
|
|
337
|
-
target_timezone: {
|
|
338
|
-
type: 'STRING',
|
|
339
|
-
description: "Target IANA timezone name (e.g., 'Asia/Tokyo', 'America/San_Francisco'). Use 'Asia/Shanghai' as local timezone if no target timezone provided by the user."
|
|
340
|
-
},
|
|
341
|
-
time: { type: 'STRING', description: 'Time to convert in 24-hour format (HH:MM)' }
|
|
342
|
-
},
|
|
343
|
-
required: ['source_timezone', 'time', 'target_timezone']
|
|
344
|
-
}
|
|
345
|
-
};
|
|
346
|
-
}
|
|
347
|
-
if (name === 'mcp__mcp_server_time__get_current_time') {
|
|
348
|
-
return {
|
|
349
|
-
...decl,
|
|
350
|
-
name,
|
|
351
|
-
description: 'Get current time in a specific timezones',
|
|
352
|
-
parameters: {
|
|
353
|
-
type: 'OBJECT',
|
|
354
|
-
properties: {
|
|
355
|
-
timezone: {
|
|
356
|
-
type: 'STRING',
|
|
357
|
-
description: "IANA timezone name (e.g., 'America/New_York', 'Europe/London'). Use 'Asia/Shanghai' as local timezone if no timezone provided by the user."
|
|
358
|
-
}
|
|
359
|
-
},
|
|
360
|
-
required: ['timezone']
|
|
361
|
-
}
|
|
362
|
-
};
|
|
363
|
-
}
|
|
1
|
+
import { buildNativeReqOutboundCompatAdapterContext } from '../../hub/pipeline/compat/native-adapter-context.js';
|
|
2
|
+
import { runReqOutboundStage3CompatWithNative } from '../../../router/virtual-router/engine-selection/native-hub-pipeline-req-outbound-semantics.js';
|
|
3
|
+
const PROFILE = 'chat:gemini-cli';
|
|
4
|
+
const DEFAULT_PROVIDER_PROTOCOL = 'gemini-chat';
|
|
5
|
+
const DEFAULT_ENTRY_ENDPOINT = '/v1/chat/completions';
|
|
6
|
+
function buildGeminiCliCompatContext(adapterContext) {
|
|
7
|
+
const nativeContext = buildNativeReqOutboundCompatAdapterContext(adapterContext);
|
|
364
8
|
return {
|
|
365
|
-
...
|
|
366
|
-
|
|
367
|
-
|
|
9
|
+
...nativeContext,
|
|
10
|
+
compatibilityProfile: PROFILE,
|
|
11
|
+
providerProtocol: nativeContext.providerProtocol ?? adapterContext?.providerProtocol ?? DEFAULT_PROVIDER_PROTOCOL,
|
|
12
|
+
entryEndpoint: nativeContext.entryEndpoint ?? adapterContext?.entryEndpoint ?? DEFAULT_ENTRY_ENDPOINT
|
|
368
13
|
};
|
|
369
14
|
}
|
|
370
|
-
function
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
return tool;
|
|
377
|
-
const record = tool;
|
|
378
|
-
const decls = Array.isArray(record.functionDeclarations)
|
|
379
|
-
? record.functionDeclarations
|
|
380
|
-
: undefined;
|
|
381
|
-
if (!decls) {
|
|
382
|
-
return {
|
|
383
|
-
...record,
|
|
384
|
-
...(record.parameters ? { parameters: normalizeSchemaTypes(record.parameters) } : {})
|
|
385
|
-
};
|
|
386
|
-
}
|
|
387
|
-
const nextDecls = decls
|
|
388
|
-
.map((decl) => normalizeToolDeclaration(decl))
|
|
389
|
-
.filter((decl) => Object.keys(decl).length > 0);
|
|
390
|
-
return { ...record, functionDeclarations: nextDecls };
|
|
391
|
-
});
|
|
392
|
-
node.tools = nextTools.filter((tool) => {
|
|
393
|
-
if (!tool || typeof tool !== 'object')
|
|
394
|
-
return true;
|
|
395
|
-
const record = tool;
|
|
396
|
-
const decls = Array.isArray(record.functionDeclarations)
|
|
397
|
-
? record.functionDeclarations
|
|
398
|
-
: undefined;
|
|
399
|
-
return !decls || decls.length > 0;
|
|
400
|
-
});
|
|
401
|
-
}
|
|
402
|
-
function normalizeFunctionCallArgs(node) {
|
|
403
|
-
const contents = node.contents;
|
|
404
|
-
if (!Array.isArray(contents))
|
|
405
|
-
return;
|
|
406
|
-
for (const item of contents) {
|
|
407
|
-
if (!item || typeof item !== 'object')
|
|
408
|
-
continue;
|
|
409
|
-
const record = item;
|
|
410
|
-
const parts = Array.isArray(record.parts) ? record.parts : [];
|
|
411
|
-
for (const part of parts) {
|
|
412
|
-
if (!part || typeof part !== 'object')
|
|
413
|
-
continue;
|
|
414
|
-
const fnCall = part.functionCall;
|
|
415
|
-
if (!isRecord(fnCall))
|
|
416
|
-
continue;
|
|
417
|
-
const rawName = typeof fnCall.name === 'string' ? fnCall.name.trim() : '';
|
|
418
|
-
const normalizedName = (TOOL_NAME_ALIASES[rawName] ?? rawName).trim();
|
|
419
|
-
fnCall.name = normalizedName;
|
|
420
|
-
const name = normalizedName.toLowerCase();
|
|
421
|
-
const args = isRecord(fnCall.args) ? { ...fnCall.args } : undefined;
|
|
422
|
-
if (!args)
|
|
423
|
-
continue;
|
|
424
|
-
if (name === 'exec_command') {
|
|
425
|
-
if (!Object.prototype.hasOwnProperty.call(args, 'command') && Object.prototype.hasOwnProperty.call(args, 'cmd')) {
|
|
426
|
-
args.command = args.cmd;
|
|
427
|
-
}
|
|
428
|
-
if (Object.prototype.hasOwnProperty.call(args, 'cmd')) {
|
|
429
|
-
delete args.cmd;
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
if (name === 'write_stdin') {
|
|
433
|
-
if (!Object.prototype.hasOwnProperty.call(args, 'chars') && Object.prototype.hasOwnProperty.call(args, 'text')) {
|
|
434
|
-
args.chars = args.text;
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
fnCall.args = args;
|
|
438
|
-
part.functionCall = fnCall;
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
function hasAnyRequestField(node) {
|
|
443
|
-
return REQUEST_FIELDS.some((key) => Object.prototype.hasOwnProperty.call(node, key));
|
|
444
|
-
}
|
|
445
|
-
function normalizeRequestNode(node) {
|
|
446
|
-
const base = { ...node };
|
|
447
|
-
const nested = base.request;
|
|
448
|
-
if (!isRecord(nested)) {
|
|
449
|
-
return base;
|
|
450
|
-
}
|
|
451
|
-
delete base.request;
|
|
452
|
-
const merged = { ...nested };
|
|
453
|
-
for (const [key, value] of Object.entries(base)) {
|
|
454
|
-
if (merged[key] === undefined) {
|
|
455
|
-
merged[key] = value;
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
return merged;
|
|
459
|
-
}
|
|
460
|
-
function isWebSearchToolName(value) {
|
|
461
|
-
if (typeof value !== 'string')
|
|
462
|
-
return false;
|
|
463
|
-
const normalized = value.trim().toLowerCase();
|
|
464
|
-
return normalized === 'web_search' || normalized.startsWith('web_search_');
|
|
465
|
-
}
|
|
466
|
-
function stripWebSearchTools(requestNode) {
|
|
467
|
-
const tools = requestNode.tools;
|
|
468
|
-
if (!Array.isArray(tools))
|
|
469
|
-
return;
|
|
470
|
-
const nextTools = [];
|
|
471
|
-
for (const tool of tools) {
|
|
472
|
-
if (!tool || typeof tool !== 'object') {
|
|
473
|
-
nextTools.push(tool);
|
|
474
|
-
continue;
|
|
475
|
-
}
|
|
476
|
-
const record = tool;
|
|
477
|
-
const fnDecls = Array.isArray(record.functionDeclarations)
|
|
478
|
-
? record.functionDeclarations
|
|
479
|
-
: undefined;
|
|
480
|
-
if (fnDecls) {
|
|
481
|
-
const filtered = fnDecls.filter((decl) => !isWebSearchToolName(decl?.name));
|
|
482
|
-
if (filtered.length === 0) {
|
|
483
|
-
continue;
|
|
484
|
-
}
|
|
485
|
-
nextTools.push({ ...record, functionDeclarations: filtered });
|
|
486
|
-
continue;
|
|
487
|
-
}
|
|
488
|
-
const name = record.name;
|
|
489
|
-
if (isWebSearchToolName(name)) {
|
|
490
|
-
continue;
|
|
491
|
-
}
|
|
492
|
-
nextTools.push(record);
|
|
493
|
-
}
|
|
494
|
-
if (nextTools.length > 0) {
|
|
495
|
-
requestNode.tools = nextTools;
|
|
496
|
-
}
|
|
497
|
-
else {
|
|
498
|
-
delete requestNode.tools;
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
function shouldEnableAntigravitySignature(adapterContext) {
|
|
502
|
-
// Prefer adapterContext (canonical) but fall back to transport hints for cases where
|
|
503
|
-
// host doesn't populate providerId (e.g. certain v1/v2 bridges).
|
|
504
|
-
if (!adapterContext || typeof adapterContext !== 'object') {
|
|
505
|
-
return false;
|
|
506
|
-
}
|
|
507
|
-
const protocol = typeof adapterContext.providerProtocol === 'string' ? adapterContext.providerProtocol.trim().toLowerCase() : '';
|
|
508
|
-
if (protocol !== 'gemini-chat') {
|
|
509
|
-
return false;
|
|
510
|
-
}
|
|
511
|
-
const ctxAny = adapterContext;
|
|
512
|
-
const providerIdOrKeyRaw = typeof ctxAny.providerId === 'string'
|
|
513
|
-
? String(ctxAny.providerId)
|
|
514
|
-
: typeof ctxAny.providerKey === 'string'
|
|
515
|
-
? String(ctxAny.providerKey)
|
|
516
|
-
: typeof ctxAny.runtimeKey === 'string'
|
|
517
|
-
? String(ctxAny.runtimeKey)
|
|
518
|
-
: '';
|
|
519
|
-
// NOTE: AdapterContext may carry providerKey (e.g. "antigravity.<alias>.<model>") instead of bare providerId.
|
|
520
|
-
// Treat the first segment as the effective provider id for compatibility checks.
|
|
521
|
-
const providerIdOrKey = providerIdOrKeyRaw.trim().toLowerCase();
|
|
522
|
-
const effectiveProviderId = providerIdOrKey.split('.')[0] ?? '';
|
|
523
|
-
// Antigravity-Manager alignment: thoughtSignature compat applies to both Antigravity and Gemini CLI
|
|
524
|
-
// (both route to Google Gemini internals that enforce thoughtSignature on tool loops).
|
|
525
|
-
return effectiveProviderId === 'antigravity' || effectiveProviderId === 'gemini-cli';
|
|
526
|
-
}
|
|
527
|
-
function injectAntigravityThoughtSignature(requestNode, signature) {
|
|
528
|
-
if (!signature || !signature.trim())
|
|
529
|
-
return;
|
|
530
|
-
const contents = requestNode.contents;
|
|
531
|
-
if (!Array.isArray(contents)) {
|
|
532
|
-
return;
|
|
533
|
-
}
|
|
534
|
-
for (const item of contents) {
|
|
535
|
-
if (!isRecord(item))
|
|
536
|
-
continue;
|
|
537
|
-
const parts = Array.isArray(item.parts) ? item.parts : [];
|
|
538
|
-
for (const part of parts) {
|
|
539
|
-
if (!isRecord(part))
|
|
540
|
-
continue;
|
|
541
|
-
if (!isRecord(part.functionCall))
|
|
542
|
-
continue;
|
|
543
|
-
const existing = part.thoughtSignature;
|
|
544
|
-
if (shouldTreatAsMissingThoughtSignature(existing)) {
|
|
545
|
-
part.thoughtSignature = signature.trim();
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
}
|
|
15
|
+
function buildGeminiCliCompatInput(payload, adapterContext) {
|
|
16
|
+
return {
|
|
17
|
+
payload,
|
|
18
|
+
adapterContext: buildGeminiCliCompatContext(adapterContext),
|
|
19
|
+
explicitProfile: PROFILE
|
|
20
|
+
};
|
|
549
21
|
}
|
|
550
22
|
export function wrapGeminiCliRequest(payload, adapterContext) {
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
const requestNode = existingRequest ?? {};
|
|
554
|
-
for (const key of REQUEST_FIELDS) {
|
|
555
|
-
if (requestNode[key] === undefined && root[key] !== undefined) {
|
|
556
|
-
requestNode[key] = root[key];
|
|
557
|
-
}
|
|
558
|
-
delete root[key];
|
|
559
|
-
}
|
|
560
|
-
for (const key of ROOT_ONLY_FIELDS) {
|
|
561
|
-
if (requestNode[key] !== undefined) {
|
|
562
|
-
delete requestNode[key];
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
stripWebSearchTools(requestNode);
|
|
566
|
-
normalizeToolDeclarations(requestNode);
|
|
567
|
-
normalizeFunctionCallArgs(requestNode);
|
|
568
|
-
const enableSignature = shouldEnableAntigravitySignature(adapterContext) ||
|
|
569
|
-
(typeof requestNode.userAgent === 'string' && requestNode.userAgent.trim().toLowerCase() === 'antigravity') ||
|
|
570
|
-
(typeof requestNode.requestId === 'string' && requestNode.requestId.trim().toLowerCase().startsWith('agent-')) ||
|
|
571
|
-
(typeof root.userAgent === 'string' && root.userAgent.trim().toLowerCase() === 'antigravity') ||
|
|
572
|
-
(typeof root.requestId === 'string' && root.requestId.trim().toLowerCase().startsWith('agent-'));
|
|
573
|
-
if (enableSignature) {
|
|
574
|
-
const aliasKey = resolveAntigravityAliasKey(adapterContext, root.requestId);
|
|
575
|
-
// Antigravity-Manager alignment: derive sessionId from request contents (first user text / JSON fallback),
|
|
576
|
-
// not from external session/conversation identifiers injected by other clients/hosts.
|
|
577
|
-
const sessionId = extractAntigravityGeminiSessionId(requestNode);
|
|
578
|
-
const directLookup = lookupAntigravitySessionSignatureEntry(aliasKey, sessionId, { hydrate: true });
|
|
579
|
-
const lookup = typeof directLookup.signature === 'string' && directLookup.signature.trim().length
|
|
580
|
-
? directLookup
|
|
581
|
-
: lookupAntigravitySessionSignatureEntry(ANTIGRAVITY_GLOBAL_ALIAS_KEY, sessionId, { hydrate: true });
|
|
582
|
-
const effectiveSessionId = typeof lookup.sourceSessionId === 'string' && lookup.sourceSessionId.trim().length ? lookup.sourceSessionId.trim() : sessionId;
|
|
583
|
-
// Antigravity-Manager alignment:
|
|
584
|
-
if (adapterContext) {
|
|
585
|
-
try {
|
|
586
|
-
const ctxAny = adapterContext;
|
|
587
|
-
const keys = [
|
|
588
|
-
adapterContext.requestId,
|
|
589
|
-
typeof ctxAny.clientRequestId === 'string' ? String(ctxAny.clientRequestId) : '',
|
|
590
|
-
typeof ctxAny.groupRequestId === 'string' ? String(ctxAny.groupRequestId) : ''
|
|
591
|
-
].filter((k) => typeof k === 'string' && k.trim().length);
|
|
592
|
-
for (const key of keys) {
|
|
593
|
-
cacheAntigravityRequestSessionId(key, aliasKey, effectiveSessionId);
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
catch {
|
|
597
|
-
// best-effort only
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
if (typeof lookup.signature === 'string' && lookup.signature.trim().length) {
|
|
601
|
-
injectAntigravityThoughtSignature(requestNode, lookup.signature);
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
// Cloud Code Assist request wrapper should not carry metadata/action/web_search/stream.
|
|
605
|
-
delete requestNode.metadata;
|
|
606
|
-
delete requestNode.action;
|
|
607
|
-
delete requestNode.web_search;
|
|
608
|
-
delete requestNode.stream;
|
|
609
|
-
delete requestNode.sessionId;
|
|
610
|
-
delete root.metadata;
|
|
611
|
-
delete root.stream;
|
|
612
|
-
delete root.sessionId;
|
|
613
|
-
if (Object.keys(requestNode).length > 0) {
|
|
614
|
-
root.request = requestNode;
|
|
615
|
-
}
|
|
616
|
-
else {
|
|
617
|
-
delete root.request;
|
|
23
|
+
if (!payload || typeof payload !== 'object') {
|
|
24
|
+
return payload;
|
|
618
25
|
}
|
|
619
|
-
return
|
|
26
|
+
return runReqOutboundStage3CompatWithNative(buildGeminiCliCompatInput(payload, adapterContext)).payload;
|
|
620
27
|
}
|
|
@@ -1,17 +1,3 @@
|
|
|
1
1
|
import type { JsonObject } from '../../hub/types/json.js';
|
|
2
2
|
import type { AdapterContext } from '../../hub/types/chat-envelope.js';
|
|
3
|
-
|
|
4
|
-
* Gemini web_search 请求适配(作用于 Gemini 请求 payload,而不是 ChatEnvelope):
|
|
5
|
-
*
|
|
6
|
-
* - 仅在 routeId 以 `web_search` 或 `search` 开头时生效(来自 AdapterContext.routeId);
|
|
7
|
-
* - 针对 Gemini 请求中的 `tools` 字段进行清洗:
|
|
8
|
-
* - 保留 name === 'web_search' 的 functionDeclarations(如果存在);
|
|
9
|
-
* - 丢弃其它 Codex 自身工具(exec_command / MCP 等),避免 Cloud Code 报
|
|
10
|
-
* “Multiple tools are supported only when they are all search tools.”;
|
|
11
|
-
* - 如果清洗后没有任何工具,则删除 `tools` 字段。
|
|
12
|
-
*
|
|
13
|
-
* 注意:
|
|
14
|
-
* - 这里处理的是 llmswitch-core 为 gemini-chat 构造的中间 payload(buildGeminiRequestFromChat 输出);
|
|
15
|
-
* - 对于 Gemini CLI 后续在传输层添加的 googleSearch 工具,本适配不负责构造或修改。
|
|
16
|
-
*/
|
|
17
|
-
export declare function applyGeminiWebSearchCompat(payload: JsonObject, adapterContext?: AdapterContext): JsonObject;
|
|
3
|
+
export declare function applyGeminiWebSearchCompat(root: JsonObject, adapterContext?: AdapterContext): JsonObject;
|