@jsonstudio/llms 0.6.1739 → 0.6.1890
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/compat/actions/deepseek-web-request.d.ts +3 -0
- package/dist/conversion/compat/actions/deepseek-web-request.js +350 -0
- package/dist/conversion/compat/actions/deepseek-web-response.d.ts +3 -0
- package/dist/conversion/compat/actions/deepseek-web-response.js +886 -0
- package/dist/conversion/compat/actions/gemini-cli-request.js +3 -1
- package/dist/conversion/compat/profiles/chat-deepseek-web.json +18 -0
- package/dist/conversion/hub/operation-table/semantic-mappers/anthropic-mapper.js +166 -2
- package/dist/conversion/hub/operation-table/semantic-mappers/gemini-mapper.js +169 -0
- package/dist/conversion/hub/operation-table/semantic-mappers/responses-mapper.js +6 -0
- package/dist/conversion/hub/pipeline/compat/compat-pipeline-executor.js +12 -0
- package/dist/conversion/hub/pipeline/compat/compat-profile-resolver.js +1 -0
- package/dist/conversion/hub/pipeline/compat/compat-types.d.ts +4 -0
- package/dist/conversion/hub/pipeline/hub-pipeline.js +365 -144
- package/dist/conversion/hub/pipeline/stages/resp_outbound/resp_outbound_stage1_client_remap/index.js +9 -0
- package/dist/conversion/hub/policy/policy-engine.d.ts +2 -0
- package/dist/conversion/hub/policy/policy-engine.js +8 -0
- package/dist/conversion/hub/process/chat-process.js +466 -16
- package/dist/conversion/hub/response/provider-response.js +0 -35
- package/dist/conversion/responses/responses-openai-bridge.d.ts +2 -0
- package/dist/conversion/responses/responses-openai-bridge.js +166 -8
- package/dist/conversion/shared/anthropic-message-utils.js +10 -1
- package/dist/conversion/shared/protocol-field-allowlists.d.ts +2 -2
- package/dist/conversion/shared/protocol-field-allowlists.js +4 -0
- package/dist/conversion/shared/tool-governor.js +102 -0
- package/dist/guidance/index.js +17 -0
- package/dist/router/virtual-router/bootstrap.js +46 -1
- package/dist/router/virtual-router/classifier.js +59 -4
- package/dist/router/virtual-router/engine/health/index.js +6 -6
- package/dist/router/virtual-router/engine/routing-state/store.js +16 -3
- package/dist/router/virtual-router/engine-logging.js +62 -24
- package/dist/router/virtual-router/engine-selection/route-utils.js +20 -20
- package/dist/router/virtual-router/engine-selection/tier-selection.js +2 -2
- package/dist/router/virtual-router/engine.d.ts +3 -1
- package/dist/router/virtual-router/engine.js +359 -39
- package/dist/router/virtual-router/features.js +2 -1
- package/dist/router/virtual-router/pre-command-file-resolver.d.ts +2 -0
- package/dist/router/virtual-router/pre-command-file-resolver.js +90 -0
- package/dist/router/virtual-router/provider-registry.js +3 -1
- package/dist/router/virtual-router/routing-instructions.d.ts +15 -1
- package/dist/router/virtual-router/routing-instructions.js +110 -151
- package/dist/router/virtual-router/routing-pre-command-actions.d.ts +3 -0
- package/dist/router/virtual-router/routing-pre-command-actions.js +26 -0
- package/dist/router/virtual-router/routing-pre-command-parser.d.ts +2 -0
- package/dist/router/virtual-router/routing-pre-command-parser.js +85 -0
- package/dist/router/virtual-router/routing-pre-command-state-codec.d.ts +3 -0
- package/dist/router/virtual-router/routing-pre-command-state-codec.js +24 -0
- package/dist/router/virtual-router/routing-stop-message-actions.d.ts +2 -0
- package/dist/router/virtual-router/routing-stop-message-actions.js +96 -0
- package/dist/router/virtual-router/routing-stop-message-parser.d.ts +3 -0
- package/dist/router/virtual-router/routing-stop-message-parser.js +142 -0
- package/dist/router/virtual-router/routing-stop-message-state-codec.d.ts +4 -0
- package/dist/router/virtual-router/routing-stop-message-state-codec.js +85 -0
- package/dist/router/virtual-router/sticky-session-store.js +206 -57
- package/dist/router/virtual-router/stop-message-stage-template-files.d.ts +12 -0
- package/dist/router/virtual-router/stop-message-stage-template-files.js +67 -0
- package/dist/router/virtual-router/stop-message-state-sync.d.ts +1 -1
- package/dist/router/virtual-router/stop-message-state-sync.js +5 -0
- package/dist/router/virtual-router/token-file-scanner.d.ts +9 -0
- package/dist/router/virtual-router/token-file-scanner.js +64 -3
- package/dist/router/virtual-router/tool-signals.d.ts +5 -0
- package/dist/router/virtual-router/tool-signals.js +42 -3
- package/dist/router/virtual-router/types.d.ts +19 -1
- package/dist/router/virtual-router/types.js +1 -0
- package/dist/servertool/clock/config.d.ts +1 -1
- package/dist/servertool/clock/config.js +27 -4
- package/dist/servertool/clock/state.js +41 -2
- package/dist/servertool/clock/task-store.d.ts +2 -2
- package/dist/servertool/clock/task-store.js +1 -1
- package/dist/servertool/clock/tasks.d.ts +3 -1
- package/dist/servertool/clock/tasks.js +209 -18
- package/dist/servertool/clock/types.d.ts +17 -0
- package/dist/servertool/continue-execution/log.d.ts +3 -0
- package/dist/servertool/continue-execution/log.js +13 -0
- package/dist/servertool/engine.js +414 -68
- package/dist/servertool/handlers/antigravity-thought-signature-bootstrap.js +6 -6
- package/dist/servertool/handlers/clock-auto.js +54 -71
- package/dist/servertool/handlers/clock.js +121 -6
- package/dist/servertool/handlers/continue-execution.d.ts +1 -0
- package/dist/servertool/handlers/continue-execution.js +91 -0
- package/dist/servertool/handlers/followup-request-builder.js +13 -0
- 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/stop-message-auto.js +386 -257
- package/dist/servertool/handlers/stop-message-stage-policy.d.ts +43 -0
- package/dist/servertool/handlers/stop-message-stage-policy.js +684 -0
- package/dist/servertool/handlers/vision.js +1 -1
- package/dist/servertool/log/progress-file.d.ts +14 -0
- package/dist/servertool/log/progress-file.js +88 -0
- package/dist/servertool/pre-command-hooks.d.ts +17 -0
- package/dist/servertool/pre-command-hooks.js +491 -0
- package/dist/servertool/registry.d.ts +23 -6
- package/dist/servertool/registry.js +66 -1
- package/dist/servertool/server-side-tools.d.ts +1 -0
- package/dist/servertool/server-side-tools.js +216 -14
- package/dist/servertool/stop-gateway-context.d.ts +14 -0
- package/dist/servertool/stop-gateway-context.js +167 -0
- package/dist/servertool/stop-message-compare-context.d.ts +24 -0
- package/dist/servertool/stop-message-compare-context.js +133 -0
- package/dist/servertool/types.d.ts +12 -0
- 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 +36 -1
- package/dist/sse/sse-to-json/builders/anthropic-response-builder.js +3 -0
- package/dist/sse/sse-to-json/chat-sse-to-json-converter.d.ts +3 -0
- package/dist/sse/sse-to-json/chat-sse-to-json-converter.js +118 -1
- package/dist/tools/apply-patch/args-normalizer/default-actions.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
const DEFAULT_OPTIONS = {
|
|
2
|
+
strictToolRequired: true,
|
|
3
|
+
textToolFallback: true
|
|
4
|
+
};
|
|
5
|
+
const SEARCH_ROUTE_PREFIXES = ['web_search', 'search'];
|
|
6
|
+
const readString = (value) => {
|
|
7
|
+
if (typeof value !== 'string') {
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
const trimmed = value.trim();
|
|
11
|
+
return trimmed.length ? trimmed : undefined;
|
|
12
|
+
};
|
|
13
|
+
const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
14
|
+
function readBoolean(input, fallback) {
|
|
15
|
+
if (typeof input === 'boolean') {
|
|
16
|
+
return input;
|
|
17
|
+
}
|
|
18
|
+
if (typeof input === 'string') {
|
|
19
|
+
const normalized = input.trim().toLowerCase();
|
|
20
|
+
if (['true', '1', 'yes', 'on'].includes(normalized)) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
if (['false', '0', 'no', 'off'].includes(normalized)) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return fallback;
|
|
28
|
+
}
|
|
29
|
+
function resolveOptions(adapterContext) {
|
|
30
|
+
const context = (adapterContext ?? {});
|
|
31
|
+
const deepseekNode = isRecord(context.deepseek)
|
|
32
|
+
? context.deepseek
|
|
33
|
+
: isRecord(context.__rt) && isRecord(context.__rt.deepseek)
|
|
34
|
+
? context.__rt.deepseek
|
|
35
|
+
: undefined;
|
|
36
|
+
if (!deepseekNode) {
|
|
37
|
+
return { ...DEFAULT_OPTIONS };
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
strictToolRequired: readBoolean(deepseekNode.strictToolRequired, DEFAULT_OPTIONS.strictToolRequired),
|
|
41
|
+
textToolFallback: readBoolean(deepseekNode.textToolFallback, DEFAULT_OPTIONS.textToolFallback)
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function normalizeContentToText(content) {
|
|
45
|
+
if (typeof content === 'string') {
|
|
46
|
+
return content;
|
|
47
|
+
}
|
|
48
|
+
if (content === null || content === undefined) {
|
|
49
|
+
return '';
|
|
50
|
+
}
|
|
51
|
+
if (Array.isArray(content)) {
|
|
52
|
+
const parts = [];
|
|
53
|
+
for (const item of content) {
|
|
54
|
+
if (!isRecord(item)) {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
const type = readString(item.type)?.toLowerCase();
|
|
58
|
+
if ((type === 'text' || type === 'input_text' || type === 'output_text') && readString(item.text)) {
|
|
59
|
+
parts.push(readString(item.text));
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (readString(item.content)) {
|
|
63
|
+
parts.push(readString(item.content));
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if (type === 'tool_result' && item.content !== undefined) {
|
|
67
|
+
parts.push(stringifyUnknown(item.content));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return parts.join('\n').trim();
|
|
71
|
+
}
|
|
72
|
+
return stringifyUnknown(content);
|
|
73
|
+
}
|
|
74
|
+
function stringifyUnknown(value) {
|
|
75
|
+
if (typeof value === 'string') {
|
|
76
|
+
return value;
|
|
77
|
+
}
|
|
78
|
+
if (value === null || value === undefined) {
|
|
79
|
+
return '';
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
return JSON.stringify(value);
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
return String(value);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function normalizeToolCallsAsText(toolCallsRaw) {
|
|
89
|
+
if (!Array.isArray(toolCallsRaw) || toolCallsRaw.length === 0) {
|
|
90
|
+
return '';
|
|
91
|
+
}
|
|
92
|
+
const toolCalls = toolCallsRaw
|
|
93
|
+
.filter((item) => isRecord(item))
|
|
94
|
+
.map((item) => {
|
|
95
|
+
const fn = isRecord(item.function) ? item.function : undefined;
|
|
96
|
+
const name = readString(fn?.name);
|
|
97
|
+
if (!name) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
const argsRaw = fn?.arguments;
|
|
101
|
+
let input = {};
|
|
102
|
+
if (typeof argsRaw === 'string') {
|
|
103
|
+
const trimmed = argsRaw.trim();
|
|
104
|
+
if (trimmed.length) {
|
|
105
|
+
try {
|
|
106
|
+
input = JSON.parse(trimmed);
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
input = { _raw: trimmed };
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
else if (argsRaw !== undefined) {
|
|
114
|
+
input = argsRaw;
|
|
115
|
+
}
|
|
116
|
+
return { name, input };
|
|
117
|
+
})
|
|
118
|
+
.filter((item) => Boolean(item));
|
|
119
|
+
if (!toolCalls.length) {
|
|
120
|
+
return '';
|
|
121
|
+
}
|
|
122
|
+
try {
|
|
123
|
+
return JSON.stringify({ tool_calls: toolCalls });
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
return '';
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function summarizeToolSchema(tool) {
|
|
130
|
+
const fn = isRecord(tool.function) ? tool.function : tool;
|
|
131
|
+
const name = readString(fn.name) ?? readString(tool.name) ?? 'unknown_tool';
|
|
132
|
+
const description = readString(fn.description) ?? 'No description';
|
|
133
|
+
const params = isRecord(fn.parameters) ? fn.parameters : undefined;
|
|
134
|
+
const properties = isRecord(params?.properties) ? params?.properties : undefined;
|
|
135
|
+
const required = Array.isArray(params?.required)
|
|
136
|
+
? params.required.map((item) => readString(item)).filter((item) => Boolean(item))
|
|
137
|
+
: [];
|
|
138
|
+
const lines = [`Tool: ${name}`, `Description: ${description}`];
|
|
139
|
+
if (properties) {
|
|
140
|
+
const fields = [];
|
|
141
|
+
for (const [propName, propValue] of Object.entries(properties)) {
|
|
142
|
+
const type = isRecord(propValue) ? (readString(propValue.type) ?? 'string') : 'string';
|
|
143
|
+
const marker = required.includes(propName) ? ' (required)' : '';
|
|
144
|
+
fields.push(` - ${propName}: ${type}${marker}`);
|
|
145
|
+
}
|
|
146
|
+
if (fields.length) {
|
|
147
|
+
lines.push('Parameters:', ...fields);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return lines.join('\n');
|
|
151
|
+
}
|
|
152
|
+
function buildToolFallbackInstruction(toolsRaw, requireToolCall) {
|
|
153
|
+
if (!Array.isArray(toolsRaw) || toolsRaw.length === 0) {
|
|
154
|
+
return '';
|
|
155
|
+
}
|
|
156
|
+
const schemas = toolsRaw
|
|
157
|
+
.filter((item) => isRecord(item))
|
|
158
|
+
.map((item) => summarizeToolSchema(item));
|
|
159
|
+
if (!schemas.length) {
|
|
160
|
+
return '';
|
|
161
|
+
}
|
|
162
|
+
return [
|
|
163
|
+
'You have access to these tools:',
|
|
164
|
+
'',
|
|
165
|
+
schemas.join('\n\n'),
|
|
166
|
+
'',
|
|
167
|
+
'Tool-call output contract (STRICT):',
|
|
168
|
+
'1) If you call a tool, your ENTIRE assistant output must be a single JSON object.',
|
|
169
|
+
'2) Use this exact top-level shape (and key names):',
|
|
170
|
+
'{"tool_calls":[{"name":"tool_name","input":{"arg":"value"}}]}',
|
|
171
|
+
'3) Use only `name` + `input` for each tool call. Do NOT emit `arguments`, `parameters`, or custom wrappers.',
|
|
172
|
+
'4) Do NOT include markdown fences, prose, progress logs, or shell transcript around the JSON.',
|
|
173
|
+
'5) Do NOT output pseudo tool results in text (forbidden examples: {"exec_command":...}, <function_results>...</function_results>).',
|
|
174
|
+
'6) If multiple tools are needed, append multiple entries in `tool_calls`.',
|
|
175
|
+
requireToolCall
|
|
176
|
+
? '7) tool_choice is required for this turn: return at least one tool call.'
|
|
177
|
+
: '7) If no tool is needed, plain text is allowed.',
|
|
178
|
+
'',
|
|
179
|
+
'Valid example:',
|
|
180
|
+
'{"tool_calls":[{"name":"exec_command","input":{"cmd":"pnpm -v","workdir":"/workspace"}}]}'
|
|
181
|
+
].join('\n');
|
|
182
|
+
}
|
|
183
|
+
function isToolChoiceRequired(root) {
|
|
184
|
+
const toolChoice = root.tool_choice;
|
|
185
|
+
if (typeof toolChoice === 'string') {
|
|
186
|
+
const normalized = toolChoice.trim().toLowerCase();
|
|
187
|
+
if (normalized === 'required') {
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
if (normalized === 'none' || normalized === 'auto') {
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
if (isRecord(toolChoice)) {
|
|
195
|
+
const type = readString(toolChoice.type)?.toLowerCase();
|
|
196
|
+
if (type === 'function') {
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
function toPromptMessages(root, options) {
|
|
203
|
+
const messagesRaw = Array.isArray(root.messages) ? root.messages : [];
|
|
204
|
+
const messages = [];
|
|
205
|
+
for (const item of messagesRaw) {
|
|
206
|
+
if (!isRecord(item)) {
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
const role = readString(item.role)?.toLowerCase() ?? '';
|
|
210
|
+
if (!role) {
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
const contentText = normalizeContentToText(item.content);
|
|
214
|
+
const toolCallsText = normalizeToolCallsAsText(item.tool_calls);
|
|
215
|
+
const reasoning = readString(item.reasoning_content) ?? readString(item.reasoning) ?? '';
|
|
216
|
+
const parts = [contentText];
|
|
217
|
+
if (toolCallsText) {
|
|
218
|
+
parts.push(toolCallsText);
|
|
219
|
+
}
|
|
220
|
+
if (reasoning) {
|
|
221
|
+
parts.push(reasoning);
|
|
222
|
+
}
|
|
223
|
+
const text = parts.filter(Boolean).join('\n').trim();
|
|
224
|
+
messages.push({ role, text });
|
|
225
|
+
}
|
|
226
|
+
if (options.textToolFallback) {
|
|
227
|
+
const instruction = buildToolFallbackInstruction(root.tools, isToolChoiceRequired(root));
|
|
228
|
+
if (instruction) {
|
|
229
|
+
const first = messages[0];
|
|
230
|
+
if (first && first.role === 'system') {
|
|
231
|
+
first.text = [first.text, instruction].filter(Boolean).join('\n\n');
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
messages.unshift({ role: 'system', text: instruction });
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return messages;
|
|
239
|
+
}
|
|
240
|
+
function mergeByRole(messages) {
|
|
241
|
+
if (!messages.length) {
|
|
242
|
+
return [];
|
|
243
|
+
}
|
|
244
|
+
const merged = [{ ...messages[0] }];
|
|
245
|
+
for (const item of messages.slice(1)) {
|
|
246
|
+
const last = merged[merged.length - 1];
|
|
247
|
+
if (last.role === item.role) {
|
|
248
|
+
last.text = [last.text, item.text].filter(Boolean).join('\n\n');
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
merged.push({ ...item });
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return merged;
|
|
255
|
+
}
|
|
256
|
+
function buildPromptFromMessages(messages) {
|
|
257
|
+
const merged = mergeByRole(messages);
|
|
258
|
+
const parts = [];
|
|
259
|
+
merged.forEach((block, index) => {
|
|
260
|
+
const role = block.role;
|
|
261
|
+
const text = block.text ?? '';
|
|
262
|
+
if (role === 'assistant') {
|
|
263
|
+
parts.push(`<|Assistant|>${text}<|end▁of▁sentence|>`);
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
if (role === 'user' || role === 'system' || role === 'tool') {
|
|
267
|
+
if (index > 0) {
|
|
268
|
+
parts.push(`<|User|>${text}`);
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
parts.push(text);
|
|
272
|
+
}
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
parts.push(text);
|
|
276
|
+
});
|
|
277
|
+
return parts
|
|
278
|
+
.join('')
|
|
279
|
+
.replace(/!\[(.*?)\]\((.*?)\)/g, '[$1]($2)')
|
|
280
|
+
.trim();
|
|
281
|
+
}
|
|
282
|
+
function resolveModel(payload, adapterContext) {
|
|
283
|
+
const direct = readString(payload.model);
|
|
284
|
+
if (direct) {
|
|
285
|
+
return direct;
|
|
286
|
+
}
|
|
287
|
+
const context = (adapterContext ?? {});
|
|
288
|
+
return readString(context.modelId) ?? readString(context.originalModelId) ?? '';
|
|
289
|
+
}
|
|
290
|
+
function resolveThinkingSearchFlags(modelRaw) {
|
|
291
|
+
const model = modelRaw.trim().toLowerCase();
|
|
292
|
+
if (model === 'deepseek-v3' || model === 'deepseek-chat') {
|
|
293
|
+
return { thinking: false, search: false };
|
|
294
|
+
}
|
|
295
|
+
if (model === 'deepseek-r1' || model === 'deepseek-reasoner') {
|
|
296
|
+
return { thinking: true, search: false };
|
|
297
|
+
}
|
|
298
|
+
if (model === 'deepseek-v3-search' || model === 'deepseek-chat-search') {
|
|
299
|
+
return { thinking: false, search: true };
|
|
300
|
+
}
|
|
301
|
+
if (model === 'deepseek-r1-search' || model === 'deepseek-reasoner-search') {
|
|
302
|
+
return { thinking: true, search: true };
|
|
303
|
+
}
|
|
304
|
+
return { thinking: false, search: false };
|
|
305
|
+
}
|
|
306
|
+
function shouldForceSearch(root, adapterContext) {
|
|
307
|
+
const routeId = readString(adapterContext?.routeId)?.toLowerCase() ?? '';
|
|
308
|
+
if (SEARCH_ROUTE_PREFIXES.some((prefix) => routeId.startsWith(prefix))) {
|
|
309
|
+
return true;
|
|
310
|
+
}
|
|
311
|
+
if (isRecord(root.web_search)) {
|
|
312
|
+
return true;
|
|
313
|
+
}
|
|
314
|
+
const context = (adapterContext ?? {});
|
|
315
|
+
if (isRecord(context.__rt) && context.__rt.forceWebSearch === true) {
|
|
316
|
+
return true;
|
|
317
|
+
}
|
|
318
|
+
return false;
|
|
319
|
+
}
|
|
320
|
+
export function applyDeepSeekWebRequestTransform(payload, adapterContext) {
|
|
321
|
+
if (!payload || typeof payload !== 'object') {
|
|
322
|
+
return payload;
|
|
323
|
+
}
|
|
324
|
+
const root = structuredClone(payload);
|
|
325
|
+
const options = resolveOptions(adapterContext);
|
|
326
|
+
const model = resolveModel(root, adapterContext);
|
|
327
|
+
const flags = resolveThinkingSearchFlags(model);
|
|
328
|
+
const forceSearch = shouldForceSearch(root, adapterContext);
|
|
329
|
+
const prompt = buildPromptFromMessages(toPromptMessages(root, options));
|
|
330
|
+
const next = {
|
|
331
|
+
...(readString(root.chat_session_id) ? { chat_session_id: readString(root.chat_session_id) } : {}),
|
|
332
|
+
parent_message_id: readString(root.parent_message_id) ?? null,
|
|
333
|
+
prompt,
|
|
334
|
+
ref_file_ids: Array.isArray(root.ref_file_ids) ? root.ref_file_ids : [],
|
|
335
|
+
thinking_enabled: flags.thinking,
|
|
336
|
+
search_enabled: forceSearch ? true : flags.search
|
|
337
|
+
};
|
|
338
|
+
if (root.stream === true) {
|
|
339
|
+
next.stream = true;
|
|
340
|
+
}
|
|
341
|
+
// Preserve a tiny runtime hint surface for response-side strict/fallback checks.
|
|
342
|
+
next.metadata = {
|
|
343
|
+
...(isRecord(root.metadata) ? root.metadata : {}),
|
|
344
|
+
deepseek: {
|
|
345
|
+
strictToolRequired: options.strictToolRequired,
|
|
346
|
+
textToolFallback: options.textToolFallback
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
return next;
|
|
350
|
+
}
|