@jsonstudio/llms 0.6.473 → 0.6.568
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.js +33 -4
- package/dist/conversion/codecs/openai-openai-codec.js +2 -1
- package/dist/conversion/codecs/responses-openai-codec.js +3 -2
- package/dist/conversion/compat/actions/claude-thinking-tools.d.ts +15 -0
- package/dist/conversion/compat/actions/claude-thinking-tools.js +72 -0
- package/dist/conversion/compat/actions/glm-history-image-trim.d.ts +2 -0
- package/dist/conversion/compat/actions/glm-history-image-trim.js +88 -0
- package/dist/conversion/compat/profiles/chat-gemini.json +15 -14
- package/dist/conversion/compat/profiles/chat-glm.json +194 -194
- package/dist/conversion/compat/profiles/chat-iflow.json +199 -199
- package/dist/conversion/compat/profiles/chat-lmstudio.json +43 -43
- package/dist/conversion/compat/profiles/chat-qwen.json +20 -20
- package/dist/conversion/compat/profiles/responses-c4m.json +42 -42
- package/dist/conversion/compat/profiles/responses-output2choices-test.json +12 -0
- package/dist/conversion/hub/pipeline/compat/compat-pipeline-executor.js +6 -0
- package/dist/conversion/hub/pipeline/compat/compat-types.d.ts +2 -0
- package/dist/conversion/hub/pipeline/hub-pipeline.d.ts +6 -1
- package/dist/conversion/hub/pipeline/hub-pipeline.js +40 -13
- package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/index.js +15 -0
- package/dist/conversion/hub/process/chat-process.js +107 -26
- package/dist/conversion/hub/semantic-mappers/anthropic-mapper.js +8 -0
- package/dist/conversion/hub/semantic-mappers/gemini-mapper.js +28 -10
- package/dist/conversion/hub/semantic-mappers/responses-mapper.js +51 -2
- package/dist/conversion/hub/tool-session-compat.d.ts +26 -0
- package/dist/conversion/hub/tool-session-compat.js +299 -0
- package/dist/conversion/hub/types/chat-envelope.d.ts +1 -0
- package/dist/conversion/responses/responses-openai-bridge.d.ts +0 -1
- package/dist/conversion/responses/responses-openai-bridge.js +0 -71
- package/dist/conversion/shared/anthropic-message-utils.js +54 -0
- package/dist/conversion/shared/args-mapping.js +11 -3
- package/dist/conversion/shared/gemini-tool-utils.js +8 -0
- package/dist/conversion/shared/responses-output-builder.js +47 -88
- package/dist/conversion/shared/streaming-text-extractor.d.ts +25 -0
- package/dist/conversion/shared/streaming-text-extractor.js +31 -38
- package/dist/conversion/shared/text-markup-normalizer.js +42 -27
- package/dist/conversion/shared/tool-filter-pipeline.js +2 -1
- package/dist/conversion/shared/tool-governor.js +75 -4
- package/dist/conversion/shared/tool-harvester.js +43 -12
- package/dist/conversion/shared/tool-mapping.d.ts +1 -0
- package/dist/conversion/shared/tool-mapping.js +33 -13
- package/dist/filters/index.d.ts +1 -0
- package/dist/filters/index.js +1 -0
- package/dist/filters/special/request-toolcalls-stringify.js +5 -55
- package/dist/filters/special/request-tools-normalize.js +14 -23
- package/dist/filters/special/response-apply-patch-toon-decode.d.ts +23 -0
- package/dist/filters/special/response-apply-patch-toon-decode.js +109 -0
- package/dist/filters/special/response-tool-arguments-toon-decode.d.ts +10 -0
- package/dist/filters/special/response-tool-arguments-toon-decode.js +55 -13
- package/dist/guidance/index.js +70 -27
- package/dist/router/virtual-router/bootstrap.js +10 -5
- package/dist/router/virtual-router/classifier.js +9 -4
- package/dist/router/virtual-router/engine-health.d.ts +22 -0
- package/dist/router/virtual-router/engine-health.js +423 -0
- package/dist/router/virtual-router/engine-logging.d.ts +20 -0
- package/dist/router/virtual-router/engine-logging.js +197 -0
- package/dist/router/virtual-router/engine-selection.d.ts +32 -0
- package/dist/router/virtual-router/engine-selection.js +649 -0
- package/dist/router/virtual-router/engine.d.ts +21 -14
- package/dist/router/virtual-router/engine.js +200 -523
- package/dist/router/virtual-router/message-utils.js +22 -0
- package/dist/router/virtual-router/routing-instructions.d.ts +8 -1
- package/dist/router/virtual-router/routing-instructions.js +137 -3
- package/dist/router/virtual-router/tool-signals.js +57 -11
- package/dist/router/virtual-router/types.d.ts +30 -0
- package/dist/router/virtual-router/types.js +1 -1
- package/dist/servertool/engine.js +3 -0
- package/dist/servertool/handlers/gemini-empty-reply-continue.d.ts +1 -0
- package/dist/servertool/handlers/gemini-empty-reply-continue.js +120 -0
- package/dist/servertool/handlers/iflow-model-error-retry.d.ts +1 -0
- package/dist/servertool/handlers/iflow-model-error-retry.js +93 -0
- package/dist/servertool/handlers/stop-message-auto.d.ts +1 -0
- package/dist/servertool/handlers/stop-message-auto.js +204 -0
- package/dist/servertool/handlers/vision.js +105 -7
- package/dist/servertool/server-side-tools.d.ts +3 -0
- package/dist/servertool/server-side-tools.js +29 -0
- package/dist/sse/sse-to-json/builders/anthropic-response-builder.js +16 -0
- package/dist/tools/apply-patch-structured.d.ts +20 -0
- package/dist/tools/apply-patch-structured.js +239 -0
- package/dist/tools/tool-description-utils.d.ts +5 -0
- package/dist/tools/tool-description-utils.js +50 -0
- package/dist/tools/tool-registry.js +14 -5
- package/package.json +2 -2
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const SHELL_TOOL_ALIASES = new Set(['shell', 'shell_command', 'exec_command']);
|
|
2
|
+
const APPLY_PATCH_NAME = 'apply_patch';
|
|
3
|
+
export function normalizeToolName(value) {
|
|
4
|
+
return typeof value === 'string' ? value.trim().toLowerCase() : '';
|
|
5
|
+
}
|
|
6
|
+
function extractToolFunctionName(entry) {
|
|
7
|
+
if (!entry || typeof entry !== 'object') {
|
|
8
|
+
return '';
|
|
9
|
+
}
|
|
10
|
+
const fnName = typeof entry.function?.name === 'string'
|
|
11
|
+
? entry.function.name
|
|
12
|
+
: undefined;
|
|
13
|
+
if (fnName && fnName.trim().length > 0) {
|
|
14
|
+
return fnName.trim();
|
|
15
|
+
}
|
|
16
|
+
const topName = typeof entry.name === 'string' ? entry.name : '';
|
|
17
|
+
return topName.trim();
|
|
18
|
+
}
|
|
19
|
+
export function isShellToolName(value) {
|
|
20
|
+
return SHELL_TOOL_ALIASES.has(normalizeToolName(value));
|
|
21
|
+
}
|
|
22
|
+
export function hasApplyPatchToolDeclared(tools) {
|
|
23
|
+
if (!Array.isArray(tools)) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
return tools.some((entry) => normalizeToolName(extractToolFunctionName(entry)) === APPLY_PATCH_NAME);
|
|
27
|
+
}
|
|
28
|
+
export function buildShellDescription(toolDisplayName, hasApplyPatch) {
|
|
29
|
+
const label = toolDisplayName && toolDisplayName.trim().length > 0
|
|
30
|
+
? toolDisplayName.trim()
|
|
31
|
+
: 'shell';
|
|
32
|
+
const base = 'Runs a shell command and returns its output.';
|
|
33
|
+
const workdirLine = `- Always set the \`workdir\` param when using the ${label} function. Avoid using \`cd\` unless absolutely necessary.`;
|
|
34
|
+
const applyPatchLine = '- Prefer apply_patch for editing files instead of shell redirection or here-doc usage.';
|
|
35
|
+
return hasApplyPatch ? `${base}\n${workdirLine}\n${applyPatchLine}` : `${base}\n${workdirLine}`;
|
|
36
|
+
}
|
|
37
|
+
export function appendApplyPatchReminder(description, hasApplyPatch) {
|
|
38
|
+
if (!hasApplyPatch) {
|
|
39
|
+
return description;
|
|
40
|
+
}
|
|
41
|
+
const trimmed = description?.trim() ?? '';
|
|
42
|
+
if (!trimmed) {
|
|
43
|
+
return buildShellDescription('shell', true);
|
|
44
|
+
}
|
|
45
|
+
if (trimmed.includes('apply_patch')) {
|
|
46
|
+
return trimmed;
|
|
47
|
+
}
|
|
48
|
+
const applyPatchLine = '- Prefer apply_patch for editing files instead of shell redirection or here-doc usage.';
|
|
49
|
+
return `${trimmed}\n${applyPatchLine}`;
|
|
50
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// Tool registry and validator (single source of truth)
|
|
2
|
+
import { buildStructuredPatch, isStructuredApplyPatchPayload, StructuredApplyPatchError } from './apply-patch-structured.js';
|
|
2
3
|
const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
3
4
|
const asString = (value) => {
|
|
4
5
|
if (typeof value === 'string' && value.trim().length > 0) {
|
|
@@ -95,12 +96,20 @@ export function validateToolCall(name, argsString) {
|
|
|
95
96
|
const rawArgs = tryParseJson(typeof argsString === 'string' ? argsString : '{}');
|
|
96
97
|
switch (normalizedName) {
|
|
97
98
|
case 'apply_patch': {
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
99
|
+
const record = rawArgs;
|
|
100
|
+
if (!isStructuredApplyPatchPayload(record)) {
|
|
101
|
+
return { ok: false, reason: 'missing_changes' };
|
|
102
|
+
}
|
|
103
|
+
try {
|
|
104
|
+
const patchText = buildStructuredPatch(record);
|
|
105
|
+
return { ok: true, normalizedArgs: toJson({ patch: patchText, input: patchText }) };
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
if (error instanceof StructuredApplyPatchError) {
|
|
109
|
+
return { ok: false, reason: error.reason || 'invalid_patch_payload' };
|
|
110
|
+
}
|
|
111
|
+
return { ok: false, reason: 'invalid_patch_payload' };
|
|
102
112
|
}
|
|
103
|
-
return { ok: true, normalizedArgs: toJson({ input: patch, patch }) };
|
|
104
113
|
}
|
|
105
114
|
case 'shell': {
|
|
106
115
|
const rawCommand = rawArgs.command;
|